akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    string s;
    cin >> s;
    if (s[s.size() - 1] == 's')
        s += "es";
    else
        s += "s";
    cout << s << endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,a=0,b=0,c=0,d=0;
    cin>>N;
    string S[N];
    for(int i=0;i<N;i++)
    {
        cin>>S[i];

    }

     for(int i=0;i<N;i++)
    {
        if(S[i]=="AC")        {
            a++;
        }
        else if(S[i]=="WA")
        {
            b++;
        }
        else if(S[i]=="TLE")
        {
            c++;
        }
        else if(S[i]=="RE")
        {
            d++;
        }

    }


    cout<<"AC x"<<" "<<a<<endl;
    cout<<"WA x"<<" "<<b<<endl;
    cout<<"TLE x"<<" "<<c<<endl;
    cout<<"RE x"<<" "<<d<<endl;
    return 0;
}


Measured memory_bytes: 6716
#include<bits/stdc++.h>
using namespace std;
int main(){
  int r,D,X[11];
  cin>>r>>D>>X[0];
  for(int i=1;i<11;i++) {
    X[i]=r*X[i-1]-D;
    cout<<X[i]<<" "<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

using namespace std;
#define md 1000000007
#define itn int
#define pb push_back
#define mp make_pair
#define ull unsigned long long int
#define ll long long int
#define ppi pair<int, int>
#define ppl pair<ll, ll>
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ff first
#define lb lower_bound
#define ub upper_bound
#define ss second
#define inf 1e9
#define enld '\n'
#define cuot cout
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define trace4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f)                                               \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl
#define trace(v)                                                               \
  for (auto it = v.begin(); it != v.end(); it++)                               \
    cerr << *it << " ";                                                        \
  cerr << endl;
#define linf 1e18
#define reset(x) memset(x, 0, sizeof(x))
#define rep(i, a, b) for (int i = a; i < b; i++)

using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    oset;

void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int par[100005];
int rankk[100005];
int findd(int x){
    if(par[x]==x)return x;
    return par[x]=findd(par[x]);
}

void unionn(int xx,int yy){
    int x=findd(xx);
    int y=findd(yy);
    if(rankk[x]<rankk[y]){
        par[x]=y;
    }
    else
        par[y]=x;
    if(rankk[x]==rankk[y])
        rankk[x]++;
}

void solve() {
    ll m,k;cin>>m>>k;
    if(k>= (1<<m)){
        cout<<-1;return;
    }       
    if(m==1 && k==1){
        cout<<-1;return;
    }
    if(m==1 && k==0){
        cout<<"0 0 1 1";return;
    }

    rep(i,0,(1<<m)){
        if(i==k)continue;
        cout<<i<<" ";
    }
    cout<<k<<" ";
    for(int i=(1<<m)-1;i>=0;i--){
        if(i==k)continue;
        cout<<i<<" ";
    }
    cout<<k<<endl;
}
int main() {
  fastio();
  int t;
  t = 1;
  //   cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
A - Rated for Me
https://beta.atcoder.jp/contests/abc104/tasks/abc104_a

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    R = int(input())
    if R < 1200:
        print('ABC')
    elif R < 2800:
        print('ARC')
    else:
        print('AGC')


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i,now = 0,ans = -100100100100100;scanf("%lld",&n);
  ll a[n*3],l[n+1],r[n+1];priority_queue<ll,vector<ll>,greater<ll>> RED;priority_queue<ll> BLUE;
  for(i=0;i<n*3;i++) scanf("%lld",&a[i]);
  for(i=0;i<n;i++){
    now += a[i];RED.push(a[i]);
  }
  for(i=n;i<=n*2;i++){
    l[i-n] = now;RED.push(a[i]);
    now = now+a[i]-RED.top();RED.pop();
  }
  now = 0;
  for(i=n*3-1;i>=n*2;i--){
    now += a[i];BLUE.push(a[i]);
  }
  for(i=n*2-1;i>=n-1;i--){
    r[i+1-n] = now;BLUE.push(a[i]);
    now = now+a[i]-BLUE.top();BLUE.pop();
  }
  for(i=0;i<=n;i++) ans = max(ans,l[i]-r[i]);
  printf("%lld\n",ans);
}

Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
int main(){
	deque<int>q;
	int a,b,c,n;cin>>n;
	while(n--){
		cin>>a;
		if(a==0){
			cin>>b>>c;
			if(b==0)q.push_front(c);
			else q.push_back(c);
		}else if(a==1){
			cin>>b;
			cout<<q[b]<<"\n";
		}else if(a==2){
			cin>>b;
			if(b==0)q.pop_front();
			else q.pop_back();
		}
	}
	return 0;
}


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

#define LL long long
const int N = 2e5;
int n, cnt;
int fa[N], ff[N];
LL di[N], siz[N];
map <LL, int> val;
pair <int, int> edges[N];
int ord[N];
int get_f(int t)
{
    if (ff[t] == t) return t;
    else return ff[t] = get_f(ff[t]);
}
vector <int> bi[N];
int tss[N];
LL sum[N];
void dfs1(int t, int f = 0)
{
    tss[t] = 1;
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
        {
            dfs1(bi[t][i], t);
            sum[t] += sum[bi[t][i]] + tss[bi[t][i]];
            tss[t] += tss[bi[t][i]];
        }
}
void dfs2(int t, int f = 0, LL u = sum[1])
{
    if (u != di[t]) {puts("-1"); exit(0);}
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
            dfs2(bi[t][i], t, u + n - 2 * tss[bi[t][i]]);
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) scanf("%lld", &di[i]);
    for (int i = 1; i <= n; ++ i) ord[i] = i, val[di[i]] = i, ff[i] = i;
    sort(ord + 1, ord + n + 1, [=](int a, int b) {return di[a] > di[b];});
    for (int i = 1; i < n; ++ i)
    {
        int p = ord[i];
        siz[p] += 1;
        LL q = di[p] + siz[p] * 2 - n;
        if (!val.count(q)) {puts("-1"); return 0;}
        fa[p] = val[q];
        if (get_f(p) == get_f(fa[p])) {puts("-1"); return 0;}
        ff[get_f(p)] = get_f(fa[p]);
        siz[fa[p]] += siz[p];
        bi[p].push_back(fa[p]);
        bi[fa[p]].push_back(p);
        edges[i] = make_pair(p, fa[p]);
    }
    dfs1(1);
    dfs2(1);
    for (int i = 1; i < n; ++ i) printf("%d %d\n", edges[i].first, edges[i].second);
}


