akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
string S[51];

template<int NV,class V> class MinCostFlow {
public:
	struct edge { int to; V capacity; V cost; int reve;};
	vector<edge> E[NV]; int prev_v[NV], prev_e[NV]; V dist[NV];
	void add_edge(int x,int y, V cap, V cost) {
		E[x].push_back((edge){y,cap,cost,(int)E[y].size()});
		E[y].push_back((edge){x,0, -cost,(int)E[x].size()-1}); /* rev edge */
	}
	
	V mincost(int from, int to, ll flow) {
		V res=0; int i,v;
		ZERO(prev_v); ZERO(prev_e);
		while(flow>0) {
			fill(dist, dist+NV, numeric_limits<V>::max()/2);
			dist[from]=0;
			priority_queue<pair<V,int> > Q;
			Q.push(make_pair(0,from));
			while(Q.size()) {
				V d=-Q.top().first;
				int cur=Q.top().second;
				Q.pop();
				if(dist[cur]!=d) continue;
				if(d==numeric_limits<V>::max()/2) break;
				FOR(i,E[cur].size()) {
					edge &e=E[cur][i];
					if(e.capacity>0 && dist[e.to]>d+e.cost) {
						dist[e.to]=d+e.cost;
						prev_v[e.to]=cur;
						prev_e[e.to]=i;
						Q.push(make_pair(-dist[e.to],e.to));
					}
				}
			}
			
			if(dist[to]==numeric_limits<V>::max()/2) return -1;
			V lc=flow;
			for(v=to;v!=from;v=prev_v[v]) lc = min(lc, E[prev_v[v]][prev_e[v]].capacity);
			flow -= lc;
			res += lc*dist[to];
			for(v=to;v!=from;v=prev_v[v]) {
				edge &e=E[prev_v[v]][prev_e[v]];
				e.capacity -= lc;
				E[v][e.reve].capacity += lc;
			}
		}
		return res;
	}
};
MinCostFlow<5050,int> mcf;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	
	int sc=0,num=0;;
	FOR(y,H) {
		cin>>S[y];
		FOR(x,W) {
			if(S[y][x]=='o') {
				num++;
				sc+=(50-y)+(50-x);
				mcf.add_edge(2501,y*50+x,1,0);
			}
			if(S[y][x]!='#') {
				mcf.add_edge(y*50+x,2502,1,(50-y)+(50-x));
			}
			if(y&&S[y][x]!='#'&&S[y-1][x]!='#') mcf.add_edge((y-1)*50+x,y*50+x,10000,0);
			if(x&&S[y][x]!='#'&&S[y][x-1]!='#') mcf.add_edge(y*50+x-1,y*50+x,10000,0);
		}
	}
	
	int ret=mcf.mincost(2501,2502,num);
	cout<<sc-ret<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4180
#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>;

int main(){
  int n;
  cin>>n;
  string s;
  cin >>s;
  rep(i,s.size()){
    s[i]=(s[i]+'A'+n)%26+'A';
  }
  cout << s << endl;

return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main(){long long n,a,b,i,x=0,y=0,z=0,d;cin>>n>>a>>b;
  string s;
  cin>>s;d=a+b;
  for(i=0;i<n;i++){
      if(s[i]=='a'){
          x++;
          if(x<=d){
              z++;
              if(z<=d)
          cout<<"Yes"<<endl;
          else
          cout<<"No"<<endl;
          }
          else
          cout<<"No"<<endl;
      }if(s[i]=='c')
      cout<<"No"<<endl;
      if(s[i]=='b'){
          y++;
          if(y<=d&&y<=b){
z++;
          if(z<=d)
           cout<<"Yes"<<endl;
           else
           cout<<"No"<<endl;}
          else
          cout<<"No"<<endl;
      }
  }

  return 0;
  
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
const int mod=1e9+7;\
int dp[100005];
 int solve(int b[],int k,int n){
          if(k<0)
          return 1;
          
          if(k==0)
          return dp[k]=0;
         if(dp[k]!=-1)
          return dp[k];  
          
        int sum=1;
        for(int i=0; i<n; i++){
		 int t=solve(b,k-b[i],n);
		   sum=sum && t;
		}
		if(sum)
		return  dp[k]=0;
		return dp[k]=1;
        
}
int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
       int n,k;
         cin>>n>>k;
         memset(dp,-1,sizeof(dp));
        int b[n];
        for(int i=0; i<n; i++)
          cin>>b[i]; 
           
           if(solve(b,k,n))
             cout<<"First\n";
          else
             cout<<"Second\n";
             
    }


Measured memory_bytes: 8448
#coding:utf-8
n = int(input())
p = list(map(int, input().split()))

p_sort = sorted(p)
diff = 0

for i in range(n):
    if p[i] != p_sort[i]:
        diff += 1


#すでに昇順ソート済みだった場合
if p == p_sort:
    print("YES")
#一回入れ替えればOK
elif diff == 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
#define MODSIZE 1000000007
// priority_queue<int, vector<int>, greater<int> > PQ; // 昇順PQ
priority_queue<ll> pq;

int a[100006];
int b[100006];
int c[100006];

int main(){
  int n,t;
  int q;
  int i;
  int cnt[100006] = {0};
  ll sum = 0;

  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%d", &a[i]);
    cnt[a[i]]++;
    sum += a[i];
  }

  scanf("%d", &q);
  for(i = 0;i < q;i++){
    scanf("%d %d", &b[i], &c[i]);
    t = c[i] - b[i];
    sum += cnt[b[i]]*t;
    cnt[c[i]] += cnt[b[i]];
    cnt[b[i]] = 0;
    printf("%lld\n", sum);
  }

  return 0;  
}

