akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(void){
    int m, f, r;
    while(1){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1) break;
        if(m==-1||f==-1) cout<< 'F' << endl;
        else if(m+f>=80) cout << 'A' << endl;
        else if(m+f>=65) cout << 'B' << endl;
        else if(m+f>=50) cout << 'C' << endl;
        else if(m+f>=30){
            if(r>=50) cout << 'C' << endl;
            else cout << 'D' << endl;
        }
        else cout << 'F' << endl;
    }
    return 0;
}

Measured memory_bytes: 3104
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int x[111111];
int y[111111];
int main(void){
  int i,n,m;
  int a,b;
  int res;
  cin>>n;
  res=m=0;
  for(i=1;i<=n;i++){
    cin>>a>>b;
    x[a]++;
    x[b+1]--;
    m=max(m,max(a,b));
  }
  m++;
  for(i=1;i<=m;i++){
    y[i]=x[i]+y[i-1];
    if(y[i]+1>=i) res=max(res,i);
  }
  /*
  for(i=1;i<=m;i++){
    cout<<x[i]<<" ";
  }
  cout<<endl;
  for(i=1;i<=m;i++){
    cout<<y[i]<<" ";
  }
  cout<<endl;
  */
  //if(res==0) cout<<0<<endl;
  cout<<res-1<<endl;
  return 0;
}

Measured memory_bytes: 3872
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
const long long lim=1000000,mod=998244353,inv2=(mod+1)/2;
long long n,m,i,j,f[1000005],g[1000005],s[1000005],c[1000005],ans;
long long qp(long long x,long long y)
{
	long long z=1;
	while(y){
		if(y&1){
			z=1ll*z*x%mod;
		}
		x=1ll*x*x%mod;
		y/=2;
	}
	return z;
}
int main()
{
	scanf("%lld",&n);
	fz1(i,n){
		long long x;
		scanf("%lld",&x);
		inc(c[x],x)
		dec(ans,x)
	}
	f[1]=1;
	fz1(i,lim){
		for(j=i+i;j<=lim;j+=i){
			dec(f[j],f[i])
		}
	}
	fz1(i,lim){
		g[i]=qp(i,mod-2);
	}
	fz1(i,lim){
		for(j=1;i*j<=lim;j++){
			inc(s[i*j],1ll*f[i]*g[j]%mod);
		}
	}
	fz1(i,lim){
		for(j=2;i*j<=lim;j++){
			inc(c[i],c[i*j])
		}
	}
	fz1(i,lim){
		inc(ans,1ll*c[i]*c[i]%mod*s[i]%mod)
	}
	cout<<ans*inv2%mod<<endl;
	return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    string S;
    cin >> S;
    int flag=-1;
    int cnt=0;
    int N=S.size();
    for(int i=0; i<N; i++){
        int x=int(S[i]);
        if(flag!=-1 && flag!=x){
            cnt--;
            flag=1^x;
        }else{
            flag=x;
            cnt++;
        }
        if(cnt==0)flag=-1;
    }
    cout << N-cnt << endl;
}

Measured memory_bytes: 512
A,B,C = map(int,input().split()) #A赤＜B緑＜C青，
K = int(input())

while A >= B and K >= 1:
  B *= 2
  K -= 1

while B >= C and K >= 1:
  C *= 2
  K -= 1
  #print(K,C)

if A < B and B < C:
  print("Yes")

else:
  print("No")

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
const int MAX_NM = 2000;

ll dp[MAX_NM + 5][MAX_NM + 5];
ll sum[MAX_NM + 5][MAX_NM + 5];

int main() {
    int n, m;
    cin >> n >> m;
    int s[n], t[m];
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < m; i++) cin >> t[i];
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = sum[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = 0;
            }
            dp[i + 1][j + 1] %= MOD;
            sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i + 1][j + 1];
            sum[i + 1][j + 1] %= MOD;
            while (sum[i + 1][j + 1] < 0) sum[i + 1][j + 1] += MOD;
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans += dp[i + 1][j + 1];
            ans %= MOD;
        }
    }
    cout << ans + 1 << endl;
}

Measured memory_bytes: 62976
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        Scanner sc = new Scanner(is);
        /* read */
        int n = sc.nextInt();

        Map<Integer, Set<Integer>> lists = new HashMap<>();

        for (int i = 0; i < n; i++) {
            String s = sc.next();
            Set<Integer> list = new HashSet<>();

            for (int j = 0; j < n; j++) {
                if (s.charAt(j) == '1') {
                    // matrix[i][j] = true;
                    list.add(j);
                }
            }
            lists.put(i, list);
        }

        int max = -1;
        for (int i = 0; i < n; i++) {
            max = Math.max(depth(i, lists, n), max);
        }

        os.println(max);
    }

    private static class Node {
        int node;
        Set<Integer> parents = new HashSet<>();
    }

    private static int depth(int start, Map<Integer, Set<Integer>> lists, int N) {
        HashMap<Integer, HashSet<Integer>> tempLists = new HashMap<>();
        for (int j = 0 ; j < N ; j++) {
            tempLists.put(j, new HashSet<>(lists.get(j)));
        }
        Set<Integer> visited = new HashSet<>();
        Set<Integer> firstGp = new HashSet<>();
        firstGp.add(start);

        int count = 0;
        while (!firstGp.isEmpty()) {
            count++;
            Set<Integer> next = new HashSet<>();
            for (Integer n : firstGp) {
                Set<Integer> nexts = tempLists.get(n);
                for (int nx : nexts) {
                    if (visited.contains(nx)) {
                        // visiting again
                        return -1;
                    }
                    next.add(nx);
                }
                visited.add(n);
            }
            for (Integer n : firstGp) {
                for(Integer child : next) {
                    tempLists.get(child).remove(n);
                }
            }
            firstGp.clear();
            firstGp.addAll(next);
        }
        return count;
    }
}

