akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

vector<int> bABa;
vector<int> a;
vector<int> b;
vector<int> A;
vector<int> B;
ll n;

vector<int> func(vector<int> p, vector<int> q){
	vector<int> ret(p.size());
	REP(i, p.size()){
		ret[i] = p[q[i]];
	}
	return ret;
}

vector<int> inverse(vector<int> v){
	vector<int> ret(v.size());
	REP(i, v.size()){
		ret[v[i]] = i;
	}
	return ret;
}

void out(vector<int> v){
	REP(i, v.size())cout << v[i] + 1 << " ";cout << endl;
}

vector<int> make_x(ll n, ll k){
	ll cou = k / 6;
	vector<int> ret(n);
	auto kake = bABa;
	REP(i, n)ret[i] = i;
	REP(i, 30){
		if(cou & (1 << i)){
			ret = func(ret, kake);
		}
		kake = func(kake, kake);
	}
	
	int tmp = k % 6;
	if(tmp <= 0)return ret;
	ret = func(ret, b);
	if(tmp <= 1)return ret;
	ret = func(ret, A);
	if(tmp <= 3)return ret;
	ret = func(ret, B);
	if(tmp <= 4)return ret;
	ret = func(ret, a);
	return ret;
}

vector<int> make_y(int k){
	int tmp = k % 6;
	switch(tmp){
		case 0:return func(b, A);
		case 1:return A;
		case 2:return B;
		case 3:return func(B, a);
		case 4:return a;
		case 5:return b;
	}
}

int main(){
	ll n, k;cin >> n >> k;
	a.resize(n);REP(i, n)cin >> a[i],a[i]--;
	b.resize(n);REP(i, n)cin >> b[i],b[i]--;
	
	if(k == 1){
		out(a);
		return 0;
	}
	if(k == 2){
		out(b);
		return 0;
	}
	k -= 3;

	A = inverse(a);
	B = inverse(b);
	bABa = func(func(func(b, A), B), a);	
	
	auto x = make_x(n, k);
	auto y = make_y(k);
	
	out(func(func(x, y), inverse(x)));
	
	return 0;
}


Measured memory_bytes: 5880
#include <iostream>
#include <vector>

