akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair <int,ii>
#define iil pair<ll,ll>
#define iiil pair<ll,iil>
#define max3(a,b,c) max(a, max(b,c))
#define min3(a,b,c) min(a, min(b,c))
#define s(v) sort(v.begin(),v.end())
#define pf printf
#define sf scanf
#define MIN INT_MIN
#define MAX INT_MAX
#define accepted 0
#define GCD(x,y)  __gcd(x, y)
#define endl "\n"
using namespace std;
const int maxn = 1e5 + 69;
//int vis[maxn];
//int indegree[maxn];
//vector<int> graph[maxn];
//vector<int> order;
/**
int gx[]= {2,2,-2,-2,1,-1,1,-1};
int gy[] ={1,-1,1,-1,2,2,-2,-2};

void DFS(int a,bool tpsort){
        vis[a] = 1;
    for(int i=0;i<graph[a].size();i++){
        int r = graph[a][i];
            if(vis[r]==0){
                DFS(r,tpsort);
            }
    }
    if(tpsort)order.push_back(a);
}

int vis[maxn],l[maxn],l2[maxn];
vector<int> graph[maxn];
vector<int> cst[maxn];
int mx,ans;
void BFS(int root){
    memset(vis,0,sizeof(vis));
    memset(l,0,sizeof(l));
    vis[root] = 1;
    l[root] = 0;
    queue <int> q;
    ans = 0;
    mx = root;
    q.push(root);
    while(!q.empty()){
        int cur = q.front();
        q.pop();
        int p = graph[cur].size();
        for(int i=0;i<p;i++){
            int r = graph[cur][i];
            if(vis[r]==0){
                vis[r] = 1 ;
                l[r] = l[cur] + cst[cur][i];
                if(l[r]>ans){
                    ans = l[r];
                    mx = r;
                }
                q.push(r);
            }
        }
    }
   // cout<< ans <<endl;
}
void ultapoth(int root){
    memset(vis,0,sizeof(vis));
    memset(l2,0,sizeof(l2));
    vis[root] = 1;
    l2[root] = 0;
    queue <int> q;
    q.push(root);
    while(!q.empty()){
        int cur = q.front();
        q.pop();
        int p = graph[cur].size();
        for(int i=0;i<p;i++){
            int r = graph[cur][i];
            if(vis[r]==0){
                vis[r] = 1 ;
                l2[r] = l2[cur] + cst[cur][i];
                q.push(r);
            }
        }
    }
   // cout<< ans <<endl;
}
**/
int main(){
    //fast
    int n,ans,x;
    string a = "";
        cin>>n;
    for(int i=0;i<1000007;i++)a+='7';
    x = a.size();
    int cnt = 0;
        ans = 0;
        for(int i=0;i<x;i++){
            ans = (ans*10) + (a[i] - '0');
            ans%=n;
            cnt++;
              if(ans==0){
                cout<< cnt <<endl;
                return accepted;
            }
            // cout<< ans <<endl;
        }

        cout<< "-1" <<endl;


    return accepted;
}


Measured memory_bytes: 5324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n, m;
    cin >> n >> m;

    cout << max(n - 2*m, 0LL) << endl;
    return 0;

}


Measured memory_bytes: 256
S = list(input())
w = 0
e = 0
n = 0
s = 0
if "W" in S :
    w = 1
if "E" in S :
    e = 1
if "N" in S :
    n = 1
if "S" in S :
    s = 1
if w == e and n == s :
    print("Yes")
else :
    print("No")


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

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

    int d;
    cin >> d;

    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];

    vector<int> t(d);
    // rep(i, d){
    //     cin >> t[i];
    //     --t[i];
    // }

    vector<int> last(26, 0);
    rep(i, d){
        int res = -1001001001;
        int mxidx = -1;
        rep(tt, 26){
            int sm = 0;
            sm += s[i][tt];
            vector<int> l = last;
            
            int minus = 0;

            rep(j, 26) ++l[j];
            l[tt] = 0;
            rep(j, 26) minus += c[j] * l[j];

            sm -= minus;
            if(sm > res){
                mxidx = tt;
                res = sm;
            }
        }
        rep(j, 26) ++last[j];
        last[mxidx] = 0;
        t[i] = mxidx+1;
    }

    rep(i, d) cout << t[i] << endl;




    return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>
