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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

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


#define CMAX 200000

ll solve(int N, vi& _a) {

    vi a;
    a.reserve(N);
    int last = -1, cmax = -1;
    for(int ai: _a){
        if (ai == last) continue;
        a.pb(ai); last = ai;
        amax(cmax, ai);
    }
    N = a.size();

    vvi loc(cmax+1);
    rep(i,N) loc[ a[i] ].pb(i);

    vll dp(N+1, 0);
    dp[0] = 1;

    rep(i,N){
        int Ci = a[i];

        (dp[i+1] += dp[i]) %= MOD;

        auto it = upper_bound(ALL(loc[Ci]), i);
        if (it != loc[Ci].end()) {
            int j = *it;
            (dp[j] += dp[i]) %= MOD;
        }
    }

    return dp[N];
}

int main() {
    int N; scanf("%d", &N);
    vi a(N); rep(i,N) { scanf("%d", &a[i]); a[i]--; }
    cout << solve(N,a) << endl;
    return 0;
}


Measured memory_bytes: 14336
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }
        sc.close();

        Arrays.sort(a);

        int[] c = new int[n];

        if(n % 2 == 0){
            int[] b1 = new int[n/2];
            int[] b2 = new int[n/2];
            for(int i=0; i<n/2; i++){
                b1[i] = a[n/2 - i - 1];
                b2[i] = a[n/2 + i];
            }
            for(int i=0; i<n/2; i++){
                c[i*2] = b1[i];
                c[i*2+1] = b2[n/2-i-1];
            }
        }else{
            int[] b1 = new int[n/2];
            int[] b2 = new int[n/2];
            for(int i=0; i<n/2; i++){
                b1[i] = a[n/2 - i - 1];
                b2[i] = a[n/2 + i + 1];
            }
            if(Math.abs(a[n/2] - a[n/2-1]) < Math.abs(a[n/2] - a[n/2+1])){
                for(int i=0; i<n/2; i++){
                    c[i*2] = b1[i];
                    c[i*2+1] = b2[n/2-i-1];
                }
                c[n-1] = a[n/2];
            }else{
                for(int i=0; i<n/2; i++){
                    c[i*2+1] = b1[n/2-i-1];
                    c[i*2] = b2[i];
                }
                c[n-1] = a[n/2];
            }
            
        }

        long ans = 0;
        for(int i=0; i<n-1; i++){
            ans += Math.abs(c[i+1] - c[i]);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 50236
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i++)
#define RFOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i--)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
using ll = long long;

constexpr int lim = 1e5;
ll k, a[lim+1];

ll f(ll x, int i){
  return x - x%a[i];
}

ll g(ll n){
  FOR(i, 1, k+1) n = f(n, i);
  return n;
}

