akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

vector<pair<char,int>> RL_S(string s){
  vector<pair<char,int>> res;
  int n=s.length();
  char ima;int cnt=0;
  rep(i,n){
    if(cnt==0){
      ima=s[i];
      cnt++;
    }
    else if(s[i]==ima)cnt++;
    else{
      res.pb(make_pair(ima,cnt));
      ima=s[i];
      cnt=1;
    }
  }
  res.pb(make_pair(ima,cnt));
  return res;
}

int a[100010];
signed main(){
  string s;cin>>s;
  int ima=0;
  for(auto p:RL_S(s)){
    char c=p.F;int ko=p.S;
    if(c=='R'){
      a[ima+ko-1]+=(ko+1)/2;
      a[ima+ko]+=ko/2;
    }
    if(c=='L'){
      a[ima]+=(ko+1)/2;
      a[ima-1]+=ko/2;
    }
    ima+=ko;
  }
  int n=s.length();
  rep(i,n)cout<<a[i]<<" ";
  cout<<endl;
  return 0;
}

Measured memory_bytes: 5836
#include<bits/stdc++.h>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,M,A[101010];
priority_queue<ll> pq;
ll i, j, k, ans;
int main(){
    scanf("%lld%lld", &N, &M);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
        pq.push(A[i]);
    }
    fornum(i,0,M){
        ll qa = pq.top();
        pq.pop();
        pq.push(qa / 2);
    }
    while(pq.size()){
        ll qa = pq.top();
        pq.pop();
        ans += qa;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
typedef signed long long int ll;

int main(){
    int n;
    ll k;
    ll a[100005];
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    int zero[70];
    int one[70];
    int keta=0;//0,1は0桁
    ll dketame[70]={0};
    while(k>0){
        dketame[keta]=k%2;
        k/=2;
        if(k>0) keta++;
    }
    for(int i=0;i<51;i++){
        for(int j=0;j<n;j++){
            
            if(a[j]%2==0) zero[i]++;
            else one[i]++;
            a[j]/=2;
        }
    }
    ll res=0;
    for(int d=40;d>=-1;d--){
        if(d!=-1 && dketame[d]==0) continue;
        
        ll tmp=0;
        
        for(int i=0;i<40;i++){
            ll mask=1LL<<i;
            if(i<d){
                tmp+=max(zero[i],one[i])*mask;
            }
            else if(i==d){
                tmp+=one[i]*mask;
            }
            else{
                if(dketame[i]==1) tmp+=zero[i]*mask;
                else tmp+=one[i]*mask;
            }
        }
        res=max(res,tmp);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int[] height = new int[20];
	int first=15,second=15,third=15;
	height[15]=0;
	for(int i=0;i<10;i++){
		height[i]=sc.nextInt();
		if(height[first]<height[i]){
			third=second;
			second=first;
			first=i;
		}else if(height[second]<height[i]){
			third=second;
			second=i;
		}else if(height[third]<height[i]) third=i; 
	}
	System.out.println(height[first]);
	System.out.println(height[second]);
	System.out.println(height[third]);
    }
}



Measured memory_bytes: 26180
import java.util.Scanner;

public class Main {

    int N, A, B, C;
    int[] len;

    void solve() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        len = new int[N];

        for (int i = 0; i < N; i++) {
            len[i] = sc.nextInt();
        }
        int ans = calcMinMP(0, 0, 0, 0);
        System.out.print(ans);
    }

    // Aの長さがlenA、 Bの長さがlenB、Cの長さがlenCの時、curIndex 以降の材料を使って算出した最小のMP。
    int calcMinMP(int curIndex, int lenA, int lenB, int lenC) {
        // 最後の len[i] まで処理したので、ここで最小値を計算してreturnする。脱出条件。
        if (curIndex == N) {
            if (Math.min(Math.min(lenA, lenB), lenC) > 0) {
                int MP = (Math.abs(A - lenA) - 10) + (Math.abs(B - lenB) - 10) + (Math.abs(C - lenC) - 10);
                return MP;
            }
            else {
                // throw new IllegalStateException();
                return (int)Math.pow(10,9);
            }
        }

        // まだ処理すべきlen[i]があるので、次に行く。

        int resultA    = calcMinMP(curIndex + 1, lenA + len[curIndex], lenB, lenC) + 10;
        int resultB    = calcMinMP(curIndex + 1, lenA, lenB + len[curIndex], lenC) + 10;
        int resultC    = calcMinMP(curIndex + 1, lenA, lenB, lenC + len[curIndex]) + 10;
        int resultNone = calcMinMP(curIndex + 1, lenA, lenB, lenC);
        return Math.min(resultA, Math.min(resultB, Math.min(resultC, resultNone)));
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

Measured memory_bytes: 23864
#include<bits/stdc++.h>
typedef long long ll;using namespace std;int main() {int n; cin >> n;ll x[1005],y[1005];int a;for (int i=0;i<n;i++){cin>>x[i]>>y[i];if(i==0)a=abs(x[i]+y[i])%2;else if(a!=abs(x[i]+y[i])%2){cout<<-1<<endl;return 0;}}vector<string> w(n,""),p(n,"");if(a==0){cout<<32<<endl<<1<<" ";for (int i=0;i<n;i++){p[i]+="R";x[i]-=1;}}else cout <<31<<endl;for(int i=0;i<=30;i++)cout<<(1<<i)<<" ";cout<<endl;for(int i=0;i<n;i++){for (int j=30;j>=0;j--){ll d=1<<j;ll nx=d-1;if(abs(x[i]-d)+abs(y[i])<=nx){w[i]="R"+w[i];x[i]-=d;}else if(abs(x[i]+d)+abs(y[i])<=nx){w[i]="L"+w[i];x[i]+=d;}else if(abs(x[i])+abs(y[i]+d)<=nx){w[i]="D"+w[i];y[i]+=d;}else{w[i]="U"+w[i];y[i]-=d;}}cout<<p[i]+w[i]<<endl;}return 0;}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;


int main() {
	int n; cin >> n;
	string s; cin >> s;
	s = "@" + s + "@";
	vector<int> cntb(n + 2), cntw(n + 2);
	for (int i = 1; i <= n + 1; i++) {
		cntb[i] = cntb[i - 1] + (s[i] == '#');
	}
	for (int i = n; i >= 0; i--) {
		cntw[i] = cntw[i + 1] + (s[i] == '.');
	}
	int ans = 1e9;
	for (int i = 0; i <= n; i++) {
		ans = min(ans, cntw[i + 1] + cntb[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

vector<int> factor(int n) {
  vector<int> ret;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i != 1 && i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  return ret;
}

int f[10000050LL];

int main() {
  ll K;
  scanf("%lld", &K);

  f[1] = -1;

  for (ll i = 2; i <= 5000001LL; i++) {
    ll n = i;
    for (;;) {
      n += i;

      if (n >= 10000005LL) {
        break;
      }

      f[n]++;
    }
  }

  ll ans = 0;

  for (ll i = 1; i <= K; i++) {
    // cout << i << ":" << f[i] << endl;

    ll cnt = f[i] + 2;
    ans += (cnt * i);
  }

  cout << ans << endl;
}


Measured memory_bytes: 42756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n;
    cin >> n;
    vector<int> l(2 * n);
    rep(i, 2 * n) cin >> l[i];

    sort(l.begin(), l.end());
    int ans = 0;
    for (int i = 0; i < 2 * n; i += 2) {
        ans += l[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
    std::string S, T;
    std::cin >> S;
    std::cin >> T;

    int ans = 0;
    for(int i = 0; i<S.length(); i++)
    {
        if(S[i] != T[i])
        {
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3912
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
#define endl '\n'
#define all(v) v.begin(), v.end()

int main() {
    string s, t;
    cin >> s >> t;
    int ls = s.size(), lt = t.size();
    int ans = t.size() + 1;
    for (int i = 0; i <= ls - lt;i++) {
        int op = 0;
        for (int j = 0; j < lt; j++) {
            if (t[j] != s[i+j])
                op++;
        }
        ans = min(ans, op);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3588
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}



void solve(){
   string s;
   cin >> s;

   int a = (s[0] - '0')*10 + s[1] - '0';
   int b = (s[2] - '0')*10 + s[3] - '0';

   if(a>0 && a<=12 && b>0 && b<=12){cout << "AMBIGUOUS" << endl;return;}
   else if(a>0 && a<=12 && (b>12 || b<=0)){cout << "MMYY" << endl;return;}
   else if((a==0 || a>12) && b>0 && b<=12){cout << "YYMM" << endl;return;}
   else cout << "NA" << endl;

} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[101]={0};
	int n,x;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin>> x;
		a[x]=1;
	}
	int s=0;
	for(int i=1;i<=100;i++)
	{
		if(a[i]==1)
		{
			s++;
		}
	}
	cout <<s <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a[]={11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,811,821,911,941,971,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381,1451,1471,1481};
  cin >> n;
  for(int i=0;i<n;i++){
    if(i>0){
      cout << ' ';
    }
    cout << a[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b=a;
		int sum=0;
		int c=10;
		for(;;) {
			if(a<10) {
				sum+=a;
				break;
			}
			sum+=a%c;
			a=a/10;
		}
		if(b%sum==0)System.out.println("Yes");
		else System.out.println("No");
		//System.out.println(sum);
	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;

int main(){
  long long int N,ans;
  cin>>N;
  long long int E = sqrt(N);

  for(long long int i = E;i>0;i--){
    if(N%i==0){
      ans = (N/i-1)+(i-1);
      break;
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(i,j,k) for (i=j;i<=k;i++)
#define edge(j) for (j=fst[x];j;j=nxt[j])
using namespace std;
const int N=2e5+5;
int n,x,y,i,j,u,v,ans,mode;
int En,fst[N],Fa[N],nxt[N*2],to[N*2];
int U[N],V[N],X[N],Y[N],A[N],B[N];
void File()
{
	freopen("game.in","r",stdin);
	freopen("game.out","w",stdout);
}
void add(int u,int v) {
	En++; nxt[En]=fst[u]; fst[u]=En; to[En]=v;
}
void dfs(int x,int fa,int step,int *A)
{
	int j,v;
	if (mode==1 && step>=B[x]) return ;
	A[x]=step;
	if (mode==2) Fa[x]=fa;
	edge(j)
	{
		v=to[j];
		if (v==fa) continue;
		dfs(v,x,step+1,A);
	}
}
void Init()
{
	scanf("%d%d%d",&n,&x,&y);
	rep(i,1,n-1)
		scanf("%d%d",&U[i],&V[i]);
	
	rep(i,1,n-1)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	rep(i,1,n) A[i]=n+1;
	
	mode=2; dfs(y,y,0,B);
	memset(fst,0,sizeof(fst));
	En=0;
	rep(i,1,n-1)
		{add(U[i],V[i]); add(V[i],U[i]);	}	
	mode=1; dfs(x,x,0,A);
}
void Solve()
{
	rep(i,1,n-1)
	{
		if (Fa[U[i]]==V[i] || Fa[V[i]]==U[i]) continue;
		if (Fa[U[i]]==Fa[V[i]] || Fa[Fa[U[i]]]==V[i] || Fa[Fa[V[i]]]==U[i]) continue;
		if (A[U[i]]<B[U[i]] || A[V[i]]<B[V[i]])
		{
			printf("-1\n");
			return ;
		}
	}
	rep(i,1,n)
		if (A[i]<B[i])
			ans=max(ans,B[i]);
	ans*=2;
	printf("%d\n",ans);
}
int main()
{
	//File();
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 17536
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <sstream>
#include <queue>
using namespace std;

int main ()
{
    int n;
    while (cin >> n, n) {
        map<string,int> atm;
        for (int i = 0; i < n; i++) {
            int b; string a;
            cin >> a >> b;
            atm[a] = b;
        }
        int m;  cin >> m;
        map<string, queue<string> > rcp;
        for (int i = 0; i < m; i++) {
            string str; int t;
            cin >> str >> t;
            queue<string> q;
            int r_cost = 0;
            for (int j = 0; j < t; j++) {
                string s; cin >> s;
                r_cost += atm[s];
                q.push(s);
            }
            if (atm.find(str) != atm.end()) atm[str] = min(atm[str], r_cost);
            else atm[str] = r_cost;
            rcp[str] = q;
        }
        string pro; cin >> pro;
        if (rcp.find(pro) == rcp.end()) cout << atm[pro] << endl;
        else {
            int res = 0;
            while (!rcp[pro].empty()) {
                string s = rcp[pro].front(); rcp[pro].pop();
                res += atm[s];
            }
            cout << (min(atm[pro], res)) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
char s[10005];
int main () {
	cin >> s+1;
	int flg = 0;
	if(s[1] == s[2] || s[2] == s[3] || s[3] == s[4]) flg = 1;

	if(flg) puts("Bad");
	else puts("Good");

	return 0;
}

Measured memory_bytes: 256
s=[]
while True:
    tmp=list(map(int,input().split()))
    if tmp==[0,0]:
        break
    else:
        s.append(tmp)

for si in s:
    H,W=si[0],si[1]
    for i in range(H):
        if i==0 or i==H-1:
            print("#"*W)
        else:
            print("#"+"."*(W-2)+"#")
    print()



Measured memory_bytes: 5624
#include <iostream>
#include <vector>
using namespace std;


int main()
{
    int N;
    int F[101][11], P[101][11];

    cin >> N;
    for( int i = 1; i <= N; ++i ){
        for( int j = 1; j <= 10; ++j ){
            cin >> F[i][j];
        }
    }
    for( int i = 1; i <= N; ++i ){
        for( int j = 0; j <= 10; ++j ){
            cin >> P[i][j];
        }
    }

    int ans = -1e+9;
    for( int i = 1; i < (1<<10); ++i ){
        int profit = 0;
        for( int j = 1; j <= N; ++j ){
            int tmp = 0;  // Joisino の店と店 j が同時に開いている日数
            for( int k = 1; k <= 10; ++k ){
                if( F[j][k] && (i & (1<<(k-1))) ) tmp++;
            }
            profit += P[j][tmp];
        }
        ans = max( ans, profit );
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>();
		for (int i = 0; i < n; i++) {
		    graph.add(new HashMap<>());
		}
		for (int i = 0; i < n - 1; i++) {
		    int a = sc.nextInt() - 1;
		    int b = sc.nextInt() - 1;
		    int c = sc.nextInt();
		    graph.get(a).put(b, c);
		    graph.get(b).put(a, c);
		}
		int q = sc.nextInt();
		int k = sc.nextInt() - 1;
		PriorityQueue<Path> queue = new PriorityQueue<>();
		queue.add(new Path(k, 0));
		long[] costs = new long[n];
		Arrays.fill(costs, Long.MAX_VALUE);
		while (queue.size() > 0) {
		    Path p = queue.poll();
		    if (costs[p.idx] <= p.value) {
		        continue;
		    }
		    costs[p.idx] = p.value;
		    for (Map.Entry<Integer, Integer> entry : graph.get(p.idx).entrySet()) {
		        queue.add(new Path(entry.getKey(), entry.getValue() + p.value));
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int a = sc.nextInt() - 1;
		    int b = sc.nextInt() - 1;
		    sb.append(costs[a] + costs[b]).append("\n");
		}
		System.out.print(sb);
   }
    
    
    static class Path implements Comparable<Path> {
        int idx;
        long value;
        
        public Path (int idx, long value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Path another) {
            if (value == another.value) {
                return 0;
            } else if (value < another.value) {
                return -1;
            } else {
                return 1;
            }
        }
    }
}



Measured memory_bytes: 188432
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    long long int q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;

    long long int per1 = min(q*4, min(h*2, s));
    cout << min(n * per1, (((n-(n%2))/2) * d + (n%2) * per1));

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    private void compute(){
        int i;
        int tmp = 0;
        int cnt = 0;

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        int[] c = new int[N];

        for (i = 0; i < N; i ++ ) a[i] = b[i] = c[i] = 0;

        int X = sc.nextInt();
        for (i = 0; i < X; i++){
            tmp = sc.nextInt();
            a[tmp - 1] = 1;
        }
        int Y = sc.nextInt();
        for (i = 0; i < Y; i++){
            tmp = sc.nextInt();
            b[tmp - 1] = 1;
        }
        int Z = sc.nextInt();
        for (i = 0; i < Z; i++){
            tmp = sc.nextInt();
            c[tmp - 1] = 1;
        }
        for (i = 0; i < N; i ++){
            if ((a[i] != 1 && c[i] == 1) || (b[i] == 1 && c[i] == 1)){
                cnt ++;
            }
        }

        System.out.println(cnt);
    }
    public static void main(String[] arg){
        new Main().compute();
    }
}


Measured memory_bytes: 26852
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
using namespace std;

 int main(){
     string s;
     cin >> s;
     if (s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
     else cout << "Yes"<<endl;
    

    
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

using namespace std;

// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> void inputVec(std::vector<T>& vec) {
	for (typename std::vector<T>::iterator it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

void Main() {
	//int N; cin >> N;
	const string steps = inputVal<string>();

	bool isEasy = true;
	for (unsigned int i = 0; i < steps.size(); ++i) {
		const char difficult = (i % 2 == 0) ? 'L' : 'R';
		if (steps[i] == difficult) {
			isEasy = false;
			break;
		}
	}
	const string ret = (isEasy ? "Yes" : "No");
	outputVal(ret);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;
const double PI = acos(-1);

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};

lli gcd(lli a , lli b) {
    if(b == 0) return a;
    a %= b;
    return gcd(b,a);
}

lli dp[MAXN];

lli f(lli x) {
    if (x < 0) return 0;
    if (x == 0) return 1;
    if (dp[x] != -1) return dp[x];

    lli ans = 0;
    ans += f(x - 100);
    ans += f(x - 101);
    ans += f(x - 102);
    ans += f(x - 103);
    ans += f(x - 104);
    ans += f(x - 105);

    return dp[x] = ans;
}

void solve() {
    lli x;
    cin >> x;
    memset(dp, -1, sizeof(dp));
    lli ans = f(x);
    cout << (ans != 0) << endl;
    //cout << ans << endl;
}

int main()
{
    IOS;
    //comment it out
    //freopen("input.txt", "r", stdin);
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1024
n,m = map(int,input().split())
res = [0]*31
for i in range(n):
    l = list(map(int,input().split()))
    for j in l[1:]:
        res[j] += 1
else:
    num = 0
    for k in res:
        if k==n:
            num += 1
    else:
        print(num)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

i64 eval (i64 x, i64 a, i64 b) {
  i64 res = x / b;
  x %= b;
  res += x / a;
  x %= a;
  return res + x;
}

void run (void) {
  i64 a, b;
  scanf ("%" SCNi64 "%" SCNi64, &a, &b);
  if (b % a == 0) {
    puts ("-1");
    return;
  }
  for (i64 c = b; c < b * a; c += b) {
    i64 v = (c + a - 1) / a * a;
    i64 x = v / a;
    i64 y = eval (v, a, b);
    if (x < y) {
      printf ("%" PRIi64 "\n", v);
      return;
    }
  }
  puts ("-1");
}

int main (void) {
  run();
  return 0;
}



Measured memory_bytes: 2112
def gets; ARGF.gets; end

def main
  n = gets.chomp.to_i

  ans = 0
  1.upto(n) do |i|
    next if i.even?
    cnt = 0
    1.upto(i) do |d|
      if i % d == 0
        cnt += 1
      end
    end
    ans += 1 if cnt == 8
  end
  puts ans
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n){

    int ans[1000];
    int p = 0;

    int m = n;
    for(int i = 2 ; i < m ; i*=2){
      if(i*2 > m)m = i;
    }

    for(int i = m ;i > 0; i/=2 ){
      if(n - i >= 0 ){
	ans[p++] = i;
	n -= i;
      }
    }
  for(int i = p - 1 ; i > 0 ; i-- ){
    cout << ans[i] << " ";
  }
  cout <<ans[0]<< endl;

  }
  }

Measured memory_bytes: 1164
N = int(input())
d = list( map(int, input().split() ) )
kai = 1
mod = 10**9+7
result = 0

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

for i in range(1,N):
    kai = (kai%mod)*i

for i in range(N-1):    
    result += ( kai * (d[N-1] - d[i]) * modinv(i+1) ) % mod 

print( result%mod )

Measured memory_bytes: 62832
#include <bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=(res*x)%INF;y=y>>1;x=(x*x)%INF;}return res%INF;} // modular exponent
ll n,m;
const int N=5e5+5;
ll fact[N];
ll invfact[N];
ll modinv(ll x)
{
  return power(x,INF-2);
}
void precompute()
{
  fact[0]=1ll;
  invfact[0]=1ll;
  repA(i,1,N-1)
  {
    fact[i]=(i*fact[i-1])%INF;
    invfact[i]=modinv(fact[i]);
  }
}
ll C(ll n,ll r)
{
  if(r>n) return 0;
  ll num=fact[n];
  num*=invfact[r];
  num%=INF;
  num*=invfact[n-r];
  num%=INF;
  return num;
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    cin>>n>>m;
    precompute();
    ll ans =0;
    ll cur=1;
    for(ll j=0;j<=n;j++)
    {
      ll val=cur*C(n,(ll)j);
      val+=INF;
      val%=INF;
      val*=C(m-(ll)j,n-(ll)j);
      val%=INF;
      val*=fact[n-(ll)j];
      val%=INF;
      ans+=val;
      ans%=INF;
      cur*=-1;
    }
    ans*=fact[n];
    ans%=INF;
    ans*=C(m,n);
    ans%=INF;
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 11436
#include<iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int H,W,h,w;
    cin >> H >> W >> h >> w;

    cout << (H - h)*(W-w) << endl;
    
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
map<string, int> mp;
set<string> cnt;
void add(int i, vi &p, vector<vector<string>> &v,vector<bool> &b) {
	if (b[i])return;
	set<string> tmp;
	b[i] = true;
	REP(j, v[i].size()) {
		if (mp[v[i][j]] != 0) {
			int nx = mp[v[i][j]] - 1;
			add(nx, p, v, b);
			
		}
		else cnt.insert(v[i][j]);
	}
	

}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		mp.clear();
		cnt.clear();
		vector<vector<string>> v(n);
		vi p(n);
		REP(i, n) {
			string s;
			cin >> s;

			s.back() = ',';
			REP(j, s.size()) {
				if (s[j] == ':') {
					p[i] = j; break;
				}
			}
			mp[s.substr(0, p[i])] = i + 1;
			string tmp;
			FOR(j, p[i] + 1, s.size()) {
				if (s[j] == ',') {
					v[i].push_back(tmp);
					tmp = "";
				}
				else tmp += s[j];
			}
		}
		vector<bool> b(n,false);
		add(0, p, v,b);
		cout << cnt.size() << endl;


	}
}

Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N;
    cin >> N;
    int val = 1000;
    if(N % val == 0){
        cout << 0 << endl;
        return 0;
    }else{
        cout << val - (N % val) << endl;
        return 0;
    }
}

Measured memory_bytes: 3608
open Printf
open Scanf

let () =
  let n = scanf " %d" (fun x -> x) in
  let a = Array.init n (fun _ -> scanf " %f" (fun x -> x)) |> Array.to_list |> List.sort compare in
  List.fold_left (fun x y -> (x +. y) /. 2.0) (List.hd a) (List.tl a)
  |> printf "%.15f\n"

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;
int main(){
        int n; cin >> n;
        long long a[100000]; rep(i,n) cin>>a[i];
        bool zeroFlag = false;
        long long costA = 0, costB = 0;

        long long sum = 0, prev=0;

        if(a[0]==0) {
                a[0]=1;
                costA+=1;
                zeroFlag = true;
        }
        rep(i,n){
                prev = sum;
                sum += a[i];
                if(i==0) continue;
                if((prev*sum) < 0) continue;
                if(prev<0) {
                        costA+= abs(sum-1);
                        sum = 1;
                }else{
                        costA+= abs(sum+1);
                        sum = -1;
                }

        }


        if(zeroFlag) {
                a[0]=-1;
                costB+=1;
        }else{
                long long a0 = a[0];
                a[0]= -1* a[0]/abs(a[0]);
                costB+=(abs(a0)+1);
        }

        sum = 0; prev = 0;
        rep(i,n){
                prev = sum;
                sum += a[i];
                if(i==0) continue;
                if((prev*sum) < 0) continue;
                if(prev<0) {
                        costB+= abs(sum-1);
                        sum = 1;
                }else{
                        costB+= abs(sum+1);
                        sum = -1;
                }
        }

        cout << min(costA,costB) << endl;

        return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
vector<string> bd;
const in mdl=1000000007;
VI rcon,ccon;
VVI bas;
queue<in> rrm,crm;
in totrm=0;
in sm=1;
void rmr(in u){
  in s=0;
  forv(i,bas[u]){
    s+=bas[u][i];
    if(bas[u][i]){
      --ccon[i];
      if(ccon[i]<=1 && ccon[i]>=0){
	ccon[i]=-1;
	++totrm;
	crm.push(i);
      }
    }
    bas[u][i]=0;
  }
  if(s)
    sm*=2;
  sm%=mdl;
}
void rmc(in u){
  in s=0;
  forv(i,bas){
    s+=bas[i][u];
    if(bas[i][u]){
      --rcon[i];
      if(rcon[i]<=1 && rcon[i]>=0){
	rcon[i]=-1;
	++totrm;
	rrm.push(i);
      }
    }
    bas[i][u]=0;
  }
  if(s)
    sm*=2;
  sm%=mdl;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in h,w;
  cin>>h>>w;
  bd.resize(h);
  forn(i,h)
    cin>>bd[i];
  if(h%2){
    string s=bd[h/2];
    reverse(all(s));
    if(s!=bd[h/2])
      sm*=2;
  }
  if(w%2){
    string s(h,'a');
    forn(i,h)
      s[i]=bd[i][w/2];
    reverse(all(s));
    bool dif=0;
    forn(i,h)
      if(s[i]!=bd[i][w/2])
	dif=1;
    if(dif)
      sm*=2;
  }
  bas.resize(h/2,VI(w/2));
  rcon.resize(h/2);
  ccon.resize(w/2);
  forn(i,h/2){
    forn(j,w/2){
      string s;
      s.PB(bd[i][j]);
      s.PB(bd[h-1-i][j]);
      s.PB(bd[i][w-1-j]);
      s.PB(bd[h-1-i][w-1-j]);
      sort(all(s));
      in pm=24;
      in csz=1;
      forn(z,4){
	if(z==0 || s[z]!=s[z-1]){
	  for(in zz=1;zz<=csz;++zz)
	    pm/=zz;
	  csz=1;
	  continue;
	}
	++csz;
      }
      for(in zz=1;zz<=csz;++zz)
	pm/=zz;
      if(pm==24){
	++rcon[i];
	++ccon[j];
	bas[i][j]=1;
	pm/=2;
      }
      sm*=pm;
      sm%=mdl;
    }
  }
  forv(i,rcon){
    if(rcon[i]<=1){
      rcon[i]=-1;
      ++totrm;
      rrm.push(i);
    }
  }
  forv(i,ccon){
    if(ccon[i]<=1){
      ccon[i]=-1;
      ++totrm;
      crm.push(i);
    }
  }
  in u;
  while(!rrm.empty() || !crm.empty()){
    if(!rrm.empty()){
      u=rrm.front();
      rrm.pop();
      rmr(u);
    }
    else{
      u=crm.front();
      crm.pop();
      rmc(u);
    }
  }
  in lft=h/2+w/2-totrm-1;
  forn(i,lft)
    sm=sm*2%mdl;
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 384
N, M = map(int, input().split())
Data = [list(map(int, input().split())) for i in range(N)]

Queue = sorted(Data, key=lambda a:a[0])
num = 0
ans = 0
while(M > num):
    q = Queue.pop(0)
    dif = min(q[1], M - num)
    num += dif
    ans += dif*q[0]
print(ans)
    

Measured memory_bytes: 29752
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
#include <string>
#include <iterator>
#include <vector>
 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 1e6 + 5;
int n = 0, m = 0;
int a[MAXN];
int b[MAXN];


int largest(int a, int b){
	return (a<b)?b:a;
}


int main() {
	int n = 0;
	string s;
	cin >> n;
	cin >> s;
	if(n == 0){
		cout << s << endl;
		return 0;
	}
	for(int i = 0; i < s.length(); ++i){
		int l = n;
		while(l != 0){
			if(s[i] == 'Z'){
				s[i] = 'A';
				--l;
				continue;
			}
			s[i]++;
			l--;
		}
	}
	cout << s << endl;






    return 0;
} 

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

int main() {
    string s;
    cin >> s;
    int n = s.size(),q;
    bool rev = false;
    deque<char> dq;
    for (int i = 0;i < n;++i) dq.push_back(s[i]);
    cin >> q;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) rev = (!rev);
        else {
            int f;char c;
            cin >> f >> c;
            if ((f == 2) == (rev == false)) dq.push_back(c);
            else dq.push_front(c);
        }
    }

    if (rev) {
        while (!dq.empty()) {
            cout << dq.back();dq.pop_back();
        }
    } else {
        while (!dq.empty()) {
            cout << dq.front();dq.pop_front();
        }
    }
    cout << endl;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<stdio.h>
using namespace std;

int a,b;

int main() {
	cin >> a >> b;
	if (b%a == 0) {
		cout << a + b << endl;
	}
	else {
		cout << b - a << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import sys

S = input()
T = input()

r_dic = {}
s_dic = {}
for i in range(len(S)):
    s = S[i]
    t = T[i]
    # print(s, t)
    # print(r_dic, s in r_dic)

    if(t in r_dic and r_dic[t] != s):
        print("No")
        sys.exit()
    else:
        r_dic[t] = s

    if(s in s_dic and s_dic[s] != t):
        print("No")
        sys.exit()
    else:
        s_dic[s] = t

print("Yes")

Measured memory_bytes: 3632
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

using namespace std;

template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using R=long double;
const R EPS=1e-9L;
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const R INF = 1E40L;
using P=complex<R>;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P c;R r;};

auto& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
auto& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline int sdet(P o,P a,P b){return sgn(det(o,a,b));}

P proj(L l,P p){ R u=real((p-l.s)/(l.t-l.s)); return (1-u)*l.s+u*l.t;}

bool iss(L a,L b){
    int sa=sdet(a.s,a.t,b.s)*sdet(a.s,a.t,b.t);
    int sb=sdet(b.s,b.t,a.s)*sdet(b.s,b.t,a.t);
    return max(sa,sb)<0;
}

VP cross(C c, L l){
    P h=proj(l,c.c),e=polar(sq(norm(c.r)-norm(h-c.c)),arg(l.t-l.s));
    return VP{h-e,h+e};
}

VP cross(C a,C b){
    P d=b.c-a.c,w=(norm(d)+norm(a.r)-norm(b.r))/(2.0L*norm(d))*d;
    return cross(a,{a.c+w,a.c+w+1il*w});
}

int n,m;
R cost[210][210];
C c[110];
L l[110];
P p[210];
 
inline int conv(int i){
    if(i==0) return -1;
    if(i==m-1) return n-1;
    return (i-1)/2;
}
 
int main(void){
    while(cin >> n,n){
        m=2*n;
        rep(i,m)rep(j,m) cost[i][j]=((i==j)?0:INF);
 
        rep(i,n) cin >> c[i].c >> c[i].r;
        
        p[0]=c[0].c;
        rep(i,n-1){
            VP res=cross(c[i],c[i+1]);
            p[2*i+1]=res[0];
            p[2*i+2]=res[1];
            l[i]=L{res[0],res[1]};
        }
        p[m-1]=c[n-1].c;
 
        rep(j,m)rep(i,j){
            L tar=L{p[i],p[j]};
 
            bool ok=true;             
            for(int k=conv(i)+1;k<conv(j);k++){
                if(iss(tar,l[k])==false)
                    ok=false;
            }
            if(ok) cost[i][j]=cost[j][i]=abs(p[i]-p[j]);
        }
        rep(k,m)rep(i,m)rep(j,m) chmin(cost[i][j],cost[i][k]+cost[k][j]);
         
        cout.precision(9);
        cout << fixed << cost[0][m-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 4144
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

bool isYYMM(const string& s) {
  // int x = atoi(s.substr(0, 2).c_str());

  int y = atoi(s.substr(2, 2).c_str());
  return 1<=y && y<=12;
}

bool isMMYY(const string& s) {
  int x = atoi(s.substr(0, 2).c_str());
  return 1<=x && x<=12;
}

int main(int argc, char** argv) {
  string S;
  cin >> S;

  bool a = isYYMM(S);
  bool b = isMMYY(S);

  if (a&&b) {
    cout << "AMBIGUOUS" << endl;
  } else if (a) {
    cout << "YYMM" << endl;
  } else if (b) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)
int main() {
	string s, t; cin >> s >> t;
	cout << t << s << endl;
}

Measured memory_bytes: 3484
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int[] size = new int[4];
        for(int i = 0; i < 3; i++) {
            int a = scan.nextInt() - 1, b = scan.nextInt() - 1;
            size[a]++;
            size[b]++;
        }
        int two = 0, one = 0;
        for(int i = 0; i < 4; i++) {
            if(size[i] == 2) two++;
            else if(size[1] == 2) one++;
        }
        System.out.println(one == 2 && two == 2 ? "YES" : "NO");
    }
}


Measured memory_bytes: 23636
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  long long ans = 0;
  int mi = 1e9, c = 0;
  for(int i = 0; i < N; ++i){
    if(A[i] > 0) ans += A[i], mi = min(mi,A[i]);
    else ans -= A[i], mi = min(mi,-A[i]), ++c;
  }
  if(c%2)
    ans -= 2*mi;
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back

using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;

void solve()
{
	string s; cin >> s;
	int k = s.size();
	int poss = 15-k;
	for (auto c : s)
		if (c == 'o')
			++poss;
	if (poss >= 8) cout << "YES\n";
	else cout << "NO\n";
}

//  ---------------------Template---------------------------
void InputSetup()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
}

int main(void)
{
	auto start = chrono::high_resolution_clock::now();

	InputSetup();
	solve();

	auto finish = chrono::high_resolution_clock::now();
	cerr << "Time elapsed: " << (chrono::duration<long double>(finish-start)).count() << "s\n";
}
//  ---------------------Template---------------------------

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    string s, t;
    cin>>s>>t;
    vector<char> chara, chara2;
    rep(i, s.size()) chara.push_back(s[i]);
    sort(all(chara));
    rep(i, s.size()) s[i]=chara[i];
    rep(i, t.size()) chara2.push_back(t[i]);
    sort(all(chara2));
    rep(i, t.size()) t[t.size()-1-i]=chara2[i];
    //cout<<s<<sp<<t<<endl;
    bool same=true, ok=true;
    rep(i, min(s.size(), t.size())){
        if(s[i]!=t[i]) same=false;
        if(!same && s[i]>t[i]) ok=false;
        if(!same && ok) break;
    }
    if(same){
        if(s.size()<t.size()) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else{
        cout<<(ok ? "Yes": "No")<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
#include <deque>
#include <math.h>
#include <tgmath.h>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

//fast power
ll calc(ll a, ll b) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = calc(a, b / 2);
        return (d * d) % MOD;
    }
    else return (a * calc(a, b - 1)) % MOD;
}

//fast combination
ll comb(ll n, ll a) {
    ll b = 1, c = 1;
    for (ll i = 1; i <= a; ++i) {
        b = b * i % MOD;
        c = c * (n - i + 1) % MOD;
    }

    return c * calc(b, MOD - 2) % MOD;
}

ll comb2(ll a) {
    ll b = a / 2;
    if (a % 2) {
        b = (a - 1) / 2;
        return (b * a);
    }
    return (b * (a - 1));
}

int kyotsu(string ss, int st, int ed, string ss2) {
    int ans = 0;
    for (int i = st; i < ed; ++i) {
        if (i - st >= ss2.size()) return ans;
        if (ss[i] == ss2[i - st] || ss[i] == '?') {
            ans++;
        } else {
            return -1;
        }
    }
    return ans;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> x >> y >> a >> b >> c;
    vector<ll> aa(a);
    vector<ll> bb(b);

    priority_queue<ll> pqr;

    rep (i, 0, a) {
        cin >> d;
        aa[i] = d;
    }
    rep (i, 0, b) {
        cin >> d;
        bb[i] = d;
    }
    rep (i, 0, c) {
        cin >> d;
        pqr.push(d);
    }

    sort(aa.begin(), aa.end(), greater<ll>());
    sort(bb.begin(), bb.end(), greater<ll>());

    rep (i, 0, x) {
        pqr.push(aa[i]);
    }
    rep (i, 0, y) {
        pqr.push(bb[i]);
    }

    o = 0;
    rep (i, 0, x + y) {
        o += pqr.top();
        pqr.pop();
    }

    cout << o << endl;

    return 0;
}


Measured memory_bytes: 8048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;

int main()
{
    int n, k, x, y, ans = 0;
    cin >> n >> k >> x >> y;
    rep(i, n) {
        if (i+1 <= k) ans += x;
        else ans += y;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List
import           Data.Maybe

main = do
  [n, m, q] <- readInts <$> BS.getLine
  lines <- replicateM q BS.getLine
  let abcds = map (toABCD . readInts) lines
  print $ solve n m q abcds
  where
    readInts :: BS.ByteString -> [Int]
    readInts = unfoldr (BS.readInt . BS.dropWhile isSpace)
    toABCD :: [Int] -> ABCD
    toABCD [a, b, c, d] = (a, b, c, d)

solve :: Int -> Int -> Int -> [ABCD] -> Int
solve n m q abcds = maximum $ map (point abcds) seqACands
  where
    seqACands :: [SeqA]
    seqACands = gen 1 m n
      where
        gen :: Int -> Int -> Int -> [SeqA]
        gen low high 0 = map (: []) [low .. high]
        gen low high n = do
          aHead <- [low .. high]
          aTail <- gen aHead high $ n - 1
          return $ aHead : aTail

point :: [ABCD] -> SeqA -> Int
point abcds seqA = sum $ map (point seqA) abcds
  where
    point :: SeqA -> ABCD -> Int
    point seqA (a, b, c, d)
      | seqA !! (b - 1) - seqA !! (a - 1) == c = d
      | otherwise = 0

type SeqA = [Int]

type ABCD = (Int, Int, Int, Int)


Measured memory_bytes: 6624