akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int64_t X, K, D;
    cin >> X >> K >> D;
    int64_t abs_X = abs(X);
    int64_t zero_kyori_kaisuu = abs_X / D;
    int64_t amari = abs_X % D;
    if (zero_kyori_kaisuu > K) {
        cout << abs_X - (K * D) << endl;
    } else if (zero_kyori_kaisuu == K) {
        cout << amari << endl;
    } else {
        int64_t nokorikaisuu = K - zero_kyori_kaisuu;
        if (nokorikaisuu % 2 == 0) {
            cout << amari << endl;
        } else {
            cout << abs(amari - D) << endl;
        }
    }
    return 0;
}

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

"""
a+b = K i
b+c = K j
c+a = K k
2(a+b+c) = K(i+j+k)

k%2=0ならば,
a+b+cはk//2の倍数でなければならない、かつ、差を取ると結局a,b,cがそれぞれk//2の倍数
でなければならい。それでa+b,b+c,c+dはｋの倍数だから、a,b,cはすべて偶数またはすべて奇数
でなければならない。

それ以外の場合、
a+b+cがkの倍数である必要があり、かつ差を取ると結局a,b,cがすべてkの倍数でなければ
ならない。
"""

if k%2==0:
    k//=2
    a = n//k
    even = a//2
    if a%2==0:
        odd = even
    else:
        odd = even+1
    ans = even**3 + odd**3
else:
    ans = (n//k)**3
print(ans)



Measured memory_bytes: 9056
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

import fileinput
import math
for line in fileinput.input():
    a, b = map(int, line.split())
    g = gcd(a, b)
    lcm = a * b // g
    print(g, lcm)

Measured memory_bytes: 7692
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)