int main(){
  cin >> k;
  ll m = 0;
  FOR(i, 1, k+1){
    cin >> a[i];
    m = max(m, a[i]);
  }

  ll l=0, r=2+k*m;
  while(r-l > 1){
    ll mid = (l+r) / 2;
    if(g(mid) >= 2) r = mid; 
    else l = mid;
  }

  ll L = r;

  l=0; r=2+k*m;
  while(r-l > 1){
    ll mid = (l+r) / 2;
    if(g(mid) > 2) r = mid;
    else l = mid;
  }

  ll R = l;

  if(L > R) cout << -1 << endl;
  else cout << L << " " << R << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n;
char a[N];
int l[N],r[N],cnt,vis[N],f[N];
char q[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  for(int i=1;i<=n;i++){
    f[i]=i;
    cin>>a+1;cnt=0;
    int n=strlen(a+1);
    for(int j=1;j<=n;j++){
      if(a[j]=='('){
        q[++cnt]='(';
      }else{
        if(q[cnt]=='(')--cnt;
        else q[++cnt]=')';
      }
    }
    for(int j=1;j<=cnt;j++){
      if(q[j]=='(')l[i]++;
      else r[i]++;
    }
 
  }
  int L=0,R=0;
  sort(f+1,f+1+n,[](int x,int y){
    if(!r[x] && !r[y])return (int)(l[x]>l[y]);
    if(!l[x] && !l[y])return (int)(r[x]<r[y]);
    
    if(l[x]>=r[x] && l[y]<r[y])return 1;
    if(l[x]<r[x] && l[y]>=r[y])return 0;
    if(l[x]>=r[x] && l[y]>=r[y])return (int)(r[x]<r[y]);
    if(l[x]<=r[x]&&l[y]<=r[y])return (int)(l[x]>l[y]);
  });
  for(int i=1;i<=n;i++){
    if(L<r[f[i]])return cout<<"No\n",0;
    L-=r[f[i]];
    L+=l[f[i]];
  }
  if(!L)cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}

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

using namespace std;

int main()
{
	int n, m, f = 0;
	cin >> n;
	m = n;
	for (int i = 0; i < 9; i++)
		f += n % 10, n /= 10;
	cout << (m%f ? "No" : "Yes") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
const ll MOD=1000000007,INF=1e18;

int N,A,B,C;
int l[100010];

int dfs(int a,int b,int c,int d,int n){
    if(n==N){
        if(a&&b&&c)return (abs(A-a)+abs(B-b)+abs(C-c)+10*(N-3-d));
        else return INF;
    }
    int ret=INF;
    chmin(ret,dfs(a+l[n],b,c,d,n+1));
    chmin(ret,dfs(a,b+l[n],c,d,n+1));
    chmin(ret,dfs(a,b,c+l[n],d,n+1));
    chmin(ret,dfs(a,b,c,d+1,n+1));
    return ret;
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    cin>>N>>A>>B>>C;
    rep(i,0,N){
        cin>>l[i];
    }
    cout<<dfs(0,0,0,0,0)<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;
long long x,y,ans,sum=0;
int main(){
    cin>>x>>y;
    ans=((long long)(y/x));
    while(ans>=1)ans/=2,sum++;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
N,X = map(int,input().split())
A = list(map(int,input().split()))
B = [abs(X-i) for i in A]
ans = B[0]
for j in B:
    ans = gcd(ans, j)
print(ans)

Measured memory_bytes: 14252
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits



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


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n, k = MAP()

print(n-k+1)

Measured memory_bytes: 4400
N,K=map(int,input().split())
A=list(map(int,input().split()))
#最終的にすべて同じ値になるなら、最小値のほうから攻めるべき
#早いソートにしたほうがいいかも。2部探索とか
mini_index=A.index(1)
if N<=K:
    print(1)
else:
    length=K
    count=1
    while(True):
        length+=K-1
        count+=1
        if length>=N:
            print(count)
            break
        

Measured memory_bytes: 52652
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 4010;
const long long mod = 998244353;
long long dp[maxn][maxn];
int n;
int v[maxn][2], h[maxn][2] = {0};
int main()
{
	std::ios::sync_with_stdio(false);
	string s;
	cin >> s;
	n = s.size();
	for(int i = 0; i < s.size(); i ++)
	{
		int a = s[i] - '0';
		v[i + 1][0] = a;
		v[i + 1][1] = 2 - a;
		h[i + 1][0] = h[i][0] + v[i + 1][0];
		h[i + 1][1] = h[i][1] + v[i + 1][1];
	}
	dp[0][0] = 1;
	for(int i = 1; i <= 2 * n; i ++)
	{
		int a, b;
		a = h[min(i, n)][0];
		b = h[min(i, n)][1];
		for(int j = max(0, i - b); j <= a && j <= i; j ++)
			dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod;
	}
	cout << dp[n * 2][h[n][0]] << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main() {
	char a, b;
	cin >> a >> b;
	
	if (a == 'H') {
		cout << b << endl;
	} else {
		if (b == 'H') {
			cout << 'D' << endl;
		} else {
			cout << 'H' << endl;
		}
	}
	
	return 0;
}

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

typedef long long ll;

int main() {
    ll H, W;
    cin >> H >> W;
    vector<string> a(H);
    vector<ll> c(26, 0);
    rep(i, H) {
        cin >> a[i];
        rep(j, W) {
            c[a[i][j] - 'a']++;
        }
    }
    ll x4 = 0, x2 = 0, x1 = 0;
    rep(i, 26) {
        if (c[i] % 4 == 0) x4++;
        else if (c[i] % 2 == 0) x2++;
        else x1++;
    }
    if (H % 2 == 0) {
        if (W % 2 == 0) {
            if (x1 == 0 && x2 == 0) cout << "Yes\n";
            else cout << "No\n";
        } else {
            if (x1 == 0 && x2 <= H / 2) cout << "Yes\n";
            else cout << "No\n";
        }
    } else {
        if (W % 2 == 0) {
            if (x1 == 0 && x2 <= W / 2) cout << "Yes\n";
            else cout << "No\n";
        } else {
            if (x1 == 1 && x2 <= (H + W - 2) / 2) cout << "Yes\n";
            else cout << "No\n";
        }
    }
}

Measured memory_bytes: 256
S = list(input())
len_S = len(S)

for i in range(1, len_S):
    partial_S = S[:-i]
    len_partial_S = len(partial_S)
    if len_partial_S % 2 != 0:
        continue
    hf = int(len_partial_S / 2)
    if ''.join(partial_S[:hf]) == ''.join(partial_S[hf:]):
        print(len_partial_S)
        break


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

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

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

    int n, m;
    cin >> n >> m;
    vector<vi> a(m);
    for(int i=0; i<m; i++){
        int k;
        cin >> k;
        for(int j=0; j<k; j++){
            int tmp;
            cin >> tmp;
            a[i].push_back(tmp-1);
        }
    }
    vi p(m);
    for(int i=0; i<m; i++)
        cin >> p[i];
    int fin = 0;
    for(int i = 0; i < (1 << n); i++){
        vi b(m);
        vi subset;
        for(int j = 0; j < n; j++){
            if(i&(1<<j)) subset.push_back(j);
        }
        
        for(int k = 0; k<subset.size(); k++){
            for(int k2 = 0; k2<m; k2++){
                for(int k3 = 0; k3<a[k2].size(); k3++){
                    if(a[k2][k3] == subset[k])
                        b[k2]++;
                }
            }
        }
        int sol = 0;            
        for(int bi = 0; bi < b.size(); bi++)
            if(b[bi]%2 == p[bi])
                sol++;
        if(sol == m)
            fin++;
    }
    cout << fin;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    String S = scan.next();
    scan.close();
        
    int tmp = 0;
    StringBuilder res = new StringBuilder();
    for(int i=0; i<S.length(); i++) {
      tmp = (int)S.charAt(i)+N;
      tmp = tmp > 90 ? tmp-26 : tmp;
      res.append((char)tmp);
    }
    System.out.println(res.toString());
  }
}

Measured memory_bytes: 22100
#include <iostream>
#include <queue>

using namespace std;

int D[110]={0};
void bfs(int src,int n,int g[110][110]){

queue<int> Q;
Q.push(src);
D[src]=0;
while (! Q.empty()){
	int cur =Q.front();
	Q.pop();
	for(int r=0;r<n;r++){
		if (g[cur][r]==1&&D[r]==0){
			D[r]=D[cur]+1;
			Q.push(r);
		}
	}
}
	
}



int main() {
int n,g[110][110]={0};
cin>>n;
int j,num,t;
for(int k=0;k<n;k++){
cin>>j>>num;
for(int kk=0;kk<num;kk++){
	cin>>t;
	g[k][t-1]=1;
}
}
bfs(0,n,g);
cout<<"1 0"<<endl;
for(int a=1;a<n;a++){
	if(D[a]!=0){
	cout<<a+1<<" "<<D[a]<<endl;
}
else{
	cout<<a+1<<" -1"<<endl;
}
}
	return 0;
}

Measured memory_bytes: 1260
#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() {
  int k;
  string s;
  cin >> k >> s;
  string ans;
  char add;
  rep(i,k) {
    try {
      add = s.at(i);
    } catch(out_of_range) {
      break;
    }
    ans += add;
  }
  if (s.size() > k) ans += "...";
  cout << ans << endl;
  return 0;
}

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

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

  vector<int> t(n);
  for (int i = 0; i < n; i++) cin >> t[i];

  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (t[i + 1] - t[i] <= s)
      ans += t[i + 1] - t[i];
    else
      ans += s;
  }

  cout << ans + s << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
	long x = scanner.nextLong();
	long n = 100;
	int i=0;
	while (n<x) {
		i++;
		n+=n/100;
	}
	System.out.println(i);
	scanner.close();}}

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


