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

int main() {
    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vector<long long> A(X), B(Y), C(Z);
    for (int i = 0; i < X; ++i) cin >> A[i];
    for (int i = 0; i < Y; ++i) cin >> B[i];
    for (int i = 0; i < Z; ++i) cin >> C[i];
    
    // A + B の上位 K 個
    vector<long long> AB;
    for (int i = 0; i < X; ++i) for (int j = 0; j < Y; ++j) AB.push_back(A[i] + B[j]);
    sort(AB.begin(), AB.end(), greater<long long>());
    AB.resize(K);
    
    // AB と C
    vector<long long> ABC;
    for (int i = 0; i < AB.size(); ++i) for (int j = 0; j < Z; ++j) ABC.push_back(AB[i] + C[j]);
    sort(ABC.begin(), ABC.end(), greater<long long>());
    
    // 出力
    for (int k = 0; k < K; ++k) cout << ABC[k] << endl;
}

Measured memory_bytes: 43368
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
int ke (int n){
    n--;
    if(n == 1 )return 0;
    int ans = 1;
    while (0 < n){
        ans *= n;
        n--;
    }
    return ans ;

}
int main(){
   int k,n;

   cin >> k >> n;
   vector<int> vec(n+1);
   REP(i,n){
       cin >> vec[i]; 
   }

    vec[n] = k;

    vector <int> sub(n);
    REP(i,n){
        sub[i] = vec[i+1] - vec[i];
    }
    sub[n-1] += vec[0];
    SORT(sub);
    ll ans = 0;
    REP(i,n-1){
        ans += sub[i];
    }

    cout << ans <<endl;

}





Measured memory_bytes: 1792
n, m, l = map(int, input().split())

vec_A = [[] for i in range(n)]
for i in range(n):
    vec_A[i] = list(map(int, input().split()))
    
vec_B = [[] for i in range(m)]
for i in range(m):
    vec_B[i] = list(map(int, input().split()))

vec_C = [[0]*l for i in range(n)]
    
for i in range(n):
    for j in range(l):
        for k in range(m):
            vec_C[i][j] += vec_A[i][k] * vec_B[k][j]

for row in range(n):
    print('{}'.format(vec_C[row][0]), end='')
    for col in range(1, l):
        print(' {}'.format(vec_C[row][col]), end='')
    print()