Measured memory_bytes: 29184
n,t=list(map(int,input().split()))
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))

m=99999
for i in range(n):
    if l[i][1]<=t:
        m=min(l[i][0],m)

if m==99999:
    print("TLE")
else:
    print(m)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int K;cin >> K;
    int M = s.size();
    vector<int> rests(M);
    rep(i,M){
        rests[i]=(int)('z'-s[i])+1;
        if(s[i]=='a')rests[i]=0;
    }
    int i=0;
    for(int i=0;i<M;i++){
        if(K>=rests[i]){
            s[i]='a';
            K-=rests[i];
        }
    }
    K%=26;
    rep(i,K){
        s[M-1]=(char)(s[M-1]+1);
        if(s[M-1]=='{')s[M-1]='a';
    }
    cout << s << endl;
    return 0;
}

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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
//int a[N+2];

int32_t  main(){
	IOS;
  int n;cin>>n;
  string s;cin>>s;
  int r=0,b=0;
  for(auto it:s){
    if(it=='R')r++;
    else b++;
  }
  if(r>b)cout<<"Yes\n";
  else cout<<"No"<<endl;

  return 0;
}



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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);

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

	cout << a.back() - a.at(0) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    string s; cin>>s;

    int ok = 0, ng = n / 2 + 1;
    while(ng - ok > 1){
        int mid = (ok + ng) / 2;

        bool valid = false;
        map<string, P> string_index;
        for(int i=0; i+mid<=n; i++){
            string t = s.substr(i, mid);
            auto itr = string_index.find(t);

            if(itr == string_index.end()){
                string_index[t] = P(i, i + mid - 1);
            }
            else{
                int ch = i;
                int ph, pt;
                tie(ph, pt) = string_index[t];
                if(pt < ch){
                    valid = true;
                    break;
                }
            }
        }

        if(valid) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

    return 0;
}


Measured memory_bytes: 6656
import sys
N = int(input())
S = input()

if len(S) == 1:
  print('No')
  sys.exit(0)
elif len(S) % 2:
  print('No')
  sys.exit(0)
else:
  l = int(len(S) / 2)
  a = S[:l]
  b = S[l:]
  if a == b:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!

        Scanner sc = new Scanner (System.in);
        
    String x=sc.nextLine();
    String y=sc.nextLine();
    
    int c=0;
    int z=0;
    
  for(int i=0;i<x.length();i++){
      char xx=x.charAt(i);
      char yy=y.charAt(i);
      
      if(xx!=yy){
        c++;
      }
      
      
  }
  System.out.println(c);
    
        
    
    }
}


Measured memory_bytes: 42204
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  cin >> N;
  int ans = (N + 2 - 1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long q,h,s,d,n,a;
    cin >> q >> h >> s >> d >> n;
    a = min({4*q,2*h,s});
    if(2*a>d)
    cout << (n/2)*d+a*(n%2) << endl;
    else
    cout << n*a << endl;
}


