akhauriyash/Code-Regression huggingface dataset:
#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()
{
    string s;
    cin >> s;
    bool ok = true;
    rep(i, s.size())
    {
        //odd
        if (i % 2 == 0)
        {
            if (s[i] == 'L')
                ok = false;
        }
        else
        {
            if (s[i] == 'R')
                ok = false;
        }
    }
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
int main()
{
    int a, b, c;
    while(scanf("%d%d%d",&a,&b,&c) != EOF)
    {

        int ans = 0;
        while(!(a==b && b==c && a==c))
        {
            if(b < c) swap(b, c);
            if(a < b) swap(a, b);
            if(b < c) swap(b, c);
            int i = a-b;
            int j = a-c;
            if(i%2==1 || j%2==1)
            {
                b += 1;
                c += 1;
                //c += 1;
                ans ++;
            }
            if(!(i%2) &&!(j%2))
            {
                c += 2;
                ans ++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define MAXN 15
#define LL long long
int n,d,ans;
int x[MAXN][MAXN],s[MAXN][MAXN];

int main()
{
	scanf("%d %d",&n,&d);
	for(int k=1;k<=d;k++)
		scanf("%d",&x[1][k]);
	for(int i=2;i<=n;i++)
	{
		for(int k=1;k<=d;k++)
		{	
			scanf("%d",&x[i][k]);
			for(int j=1;j<i;j++)//if(i==2&&j==1) printf("*%d %d\n",x[i][k],x[j][k]);
				s[i][j]+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
		}
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)
			//printf("%d\n",s[i][j]);
			if(((int)sqrt(s[i][j]))*((int)sqrt(s[i][j]))==s[i][j])
				ans++;
	printf("%d\n",ans);
	return 0;
}

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

int c[6]={500,100,50,10,5,1};

int main(){
	int n;
	while(scanf("%d",&n)&&n){
		int m=1000-n;
		int res=0;
		for(int i=0;i<6;i++){ res+=m/c[i]; m%=c[i]; }
		printf("%d\n",res);
	}
}

Measured memory_bytes: 1184
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))


INF = 2147483647


import sys
stdin = sys.stdin

X =        int( stdin.readline().strip() )

start = int((2*X)**0.5)

def triangular(n):
    return n*(n+1)//2

while triangular(start) > X:
    start -= 1

while triangular(start) < X:
    start += 1

print start



Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,a,b,r;
    cin>>a>>b>>x>>y>>r;
    if (x+r<=a && y+r<=b && x-r>=0 && y-r>=0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}



Measured memory_bytes: 3100
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(void){
    // Your code here!
    int h,w;
    cin>>h>>w;
    int p=0;
    for(int i=0;i<h;i++){
        string s;
        cin>>s;
        for(int j=0;j<w;j++){
            if(s[j]=='#')p++;
        }
    }
    if(p==w+h-1)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
pragma(inline, true)
void chmin(T)(ref T a, T b) {
    if (a > b) a = b;
}

int[] init() {
    enum INF = 1 << 28;
    int[] dp = new int[100010];
    foreach (i; 1..100001) {
        dp[i] = INF;
        int p6 = 1, p9 = 1;
        while (p6 <= i || p9 <= i) {
            if (i - p6 >= 0)
                chmin(dp[i], dp[i - p6] + 1);
            if (i - p9 >= 0)
                chmin(dp[i], dp[i - p9] + 1);
            p6 *= 6; p9 *= 9;
        }
    }
    return dp;
}

void main() {
    import std.conv : to;
    import std.stdio : readln, writeln;
    import std.string : chomp;
    int[] dp = init();
    writeln(dp[readln.chomp.to!int]);
}

Measured memory_bytes: 2684
#include "bits/stdc++.h"
using namespace std;
 
string ex(long long int a){
	string s="000000000000000000000000000000";
	for(int i=0;i<30;i++){
		if(a&1<<i){
			s[29-i]='1';
		}
	}
	
	//cout<<s<<endl;
	
	return s;
}
 
int main(){
	long long int n,k;
	cin>>n>>k;
	
	string s1;
	s1=ex(k);
	string s2="000000000000000000000000000000";
	string s3="000000000000000000000000000000";
	
	
	long long int cnt=0;
	for(int i=0;i<30;i++){
		if(cnt==0&&s1[i]=='1'){
			cnt++;
		}else if(cnt==1){
			s3[i]='1';
		}
	}
	
	//cout<<s1<<endl;
	//cout<<s2<<endl;
	//cout<<s3<<endl;
	
	
	long long int ans1=0;
	long long int ans2=0;
	long long int ans3=0;
	
	long long int ans=0;
	
	vector<string> a(n);
	vector<long long int> b(n);
	int flag;
	for(int i=0;i<n;i++){
		long long int x;
		cin>>x>>b[i];
		a[i]=ex(x);
		
		flag=0;
		for(int j=0;j<30;j++){
			if(s1[j]=='0'&&a[i][j]=='1'){
				flag=1;
				break;
			}
		}
		if(flag==0)ans1+=b[i];
		
		/*
		for(int l=0;l<15;l++){
			s2="000000000000000000000000000000";
			int cnt=0;
			for(int m=0;m<30;m++){
				if(cnt<=l&&s1[m]=='1'){
					cnt++;
					s2[m]='1';
				}else if(cnt==l+1&&s1[m]=='1'){
					cnt++;
				}else if(cnt>l+1){
					s2[m]='1';
				}
			}
			
			//cout<<s2<<endl;
			
			ans2=0;
			flag=0;
			for(int j=0;j<30;j++){
				if(s2[j]=='0'&&a[i][j]=='1'){
					flag=1;
					break;
				}
			}
			if(flag==0)ans2+=b[i];
			ans=max(ans,ans2);
		}
		
		*/
		
		
		flag=0;
		for(int j=0;j<30;j++){
			if(s3[j]=='0'&&a[i][j]=='1'){
				flag=1;
				break;
			}
		}
		if(flag==0)ans3+=b[i];
	}
	
	for(int l=0;l<30;l++){
		s2="000000000000000000000000000000";
		int cnt=0;
		for(int m=0;m<30;m++){
			if(cnt<=l&&s1[m]=='1'){
				cnt++;
				s2[m]='1';
			}else if(cnt==l+1&&s1[m]=='1'){
				cnt++;
			}else if(cnt>l+1){
				s2[m]='1';
			}
		}
		//cout<<s2<<endl;
		ans2=0;
		for(int i=0;i<n;i++){
			//cout<<s2<<endl;
			
			flag=0;
			for(int j=0;j<30;j++){
				if(s2[j]=='0'&&a[i][j]=='1'){
					flag=1;
					break;
				}
			}
			if(flag==0)ans2+=b[i];
		}
		//cout<<ans2<<endl;
		ans=max(ans,ans2);
	}
	
	ans=max(ans1,max(ans,ans3));
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 8064
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] map = new int[2][N];
        for(int i=0; i<2; i++)
            for(int j=0; j<N; j++)
                map[i][j] = sc.nextInt();
        System.out.println(func(N,map));
    }

    public static int func(int N, int[][] ar){
        int[][] dp = new int[2][N];
        dp[0][0] = ar[0][0];
        for(int i=0; i<2; i++)
            for(int j=0; j<N; j++){
                if(i+1<2) dp[i+1][j] = Math.max(dp[i+1][j], dp[i][j] + ar[i+1][j]);
                if(j+1<N) dp[i][j+1] = Math.max(dp[i][j+1], dp[i][j]+ ar[i][j+1]);
            }
        return dp[1][N-1];
    }
}

Measured memory_bytes: 22996
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int d=a;
	for(int i=1;i<=99999;i++){
		if(a%b==c){
			cout<<"YES"<<endl;return 0;
		} 
		a+=d;
	}
	cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(void)
{
  int n,i;
  cin>>n;
  vector<vector<int> >h(n,vector<int>(3));
  for(i=0;i<n;i++)
  {
    cin>>h[i][0]>>h[i][1]>>h[i][2];
  }
  vector<vector<int> >dp(n,vector<int>(3));
  dp[0][0]=h[0][0];dp[0][1]=h[0][1];dp[0][2]=h[0][2];
  for(i=1;i<n;i++)
  {
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+h[i][0];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+h[i][1];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+h[i][2];
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
  return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,a[51];
int32_t main(){
CODE_START;
cin>>n;
ll s=0;
for(ll i=0;i<n;i++)
{
cin>>a[i];
if(a[i]!=i+1){
    s++;
}
}
if(s>2){
    rc("NO");
}
cout<<"YES"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        //string input= Console.ReadLine();
        int[] input = new int[4];
        for (int a = 0; a < 4; a++)
        {
            input[a] = int.Parse(Console.ReadLine());
        }
        //int input =int.Parse();
        Console.WriteLine(Math.Min(input[0],input[1])+Math.Min(input[2],input[3]));


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

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

int main() {

	int a, b, c; cin >> a >> b >> c;
	int k; cin >> k;
	int cnt = 0;
	while (b <= a) {
		if (b <= a) {
			b *= 2;
			cnt++;
		}
	}
	while (c <= b) {
		if (c <= b) {
			c *= 2;
			cnt++;
		}
	}
	if (cnt <= k) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(void){
    // Your code here!
    int n, k;
    
    cin >> n >> k;
    if(n % k == 0)
        cout << 0 << endl;
    else
        cout << 1 << endl;
        
    return 0;
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

//π M_PI
//deg = rad*180/M_PI

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    int keep = a;
    for (size_t i = 2; i < b; i++) {
        if ( a%b == c ) {
            ans = 1;
            break;
        }

        a = keep*i;
    }
    cout << (ans ? "YES" : "NO") << endl;
    return 0;
}


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

int main() {
    string S; cin >> S;

    vector<int> s; for (int i=0; i<S.size(); ++i) s.push_back(S[i] - '0');

    ll sum = 0;
    int n = s.size()-1;
    
    for (int bit=0; bit < (1<<n); ++bit) {
        ll psum = 0;
        for (int i=0; i<n; ++i) {
            if (bit & (1<<i)) {
                sum += psum + s[i];
                psum = 0;
            } else {
                psum = (psum + s[i]) * 10;
            }
            
        }
        //cout << psum << endl;
        if (bit & (1<<n)) {
            sum += psum / 10 + s[n];
        } else {
            sum += psum + s[n];
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
MOD = 998244353
MAX = 2*10**5+1
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def C(n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


n, m, k = map(int, input().split())
ans = 0
for x in range(k+1):
    ans += C(n - 1, x) * m * pow(m-1, n-x-1, mod=MOD)
    ans %= MOD
print(ans)

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

#define ll long long

int main() {
    int n;
    vector<int> v;

    cin >> n;
    // Load
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        v.push_back(x);
    }
    // Sort
    sort(v.begin(), v.end());

    int h1 = 0, h2 = 0;
    bool f1 = false;
    for (int i = v.size() - 1; i >= 0; i--) {
        if (v[i] == v[i-1]) {
            if (!f1) {
                h1 = v[i];
                f1 = true;
            } else {
                h2 = v[i];
                break;
            }
            i--;
        }
    }
    printf("%lld\n", (ll)h1 * h2);
}

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

int main() {
  int N;
  int A[60];
  int B[60];
  int C[60];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i];
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += B[i];
  }
  
  for (int i = 0; i < N - 1; i++) {
    if (A[i+1] - A[i] == 1) {
      sum += C[A[i]-1] ;
    }
  }
  cout << sum << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define int long long int
#define pb push_back
#define mk make_pair
#define flp(i, k, n) for(int i=k; i<n; i++)
#define rev(i, k) for(int i=k; i>=0; i--)
#define F first
#define S second
#define SIZE 100001
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
int pre[SIZE];


int32_t main(void)
{
   int a, b, c, d;
   cin>>a>>b>>c>>d;
   while(a>0 && c>0)
   {
      if(a>0) c-=b;
      if(c>0) a-=d;
   }

   if(a>0) cout<<"Yes\n";
   else cout<<"No\n";
   return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const int dir[][2] = {
	1, 0,
	0, 1,
	-1, 0,
	0, -1
};

string solve( VVI board, int sy, int sx, int gy, int gx )
{
	const int H = board.size(), W = board[0].size();

	int color = board[ sy ][ sx ];
	
	queue< PII > que;
	que.push( MP( sy, sx ) );

	set< PII > visited;
	visited.insert( MP( sy, sx ) );

	while ( !que.empty() )
	{
		auto cur = que.front();
		que.pop();

		if ( cur == MP( gy, gx ) )
		{
			return "OK";
		}

		REP( d, 0, 4 )
		{
			auto next = cur;

			next.fst += dir[d][0];
			next.snd += dir[d][1];

			if ( !( 0 <= next.fst && next.fst < H && 0 <= next.snd && next.snd < W ) || 
				 EXIST( visited, next ) ||
				 board[ next.fst ][ next.snd ] != color )
			{
				continue;
			}

			que.push( next );
			visited.insert( next );
		}
	}

	return "NG";
}			

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

	while ( true )
	{
		int w, h;
		cin >> w >> h;

		if ( !( w | h ) )
		{
			break;
		}

		int sx, sy, gx, gy, n;
		cin >> sx >> sy >> gx >> gy >> n;

		sx--;
		sy--;
		gx--;
		gy--;

		VVI board( h, VI( w, 0 ) );

		REP( i, 0, n )
		{
			int c, d, x, y;
			cin >> c >> d >> x >> y;

			x--;
			y--;

			if ( !d )
			{
				REP( j, 0, 2 )
				{
					REP( k, 0, 4 )
					{
						board[ y + j ][ x + k ] = c;
					}
				}
			}
			else
			{
				REP( j, 0, 4 )
				{
					REP( k, 0, 2 )
					{
						board[ y + j ][ x + k ] = c;
					}
				}
			}
		}

		cout << solve( board, sy, sx, gy, gx ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb(a) push_back(a)
using namespace std;

typedef long long ll;

typedef pair<ll,ll> P1;
typedef pair<int,P1> P2;
typedef pair<P1,int> Pli;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 100002

int dp[MAX_N]={};
vector<int> G[MAX_N];
vector<int> v;
bool d[MAX_N]={};
queue<int> que;

int main() {

	int n,m;
	cin>>n>>m;
	int a1,b1;
	rep(i,m){
		cin>>a1>>b1;
		dp[a1]++;
		dp[b1]++;
	}
	bool flg=true;
	rep(i,n){
		if(dp[i]%2==1)flg=false;
	}
	yesno(flg);
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=0;k<n;++k)

int main() {
	int L, R, d;
	cin >> L >> R >> d;
	int count=0;
	for (int i = L; L < R + 1; L++) {
		if (L % d == 0) count = count + 1; 
	}
	cout << count;
	return 0;
}

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

int main() {
 int A,B;
  cin >> A >> B;
  string ans;
  int c = 0;
  for(int i = A; i <= B; i++){
    ans = to_string(i);
    if(ans.at(0) == ans.at(4)&&ans.at(1) == ans.at(3)){
      c++;
    }
  }
  cout << c << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, T, A, mn, mx, cnt;

int main() {
	cin >> N >> T;
	mn = intmax;
	for (int i = 0; i != N; ++i) {
		cin >> A;
		mn = min(mn, A);
		if (mx == A - mn) {
			++cnt;
		}
		if (mx < A - mn) {
			cnt = 1;
			mx = A - mn;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;

vector<vector<int>> g;
vector<int> vis;
int curr;
void dfs(int u, int &cnt){
    cnt++;
    vis[u] = true;
    for(int v : g[u]){
        if(!vis[v]){
            dfs(v, cnt);
        }
    }
}
int main(){
    Shazam;
    int n,m; cin>>n>>m;
    g = vector<vector<int>>(n+1);
    vis = vector<int> (n+1);
    for(int i = 0 ; i < m; i++){
        int a,b; cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    for(int i = 1; i <=n; i++){
        if(!vis[i]){
            curr = 0;
            dfs(i,curr);
            ans = max(ans, curr);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 21036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> x(n),s(n);
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<n;i++)s[i]=x[i];
    sort(s.begin(),s.end());
    int c1=s[n/2-1],c2=s[n/2];
    for(int i=0;i<n;i++){
        if(x[i]>=c2)cout<<c1<<endl;
        else cout<<c2<<endl;
    }
    return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int64_t>A(90);
  A.at(0)=2;
  A.at(1)=1;
  for(int i=2;i<N+1;i++){
    A.at(i)=A.at(i-1)+A.at(i-2);
  }
  cout<<A.at(N)<<endl;
}

Measured memory_bytes: 3548
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

long long inv_t[200005];
const int mod = 1000000007;

void ext_gcd(ll a, ll b, ll &d, ll &x, ll &y) {
	if(!b) {d = a, x = 1, y = 0;}
	else {
		ext_gcd(b, a % b, d, y, x);
		y -= x * (a / b);
	}
}

ll inv(ll a, ll n) {
	ll d, x, y;
	ext_gcd(a, n, d, x, y);
	return d == 1? (x % n + n) % n: -1;
}

ll fac[200005], fac_inv[200005];

ll C(int n, int m) {
	ll ret = fac[n];
	if(m == 0 or n == m) return 1;
	ret = ret * fac_inv[m] % mod;
	ret = ret * fac_inv[n - m] % mod;
	return ret;
}

int main() {
	int h, w, a, b;
	ll ret = 0;
	scanf("%d%d%d%d", &h, &w, &a, &b);
	for(int i = 1;i <= h + w;i++)
		inv_t[i] = inv(i, mod);
	fac[1] = 1; fac_inv[1] = inv_t[1];
	for(int i = 2;i <= h + w;i++) {
		fac[i] = i * fac[i - 1] % mod;
		fac_inv[i] = inv_t[i] * fac_inv[i - 1] % mod;
	}
	for(int i = 0;i < h - a;i++) {
		ret = (ret + (C(i + b - 1, b - 1) * C(w - b + h - i - 2, h - i - 1) % mod)) % mod;
	}
	printf("%lld\n", ret);
}


Measured memory_bytes: 4864
#include <stdio.h>

int main() {
	double i, P08, P10;
	int A, B, p08, p10, flag=0, ans=0;
	scanf("%d %d", &A, &B);
	
	for (i = 0; i <= 1000; i++) {
		P08 = i * 0.08;
		p08 = P08;
		P10 = i * 0.1;
		p10 = P10;
		if (p08 == A && p10 == B) {
			flag = 1;
			ans = i;
			break;
		}
	}

	if (flag == 1) {
		printf("%d", ans);
	}
	else {
		printf("-1");
	}

	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int i,j,n,q,S[10001],T[501],count=0;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for (i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for (j=0;j<q;j++){
    for (i=0;i<n;i++){
      if (S[i]==T[j]){
	count++;
	break;
      }
    }
  }

  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _001_FindingMissingCards
{

    class Program
    {
        static void Main()
        {
            var numElements = Convert.ToInt32(Console.ReadLine());
            var tmpStrings = Console.ReadLine().Split(' ');
            var elements = new int[numElements];
            for (int i = 0; i < numElements; i++)
            {
                elements[i] = Convert.ToInt32(tmpStrings[i]);
            }
            for (int k = 0; k < numElements - 1; k++)
            {
                Console.Write("{0} ", elements[k]);
            }
            Console.WriteLine("{0}", elements[numElements - 1]);

            for (int i = 1; i < numElements; i++)
            {
                int v = elements[i];
                int j = i - 1;
                while (j >= 0 && elements[j] > v)
                {
                    elements[j + 1] = elements[j];
                    j--;
                }
                elements[j + 1] = v;

                for (int k = 0; k < numElements-1; k++)
                {
                    Console.Write("{0} ", elements[k]);
                }
                Console.WriteLine("{0}", elements[numElements - 1]);
            }
            

        }
    }
}

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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

vector<pair<long long, long long>> factor(long long n) {
  vector<pair<long long, long long>> res;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      long long ex = 0;
      while (n % i == 0) {
        ex++;
        n /= i;
      }
      res.push_back({i, ex});
    }
  }
  if (n != 1) res.push_back({n, 1});
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b;
  cin >> a >> b;
  auto fa = factor(a), fb = factor(b);
  int ans = 1;
  for (auto&& [n, _] : fa) {
    for (auto&& [m, _] : fb) {
      if (n == m) ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int a[100], b[100];
ll dp[100][101] = {0};

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    rep(i, n)rep(j, n + 1)dp[i][j] = (1LL << 32);
    rep(i, n)scanf("%d%d", a+i, b+i);
    rep(i, n)dp[i][i + 1] = 0;
    rep(i, n - 1)dp[i][i + 2] = a[i] * b[i] * a[i + 1] * b[i + 1];

    for(j = 3;j <= n;++j)rep(i, n - j + 1)for(int k = 1;k < j;++k)
    dp[i][i + j] = min(dp[i][i + j], dp[i][i + k] + dp[i + k][i + j] + a[i] * b[i + k - 1] * a[i + k] * b[i + j - 1]);

    pri(dp[0][n]);
    //rep(i, n)rep(j, n + 1)if(i < j)pri3(i, j, dp[i][j]);

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3124
def calcA(x):
    return x*2

def calcB(k, x):
    return x + k

def main():
    n = int(input())
    k = int(input())
    start = 1
    for i in range(n):
        start1 = calcA(start)
        start2 = calcB(k, start)
        if start1 < start2:
            start = start1
        else:
            start = start2
    print(start)
main()

Measured memory_bytes: 2940
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,a,b; cin>>n>>a>>b;
    cout<<min(b,n*a)<<endl;
}

Measured memory_bytes: 256
from queue import Queue

q = Queue()

n = int(input())
li = list(map(int, input().split()))

def gcd(a, b) :
    if (b == 0):
        return a
    return gcd(b, a % b)

for i in li:
    q.put(i)


while True:
    a = q.get()
    if q.empty():
        break
    b = q.get()
    q.put(gcd(a, b))

print(a)

Measured memory_bytes: 15192
// 1154
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    string s, ans; cin >> s;
    For(i, 0, s.size()) {
        if(s[i] == '0') ans += '0';
        else if(s[i] == '1') ans += '1';
        else {
            if(ans.size() > 0)
            ans.erase(ans.size()-1);
        }
    }
    cout << ans;
    

    
    
    
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 2000000000000000000 //2e18
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,s,pos,sum=0,flag=0,count=0;
    string S,T,U; 
    int mx;
    cin>>n>>mx;
    vi weight(n),value(n),dp(100001,INF);
    rep(i,0,n) cin>>weight[i]>>value[i];//dp[value[i]]=weight[i];
    dp[0]=0;
    rep(j,0,n)
    {
        rep(i,100001,value[j])
        {
            if(value[j]<=i)
            {
                if(dp[i-value[j]]<INF)
                {
                    dp[i]=min(dp[i],weight[j]+dp[i-value[j]]);
                }
            }
        }
    }
    rep(i,100001,0)
    {
        if(dp[i]<=mx)
        {
            cout<<i;
            return;
        }
    }
}

 

signed main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);

    while(b != 0){
        ll t = a;
        a = b;
        b = t%b;
    }

    return a;
}

ll f(ll A, ll C, ll D){
    ll a = A/C;
    ll b = A/D;
    ll c = A/(C*D/gcd(C,D));
    ll d = a+b-c;
    return A-d;
}

int main(){
    ll A, B, C, D; cin >> A >> B >> C >> D;
    cout << f(B, C, D) - f(A-1, C, D) << endl;
}

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

        #define ll long long
        #define pb push_back
        #define printV(v) for(int i=0;i<(int)v.size();i++){cout << v[i]<< " ";} cout << endl
        #define printRev(v) for(int i=(int)v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
        #define sortV(v) sort(v.begin(),v.end())
        #define revV(v) reverse(v.begin(),v.end())
    

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;
        const int N = 3009;
       
        
            
        void solve(){
            cin >> n;
            int arr[n];
            int gcd = 0;
            vector<int> freq(1000009,0);
            for(int i=0;i<n;i++){
                cin >> arr[i];
                if(gcd == 1) continue;
                if(i == 0) gcd = arr[i];
                else gcd = __gcd(gcd,arr[i]);
            }
            bool flag = true;
            for(int i=0;i<n;i++){
                if(!flag) break;
                for(int j=1; j<= sqrt(arr[i]); j++){
                    if(arr[i] % j == 0){
                        if(j != 1) freq[j]++;
                        freq[arr[i]/j]++;
                        if(j*j == arr[i]) freq[j]--;
                        if( (freq[j] > 1 || freq[arr[i]/j] > 1)){
                            flag = false;
                            break;
                        }
                    }
                }
            }
            if(flag){
                cout << "pairwise coprime" << endl;
                return;
            }

            if(gcd == 1){
                cout << "setwise coprime";
                return;
            }
            cout << "not coprime";

        }
        


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

            
          

            int cases = 1;
            //cin >> cases;

            while(cases--) solve();
            return 0;

        }


Measured memory_bytes: 11164
#include <stdio.h>

int main(void)
{
    int t[2][2], k;
    int ans = 0, s, g;
    scanf("%d%d%d%d%d", &t[0][0], &t[0][1], &t[1][0], &t[1][1], &k);
    s = t[0][0] * 60 + t[0][1];
    g = t[1][0] * 60 + t[1][1];

    printf("%d\n", g - s - k);
    return 0;
}

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

bool check(string x){
    if (x.length()%2==1) return false;
    if (x.substr(0, x.length()/2)!=x.substr(x.length()/2)){
        return false;
    }
    return true;
}

int main() {
	string S;
	cin >> S;
	for (int i=S.length()-1; ; i--){
	    if (check(S.substr(0,i))) {
	        cout << i<< endl;
	        return 0;
	    }
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
const int MOD=1e9+7;
const int INF=1e18;
void io(string s="file"){freopen((s + ".in").c_str(), "r", stdin);freopen((s + ".out").c_str(), "w", stdout);}

int dp[2001];


int f(int s){
    if(s<0 || s==1 || s==2)return 0;
    if(s==0)return 1;
    int &ans=dp[s];
    if(ans!=-1)return ans;
    ans=0;
    for(int j=3;j<=s;j++){
        ans+=f(s-j);
        ans%=MOD;
    }
    return ans;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int S;cin>>S;
    memset(dp,-1,sizeof dp);
    cout<<f(S);
}

Measured memory_bytes: 3688
#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define fr first
#define sc second
typedef pair<int,int> P;
int main(){
  int X,Y,Z,N,E,A;
  double dp[51][5001];
  int jump[4];
  P ivent[51];
  while(cin >> X >> Y >> Z , X){
    for(int i = 0 , limit = 0 ; i <= Y ; i++ , limit += 100 ){
      ivent[i] = P( 0 , 0 );
      for(int j = 0 ; j <= limit ; j++ ) dp[i][j] = 0.0;
    }
    dp[0][0] = 1.0;

    for(int i = 0 ; i < X ; i++ ){
      cin >> jump[i];
    }
    for(int i = 0 ; i < Z ; i++ ){
      cin >> N >> E >> A;
      switch(E){
      case 1: ivent[N].fr = A; break;
      case 2: ivent[N].sc = A; break;
      case 3: ivent[N].sc = -A; break;
      }
    }
    for(int i = 0 , limit = 0 ; i < Y ; i++ , limit += 100 ){
      for(int j = 0 ; j <= limit ; j++ ){
        if(dp[i][j]){
          for(int k = 0 , p_mas , p_money ; k < X ; k++ ){
            p_mas = min( i + jump[k] , Y );
            p_money = max(0,ivent[p_mas].sc + j );
            p_mas = min( p_mas + ivent[p_mas].fr , Y );

            dp[p_mas][p_money] += dp[i][j] / X;
          }
        }
      }
    }
    double ans = 0.0;
    for(int i = 0 ; i < 5001 ; i++ ){
      ans += dp[Y][i] * i;
    }
    cout << (int)ans << endl;
  }
}

Measured memory_bytes: 2348
#include <iostream>

using namespace std;
#include <string>
typedef long long int ll;
#include <algorithm>
#include <stack>
#include <vector>
#include <array>
#include <queue>
#include <bitset>
#include <math.h>

int main(){

  ll N;
  cin >> N;
  //vector<int> a(N,0);
  ll num = 1;
  ll count = 0;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    if(a==num){
      num += 1;
    }else{
      count += 1;
    }
  }

  if(num == 1){
    cout << -1;
  }else{
    cout << count;
  }


  return 0;

}


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

int main()
{
    int m, f, r;

    for (cin >> m >> f >> r; ~m | ~f | ~r; cin >> m >> f >> r){

        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 || (m + f >= 30 && r >= 50)) cout << 'C' << endl;
        else if (m + f >= 30) cout << 'D' << endl;
        else cout << 'F' << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <queue>
#include <cmath>
#include <cstdio>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

class UnionFind {
  vector<int> a;
public:
  UnionFind(int n) { REP(i, 0, n) a.push_back(i); }
  int find(int i) { return a[i] == i ? i : (a[i] = find(a[i])); }
  bool unite(int i, int j) {
    if(find(i) == find(j)) return false;
    a[find(i)] = find(j);
    return true;
  }
};

struct edge {
  int a, b;
  double d;
  bool operator<(const edge e) const {
    return d > e.d;
  }
};

int N;
double X[100], Y[100], Z[100], R[100];

double dist(int i, int j) {
  double dx = X[i] - X[j];
  double dy = Y[i] - Y[j];
  double dz = Z[i] - Z[j];
  double d = sqrt(dx * dx + dy * dy + dz * dz);
  if(d < R[i] + R[j]) return 0;
  return d - R[i] - R[j];
}

int main(void) {
  while(cin >> N, N) {
    REP(i, 0, N) cin >> X[i] >> Y[i] >> Z[i] >> R[i];

    priority_queue<edge> q;
    REP(i, 0, N) REP(j, i + 1, N) q.push((edge) { i, j, dist(i, j) });

    UnionFind uf(N);
    double ans = 0;
    while(q.size()) {
      int a = q.top().a, b = q.top().b;
      double d = q.top().d;
      q.pop();
      if(uf.unite(a, b)) ans += d;
    }
    printf("%.3lf\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3188
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    t, x = list(map(int,ipti().split()))
    print(t/x)

if __name__ == '__main__':
    main()

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

int main(){
    int N;
    int min_a, max_a;
    cin >> N;
    min_a = 1001;
    max_a = -1;

    int tmp;
    for(int i = 0; i < N; ++i){
        cin >> tmp;
        min_a = min(min_a, tmp);
        max_a = max(max_a, tmp);
    }

    cout << max_a - min_a << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());

            int Y = 0;
            int T = X;

            while(T > 0)
            {
                Y += T % 10;
                T = T / 10;
            }
            
            if(X % Y ==0)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
loop do
    a = gets.split.map(&:to_i)
    break if a.all? {|x| x == 0}
    x, y, z = a[0] + a[3], a[1] + a[4], a[2] + a[5]
    n = 0
    if x > 0
        n += x / 3
        x %= 3
        if x == 0
            n -= 1
            x = 3
        end
    end
    if y > 0
        n += y / 3
        y %= 3
        if y == 0
            n -= 1
            y = 3
        end
    end
    if z > 0
        n += z / 3
        z %= 3
        if z == 0
            n -= 1
            z = 3
        end
    end
    r = [x, y, z].sort
    if r[0] == 3
        n += 3
    elsif r[0] == 2
        n += 2
    elsif r[0] == 1 && r[1] <= 2
        n += 1
    else
        n += 1 if r[1] == 3
        n += 1 if r[2] == 3
    end
    puts n
end


Measured memory_bytes: 6920
#include<stdio.h>

int main(){
  char a[4]; scanf("%s",a);
  if(a[0]==a[1]){
    if(a[2]==a[3] && a[0]!=a[2]) printf("Yes\n");
    else printf("No\n");
  }else if(a[0]==a[2]){
    if(a[1]==a[3] && a[1]!=a[2]) printf("Yes\n");
    else printf("No\n");
  }else if(a[0]==a[3]){
    if(a[2]==a[1] && a[0]!=a[2]) printf("Yes\n");
    else printf("No\n");
  }else printf("No\n");
    
  
  /*int n,a,b; scanf("%d%d%d",&n,&a,&b);
  if(n*a<b) printf("%d\n",n*a);
  else printf("%d\n",b);*/
  return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
    int a[101];
    int n;
    int ans;
void solve(int left, int right) {
    if(left > right) return;
    for(int i = left; i <= right; i++) {
        if(a[i] == 0) {
            solve(left, i - 1);
            solve(i + 1, right);
            return;
        }
    }
    int mini = 300;
    for(int i = left; i <= right; i++) {
        mini = min(a[i], mini);
    }
    for(int i = left; i <= right; i++) {
        a[i] -= mini;
    }
    ans += mini;
    solve(left, right);
    return;
}

int main() {
    //cout.precision(10);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    solve(1, 100);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d %d",&A,&B);
    if(A==1 && B==2)
        printf("3\n");
    else if(A==2 && B==3)
        printf("1\n");
    else if(A==3 && B==1)
        printf("2\n");
    else if (A==3 && B==2)
        printf("1\n");
    else if(A==2 && B==1)
        printf("3\n");
    else
        printf("2\n");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main{
  	public static int[] array = new int[100000];
  public static int count = 1;
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int s = sc.nextInt();
      array[0] = s;
      System.out.println(run(s));
      
    }
  	public static int run(int s){
      	if(count > 1)
        for(int i = 0;i<count-1;i++){
        	if(array[count-1] == array[i]){
            	return count;
            }
        }
    	if(s%2==0){
          array[count] = s/2;
          count++;
          return run(s/2);
        }
        else{
          array[count] = s*3+1;
          count++;
          return run(s*3+1);
        }
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (a[0] > 0) {
    cout << -1 << '\n';
    return 0;
  }
  int cnt = 1;
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] > a[i - 1] + 1) {
      cout << -1 << '\n';
      return 0;
    } else if (a[i] == a[i - 1] + 1) {
      ans += (long long)(cnt - 1) * a[i - 1];
      cnt = 1;
    } else if (a[i] == a[i - 1]) {
      cnt++;
    } else {
      ans += (long long)cnt * a[i - 1];
      cnt = 1;
    }
  }
  ans += (long long)cnt * a[n - 1];
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int i = 0; i < n; i++ ){ cout << x[i] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second
     
using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head


struct Mod{
  unsigned n;
  Mod() : n(0){}
  Mod( ll x ){
    if( x < 0 ) n = x%MOD+MOD;
    else n = x%MOD;
  }
};
Mod operator + ( Mod a  , Mod b ){ return Mod( a.n + b.n ); }
Mod operator +=( Mod &a , Mod b ){ return a = a + b; }
Mod operator - ( Mod a ){ return Mod( MOD - a.n ); }
Mod operator - ( Mod a  , Mod b ){ return Mod( a.n + MOD - b.n ); }
Mod operator -=( Mod &a , Mod b ){ return a = a - b; }
Mod operator * ( Mod a  , Mod b ){ return Mod( (ll)a.n * b.n ); }
Mod operator *=( Mod &a , Mod b ){ return a = a * b; }
Mod modpow( Mod x , ll k ){
  Mod res = 1;
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}
ll extgcd( ll a , ll b , ll &x , ll &y ){
  ll d = a;
  if( b != 0 ){
    d = extgcd( b , a % b , y , x );
    y -= a / b * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}
Mod inv( Mod a ){ ll x, y; assert( extgcd( a.n , MOD , x , y ) == 1 ); return Mod( x ); }
Mod operator / ( Mod a  , Mod b ){ return Mod( (ll)a.n * inv(b).n ); }
Mod operator /=( Mod &a , Mod b ){ return a = a / b; }


Mod dp[72][4][2];

ll n;
int len;
int a[72];

int main(){

  n = in();
  for( len = 0; n > 0; len++ ){
    a[len] = n % 2;
    n /= 2;
  }

  // SHOWA( a , len );

  dp[0][0][0] = 1;
  REP( i , len ){
    REP( j , 4 ){
      int ju = j % 2;
      int jv = j / 2;
      REP( k , 2 ){
	REP( l , 2 ){
	  REP( m , l+1 ){
	    int nu = l ^ m;
	    int nv = ( l + m + k ) % 2;
	    int nk = ( l + m + k ) / 2;
	    int nju = nu > a[i] or ( ju and nu >= a[i] );
	    int njv = nv > a[i] or ( jv and nv >= a[i] );
	    int nj = nju + njv * 2;
	    dp[i+1][nj][nk] += dp[i][j][k];
	  }
	}
      }
    }
  }

  
  cout << dp[len][0][0].n << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
  char number[1001];
  int sum, i;
  char ch;
  while(1) {
    scanf("%s", number);
    if (strcmp(number, "0") == 0) break;
    i = 0;
    sum = 0;
    while((ch = number[i]) != '\0') {
      sum += number[i] - '0';
      i++;
    }
    printf("%d\n", sum);
  }
  return 0;
}



Measured memory_bytes: 2044
import sys
import math
input = sys.stdin.buffer.readline
 
def main():
    a,b,c,d = map(int,input().split())
    MOD = 10**9+7
    N = c+d+5
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1
 
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    def comb(x,y):
        return (fac[x+y]*pow(fac[x],MOD-2,MOD)*pow(fac[y],MOD-2,MOD))%MOD
 
    print((comb(c+1,d+1)-comb(c+1,b)-comb(d+1,a)+comb(a,b))%MOD)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 82200
#include<stdio.h>
int main(void)
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a<=b&&b<=c){
    printf("%d %d %d\n",a,b,c);
  }else if(a<=c&&c<=b){
    printf("%d %d %d\n",a,c,b);
  }else if(b<=a&&a<=c){
    printf("%d %d %d\n",b,a,c);
  }else if(b<=c&&c<=a){
    printf("%d %d %d\n",b,c,a);
  }else if(c<=a&&a<=b){
    printf("%d %d %d\n",c,a,b);
  }else{
    printf("%d %d %d\n",c,b,a);
  }
  return 0;
}     


Measured memory_bytes: 1780