akhauriyash/Code-Regression huggingface dataset:
w,h,n=map(int,input().split())
X=[]
for i in range(n):
    x,y,a=map(int,input().split())
    X.append([x,y,a])

X_max=[0]
X_min=[w]
Y_max=[0]
Y_min=[h]


for i in range(n):
    if X[i][2]==1:
        X_max.append(X[i][0])
    elif X[i][2]==2:
        X_min.append(X[i][0])
    elif X[i][2]==3:
        Y_max.append(X[i][1])
    elif X[i][2]==4:
        Y_min.append(X[i][1])

a=min(X_min)-max(X_max)
b=min(Y_min)-max(Y_max)

if a<=0 or b<=0:
    ans=0
else:
    ans=a*b


print(ans)
        

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //usefile;
  //test
  {
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    {
      cin>>v[i];
    }
    int ans=0;
    for(int j=0;j<=60;j++)
    {
      int c=0;
      for(int i=0;i<n;i++)
      {
        if(v[i]&1)
         c++;
        v[i]>>=1;
      }
      ans+=((c*(n-c))%mod)*expm(2,j);
      ans%=mod;
    }
    cout<<ans<<endl;
  }
  //time("");
  return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a>b){
    swap(a,b);
  }
  if(a>c){
    swap(a,c);
  }
  if(b>c){
    swap(b,c);
  }
  cout << a << ' ' << b << ' ' << c << endl;
}



Measured memory_bytes: 3080
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <utility>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include <set>


using namespace std;
typedef pair<int, int> XY;// Pair型変数の宣言
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
    

int main()
{
  	int Nmax = 100;
    char String[Nmax+1];
    int len;
    int N;
    int i,j,k;

 
      
    // 入力読込
    // 文字列
    scanf("%s", String);   
    
 
    
    // 文字列の長さをチェック
    // 文字列は配列の0からlen-1に格納されてる
   len = strlen( String );
//  	printf("%d\n",len);
    
    
//    Sが以下の 2条件を満たすとき、またその時に限り,Sを「踏みやすい」文字列といいます。
//奇数文字目がすべて R, U, D のいずれか。
//偶数文字目がすべて L, U, D のいずれか。
    
    int cL,cR;
    cL = 0;
    cR = 0;
    for(i=0;i<len;i++){
        if ( ( (i%2 == 0) && (String[i] == 'L')) 
           ||( (i%2 != 0) && (String[i] == 'R')) ){
          printf("No");
          cL =1;
          break;
        }
    }
    
	if(cL ==0) printf("Yes");
    
    
    
   
  
  return 0;
   
}

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

Measured memory_bytes: 1008
#include <stdio.h>

int main()
{
    int n, i;
    double x1, x2, x3, x4, y1, y2, y3, y4, eps = 1e-10;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
        if((x1 == x2) && (x3 == x4)) printf("YES\n");
        else if((x1 == x2) || (x3 == x4)) printf("NO\n");
        else if(fabs((y1-y2)/(x1-x2) - (y3-y4)/(x3-x4)) < eps) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int a[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int x;
		int y;
		for (int i = k; i < n; i ++) {
			x = a[i - k];
			y = a[i];
			if (x < y) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}



		sc.close();
	}

}