int main() {
	int n, m, c, i = 0, j = 0, ans=0,anss=0;
	cin >> n>> m>> c;
	vector<int>b(m);
	vector<vector<int>>a(n,vector<int>(m));
	rep(i, m) {
		cin >> b.at(i);
	}
	rep(i, n) {
		ans = 0;
		rep(j, m) {
			cin>>a.at(i).at(j);
			ans += a.at(i).at(j) * b.at(j);

		}
		if (ans + c > 0) {
		
			anss++;
		}
		
	}
	cout << anss  << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>

int main(void)
{
	int n, x, n1, n2, n3, k;

	scanf("%d %d", &n, &x);
	while( n != 0 || x != 0)
	{
		k=0;
		for(n1 = 1; n1 <= n - 2; n1++)
		{
			for(n2 = n1 + 1; n2 <= n - 1; n2++)
			{
				for(n3 = n2 + 1; n3 <= n; n3++)
				{
					if(n1 + n2 + n3 == x)
						k++;
				}
			}
		}
		printf("%d\n",k);
		scanf("%d %d", &n, &x);
	}
}



Measured memory_bytes: 2040
#include <iostream>
using namespace std;
using ll = long long ;

int main () {
    ll x, step = 0, bank = 100;
    cin >> x;

    while (bank < x) {
        step++;
        bank += bank/100;
    }
    // for (int i = 0;;i++ ) {
    //     if (bank > x) 
    // }
    cout << step << endl;
    return 0;
}

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


def solve(S: str):
    t = S.split("/")
    hi = int("".join(t))

    if hi > 20190430:
        print("TBD")
    else:
        print("Heisei")

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;

typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
#define log sdfdsfdsf

const ll DIM = 2E5+7;
const ll MOD = 1e9+7;

const ll INF = 1E19;
const ld eps = 0.00000000000001;
const ld PI = 3.14159265358979323846;
int getInt(int a = 0, int b = INT_MAX){
    static mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution <int> (a, b)(rng);
}
struct node{
    ll fi,sc,pos;
};
const bool operator<(const node &a,const node &b){
    if (a.fi==b.fi)return a.sc<b.sc;
    return a.fi<b.fi;
}

long long gcdex(long long a, long long b, long long &x, long long &y) {
    if(a == 0) {
        x = 0; y = 1; return b;
    }

    long long x1,y1,d;
    d = gcdex(b%a, a, x1, y1);
    y = x1;
    x = y1 - (b/a) * x1;
    return d;
}
ll n;
ll F(ll a){
    ll b = n/a;
    a = -a;
    ll x,y;
    ll g = gcdex(a,b,x,y);
    if (abs(g)!=1)return INF;
    x*=g;
    y*=g;
    if (x<0){
        ll cnt = (-x)/b+(((-x)%b)!=0);
        x+=cnt*b;
        y-=cnt*a;
    }
    if (x==0){
        x+=b;
        y-=a;
    }
    return (-a)*x;

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

    cin>>n;
    n*=2;
    ll sq = sqrt(n);
    ll res = INF;
    for(ll i = 1;i<=sq;++i){
        if (n%i!=0)continue;
        res = min(res,F(n/i));
        res = min(res,F(i));
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3696
N, M = map(int, input().split())
ac = 0
wa = 0
ref = [0] * N
for i in range(M):
  p, s = map(str, input().split())
  p = int(p) - 1
  if ref[p] != -1:
    if s == 'WA':
      ref[p] += 1
    else:
      wa += ref[p]
      ac += 1
      ref[p] = -1
print(ac, wa)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5+1;
vector<vector<char>>a(6,vector<char>(6));
int n,m;

bool check(int p,int q,int k,int count)
{
        //cout<<p<<" "<<q<<"  ";
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                {
                        if(a[i][j]=='#')
                        {
                                if(((p>>i) & 1) || ((q>>j) & 1))
                                count--;
                        }
                }
        }
        //cout<<count<<" "<<k<<endl;
        return count==k;
}

void solve()
{
   ll k;
   cin>>n>>m>>k;
   
   
   ll countb = 0;
   for(int i=0;i<n;i++)
   {
        for(int j = 0;j<m;j++)
        {
                cin>>a[i][j];
                if(a[i][j]=='#') countb++;
        }
   }
   
   if(countb<k){
           cout<<0<<endl;
           
   }
   
   else if(countb==k)
   {
        vector<ll>row(n,0);
        vector<ll>col(m,0);
        
        for(int i=0;i<n;i++)
       {
                int f = 0;
                for(int j = 0;j<m;j++)
                {
                        if(a[i][j]=='#')
                        {
                                f = 1;
                                col[j] = 1;
                        }
                }
                row[i] = f;   
       }    
       
       ll count = 0;
        for(int i=0;i<n;i++)
        {
                if(row[i]==0) count++;
        }
        for(int i=0;i<m;i++)
        {
                if(col[i]==0) count++;
        }
        cout<<pow(2,count)<<endl;
   }
   
   else
   {
        ll rem = countb - k;
        ll ans = 0;    
        for(int i=0;i<(1<<n);i++)
        {
                for(int j=0;j<(1<<m);j++)
                {
                        if(check(i,j,k,countb))
                        ans++;
                }
        }
        cout<<ans<<endl;
   }
   
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
	    //cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

Measured memory_bytes: 4116
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, k = LI()
    s = S()
    s[k-1] = s[k-1].lower()
    print("".join(s))

    return

#B
def B():
    s = S()
    a = int("".join(s[:2]))
    b = int("".join(s[2:]))
    if 0 < a <= 12:
        if 0 < b <= 12:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    elif a == 0:
        if 0 < b <= 12:
            print("YYMM")
        else:
            print("NA")
    else:
        if 0 < b <= 12:
            print("YYMM")
        else:
            print("NA")
    return

#C
def C():
    n, k = LI()
    ans = 0
    if k == 1:
        print(1)
        return
    nibuiti = [None for i in range(int(math.log2(k) + 1))]
    for num in range(int(math.log2(k) + 1)):
        if num == 0:
            nibuiti[num] = 1 / 2
            continue
        nibuiti[num] = nibuiti[num-1]/2
        
    for i in range(1, n + 1):
        if i >= k:
            ans += 1
            continue
        b = nibuiti[int(math.log2((k - 1) // i))]
        ans += b
    print(ans/n)
    return

#D
def D():
    n = II()
    color = [0 for i in range(n)]
    edge = [[] for i in range(n)]
    for i in range(n - 1):
        v, u, w = LI_()
        edge[v].append((u,w+1))
        edge[u].append((v,w+1))
    check = [True for i in range(n)]
    for i in range(n):
        q = deque()
        q.append(i)
        
        while q:
            a = q.pop()
            if check:
                check[a] = False
                for k,w in edge[a]:
                    if check[k]:
                        q.append(k)
                        if w % 2:
                            color[k] = color[a] ^ 1
                        else:
                            color[k] = color[a]
    for c in color:
        print(c)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 71344
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input!{
        k: usize,
        s: String,
    };
    if s.len() > k {
        println!("{}...", &s[..k]);
    } else {
        println!("{}", s);
    }
}


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

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long

int main()
{
  IOS;
  string s, t;
  int a, b;
  string u;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if (u==s)
    cout << a-1 << " " << b << endl;
  else if (u==t)
    cout << a << " " << b-1 << endl;
  return 0;
}


Measured memory_bytes: 3604
local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = bls(1, i - 1)
    for j = 1, cnt do
      self.stage[i][j] = self.func(self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.stage = {{}}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.stage[stagenum] = {}
  end
  self.stagenum = stagenum
  for i = 1, n do self.stage[stagenum][i] = i end
  for i = n + 1, mul do self.stage[stagenum][i] = emptyvalue end
  self:updateAll()
end
SegTree.update = function(self, idx)
  for i = self.stagenum - 1, 1, -1 do
    local dst = brs(idx + 1, 1)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.func(self.stage[i + 1][idx], self.stage[i + 1][rem])
    idx = dst
  end
end
SegTree.top = function(self) return self.stage[1][1] end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local n, m = io.read("*n", "*n")
local len = {}
local edge = {}
local invedge = {}
local updated = {}
for i = 1, n + 1 do
  len[i] = {}
  for j = 1, n + 1 do
    len[i][j] = -1
  end
  edge[i] = {}
  invedge[i] = {}
  updated[i] = false
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  edge[a][b] = true
  invedge[b][a] = true
end
local g_start = false
local function getmin(a, b)
  if updated[a] and updated[b] then
    return len[g_start][a] < len[g_start][b] and a or b
  elseif updated[a] then return a
  elseif updated[b] then return b
  else return n + 1
  end
end
local st = SegTree.new(n, getmin, n + 1)
for i_start = 1, n do
  g_start = i_start
  for i = 1, n do
    len[i_start][i] = -1
    updated[i] = false
  end
  len[i_start][i_start] = 0
  updated[i_start] = true
  st:updateAll()
  while true do
    local src = st:top()
    if src == n + 1 then break end
    for dst, _u in pairs(edge[src]) do
      if len[i_start][dst] < 0 or len[i_start][src] + 1 < len[i_start][dst] then
        len[i_start][dst] = len[i_start][src] + 1
        updated[dst] = true
        st:update(dst)
      end
    end
    updated[src] = false
    st:update(src)
  end
end
local inf = 1000000007
local minlen = inf
local scand = 0
for i = 1, n do
  for j = 1, n do
    if i ~= j then
      if 0 <= len[i][j] and 0 <= len[j][i] then
        if len[i][j] + len[j][i] < minlen then
          minlen = len[i][j] + len[j][i]
          scand = i
        end
      end
    end
  end
end
if scand == 0 then
  print(-1)
else
  print(minlen)
  local ans = {scand}
  for i = minlen - 1, 1, -1 do
    local dst = ans[#ans]
    for src, _u in pairs(invedge[dst]) do
      if len[scand][src] == i and len[src][scand] == minlen - i then
        table.insert(ans, src)
        break
      end
    end
  end
  print(table.concat(ans, "\n"))
end


Measured memory_bytes: 8832
n,m = map(int,input().split())

p = [True for _ in range(n+1)]

p[0] = 1
p[1] = 1

for _ in range(m):
    a = int(input())
    p[a] = 0

for i in range(2,n+1):
    if p[i]:
        p[i] = p[i-1] + p[i-2]

print(p[n]%(10**9+7))

Measured memory_bytes: 460056
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n, m = MII()
    hh = MII()
    ab = [MIIZ() for _ in range(m)]
    t = {i: [] for i in range(n)}
    cnt = 0
    for a, b in ab:
        t[a].append(b)
        t[b].append(a)
    for k, v in t.items():
        o = hh[k]
        for vi in v:
            if hh[vi] >= o:
                break
        else:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

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

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

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

    //vector <pair<pair<string,int>,int> p(N);
    pair<pair<string,int>,int> p[N];

    REP(i,N){
        int t;
        string strT;
        cin >> strT >> t;

        //-にして入れれば、降順でソートできる
        //firstに複数ぶちこめば、二値の昇順でソートしてくれる
        p[i] = make_pair(make_pair(strT,-t),i+1);
    }
    //sort(p.begin,p.end);
    sort(p,p+N);

    REP(i,N){
        cout << p[i].second << endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll p[1000005];
int main(){
    int k=7;
    int a;
    cin>>a;
    int ans=1;
    while(1){
        if(k<a){
            k*=10;
            k+=7;
            ans++;
        }
        else{
            k%=a;
            if(k==0){
                cout<<ans<<endl;
                return 0;
            }
            else if(p[k]){
                cout<<-1<<endl;
                return 0;
            }
        p[k]=1;
        }
    }
    return 0;
}

Measured memory_bytes: 11384
#include <bits/stdc++.h>
using namespace std;
 
#define rng(x) x.begin(), x.end()
#define pb push_back
#define F first
#define S second
#define el '\n'
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.F << "," << P.S << ")"; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ "; for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") "; return os<<"}";}
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout<<name<<" : "<<arg1<<'\n';}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names,comma-names)<<" : "<<arg1<<" |";__f(comma+1, args...);}
typedef long long ll; typedef pair<int,int> pi; 
typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi;
 
/*-----------------------------Code begins----------------------------------*/

/*

leftest element which is (>= e and <= e + k);

(
1 5 4 3 8 6 9 7 2 4
1 1 2 3 1 4 5 6 4 7
)
.
*/

void solve(){
    int n, k; cin>>n>>k;
    vi a(n); for(int &i : a) cin>>i;
    vi eui(n, -1), eli(n, -1);
    set <pi> up, lw;
    for (int i = 0; i < n; ++i){
        auto itr = up.lower_bound({a[i], -1});
        for (; itr != up.end() ; itr = up.upper_bound(*itr)){
            if(itr->F > a[i] + k) break;
            eli[itr->S] = i;
            up.erase(*itr);
        }
        itr = lw.lower_bound({a[i] - k, -1});
        for (; itr != lw.end() ; itr = lw.upper_bound(*itr)){
            if(itr->F > a[i]) break;
            eui[itr->S] = i;
            lw.erase(*itr);
        }
        up.insert({a[i], i}), lw.insert({a[i], i});
    }

    vi dp(n, 1);
    for (int i = n-1; i >= 0; --i){
        if(eui[i] != -1)
            dp[i] = max(dp[i], dp[eui[i]] + 1);
        if(eli[i] != -1)
            dp[i] = max(dp[i], dp[eli[i]] + 1);
    }
    cout<<(*max_element(rng(dp)))<<el;
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int T=1, tc = 1;
    // cin>>T; 
    while(T--){
        solve();
    }
    return 0; 
}

Measured memory_bytes: 7948
#include<stdio.h>
#include<math.h>

int main(){
	int hei[29][29], top[29][29], cnt[6];
	int j, k, l, m, ro[2], nx[2], nowx, nowy, stop;
	int n, t, f;
	int hoko[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};
	scanf("%d", &n);
	while(n != 0)
	{
		//init
		for(j=0;j<29;j++)
		{
			for(k=0;k<29;k++)
			{
				hei[j][k]=0;
				top[j][k]=0;
			}
		}
		for(l=0;l<6;l++)
		{
			cnt[l]=0;
		}
		//init
		for(m=0;m<n;m++)
		{
			nowx=14;
			nowy=14;
			stop=0;
			scanf("%d %d", &t, &f);
			while(stop==0)
			{
				if(t==1)
				{
					nx[0]=2;
					nx[1]=3;
					if(f==2)
					{
						ro[0]=2;
						ro[1]=3;
					}
					if(f==3)
					{
						ro[0]=1;
						ro[1]=2;
					}
					if(f==4)
					{
						ro[0]=3;
						ro[1]=0;
					}
					if(f==5)
					{
						ro[0]=0;
						ro[1]=1;
					}
				}
				if(t==2)
				{
					nx[0]=1;
					nx[1]=3;
					if(f==1)
					{
						ro[0]=2;
						ro[1]=1;
				}
					if(f==3)
					{
						ro[0]=3;
						ro[1]=2;
					}
					if(f==4)
					{
						ro[0]=1;
						ro[1]=0;
					}
					if(f==6)
					{
						ro[0]=0;
						ro[1]=3;
					}
				}
				if(t==3)
				{
					nx[0]=1;
					nx[1]=2;
					if(f==1)
					{
						ro[0]=2;
						ro[1]=3;
					}
					if(f==5)
					{
						ro[0]=3;
						ro[1]=0;
					}
					if(f==2)
					{
						ro[0]=1;
						ro[1]=2;
					}
					if(f==6)
					{
						ro[0]=0;
						ro[1]=1;
					}
				}
				if(t==4)
				{
					nx[0]=1;
					nx[1]=2;
					if(f==1)
					{
						ro[0]=2;
						ro[1]=1;
					}
					if(f==2)
					{
						ro[0]=3;
						ro[1]=2;
					}
					if(f==5)
					{
						ro[0]=1;
						ro[1]=0;
					}
					if(f==6)
					{
						ro[0]=0;
						ro[1]=3;
					}
				}
				if(t==5)
				{
					nx[0]=1;
					nx[1]=3;
					if(f==1)
					{
						ro[0]=2;
						ro[1]=3;
					}
					if(f==4)
					{
						ro[0]=3;
						ro[1]=0;
					}
					if(f==3)
					{
						ro[0]=1;
					ro[1]=2;
					}
					if(f==6)
					{
						ro[0]=0;
						ro[1]=1;
					}
				}
				if(t==6)
				{
					nx[0]=2;
					nx[1]=3;
					if(f==2)
					{
						ro[0]=2;
						ro[1]=1;
					}
					if(f==3)
					{
						ro[0]=3;
						ro[1]=2;
					}
					if(f==4)
					{
						ro[0]=1;
						ro[1]=0;
					}
					if(f==5)
					{
						ro[0]=0;
						ro[1]=3;
					}
				}
				if(hei[nowx][nowy]>hei[nowx+hoko[ro[0]][0]][nowy+hoko[ro[0]][1]])
				{
					nowx += hoko[ro[0]][0];
					nowy += hoko[ro[0]][1];
					if(ro[0]==2) f = 7 - t;
					if(ro[0]==0) f = t;
					t = nx[0];
				}
				else if(hei[nowx][nowy]>hei[nowx+hoko[ro[1]][0]][nowy+hoko[ro[1]][1]])
				{
					nowx += hoko[ro[1]][0];
					nowy += hoko[ro[1]][1];
					if(ro[1]==2) f = 7 - t;
					if(ro[1]==0) f = t;
					t = nx[1];
				}
				else
				{
					if(cnt[top[nowx][nowy]-1]>0) cnt[top[nowx][nowy]-1]--;
					top[nowx][nowy] = t;
					cnt[t-1]++;
					hei[nowx][nowy]++;
					stop++;
				}
			}
		}
		printf("%d %d %d %d %d %d\n", cnt[0], cnt[1], cnt[2], cnt[3], cnt[4], cnt[5]);
		scanf("%d", &n);
	}
	return 0;
}

Measured memory_bytes: 608
n=int(input())
sche=[0 for i in range(n)]
#ith store,jth day ,kth time >sche[i][2*(j-1)+(k-1)]
for h in range(n):
    sche[h]={i for i,v in enumerate(input().split()) if v=="1" }
profit=[list(map(int,input().split())) for i in range(n)]
ans=-float("INF")
for i in range(1,1024):
    op={j for j in range(10) if (i>>j)%2}
    pre=0
    for g in range(n):
        pre+=profit[g][len(op&sche[g])]
    ans=max(pre,ans)
print(ans)

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

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


	int sight = 1 + 2 * D;
	bool break_flg = false;
	int count = 0;

	for (int i = 1; i < N + 1; ++i) {
		if (N <= (sight * i)) {
			break_flg = true;
		}

		count = i;
		if (break_flg) break;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll dp[22][2100000];
int a[30][30];

int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n)rep(j,0,n)scanf("%d",&a[i][j]);
	dp[0][0]=1;
	rep(i,0,n)rep(j,0,1LL<<n)if(dp[i][j])rep(k,0,n)if(a[i][k]==1&&bit(j,k)==0){
		dp[i+1][j|1LL<<k]=(dp[i+1][j|1LL<<k]+dp[i][j])%MOD;
	}
	printf("%lld\n",dp[n][(1LL<<n)-1]);
	return 0;
}

Measured memory_bytes: 309376
from collections import Counter, defaultdict
# n = int(input())
# li = list(map(int, input().split()))
# n = int(input())
a, b = map(int, input().split())
c, d = map(int, input().split())
# d = defaultdict(lambda: 0)

# s = input()
print("1" if c == a+1 else "0")

Measured memory_bytes: 64780
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

a,b,c = nm()
eps = 10**-7

if c > a + b and (c - a - b)**2 > 4 * a * b:
    print('Yes')
else:
    print('No')


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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

int n[4];

int main()
{
  for (int i = 0; i < 4; i++) cin >> n[i];
  sort(n,n+4);
  if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
N,M=map(int,input().split())
sc=[-1]*N
for _ in range(M):
  s,c=map(int,input().split())
  if sc[s-1]==-1:
    sc[s-1]=c
  elif sc[s-1]!=c:
    print("-1")
    sys.exit(0)
    
if sc[0]==-1 and N!=1:
  sc[0]=1
elif sc[0]==-1 and N==1:
  print("0")
  sys.exit(0)
elif sc[0]==0 and N==1:
  print("0")
  sys.exit(0)
for i in range(1,N):
  if sc[i]==-1:
    sc[i]=0

for i in range(N):
  if sc[i]!=0:
    break
  else:
    if i==N-1:
      print("-1")
      sys.exit(0)
print((''.join(map(str, sc))))


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#define ll long long
#define maxn 7510
using namespace std;

ll a[maxn];
int main(){
  int k,s;
  ll ans=0;
  scanf("%d%d",&k,&s);
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      if(s-x-y<=k&&s-x-y>=0)
        ans++;
    }
  }
  printf("%lld\n",ans);
  return 0;
}

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

const int maxn = 1e5+10;

int n;

typedef long long ll;
const int LEN = 100000;
struct fastio{
  char s[LEN + 5]; int len,it;
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(len == LEN) fwrite(s,1,LEN,stdout), len = 0;
    s[len++] = c;
  }
  void flush(){
    fwrite(s,1,len,stdout);
    len = 0;
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get())
    res = (res << 3) + (res << 1) + (c - '0');
  return sig * res;
}
inline void putll(ll x){
  if(!x) bufo.put('0');
  else if(x < 0) bufo.put('-'), x = -x;
  char s[25]; int k = 0;
  while(x){
    s[++k] = x % 10 + '0';
    x /= 10;
  }
  for(int i = k;i >= 1;i--) bufo.put(s[i]);
}

