akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

UL D;
LL C[26];
LL S[400][26];

UL T[400];
LL Last[400][26];
LL Score[26] = {};
LL Sum = 0;

LL MaxScore = -1000000000;
UL ans[400];

mt19937 mt;

void CalcScore(UL i){
 Sum -= Score[i];
 Score[i]=0;
 rep(d,D){
  Last[d+1][i]=Last[d][i];
  if(T[d]==i) {
   Score[i] += S[d][i];
   Last[d+1][i]=d;
  }
  Score[i] -= C[i] * ((LL)d-Last[d+1][i]);
 }
 Sum += Score[i];
}

void Change(){
 UL d = mt() % D;
 UL t = mt() % 26;
 UL TBuf = T[d]; T[d] = t;
 CalcScore(TBuf);
 CalcScore(t);
 if (Sum <= MaxScore - 500) {
  T[d] = TBuf;
  CalcScore(t);
  CalcScore(TBuf);
 }
 else if(MaxScore < Sum) {
  rep(d,D) ans[d] = T[d];
  MaxScore = Sum;
 }
}

void Swap(){
 UL d = mt() % (D-1);
 if(T[d]==T[d+1]) return;
 swap(T[d],T[d+1]);
 CalcScore(T[d]);
 CalcScore(T[d+1]);
 if (Sum <= MaxScore - 500) {
 swap(T[d],T[d+1]);
  CalcScore(T[d]);
  CalcScore(T[d+1]);
 }
 else if(MaxScore < Sum) {
  rep(d,D) ans[d] = T[d];
  MaxScore = Sum;
 }
}

void Step(){
 Change();
 Swap();
}

int main() {
 ULL StartP = clock();
 mt.seed(999999999);

 scanf("%u", &D);
 rep(i,26) scanf("%lld",&C[i]);
 rep(i,D)rep(j,26) scanf("%lld",&S[i][j]);
 
 rep(d,D) T[d] = mt() % 26;
 rep(i,26) CalcScore(i);
 MaxScore = Sum;
 rep(i,26) Last[0][i] = -1;
 while(true){
  ULL CheckP = clock();
  if(CheckP-StartP > CLOCKS_PER_SEC * 3 / 2) break;
  Step();
 }
 
 rep(i,D) printf("%u\n", ans[i]+1);
 
 return 0;
}



Measured memory_bytes: 3972
import java.util.*;

public class Main{
	// N A B C X
	// Y1 Y2 ... YN 
	// x' = (A テδ?x + B) mod C
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n, a, b, c, x;
		
		while(true){
			// ティツェツュテ」ツ?ソテ・ツ渉姪」ツつ?
			n = in.nextInt();
			a = in.nextInt();
			b = in.nextInt();
			c = in.nextInt();
			x = in.nextInt();
			
			if(n == 0 && a == 0 && b == 0 && c == 0 && x == 0) break;
			
			int[] y = new int[n];
			for(int i=0;i<n;i++){
				y[i] = in.nextInt();
			}
			
			System.out.println(solve(n,a,b,c,x,y));
		}
	}

	static int solve(int n, int a, int b, int c, int x, int[] y){
		int count = 0; // frameテヲツ閉ー
		
		if(n==1 && y[0]==x) return 0;
		
		for(int i=0;i<n;i++){
			while(true){ 
				//System.out.println("i="+i+" x="+x+" count="+count);
				if(count>10000 || y[i]==x){
					x = (a*x+b)%c; if(i+1 < n)count++; // テヲツャツ。テ」ツ?ォティツ。ツ古」ツ?湘」ツ?淌」ツつ?」ツ?ョテ・ツ?ヲテァツ青?
					break;
				}
				count++;
				x = (a*x+b)%c;
			}
		}
		
		return (count > 10000 ? -1 : count);
	}
}

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

int main() {
  int n; cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (v.at(j) >= i)
      cnt++;
    }
    if (cnt >= i) {
      ans = i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>>s(h,vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)cin>>s[i][j];
    }
    int m=0;
    for(int sx=0;sx<h;sx++){
        for(int sy=0;sy<w;sy++){
            for(int gx=0;gx<h;gx++){
                for(int gy=0;gy<w;gy++){
                    vector<vector<int>>dist(h,vector<int>(w,1000));//startからの距離
                    if(sx==gx && sy==gy)continue;
                    if(s[sx][sy]=='#' || s[gx][gy]=='#')continue;
                    dist[sx][sy]=0;
                    queue<int>x;
                    queue<int>y;
                    x.push(sx);
                    y.push(sy);
                    while(x.front()!=gx || y.front()!=gy){
                        int xf=x.front();
                        int yf=y.front();
                        if(xf<h-1 && s[xf+1][yf]=='.' && dist[xf+1][yf]==1000){//x正方向
                            x.push(xf+1);
                            y.push(yf);
                            dist[xf+1][yf]=dist[xf][yf]+1;
                        }
                        if(yf<w-1 && s[xf][yf+1]=='.' && dist[xf][yf+1]==1000){//y正方向
                            x.push(xf);
                            y.push(yf+1);
                            dist[xf][yf+1]=dist[xf][yf]+1;
                        }
                        if(xf>0 && s[xf-1][yf]=='.' && dist[xf-1][yf]==1000){//x負方向
                            x.push(xf-1);
                            y.push(yf);
                            dist[xf-1][yf]=dist[xf][yf]+1;
                        }
                        if(yf>0 && s[xf][yf-1]=='.' && dist[xf][yf-1]==1000){//y負方向
                            x.push(xf);
                            y.push(yf-1);
                            dist[xf][yf-1]=dist[xf][yf]+1;
                        }
                        x.pop();
                        y.pop();
                    }
                    m=max(m,dist[x.front()][y.front()]);
                }
            }
        }
    }
    cout<<m<<endl;
    return 0;
}

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