using namespace std;
int main() {
	int a, b, c, d, e, f;
	double x, y;
	while(scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF) {
		int a1 = a, b1 = b, c1 = c, d1 = d, e1 = e, f1 = f;
		a1 *= e;
		b1 *= e;
		c1 *= e;
		d1 *= b;
		e1 *= b;
		f1 *= b;
		if(f1 - c1 == 0) printf("0.000 ");
		else printf("%.3f ", (double) (f1 - c1) / (d1 - a1));

		b *= d;
		c *= d;
		d *= a;
		e *= a;
		f *= a;
		if(f - c == 0) printf("0.000\n");
		printf("%.3f\n", (double) (f - c) / (e - b));
	}
	return 0;
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using vvv= vector<vv>;
const int INF = 1001001001;

int main(){
    int n,k;cin>>n>>k;
    vi h(n);
    rep(i,n)cin>>h[i];
    
    vi dp(n+1, INF);
    dp[0] = 0;
    for(int i=1; i<n; i++){
        for(int j=1; j<=k; j++){
            if(i-j>=0)dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 4024
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
char name[100];
int t;
} P;
P Q[LEN];
int head,tail,n;
void enqueue(P x){
Q[tail]=x;
tail=(tail+1)%LEN;
}
P dequeue(){
P x=Q[head];
head=(head+1)%LEN;
return x;
}
int min(int a,int b){return a<b?a:b;}
int main(){
int elaps=0,c;
int i,q;
P u;
scanf("%d %d",&n,&q);
for(i=1;i<=n;i++){
scanf("%s",Q[i].name);
scanf("%d",&Q[i].t);
}
head = 1; tail=n+1;
while(head != tail){
u=dequeue();
c=min(q,u.t);
u.t-=c;
elaps+=c;
if(u.t>0)enqueue(u);
else{
printf("%s %d\n",u.name,elaps);
}
}
return 0;
}

Measured memory_bytes: 10756
#include<iostream>
#include<stdio.h>
#include<string.h>
#include <math.h>
using namespace std;

int main(void){
    int n, d, ans = 0;
    cin >> n >> d;
    double x[n], y[n] ;

    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
        if(sqrt(x[i] * x[i] + y[i] * y[i]) <= d) ans++;
    }

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

Measured memory_bytes: 6876
import sys


def f(t, x, y):
    d = t - (x+y)
    return d >= 0 and d % 2 == 0

N = int(sys.stdin.readline())
last_T = 0
last_X = 0
last_Y = 0
for _ in range(N):
    T, X, Y = map(int, sys.stdin.readline().split())
    if not f(T-last_T, X-last_X, Y-last_Y):
        print('No')
        sys.exit()
    last_T, last_X, last_Y = T, X, Y
print('Yes')


Measured memory_bytes: 3064
S = list(input())
ans = 0
N = len(S)

L = [-1] *( len(S) + 1)

for i in range(N):
    if i==0 and S[i] == '<':
        L[i] = 0
    elif i==N-1 and S[i] == '>':
        L[i+1] = 0
    elif S[i-1] == '>' and S[i] == '<':
        L[i] = 0

i=0
tmp = 0
while (i<N):
    while (i<N and L[i] != 0): i+=1
    tmp = 0
    while (i<N and S[i] == '<'):
        tmp += 1
        L[i+1] = tmp
        i += 1
        

i=N
tmp = 0
while (i>0):
    while (i>0 and L[i] != 0): i-=1
    tmp = 0
    while (i>0 and S[i-1] == '>'):
        tmp += 1
        L[i-1] = max(L[i-1],tmp)
        i -= 1
    
print(sum(L))
        


Measured memory_bytes: 26948
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 2e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
	ll n;
	cin >> n;
	ll ans = 0;
	for(int i = 1; i <= n; i++)
	{
		ll x = n / i;
		if(n % i == 0)
			x--;
		ans += x;
	}
	cout << ans << '\n';

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


Measured memory_bytes: 3656
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  long long x[n];
  long long y[n];
  REP(i,n){
    cin >> x[i] >> y[i];
  }
  long long surface_min;
  bool min_set = false;
  REP(a,n){
    REP(b,n){
      REP(c,n){
        REP(d,n){
          int in_cnt = 0;
          REP(e,n){
            if(x[e]>=x[a]&&x[e]<=x[b]&&y[e]>=y[c]&&y[e]<=y[d]){
              in_cnt++;
            }
          }
          if(in_cnt>=k){
            long long surface = (x[b]-x[a])*(y[d]-y[c]);
            if(!min_set||surface<surface_min){
              surface_min = surface;
              min_set = true;
            }
          }
        }
      }
    }
  }
  cout << surface_min << endl;
}


Measured memory_bytes: 384
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <vector>
#include <stack>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;


const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}



bool com(vector<long>& lhs, vector<long>& rhs){
  int lsize = lhs.size();
  int rsize = rhs.size();
  if (lsize != rsize)//サイズが違うなら即返す
    return lsize < rsize;

  for (int i = 0; i < lsize; i++)//サイズが同じなら桁を見ていく
    if (lhs[i] != rhs[i])
      return lhs[i]  < rhs[i];
  return false;
}



int main()
{
  const int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  const string num[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

  ll n, m;
  long b[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  cin >> n >> m;
  vector<long> a(m);
  cin >> a;

  sort(a.begin(), a.end(), greater<long>());

  vector<long> dp(n + 100, 0);


  vector<vector<long>> ans(n+100,vector<long>());

  for (int i = 1; i <= n; ++i) {
    for (auto v : a) {
      if (i - b[v] < 0)continue;
      if (dp[i-b[v]] ==0 && i-b[v] !=0)continue;

      vector<long> tmp;
      tmp = ans[ i - b[v] ];
      tmp.push_back(v);

      if (com(ans[i],tmp)){
        ans[i] = tmp;
        dp[i] = tmp.size();
      }
    }
  }


  for (auto v:ans[n]){
    cout << v;
  }cout <<endl;

  return 0;
}


















Measured memory_bytes: 293720
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  int A1, A2, A3, A4;
  cin >> A1;
  cin >> A2;
  cin >> A3;
  cin >> A4;

  vector<int> A(10, 0);

  A[A1]++;
  A[A2]++;
  A[A3]++;
  A[A4]++;

  for(int i=0; i<10; ++i){
    if(i==1 || i==9 || i==7 || i==4){
      if(A[i] != 1){
        printf("NO\n");
        return 0;
      }
    }else{
      if(A[i] != 0){
        printf("NO\n");
        return 0;
      }
    }
  }

  printf("YES\n");

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;  
#define pb push_back
#define F first
#define S second
#define ppp pair<ll,pair<ll,ll>>
#define pp pair<ll,ll>
#define all(x) (x).begin(),(x).end()
#define pi 3.14159265358
#define MOD 998244353



int main()
{

  
    
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);

     
   	 

   	 ll n,i,j,k;

   	 cin>>n;

   	 vector<ll> v;
   	 for(i=2;i<=sqrt(n);i++)
   	 {	
   	 	ll occ=0;
   	 	while(n%i==0)
   	 	{
   	 		n=n/i;
   	 		occ++;
   	 	}
   	 	if(occ!=0)
   	 		v.pb(occ);
   	 }

   	 if(n!=1)
   	 	v.pb(1);

   	 ll ans=0;
   	 for(i=0;i<v.size();i++)
   	 {
   	 	ll sum=0;
   	 	for(j=1; ;j++)
   	 	{
   	 		if(sum+j>v[i])
   	 			break;
   	 		sum+=j;
   	 	}

   	 	ans+=j-1;
   	 	//cout<<v[i]<<" "<<j<<endl;
   	 }

   	 cout<<ans<<endl;



}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define tios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tmod 1000000007

#define tvi vector<int>
#define tvii vector<int,int>
#define tvpii vector<pair<int,int>>
#define tmii map<int,int>
#define tmiv map<int,vector<int>>
#define tmsi map<string,int>
#define tmci map<char,int>
#define tumi unordered_map<int,int>
#define tumsi unordered_map<string,int>
#define tumci unordered_map<char,int>
#define tpii pair<int,int>
#define tsi set<int>
#define tusi unordered_set<int>
#define tqi queue<int>
#define tdqi deque<int>
#define tpqi priority_queue<int>

#define tr(i,n) for(int i=0;i<n;i++)
#define tl(i,n) for(int i=n;i>=0;i--)
#define tcr(a,x) for(auto a=x.begin();a!=x.end();a++)
#define tcbe(x) x.begin(),x.end()


int32_t main(void) {
    tios
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,a*d,b*c,b*d});
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	string X, Y;
	cin >> X >> Y;

	if (X[0] < Y[0]) co("<");
	else if (X[0] > Y[0]) co(">");
	else  co("=");
	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main()
{
    ll n;
    cin>>n;
    vector<ll> v(n);
    ll sum=0;
    for(ll i=0;i<n;i++)
        cin>>v[i],sum+=v[i];
    
    ll x[n];
    ll sum2{};
    for(ll i=1;i<n;i+=2)
        sum2 += v[i];
    x[0] = sum - 2*sum2;
    for(ll i=0;i<n-1;i++)
    {
        x[i+1] = 2*v[i] - x[i];
    }
    for(ll i=0;i<n;i++)
        cout<<x[i]<<" ";
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define inf 0x3f3f3f3f
#define met(a, x) memset(a,x,sizeof(a))
#define mp make_pair;

using namespace std;
const int mod = 19e+7;
const int N = 3e4 + 10;
const int M = 1e5 + 10;

int a[M];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        a[x]++;
        a[y]++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]%2==1){
            cout<<"NO"<<endl;return 0;
        }
        
    }
    cout<<"YES"<<endl;
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> ans(100010, 0);
  for (int i = 0; i < n; i++) {
    ans[a[i]]++;
    ans[a[i] + 1]++;
    ans[a[i] + 2]++;
  }
  int mx = 0;
  for (int i = 0; i < 100010; i++) {
    if (mx < ans[i]) {
      mx = ans[i];
    }
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int main(){
    ll A,B,N;cin>>A>>B>>N;
    if(N<B){
        cout<<A*N/B-A*(N/B)<<endl;
    }else{
        cout<<A*(B-1)/B-A*((B-1)/B)<<endl;
    }
    return 0;
}


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

long long dp[3001][3001];// true, false がそれぞれ勝ち、負け

int main(){
  int N;
  int a[3000];
  std::cin>>N;
  for(int i=0;i<N;++i){
    std::cin>>a[i];
  }
  for(int i=0;i<N;++i){
    dp[i][i]=0;
  }
  for(int d=1;d<=N;++d){
    for(int i=0;i+d<=N;++i){
      int j=i+d;
      if((N-d)%2==0){
	//太郎くんの番。X-Yを最大化。
	dp[i][j]=std::max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1]);
      }else{
	dp[i][j]=std::min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1]);
      }
    }
  }
  printf("%ld\n",dp[0][N]);
  return 0;
}