int main() {
    int N; std::cin >> N;
    std::vector<int> b(N);
    for (int i = 0; i < N; i++) {
        std::cin >> b[i];
    }

    std::sort(b.begin(), b.end());

    int ret = 0;
    int p = b[0]; bool f = true;
    for (int i = 1; i < N; i++) {
        if (p != b[i]) {
            if (f) {
                ret++;
            }
            p = b[i]; f= true;
        } else {
            f = !f;
        }
    }
    if (f) {
        ret++;
    }

    std::cout << ret << std::endl;
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <regex>

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

using namespace std;
using ll = long long int;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	string s;
	cin >> s;
	regex re("(0|1)?B");
	string result;
	for (int i = 0; i < 10; i++) {
		result = regex_replace(s, re, "", regex_constants::format_first_only);
        s = result;
	}
	cout << result;
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string sn;
    cin >> sn;
    int k;
    cin >> k;
    //ll ans = 0;
    int l = (int)sn.size();
    vvll dp(l,vll(8,0LL));
    dp[0][1] = 1;
    dp[0][5] = (ll)(sn[0]-'0')-1;
    for(ll i = 1;i<l;++i){
        ll num = (ll)(sn[i]-'0');
        if(num==0){
            dp[i][1] = dp[i-1][1];
            dp[i][2] = dp[i-1][2];
            dp[i][3] = dp[i-1][3];
        }else{
            dp[i][1] = 0;
            dp[i][2] = dp[i-1][1];
            dp[i][3] = dp[i-1][2];
        }
        if(num==0){
            dp[i][5] = dp[i-1][5]+9;
            dp[i][6] = dp[i-1][6]+9*dp[i-1][5];
            dp[i][7] = dp[i-1][7]+9*dp[i-1][6];
        }else{
            dp[i][5] = dp[i-1][1] + dp[i-1][5] + 9LL;
            dp[i][6] = dp[i-1][2] + dp[i-1][1]*(num-1)+ dp[i-1][5]*9 + dp[i-1][6];
            dp[i][7] = dp[i-1][3] + dp[i-1][2]*(num-1)+ dp[i-1][6]*9 + dp[i-1][7];
        }
    }
    /*
    REP(i,l){
        cout << dp[i][1] << " " << dp[i][2] << " " << dp[i][5] << " " << dp[i][6] << endl;
    }
    */
    cout << dp[l-1][k] + dp[l-1][k+4] << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

while True:
    a, b = [int(i) for i in input().split()]
    if a == 0 and b == 0:
        exit()
    H = [int(i) for i in input().split()]
    W = [int(i) for i in input().split()]

    h_cnt = defaultdict(int)
    w_cnt = defaultdict(int)

    for h in H:
        h_cnt[h] += 1
    for w in W:
        w_cnt[w] += 1

    ans = 0

    for k, v in h_cnt.items():
        ans += k * max(v, w_cnt[k])
        w_cnt[k] = 0

    for k, v in w_cnt.items():
        ans += k * v

    print(ans)


Measured memory_bytes: 6000
n, k = map(int, input().split())


def simple(l):
    if not l:
        return "P"
    mid = simple(l - 1)
    return "B{}P{}B".format(mid, mid)


def length(l):
    return -2 + (1 - 2**(l + 2)) // (1 - 2)


def plen(l):
    return (1 - 2**(l + 1)) // (1 - 2)


def check(x, left, center, right, result):
    if x < center:
        if x == left:
            pos = -2
        else:
            return -1
    elif x > center:
        if x == right:
            pos = 2
        else:
            return 1
    else:
        pos = 0
    if pos in [-2, 0, 2]:
        if pos == -2:
            # print("end left")
            pass
        elif pos == 2:
            # print("end right")
            result += plen(depth + 1)
        else:
            # print("end center", plen(depth), depth)
            result += plen(depth) + 1
        print(result)
        # print(s[:k + 1].count("P"))
        exit()
k -= 1
# s = simple(n)
# print(s[:k], s[k], s[k + 1:])
# print(" - - - - - ", length(1))

left = 0
right = length(n)
center = (left + right) // 2
result = 0
depth = n - 1
# tmp = s
for i in range(50):
    # print(left, center, right, "depth", depth)
    # print(s[:center], s[center], s[center + 1:])
    # tmp = s[left : right + 1]
    # if len(tmp) != 3:
    #     print(tmp[0], tmp[1:len(tmp) // 2], tmp[len(tmp) // 2], tmp[len(tmp) // 2 + 1:-1], tmp[-1])
    # else:
    #     print("P P P")

    pos = check(k, left, center, right, result)
    if pos == -1:
        if depth == 0:
            print(result + 1)
            exit()
        left += 1
        right = center - 1
        center = (left + right) // 2
        # print("left")
    else:
        if depth == 0:
            print(result + 3)
            exit()
        right -= 1
        left = center + 1
        center = (left + right) // 2
        result += plen(depth) + 1
    #     print("right", result, plen(depth) + 1)
    # print()
    depth -= 1


Measured memory_bytes: 3064
import math

def search(cap, loads, num_tracks):
    num = 0
    capacity = cap
    tracks = num_tracks

    for l in loads :
        if capacity >= l: 
            capacity -= l
            num += 1
        else:
            if tracks > 1:
                tracks -= 1
                capacity = cap

                if capacity >= l:
                    capacity -= l
                    num += 1
                else:
                    break
            else:
                break
    return num

def Main():
    N, K = map(int, input().split())
    loads = list()

    for i in range(N):
        l = int(input())
        loads.append(l)

    pl = 0
    pr = sum(loads)

    pm = int( (pl + pr)/2.0 ) + 1
    pm_ = 0

    while pl < pr :
        pm = math.ceil( (pl + pr)/2.0 )

        nl = search( pl, loads, K)
        nm = search( pm, loads, K)
        nr = search( pr, loads, K)

        if pm_ == pm:
            print(pm)
            break

        if nm == nr :
            pl = pl
            pr = pm
            pm_ = pm
        else :
            pl = pm
            pr = pr
            pm_ = pm

Main()


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

int main(){
    int n;
    cin >> n;
    int f[n][10];
    rep(i, n){
        rep(j, 10){
            cin >> f[i][j];
        }
    }

    int p[n][11];
    rep(i, n){
        rep(j, 11){
            cin >> p[i][j];
        }
    }

    int MAX = -INF;
    for (int i = 1; i<1 << 10; i++){
        int ff[10];
        int ii = i;
        rep(j, 10){
            ff[j] = ii%2;
            ii /=2;
        }

        int sum = 0;
        rep(j, n){
            int s = 0;
            rep(k, 10){
                if(ff[k]==1 && f[j][k]==1) s++;
            }
            sum += p[j][s];
        }
        MAX = max(MAX, sum);
    }
    

    cout << MAX << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for i in range(M)]

ans = min(a) + min(b)

for x, y, c in xyc:
    ans = min(ans, a[x-1] + b[y-1] - c)

print(ans)

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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

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

#define MAX_V 100000

#define MOD 1000000007L
#define INF 2147483647

signed main() {
	int N;
	cin >> N;
	cout << (N * (N + 1) / 2) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
    while (true)
    {
        int n;
        vector<char> c(101);
        map<char, int> point;
        cin >> n;
        if (n == 0)
            break;
        for (int i = 1; i <= n; i++)
        {
            cin >> c[i];
            point[c[i]]++;
        }
        char TopPerson;
        int tmp = 0;
        for (int i = 0; i <= 'Z' - 'A'; i++)
        {
            tmp = max(tmp, point['A' + i]);
        }
        int count = 0;
        for (int i = 0; i <= 'Z' - 'A'; i++)
        {
            if (tmp == point['A' + i])
            {
                TopPerson = 'A' + i;
                count++;
            }
        }
        if (count != 1)
        {
            cout << "TIE" << endl;
            continue;
        }
        map<char, int> point2;
        int Second = 0;
        for (int i = 1; i <= n; i++)
        {
            point2[c[i]]++;
            if (c[i] != TopPerson)
            {
                Second = max(Second, point2[c[i]]);
            }
            if(Second+n-i <point2[TopPerson]){
                cout<<TopPerson<<" "<<i<<endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 3100
#include <cstdlib>
#include <iostream>
#include <typeinfo>
//#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  string s = "ACGT";
  char c;
  cin >> c;
  for (int i = 0; i < 4;i++){
    if(c==s.at(i)){
      cout << s.at(3 - i) << endl;
      break;
    }
  }
    return 0;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m, l; cin >> n >> m;

    string a[n]; REPI(i, n) cin >> a[i];
    string b[m]; REPI(i, m) cin >> b[i];

    REPI(i, n - m + 1){
        REPJ(j, n - m + 1){
            bool ans = 1;
            for(int k = 0; k < m; k++){
                for(l = 0; l < m; l++){
                    if(a[i + k][j + l] != b[k][l])
                        ans = 0;
                }
            }

            if(ans){ cout << "Yes"; return 0; }
        }
    }
    cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

ll N,M;
VI U(200200),V(200200);
VVI X(100100,VI(0));
VI D(100100,-1);

int solve(int P){
  if(D[P]==-1) D[P]=0;
  if(X[P].size()==0) return 0;
  queue<int> Q;
  Q.push(P);
  int F=1;
  while(!Q.empty()){
    int tmp=Q.front();
    Q.pop();
    rep(i,X[tmp].size()){
      if(D[X[tmp][i]]==-1){
        D[X[tmp][i]]=(D[tmp]+1)%2;
        Q.push(X[tmp][i]);
      }else if(D[X[tmp][i]]==D[tmp]) F=0;
    }
  }
  if(F) return 1;
  return 2;
}

int main(){
  cin>>N>>M;
  rep(i,M) cin>>U[i]>>V[i];
  VL A(3);
  rep(i,M){
    X[U[i]-1].pb(V[i]-1);
    X[V[i]-1].pb(U[i]-1);
  }
  rep(i,N) if(D[i]==-1) A[solve(i)]++;
  cout<<A[0]*A[0]+A[0]*(N-A[0])*2+A[1]*A[1]*2+A[1]*A[2]*2+A[2]*A[2]<<endl;
}

Measured memory_bytes: 8960
s = input()

d = 0
ans = 0

for m in s:
  if m == "g":
    if d == 0:
      d += 1
    elif d != 0:
      ans += 1
      d -= 1

  elif m == "p":
    if d == 0:
      ans -= 1
      d += 1
    elif d != 0:
      d -= 1

print(ans)

Measured memory_bytes: 39792
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100010
char s[MAXN];
int main()
{
	scanf("%s",s);
	int n=strlen(s);
	int cntg=0,cntp=0;
	for(int i=0;i<n;i++)
		if(s[i]=='g') cntg++;
		else cntp++;
	int ans=(cntg-cntp)/2;
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int p, q, r;
	cin >> p >> q >> r;
	cout << p+q+r-max({p,q,r}) << endl;
	return 0;
}

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

#define ll long long
#define endl "\n"

const int mx = 1000005;
const ll MOD = 1e9+7;

ll factorial[mx];

ll power(ll a, ll b){
	ll res = 1;
	
	while (b > 0){
		if (b%2){
			res = (res * a)%MOD;
		}
		a = (a*a)%MOD;
		b /= 2;
	}
	
	return res;
}

ll inverse(ll a){
	return power(a, MOD - 2);
}

ll combination(ll n, ll r){
	
	if (n < r) return 0;
	if (n == r or r == 0) return 1;
	ll ans = factorial[n];
	ll also = inverse(factorial[r]);
	ans = (ans*also)%MOD;
	also = inverse(factorial[n-r]);
	ans = (ans*also)%MOD;
	
	return ans;
}

ll way(ll first_x, ll first_y, ll last_x, ll last_y){
	ll x = last_x - first_x;
	ll y = last_y - first_y;
	return combination(x+y, x);
}

int main ()
{

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #define int ll
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);

	
	factorial[0] = 1;
	for (int i=1; i<mx; i++){
		factorial[i] = factorial[i-1]*i;
		if (factorial[i] >= MOD) factorial[i] %= MOD;
	}
	
	//cerr << combination(5, 2) << endl;
	//cerr << combination(10, 5) << endl;
	
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	
	int ans = 0;
	for (int i=b; i<w; i++){
		int one = way(0, 0, h-a-1, i);
		int two = way(h-a, i, h-1, w-1);
		
		one = (one*two)%MOD;
		
		ans = (ans + one)%MOD;
	}
	    	
	cout << ans << endl;
	
    return 0;

}

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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	int a,b;
	cin >> a >> b;
	if(a >= 13)cout << b << endl;
	else if(a >= 6)cout << b / 2 << endl;
	else cout << 0 << endl; 
	return 0; 
}


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

using namespace std;

long long ans=0;

int main()
{
    long long a,b,c,k;

    cin>>a>>b>>c>>k;

    ans+=min(k,a);k-=min(k,a);

    if(k>0)
        k-=min(k,b);

    if(k>0)
    {
        ans+=min(k,c)*(-1);
    }

    cout<<ans<<"\n";

    return 0;
}

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

bool f[4050];
char ch[2];

int main() {
	int a, b, n;
	scanf("%d%d", &a, &b);
	if(a <= b) {
		puts("Impossible");
		fflush(stdout);
		return 0;
	}
	n = a + b;
	stack<int> q;
	for(int i = 1; i <= n; i++) {
		if(!q.size()) {
			if (i == n) {
				q.push(i);
			} else {
				printf("? %d %d\n", i-1, i);
				fflush(stdout);
				scanf("%s", ch);
				if(ch[0] == 'Y') q.push(i), q.push(i + 1);
				i++;
			}
		} else {
			printf("? %d %d\n", q.top()-1, i-1);
			fflush(stdout),
			scanf("%s", ch);
			if(ch[0] == 'Y') q.push(i);
			else q.pop();
		}
	}
	int u = q.top();
	for(int i = 1; i <= n; i++) {
		printf("? %d %d\n", u-1, i-1);
		fflush(stdout);
		scanf("%s", ch);
		f[i] = ch[0] == 'Y';
	}
	printf("! ");
	for(int i = 1; i <= n; i++) printf(f[i] ? "1" : "0");
	puts("");
	fflush(stdout);
	return 0;
}


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

struct water{
  int left,sum;
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  stack<int> st1;
  stack<water> st2;
  int sum=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='\\'){
      st1.push(i);
    }else if(s[i]=='/'){
      if(st1.empty()==true){
        continue;
      }
      int temp=i-st1.top();
      sum+=temp;
      while(!st2.empty()&&st2.top().left>st1.top()){
        temp+=st2.top().sum;
        st2.pop();
      }
      water a;
      a.left=st1.top();
      a.sum=temp;
      st2.push(a);
      st1.pop();
    }
  }
  cout<<sum<<endl<<st2.size()<<flush;
  stack<int> ans;
  while(!st2.empty()){
    ans.push(st2.top().sum);
    st2.pop();
  }
  while(!ans.empty()){
    cout<<" "<<ans.top()<<flush;
    ans.pop();
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3356
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
int main(){
  int n,m;  cin >> n >> m;
  vector<ll> v(n,0);
  rep(i,0,m){
    ll x,y; cin >> x >> y;  --x; --y;
    v[x]++; v[y]++;
  }
  bool odd = false;
  rep(i,0,n){
    if(v[i]%2==1) odd = true;
  }
  if(odd){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

vector<ll> fac(500001); //n!(mod M)
vector<ll> ifac(500001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}
int main(){
    ll n,m;
    cin >> n >> m;
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<500000; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    ll B=0;
    for(ll i=1;i<n+1;i++){
        ll x=comb(n,i)*comb(m-i,n-i)%MOD;
        x=x*fac[n-i]%MOD;
        x*=pow(-1,i+1);
        B+=x;
        B%=MOD;
    }
    ll ans;
    if(((fac[m]*ifac[m-n])%MOD)>=B){
        ans=((fac[m]*ifac[m-n])%MOD)-B;
    }
    else{
        ans=((fac[m]*ifac[m-n])%MOD)-B+MOD;
    }
    ans=ans*fac[m]%MOD;
    ans=ans*ifac[m-n]%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 11004
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while (true){
			String s = sc.nextLine();
			String[] st = s.split(" ");
			int x = Integer.parseInt(st[0]);
			s = st[1];
			int y = Integer.parseInt(st[2]);
			if(s.equals("+")){
				System.out.println(x+y);
			}else if(s.equals("-")){
				System.out.println(x-y);
			}else if(s.equals("*")){
				System.out.println(x*y);
			}else if(s.equals("/")){
				System.out.println(x/y);
			}else if(s.equals("?")){
				break;
			}
		}
	}
}

Measured memory_bytes: 26196
from itertools import permutations as par
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
i=0
for q in par([i+1 for i in range(n)]):
    q=list(q)
    if q==A: A=i
    if q==B: B=i
    i+=1
print(abs(A-B))

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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

//復習必要 600点
int main() {
    map<char,pii> mp;
    //x0,y0=0,0

    int N;
    cin >> N;

    vector<pll> pos(N);
    FOR(i,0,N){
        cin >> pos[i].first >> pos[i].second;
    }

    int par = (abs(pos[0].first) + abs(pos[0].second)) % 2; //パリティ

    for (int i = 0; i < N; ++i) { //パリティチェック
        int par2 = (abs(pos[i].first) + abs(pos[i].second)) % 2;
        pos[i] = pll(pos[i].first + pos[i].second, pos[i].first - pos[i].second);//
        if (par2 != par) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<long long> d;
    for (int i = 30; i >= 0; --i) d.push_back(1LL<<i); //２のべき乗項

    if (par % 2 == 0) d.push_back(1);
    cout << d.size() << endl; //何回移動するか
    for (int j = 0; j < d.size(); ++j) cout << d[j] << " ";
    cout << endl;
    

        for (int i = 0; i < N; ++i) {
        int xdir, ydir;
        long long xsum = 0, ysum = 0;
        for (int j = 0; j < (int)d.size(); ++j) {
            if (xsum <= pos[i].first) xdir = 1, xsum += d[j];
            else xdir = -1, xsum -= d[j];
            if (ysum <= pos[i].second) ydir = 1, ysum += d[j];
            else ydir = -1, ysum -= d[j];
            
            if (xdir == 1 && ydir == 1) cout << "R";
            else if (xdir == 1 && ydir == -1) cout << "U";
            else if (xdir == -1 && ydir == -1) cout << "L";
            else cout << "D";
        }
        cout << endl;
    }
    //１つの移動で関節は好きな４つの方向にd動くことができる


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
int findTrailingZeros(int n)
{
	int count = 0;
	for (int i = 10; n / i >= 1; i *= 5)
		count += n / i;
	return count;
}
main()
{
	int n;
	cin >> n;
	if (n & 1) cout << 0 << endl;
	else
		cout << findTrailingZeros(n) << endl;;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define iterator IT
#define SIZ(V) V.size()
#define FS(a) fixed<<setprecision(a)
using namespace std;
namespace STARTER {
	int MAX(int a,int b) {
		return a>b?a:b;
	}
	int MIN(int a,int b) {
		return a<b?a:b;
	}
	int ABS(int a) {
		return a<0?-a:a;
	}
	int GCD(int a,int b) {
		return !b?a:GCD(b,a%b);
	}
	int LCM(int a,int b) {
		return a/GCD(a,b)*b;
	}
	int QSM(int a,int b,int p) {
		int ret=1;
		while (b) {
			if (b&1)
				ret=ret*a%p;
			a=a*a%p;
			b>>=1;
		}
		return ret;
	}
	int ROUND(double a) {
		return a+0.5;
	}
}
using STARTER::MAX;
using STARTER::MIN;
using STARTER::ABS;
using STARTER::GCD;
using STARTER::LCM;
using STARTER::QSM;
using STARTER::ROUND;
int n,k;
int change();
int main() {
	cin>>n>>k;
	cout<<change()<<'\n';
	return 0;
}
int change() {
	int ans=0;
	while (n) {
		n/=k;
		ans++;
	}
	return ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    int l = 100001;
    ll v[l]{};
    ll A[N];
    ll s = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        v[A[i]]++;
        s += A[i];
    }
    int Q;
    cin >> Q;
    ll B[Q], C[Q];
    for (int i = 0; i < Q; i++) {
        cin >> B[i] >> C[i];
    }
    for (int i = 0; i < Q; i++) {
        ll e = C[i] * v[B[i]] - B[i] * v[B[i]];
        s += e;
        v[C[i]] += v[B[i]];
        v[B[i]] = 0;
        cout << s << "\n";
    }
    return 0;
}

Measured memory_bytes: 6764
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int n,max_num = -1000001,min_num = 1000001,tmp;
	long long int sum = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);
		sum += tmp;
		max_num = max(max_num,tmp);
		min_num = min(min_num,tmp);
	}
	printf("%d %d %lld\n",min_num,max_num,sum);
}



Measured memory_bytes: 2740
function Main(input) {
	input = input.split("\n");
	var n = input[0];
	var s = "No";
	if(n[1]==n[2]){
	    if(n[0]==n[1]||n[2]==n[3])s = "Yes";
	}
	console.log('%s',s);
}

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

Measured memory_bytes: 7372
x = 0
while x == 0:

 m = map(int,raw_input().split())

 if m[0] == 0 and m[1] == 0:
     break

 print "#" * m[1]
 for i in xrange(m[0]-2):
    print "#" + "." * (m[1]-2) + "#"
 print "#" * m[1]
 print ""

Measured memory_bytes: 6380
import 'dart:io';

main(List<String> args) {
  List ABCD = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  var A = ABCD[0];
  var B = ABCD[1];
  var C = ABCD[2];
  var D = ABCD[3];
  var c = C - A;
  var d = D - B;
  List<List<int>> dp =
      List.generate(c + 1, (_) => List.generate(d + 1, (_) => 0));

  var mod = 998244353;
  dp[0][0] = 1;
  var ret;
  for (var i = 0; i < c + 1; i++) {
    for (var j = 0; j < d + 1; j++) {
      if (i == 0 && j == 0) continue;
      ret = 0;
      if (i > 0 && j > 0) {
        if (i == j && i == 1) {
          ret -= (A + i - 1) * (B + j - 1);
        } else {
          ret -= dp[i - 1][j - 1];
          ret *= (A + i - 1) * (B + j - 1);
        }
      }
      if (i > 0) ret += dp[i - 1][j] * (B + j);
      if (j > 0) ret += dp[i][j - 1] * (A + i);
      ret %= mod;
      dp[i][j] = ret;
    }
  }
  print(dp[c][d]);
}


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

public class Main {
    static int mod = (int)Math.pow(10, 9) + 7;
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int rows = scanner.nextInt();
        int cols = scanner.nextInt();
        List<String> grid = new ArrayList<>();
        for (int i = 0; i < rows; i++) {
            grid.add(scanner.next());
        }
        int curent[] = new int[cols+1];
        int previous[] = new int[cols+1];
        previous[cols-1] = 1;
        for (int i = rows-1; i >= 0; i--) {
            for (int j = cols-1; j >= 0; j--) {
                if (grid.get(i).charAt(j) == '#') {
                    curent[j] = 0;
                    continue;
                }
                curent[j] = (curent[j+1]%mod + previous[j]%mod)%mod;
            }
            int temp[] = curent;
            curent = previous;
            previous = temp;
        }
        System.out.println(previous[0]);
    }
}


Measured memory_bytes: 29204
#!/usr/bin/env python3

N = int(input())
lst = [int(h) for h in input().split()]

def judge():
    cur = lst[0]
    for i in range(1, N):
        if lst[i] < cur - 1:
            return False
        if lst[i] > cur:
            cur = lst[i]
    return True

if judge():
    print('Yes')
else:
    print('No')
    


Measured memory_bytes: 20304
#include<iostream>

using namespace std;

int main()
{
	char input[4];
	int count = 0;
	cin >> input;

	if(input[0]=='1')count++;
	if(input[1]=='1')count++;
	if(input[2]=='1')count++;

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int w;
	cin>>w;
	while(w--){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		int n;cin>>n;
		int out=0;
		rep(i,n){
			int x,y;cin>>x>>y;
			if(a<=x&&x<=a+c&&b<=y&&y<=b+d)out++;
		}
		cout<<out<<endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

class CumulativeSum {
    vector<ll> numbers;
    vector<ll> sums;

public:
    CumulativeSum(int n) {
        numbers.resize(n);
        sums.resize(n);
    }

    void set(int i, ll value) {
        numbers[i] = value;
    }

    ll getSum(int i) {
        if (i == -1) return 0;
        if (i == sums.size()) return sums.back();
        return sums[i];
    }

    ll getSectionSum(int start, int end) {
        return getSum(end) - getSum(start - 1);
    }

    void build() {
        for (int i = 0; i < numbers.size(); i++) {
            sums[i] = getSum(i - 1) + numbers[i];
        }
    }

};


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

    string s;
    cin >> s;

    CumulativeSum cs(n);
    rep(i, n - 1) {
        if (s[i] == 'A' && s[i + 1] == 'C') cs.set(i, 1);
    }
    cs.build();

    rep(_, q) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;

        int now = cs.getSectionSum(l, r);
        if (r < n - 1 && s[r] == 'A' && s[r + 1] == 'C') {
            now--;
        }
        cout << now << endl;
    }

}


Measured memory_bytes: 5100
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	int X;
	cin >> X;
	int sum = X/100;
	int rest = X%100;

	int cnt = 0;
	for(int i=5; i>0; i--) {
		cnt += rest/i;
		rest = rest%i;
	}
	if(cnt > sum) {
		cout << 0 << endl;
	} else {
		cout << 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def smaller(x, y):
	if x < y: return x
	return y

N = int(input())
W = list(map(int, input().split()))
sumlist = []
sum = 0
for i in range(0, N):
	sum += W[i]
	sumlist.append(sum)
min = 5000000000000000
for i in range(0, N):
	d = abs(sumlist[i]-(sumlist[-1]-sumlist[i]))
	min = smaller(min, d)
print(min)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
typedef pair<pii,pii> e;
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    ll cnt[n+1];
    fill(cnt,cnt+n+1,0);
    rep(i,2,n+1){
        int a;cin>>a;
        cnt[a]++;
    }
    rep(i,1,n+1)cout<<cnt[i]<<endl;
}


Measured memory_bytes: 5172
#include <iostream>

using namespace std;
const int INF = (1 << 30);

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

int main() {
  int V, E, r;
  cin >> V >> E >> r;
  Edge edges[E];
  for (int i = 0; i < E; ++i) {
    int s, t, c;
    cin >> s >> t >> c;
    edges[i] = Edge({s, t, c});
  }
  int d[V];
  fill(d, d + V, INF);
  d[r] = 0;
  for (int i = 0; i < V; ++i) {
    for (int j = 0; j < E; ++j) {
      Edge e = edges[j];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        if (i == V - 1) {
          cout << "NEGATIVE CYCLE" << endl;
          return 0;
        }
        d[e.to] = d[e.from] + e.cost;
      }
    }
  }
  for (int i = 0; i < V; ++i) {
    if (d[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, M; cin >> N >> M;
	pair<long long, int> A[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i].first>>A[i].second;
	}
	sort(A, A + N);
	int cur = 0;
	long long cost = 0;
	int i = 0;
	while (true) {
		if (A[i].second >= M - cur) {
			cost += (M - cur)*A[i].first;
			break;
		}
		else {
			cost += A[i].second*A[i].first;
			cur += A[i].second;
		}
		i++;
	}
	cout << cost << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
map<int, int>::iterator itr;
void c_p_c()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
}
void ans()
{
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            cout << "OK";
            return;
        }
    }
    cout << "NG";

}
int32_t main()
{
    c_p_c();
    ans();
    return 0;
}

Measured memory_bytes: 3640
import Foundation

gets()
let a = getsA().lazy.map { Int($0)! }

let (res, _) = a.reduce((0, 0)) { acc, num in
  return acc.1 > num ? (acc.0 &+ acc.1 &- num, acc.1) : (acc.0, num)
}

print(res)

@discardableResult
@inlinable @inline(__always) func gets() -> String { readLine()! }
@inlinable @inline(__always) func geti() -> Int    { Int(gets())! }
@inlinable @inline(__always) func getd() -> Double { Double(gets())! }

@inlinable @inline(__always) func getsA(_ c: Character = " ") -> [String] { gets().split(separator: c).map(String.init) }
@inlinable @inline(__always) func getiA(_ c: Character = " ") -> [Int]    { getsA(c).map { Int($0)! } }
@inlinable @inline(__always) func getdA(_ c: Character = " ") -> [Double] { getsA(c).map { Double($0)! } }

@inlinable @inline(__always)
func printf(_ format: String, _ args: CVarArg...) -> Void {
  print(String(format: format, arguments: args), terminator: "")
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n, m, x, y;
    cin >> n >> m >> x >> y;

    vector<int> a(n), b(m);
    int am = x, bm = y;
    arep(i, a) cin >> i, chmax(am, i);
    arep(i, b) cin >> i, chmin(bm, i);

    if (am < bm)
        cout << "No War\n";
    else
        cout << "War\n";
}

Measured memory_bytes: 256
while True:
    n,x = map(int,input().split())
    if n==0 and x==0:
        break
    count=0
    for a in range(1,n-1):
        for b in range(a+1,n):
            for c in range(b+1,n+1):
                if a+b+c == x:
                    count += 1
    print(count)

Measured memory_bytes: 7664
/* AOJ (Aizu Online Judge) My Practice
 * Author: Leonardone @ NEETSDKASU
 */
#include <stdio.h>
#include <stdlib.h>

typedef struct my_pos {
    union {
        struct {
            int x, y;
        };
        long long p;
    };
} POS;

int cmp (const void *a, const void* b) {
    long long d = *(long long *)a - *(long long *)b;
    if (d < 0) return -1;
    if (d > 0) return 1;
    return 0;
}


int main(void) {
    
    int m, n;
    POS ms[200], ns[1000];
    int i;
    
    for (;;) {
        scanf("%d", &m);
        if (m == 0) { break; }
        for (i = 0; i < m; i++) {
            scanf("%d", &ms[i].x);
            scanf("%d", &ms[i].y);
        }
        scanf("%d", &n);
        for (i = 0; i < n; i++) {
            scanf("%d", &ns[i].x);
            scanf("%d", &ns[i].y);
        }
        qsort(ns, n, sizeof(long long), cmp);
        
        for (i = 0; i < n; i++) {
            int dx = ns[i].x - ms[0].x;
            int dy = ns[i].y - ms[0].y;
            int j;
            for (j = 1; j < m; j++) {
                POS key;
                key.x = ms[j].x + dx;
                key.y = ms[j].y + dy;
                if (NULL == bsearch(&key, ns, n, sizeof(long long), cmp)) {
                    break;
                }
            }
            if (j == m) {
                printf("%d %d\n", dx, dy);
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 660
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

using int64 = long long;

int main() {
  int64 n, k;
  cin >> n >> k;
  vector<int64> H(n);
  for (int64& h : H)
    cin >> h;
  sort(H.begin(), H.end(), greater<int>());
  int64 sum = accumulate(H.begin() + min(n, k), H.end(), 0LL);
  cout << sum << "\n";
  
  return 0;
}


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

		// 整数の入力
		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();

		int ans = 0;

		if(p>=q&&p>=r)ans = q+r;
		if(q>=p&&q>=r)ans = p+r;
		if(r>=p&&r>=q)ans = p+q;

		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define int long long
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MAXIN(x) max_element(ALL(x)) - x.begin();
#define MIN(x) *min_element(ALL(x))
#define MININ(x) min_element(ALL(x)) - x.begin();
#define INF 1000000000000
#define MOD 100000070

#define MAXR 100000
#define PI 3.14159265358979323846

using namespace std;

signed main() {
    long double  a;
    long double b;
    cin >> a >> b;
    long double ans = a * b;

    cout << (int)(ans) << endl;
    return 0;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll>A(n);
  for(int i=0;i<n;i++) cin >> A[i],A[i]--;
  vector<int>all,roop;
  vector<int>check(n,0);
  int now = 0;
  while(check[now]!=2){
    if(check[now]==0) all.push_back(now);
    else roop.push_back(now);
    check[now]++;
    now = A[now];
  }
  if(all.size()>k) cout<< all[k]+1 <<endl;
  else cout<< roop[(k-(all.size()-roop.size()))%roop.size()]+1 <<endl;


}


Measured memory_bytes: 7868
N, X, D = gets.split.map(&:to_i)

(puts X == 0 ? 1 : N + 1; exit) if D == 0
D < 0 ? (x, d = X, D) : (x, d = -X, -D)
h = Hash.new{|h, k| h[k] = []}
(0 .. N).each do |i|
  l = x*i + i*(i - 1)/2 * d
  r = x*i + i*(N - i + N - 1)/2 * d
  h[l % d] << [l/d, r/d + 1]
end
ans = 0
h.values.each do |a|
  lst = -10**18
  a.sort.each do |s, e|
    if lst < s
      ans += e - s
      lst = e
    end
    if lst < e
      ans += e - lst
      lst = e
    end
  end
end
puts ans

Measured memory_bytes: 39548
#!/usr/bin/env python3

COINS = [100, 101, 102, 103, 104, 105]


def find_combinations(x, coins=COINS):
    dp = [int(i % coins[0] == 0) for i in range(x + 1)]
    for coin in coins[1:]:
        for i in range(coin, x + 1):
            dp[i] += dp[i - coin]
    return dp[x] > 0


def main():
    x = int(input())
    res = find_combinations(x)
    if res:
        print(1)
    else:
        print(0)


if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;

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

    int ret = 0;
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d)ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int main() {
    cout << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int n;
    cin >> n;
    double a[n];
    double ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans += ((double) 1 / a[i]);
    }

    cout << (double) 1 / ans;





}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  
  int result = 0,i;
  char s[4];
  
  scanf("%s",s);
  
  for(i = 0;i < 4;i++){
    if(s[i] == '1'){
      result++;
    }
  }
  
  printf("%d",result);
  return 0;
}

Measured memory_bytes: 128