using namespace std;


int main()
{
  int N, dp1[1 << 10], dp2[1 << 10];

  string S;
  while(cin >> N, N) {
    memset(dp1, 0, sizeof(dp1));

    cin >> S;
    for(int i = 0, curr = 0; i < N; i++) {
      if(S[i] == 'u') {
        curr = 0;
      } else {
        dp1[curr] |= 1 << (S[i] - '0');
        curr |= 1 << (S[i] - '0');
      }
    }
    for(int i = 0; i < (1 << 10); i++) {
      dp2[i] = dp1[i];
    }
    for(int i = 1; i < 10; i++) {
      for(int j = 0; j < (1 << 10); j++) {
        for(int k = 0; k < (1 << 10); k++) {
          if((j & k) != k) continue;
          if(dp2[j - k] == 0) continue;
          if(dp1[k] == 0) continue;
          dp2[j] |= dp2[j - k] | dp1[k];
        }
      }
    }
    if([&]()
    {
      for(int i = 0; i < (1 << 10); i++) {
        if(dp2[i] && (dp2[i] & i) == dp2[i]) return (false);
      }
      return (true);
    }
        ())
      cout << "SAFE" << endl;
    else {
      cout << "UNSAFE" << endl;
    }
  }
}

Measured memory_bytes: 3236
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int a;
string s;

int main()
{
   cout << fixed << setprecision(10);
   cin >> a >> s;
   if (a >= 3200) cout << s << endl;
   else cout << "red" << endl;
   return 0;
}



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

int main() {
	int A, B, X;
	std::cin >> A >> B >> X;
	if (A <= X && X <= A + B) {
		std::cout << "YES" << std::endl;
	} else {
		std::cout << "NO" << std::endl;
	}
	return 0;
}

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