struct edge{ int a, b, c; };
struct query{ int i, v, x, y; };
vector<edge> g[maxn];
vector<query> q[maxn];
void add2(int a, int b, int c, int d) {
	g[a].push_back((edge){b, c, d});
	g[b].push_back((edge){a, c, d});
}

int f[maxn], v[maxn];
int find(int x) { return f[x]>0?f[x]=find(f[x]):x; }
void merge(int x, int y) {
	int fx = find(x), fy = find(y);
	if (fx == fy) return;
	v[fy] = v[fx];
	if (f[fx] > f[fy]) swap(fx, fy);
	f[fx] -= f[fx]==f[fy];
	f[fy] = fx;
}

int dis[maxn], col[maxn], cdis[maxn];
int ans[maxn], lca[maxn];
void dfs(int u, int fa) {
	for (int i = 0; i < g[u].size(); ++i) {
		int v = g[u][i].a;
		if (v == fa) continue;
		dis[v] = dis[u] + g[u][i].c;
		col[g[u][i].b]++;
		cdis[g[u][i].b] += g[u][i].c;
		dfs(v, u);
		merge(u, v);
		col[g[u][i].b]--;
		cdis[g[u][i].b] -= g[u][i].c;
	}
	for (int i = 0; i < q[u].size(); ++i) {
		query &qq = q[u][i];
		debug(" %d %d %d %d: %d\n", qq.i, qq.v, qq.x, qq.y, ans[qq.i]);
		debug("%d: %d %d %d %d\n", qq.i, u, dis[u], cdis[qq.x], col[qq.x]*qq.y);
		if (qq.v) {
			ans[qq.i] += dis[u]-cdis[qq.x]+col[qq.x]*qq.y;
			if (!lca[qq.i] && dis[qq.v]) {
				lca[qq.i] = v[find(qq.v)];
				debug("lca: %d %d: %d\n", u, qq.v, lca);
				q[lca[qq.i]].push_back((query){qq.i, 0, qq.x, qq.y});
			}
		}
		else {
			ans[qq.i] -= 2*(dis[u]-cdis[qq.x]+col[qq.x]*qq.y);
		}
	}
}