Measured memory_bytes: 159724
#include<bits/stdc++.h>
using namespace std;
int dp[2005][2005][2]={};
int main(){
  int m,n;
  char s[2001],t[2001];
  scanf("%d %d",&m,&n);
  scanf("%s %s",s,t);

  for(int i=0;i<=m;i++){
    for(int j=0;j<=n;j++){

      if(i < m){
	if(s[i] == 'I') dp[i+1][j][1] = max(dp[i+1][j][1],dp[i][j][0]+1);
	if(s[i] == 'O'){
	  if(dp[i][j][1] > 0) dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][1]+1);
	}
      }
      if(j < n){
	if(t[j] == 'I') dp[i][j+1][1] = max(dp[i][j+1][1],dp[i][j][0]+1);
	if(t[j] == 'O'){
	  if(dp[i][j][1] > 0) dp[i][j+1][0] = max(dp[i][j+1][0],dp[i][j][1]+1);
	}
      }
    }
  }

  int ans = 0;
  for(int i=0;i<=m;i++){
    for(int j=0;j<=n;j++) ans = max(ans,dp[i][j][1]);
  }
  printf("%d\n",ans);
  return(0);
}



Measured memory_bytes: 34576
n = gets.to_i
p = gets.split("\s").join.to_i
q = gets.split("\s").join.to_i

p_ord = 0
q_ord = 0
count = 0

(1..n).to_a.permutation.each do |i|
  perm = i.join.to_i
  p_ord = count if p == perm
  q_ord = count if q == perm
  count += 1
end

dist = (p_ord - q_ord)

p dist > 0 ? dist : -dist

Measured memory_bytes: 1916
import std.stdio, std.string, std.conv, std.range, std.algorithm;

void main() {
  auto NL = readln.chomp.split.map!(to!int);
  auto N = NL[0];

  string[] S;
  foreach(_; iota(N)) {
    S ~= readln.chomp;
  }

  S.sort.join.writeln;
}


Measured memory_bytes: 376
//BFS

#include<stdio.h>
#include<stdlib.h>
#define N 100

int n,i,j;
int arr[N][N];
int imp[N];

void work(int x,int leng)
{
  int k;
  leng++;
  imp[x] = leng;

  for(k = 0; k < n; k++)
    {
      if(arr[x][k] == 1)
	{
	  if(imp[k] <= leng && imp[k] >= 0) continue;
	  work(k,leng);
	}
    }
}


int main()
{
  int l,b,remain;
  
  //input data
  scanf("%d",&n);
  for(i = 0; i < n; i++)
    {
      scanf("%d%d",&l,&remain);
      for(j = 0; j < remain; j++)
	{
	  scanf("%d",&b);
	  arr[l-1][b-1] = 1;
	}
    }

  //initialize number
  for(i = 0; i < n; i++) imp[i] = -1;

  //work
  work(0,-1);

  //output data
  for(i = 0; i < n; i++)
    {
      printf("%d %d\n",i+1,imp[i]);
    }

  return 0;
  
}



Measured memory_bytes: 2084
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int i=0 ; i<b ; i++)scanf("%d",&a[i])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265



int main()
{
	int n,m;
	scdd(n,m);
	int a[200][200];
	int b[2000];
	forin(i,0,n)
	{
		forin(j,0,m)
		scanf("%d",&a[i][j]);
	}
	forin(i,0,m)
	scanf("%d",&b[i]);
	int c[2000];
	iniarr(c,n);
	forin(i,0,n)
	{
		forin(j,0,m)
		{
			c[i]+=a[i][j]*b[j];
		}
	}
	forin(i,0,n)
	{
		printf("%d\n",c[i]);
	}
	
	return 0;
}

Measured memory_bytes: 3268
#include <stdio.h>