int main() {
    ll n,c,k,i,ans=0;
    cin >> n >> c >> k;
    ll t[n];
    rep(i,n) cin >> t[i];
    sort(t,t+n);
    ll first=0;
    while(first<n){
        for(i=first+1;i<min(first+c,n);i++){
        if(t[i] > t[first]+k){
            break;
        }
    }
    first=i;
    ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <functional>
#define int long long 
#define pi pair<int,int> 
#define endl "\n"
using namespace std ;

const int inf = 1e15 ;
const int size = 1e5 + 5 ;
int n , k ,dp[size][3],a[size][3] ;

int fun( int ind , int prev , int sum )
{
     if(ind == n )
     {
        return 0 ;
     } 

     int &ans = dp[ind][prev] ;
     if(ans!=-1) return ans ;
     ans = 0 ;
     for(int j = 0; j < 3 ; j++ )
     {
         if(j!=prev) ans = max(ans,a[ind][j]+fun(ind+1,j,sum+a[ind][j]));
     }
     return ans ;
}



int32_t main() 
{


     /*#ifndef ONLINE_JUDGE 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
     #endif*/ 
     memset(dp,-1,sizeof(dp));
     cin >> n ;
     for(int i = 0 ; i < n ; i++ ) cin >> a[i][0] >> a[i][1] >> a[i][2] ;
     int ans = fun(0,1,0) ;
     ans = max(ans,fun(0,0,0));
     ans = max(ans,fun(0,2,0)) ;
     cout<<ans<<endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)cin>>a[i];
    vector<int> ans;
    vector<vector<int> > v(n+1);
    int b[n+1]={0};
    for(int i=1;i<=n;i++){
        for(int j=1;j*j<=i;j++){
            if(j*j==i){
                v[i].pb(j);
            }
            else if(i%j==0){
                v[i].pb(j);
                v[i].pb(i/j);
            }
        }
    }
    int maki;
    for(int i=n;i>=1;i--){
        if((b[i]%2)^a[i]){
            ans.pb(i);
            maki=v[i].size();
            for(int j=0;j<maki;j++){
                b[v[i][j]]++;
            }
        }
    }
    sort(be(v));
    maki=ans.size();
    cout << maki<<endl;
    for(int i=0;i<maki;i++){
        cout << ans[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 22648
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			int N = Integer.parseInt(br.readLine());
			int[] T = strToIntArray(br.readLine());
			int M = Integer.parseInt(br.readLine());
			int[] P = new int[M];
			int[] X = new int[M];
			for (int i = 0; i < M; i++) {
				int[] a = strToIntArray(br.readLine());
				P[i] = a[0] - 1;
				X[i] = a[1];
			}

			for (int i = 0; i < M; i++) {

				int sum = 0;
				for (int j = 0; j < N; j++) {
					if (P[i] == j) {
						sum += X[i];
					} else {
						sum += T[j];
					}
				}

				System.out.println(sum);
			}

		} catch (Exception e) {
			System.err.println("Error:" + e.getMessage());
		}
	}

	// Stringで読みこんでスペースで分割されている数字を配列に入れるやつ
	// 利用法 int[] A = strTointArray(br.readLine());
	static int[] strToIntArray(String S) {
		String[] strArray = S.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}
}


Measured memory_bytes: 8272
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

int main() {
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  std::vector<bool > positive(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  std::sort(A.begin(), A.end());
  int positive_count = 1;
  int negative_count = 1;
  positive[0]=false;
  positive[N-1]=true;
  for (int i=1; i<N-1; i++){
    if (A[i]>=0) {
      positive[i]=true;
      positive_count++;
    } else {
      positive[i]=false;
      negative_count++;
    }
  }
  long long ans = 0;
  for (int i=0; i<N; i++){
    if (positive[i]){
      ans += A[i];
    } else {
      ans -= A[i];
    }
  }
  printf("%lld\n", ans);
  long long left = A[0];
  for (int i=0; i<positive_count-1; i++){
    printf("%lld %d\n", left, A[i+negative_count]);
    left -= A[i+negative_count];
  }
  printf("%d %lld\n", A[N-1],left);
  left = A[N-1]-left;
  for (int i=0; i<negative_count-1; i++){
    printf("%lld %d\n", left, A[1+i]);
    left -= A[i+1];
  }
  return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<stdio.h> 
using namespace std;
string s,t;
int main()
{
	int i,j;
    int a[31]={0};
	int b[31]={0}; 
	cin>>s>>t;
	for(i=s.length()-1;i>=0;i--)
     {
     	if(s[i]==t[i])
     	{
     	    a[s[i]-'a'+1]=b[s[i]-'a'+1]=s[i]-'a'+1;	
     	    continue;
		}
		else 
		{
			if(b[t[i]-'a'+1]==0&&a[s[i]-'a'+1]==0)
			{
				b[t[i]-'a'+1]=s[i]-'a'+1;
				a[s[i]-'a'+1]=t[i]-'a'+1;
			}
			else if(a[s[i]-'a'+1]!=0)
			{
				if(a[s[i]-'a'+1]==t[i]-'a'+1) 
				{
					continue;
				}
				else 
				{
				   cout<<"No";
				   return 0;	
				}
			}
			else if(b[t[i]-'a'+1]!=0)
			{
				if(b[t[i]-'a'+1]==s[i]-'a'+1)
				{
					continue;
				}
				else 
				{
					cout<<"No";
					return 0;
				}
			}			
		}		
	 }
    cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll a,n,b,i,j,k,l,m,s=0,op=0;
	cin>>n>>k;
	ll h[n+1]={0},dp[n+1]={0};
	for(i=0;i<n;i++) cin>>h[i];
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	for(i=2;i<n;i++)
	{s=INT_MAX;
		for(j=max((ll)0,i-k);j<i;j++)
		{//s=INT_MAX;
			op=dp[j]+abs(h[j]-h[i]);
			s=min(op,s);
		}
		dp[i]=s;
	}
//	for(i=0;i<n;i++) cout<<dp[i]<<" ";
	cout<<dp[n-1];

}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

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

const int INF = 1000000007;

int main(){
	int n; cin>>n;
	int a[210000]={0};
	int b[210000]={0};
	int x[2]={1, -1};
	for(int i=0;i<n;i++) cin>>a[i];

	if(n%2 == 0){
		int j=1;
		for(int i=0;i<n/2;i++){
			b[(n/2-1) - i] = a[j];
			j += 2;
		}
		j=0;
		for(int i=0;i<n/2;i++){
			b[(n/2) + i] = a[j];
			j += 2;
		}
	}

	if(n%2 != 0){
		int j=0;
		for(int i=0;i<=n/2;i++){
			b[(n/2) - i] = a[j];
			j += 2;
		}
		j=1;
		for(int i=0;i<n/2;i++){
			b[(n/2+1) + i] = a[j];
			j += 2;
		}
	}


	for(int i=0;i<n;i++) cout<<b[i]<<" ";
	cout<<endl;

	return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int N, A, B, C;
	cin >>N >>A >>B >>C;
	vector<string> s(N, "");
	Rep0(i, N)
		cin >>s.at(i);
	//
	vector<char> a(N, ' ');
	bool OK=true;
	Rep0(i, N) {
		string S=s.at(i);
		if ("AB"==S)
			if (0==A)
				if (0==B) 
					OK=false;
				else
					a.at(i)='A';
			else if (0==B) // 0!=A, 0==B
				a.at(i)='B';
			else // 0!=A, 0!=B
				if (1==A)
					if (1==B) // 1==A==B
						if (i==N-1) // Last
							a.at(i)='A';// Either A or B
						else // Not last, check next 
							if ("AC"==s.at(i+1))
								a.at(i)='A';
							else
								a.at(i)='B';
					else // 1==A, B>1
						a.at(i)='A';
				else // A>1
					a.at(i)='B';
		else if ("AC"==S)
			if (0==A)
				if (0==C) 
					OK=false;
				else
					a.at(i)='A';
			else if (0==C) // 0!=A, 0==C
				a.at(i)='C';
			else // 0!=A, 0!=C
				if (1==A)
					if (1==C) // 1==A==C
						if (i==N-1) // Last
							a.at(i)='A';// Either A or C
						else // Not last, check next 
							if ("AB"==s.at(i+1))
								a.at(i)='A';
							else
								a.at(i)='C';
					else // 1==A, C>1
						a.at(i)='A';
				else // A>1
					a.at(i)='C';
		else // "BC"
			if (0==B)
				if (0==C) 
					OK=false;
				else
					a.at(i)='B';
			else if (0==C) // 0!=B, 0==C
				a.at(i)='C';
			else // 0!=B, 0!=C
				if (1==B)
					if (1==C) // 1==B==C
						if (i==N-1) // Last
							a.at(i)='B';// Either B or C
						else // Not last, check next 
							if ("AB"==s.at(i+1))
								a.at(i)='B';
							else
								a.at(i)='C';
					else // 1==B, C>1
						a.at(i)='B';
				else // B>1
					a.at(i)='C';
		if (!OK)
			break;
		Rep0(i, 2) {
			char ss=S.at(i);
			if ('A'==ss)
				A--;
			else if ('B'==ss)
				B--;
			else
				C--;
		}
		if ('A'==a.at(i))
			A +=2;
		else if ('B'==a.at(i))
			B +=2;
		else
			C +=2;
	}
	if (OK) {
		cout <<"Yes" <<endl;
		Rep0(i, N)
			cout <<a.at(i) <<endl;
	} else
		cout <<"No" <<endl;
	return 0;
}



Measured memory_bytes: 6432
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main (void) {
    int N;

    cin >> N;
    int A[N], B[N], C[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; i++) {
        cin >> C[i];
    }

    sort(A, A + N);
    sort(B, B + N);
    sort(C, C + N);

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll a = lower_bound(A, A + N, B[i]) - A;
        ll b = N - (upper_bound(C, C + N, B[i]) - C);
        ans += a * b;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;

    A*=100; B*=100;

    int W=A,S=0;
    for(int a=0;a<=F;a+=A) for(int b=0;a+b<=F;b+=B){
        for(int c=0;a+b+c<=F;c+=C) for(int d=0;a+b+c+d<=F;d+=D){
            int w=a+b,s=c+d;
            if(w>0 and s<=w/100*E and s*(W+S)>S*(w+s)){
                W=w; S=s;
            }
        }
    }
    cout<<W+S<<' '<<S<<endl;
 
}


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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,ans=0;
    cin>>a>>b>>c;
    if(a==b&&b==c){
        if(a%2==0){
            cout << -1<<endl;
        }
        else{
            cout <<0<<endl;
        }
    }
    else{
        while(a%2==0&&b%2==0&&c%2==0){
            int x=a,y=b,z=c;
            a=(y+z)/2;
            b=(x+z)/2;
            c=(z+y)/2;
            ans++;
        }
        cout <<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  	int n, m, sum = 0, ans = 0;
  	cin >> n >> m;
  	int a[n];
  	for (int i = 0; i < n; i++) {
      	cin >> a[i];
      	sum += a[i];
    }
  	for (int i = 0; i < n; i++) {
      	if (a[i] * (m * 4) >= sum) {
          	ans++;
        }
    }
  	if (ans >= m) {
      	cout << "Yes" << endl;
    } else {
      	cout << "No" << endl;
    }
  
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int r, g, b;

bool solve() {
    return (r*100 + g*10 + b) % 4 == 0;
}

void input() {
    cin >> r >> g >> b;
}

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

    input();
    cout << (solve() ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int,x)
function main()
    n = map(parseInt, split(readline()))
    v = map(parseInt, split(readline()))
  	c = map(parseInt, split(readline()))
  vc = v - c
  a = sum(vc[find(vc .>=0)])
    println(Int64(a))
end
main()

Measured memory_bytes: 176164
N = int(input())
A = list(map(int, input().split()))

li = []

for i in range(N-1):
    if A[i+1] - A[i] > 0:
       li.append('+')
    elif A[i+1] - A[i] < 0:
        li.append('-')
    else:
        pass
# print(li)
ans = 1
p = 0
m = 0
for i in li:
    if i == '+':
        p = 1
    elif i == '-':
        m = 1
    if p == 1 & m == 1:
        ans += 1
        p = 0
        m = 0
print(ans)

Measured memory_bytes: 20452
gets
c=0
puts$<.map{|s|a=0
b=s.chop.bytes.map{|e|a+=81-e*2}.min
[-b,a-b]}.sort_by{|a,b|a<b ?a:2e9-b}.map{|a,b|b+c+=a-b}.max>0||c<0?:No: :Yes

Measured memory_bytes: 103396
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getval(_T& a) {
	std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int N;
	getval(N);

	LLONG tcnt = 0, acnt = 0;
	for (int i = 0; i < N; i++) {
		LLONG ti, ai;
		getval(ti, ai);

		if (tcnt <= ti && acnt <= ai) {
			tcnt = ti;
			acnt = ai;
		}
		else if (ti == ai) {
			tcnt = std::max(tcnt, acnt);
			acnt = tcnt;
		}
		else {
			LLONG nt = tcnt / ti + (tcnt % ti ? 1 : 0);
			LLONG na = acnt / ai + (acnt % ai ? 1 : 0);
			LLONG mul = std::max(nt, na);

			acnt = ai * mul;
			tcnt = ti * mul;
		}
	}
	printf("%lld\n", acnt + tcnt);
}


Measured memory_bytes: 3764
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>
using namespace std;
#define int long long

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(NULL);
        std::cout.tie(NULL);
    }

    int w, h;
    cin >> w >> h;
    if (w == 1 || h == 1) {
        cout << 1;
        return 0;
    }
    int ans = w * (h / 2LL) + ((w + 1LL) / 2LL) * (h % 2LL);
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int x, a, b;
	cin >> x >> a >> b;

	if (abs(x - a) > abs(x - b))
		cout << 'B';
	else
		cout << 'A';

	cout << endl;
		
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

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

    ll x,k,d;
    cin>>x>>k>>d;
    ll c=abs(x)/d;
    if(c>k){
        cout<<abs(x+(x<0?d*k:-d*k))<<endl;
        return 0;
    }
    ll t1=x%d,t2=t1+(t1<0?d:-d);
    if(c==k){
        cout<<abs(t1)<<endl;
        return 0;
    }
    ll b=k-c;
    if(b&1)cout<<abs(t2)<<endl;
    else cout<<abs(t1)<<endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 105;
char arr[MAX][MAX];
int dp[MAX][MAX], pre[MAX][MAX];
int main()
{
	boost;
	int h, w, i, j;
	cin >> h >> w;
	foe(i, 1, h) {
		foe(j, 1, w)
		cin >> arr[i][j];
	}
	foe(i, 1, h) {
		int sum = 0;
		foe(j, 1, w) {
			sum += (arr[i][j] == '#');
			pre[i][j] = pre[i - 1][j] + sum;
		}
	}
	foe(i, 0, h) {
		foe(j, 0, w)
		dp[i][j] = dp[i][j] = inf;
	}
	dp[1][1] = (arr[1][1] == '.' ? 0 : 1); 
	foe(i, 1, h) {
		foe(j, 1, w) {
			if(i * j == 1) continue;
			
			if(arr[i][j] == '#') {
				for(int c1 = i; c1 > 0; c1--) {
					for(int c2 = j; c2 > 0; c2--) {
						int val = pre[i][j] - pre[i][c2 - 1] - pre[c1 - 1][j] + pre[c1 - 1][c2 - 1];
						int x = (i - c1 + 1) * (j - c2 + 1);
						if(val == x)
						dp[i][j] = min(dp[i][j], dp[c1][c2]);
					}
				}
				if(arr[i - 1][j] == '.')
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
				if(arr[i][j - 1] == '.')
				dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
			}
			else
			dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	cout << dp[h][w];
}


Measured memory_bytes: 384
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

while true
    h,w=get_i
    break if h.zero? and w.zero?
    h.times do|i|
        w.times do|i|
            print("#")
        end
        print("\n")
    end
        print("\n")
end


Measured memory_bytes: 6880
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
int main(){
    int64_t n,k;
    cin>>n>>k;
    int64_t ans = 1;
    for(int i=0;i<n;i++){
        if(i==0){
            ans*=k;
        }
        else{
            ans*=k-1;
        }
    }
    cout<<ans<<endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;

  int n = s.size();

  vector<vector<int>> v(26);
  for (int i = 0; i < n; ++i) {
    v[s[i] - 'a'].push_back(i);
  }

  int pos = 0;
  long long ans = 0;
  for (int i = 0; i < t.size(); ++i) {
    int j = t[i] - 'a';
    if (v[j].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
    auto iter = lower_bound(v[j].begin(), v[j].end(), pos);
    if (iter == v[j].end()) {
      i -= 1;
      pos = 0;
      ans += n;
    } else {
      pos = *iter + 1;
    }
  }
  ans += pos;

  cout << ans << endl;
}

Measured memory_bytes: 1216
N = int(input())
st = input().split()
d = 10**9 + 7
A = []
m = N%2
fl = {}
exflag = False
for i in range(N):
    a = int(st[i])
    A.append(a)
    if (a + m) % 2 == 0:
        print(0)
        exflag = True
        break
    if a == 0:
        if 0 in fl.keys():
            print(0)
            exflag = True
            break
        fl[0] = 1
    else:
        if a in fl.keys():
            if fl[a] > 1:
                print(0)
                exflag = True
                break
            else:
                fl[a] = 2
        else:
            fl[a] = 1

        
if exflag == False:    
    ret = 2**(N//2) %d
    print(ret)
    

Measured memory_bytes: 16756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<P>vec;
int n,m,p[100005],y[100005],c[100005];
string ans[100005];
int main(){
	cin>>n>>m;
	rep(i,m){
		cin>>p[i]>>y[i];
		vec.pb(mp(y[i],i));
	}
	SORT(vec);
	rep(i,m){
		int s = vec[i].sc;
		int A = p[s];
		int B = c[A]+1;
		c[A]++;
		string aa="",bb="";
		rep(x,6){
			aa.pb(A%10+'0');
			A/=10;
		}
		rep(x,6){
			bb.pb(B%10+'0');
			B/=10;
		}
		reverse(aa.begin(),aa.end());
		reverse(bb.begin(),bb.end());
		ans[s] = aa+bb;
	}
	rep(i,m) cout<<ans[i]<<endl;
}

Measured memory_bytes: 8948
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int p, q, r;
    cin >> p >> q >> r;
    vector<int> hours = {p, q, r};
    sort(hours.begin(), hours.end());
    cout << hours[0] + hours[1] << endl;
}


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

int main() {
  int n;
  cin >> n;
  string color;

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    
    if (s == "Y") {
      color = "Four";
      break;
    }
    else {
      color = "Three";
    }
  }
  cout << color << endl;
}

Measured memory_bytes: 256
xs = []
for x in range(5):
    xs.append(int(input()))


def lastDigit(x):
    return x % 10


xs.sort(key=lastDigit)
# print(xs)
time = 0
first = True
for x in xs:
    if x % 10 == 0:
        time += x
    else:
        if first:
            time += x
            first = False
        else:
            time += x + 10 - x % 10
print(time)


Measured memory_bytes: 3060
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimize("02")
using namespace std;
const int maxn=2e5+5;
long long  n,a[maxn],num[maxn],sum;
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		num[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		if(num[i]>1){
			sum+=(num[i]*(num[i]-1)/2);
		}
	}
	for(int i=0;i<n;i++){
		if(num[a[i]]>0){
			cout<<sum-(num[a[i]]-1)<<endl;
		}
		else{
			cout<<sum<<endl;
		}
	}
}


Measured memory_bytes: 4736
N = int(input())
x = [0.0] * N
u = [""] * N
currency = {"JPY": 1.0, "BTC": 380000.0}
for i in range(N):
    tmp = list(input().split())
    x[i] = float(tmp[0])
    u[i] = tmp[1]

print(sum([x[i] * currency[u[i]] for i in range(N)]))


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            var k = long.Parse(Console.ReadLine());
            var not1 = '1';
            var index = 0;
            for (var i = 0; i < s.Length; i++)
            {
                if (s[i] != '1')
                {
                    not1 = s[i];
                    index = i + 1;
                    break;
                }
            }
            Console.WriteLine(k < index ? '1' : not1);
        }
    }
}


Measured memory_bytes: 11092
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  ll n;
  cin >> n;
  if(n == 2){
    cout << 1 << endl;
    return 0;
  }
  int ans = 0;
  ll target;
  vector<ll> div;
  vector<ll> ndiv;
  target = n;
  for(int k=2;k<=sqrt(n);k++){
    if(target%k == 0){
      div.push_back(k);
      if(k != target/k) div.push_back(target/k);
    }
  }

  target = n-1;
  for(int k=2;k<=sqrt(n-1);k++){
    if(target%k == 0){
      ndiv.push_back(k);
      if(k != target/k) ndiv.push_back(target/k);
    }
  }
  for(int i=0;i<div.size();i++){
    target = n;
    while(target%div[i] == 0) target /= div[i];
    if(target%div[i] == 1) ans++;
  }
  cout << ans+2+ndiv.size() << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);
