akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int n,i,a[N],d[N],v[N];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
int main(){
	for (n=read(),i=1;i<=n;i++) a[i]=read()-1;
	sort(a+1,a+n+1);a[0]=-1;
	for (i=1;i<=n;i++){
		int px=a[i-1]+i,dx=d[i-1]==px-1?v[i-1]:0;
		int rx=((a[i]-a[i-1])&1)^1;
		d[i]=px;v[i]=!dx||!rx?1:0;
	}
	for (i=1;d[i]<n;i++);
	int res=d[i]==n?v[i]:((d[i]-n)&1)^1;
	puts(res?"First":"Second");
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    vector<int> X(3);
    rep(i, 3) cin >> X[i];
    sort(X.begin(), X.end());

    int ans = 0;
    while (X[0] + 2 <= X[2]) {
        X[0] += 2;
        ans++;
    }

    while (X[1] + 2 <= X[2]) {
        X[1] += 2;
        ans++;
    }

    sort(X.begin(), X.end());
    if (X[1] < X[2]) ans++;
    if (X[0] < X[1]) ans += 2;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;

    int n = s.length();
    vector<int>mae(2019);

    // for(int i=0;i<2019;i++)dp[0][i] = 0;
    long ans = 0;
    int a = (int)(s[0]-'0');
    mae[a] = 1;

    for(int i=1;i<n;i++){
        vector<int>ima(2019);

        int tmp = (int)(s[i]-'0');

        for(int j=0;j<2019;j++){
            ima[(j*10+tmp)%2019] = mae[j];
        }
        ima[tmp]++;
        ans += ima[0];
        mae = ima;
    }
    

    cout << ans << endl;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

vec ans(2e5+10),dp(2e5+10),a(2e5+10);
ll n;
vector<set<ll>> G(2e5+10);

void dfs(ll f, ll ff,ll R) {
  ll l=0,r=R;
  while(r-l>1) {
    ll m=(r+l)/2;
    if(dp[m]<a[f]) l=m;
    else r=m;
  }
  ll pre=dp[r];
  dp[r]=a[f];
  if(r==R) ans[f]=R++;
  else ans[f]=R-1;
  for(ll t:G[f]) if(t!=ff) dfs(t,f,R);
  dp[r]=pre;
}

int main() {
  cin >> n;
  for(ll i=0;i<n;i++) cin >> a[i];
  for(ll i=0;i<n-1;i++) {
    ll u,v;
    cin >> u >> v;
    u--,v--;
    G[u].insert(v);
    G[v].insert(u);
  }
  for(ll i=0;i<=n;i++) dp[i]=inf;
  dfs(0,-1,1);
  for(ll i=0;i<n;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 50456
import sys
sys.setrecursionlimit(10**6)


class UnionFind(object):
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]
        self.root = [False]*size
        self.ans = 0

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                if self.root[s2]:
                    self.ans -= (-self.table[s2])*(-self.table[s2]-1)//2
                self.root[s2] = False
                if self.root[s1]:
                    self.ans -= (-self.table[s1])*(-self.table[s1]-1)//2
                self.root[s1] = True
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
                self.ans += (-self.table[s1])*(-self.table[s1]-1)//2
            else:
                if self.root[s1]:
                    self.ans -= (-self.table[s1])*(-self.table[s1]-1)//2
                self.root[s1] = False
                if self.root[s2]:
                    self.ans -= (-self.table[s2])*(-self.table[s2]-1)//2
                self.root[s2] = True
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
                self.ans += (-self.table[s2])*(-self.table[s2]-1)//2
            return True
        else:
            return False


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

uf = UnionFind(N)
tmp = [0]
for elem in reversed(AB):
    a, b = elem
    uf.union(a-1, b-1)
    tmp.append(uf.ans)
for i, elem in enumerate(reversed(tmp)):
    if i == 0:
        continue
    print(tmp[-1]-elem)


Measured memory_bytes: 35616
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;

int main()
{
	string a,b;
	int c;
	double d; 
	cin>>a>>b;
	c=stoi(a+b);
	d=sqrt(c);
	if(ceil(d)==floor(d)){
		printf("Yes");
		}
	else{
		printf("No");
		}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    cin>>n;
    vector<int> v(n,0);
    rep(i,n) cin>>v[i];
    sort(v.begin(),v.end());
    int ans = 0;
    rep(b,n){
        rep(a,b){
            int ab=v[a]+v[b];
            int r = lower_bound(v.begin(),v.end(),ab) - v.begin();
            int l = b+1;
            ans += r-l;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;

const long long mod = 1e9+7;

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N;
  cin >> N;
  vector<pair<int, int>> red(N), blue(N);
  vector<bool> judge(N, true);
  for(int i = 0; i < N; i++) {
    cin >> red[i].first >> red[i].second;
  }
  for(int i = 0; i < N; i++) {
    cin >> blue[i].first >> blue[i].second;
  }
  sort(red.begin(), red.end());
  sort(blue.begin(), blue.end(), compare_by_second);

  int ans = 0;
  for(int i = 0; i < N; i++) {
    int tmp = -1;
    for(int j = 0; j < N; j++) {
      if(judge[j] && red[j].first < blue[i].first && red[j].second < blue[i].second) {
        tmp = j;
      }
    }
    if(tmp != -1) {
      judge[tmp] = false;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3580
l=sorted(list(map(int,input().split())))

ans=0
if l[0]!=l[1]:
  d1 = l[1]-l[0]
  l[0] += d1
  if d1 % 2 == 0:    
    ans += d1//2
  else:
    l[2] += 1
    ans += d1//2 +1
  
ans += l[2]-l[0]
print(ans)

Measured memory_bytes: 3060
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1.01e9;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

void add(int & x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int sum(int x, int y) {
  add(x, y);
  return x;
}

int mult(int x, int y) {
  return (ll) x * y % mod;
}

int power(int x, ll p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}

void precalc() {
}

int gcd(int a, int b) {
  if (!b) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

const int maxn = 1e5 + 100;

int n;
int a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  return true;
}

void solve() {
  if (n == 1) {
    printf("Second\n");
    return;
  }
  int it = 0;
  for (; ; it++) {
    int cnteven = 0;
    bool fail = true;
    int posodd = -1;
    for (int i = 0; i < n; i++) {
      if (a[i] != 1) {
        fail = false;
      }
      if (a[i] % 2 == 0) {
        cnteven++;
      } else {
        posodd = i;
      }
    }
    if (fail) {
      it++;
      break;
    }
    if (cnteven % 2 == 1) {
      break;
    }
    if (cnteven == n - 1) {
      if (a[posodd] == 1) {
        it++;
        break;
      }
      a[posodd]--;
      int g = a[0];
      for (int i = 0; i < n; i++) {
        g = gcd(a[i], g);
      }
      for (int i = 0; i < n; i++) {
        a[i] /= g;
      }
    } else {
      it++;
      break;
    }
  }
  if (!(it & 1)) {
    printf("First\n");
  } else {
    printf("Second\n");
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.3f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using Int = long long;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n+2);
    for (int i = 1; i <= n; i++) cin >> a[i];
    int sum = 0;
    for (int i = 1; i <= n+1; i++) sum += abs(a[i] - a[i-1]);
    for (int i = 1; i <= n; i++) {
        cout << sum - 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: 1664
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> m(K, 0);
	for (int i = 1; i <= N; ++i) {
		++m[i % K];
	}

	long long ans = 0;
	for (int a = 1; a <= N; ++a) {
		int x = a % K;
		int y = (K - x) % K;
		if ((2 * y) % K == 0) {
			ans += 1LL * m[y] * m[y];
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }



int main() {
	int n;
	cin >> n;
	vector <ll> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	
	if (n % 2 == 0) {
		ll ans = 0;
		int minx = n / 2 - 1;
		int maxx = n / 2;
		rep(i, minx) {
			ans -= 2 * a[i];
		}
		ans -= a[minx];
		ans += a[maxx];
		FOR(i, maxx + 1, n) {
			ans += 2 * a[i];
		}
		cout << ans << endl;
		return 0;
	}
	else {
		ll ans1 = 0;
		ll ans2 = 0;
		{
			int minx = n / 2;
			int maxx = n / 2 + 1;
			rep(i, minx) {
				ans1 -= 2 * a[i];
			}
			ans1 += a[minx] + a[maxx];
			FOR(i, maxx + 1, n) {
				ans1 += 2 * a[i];
			}
		}
		{
			int minx = n / 2 - 1;
			int maxx = n / 2;
			rep(i, minx) {
				ans2 -= 2 * a[i];
			}
			ans2 -= a[minx] + a[maxx];
			FOR(i, maxx + 1, n) {
				ans2 += 2 * a[i];
			}
		}
		if (ans1 > ans2) {
			cout << ans1 << endl;
			return 0;
		}
		else {
			cout << ans2 << endl;
			return 0;
		}

	}




}

Measured memory_bytes: 1024
n=int(input())
l=list(map(int,input().split()))
d=dict()

for i in range(len(l)):
  d.setdefault(l[i],0)
  d[l[i]] += 1

result=0

for key,value in d.items():
    num=(value*(value-1))/2
    result += num

for i in range(len(l)):
    r1=int((d[l[i]]*(d[l[i]]-1))/2)
    r2=int(((d[l[i]]-1)*(d[l[i]]-2))/2)
    output=int(result-r1+r2)
    print(output)

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

using namespace std;

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

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define all(v) (v).begin(), (v).end()
#define dbg(a) cerr << #a << " = " << a << endl

int cnt(int x) {
    int ans = 0;
    while(x) {
        ++ans;
        x /= 10;
    }
    return ans;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int a, b;
    cin >> a >> b;
    for(int i = 0; i < cnt(b); ++i) {
        a *= 10;
    }
    a += b;
    if(sqrt(a) == (int) sqrt(a)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/perl
my ($n,$l) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $r = $n * $l + ($n * ($n -1 ))/2;
if( $l <= 0 and 0 <= $l + $n - 1 ){
  
} elsif( 0 < $l ){
  $r -= $l;
} elsif( $l + $n - 1 < 0 ){
  $r -= ($l + $n - 1);
}

print "$r\n";



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

int main(){
    int a, b, c;
    char op;
    while (1){
        cin >> a >> op >> b;
        if (op == '+') c = a + b;
        if (op == '-') c = a - b;
        if (op == '*') c = a * b;
        if (op == '/') c = a / b;
        if (op == '?') break;
        cout << c << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#!/usr/bin/env python3
import sys

def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    import numpy as np    
    from scipy.sparse import csr_matrix    
    from scipy.sparse.csgraph import floyd_warshall
    omat = csr_matrix((c, (a, b)), shape=(N+1, N+1), dtype=np.int32)
    smat = floyd_warshall(omat, directed=False)
    return ((smat-omat) < 0).sum()


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    print(solve(N, M, a, b, c))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 38188
class Dice:
    def __init__(self, one: int, two: int, three: int, four: int, five: int, six: int) -> None:
        self.__one = one
        self.__two = two
        self.__three = three
        self.__four = four
        self.__five = five
        self.__six = six

    def roll(self, direction) -> None:
        if direction == "N":
            tmp = self.__one
            self.__one = self.__two
            self.__two = self.__six
            self.__six = self.__five
            self.__five = tmp

        if direction == "E":
            tmp = self.__one
            self.__one = self.__four
            self.__four = self.__six
            self.__six = self.__three
            self.__three = tmp

        if direction == "S":
            tmp = self.__one
            self.__one = self.__five
            self.__five = self.__six
            self.__six = self.__two
            self.__two = tmp

        if direction == "W":
            tmp = self.__one
            self.__one = self.__three
            self.__three = self.__six
            self.__six = self.__four
            self.__four = tmp

    @property
    def one(self) -> int:
        return self.__one


if __name__ == "__main__":
    one, two, three, four, five, six = map(int, input().split(' '))
    dice = Dice(one, two, three, four, five, six)
    directions = list(input())
    for direction in directions:
        dice.roll(direction)
    print(dice.one)



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1e18;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

int n, m;
vi a, b;

bool f(ll s, ll t, ll x) {
  vi dp(m+1);
  dp[s] = 1;
  drep(i,m) if (x>>i&1) {
    drep(j,m+1) if (dp[j]) {
      dp[j%(i+1)] = 1;
    }
  }
  return dp[t];
}
bool f(ll x) {
  rep(i,n) {
    if (!f(a[i],b[i],x)) return false;
  }
  return true;
}

int main() {
  scanf("%d",&n);
  a = b = vi(n);
  cin>>a>>b;

  m = 50;
  ll ans = (1ll<<m)-1;
  if (!f(ans)) dame;
  drep(i,m) {
    if (f(ans^(1ll<<i))) ans ^= 1ll<<i;
  }
  ans <<= 1;
  cout<<ans<<endl;
  return 0;
}






















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

int gcd(long long a, long long b){
  long long M = max(a, b), m = min(a, b);
  while(m != 0){
  	long long r = M%m;
    M = m; m = r;
  }
  return M;
}

int main(){
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long l = c*d/gcd(c, d);
  a--;
  cout << b - b/c - b/d + b/l - a + a/c + a/d - a/l << endl;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define int long long
#define FOR(a, b, c) for(int a = b, _c = c; a <= _c; ++a)
#define ROF(a, b, c) for(int a = b, _c = c; a >= _c; --a)
#define REP(a, b, c) for(int a = b, _c = c; a < _c; ++a)
#define VEC(a, b) for(auto &a : b)
#define ii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define sz(x) (int)(x.size())
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))

template <class T> void Max(T &x, T y) { x = (x > y) ? x : y;}
template <class T> void Min(T &x, T y) { x = (x < y) ? x : y;}

#define debug(x) cerr << #x << '=' << x << '\n'
#define debugn(a, n) FOR(i, 1, n) cerr << a[i] << ' '
#define debugv(a) VEC(v, a) cerr << v << ' '

const int N = 2e5 + 5;
const int inf = 1e18;
int n, a[N];
int f[N][3][3];

main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n;
  FOR(i, 1, n) cin >> a[i];
  FOR(i, 0, n) FOR(j, 0, 2) FOR(k, 0, 1) f[i][j][k] = -inf;
  f[0][0][0] = 0;
  for(int i = 1; i <= n;  i += 2) {
    int j = (i + 1) / 2;
    f[j][0][1] = max({ f[j - 1][0][0], f[j - 1][2][0], f[j - 1][1][0]});
    f[j][1][0] = max(f[j - 1][0][0], f[j - 1][1][0]) + a[i];
    f[j][2][0] = max({ f[j - 1][0][0], f[j - 1][1][0], f[j - 1][2][0]}) + a[i + 1];
    f[j][1][1] = max({ f[j - 1][0][1], f[j - 1][1][1]}) + a[i];
    f[j][2][1] = max({ f[j - 1][0][1], f[j - 1][1][1], f[j - 1][2][1]}) + a[i + 1];
  }
  int ans = max(f[n / 2][1][0], f[n / 2][2][0]);
  if(n % 2 == 1) ans = max(ans, max(f[n / 2][0][1], f[n / 2][1][1]) + a[n]);
  cout << ans;
}


Measured memory_bytes: 19280
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort(ALL(c))
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;

int main() {
	vector<PII> X;

	LL a, b;
	for (int i = 0; i <= 2; i++) {
		cin >> a >> b;
		X.PB(MP(a, b));
	}
	
	int perm[] = {0, 1, 2};   // これらを並び替える

	int flag = 0;
	do {
		// ここでpermは並び替えられており、普通の配列のように使うことができる
		REP(i, 1 << 3) {   // i moves from 0...0 to 1...1 as binary (|i|=N), which indicates choice/no-choice of each element
			vector<PII> Y;
			REP(k, 3) {   // for each element index
				if (i & (1 << k)) {
					//cout << "hoge\n";
					// element k is selected in this choice
					Y.PB(MP(X[perm[k]].second, X[perm[k]].first));
				} else {
					//cout << "foo\n";
					Y.PB(MP(X[perm[k]].first, X[perm[k]].second));
				}
			}
			/*cout << "##" << endl;
			REP(j, 3) {
				cout << Y[j].first << ", " << Y[j].second << endl;
				}*/
			if (Y[0].second == Y[1].first && Y[1].second == Y[2].first) {
				set<LL> S;
				REP(j, 3) {
					S.insert(Y[j].first);
				}
				S.insert(Y[2].second);
				if (SZ(S) == 4) {
					flag = 1;
					break;
				}
			}
		}
	} while (next_permutation(perm, perm + 3));

	if (flag == 0) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
	}
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(x) (x)*(x)

using namespace std;

const double eps = 1e-9;
const double PI = acos(-1.0);
const int INF = 1e9+7;
const int N = int (2e5+7);
    
int n, a[N];
ll res, ans;
string s;

int main () { 
   	//freopen("input.txt", "r", stdin);
   	//freopen("output.txt", "w", stdout);  
   	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for(int i = 0; i < n; i ++) {
		cin >> a[i];
	}	
	for(int i = 0; i < n; i ++) {
		ans += a[i] / 2;
		if(a[i + 1] && a[i] & 1)
			ans ++, a[i + 1] --;
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 640
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    int N;
    cin >> N;
    int free = 0;
    vector<bool> validColor(8, false);
    REP (i, N) {
        int a;
        cin >> a;
        int color = a / 400;
        if (color > 7) {
            free++;
        } else {
            validColor[color] = true;
        }
    }
    int c = count(validColor.begin(), validColor.end(), true);
    int ans1 = max(c, 1);
    int ans2 = c + free;

    cout << ans1 << " " << ans2 << endl;

    return 0;
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  if(L == R){
    cout << "Balanced" << endl;
  }
  if(L > R){
    cout << "Left" << endl;
  }
  if(L < R){
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <complex>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define rep(i, a, b) for(int (i) = (a), __omega = (b); (i) <= __omega; ++(i))
#define down(i, a, b) for(int (i) = (a), __omega = (b); (i) >= (b); --(i))
#define openfile(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout)
using namespace std;

int n, m; 

int f[300010], v;

struct edge { int to; edge *next; } e[300010], *et = e, *last[300010];

void add(int u, int v) { *++et = (edge) {v, last[u]}, last[u] = et; }

struct node {
	int cnt;
	node *ls, *rs;
} t[6000010], *ct = t, *root[300010];

#define Ls rt->ls, l, mid
#define Rs rt->rs, mid+1, r

void build(node *&rt, int l, int r) {
	rt = ++ct;
	if(l == r) return;
	int mid = (l+r)>>1;
	build(Ls);
	build(Rs);
}

void modify(node *&rt, int l, int r, int pos) {
	if(r < pos || pos < l) return;
	*++ct = *rt; rt = ct;
	if(l == r) {
		rt->cnt++;
		return;
	}
	int mid = (l+r)>>1;
	modify(Ls, pos);
	modify(Rs, pos);
	rt->cnt = (rt->ls->cnt)+(rt->rs->cnt); 
}

int query(node *rt, int l, int r, int L, int R) {
	if(r < L || R < l) return 0;
	if(L <= l && r <= R) return rt->cnt;
	int mid = (l+r)>>1;
	return query(Ls, L, R)+query(Rs, L, R);
}

int main() {
	//freopen("train.in", "r", stdin);
	//freopen("train.out", "w", stdout);
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) {
		int l, r;
		scanf("%d%d", &l, &r);
		if(l) add(l, r); else v++;
	}
	build(root[0], 1, m);
	for(int i = 1; i <= m; i++) {
		root[i] = root[i-1];
		for(edge *it = last[i]; it; it = it->next)
			modify(root[i], 1, m, it->to);
	}
	f[1] = n-v;
	for(int i = 2; i <= m; i++)
		for(int j = i; j <= m; j += i)
			f[i] += query(root[j], 1, m, j, m)-query(root[j-i], 1, m, j, m);//l : [j-i+1, j], r : [j, m]
	for(int i = 1; i <= m; i++)
		printf("%d\n", f[i]+v);
	return 0;
}


Measured memory_bytes: 141824
number_of_packages, number_of_trucks = gets.split.map(&:to_i)

packages = $stdin.readlines.map(&:to_i)

check = lambda do |capacity|
  package_pos = 0

  0.upto(number_of_trucks - 1) do |j|
    weight = 0

    while weight + packages[package_pos] <= capacity
      weight += packages[package_pos]
      package_pos += 1

      return number_of_packages if package_pos == number_of_packages
    end
  end

  return package_pos
end

left = 0
right = 100000 * 10000

while right - left > 1
  mid = (left + right) / 2

  v = check.call(mid)

  if v >= number_of_packages
    right = mid
  else
    left = mid
  end
end

puts right

Measured memory_bytes: 13684
n, m = gets.strip.split(" ").map(&:to_i)

ans = 0

if n == 1 && m== 1
  puts 1
elsif n == 1
  puts (m - 2)
elsif m == 1
  puts (n - 2)
else
  puts (n - 2) * (m - 2)
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    if (a[i] > x){
      ans += a[i] - x;
      a[i] = x;
    }
  }
  for (int i = 1; i < N; i++){
    if (a[i - 1] + a[i] > x){
      ans += a[i - 1] + a[i] - x;
      a[i] = x - a[i - 1];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

ll dp[201][100001];

int main(){
	int n; ll x;
	cin >> n >> x;
	vector<ll> s(n);
	for( auto &k : s ) cin >> k;
	sort( s.begin(), s.end() );
	for( int k = 0; k <= x; ++k ) dp[0][k] = k;
	for( int i = 1; i <= n; ++i ){
		for( int j = 1; j <= x; ++j ){
			dp[i][j] += dp[i-1][j%s[i-1]];
			dp[i][j] %= MOD;
			dp[i][j] += ((dp[i-1][j]*(i-1))%MOD);
			dp[i][j] %= MOD;
		}
	}
	cout << dp[n][x] << endl;
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(int i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int M=1e5+5;
const ll INF=1e15;
const int MOD=1e9+7;

int n,k;
int dp[M],val[105];

int DP(int x){
	if (x < 0) return 1;
	if (dp[x] != -1) return dp[x];
	dp[x] = 1;
	fp(i,0,n) dp[x] = dp[x]&DP(x-val[i]);
	dp[x] = dp[x]^1;
	return dp[x];
}

int main(){

	fastio;
	cin >> n >> k;
	fp(i,0,M) dp[i] = -1;
	fp(i,0,n) cin >> val[i];
	if (DP(k) == 1) cout << "First\n";
	else cout << "Second\n";

	return 0;
}


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

struct Point{
	double x,y;
};
Point operator-(Point a,Point b){
	return {a.x-b.x,a.y-b.y};
}
struct Segment{
	Point p1,p2;
};

double cross(Point a,Point b){
	return a.x*b.y-a.y*b.x;
}
const int CLOCKWISE=-1;
const int COUNTER_CLOCKWISE=1;

int ccw(Point p1,Point p2,Point p3){
	Point p=p2-p1,q=p3-p1;
	if(cross(p,q)>0)return COUNTER_CLOCKWISE;
	if(cross(p,q)<0)return CLOCKWISE;
	return 0;
}

Point p[40000];
int ans[70000];

int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%lf%lf",&p[i].x,&p[i].y);
		p[i].x=p[i].x/(1e6-100)*1e6;
		p[i].y=p[i].y/(1e6-100)*1e6;
	}
	int Q;cin>>Q;
	vector<pair<Point,int>>qs(Q);
	rep(i,Q){
		scanf("%lf%lf",&qs[i].first.x,&qs[i].first.y);
		qs[i].second=i;
	}
	sort(p,p+n,[](Point a,Point b){
		return a.x<b.x;
	});
	vector<Point>a,b;
	rep(i,n){
		while(a.size()>1&&ccw(a[a.size()-2],a[a.size()-1],p[i])!=CLOCKWISE)a.pop_back();
		a.push_back(p[i]);
	}
	for(int i=n-1;i>=0;i--){
		while(b.size()>1&&ccw(b[b.size()-2],b[b.size()-1],p[i])!=CLOCKWISE)b.pop_back();
		b.push_back(p[i]);
	}
	reverse(b.begin(),b.end());
	sort(qs.begin(),qs.end(),[](auto a,auto b){
		return a.first.x<b.first.x;
	});
	memset(ans,-1,sizeof(ans));
	int s1=0,s2=0;
	for(auto&q:qs){
		if(q.first.x<a[0].x)ans[q.second]=0;
		else if(a.back().x<q.first.x)ans[q.second]=0;
		else{
			while(s1+1<a.size()&&a[s1+1].x<q.first.x)s1++;
			while(s2+1<b.size()&&b[s2+1].x<q.first.x)s2++;
			double l=(a[s1+1].y-a[s1].y)/(a[s1+1].x-a[s1].x)*(q.first.x-a[s1].x)+a[s1].y;
			double r=(b[s2+1].y-b[s2].y)/(b[s2+1].x-b[s2].x)*(q.first.x-b[s2].x)+b[s2].y;
			if(l>r)swap(l,r);
			if(l<=q.first.y&&q.first.y<=r)ans[q.second]=1;
			else ans[q.second]=0;
		}
	}
	rep(i,Q){
		printf("%d\n",ans[i]);
	}
}



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

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

    vector<int> a(n);
    vector<int64_t> sunuke(n);
    vector<int64_t> arai(n);
    int64_t sum = 0;
    for (auto i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
        sunuke[i] = sum;
    }
    sum = 0;
    for (auto i = n - 1; i >= 0; i--) {
        sum += a[i];
        arai[i] = sum;
    }

    int64_t ans = INT_MAX;
    for (auto i = 0; i < n - 1; i++) {
        // cout << sunuke[i] << " " << arai[i + 1] << endl;
        ans = min(ans, abs(sunuke[i] - arai[i + 1]));
    }

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

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

using namespace std;

int main(){
 int n,i,p,d,j,N=0;
 cin >> n;
 for (i=0;i<n;++i) {
   cin >> p;
   d=sqrt(p);
   for (j=2;j<d+1;++j) {
     if (p%j==0) {
       N++;
       break;
     }
   }
 }
 cout << (n-N) << endl;
 return 0;
}



Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int K = in.nextInt();
            int[] D = new int[K];
            for (int i = 0; i < K; i++) {
                D[i] = in.nextInt();
            }

            for (int n = N;; n++) {
                if (isLike(n, D)) {
                    System.out.println(n);
                    return;
                }
            }
        }
    }

    private static boolean isLike(int n, int[] D) {
        for (; n > 0; n /= 10) {
            int mod = n % 10;
            for (int d : D) {
                if (mod == d) {
                    return false;
                }
            }
        }
        return true;
    }
}


Measured memory_bytes: 23252
#include <iostream>

using namespace std;

int main(void){
  char C[2][3];
  int i, j;
  for(i=0; i<2; i++)
    for(j=0; j<3; j++)
      cin >> C[i][j];

  //1行目の左＝2行目の右 かつ 1行目の右=2行目の左
  if(C[0][0] == C[1][2] && C[0][2] == C[1][0])
    //1行目と2行目で中央が等しい
    if(C[0][1] == C[1][1])
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  else
    cout << "NO" << endl;
      
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    ll mat[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            mat[i][j] = 1ll<<60;
        }
    }
    while(m-- > 0){
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        mat[a][b] = mat[b][a] = c;
    }
    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(mat[i][k] == 1ll<<60 || mat[k][j] == 1ll<<60)  continue;
                mat[i][j] = min(mat[i][j], mat[i][k]+mat[k][j]);
            }
        }
    }
    vector<int> path[n];
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(mat[i][j] > l)   continue;
            path[i].push_back(j);
            path[j].push_back(i);
        }
    }
    int q;
    cin >> q;
    while(q-- > 0){
        int s, t;
        cin >> s >> t;
        s--, t--;
        vector<int> dp(n, 1<<30);
        queue<int> q;
        q.push(s);
        dp[s] = -1;
        while(!q.empty()){
            int x = q.front();  q.pop();
            for(int next : path[x]){
                if(dp[next] > dp[x]+1){
                    dp[next] = dp[x]+1;
                    if(next == t){
                        break;
                    }
                    q.push(next);
                }
            }
            if(dp[t] != 1<<30)  break;
        }
        cout << (dp[t] == 1<<30 ? -1 : dp[t]) << endl;
    }
    return 0;
}


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

main(){
	int n;
	double ans,k;
	double a[110];
	cin>>n;
	ans = 1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ans *= a[i];
	}
	for(int i=1;i<=n;i++)
		k += ans/a[i];
	ans /= k;
	cout<<fixed<<setprecision(20)<<ans;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;

int main(){
	int K;
	cin >> K;
	if(K % 2 == 0) cout << (K / 2) * (K / 2) << endl;
	else cout << ((K - 1) / 2) * ((K - 1) / 2 + 1) << endl;
}

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

const int64_t N = int64_t(1e9);

int main() {
	int n, k;
	cin >> n >> k;
	map<int, int> cnt;
	int64_t ans = 0;
	int s = 0;
	cnt[0]++;
	queue<int> q;
	q.push(0);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		s = (s + x - 1) % k;
		q.push(s);
		if (q.size() > k) {
			cnt[q.front()]--;
			q.pop();
		}
		ans += cnt[s];
		cnt[s]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10496
#include <iostream>

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int c = 0;
        int t = i;
        for (int j = 0; j < 5; j++) {
            c += t % 10;
            t /= 10;
        }
        if (a <= c && c <= b) cnt += +i;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3140
# 入力
N = int(input())
witness = [[-1] * N for _ in range(N)]
for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        witness[i][x - 1] = y

# 正直者の組を作り判定
ans = 0
for i in range(1, 2 ** N + 1):
    honest = [0] * N
    for j in range(N):
        if int(format(i, 'b').zfill(N)[j]) == 1:
            honest[j] = 1

    is_correct = True
    for j in range(N):
        if honest[j] == 1:
            for k in range(N):
                if witness[j][k] == -1:
                    pass
                elif witness[j][k] != honest[k]:
                    is_correct = False
    if is_correct:
        ans = max(ans, sum(honest))

print(ans)


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

struct edge {ll to,cost;};
vector<edge> G[100000];
vector<ll> depth(100000);

void dfs(int v,int p,ll d){
    depth[v] = d;
    for(int i = 0;i < G[v].size();i ++){
        if(G[v][i].to==p) continue;
        dfs(G[v][i].to,v,G[v][i].cost+d);
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n-1;i ++){
        ll a,b,c;
        cin >> a >> b >> c;
        a --;b --;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    
    int q,k;
    cin >> q >> k;k --;
    dfs(k,-1,0);

    for(int i = 0;i < q;i ++){
        int x,y;
        cin >> x >> y;
        x --;y --;
        cout << depth[x]+depth[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 15872
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b,c;
};

//降順
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
#define MAXSIZE 200000
int list[MAXSIZE];
int tail;

void Init(void){
    tail=0;
}
int Top(void){
    return 0;
}

int Next(int pos){
    if(pos<tail-1){
        return pos+1;
    }else{
        return -1;
    }
}
int Count(void){
    return tail;
}

int Item(int pos){
    if((pos>=0)&&(pos<tail)){
        return list[pos];
    }else{
        return 0;
    }
}
void Add(int value){
    if(tail<MAXSIZE){
        list[tail]=value;
        tail++;
    }
}
void Delete(int pos){
    if((pos>=0)&&(pos<tail)){
        int i;
        for(i=pos;i<tail-1;i++){
            list[i]=list[i+1];
        }
        tail--;
    }
}

int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    char spr[a];
    scanf("%s",spr);
    int j;
    int cnt=0;
    int temp=0;
    for(j=0;j<a;j++){
        if(spr[j]=='a' && temp<(b+c)){
            printf("Yes\n");
            temp++;
        }else if(spr[j]=='b' && temp<(b+c) && cnt<c){
            printf("Yes\n");
            cnt++;
            temp++;
        }else if(spr[j]=='b'){
            cnt++;
            printf("No\n");
        }else{
            printf("No\n");
        }
    }
    
}


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

int main() {
  int n, k, x;
  cin >> n >> k;
  x = 1;

  // ここにプログラムを追記
  rep (i, n) {
    if ((x * 2) < (x + k)) {
      x *= 2;
    }
    else {
      x += k;
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n;
    cin>>n;
    vector<int> a(n+2);
    a[0]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    a[n+1]=0;
    int s=0;
    rep(i,n+1){
        s +=abs(a[i+1]-a[i]);
    }
    //cout<<s<<endl;
    for(int i=1;i<=n;i++){
        if(a[i]>=a[i-1]&&a[i]<=a[i+1]){
            cout<<s<<endl;
        }
        else if(a[i]<=a[i-1]&&a[i]>=a[i+1]){
            cout<<s<<endl;
        }
        else if(a[i]>=a[i-1]){
            cout<<s-2*abs(a[i]-max(a[i-1],a[i+1]))<<endl;
        }
        else{
            cout<<s-2*abs(a[i]-min(a[i-1],a[i+1]))<<endl;
        }

    }
}

Measured memory_bytes: 1664
a = []
for i in range(5):
    a.append(int(input()))
r = list(map(lambda x: (x // 10 + 1) * 10 if x % 10 != 0 else x, a))
ans = sum(r)
adv = []
for i in range(5):
    adv.append(r[i] - a[i])
adv.sort()
ans -= adv[4]
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N)cin >> A[i];
    ll sum = 1;
    rep(i,K)sum *= A[i];
    for(int i = K; i < N; i++){
        ll tmp = sum;
        tmp /= A[i-K];
        tmp *= A[i];
        if(A[i-K] < A[i]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
        sum = tmp;
    }
}


Measured memory_bytes: 4776
#include <iostream>
#include <vector>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)

bool check(int num, vector<int> vec, int k)
{
    int i = 0;
    int sum = 0;
    repi(j, k, 0)
    {
        sum = 0;
        while (vec[i] + sum <= num)
        {
            sum += vec[i];
            i++;
            if (i == vec.size())
                return true;
        }
    }
    return false;
}
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> w(n);
    repi(i, n, 0)
    {
        cin >> w[i];
    }

    int left = 0, right = INF + k - 1 / k;
    while (right - left > 1)
    {
        int mid = (left + right) / 2;
        if (check(mid, w, k))
        {
            right = mid;
        }
        else
        {
            left = mid;
        }
        // cout << right << endl;
        // cout << left << endl;
    }
    cout << right << endl;
    return 0;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1)res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

struct Combination{
    vector<ll> fac,finv,inv;
    Combination(int mx){init(mx);}
    void init(int mx){
        fac.resize(mx+1);
        finv.resize(mx+1);
        inv.resize(mx+1);
        fac[0]=fac[1]=1;
        finv[0]=finv[1]=1;
        inv[1]=1;
        for(int i=2;i<=mx;i++){
            fac[i]=fac[i-1]*i%MOD;
            inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
            finv[i]=finv[i-1]*inv[i]%MOD;
        }
    }
    ll calc(int n,int k){
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
    }
};

int main(){
    int n;
    cin>>n;
    ll c[n];
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    sort(c,c+n);
    Combination comb(n-1);
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=c[n-1-i]*(i+2);
        ans%=MOD;
    }
    ans=(ans*modpow(4,n-1))%MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 6528
fs = [5, 7, 5, 7, 7]
while True:
    flag = 0
    n = int(input())
    if n == 0:
        quit()
    w = []
    for i in range(n):
        w.append(len(input()))
    for i in range(len(w)):
        k, temp = 0, 0
        for j in range(i, len(w)):
            temp += w[j]
            if temp > fs[k]:
                break
            elif temp == fs[k]:
                if k == 4:
                    print(i+1)
                    flag = 1
                    break
                else:
                    k += 1
                    temp = 0
        if flag == 1:
            break



Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

char dp[21][1<<14];
int maxSize[21];
int n;
// ツ残ツづィsツづ、idxツづ個タツーツδ督づ個づつォツ、ツ渉淞づづゥツつゥツづつ、ツつゥ
bool dfs(int idx,int s){
    if(dp[idx][s]!=-1)
        return dp[idx][s];
    else if(s==1)
        return false;
    bool res=false;
    for(int i = 1; i <= maxSize[idx]; i++){
        if(s-i>=1){
            bool b=dfs((idx+1)%(2*n),s-i);
            if(!b){
                res=true;
                break;
            }
        }
    }
    return dp[idx][s]=res;
}

int main(){
    while(cin>>n&&n!=0){
        memset(dp,-1,sizeof(dp));
        int s;
        cin>>s;
        for(int i = 0; i < 2*n; i++)cin>>maxSize[i];
        if(dfs(0,s))
            cout<<1<<endl;
        else
            cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#define PIE 3.14159265358979
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;


const ll MOD=1e9+7;
vector<int> K;
ll dp[100015][105];
ll D;
int N;

int main(){
    string str;
    cin>>str;
    cin>>D;
    ll bigD = 100*D;
    N=str.length();
    K.resize(N);
    rep(i,N){
        K[i]=(ll)(str[i]-'0');
    }
    rep(i,D){
        dp[0][i]=0;
    }
    dp[0][0]=1;
    rep(i,N){
        rep(j,D){
            ll &next = dp[i+1][j];
            next = 0;
            rep(k,10){
                next += dp[i][(j+bigD-k)%D];
                next %= MOD;
            }
        }
    }
//    rep(i,N){
//        rep(j,D){
//            cout<<dp[i][j]<<" ";
//        }
//        cout<<endl;
//    }
    ll ans = MOD-1;
    ll digsum = 0;
    rep(i,N){
        rep(j,K[i]){
            ans += dp[N-1-i][(bigD-j-digsum)%D];
            ans %= MOD;
        }
        digsum += K[i];
        digsum %= D;
    }
    if(digsum==0){
        ans = (ans+1)%MOD;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 10496
#include <cstdio>
#include <string>

using namespace std;

int main(){
	
	char input[500000];
	string s;
	long long int sum = 0;
	long int bct = 0;
	
	scanf("%s", input);
	s = input;
	
	for(int i=0; i<s.length(); i++){
		if(s[i] == 'B') bct++;
		else if(s[i] == 'W'){
			sum += bct;
		}
	}
	
	printf("%lld", sum);
	
	return 0;
	
}


Measured memory_bytes: 640