int main() {
	int qq;
	n = getint(), qq = getint();
	int a, b, c, d;
	for (int i = 0; i < n-1; ++i) {
		a = getint(), b = getint(), c = getint(), d = getint();
		add2(a, b, c, d);
	}
	for (int i = 0; i < qq; ++i) {
		a = getint(), b = getint(), c = getint(), d = getint();
		q[c].push_back((query){i, d, a, b});
		q[d].push_back((query){i, c, a, b});
	}
	memset(f, -1, sizeof(f));
	for (int i = 1; i <= n; ++i) v[i] = i;
	dis[1] = 1;
	dfs(1, 0);
	for (int i = 0; i < qq; ++i) {
		putll(ans[i]);
		bufo.put('\n');
	}
	bufo.flush();
}


Measured memory_bytes: 26964
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll k;
    cin>>k;
    ll r = 7%k;
    ll c = 1;
    while((r%k)!=0 && c<1e7)
    {
        r = (r%k)*10 + 7;
        c++;
    }
    if(r%k) cout<<"-1\n";
    else cout<<c<<"\n";
}

Measured memory_bytes: 3628
import math
def aux(v):
    [xa,ya,ra,xb,yb,rb] = v
    ab = math.sqrt((xb-xa)**2 + (yb-ya)**2)
    if ab > ra + rb:
        rst = 0
    elif ab + rb < ra:
        rst = 2
    elif ab + ra < rb:
        rst = -2
    else:
        rst = 1      
    return(rst)    