//const int INF=(1<<29);

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

  if(s.front() == s.back()){
    if(s.size()%2==0){
      cout << "First" << endl;
    }else{
      cout << "Second" << endl;
    }
  }else{
    if(s.size()%2==0){
      cout << "Second" << endl;
    }else{
      cout << "First" << endl;
    }
  }
}



Measured memory_bytes: 512
#include<stdio.h>
int min(int x,int y){
if(x<y)return x;
  else return y;
}
int main(void){
int a,b,c,x,y;
  scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
  long sum=0;
  if(2*c<a+b)sum+=2*c*min(x,y);
  else sum+=min(x,y)*(a+b);
  int amari,m;
  if(x<y){amari=y-x;
           m=b;
         }
  else{amari=x-y;
       m=a;
      }
  if(2*c<m)sum+=2*c*amari;
  else sum+=m*amari;

  printf("%ld",sum);
  
  return 0;
}

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

int main() 
{
    long long int c=0,t=0,a[100005]={0},n,i;
    
    cin>>n;
    
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
	
	for(i=0;i<n;i++)
	{
	    if(a[i]%4==0)
	    {
	        c++;
	    }
	    if(a[i]%2==0&&a[i]%4!=0)
	    {
	        t++;
	    }
	}
	
	if(t>=2)
	{
	    n-=t;
	    if(n%2==0)
       	{
 	        if(c>=n/2)
        	{
	          cout<<"Yes"<<endl;
        	}
         	else
        	{
          	    cout<<"No"<<endl;
        	}
    	}
     	else
    	{
	       if(c>n/2)
        	{
	          cout<<"Yes"<<endl;
        	}
         	else
        	{
          	    cout<<"No"<<endl;
        	}
	    }
	}
	else if(c>=n/2)
	{
	    cout<<"Yes"<<endl;
	}
	else
	{
	    cout<<"No"<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 1024
n,t=map(int,input().split())
a=[]
for i in range(n):
  b,c=map(int,input().split())
  a.append((b,c))
a.sort()
for i in range(n):
  if a[i][1]<=t:
    print(a[i][0])
    break
  if i == n-1:
    print("TLE")

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

var comb [][]int

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	abc := make(map[int][][]int, n-1)
	for i := 0; i < n-1; i++ {
		x := make([][]int, 0)
		abc[i] = x
	}
	for i := 0; i < n-1; i++ {
		a, _ := strconv.Atoi(stringLineScan())
		b, _ := strconv.Atoi(stringLineScan())
		c, _ := strconv.Atoi(stringLineScan())
		a--
		b--
		p := make([]int, 2)
		p[0], p[1] = b, c
		abc[a] = append(abc[a], p)
		q := make([]int, 2)
		q[0], q[1] = a, c
		abc[b] = append(abc[b], q)
	}
	d := make([]int, n)
	for i := 0; i < n; i++ {
		d[i] = -1
	}
	q, _ := strconv.Atoi(stringLineScan())
	k, _ := strconv.Atoi(stringLineScan())
	k--
	d[k] = 0
	d = dist(k, abc, d)
	for i := 0; i < q; i++ {
		x, _ := strconv.Atoi(stringLineScan())
		y, _ := strconv.Atoi(stringLineScan())
		fmt.Println(d[x-1] + d[y-1])
	}
}
func dist(init int, abc map[int][][]int, d []int) []int {
	for _, i := range abc[init] {
		if d[i[0]] == -1 {
			d[i[0]] = d[init] + i[1]
			d = dist(i[0], abc, d)
		}
	}
	return d
}


Measured memory_bytes: 72576
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+3;
 
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      #ifndef ONLINE_JUDGE
      //freopen("input.txt", "r", stdin);
      // freopen("output.txt","w",stdout);
      #endif
      int n;
      cin>>n;
      cout<<(n*n*n);
}
// I never lose. I either win or I learn

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

