akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	while(1){
		int N;
		cin>>N;
		if(N==0) break;
		vector<int> x;
		vector<int> y;
		x.push_back(0);
		y.push_back(0);
		for(int i=1;i<=N-1;i++){
			int n,d;
			cin>>n>>d;
			switch(d){
			case 0:
				x.push_back(x[n]-1);
				y.push_back(y[n]);
				break;
			case 1:
				x.push_back(x[n]);
				y.push_back(y[n]-1);
				break;
			case 2:
				x.push_back(x[n]+1);
				y.push_back(y[n]);
				break;
			case 3:
				x.push_back(x[n]);
				y.push_back(y[n]+1);
				break;
			}
		}
		sort(x.begin(),x.end());
		sort(y.begin(),y.end());
		cout<<x[x.size()-1]-x[0]+1<<" "<<y[y.size()-1]-y[0]+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
def main():
	N, A = map(int, input().split())
	x = list(map(int, input().split()))
	X = A
	for xi in x:
		X = max(X, xi)
	y = [xi-A for xi in x]
	dp = [[0 for _ in range(2*N*X+1)] for _ in range(N+1)]
	dp[0][N*X] = 1
	for j in range(1, N+1):
		for t in range(2*N*X):
			if t - y[j-1] < 0 or t - y[j-1] > 2*N*X:
				dp[j][t] = dp[j-1][t]
			else:
				dp[j][t] = dp[j-1][t] + dp[j-1][t-y[j-1]]
	print(dp[N][N*X]-1)


if __name__ == '__main__':
	main()

Measured memory_bytes: 5740
#!/usr/bin/env python3
import sys
INF = float("inf")


def f(n):
    if n & 1:
        return 3*n+1
    else:
        return n//2


def solve(s: int):
    a = [s]
    for i in range(10**7):
        s = f(s)
        # print(s)
        for av in a:
            if av == s:
                print(i+2)
                return
        a.append(s)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  # type: int
    solve(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s;
    cin >> s;
    VI cnt(2);
    for (char c : s) cnt[c - '0']++;
    cout << min(cnt[0], cnt[1]) * 2 << endl;

    return 0;
}


Measured memory_bytes: 512
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100055
#define M 200005
#define LL long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mi d + 1, r
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MP make_pair
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
int n, vis[N], a[N];
LL fac[N], inv[N], facinv[N];
void init(){
    fac[0] = fac[1] = inv[0] = inv[1] = facinv[0] = facinv[1] =  1;
    for(int i = 2; i <= 100005; ++i){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
        facinv[i] = facinv[i - 1] * inv[i] % MOD;
    }
}
LL C(LL n, LL m){
    if(n < 0 || m < 0 || m > n)return 0;
    return fac[n] * facinv[m] % MOD * facinv[n-m] % MOD;
}
int l, r;
int main(){
  //  IN;
    SC(n);
    init();
    FF(i, 1, n + 1){
        II(a[i]);
        if(vis[a[i]] > 0){
            l = vis[a[i]];
            r = i;
            break;
        }
        vis[a[i]] = i;
    }
    l = l - 1;
    r = n + 1 - r;
    FF(i, 1, n){
        if(i == 1){
            printf("%d\n", n);
            continue;
        }
        LL s = C(n + 1, i);
        LL s1 = C(l + r, i - 1);
        s -= s1;
        if(s < 0) s += MOD;
        printf("%lld\n", s);
    }
    puts("1");
    return 0;
}


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

int d[100], a[100];
map<vector<int>, int>id;
map<int, vector<int>>re;
int dp[100][5040];

int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &d[i]);
	rep(i, n)scanf("%d", &a[i]);
	vector<int>v(7); iota(v.begin(), v.end(), 0);
	int p = 0;
	do {
		id[v] = p; re[p] = v;
		int cnt = 0, t = 0;
		for (int i : v) {
			rep(j, 7) {
				if ((t >> j & 1) && abs(j - i) <= d[j])cnt += a[j];
			}
			t |= 1 << i;
		}
		dp[0][p] = cnt;
		p++;
	} while (next_permutation(v.begin(), v.end()));
	int ans = 0;
	for (int i = 1; i + 6 < n; i++)rep(j, 5040) {
		vector<int>v = re[j];
		rep(k, 8) {
			vector<int>t = v;
			t.insert(t.begin() + k, 7);
			int cnt = 0, p = 0;
			for (int u : t){
				if (u == 7) {
					rep(y, 8) {
						if ((p >> y & 1) && y + d[i - 1 + y] >= 7)
							cnt += a[i - 1 + y];
					}
				}
				if ((p >> 7 & 1) && 7 - d[i + 6] <= u)cnt += a[i + 6];
				p |= 1 << u;
				vector<int>q;
				for (int c : t) {
					if (c)q.push_back(c - 1);
				}
				int v = id[q];
				dp[i][v] = max(dp[i][v], dp[i - 1][j] + cnt);
				ans = max(ans, dp[i][v]);
			}
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 6368
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(N);

    for (int i=0; i<N; i++) {
        cin >> A[i];
    }

    int idx = 0;
    vector<int> cities; 
    vector<int> visits(N,-1); 
    while (true) {
        cities.push_back(idx);
        visits[idx] = cities.size()-1;
        idx = A[idx] -1;
        if (visits[idx] != -1) {
            int t = visits[idx] + (K-visits[idx])%(cities.size() - visits[idx]);
            
            cout << cities[t]+1 << endl;
            break;
        }
        if (cities.size() == K + 1) {
            cout << cities.back()+1<< endl;
            break;
        }
    }

    
    return 0;
}

Measured memory_bytes: 5772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll n, w, weight, value, bd[101][100001], ans;
 
int main() {
	cin >> n >> w;
    cin >> weight >> value;
    for (int i=0; i<=100001; i++) {
    	if (i==value) 
            bd[0][i] = weight;
        else bd[0][i] = 2e9;
    }
    
    for (int i=1; i<n; i++) {
    	cin >> weight >> value;
        for (int j=0; j<100001; j++) {
            bd[i][j] = bd[i-1][j];    
        }
        bd[i][value] = min(bd[i][value], weight);
        for (int j=0; j<100001-value; j++) {
            bd[i][j+value] = min(bd[i][j+value], bd[i-1][j]+weight);
        }
    }
    for (int i=0; i<100001; i++) {
        if (bd[n-1][i]<=w) {
            ans = i;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 78336
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<stdint.h>
#include<limits.h>

#include<sstream>
using namespace std;

 
int main() {
	int n,x,y,nr=0,nrmax=0;
	cin >> n;
	cin >> x;
	for (int i = 1;i < n;i++)
	{
		cin >> y;
		if (y <= x)
			nr++;
		else {
			if (nr > nrmax)
				
			nrmax = nr;
			nr = 0;
		}
		x = y;
	}
	if (nr > nrmax)
		nrmax = nr;
	cout << nrmax;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;


int main(){
  int N;
  cin>>N;
  int A[N];
  REP(i,N) cin>>A[i];
  bool CAN=true;
  
  REP(i,N){
    if(A[i]%2==0){
      if(A[i]%3!=0 && A[i]%5!=0){
        CAN=false;
      }
    }
  }
  
  if(CAN) cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int s[3]={a,b,c};
    int i;
    int j;
    int t;
    for (j=0;j<2;j++)
    {
        for (i=0;i<2-j;i++)
        {
            if (s[i]>s[i+1])
            {
                t=s[i];
                s[i]=s[i+1];
                s[i+1]=t;
            }
        }
    }
    a=s[0];
    b=s[1];
    c=s[2];
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2056
//encoding:utf-8
//#include <iostream> //c++
//#include<stack> //スタックに関して　最新のデータから捨てる
//#include<queue> //キューに関して　最古のデータから捨てる
//#include<math.h>
//#include<vector>
//#include<algorithm> //sort とかにいる
#include<bits/stdc++.h>//vector,algorithm,que
#include<time.h> //時間にかんして

#define ll long long
#define MOD 1000000007
using namespace std;
int main(){
  int R,G;
  cin>>R>>G;
  int ans;
  ans = (G-R)+G;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main(){
    ll N, K, ans = 0;
    cin >> N >> K;
    VL H(N);
    FOR(i, 0, N) cin >> H[i];

    sort(ALL(H), greater<ll>());
    for (int i = 0; (i < K) && (i < N); i++){
        H[i] = 0;
    }

    for (int i = 0; i < N; i++){
        ans += H[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N;
  cin >> N;
  vll A(N);

  ll oddCount = 0;
  ll count = 0;
  ll sum = 0;
  ll mini = INF;
  rep(i, N) {
    ll a;
    cin >> a;
    A[i] = a;
    sum += abs(a);

    if (mini > abs(a)) {
      mini = abs(a);
    }

    if (a < 0) {
      count++;
    } else {
      if (count % 2 == 1) {
        oddCount++;
      }
      count = 0;
    }
  }

  if (count % 2 == 1) {
    oddCount++;
  }

  // debug(sum);
  // debug(mini);
  // debug(oddCount);

  if (oddCount % 2 == 1) {
    COUT(sum - 2 * mini);
  } else {
    COUT(sum);
  }

  return 0;
}

Measured memory_bytes: 1024
N= int(input())
p_list = [i for i in map(int,input().split())]
f = 0
for i in range(N):
  #print(i+1,p_list[i])
  if i+1 != p_list[i]:
    f += 1
if f==0 or f==2:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int dp[100001],n,w,weight,value,i,j;
int main(){
	cin>>n>>w;
	for(auto &x:dp)x=1000000001;
	dp[0]=0;
	for(;i<n;i++){
		cin>>weight>>value;
		for(j=100000;j>=value;j--)dp[j]=min(dp[j],dp[j-value]+weight);
	}
	for(i=100000;i;i--)if(dp[i]<=w){cout<<i<<endl;return 0;}
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int,input().split()))
A = sorted(A, reverse = True)
ans = A[0]
A.remove(A[0])
B = []
for i in range(len(A)):
    B.append(A[i])
    B.append(A[i])

for i in range (N-2):
    ans += B[i]

print(ans)

Measured memory_bytes: 31536
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <iomanip>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

struct edge { int from, to, cost; };

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(int, V); invar(int, E); invar(int, r);
  
  vector<edge> edges(E);
  
  rep(i, E) {
    int s, t, d; 
    cin >> s >> t >> d;
    edges[i] = {from:s, to:t, cost:d};
  }
  
  vector<int> dist(V, INF);
  dist[r] = 0;
  
  for(int i=0; i<V; ++i) {
    bool updated = false;
    for(int j=0; j<E; ++j) {
      edge e = edges[j];
      if(dist[e.from] != INF) {
        if(dist[e.from] + e.cost < dist[e.to]) {
          updated = true;
          dist[e.to] = dist[e.from] + e.cost;
        }
      }
    }
    
    if(!updated) break;
    
    if(i == V-1 && updated) {
      fin("NEGATIVE CYCLE");
      return 0;
    }
  }
  
  rep(i, V) {
    if(dist[i] == INF) {
      fin("INF");
    } else {
      fin(dist[i]);
    }
  }
}


Measured memory_bytes: 3208
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
int n,m,x[200010],cnt,y[200010],inf=1e9;
struct tree
{
	int ov,ev,lz,li;
}tr[800010];
void pd(int i)
{
	if(tr[i].lz)
	{
		swap(tr[i*2].ov,tr[i*2].ev);    tr[i*2].lz^=1;
		swap(tr[i*2+1].ov,tr[i*2+1].ev);tr[i*2+1].lz^=1;
		tr[i].lz=0;
	}
}
int mx(int a,int b)
{
	if(x[a]<x[b])return a;
	return b;
}
void clear(int i,int l,int r,int k)
{
	if(l==r)
	{
		tr[i].ov=tr[i].ev=0;
		tr[i].li=l;
		return ;
	}
	pd(i);
	if(k<=(l+r)/2)
	{
		clear(i*2,l,(l+r)/2,k);
		swap(tr[i*2+1].ov,tr[i*2+1].ev);
		tr[i*2+1].lz^=1;
	}
	else clear(i*2+1,(l+r)/2+1,r,k);
	tr[i].ov=mx(tr[i*2].ov,tr[i*2+1].ov);
	tr[i].ev=mx(tr[i*2].ev,tr[i*2+1].ev);
	if(tr[i*2].li)tr[i].li=tr[i*2].li;
	else tr[i].li=tr[i*2+1].li;
}
int sl(int i,int l,int r,int k)
{
	if(r<k)return 0;
	if(l>=k)return tr[i].li;
	int a;
	a=sl(i*2,l,(l+r)/2,k);
	if(a)return a;
	return sl(i*2+1,(l+r)/2+1,r,k); 
}
int se(int i,int l,int r,int ql,int qr)
{
	if(l>qr ||ql>r)return 0;
	//cout<<"se "<<l<<" "<<r<<" "<<tr[i].ov<<" "<<tr[i].ev<<endl;
	if(ql<=l && r<=qr)return tr[i].ov;
	pd(i);
	return mx(se(i*2,l,(l+r)/2,ql,qr),se(i*2+1,(l+r)/2+1,r,ql,qr));
}
void bu(int i,int l,int r)
{
	if(l==r)
	{
		if(l&1)tr[i].ov=l;
		else tr[i].ev=l;
		return ;
	}
	bu(i*2,l,(l+r)/2);bu(i*2+1,(l+r)/2+1,r);
	tr[i].ov=mx(tr[i*2].ov,tr[i*2+1].ov);
	tr[i].ev=mx(tr[i*2].ev,tr[i*2+1].ev);
	//cout<<" "<<l<<" "<<r<<" "<<tr[i].ov<<" "<<tr[i].ev<<endl; 
}
int main()
{
	int i,s,a,b,k,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&x[i]);x[0]=1e9;
	bu(1,1,n);
	for(i=1;i<=n/2;i++)
	{
		a=tr[1].ov;cnt++;y[cnt]=x[a];clear(1,1,n,a);
		j=sl(1,1,n,a+1);
		//cout<<"a "<<a<<endl;
		if(!j)j=n+1;//cout<<"j "<<j<<endl; 
		b=se(1,1,n,a+1,j-1);clear(1,1,n,b);
		cnt++;y[cnt]=x[b];
		//cout<<"b "<<b<<endl;
	}
	for(i=1;i<=n;i++)printf("%d ",y[i]);
	return 0;
}

Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	long long sum = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 && i % 5) sum += i;
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 3828
package main

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

type P struct {
	X int
	Y int
}

type Queue struct {
	p []*P
}

func (q *Queue) push(p *P) {
	q.p = append(q.p, p)
}

func (q *Queue) pop() {
	q.p = q.p[1:]
}

func (q *Queue) front() *P {
	return q.p[0]
}

func (q *Queue) size() int {
	return len(q.p)
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var (
	H int
	W int
)

// 地形データ
var field [][]string

// 訪問状態
var visited [][]bool

// 各点までの最短距離のスライス
var d [][]int

func main() {
	sc.Split(bufio.ScanWords)
	H, W = nextInt(), nextInt()
	field = make([][]string, H)
	visited = make([][]bool, H)
	d = make([][]int, H)

	for i := 0; i < H; i++ {
		// 地形データ初期化
		field[i] = make([]string, W)

		// 訪問状態を初期化
		visited[i] = make([]bool, W)

		// 各点までの最短距離のスライス初期化
		d[i] = make([]int, W)
	}

	for i := 0; i < H; i++ {
		line := strings.Split(nextLine(), "")
		for j, l := range line {
			field[i][j] = l
		}
	}

	fmt.Println(bfs())

}

func bfs() int {
	// 初期位置をキューにpush
	q := Queue{}
	for h := 0; h < H; h++ {
		for w := 0; w < W; w++ {
			if field[h][w] == "#" {
				q.push(&P{X: h, Y: w})
				// 初期位置のコストを0

				d[h][w] = 0
				visited[h][w] = true
			}
		}
	}

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

	for q.size() > 0 {
		// キューの先頭を取り出す
		p := q.front()

		q.pop()

		// 移動4方向をループ
		for i := 0; i < 4; i++ {
			nx := p.X + dx[i]
			ny := p.Y + dy[i]

			if 0 <= nx && nx < H && 0 <= ny && ny < W && string(field[nx][ny]) != "#" && !visited[nx][ny] {
				q.push(&P{X: nx, Y: ny})
				d[nx][ny] = d[p.X][p.Y] + 1
				visited[nx][ny] = true

			}
		}

	}

	res := -1
	for h := 0; h < H; h++ {
		for w := 0; w < W; w++ {
			res = max(res, d[h][w])
		}
	}

	return res
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 79872
#include<stdio.h>
#include<math.h>
typedef struct a{
  double p1;
  double p2;
}zahyou;

void curve(int,zahyou,zahyou);

int main(){
  int n;
 zahyou syoki1,syoki2;

  scanf("%d",&n);
  

  syoki1.p1=0;
  syoki1.p2=0;
  syoki2.p1=100;
  syoki2.p2=0;
   printf("%f   %f\n",syoki1.p1,syoki1.p2);
  curve(n,syoki1,syoki2);
   printf("%f   %f\n",syoki2.p1,syoki2.p2);
}
void curve(int n,zahyou syoki1,zahyou syoki2){
  zahyou s,u,t;
  
  s.p1=((2*syoki1.p1)+(1*syoki2.p1))/3;
  s.p2=((2*syoki1.p2)+(1*syoki2.p2))/3;
  t.p1=((1*syoki1.p1)+(2*syoki2.p1))/3;
  t.p2=((1*syoki1.p2)+(2*syoki2.p2))/3;
  u.p1=((t.p1-s.p1)* 0.5)-((t.p2-s.p2)*0.866025)+s.p1;
  u.p2=((t.p1-s.p1)*0.866025)+((t.p2-s.p2)*0.5)+s.p2;
  if(n==0)return;
  curve(n-1,syoki1,s);
  printf("%f   %f\n",s.p1,s.p2);
  curve(n-1,s,u);
   printf("%f   %f\n",u.p1,u.p2);
   curve(n-1,u,t);
   printf("%f   %f\n",t.p1,t.p2);
   curve(n-1,t,syoki2);
  
}



Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<cstdlib>
#include<deque>
#include<queue>
#include<bitset>
#include<functional>
#include<utility>
#include<list>
#include<iomanip>
#include<ctime>
#include<cassert>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
const int INF=1e9+1;
vector<int > v[100005],con;
bool vis[100005],q;
int a,n,sp[2];
void meet(int x)
{
	if(q) return;
	vis[x]=1;
	con.push_back(x);
	for(int i=0;i<v[x].size();i++)
	{
		if(v[x][i]==n-1)
		{
			q=1;
			return;
		}
		if(!vis[v[x][i]]) meet(v[x][i]);
	}
	if(q) return;
	con.pop_back();
}
void dfs(int x)
{
	vis[x]=1;
	a++;
	for(int i=0;i<v[x].size();i++)
	{
		if(!vis[v[x][i]]&&!((sp[0]==x&&sp[1]==v[x][i])||(sp[0]==v[x][i]&&sp[1]==x))) dfs(v[x][i]);
	}
}
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		x--,y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	meet(0);
	con.push_back(n-1);
	int len=con.size();
	sp[0]=con[(len+1)/2-1],sp[1]=con[(len+1)/2];
	for(int i=0;i<n;i++) vis[i]=0;
	dfs(0);
	int a1=a;
	a=0;
	dfs(n-1);
	int a2=a;
	/*cout<<sp[0]<<" "<<sp[1]<<endl;
	for(int i=0;i<len;i++)
	{
		cout<<con[i]<<" ";
	}
	cout<<endl;
	cout<<a1<<" "<<a2<<endl;*/
	if(a1>a2) cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
	return 0;
}


Measured memory_bytes: 9464
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

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

typedef long long lint;
typedef pair<int,int> P;

const long long int mod=1e9+7;



int main(){
	int A,B,K;
	cin >> A >> B;

	if((A+B)%2==0) cout << (A+B)/2 << endl;
	else cout << "IMPOSSIBLE" << endl;


}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab_array = [[int(x) for x in input().split()] for x in range(n)]
ab_array = sorted(ab_array, key=lambda x:x[0])
tmp = 0
res = 0
for a, b in ab_array:
    if tmp + b < m:
        tmp += b
        res += a*b
    else:
        res += (m-tmp)*a
        break
print(res)

Measured memory_bytes: 23524
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
int c[2019];
ll bpow(ll b, ll p, ll m) {
  ll rt = 1;
  for (; p; b = b * b % m, p >>= 1) {
    if (p & 1)
      rt = rt * b % m;
  }
  return rt;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  ll rem = 0;
  ll ans = 0;
  for (int i = 0; i < s.length(); i++) {
    rem = (rem + (s[i] - '0') * bpow(10, i, 2019)) % 2019;
    c[rem]++;
  }
  for (int i = 0; i < 2019; i++) {
    if (c[i]) {
      ans += 1LL * (c[i]) * (c[i] - 1) / 2;
    }
  }
  cout << ans + c[0] << endl;
}

Measured memory_bytes: 3680
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    string s;
    cin >> s;
    string t = "";
    rep(i, s.size()) {
        if(s[i] != 'x') t += s[i];
    }
    bool ok = true;
    rep(i, t.size()) {
        if(t[i] != t[t.size() - 1 - i]) ok = false;
    }
    int ans = 0;
    if(!ok) {
        cout << -1 << endl;
    }else {
        int i = 0, j = s.size() - 1, xcount_l = 0, xcount_r = 0;
        while(i < j) {
            if(s[i] == 'x') ++xcount_l, ++i;
            if(s[j] == 'x') ++xcount_r, --j;
            if(s[i] == s[j] && s[i] != 'x') {
                ans += abs(xcount_l - xcount_r);
                xcount_l = xcount_r = 0;
                ++i;
                --j;
            }
        }
        ans += abs(xcount_l - xcount_r);
        cout << ans << endl;
    }
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] a = sc.next().split("");
        String[] b = sc.next().split("");
        String[] c = sc.next().split("");
        if (a[a.length - 1].equals(b[0])
                && b[b.length - 1].equals(c[0])) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }

}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
long long mod = 1000000000000000000;
long long power(long long m,long long n){
    long long res = 1;
    if(n > 0){
        res = power(m,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }
        else{
            res = (((res * res) % mod) * m) % mod;
        }
    }
    return res;
}
//modはグローバル変数にしておく
int main(){
  ll n = 0;
  ll p = 0;
  cin >> n >> p;
  vector<ll> count(2);
  count[0] = 0;
  count[1] = 0;
  for(int i = 0;i < n;i++){
    ll num = 0;
    cin >> num;
    count[num % 2]++;
  }
  ll res = 0;
  if(count[1] > 0)res = power(2,n-1);
  else {
    if(p == 0)res= power(2,n);
    else res = 0;
  }
  cout << res << endl;
  return 0;
}

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

int main() {
  string C1, C2;
  cin >> C1 >> C2;
  if (C1.at(0)==C2.at(2)&&C1.at(1)==C2.at(1)&&C1.at(2)==C2.at(0)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    int n;
    cin >> n;

    int cnt[10001]{};

    FOR(x, 1, 101) FOR(y, 1, 101) FOR(z, 1, 101) {
        if(x * x + y * y + z * z + x * y + y * z + z * x <= n)
            ++cnt[x * x + y * y + z * z + x * y + y * z + z * x];
    }

    FOR(i, 1, n + 1) cout << cnt[i] << endl;

    return 0;
}

Measured memory_bytes: 3688
#include<iostream>
using namespace std;
int main(){
int a=0,b=0,c=0,d=0;
string s;
cin>>s;
a=s[0]-48;
b=s[1]-48;
c=s[2]-48;
d=s[3]-48;
if(a+b+c+d==7)
    cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
else if(a+b+c-d==7)
     cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
else if(a+b-c-d==7)
     cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
else if(a+b-c+d==7)
     cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
     else if(a-b+c+d==7)
     cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
     else if(a-b-c+d==7)
     cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
     else if(a-b+c-d==7)
     cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
     else if(a-b-c-d==7)
     cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;

return 0;
}



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

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define MOD 1000000007
#define FOR(i, n) for(ll i = 0; i < n; i++)
using namespace std;
const long long INF = 3*1e18;

int main() {
    ios::sync_with_stdio(0);    
    cin.tie(0);
    ld X;
    cin >> X;
    // // X = (ld) X / (ld) 100;
    // db(X);
    // ld num = log10(X) - 2, den = log10(1.01);
    // db(num); db(den);
    // ld n = (ld) num / (ld) den;
    // db(n);
    // cout << ceil(n) << "\n";
    ll year = 0;
    ld amount = 100;
    while(amount < X){
        ++year;
        amount *= (ld) 1.01;
        amount = (ld) (floor(amount));
    }
    cout << year << "\n";
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define Pct puts("------ Yes ------");
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define per(a, b, c) for(int a = (b); a >= (c); -- a)
#define fir first
#define sec second
#define ls son[u][0]
#define rs son[u][1]
#define eps 1e-8
#define PI acos(-1.0)
using namespace std;
template <class T> void rd(T &x){ x = 0; int f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); x *= f; }

typedef long long ll;
const int mod = 1e9 + 7;
int u[120], v[120], t[120];
int c[1 << 15], d[1 << 15];
int f[2][1 << 15];
int n, m, ans;

void add(int &a, int b){ a = (a + b) % mod; }

int main(){
	rd(n), rd(m);
	int all = (1 << n) - 1;
	t[0] = 1;
	rep(i, 1, m) rd(u[i]), rd(v[i]), t[i] = t[i - 1] * 2ll % mod;
	rep(i, 1, all){
		rep(j, 1, m){
			if(i & (1 << u[j] - 1) && i & (1 << v[j] - 1)) c[i] ++;
			if(i & (1 << u[j] - 1) || i & (1 << v[j] - 1)) d[i] ++;
		}
	}
	rep(i, 0, 1){
		rep(j, 1, all) if(j & (1 << i)){
			f[i][j] = t[c[j]];
			for(int k = j; k; k = (k - 1) & j)
				add(f[i][j], mod - (ll) f[i][j - k] * t[c[k]] % mod);
		}
	}
	rep(i, 1, all){
		int Ci = all ^ i;
		for(int j = Ci; j; j = (j - 1) & Ci){
			if(c[i] + c[j] != c[i | j]) continue;
			add(ans, (ll) f[0][i] * f[1][j] % mod * t[m - d[i | j]] % mod);
		}
	}
	printf("%d\n", (t[m] - ans + mod) % mod);
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<math.h>
using namespace std;
void solve();
int main (){ 
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t;
    //cin >> t;
    t = 1;
    for (int i = 0; i < t; i++) solve();
    
}
void solve() {
    int x,y;
    cin >> x >> y;
    long long prod = x;
    int found = 0; 
    if (x % y == 0) {
        cout << -1;
        return;
    }
    while (prod < pow(10,18) && !found) {
        if ((prod % y))found = 1;
        else{
            prod += x;
        }
    }
    if (found)cout << prod;
}

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

int num;
int a[21][21];

int retcost(int Island){
	int x=0;
	for(int i=1;i<=num;i++){
		if(a[Island][i]){
			a[i][Island]=0;
			x=max(x,a[Island][i]+retcost(i));
		}
	}
	return x;
}

int main(void){
	while(cin>>num,num){
		int I1,I2,t,ans,I[num+1]={},Cost=0;
		memset(a,0,sizeof(a));
		for(int i=1;i<num;i++){
			cin>>I1>>I2>>t;
			a[I1][I2]=a[I2][I1]=t;
			I[I1]++,I[I2]++;
			Cost+=t*2;
		}
		for(int i=1;i<=num;i++){
			for(int j=1;j<=num;j++){
				if((I[i]==1||I[j]==1)&&!((i==1&&I[i]==1)||(j==1&&I[j]==1))){
					Cost-=a[i][j]*2;
					a[i][j]=a[j][i]=0;
				}
			}
		}
		ans=Cost-retcost(1);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3004
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	if(A>=13){
	    System.out.print(B);
	}else if(A>=6 && A<=12){
	    System.out.print(B/2);
	}else{
	    System.out.print(0);
	}
    }
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int h, w;cin >> h >> w;
    for(int i=0;i<w+2;i++) cout << '#';
    cout << endl;
    for(int i=0;i<h;i++){
        string s;cin >> s;
        cout << '#' << s << '#' << endl;
    }
    for(int i=0;i<w+2;i++) cout << '#';
    cout << endl;
    return 0;
}


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

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

using namespace std;

struct Data {
  int start,end,onAir,recorded;
  bool operator < ( const Data &data ) const {
    if( end != data.end ) return end < data.end;
    if( start != data.start ) return start < data.start;
    return ( onAir != data.onAir ) ? onAir < data.onAir : recorded < data.recorded;
  }
};

const int MAX_N = 1100;
int N,dp[2000][2000],h,m;
vector<int> buf;

int toTime(string s){
  rep(i,(int)s.size()) if( s[i] == ':' ) s[i] = ' ';
  stringstream ss(s);
  ss >> h >> m;
  return h * 60 + m;
}

int main(){
  while( cin >> N, N ){
    vector<Data> vec(N);
    rep(i,N) {
      string a,b,c;
      cin >> a >> b >> c >> vec[i].onAir >> vec[i].recorded;
      vec[i].start = toTime(b), vec[i].end = toTime(c);
    }
    vec.push_back((Data){0,0,0,0});
    rep(i,N+2) rep(j,N+2) dp[i][j] = 0; 
    sort(vec.begin(),vec.end());
    buf.clear();
    rep(i,vec.size()) buf.push_back(vec[i].end);
    rep(i,vec.size()){
      rep(j,vec.size()){
        if( i == j ) dp[i][j] = max((i?dp[i-1][j]:0),(j?dp[i][j-1]:0));
        else if( i < j ) {
          int prev = upper_bound(buf.begin(),buf.begin()+j,vec[j].start) - buf.begin() - 1;
          dp[i][j] = max(dp[i][j-1],((prev!=-1)?dp[i][prev]:0)+vec[j].recorded);
        } else {
          int prev = upper_bound(buf.begin(),buf.begin()+i,vec[i].start) - buf.begin() - 1;
          dp[i][j] = max(dp[i-1][j],((prev!=-1)?dp[prev][j]:0)+vec[i].onAir);
        }
      }
    }
    printf("%d\n",dp[(int)vec.size()-1][(int)vec.size()-1]);
  }
  return 0;
}

Measured memory_bytes: 9448
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num;
		main: while (sc.hasNext()) {
			String str = sc.next();
			int sum = 0;
			for (int i=0; i < str.length(); i++) {
				num = Integer.parseInt(str.substring(i, i+1));
				if (i == 0 && num == 0) break main;
				sum += num;
			}
			System.out.println(sum);
		}
		sc.close();
	}
}

Measured memory_bytes: 18148
#include <iostream>
#include <algorithm>
#include <set>
#include <string>

using namespace std;


int main() {
  int N;
  cin >> N;
  string result = "Yes";
  for(int i=0;i<N;i++){
    int t,x,y;
    cin >> t >> x >> y;
  
    int d = x+y;
    if(t<d){result="No";break;}
    if(d%2!=t%2){result="No";break;}
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INF = 1ll << 60;

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

  ll sumA = 0, sumB = 0;
  vector<ll> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    sumA += A[i];
  }
  vector<ll> B(n);
  for (int i = 0; i < n; i++) {
    cin >> B[i];
    sumB += B[i];
  }

  if (sumA < sumB) {
    cout << -1 << endl;
    return 0;
  }

  vector<ll> sa(n);
  for (int i = 0; i < n; i++) sa[i] = A[i] - B[i];

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

  int count = 1;
  int f = 0, l = n - 1;
  while (sa[f] < 0) {
    if (0 < sa[f] + sa[l]) {  // 大きい方が勝っていたら
      sa[l] += sa[f];
      sa[f] = 0;
      f++;
      count++;
    } else if (0 > sa[f] + sa[l]) {  // 負けていたら
      sa[f] += sa[l];
      sa[l] = 0;
      l--;
      count++;
    } else {  // 同じだったら
      sa[f] = 0;
      sa[l] = 0;
      f++;
      l--;
      count += 2;
    }
  }
  if (count == 1) {  // 1はありえない(必ず2以上である)ので…
    cout << 0 << endl;
    return 0;
  }
  cout << count << endl;
}


Measured memory_bytes: 2560
from bisect import bisect_right,bisect_left
N,C=map(int,input().split())
S=[[int(i) for i in input().split()] for i in range(N)]
Way1=[S[0][1]-S[0][0]]
p1=[]
if Way1[0]>0:
  p1.append(0)
for i in range(1,N):
  Way1.append(Way1[i-1]+S[i][1]-(S[i][0]-S[i-1][0]))
  if p1==[] and Way1[i]>0:
    p1.append(i)
  elif p1!=[]:
    if Way1[p1[-1]]<Way1[i]:
      p1.append(i)
    
Way2=[S[-1][1]-(C-S[-1][0])]
p2=[]
if Way2[0]>0:
  p2.append(N-1)
for i in range(1,N):
  Way2.append(Way2[i-1]+S[N-i-1][1]+(S[N-i-1][0]-S[N-i][0]))
  if p2==[] and Way2[i]>0:
    p2.append(N-i-1)
  elif p2!=[]:
    if Way2[N-1-p2[-1]]<Way2[i]:
      p2.append(N-i-1)
Way2.reverse()
p2.reverse()

ans=0
for i in p1:
  if i!=N-1:
    if bisect_right(p2,i+0.1)<len(p2):
      j=p2[bisect_right(p2,i+0.1)]
      ans=max(ans,Way1[i],Way1[i]-S[i][0]+Way2[j])
    else:
      ans=max(ans,Way1[i])
  else:
    ans=max(ans,Way1[i])
for j in p2:
  if j!=0:
    if bisect_left(p1,j-0.1)>0:
      i=p1[bisect_left(p1,j-0.1)-1]
      ans=max(ans,Way2[j],Way1[i]-(C-S[j][0])+Way2[j])
    else:
      ans=max(ans,Way2[j])
  else:
    ans=max(ans,Way2[j])
    
print(ans)


Measured memory_bytes: 75224
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const ll MOD=1e9+7;
ll add(ll a, ll b){a+=b; if(a>=MOD)a-=MOD; return a;}
ll sub(ll a, ll b){a-=b; if(a<0)a+=MOD; return a;}

const int N=1e4+5, D=101;
ll dp[N][D][2];
int nxt[D][10], d;
string n;
ll f(int i, int j, int b){
	if(i==SZ(n))return j == 0;
	ll &r=dp[i][j][b];
	if(r!=-1)return r;
	r=0;
	for(int c=b?9:n[i]; c>=0; c--)r=add(r,f(i+1,nxt[j][c],c<n[i]||b));
	return r;
}

int main(){FIN;mset(dp,-1);
	cin >> n >> d;
	fore(x,0,SZ(n))n[x]-='0';
	fore(x,0,d)fore(c,0,10)nxt[x][c]=(x+c)%d;
	cout << sub(f(0,0,0),1) << "\n";
}

Measured memory_bytes: 16896
#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;
	string s0 = "";
	int sum = 0;
	vector<int> a(0);
	int xsum = 0;
	rep(i, s.size()){
		if(s.at(i) != 'x'){
			sum++;
			s0 += s.at(i);
			a.push_back(xsum);
			xsum = 0;
		}else{
			xsum++;
		}
	}
	a.push_back(xsum);
	int f = 0;
	rep(i, s0.size()){
		if(s0.at(i) != s0.at(s0.size()-1-i)) f = 1;
	}
	int ans = 0;
	rep(i, (a.size()+1)/2){
		if(a[i] != a[a.size()-1-i]) ans += abs(a[i] - a[a.size()-1-i]);
	}
	if(f == 0){
		cout << ans << endl;
	}else{
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1148
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
    va[i]--;
  }

  ll ans = 0LL;
  for (ll i = 0; i < N; i++) {
    //print(va[va[i]]);
    if (va[va[i]] == i && va[i] > i) {
      ans++;
    }
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL =LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    int n;cin>>n;
    vint A(n),B(n);
    rep(i,n){
        cin>>A[i]>>B[i];
    }
    ll c=0;
    for(auto i = n-1;i>=0;i--){
        if((c+A[i])%B[i] == 0)continue;
        c+=(B[i]-((c+A[i])%B[i]));
    }
    
    cout<<c<<endl;
    
    
    return 0;
}








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

int main() {
	int A, B, C;
	
	std::cin >> A >> B >> C;
	
	std::vector<int> lst;
	lst.emplace_back(A);
	lst.emplace_back(B);
	lst.emplace_back(C);
	
	int max = *std::max_element(lst.begin(), lst.end());
	
	int sum = 0;
	for(auto item : lst) {
		sum += item;
	}
	
	int rest = max * 3 - sum;
	
	if(rest % 2 == 1) {
		rest += 3;
	}
	
	std::cout << rest / 2 << std::endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}

ll a[123], b[123], c[123], d[123];
signed main() {
	ll n, m, ans = 1; cin >> n >> m;
	rep(i, n) {
		cin >> a[i] >> b[i];
	}
	rep(i, m) {
		cin >> c[i] >> d[i];
	}
	rep(i, n) {
		ll cnt = INF;
		rep(j, m) {
			if (cnt > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				cnt = abs(a[i] - c[j]) + abs(b[i] - d[j]); ans = j;
			}
		}
		cout << ans + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3644
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public enum mark{

		S,
		H,
		C,
		D;

	}

	public static void main(String[] args) {

		List<String> allCard = new ArrayList<>();

		for(mark mark: mark.values()){

			for(int i = 1; i <= 13; i++) {

				allCard.add(String.valueOf(mark) + " " + i);

			}
		}

		Scanner in = new Scanner(System.in);

		int cardCount = Integer.parseInt(in.nextLine());

		for(int i = 0; i < cardCount; i++) {

			allCard.remove(in.nextLine());

		}

		for(String result: allCard) {

			System.out.println(result);

		}
	}
}

Measured memory_bytes: 26204
from collections import deque
h,w=map(int,input().split())
S=[input()for _ in range(h)]
inf=float("inf")
ans=0
for i in range(h):
      for j in range(w):
            if S[i][j]==".":
                  dp=[[inf for _ in range(w)]for _ in range(h)]
                  dp[i][j]=0
                  que=deque([(i,j)])
                  while que:
                        si,sj=que.popleft()
                        for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
                              if 0<=ni<h and 0<=nj<w and S[ni][nj]!='#':
                                    if dp[ni][nj]>dp[si][sj]+1:
                                          dp[ni][nj]=dp[si][sj]+1
                                          que.append((ni,nj))
                                          ans=max(ans,dp[si][sj]+1)
print(ans)

Measured memory_bytes: 48476
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
string s; 
int main()
{
    cin>>s;
    int len=s.length()-2;
    cout<<s[0]<<len<<s[s.length()-1];
    
    return 0;
}

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

using namespace std;

int main ()
{
	int a, b;
	cin >> a >> b;
	
	if( a == b){
		cout << a;
	}
	else if( a > b){
		cout << a - 1;
	}
	else if( a < b){
		cout << a;
	}
	else  cout << b;
	

		return 0;
}

Measured memory_bytes: 256