Measured memory_bytes: 256
import sys
INPUT = sys.stdin.readline
MOD = 10 ** 9 + 7

def SINGLE_INT(): return int(INPUT())
def MULTIPLE_INT_LIST(): return list(map(int, INPUT().split()))
def MULTIPLE_INT_MAP(): return map(int, INPUT().split())
def SINGLE_STRING(): return INPUT()
def MULTIPLE_STRING(): return INPUT().split()

def solve(n, m):
    floors = [0] * (n + 1)
    floors[0] = 1
    floors[1] = 1

    last, current = 0,0

    for i in range(m):
        if i == 0:
            current = SINGLE_INT()
            floors[current] = -1

        else:
            last = current
            current = SINGLE_INT()
            floors[current] = -1
            if current == last + 1:
                return 0

    for i in range(2, n+1):
        if floors[i] == -1:
            continue
        else:
            if floors[i-2] > 0:
                floors[i] += floors[i-2]
            if floors[i-1] > 0:
                floors[i] += floors[i-1]

        floors[i] %= MOD

    return(floors[-1])


N, M = MULTIPLE_INT_MAP()

if N == 1:
    print(1)

elif N > 1:
    print(solve(N,M))

Measured memory_bytes: 7764
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
check = [0] * n
for i in range(n):
    check[i] = a[i] - b[i]
check.sort()
m_check = sorted(check, reverse=True)
m_cnt = 0
p = 0
ans = 0
for i in range(n):
    if check[i] < 0:
        p += check[i]
        ans += 1
    else:
        if p >= 0:
            print(ans)
            exit()
        else:
            p += m_check[m_cnt]
            m_cnt += 1
            ans += 1
if p >= 0:
    print(ans)
else:
    print(-1)


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, Q;
int A[110000], ap[110000], B[110000], C[110000];
signed main() {
    cin >> N;
    int ans = 0;
    rep(i, N) {
        cin >> A[i];
        ap[A[i]]++;
        ans += A[i];
    }
    cin >> Q;
    rep(i, Q) {
        cin >> B[i] >> C[i];
        ans += (C[i] - B[i]) * ap[B[i]];
        ap[C[i]] += ap[B[i]];
        ap[B[i]] = 0;
        cout << ans << endl;
    }
}


Measured memory_bytes: 6760
#include<bits/stdc++.h>
#define il inline
#define stt static
#define rg register
#define ll long long
#define db double
#define pii pair<int,int>
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define y1 substitute_of_y1
#define DEBUG(x) cerr<<#x" = "<<x<<endl;
using namespace std;

template<typename T> il T rd(){
	T nmb=0;int sgn=0;char chr=getchar();
	while(!isdigit(chr)){if(chr=='-')sgn=1;chr=getchar();}
	while(isdigit(chr)){nmb=(nmb<<3)+(nmb<<1)+chr-'0';chr=getchar();}
	return sgn?-nmb:nmb;
}
template<typename T> void wt(T nmb){
	if(nmb>9)wt(nmb/10);
	putchar(nmb%10+'0');
}
template<typename T> il void cmax(T &x,T y){x=x>y?x:y;}
template<typename T> il void cmin(T &x,T y){x=x<y?x:y;}
inline void proc_status(){
	ifstream t ("/proc/self/status");
	cerr<<string(istreambuf_iterator<char>(t),istreambuf_iterator<char>())<<endl;
	/*freopen("/proc/self/status","r",stdin);
	char ch[100];
	while(scanf("%s",ch)!=EOF)cerr<<ch<<endl;*/
}

const int N=410,M=1e5+10;

int n,m;
int g[M][3];

bitset<N>S[N];
int Flg[N];