int main()
{
    int N;

    cin >> N;

    int P[N], Q[N];

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

    for (int i = 0; i < N; i++)
    {
        cin >> Q[i];
    }

    int count = 0;
    int a, b;

    vector<int> v1(N);
    iota(v1.begin(), v1.end(), 1); // v に 1, 2, ... N を設定
    do
    {
        count++;
        bool flg = true;

        for (int i = 0; i < N; i++)
        {
            if (v1[i] != P[i])
            {
                flg = false;
                break;
            }
        }

        if (flg == true)
        {
            a = count;
            break;
        }

    } while (next_permutation(v1.begin(), v1.end())); // 次の順列を生成

    count = 0;
    vector<int> v2(N);
    iota(v2.begin(), v2.end(), 1); // v に 1, 2, ... N を設定
    do
    {
        count++;
        bool flg = true;

        for (int i = 0; i < N; i++)
        {
            if (v2[i] != Q[i])
            {
                flg = false;
                break;
            }
        }

        if (flg == true)
        {
            b = count;
            break;
        }

    } while (next_permutation(v2.begin(), v2.end())); // 次の順列を生成

    cout << abs(a - b) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  const int N_RANK=5;
  const char rank[]="FDCBA";
  const int border[N_RANK+1]={0,30,50,65,80,101};
  int i,m,f,r;
  while(1){
    scanf("%d %d %d",&m,&f,&r);
    if(m==-1&&f==-1&&r==-1)break;
    else if(m==-1||f==-1){
      printf("%c\n",rank[0]);
      continue;
    }
    for(i=0;i<N_RANK;i++){
      if((m+f)>=border[i]&&(m+f)<border[i+1]){
        if(i==1&&r>=50){
          printf("%c\n",rank[i+1]);
          break;
        }
        else printf("%c\n",rank[i]);
      }
    }
  }
  return 0;
}

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