/*
 * N=5
 * A={1,5,3,4,2}
 * i,j (i<j)
 * j-i = Aj+Ai
 * j-Aj=Ai+i
 * lj = ri
 */
int main()
{
	int N;
	cin>>N;
	map<ll,ll> r;
	map<ll,ll> l;
	rep(i,N)
	{
		ll a;
		cin>>a;
		l[(i+1)-a]++;
		r[a+(i+1)]++;
	}
	ll ans=0;
	for(pair<ll,ll> p : l)
	{
		ans+=p.second*r[p.first];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 37912
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  int h,w;
  cin>>h>>w;
  string s;
  for(int i=1;i<=h;i++){
    char c='A';
    for(int j=1;j<=w;j++){
      cin>>s;
      if(s=="snuke"){
        cout<<c<<i<<endl;
      }
      c++;
    }
  }
  return 0;
}


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

using namespace std;

int main()
{
  string s;
  int ans=0;

  cin >> s;

  for(int i=0;i<6;i++)if(s[i]=='A'&&s[i+1]=='C')ans = 1;

  if(ans==1)cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
typedef unsigned long long ull;
#define vvi std::vector<std::vector<int> >
#define vvs std::vector<std::vector<string> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  ll ans = 0;
  string s, S, t, T="";
  std::cin >> N;
  std::cin >> s;
  S = s.substr(0, N);
  t = s.substr(N);
  for(int i=0;i<N;i++) T+=t[N-1-i];
  std::vector<int> num(26, 0);
  for(int i=0;i<N;i++) num[S[i]-'a']++, num[T[i]-'a']--;
  bool flag = true;
  for(int i=0;i<26;i++) if(num[i]!=0) flag = false;
  vvs str = vv(0, 2, "", string);
  for(int i=0;i<(1<<N);i++){
    int n = i+(1<<20), count=0;
    string ah = "", bh = "";
    while(count<N){
      if(n%2==1) ah += T[count];
      if(n%2==0) bh += T[count];
      count++;
      n/=2;
    }
    str.push_back(std::vector<string> {ah, bh});
  }
  sort(str.begin(), str.end());
  for(int i=0;i<(1<<N);i++){
    int n = i + (1<<20), count=0;
    string ah="", bh="";
    while(count<N){
      if(n%2==1) ah += S[count];
      if(n%2==0) bh += S[count];
      count++;
      n/=2;
    }
    int k = upper_bound(str.begin(), str.end(), std::vector<string> {ah,bh}) - lower_bound(str.begin(), str.end(), std::vector<string> {ah, bh});
    ans += k;
  }
  std::cout << (!flag?0:ans) << '\n';
  return 0;
}


Measured memory_bytes: 22828
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
H = readInts()
ma = H[0]
for i in range(1,n):
    if ma < H[i]:
        H[i] -= 1
    if ma <= H[i]:
        ma =  H[i]
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 22000
#include <stdio.h>
int main() {
  int S, h, m, s;
  scanf("%d",&S);

  h = S / 60 / 60;
  m = S / 60 % 60;
  s = S % 60;

    printf("%d:%d:%d\n",h, m, s);
  return 0;
}

Measured memory_bytes: 592
#include<iostream>
using namespace std;
int main()
{
	int n,k,ans=1;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		if(ans<=k) ans*=2;
		else ans+=k;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    char num[7];
    cin >> num;
    int bee = 0;
    for(int i = 0;i < 3;i++){
        if(num[i] == '1'){
            bee++;
        }
    }
    cout << bee << endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int alice=0,bob=0;
  for(int i=0;i<N;i+=2){
    alice+=a.at(i);
  }
  for(int i=1;i<N;i+=2){
    bob+=a.at(i);
  }
  cout << alice-bob <<endl;
}


Measured memory_bytes: 256
line = input().rstrip()
count = 0


if 'R' in line:
  if line == 'RRR':
    print(3)
  elif line == 'RSR':
  	print(1)
  else:
    for i in range(3):
      if line[i] == 'R':
        count += 1
    print(count)
else:
  print(0)
    

Measured memory_bytes: 8908
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    sort(v.begin(),v.end());
    int ans=0;
    if(v[n/2-1]!=v[n/2]) ans=v[n/2]-v[n/2-1];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
int main()
{
int n,k;cin>>n>>k;
vector<int> h(n);
for(int &x : h)
scanf("%d",&x);
vector<int> dp(n,INF);
dp[0]=0;
for(int i=0;i<n;i++)
{
	for(int j=i+1;j<=i+k;j++)
	{if(j<n)
		dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
	}
}
printf("%d",dp[n-1]);
return 0;
}

Measured memory_bytes: 1024
package main
  
import (
    "fmt"
)

func main() {
    var n, x int
    fmt.Scan(&n, &x)
    var cnt, sum int
    cnt++
    for i := 0; i < n; i++ {
        var l int
        fmt.Scan(&l)
        sum += l
        if sum <= x {
            cnt++
        }
    }
    fmt.Println(cnt)
}


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

# from numba import njit

# input = stdin.readline

# @njit
def solve(d,next="A"):
  while len(d[next]) != 0:
    next = d[next].pop(0)
  return next



def main():
  d = {}
  d["A"] = list(input().upper())
  d["B"] = list(input().upper())
  d["C"] = list(input().upper())
  print(solve(d))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 8996
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char s1[1201],s2[1001];
int main()
{
    gets(s1);
    gets(s2);
    int n=strlen(s1);
    int m=strlen(s2); 
    sort(s1,s1+n);
    sort(s2,s2+m);
    reverse(s2,s2+m);
    for(int i=0;i<max(n,m);++i)
    {
        if(s1[i]<s2[i])
        {
            printf("Yes\n");
            return 0;
        }
        if(s1[i]>s2[i])
            break;
    }
    printf("No\n");
    return 0;
} 


Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	int n, t;
	int a, bef = -1;
	cin >> n >> t;
	ll sum = 0;
	for(int i = 0;i < n;i++){
		cin >> a;
		if(bef != -1){
			sum += min(a-bef, t);
		}
		bef = a;
	}
	sum += t;

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
  long long num;
  cin >> num;
  
  int rem = 0;
  string ans = "";
  
  while(num != 0){
    num--;
    rem = num % 26;
    num /= 26;
    ans = char('a' + rem) + ans;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int ans = 700;
char s[10];
int main(){
	scanf("%s", s + 1);
	for(int i = 1; i <= 3; ++i) ans += 100 * (s[i] == 'o');
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
N, Q, *ABPX = map(int, open(0).read().split())
AB, PX = ABPX[:2 * (N - 1)], ABPX[2 * (N - 1):]

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)

ans = [0] * (N + 1)
for p, x in zip(*[iter(PX)] * 2):
    ans[p] += x


stack = [(1, 0)]
while stack:
    v, p = stack.pop()
    for c in E[v]:
        if c == p:
            continue
        ans[c] += ans[v]
        stack.append((c, v))

print(*ans[1:])

Measured memory_bytes: 94828
using System;
using System.Collections.Generic;
using System.Linq;

namespace DiceInLine
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int diceAmount = int.Parse(input[0]);
            int chosenDice = int.Parse(input[1]);

            List<string> data = (Console.ReadLine().Split(' ').ToList());
            List<int> dicesValue = new List<int>();

            for (int i = 0; i < diceAmount; i++)
            {
                dicesValue.Add(int.Parse(data[i]));
            }

            double exceptedValue = 0.0;
            double[] output = new double[diceAmount];
            for (int i = 0; i < diceAmount; i++)
            {
                exceptedValue += (1.0 + dicesValue[i]) / 2;
                output[i] = exceptedValue;
            }

            double printValue = output[chosenDice - 1];            
            for (int i = 0; i + chosenDice < diceAmount; i++)
            {
                printValue = Math.Max(printValue, output[i + chosenDice] - output[i]);                
            }
            Console.WriteLine(printValue);            
        }
    }
}