if __name__ == "__main__": 
    n = int(input())
    for i in range(n):
        v = list(map(float, input().split()))
        print(aux(v))

Measured memory_bytes: 7688
# import copy


def main():
    D = int(input())
    C = list(map(int, input().split()))
    S = [list(map(int, input().split()))for _ in range(D)]

    len_C = len(C)
    types = []
    lasts = [0] * 26

    for i in range(D):
        s = max(S[i])

        c = []
        c_sum = 0
        for j in range(len_C):
            c.append((i + 1 - lasts[j]) * C[j])
            c_sum += (i + 1 - lasts[j]) * C[j]  # 満足度低下の合計

        if c_sum >= s:  # 低下が増加の最高値より高ければ一番大きい低下を無くす
            s_c = []
            for j in range(len_C):
                s_c.append(S[i][j] + c[j])  # 増加と損失の合計値→大きいほど開催する価値がある。

            t = s_c.index(max(s_c)) + 1
            lasts[t - 1] = i + 1
        else:
            t = S[i].index(s) + 1

        types.append(t)

    for type in types:
        print(type)


if __name__ == '__main__':
    main()


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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 <= i; i--)
#define FOR(i, from, to) for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to) for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

int main()
{
    ll N, L;
    cin >> N >> L;
    ll m = L + N - 1;
    ll s = (L - 1) * N + N * (N + 1) / 2;
    if (L <= 0 && 0 <= m)
    {
        cout << s << endl;
        return 0;
    }
    if (L <= 0 && m <= 0)
    {
        cout << s - m << endl;
        return 0;
    }
    cout << s - L << endl;
    return 0;
}


Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;
int a[10004];
int main()
{
   int n,m,res=0;
   cin>>n>>m;
   for(int i=0;i<m;i++)
   {
       cin>>a[i];
       res+=a[i];
       
   }
   
   int ans=n-res;
   if(ans>=0)
   cout<<ans;
   else
   cout<<-1;
   
   

    return 0;
}


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