Measured memory_bytes: 5340
n = gets.to_i
ans = 0
ary = Array.new(10){Array.new(10){0}}
1.upto(n) do |i|
    ary[(i.to_s[0]).to_i][(i.to_s[-1]).to_i] += 1
end
10.times do |i|
    10.times do |j|
        ans += ary[i][j]*ary[j][i]
    end
end
puts ans

Measured memory_bytes: 1788
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int n = nextInt();
		int[] A = nextIntArray(n);
		sc.close();
		int[] XorA = new int[n];
		XorA[0]=A[0];
		for(int i=0;i<n-1;i++)XorA[i+1] = XorA[i]^A[i+1];

		int INF = 20;
		long[] dp1 = new long[1<<INF];
		long[] dp0 = new long[1<<INF];
		long[] cnt = new long[1<<INF];
		Arrays.fill(dp0, 1);
		int zero=0;
		for (int i=0;i<n;i++) {
			if (XorA[i]==0) {
				zero++;
			} else {
				dp0[XorA[i]]+=dp1[XorA[i]]*(zero-cnt[XorA[i]]);
				dp1[XorA[i]]+=dp0[XorA[i]];
				dp0[XorA[i]]%=Mod;
				dp1[XorA[i]]%=Mod;

				cnt[XorA[i]]=zero;
			}
		}

		if (XorA[n-1]>0) {
			out.println(dp0[XorA[n-1]]);
		} else {
			long sum = 1;
			for (int i=0;i<zero-1;i++) {
				sum*=2;
				sum-=sum<Mod?0:Mod;
			}
			for (int i=0;i<(1<<INF);i++) {
				sum+=dp1[i];
				sum%=Mod;
			}
			out.println(sum);
		}
	}
	@SuppressWarnings("unused")
	private int min(int a, int b) {
		return Math.min(a, b);
	}
	private static int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	private static int nextInt() {
		return Integer.parseInt(next());
	}
	@SuppressWarnings("unused")
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16>>(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int R, C;
    while (cin >> R >> C, R || C) {
        vector<vector<int>> grid(R, vector<int>(C));
        rep(r, R) rep(c, C) cin >> grid[r][c];

        int ans = 0;
        for (int i=0; i<(1<<R); i++) {
            // cerr << "i = " << BINARY(i) << endl;

            vector<vector<int>> tgrid = grid;
            vector<int> num(C);

            rep(r, R) {
                if (i>>r & 1) {
                    // ?£???????
                    rep(c, C) {
                        tgrid[r][c] = 1 - tgrid[r][c];
                    }
                }
                rep(c, C) num[c] += tgrid[r][c];
            }

            int tmp = 0;
            rep(c, C) {
                tmp += max(num[c], R - num[c]);
            }
            ans = max(ans, tmp);

            // cerr << tmp << endl;
        }
        
        cout << ans << endl;
    }
}

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