Measured memory_bytes: 33628
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int l,j,i,n,cnt=0,g;
	cin>>n;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(l=1;l<=n;l++){
				g=__gcd(i,j);
				cnt+=__gcd(g,l);
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    vector<int> cup(3, 0);
    cup[0] = 1;
    char a, c, b;
    while (cin >> a >> c >> b) {
        swap(cup[a-'A'], cup[b-'A']);
    }
    
    cout << (char)('A' + (find(cup.begin(), cup.end(), 1) - cup.begin())) << endl;
    return 0;
}

Measured memory_bytes: 3020
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long[] a = new long[n];
		long ans=0;
		long[] front=new long[n];
		long[] back=new long[n];
		for(int i = 0; i<n; i++){
			a[i]= sc.nextLong();
		}
		front[0]=a[0];
		back[n-1]=a[n-1];
		for(int i = 1; i<n; i++){
			front[i]=gcd(a[i],front[i-1]);
			back[n-1-i]=gcd(back[n-i],a[n-1-i]);
		}
		for(int i = 0; i<n; i++){
			if(i==0){
				ans=Math.max(ans,back[1]);
			}else if(i==n-1){
				ans=Math.max(ans,front[n-2]);
			}else{
				ans=Math.max(ans,gcd(front[i-1],back[i+1]));
			}
		}
		System.out.println(ans);
	}
	private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}