Measured memory_bytes: 7048
#include<iostream>
#include<string>
using namespace std;
int main(){
	int c[3];
	while(cin>>c[0]>>c[1]>>c[2]){
		int a[10],count=0;
		for(int i=0;i<10;i++)
			a[i]=1;
		a[c[0]-1]=0;
		a[c[1]-1]=0;
		a[c[2]-1]=0;
		for(int i=0;i<10;i++){
			if(c[0]+c[1]+i+1>20){
				a[i]=0;
			}
			count+=a[i];
		}
		if(count>3.5)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> data(n);
  for(int i = 0; i < n; i++) {
    cin >> data.at(i);
  }
  int count = 0;
  for(int i = 1; i < n - 1; i++) {
    if(data.at(i - 1) < data.at(i) && data.at(i) < data.at(i + 1)) {
      count++;
    }
    else if(data.at(i - 1) > data.at(i) && data.at(i) > data.at(i + 1)) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int >a(100000,0);
vector<int >b(100000,0);
vector<int >c(100000,0);
vector<vector<int> >memo(3,vector<int >(100000,-1));
int calc(int day,int task){
	if(day==n)return 0;
	if(memo[task][day]!=-1)return memo[task][day];
  	else{
      int maxi=0;
       if(task==0){
            maxi = max(b[day]+calc(day+1,1),c[day]+calc(day+1,2));
        }
       if(task==1){
            maxi = max(a[day]+calc(day+1,0),c[day]+calc(day+1,2));
        }
       if(task==2){
            maxi = max(b[day]+calc(day+1,1),a[day]+calc(day+1,0));
        }
    memo[task][day]=maxi;
     return maxi;
    }
}
int main(){
	cin>>n;
  	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
	int maxi=0;
  //Iam choosing the 0th day
    maxi = max(maxi,a[0]+calc(1,0));
    maxi = max(maxi,b[0]+calc(1,1));
    maxi = max(maxi,c[0]+calc(1,2));

	cout<<maxi;
}

Measured memory_bytes: 10180
x1,y1,x2,y2 = list(map(int,input().split()))

ad_x = x1 - x2
ad_y = y1 - y2

x3 = x2 + int(ad_y)
x4 = x3 + int(ad_x)

y3 = y2 - int(ad_x)
y4 = y1 - int(ad_x)

print(x3, y3, x4, y4)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}

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


int main() {
  
  long long N;
  cin>>N;
  
  long long ans=0;
  
  
  if(N%2==1){
    cout<<ans<<endl;
  }
  else{
    long long x=10;
    while(x<=N){
      ans+=N/x;
      x*=5;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out

#define N 123456*2+100
bool num[N];
void eratosmake(){
    //整数を列挙して素数の候補とする
    for(int i=0;i<N;i++)num[i]=true;
        //0と1を消す
        num[0]=num[1]=false;
        //iを残してiの倍数を消していく
        for(int i=2;i<N;i++){
            if(num[i]){
            for(int j=i+i;j<N;j+=i){
                num[j]=false;
            }
        }
    }
}
bool isprime(int n){
    return num[n];
}

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int i,n;
    eratosmake();
    while(1){
        cin>>n;
        if(n==0)break;
        int ans=0;
        for(i=n+1;i<=2*n;i++)if(num[i])ans++;
        cout<<ans<<endl;
    }
    
    
//////////////////////////////////////////////////////
return 0;}








Measured memory_bytes: 3364
def dfs(s, mx, N):
    if len(s) == N:
        print s
    else:
        for ch in range(ord('a'), ord(mx) + 1):
            if chr(ch) == mx:
                dfs(s + chr(ch), chr(ord(mx) + 1), N)
            else:
                dfs(s + chr(ch), mx, N)

def solve2():
    N = int(raw_input())
    dfs('', 'a', N)

if __name__ == '__main__':
    solve2()


Measured memory_bytes: 39324
N,M,K=map(int, input().split())
div=10**9+7

def modinv(a, m):
    b = m
    u = 1
    v = 0
    while (b):
        t = a // b
        a -= t * b 
        a = a^b
        b = a^b
        a = a^b
        u -= t * v
        u = u^v
        v = u^v
        u = u^v
    u %= m 
    if (u < 0): u += m
    return u

def ncr(n, r):
    res = 1
    for i in range(1, r+1):
        res = res*n*modinv(i, div) % div
        n = n-1
    return res % div

result = 0
comb = ncr(N*M-2, K-2)
for d in range(1, N):
    result += d*comb*M*M*(N-d)

for d in range(1, M):
    result += d*comb*(M-d)*N*N

print(result % div)


Measured memory_bytes: 40812
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, h;
    cin >> n >> h;
    int a[n], b[n], m = 0, d = 0;
    for (int i = 0 ; i < n ; i++) cin >> a[i] >> b[i], m = max(m, a[i]);
    sort(b, b + n);
    for (int i = n - 1 ; i >= 0 ; i--) {
    	if (b[i] < m) break;
    	h -= b[i];
    	d++;
    	if (h <= 0) {
            cout << d;
            return 0;
        }
	}
	if (h % m == 0) cout << d + h / m;
	else cout << d + h / m + 1;
}

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

long long i,j,k,n,m,hasil;

int main()
{
	cin>>n>>m;
	if (abs(n-m)>=2)
	 {
	 	cout<<0<<"\n";
	 	return 0;
	 }
	else
	 {
	 	long long kali=min(n,m);
	 	long long satunya=max(n,m);
	 	hasil=1;
	 	if (n==m)
	 	{
	 		long long hasil1=1;
	 		long long hasil2=1;
	 		for (i=1;i<=n;i++)
	 		{
	 			hasil1=((hasil1%1000000007)*(i%1000000007))%1000000007;
	 			hasil2=((hasil2%1000000007)*(i%1000000007))%1000000007;
			 }
			hasil=(2*(hasil1%1000000007)*(hasil2%1000000007))%1000000007;
			cout<<hasil<<"\n";
			return 0;
		 }
		else
		 {
		 	long long hasil1=1;
		 	long long hasil2=1;
		 	for (i=1;i<=satunya;i++)
		 	{
		 		if (i==satunya)
		 		 hasil1=((hasil1%1000000007)*(i%1000000007))%1000000007;
		 		else
		 		 {
		 		 	hasil1=((hasil1%1000000007)*(i%1000000007))%1000000007;
		 		 	hasil2=((hasil2%1000000007)*(i%1000000007))%1000000007;
				 }
			 }
			 hasil=((hasil1%1000000007)*(hasil2%1000000007))%1000000007;
			 cout<<hasil<<"\n";
			 return 0;
		 }
	 }
}

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

int main()
{
    ll x, k, d;
    cin>>x>>k>>d;
    if(x<0)x=-x;
    ll kp = (x/d);
    ll ans;
    if(kp>=k)ans=x-(d*k);
    else{
        ll p1=x-(d*kp);
        ll p2=d-p1;
        k = k-kp;
        if(k%2==0)ans=p1;
        else ans=p2;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#define f first
#define s second
#define INF (1<<29)
using namespace std;

typedef pair<int,int> P;

int h,w,s,u[34][34];
P memo[34][34][34][34];

P rec(int x1,int y1,int x2,int y2){
	
	if(memo[x1][y1][x2][y2]!=P(0,INF))return memo[x1][y1][x2][y2];
	if(u[h-1][w-1]-(u[y2-1][x2-1]-u[y2-1][x1-1]-u[y1-1][x2-1]+u[y1-1][x1-1])>s)return P(0,INF);
	P res=P(1,s-(u[h-1][w-1]-(u[y2-1][x2-1]-u[y2-1][x1-1]-u[y1-1][x2-1]+u[y1-1][x1-1])));
	
	for(int i=y1+1;i<y2;i++){
		P a=rec(x1,y1,x2,i);
		P b=rec(x1,i,x2,y2);
		res=max(res,P(a.f+b.f,min(a.s,b.s)));
	}
	
	for(int i=x1+1;i<x2;i++){
		P a=rec(x1,y1,i,y2);
		P b=rec(i,y1,x2,y2);
		res=max(res,P(a.f+b.f,min(a.s,b.s)));
	}
	
	return memo[x1][y1][x2][y2]=res;
}

int main(void){
	
	while(cin >> h >> w >> s,h++|w++|s){
		
		fill(u[0],u[34],0);
		
		for(int i=0;i<34;i++)
			for(int j=0;j<34;j++)
				for(int k=0;k<34;k++)
					for(int l=0;l<34;l++)memo[i][j][k][l]=P(0,INF);
		
		for(int i=1;i<h;i++)
			for(int j=1;j<w;j++)cin >> u[i][j];
		
		for(int i=1;i<h;i++)
			for(int j=1;j<w;j++)
				u[i][j]+=u[i-1][j]+u[i][j-1]-u[i-1][j-1];
		
		P ans=rec(1,1,w,h);
		cout << ans.f << " " << ans.s << endl;
	}
	return 0;
}

Measured memory_bytes: 11616
'use strict'

function main(s) {

  s = s.split('\n');

  const N = Number(s[0].split(' ')[0]);
  const link = s.slice(1, -1).map(l => l.split(' ').map(n => Number(n)));

  const mx = [...Array(N)].map(l => [...Array(N)].fill(0));

  for (const l of link) {
    const fr = l[0] - 1;
    const to = l[1] - 1;
    mx[fr][to] = 1;
    mx[to][fr] = 1;
  }

  let sum = 0;
  const dfs = (v, visited) => {
    if (visited.every(v => v === true)) sum += 1;

    for (let i = 0; i < N; i++) {
      if (mx[v][i] === 0) continue;
      if (visited[i]) continue;

      visited[i] = true;
      dfs(i, visited);
      visited[i] = false;
    }
    return;
  }

  const visited = [true, ...[...Array(N - 1)].map(l => false)];
  dfs(0, visited);

  console.log(sum);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll N;
  cin>>N;
  vector<ll> v(N);
  rep(i,N) cin>>v[i];
  rep(i,N) v[i]--;
  vector<ll> place(N);
  rep(i,N) place[v[i]] = i;
  set<ll> s;
  s.insert(-1);
  s.insert(N);
  ll ans = 0;
  rep(i,N){
    auto iter = s.upper_bound(place[i]);
    auto itel = iter;
    itel--;
    ans += (*iter-place[i])*(place[i]-*itel)*(i+1);
    s.insert(place[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 15640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define INF 1200000000



int main(){
    
    int N,K,R,S,P;
    cin>>N>>K>>R>>S>>P;
    char T[100100];
    cin>>T;
    int hand[100100];
    rep(i,0,N){
        if(T[i]=='r')hand[i]=3;
        if(T[i]=='s')hand[i]=1;
        if(T[i]=='p')hand[i]=2;
    }
    long long ans=0;
    rep(i,0,K){
                if(hand[i]==1)ans+=R;
                if(hand[i]==2)ans+=S;
                if(hand[i]==3)ans+=P;        
    }
    rep(i,0,K){
        rep(j,1,(N/K)+3){
            if((i+j*K)>N)break;
            if(hand[i+j*K]!=hand[i+(j-1)*K]){
                if(hand[i+j*K]==1)ans+=R;
                if(hand[i+j*K]==2)ans+=S;
                if(hand[i+j*K]==3)ans+=P;
            }
            else{
                hand[i+j*K]=0;
            }
        }
    }
    
    cout<<ans<<endl;
}




Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  string s,t; cin >>s>>t;
  int n=s.size();
  rep(i,n){
    if(s[i]!=t[i]) {
      cout <<"No"<<endl;
      return 0;
    }
  }
  cout <<"Yes"<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}

struct SCC{
    int n;
    vector<vector<int>> g,rg;
    vector<int> vs,cmp;
    vector<bool> used;
    SCC(int _n){
        n=_n;
        g=vector<vector<int>>(n);rg=g;
        cmp=vector<int>(n);used=vector<bool>(n);
    }
    void add_edge(int f, int t){
        g[f].push_back(t);
        rg[t].push_back(f);
    }
    int init(){
        rep(i,n)if(!used[i])dfs(i);
        int k=0;
        used=vector<bool>(n,false);
        per(i,n){
            if(!used[vs[i]]){
                rdfs(vs[i],k);
                k++;
            }
        }
        return k;
    }
    private:
    void dfs(int v){
        used[v]=true;
        rep(i,g[v].size()){
            if(!used[g[v][i]])dfs(g[v][i]);
        }
        vs.push_back(v);
    }
    void rdfs(int v, int k){
        used[v]=true;cmp[v]=k;
        rep(i,rg[v].size()){
            if(!used[rg[v][i]]){
                rdfs(rg[v][i],k);
            }
        }
    }
};

int main(){
    ll n,m;cin >> n>>m;
    SCC g(n);
    rep(i,m){
        ll a,b;cin >> a >> b;
        g.add_edge(a,b);
    }
    int s=g.init();
    vvl ans(s);
    rep(i,n){
        ans[g.cmp[i]].pb(i);
    }
    cout << s <<endl;
    rep(i,s){
        cout << ans[i].size() <<" ";
        for(auto p:ans[i])cout << p <<" ";cout << endl;
    }
}


Measured memory_bytes: 80072
#include <iostream>

using namespace std;
int arr[101];

int main()
{
    int n,c=0,m=1;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    for(int i=0; i<n;i++)
    {

        if(arr[i]%2==1&& m%2==1)
        {
            c++;
        }
        m++;
    }
    cout<<c;

    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  
  int color = K;
  if (N>=2){
    for (int i=0; i<N-1; i++){
      color *= K-1;
    }
  }
  cout << color << endl;
}

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

int main() {
  int a, b;
  int total = 0;
  cin >> a >> b;
  for(int i=0;i<2;i++) {
    if(a>b) {
      total += a;
      a--;
    } else {
      total += b;
      b--;
    }
  }

  cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof x)
#define copy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 105;

char s[MAXN];
int n, ans = 100;

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	scanf("%s", s + 1); n = strlen(s + 1);
	for (int i = 0; i < 26; i ++)
	{
		int last = n + 1, ret = 0;
		for (int j = n; j; j --)
			if (s[j] == i + 'a') last = j;
			else ret = max(ret, last - j);
		ans = min(ans, ret);
	}
	return printf("%d\n", ans), 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    int x[n][d];
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < d; j++)
        {
            cin >> x[i][j];
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            double distance2 = 0;
            for(int k = 0; k < d; k++)
            {
                distance2 += pow(abs(x[i][k] - x[j][k]), 2);
            }
            if(ceil(sqrt(distance2)) == floor(sqrt(distance2)))
            {
                ans++;
            }
        }
    }
    cout << ans;

    return 0;
}


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

int r[100][100], h, w, n, a, nh = 0, nw = 0;
void paint(int c) {
	r[nh][nw] = c;
	if (nh % 2) {
		if (nw != 0)
			nw--;
		else
			nh++;
	}
	else {
		if (nw != w - 1)
			nw++;
		else
			nh++;
	}
}
int main(void) {
	scanf("%d%d%d", &h, &w, &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a);
		while (a--)
			paint(i);
	}
	for (int i = 0; i < h; i++) {
		printf("%d", r[i][0]);
		for (int j = 1; j < w; j++)
			printf(" %d", r[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
struct edge {
    int to, cost;
};

int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

map<int,int> factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
signed main() {
int x,y,a,b,c;
cin>>x>>y>>a>>b>>c;
vector<int>p(a),q(b),r(c);
rep(i,a)cin>>p[i];
rep(i,b)cin>>q[i];
rep(i,c)cin>>r[i];
sort(p.begin(),p.end());
sort(q.begin(),q.end());
sort(r.begin(),r.end());
reverse(p.begin(),p.end());
reverse(q.begin(),q.end());
reverse(r.begin(),r.end());
int red=0;int mu=0;int green=0;
int ans=0;
while(red+mu+green<x+y){
  if(red==x){
    if(q[green]>=r[mu]){ans+=q[green];green++;}
    else {ans+=r[mu];mu++;}
  }
  else if(green==y){
    if(p[red]>=r[mu]){ans+=p[red];red++;}
    else{ans+=r[mu];mu++;}
  }
  else{
    if(p[red]>=r[mu]&&p[red]>=q[green]){ans+=p[red];red++;}
    else if(r[mu]>=p[red]&&r[mu]>=q[green]){ans+=r[mu];mu++;}
    else {ans+=q[green];green++;}
  }
  }

cout<<ans<<endl;
}


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

int main()
{
	int N, flag = 0;
	cin >> N;

	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == N) {
				flag = 1;
			}
		}
	}

	if (flag == 1) {
		cout << "Yes" << endl;
	}

	else if (flag == 0) {
		cout << "No" << endl;
	}
}

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

int main() {
  set <int> s;
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    int d;
    cin>>d;
    s.insert(d);
  }
  cout<<s.size()<<endl;
  return 0;
}


Measured memory_bytes: 3480
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	if (n-1)%(k-1) == 0 {
		fmt.Println((n - 1) / (k - 1))
	} else {
		fmt.Println((n-1)/(k-1) + 1)
	}
}

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

int main() {
    int N;
    cin >> N;
    vector<int> W(N);
    vector<int> Wsum(N + 1);
    for (int i = 0; i < N; i++) {
        cin >> W[i];
        Wsum[i + 1] += Wsum[i] + W[i];
    }

    int ans = 1000000;
    for (int T = 1; T < N; T++) {
        int sum1 = Wsum[T];
        int sum2 = Wsum[N] - Wsum[T];
        ans = min(ans, abs(sum2 - sum1));
    }
    cout << ans << endl;
}

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

int main() {
    int n,a=0;
    cin>>n;
    for(int i=1;i<=n;i++) {
        int x;
        cin>>x;
        if(x&1 and i&1) a++;
    }
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N;
    string S,T;
    cin >> N;
    vector<ll> b(N),v;
    rep(i,N){
        cin >> b[i];
    }
    rep(i,N){
        rep(j,b.size()){
            if(b[b.size()-1-j] == ll(b.size())-j){
                b.erase(b.begin()+b.size()-1-j);
                v.push_back(b.size()-j+1);
                break;
            } 
        }
    }
    if(b.size() > 0){
        cout << -1 << endl;
    }else{
        rep(i,N){
            cout << v[N-1-i] << endl;
        }
    }
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const int MAX_N = 2e5 + 10;
bool erased[MAX_N];

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

    stack<char> S;
    for (auto c : X) {
        if (c == 'S') {
            S.push(c);
        } else {
            if (S.size() && S.top() == 'S') S.pop();
            else S.push(c);
        }
    }

    cout << S.size() << endl;
}



Measured memory_bytes: 644
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> list = new ArrayList<Integer>();

        int a = 0;
        int b = 0;

        int n = sc.nextInt();

        for(int i = 0; i < n; i++){
            list.add(sc.nextInt());
        }

        Collections.sort(list);
        Collections.reverse(list);

        for(int i = 0; i < n; i++){
            if(i % 2 == 0) a += list.get(i);
            else b += list.get(i);
        }

        System.out.println(a - b);

        sc.close();
    }
}

Measured memory_bytes: 21844
W, H, N = map(int, input().split())
lx = 0
rx = W
dy = 0
uy = H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        lx = max(lx, x)
    elif a == 2:
        rx = min(rx, x)
    elif a == 3:
        dy = max(dy, y)
    elif a == 4:
        uy = min(uy, y)
if 0 > rx - lx or 0 > uy - dy:
    print(0)
else:
    print((rx - lx) * (uy - dy))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	long n, m;
	cin >> n >> m;
	long k = m/n;
	while(true) {
		if (m%k==0) {
			cout << k << endl;
			return 0;
		}
		--k;
	}
	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  vector<int> pos, neg;
  rep(i, n) {
    cin >> a.at(i);
    if (a.at(i) < 0) neg.push_back(a.at(i));
    else pos.push_back(a.at(i));
  }

  // 正にできる組み合わせがあるか調べる
  bool ok = true;
  int posSize = pos.size();
  int negSize = neg.size();
  if (posSize == 0) {
    ok = (k % 2 == 0);
  } else {
    if (n == k) ok = (negSize % 2 == 0);
  }

  ll ans = 1;
  if (!ok) {
    // できない場合は絶対値の小さい順に取る
    sort(a.begin(), a.end(), [](int x, int y) {
      return abs(x) < abs(y);
    });
    rep(i, k) ans = ans * a.at(i) % mod;
    ans = mod + ans;
  } else {
    // できる場合は積を大きくできる組み合わせを選ぶ
    sort(pos.begin(), pos.end());
    sort(neg.rbegin(), neg.rend());
    if (k % 2 == 1) {
      ans = ans * pos.back() % mod;
      pos.pop_back();
    }

    vector<ll> p;
    while (pos.size() > 1) {
      ll tmp = pos.back(); pos.pop_back();
      tmp *= pos.back(); pos.pop_back();
      p.push_back(tmp);
    }
    while (neg.size() > 1) {
      ll tmp = neg.back(); neg.pop_back();
      tmp *= neg.back(); neg.pop_back();
      p.push_back(tmp);
    }
    sort(p.rbegin(), p.rend());
    rep(i, k/2) ans = ans * (p.at(i) % mod) % mod;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6400
import java.util.*;
import java.awt.geom.*;
public class Main {
	int [][] data;
	int n = 8;

	private void doit(){
		Scanner sc = new Scanner(System.in);
		int dataset = sc.nextInt();
		int count = 1;
		while(dataset-- > 0){
			data = new int[8][8];
			for(int i = 0; i < n; i++){
				String s = sc.next();
				for(int j = 0; j < 8; j++){
					data[i][j] = s.charAt(j) - '0';
				}
			}
			int x = sc.nextInt() - 1;
			int y = sc.nextInt() - 1;

			dfs(x,y);

			System.out.printf("Data %d:\n", count++);
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					System.out.print(data[i][j]);
				}
				System.out.println();
			}
		}
	}

	private void dfs(int x, int y) {
		data[y][x] = 0;

		for(int i = -3; i <= 3; i++){
			if(isOK(x + i, y) && data[y][x + i] == 1){
				dfs(x + i,y);
			}
		}
		for(int i = -3; i <= 3; i++){
			if(isOK(x, y+i) && data[y+i][x] == 1){
				dfs(x,y+i);
			}
		}

	}

	private boolean isOK(int x, int y) {
		if(0 <= x && x < n && 0 <= y && y < n){
			return true;
		}
		return false;
	}

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

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e3+7;
const int mod=1e9+7;
char s[maxn][maxn];int a[maxn][maxn];
int x_p[maxn][maxn],y_p[maxn][maxn],x_s[maxn][maxn],y_s[maxn][maxn];
int h,w;
int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
	{
		scanf("%s",s[i]+1);
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(s[i][j]=='.')
			{
				a[i][j]=1;
				x_p[i][j]=x_p[i][j-1]+a[i][j];
				y_p[i][j]=y_p[i-1][j]+a[i][j];
			}
			else
			{
				a[i][j]=0;
				x_p[i][j]=0;
				y_p[i][j]=0;
			}
		}
	}
	for(int i=h;i>=1;i--)
	{
		for(int j=w;j>=1;j--)
		{
			if(s[i][j]=='.')
			{
				a[i][j]=1;
				x_s[i][j]=x_s[i][j+1]+a[i][j];
				y_s[i][j]=y_s[i+1][j]+a[i][j];
			}
			else
			{
				a[i][j]=0;
				x_p[i][j]=0;
				y_p[i][j]=0;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(s[i][j]=='#') continue;
			ans=max(ans,x_s[i][j]+x_p[i][j]+y_s[i][j]+y_p[i][j]-3);
		}
	}
	cout<<ans<<endl;
 } 