int main() {
  int x;cin>>x;
  for(int i=1;i<=x;i++){
    if(360*i%x==0){
      cout<<360*i/x<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3624
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int N;
	cin >> N;
	vi H(N);
	REP(i, N) {
		cin >> H[i];
	}


	int ans = 0, M = -1;
	REP(i, N) {
		if (M <= H[i]) {
			ans++;
			M = max(M, H[i]);
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io;

fn main() {
    let sin = io::stdin();
    let mut buf = String::new();
    sin.read_line(&mut buf).ok();

    let s = buf.chars()
        .map(|c| {
            if c.is_lowercase() {
                c.to_uppercase().to_string()
            } else if c.is_uppercase() {
                c.to_lowercase().to_string()
            } else {
                c.to_string()
            }
        })
        .collect::<Vec<String>>()
        .join("");
    print!("{}", s);
}



Measured memory_bytes: 5072
N,K=map(int,input().split())
td=[]
for i in range(N):
    t,d=map(int,input().split())
    td.append([t,d])
td.sort(key=lambda x:x[1],reverse=True)
A=td[:K]
B=[]
s2=set()
for i,j in td[K:]:
    if not(i in s2):
        s2.add(i)
        B.append([i,j])
s1=set()
n=0
C=[]
sum=0
for i,j in A:
    if not(i in s1):
        s1.add(i)
        n+=1
        sum+=j
    else:
        C.append([i,j])
        sum+=j
sum+=n**2
B.reverse()
D=[]
for i,j in B:
    if not(i in s1):
        D.append([i,j])
list=[sum]

while(C):
    if D:
        i,j=D.pop()
        list.append(list[-1]+2*n+1+(j-C[-1][1]))
        n+=1
    C.pop()
print(max(list))


Measured memory_bytes: 78296
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	char c[1000000];
	cin >>n;
	int w=0;
	for(int i=1;i<=n;i++){
		cin >>c[i];
		if(c[i]=='W')
			w++;
	}
	int ans=w;
	for(int i=n;i>n-w;i--)
		if(c[i]=='W')
			ans--;
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 3820
/****************************************
/ AUTHOR : ROHAN BAIJAL                  /  
/ ALIAS : rohanblueboybaijal             /
/ INSTITUTE : IIT KANPUR                 /
*****************************************/
//              TEMPLATE                //

#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define PB push_back
#define ll long long int
#define F first
#define S second
#define MAX(x,y) (x)>(y)?(x):(y)
#define MIN(x,y) (x)<(y)?(x):(y)
#define REP(i,a,n) for(i=a;i<(n);i+=1)
#define REPL(i,a,n) for(i=a;i<=(n); i+=1)
#define REPr(i,n) for(i=n-1;i>=0;i-=1)

typedef vector<ll> vll;
typedef set<int>::iterator sit;
typedef unordered_set<int>::iterator usit;
typedef multiset<int>::iterator msit;
typedef unordered_multiset<int>::iterator umsit;
typedef vector<ll>::iterator vllit;

//cin.ignore(numeric_limits<streamsize>::max(),'\n');


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, x, t;
    cin>>n>>x>>t;
    ll ans = n/x;
    ans  += n%x ? 1 : 0;
    cout<<ans*t<<endl;
    return 0;
}

Measured memory_bytes: 3620
import sys
# from collections import Counter, deque
# from collections import defaultdict
# from itertools import combinations, permutations, accumulate, groupby, product
# from bisect import bisect_left,bisect_right
# from heapq import heapify, heappop, heappush
# from math import floor, ceil,pi,factorial
# from operator import itemgetter
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9 + 7


n = int(input())
def f(n): return n*(n+1)//2
ans = 0
for i in range(1,n+1):
    x=n//i
    ans+=i*f(x)

print(ans)


Measured memory_bytes: 9080
#include<stdio.h>
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define max 31
typedef long long ll;
int main(void){
    int n,m;
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        //dp[i番目の人][j日]の地図(bit)
        ll dp[51][max]={0};
        int is_ok[51][max]={0};
        int f;
        rep(i,n){
            scanf("%d",&m);
            rep(j,m){
                scanf("%d",&f);
                is_ok[i][f]=1;
            }
        }
        rep(i,n) dp[i][0]|=1LL<<i;
        const ll comp=(1LL<<n)-1;
        int ans=-1;
        for(int j=1;j<max;j++){
            for(int i=0;i<n;i++){
                if(is_ok[i][j]){
                    for(int k=0;k<n;k++){
                        if(is_ok[k][j])
                        dp[i][j]|=dp[k][j-1];
                    }
                }else{
                    dp[i][j]=dp[i][j-1];
                }
                if(dp[i][j]==comp){ans=j; break;}
            }
            if(ans!=-1) break;
        }
        printf("%d\n",ans);
    }
}



Measured memory_bytes: 2036
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {

            //string line = Console.ReadLine();
            

            for (int i = 0; ; i++) {
                string line = Console.ReadLine();

                int n = int.Parse(line);
                if (n == 0) { break; }

                n_to_printAns(n);
            }
            //Console.WriteLine();




        }




        static void n_to_printAns( int n ) {
            for (int i = 0; i < n; i++) {
                int num = n - i;
                nPriAux(num + "", i, num);
            }
        }

        static void nPriAux(string lin, int rem, int lastN) {
            if (rem == 0) {
                Console.WriteLine(lin);
                return;
            }


            for (int i_nexPostPone = 0; i_nexPostPone < rem; i_nexPostPone++) {

                int putN = rem - i_nexPostPone;
                if (putN > lastN) { continue; }
                nPriAux(lin + " " + putN, i_nexPostPone, putN);
                

            }


        }


    }
}



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

using namespace std;

int main()
{
    set<int> s;

    int a, b, k;
    cin >> a >> b >> k;


    if ((b - a) - 1 < k)
        for (int i = a; i <= b; i++)
            cout << i << endl;
    else
    {
        for (int i = a; i < a + k; i++)
            s.insert(i);
        for (int i = b - k + 1; i <= b; i++)
            s.insert(i);

        for (int x : s)
            cout << x << endl;
    }


}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scan s = new Scan();
        int A = s.nI();
        int B = s.nI();
        int[] N = new int[2];
        int res = -1;
        for(int i=0;i<2000;i++){
            N[0] = (int)Math.floor(i * 0.08);
            N[1] = (int)Math.floor(i * 0.10);
            if(A == N[0] && B == N[1]){
                res = i;
                break;
            }
        }
        System.out.println(res);
    }
    
    static class Scan{
        private static Scanner sc = new Scanner(System.in);
        public static int nI(){
            return Integer.parseInt(sc.next());
        }
        public static long nL(){
            return Long.parseLong(sc.next());
        }
        public static String nS(){
            return sc.next();
        }
        public static double nD(){
            return Double.parseDouble(sc.next());
        }
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int a,b;cin>>a>>b;
	string aa="",bb="";
	char aaa=a+'0';
	char bbb=b+'0';
	for(int i=1;i<=a;i++)aa+=bbb;
	for(int i=1;i<=b;i++)bb+=aaa;
	cout<<min(aa,bb)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;

long long a,b,c,d=1,e;
string ss;
int main(){
    cin>>a>>b>>c;
    if (c-b>=2){
        d+=min(a,b-1);
        a-=(d-1);
        if (a<2){
            cout<<d+a<<endl;
        }
        else{
            cout<<(a/2)*(c-b)+(a%2)+d<<endl;
        }
    }
    else{
        cout<<a+1<<endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;

namespace AtCoder.ABC
{
	class QuestionB
	{
		public static Dictionary<NCR, long> NcrDict = new Dictionary<NCR, long>();

		public static void Main(string[] args)
		{
			var np = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
			var n = np[0];
			var p = np[1];

			var a = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
			
			var kisuuCount = 0;

			for (int i = 0; i < n; i++) {
				if(a[i] % 2 == 1) {
					kisuuCount++;
				}
			}
			/*
			var guusuuCount = n - kisuuCount;

			var sumGuusuu = 0L;

			for(int i = 0; i <= guusuuCount; i++) {
				sumGuusuu += nCr(guusuuCount, i);
			}

			var sumKisuu = 0L;

			for (int i = 0; i <= kisuuCount; i += 2) {
				sumKisuu += nCr(kisuuCount, i);
			}

			if(p == 1 && kisuuCount == 0) {
				sumKisuu = 0;
			}
			
			Console.WriteLine(sumKisuu * sumGuusuu);
			*/
			{
				var ruijou = 1L;

				if (p == 1 && kisuuCount == 0) {
					ruijou = 0;
				}

				var max = kisuuCount == 0 ? n : n - 1;

				for (int i = 0; i < max; i++) {
					ruijou *= 2;
				}


				Console.WriteLine(ruijou);
			}
		}

		public class NCR
		{
			public int n;
			public int r;

			public NCR(int nn, int rr)
			{
				n = nn;
				r = rr;
			}

			public override int GetHashCode()
			{
				return n.GetHashCode() + r.GetHashCode() * 117;
			}

			public override bool Equals(object obj)
			{
				if(obj is null) {
					return false;
				}

				if(obj is NCR ncr) {
					return this.n == ncr.n && this.r == ncr.r;
				}

				return false;
			}
		}

		public static long nCr(int n, int r)
		{
			if(n < r) {
				throw new Exception();
			}

			r = Math.Min(r, n - r);

			var cr = new NCR(n, r);

			if (NcrDict.ContainsKey(cr)){
				return NcrDict[cr];
			}

			if (r == 1) {
				return n;
			} else if (r == 0) {
				return 1;
			}

			var temp = nCr(n - 1, r) + nCr(n - 1, r - 1);

			NcrDict.Add(cr, temp);

			return temp;
		}
	}
}


Measured memory_bytes: 28276
require 'set'
loop {
    n, m = gets.split.map &:to_i
    break if n == 0
    infected = Set[1]
    com = (1..m).map { gets.split.map &:to_i}.sort
    com.each{|_, i, j|
        if infected.include?(i)
            infected << j
        end
    }
    p infected.size
}

Measured memory_bytes: 9264
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>c>>a;
	a+=c*60;
	cin>>c>>b;
	b+=c*60;
	cin>>c;
	cout<<b-a-c<<endl;
}

Measured memory_bytes: 3632
import java.util.*;
import java.lang.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        String card1, card2;
        int taro = 0, hanako = 0;
        
        for (int i = 0; i < n; i++) {
            card1 = sc.next();
            card2 = sc.next();
            int result = card1.compareTo(card2);
            if (result > 0) taro += 3;
            else if (result < 0) hanako += 3;
            else {
                taro++;
                hanako++;
            }
        }
        System.out.println(taro + " " + hanako);
    }
}