public class Main{

	public static void main(String[] args) throws IOException {
		int N = readInt(), K = readInt();
		long sum = N/K;
		sum = sum*sum*sum;
		if(K%2 == 0) {
			long temp = (N+(K/2))/K;
			temp = temp*temp*temp;
			println(sum+temp);
		}
		else println(sum);
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    string s; cin>>s;
    for(c: s) {
        if (count(begin(s), end(s), c)%2) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

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

#import
#import math
#import numpy as np
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [10 ** 9] * N
dp[0] = 0

for i in range(1, N):
    for j in range(1, K + 1):
        if i - j < 0:
            break

        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
        

print(dp[-1])


Measured memory_bytes: 84160
var
  p,q,o,e,a,b:longint;
begin
  read(p,o,q,e);
  a:=abs(p-q);
  b:=abs(o-e);
  if (p<=q)and(o>=e) then
    write(q+b,' ',e+a,' ',q+b-a,' ',e+a+b) else
  if (p<=q)and(o<=e) then
   write(q-b,' ',e+a,' ',q-b-a,' ',e+a-b) else
  if (p>=q)and(o<=e) then
    write(q-b,' ',e-a,' ',q-b+a,' ',e-a-b) else
  write(q+b,' ',e-a,' ',q+a+b,' ',e-a+b);
end.


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}

int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
string s;
cin>>s;
int n=s.size();
if(s[n-1]=='s')
{
	cout<<s<<"es";
}
else
{
	cout<<s<<"s";
}
}



 

Measured memory_bytes: 3624
x = int(input())

if x>= 1800:
    print(1)
elif x >= 1600:
    print(2)
elif x >= 1400:
    print(3)
elif x >= 1200:
    print(4)
elif x >= 1000:
    print(5)
elif x >= 800:
    print(6)
elif x >= 600:
    print(7)
elif x >= 400:
    print(8)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
N^2
4 5 5 6
100
101
101
110
010=2
4^5=1
5^6=11=3
1^3=2

6
4 6 0 0 3 3
0 5 6 5 0 3

000
101
110
101
000
011
101=5

100
110
011
011
010=2

6
4 6 0 0 3 3
0 5 6 5 0 3
set消す
4 6
6 3
10 7 12 9
1010
0111
1100
1001
1000=8

bの論理和とってaとN通り
Nを論理和とっておしまい？
んなこたない

3+7
繰り上がりがやっかい
ペアはけしていい
繰り上がるのと繰り上がらないのとの積を出す？
3 4 5
4 6 8
16=0
8=8通り -8する
-4 -2 0
4=2通り
-4-6-4
logNを28桁
Nを28回
200000を29回sort=86ms
N回lowerをするのはNGか
繰り上がりが何回あるかを記録しとくとか

2
1 2
3 4

A[0,1,1]
B[1,1,1]
=[1,2,2]和でいいの？
=[1,3,0]
=[2,3,0]
=[0,1,0]
=2

2
1 1
3 4
4,5,4,5=0
[0,0,0]
[1,1,1]
[1,1,3]
[1,2,1]
[0,0,1]=1

3
2 3 4
3 4 5
=5,6,7,6,7,8,7,8,9
=5,7,9
1001
0111
0101
1011=11
  [1,2,1]
  [2,1,2]
全部で3
2*2+1*1=5//1の位(N-A)*B+N*(N-B)
1*2=2//1から繰り上がる
[0,0,2,5]//1
[0,2,5,0]//2
[2,5,0,0]
[2,7,7,5]
[3,6,5,5]になるはず

[0,1,0,5]//1
[1,0,5,0]//2
[2,5,0,0]
[3,6,6,5]//さらに繰り上がるやつとそうでない奴を管理できない

3+5が管理できない
 101
 011
1000
5,6,6,7,7,7,8,8,9
0101
0110
0111
1000
1001
3655

1+7とか

やっぱlowerのNlogNか
0桁目 mod2 自分が0なら1 1なら0の数
1桁目 mod4 自分が0なら2-3 1なら12 3なら03か
1,3 2-1 4-3
23,67　2個 4-2 8-6
4567,12131415 4個 8-4 16-12
8,24 *3すればいいか
厄介
0桁目 mod4 13ならOK？
1桁目 mod8 
4で割る
むり、

2
1 2
3 4

1 0
1 0

1 2
3 0

*/
int main(){
  ll N,ans=0; cin>>N;
  vector<ll> A(N,0),B(N,0),C(N,0);
  for(ll i=0; i<N; i++) cin>>A[i];
  for(ll i=0; i<N; i++) cin>>B[i];
  for(ll i=1; i<=29; i++){//28条まで
    ll n=1<<i;
    for(ll j=0; j<N; j++) C[j]=B[j]%n;
    sort(C.begin(), C.end());
    ll tmp=0;
    for(ll j=0; j<N; j++){
      ll m=A[j]%n;
//cout<<"m:"<<m<<endl;      
      auto a1=lower_bound(C.begin(), C.end(), n-m);
      auto a2=lower_bound(C.begin(), C.end(), n/2-m);
      auto b1=lower_bound(C.begin(), C.end(), n*2-m);
      auto b2=lower_bound(C.begin(), C.end(), n/2*3-m);
      (tmp+=a1-a2+b1-b2)%=2;
//cout<<"a:"<<a1-a2<<" b:"<<b1-b2<<" ans:"<<ans<<endl;      
    }
    ans+=tmp%2*n/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,l,sum=0;
    char flag='y';
    cin>>n>>l;
    vector<pair<int,int>> vec(n);
    for(int i=0;i<n;i++)
    {
        vec[i].first=i+1;
        vec[i].second=l+i;
        sum+=vec[i].second;
        if(vec[i].second==0)
            flag='n';
    }
    if(flag=='n')
        cout<<sum;
    else if(sum>0)
        cout<<sum-l;
    else
        cout<<sum-l-n+1;









    fflush(stdout);
    return 0;


} 







Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
#include <algorithm>
#include <cmath>

const int Wmax = pow(10, 4) + 1;
int s;

int solve(int A[], int n){
    bool T[n];
    int B[n], Index[Wmax];
    for(int i=0; i<n; i++){
        T[i] = false;
        B[i] = A[i];
    }
    int total_w = 0;
    sort(B, B+n);
    for(int i=0; i<n; i++){ Index[B[i]] = i;}
    for(int j=0; j<n; j++){
        if(T[j] == false){
            T[j] = true;
            int wmin, sum = 0, cur, cnt=1;
            wmin = A[j];
            sum += A[j];
            cur = Index[wmin];
            while(cur != j){
                T[cur] = true;
                cnt++;
                sum += A[cur];
                wmin = min(wmin, A[cur]);
                cur = Index[A[cur]];
            }
            total_w += min(sum+(cnt-2)*wmin, sum+wmin+(cnt+1)*s);
        }
    }

    return total_w;
}

int main(){
    int n;
    s = Wmax;
    scanf("%d", &n);
    int A[n];
    for(int i=0; i<n; i++){
        scanf("%d", &A[i]);
        s = min(s, A[i]);
    }

    int ans = solve(A, n);
    printf("%d\n", ans);

    return 0;
}


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

    string s[N];
    rep(i,N){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
  	sort(s, s+N);
  	//rep(i, N) cout << s[i] << endl;

    unsigned long long int cnt = 0; unsigned long long int k = 0; int l = 0;
    rep(i,N-1){
      	bool flag = false;
      	//cout << s[i+1] << " " << k << endl;
        rep(j,s[i].length()){
            if(s[i+1] != s[i] && !flag){
              cnt += k; l = 0; k = 0;
              flag = true;
            }
        }
        if(!flag){
          l += 1;
          k += l;
        }
    }
    cnt += k;
    cout << cnt;
}

Measured memory_bytes: 7296
from fractions import gcd


def p_c():
    n = int(input())
    *a, = map(int, input().split())
    L = [0] * n
    R = [0] * n
    for i in range(n - 1):
        L[i] = gcd(L[i - 1], a[i])
        R[n - 1 - i] = gcd(R[(n - i) % n], a[n - 1 - i])
    ans = [gcd(L[i - 1], R[(i + 1) % n]) for i in range(n)]
    print(max(ans))

p_c()

Measured memory_bytes: 92256
#include<stdio.h>
int main(void) {
  int max, time, n, a;
  scanf("%d %d %d", &n, &max, &time);
  for (a=0; n>0; a++) {
    n = n - max;
  }
  a=a*time;
  printf("%d\n", a);
  return 0;
}


Measured memory_bytes: 1728
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535;
#define MOD 1000000007;



int main(void) {
	int n,cnt=0 ,ans;
	string s;
	cin >>n>> s;
	if (n == 1) {
		cout << 0 << endl;
		return 0;
	}

	for (int i = 1; i < n; i++) {
		if (s[i] == 'E') {
			cnt++; 
		}
	}
	ans = cnt;
	for (int i = 1; i < n; i++) {
		if (s[i - 1] == 'W') {
			cnt++;
		}
		if (s[i] == 'E') {
			cnt--;
		}
		ans = min(cnt, ans);
	}

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

Measured memory_bytes: 900
n, k, *V = map(int, open(0).read().split())
def calc(i, j, k):
    W = sorted(V[:i] + V[:-j-1:-1], reverse=True)
    for _ in range(k):
        if W[-1] < 0:
            W.pop()
    return sum(W)

ans = 0
r = min(n, k)+1
for i in range(r):
    for j in range(r-i):
        for k_ in range(min(i+j, k+1-i-j)):
            ans = max(ans, calc(i, j, k_))
print(ans)

Measured memory_bytes: 3316
n,k=map(int,input().split())
v=[0 for _ in range(n)]
w=[0 for _ in range(n)]
for i in range(n):
	w[i],v[i] = map(int,input().split())

dp = [[0 for i in range(k+1)] for j in range(n+1)]

for i in range(n):
	for j in range(k+1):
		if j-w[i] < 0:
			dp[i+1][j] = dp[i][j]
		else:
			dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i])
print(dp[n][k])

Measured memory_bytes: 171400
#include <bits/stdc++.h>
#define pb push_back
#define INF 0x3f3f3f3
#define ll long long
using namespace std;
typedef pair<int, string> pii;

int n, k, vet[100005][5], dp[100005][5];

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= 3; j++)
            cin >> vet[i][j];

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= 3; j++) {
            if(j == 1)
                dp[i][j] = max(dp[i-1][j+1]+vet[i][j], dp[i-1][j+2]+vet[i][j]);
            if(j == 2)
                dp[i][j] = max(dp[i-1][j-1]+vet[i][j], dp[i-1][j+1]+vet[i][j]);
            if(j == 3)
                dp[i][j] = max(dp[i-1][j-1]+vet[i][j], dp[i-1][j-2]+vet[i][j]);
        }
    }

    int ans = 0;
    for(int j = 1; j <= 3; j++)
        ans = max(ans, dp[n][j]);
    cout << ans << endl;
}


