akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while(N>0) {
    N /= K;
    ++ans;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
   int H[300],W[300],i,j,k,flag=1,cnt=0;
   do{
      scanf("%d %d",&H[cnt],&W[cnt]);
      if(H[cnt]==0&&W[cnt]==0){
         flag=0;
      }
      cnt++;
   }while(flag);
   for(i=0;i<cnt-1;i++){
      for(j=0;j<H[i];j++){
         for(k=0;k<W[i];k++){
            if((j+k)%2==0){
               printf("#");
            }
            else{
               printf(".");
            }
         }
         printf("\n");
      }
      printf("\n");
   }
   return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int a;cin >> a;
	string s;cin >> s;
	if(a < 3200)cout << "red" << endl;
	else cout << s << endl;
	return 0;
}

Measured memory_bytes: 3592
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
reqs = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for A in combinations_with_replacement(range(1, M + 1), N):
    temp = 0
    for a, b, c, d in reqs:
        a, b = a - 1, b - 1
        if A[b] - A[a] == c: temp += d
    ans = max(ans, temp)
print(ans)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cout<<x
#define pb push_back
#include<string.h>
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);                    
    cout.tie(NULL);
    ll T=1;
    //cin>>T;
    while(T--){
    	ll n,cnt=0;
    	cin>>n;
    	ll arr[n+1];
    	for(int i=1;i<=n;i++){
    		cin>>arr[i];
    		if(i%2&&arr[i]%2) cnt++;
    	}
    	cout<<cnt;
    }
   	return 0; 
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#pragma GCC optimize("O2")
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
const int mod = 1e9 + 7;
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll,ll>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
bool isPowerOfTwo(int x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}
double distform(int x, int y, int z, int w) {//(x1,y1,x2,y2)
    return sqrt(1. * pow(x-z,2) + 1. * pow(y-w,2));
}
const int MAXN = 2e5+ 10;
const ll inf = 1e18;