Measured memory_bytes: 30600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())

ll choose(ll a) { //aC2
	return (a - 1) * a / 2;
}
int main() {
	ll n;
  	cin>>n;
  
  	vector<string> s(n);
 	rep (i,n)cin>>s[i];
  	rep (i,n)SORT(s[i]);
  	SORT(s);
  
  	vector <ll> cnt(n,1);
	ll sum=0;
  	ll j=0;
  
  	rep(i,n-1){
    	if(s[i]==s[i+1])
          cnt[j]++;
      	else j++;
    }
	j++;
  	rep(i,j)sum+=choose(cnt[i]);
  	cout<<sum<<endl;
  
}

Measured memory_bytes: 7156
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
using namespace std;
namespace io{
	const int Sz=1<<13;
	char ibuf[Sz],*ips=ibuf+Sz-1;
	inline int getchar(){
		if(++ips==ibuf+Sz)fread(ips=ibuf,1,Sz,stdin);
		return *ips;
	}
	char obuf[Sz],*ops=obuf;
	inline void flush(){
		fwrite(obuf,1,ops-obuf,stdout);
		ops=obuf;fflush(stdout);
	}
	inline void putchar(int c){
		if(ops==obuf+Sz)flush();
		*ops=c,ops++;
	}
	void gets(char *s){
		int c=getchar();
		while(c<=32)c=getchar();
		while(c>32)*s=c,++s,c=getchar();
		*s=0;
	}
	void puts(const char *s){
		while(*s)putchar(*s),++s;
	}
}
#define getchar io::getchar
#define putchar io::putchar
#define gets io::gets
#define puts io::puts
int read(){
	int x=0,f=1,c=getchar();
	for(;c<48||c>57;c=getchar())
		if(c=='-')f=-f;
	for(;c>=48&&c<=57;c=getchar())
		x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
void write(ll x){
	int stk[20],tp=0;
	if(!x)putchar(48);
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)stk[tp++]=(x-x/10*10)^48;
	for(;tp;)putchar(stk[--tp]);
}
struct Flusher{~Flusher(){io::flush();}}flusher;
// ------------------------- Template End ------------------------- //
const int N=5005;
int n,A,B;
int p[N],ps[N];
ll dp[N][N],mndp[N][N];
const ll inf=0x3f3f3f3f3f3f3f3f;
void chkmin(ll &x,ll y){if(y<x)x=y;}
int main(){
	n=read(),A=read(),B=read();
	for(int i=0;i<n;++i)p[i]=read(),ps[p[i]]=i;
	memset(dp,0x3f,sizeof dp);dp[0][0]=0;
	memset(mndp,0x3f,sizeof mndp);
	for(int i=0;i<=n;++i)mndp[0][i]=0;
	for(int i=1;i<=n;++i)for(int j=0;j<=n;++j){
		chkmin(dp[i][j],mndp[i-1][j]+(ps[i]==j?0:(ps[i]<j?A:B)));
		if(j)mndp[i][j]=mndp[i][j-1];chkmin(mndp[i][j],dp[i][j]);
	}
	write(mndp[n][n]);putchar('\n');
	return 0;
}