Measured memory_bytes: 70016
n=int(input())
for i in range(1,3501):
  for j in range(1,3501):
    if 4*i*j-i*n-j*n!=0:
      k=(i*j*n)/(4*i*j-i*n-j*n)
      if k>0 and k.is_integer():
        print(i,j,int(k))
        exit(0)

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

#define INF ( 1<<29 )

typedef pair<int,int> P;

int H,W;
char fie[51][51];

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

int dx2[]={0,2,0,-1};
int dy2[]={-1,0,2,0};
int dx3[]={1,2,1,-1};
int dy3[]={-1,1,2,1};

int bmem[51][51];


struct state{
  int x,y,d,c;
  bool operator<(const state &a) const {
    return c > a.c;
  }
};

bool check(int x,int y,int kx,int ky){
  if( x < 0 || y < 0 || x >= W || y >= H ) return false;
  if( kx <= x && x <= kx + 1 && ky <= y && y <= ky + 1 ) return false; 
  if( fie[x][y] == '*' ) return false;
  if( bmem[x][y] > -1 ) return false;
  return true;
}

int bfs(int sx,int sy,int tx,int ty,int kx,int ky){
  memset(bmem,-1,sizeof(bmem));
  queue<P> q;
  q.push( P(sx,sy) );
  bmem[sx][sy] = 0;
  while( !q.empty() ){
    P p = q.front(); q.pop();
    int x = p.first, y = p.second;
    if( x == tx && y == ty ) return bmem[x][y];
    for(int i=0;i<4;i++){
      int nx = x + dx[i], ny = y + dy[i];
      if( check( nx, ny, kx, ky ) ) {
	q.push( P(nx,ny) );
	bmem[nx][ny] = bmem[x][y] + 1;
      }
    }
  }
  return INF;   
}