int intlog(double base, double x) {
    return (int)(log(x) / log(base));
}
void read(vi & a) {
    for (int i = 0; i < sz(a); ++i) {
        cin >> a[i];
    }
}
int32_t main() {
    fio
    int n,m;
    cin >> n >> m;
    vi a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    unordered_set<int>same;
    for(auto &x : a) {
        x/=2;
        int cnt = 0;
        int t = x;
        while(x%2 == 0) {
            x/=2;
            cnt++;
        }
        x = t;
        same.insert(cnt);
    }
    D2(same)
    D2(a)
    if(sz(same) > 1) {
        cout << 0 << endl;
        return 0;
    }
    int LCM = 1;
    for (int i = 0; i < n; ++i) {
        int g = gcd(LCM,a[i]);
        LCM = (LCM * a[i])/g;
        if(LCM > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    int x = m/LCM;
    cout << (x + 1)/2;




}






Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int b[3];

int main(){
  cin >> b[0] >> b[1] >> b[2];

  bool ans = (b[0] && b[1]) || (b[2]);

  if(ans){
    cout << "Open" << endl;
  }
  else{
    cout << "Close" << endl;
  }
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    string s;
    cin >> n >> s;
    vector<pair<string,string>> v;
    rep(bit,1<<n) {
        string r,b;
        rep(i,n) {
            if(bit>>i&1) r += s[n+i];
            else b += s[n+i];
        }
        reverse(all(b));
        v.eb(r,b);
    }
    sort(all(v));
    ll ans = 0;
    rep(bit,1<<n) {
        string r,b;
        rep(i,n) {
            if(bit>>i&1) r += s[i];
            else b += s[i];
        }
        reverse(all(b));
        pair<string,string> p = {b,r};
        ans += upper_bound(all(v),p)-lower_bound(all(v),p);
    }
    cout << ans << endl;
}


Measured memory_bytes: 33388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sq(ll n) {
	ll s = 0,e=1e7;
	ll ls;
	while(s <= e) {
		ll m = (s+e)/2;
		if(m*m >= n) {ls = m;e = m-1;} else {
			s = m+1;
		}
	}
	return ls;
}
int main() {
	ll n;
	cin >> n;
	ll val = sq(n)-1;
	ll tot = 0;
	for(int i=1;i<=val;i++) {
		if(!(n%i)) {
			ll bs = n/i-1;
			if(n%bs == n/bs) {
			tot += bs;}
		}
	}
	cout << tot << '\n';
}


Measured memory_bytes: 256
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
vector<LL> vec[100010],l[100010],r[100010];
LL n,mod;
struct node{
	LL y,next;
}a[200010];LL len=0,last[100010],f[100010];
LL ans[100010];
void ins(LL x,LL y)
{
	a[++len].y=y;
	a[len].next=last[x];last[x]=len;
}
void dfs(LL x,LL fa)
{
	f[x]=1;LL tot=0;
	for(LL i=last[x];i;i=a[i].next)
	{
		LL y=a[i].y;
		if(y==fa) continue;
		dfs(y,x);
		vec[x].push_back(y);
		l[x].push_back(0);r[x].push_back(0);
		(f[x]*=(f[y]+1))%=mod;
		tot++;
	}
	for(LL i=0;i<tot;i++)
	{
		l[x][i]=(i==0)?1:l[x][i-1];
		(l[x][i]*=(f[vec[x][i]]+1))%=mod;
	}
	for(LL i=tot-1;i>=0;i--)
	{
		r[x][i]=(i==tot-1)?1:r[x][i+1];
		(r[x][i]*=(f[vec[x][i]]+1))%=mod;
	}
	//printf("x:%lld %lld\n",x,f[x]);
}
void solve(LL x,LL c)
{
	ans[x]=(f[x]*(c+1))%mod;
	for(LL i=0;i<vec[x].size();i++)
	{
		LL y=vec[x][i];
		LL c1=(i==0)?1:l[x][i-1];
		LL c2=(i==vec[x].size()-1)?1:r[x][i+1];
		solve(y,(c+1)*c1%mod*c2%mod);
	}
}
int main()
{
	scanf("%lld %lld",&n,&mod);
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld %lld",&x,&y);
		ins(x,y);ins(y,x);
	}
	dfs(1,0);solve(1,0);
	for(LL i=1;i<=n;i++) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 27520
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  int x;cin>>x;
  int ans=1;
  repd(b,2,sqrt(x)+1){
    int p=2;
    int next=pow(b,p);
    while(next<=x){
      ans = max(ans,next);
      p++;
      next = pow(b,p);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
a = [list(map(int,input().split())) for _ in range(N)]

dp = [[0]*3 for _ in range(100010)] 
# dp[i][j] : i日目にj番目の活動をしたときの幸福度の総和
idx = [[1,2],[2,0],[0,1]]

for i in range(3):
    dp[0][i] = a[0][i]
    
for i in range(1,N):
    for j in range(3):
        dp[i][j] = max(dp[i-1][idx[j][0]],dp[i-1][idx[j][1]])+a[i][j]
    
print(max(dp[N-1]))

Measured memory_bytes: 74456
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int fn(int x,int y){
	if(x<=y)
		return y-x;
	else
		return INF;
	return 0;
}

int main(void){
	int x,y,result=INF;

	cin>>x>>y;
	chmin(result,fn(x,y));
	chmin(result,fn(x,-y)+1);
	chmin(result,fn(-x,y)+1);
	chmin(result,fn(-x,-y)+2);
	print(result);
	return 0;
}


Measured memory_bytes: 256
def Sol(n,a,b):
    
    m = b%n
    if b-m >= a:
        print("OK")
    else:
        print("NG")
    
    return

    
n = int(input())

#for t in range(int(input())):
a,b = map(int,input().split())
#    arr = []
#    for i in range(c):
#        arr.append(list(map(int,input().split())))
#arr = list(map(int,input().split()))
#k = input()
#n = int(input())
Sol(n,a,b)


Measured memory_bytes: 61796
#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <string>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int N,w;
string inl,wks,ans;
	
	getline(cin,wks);
	N = atoi(wks.c_str());

	rep(i,N){
		getline(cin,wks);
		rep(j,100) rep(k,26){
			inl = wks;
            for(int m=0; m < inl.size(); m++){
                if(inl[m] >= 'a' && inl[m] <= 'z')
            		inl[m]=( j * (inl[m]-'a') +k) %26 + 'a';
            }
//			if(j<2) cout << j <<"-" << k << ": " << inl << endl;
			if(inl.find("this") != string::npos 
            	|| inl.find("that") != string::npos ){
				ans = inl;
            	break;
            	
            }
		}
		cout << ans << endl;
	}	
	
	return 0;
	
	
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using Tuple = tuple<int, int, int>;


int dfs(string input, int depth, ll k, int count) {
    if(depth == 1) {
        if(k == count) {
            cout << input << endl;
        }
        count++;
        return count;
    }

    int tailnum = input[input.size()-1]-'0';
    EFOR(i, max(0, tailnum-1), min(tailnum+1, 9)) {
        count = dfs(input+to_string(i), depth-1, k, count);
    }
    return count;

}


int main() {
    ll k; cin >> k;
    int depth = 1;
    ll count = 1;
    while(true) {
        EFOR(j,1,9) {
            string ans = to_string(j);
            if(depth > 1) {
                count = dfs(ans, depth, k, count);
            } else {
                if(count == k) {
                    cout << ans << endl;
                    return 0;
                }
                count++;
            }
            if(count > k) {
                return 0;
            }
        }
        depth++;
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(i) i.begin(),i.end()

using namespace std;
	
vector<int> doCut(int p,int c,vector<int> x,int n){
	vector<int> ret;
	for(int i=p-1;i<=p-1+c-1;i++){
		ret.push_back(x[i]);
	}
	rep(i,p-1){
		ret.push_back(x[i]);
	}
	for(int i=p+c-1;i<=n-1;i++){
		ret.push_back(x[i]);
	}
	return ret;
}

int main(){
	int n,r;
	while(1){
		vector<int> x;
		cin>>n>>r;

		for(int i=n-1;i>=0;i--){
			x.push_back(i+1);
		}
		if(n==0 && r==0)break;

		rep(i,r){
			int p,c;
			cin>>p>>c;
			x=doCut(p,c,x,n);

		}
		cout<<x[0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
i = gets.chomp.split(" ").map(&:to_i)
n = gets.chomp.split(" ").map(&:to_i)
k=[]
(i[1]-1).times{|t|
  k[t]=n[t+1]-n[t]
}
k[i[1]-1]= i[0] - n[i[1]-1] + n[0]
k.sort!
k.delete_at(-1)
puts k.inject(:+)

Measured memory_bytes: 20296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pii = pair<int, int>;

//AC using DP
int main(){
  int h, n;
  cin>>h>>n;
  int INF = 1<<29;

  vector<int> dp(h+1, INF);
  dp[0] = 0;

  int a, b;
  for(int rp=0; rp<n; rp++){
    cin>>a>>b;
    for(int i=0; i<=h; i++){//i+=aではダメ
      int next = min(i+a, h);
      dp[next] = min(dp[next], dp[i]+b);
    }
  }

  //int ans = *min_element(dp.begin()+h, dp.end());
  int ans = dp[h];
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
a = []
for l in range(N):
    a.append(list(map(int, input().split())))
res = 0
for s in a:
    left = C
    for i in range(0, M):
        left += s[i] * B[i]
    if left > 0:
        res += 1

print(res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int func(int n)
{
    int m = sqrt(n);
    int sum =0;
    int ans =0;
    for(int i = 1;i<m;i++)
    {
        for(int j = i;j<m;j++)
        {
            for(int k = j;k<m;k++)
            {
               sum = pow(i,2) + pow(j,2) + pow(k,2) + i*j + j*k + k*i;
               if(sum==n)
               {
                   if(i==j && j==k)
                        ans++;
                    else if (i==j && j!=k)
                        ans = ans + 3;
                    else if (i==k && j!=k)
                        ans = ans + 3;
                    else if (k==j && j!=i)
                        ans= ans + 3;
                    else
                        ans = ans  + 6;
               }
            }
        }
    }
    return ans;
}
int main()
{
   int n;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
       cout<<func(i)<<endl;
   }
}


Measured memory_bytes: 3516
#include <iostream>
using namespace std;
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <cstdlib>

int dx[8] = {1, 2, 1, 2, -1, -2, -1, -2}, dy[8] = {2, 1, -2, -1, -2, -1, 2, 1};

int main() {
	int n, k; cin >> n >> k;
	long long int ans = 0;
	ans = k*pow(k-1, n-1);
	cout << ans <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<vector>
using namespace std;

int solve(){
  int mov[26];
  string alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int n;
  string s;
  cin >> n >> s;
  for(int i=0; i<26; i++) {
    mov[i] = (i+n)%26;
  }
  for(int i=0; i<s.length(); i++){
    s[i] = alph[mov[s[i]-'A']];
  }
  cout << s << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>

using namespace std;

typedef complex<int> P;

struct human {
	P p;
	int dir;

	human(P p, int dir) : p(p), dir(dir) { }
	human() { this -> p = P(0, 0); this -> dir = 0; }
};

bool cp(human a, human b) {
	return a.dir > b.dir;
}

P dir(int n) {
	n %= 4;
	return n == 0 ? P(0, -1) : n == 1 ? P(1, 0) : n == 2 ? P(0, 1) : P(-1, 0);
}

int W, H;
int m[30][30];
int state(P p) {
//	if (p.real() < 0 || p.real() >= W || p.imag() < 0 || p.imag() >= H) cout << "ERROR" << endl;
//	cout << p.real() << " " << p.imag() << endl;
	return m[p.imag()][p.real()];
}

int main() {
	while (cin >> W >> H, W || H) {
		vector<human> v;

		for (int y = 0; y < H; ++y) {
			string str; cin >> str;
			for (int x = 0; x < W; ++x)
				m[y][x] =
					  str[x] == '#' ? 1
					: str[x] == 'X' ? -1
					: str[x] == 'N' ? (v.push_back( human( P(x, y), 0) ), 2)
					: str[x] == 'E' ? (v.push_back( human( P(x, y), 1) ), 2)
					: str[x] == 'S' ? (v.push_back( human( P(x, y), 2) ), 2)
					: str[x] == 'W' ? (v.push_back( human( P(x, y), 3) ), 2)
					: 0
					;
		}

		int t = 0;
		while (v.size() && ++t <= 180) {
			// 向き変更
			for (int i = 0; i < v.size(); ++i)
				v[i].dir =
					  state(v[i].p + dir(v[i].dir + 1)) <= 0 ? (v[i].dir + 1) % 4
					: state(v[i].p + dir(v[i].dir))     <= 0 ? v[i].dir
					: state(v[i].p + dir(v[i].dir + 3)) <= 0 ? (v[i].dir + 3) % 4
					: state(v[i].p + dir(v[i].dir + 2)) <= 0 ? (v[i].dir + 2) % 4
					: v[i].dir
					;

			// 向きでソート
			sort( v.begin(), v.end(), cp );

			// 移動
			vector<P> zero;
			vector<P> negative;
			for (int i = 0; i < v.size(); ++i) {
				int s = state(v[i].p + dir(v[i].dir));
				if (s > 0) continue;

				zero.push_back(v[i].p);
				v[i].p += dir(v[i].dir);

				m[v[i].p.imag()][v[i].p.real()] = 2;
				if (s < 0) {
					negative.push_back(v[i].p);
					v.erase( v.begin() + i-- );
				}
			}

			for (int i = 0; i < zero.size(); ++i)
				m[zero[i].imag()][zero[i].real()] = 0;

			for (int i = 0; i < negative.size(); ++i)
				m[negative[i].imag()][negative[i].real()] = -1;
		}

		if (t > 180) cout << "NA" << endl;
		else cout << t << endl;
	}
}

Measured memory_bytes: 0
s = input()
t = input()

# ans = []
# for i in range(len(t)):
#     # print(t[i:])
#     # print(s[i:])
#     if t[i:] in s[i:]:
#         break
#     for j in range(1,len(t[i:])):
#         # print(t[i:][:-j])
#         # print(s[i:][:-j])
#         if t[i:][:-j] in s[i:][:-j]:
#             ans.append(i+j)
#             break
# if t in s:
#     print(0)
# elif len(ans) == 0:
#     print(len(t))
# else:
#     print(min(ans))
ans = len(t)
for i in range(len(s)-len(t)+1):
    dif = 0
    for j in range(len(t)):
        if t[j] != s[i:i+len(t)][j]:
            dif += 1
    ans = min(dif,ans)

print(ans)     

Measured memory_bytes: 9048
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;

// Extended Print Func
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& input){
    os << "[ ";
    REP(i, input.size()){
        os << input[i];
        if (i < input.size()-1) { os << " "; }
    }
    os << " ]";
    return os;
}
void print() { std::cout << "\n"; }
template<class T, class... A> void print(const T& first, const A&... rest) { std::cout << first << " "; print(rest...); }
template<class... A> void print(const A&... rest) { print(rest...); }



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

  string S, T;
  cin >> S >> T;

  ll ans = 0;
  REP(i, S.length()){
    if (S[i] == T[i]) ans++;
  }
  cout << ans << "\n";
  return 0;
}


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

#define REP(i, x) REPI(i, 0, n)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, K;
  string S;

  cin >> N >> K >> S;

  int ans = 0;
  REPI(i, 1, N){
    if(S[i-1] == S[i]){
      ++ans;
    }
  }

  cout << min(ans + 2 * K, N-1) << endl;

  return 0;
}


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

struct UnionFind{
  vector<int> p;
  UnionFind(int n){
    p.resize(n);
    for(int i=0; i<n; i++)  p[i] = i;
  }
  int find(int x){
    if(p[x] == x)  return x;
    return p[x] = find(p[x]);
  }
  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y)  return;
    p[x] = y;
  }
};

int main(){
  int n;  cin >> n;
  vector<tuple<int, int, int>> xyn(n);  // 0:x  1:y  2:idenfi.. number
  for(int i=0; i<n; i++){
    cin >> get<0>(xyn[i]) >> get<1>(xyn[i]);
    get<2>(xyn[i]) = i;
  }

  vector<tuple<int, int, int>> edge;  // 0:cost  1:from  2:to
  // x でソート
  sort(xyn.begin(), xyn.end(), [](auto &a, auto &b){ return get<0>(a) < get<0>(b); });
  for(int i=1; i<n; i++)  // 隣接する2頂点を cost : x座標差で辺として格納
    edge.push_back({get<0>(xyn[i])-get<0>(xyn[i-1]), get<2>(xyn[i-1]), get<2>(xyn[i])});

  // y でソート
  sort(xyn.begin(), xyn.end(), [](auto &a, auto &b){return get<1>(a) < get<1>(b); });
  for(int i=1; i<n; i++)  // 隣接する2頂点を cost : y座標差で辺として格納
    edge.push_back({get<1>(xyn[i])-get<1>(xyn[i-1]), get<2>(xyn[i-1]), get<2>(xyn[i])});

  sort(edge.begin(), edge.end());  // 辺たちをコストで昇順
  long ans = 0;

  // クラスカル法
  UnionFind uf(n);
  for(auto nowe : edge){
    if(uf.find(get<1>(nowe)) == uf.find(get<2>(nowe)))  continue;
    uf.unite(get<1>(nowe), get<2>(nowe));
    ans += get<0>(nowe);
  }

  cout << ans << endl;

  return 0;
}


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


int main() {
  string S;
  cin >> S;
  if ( S.at(2)== S.at(3) && S.at(4) == S.at(5) ){
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" <<endl;
  }
}

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

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

int main(int argc, char const* argv[])
{
  while (true) {
    int N, Q;
    std::cin >> N >> Q;
    if (N == 0 && Q == 0)
      break;
    std::vector<int> schedule(100, 0);
    for (int i = 0; i < N; ++i) {
      int M;
      std::cin >> M;
      for (int j = 0; j < M; ++j) {
        int x;
        std::cin >> x;
        ++schedule[x];
      }
    }
    std::vector<int>::iterator conv = std::max_element(schedule.begin(), schedule.end());
    if (*conv < Q)
      std::cout << 0 << std::endl;
    else
      std::cout << std::distance(schedule.begin(), conv) << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#これはmaspyさんの提出コードの写経です
from sys import setrecursionlimit
setrecursionlimit(10**6) 

from sys import stdin
from functools import lru_cache
n = int(stdin.readline().rstrip())
k = int(stdin.readline().rstrip())
#n以下の数字で0でないものがちょうどk個
@lru_cache(maxsize=None)
def kosuu(n,k):
    #残り10以下の場合
    if n < 10:
        if k == 0:
            return 1
        if k == 1:
            return n
        return 0
    q = n//10#商
    r = n%10#余り
    ret = 0
    if k >= 1:
        # 1の位が nonzero
        ret += kosuu(q, k-1) * r
        ret += kosuu(q-1, k-1) * (9-r)
    ret += kosuu(q,k)
    return ret
print(kosuu(n,k))

Measured memory_bytes: 38896
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		for(int i = 0 ; i < n ; i++) {
			if(!map.containsKey(a[i])) {
				map.put(a[i], 1);
			} else {
				map.put(a[i], map.get(a[i]) + 1);
			}
		}
		long ans = 0;
		for(int key : map.keySet()) {
			if(map.get(key) > key) {
				ans += map.get(key) - key;
			} else if(map.get(key) < key) {
				ans += map.get(key);
			}
		}
		System.out.println(ans);
	}
}


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; 
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input();
    vector< int > B(N - 1), A(N, inf);
    cin >> B;
    
    range(i, 0, N - 1) {
        chmin(A[i], B[i]);
        chmin(A[i + 1], B[i]);
    }
    
    cout << whole(accumulate, A, 0) << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


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

int main()
{
    ll n,i,sum=0,a,sum1=0;
    cin >> n;
    for(i=0; i<n; i++)
    {
        cin >> a;
        if(a%2)
            sum1++;
    }
    if(sum1%2==0)
        cout << "YES\n";
    else
        cout << "NO\n";


    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
 #include<string.h>
 #include<stdlib.h>
  
 void LCS_lenght(char *x,char *y){
   int i,j,m,n,c[1001][1001];;
   m=strlen(x+1);
   n=strlen(y+1);
   for(i=1;i<=m;i++){
     c[i][0]=0;
   }
   for(j=0;j<=n;j++){
     c[0][j]=0;
   }
   for(i=1;i<=m;i++){
     for(j=1;j<=n;j++){
       if(x[i]==y[j]){
     c[i][j]=c[i-1][j-1]+1;
       }
       else if(c[i-1][j]>=c[i][j-1]){
     c[i][j]=c[i-1][j];
       }
       else {
     c[i][j]=c[i][j-1];
       }
     }
   }
   printf("%d\n",c[i-1][j-1]);
 }
  
 int main(){
   int i,numberofdataset;
   char x[1001],y[1001];
  
   scanf("%d",&numberofdataset);
  
   for(i=0;i<numberofdataset;i++){
     scanf("%s",x+1);
     scanf("%s",y+1);
    LCS_lenght(x,y);
  }
 
  return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;

int N, deep;
vector<int> edge[100005];
int color[100005]={};
int dfs(int n, int b = -1, int d = 0){
	if( n == N-1 ){
		deep = d;
		return n;
	}
	for(auto t: edge[n]) if(t != b){
		int r = dfs(t, n, d+1);
		if( r > 0 ){
			if( d > deep / 2 ) color[n] = 2;
			else color[n] = 1;
			return r;
		}
	}
	return 0;
}

int dfs2(int n, int b = -1, int c = -1){
	color[n] = c;
	for(auto t: edge[n]) if(t != b && color[t] == 0){
		dfs2(t, n, c);
	}
	return 0;
}

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

	cin >> N;
	rep(i,N-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	color[0] = 1;
	color[N-1] = 2;

	dfs(0);
	rep(i,N) if(color[i] != 0){
		dfs2(i, -1, color[i]);
	}

	int count[5]={};
	rep(i,N) count[ color[i] ]++;

	//cout << count[1] << " " << count[2] << endl;

	if( count[1] > count[2] ){
		cout << "Fennec" << endl;
	}else{
		cout << "Snuke" << endl;
	}

	return 0;
}

Measured memory_bytes: 13952
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int h, w;

    cin >> h >> w;

    int H, W;

    REP(i, h)
    REP(j, w)
    {
        string s;
        cin >> s;
        if (s == "snuke")
        {
            H = i;
            W = j;
        }
    }

    cout << ((char)('A' + W)) << H + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
x = 0; y = 0; th = 90
while gets do
  r, rot = $_.split(/,/).map(&:to_i)
  break if r == 0 && rot == 0
  x += r * Math.cos(th/180.0*Math::PI)
  y += r * Math.sin(th/180.0*Math::PI)
  th -= rot
end
puts x.truncate, y.truncate

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


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a, b;
	char op;
	cin >> a >> op >> b;

	switch (op)
	{
	case '+':
		cout << a + b << endl;
		break;

	case '-':
		cout << a - b << endl;
		break;

	default:
		break;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ll n;
    cin>>n;
    vector<ii> v;
    ll a[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        if(i==0){
            v.push_back({a[i], 0});
        }
        else{
            if(a[i]!=v.back().F){
                v.push_back({a[i], i});
            }
        }
    }

    ll ans=1000;
    ll i = 0; 
    while (i<(n-1)){ 
        while ((i<n-1) && (a[i + 1]<=a[i])) {
            i++;
        }
        if(i ==n-1){
            break; 
        }
        ll buy = i++;
        while ((i < n) && (a[i] >= a[i - 1])) {
            i++; 
        }
        ll sell = i-1;
        ll bought_stocks = ans/a[buy];
        ll rem = ans%a[buy];
        ll sold_money = bought_stocks*a[sell];
        ans=sold_money+rem;
    }
    cout<<ans;

    return 0;
}


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

int main()
{
	int n, m, a[100][100], b[100];
	cin >> n >> m;
	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j];
	for (int j = 0; j < m; j++) cin >> b[j];
	for (int i = 0; i < n; i++)
	{
		int c = 0;
		for (int j = 0; j < m; j++)
			c += a[i][j] * b[j];
		cout << c << endl;
	}
}


Measured memory_bytes: 3092
/*
  author:@bhaskar_8998
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef vector<i64> vi;
typedef pair<i64,i64>ii;
typedef vector<ii> vii;
typedef map<i64,i64> mi;
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
#define ff first
#define ss second
#define deb(x) cerr<<#x<<" "<<x<<"\n";
#define fastio() {ios_base::sync_with_stdio(false);cin.tie(NULL);}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    fastio();
    clock_t beg=clock();
    i64 t=1;
    // cin>>t;
    while(t--){
      for(int i=0,a;i<5;i++){
        cin>>a;
        if(a==0)cout<<i+1;
      }

    }
    clock_t end=clock(); 
    fprintf(stderr, "\n%lf sec\n", (double)(end-beg)/(CLOCKS_PER_SEC));
    return 0;
}


  

Measured memory_bytes: 3728
#include <stdio.h>
#define DIGITUP 1000    //精度確保
int main(void) {
    double a,b,c,d,e,f;
    double x,y;
    double roundx,roundy;
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
        y=(a*f-c*d)/(a*e-b*d);
        x=(c-b*y)/a;
        if(x<0.0){
            roundx=-0.0005;
        }else{
            roundx=0.0005;
        }
        if(y<0.0){
            roundy=-0.0005;
        }else{
            roundy=0.0005;
        }
        x=((double)(int)((x+roundx)*DIGITUP))/DIGITUP;
        y=((double)(int)((y+roundy)*DIGITUP))/DIGITUP;
        printf("%.3f %.3f\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h> 
using namespace std;  
long INF=1000000000000000;
int main() {
    long N;
    cin>>N;
    vector<long> A(N+1);
    vector<long> B(N);
    for(int i=0;i<N+1;i++){
        cin>>A.at(i);
    }
    for(int i=0;i<N;i++){
        cin>>B.at(i);
    }
    
    long ans=0;
    for(int i=0;i<N;i++){
        long l=min(A.at(i),B.at(i));
        B.at(i)-=l;
        long r=min(A.at(i+1),B.at(i));
        A.at(i+1)-=r;
        B.at(i)-=r;
        
        ans+=(l+r);
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int A,P;
    cin >> A >> P;
    int ans = 0;
    ans = (3*A+P) /2;

    cout << ans << endl;

    
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

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

    bool res[26] = {false};
    for(int i = 0; i < S.size(); i++){
        res[S[i] - 'a'] = true;
    }

    for(int i = 0; i < 26; i++){
        if(res[i] == false){
            cout << char(i + 'a') << endl;
            return 0;
        }

    }

    cout << "None" << endl;
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;
public class Main{
  
    public static void main(String [] args){
        Scanner sc=new Scanner(System.in);
        String s=sc.next();

        boolean a=false;
        boolean b=false;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='A'){
                a=true;
            }else if(s.charAt(i)=='B'){
                b=true;
            }
        }

        if(a&&b){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        


    }
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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;
}
//最大公倍数。（最小公倍数は a + b / gcd）
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);

  rep(i, N) { cin >> A[i]; }

  vector<int> fromTop(N);
  vector<int> fromBot(N);
  fromTop[0] = A[0];
  fromBot[0] = A[N - 1];
  rep(i, N - 1) {
    fromTop[i + 1] = gcd(fromTop[i], A[i + 1]);
    fromBot[i + 1] = gcd(fromBot[i], A[N-i-2]);
  }
  int max = 0;
  rep(i, N-2) {
    chmax(max,gcd(fromTop[i],fromBot[N-i-3]));
  }
  chmax(max, fromTop[N - 2]);
  chmax(max, fromBot[N - 2]);
  cout << max << endl;

  rep(i, N) {
    PRINT(fromTop[i])
    PRINT(fromBot[i])
    }
}

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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pii pair<int,int>
#define mod 998244353

int lowbit(int x) {return x&(-x);}
int n,m;
vector <int> edge[100010]; 
int ans[100010];
int ANS[100010];
vector <int> son[100010];
vector <int> pre[100010],suf[100010];

int dfs(int node,int lst) {
	ans[node]=1;
	for (int i=0;i<edge[node].size();i++) {
		if (edge[node][i]==lst) continue;
		son[node].pb(edge[node][i]);
		ans[node]=(ll)(ans[node])*(ll)(dfs(edge[node][i],node)+1)%m;
//		cout<<node<<" "<<ans[node]<<endl;
	}
	for (int i=0;i<son[node].size();i++) {
		if (i==0) pre[node].pb((ans[son[node][i]]+1)%m);
		else pre[node].pb((ll)pre[node][i-1]*(ll)(ans[son[node][i]]+1)%m);
	}
	for (int i=son[node].size()-1;i>=0;i--) {
		if (i==son[node].size()-1) suf[node].pb((ans[son[node][i]]+1)%m);
		else suf[node].pb((ll)suf[node][son[node].size()-1-i-1]*(ll)(ans[son[node][i]]+1)%m);
	}
	reverse(suf[node].begin(),suf[node].end());
	return ans[node];
}

void getANS(int node,int lst,int cnt) {
	ANS[node]=(ll)ans[node]*(ll)(cnt+1)%m;
	for (int i=0;i<son[node].size();i++) {
		ll tmp=1ll;
		if (i) tmp*=(ll)pre[node][i-1];
		if (i<son[node].size()-1) tmp*=(ll)suf[node][i+1];
		tmp%=m;
//		cout<<son[node][i]<<" "<<tmp<<endl;
		tmp*=(ll)(cnt+1),tmp%=m;
		getANS(son[node][i],node,tmp);
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=0;i<n-1;i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		edge[x].pb(y);
		edge[y].pb(x);
	}
	cout<<dfs(1,-1)<<endl;
	getANS(1,-1,0);
	for (int i=2;i<=n;i++) cout<<ANS[i]<<endl;
	return 0;
}


Measured memory_bytes: 29440
def exec_ncr(max_step, record_dict):
    for i in range(2, max_step+1):
        record_dict[i] = record_dict[i-1] + record_dict[i-2]


num_stair, num_wet = map(int, input().split(' '))

last_wet = -1
num_pattern = 1
d = {0: 1, 1: 1}
exec_ncr(num_stair, d)

for i in range(0, num_wet):
    wet = int(input())
    dry_step = wet - last_wet - 1
    last_wet = wet

    if dry_step <= 0:
        print('0')
        exit(0)

    elif dry_step == 1 or dry_step == 2:
        continue

    else:
        num_pattern *= d[dry_step-1]

# last step
dry_step = num_stair - last_wet

num_pattern *= d[dry_step-1]

print(num_pattern % 1000000007)
exit(0)


Measured memory_bytes: 468608
#include <iostream>
using namespace std;
int main() {
    long long i, min, max, sum, n, x;
    cin >> n;
    min = 1000001;
    max = -1000001;
    sum = 0;
    for (i = 1; i <= n; ++i) {
        cin >> x;
        if (x > max) 
            max = x;
        if (x < min)
            min = x;
        sum = sum + x;
    }
    cout << min << " " << max << " " << sum << "\n";
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    forn(i, 0, n) cin >> a[i];
    vector<int> pr(n), nx(n);
    stack<int> q;
    forn(i, 0, n) {
        while (!q.empty() && a[q.top()] > a[i]) q.pop();
        pr[i] = q.empty() ? -1 : q.top();
        q.push(i);
    }
    while (!q.empty()) q.pop();
    ford(i, 0, n) {
        while (!q.empty() && a[q.top()] > a[i]) q.pop();
        nx[i] = q.empty() ? n : q.top();
        q.push(i);
    }
    ll ans = 0;
    forn(i, 0, n) ans += 1ll * a[i] * (i - pr[i]) * (nx[i] - i);
    cout << ans << '\n';
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int st=max(A,C),en=min(B,D);
  int ans=en-st;
  if(ans<0)ans=0;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N,M,X,Y;
	cin>>N>>M>>X>>Y;
	vi XX(N+1); rp(i,0,N) cin>>XX[i];XX[N]=X;
	vi YY(M+1); rp(i,0,M) cin>>YY[i];YY[M]=Y;
	sort(all(XX));
	sort(all(YY));
	// for(auto e:XX)cout<<e<<" ";puts("");//
	// for(auto e:YY)cout<<e<<" ";puts("");//
	if(XX[N] < YY[0]){
		puts("No War");
	}
	else{
		puts("War");
	}
}


Measured memory_bytes: 256