Measured memory_bytes: 391808
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  string s, t;
  cin >> s;
  cin >> t;
  int n=s.size(), ans=0;
  rep(i, n){
    if(s[i]!=t[i]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

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

llint T;
llint n;
vector<llint> G[55], G2[55];
llint par[55], par2[55];

void dfs(int v, int p, vector<llint> G[], llint par[])
{
	par[v] = p;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		dfs(G[v][i], v, G, par);
	}
}

bool dfs2(int v, int p, bool flag)
{
	if(par[v] == par2[v] && flag) return false;
	
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		if(!dfs2(G[v][i], v, flag || (par[v] != par2[v]))) return false;
	}
	return true;
}

vector<llint> g[55];
vector<int> topo;
bool used[55];

void tpsort(int v)
{
	used[v] = true;
	for(int i = 0; i < g[v].size(); i++){
		if(!used[g[v][i]]) tpsort(g[v][i]);
	}
	topo.push_back(v);
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> T;
	for(int t = 0; t < T; t++){
		cin >> n;
		for(int i = 1; i <= n; i++) G[i].clear(), G2[i].clear();
		
		llint u, v;
		for(int i = 0; i < n-1; i++){
			cin >> u >> v;
			G[u].push_back(v);
			G[v].push_back(u);
		}
		for(int i = 0; i < n-1; i++){
			cin >> u >> v;
			G2[u].push_back(v);
			G2[v].push_back(u);
		}
		
		llint ans = inf;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				
				llint v;
				if(i != j){
					if(G[i].size() > 1) continue;
					v = G[i][0];
					if(v == j) continue;
					G[i].pop_back();
					G[i].push_back(j);
					G[j].push_back(i);
					for(int k = 0; k < G[v].size(); k++){
						if(G[v][k] == i){
							G[v].erase(G[v].begin()+k);
							break;
						}
					}
				}
				dfs(i, 0, G, par);
				dfs(i, 0, G2, par2);
				
				llint cnt = 0;
				for(int k = 1; k <= n; k++){
					if(par[k] != par2[k]) cnt++;
				}
				
				for(int k = 1; k <= n; k++) g[k].clear();
				for(int k = 1; k <= n; k++){
					if(par[k] == par2[k]) continue;
					if(par[par[k]] != par2[par[k]]) g[k].push_back(par[k]);
					if(par[par2[k]] != par2[par2[k]]) g[par2[k]].push_back(k);
				}
				
				topo.clear();
				for(int k = 1; k <= n; k++) used[k] = false;
				for(int k = 1; k <= n; k++) if(!used[k]) tpsort(k);
				reverse(topo.begin(), topo.end());
				
				bool flag = true;
				for(int k = 1; k <= n; k++) used[k] = false;
				for(int k = 0; k < topo.size(); k++){
					int v = topo[k];
					used[v] = true;
					for(int l = 0; l < g[v].size(); l++){
						if(used[g[v][l]]) flag = false;
					}
				}
				
				flag &= dfs2(i, 0, false);
				
				if(i != j){
					G[j].pop_back();
					G[i].pop_back();
					G[i].push_back(v);
					G[v].push_back(i);
					cnt++;
				}
				
				if(flag) ans = min(ans, cnt);
			}
		}
		
		if(ans > inf/2) ans = -1;
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    string s; cin >> s;
    stack<char> stk;
    rep(i,s.length()) {
        if (s[i] == 'B') {
            if (stk.size() != 0)
                stk.pop();
        } else {
            stk.push(s[i]);
        }
    }

    vector<char> ans;
    while (stk.size()) {
        ans.push_back(stk.top());
        stk.pop();
    }
    reverse(ans.begin(), ans.end());
    rep(i,ans.size()) {
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3640
//============================================================================
// Name        : TopCoderCompetition.cpp
// Author      : taguchi
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <bitset>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <numeric>
#include <list>
#include <sstream>
using namespace std;
//#define P pair<int,int>
//#define max 999999
typedef unsigned int uint;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(ull i = 0;i<n;i++)
#define pb(n) push_back(n)
#define clear(n) memset(n,0,sizeof(n))

typedef vector<int> vi;
typedef vector<string> vs;
struct edge{int cost,to;};

vector<string> split(string &in,char delimiter){
	vector<string> re; uint cur = 0,next;
	while((next = in.find_first_of(delimiter,cur)) != string::npos){
		re.pb(string(in,cur,next-cur));
		cur = next + 1;
	}
	re.pb(string(in,cur,in.size()-cur));
	return re;
}
vector<int> split_int(string &in, char delimiter){
	vector<string> str = split(in,delimiter);
	vector<int> re;
	rep(i,str.size()){
		re.pb(strtol(str[i].c_str(),NULL,10));
	}
	return re;
}

class Range{
public:
	int a,b;
	Range(int an,int bn) : a(an),b(bn){}

	bool operator()(int n){
		return a<=n&&n<=b;
	}
	bool isCross(Range x){
		return x(a) || x(b);
	}
	bool contains(Range x){
		return this->a <= x.a && x.b <= this->b;
	}
};

bool isnprime[1000010];
uint indexpri[100100];
int main(){
	int cnt = 0;
	for(int i = 2;i<1000010;i++){
		if(!isnprime[i]){
			indexpri[cnt++] = i;
			for(int j = 2;i*j<1000010;j++){
				isnprime[i*j] = true;
			}
		}
	}
	isnprime[0] = true;isnprime[1] = true;
	while(1){
		int a,d,n,result = 0;
		cin >> a >> d >> n;
		if(a+d+n == 0)break;
		uint cnt = 1;
		for(int k = 0;a+d*k<1000000;k++){
			if(!isnprime[a+d*k]){
				if(cnt == n) {
					result = a+d*k;
					break;
				}
				else{
					cnt++;
				}
			}
		}
		cout << result << endl;
	}

	return 0;
}

Measured memory_bytes: 0
inputArray = Array.new
rows = gets.to_i
i = 0
rows.times do
  temp = gets
  inputArray[i], inputArray[i+1], inputArray[i+2] = temp.split(" ").map(&:to_i)
  i += 3
end
i = 0
inputArray.map!{|n| n ** 2}
test = Array.new
rows.times do
  test = [inputArray[i], inputArray[i+1], inputArray[i+2]]
  test.sort!
  if test[0] + test[1] == test[2]
    puts "YES"
  else
    puts "NO"
  end
  i += 3
end

Measured memory_bytes: 8788
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 100005
using namespace std;
ll a[N+3],seg[4*N+3];
int main(){
    string s;
    cin>>s;
    cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e4 + 3;
const int MAXS = (int)107;
const int infint = (int)1e9;
const ll inf = (ll)1e18;
int get(int x)
{
	if(x < 10)
		return x;
	else
		return get(x / 10) + (x % 10);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int mn = infint;
	for (int i = 1; i < n; i++)
		mn = min(mn, get(i) + get(n - i));
	cout << mn;
}

Measured memory_bytes: 256
import fractions
import functools
N,X = list(map(int, input().split()))
x = list(map(int, input().split()))
diff_list = []

for i in range(N):
    diff_list.append(max(x[i], X) - min(x[i], X))
gcd = functools.reduce(fractions.gcd, diff_list)
print(gcd)


Measured memory_bytes: 16240
#include<stdio.h>
#include<string.h>
int main(){
    int N,L,i,j;
    char a[101][101],b[101];   //b要设置成字符串
    scanf("%d%d",&N,&L);
    for(i=0;i<N;i++){
        scanf("%s",a[i]);
    }
   for(i=0;i<N-1;i++){
        for(j=i+1;j<N;j++){
            if(strcmp(a[i],a[j])>0){      //头文件
                strcpy(b,a[i]);
                strcpy(a[i],a[j]);
                strcpy(a[j],b);
            }
        }
    }

    for(i=0;i<N;i++){
        printf("%s",a[i]);
    }
return 0;
}

Measured memory_bytes: 128
lists=list(map(int,input().split()))
n=lists[0]
k=lists[1]
beforeSort = [[0]*2]*n
for i in range(n):
  getNum=list(map(int,input().split()))
  beforeSort[i]=getNum
afterSort=sorted(beforeSort)
for i in range(n):
  k=k-afterSort[i][1]
  if k<=0:
  	print(afterSort[i][0])
  	break

Measured memory_bytes: 28640
import math
a,b,c = map(int,input().split())
s = input()
g = 1
d = b+c
k = 1
for i in range(a):
    if s[i]=='c':
        print("No")
    elif s[i] == 'a' and k<=d:
        print("Yes")
        k+=1
    elif s[i] == 'b' and g<=c and k<=d:
        print("Yes")
        k+=1
        g += 1
    else:
        print("No")


Measured memory_bytes: 70540
N, Y = map(int, input().split())
for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - x - y
        if 0 <= z <= 2000 and 10000 * x+5000 * y+1000 * z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)


Measured memory_bytes: 2940
import numpy as np
from itertools import accumulate
MOD = 10**9+7
n = int(input())
S = input()
dp = np.ones(n, dtype=np.int64)
for s in S:
  if s == "<":
    dp = np.cumsum(dp[::-1][:-1])[::-1]%MOD
  else:
    dp = np.cumsum(dp[:-1])%MOD
ans = dp[0]
print(ans)

Measured memory_bytes: 12504
#include <stdio.h>

int main(void){

  int i, j;
  int H, W;

  while(1){

  scanf("%d %d", &H, &W);
  if(H == 0 && W == 0){break;}
  else if(H > 300 || W > 300){break;}
  else

    for(j = 0; j < H; j++){ 

      for(i = 0; i < W; i++){    printf ("#");}
      printf("\n");
 
    }

  printf("\n");

  }

  return 0;

}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  ll n, q, k;
  cin >> n;
  vector<ll> a(n, 0);
  map<ll, ll> m;
  ll sum = 0;
  rep(i, n) {
    cin >> k;
    auto itr = m.find(k);
    if (itr != m.end()) {
      (itr->second)++;
    } else {
      m.insert(make_pair(k, 1));
    }
    sum += k;
  }
  cin >> q;
  rep(i, q) {
    ll b, c;
    cin >> b >> c;
    sum += m[b] * (c - b);
    cout << sum << endl;
    m[c] += m[b];
    m[b] = 0;
  }
  return 0;
}