Measured memory_bytes: 60352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int N,a[200000],ia[200000];
set<int> dones;
int main(){
	cin>>N;
	rep(i,N) cin>>a[i],a[i]--,ia[a[i]]=i;
	ll ans=0;
	dones.insert(-1);
	dones.insert(N);
	rep(v,N){
		auto it=dones.lower_bound(ia[v]);
		int r=(*it);
		it--;
		int l=(*it);
		ans+=(ll)(r-ia[v])*(ia[v]-l)*(v+1);
		dones.insert(ia[v]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 11136
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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 N;

//dfs
vector<string> vec;

void dfs(ll n,ll cha,string str){
  if(n==N-1){vec.push_back(str); return;}
  rep(i,cha+1){
    auto sstr=str;
    sstr+=char(i+'a');
    dfs(n+1,cha,sstr);
  }
  str+=char(cha+1+'a');
  dfs(n+1,cha+1,str);
}
int main()
{
  cin>>N;
  
  //dfs
  vec=vector<string>(0);
  dfs(0,0,"a");
  
  sort(vec.begin(),vec.end());
  
  for(auto str:vec) cout<<str<<endl;
  
  return 0;
}

Measured memory_bytes: 7360
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 
  int64_t N,L;
  cin>>N>>L;

  vector<string> s(N);
  for(int i=0;i<N;i++){
    cin>>s.at(i);
  }	

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

  for(int i=0;i<N;i++){
    cout<<s.at(i);
  }
  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 3584
while(True):
    line=input().rstrip().split(' ')
    a=int(line[0])
    b=int(line[2])
    c=line[1]

    if c=="+":
        print(a+b)
    elif c=="-":
        print(a-b)
    elif c=="*":
        print(a*b)
    elif c=="/":
        print(a//b)
    else:
        break


Measured memory_bytes: 5596
#include <stdio.h>

int main()
{
	int a, b, c;
	char op;
	
	while (1)
	{
		scanf("%d %c %d", &a, &op, &b);

		if (op == '+')
		{
			c = a + b;
		}
		else if (op == '-')
		{
			c = a - b;
		}
		else if (op == '*')
		{
			c = a * b;
		}
		else if (op == '/')
		{
			c = a / b;
		}
		else
		{
			break;
		}
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 600
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	string s;
	cin>>s;
	cout<<string(s,0,SZ(s)-8);
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            if ((n | k) == 0)
                break;
            int cs[] = new int[n];
            for (int i = 0; i < n; i++) {
                cs[i] = sc.nextInt();
            }
            int ck = 0;
            for (int i = 0; i <= n - k; i++) {
                int pro = 1;
                for (int j = 0; j < k; j++) {
                    pro *= cs[i + j];
                }
                ck = Math.max(ck, pro);
            }
            int ckd = 0;
            int ans = 0;
            boolean nogame = true;
            for (int i = 0; i < n; i++) {
                int[] tmp = new int[n];
                for (int j = i + 1; j < n; j++) {
                    for (int p = 0; p < n; p++) {
                        tmp[p] = cs[p];
                    }
                    int temp = tmp[i];
                    tmp[i] = tmp[j];
                    tmp[j] = temp;
                    for (int l = 0; l <= n - k; l++) {
                        int pro = 1;
                        for (int m = 0; m < k; m++) {
                            pro *= tmp[l + m];
                        }
                        ckd = Math.max(ckd, pro);
                        if (ckd >= ck) {
                            nogame = false;
                            ans = Math.max(ckd - ck, ans);
                        }
                    }
                }
            }
            System.out.println(nogame ? "NO GAME" : ans);
        }
    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};
int N;
vector<pair<int, ll>> edge[100010];
vector<bool> color(100010, 0);
void dfs(int x, int ad){
    
    if(ad == -1) color[x] = 1;
    
    for(int i = 0; i < edge[x].size(); i++){
        
        ll cost = edge[x][i].second;
        int nv = edge[x][i].first;
        if(nv == ad) continue;
        if(cost % 2 == 0){
            color[nv] = color[x];
            dfs(nv, x);
        }else{
            color[nv] = (!color[x]);
            dfs(nv, x);
        }
    }
    
}



int main(void){
    cin >> N;
    int U = -1, V = -1;
    for(int i = 0; i < N-1; i++){
        int u, v;
        ll w;
        cin >> u >> v >> w;
        u--, v--;
        edge[u].push_back({v, w});
        edge[v].push_back({u, w});
        if(w % 2 == 1){
            U = u, V = v;
        }
    }
    
    
    if(U == -1){
        for(int i = 0; i < N; i++){
            cout << 0 << endl;
        }
    }else{
        dfs(U, -1);
        for(int i = 0; i < N; i++){
            cout << color[i] << endl;
        }
    }
    
    
    
    
}


Measured memory_bytes: 14336
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(void){
  ll n;
  cin >> n;
  ll ans=0,a,p=0;
  for (int i=0; i<n; i++){
    cin >> a;
    if (a<p) {
      ans+=p-a;
    }
    else p=a;
  }

  cout << ans << endl;
}

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

using namespace std;
#define BUF (100)
#define ll long long 

int h,w;

char s[BUF][BUF];

int main(void){
	cin >> h >> w;

    for(int y=0;y<=h+1;++y){
		for(int x=0;x<=w+1;++x){
			s[y][x]='.';
		}
	}


    for(int y=1;y<=h;++y){
		for(int x=1;x<=w;++x){
			cin >> s[y][x];
		}
	}

	for(int y=1;y<=h;++y){
		for(int x=1;x<=w;++x){
			if(s[y][x]=='#'){
				if(s[y+1][x]=='.' && s[y][x+1]=='.' && s[y-1][x]=='.' && s[y][x-1]=='.' ){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}


	cout << "Yes" << endl;

	return 0;
}


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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define dbg(x) cout<<#x<<"="<<x<<endl
#define all(x) (x).begin(),(x).end()

typedef pair<int,int> P;
typedef pair<P,int> PI;
#define fi first
#define se second

#define INF INT_MAX/3
#define MAX_V 300

struct edge{
  int to,cap,cost,rev;
};

int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void init(int v){
  V=v;
  for(int i=0;i<MAX_V;i++){
    G[i].clear();
  }
}

void add_edge(int from,int to,int cap,int cost){
  //printf("%d -> %d : %d\n", from,to,cap);
  G[from].push_back((edge){to,cap,cost,(int)G[to].size()});
  G[to].push_back((edge){from,0,-cost,(int)G[from].size()-1});
}

int min_cost_flow(int s,int t,int f){
  int res=0;
  memset(h,0,sizeof(h));
  while(f>0){
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update=true;
    while(update){
      update=false;
      for(int v=0;v<V;v++){
        if(dist[v]==INF)continue;
        for(int i=0;i<(int)G[v].size();i++){
          edge &e=G[v][i];
          if(e.cap>0&&dist[e.to]>dist[v]+e.cost){
            dist[e.to]=dist[v]+e.cost;
            prevv[e.to]=v;
            preve[e.to]=i;
            update=true;
          }
        }
      }
    }
    if(dist[t]==INF)return INF;

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*dist[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap-=d;
      G[v][e.rev].cap+=d;
    }
  }
  return res;
}

int N,M;
int g[2][303][303];

int main(){
  cin>>N>>M;
  rep(x,2)rep(y,2){
    int L;
    cin>>L;
    rep(i,L){
      int a,b;
      cin>>a>>b;
      if(x==0) g[y][a][b]++;
      else g[y][b][a]++;
    }
  }

  int source=N+M,sink=N+M+1;

  PI res=PI(P(0,0),0);
  repl(f,1,min(N,M)+1){
    init(N+M+2);

    rep(i,N)add_edge(source,i,1,0);
    rep(i,M)add_edge(N+i,sink,1,0);

    rep(i,N)rep(j,M){
      if(g[0][i][j]==2){
        add_edge(i,N+j,1,-30000);
      }else if(g[0][i][j]==1&&g[1][i][j]==1){
        add_edge(i,N+j,1,-200);
      }else if(g[1][i][j]==2){
        add_edge(i,N+j,1,-1);
      }
    }

    int m=-min_cost_flow(source,sink,f);
    int resa=m/30000;
    int resb=(m-resa*30000)/200;
    int resc=(m-resa*30000-resb*200);
    res=max(res,PI(P(resa,resb),resc));
  }

  cout<<res.fi.fi<<" "<<res.fi.se<<" "<<res.se<<endl;
}



Measured memory_bytes: 3468
#include<stdio.h>

int logt(int a){
	if(a==0)return 0;
	return logt(a/2)+1;
}

double ru2(int a){
	int i;
	double r=1;
	for(i=0;i<a;i++)r*=(0.5);
	return r;
}

int main(){
	int n,k,i;
	double ans=0;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++){
		if(i<k){
			int tmp=logt((int)((k)/(double)i-0.00000001));
			ans+=(ru2(tmp));
		}else ans+=1;
	}
	printf("%.15f\n",ans/(double)n);
	return 0;
}


Measured memory_bytes: 128
n = int(input())
s = input()
ans = 0

for i in range(1, n):
    count = 0
    left = list(set(s[:i]))
    right = list(set(s[i:]))
    for i in left:
        if right.count(i) == 1:
            count += 1
    if count > ans:
        ans = count

print(ans)

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

int ans, H, W;
char c[300][300];

int main(){
	cin >> H >> W;
	rep(i, H)rep(j, W) cin >> c[i][j];
	rep(n, W-1){
		int dp[H+1][H+1];
		int cost[H+1][H+1];
		rep(i, H+1){
			int cnt1 = 0, cnt2 = 0;
			rep(j, i){
				cnt1 += (c[j][n] == c[H-i+j][n+1]);
				cnt2 += (c[j][n+1] == c[H-i+j][n]);
			}
			cost[i][H] = cnt1;
			cost[H][i] = cnt2;
		}
		for(int i=H-1; i>=0; i--){
			for(int j=0; j<H; j++){
				cost[i][j] = cost[i+1][j+1] - (c[i][n] == c[j][n+1]);
			}
		}
		rep(i, H+1){ dp[i][0] = 0, dp[0][i] = 0; }
		for(int i=1; i<H+1; i++){
			for(int j=1; j<H+1; j++){
				dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + cost[i][j];
			}
		}
		ans += dp[H][H];
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int solve(ll a, ll b , ll c, ll d) {
    if (a < b) return 0;
    if (d < b) return 0;
    if (c >= b) return 1;
    if (a % b > c) return 0;
    ll diff = __gcd(b, d);
    ll base = a % diff;
    ll mx = base % diff - diff + b;
    return mx <= c;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n){
        REP(_, n) {
            ll a, b, c, d;
            cin >> a >> b >> c >> d;
            cout << (solve(a, b, c, d) ? "Yes" : "No") << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    string n;
    cin >> n;
    int a, b, c, d;
    a = n[0] - '0';
    b = n[1] - '0';
    c = n[2] - '0';
    d = n[3] - '0';
    
    if(a + b + c + d == 7){
        cout << to_string(a) + "+" + to_string(b) + "+" + to_string(c) + "+" + to_string(d) + "=7" << endl;
    }else if(a - b + c + d == 7){
        cout << to_string(a) + "-" + to_string(b) + "+" + to_string(c) + "+" + to_string(d) + "=7" << endl;
    }else if(a + b - c + d == 7){
        cout << to_string(a) + "+" + to_string(b) + "-" + to_string(c) + "+" + to_string(d) + "=7" << endl;
    }else if(a + b + c - d == 7){
        cout << to_string(a) + "+" + to_string(b) + "+" + to_string(c) + "-" + to_string(d) + "=7" << endl;
    }else if(a - b - c + d == 7){
        cout << to_string(a) + "-" + to_string(b) + "-" + to_string(c) + "+" + to_string(d) + "=7" << endl;
    }else if(a + b - c - d == 7){
        cout << to_string(a) + "+" + to_string(b) + "-" + to_string(c) + "-" + to_string(d) + "=7" << endl;
    }else if(a - b + c - d == 7){
        cout << to_string(a) + "-" + to_string(b) + "+" + to_string(c) + "-" + to_string(d) + "=7" << endl;
    }else if(a - b - c - d == 7){
        cout << to_string(a) + "-" + to_string(b) + "-" + to_string(c) + "-" + to_string(d) + "=7" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	vector<ll> b(n);
	REP(i,n) cin>>a[i]>>b[i];
	bool d=true;
	REP(i,n) if(a[i]!=b[i]) d=false;
	if(d) {
		cout<<0<<endl;
		return 0;
	}
	ll sum=0;
	REP(i,n) sum+=a[i];
	ll ans=0;
	REP(i,n) {
		if(a[i]>b[i]) {
			ans=max(ans,sum-b[i]);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
using static System.Console;
using static System.Convert;
class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var length = ToInt32(input[0]);
        var num1 = ToInt32(input[1]);
        var num2 = ToInt32(input[2]);
        var result = num1 <= num2 ? num2 - (num1 + length) : num1 - (num2 + length);
        if (result < 0) result = 0;
        WriteLine(result);
    }
}

Measured memory_bytes: 11220
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n, int r) {
vvl v(n + 1,vl(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}


int main(){
	int a,b;
	cin>>a>>b;
	if(a==b)print("Yes");
	else print("No");


}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 300005;

/* ...o(^-^)o... */

int main(){
    lint k; cin >> k;
    lint sum = 0;
    repn(i, k) repn(j, k) repn(l, k){
        sum += gcd(i, gcd(j, l));
    }
    out(sum);
}

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

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

    if(n % 111 == 0) {
        cout << n << endl;
        return 0;
    }
    else {
        cout << 111 * ((n / 111)+1) << endl;
    }
}

Measured memory_bytes: 3604
// In the name of Allah the Lord of the Worlds.

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

typedef long long ll;

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

    int n , m;
    cin >> n >> m;
    priority_queue<int>pq;
    for(int i=0;i<n;i++){
        int in;
        cin >> in;
        pq.push(in);
    }
    for(int i=0;i<m;i++){
        int now = pq.top();
        pq.pop();
        pq.push(now/2);
    }
    ll ans = 0;
    while(!pq.empty()){
        ans+=pq.top();
        pq.pop();
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 892
#  105 B
N = int(input())
cMax = N // 4
dMax = N // 7
found = False
for c in range(cMax+1):
    for d in range(dMax+1):
        if c*4+d*7==N:
            found = True
            break
    if found: break
#print(c, d)#
if found: print('Yes')
else: print('No')

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

struct Dice {
  int top, front, right, left, back, bottom;
  // constructor
  //
  //         top:1
  //           |
  // left:4--front:2--right:3--back:5
  //           |
  //         bottom:6
  //
  Dice(vector<int> v) {
    top    = v.at(0);
    front  = v.at(1);
    right  = v.at(2);
    left   = v.at(3);
    back   = v.at(4);
    bottom = v.at(5);
  }

  void roll(char c) {
    int old_top = top;
    if (c == 'E') {
      top    = left;
      left   = bottom;
      bottom = right;
      right  = old_top;
    } else if (c == 'N') {
      top    = front;
      front  = bottom;
      bottom = back;
      back   = old_top;
    } else if (c == 'S') {
      top    = back;
      back   = bottom;
      bottom = front;
      front  = old_top;
    } else if (c == 'W') {
      top    = right;
      right  = bottom;
      bottom = left;
      left   = old_top;
    }
  }

  // 1回、右回転させる
  // NOTE: ダイスを転がすわけではなく、見る位置を変える
  void rotate_front_surface() {
    int old_front = front;
    front = left;
    left = back;
    back = right;
    right = old_front;
  }

  bool operator==(Dice other) {
    if (top == other.top
        && front == other.front
        && right == other.right
        && left == other.left
        && back == other.back
        && bottom == other.bottom) {
      return true;
    } else {
      return false;
    }
  }

  // 表・裏・左・右の4方向から比較する
  bool matches_somewhere_in_4_directions(Dice other) {
    for (int i = 0; i < 4; i++) {
      other.rotate_front_surface();
      if (top == other.top
          && front == other.front
          && right == other.right
          && left == other.left
          && back == other.back
          && bottom == other.bottom)
      {
        return true;
      }
    }
    return false;
  }
};

int main() {
  // 1つ目のサイコロ
  vector<int> v1(6);
  for (int i = 0; i < 6; i++) {
    cin >> v1.at(i);
  }
  Dice dice1(v1);

  // 2つ目のサイコロ
  vector<int> v2(6);
  for (int i = 0; i < 6; i++) {
    cin >> v2.at(i);
  }
  Dice dice2(v2);

  bool matching = false;
  // サイコロ2を転がして、上面を1から6のラベルに変えていく
  // サイコロ2のそれぞれのラベルが上面になった状態で、
  // 前後左右からサイコロ2を見て、サイコロ1と比較する
  // top:1
  if (dice1.matches_somewhere_in_4_directions(dice2)) {
    matching = true;
  }
  // top:1 --> front:2
  dice2.roll('N');
  if (dice1.matches_somewhere_in_4_directions(dice2)) {
    matching = true;
  }
  // front:2 --> right:3
  dice2.roll('E');
  if (dice1.matches_somewhere_in_4_directions(dice2)) {
    matching = true;
  }
  // right:3 --> back:5
  dice2.roll('E');
  if (dice1.matches_somewhere_in_4_directions(dice2)) {
    matching = true;
  }
  // back:5 --> left:4
  dice2.roll('E');
  if (dice1.matches_somewhere_in_4_directions(dice2)) {
    matching = true;
  }
  // left:4 --> front:2 --> bottom:6
  dice2.roll('E');
  dice2.roll('N');
  if (dice1.matches_somewhere_in_4_directions(dice2)) {
    matching = true;
  }

  cout << (matching ? "Yes" : "No") << endl;
  return 0;
}



Measured memory_bytes: 3156
package main

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

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n := io.NextInt()
	count := make(map[string]int, 4)
	for i := 0; i < n; i++ {
		si := io.Next()
		count[si]++
	}
	keys := []string{"AC", "WA", "TLE", "RE"}
	for _, key := range keys {
		io.Printf("%s x %d\n", key, count[key])
	}
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Printf is awapper of fmt.Fprintf
func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}


Measured memory_bytes: 5036
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		double x[] = new double[4];
		double y[] = new double[4];

		for(int j=0; j<n; j++){
			for(int i=0; i<4; i++){
				x[i] = scan.nextDouble();
				y[i] = scan.nextDouble();
			}

			double d1 = (y[1]-y[0])/(x[1]-x[0]);
			double d2 = (y[3]-y[2])/(x[3]-x[2]);

			System.out.println(d1==d2 ? "YES" : "NO");

		}
	}
}

Measured memory_bytes: 20556
import numpy as np


n = int(input())
st = [tuple(input().split()) for i in range(n)]
x = input()
T = []

for i, (s, t) in enumerate(st):
    T.append(int(t))

    if s == x:
        fin = i

T = np.array(T)

ans = np.sum(T[fin+1:])

print(ans)

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

#define sc second
#define fr first

#define ll long long
#define pi pair<int,int>
#define ppi pair<pi,pi>
#define mp make_pair
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int n , k;
string s;

int main()
{

	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

    cin >> n >> k;
    cin >> s;
    vector<pair<int,int>>v;
    int cnt = 0,t = s[0] - '0' , cnta = 0;
    int ans = 0;
    for(int i = 0;i < n;i++)
    {
        s[i]-='0';
        if(s[i] == t)
            cnt++;
        else{
            v.push_back({cnt , t});
            if(t == 1)ans = max(ans , cnt);
            cnt = 1 , t = s[i];
        }
    }
    v.push_back({cnt,t});
    if(t == 1)ans = max(ans , cnt);
    int i = 0 , j = 0;
    cnt = 0,cnta = 0;
    n = v.size();
    while(i < n)
    {
        while(j < n && (cnt + (!v[j].sc)) <= k)
        {
            cnt += (!v[j].sc);
            cnta += v[j].fr;
            j++;
        }
        ans = max(ans , cnta);
        cnt -= (!v[i].sc);
        cnta -= v[i].fr;
        i++;
    }
    cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define F first
#define S second
#define ld long douroote
#define pb push_back
#define sz size
#define ll long long
#define ull unsigned long long
#define INF 0x7f7f7f7f
#define sc(a) scanf("%d",&a)
#define scll(a) scanf("%lld",&a)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf(" %c",&a)
#define scs(a) scanf(" %s",a)
#define me(a,b) memset(a,b,sizeof a)
#define all(a) a.begin(),a.end()
#define allr(a,n) a,a+n
#define loop(a,s,e) for(ll a=s;a<=e;a++)
#define read_arr(a,s,n) for(int i=s;i<n+s;i++){sc(a[i]);}
#define read_arr_ll(a,s,n) for(int i=s;i<n+s;i++){scll(a[i]);}
#define err(a,s) cerr<<a<<s;
#define err_arr(a,s,n) for(int i=s;i<n+s;i++){cerr<<a[i]<<" ";}cerr<<endl;
#define prtll(x) printf("%lld",x);
#define prt(x) printf("%d",x);
using namespace std;
const int N=1e4+10;
char s[N];
int n,d,mem[N][110][3],mod=1e9+7;
int dp(int ind,int sum,int ok){
if(ind==n){return (sum==0);}
int &ret=mem[ind][sum][ok];
if(ret!=-1){return ret;}
ret=0;
int dig=s[ind]-'0';
if(ok){
loop(i,0,9){ret+=dp(ind+1,(sum+i)%d,ok)%mod;ret%=mod;}
}
else{
loop(i,0,dig-1){ret+=dp(ind+1,(sum+i)%d,1)%mod;ret%=mod;}
ret+=dp(ind+1,(sum+dig)%d,0)%mod;
ret%=mod;
}
return ret;
}
int main(){
me(mem,-1);
scs(s);
sc(d);
n=strlen(s);
int ans=((dp(0,0,0)-1)+mod)%mod;
printf("%d\n",ans);
}

/**
**/


Measured memory_bytes: 13952
N = int(input())
MOD = 10**9+7
dp = [[0]*3 for _ in range(61)]
dp[60][0] = 1
for d in range(59,-1,-1):
  for s in range(3):
    for k in range(3):
      ns = min(2, 2*s + ((N>>d)&1) - k)
      if ns < 0:
        continue
      dp[d][ns] += dp[d+1][s]
      dp[d][ns] %= MOD

print(sum(dp[0])%MOD)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
vector<int> dp(100000,INT_MAX);
int back(vector<int> & heights,int k, int index){
    if(index>heights.size()) return INT_MAX;
    if(dp[index]!=INT_MAX) return dp[index];
    for(int i=1;i<k+1;i++){
    int step1=INT_MAX;
    
    if(index+i<heights.size()) step1= abs(heights[index+i]-heights[index])+back(heights,k,index+i);
    
       dp[index]= min(step1,dp[index]);
    }
    return dp[index];
    
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	vector<int> heights(n);
	for(int i=0;i<n;i++) cin>>heights[i];
	dp[heights.size()-1]=0;
	int ans= back(heights,k,0);
	cout<< ans<<endl;
	return 0;
}

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

using namespace std;

int main(){
    string s;
	cin >> s;
	if(s.size()==2)
		cout << s << endl;
	else if(s.size()==3){
		for(int i=2;i>=0;--i) 
			cout << s[i] ;
		cout << endl;
	}
}


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

int main(void) {
	int N, i, A = 0, b = 0, j, c = 0;
	cin >> N;
	int s[100];
	for (i = 1; i <= N; i++) {
		cin >> s[i - 1];
	}
	for (i = 1; i <= N; i++) {
		A += s[i - 1];
	}

	for (j = 1; j <= N; j++) {
		for (i = 1; i <= N; i++) {
			if (s[i - 1] >= s[i]) {
				b = s[i - 1];
				s[i - 1] = s[i];
				s[i] = b;
			}
		}
		i = 1;
	}
	if (A % 10 != 0) {
		cout << A << endl;
		return 0;
	}
	else {
		for (i = 1; i <= N; i++) {
			if ((A - s[i - 1]) % 10 != 0) {
				cout << A - s[i - 1] << endl;
				c = 1;
				goto aaaa;
			}
		}
	}
aaaa:
	if (c == 0) {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
p = 2
count = []

print('{}:'.format(n), end = ' ')

while p*p  <= n: 
    while n%p == 0: 
        n = n//p
        count.append(p)
    p += 1


if not n == 1:
     count.append(n)

print(*count)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;++i)
int main(){
  int n;
  while(cin>>n,n){
    int w,h; cin>>w>>h;
    vector<vector<int> > c(h,vector<int>(w,0));
    FOR(i,0,n){
      int x,y; cin>>x>>y;
      c[--y][--x]=1;
    }
    int s,t; cin>>s>>t;
    int ans=0;
    FOR(i,0,h-t+1) FOR(j,0,w-s+1){
      int a=0;
      FOR(k,i,i+t) FOR(l,j,j+s)
        a+=c[k][l];
      ans=max(ans,a);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define str string
#define deb_arr(arr,n) for(ll i=0;i<(n);i++){ cout << (arr)[i] << " ";}
#define in_arr0(arr,n) for(ll i=0;i<(n);i++){ cin >> (arr)[i]; }
#define in_arr1(arr,n) for(ll i=1;i<=(n);i++){ cin >> (arr)[i];}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define vll vector<ll> 
#define fr(n) for(i=0;i<(n);i++)
#define fr1(n) for(i=1;i<=(n);i++)
#define pll pair<ll,ll>
#define f first
#define s second
#define vpll vector<pll>
#define ump unordered_map
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define debb(x) cout << (x) << endl
#define IN(a,b) ((a).find(b)!=(a).end())
#define pb push_back
#define mkp make_pair
#define PI M_PI
#define INF 1e18
#define deb(x) if(ON) cout << #x <<" : " << x << endl
#define fast ios_base::sync_with_stdio(false)
#define io cin.tie(NULL),cout.tie(NULL)
#define ON !false
ll dx[]={0,-1,0,1};
ll dy[]={1,0,-1,0};
const ll mod=1e9+7;
inline ll add(ll a,ll b){
    return  ((a%mod)+(b%mod)+mod)%mod;
}
inline ll mul(ll a,ll b){
    return ((a%mod)*(b%mod)+mod)%mod;
}
void pause(ll id){
    cout << "Waiting " << id << endl;
    cin >> id;
}

const int mxn=1e6+10;

ll arr[mxn];
ll minPrime[mxn];

void init(){

	ll i,j;
	for(i=2;(i*i)<mxn;i++){
		if(minPrime[i]==0){
			for(j=i*i;j<mxn;j+=i){
				if(minPrime[j]==0){
					minPrime[j]=i;
				}
			}
		}
	}
	for(i=1;i<mxn;i++){
		if(minPrime[i]==0){
			minPrime[i]=i;
		}
	}

    return ;
}


signed main(){
    fast;
    io;
    if(!true){
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    }
    init();
    ll i,j;
    // iota(itf,its) ;
    // n=unique(a+1,a+1+n,n)-(a+1);

    ll n;
    cin >> n;


	for(i=1;i<=n;i++){
		cin >> arr[i];
	}

	ll g=arr[1];
	for(i=2;i<=n;i++){
		g=__gcd(g,arr[i]);
	}

	if(g!=1){
		debb("not coprime");
		return 0;
	}

	// g==1;

	unordered_map<ll,ll> mp;
	mp.reserve(n);

	bool flag=true;
	for(i=n;i>=1;i--){

		ll x=arr[i];


		while(x > 1){
			ll temp=minPrime[x];
			if(mp.count(temp)){
				flag=false;
				break;
			}
			while(x%temp == 0){
				x/=temp;
			}

			mp[temp]=1;
		}


	}
	if(flag){
		debb("pairwise coprime");
	}
	else{
		debb("setwise coprime");
	}

    return 0;
}


Measured memory_bytes: 29364
#include <stdio.h>

int main(void)
{
	long long int a[5] = { 0 };
	int m = 0;
	scanf("%lld%lld%lld%lld%lld", &a[0], &a[1], &a[2], &a[3], &a[4]);

	for (int i = 0; i < 5; i++) {
		if (a[i] == 0)
			m = i+1;
	}
	printf("%d\n", m);
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
 
using namespace std;

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

  int n, m;
  string s;
  cin >> n >> m >> s;
  vector<int> ans;

  int i;
  while(n > 0){
    for( i = m ; i > 0 ; i -- ){
      if( n - i >= 0 && s[n - i] == '0' ){
	ans.pu(i);
	n -= i;
	break;
      }
    }

    if(i == 0){
      cout << -1 << '\n';
      return 0;
    }
    // cout<< n << " ";
  }

  for(i = ans.size() - 1 ; i > 0 ; i -- ){
    cout << ans[i] << " ";
  }
  cout << ans[0] << '\n';
  return 0;
}


Measured memory_bytes: 1096
from collections import defaultdict

s = input()
n = len(s)
MOD = 2019

dd = defaultdict(int)
dd[0] += 1
prev = 0
for i in reversed(range(n)):
    x = (prev + int(s[i])*pow(10, n-i, MOD)) % MOD
    dd[x] += 1
    prev = x

ans = sum(v*(v-1)//2 for v in dd.values())
print(ans)


Measured memory_bytes: 9656
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)



signed main(){

	int N, K;
	vector<P> v;
	cin >> N >> K;
	for (int i = 0; i < N; i++){
		int a, b;
		cin >> a >> b;
		v.push_back({ a, b });
	}
	sort(v.begin(), v.end());
	int k = 0;
	for (int i = 0; i < N; i++){
		k += v[i].second;
		if (k >= K){
			cout << v[i].first << endl;
			return 0;
		}
	}
	

	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin>>n;
	int ans=0;
	for(int i=2;1ll*i*i<=n;i++){
		if(n%i==0){
			int cnt=0,tot=1;
			while(n%i==0){
				n/=i,cnt++;
				if(cnt==tot)
					cnt=0,ans++,tot++;
			}
		}
	}
	if(n>1) ans++;
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  string str;
  int i = 0;
  getline(cin, str);
  while(str[i]){
    if(str[i] >= 'a' && str[i] <= 'z'){
       str[i] -= ('a'-'A');
    } 
    else if(str[i] >= 'A' && str[i] < 'a'){
       str[i] -= ('A'-'a');
    }
    cout << str[i];
    i++;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;



// modinvも呼ぶ！！
// (a/b)%P の場合は，(a%P)*modinv(b)%P とする
ll modinv(ll a) {
    ll b = MOD, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

ll nck[202020];

void nCk(ll n, ll k) {
    nck[1]=n;
    for(int i=2;i<=k;i++){
        nck[i]=nck[i-1];
        nck[i]*=n-i+1;
        nck[i]%=MOD;
        nck[i]*=modinv(i);
        nck[i]%=MOD;
    }
}

// xのn乗%modを計算
ll mod_pow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

int main() {

    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=mod_pow(2,n);
    nCk(n,a);
    ans-=nck[a];
    ans+=MOD;
    ans%=MOD;
    nCk(n,b);
    ans-=nck[b];
    ans+=MOD;
    ans%=MOD;
    fin(ans-1);
    
}


Measured memory_bytes: 5172
/*
 * Improve XOR funcition using != notation.
 * Ref: http://stackoverflow.com/questions/1596668/logical-xor-operator-in-c
 */
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

pair<int, bool> p[100005];

int main(){
    //freopen("c2.in", "r", stdin);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int ai;
        cin >> ai;
        p[i].first = ai;
        p[i].second = i&1;  // 0: even, 1: odd
    }
    sort(p, p + n);

    int total = 0;
    for (int i = 0; i < n; ++i) {
        if(p[i].second != (bool)(i&1)) {
            total++;
        }
    }
    cout << total / 2 << endl;


    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N],c[N];
int n; 
inline bool solve(int t){
	for(int i=1;i<=n*2-1;i++)b[i]=(a[i]>=t),c[i]=-1;
	for(int i=2;i<=n*2-1;i++)if(b[i]==b[i-1]){
		c[i]=c[i-1]=b[i];
	}
	int mid=n;
	if(~c[mid])return c[mid];
	for(int i=1;i<n;++i){
		if(~c[mid-i])return c[mid-i];
		if(~c[mid+i])return c[mid+i];
	}
	return b[1];
}

int main()
{
	cin >> n;
	for(int i=1;i<=n*2-1;i++)scanf("%d",&a[i]);
	int l=1,r=n*2-1;
	while(l<r){
		int mid=(l+r+1)>>1;
		bool ret=solve(mid);
		if(ret==1) l=mid;
		else r=mid-1;
	}
	printf("%d\n",l);
}

Measured memory_bytes: 2688
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            if (str == "SUN") Console.WriteLine(7);
            else if (str == "MON") Console.WriteLine(6);
            else if (str == "TUE") Console.WriteLine(5);
            else if (str == "WED") Console.WriteLine(4);
            else if (str == "THU") Console.WriteLine(3);
            else if (str == "FRI") Console.WriteLine(2);
            else if (str == "SAT") Console.WriteLine(1);
        }
    }
}


Measured memory_bytes: 11092