int main(){
	while(1){
		int m,nmin,nmax;
		
		cin>> m>>nmin>>nmax;
		
		if(m==0 && nmin==0 && nmax == 0)
			break;
			
		int P[m];
		for(int i=0; i<m ;i++){
			cin>>P[i];
		}
		
		int maxgap=0;
		int chosen=0;
		for(int i=nmin-1; i<nmax; i++){
			
			if(maxgap <= (P[i]-P[i+1])){
				maxgap=P[i]-P[i+1];
				chosen=i+1;
			}
		}
		cout<<chosen<<endl;
	}
	return 0;
}

Measured memory_bytes: 3048
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	ll N,P;
	cin>>N>>P;
	for(int i=0;i<N;i++){
		int A;
		cin>>A;
		if(A%2){
			cout<<(1LL<<N-1)<<endl;
			return 0;
		}
	}
	if(P)
		cout<<0<<endl;
	else
		cout<<(1LL<<N)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	int cnt = 0;
	int ans = 0;
	do {
		int R = 0;
		int L = 1000;
		for (int i = 0; i < M; i++) {
			R = max(R, v[cnt]);
			L = min(L, v[cnt]);
			cnt++;
			cnt %= N;
		}
		ans += R - L;
	} while (cnt);
	cout << ans << endl;
}



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