Measured memory_bytes: 4096
#include<stdio.h>
#include<math.h>

int main(){
  int i,j,k=0;
  int N,T,A;
  double min=10000000000;
  
  scanf("%d",&N);
  scanf("%d %d",&T,&A);
  int H[N];
  for(i=0;i<N;i++)
    scanf("%d ",&H[i]);
  double x;
  for(i=0;i<N;i++){
    x =  T - H[i] * 0.006 - A;
    if(fabs(x) < min){
      min = fabs(x);
      k = i;
    }
  }
  
  printf("%d\n",k+1);
  
  return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll L, N; scanf("%lld%lld", &L, &N);
    vector<ll> X; // 2N + 1 要素, 座標 0 は X[N] にある
    for(int i=0; i<N; i++) {
        ll x; scanf("%lld", &x);
        X.emplace_back(x);
    }
    X.emplace_back(L);
    for(int i=0; i<N; i++) {
        X.emplace_back(X[i] + L);
    }

    ll ans = 0;
    for(int k=0; k<2; k++) {
        int M = X.size();
        // 前半: S[1..N], 後半: S[N+1..2N]
        vector<ll> S(M+1);
        for(int i=0; i+1<M; i++) S[i+1] = S[i] + (X[i+1] - X[i]);

        ll sum = S[N];
        for(int i=0; i<N; i++) {
            chmax(ans, sum);
            int l = i - i / 2, r = N + i/2 + 1;
            sum -= S[i+1] - S[l];
            sum += S[r] - S[i+1];
        }

        reverse(X.begin(), X.end());
        for(auto &e : X) e *= -1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7276