Measured memory_bytes: 82816
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
    int a,b;cin>>a>>b;
    cout<<a*b<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 3604
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

void main() {
    bool solve() {
        auto s = readln.chomp;
        if (s == ".") return false;
        auto t = readln.chomp;
        if (s == t) {
            writeln("IDENTICAL");
            return true;
        }
        auto ss = s.split("\"").array;
        auto ts = t.split("\"").array;
        if (ss.length != ts.length) {
            writeln("DIFFERENT");
            return true;
        }
        foreach (int i, x; ss) {
            if (i % 2 != 0) continue;
            if (x != ts[i]) {
                writeln("DIFFERENT");
                return true;
            }
        }
        int c = 0;
        foreach (int i, x; ss) {
            if (i % 2 == 0) continue;
            c += (x != ts[i]);
        }
        writeln(c == 1 ? "CLOSE" : "DIFFERENT");
        return true;
    }
    while (solve()) {}
}

Measured memory_bytes: 2432
#include <stdio.h>

int main(void) {

	int n, m, i, ii;
	int la[100][100] = { 0 };
	int b[100] = { 0 };
	int laa = 0;

	scanf("%d%d", &n, &m);

	for (i = 0; i < n; i++) {
		for (ii = 0; ii < m; ii++) {
			scanf("%d", &la[i][ii]);
		}
	}

	for (i = 0; i < m; i++) {
		scanf("%d", &b[i]);
	}

	for (i = 0; i < n; i++) {
		for (ii = 0; ii < m; ii++) {
			laa += la[i][ii] * b[ii];
		}
		printf("%d\n", laa);
		laa = 0;
	}
	scanf("%d", &b[i]);
	return 0;
}