int main(){
	n=rd<int>(),m=rd<int>();
	for(int k=1;k<=m;++k)
		g[k][1]=rd<int>(),g[k][2]=rd<int>();
	for(int i=1;i<=n;++i){
		S[i][i]=Flg[i]=1;
		for(int k=m;k;--k){
			if(S[i][g[k][1]]&&S[i][g[k][2]]){Flg[i]=0;break;}
			if(S[i][g[k][1]])S[i][g[k][2]]=1;
			else if(S[i][g[k][2]])S[i][g[k][1]]=1;
		}
	}
	int Ans=0;
	for(int i=1;i<n;++i)
		for(int j=i+1;j<=n;++j)
			if(Flg[i]&&Flg[j]&&(S[i]&S[j]).count()==0)
				++Ans;
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 1408
# 解説AC
mod = 10 ** 9 + 7
n, k = map(int, input().split())
dp = [-1] * (k + 1)
ans = 0
for i in range(k, 0, -1):
    dp[i] = pow(k // i, n, mod)
    t = 0
    t += 2 * i
    while t <= k:
        dp[i] -= dp[t]
        dp[i] %= mod
        t += i
    ans += i * dp[i]
    ans %= mod
print(ans)


Measured memory_bytes: 68584
from sys import stdin
N = int(stdin.readline().rstrip())
A = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(2)]

dp = [[0] * N for _ in range(2)]
for n in range(N):
    dp[0][n] = sum(A[0][:n + 1])
dp[1][0] = A[0][0] + A[1][0]
for n in range(1, N):
    dp[1][n] = max(dp[0][n], dp[1][n - 1]) + A[1][n]
print(dp[1][N - 1])


Measured memory_bytes: 38384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <map>
#include <cmath>
using namespace std;

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

typedef long long ll;

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

int main() {
    int n;
    cin >> n;
    char a[n], b[n], c[n];
    cin >> a;
    cin >> b;
    cin >> c;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if ((a[i] == b[i]) && (b[i] == c[i]))
            continue;
        if ((a[i] == b[i]) || (b[i] == c[i]) || (c[i] == a[i])){
            ans++;
        } else {
            ans += 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
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; }
using namespace std;

signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<int> w(n);
    rep(i,n)cin>>w[i];

    int ans=INF;
    rep(i,n+1){
        int s1=0,s2=0;
        rep(j,n){
            if(j<=i)s1+=w[j];
            else s2+=w[j];
        }
        chmin(ans,abs(s1-s2));
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
package main

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

func main() {
	n := nextInt()
	k := nextInt()

	if n <= k {
		fmt.Println(dupcomb(n, n))
		return
	}

	ans := mint(0) // 移動なし

	for i := 0; i <= k; i++ {
		a := comb(n, i).mul(dupcomb(n-i, i)) // 0人の部屋の数 * 残りの人の配置
		ans = ans.add(a)
	}

	fmt.Println(ans)
}

var facts []mint  // facts[i] = i!
var ifacts []mint // ifacts[i] = i!の逆元

// nの階乗までを初期化します
func initFact(n int) {
	if len(facts) == 0 {
		facts = []mint{mint(1)}
		ifacts = []mint{mint(1)}
	}

	m := mint(n)
	for i := mint(len(facts)); i <= m; i++ {
		facts = append(facts, facts[i-1].mul(i))
		ifacts = append(ifacts, ifacts[i-1].mul(i.pow(mod-2)))
	}
}

// perm はnPkを返します
func perm(n, k int) mint {
	if n < k {
		return 0
	}
	initFact(n)
	return ifacts[n-k].mul(facts[n])
}

// comb はnCkを返します
func comb(n, k int) mint {
	if n == 0 && k == 0 {
		return mint(1)
	} else if n < k || n < 0 {
		return mint(0)
	}
	initFact(n)
	return facts[n].mul(ifacts[n-k]).mul(ifacts[k])
}

// dupcomb はnHkを返します
func dupcomb(n, k int) mint {
	return comb(n+k-1, n-1)
}

type mint int64

var mod = mint(1e9 + 7)

// add は a + bを返します
func (a mint) add(b mint) mint {
	return (a + b) % mod
}

// sub は a - bを返します
func (a mint) sub(b mint) mint {
	return (a - b + mod) % mod
}

// mul は a * bを返します
func (a mint) mul(b mint) mint {
	return (a * (b % mod)) % mod
}

// div は a/bを返します
func (a mint) div(b mint) mint {
	return a.mul(b.inv())
}

// inv は aの逆元を返します
func (a mint) inv() mint {
	// 拡張ユークリッドの互除法
	b := mod
	u := mint(1)
	v := mint(0)
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	return (u + mod) % mod
}

// pow は a ^ bを返します
func (a mint) pow(b mint) mint {
	ans := mint(1)

	for b != 0 {
		if b&1 == 1 {
			ans = ans.mul(a)
		}
		a = a.mul(a)
		b = b >> 1
	}
	return ans
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


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

using namespace std;
using ll = long long;

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

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

  vector<int> id(m, -1);
  vector<int> a;
  int len = 0;
  ll sum = 0;
  while (id[x] == -1) {
    a.push_back(x);
    id[x] = len;
    ++len;
    sum += x;
    x = x * x % m;
  }

  int c = len - id[x];
  ll s = 0;
  for (int i = id[x]; i < len; ++i) s += a[i];

  ll ans = 0;
  if (n <= len) {
    rep(i, n) ans += a[i];
  } else {
    ans += sum;
    n -= len;
    ans += s * (n / c);
    n %= c;
    rep(i, n) ans += a[id[x] + i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3960
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

typedef long long ll;

int main(){
  ll k, n;
  cin >> k >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  
  ll max_a = 0ll;
  ll dis = 0ll;
  rep(i, n){
    if(i == n-1) dis = k - a[i] + a[0];
    else dis = a[i+1] - a[i];
    if(dis > max_a) max_a = dis;
  }
  
  cout << k - max_a;
  
  return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000007;
const long long INF = 1LL << 60;
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; }

ll abc[100100][3]{};
ll dp[100100][3]{};

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> abc[i][j];
    for (int a = 0; a < N; ++a) {
        for (int b = 0; b < 3; ++b) {
            for (int c = 0; c < 3; ++c) {
                if (b == c) continue;
                chmax(dp[a+1][c], dp[a][b] + abc[a][c]);
            }
        }
    }
    ll res = 0;
    for (int i = 0; i < 3; ++i) chmax(res, dp[N][i]);
    cout << res << endl;
    return 0;
}

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

int main() {
  string s;
  while (cin >> s, s != "#") {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<vector<char>> m;
    vector<char> t;
    for (auto e : s) {
      if (e == '/') {
        m.push_back(t);
        t.clear();
      } else if (e == 'b') {
        t.push_back('b');
      } else {
        for (int i = 0; i < e - '0'; i++) t.push_back('.');
      }
    }
    m.push_back(t);
    m[a - 1][b - 1] = '.';
    m[c - 1][d - 1] = 'b';
    string r;
    for (auto l : m) {
      for (auto e : l) {
        if (e == 'b') {
          r.push_back('b');
        } else if ('0' < r.back() && r.back() <= '9') {
          (*r.rbegin())++;
        } else {
          r.push_back('1');
        }
      }
      r.push_back('/');
    }
    r.pop_back();
    cout << r << endl;
  }
}



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

int main(){
    int n; cin>>n;
    string s; cin>>s;
    map<char,set<int>> mp;

    for(int i = 0; i < (int)s.length(); i++){
       mp[s[i]].insert(i+1);
    }

    int q;cin >> q;
    while(q--){
        int a;
        cin>>a;
        if(a == 1){
            int i;char t;
            cin>>i>>t;
            mp[s[i-1]].erase(i);
            s[i-1] = t;
            mp[t].insert(i);
        }
        if (a == 2){
            int l,r ;cin>>l>>r;
            int count = 0;
            for(char a = 'a'; a <= 'z'; a++){
                auto idx = mp[a].lower_bound(l);
                if (idx == mp[a].end()) continue;
                if (*idx>=l && *idx<=r) count++;
                //if(*idx != l && idx == mp[a].begin() && *idx>r) continue;
                //cout<<a<<" "<<(*idx)<<endl;
            }
            cout<<count<<endl;
        }
    }
}


Measured memory_bytes: 24196
SA, SB, SC = input(), input(), input()
turn = 'a'
while 1:
  if turn == 'a':
    if len(SA) == 0:break
    turn = SA[0]
    SA = SA[1:]
  elif turn == 'b':
    if len(SB) == 0:break
    turn = SB[0]
    SB = SB[1:]
  else:
    if len(SC) == 0:break
    turn = SC[0]
    SC = SC[1:]
print(turn.upper())

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (i = 0; i < n; i++)
//const long long INF = 1LL << 60;

  long long V[3001][3001];
long long dp[3001][3001][5];



int main()
{


    int i, j, k, R, C, K;
    cin >> R >> C >> K;
    memset(V, 0, sizeof(V));
    memset(dp, 0, sizeof(dp));
    int r, c, v;
    rep(i, K){
        cin >> r >> c >> v;
        V[r-1][c-1]=v;
    }

    dp[0][0][1] = V[0][0];

    rep(i, R){ rep(j, C) { rep(k, 4){
        // to right
        dp[i][j+1][k+1]=max(dp[i][j+1][k+1],dp[i][j][k]+V[i][j+1]);
        dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
        // to down
        dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][k]+V[i+1][j]);
        dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
    }}}

    long long int ans=0;
    rep(i,4) ans=max(ans,dp[R-1][C-1][i]);

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


Measured memory_bytes: 425804
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        string s = Console.ReadLine();
        int L = int.Parse(s.Split(' ')[0]);
        int R = int.Parse(s.Split(' ')[1]);

        int ans = 2020;

        if (R - L >= 2019) {
            ans = 0;
            goto Go;
        } else if (L % 2019 < R % 2019) {
            L = L % 2019;
            R = R % 2019;
        } else {
            ans = 0;
            goto Go;
        }

        for (int i = L; i <= R - 1; i++) {
            for (int j = i + 1; j <= R; j++) {
                int X = (i * j) % 2019;
                ans = Math.Min(ans, X);
            }
        }
        Go:

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>

#include <algorithm>

using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const ll INF = 1ll << 60;

ll MOD = 1e9 + 7;

int main()
{

    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    int ans = max(0, (b + c - a));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    
    cin >> a >>b;
    if(a > b){
        cout << "a > b" << endl;
    } else if(a < b){
        cout <<"a < b" << endl;
    }else if(a == b){
        cout << "a == b" << endl;
    }
    return 0;
}



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

int n;
int arr[100100]={};
bool cek[100100];
	
int main(){
	scanf("%d",&n);
	
	for(int i=1;i<=n;i++) scanf("%d",&arr[i]);
	
	int cnt=0, idx=1, now, wew=0;
	cek[idx] = true;
	now = arr[idx]; 
	idx = now;
	
	while(idx!=2){
		if(cek[idx]==false) cek[idx] = true;
		else{
			wew=1;
			break;
		}
		
		now = arr[idx];
		idx = now;
		cnt++;
	}
	
	if(wew==1) printf("-1\n");
	else printf("%d\n",cnt+1);
	
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n;
	ll x[100005] = {};
	ll y[100005] = {};
	ll z[100005] = {};
	cin >> a;
	cin >> b;
	while (a<=b)
	{
		a *= 2;
		ans++;
	}

	cout << ans << endl;


	return 0;


	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	int n;
	cin >> n;
	cout << n / 3600 << ":" << (n / 60) % 60 << ":" << n % 60 << endl;

	return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>

int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);

    int nokori=a-b;
    c-=nokori;
    if(c<0){
        c=0;
    }

    printf("%d\n",c);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> p(n),  q(n);
    rep(i,n) cin>>p[i];
    q=p;
    sort(btoe(q));
    rep(i,n){
        if(p[i]<=q[n/2-1]){
            cout<<q[n/2]<<endl;
        }else{
            cout<<q[n/2-1]<<endl;
        }
    }
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x;
    cin>>n>>x;
    vll a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    ll ans=0;
    for(int i=0;i<n-1;i++){
        if(a[i]+a[i+1]>x){
            ll total=a[i]+a[i+1]-x;
            ll cnt=min(total,a[i+1]);
            a[i+1]-=cnt;
            a[i]-=total-cnt;
            ans+=total;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using ll=long long;
int main(){
    const int INF=1e9+10;
    int h,n;
    cin >> h >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    ll dp[n+5][h+5];
    for(int i=0;i<n+5;i++){
        for(int j=0;j<h+5;j++){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=h;j++){
            if(dp[i][j]!=INF){
                dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
            }
            if(dp[i+1][j]!=INF){
                dp[i+1][min(j+a[i],h)]=min(dp[i+1][min(j+a[i],h)],dp[i+1][j]+b[i]);
            }
        }
    }
    cout << dp[n][h] << endl;
}



Measured memory_bytes: 78848
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char N[3],i;
	for(int j=0;j<3;j++)
	{
		scanf("%c", &N[j]);
	}
	if(N[0]==N[2]){
		printf("Yes");
	}
	else{
		printf("No");	
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
int a[maxn],b[maxn],c[maxn],n,i,k=0,t=0,ans=0;
int getnum()
{
	int s=0;
	char c=getchar();
	for (;!isdigit(c);c=getchar());
	for (;isdigit(c);c=getchar())
		s=s*10+c-'0';
	return s;
}
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	n=getnum();
	for (i=1;i<=n;i++)
		a[i]=getnum();
	for (i=1;i<=n;i++)
		b[i]=getnum();
	for (i=1;i<=n;i++)
		if (a[i]>b[i]) c[++k]=a[i]-b[i];
			else if (a[i]<b[i]) ans++;
	sort(c+1,c+k+1,cmp);
	for (i=1;i<=n;i++)
		if (a[i]<b[i])
		{
			for (;t<=k;)
				if (c[t]>=b[i]-a[i])
				{
					c[t]-=b[i]-a[i];
					a[i]=b[i];
					break;
				}
				else
				{
					a[i]+=c[t];
					t++;
					ans++;
				}
			if ((t>k) && (a[i]<b[i])) break;
		}
	if (i>n) printf("%d",ans);
		else printf("-1");
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int[] count = new int[26];

        while(sc.hasNextLine()) {
            String S = sc.nextLine();
            for (int i = 0; i < S.length(); i++) {
                char temp = S.charAt(i);
                if (Character.isLetter(temp)) {
                    char s = Character.toLowerCase(temp);
                    count[s - 'a']++;
                }
            }
        }
        for (int i = 0; i < 26; i++) {
            out.printf("%c : %d\n", i + 'a', count[i]);
        }
        out.flush();
    }
}


Measured memory_bytes: 26312
package main

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

var sc = bufio.NewScanner(os.Stdin);

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

func main(){
	var a, b int
	sc.Split(bufio.ScanWords)
	a = nextInt()
	b = nextInt()
	a--
	b--
	var ans int
	ans = (b + (a-1)) / a
	fmt.Println(ans)
}

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

#define MAX 2000001
#define MAX1 10000

int main(){
  unsigned short *A, *B;

  int C[MAX1+1],n,m,i, j;


  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for ( i = 0; i <= MAX1; i++ ) {
    C[i] = 0;
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d", &A[i + 1]);
    m = A[i + 1];
    C[m]++;
  }

  for ( i = 1; i <= MAX1; i++ ){
    C[i] = C[i] + C[i - 1];
  }

  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 8456
#include<stdio.h>
int main(){
	int n,k,i,j,a[1001],b[1001],cnt,now;
	while(scanf("%d%d",&n,&k),n!=0 && k!=0){
		cnt=0,now=0;
		for(i=0;i<n;i++)scanf("%d",&a[i]);
		for(i=0;i<k;i++)scanf("%d",&b[i]);
		for(i=0;i<k;i++){
			++cnt;
			now+=b[i];
			if(now>=n-1)break;
			now+=a[now];
			if(now>=n-1)break;
		}
		printf("%d\n",cnt);
	}
	return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    ll z = 0;
    for (int k = 0; k < (1 << s.size() - 1); ++k)
    {
        ll x = 0;
        for (int j = 0; j < s.size(); ++j)
        {
            x *= 10;
            x += s[j] - '0';
            if (k & (1 << j))
                z += x, x = 0;
        }
        z += x;
    }
    cout << z;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair

// random generator
// mt19937 rndm(time(0));

ll gcd(ll a, ll b)
{
    while (b>0)
    {
        int tmp = a;
        a = b;
        b = tmp%b;
    }
    return a;
}

 
const int M=1e9+7;
ll powmod(ll a,ll b, ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}/* a^b%mod */
const int N=1e5+10;



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

	int n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<int>v1(n+1), v2(m+1);
	for(int i=0;i<n;++i)
		cin>>v1[i];
	for(int i=0;i<m;++i)
		cin>>v2[i];
	v1[n]=x;
	v2[m]=y;
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	if(v1[n]>=v2[0]) {
		puts("War");
	}
	else {
		puts("No War");
	}
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	string S;
	cin >> S;

	bool yymm=false;
	bool mmyy=false;

	if(S[2]=='0' && '1'<=S[3] && S[3]<='9')yymm=true;
	else if(S[2]=='1' && '0'<=S[3] && S[3]<='2')yymm=true;

	if(S[0]=='0' && '1'<=S[1] && S[1]<='9')mmyy=true;
	else if(S[0]=='1' && '0'<=S[1] && S[1]<='2')mmyy=true;

	if(yymm && mmyy)
		cout << "AMBIGUOUS";
	else if(yymm)
		cout << "YYMM";
	else if(mmyy)
		cout << "MMYY";
	else
		cout << "NA";
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
if __name__ == '__main__':
    N, M = map(int, input().split())

    ans = [None] * M
    prefMap = {}
    for i in range(M):
        P, Y = map(int, input().split())

        if P in prefMap:
            prefMap[P].append((Y, i))
        else:
            prefMap[P] = [(Y, i)]

    for P, L in prefMap.items():
        L.sort()

        for j, (y, i) in enumerate(L):
            ans[i] = str(P).zfill(6) + str(j + 1).zfill(6)

    print("\n".join(ans))


Measured memory_bytes: 45368
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve()
{
	//Enter your code here Tanmay:)
	int n,sum=0;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<n-1;i++)
	{
		if(s.at(i)!=s.at(i+1))
			sum++;
	}
	//if(s.at(n-2)!=)
	cout<<sum+1;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 512
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main()
{
	int N;
	cin >> N;
	vector<ll> A(N+1);
	A[0]=0;
	REP(i, N){
		ll a;
		cin >> a;
		A[i+1] = A[i]+a;
	}
	map<ll, ll> mp;
	REP(i, N+1){
		mp[A[i]]++;
	}
	ll ans=0;
	for(auto v : mp){
		ans += v.S*(v.S-1)/2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 16988
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;


int main() {
  string t, p;
  cin >> t >> p;
  int i, j;
  vector<int> a;
  for(i = j = 0; i < t.size() && j < p.size(); i++) {
    if (t[i] == p[j]) {
      j++;
      a.push_back(i);
    }
  }
  if (j != p.size()) {
    cout << "no" << endl;
    return 0;
  }
  string s = t, q = p;
  reverse(s.begin(), s.end());
  reverse(q.begin(), q.end());
  int k, l;
  vector<int> b;
  for(int k = l = 0; k < s.size() && l < q.size(); k++) {
    if (s[k] == q[l]) {
      l++;
      b.push_back(s.size() - k - 1);
    }
  }
  reverse(b.begin(), b.end());
  for (int m = 0; m < a.size(); m++) {
    if (a[m] != b[m]) {
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
}



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

#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

lli table_w[2001][2001];
lli table_h[2001][2001];

int main() {
    lli h, w;
    cin >> h >> w;
    string str[h];
    REP(i, 0, h) {
        string x;
        cin >> x;
        str[i] = x;
    }

    REP(i, 0, h) {
        lli s = 0;
        lli e = 0;
        REP(j, 0, w) {
            if (str[i][j] == '#') {
                for(lli k = s; k < e; k++) {
                    table_w[i][k] = e-s;
                }
                s = j+1;
                e = j+1;
            }
            else if (j == w-1) {
                e++;
                for(lli k = s; k < e; k++) {
                    table_w[i][k] = e-s;
                }
            }
            else {
                e++;
            }
        }
    }
    //REP(i, 0, h) {
    //    REP(j, 0, w) {
    //        cout << table_w[i][j] << ", ";
    //    }
    //        cout << endl;
    //}

    REP(i, 0, w) {
        lli s = 0;
        lli e = 0;
        REP(j, 0, h) {
            if (str[j][i] == '#') {
                for(lli k = s; k < e; k++) {
                    table_h[k][i] = e-s;
                }
                s = j+1;
                e = j+1;
            }
            else if (j == h-1) {
                e++;
                for(lli k = s; k < e; k++) {
                    table_h[k][i] = e-s;
                }
            }
            else {
                e++;
            }
        }
    }
    //cout << endl;
    //REP(i, 0, h) {
    //    REP(j, 0, w) {
    //        cout << table_h[i][j] << ", ";
    //    }
    //        cout << endl;
    //}
    lli ans = 0;
    REP(i, 0, h) {
        REP(j, 0, w) {
            lli total;
            total = table_h[i][j] + table_w[i][j] - 1;
            ans = max(ans, total);
        }
    }
    cout << ans << endl;
}


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

signed main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A+B+C>21)cout<<"bust"<<endl;
  else cout<<"win"<<endl;
  return 0;
}

Measured memory_bytes: 3564
//
// Created on 2019-02-09.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    ll N, num_negatine = 0;
    cin >> N;

    vector<ll> A(N);
    REP(i,N) {
        cin >> A[i];
        if (A[i] < 0) {
            num_negatine++;
            A[i] *= -1;
        }
    }

    if (num_negatine%2 == 0) cout << accumulate(ALL(A),0LL) << endl;
    else cout << accumulate(ALL(A),0LL) - *min_element(ALL(A))*2 << endl;



    return 0;

}


Measured memory_bytes: 1024
require 'pp'
require 'prime'
require 'set'

n = gets.chomp!.to_i
a_n = gets.chomp!.split(" ").map(&:to_i)

max_digit = 0
a_n_bin = []

a_n.each do |i|
    chars = i.to_s(2).chars
    digit = chars.length
    a_n_bin << chars.reverse
    if digit > max_digit
        max_digit = digit
    end
end

#pp max_digit
#pp a_n_bin

ok = true

max_digit.times do |i|
    zero_count = 0
    one_count = 0
    a_n_bin.length.times do |j|
        a_n_bin[j][i] ||= "0"
        if a_n_bin[j][i] == '0'
            zero_count += 1
        elsif 
            one_count += 1
        end
    end

    #pp zero_count
    #pp one_count

    if one_count == 0
        # OK
    elsif zero_count * 2 == one_count
        # OK
    else
        # NG
        ok = false
        break
    end

    if !ok
        break
    end
end

puts ok ? "Yes" : "No"


Measured memory_bytes: 244884
w = input()

if w == 'SUN':
  print(7)
elif w == 'MON':
  print(6)
elif w == 'TUE':
  print(5)
elif w == 'WED':
  print(4)
elif w == 'THU':
  print(3)
elif w == 'FRI':
  print(2)
else:
  print(1)

Measured memory_bytes: 2940
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    c = input()
    r_count = c.count('R')
    ans = 0

    # コーナーケース: すべてWのとき
    if r_count == 0:
        print(0)
        exit()

    # 左側にすべてのRを寄せるイメージ
    # 左端からWをRに置き換える
    # ACはしたが、この考え方でよかったのか?
    for ci in c:
        if ci == 'W':
            ans += 1

        r_count -= 1

        if r_count == 0:
            print(ans)
            exit()

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9444
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);   
    cin.tie(NULL);
  int k;
  cin>>k;
  ll ans=0;
  rep(i,1,k+1)
  {
    rep(j,1,k+1)
    {
      rep(x,1,k+1)
      {
        ans+=__gcd(__gcd(i,j),x);
      }
    }
  }
    cout<<ans;
  }
  

Measured memory_bytes: 3656