Measured memory_bytes: 10044
import numpy as np

N = int(input())
mod = 10**9 + 7
A = np.array(input().split(), dtype=np.int64)
# print(A)

ans = 0
for i in range(60):
    b = np.count_nonzero(A >> i & 1)
    ans += 2**i*(b*(N-b))
    ans %= mod
    # c = np.count_nonzero(A >> i)
    # print(c)
print(ans)


Measured memory_bytes: 62752
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
int n, m, a,b;
set<int> adj[(int)1e5+5];
 
void sol(){
    queue<int> q;
    q.push(1);
    vector<int> signpost((int)1e5+5, 1e9);
 
    while(!q.empty()){
        int here = q.front(); q.pop();
        for(auto there : adj[here]){
            if(signpost[there] == 1e9){
                signpost[there] = here;
                q.push(there);
            }
        }
    }
    cout << "Yes\n";
    for(int i = 2; i <= n ; ++i){
        cout << signpost[i] << "\n";
    }
}
 
int main(){
    cin >> n >> m;
    while(m--){
       cin >> a >> b;
       adj[a].emplace(b);
       adj[b].emplace(a);
    }
    sol();
    return 0;
}


Measured memory_bytes: 27516
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ans = -1
for i in range(2**n):
    li = [0]*(m+1)
    # print('＝＝＝＝＝＝＝＝＝＝')
    for j in range(n):
        # print('i = ', i)
        # print('j = ', j)
        # print('(i >> j) = ', (i >> j))
        # print('((i >> j) & 1) = ', ((i >> j) & 1))
        if ((i >> j) & 1):
            for k in range(m+1):
                li[k] += ca[j][k]
        # print('li = ', li)
    for j in range(1, m+1):
        if li[j] < x:
            break
    else:
        if ans == -1:
            ans = li[0]
        else:
            if ans > li[0]:
                ans = li[0]