int dmem[51][51][5];

int solve(int x1,int y1,int x2,int y2,int kx,int ky){
  priority_queue<state> q;
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      for(int k=0;k<4;k++) dmem[j][i][k] = INF;

  for(int i=0;i<4;i++){
    int px1 = kx + dx2[i], py1 = ky + dy2[i];
    int px2 = kx + dx3[i], py2 = ky + dy3[i];
    
    int sca1 = bfs(x1,y1,px1,py1,kx,ky);
    int sca2 = bfs(x1,y1,px2,py2,kx,ky);
    int scb1 = bfs(x2,y2,px1,py1,kx,ky);
    int scb2 = bfs(x2,y2,px2,py2,kx,ky);

    int sc =  min( sca1 + scb2, sca2 + scb1 );
    if( sc >= INF ) continue;
    dmem[kx][ky][i] = sc;
    q.push( (state){kx,ky,i,sc} );
  }

  while( !q.empty() ){
    state p = q.top(); q.pop();
    kx = p.x, ky = p.y;
    int d = p.d, c = p.c;
    
    x1 = kx + dx2[d], y1 = ky + dy2[d];
    x2 = kx + dx3[d], y2 = ky + dy3[d];
    if( c > dmem[kx][ky][d] ) continue;
    if( kx == 0 && ky == 0 ) return c;
    for(int i=0;i<4;i++){
      int nx = kx + dx[i], ny = ky + dy[i];
      int px1 = kx + dx2[i], py1 = ky + dy2[i];
      int px2 = kx + dx3[i], py2 = ky + dy3[i];
      
      int sca1 = bfs(x1,y1,px1,py1,kx,ky);
      int sca2 = bfs(x1,y1,px2,py2,kx,ky);
      int scb1 = bfs(x2,y2,px1,py1,kx,ky);
      int scb2 = bfs(x2,y2,px2,py2,kx,ky);

      int sc =  min( sca1 + scb2, sca2 + scb1 ) + 1;      
      if( sc >= INF ) continue;
      int nd = (i+2)%4;
      if( sc + c < dmem[nx][ny][nd] ){
	q.push( (state){nx,ny,nd,sc+c} );
	dmem[nx][ny][nd] = sc + c;
      }      
    }
  }
  return -1;
}


int main(){
  while( cin >> H >> W && (H||W) ){
    int x1, y1,x2,y2, kx, ky;
    bool f1 = false,f2 = false;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> fie[j][i];
	if( fie[j][i] == '.' ){
	  if( !f1 ){
	    x1 = j; y1 = i;  f1 = true;
	  } else {
	    x2 = j; y2 = i;
	  }
	} else if ( fie[j][i] == 'X' && !f2) {
	  kx = j; ky = i; f2 = true;
	}
      }
    }

    if( kx == 0 && ky == 0 ) cout << 0 << endl;
    else cout << solve(x1,y1,x2,y2,kx,ky) << endl;;
    
  }
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <utility>
#include <queue>

constexpr int INF = 1000000000;
using Pair = std::pair<int, int>;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

int h, w, n;
std::string map[1010];
int cost[1010][1010];
Pair pts[10];

int bfs(Pair st, Pair en) {
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cost[i][j] = INF;
        }
    }
    cost[st.first][st.second] = 0;

    std::queue<Pair> que;
    que.push(st);

    while(!que.empty()) {
        auto p = que.front(); que.pop();

        for(int i = 0; i < 4; ++i) {
            int py = p.first + dy[i], px = p.second + dx[i];

            if(py < 0 || px < 0 || py >= h || px >= w)
                continue;

            if(map[py][px] == '.' && cost[py][px] == INF) {
                que.push({py, px});
                cost[py][px] = cost[p.first][p.second] + 1;
            }
        }
    }

    return cost[en.first][en.second];
}

