akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N, x, y;
  cin >> N;

  vector<int> P(N);
  vector<int> Q(N);

  REP(i, N) cin >> P[i];
  REP(i, N) cin >> Q[i];

  vector<int> v(N);
  REP(i, N) v[i] = i+1;
  int cnt = 1;
  do{
    if(v == P) x = cnt;
    if(v == Q) y = cnt;
    cnt++;
  }while(next_permutation(ALL(v)));

  cout << abs(x-y) << endl;


  return 0;
}

Measured memory_bytes: 256
//WA
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
#include <limits.h>
//#include <math.h>

typedef struct Enemy{
  int h;
  long x;
}Enemy;

//昇順
int acs(const void *a, const void *b)
{
  return ((Enemy *)a)->x - ((Enemy *)b)->x;
}

//acs, return i such that a[i-1]<=b<a[i] (a[0]<=b<a[n-1])
int binary_search(Enemy *a, int size, int b)
{
  if (size <= 1)
    return size;
  int mid = size / 2;
  if ((a[mid]).x <= b)
    return mid + binary_search(a + mid, size - mid, b);
  else
    return binary_search(a, mid, b);
}

int main() {
  int n, d, a;
  scanf("%d%d%d", &n, &d, &a);
  Enemy e[n+1];
  e[n].x = LONG_MAX;
  for (int i=0; i<n; i++) scanf("%ld%d", &((e[i]).x), &((e[i]).h));
  qsort(e, n, sizeof(Enemy), acs);
  int domain[n];
  for (int i=0; i<n; i++) {
    domain[i] = binary_search(e, n+1, e[i].x+2*d);
  }
  //for (int i=0; i<n; i++) printf("%d ", domain[i]);
  //printf("\n");
  long f[n+1];
  f[n] = 0;
  for (int i=n-1; i>=0; i--) {
    int idx = domain[i];
    if ((f[i+1] - f[idx])*a >= e[i].h) f[i] = f[i+1];
    else f[i] = f[i+1] + (e[i].h-(f[i+1]-f[idx])*a-1)/a + 1;
  }
  //for (int i=0; i<n; i++) printf("%ld ", f[i]);
  printf("%ld\n", f[0]);
  return 0;
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int a;
	cin>>a;
	if(a<1200)cout<<"ABC\n";
	else if(a<2800&&a>=1200)cout<<"ARC\n";
	else if(a>=2800)cout<<"AGC\n";
    return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

static const int MAX_N = 300;
int N;
double dp[MAX_N+1][MAX_N+1][MAX_N+1];
vector<double> A(N);

double solve(int o, int t, int h) { // one, two, three
  if (dp[o][t][h] != -1) return dp[o][t][h];
  if (o == 0 && t == 0 && h == 0) return 0;
  double ans = (double)N / (o + t + h);
  if (o > 0) ans += 1.0 * o / (o + t + h) * solve(o-1, t, h);
  if (t > 0) ans += 1.0 * t / (o + t + h) * solve(o+1, t-1, h);
  if (h > 0) ans += 1.0 * h / (o + t + h) * solve(o, t+1, h-1);
  dp[o][t][h] = ans;
  return ans;
};

int main() {
  cin >> N;

  rep(i, 0, MAX_N+1) {
    rep(j, 0, MAX_N+1) {
      rep(k, 0, MAX_N+1) {
        dp[i][j][k] = -1;
      }
    }
  }

  int a1 = 0, a2 = 0, a3 = 0;
  rep(i, 0, N) {
    int x;
    cin >> x;
    if (x == 1) a1++;
    if (x == 2) a2++;
    if (x == 3) a3++;
  }

  Decimal(solve(a1, a2, a3));
};


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

using namespace std;

int main() {
	string S;
	cin >> S;
	int count = -1;

	if (S == "RRR") {
		count = 3;
	}
	else if (S == "RRS" || S == "SRR") {
		count = 2;
	}
	else if (S == "SSS") {
		count = 0;
	}
	else {
		count = 1;
	}

	cout << count << endl;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;


int main() {
	int H,W;cin>>H>>W;
	vector<vector<int>>as(H,vector<int>(W));

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin>>as[i][j];
		}
	}
	
	int ans=1e9;
	for (int ro = 0; ro < H; ++ro) {
		for (int co = 0; co < W; ++co) {
			int nans=0;
			for (int y = 0; y < H; ++y) {
				for (int x = 0; x < W; ++x) {
					int ans1=abs(y-ro);
					int ans2=abs(x-co);

					nans+=min(ans1,ans2)*as[y][x];
				}
			}
			ans=min(ans,nans);
		}
	}

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




Measured memory_bytes: 3172
/* 

Good 

 */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define EB(x) emplace_back(x)
#define DEBUG(x) cout << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

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

const int MAX_V = 1e5 + 5;
vi from[MAX_V * 2];
vector<bool> seen(MAX_V * 2);
vi cnt(2);

void dfs(int u)
{
    if (seen[u])
        return;
    seen[u] = true;
    cnt[u / MAX_V]++;

    for (auto &v : from[u])
        dfs(v);
}

int main()
{
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    REP(i, N)
    {
        int x, y;
        cin >> x >> y;
        y += MAX_V;
        from[x].push_back(y);
        from[y].push_back(x);
    }

    ll ans = 0LL;
    REP(i, MAX_V * 2) {
        cnt = vi(2);
        dfs(i);
        ans += (ll) cnt[0] * cnt[1];
    }
    ans -= N;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10112
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  int r, D, x2000;
  cin >> r >> D >> x2000;

  int x = x2000;
  rep(i, 0, 10) {
    x = r * x - D;
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    ll N;
    cin>>N;
    vector<ll> X(N);
    ll count=0;
    rep(i,N){
        char A;
        cin>>A;
        if(A=='1'){
            X.at(i)=1;
            count++;
        }
        else X.at(i)=0;
    }
    ll modA=0;
    ll modB=0;
    ll countA=count+1;
    ll one=1;
    ll countB=max(count-1,one);
    rep(i,N){
        modA=(modA+X.at(i)*powerup(2,N-1-i,countA))%countA;
        modB=(modB+X.at(i)*powerup(2,N-1-i,countB))%countB;
    }
    rep(i,N){
        ll val=0;
        ll ans=0;
        if(X.at(i)==0){
            val=(modA+powerup(2,N-1-i,countA))%countA;
        }
        else if(X.at(i)==1){
            val=(modB+countB-powerup(2,N-1-i,countB))%countB;
        }
        ans++;
        while(val>0){
            ll countC=0;
            ll j=0;
            while((1<<j)<=val){
                if((val&1<<j)==(1<<j))countC++;
                j++;
            }
            val=val%countC;
            ans++;
        }
        if(count==1&&X.at(i)==1)cout<<0<<endl;
        else cout<<ans<<endl;
    }
}

Measured memory_bytes: 4828
#include<iostream>
int m[]={5,1,2,4,1,3,1,0,0,2,3,2,2,4,5,1,4,0,4,3,3,5,0,5},a,b,c,d,r;
char s[99];
int main(){
	for(s[87]=1,s[78]=4,s[69]=3,s[83]=2;~scanf("%s",s);*s<60?printf(r?"%d\n":0,r),a=c=0,b=r=1:(d=s[*s],d?d=d+c&3,a=m[4*a+d],b=m[4*b+d]:c+=*s-76?1:3,r+=a%3?b%3?(b+6-a)%6<3?2:5:3+!b:a?6:1));
}

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


int main() {
    int N, H;
    cin >> N >> H;
    int A[N], B[N];
    rep(i, N) cin >> A[i] >> B[i];
    sort(A, A+N, greater<int>());
    sort(B, B+N, greater<int>());

    int ans = 0, idx_BoverA = -1;
    rep(i, N) if (B[i] > A[0]) idx_BoverA = i;
    rep(i, idx_BoverA + 1) {
        if (H > 0) {
            H -= B[i];
            ans++;
        }
    }

    if (H > 0) ans += (H + A[0] - 1) / A[0];

    cout << ans << endl;

    return 0;
}

 

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

int main()
{
  string S;cin>>S;
  int len=S.size();
  vector<char> T(len);
  vector<char> U(len);
  for (int i=0;i<len;i++)
  {
    if (i%2==0)
    {
      T[i]='0';U[i]='1'; 
    }
    else
    {
      T[i]='1';U[i]='0'; 
    }
  }
  
  int count1=0;int count2=0;
  for (int i=0;i<len;i++)
  {
     if (S[i]!=T[i]) count1++;
     if (S[i]!=U[i]) count2++;
  }
  if (count1>count2)cout<<count2<<endl;
  else cout<<count1<<endl;
}

Measured memory_bytes: 512
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

int X,A;

signed main(){

    in(X,A);
    out(X<A?0:10);

    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	string a,b;
	
	cin>>a>>b;
	
	int cnt=0;
	
	for(int i=0;i<a.size();i++)
	{
		if(a[i]!=b[i])
		{
			cnt++;
		}
	}
	
	cout<<cnt<<endl;
	
	return 0;
}


Measured memory_bytes: 3808
n=int(input())
l=len(str(n))
ans=0
if l>=4:
    if l==6:
        ans+=100000-10000
    elif l==5:
        ans+=n+1-10000
    ans+=1000-100
    ans+=10-1
elif l>=2:
    if l==3:
        ans+=n+1-100
    ans+=10-1
else:
    ans+=n   
print(ans)

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

int main() {
    int n, k;
    cin >> n >> k;
    int h;
    int count = 0;
    for(int i = 0; i < n; i++) {
        cin >> h;
        if(h >= k) count++;
    }

    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector <pair<int,int>> myVec;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    myVec.push_back(make_pair(a,i));
  }
  sort(myVec.begin(),myVec.end());
  for(int i = 0; i < myVec.size(); i++){
    cout << myVec[i].second + 1 << " ";
  }
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define ll long long
ll mod=1000000007;
#define vl vector<ll>
#define pl pair<ll,ll>
#define rep(i,b) for(ll i=0;i<b;i++)
#define all(v) (v).begin(),(v).end()
using namespace std;

int main(){
    ll n,ans=0;
    cin>>n;
    vl a(n);
    rep(i,n){
        cin>>a[i];
    }
  sort(all(a));
    for(ll i=1;i<100002;i++) {
        if(a.end() - upper_bound(all(a), i - 1)==lower_bound(all(a), i) - a.begin() )ans++;
    }
    cout<<ans<<endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> V(10, vector<int>(10));
  for (int i = 1; i <= N; i++) {
    int f = i;
    while (f > 9) f /= 10;
    int b = i % 10;
    V.at(f).at(b)++;
  }

  int sum = 0;
  for (int i = 1; i <= N; i++) {
    int f = i;
    while (f > 9) f /= 10;
    int b = i % 10;
    sum += V.at(b).at(f);
  }

  cout << sum << "\n";
}

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

int main(){
	int N,M;	cin>>N>>M;
	vector< vector<int> > vec(M); // 各電球につながる、スイッチの番号を記録
	for(int i=0;i<M;i++){
		int k;	cin>>k;

		vec[i].resize(k);
		for(int j=0;j<k;j++){
			cin>>vec[i][j];		// 電球につながるスイッチ番号を入力
			--vec[i][j];	// スイッチ番号を、0-オリジンにする
		}
	}

	vector<int> p(M);
	for(int i=0;i<M;i++) cin>>p[i];


	// 解答
	int ans=0;
	for(int i=0;i<(1<<N); i++){		// i: スイッチの全パターン
		bool ok = true;
		for(int j=0;j<M;j++){
			int c=0;	// 電球の点灯個数
			for(int id : vec[j]){
				if( (i>>id)&1 ) c++;
				/* 
					i を id ぶんだけシフト -> 一番下の桁に、
					idスイッチのオン・オフ(1・0)が来るので、
					オンかどうかは、AND 1 の真偽でわかる。
				*/
			}
			if(c%2 != p[j]){
				ok = false;
			}
		}
		if(ok) ans++;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <utility>
#include <climits>
 
#include <cstdio>
  
using namespace std;
 
#define REP(var, count) for(int var=0; var<count; var++)
 
const int IPPAI = 214748364;
 
int umi[210][210];
int riku[210][210];
 
int cmpl[1010][210]; //[??????????????§??????][????????????]
bool used[1010][210];
 
bool solve(void) {
    int N, M;
    
    cin >> N >> M;
    if ( N == 0 ) { return false; }
    
    REP(i, 210) REP(j, 210) {
        int a = (i==j) ? 0 : IPPAI;
        umi[i][j] = a;
        riku[i][j] = a;
    }
    
    REP(i, M) {
        int x, y, l;
        char ty;
        cin >> x >> y >> l >> ty;
        
        if (ty == 'L') {
            riku[x][y] = l;
            riku[y][x] = l;
        } else {
            umi[x][y] = l;
            umi[y][x] = l;
        }
    }
    
    // ???
    for(int k=1; k<=N; k++) {
        for(int i=1; i<=N; i++) {
            for(int j=1; j<=N; j++) {
                umi[i][j] = std::min(umi[i][j], umi[i][k] + umi[k][j]);
                riku[i][j] = std::min(riku[i][j], riku[i][k] + riku[k][j]);
            }
        }
    }
 
    int R;
    int list[1010];
    cin >> R;
    REP(i, R) { cin >> list[i]; }
    
    for(int i=1; i<=N; i++) {
    	cmpl[0][i] = IPPAI;
    }
    // ?§???????????????????
    cmpl[0][ list[0] ] = 0;
    
    for(int f=1; f<R; f++) {
    	for(int i=1; i<=N; i++) {
    	
    		int prevpos = list[f-1];
    		int nextpos = list[f];
    		
       		// ??????????????§?§??????????
    		int rikuro = IPPAI;
    		if ( cmpl[f-1][i] != IPPAI && riku[prevpos][nextpos] != IPPAI ) {
    			rikuro = cmpl[f-1][i] + riku[prevpos][nextpos];
    		}
    		
    		// ???????§?????????????????§??????????
    		int kairo = IPPAI;
    		// ?????????????????????
    		for(int pf=1; pf<=N; pf++) {
    			if ( cmpl[f-1][pf] == IPPAI ) { continue; }
    			
    			int cost = 0;
    			// ????????§????????§???????????????
    			if ( riku[prevpos][pf] == IPPAI ) { continue; }
    			cost += riku[prevpos][pf];
    			
    			// ????????§?§??????????
    			if ( umi[pf][i] == IPPAI ) { continue; }
    			cost += umi[pf][i];
    			
    			// ?????????????????°?????§????????§?§??????????
    			if ( riku[i][nextpos] == IPPAI ) { continue; }
    			cost += riku[i][nextpos];
    			
    			kairo = std::min(kairo, cmpl[f-1][pf] + cost);
    		}
    		
    		cmpl[f][i] = std::min(rikuro, kairo);
    	}
    }
    
    int ret = IPPAI;
    for(int i=1; i<=N; i++) {
        ret = std::min(ret, cmpl[R-1][i]);
    }
     
    cout << ret << endl;
    
    return true;
}
 
int main(void) {
    while( solve() ) {}
}

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

int main(){
	int N,D,X;
	int A[101];
	cin>>N>>D>>X;
	int res = X+N;
	for(int n=0; n<N; ++n){
		cin>>A[n];
	}
	for(int i=0; i<N; ++i){
		int count = 1;
		int diff = A[i];
		while(count<D){
			count += diff;
			if(count<=D){
				res++;
			}
		}
	}
	cout << res << endl;
	return 0; 
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		String S=stdIn.next();
		int N=S.length();
		int roop[]=new int[S.length()];
		char A[]=new char[N];
		int ans[]=new int[N];
		int z=0,y=0,x=0;
		while(z<N){
			A[z]=S.charAt(z);
			if(z!=0)
				if(A[z]=='L'&&A[z-1]=='R'){
					roop[y]=z-1;
					roop[y+1]=z;
					y+=2;
				}
			z++;
		}z=0;
		while(z<N){
			if(z==roop[x+1]){
				ans[roop[x+1]]++;
				x+=2;
			}
			else{
				if(z<roop[x]&&A[z]=='R')
					if((roop[x]-z)%2==1)
						ans[roop[x+1]]++;
					else
						ans[roop[x]]++;
				if(x!=0&&z>roop[x-1]&&A[z]=='L')
					if((z-roop[x-1])%2==1)
						ans[roop[x-2]]++;
					else
						ans[roop[x-1]]++;
				if(z==roop[x])
					ans[roop[x]]++;
			}
			z++;
		}z=0;
		while(z<N){
			System.out.println(ans[z]);
			z++;
		}
	}
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,m,q;  cin >> n >> m >> q;
  vector<int> v[501];
  for(int i = 0; i < m; ++i){
    int l,r; cin >> l >> r;
    v[r].push_back(l);
  }
  vector<P<int,int>> qry[501];
  for(int i = 0; i < q; ++i){
    int l,r; cin >> l >> r;
    qry[r].emplace_back(l,i);
  }
  vector<int> ans(q);
  vector<int> fnd;
  fnd.reserve(m);
  for(int i = 0; i <= n; ++i){
    for(auto e:v[i])
      fnd.insert(lower_bound(fnd.begin(),fnd.end(),e),e);
    for(auto e:qry[i]){
      ans[e.second] = distance(lower_bound(fnd.begin(),fnd.end(),e.first),fnd.end());
    }
  }
  for(auto e:ans)cout << e << endl;
}


Measured memory_bytes: 6888
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

//1-indexed
int h, w;
ll ans;
string s[401][401];
bool vst[401][401];

ll num_black, num_white;

void dfs(int sh, int sw){

  if(vst[sh][sw]) return;
  if(s[sh][sw] == "#") num_black++;
  else num_white++;
  vst[sh][sw] = true;
  
  int nh = sh-1, nw = sw;
  //hidari
  if(0 <= nh && nh < h && 0 <= nw && nw < w && s[nh][nw] != s[sh][sw]){
    dfs(nh, nw);
  }  
  //migi
  nh = sh+1, nw = sw;
  if(0 <= nh && nh < h && 0 <= nw && nw < w && s[nh][nw] != s[sh][sw]){
    dfs(nh, nw);
  }
  //ue
  nh = sh, nw = sw-1;
  if(0 <= nh && nh < h && 0 <= nw && nw < w && s[nh][nw] != s[sh][sw]){  
    dfs(nh, nw);
  }
  //sita
  nh = sh, nw = sw+1;
  if(0 <= nh && nh < h && 0 <= nw && nw < w && s[nh][nw] != s[sh][sw]){
    dfs(nh, nw);
  }
  return ;
}

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

  cin >> h >> w;

  string stmp;
  REP(i, h) {
    cin >> stmp;
    REP(j, stmp.size()){
      s[i][j] = stmp[j];
    }
  }

  REP(i, h){
    REP(j, w){
      num_black = 0;
      num_white = 0;
      dfs(i, j);
      ans += (ll)num_black*(ll)num_white;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 24192
import java.util.Scanner;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int a[] = new int[n];
		long sub[] = new long[n+1];
		for(int i=0; i<n; i++) {
			a[i]=sc.nextInt();
		}
		long max=0;
		for(int i=1; i<n; i++) {
			sub[i]=Math.abs(a[i]-a[i-1]);
			max = Math.max(max, sub[i]);
		}
		sub[n] = Math.abs(a[0]+k-a[n-1]);
		max = Math.max(max, sub[n]);
		System.out.println(k-max);
		sc.close();
	}
}


Measured memory_bytes: 90204
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int64_t k;
  cin >> k;
  int64_t m=1000000000000001;
  rep(i,5){
    int64_t a;
    cin >> a;
    m=min(m,a);
  }
  cout << 5+(k-1)/m << endl;
}


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

a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
cnt = 0
total_l = []
cnt_l = []
for i in range(n):
    if a[i] - (b[i] - cnt) >= 0:
        total += b[i] - cnt
        cnt = 0
    else:
        total += a[i]
        cnt = max(-b[i], a[i] - (b[i] - cnt))

if cnt < 0:
    total += min(a[n], abs(cnt))

print(total)

Measured memory_bytes: 24208
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll h, w;


//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	string s;
	cin >> s;
	ll n = s.length();
	ll g = 0, p = 0;
	ll ans = 0;
	rep(i, n) {
		if (s[i] == 'g') {
			if (p >= g) {
				g++;
			}
			else {
				p++;
				ans++;
			}
		}
		else {
			if (p >= g) {
				g++;
				ans--;
			}
			else {
				p++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define rep(n,k) for(int i = (int)n;i<k;i++)
using Int =long long int;
using Graph =vector<vector<int>>;
int main(){
    string s,t;cin>>s>>t;
    int ssize= s.size();int tsize=t.size();
    int current=-1;
    for(int i=0;i+tsize<=ssize;i++){
        int sa=0;
        int sum=0;
        for(int j=0;j<tsize;j++){
            sa =int(s.at(j+i))-int(t.at(j));
         
            if (sa!=0) sum++;
        }

        if(current==-1||current>sum){
            current=sum;
           
        }
    
    }
    cout<<current<<endl;
}

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

const int IMINUS_JMINUS = 1, IMINUS = 2, JMINUS = 3;

struct state
{
    int length, from;
};

void lcs(string &s, string &t)
{
    state dp[s.length() + 1][t.length() + 1];
    memset(dp, 0, sizeof(dp));
    
    //cout << dp[0][0].length << endl;
    for (int i = 1; i < s.length() + 1; i++) {
        for (int j = 1; j < t.length() + 1; j++) {
            //if (i == 5 && j == 2) {
            //    cout << "" << endl;
            //}
            if (s[i - 1] == t[j - 1]){
                if (dp[i][j].length < dp[i - 1][j - 1].length + 1)
                {
                    dp[i][j].length = dp[i - 1][j - 1].length + 1;
                    dp[i][j].from = IMINUS_JMINUS;
                }
            } else {
                if (dp[i][j].length < dp[i - 1][j].length)
                    dp[i][j].length = dp[i - 1][j].length, dp[i][j].from = IMINUS;
                if (dp[i][j].length < dp[i][j - 1].length)
                    dp[i][j].length = dp[i][j - 1].length, dp[i][j].from = JMINUS;
            }
            //cout << "i,j" << i << ", " << j << ":" <<  dp[i][j].length << endl;
        }
    }
    cout << dp[s.length()][t.length()].length << endl;
}

int main(int argc, char *argv[])
{
    
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s, t;
    while (n--) {
        cin >> s >> t;
        lcs(s, t);
    }
    
    
    
    return 0;
}



Measured memory_bytes: 11064
#include <cstdio>
int n,m,d;
int main(){
	long long N,h,n,w;
	bool flag=false;
	scanf("%lld",&N);
	if(N%2==0)
		printf("%lld %lld %lld",N/2,N,N);
	else{
		for(h=3500;h>0;h--){
			for(n=3500;n>0;n--){
				if(n*N+h*N>4*n*h) break;
				if((N*h*n)%(4*h*n-N*h-N*n)==0){
					if((N*h*n)<(4*h*n-N*h-N*n)*3500){
					w=(N*h*n)/(4*h*n-N*h-N*n);
					flag=true;
					}
				}
				if(flag) break;
			}
			if(flag) break;
		}
		printf("%lld %lld %lld\n",h,n,w);
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    string a;
    cin >> a;

    set<char> st;
    for(char d:a) {
        st.insert(d);
    }
    pri(st.size()==a.size()?"yes":"no");


    return 0;
}



Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
li = list(map(int,input().split()))
se = set(li)
if len(se) == 1:
    if sum(se) == 0:
        print('Yes')
    else:
        print('No')
elif len(se) == 2:
    a,b = sorted(se)
    if a == 0:
        if li.count(a) * 3 == n:
            print('Yes') # 0 count is equal 1
        else:
            print('No')
    else:
        print('No')
elif len(se) == 3:
    a,b,c = se
    if li.count(a) == li.count(b) == li.count(c):
        if a^b == c:
            print('Yes')
        else:
            print('No') # a xor b xor c = 0 is ok
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 22028
#include<cstdio>
#include<iostream>
#include<queue>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<cstdlib>
#include<stack>
#include<ctime>
#include<map>
#include<list>
#include<cctype>
using namespace std;

int main()
{
	int d,t,s;
	scanf("%d%d%d",&d,&t,&s);
	if(s*t>=d) puts("Yes");
	else puts("No");
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  string S[N];
  cin >> S[0];
  for (int i=1;i<N;i++){
    cin >> S[i];
    if (S[i].front()!=S[i-1].back()){
      cout << "No" << endl;
      return 0;
    }
    for (int j=0;j<i;j++){
      if (S[i]==S[j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


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

int main() {

    string S;
    cin >> S;    
    
    int isb[S.size()] = {0};
    int num_b = 0;
    
    int size = S.size();
    for(int i = 0; i < size; i++){
        if(S[i] == 'B'){
            isb[i] = 1;
            num_b++;
        }
    }
    long long initial = 0;
    for(int i = 0; i < size; i++){
        if(isb[i]){
            initial += i;
        }
    }

    long long final = 0;
    for(int  i = size - num_b; i < size; i++){
        final += i;
    }
    cout << final - initial << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int>gate(m);
    rep(i, m)cin >> gate[i];
    int right = m+1, left = 0,mid;
    while (!(left +1 == right)) {
        mid = (right + left ) / 2;
        if (gate[mid] < x)left = mid;
        else right = mid;
    }
    if (left == 0)cout << 0 << endl;
    else cout << min(left+1, m - right) << endl;
    return 0;
}

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

int n,maxn;
string s[200005];
map <string,int> ma;

bool cmp(string a,string b){
	return a<b;
}

int main(void){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	cin>>s[i],ma[s[i]]++,maxn=max(maxn,ma[s[i]]);
	sort(s+1,s+1+n,cmp);
	for(int i=1;i<=n;i++)
	if(ma[s[i]]==maxn){
		cout<<s[i]<<endl;
		ma[s[i]]=-1;
	}
}

Measured memory_bytes: 26752
import java.util.*;


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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		ArrayList<Integer> a = new ArrayList<Integer>();
		for(int i=0; i<n; i++) a.add(sc.nextInt());
		Collections.sort(a);
		int N = a.get(n-1);
		int K = 0;
		int max = 0;
		for(int i=0; i<n-1; i++) {
			int v=a.get(i);
			int tmp = Math.min(v, N-v);
			if(max < tmp) {
				max = tmp;
				K = v;
			}
		}
		System.out.println(N+" "+K);
		sc.close();
	}


}


Measured memory_bytes: 61064
from itertools import product
s = input()
s_last = s[-1]
len_s = len(s)
ttl = 0
for i in product(['', '+'], repeat=len_s- 1):
    ttl += eval(''.join(s[j] + i[j] for j in range(len_s - 1)) + s_last)
print(ttl)


Measured memory_bytes: 3060
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int n;
    string s[55];
    int t[55];
    string x;
    cin >> n;
    rep(i, n) cin >> s[i] >> t[i];
    cin >> x;

    int ans = 0;
    int i = 0;
    while (s[i] != x) ++i;
    ++i;
    for (; i < n; ++i) ans += t[i];
    print(ans);


    return 0;
}



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

const int maxn = 1e5 + 5;
char str[maxn];
int contp,contg,w,l;

int main()
{
    while(scanf("%s",str) != EOF)
    {
        contp = 0;
        contg = 0;
        w = 0;
        l = 0;
        for(int i = 0;str[i] != '\0';i++)
        {
            if(contg <= contp)
            {
                contg++;
                if(str[i] == 'p')
                {
                    l++;
                }
            }
            else
            {
                contp++;
                if(str[i] == 'g')
                {
                    w++;
                }
            }
        }
        printf("%d\n",w - l);
    }
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main() {
    int n;
    int i = 1;
    scanf("%d", &n);
    while (1) {
        int x = i;
        if (x % 3 == 0) {
            printf(" %d", i);
            if (++i <= n) {continue;}
            break;
        }
        while (1) {
            if (x % 10 == 3) {
                printf(" %d", i);
                break;
            }
            x /= 10;
            if (x) {continue;}
            break;
        }
        if (++i <= n) {continue;}
        else break;
    }
    printf("\n");
    return 0;
}




Measured memory_bytes: 2056
//#include<iostream>
#include<cstring>
#include<cstdio>
//#include<time.h>
//#include<complex>
//#include<set>
#include<algorithm>
//#include<math.h>
#include<stdlib.h>
using namespace std;
 
int n,m;
char mp[15][15];
 
int a[15]; bool vis[15],ans=0;
 
bool v2[15];
bool check()
{
//	for (int i=1;i<=n;i++) cout<<a[i]<<' ';cout<<endl;
	memset(v2,0,sizeof(v2));
	bool used=(m&1);
	for (int i=1;i<=m;i++) if (!v2[i])
	{
		bool flag=0;
		for (int j=i+1;j<=m;j++) if (!v2[j])
		{
			bool ff=1;
			for (int k=1;k<=n;k++) if (mp[a[k]][i]!=mp[a[n-k+1]][j]) ff=0;
			if (ff) {v2[j]=1; flag=1; break;}
		}
		if (!flag)
		{
			if (used)
			{
				bool ff=1;
				for (int k=1;k<=n;k++) if (mp[a[k]][i]!=mp[a[n-k+1]][i]) ff=0;
				if (ff) used=0;
				else return 0;
			}
			else return 0;
		}
	}
	return 1;
}
			
void dfs(int cur,int pos,bool odd)
{
	if (ans) return;
	if (cur>n) {ans=check(); return;}
	if (vis[cur]) {dfs(cur+1,pos,odd); return;}
	
	for (int i=cur+1;i<=n;i++) if (!vis[i])
	{
		a[pos]=i; a[n-pos+1]=cur;
		vis[i]=1;
		dfs(cur+1,pos+1,odd);
		vis[i]=0;
	}
	if (odd)
	{
		a[(n>>1)+1]=cur;
		dfs(cur+1,pos,0);
	}
}
 
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%s",mp[i]+1);
	dfs(1,1,n&1);
	puts(ans?"YES":"NO");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

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();
        }
        Arrays.sort(a);
        long x = 0;
        long y = 0;
        for(int i = n-1; i >= 1; i--) {
            if( a[i] == a[i-1] ) {
                if(x == 0) {
                    x = a[i];
                    i--;
                } else {
                    y = a[i];
                    System.out.println(x*y);
                    System.exit(0);
                }
            }
        }
        System.out.println(0);
    }
}

Measured memory_bytes: 50352
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
#define fcout cout<<fixed<<setprecision(10)
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int ketawa(ll k,int a){
	if(k) return k%a+ketawa(k/a,a);
	else return 0;
}

ll beki(int k){
	ll ans=1;
	FOR(i,0,k) ans*=10;
	return ans;
}

int main(){
	vector<ll> v;
	int k; cin>>k;
	FOR(i,0,16){
		FOR(j,0,1000){
			if(j*beki(i)+beki(i)-1<=10e15)
			v.PB(j*beki(i)+beki(i)-1);
		}
	}
	sort(v.rbegin(),v.rend());
	v.erase(unique(v.begin(), v.end()), v.end());
	vector<ll> snuke;
	double m=10e17;
	FOR(i,0,v.size()-1){
		if(v[i]<=m*ketawa(v[i],10)){
			snuke.PB(v[i]);
			m=(double)v[i]/ketawa(v[i],10);
		}
	}
	FOR(i,0,k){
		co(snuke[snuke.size()-1-i]);
	}
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }

char SS[200010];
int S[200010];

array<int, 2020> mem;

signed main()
{
	cin >> SS;
	int len = strlen(SS);
	for (int i = 0; i < len; i++)
	{
		S[i] = SS[i] - '0';
	}

	int ans = 0;
	for (int i = 0; i < len; i++)
	{
		array<int, 2020> temp = {};
		for (int j = 0; j < 2019; j++)
		{
			int n = j * 10 + S[i];
			if (n >= 2019)
			{
				n %= 2019;
			}
			temp[n] += mem[j];
		}
		mem = temp;
		mem[S[i]]++;

		ans += mem[0];
	}

	cout << ans << endl;
}




Measured memory_bytes: 5424
import java.util.Arrays;
public class Main {
    static int[] baseNumbers = {1,2,3,4,5,6,7,8,9};
    public static void main(String[] args) {
        Arrays.stream(baseNumbers).forEach(n -> Arrays.stream(baseNumbers).forEach(m -> System.out.println(n + "x" + m + "=" + (n*m))));
    }
}

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

int main () {
    int A, B, C, X, sum = 0;
    cin >> A >> B >> C >> X;
    int total = 0;
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                total = 500 * i + 100 * j + 50 * k;
                if (X == total) {
                    sum++;
                }
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set> 
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin>>N;
    ll n=log10(((25*N)/26)+1)/log10(26);
    N-=(26*(pow(26,n)-1))/25;
    if(N==0){
        for(int i=0;i<n;i++)cout<<"z";
    }
    else {
        n++;
        for(int i=0;i<n;i++){
            int x=ceil((double)N/pow(26,n-i-1))-1;
            cout<<(char)('a'+x);
            N-=((ll)pow(26,n-i-1)*x);
        }
    }
    return 0;
}

Measured memory_bytes: 3972