Measured memory_bytes: 648
// Elementary Number Theory - Prime Factorize
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_A
using System;
using System.Linq;
using System.Collections.Generic;

namespace NTL_1_A {
	class Program {
		public Program() {}
		
		public static void Main() {
			new Program().Calc();
		}
		
		void Calc() {
			var n = int.Parse(Input);
			var factors = Factorize(n).Select(i => i.ToString())
									.Aggregate((i, j) => i + " " + j);
			
			Output(n + ": " + factors);
		}
		
		String Input {
			get {
				return Console.ReadLine();
			}
		}
		
		void Output(String str) {
			Console.WriteLine(str);
		}
		
		int[] Factorize(int n) {
			List<int> factors = new List<int>();

			if(n <= 0) return new int[] {0};
			if(n == 1) return new int[] {1};

			while(n % 2 == 0) {
				factors.Add(2);
				n /= 2;
			}
			while(n % 3 == 0) {
				factors.Add(3);
				n /= 3;
			}

			int factor = 5;
			int step = 2;
			while(factor * factor <= n) {
				if(n % factor == 0) {
					factors.Add(factor);
					n /= factor;
				} else {
					factor += step;
					step = 6 - step;
				}
			}
			if(n != 1) factors.Add(n);
			return factors.ToArray();
		}
	}
}