#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int ll;

using namespace std;
// typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e18)

ll A, B, C, D;
map<ll, ll> mp;

ll f(ll n) {
    if (mp.find(n) != mp.end()) return mp[n];

    ll ans = n * D;

    ans = min(ans, f(n / 2) + A + (n % 2) * D);
    if (n % 2 != 0)
        ans = min(ans, f(n / 2 + 1) + A + (2 - (n % 2)) * D);

    ans = min(ans, f(n / 3) + B + (n % 3) * D);
    if (n % 3 != 0)
        ans = min(ans, f(n / 3 + 1) + B + (3 - (n % 3)) * D);

    ans = min(ans, f(n / 5) + C + (n % 5) * D);
    if (n % 5 != 0)
        ans = min(ans, f(n / 5 + 1) + C + (5 - (n % 5)) * D);

    mp[n] = ans;
    return ans;
}

int main() {
    ll T;
    cin >> T;
    for (ll i = 0; i < T; i++) {
        ll N;
        cin >> N >> A >> B >> C >> D;
        mp = {{0, 0}, {1, D}};
        cout << f(N) << endl;
    }
}


Measured memory_bytes: 5080
from itertools import combinations

def f(in_A,in_B,in_C,A,B,C,ex_l,counter):
    if (counter == len(ex_l)):
        return abs(in_A-A)+abs(in_B-B)+abs(in_C-C)
    else:
        tmp = ex_l[counter]
        counter +=1
        a1 = f(in_A+tmp,in_B,in_C,A,B,C,ex_l,counter)+10
        a2 = f(in_A,in_B+tmp,in_C,A,B,C,ex_l,counter)+10
        a3 = f(in_A,in_B,in_C+tmp,A,B,C,ex_l,counter)+10
        a4 = f(in_A,in_B,in_C,A,B,C,ex_l,counter)
    return min(a1,a2,a3,a4)

