akhauriyash/Code-Regression huggingface dataset:
while True :
    try :
        c1, c2, c3 = map(int, input().split())
    except EOFError :
        break
    
    n = 20 - c1 - c2
    ans = n
    if c1 <= n :
        ans -= 1
    if c2 <= n :
        ans -= 1
    if c3 <= n :
        ans -= 1
    if ans >= 4 :
        print("YES")
    else :
        print("NO")


Measured memory_bytes: 5600
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))
dp=[None]*(n+1)
dp[0]=1
dp[1]=1
if 1 in a:
    dp[1]=0
for i in a:
    dp[i]=0
for i in range(2,n+1):
    if dp[i]!=0 :
        dp[i]=dp[i-1]+dp[i-2]
print(dp[-1]%(10**9+7))

Measured memory_bytes: 460020
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
int main(){
       int K;
       cin >> K;
       int T;
       cin >> T;
       int tmp = T;
       vector<int>  nums;
	      while(tmp--){
	         int element;
	         cin >> element;
	         nums.push_back(element);
	      }
       priority_queue<int> q;
       for(auto b : nums){
       	q.push(b);
       }
       while(q.size() > 1){
       		vector<int> tmp;
       		for(int i = 0; i < 2; i++){
       			auto t = q.top();
       			q.pop();
       			if(--t > 0)
       				tmp.push_back(t);
       		}
       		for(auto a : tmp)
       			q.push(a);
       }
       if(q.empty())
       		cout << 0 << endl;
       else if(q.size() == 1)
       		cout << q.top() - 1 << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int w[105], v[105];
signed main(void)
{
	int n, W;
	cin >> n >> W;
	REP(i, n) cin >> w[i] >> v[i];

	VVI dp(4);
	REP(i, n) dp[w[i]-w[0]].PB(v[i]);
	REP(i, 4) {sort(ALL(dp[i])); reverse(ALL(dp[i]));}
	REP(i, 4) REP(j, dp[i].size()-1) dp[i][j+1] += dp[i][j];
	REP(i, 4) dp[i].insert(dp[i].begin(), 0);

	int ans = -INF;
	REP(i, dp[0].size()) REP(j, dp[1].size()) REP(k, dp[2].size()) REP(l, dp[3].size()) {
		if(w[0]*i+(w[0]+1)*j+(w[0]+2)*k+(w[0]+3)*l > W) continue;
		ans = max(ans, dp[0][i]+dp[1][j]+dp[2][k]+dp[3][l]);
	}
	cout << ans << endl;

	return 0;
}


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

int main() {

	char mas[9][9];
	rep(i, 9)
		rep(j, 9)
		mas[i][j] = '.';

	int h, w;
	cin >> h >> w;
	rep(i, h)
		cin >> mas[i];
	int cnt=0;
	rep(i, h) {
		if (mas[i + 1][cnt] == '#') {
			mas[i][cnt] = '.';
			continue;
		}
		else if (mas[i][cnt]=='#') {
			mas[i][cnt] = '.';
			i--;
			cnt++;
			continue;
		}
	}
	cnt = 0;
	rep(i, h)
		rep(j, w)
		if (mas[i][j] == '#')
			cnt = 1;
	if (cnt == 1)
		cout << "Impossible" << endl;
	else cout << "Possible" << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int MOD = 998244353;

int main() {
	cin.tie(0)->sync_with_stdio(false);

	int n, k; cin >> n >> k;
	vector<int> L(k), R(k);
	REP(i, k) cin >> L[i] >> R[i];
	vector<int> dp(n + 1, 0), s(n + 1, 0);
	dp[1] = s[1] = 1;
	for(int i = 2; i <= n; i++) {
		REP(j, k) {
			int l = i - R[j];
			int r = i - L[j];
			if (r < 0) continue ;
			l = max(l, 1);
			int sum = s[r] - s[l-1];
			sum %= MOD;
			sum += MOD;
			sum %= MOD;
			dp[i] += sum;
			dp[i] %= MOD;
		}
		s[i] = s[i-1] + dp[i];
		s[i] %= MOD;
	}
	cout << dp[n] << '\n';
	return 0;
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define uint unsigned int
#define FOR(a,b,i) for(register int i=a;i<b;++i)

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int p = s.find('1');
    while (p > -1) {
        s.replace(p, 1, "0");
        p = s.find('1', p + 1);
    }
    p = s.find('9');
    while (p > -1) {
        s.replace(p, 1, "1");
        p = s.find('9', p + 1);
    }
    p = s.find('0');
    while (p > -1) {
        s.replace(p, 1, "9");
        p = s.find('0', p + 1);
    }
    cout << s;
    return 0;
}

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

using namespace std;



typedef long long ll;

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  n--;
  ll A = abs(a-b);
  for (ll k = 0; k < n; k++) {
    if (A<=d*(n-k)-k*c && A>=c*(n-k)-k*d) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
string a="Alice" ,b="Bob",d="Draw";
int x,y;
cin>>x>>y;
if (x==y){cout<<d;}
else if (x==1){cout<<a;}
else if (y==1){cout<<b;}
else if (x>y){cout<<a;}
else if (y>x){cout<<b;}
else if (x==y){cout<<d;}

    return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cerr << #x << " = " << x << endl


int main(int qtd, char* nome[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	ll n, k;
	cin >> n >> k;
	cout << min({n, k-n%k, n%k}) << endl;
	
	return 0;
}

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

int main() {
	string s;
	int n, q, f, lst;
	char c;
	bool flip = false;

	cin >> s >> n;

	lst = (int)s.size();
	for (int i = 0; i < n; i++) {
		cin >> q;
		if (q == 1) {
			flip = !flip;

		}else {
			cin >> f >> c;
			if (flip)f++;
			if (f % 2 == 1)s.insert(s.begin(), c);
			else s.push_back(c);
		}
	}
	if (flip) reverse(s.begin(), s.end());

	cout << s << endl;
	
}


Measured memory_bytes: 900
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------
from math import gcd, ceil
 
def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi
 
 
def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans
 
def lcm(a, b): return a * b // gcd(a, b)
 
 
def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

N = input()
hon = ['2', '4', '5', '7', '9']
pon = ['0', '1', '6', '8']
bon = ['3']

if N[-1] in hon:
    print('hon')
elif N[-1] in bon:
    print('bon')
else:
    print('pon')


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nm[0];
        var m = nm[1];
        var seqA = new int[m];
        var seqC = new int[m];
        for (int i = 0; i < m; ++i)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            seqA[i] = ab[0];
            seqC[i] = Console.ReadLine().Split().Sum(x => 1 << int.Parse(x) - 1);
        }

        var full = (1 << n) - 1;
        if (full - seqC.Aggregate((x, y) => x | y) > 0)
        {
            Console.WriteLine(-1);
            return;
        }

        var dp = new int[full + 2];
        for (int i = 1; i < dp.Length; ++i)
        {
            dp[i] = int.MaxValue;
        }
        for (int i = 0; i < seqC.Length; ++i)
        {
            for (int j = 1; j <= seqC[i]; ++j)
            {
                int jj = seqC[i] & j;
                if (jj == 0)
                {
                    continue;
                }
                
                dp[jj] = Math.Min(dp[jj], seqA[i]);
            }
        }
        for (int i = 1; i < dp.Length; ++i)
        {
            for (int j = 1; j <= i; ++j)
            {
                int jj = i & j;
                int kk = i ^ jj;
                if (jj >= kk)
                {
                    break;
                }
                if (kk == i || dp[jj] == int.MaxValue || dp[kk] == int.MaxValue)
                {
                    continue;
                }

                dp[i] = Math.Min(dp[i], dp[jj] + dp[kk]);
            }
        }
        Console.WriteLine(dp[full]);
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

const ll MOD=1e9+7;

ll ad(ll x,ll y=0){
  return (x+y)%MOD;
}

ll mlt(ll x,ll y=1){
  return (x*y)%MOD;
}

int main(){
  ll n,dp[52][6]={},m=0,i=0,ans=0;
  string s[2];
  cin>>n>>s[0]>>s[1];
  fr(i,3) dp[0][i]=1;
  while(i<n){
    m++;
    if(s[0][i]==s[1][i]){
      if(i==0) fr(i,3) dp[m][i]=1;
      i++;
      if(i==1) continue;
      dp[m][0]=ad(dp[m-1][1]+dp[m-1][2],dp[m-1][3]);
      dp[m][1]=ad(dp[m-1][0]+dp[m-1][2],dp[m-1][4]);
      dp[m][2]=ad(dp[m-1][1]+dp[m-1][0],dp[m-1][5]);
    }
    else{
      dp[m][3]=ad(2*dp[m-1][0],dp[m-1][3]+dp[m-1][4]+dp[m-1][5]);
      dp[m][4]=ad(2*dp[m-1][1],dp[m-1][3]+dp[m-1][4]+dp[m-1][5]);
      dp[m][5]=ad(2*dp[m-1][2],dp[m-1][3]+dp[m-1][4]+dp[m-1][5]);
      i+=2;
    }
  }
  fr(i,6) ans=ad(ans,dp[m][i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<=n;i++)
typedef int long long ll;
using namespace std;

int main(){
    int ans=0;
    int n,a,b;
    cin>>n>>a>>b;
    for(int i=0;i<=n;i++){
        int sum=0;
        int j=i;
        while(j>0){
            sum+=j%10;
            j=j/10;
        }
        if(a<=sum&&sum<=b){
            ans+=i;
           // cout<<sum<<endl;
        }
        
    }
    

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


Measured memory_bytes: 256
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = 1e9+7;

int main(void)
{
	ll n;
	cin >> n;
	vector<ll> vs(n);
	rep(i, n) cin >> vs[i];
	unordered_map<ll, ll> m;
	rep(i, n) {
		m[vs[i]] = i + 1;
	}
	ll maxLen = 0;
	ll len = 0;
	ll prev = 0;
	for (int i = 1; i <= n; i++) {
		if (m[i] > prev) {
			len++;
		}
		else {
			len = 1;
		}
		maxLen = max(maxLen, len);
		prev = m[i];
	}
	cout << (n - maxLen) << endl;
	return 0;
}


Measured memory_bytes: 10056
n, l = list(map(int, input().split()))
if l > 0:
  print( int((n-1)*l + 0.5 * n * (n-1)) )
elif l+n-1 < 0:
  print( int((n-1)*l + 0.5 * (n-2) * (n-1)) )
else:
  print(int(n*l + 0.5 * n * (n-1)))

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

int main() {
  int n;
  cin >> n;
  int ans=0;

  for (int i = 0; i < n; i++) {
    int b, c;
    cin >> b >> c;
    ans+=c-b+1;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
import math

def plot (x,y):
    print(f'{x:.8f} {y:.8f}')
    
def Koch(n,x1,y1,x2,y2):
    if n ==0:
        plot(x1,y1)
        return
    sx = (2 * x1 + x2)/ 3
    sy = (2 * y1 + y2)/ 3
    tx = (x1 + 2 * x2)/ 3
    ty = (y1 + 2 * y2)/ 3
    ux = (tx-sx)/2 -(ty-sy)*(math.sqrt(3)/2)+sx
    uy = (tx-sx)*(math.sqrt(3)/2) +(ty-sy)/2+sy
    
    Koch(n-1,x1,y1,sx,sy)
    Koch(n-1,sx,sy,ux,uy)
    Koch(n-1,ux,uy,tx,ty)
    Koch(n-1,tx,ty,x2,y2)
    
n= int(input())
Koch(n,0,0,100,0)

plot(100,0)


Measured memory_bytes: 5732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
const ll mo=1000000007;
ll ans=9999999;
ll dp[0][0];

int main()
{
ll n;
cin >> n;
string s;
cin >> s;
ll bl=0;
ll ren=0;
ll ten=0;
ll bll=0;
bool a=0;
rep(i,n){
    if(s[i]!='#')ten++;
    if(s[i]=='#')bll++;
}
ll nowten=0;
ll temp;
rep(i,n-1){
    if(s[i]!='#')nowten++;
    if(s[i]=='#'){ren++;bl++;}
    if(s[i]=='#'&&s[i+1]!='#'){
        temp=ten-nowten+bl-ren;
        if(temp>bll)temp=bll;
        if(ans>temp){ans=temp;}
        ren=0;}
}
if(ans==9999999)ans=0;
cout << ans << endl;
return 0;
}








Measured memory_bytes: 644
N = int(input())
W = [input() for i in range(N)]

def endgame():
    print("No")
    exit()

if len(list(set(W))) != len(W):
    endgame()
for i in range(N-1):
    if W[i+1][0] != W[i][-1]:
        endgame()
print("Yes")


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    // Your code here!
	int x,y,z,tmp;
	scanf("%d", &x);
    scanf("%d", &y);
    scanf("%d", &z);
    
	if(x>y){
	    tmp=x;
	    x=y;
	    y=tmp;
	}
	if(x>z){
	    tmp=x;
	    x=z;
	    z=tmp;
	}
	if(y>z){
	    tmp=y;
	    y=z;
	    z=tmp;
	}
	printf("%d %d %d\n",x,y,z);
	return 0;
}


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

int main() {
  int a;
  cin >> a;
  vector<int> data(a);
  for (int i = 0; i < a; i++) {
    cin >> data.at(i);
  }

  
  int answer = 0;

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

    
      answer = answer ^  data.at(i);

  }
 if (answer == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define N 300005
using namespace std;
int val[N];
int n,m;
void solve(int l,int r){
	for(int i=1,ne,lastl=1e9;i<=r;i=ne+1){
		if(i<=l) ne=min(l/(l/i),r/(r/i));
		else ne=r;
		if(l/i<lastl){
			val[l/i+1]++,val[min(lastl,r/i)+1]--;
			lastl=l/i;
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,l,r;i<=n;i++){
		scanf("%d%d",&l,&r);
		solve(l-1,r);
	}
	for(int i=1;i<=m;i++) printf("%d\n",val[i]+=val[i-1]);
	return 0;
}

Measured memory_bytes: 1280
s=input()

x=int(s[:2])
y=int(s[2:])

if (1<=x and x<=12) and (1<=y and y<=12):
    print('AMBIGUOUS')

elif (x==0 or x>12) and (1<=y and y<=12):
    print('YYMM')

elif (1<=x and x<=12) and (y==0 or y>12):
    print('MMYY')

else:
    print('NA')

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

int main()
{
	double r;
	double x, y;
	cin >> r;
	x = (double)(r * r*3.141592653589);
	y = (double)(2*r*3.141592653589);
	cout << fixed << setprecision(20) << x <<" "<< fixed << setprecision(20) << y << endl;

	return 0;
}


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

int main(){
  string s;
  cin>>s;
  int n = s.size();
  int ans;
  
  for(int i=n/2-1;i>0;i--){
    string p = s.substr(0,i);
    string q = s.substr(i,i);
    if(p==q){
      ans = 2*p.size();
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
d={i:set() for i in range(1,n+1)}
for i in range(m):
    a,b=map(int,input().split())
    d[a].add(b)
    d[b].add(a)

vis=set()
ma=0
for i in range(1,n+1):
    if i not in vis:
        stack=[i]
        ans=1
        vis.add(i)
        while(stack):
            cur=stack.pop()
            for j in d[cur]:
                if j not in vis:
                    vis.add(j)
                    ans += 1
                    stack.append(j)
        ma=max(ma,ans)
print(ma)


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

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    int x,a,b;
    cin>>x>>a>>b;
    cout<<(abs(x-a)<abs(x-b) ? 'A' : 'B')<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    const int N=1000000;
    int n;
    scanf("%d",&n);
    char s[N+1];
    vector<array<int,2>> pos,neg;
    for(int o=1;o<=n;o++)
    {
        scanf("%s",s);
        int d=0;
        int m=0;
        for(int i=0;s[i]!='\0';i++)
        {
            if(s[i]=='(') d++;
            else d--;
            m=min(m,d);
        }
        if(d>=0) pos.push_back({-m,d});
        else neg.push_back({max(-m,-d),d});
    }
    sort(pos.begin(),pos.end());
    sort(neg.begin(),neg.end(),[](array<int,2> a,array<int,2> b){return (a[0]+a[1]>b[0]+b[1]);});
    int r=0;
    auto out=[]()->void
    {
        printf("No\n");
        exit(0);
    };
    for(auto [a,b]:pos)
    {
        if(r<a) out();
        r+=b;
    }
    for(auto [a,b]:neg)
    {
        if(r<a) out();
        r+=b;
    }
    if(r!=0) out();
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 11432
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long A, B;

int main()
{
	scanf("%lld %lld", &A, &B);
	if(A <= 8 && B <= 8) {
		printf("Yay!\n");
	}
	else {
		printf(":(\n");
	}
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

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; }

typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define vi vector<int>
#define vii vector< vector<int> >

int N;
ll A[3100];
ll dp[3100][3100];

int main() {

	cin >> N;
	rep(i, N) cin >> A[i];

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

	for (int w = 1; w <= N; w++) {
		for (int l = 0; l + w <= N; l++) {

			int r = w + l;
			if (w % 2 == N % 2) {
				dp[l][r] = max(dp[l + 1][r] + A[l],
					dp[l][r - 1] + A[r - 1]);
			}
			else {
				dp[l][r] = min(dp[l + 1][r] - A[l], 
					dp[l][r - 1] - A[r - 1]);
			}
		}
	}

	cout << dp[0][N] << endl;

}


Measured memory_bytes: 73984
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll b,c,s=0,g,a[1000005];

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

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
	cin>>b>>c;
	g=gcd(b,c);
	for(ll i=1;i*i<=g;i++)
	{
		if(g%i==0){
			a[++s]=i;
			if(i*i==g) continue;
			a[++s]=g/i;
		}
	}
	ll ss=s;
	sort(a+1,a+1+s);
	for(int i=s;i>1;i--)
		for(int j=i-1;j>1;j--)
			if(a[i]%a[j]==0){
				ss--;
				break;
			}
	cout<<ss<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {  
  int64_t a, b, c;
  
  cin >> a >> b >> c;
  int64_t x = c - a - b;
  if (x < 0) {
    cout << "No" << endl;
    return 0;
  }
  
  if (4 * a * b < x * x) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-9
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
vint adj[1000001];

int A[1001][1001];
int N;

int dp[1000001];
int rec(int p){
	if(dp[p]>=0) return dp[p];
	if(adj[p].empty()){
		dp[p]=0;
		return 0;
	}
	rep(i,adj[p].size()){
		dp[p]=max(dp[p],rec(adj[p][i])+1);
	}
	return dp[p];
}

int color[1000001]={};
vint L;
int V;
void dfs(int u) {
  if(color[u]==1){
	  prin(-1);
	  exit(0);
  }
  if(color[u]==0){
	  color[u]=1;
	  for(auto& i: adj[u]) dfs(i);
	  color[u]=2;
	  L.push_back(u);
  }
}
void tsort() {
  for(int i=0; i<V; ++i) if(color[i]==0) dfs(i);
  reverse(ALL(L));
}
int main(){
	scan(N);
	rep(i,N){
		rep(j,N-1){
			scan(A[i][j]);
			A[i][j]--;
		}
	}
	rep(i,N){
		rep(j,N-2){
			int m1=min(i,A[i][j]),u1=max(i,A[i][j]);
			int m2=min(i,A[i][j+1]),u2=max(i,A[i][j+1]);
			adj[m1*N+u1].push_back(m2*N+u2);
		}
	}
	V=N*N;
	tsort();
	fill(dp,dp+V,-1);
	rep(i,V) rec(i);
	int ans=0;
	rep(i,V) ans=max(ans,dp[i]);
	prin(ans+1);
	return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int Tc; cin >> Tc;
  while(Tc--) {
    int x, y, w, h; cin >> x >> y >> w >> h;
    int N; cin >> N;
    int cnt = 0;
    rep(i, N) {
      int X, Y; cin >> X >> Y;
      cnt += x <= X && X <= x + w && y <= Y && Y <= y + h;
    }
    cout << cnt << endl;
  }
  
  return 0;
}

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

int n;
int x, y;
map<int, int> mp;


int cal(int i, int j)
{
    int dis = j - i;
    dis = min(dis, abs(i - x) + abs(j - y) + 1);
    dis = min(dis, abs(i - y) + abs(j - x) + 1);
    return dis;
}


int main()
{
    scanf("%d %d %d", &n, &x, &y);
    for (int i = 1; i <= n;i++)
    {
        for (int j = i + 1; j <= n;j++)
        {
            mp[cal(i, j)]++;
        }
    }
    for (int i = 1; i < n;i++)
    {
        printf("%d\n", mp[i]);
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol n,k;
  cin >>n>>k;
  lol ans=-inf;
  vector<lol> p(n+3),c(n+3);
  for(int i=1;i<=n;i++) cin >>p[i];
  for(int i=1;i<=n;i++) cin >>c[i];

  for(int i=1;i<=n;i++){
    lol sum=0;
    lol e=0;
    int tmp=i;
    while(e<k){
      sum+=c[tmp];
      tmp=p[tmp];
      e++;
      chmax(ans,sum);
      if(tmp==i){
        sum*=(k/e)-1;
        e=k-(k%e)-e;
        break;
      }
    }
    while(e<k){
      sum+=c[tmp];
      tmp=p[tmp];
      e++;

      chmax(ans,sum);
    }
    chmax(ans,sum);
  }

   cout <<ans<<'\n';
  return(0);
}


Measured memory_bytes: 3716
n = int(input())
A = ''

for i in range(n):
    a = input()
    A += a[0]

m = A.count('M')
a = A.count('A')
r = A.count('R')
c = A.count('C')
h = A.count('H')

ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h
print(ans)

Measured memory_bytes: 3064
//参考:http://kmjp.hatenablog.jp/entry/2019/06/17/0930  ムズかしい.....><
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(x,to) for(x=0;x<(to);x++)
const ll MOD = 1000000007;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(void){
    int n,m; cin>>n>>m;
    vector <ll> s(n), t(m);
    for(int i=0;i<n;i++) cin>>s[i];
    for(int i=0;i<m;i++) cin>>t[i];
    vector <vector<ll>> dp(2019 ,vector <ll>(2019 ));
    vector <vector<ll>> sum(2019 ,vector <ll>(2019));
    rep(i,2019) sum[i][0]=sum[0][i]=1;
    ll ans = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i]==t[j]) {dp[i+1][j+1] = (sum[i][j])%MOD;  dp[i+1][j+1]%=MOD; ans += dp[i+1][j+1]%MOD;}
            sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] + MOD + dp[i+1][j+1] - sum[i][j]) %MOD;
        }
    }
    cout<<ans%MOD<<endl;
	
}


Measured memory_bytes: 64256
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

def check(x):
    res[0] = x[0]
    res[1] = x[1]
    for i in range(1,n-1):
        if (res[i] == 'S' and s[i] == 'o') or (res[i] == 'W' and s[i] == 'x'):
            if res[i-1] == 'S':
                res[i+1] = 'S'
            else:
                res[i+1] = 'W'
        else:
            if res[i-1] == 'S':
                res[i+1] = 'W'
            else:
                res[i+1] = 'S'
    # print(res)
    if (res[n-1] == 'S' and s[n-1] == 'o') or (res[n-1] == 'W' and s[n-1] == 'x'):
        if res[n-2] != res[0]:
            return False
    else:
        if res[n-2] == res[0]:
            return False
    if (res[0] == 'S' and s[0] == 'o') or (res[0] == 'W' and s[0] == 'x'):
        if res[n-1] != res[1]:
            return False
    else:
        if res[n-1] == res[1]:
            return False
    return res

n = inp()
s = input()
a = [['S','S'],['S','W'],['W','S'],['W','W']]
res = [''] * n
# print(a)
for i in range(4):
    if check(a[i]):
        print(''.join(res))
        quit()
print(-1)

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
ans = 0
if abs(x)==abs(y):
  if x != y:ans += 1
elif 0<=x:
  if abs(x) < abs(y):
    ans += abs(y)-abs(x)
    if y<0: ans += 1
  else:
    ans += 1
    ans += abs(x)-abs(y)
    if y>0: ans += 1
else:
  if abs(x) < abs(y):
    ans += 1
    ans += abs(y)-abs(x)
    if y<0: ans += 1
  else:
    ans += abs(x)-abs(y)
    if y>0: ans += 1

print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
int main(){
	cin >> n;
	int ans = 0;
	for(int i=1;i<=n;i+=2){
		int num = 0;
		for(int j=1;j<=i;j++){
			if(i % j == 0) num++;
		}
		if(num == 8) ans++;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  long long n, a, b;
  cin>>n>>a>>b;
  if (a > b) {
    cout<<0<<endl;
  } else if (n == 1 && a != b) {
    cout<<0<<endl;
  } else {
    cout<<(n - 1)*b + a - (n - 1) *a - b + 1<<endl;
  }
}

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

using namespace std;

int main()
{
    int N, P;
    cin >> N >> P;

    int t, ar[2] = { 0 };
    for( int i = 0; i < N; ++i ){
        cin >> t;
        ++ar[t%2];
    }


    long long int ans = 0;

    if( ar[1] == 0 ){
        if( P == 0 ) ans = pow(2, N);
        else if( P == 1 ) ans = 0;
    } else if( 0 < ar[1] ){
        long long int others = pow(2, N-1), S = ar[0]+ar[1]-1;
        for( int i = 0; i < ar[1]; ++i ){
            if( S%2 == 1 ) ;
            else if( S%2 == 0 ) ;
        }
        ans = others;
    }

    cout << ans << endl;

    return 0;
}


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

typedef vector<int> vi;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<vi > vvi;


int n, i, a, f, b, afs;
vi v;
int main() {
    cin >> a >> f;
    for(i = 0; i < a; i++) {
        cin >> b;
        v.push_back(b);
    }
    sort(v.begin(), v.end(), greater<int>());
    afs = 0;
    for(i = 0; i < f; i++) afs += v[i];

    cout << afs << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations

N = int(input())
L = list(map(int, input().split()))
cnt = 0
for i in combinations(L, 3):
    if i[0] != i[1] and i[1] != i[2] and i[2] != i[0]:
        if i[0] + i[1] > i[2] and i[0] + i[2] > i[1] and i[1] + i[2] > i[0]:
            cnt += 1
print(cnt)

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

int main(){
    char a[4];
    int ans = 0;
    cin >> a;
    for(int i = 0; i < 4; i++){
        if(a[i] == '+'){
            ans++;
        }
        else{
            ans--;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;

int main(){

	ll n, a[100010]={0}, total=0;
	cin >> n;
	for(int i=1; i<n+1; i++){
		cin >> a[i];
	}
	for(int i=0; i<n+1; i++){
		total+=abs(a[i+1]-a[i]);
	}
	for(int i=1; i<n+1; i++){
		cout << total-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]) << endl;
	}

	return 0;
}

Measured memory_bytes: 2048
'use strict'

function main(s) {

  const nums = s.split('\n')[1].split(' ').map(n => Number(n));
  const odd_len = nums.filter(n => n % 2 === 1).length;

  const answer = (odd_len % 2 === 0) ? 'YES' : 'NO';
  console.log(answer);
}

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


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

namespace P_AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());
            if(input < 1200)
            {
                Console.WriteLine("ABC");
            }else if(input < 2800)
            {
                Console.WriteLine("ARC");
            }else
            {
                Console.WriteLine("AGC");
            }
            
        }
    }
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int a=0, b=0, ab=0, cnt_ab=0;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        if(s[0]=='B' && s[s.length()-1]=='A') ab++;
        else{
            if(s[0]=='B') b++;
            if(s[s.length()-1]=='A') a++;
        }
        for(int i=0; i<s.length()-1; i++){
            if(s[i]=='A' && s[i+1]=='B') cnt_ab++;
        }
    }
    if(ab==0){
        cout << cnt_ab+min(a,b) << endl;
        return 0;
    }
    int ans=ab-1;
    if(a>0){
        ans++;
        a--;
    }
    if(b>0){
        ans++;
        b--;
    }
    ans+=min(a,b)+cnt_ab;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
// AOJ 2035: It Prefokery Pio
// 2017.10.9 bal4u@uu

#include <stdio.h>
#include <string.h>

char s[2005], t[2005];

int c[2005][2005]; char z[2005];    // for LCS
char f[2005][2005];
void LCS(char *x, int m, char *y, int n)
{
	int i, j, ret, ret2;

	memset(c, 0, sizeof(c)); memset(f, 0, sizeof(f));
	for (i = 1; i <= m; i++) for (j = 1; j <= n; j++) {
		if (x[i-1] == y[j-1]) c[i][j] = c[i-1][j-1]+1, f[i][j] = 0;
		else {
			if (c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j], f[i][j] = 1;
			else                        c[i][j] = c[i][j-1], f[i][j] = -1;
		}
	}
	ret2 = ret = c[m][n]-1;
	while (ret >= 0) {
		if      (f[m][n] > 0) m--;
		else if (f[m][n] < 0) n--;
		else z[ret] = x[m-1], ret--, m--, n--;
	}
	z[ret2+1] = 0;
}

int main()
{
	int n;
	char *p, *q;

	while (scanf("%s", s) == 1) {
		n = strlen(s);
		p = s, q = t+n; *q = 0;
		while (*p) *--q = *p++;
		LCS(s, n, t, n);
		puts(z);
	}
	return 0;
}

Measured memory_bytes: 21296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  int N,min=1000000;
  cin >> N;
  int w[N+1];
  for(int i=1;i<N+1;i++){
    cin >> w[i];
  }
  vector<int> a(2);
  for(int t=1;t<N;t++){
    a[0]=0;
    a[1]=0;
    for(int i=1;i<=t;i++){
      a[0]+= w[i];
    }
    for(int i=t+1;i<N+1;i++){
      a[1]+= w[i];
    }
    sort(a.begin(),a.end());
    if(a[1]-a[0]<min) min=a[1]-a[0];
  }
  
  
  
  cout << min << endl;
}

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

using namespace std;

typedef long long ll;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string a, b;
    cin >> a >> b;
    for (int i = 0; i < a.size(); i++)
    {
        cout << a[i];
        if (i < b.size()) cout << b[i];
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(int (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(int (i)=(a)-1;(i)>=(b);(i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;
#define VI vector<int>
#define VII vector<VI>
#define VL vector<LL>
#define VLL vector<VL>
#define VD vector<double>
#define VDD vector<VD>
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<LL,LL>
#define VPII vector<PII>
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a,b) for(auto &&a:b)

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9;
const int MOD=INF+7;
#define int LL

const int NUM = (50*50)+1;
int N,A;
VI x;
LL dp[51][51][NUM]={0};

signed main(void){
    cin >> N >> A;
    x=VI(N);
    REP(i,N){
        cin >> x[i];
    }
    dp[0][0][0]=1;
    //先頭からi個の内，j個選んだ組み合わせで総和kが何通りか
    REP(i,N){
        REP(j,i+1){
            REP(k,NUM){
                dp[i+1][j][k]+=dp[i][j][k]; //x[i]を候補に追加して使用しなかった場合
                dp[i+1][j+1][k+x[i]]+=dp[i][j][k]; //x[i]を候補に追加して使用した場合
            }
        }
    }
    LL ans=0;
    //先頭からN個のうち，ave==(i*A)/i==A
    FOR(i,1,N+1){
        ans+=dp[N][i][i*A];
    }
    cout << ans << endl;
}


Measured memory_bytes: 26368
#include <iostream>
#include <set>

using namespace std;
#define ll long long

int main() {
    string a;
    cin >> a;
    set<char> dat;
    for (auto i: a) dat.insert(i);
    if (dat.size() == a.size()) cout << "yes" << endl;
    else cout << "no" << endl;

    return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[0]*h
for i in range(h):
    s[i] = input()

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if i != 0:
                if s[i-1][j] == '#':
                    continue
            if j != 0:
                if s[i][j-1] == '#':
                    continue
            if i != h-1:
                if s[i+1][j] == '#':
                    continue
            if j != w-1:
                if s[i][j+1] == '#':
                    continue
        else:
            continue
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 9088
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program {
    static void Main() {
        var n = NextInt();
        var p = NextInt();
        var odd = 0;
        var even = 0;

        foreach (var i in Enumerable.Range(0, n)) {
            var a = NextInt();
            odd += a % 2;
            even += (a % 2) ^ 1;
        }
        if (odd == 0) {
            WriteLine(Pow(2, even) * Int(p == 0));
        } else {
            WriteLine(Pow(2, odd - 1) * Pow(2, even));
        }
    }

    static long Pow(int a, int b) {
        var result = 1L;
        foreach (var i in Enumerable.Range(0, b)) {
            result *= a;
        }
        return result;
    }

    static int Int(bool ok) {
        if (ok) {
            return 1;
        }
        return 0;
    }

    static int NextInt() {
        return int.Parse(NextString());
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 13268
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner s = new Scanner(System.in);
        Set<Integer> m = new HashSet<>();
        for(int i = s.nextInt(); i > 0; i--){
            int t = s.nextInt();
            if(!m.remove(t)) m.add(t);
        }
        System.out.println(m.size());
    }
}

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

using namespace std;

int main() {
  string s;
  int n;
  cin >> n >> s;
  int m = 0;
  for(int i=0; i < s.size(); i++) {
    if(s.substr(i, 3) == "ABC") m++;
  }
  cout << m << endl;
}


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

int main()
{
	int a,b,k,f;
	cin >> a >> b;
	f = (a + b) % 2;
	k = (a + b) / 2;
	if(f==0)
	{
		cout << k <<endl;
	}
	else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
N = int(input())
yakusu = [0] * (N + 2)
cnt = 0
for i in range(1, N+1):
    x = i
    cnt += i * (yakusu[i] + 1)
    yakusu[i] += 1
    while (True):
        x += i
        if (x <= N):
            yakusu[x] += 1
        else:
            break

print(cnt)

Measured memory_bytes: 145676
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,s; cin>>n>>s;
    int arr[n+1],ans=0;
    for(int i=1;i<=n;i++) cin>>arr[i];
    int dp[s+1][n+1]; fill(dp,0);
    for(int j=1;j<=n;j++){
        int temp=0;
        if(s>arr[j]) temp=dp[s-arr[j]][j-1];
        else if(s==arr[j]) temp=j;
        ans=(ans+temp*(n+1-j))%mod;
        for(int i=1;i<=s;i++){
            dp[i][j]=dp[i][j-1];
            if(arr[j]<=i) dp[i][j]=(dp[i][j]+dp[i-arr[j]][j-1])%mod;
        }
        if(arr[j]<=s) dp[arr[j]][j]=(dp[arr[j]][j]+j)%mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 70656
#include<iostream>
#include<string>
#include <sstream>
#include <stdio.h>
#include <math.h>
 
using namespace std;
 
int main() {
    double a,b,c;
    
    cin >> a >> b >> c;

    if( (a/c)  >  b ){
        cout << "No" <<endl;
       
    }else{
    cout << "Yes"  << endl;
    }
} 

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1 << 20;
const int MOD = 1e9 + 7;

int f(int x) {
   int cnt = 0;
   while (x % 2 == 0) {
      x /= 2;
      cnt++;
   }
   return cnt;
}

ll gcd(ll a, ll b) {
   if (b == 0) return a;
   return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
   int n, m;
   cin >> n >> m;
   vector<int> a(n);
   rep(i, 0, n) {
      cin >> a[i];
      a[i] /= 2;
   }

   int t = f(a[0]);
   a[0] >>= t;
   rep(i, 1, n) {
      if (f(a[i]) != t) {
         cout << 0 << endl;
         return 0;
      }
      a[i] >>= t;
   }
   m >>= t;
   ll l = 1;
   rep(i, 0, n) {
      l = lcm(l, a[i]);
      if (l > m) {
         cout << 0 << endl;
         return 0;
      }
   }
   m /= l;
   int ans = (m + 1) / 2;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int area(P rect)
{
    return rect.first * rect.second;
}
using PP = pair<P, P>;
PP split(vp &c, int p, int r)
{
    int h = c[p].first, w = c[p].second;
    r %= h + w;
    P a, b;
    if (r > h)
    {
        r -= h;
        a = P(h, r);
        b = P(h, w - r);
    }
    else
    {
        a = P(r, w);
        b = P(h - r, w);
    }
    if (area(a) > area(b))
        swap(a, b);

    return PP(a, b);
}

int main()
{
    int n, h, w;
    while (cin >> n >> h >> w, n || h || w)
    {
        vp c(n + 1);
        c[0] = P(h, w);
        rep(i, n)
        {
            int p, r;
            cin >> p >> r;
            p--;
            PP cut = split(c, p, r);
            for (int after = p; after < i; after++)
            {
                c[after] = c[after + 1];
            }
            c[i] = cut.first;
            c[i + 1] = cut.second;
        }
        sort(c.begin(), c.end(), [](P a, P b) { return area(a) < area(b); });

        rep(i, n + 1)
        {
            cout << area(c[i]) << (i == n ? "\n" : " ");
        }
    }

    return 0;
}


Measured memory_bytes: 3104
import math
from collections import deque

def main():
        
    N,D,A = map(int, input().split())

    xh = [list(map(int, input().split())) for _ in range(N)]

    xh.sort()

    ans = 0
    q = deque()
    dmg = 0
    for i in range(N):
        # 過去に使った爆弾で、現在地点まで攻撃が届かないものは効果切れにする
        while q and q[0][0] < xh[i][0]:
            _, d = q.popleft()
            dmg -= d

        # それまでの攻撃でその地点の敵が死んでいるので、その敵に対しては新たに爆弾を使わない
        if xh[i][1] - dmg <= 0:
            continue

        remaining = xh[i][1] - dmg

        cnt = math.ceil(remaining / A)
        ans += cnt
        dmg += cnt * A
        # その敵に対して爆弾を使ったので、追加
        q.append((xh[i][0] + 2*D, cnt*A))


    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 66420
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

const int N_max = 100000;
using edge = struct {int to; ll cost;};
vector<edge> tree[N_max];
ll dis[N_max];

void dfs(int v, int p, ll d){
  dis[v] = d;
  for (auto &e: tree[v]) {
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}

int main() {
  int N; cin >> N;
  rep(i, N-1) {
    int a, b, c; cin >> a >> b >> c; a--; b--;
    tree[a].push_back({b,c});
    tree[b].push_back({a,c});
  }

  int Q, K; cin >> Q >> K; K--;

  dfs(K, -1, 0);

  rep(i, Q) {
    int x, y; cin >> x >> y; x--; y--;
    ll result = dis[x] + dis[y];
    cout << result << endl;
  }

  return 0;
}

Measured memory_bytes: 14336
#117_D
N,K=map(int,input().split())
A=list(map(int,input().split()))
#各桁の和を求める
Pro=[0]*40
for i in range(40):
    res=0
    for j in range(N):
        if (A[j]>>i)&1:
            res+=1
    Pro[i]=res

K_bin=[]
tmp=K+1
for i in range(40):
    K_bin.append(tmp%2)
    tmp//=2
    
Ans=0    
    
for i in range(40):
    x=0
    if K_bin[i]==1:
        x+=sum([max(Pro[j],N-Pro[j])*(2**j) for j in range(0,i)])
        x+=Pro[i]*(2**i)
        x+=sum([(2**j)*(Pro[j]+(N-2*Pro[j])*K_bin[j]) for j in range(i+1,40)])
    Ans=max(Ans,x)
    
print(Ans)

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

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

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll dp[114514][2][114];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string K;
	int d;
	cin>>K>>d;
	int n=K.size();
	dp[0][0][0]=1;
	REP(i, n){
		REP(j, 2){
			int x=j ? 9 : K[i]-'0';
			REP(k, d){
				REP(l, x+1){
					dp[i+1][j || l<x][(k+l)%d]=(dp[i+1][j || l<x][(k+l)%d]+dp[i][j][k])%MOD;
				}
			}
		}
	}
	ll ans=0;
	if(dp[n][0][0]+dp[n][1][0]==0){
		ans=(MOD-1)%MOD;
	}
	else{
		ans=(dp[n][0][0]+dp[n][1][0]-1)%MOD;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 18688