Measured memory_bytes: 9584
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;

int main()
{
    set<int > s;
    int q;
    cin>>q;
    int b,tp1;
    while(q--){
        cin>>tp1;
        if(tp1==1){
                cin>>b;
            if(s.find(b)!=s.end()){
                cout<<"1\n";
            }
            else{
                cout<<"0\n";
            }
        }
        else if(tp1==0){
            cin>>b;
            s.insert(b);
            cout<<s.size()<<"\n";
        }
        else if(tp1==2){
            cin>>b;
            s.erase(b);
        }
        else{
            int r,l;
            cin>>l>>r;
            set<int>::iterator it=s.lower_bound(l);
            while(*it<=r&&it!=s.end()){
                cout<<*it<<"\n";
                it++;
            }
        }
    }

}




Measured memory_bytes: 12460
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 2e5 + 5;
char s[maxn], t[maxn];
int main()
{
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; s[i]; i++)
	{
		if (s[i] != t[i])
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=2*1e5;
int n,A[MAXN+5];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&A[i]);
    int l=1,r=0,F=0;
    long long ans=0;
    while(r<n)
    {
        while(r<n && !(F&A[r+1]))
        {
            r++;ans+=r-l+1;
            F^=A[r];
        }
        while(l<=r && (F&A[r+1]))
            F^=A[l++];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
int main() {

	int H, W;
	char pic[105][105];
	char ans[205][105];

	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {

			cin >> pic[i][j];

		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {

			ans[i * 2][j] = pic[i][j];
			ans[i * 2 + 1][j] = pic[i][j];

		}
	}

	for (int i = 0; i < H * 2; i++) {
		
		for (int j = 0; j < W; j++) {

			cout << ans[i][j];

		}
		cout << endl;

	}

	return 0;
}

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

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000000000000

ll n;
ll a[100005][4];
ll dp[100005][4];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;

    fr(i,1,n)
    {
        cin >> a[i][1] >> a[i][2] >> a[i][3];
    }

    dp[1][1] = a[1][1];
    dp[1][2] = a[1][2];
    dp[1][3] = a[1][3];

    fr(i,2,n)   
    {
        fr(j,1,3)
        {
            ll x = 0;
            fr(k,1,3)
            {
                if(k==j)
                    continue;
                x = max(x,dp[i-1][k]); 
            }
            dp[i][j] = x + a[i][j];
        }
    }

    cout << max({dp[n][1], dp[n][2], dp[n][3]}) << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>

using namespace std;

int main(void){
  string a[10];

  a[0]="";
  a[1]=" .,!?";
  a[2]="cab";
  a[3]="fde";
  a[4]="igh";
  a[5]="ljk";
  a[6]="omn";
  a[7]="spqr";
  a[8]="vtu";
  a[9]="zwxy";

  int n;
  cin >> n;
  cin.ignore();
  while(n--){
    string str;
    getline(cin,str);

    int sz=str.size(),i=0,cnt=0;
    while(str[i]=='0')i++;
    for(;i<sz;i++){
      if(str[i]=='0'){
	cout << a[str[i-1]-'0'][cnt%a[str[i-1]-'0'].size()];
	cnt=0;
	while(str[i+1]=='0')i++;
      }
      else cnt++;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream> 
using namespace std;
int a,b,c,d,e;
int main(){
	cin>>a>>b;
	c=a+a-1;
	d=b+b-1;
	e=a+b;
	if(e>d && e>c)
	cout<<e;
	else if(c>d)
	cout<<c;
	else cout<<d;
	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>adj[100008];
bool visited[100008]={0};
ll dp[100008]={0};
void dfs(ll a1)
{
    visited[a1]=1;
    for(ll q1:adj[a1])
    {
        if(visited[q1]==0)
        {
            dfs(q1);
        }
        dp[a1]=max(dp[a1],1+dp[q1]);
    }
}
int main()
{
ll n,m;
cin>>n>>m;
for(ll i=0;i<m;i++)
{
    ll x,y;
    cin>>x>>y;
    adj[x].push_back(y);
}
for(ll i=1;i<=n;i++)
{
    if(visited[i]==0)
    {
        dfs(i);
    }
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
    ans=max(ans,dp[i]);
}
cout<<ans;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
const int mod = 1000000007;
const int max_n = 200005;
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;
}

int main(){
    ll n;cin >> n;
    ll ans=0;
    rep(i,n){
        ll l,r;cin >> l >>r;
        ans+=(r-l)+1;
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main(){
    int a,b,c;scanf("%d%d%d",&a,&b,&c);
    int ok=0;
    rep(i,b-1) if((a*(i+1))%b==c) ok=1;

    if(ok) puts("YES");
    else puts("NO");
}

Measured memory_bytes: 1640
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,i,p=0,m;
	cin>>a>>b>>c;
	for(i=a;i<=b;i++)
	{
	m=c%i;
	if(m==0)
	{
		p++;
	}
	}
	cout<<p<<endl;
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int x;
	int n; cin>>n;
	int a[n];
	map<int,int> d;
	rep(i,n){
		cin>>x;
		a[i]=x;
		d[x]++;
	}
	int m; cin>>m;
	int b[m];
	map<int,int> t;
	rep(i,m){
		cin>>x;
		b[i]=x;
		t[x]++;
	}

	string ans="YES";
	rep(i,m){
		x=b[i];
		if(d[x]<t[x]) ans="NO";
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 20608
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

enum Selection{
    A, B, C
};

int main(){
    llong N;
    cin >> N;
    vector<vector<llong> > dp(N, vector<llong>(3,0));
    vector<vector<llong> > Table(N);
    llong a,b,c;

    for(int i=0; i<N; i++){
        cin >> a >> b >> c;
        Table[i].push_back(a);
        Table[i].push_back(b);
        Table[i].push_back(c);
    }
    dp[0][A] = Table[0][A];
    dp[0][B] = Table[0][B];
    dp[0][C] = Table[0][C];

    for(int i=1; i<N; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(j!=k){
                    dp[i][j] = max(dp[i-1][k]+Table[i][j], dp[i][j]);
                }
            }
        }
    }

    llong ans = 0;
    for(int i=0; i<3; i++){
        ans = max(ans, dp[N-1][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15200
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): 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 LSS(): return input().split()

def resolve():
    a, b, c, d = LI()

    ans = max(a * c, a * d, b * c, b * d)
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10104
import sys
input = sys.stdin.readline

N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda k: k[1])
t = 0

for Ai, Bi in AB:
    t += Ai
    
    if t>Bi:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 76636
n,m = input().split()
n = int(n)
m = int(m)
A = [input() for i in range(n)]
B = [int(input()) for i in range(m)]
ans = 0
for i in A:
    y = 0
    b = i.split()
    for x in b:
        ans += int(x) * B[y]
        y += 1
    print(ans)
    ans = 0


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int inf = 1000000;

int dp[41][401][401];

int main()
{
    int n, ma, mb;
    cin >> n >> ma >> mb;

    int a[n], b[n], c[n];

    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    rep(i, n + 1) rep(j, 401) rep(k, 401) dp[i][j][k] = inf;

    dp[0][0][0] = 0;

    rep(i, n)
    {
        rep(j, 401)
        {
            rep(k, 401)
            {
                dp[i + 1][j][k] = dp[i][j][k];
                if (j - a[i] >= 0 && k - b[i] >= 0)
                    dp[i + 1][j][k] = min(dp[i][j - a[i]][k - b[i]] + c[i], dp[i + 1][j][k]);
                        }
        }
    }
    int ans = 1e7;

    rep(j, 401)
    {
        rep(k, 401)
        {
            if (j * k == 0)
                continue;
            if (j * mb == k * ma)
                ans = min(ans, dp[n][j][k]);
        }
    }

    OP((ans == inf ? -1 : ans));

    return 0;
}

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

#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i=(a);i!=(b);++i)
#define all(v) (v).begin(), (v).end()
#define rs resize
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

ostream& operator<<(ostream &out, const pii &a) { return out << '(' << a.x << ", " << a.y << ')'; }
istream& operator>>(istream &in, pii &a) { return in >> a.x >> a.y; }

const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

// lambda-expression: [] (args) -> retType { body }

void run(int tc)
{
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// cerr << boolalpha;
	(cout << fixed).precision(10);

	string S;
	cin >> S;
	cout << S.substr(0, S.size() - 8) << endl;

	return 0;
}

Measured memory_bytes: 256