N,A,B,C=map(int,input().split())
l = []
for i in range(N):
    l.append(int(input()))
in_l = list(map(list,combinations(l,3)))
ex_l = [l[:] for _ in range(len(in_l))]
for i in range(len(in_l)):
    ex_l[i].remove(in_l[i][0])
    ex_l[i].remove(in_l[i][1])
    ex_l[i].remove(in_l[i][2])

mp = 1000000
for i in range(len(in_l)):
    tmp = f(in_l[i][0],in_l[i][1],in_l[i][2],A,B,C,ex_l[i],0)
    if(mp>tmp):
        mp = tmp
for i in range(len(in_l)):
    tmp = f(in_l[i][0],in_l[i][1],in_l[i][2],A,C,B,ex_l[i],0)
    if(mp>tmp):
        mp = tmp
for i in range(len(in_l)):
    tmp = f(in_l[i][0],in_l[i][1],in_l[i][2],B,A,C,ex_l[i],0)
    if(mp>tmp):
        mp = tmp
for i in range(len(in_l)):
    tmp = f(in_l[i][0],in_l[i][1],in_l[i][2],B,C,A,ex_l[i],0)
    if(mp>tmp):
        mp = tmp
for i in range(len(in_l)):
    tmp = f(in_l[i][0],in_l[i][1],in_l[i][2],C,A,B,ex_l[i],0)
    if(mp>tmp):
        mp = tmp
for i in range(len(in_l)):
    tmp = f(in_l[i][0],in_l[i][1],in_l[i][2],C,B,A,ex_l[i],0)
    if(mp>tmp):
        mp = tmp
print(mp)

Measured memory_bytes: 3192
H, W, K = map(int, input().split())
dot=[list(input()) for i in range(H)]
ans = 0

for R in range(2**H):
    for C in range(2**W):
        blk = 0
        for i in range(H):
            for j in range(W):
                 if ((R >> i) & 1) == 0 and ((C >> j) & 1) == 0 and dot[i][j] == '#':
                    blk += 1
        if blk == K:
            ans += 1
print(ans)


Measured memory_bytes: 9188
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 300000
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	int ren[SIZE];
	void init()
	{
		for (int i = 0; i<SIZE; i++)
		{
			par[i] = i;
			ran[i] = 0;
			ren[i] = 1;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return par[a] = find(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
		}
		if (ran[a] == ran[b])ran[b]++;
	}
};
unionfind uf1, uf2;
typedef long long ll;
int deg[100000];
int sum[100000];
bool flag[100000];
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	uf2.init();
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		uf2.unite(za * 2, zb * 2 + 1);
		uf2.unite(za * 2 + 1, zb * 2);
		deg[za]++, deg[zb]++;
	}
	int maxi = 0;
	for (int i = 0; i < num; i++)maxi = max(maxi, deg[i]);
	if (maxi == way)printf("0\n");
	else if (uf2.find(0) == uf2.find(1))printf("%lld\n", (ll)(num)*(ll)(num - 1) / 2 - way);
	else
	{
		ll a = 0;
		for (int i = 0; i < num; i++)if (uf2.find(i * 2) == uf2.find(0))a++;
		printf("%lld\n", a*(num - a) - way);
	}
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#pragma GCC optimize(2)
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const double eps=1e-5;
const double pi=acos(-1.0);
const int MOD=1e9+7;
const int maxn=1e5+10;
ll k=1e9;
int main ()
{
    ll s=0;
    scanf("%lld",&s);
    ll x=0,y=0;
    x=s/k;
    if(s%k!=0)
        x++;
    y=x*k-s;
    printf("0 0 1 1000000000 %lld %lld",x,y);
    return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=1e5+10;

int main(){
	int N,M;
	cin>>N>>M;
	int ct[MAX];
	rep1(i,MAX-1)ct[i]=0;
	rep(_,N){
		int x;
		cin>>x;
		ct[x]++;
	}
	int card[MAX];
	int pair[MAX];
	rep(i,M){
		card[i]=0;
		pair[i]=0;
	}
	rep1(i,MAX-1){
		card[i%M]+=ct[i];
		pair[i%M]+=ct[i]/2;
	}
	int ans=card[0]/2;
	if(M%2==0){
		ans+=card[M/2]/2;
		rep1(i,M/2-1){
			int ac=card[i], ap=pair[i];
			int bc=card[M-i], bp=pair[M-i];
			int d1=ac-(bc-2*bp);
			int d2=(ac-2*ap)-bc;
			if(d1>0 && d2>0){
				ans+=(ac+bc-min(abs(d1), abs(d2)))/2;
			}
			else if(d1<0 && d2<0){
				ans+=(ac+bc-min(abs(d1), abs(d2)))/2;
			}
			else{
				ans+=(ac+bc-(ac+bc)%2)/2;
			}
		}
	}
	if(M%2==1){
		rep1(i,M/2){
			int ac=card[i], ap=pair[i];
			int bc=card[M-i], bp=pair[M-i];
			int d1=ac-(bc-2*bp);
			int d2=(ac-2*ap)-bc;
			if(d1>0 && d2>0){
				ans+=(ac+bc-min(abs(d1), abs(d2)))/2;
			}
			else if(d1<0 && d2<0){
				ans+=(ac+bc-min(abs(d1), abs(d2)))/2;
			}
			else{
				ans+=(ac+bc-(ac+bc)%2)/2;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1536