Measured memory_bytes: 64264
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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




int main(){
    int N; cin >> N;
    vector<pair<string, int>> st(N);
    REP(i, N){
        cin >> st[i].first >> st[i].second;
    }
    string X; cin >> X;
    bool asleep = false;
    int ans = 0;
    REP(i, N){
        if(asleep) ans += st[i].second;
        else if(X == st[i].first) asleep = true;
    }
    cout << ans << endl;
    return 0;
}


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

int f(int n) {
  while (n > 9) n /= 10;
  return n;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> V(10, vector<int>(10));
  for (int i = 1; i <= N; i++) V.at(f(i)).at(i - i / 10 * 10)++;
  int sum = 0;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      sum += V.at(i).at(j) * V.at(j).at(i);
  cout << sum << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int x[6];
  int i;
  scanf("%d %d %d %d %d", &x[1],&x[2],&x[3],&x[4],&x[5]);
  
  for(i=1;i<=5;i++){
    if(x[i]==0)printf("%d", i);
  }
  
  return 0;
}




Measured memory_bytes: 1708
#include <iostream>
#include <algorithm>

using namespace std;

int main(){

    int n, m;
    cin >> n >> m;

    int nums[n];

    for (int i = 0; i < n; i++) cin >> nums[i];

    sort(nums, nums + n);

    int ans = 0;

    for (int i = n - m; i < n; i++){
        ans += nums[i];
    }

    cout << ans << endl;

    return 0; 
}

Measured memory_bytes: 256
import sys, os
from itertools import accumulate
import bisect

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

n = f()[0]
def get_mid(b, i):
    global n
    front_i_sum = b[i]

    idx1 = bisect.bisect_right(b, front_i_sum/2)
    if idx1 == 0:
        idx1 = 1
        max_fisrt = max(b[0], b[i]-b[0])
        min_first = min(b[0], b[i]-b[0])
    
    else:


        max1 = b[idx1]
        min1 = b[i] - b[idx1]

        max2 = b[i] - b[idx1-1]
        min2 = b[idx1-1]

        if max1 - min1 >= max2 - min2:
            max_fisrt = max2
            min_first = min2
        else:
            max_fisrt = max1
            min_first = min1


    idx2 = bisect.bisect_right(b, front_i_sum + (b[n-1] - b[i])/2)

    if idx2 == i+1:
        max_s = max(b[i+1]- b[i], b[n-1]- b[i+1])
        min_s = min(b[i+1]- b[i], b[n-1]- b[i+1])

    else:
        max1 = b[idx2] - front_i_sum
        min1 = b[n-1] - b[idx2]

        max2 = b[n-1] - b[idx2-1]
        min2 = b[idx2-1] - front_i_sum

        if max1 - min1 >= max2 - min2:
            max_s = max2
            min_s = min2
        else:
            max_s = max1
            min_s = min1
    
    return max(max_fisrt, max_s) - min(min_first, min_s)


