akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    ll n;cin>>n;
    vll c(n-1), s(n-1), f(n-1);
    REP(i,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }
    FOR(i,0,n-2){
        ll sum = c[i] + s[i];
        FOR(j, i+1, n-2){
            if (sum < s[j]) sum = s[j]+c[j];
            else{
                sum += (f[j]- (sum % f[j])) % f[j];
                sum += c[j];
            }
        }
        cout<<sum<<endl;
    }
    cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
#define abs(x) ((x) < 0 ? (-x) : (x))
using namespace std;

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

int main() {
  long long int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long int lcm = c / gcd(c, d) * d;
  
  long long int nc = b/c - (a-1)/c;
  long long int nd = b/d - (a-1)/d;
  long long int ncd = b/lcm - (a-1)/lcm;
    
  cout << (b - (a - 1)) - (nc + nd - ncd) << endl;  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const ll INF = 1061109567;
const double EPS = 1e-10;
int main(){
    int K,N;
    cin>>N>>K;
    vector<int> p;
    int min;
    for(int i=0;i<N;i++){
        int buf;
        cin>>buf;
        p.push_back(buf);
    }
    sort(p.begin(),p.end());
    int ans=0;
    for(int i=0;i<K;i++){
        ans+=p[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  int t;
  rep(i, m) {
    cin >> t;
    sum += t;
  }

  cout << max(-1, n - sum) << endl;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<iostream>
#include<algorithm>

#define P 998244353

using namespace std;

int read(){
	int x=0;
	char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}

const int N = 3005;

int A,B,C,D;
int f[N][N];

int Pow_mod(int x,int y) {
	int ret=1;
	while(y){
		if(y&1) ret=1ll*ret*x%P;
		x=1ll*x*x%P;
		y>>=1;
	}
	return ret;
}
int Plus(int x,int y) { return x+y<P?x+y:x+y-P; }
int Minus(int x,int y) { return x>=y?x-y:x-y+P; }

int main()
{
	A=read(); B=read(); C=read(); D=read();
	
	if(A==C && B==D) { printf("1\n"); return 0; }
	if(A==C) { printf("%d\n",Pow_mod(A,D-B)); return 0; }
	if(B==D) { printf("%d\n",Pow_mod(B,C-A)); return 0; }
	
	f[A][B]=1;
	for(int i=A+1;i<=C;i++) f[i][B]=1ll*f[i-1][B]*B%P;
	for(int i=B+1;i<=D;i++) f[A][i]=1ll*f[A][i-1]*A%P;
	for(int i=A+1;i<=C;i++)
		for(int j=B+1;j<=D;j++)
			f[i][j]=Minus(Plus(1ll*i*f[i][j-1]%P,1ll*j*f[i-1][j]%P),1ll*(i-1)*(j-1)%P*f[i-1][j-1]%P);
	
	printf("%d\n",f[C][D]);
	
	return 0;
}

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

using namespace std;

int main(){
    int R;
    cin >> R;

    if(R > 2799){
        cout << "AGC" << endl;
    }else if(R > 1199){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }


    return 0;
}


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

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

vector<long long> stk, ans;
set<pair<long long, long long>> mst;

inline void update( long long p, long long q ) {
    pair<long long, long long> pr( p, 0 );
    
    if( mst.lower_bound( pr ) -> first == p ) {
        q += mst.lower_bound( pr ) -> second;
        mst.erase( mst.lower_bound( pr ) );
    }
    
    mst.insert( make_pair( p, q ) );
    return;
}

int main( void ) {
    
    int n, q;
    cin >> n >> q;
    
    stk.assign( 1, n );
    for( int i = 1; i <= q; i ++ ) {
        long long x;
        cin >> x;
        
        while( stk.empty() == false && stk.back() >= x )
            stk.pop_back();
        stk.push_back( x );
    }
    
    reverse( stk.begin(), stk.end() );
    mst.insert( make_pair( stk.front(), 1 ) );
    
    for( long long x : stk ) {
        while( mst.rbegin() -> first > x ) {
            update( x, mst.rbegin() -> second * ( mst.rbegin() -> first / x ) );
            update( mst.rbegin() -> first % x, mst.rbegin() -> second );
            mst.erase( *mst.rbegin() );
        }
    }
    
    ans.resize( n + 2 );
    for( pair<long long, long long> pr : mst )
        ans[pr.first] += pr.second;
    
    for( int i = n; i >= 1; i -- )
        ans[i] += ans[i + 1];
    for( int i = 1; i <= n; i ++ )
        cout << ans[i] << " ";
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 9076
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String s = sc.next();
        if (a >= 3200) {
            System.out.println(s);
        } else {
            System.out.println("red");
        }
        sc.close();
    }
}


Measured memory_bytes: 21204
#include<stdio.h>
int main(){
  int h, w, i, j;
  while(1){
    scanf("%d %d",&h,&w);
    if(h==0 && w==0) break;

    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if((i+j)%2==0)printf("#");
	else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2148
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,M; cin>>N>>M;
    //コスト
    vector<ll> A(M+1,0);
    
    //鍵iができる箱
    vector<ll> BOX(M+1,0);
    
    //鍵i
    rep1(i,M){
        ll B; cin>>A[i]>>B;
        
        ll tmp=0;
        //箱x
        rep(j,B){
            ll x; cin>>x;
            //箱1,3なら
            // .....     [3-1][2-1][1-1]
            // ..... 0 0   1    0    1
            tmp += pw2[x-1];
        }
        BOX[i]=tmp;
    }
    
    //dp[i][j]:鍵iまで見てjの状態になる.コスト最小
    vector<vector<ll> > dp(M+1,vector<ll>(pw2[12],INF));
    dp[0][0]=0;
    
    rep1(i,M){
        rep(j,pw2[N]){
            //i-1まで見て状態j
            //鍵i使う
            chmin(dp[i][j|BOX[i]],dp[i-1][j]+A[i]);
            //使わない
            chmin(dp[i][j],dp[i-1][j]);
        }
    }
    
    if(dp[M][pw2[N]-1]==INF) cout<<-1<<endl;
    else cout<<dp[M][pw2[N]-1]<<endl;
}



Measured memory_bytes: 35372
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    vector<ll>v;
    map<ll,ll>mp;
    for(ll i=0;i<n;i++)
        {
            cin>>a[i];
            if(find(v.begin(),v.end(),a[i])==v.end())
                v.push_back(a[i]);
                mp[a[i]]++;
        }
        sort(v.begin(),v.end());
        //reverse(v.begin(),v.end());
        ll cnt=0;
        ll rc=0;
        if(v.size()==1)
            {cout<<"0\n";
        return 0;}
    for(ll i=0;i<v.size()-2;i++)
    {
        for(ll j=i+1;j<v.size()-1;j++)
        {
            for(ll k=j+1;k<v.size();k++)
            {
                if(v[i]+v[j]>v[k])
                    {
                        rc+=(mp[v[i]]*mp[v[j]]*mp[v[k]]);
                    }
                else
                    break;
            }
        }
    }
    cout<<rc<<"\n";
}


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;

char maze[2010][2010];
ll ansmaze[2010][2010];


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

	int h,w;cin>>h>>w;

	rep(i,h){
		rep(j,w){
			cin>>maze[i][j];
		}
	}


	int cnt=0;
	int s=0;
	rep(i,h){
		rep(j,w){
			if(maze[i][j] =='.'){
				if(cnt ==0){
					s=j;
				}
				cnt++;
			}else  {
				for(int k=s; k<j; k++){
					ansmaze[i][k] = cnt;
				}
				s=j;
				cnt =0;
			}
			if(j== w-1 && cnt !=0){
				for(int k=s; k<=j; k++){
					ansmaze[i][k] = cnt;
				}
				cnt=0;
			}
		}
	}
/*
	rep(i,h){
		rep(j,w){
			cout<<ansmaze[i][j];
		}
		cout<<endl;
	}
	cout<<endl;

*/

	cnt=0;
	 s=0;
	rep(i,w){
		rep(j,h){
			if(maze[j][i] =='.'){
				if(cnt ==0){
					s=j;
				}
				cnt++;
			}else  {
				for(int k=s; k<j; k++){
					ansmaze[k][i] += cnt;
				}
				s=j;
				cnt =0;
			}
			if(j== h-1 && cnt !=0){
				for(int k=s; k<=j; k++){
					ansmaze[k][i] += cnt;
				}
				cnt=0;
			}
		}
	}
/*
	rep(i,h){
		rep(j,w){
			cout<<ansmaze[i][j]<<" ";
		}
		cout<<endl;
	}
*/
	ll ans =0;
	rep(i,h){
		rep(j,w){
			ans = max(ans,ansmaze[i][j]-1);
		}
	}
	writeln(ans);








}


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


int A[100];
long long dp[100][100][5000];

int main(){
	int n,k;
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> A[i];
	}
	
	dp[0][0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<=2500;k++){
				if(dp[i][j][k]){
					dp[i+1][j][k]+=dp[i][j][k];
					dp[i+1][j+1][k+A[i]]+=dp[i][j][k];
				}
			}
		}
	}
	
	long long ans=0;
	for(int i=1;i<=n;i++) ans+=dp[n][i][i*k];
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 151808
h,w = map(int,input().split())
X = []