print(ans)


Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, A, B, C, D);
  print(max(min(B, D) - max(A, C), 0));
}


Measured memory_bytes: 256
#include<cstdio>
const int N=20+10;
int a[N],n,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=2;i<n;i++)
		ans+=(a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]<a[i-1]&&a[i]>a[i+1]);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 128
N=int(input())
S = {}
for i in range(N):
    let = input()
    try:
        S[let] += 1
    except:
        S[let] = 1
max_val = max(S.values())
answers = []
for k,v in S.items():
    if v == max_val:
        answers.append(k)
answers.sort()
for ans in answers:
    print(ans)

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




int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
    }
    double ave = std::accumulate(a.begin(),a.end(),0.0) / n;
    int aa = std::round(ave);

    int cnt = 0;
    for(int i = 0; i < n; i++){
        cnt += (aa - a[i]) * (aa - a[i]);
    }
    std::cout << cnt << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
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 counter[5];
int main() {
    int N;
    cin >> N;
    rep(i, N){
        string name;
        cin >> name;
        if(name[0] == 'M') counter[0] += 1;
        if(name[0] == 'A') counter[1] += 1;
        if(name[0] == 'R') counter[2] += 1;
        if(name[0] == 'C') counter[3] += 1;
        if(name[0] == 'H') counter[4] += 1;
    }
    ll ans = 0;
    rep(i, 5){
        for(int j=i+1; j < 5; j++){
            for(int k=j+1; k < 5; k++){
                ans += counter[i]*counter[j]*counter[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int x, y;
    cin >> x >> y;
    vector<set<int>> v = {{1, 3, 5, 7, 8, 10, 12}, {4, 6, 9, 11}, {2}};
    int x_index, y_index;
    rep(i, 3) {
        if (v[i].count(x)) {
            x_index = i;
        }
    }
    rep(i, 3) {
        if (v[i].count(y)) {
            y_index = i;
        }
    }

    if (x_index == y_index) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
from sys import stdin

def Base_10_to_n(X, n):
    if X == 26:
        return "z"
    alpha = "zabcdefghijklmnopqrstuvwxy"
    X_dumy = X
    out = ''
    while X_dumy>0:
        amari = X_dumy%n
        if amari == 0:
            new = alpha[amari]
            out = new+out
            X_dumy = int(X_dumy/n)-1
        else:
            new = alpha[X_dumy%n]
            out = new+out
            X_dumy = int(X_dumy/n)
    return out

def main():
    n = int(input())
    x16_expr = Base_10_to_n(n, 26)
    print(x16_expr)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9224
def main(S):
    listdreamereraser = ['dreamer','eraser','dream','erase']
    while True:
        for i in listdreamereraser:
            if i == S[-len(i):]:
                S = S[:-len(i)]
                break
        else:
            return False
        if len(S) == 0:
            return True

S = input()
print('YES' if main(S) else 'NO')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int main() {
    
    int k;
    cin >> k;
    int a,b;
    cin >> a >> b;

    for(int i = a;i<b+1;i++) {
        if(i%k == 0) {
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    
 return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
int main(){
  int a,b,A[1000],B[1000],c;
  scanf("%d %d",&a,&b);
  if(b>a){
    c=a;
    a=b;
    b=c;
  }
  while(1){
    c=a%b;
    if(c==0)break;
    a=b;
    b=c;
  }
  printf("%d\n",b);
}



Measured memory_bytes: 2752
#include <stdio.h>

int main(void) {
    int a, b, c, d;
    
    scanf("%d %d %d %d", &a, &b, &c, &d);

    if (a + b == c + d) {
        puts("Balanced");
    } else {
        puts((a + b > c + d) ? "Left" : "Right");
    }
    
    return 0;
}

Measured memory_bytes: 128
import Control.Monad
import Data.List
    
readInt :: String -> Int
readInt = read

hale_punching :: Maybe Int -> [Int] -> [Int]
hale_punching (Just z) xs = take z xs ++ [0] ++ drop (z+1) xs
hale_punching Nothing xs = xs
                       
check_card:: [Int] -> [Int] -> [Int]
check_card xs [] = xs
check_card xs (y:ys) = check_card (hale_punching z xs) ys
    where
      z = elemIndex y xs

check_bingo :: [Int] -> Bool
check_bingo xs
            |sum xs == 0 = True
            |otherwise = False
                         
check_result :: [Int] -> String
check_result xs
             | result == True = "Yes"
             | otherwise = "No"
                     where          
                       cl1 = check_bingo [xs !! 0 ,xs !! 1 , xs !! 2]
                       cl2 = check_bingo [xs !! 3 , xs !! 4 , xs !! 5]
                       cl3 = check_bingo [xs !! 6 , xs !! 7 , xs !! 8]
                       rw1 = check_bingo [xs !! 0 , xs !! 3 , xs !! 6]
                       rw2 = check_bingo [xs !! 1 , xs !! 4 , xs !! 7]
                       rw3 = check_bingo [xs !! 2 , xs !! 5 , xs !! 8]
                       cr1 = check_bingo [xs !! 0 , xs !! 4 , xs !! 8]
                       cr2 = check_bingo [xs !! 2 , xs !! 4 , xs !! 6]
                       result = cl1 || cl2 || cl3 || rw1 || rw2 || rw3 || cr1 || cr2  

bingo :: [Int] -> [Int] -> String
bingo xs ys = check_result (check_card xs ys)
    
main :: IO ()
main  = do
  a1 <- (map readInt . words) <$> getLine
  a2 <- (map readInt . words) <$> getLine
  a3 <- (map readInt . words) <$> getLine
  n  <- readInt <$> getLine
  b  <- replicateM n $ readInt <$> getLine
  let a = a1 ++ a2 ++ a3
  putStrLn $bingo a b

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
inline long long read()
{
    long long x=0,k=1; char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') k=-1;c=getchar();}
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*k;
}
long long n,m,s;
int main(void)
{
	n=read(),m=read();
	printf("%lld",min(n,m/2)+max(m-n*2,s)/4);
}

Measured memory_bytes: 256
import java.util.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      int h;
      int w;
      int i,j;
         
      while(true){
         str = sc.nextLine();
         arr = str.split(" ");
         h = Integer.parseInt(arr[0]);
         w = Integer.parseInt(arr[1]);
         
         if(h == 0 && w == 0){
            break;
         }
         
         
         for(i = 0; i < h; i ++ ){
            for(j = 0; j < w; j ++){
               System.out.print("#");
            }
            System.out.println();
         }
         System.out.println();
      
      }    
   }//main method 
}//class

Measured memory_bytes: 34808