int main(void)
{
    int x;
    scanf("%d",&x);
    printf("%d:%d:%d\n",x / 3600,(x - (x / 3600) * 3600) / 60,x - (x / 3600) * 3600 - ((x - (x / 3600) * 3600) / 60 ) * 60);

    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    bool b[26];
    for (int i = 0; i < 26; i++) b[i] = false;
    for (int i = 0; i < int(s.size()); i++) {
        b[s[i] - 'a'] = true;
    }
    for (int i = 0; i < 26; i++) {
        if (!b[i]) {
            cout << char(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


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

int main() {

  int n; 
  cin >> n;
  vector<double> u(n);
  for(int i = 0; i < n; i++) { cin >> u.at(i); }

  sort(u.begin(), u.end());

  for(int i = 1; i < n; i++) {
    double tmp = (u.at(0) + u.at(1)) / 2;
    u.at(1) = tmp;
    u.erase(u.begin() + 0);
    sort(u.begin(), u.end());
  }
  cout << u.at(0) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) 
{
  char ch[1200];
  int i,n;
  n=0;
  char a[1200];
  while(1) {
    scanf("%c",&a[n]);
    if(a[n] == '\n') {
      break;
    }
    ch[n] = a[n];
    if('A' <= a[n] && a[n] <= 'Z') {
      ch[n] = a[n] + 32;
    } else if(a[n] >= 'a' && a[n] <= 'z') {
      ch[n] = a[n] - 32;
    }
    n = n +1;
  }
  for(i=0; i<n ; i++) {
    printf("%c" ,ch[i]);
  }
  printf("\n"); 
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int dight(int n){
  return n==0?1:int(log10(n)+1);
}
int kakeru(int n){
  int m = 1;
  for(int i=0;i<n;i++) m *= 10;
  return m;
}
int main(){
  int n,count=0;
  cin >> n;
  int s[n],m[n];
  for(int i=0;i<n;i++) cin >> s[i]; 
  sort(s,s+n);
  for(int i=0;i<6;i++) m[i] = s[i];
  for(int i=0;i<6;i++){
    for(int j=0;j<6;j++){
      if(i!=j){
	m[count] = s[i] * kakeru(dight(s[j]));
	m[count] += s[j];
	count++;
      }
    }
  }
  sort(m,m+count);
  //for(int i=0;i<count;i++) cout << m[i] << endl;
  cout << m[2] << endl;
  return 0;
}

Measured memory_bytes: 1252
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	vector<int>a(n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	vector<vector<int>>v={
		{2,3,0,1},{0,3,1,2}
	};
	for(int i=3;i<n;i++)v.push_back({0,1,i-1,i});
	vector<double>r;
	transform(v.begin(),v.end(),back_inserter(r),[&a](const vector<int> &e)->double{
		return (a[e[0]]+a[e[1]])*1.0/(a[e[2]]-a[e[3]]);
	});
	printf("%f\n",*max_element(r.begin(),r.end()));
}

Measured memory_bytes: 2796
#include<bits/stdc++.h>
using namespace std;
struct st{
  int p,d,f,b;
  st(){}
  st(int p,int d,int f,int b):p(p),d(d),f(f),b(b){}
  bool operator<(const st& a) const{
    return d>a.d;
  }
};
struct edge{
  int to,cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){}
};
vector<edge> G[10001];
int dp[10001][2][201];
int main(){
  int n,m,x;
  cin>>n>>m>>x;
  int s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  for(int i=0;i<m;i++){
    int a,b,d;
    cin>>a>>b>>d;
    a--;b--;
    G[a].push_back(edge(b,d));
    G[b].push_back(edge(a,d));
  }
  memset(dp,-1,sizeof(dp));
  priority_queue<st> q;
  q.push(st(0,0,0,x));
  dp[0][0][x]=0;
  int ans=-1;
  while(!q.empty()){
    st p=q.top();q.pop();
    if(dp[p.p][p.f][p.b]>0&&dp[p.p][p.f][p.b]<p.d) continue;
    //cout<<p.p<<" "<<p.f<<" "<<p.b<<" "<<p.d<<endl;
    if(p.p==n-1){
      ans=p.d;
      break;
    }
    for(int i=0;i<(int)G[p.p].size();i++){
      int np=G[p.p][i].to,nc=G[p.p][i].cost;
      int nb=max(0,p.b-nc),nf=p.f;
      if(s[np]==0){
	if(nf==1&&nb) continue;
	nf=0;
	nb=x;
      }
      if(s[np]==2){
	if(nf==0&&nb) continue;
	nf=1;
	nb=x;
      }
      if(dp[np][nf][nb]<0||dp[np][nf][nb]>p.d+nc){
	dp[np][nf][nb]=p.d+nc;
	q.push(st(np,p.d+nc,nf,nb));
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 19748
n = int(input())
l = list(map(int, input().split()))
t = 0

for i in range(len(l)):
    for j in range(i + 1, len(l)):
        for k in range(j + 1, len(l)):
            sum = l[i] + l[j] + l[k]
            if sum - max(l[i], l[j], l[k]) > max(l[i], l[j], l[k]):
                if l[i] != l[j] and l[i] != l[k] and l[j] != l[k]:
                    t += 1

print(t)


Measured memory_bytes: 9212
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <map>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N;
    cin >> N;
    vector<ll> Taka(N), Must(N);
    REP(i, N) cin >> Taka[i];
    REP(i, N) cin >> Must[i];
    
    // calculation
    ll sum = 0, sum_Taka = 0, sum_Must = 0;
    REP(i, N) {
        if (Taka[i] >= Must[i]) sum++;
    }
    
    REP(i, N) {
        sum_Taka += Taka[i];
        sum_Must += Must[i];
    }
    
    if (sum == N) {
        cout << 0 << "\n";
    } else if (sum_Taka < sum_Must) {
        cout << -1 << "\n";
    } else {
        vector<ll> Taka_plus, Taka_minus;
        REP(i, N) {
            if (Taka[i] > Must[i]) {
                Taka_plus.push_back(Taka[i] - Must[i]);
            } else if (Taka[i] < Must[i]) {
                Taka_minus.push_back(Taka[i] - Must[i]);
            }
        }
        
        ll len_minus = (ll)Taka_minus.size(), minus = 0;
        REP(i, len_minus) {
            minus += Taka_minus[i];
        }
        
        sort(Taka_plus.begin(), Taka_plus.end(), greater<>());  // int big -> small
        
        ll num = (ll)Taka_minus.size(), len = (ll)Taka_plus.size();
        
        REP(i, len) {
            num++;
            minus += Taka_plus[i];
            if (minus >= 0) {
                cout << num << "\n";
                return 0;
            }
        }
        
        cout << -1 << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int a[N];
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int b;
  for(int p=0;p<N;p++){
    for(int i=0;i<N-1;i++){
      if(a[i]>=a[i+1]){
        b=a[i];
        a[i]=a[i+1];
        a[i+1]=b;
      }
    }
  }
  int s=0;
  int t=0;
  if(N%2==0){
    for(int i=1;i<N;i+=2){
      s+=a[i];
    }
    for(int i=0;i<N;i+=2){
      t+=a[i];
    }
  }
  else{
    for(int i=0;i<N;i+=2){
      s+=a[i];
    }
    for(int i=1;i<N;i+=2){
      t+=a[i];
    }
  }
  cout<<s-t<<endl;
  return 0;
}

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


public class D
{
	public static void Main()
	{
		int N = GetInt();
		int K = GetInt();
		int L = GetInt();

		UnionFind ufRoad = new UnionFind(N+1);
		for(int i = 0; i < K; i++)
		{
			int p = GetInt();
			int q = GetInt();
			if(!ufRoad.IsSame(p,q))
				ufRoad.Merge(p,q);
		}
		
		UnionFind ufRailway = new UnionFind(N+1);
		for(int i = 0; i < L; i++)
		{
			int r = GetInt();
			int s = GetInt();
			if(!ufRailway.IsSame(r,s))
				ufRailway.Merge(r,s);
		}

		Dictionary<long, int> num = new Dictionary<long, int>(N);
		for(int i = 1; i <= N; i++)
		{
			int currentNum = 0;
			long hashCode = getHashCode(ufRoad.Root(i), ufRailway.Root(i));
			num.TryGetValue(hashCode, out currentNum);
			num[hashCode] = currentNum + 1;
		}

		StringBuilder sb = new StringBuilder();
		for(int i = 1; i <= N; i++)
		{
			long hashCode = getHashCode(ufRoad.Root(i), ufRailway.Root(i));
			sb.AppendFormat($"{num[hashCode]} ");
		}
		Console.WriteLine(sb);
	}

	private static long getHashCode(int x, int y)
	{
		return (long)x * 1000000 + (long)y;
	}
}


public class UnionFind
{
	private int[] par = null;
	private int[] rank = null;
	private int[] ccSize = null;
	
	public UnionFind(int n)
	{
		par = new int[n];
		rank = new int[n];
		ccSize = new int[n];
		for(int i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
			ccSize[i] = 1;
		}
	}

	public bool IsSame(int x, int y)
	{
		return (Root(x) == Root(y));
	}

	public int Root(int x)
	{
		if(par[x] == x)
			return x;

		int r = Root(par[x]);
		par[x] = r;
		return r;
	}
	
	public bool Merge(int x, int y)
	{
		int rx = Root(x);
		int ry = Root(y);
		if(rx == ry)
			return false;
		
		if(rank[rx] < rank[ry])
		{
			int tmp = rx;
			rx = ry;
			ry = tmp;
		}
		else if(rank[rx] == rank[ry])
			rank[rx]++;

		par[ry] = rx;
		ccSize[rx] = ccSize[rx] + ccSize[ry];
		return true;
	}

	public int Size(int x)
	{
		return ccSize[Root(x)];
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 28704
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

set<int> st[0x100];

void solve(std::string s, std::string t){
    for(int i = 0; i < s.size(); ++i) {
        st[s[i]].insert(i);
    }
    for(auto c : t) {
        if (st[c].empty()) {
            cout << -1 << endl;
            return;
        }
    }
    int res = 0, p = 0;
    for(int i = 0; i < t.size(); ++i) {
        char c = t[i];
        auto it = st[c].lower_bound(p);
//        cerr << c << "," << p << ",";
        if (it == st[c].end()) {
            res += (int)s.size() - p;
            p = 0;
            --i;
        } else {
            res += *it - p + 1;
            p = *it + 1;
        }
//        cerr << res << "," << p << endl;
    }
    cout << res << endl;
}

signed main(){
    std::string s;
    std::cin >> s;
    std::string t;
    std::cin >> t;
    solve(s, t);
    return 0;
}


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



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, X, T;
    cin >> N >> X >> T;
    int temp = N / X;
    bool flag = N % X;
    if (flag) temp++;
    cout << temp*T << "\n";
}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *   ****      *  ****

//     ****   *****   ****         *   *  *****  *   *   ****
//    *   *    *    *             ** **    *    **  *  *
//   ****     *    * ***  *****  * * *    *    * * *  * ***
//  *   *    *    *   *         *   *    *    *  **  *   *
// ****   *****   ****         *   *  *****  *   *   ****



Measured memory_bytes: 3648
from itertools import permutations

N,C=list(map(int,input().split()))
D=[list(map(int,input().split())) for _ in range(C)]
c=[list(map(int,input().split())) for _ in range(N)]

cnt=[[0]*(C+1) for _ in range(3)]
disc=[[0]*(C+1) for _ in range(3)]

for i in range(N):
    for j in range(N):
        cnt[(i+j)%3][c[i][j]]+=1

for i in range(3):
    for j in range(C):
        for k in range(C):
            disc[i][j]+=D[k][j]*cnt[i][k+1]
ans=10**10

for i,j,k in permutations(range(C),3):
    ans=min(ans,disc[0][i]+disc[1][j]+disc[2][k])

print(ans)

Measured memory_bytes: 44124
/*  -*- coding: utf-8 -*-
 *
 * 1362.cc: Do Geese See God?
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 2000;
const long long LINF = 1LL << 61;

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_N + 4], t[MAX_N + 4];
int dp0[MAX_N][MAX_N + 1];
ll dp1[MAX_N][MAX_N + 1];

/* subroutines */

/* main */

int main() {
  ll k;
  scanf("%s%lld", s, &k);
  int n = strlen(s);
  k--;

  for (int i = 0; i < n; i++) {
    dp0[i][i + 1] = 1;
    dp1[i][i] = dp1[i][i + 1] = 1;
  }

  for (int l = 2; l <= n; l++)
    for (int i = 0, j = l; j <= n; i++, j++) {
      if (s[i] == s[j - 1]) {
	dp0[i][j] = dp0[i + 1][j - 1] + 2;
	dp1[i][j] = dp1[i + 1][j - 1];
      }
      else if (dp0[i][j - 1] == dp0[i + 1][j]) {
	dp0[i][j] = dp0[i][j - 1] + 2;
	dp1[i][j] = min(LINF, dp1[i][j - 1] + dp1[i + 1][j]);
      }
      else if (dp0[i][j - 1] < dp0[i + 1][j]) {
	dp0[i][j] = dp0[i][j - 1] + 2;
	dp1[i][j] = dp1[i][j - 1];
      }
      else {
	dp0[i][j] = dp0[i + 1][j] + 2;
	dp1[i][j] = dp1[i + 1][j];
      }
    }

  //printf("%d %lld\n", dp0[0][n], dp1[0][n]);

  int l = 0, mc = 0;
  for (int i = 0, j = n; i < j;) {
    if (s[i] == s[j - 1]) {
      if (i + 1 == j) {
	mc = s[i];
	break;
      }
      t[l++] = s[i];
      i++, j--;
    }
    else if (dp0[i][j - 1] == dp0[i + 1][j]) {
      char c0, c1;
      int i0, j0, i1, j1;
      if (s[i] < s[j - 1])
	c0 = s[i], c1 = s[j - 1], i0 = i + 1, j0 = j, i1 = i, j1 = j - 1;
      else
	c0 = s[j - 1], c1 = s[i], i0 = i, j0 = j - 1, i1 = i + 1, j1 = j;
      if (k < dp1[i0][j0])
	t[l++] = c0, i = i0, j = j0;
      else
	t[l++] = c1, i = i1, j = j1, k -= dp1[i0][j0];
    }
    else if (dp0[i][j - 1] < dp0[i + 1][j]) {
      t[l++] = s[j - 1];
      j--;
    }
    else {
      t[l++] = s[i];
      i++;
    }
  }

  if (k > 0) {
    puts("NONE");
    return 0;
  }

  for (int i = 0; i < l; i++) putchar(t[i]);
  if (mc) putchar(mc);
  for (int i = l - 1; i >= 0; i--) putchar(t[i]);
  putchar('\n');
  return 0;
}



Measured memory_bytes: 39548
N=int(input())
lsa=[int(s) for s in input().split()]
lsb=[int(s) for s in input().split()]
ls=[lsa[0]+sum(lsb)]
for i in range(1,N):
  ls.append(ls[-1]+lsa[i]-lsb[i-1])
print(max(ls))


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
int k[10];
bool s[10][11];
int p[10];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  REP(i, m) {
    REP(j, n + 1) {
      s[i][j] = false;
    }
  }

  cin >> n >> m;
  REP(i, m) {
    cin >> k[i];
    REP(j, k[i]) {
      int a;
      cin >> a;
      s[i][a] = true;
    }
  }

  REP(i, m) cin >> p[i];

  int ans = 0;
  REP(i, (1 << n)) {
    vector<int> d(m, 0);

    REP(j, n) {
      REP(k, m) {
        if(s[k][j + 1] && (i & (1 << j))) d[k]++;
      }
    }

    bool f = true;
    REP(j, m) {
      if(d[j] % 2 != p[j]) f = false;
    }
    if(f) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
A,B = map(int, input().split())


def f(n):
    if n%4 == 0:
        return n
    elif n%4 == 1:
        return 1
    elif n%4 == 2:
        return n ^ (n-1) ^ (n-2)
    elif n%4 == 3:
        return 0

print(f(A-1)^f(B))

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

int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<pair<int, int>> group_S;
    int prev_num = S.at(0) == '0' ? 0 : 1;
    int cur_count = 1;
    for (int i = 1; i < S.size(); i++) {
        int cur_num = S.at(i) == '0' ? 0 : 1;
        if (cur_num == prev_num) cur_count += 1;
        else {
            group_S.emplace_back(prev_num, cur_count);
            prev_num = cur_num;
            cur_count = 1;
        }
    }
    group_S.emplace_back(prev_num, cur_count);

    int left = 0, right = 0;
    int num_group_zeros = 0;
    int cur_num_items = 0;
    int max_consecutive_ones = 0;
    for (int i = 0; i < group_S.size(); i++) {
        while (right < group_S.size() && (
            group_S.at(right).first == 1 || (num_group_zeros < K))) {
            pair<int, int> cur_group = group_S.at(right);
            if (cur_group.first == 0) num_group_zeros += 1;
            cur_num_items += cur_group.second;
            right += 1;
        }
        max_consecutive_ones = max(max_consecutive_ones, cur_num_items);
        pair<int, int> poped_group = group_S.at(i);
        if (poped_group.first == 0) num_group_zeros -= 1;
        cur_num_items -= poped_group.second;
    }
    cout << max_consecutive_ones << "\n";
}

Measured memory_bytes: 1528
n = int(input())
w= list(map(int, input().split()))

s1=[]
s2=[]

for i in range(1, n):
    s1.append(sum(w[:i]))
    s2.append(sum(w[i:]))

func = lambda i:abs(s1[i] - s2[i])
val = map(func, range(n-1))


print(min(val))

Measured memory_bytes: 3064
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), c = sc.nextInt();
        int[] b = new int[m];
        for(int i = 0; i < m; i++){
            b[i] = sc.nextInt();
        }
        int[][] a = new int[n][m];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                a[i][j] = sc.nextInt();
            }
        }
        int ans = 0;
        for(int i = 0; i < n; i++){
            int x = c;
            for(int j = 0; j < m; j++){
                x += a[i][j] * b[j];
            }
            if(x > 0) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
int main(){
	int A,B,m;
	cin >> A >> B >> m;
	int a[A],b[B],x[m],y[m],c[m];
	rep(i,A)cin>>a[i];
	rep(i,B)cin>>b[i];
	int cost=a[0]+b[0];
	rep(i,m){
		cin >> x[i] >> y[i] >> c[i];
		cost = min(cost,a[x[i]-1]+b[y[i]-1]-c[i]);
	}
	sort(a,a+A);
	sort(b,b+B);
	cost = min(cost,a[0]+b[0]);
	cout << cost << endl;
}


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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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

int n, a[100000];

bool jou(int i){
	while(i > 1){
		if(i % 2 == 1) return false;
		i /= 2;
	}
	return true;
}

int main(){
	cin >> n;
	int cnt[2] = {0};
	for(int i = 0; i < n; i++){
		cin >> a[i];
		cnt[a[i]%2]++;
	}
	
	if(cnt[1]%2 == 1 && cnt[0] > 0) cout << "NO" << endl;
	else cout << "YES" << endl;
	
	return 0;
}

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

using namespace std;

int DiceInfo[7];
vector<string> DicePosition;
const string WEDirection = "364136";
const string NSDirection = "265126";
const string LRDirection = "453245";

void swap(string &ans, int pos, const string &direction) {
	char tmp;

	tmp = ans[direction[pos] - '0'];
	ans[direction[pos + 0] - '0'] = ans[direction[pos + 1] - '0'];
	ans[direction[pos + 1] - '0'] = ans[direction[pos + 2] - '0'];
	ans[direction[pos + 2] - '0'] = ans[direction[pos + 3] - '0'];
	ans[direction[pos + 3] - '0'] = tmp;
	//cout << "=" << ans << endl;
}

void solve() {
	int len;
	string ans;

	ans = "0123456";
	DicePosition.push_back(ans);
	for (int i = 0; i < 3; ++i) {
		swap(ans, i, WEDirection);
		DicePosition.push_back(ans);
	}

	len = DicePosition.size();
	for (int i = 0; i < len; ++i) {
		ans = DicePosition[i];
		for (int k = 0; k < 3; ++k) {
			swap(ans, k, NSDirection);
			DicePosition.push_back(ans);
		}
	}

	len = DicePosition.size();
	for (int i = 0; i < len; ++i) {
		ans = DicePosition[i];
		for (int k = 0; k < 3; ++k) {
			swap(ans, k, LRDirection);
			DicePosition.push_back(ans);
		}
	}
}

int judge(int up, int front) {
	int len;

	len = DicePosition.size();
	for (int i = 0; i < len; ++i) {
		if (DiceInfo[DicePosition[i][1] - '0'] == up
			&& DiceInfo[DicePosition[i][2] - '0'] == front) {
			return DiceInfo[DicePosition[i][3] - '0'];
		}
	}
}

int main() {
	int q, up, front;

	for (int i = 1; i < 7; ++i) {
		cin >> DiceInfo[i];
	}
	solve();
	cin >> q;
	for (int i = 0; i < q; ++i) {
		cin >> up >> front;
		cout << judge(up, front) << endl;
	}

	return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
int a, b;
vector<vector<char>> s;
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> a >> b;
    a--; b--;
    
    REP(i, 100){
        s.resize(i+1);
        REP(j, 100){
            if(i < 50) s[i].pb('#');
            else s[i].pb('.');
        }
    }
    
    for(int i = 1; i < 49; i += 2){
        for(int j = 0; j < 100; j += 2){
            if(a > 0){
                s[i][j] = '.';
                a--;
            }
        }
    }
    for(int i = 51; i < 99; i += 2){
        for(int j = 0; j < 100; j += 2){
            if(b > 0){
                s[i][j] = '#';
                b--;
            }
        }
    }
    
    cout << 100 << " " << 100 << endl;
    REP(i, 100){
        REP(j, 100) cout << s[i][j];
        cout << endl;
    }

}


Measured memory_bytes: 256
from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]
gcd_ = [0] * n
L, R = [0] * (n + 1), [0] * (n + 1)
for i in range(n):
    L[i + 1] = gcd(L[i], a[i])
    R[n - (i + 1)] = gcd(R[n - i], a[(n - 1) - i])
for i in range(n):
    gcd_[i] = gcd(L[i], R[i + 1])
print(max(gcd_))

Measured memory_bytes: 16056
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.lang.Math;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int N = fs.nextInt(); int X = fs.nextInt(); int T = fs.nextInt();

        int times = 0;
        if (N%X != 0) {
            times+= N/X;
            times+= 1;
        } else {
            times+=N/X;
        }
        System.out.println(times*T);

    }


    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");

        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
    }

}



Measured memory_bytes: 32600
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
n,m = map(int, input().split())
a = list(map(int, input().split()))

total = sum(a)
re = m
for i in range(n):
    if (4*m*a[i] >= total):
        re = re -1
        if (re == 0):
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 9068
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int i = sc.nextInt();

		if(N == 1) {

			System.out.println(1);

		}else {

			System.out.println((N-i+1));
		}

	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define ff first
#define ss second
int main() {
	ios::sync_with_stdio(0);
	int N; 
	cin >> N;
	long double coins[N + 1];
	for (int i = 1; i < N + 1; i++) {
		cin >> coins[i];
	} 
	long double probability[N + 1][N + 1];
	for (int i = 0; i < N + 1; i++) {
		for (int j = 0; j < N + 1; j++) {
			probability[i][j] = 0;
		}
	}

	probability[0][0] = 1;
	for (int i = 1; i < N + 1; i++) {
		for (int j = 0; j < N + 1; j++) {
			if (j == 0) { 
				probability[i][j] = probability[i - 1][j] * (1 - coins[i]);
			}  
			else {
				probability[i][j] = probability[i - 1][j] * (1 - coins[i]);
				probability[i][j] += probability[i - 1][j - 1] * coins[i];
			}
		}
	}
	long double answer = 0;
	for (int i = (N + 1)/2; i < N + 1; i++) {
		answer += probability[N][i];
	}
	cout << setprecision(10) << answer << endl;
	return 0;
}

Measured memory_bytes: 140928
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		for(int a = 1;a>0;a++){
			int H = scan.nextInt();
			int W = scan.nextInt();
			if(H == 0 && W == 0){
				break;
			}
			for(int b = 0;b<H;b++){
				for(int c =0;c<W;c++){
					if(b%2 == 0){
						if(c%2 == 0){
							System.out.print("#");
						}else{
							System.out.print(".");
						}
					}else{
						if(c%2 == 0){
							System.out.print(".");
						}else{
							System.out.print("#");
						}
					}
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}

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

int n, nodes[101010];
vector<vector<P>> tree(101010, vector<P>(0));

void dfs(int a, int pa, int c){
  
  for(auto x : tree.at(a)){
    if(x.first == pa) continue;
    int nc = ((x.second % 2 == 0)? c : (c ^ 1));
    nodes[x.first] = nc;
    dfs(x.first, a, nc);
  }
  return;
}

int main(){
  cin >> n;
  rep(i, n - 1){
    int a, b, c;
    cin >> a >> b >> c;
    tree[a].emplace_back(P(b, c));
    tree[b].emplace_back(P(a, c));
  }
  
  dfs(1, 0, 0);
  
  for(int i = 1; i <= n; i++){
    cout << nodes[i] << endl;
  }
  
  return 0;
}


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

int main() {
int64_t n,a;
  string s;
  cin>>n;
  cin>>s;
  int64_t r,g,b;
  r=0;
  g=0;
  b=0;
  for(int64_t i=0;i<n;i++){
  if(s.at(i)=='R'){r++;}
  if(s.at(i)=='G'){g++;}
  if(s.at(i)=='B'){b++;}
  }
  a=r*g*b;
  for(int64_t i=0;i<n;i++){
  for(int64_t j=0;i+2*j<n;j++){
  r=0;
    g=0;
    b=0;
  if(s.at(i)=='R'){r++;}
  if(s.at(i)=='G'){g++;}
  if(s.at(i)=='B'){b++;}
  if(s.at(i+j)=='R'){r++;}
  if(s.at(i+j)=='G'){g++;}
  if(s.at(i+j)=='B'){b++;}
  if(s.at(i+j*2)=='R'){r++;}
  if(s.at(i+j*2)=='G'){g++;}
  if(s.at(i+j*2)=='B'){b++;}
  
  if(r==1&&g==1&&b==1){a--;}}}
  cout<<a<<endl;
}

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

int main()
{
	int a[10];

	for (int i = 0; i < 10; i++)
		cin >> a[i];

	sort(a, a + 10, greater<int>());

	for(int i = 0; i < 3; i++)
		cout << a[i] << endl;

	return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define ff(i, x, y) for(int i = x;i <= y;i++)
#define fs(i, x, y) for(int i = x;i >= y;i--)
#define maxn 100010
using namespace std;
typedef long long ll;
int v[1100000];
int main() {
    v[0] = 1;
    ff(i, 0, 1000000) {
        if(v[i] == 1)
        ff(j, 0, 5) {
            v[i + 100 + j] = 1;
        }
    }
    int x;
    scanf("%d", &x);
    printf("%d", v[x]);
    return  0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef long long ll;

int dp[1024];

int s[512], l[512], p[512];
int w[512];
int ans[512];

int main(){
    int n;
    while(cin >> n){
        int a[2], b[2];
        rep(i,2){
            cin >> a[i] >> b[i];
            a[i]--, b[i]--;
        }
        int ans = 1e9;
        loop(w,1,n+1){
            int x = 0;
            rep(i,2) x += abs(a[i]/w-b[i]/w)+abs(a[i]%w-b[i]%w);
            //printf(" %d\n",x);
            ans = min(ans,x);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	void run() {
		MyScanner sc = new MyScanner();

		while (true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int s = sc.nextInt();
			int g1 = sc.nextInt();
			int g2 = sc.nextInt();
			if ((n | m | s | g1 | g2) == 0) {
				break;
			}
			s--;
			g1--;
			g2--;
			int[][] g = new int[n][n];
			for (int i = 0; i < n; i++) {
				Arrays.fill(g[i], 1 << 20);
				g[i][i] = 0;
			}
			for (int i = 0; i < m; i++) {
				int u = sc.nextInt() - 1;
				int v = sc.nextInt() - 1;
				int w = sc.nextInt();
				g[u][v] = w;
			}

			for (int k = 0; k < n; k++) {
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < n; j++) {
						g[i][j] = Math.min(g[i][j], g[i][k] + g[k][j]);
					}
				}
			}

			int min = g[s][g1] + g[s][g2];
			for (int i = 0; i < n; i++) {
				min = Math.min(min, g[s][i] + g[i][g1] + g[i][g2]);
			}

			System.out.println(min);
		}
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

Measured memory_bytes: 37932
input = require("fs").readFileSync("/dev/stdin", "utf8")

lines = input.split("\n")
N = lines.shift() * 1
B = lines.shift().split(' ').map(function(i) { return i * 1 })

ans = 0
ans += B[0]
ans += B[N-2]
for (i = 1; i < N - 1; i++) {
  min = Math.min(B[i], B[i-1])
  ans += min
}

console.log(ans)


Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
signed main()
{
	Very_fast;
	int x;
	cin>>x;
	x^=1;
	cout<<x;
	return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String args[]) throws Exception{
        String[] s = new BufferedReader(new InputStreamReader(System.in)).readLine().split(" ");
        if((s[0].charAt(s[0].length() - 1) & 1) == 0 || (s[1].charAt(s[1].length() - 1) & 1) == 0){
          System.out.println("Even");
        } else {
          System.out.println("Odd");
        }
    }
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i=0; i<n; i++) {
        int num;
        cin >> num;
        num--;
        a[i] = num;
    }
    int ans = 0;
    for (int i=0; i<n; i++) {
        int num;
        cin >> num;
        ans += num;
    }
    for (int i=0; i<n-1; i++) cin >> c[i];
    int pred = -10;
    for (int i=0; i<n; i++) {
        int d = a[i];
        if (pred == d - 1) ans += c[pred];
        pred = d;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApplication1
{
  internal class Program
  {
    public static void Main(string[] args)
    {
      int N = int.Parse(Console.ReadLine());
      string S = Console.ReadLine();
      int rcnt = 0;
      int bcnt = 0;

      for (int i = 0; i < S.Length; i++)
      {
        if (S[i] == 'B')
        {
          bcnt++;
        }else if (S[i] == 'R')
        {
          rcnt++;
        }
      }

      if (rcnt > bcnt)
      {
        Console.WriteLine("Yes");
      }
      else
      {
        Console.WriteLine("No");
      }
    }
  }
}

Measured memory_bytes: 11092