for i in range(h):
    x = input()
    
    if x.count(".") != w:
        x = list(x)
        X.append(x)
        
h = len(X)

for i in range(w):
    wrong = 0
    for j in range(h):
        if X[j][i] == ".":
            wrong += 1
            
        if wrong == h:
            for k in range(h):
                X[k][i] = "*"
                
for i in range(h):
    print(("".join(X[i])).replace("*",""))

Measured memory_bytes: 3188
//write：Sakura
//id：
//problem：Digit Sums
//note：

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

char s[100000005];
int a=0;
int len=0;
int sum=0;

int zero(int x){
	int ss=1;
	for(int i=x;i<len-1;i++)ss*=10;
	return ss;
}

int main(){
	//freopen("Digit Sums.in","r",stdin);
	//freopen("Digit Sums.out","w",stdout);
	scanf("%s",s);
	len=strlen(s);
	for(int i=0;i<len;i++){
		sum+=s[i]-'0';
		a+=(s[i]-'0')*zero(i);
	}
	//printf("%d\n",a);
	//printf("%d\n",sum);
	if(sum%a==0 || a%sum==0)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
x=int(input())

def is_prime(c):
  for i in range(2,int(c**(1/2))+2):
    if c%i==0 and c!=2:
      return False
  return True

for i in range(x,100004):
  if is_prime(i)==False:
    pass
  else:
    print(i)
    break
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  map<int,int> mp;
  rep(i,n){
    mp[a.at(i)]++;
  }
  vector<int> kind;
  for(auto p:mp){
    kind.push_back(p.second);
  }
  sort(ALL(kind));
  int ans = 0;
  rep(i,kind.size()-k){
    ans += kind.at(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 11516
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>
#include <queue>

typedef long long ll;

using namespace std;

int main(){
    cout.precision(15);
    int l;
    cin >> l;
    double a = l / 3.0;
    cout << pow(a, 3) << endl;
}

Measured memory_bytes: 256
def resolve():
    n = int(input())

    ans = []
    while n > 0:
        n, mod = divmod(n, 26)
        if mod == 0:
            ans.append(26)
            n -= 1
        else:
            ans.append(mod)

    ans.reverse()

    for i in range(len(ans)):
        if ans[i] == 0:
            pass
        else:
            print(chr(96+ans[i]), end='')
    print()

resolve()

Measured memory_bytes: 9104
#include <iostream>
#include <algorithm>

using namespace std;
int main(void){
    // Your code here!
    
    int a,b,c;
    int hairetu[3];
    cin >> hairetu[0] >> hairetu[1] >> hairetu[2];
    sort(hairetu, hairetu+3);
    
    cout << hairetu[0] << " " << hairetu[1] <<" " << hairetu[2] << endl;
    
    return 0;
}


Measured memory_bytes: 3120
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,c;
	string b;
	cin>>a>>b>>c;
	c--;
	for(int i=0;i<a;i++){
		if(b[i]!=b[c])
			b[i]='*';
	}
	cout<<b<<endl;
	return 0;
}

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

using namespace std;

string s;

int main()
{
    cin >> s;
    int len = s.length();
    if (s[len - 1] == 's')
        cout << s + "es" << endl;
    else cout << s + 's' << endl;

    return 0;
}

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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
#define int long long

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;

ll n;

ll check (ll x) {
        return x * (x + 1) / 2;
}
 main () {
        cin >> n;

        ll l = 1,r = n;

        while (r - l > 1) {
                int m = (r + l) >> 1;

                if (check(m) < n)
                        l = m;
                else
                        r = m;
        }
        ll sum = check(r);

        for (int i = 1; i <= r; i ++) {
                if (sum - n != i)
                        cout << i << endl;
        }
}


Measured memory_bytes: 256
nmx = gets.chomp!.split(' ')
n = nmx[0].to_i
m = nmx[1].to_i
x  =  nmx[2].to_i
 
ai = gets.chomp!.split(' ')
 
cost1 = 0
cost2 = 0
 
for gate in ai
  if gate.to_i < x
    cost1 = cost1+ 1
   else
    cost2 = cost2+1
  end
end
if cost1 < cost2
  puts cost1
else
  puts cost2
end

Measured memory_bytes: 1788
#include <iostream>
#include <cctype>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cstring>
#include <fstream>
#include <cmath>
#include <stack>
#include <algorithm>
#include <queue>
#include <iterator>
#include <limits>

using namespace std;

int main()
    {
          int N;
          cin>>N;
          cout<<180*(N - 2);
          system("pause");
          return 0;
    }


Measured memory_bytes: 504
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    ll n;
    cin>>n;
    vi v;
    rep(i,0,n)
    {
        ll x;
        cin>>x;
        v.pb(x);
    }
    ll dp[n+1];
    dp[n]=v[n-1];
    for(int i=n-1;i>0;i--)
    {
        dp[i]=(dp[i+1]+v[i-1])%hell;
    }
    // rep(i,1,n+1)
    // cout<<dp[i]<<" ";
    // cout<<endl;
    ll ans=0;
    rep(i,0,n-1)
    {
        ans=(ans+(v[i]*dp[i+2])%hell)%hell;
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

ll N, L;
ll A[MAX_N] = {};

int main()
{
    cin >> N >> L;
    REP(i, N) { cin >> A[i]; }

    ll core = -1;
    // 2 つで L を超えるものを探す
    for(int i = 0; i < N - 1; ++i) {
        if(A[i] + A[i+1] >= L) {
            core = i;
            break;
        }
    }
    if(core < 0) {
        printf("Impossible\n");
        return 0;
    }
    printf("Possible\n");
    // 左右の端から結び目をほどく
    for(int i = 0; i < core; ++i) {
        printf("%d\n", i+1);
    }
    for(int i = N - 2; i >= core; --i) {
        printf("%d\n", i+1);
    }
    return 0;
}


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

int main()
{   
    int m,n,c;
    cin>>m>>n;
    if((m==1&&n==2)||(m==2&&n==1)) cout<<3;
    if((m==1&&n==3)||(m==3&&n==1)) cout<<2;
    if((m==2&&n==3)||(m==3&&n==2)) cout<<1;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
bool isPerfectNum(int num)
{
    for (int i = 2; i <= 40; i++)
    {
        int temp=num;
        int cnt = 0;
        while (temp != 1)
        {
            if (temp % i == 0)
            {
                temp /= i;
                cnt++;
            }
            else
            {
                cnt = 0;
                break;
            }
        }
        if (cnt >= 2)
        {
            return true;
        }
    }
    return false;
}
int main()
{
    //freopen("B.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x;
    scanf("%d", &x);
    if(x==1){
        printf("%d",1);
    }
    for(int i = x;i>=2;i--){
        if(isPerfectNum(i)){
            printf("%d",i);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3712
#include<stdio.h>
#include<algorithm>
using namespace std;
long long a[200005];
int main(){
	int n,w=1;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	scanf("%lld",&a[i]);
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		if(a[i]==a[i+1])
		{
			w=0;
			break;
		}
	}
	if(w)
	printf("YES\n");
	else
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 1792
from collections import deque
h, w = map(int, input().split())
s = []
sharp = 0
for i in range(h):
	t = input()
	sharp += t.count("#")
	s.append(t)

queue = deque([[0,0]])

visited = [[-1 for i in range(w)] for j in range(h)]
visited[0][0] = 0
d = [(1,0),(0,1),(-1,0),(0,-1)]
while queue:
	i, j = queue.popleft()
	for n, m in d:
		x = i+n
		y = j+m
		if x < 0 or x >= h or y < 0 or y >= w or s[x][y] == "#" or visited[x][y] != -1:
			continue
		visited[x][y] = visited[i][j] + 1
		queue.append([x,y])
if visited[h-1][w-1] == -1:
	print (-1)
else:
	ans = h*w-visited[h-1][w-1]-1-sharp
	print (ans)

Measured memory_bytes: 3444
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    V, E = LI()
    con = [[INF]*V for _ in range(V)]
    for _ in range(E):
        std = LI()
        con[std[0]][std[1]] = std[2]

    # dp[S][i]: 集合Sを使ったiで終わるルートの最短コスト
    dp = [[INF]*V for _ in range(2**V)]
    # 0スタートに限定
    dp[1][0] = 0
    visited = [[False]*V for _ in range(2**V)]

    def dfs(S, i):
        if not visited[S][i]:
            if S&1:
                Smi = S & ~(1<<i)
                for j in range(V):
                    if Smi>>j & 1:
                        tmp = dfs(Smi, j) + con[j][i]
                        if dp[S][i] > tmp:
                            dp[S][i] = tmp
            visited[S][i] = True

        return dp[S][i]

    for i in range(V):
        dfs(2**V-1, i)

    ans = min([dp[-1][i]+con[i][0] for i in range(V)])
    print(ans if ans<INF else -1)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 21860
#include<bits/stdc++.h>
using namespace std;
long long ans;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long N, A , B;
    cin >> N >> A >> B;
    if (abs(A-B)%2 == 0) {
        ans = abs(A-B)/2;
    } else {
        ans = min((A+B)/2, (N*2+2-A-B)/2);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,cnt=1,ans=0;
    cin >>n;
    string s;
    vector<string> sv(n);
    for(int i=0;i<n;i++){
        cin >>s;
        sort(s.begin(),s.end());
        sv[i]=s;
    }
    sort(sv.begin(),sv.end());
    for(int i=0;i<n-1;i++){
        if(sv[i]!=sv[i+1]){
            ans+=cnt*(cnt-1)/2;
            cnt=1;
        }
        else cnt++;
    }
    ans+=cnt*(cnt-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 5760
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    ll ans=1;
    for(int i=1;i<=n;i++){
        ans*=i;
        ans%=MOD;
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <numeric>
using namespace std;
#define mod (long)(100000)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int main(){
    int N;
    cin >> N;
    int GCD;
    cin >> GCD;
    for(int i = 1; i < N; i++){
        int A;
        cin >> A;
        GCD = gcd(GCD, A);
    }
    cout << GCD << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_f

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

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

  // dp[i][j]: S の i 文字目 (1-indexed) と t の j 文字目までを使用した場合の
  // LCS 長
  auto dp = VVL(s.size() + 1, VL(t.size() + 1, 0));

  rep(i, 0, s.size()) {
    rep(j, 0, t.size()) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      } else {
        dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
      }
    }
  }

  string res = "";

  auto si = s.size();
  auto ti = t.size();

  while (si > 0 && ti > 0) {
    if (dp[si][ti] == dp[si - 1][ti]) {
      si--;
      continue;
    }

    if (dp[si][ti] == dp[si][ti - 1]) {
      ti--;
      continue;
    }

    // si, ti は LCS に含まれる
    res += s[si - 1];
    si--;
    ti--;
  }

  reverse(res.begin(), res.end());

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, 0, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 70784
#!/usr/bin/env ruby
n, k = gets.chomp.split(' ').map(&:to_i)
h_array = gets.chomp.split(' ').map(&:to_i)
 
h_array = h_array.sort.reverse

ans = if k >= h_array.length
    0
else
    arr =  h_array.slice(k, h_array.length)
    arr.inject(:+)
end

puts ans



Measured memory_bytes: 21360
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class CR
{
    public static string Get() { return Console.ReadLine(); }
    public static IEnumerable<string> GetTexts() { return Console.ReadLine().Split(' '); }
    public static int GetInteger() { return int.Parse(Console.ReadLine()); }
    public static IEnumerable<int> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)); }
}

namespace AtCoderBeginnerContest
{
    internal class Program
    {
        public static int N { get; private set; }
        public static string S { get; private set; }

        private static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.WriteLine(r); }

        private static object GetResult()
        {
            N = CR.GetInteger();
            S = CR.Get();

            var count = 0;
            for (int i = 0; i < N; i++)
            {
                var s = S[i];
                if (s == 'A')
                {
                    try
                    {
                        if (S[i + 1] == 'B' && S[i + 2] == 'C')
                        {
                            count++;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return count;
        }
    }
}


Measured memory_bytes: 11092
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;ll x;cin>>n>>x;
    ll cntp[51];
    ll cnt[51];
    cntp[0]=1;
    cnt[0]=1;
    int now=0;
    int i;
    for(i=1;i<=n;i++){
        cntp[i]=cntp[i-1]*2+1;
        cnt[i]=cnt[i-1]*2+3;
        if(now==0&&cnt[i]>=x)
            now=i;
    }
    i=now;
    ll ans=0;
    //cout<<x<<endl;
    for(int i=n;i>=0;i--){
        if(x>=cnt[i]){
            x-=cnt[i];
            ans+=cntp[i];
            if(x){
                x--;ans++;
            }
            if(x>=cnt[i]){
            x-=cnt[i];
            ans+=cntp[i];
            }
            if(x)
                x--;
        }
        else x--;
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  priority_queue<pi> que;
  int n, r, l;
  cin >> n >> r >> l;
  que.push(make_pair(0, -1));

  vi score(n + 1, 0), time(n + 1, 0);
  int pret = 0, pred = 1;

  rep(i, 0, r) {
    int d, t, x;
    cin >> d >> t >> x;
    score[d] += x;
    que.push(make_pair(score[d], -d));

    while(1) {
      pi p = que.top();
      if(p.first == score[-p.second]) {
        time[pred] += t - pret;
        pred = -p.second;
        pret = t;
        break;
      }
      que.pop();
    }
  }
  time[pred] += l - pret;

  int ans = 1;
  erep(i, 2, n) {
    if(time[ans] < time[i]) ans = i;
  }
  cout << ans << endl;
}



Measured memory_bytes: 11920
import sys
n = int(sys.stdin.readline())
arr = [list(map(int, sys.stdin.readline().split())) for i in range(n)]

dp = [[-1] * 3 for i in range(n)]

dp[0][0] = arr[0][0]
dp[0][1] = arr[0][1]
dp[0][2] = arr[0][2]

for i in range(1, n):
	dp[i][0] = max(dp[i - 1][1] + arr[i][0], dp[i - 1][2] + arr[i][0])
	dp[i][1] = max(dp[i - 1][0] + arr[i][1], dp[i - 1][2] + arr[i][1])
	dp[i][2] = max(dp[i - 1][0] + arr[i][2], dp[i - 1][1] + arr[i][2])

print(max(dp[n - 1]))

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

int temp[201];
int a[201], b[201], c[201];

int dp[201][201];

int main() {
  int D,N;
  cin>>D>>N;
  for (int i=0; i<D; ++i) cin>>temp[i];
  for (int i=0; i<N; ++i) cin>>a[i]>>b[i]>>c[i];

  for (int i=0; i<D; ++i)
    for (int j=0; j<201; ++j)
      dp[i][j] = 1<<29;

  for (int i=0; i<N; ++i) {
    if (temp[0] <= b[i] && a[i] <= temp[0])
      dp[0][c[i]] = 0;
  }

  for (int i=1; i<D; ++i) {
    for (int j=0; j<N; ++j) {
      if (temp[i] <= b[j] && a[j] <= temp[i]) {
        for (int k=0; k<201; ++k) {
          if (dp[i-1][k] == 1<<29) continue;
          if (dp[i][c[j]] == 1<<29)  dp[i][c[j]] = dp[i-1][k]+abs(k-c[j]);
          dp[i][c[j]] = max(dp[i-1][k]+abs(k-c[j]), dp[i][c[j]]);
        }
      }
    }
  }

  int ans = 0;
  for (int i=0; i<201; ++i) {
    if (dp[D-1][i] == 1<<29) continue;
    ans = max(ans, dp[D-1][i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1320
/*
    A=0
    G=1
    C=2
    T=3
*/
#include <bits/stdc++.h>
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define rep(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

ll n,dp[101][4][4][4],ans;

int main(){
    cin>>n;
    rep(i,4)rep(j,4)rep(k,4){
        if(!(i==0&&j==1&&k==2||i==0&&j==2&&k==1||i==1&&j==0&&k==2))dp[3][i][j][k]=1;
    }

    FOR(i,4,n+1)rep(j,4)rep(k,4)rep(l,4)rep(m,4){
        if(!(k==0&&l==1&&m==2||j==0&&l==1&&m==2||k==1&&l==0&&m==2||k==0&&l==2&&m==1||j==0&&k==1&&m==2))
            (dp[i][k][l][m]+=dp[i-1][j][k][l])%=mod;
    }

    rep(i,4)rep(j,4)rep(k,4)(ans+=dp[n][i][j][k])%=mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int main() {
  int X;
  cin >> X;

  cout << 10 - X / 200 << endl;
  return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

using namespace std;

//------------------------------------------------------------------------------
ll power(ll a,ll n)
{
          ll result=1;
          while(n>0)
          {
               if(n&1)
                    result=result*a;
               a=a*a;
               n=n>>1;
          }
          return result;
}
ll lcm(ll a,ll b)
{
          return ((a*b)/__gcd(a,b));
}
bool ispow2(ll n)
{
          return (ceil(log2(n))==floor(log2(n)));
}
bool isprime(ll n)
{
          if(n==1)
               return false;
          else if(n==2)
               return true;
          else
          {
               for(ll i=2;i*i<=n;++i)
               {
                    if(n%i==0)
                         return false;
               }
               return true;
          }
}

ll ncr(ll n,ll r)
{
    if(r > n - r)
          r = n - r;
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++)
     {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
void sieve(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
     prime[1]=false;
     prime[0]=false;
    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout<<p<<" ";
}
//------------------------------------------------------------------------------


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

          int t=1;
          //cin>>t;
          while(t--)
          {
                    int n;
                    cin>>n;
                    vector<pair<int,int>>a(n);
                    int x,y;
                    for(int i=0;i<n;++i)
                    {
                         cin>>a[i].fi>>a[i].se;
                    }
                    int f=0;
                    for(int i=0;i<n-2;++i)
                    {
                         if(a[i].fi==a[i].se && a[i+1].fi==a[i+1].se && a[i+2].fi==a[i+2].se)
                         {
                              f=1;break;
                         }
                    }
                    if(f)
                         cout<<"Yes";
                    else
                         cout<<"No";
          }
          return 0;
}


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

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

	string n;
	int sn = 0;

	cin >> n;

	for(int i=0;i<n.length();i++)
	{
		sn += (n[i]-'0');
	}

	if(stoi(n)%sn==0)
	{
		cout << "Yes" << '\n';
	}
	else
	{
		cout << "No" << '\n';
	}

	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

int main() {
	int w;
	int dp[5001];
	fill_n(dp, 5001, INT_MAX);
	for (int i = 0; i < 25; i++)
		for (int j = 0; j < 17; j++)
			for (int k = 0; k < 10; k++) {
				int cost = (i*380) - (i/5*380) + (j*550) - (j/4*330) + (k*850) - (k/3*306);
				int total = 200 * i + 300 * j + 500 * k;
				if (total <= 5000)
					dp[total] = min(dp[total], cost);
			}
	while (cin >> w && w) {
		cout << dp[w] << endl;
	}

	return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {

   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n;
   cin >> n;
   vector<int> a(n);
   set<int> s;
   for(int &x : a)
      cin >> x , s.insert(x);

   cout << (s.size() == a.size() ? "YES\n" : "NO\n");

}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;

ll dp[405][405];
ll num[1000], n, inf = 1e18+1;
ll pre[1000];

ll sum(ll l, ll r) {
	if(l == 0) return pre[r];
	return pre[r] - pre[l-1];
}

ll answer(ll l, ll r) {
	if(l == r) return 0;
	if(dp[l][r] != -1) return dp[l][r];
	ll ret = inf;

	for(ll i = l; i < r; i++) {
		//if(i == l) ret = min(ret, num[i] + answer(i+1, r));
		//else if(i == r) ret = min(ret, num[i] + answer(l, r-1));
		//else ret = min(ret, process(answer(l, i-1), num[i], answer(i+1, r)));

		ret = min(ret, answer(l, i) + answer(i+1, r) + sum(l, r));
	} 
	return dp[l][r] = ret;
}

int main()
{	
	cin >> n;
	for(int i = 0; i < n; i++) cin >> num[i];	pre[0] = num[0];
	for(int i = 1; i < n; i++) pre[i] = pre[i-1]+num[i];
	memset(dp, -1, sizeof dp);
	cout << answer(0, n-1) << endl;
    return 0;
}

Measured memory_bytes: 1536
//
//  main.cpp
//  PowersOfTwo2
//
//  Created by SZhang on 7/4/19.
//  Copyright © 2019 SZhang. All rights reserved.
//

#include <iostream>
#include <map>
#include <cmath>
using namespace std;

int main() {
    int a,b,mx=0, counter=0;
    cin>>a;
    multimap<int,int> mp;
    for (int i=0;i<a;i++){
        cin>>b;
        mp.insert(pair<int,int>(b,a));
    }
    
    while (!mp.empty()){
        typeof mp.end() i=mp.end();
        i--;
        mx=(i)->first;
        mp.erase(i);
        int target=pow(2,(int)((log(mx)/log(2)+1)))-mx;
        typeof(mp.find(target)) it=mp.find(target);
        if(it!=mp.end()) {
            counter++;
            mp.erase(it);
        }
    }
    cout<<counter<<endl;
    return 0;
}


Measured memory_bytes: 9600
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        int N = ReadInt();
        int[] B = ReadInts();
        int ans = 0;
        ans += B[0];
        for (int i = 0; i < N - 2; i++)
        {
            ans += Math.Min(B[i], B[i + 1]);
        }
        ans += B[N - 2];
        return ans.ToString();
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
using namespace std;
int main(){
  char c[3];
  cin >> c;
  char c2[3];
  cin >> c2;
  int count = 0;
  for(int i = 0; i < 3; i++){
    if(c[i] == c2[i]){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

#define MAX 1000001
int main(){
  vector<bool> prime(1000001, true);
  prime[0] = prime[1] = false;
  for(int i=2; i<MAX; i++)
    if(prime[i])
      for(int j=i+i; j<MAX; j+=i)
	prime[j] = false;

  int n, x;
  while(scanf("%d%d",&n,&x),n+x){
    int cost[n];
    int ans = 0;
    REP(i,n) scanf("%d",cost+i);
    vector<bool> f(x+1, false);
    f[0] = true;
    REP(i,x+1){
      if(f[i]){
	if(prime[i]) ans = i;
	REP(j,n){
	  if(i+cost[j] <= x)
	    f[i+cost[j]] = true;
	}
      }
    }
    if(ans == 0) printf("NA\n");
    else printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1164