int main() {
    std::cin >> h >> w >> n;

    for(int i = 0; i < h; ++i) {
        std::cin >> map[i];

        for(int j = 0; j < w; ++j) {
            if(map[i][j] != '.' && map[i][j] != 'X') {
                int idx = (map[i][j] == 'S' ? 0 : map[i][j] - '0');

                pts[idx] = {i, j};
                map[i][j] = '.';
            }
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        ans += bfs(pts[i - 1], pts[i]);
    }

    std::cout << ans << std::endl;
}

Measured memory_bytes: 8020
fun main() {
    val (N, K) = readLine()!!.split(" ").map { it.toInt() }
    val A = readLine()!!.split(" ").map { it.toLong()}

    for (i in 0 until N - K) {
        if (A[i] < A[K+i]) {
            println("Yes")
        } else {
            println("No")
        }
    }
}


Measured memory_bytes: 70480
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

import java.io.PrintWriter;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        final int N = fs.nextInt();

        int[] A = new int[N + 2];

        int sum = 0;

        for (int i = 1; i <= N; i++) {
            A[i] = fs.nextInt();
            sum += Math.abs(A[i] - A[i - 1]);
        }

        sum += Math.abs(A[N + 1] - A[N]);

        for (int i = 1; i <= N; i++) {
            int ans =
                sum
                - Math.abs(A[i] - A[i - 1])
                - Math.abs(A[i + 1] - A[i])
                + Math.abs(A[i + 1] - A[i - 1]);

            out.println(ans);
        }

        out.flush();
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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


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

    cout<<(48-m)<<endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
restaurants = []

for i in range(N):
    idx = i + 1
    S, P = input().split()
    tuple = ( (idx, str(S), int(P)) )

    restaurants.append(tuple)

restaurants = sorted(restaurants, key=lambda x:x[2], reverse = True)  
restaurants = sorted(restaurants, key=lambda x:x[1])

for i in range(N):
    print (restaurants[i][0])



Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    long h;
    long w;
    cin >> h >> w;
    if (h == 1 || w == 1){
        cout << 1 << endl;
    }
    else if (h != 1 && w != 1 && h%2 == 1 && w%2 == 1){
        cout << (h*w)/2 + 1 << endl;
    }
    else {
        cout << (h*w)/2 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long x,y,v,w,d;
	cin>>x>>v>>y>>w>>d;
	long long dis=abs(x-y);
	if(dis<=(v-w)*d){
		cout<<"YES\n";
	}
	else{
		cout<<"NO\n";
	}
	return 0;
}

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

int main(){
    int n,l;
    cin >> n >>l;
    string s[100];
    for(int i=0;i<n;i++)
        cin >>s[i];
    sort(s,s+n);
    for(int i=0;i<n;i++)
    cout << s[i];
    cout << endl;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

even = v[0::2]
odd = v[1::2]
count_even = Counter(even).most_common()
count_odd = Counter(odd).most_common()

if count_even[0][0] == count_odd[0][0]:
    a = 0 if len(count_odd) == 1 else count_odd[1][1]
    b = 0 if len(count_even) == 1 else count_even[1][1]
    print(n - max(count_even[0][1] + a, count_odd[0][1] + b))
else:
    print(n - count_even[0][1] - count_odd[0][1])



Measured memory_bytes: 21084
#include<stdio.h>
#include<string.h>

int main(){
	int team[301][4],U[1001],n,i,j,sen,k,a,deru[27];
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		memset(team,0,sizeof(team));
		
		for(i=0;i<n;i++){
			for(j=0;j<4;j++)
			scanf("%d",&team[i][j]);
		}

		for(i=0;i<n-1;i++){
			for(j=0;j<n-1;j++){
				if(team[j][0]>team[j+1][0]){
					for(k=0;k<4;k++){
						a=team[j+1][k];
						team[j+1][k]=team[j][k];
						team[j][k]=a;
					}
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=0;j<n-1;j++){
				if(team[j][3]>team[j+1][3]){
					for(k=0;k<4;k++){
						a=team[j+1][k];
						team[j+1][k]=team[j][k];
						team[j][k]=a;
					}
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=0;j<n-1;j++){
				if(team[j][2]<team[j+1][2]){
					for(k=0;k<4;k++){
						a=team[j+1][k];
						team[j+1][k]=team[j][k];
						team[j][k]=a;
					}
				}
			}
		}
		memset(U,0,sizeof(U));
		memset(deru,0,sizeof(deru));
		sen=1;
		deru[0]=team[0][0];
		i=1;
		U[team[0][1]]=1;
		while(0!=team[i][0]){
			if(sen<10 && U[team[i][1]]<3){
				++U[team[i][1]];
				deru[sen]=team[i][0];
				++sen;
				++i;
				continue;
			}
			
			if(sen<20 && U[team[i][1]]<2){
				++U[team[i][1]];
				deru[sen]=team[i][0];
				++sen;
				++i;
				continue;
			}
			
			if(sen<26 && U[team[i][1]]==0){
				++U[team[i][1]];
				deru[sen]=team[i][0];
				++sen;
				++i;
				continue;
			}
			++i;
			if(i>=n)break;
		}
		i=0;
		while(deru[i]!=0){
			printf("%d\n",deru[i]);
			++i;
		}
	}
	return 0;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
P, S = list(), list()
for _ in range(M):
    p, s = input().split()
    P.append(int(p))
    S.append(s)

AC_flags = [[0, 0] for _ in range(N)]

for p, s in zip(P, S):
    if AC_flags[p - 1][0] == 0 and s == "WA":
        AC_flags[p - 1][1] += 1
    elif AC_flags[p - 1][0] == 0 and s == "AC":
        AC_flags[p - 1][0] += 1

sum_ac, sum_wa = 0, 0
for ac, wa in AC_flags:
    if ac == 1:
        sum_ac += ac
        sum_wa += wa
    else:
        pass

print(sum_ac, sum_wa)


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

using namespace std;
using ll = long long;
int n;
ll monster = 0;
std::vector<ll> a, b;
int main() {
    cin >> n;
    a.assign(n+1, 0);
    b.assign(n, 0);
    for (int i = 0; i < n+1; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        std::cin >> b[i];
    }
    for (int k = 0; k < n; k++) {
        if (a[k] > b[k]) {
            a[k] -= b[k];
            monster += b[k];
            b[k] = 0;
        }
        else if (a[k] <= b[k]) {
            monster += a[k];
            b[k] = b[k] - a[k];
            a[k] = 0;
        }
        if (a[k+1] > b[k]) {
            a[k+1] -= b[k];
            monster += b[k];
            b[k] = 0;
        }
        else if (a[k+1] <= b[k]) {
            monster += a[k+1];
            b[k] = b[k] - a[k+1];
            a[k+1] = 0;
        }        
    }
    cout << monster << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long double dist(int xi,int xj,int yi,int yj){
    return sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj));
}
int main(void){
    int N;
    long double sum=0.0;
    cin >> N;
    int X[N],Y[N];
    for(int i=0;i<N;i++){
        cin >> X[i] >> Y[i];
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            sum+=dist(X[i],X[j],Y[i],Y[j]);
        }
    }
    printf("%.10Lf",(long double)sum*2/N);
    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef double ll;

int main(){
    int N;
    ll value, ans = 0;
    cin >>N;
    vector<ll> v(0);
    while(N){
        cin >> value;
        v.push_back(value);
        --N;
    }
    sort(v.begin(), v.end());
    ans += (v[0] + v[1])/2;
    for(int i = 2; i< v.size(); ++i){
        ans += v[i];
        ans /=2;
    }
    cout << ans;
 }




Measured memory_bytes: 256
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define debug(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}


#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  ll H, W;

  cin >> H >> W;
  vector<vector<int>> s;
  s.resize(H + 2);
  rep(i, H + 2){
    s[i].resize(W + 2);
  }
  // rep(x, H + 2){
  //   s[x][0] = 0;
  //   s[x][W + 1] = 0;
  // }
  // rep(y, W + 2){
  //   s[0][y] = 0;
  //   s[H + 1][y] = 0;
  // }

  rep1(y, W + 1){
    rep1(x, H + 1){
      char c;
      cin >> c;
      // cout << c << endl;
      if(c == '#'){
        s[x][y] = 1;
      }else{
        s[x][y] = 0;
      }
    }
  }
  // cout << s;
  bool res = true;
  // debug(W);
  // debug(H);
  rep1(y, W + 1){
    rep1(x, H + 1){
      // cout << x << " " << y << endl;

      bool a = false;
      if(s[x][y]){
        if(s[x - 1][y] == 1){
          a = true;
        }
        if(s[x][y - 1] == 1){
          a = true;
        }
        if(s[x + 1][y] == 1){
          a = true;
        }
        if(s[x][y + 1] == 1){
          a = true;
        }
        // if(a){
        //   cout << x << " " << y << endl;
        // }
        res = res && a;
      }
    }
  }
  
  if(res){
    cout << "Yes";
  }else{
    cout << "No";
  }
}
#endif




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

using namespace std;

int a, b, c, d, p;
int ans, sum;

int main() {

	cin >> a >> b >> c >> d >> p;
	sum = a * p;

	if (c - p >= 0) sum <= b ? printf("%d\n", sum) : printf("%d\n", b);
	else {

		int x;
		x = p - c;
		x = d * x;

		sum <= x ? printf("%d\n", sum) : printf("%d\n", x+b);

	}

	return 0;

}


Measured memory_bytes: 3192
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 10**10

for i in range(M):
	x,y,c = list(map(int,input().split()))
	ans = min(ans,a[x-1]+b[y-1]-c)

ans = min(ans,min(a)+min(b))
print(ans)

Measured memory_bytes: 66540
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 A PICTURE 999.
       01 B PICTURE 999.
       01 X PICTURE 999.
       01 INp PICTURE X(21).
       01 temp picture 9999.
       01 S PICTURE 999.
       01 N PIC 999.
       01 tempb picture 9999.
       PROCEDURE DIVISION.
       MAIN.
       ACCEPT INp.
       PERFORM VARYING S FROM 1 BY 1 UNTIL INp(S:1)= SPACE
       END-PERFORM.
       move S TO temp.
       add -1 to temp.
       MOVE INp(1:temp) TO A.
       add 2 to temp
       PERFORM VARYING N FROM temp BY 1 UNTIL INp(N:1)= SPACE
       END-PERFORM.
       move N TO tempb.
       subtract S FROM tempb.
       MOVE INp(temp:tempb) TO B.
       MOVE N TO temp.
       add 1 to temp.
       PERFORM VARYING S FROM temp BY 1 UNTIL INp(S:1)= SPACE
       END-pERFORM.
       move S TO tempb.
       subtract N FROM tempb.
       MOVE INp(temp:tempb) TO X.
      	IF X >= A AND X<=A+B THEN
      		DISPLAY "YES"
      	ELSE
      		DISPLAY "NO"
      	END-IF.
      	STOP RUN.

Measured memory_bytes: 764
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll
void solve() {
		string s;
		cin >> s;
		string sup[10] = { "1111",".,!? ","abc" , "def","ghi","jkl","mno","pqrs","tuv","wxyz" };
		int now = -1;
		int target = -1;
		REP(q, s.length()) {
			if (s[q] == '0') {
				if (target != -1) {
					cout << sup[target][now % sup[target].length()];
				}
				target = -1;
				now = -1;
			}
			else {
				now++;
				target = s[q] - '0';
			}
		}
		cout << endl;
}
#undef int

int main() {
	init();
	int test;
	cin >> test;
	REP(te,test)
	solve();
}


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

int main(void) {
    int n;
    cin >> n;
    int p[10],q[10],a[10];
    for(int i=0; i<n; i++) cin >> p[i];
    for(int i=0; i<n; i++) cin >> q[i];
    
    for(int i=0; i<n; i++) a[i] = p[i];
    int ans=0;
    do {
        bool flag = true;
        for (int i=0; i<n; i++) {
            if(a[i] != q[i]) flag=false;
            }
        if (flag){
            cout << ans << endl;
            return 0;
        }
        ans++;
    } while(next_permutation(a, a + n));

    swap(p,q);
    for(int i=0; i<n; i++) a[i] = p[i];
    ans=0;
    do {
        bool flag = true;
        for (int i=0; i<n; i++) {
            if(a[i] != q[i]) flag=false;
            }
        if (flag){
            cout << ans << endl;
            return 0;
        }
        ans++;
    } while(next_permutation(a, a + n));
}

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;
ll mod = 1e9+7;

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> l(n), r(n);
    rep(i,n-1) l[i+1] = gcd(l[i],a[i]);
    for(int i = n-1; i>= 1; i--) r[i-1] = gcd(r[i], a[i]);
    int ans = 1;
    rep(i,n) ans = max(ans, gcd(l[i],r[i]));
    cout << ans << endl;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll n;
    cin >> n;
    vector<pair<string, ll>> S(n);
    REP(i, n){
    	cin >> S[i].first >> S[i].second;
    }
    string t;
    cin >> t;

    bool ok = false;
    ll res = 0;
    REP(i, n){
    	if(ok) res += S[i].second;
    	if(S[i].first == t) ok = true;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define min(a,b) a<b ? a:b
// #define max(a, b) a < b ? b : a
#define IOS                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)

#define pb push_back
#define pi 3.14159265358979323846

// int explore(vector<vector<int>> &adj,int x,int y,vector<int> &visited)
// {
//     if(x==y)
//     return 1;
//     visited[x]=1;
//     for(int i=0;i<adj[x].size();i++)
//     {
//         if(!visited[adj[x][i]])
//         {
//             if(explore(adj,adj[x][i],y,visited))
//             return 1;
//         }
//     }
//     return 0;
// }
bool valley(int p[], int k)
{
    if (p[k] < p[k - 1] && p[k] < p[k + 1])
        return true;
    return false;
}
bool peak(int p[], int k)
{
    if (p[k] > p[k - 1] && p[k] > p[k + 1])
        return true;
    return false;
}
int gcd(int a,int b)
{
    return b? gcd(b,a%b):a;
}
int pow(int x,int p)
{
    int ctr=1;
    for(int i=0;i<p;i++)
    {
        ctr*=x;
    }
    return ctr;
}
int32_t main()
{
    IOS;
    // int t;
    // cin >> t;
    // while (t--)
    // {
        int n;
        cin>>n;
        int d1[n],d2[n];
        for(int i=0;i<n;i++)
        {
            cin>>d1[i]>>d2[i];
        }
        for(int i=0;i<n-2;i++)
        {
            if(d1[i]==d2[i] && d1[i+1]==d2[i+1] && d1[i+2]==d2[i+2])
            {
                cout<<"Yes";
                return 0;
            }
        }
        cout<<"No";
    // }
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
 
int n,a[1000009];
bool check(){
	int i,ans=0,tmp=0;
	for (i=1; i<=n; i++) ans=max(ans,a[i]);
	for (i=1; i<=n; i++) if (ans>a[i]+1) return 0;
	for (i=1; i<=n; i++) if (ans>a[i]) tmp++;
	int x,y;
	if (tmp==n) return ans==n; else{
		if (!tmp && ans==n-1) return 1;
		x=1; y=(n-tmp)/2;
		if (x+tmp<=ans && ans<=y+tmp) return 1; else return 0;
	}
}
int main(){
	scanf("%d",&n);
	int i;
	for (i=1; i<=n; i++) scanf("%d",&a[i]);
	puts(check()?"Yes":"No");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

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

  vector<int> x;

  while(n!=0){
    if(n%2!=0){
      x.push_back(1);
      n--;
    }else{x.push_back(0);}
    n/=-2;
    
  }

  reverse(x.begin(),x.end());
  r(i,x.size())cout<<x.at(i);
  cout<<endl;
  if(x.size()==0)cout<<0<<endl;;






  return 0;
}


Measured memory_bytes: 256
import itertools

lists = range(1, int(input()) + 1)
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

a = 0
b = 0
i = 0
for v in itertools.permutations(lists):
    if v == P:
        a = i
    if v == Q:
        b = i
    if a != 0 and b != 0:
        break
    i += 1

print(abs(b - a))

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

int main(){
	string s;
	cin>>s;
	int ret = 0;
	for(int i=0; s[i]; i++){
		ret+=(int)(s[i]-'0');
	}
	if(ret%9==0) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3720
#include<queue>
#include<cstdio>

#define	mp	make_pair

using namespace std;

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

struct Ant{
	int hp,x,y;
	Ant(int H,int Y,int X):hp(H),x(X),y(Y){}
	bool operator<(const Ant &a)const{return true;}
};

int main(){
	for(int w,h;scanf("%d%d",&w,&h),w;){
		int grid[8][8],sx,sy;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			scanf("%d",grid[i]+j);
			if(grid[i][j]==2)	sy=i,sx=j,grid[i][j]=1;
		}

		int tmin[8][8][7],ans=-1;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)for(int h=0;h<7;h++)	tmin[i][j][h]=1<<30;
		priority_queue< pair<int,Ant> > pq;	pq.push(mp(0,Ant(6,sy,sx)));
		while(!pq.empty()){
			pair<int,Ant> a=pq.top();	pq.pop();
			int t=-a.first,hp=a.second.hp,x=a.second.x,y=a.second.y;
			if(hp==0)	continue;
			if(grid[y][x]==3){ ans=t; break; }
			if(tmin[y][x][hp]<t)	continue;
			if(grid[y][x]==4)	hp=6;

			for(int i=0;i<4;i++){
				int xx=x+dx[i],yy=y+dy[i];
				if(0<=xx && xx<w && 0<=yy && yy<h && grid[yy][xx]!=0){
					if(t+1<tmin[yy][xx][hp-1]){
						pq.push(mp(-(t+1),Ant(hp-1,yy,xx)));
						tmin[yy][xx][hp-1]=t+1;
					}
				}
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 0
// 解き直し.
// ABC 131解説.
// https://img.atcoder.jp/abc131/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
const int MAX_V = 1e5 + 1;
// const int MAX_V = 8;
using LL = long long;
int cX[MAX_V], cY[MAX_V];   // 各頂点X, Y ごとに, 連結成分番号を保存.
LL cVX[MAX_V], cVY[MAX_V]; // 各連結成分 の X, Y の 頂点数を保存.
vector<int> X[MAX_V], Y[MAX_V];

// 深さ優先探索(depth-first search).
// https://ja.wikipedia.org/wiki/深さ優先探索
// @param x: 探索開始の頂点X番号.
// @param l: 連結成分番号(※1以上).
// @return : 特に無し.
void dfs(int x, int l){

    // 1. 終了条件設定.
    // -> 連結成分番号が設定済みであれば, 終了.
    if(cX[x] > 0) return;
    
    // 2. 頂点 X について, 連結成分情報 を 設定.
    cX[x] = l, cVX[l]++;
    
    // 3. 頂点 X に, 隣接する 頂点 Y を 探索.
    for(auto &y : X[x]){
        
        if(cY[y] > 0) continue;
        // 3-1. 頂点 Y に, 連結成分 l を設定し, 連結成分のカウンターを +1 更新.
        cY[y] = l, cVY[l]++;
        
        // 3-2. 頂点 Y に, 隣接する 頂点 X を 探索(再帰処理).
        for(auto &nx : Y[y]){
            if(cX[nx] > 0) continue;
            dfs(nx, l);
        }
    }
}

int main() {

    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);

    // 以下, 解説通り.
    // 2. グラフ作成.
    for(int i = 0; i < N; i++){
        int u, v;
        scanf("%d %d", &u, &v);
        // u -> v
        X[u].push_back(v);
        // v -> u
        Y[v].push_back(u);
    }
    
    // グラフ情報確認.
    // for(int i = 1; i < MAX_V; i++){
    //     if(X[i].size() > 0) for(auto &p : X[i]) printf("%d %d\n", i, p);
    // }
    
    // 3. 連結成分に分解.
    int c = 0;
    for(int i = 1; i < MAX_V; i++) if(X[i].size() > 0 && cX[i] == 0) c++, dfs(i, c);
    
    // グラフ連結情報確認.
    // for(int i = 1; i < MAX_V; i++){
    //     printf("cX[%d], cY[%d] = [%d, %d]\n", i, i, cX[i], cY[i]);
    //     printf("cVX[%d], cVY[%d] = [%lld, %lld]\n", i, i, cVX[i], cVY[i]);
    // }
    
    // 5. 後処理.
    LL ans = 0;
    for(int i = 1; i < MAX_V; i++) ans += cVX[i] * cVY[i];
    // 連結済 の 辺数 を 減算.
    ans -= N;
    printf("%lld\n", ans);
    return 0;

}

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v.at(i);
    }
    
    int index = 1;
    for (int i = 0; i < n; i++)
    {
        int x = v[index - 1];
        if (x == 2)
        {
            cout << i + 1 << "\n";
            return 0;
        }
        index = x;
    }
    cout << -1 << "\n";
}

Measured memory_bytes: 640
#b（直し）
class TrieNode:
    def __init__(self):
        self.parent = None
        self.children = {}
    def new_child(self, key):
        self.children[key] = TrieNode()
        self.children[key].parent = self
        self.children[key].label = key
        return self.children[key]

import sys
def input(): return sys.stdin.readline().strip()

n = int(input())
s = [input() for _ in range(n)]
ans = -n # (Si, Si)
trie = TrieNode()
ends = set()

#build the trie
for si in s:
    cursor = trie
    for char in reversed(si):
        if char in cursor.children:
            cursor = cursor.children[char]
        else:
            cursor = cursor.new_child(char)
    else:
        ends.add(cursor)

#climb up the trie
for cursor in ends:
    head = set()
    while cursor.parent is not None:
        head.add(cursor.label)
        cursor = cursor.parent
        for char in cursor.children:
            if cursor.children[char] in ends and char in head:
                ans += 1
print(ans)

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(A*B, C*D) << endl;
}

Measured memory_bytes: 256
var a,b,c,ans:int64;
begin
read(a,b,c);
if b>=c then
	ans := c+b
else
	begin
    	ans := b*2;
        dec(c,b);
        if a>=c then
        	inc(ans,c)
        else
        	begin
        		inc(ans,a+1);
            end;
    end;
write(ans);
end.

Measured memory_bytes: 128