def solve():
    a = f()
    b = list(accumulate(a))

    ans = int(2e14)
    for i in range(1, n-2):
        ans = min(ans, get_mid(b, i))

    print(ans)




solve()


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

int main()
{ 
  int a, b, c ;
  cin >> a >> b >> c ;
  if(a == b && b == c && c == a)
  {
    cout << "Yes" << endl ;
  }
  else
  {
    cout << "No" << endl ;
  }
  
}


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

int main()
{
	int T;
	cin >> T;
	vector<long long> N( T );
	vector<long long> A( T );
	vector<long long> B( T );
	vector<long long> C( T );
	vector<long long> D( T );
	for( int i = 0; i < T; i++ ) {
		cin >> N[i] >> A[i] >> B[i] >> C[i] >> D[i];
	}

	typedef pair<long long, long long> P;
	for( int i = 0; i < T; i++ ) {
		priority_queue<P, vector<P>, greater<P>> que;
		map<long long, long long> mp;
		long long ans = 1e18;

		auto push = [&]( long long cost, long long loc )
		{
			if( mp.count( loc ) && cost >= mp[loc] ) return;
			if( cost >= ans ) return;
			que.push( P( cost, loc ) );
			mp[loc] = cost;
		};

		push( 0, N[i] );
		while( !que.empty() ) {
			long long cost, loc;
			tie( cost, loc ) = que.top();
			que.pop();
			if( cost > ans ) break;
			if( loc <= 2e18 / D[i] ) ans = min( ans, cost + loc * D[i] );
			if( loc % 2 == 0 ) push( cost + A[i], loc / 2 );
			else {
				push( cost + A[i] + D[i], (loc - 1) / 2 );
				push( cost + A[i] + D[i], (loc + 1) / 2 );
			}
			if( loc % 3 == 0 ) push( cost + B[i], loc / 3 );
			else {
				int m = loc % 3;
				push( cost + B[i] + D[i] * m, (loc - m) / 3 );
				push( cost + B[i] + D[i] * (3 - m), (loc + (3 - m)) / 3 );
			}
			if( loc % 5 == 0 ) push( cost + C[i], loc / 5 );
			else {
				int m = loc % 5;
				push( cost + C[i] + D[i] * m, (loc - m) / 5 );
				push( cost + C[i] + D[i] * (5 - m), (loc + (5 - m)) / 5 );
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 4148
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <numeric>
using namespace std;


int main()
{
    int N,M,C;
    int B[30];
    int A[30][30];
    
    cin>>N>>M>>C;
    for(int i=1;i<M+1;i++){
        cin>>B[i];
    }
    
    for(int i=1;i<N+1;i++){
        for(int j=1;j<M+1;j++){
        cin>>A[i][j];
        }
    }
    
    int counter=0;
    
    for(int i=1;i<N+1;i++){
        int judge=0;
        for(int j=1;j<M+1;j++){
            judge+=B[j]*A[i][j];
        }
        if(judge+C>0){
            counter+=1;
        }
        
    }
    cout<<counter<<endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

bool judge(vector <int> A,int goal,bool orx);

int main(){
  string s;int x;int y;cin>>s>>x>>y;

  vector <int> partx(0); vector <int>  party(0);
  int cntx=0;int cnty=0;
  bool xturn=true;

  for(int i=0;i<s.size();i++){
    if(s[i]=='T' or i==s.size()-1){
      if(s[i] == 'F') {
        cntx++;cnty++;
      }
      if(xturn){
        partx.push_back(cntx);
        cntx=0;
      } else {
        party.push_back(cnty);
        cnty=0;
      }
      xturn = not xturn;
      continue;
    }

    if(xturn) cntx++;
    else cnty++;
  }
/*
  for (const auto& e : partx) {
  std::cout << e <<" ";//<<std::endl;
}
cout<<endl;
for (const auto& e : party) {
  std::cout << e <<" ";//<< std::endl;
}
cout<<endl;
*/
bool flagx=false,flagy=false;
if(partx.size()>0)
   flagx=judge(partx,x,true);
  //cout<<flagx<<endl;
if(party.size()>0)
   flagy=judge(party,y,false);
  //cout<<flagy<<endl;

bool flagx0= partx.size()==0 ;
bool flagy0= party.size()==0; 


  if(flagx0){
    if(x!=0) {
      cout<<"No"<<endl;
      return 0;
    }
    if(x==0){
      flagx=true;
    }
  }

 if(flagy0){
    if(y!=0) {
      cout<<"No"<<endl;
      return 0;
    }
    if(y==0){
      flagy=true;
    }
  }

    
  

 if(flagx and flagy ) cout<<"Yes"<<endl;
 else cout<<"No"<<endl;

return 0;
}

bool judge(vector <int> A,int goal,bool orx){
  set <int> Sp;
  set <int> Sn;

  Sp.insert(0);
  //vector <int>::iterator itr;
  for(int i=0;i<A.size();i++){

    //cout<<2<<endl;

    //set <int> ::iterator itr;
    

   for(auto itr = Sp.begin();itr != Sp.end() ; itr++){

    // cout<<1<<endl;
    if(i == 0 and orx){
      Sn.insert(*itr + A[i]);
      continue;
    }

     Sn.insert(*itr + A[i]);
     Sn.insert(*itr - A[i]);
  
   }

   if(i==A.size()-1) break;

   Sp = Sn;
   Sn.clear();

  }

/*
 for (const auto& e : Sn) {
  std::cout << e <<" ";//<<std::endl;
}
cout<<endl;
*/
  

return (Sn.find(goal) != Sn.end() );
  
}


Measured memory_bytes: 640
H, W = map(int, input().split())
S = ['' for _ in range(H)]
for i in range(H):
    S[i] = input()
DP = [[0 for _ in range(W)] for _ in range(H)]
if S[0][0] == '#':
    DP[0][0] = 1
for i in range(1,W):
    if S[0][i] == '#' and S[0][i-1] == '.':
        DP[0][i] = DP[0][i-1] + 1
    else:
        DP[0][i] = DP[0][i-1]
for h in range(1,H):
    for w in range(W):
        if w == 0:
            if S[h][w] == '#' and S[h-1][w] == '.':
                DP[h][w] = DP[h-1][w] + 1
            else:
                DP[h][w] = DP[h-1][w]
        else:
            if S[h][w] == '#' and S[h-1][w] == '.':
                r = DP[h-1][w] + 1
            else:
                r = DP[h-1][w]
            if S[h][w] == '#' and S[h][w-1] == '.':
                c = DP[h][w-1] + 1
            else:
                c = DP[h][w-1]
            DP[h][w] = min(r, c)
print(DP[H-1][W-1])


Measured memory_bytes: 3188
fn main() {
    let mut r_x = String::new();
    std::io::stdin().read_line(&mut r_x).unwrap();
    let x: i64 = r_x.trim().parse().unwrap();

    for a in 0..2048 as i64 {
        for b in 0..2048 as i64 {
            if a.pow(5) - b.pow(5) == x {
                println!("{} {}", a, b);
                std::process::exit(0)
            }
            if a.pow(5) + b.pow(5) == x {
                println!("{} {}", a, -b);
                std::process::exit(0)
            }
        }
    }
}


Measured memory_bytes: 2136
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i + 100*j + 50*k == X:
                count += 1

print(count)

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;

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

void Main()
{
	int a,b; cin>>a>>b;
	if(1<= a && 9>= a && 1<= b && 9>= b ){
		cout << a*b << endl;
	}
	else{
		cout << -1 << endl;
	}

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#coding: utf-8

N = int(input())
A0 = list(map(int, input().split()))
A1 = list(map(int, input().split()))

sum = []

for n in range(N):
    tmp = 0
    if(n==0):
        tmp += A0[0]
        for j in range(N):
            tmp += A1[j]
        sum.append(tmp)
    else:
        for i in range(n):
            tmp += A0[i]
        for j in range(n-1, N):
            tmp += A1[j]
        sum.append(tmp)

ans = max(sum)

print(ans)

Measured memory_bytes: 3064
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
        x: i64,
        y: i64,
        xs: [i64;n],
        ys: [i64;m],
    }

    if x>=y {
        println!("War");
        return;
    }

    let mut z_can: Vec<i64> = Vec::new();
    for i in x+1..y+1 {
        z_can.push(i);
    }

    let mut ok = true;
    for i in 0..z_can.len() {
        ok = true;
        for j in 0..n {
            if xs[j]>=z_can[i] {
                ok = false;
            }
        }
        for j in 0..m {
            if ys[j]<z_can[i] {
                ok = false;
            }
        }
        if ok==true {
            break;
        }
    }

    if ok==true {
        println!("No War");
    } else {
        println!("War");
    }

}


Measured memory_bytes: 2152
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define len(val) static_cast<long long>(val.size())
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
typedef pair<int, int> P;


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

    int N, M;
    cin >> N >> M;
    int X[M];
    rep(i, M) cin >> X[i];
    sort(X, X+M);

    int A[M-1];
    rep(i, M-1){
        A[i] = X[i+1]-X[i];
    }
    sort(A, A+M-1);
    int ans = 0;
    rep(i, M-1-(N-1)){
        ans += A[i];
    }
    cout << ans << endl;
}


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

class bilding{
public:
  int room[3][10]; // [floor][room]
}build[4];

int main(){
  int n, b, f, r, v;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> b >> f >> r >> v;
    build[b-1].room[f-1][r-1] += v;
  }

  for(int k=0; k<4; k++){
    for(int j=0; j<3; j++){
      for(int i=0; i<10; i++)
        cout << " " << build[k].room[j][i];
      cout << endl;
    }
    if(k < 3) cout << "####################\n";
  }
  return 0;
}



Measured memory_bytes: 3132
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
typedef complex<double> P;
const double eps = 1e-11;
int vex[4] = {1, 0, -1, 0};
int vey[4] = {0, 1, 0, -1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD = 1000000007;
int main()
{
    int N, a[100005];
    map<int, int> cnt;
    cin >> N;
    lli ans = 0;
    rep(i, N)
    {
        cin >> a[i];
        a[i]--;
    }
    rep(i, N)
    {
        if (i == a[a[i]])
            ans++;
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 640
N,K=map(int, input().split())
A=tuple(map(int,input().split()))
l=[0]*40
for i in A:
    b=bin(i)
    for i in range(-1,1-len(b),-1):
        if b[i]=="1":
            l[i]+=1
x=[0]*40
xi=0
for i in range(40):
    if l[i]<=N//2 and xi+2**(39-i)<=K:
        x[i]=1
        xi+=2**(39-i)
a=0
for i in range(40):
    if x[i]:
        a+=(N-l[i])*2**(39-i)
    else:
        a+=l[i]*2**(39-i)
print(a)

Measured memory_bytes: 72208
from string import ascii_lowercase

cd = {c: 1 << i for i, c in enumerate(ascii_lowercase)}
bt = set(cd.values())
bt.add(0)


def solve(s):
    a, b = [], 0
    for c in s:
        b ^= cd[c]
        a.append(b)
    if a[-1] == 0:
        return 1

    dp = {0: 0}
    for b1 in a:
        for b2 in bt:
            b3 = b1 ^ b2
            if b3 not in dp:
                continue
            if b1 in dp:
                dp[b1] = min(dp[b1], dp[b3] + 1)
            else:
                dp[b1] = dp[b3] + 1
    return dp[a[-1]]


print(solve(input()))


Measured memory_bytes: 36032
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

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

ll dp[210][10010];
int w[210];
int sum[210];
const ll MOD = 1000000007;

int main(void) {
    int N, W;
    cin >> N >> W;
    for (int i = 1; i <= N; i++) {
        cin >> w[i];
    }
    sort(w, w+N+1);
    for (int i = 1; i <= N; i++) {
        sum[i] = sum[i-1] + w[i];
    }
    if (sum[N] <= W || N == 1) {
        cout << 1 << endl;
        return 0;
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        int rest = W - sum[i];
        if (rest < 0) break;
        for (int j = i+1; j <= N; j++) {
            for (int k = sum[i]; k <= W; k++) {
                dp[j][k] = 0;
            }
        }
        dp[i+1][sum[i]] = 1;
        for (int j = i+1; j < N; j++) {
            for (int k = sum[i]; k <= W; k++) {
                if (dp[j][k] == 0) continue;
                dp[j+1][k] += dp[j][k];
                int tmp = k+w[j+1];
                if (tmp <= W) {
                    dp[j+1][tmp] += dp[j][k];
                }
            }
        }
        for (int j = W-w[i+1]+1; j <= W; j++) {
            ans = (ans + dp[N][j]) % MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17468
#include<iostream>

using namespace std;

int main() {
	int k, s, ans=0;
	cin >> k >> s;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= x; y++) {
			for (int z = 0; z <= y; z++) {
				if (x + y + z == s) {
					switch ((x == y) + (y == z)) {
					case 0:
						ans += 6;
						break;
					case 1:
						ans += 3;
						break;
					case 2:
						ans += 1;
						break;
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var dp []int64

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}
func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n int
	fmt.Sscan(getNextLine(scanner), &n)
	aList := make([]int, n)
	hList := make([]int, n)
	h := strings.Split(getNextLine(scanner), " ")
	a := strings.Split(getNextLine(scanner), " ")
	for i := 0; i < n; i++ {
		fmt.Sscan(h[i], &hList[i])
		fmt.Sscan(a[i], &aList[i])
	}

	segSize := 1
	for segSize < n {
		segSize = segSize << 1
	}
	dp = make([]int64, segSize*2)
	for i := 0; i < n; i++ {
		dp[segSize-1+hList[i]-1] = int64(aList[i]) + query(0, hList[i]-1, 0, 0, segSize)
		update(segSize - 1 + hList[i] - 1)
	}
	fmt.Println(query(0, n, 0, 0, n))
}

func query(a int, b int, k int, l int, r int) int64 {
	if b <= l || r <= a {
		return int64(0)
	}
	if a <= l && r <= b {
		return dp[k]
	}
	vl := query(a, b, k*2+1, l, (l+r)/2)
	vr := query(a, b, k*2+2, (l+r)/2, r)
	if vl < vr {
		return vr
	}
	return vl
}

func update(i int) {
	for i > 0 {
		i = (i - 1) / 2
		dp[i] = dp[i*2+1]
		if dp[i] < dp[i*2+2] {
			dp[i] = dp[i*2+2]
		}
	}
}


Measured memory_bytes: 34304