akhauriyash/Code-Regression huggingface dataset:
class BIT(object):
    from operator import add
    def __init__(self,A,f=add):
        N=len(A)
        self.__len=N
        self.__f=f
        # built (O(N))
        self.__bit=A[:] # shallow copy
        for i in range(N):
            j=i+((i+1)&-(i+1))
            if j<N: self.tree[j]=self.func(self.tree[i],self.tree[j])

    def __repr__(self):
        return str(self.tree)

    @property
    def func(self):
        return self.__f

    @property
    def tree(self): # getterにしてる意味あんまない
        return self.__bit

    def add(self,i,w):
        while(i<self.__len):
            self.tree[i]=self.func(self.tree[i],w)
            i+=(i+1)&-(i+1)

    def sum(self,i):
        res=0
        while(i>-1):
            res=self.func(res,self.tree[i])
            i-=(i+1)&-(i+1)
        return res

    def bisect_left(self,w):
        # sum(A)より大きければ一番右
        if w>self.sum(self.__len-1): return self.__len
        # 1個しかなく、右じゃないなら左
        elif self.__len==1: return 0
        # それ以外だと、len未満の2のべき乗からスタート
        n=2**((self.__len-1).bit_length()-1)
        res=0
        while(n):
            if res+n-1>self.__len-1: # index over(2べきじゃないときに起こる)
                n//=2
                continue
            if w<=self.tree[res+n-1]: # 左にいく
                n//=2
            else: # 右にいく
                w-=self.tree[res+n-1]
                res+=n
                n//=2
        return res

    def bisect_right(self,w):
        if w>=self.sum(self.__len-1): return self.__len
        elif self.__len==1: return 0
        n=2**((self.__len-1).bit_length()-1)
        res=0
        while(n):
            if w<self.tree[res+n-1]:
                n//=2
            else:
                w-=self.tree[res+n-1]
                res+=n
                n//=2
        return res

# input
n=int(input())
A=list(map(int,input().split()))
# built idx
idx=[0]*n
for i,a in enumerate(A): idx[a-1]=i

# built bit
bit=BIT([0]*n)

# calculate
score=0
for k in range(n,0,-1):
    i=idx[k-1]
    bit.add(i,1)
    s=bit.sum(i)
    # 0.5を引くことでbisect_left=bisect_right
    l0=bit.bisect_left(s-1.5)-(s<=1) # 一番左を含むか含まないかで場合分け
    l1=bit.bisect_left(s-2.5)-(s<=2) # 一番左を含むか含まないかで場合分け
    r0=bit.bisect_left(s+0.5)
    r1=bit.bisect_left(s+1.5)
    score+=k*((l0-l1)*(r0-i)+(r1-r0)*(i-l0))
print(score)

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

int main() {
    string S; cin >> S;
    reverse(S.begin(), S.end());
    string sel4[] = {"dream", "dreamer", "erase", "eraser"};
    for(int i = 0; i < 4; i++) reverse(sel4[i].begin(), sel4[i].end());

    int i;
    for(i = 0; i < S.size(); ) {
        for(int j = 0; j < 4; j++) {
            string checking = sel4[j];
            int ichecking = checking.size();
            string sub = S.substr(i, ichecking);
            if(sub == checking) {
                i += ichecking;
                break;
            } else {
                if(j == 3) {
                    puts("NO");
                    return 0;
                }
            }
        }
    }
    puts("YES");
}


Measured memory_bytes: 512
a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
min_cost = min(a_list) + min(b_list)
for i in range(m):
  x,y,c = map(int, input().split())
  cost = a_list[x - 1] + b_list[y -1] - c
  if cost < min_cost:
    min_cost = cost
print(min_cost)

Measured memory_bytes: 18612
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

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

const int INF = 1 << 24;

int main(void){
    for(int n; cin >> n, n;)
        for(int x1, y1, z1, w1, x2, y2, z2, w2; n -- && cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2; cout << x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2 << ' ' << x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2 << ' ' << x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2 << ' ' << x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2 << endl);
 
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;


struct UnionFind
{
    int n;
    vector<int> parent;
    vector<int> rank;
    UnionFind(int _n) :n(_n)
    {
        parent.assign(n, -1);
        rank.assign(n, 1);
    }

    int find(int i)
    {
        if (parent[i] == -1)
            return i;
        else
            return parent[i] = find(parent[i]);
    }

    void unite(int i, int j)
    {
        i = find(i);
        j = find(j);

        if (i == j) return;

        if (rank[i] == rank[j])
        {
            parent[j] = i;
            ++rank[i];
        }
        else
        {
            if (rank[i] < rank[j]) swap(i, j);
            parent[j] = i;
        }
    }

    bool is_same(int i, int j)
    {
        return find(i) == find(j);
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i, 0, n)
    {
        cin >> p[i];
        --p[i];
    }

    UnionFind uf(n);
    rep(i, 0, m)
    {
        int x, y;
        cin >> x >> y;
        --x,  --y;
        uf.unite(x, y);
    }

    int ans = 0;
    rep(i, 0, n)
    {
        if (uf.is_same(p[i], i))
            ++ans;
    }
    cout << ans << endl;

    return 0;
}

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

signed main(){
  int N;
  while(cin >> N, N){
    vector<int> a(N);
    vector<vector<int> > dp(N, vector<int> (N, 0));
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 1; i < N; i++){
      for(int j = 0; j + i < N; j++){
        for(int k = j; k < i + j; k++){
          dp[j][j + i] = max(dp[j][j + i], dp[j][k] + dp[k + 1][j + i]);
        }
        if(dp[j + 1][j + i - 1] == i - 1 && abs(a[j] - a[j + i]) <= 1){
          dp[j][j + i] = i + 1;
        }
      }
    }
    cout << dp[0][N - 1] << endl;
  }
}


Measured memory_bytes: 3236
N, A, B, C, D = map(int, input().split())
S = input()

from sys import exit

# check
goal = max(C, D)
if "##" in S[A-1:goal]:
    print("No")
    exit()

if C < D:
    # Bから先に動く
    print("Yes")

else:
    # 入れ替わる必要がある

    # cehck : 初期値で入れ替えられる
    if "..." in S[B-2:D+1]:
    # if ('...' in S[B-1:D]) or ('...' in S[B-2:B+1]) or ('...' in S[D-2:D+1]):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3572
function main()
  
  N = parse(Int,readline())
  T = map(x -> parse(Int,x), split(readline()))
  M = parse(Int,readline())
  
  P = zeros(Int,M)
  X = zeros(Int,M)
  
  for i in 1:M
    (P[i],X[i]) = map(x -> parse(Int,x), split(readline()))
  end
  
  for i in 1:M
    ans = 0
    for j in 1:N
      
      if P[i] == j
        ans += X[i]
      else
        ans += T[j]
      end
      
    end
    println(ans)
  end
  
end

main()

Measured memory_bytes: 112056
#include <bits/stdc++.h>
using namespace std;
const double pi=2*acos(0.0);
double inff=1.0/0.0;
#define ll           long long int
#define inf          1000000000000000008
#define MOD          1000000007
#define pb           push_back
#define sz(x)        (int)x.size()
#define mp           make_pair
#define lbd          lower_bound
#define ubd          upper_bound
#define ipair        pair<ll,ll> 
#define all(v)       v.begin(),v.end()
#define watch(x)     cout<<(#x)<<" is "<<(x)<<endl;
#define rep(a,b,c)   for(a=(int)b;a<(int)c;a++)    
#define bac(a,b,c)   for(a=(int)b;a>=(int)c;a--)
#define se           second
#define f            first
#define ios          ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
#define mem(a,val)   memset(a,val,sizeof a)
#define endl         "\n"
#define mxn          100002
#define vi           vector<ll>
#define vii          vector<ipair> 
#define si           set<ll> 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*Variables Start*/
ll x,y,n,i,z,j,k,w,u,q,m,t;
vi v;map<ll,ll> m1;
/*Variables End*/
void solve()
{
  cin>>n>>k;
  v.resize(n+1);
  v[0]=0;
  rep(i,1,n+1)
  {
    cin>>v[i];
    v[i]+=v[i-1];
  }
  rep(i,0,n+1)
  {
    if(i>=k)
    {
      x=labs(v[i-k]-i+k)%k;
      m1[x]--;
    }
    x=labs(v[i]-i)%k;
    w+=m1[x];
    m1[x]++;
  }
  cout<<w<<endl;
}
int main() 
{ 
  int TESTS=1;
  ios;  
  // cin>>TESTS;
  while(TESTS--)
  {
    solve();
  }  
}

Measured memory_bytes: 14336
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int A,B;
inline void solve(){
  IN2(A,B);
  OUT((A-1)*(B-1));
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
n, a, b, c, d = map(int,input().split())
s = input()
a -= 1
b -= 1
c -= 1
d -= 1
if "##" in s[a: c+1] or "##" in s[b:d+1]:
    print('No')
else:
    if c < d:
        print('Yes')
    else:
        if "..." in s[b-1: d+2]:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 40816
a = [
  "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
  "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
]
n = gets.chomp!.to_i
s = gets.chomp!.to_s
ls = s.split("")

ans = []

ls.each do |e|
  i = a.index(e)
  if i + n >= 26
    i = i - 26
  end
  #p i
  ans << a[i+n]
end

v = ans.join.to_s
puts v

Measured memory_bytes: 3836
n = int(input())
dp = [float('inf') for i in range(n+1)]
dp[0] = 0
for i in range(1,n+1):
    ngo = 1
    while ngo <= i:
        dp[i] = min(dp[i],dp[i-ngo]+1)
        ngo *= 6
    ngo = 1
    while ngo <= i:
        dp[i] = min(dp[i],dp[i-ngo]+1)
        ngo *= 9
print(dp[n])

Measured memory_bytes: 6296
a,b,c=(list(input()) for x in range(3))
n=a.pop(0)
while not ((len(a)==0 and n=='a') or (len(b)==0 and n=='b') or (len(c)==0 and n=='c')):
   if n=='a':n=a.pop(0)
   elif n=='b':n=b.pop(0)
   else:n=c.pop(0)
if n=='a':print('A')
elif n=='b':print('B')
else:print('C')

Measured memory_bytes: 3064
n,k = map(int,input().split())
s = input()
l = [0]*n
if int(s[0]) == 0:
    l[0] = 1
for i in range(1,n):
    if s[i] ==  "0" and s[i-1]=="0":
        l[i] = l[i-1]
    elif s[i] == "0" and s[i-1] =="1":
        l[i] = l[i-1] + 1
    else:
        l[i] = l[i-1]
def solve(x):
    for i in range(0,n-x+1):
        if i ==0:
            if l[x-1] <= k:
                return True
            else:
                continue
        elif s[i] == "0":
            if l[i+x-1] - l[i] + 1 <= k:
                return True
        else:
           if l[i+x-1] - l[i] <= k:
               return True
    return False


def binary_search(ok,ng):
    while abs(ok-ng) >1:
        mid = (ok+ng)//2
        if solve(mid):#判定のとこは別で
            ok = mid
        else:
            ng = mid
    return ok
a = binary_search(1,n)
if solve(a+1):
    print(a+1)
else:
    print(a)


Measured memory_bytes: 41200
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool has_key(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        string S;
        cin >> N >> S;
        rep(i, 0, len(S)) {
                char c = S[i];
                c += N;
                if (c > 'Z') c -= 26;
                cout << c;
        }       
        cout << endl;
}

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

using namespace std;
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.substr(a.length() - 1) == b.substr(0, 1) &&
      b.substr(b.length() - 1) == c.substr(0, 1)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int cnt = 0;

    for(int i = 0; i < n; ++i) {
    	if(isPrime(sc.nextInt())){
    		cnt += 1;
    	}
    }

    System.out.println(cnt);
  }

  public static boolean isPrime(int p) {
  	if(p == 2) return true;
  	if(p % 2 == 0) return false;
	for(int q = 3; q < Math.sqrt(p) + 1; q += 2){
		if(p % q == 0){
			return false;
		}
	}
  	return true;
  }
}

Measured memory_bytes: 40692
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

n = INT()
s = []
for i in range(n):
    m = list(input())
    m.sort()
    s.append(m)
s.sort()
# print(s)
# print(s)
count = 0
ren = 1
r = []
rsum = [0] * n
for i in range(n-1):
    if s[i] == s[i+1]:
        count += 1
        ren += 1
        # print(ren)
        rsum[i+1] +=rsum[i]+1
    else:
        r.append(ren)
        ren = 1
        # print(ren)
r.append(ren)
        
for i in range(n):
    rsum[i] = rsum[i] + 1
    

def P(n, r):
    return factorial(n)//factorial(n-r)

def C(n, r):
    return P(n, r)//factorial(r)
# print(r)

# print(count)
# print("rsum:", rsum)
b = []
rsum.append(1)

for i in range(n):
    if rsum[i]>rsum[i+1]:
        b.append(rsum[i])
    #     continue
    # else:
    #     print(rsum[i+1])
    #     b.append(rsum[i+1])
# print("b", b)
count2 = 0
for i in b:
    # print(i)
    # print(C(i,2))
    count2 += C(i, 2)
print(count2)
    # if b[i]>=3:


# for i in range(n):
#     for j in range(n):
#         # if i != j:
#         if i < j:
#         #     print(s[i])
#         # print(s[j])
#             if s[i] == s[j]:
#                 count += 1
# # for i in range(n):
    
# print(count)

Measured memory_bytes: 31444
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    memo = As[0]
    res = 0
    for i in range(N-1):
        res += (memo * As[i+1])%(10**9 + 7)
        memo += As[i+1]

    print(res % (10**9 + 7))


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 31568
import sys
from collections import deque
import copy
import math

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [S] = [(input_raw[0])]

    stack = []

    for s in S:
        if len(stack) == 0:
            stack.append(s)
        else:
            if s == "T" and stack[len(stack) - 1] == "S":
                stack.pop()
            else:
                stack.append(s)
    print len(stack)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4780
import java.util.*;
public class Main {

	public static void main(String[] args) {
		long m = 1000000007;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] A = new String[N];
		Arrays.setAll(A, i -> Long.toBinaryString(sc.nextLong()));
		long ans = 0;
		long[] digit = new long[60];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < A[i].length(); j++) {
				if(A[i].charAt(A[i].length()-1-j) == '1')
					digit[j]++;
			}
		}
		for(int i = 0; i < 60; i++)
			ans += Math.pow(2, i) % m * digit[i] % m * (N-digit[i]) % m;
		System.out.println(ans % m);

	}

}

Measured memory_bytes: 135020
use whiteread::parse_line;
use num_integer::gcd;

fn main() {
    let (a, b, c, d): (usize, usize, usize, usize) = parse_line().unwrap();
    let cd: usize = c*d / gcd(c, d);

    let bc = b/c;
    let ac = (a-1)/c;
    let bd = b/d;
    let ad = (a-1)/d;
    let bcd = b/cd;
    let acd = (a-1)/cd;

    let cc = bc - ac;
    let dc = bd - ad;
    let cdc = bcd - acd;

    println!("{}", b - a + 1 - cc - dc + cdc);
}


Measured memory_bytes: 2180
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = br.readLine().split(" ");
		int five = 0;
		int seven = 0;
		for(int i = 0 ; i < strs.length ; i++){
			int n = Integer.parseInt(strs[i]);
			if(n == 5)
				five++;
			if(n == 7)
				seven++;
		}
		if(five == 2 && seven == 1){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 7636
#include <stdio.h>
int main (){
  int n,n4=0,n1=0,n2=0;
  scanf("%d", &n);

  int a[n+1];

  for(int i=0; i<n; i++)
    scanf("%d", &a[i]);

  for(int i=0;i<n;i++){
    if(a[i] % 4 == 0){
      n4++;
    } else if ( a[i] % 2 == 0 ) {
      n2++;
    } else {
      n1++;
    }
  }

  if( (n2==0 && n1<= n4 +1) || (n2>0 && n1<=n4) ){
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;
  cin >> k;
  cin >> a >> b;
  int flag = 0;
  for (int i = a; i <= b; i++){
    if (i%k==0){
      flag++;
      cout << "OK" << endl;
      break;
    }
  }
  if (flag == 0){
    cout << "NG" << endl;
  }
}


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

using namespace std;

#define DEBUG 0
#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define VIN(VECTOR,n)\
REP(CNT,n){\
	lli TMP;\
	cin>>TMP;\
	VECTOR.push_back(TMP);\
}

lli zettai(lli a){
	if(a>=0)return a;
	else return -a;
}

lli minAB(lli a,lli b){
	if(a>=b)return b;
	else return a;
}

int main(){

	lli n,k;
	lli *x;

	cin>>n>>k;
	x = new lli[n];
	REP(i,n){
		cin>>x[i];
	}
	lli ans = 223372036854775807;
	for(lli i=0;i<n-k+1;i++){
		lli now;
		if(x[i]<0 && x[i+k-1] < 0){//両方マイナスパターン
			now = zettai(x[i]);
		}
		else if(x[i]<0 && x[i+k-1]>=0){//片方マイナス片方プラスパターン
			now = minAB(zettai(2*x[i])+zettai(x[i+k-1]),zettai(x[i])+zettai(2*x[i+k-1]));
		}
		else{//両方プラスパターン
			now = zettai(x[i+k-1]);
		}
		if(ans>=now)ans=now;
	}
	cout<<ans<<endl;

	return 0;

}



Measured memory_bytes: 1024
import numpy as np

N,W = map(int, input().split())

dp = np.full(N*1000+1, W+1, dtype=np.int64)
dp[0] = 0

for _ in range(N):
  w,v = map(int,input().split())
  np.minimum(dp[:-v]+w, dp[v:], out=dp[v:])

print(((dp <= W)*np.arange(N*1000+1)).max())

Measured memory_bytes: 14904
#include<stdio.h>

int fibo(int n){
    int f,i;
    int fib[50];
    for(i=0; i<=n; i++){
        if(i==0 || i==1)fib[i] = 1;
        else fib[i] = fib[i-2] + fib[i-1];
    }
    if(n==0 || n==1) return fib[n];
    else {
        f = fib[n-1]+fib[n-2];
        return f;
    }
}
int main(){
    int n;
    scanf("%d", &n);
    printf("%d\n",fibo(n));
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
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++)
#define _GLIBCXX_DEBUG

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

const int max_m = 15;
int n, m, ans = 0;
int k[max_m], s[max_m][max_m], p[max_m];

int main(){
    cin >> n >> m;
    rep(i, m){
        cin >> k[i];
        rep(j, k[i]){
            cin >> s[i][j];
        }
    }
    rep(i, m) cin >> p[i];

    for(int bit = 0; bit < (1 << n); bit++){
        bool flag = true;
        for(int i = 0; i < m; i++){
            int sw = 0;
            for(int j = 0; j < k[i]; j++){
                if(bit & (1 << (s[i][j] - 1))) sw++;
            }
            sw %= 2;
            if(p[i] != sw){
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> x(n), y(n), z(n);
    rep(i, n) cin >> x[i] >> y[i] >> z[i];

    ll res = 0;
    rep(pat, 1 << 3) {
        vector<ll> a = x;
        vector<ll> b = y;
        vector<ll> c = z;

        if (pat & (1 << 0)) {
            rep(i, n) a[i] = -a[i];
        }

        if (pat & (1 << 1)) {
            rep(i, n) b[i] = -b[i];
        }

        if (pat & (1 << 2)) {
            rep(i, n) c[i] = -c[i];
        }

        vector<ll> d(n);
        rep(i, n) d[i] = a[i] + b[i] + c[i];

        sort(all(d));
        reverse(all(d));

        ll v = 0;
        rep(i, m) {
            v += d[i];
        }

        res = max(res, v);
    }

    put(res);
    
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define M 998244353
#define MOD 1000000007
signed main()
{
    SPEED;
    int n;
    cin>>n;
    while(n!=0)
    {
        if(n%10==7)
        {
            cout<<"Yes";
            return 0;
        }
        n/=10;
    }
    cout<<"No";
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define int long long
using namespace std;
inline int read(){
	int f=1,ans=0;char c;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}
priority_queue<int,vector<int>,greater<int> > que;
const int MAXN=100001;
int n,m;
struct node{
	int b,c;
}k[MAXN];
bool cmp(node x1,node x2){return x1.c>x2.c;}
signed main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++) que.push(read());
	for(int i=1;i<=m;i++) k[i].b=read(),k[i].c=read();
	sort(k+1,k+m+1,cmp);
	for(int i=1;i<=m;i++){
		if(k[i].c<=que.top()) break;
		for(int j=1;j<=k[i].b;j++){
			if(k[i].c>que.top()){
				que.pop();
				que.push(k[i].c);
			}else break;
		}
	}
	int ans=0;
	while(!que.empty()) ans+=que.top(),que.pop();
	printf("%lld\n",ans);
}


Measured memory_bytes: 2676
import bisect
N,M,K=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

sum_alist=[0]
for i in range(N):
  sum_alist.append(sum_alist[-1]+alist[i])
#print(sum_alist)

sum_blist=[0]
for i in range(M):
  sum_blist.append(sum_blist[-1]+blist[i])
#print(sum_blist)

limit_a=bisect.bisect(sum_alist,K)
#print(limit_a)

answer=0
for i in range(limit_a):
  a_sum=sum_alist[i]
  b_sum=K-a_sum
  pos_b=bisect.bisect(sum_blist,b_sum)
  #print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
  answer=max(answer,i+pos_b-1)
  
print(answer)

Measured memory_bytes: 127060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    vector<P> lr(n);
    rep(i,n){
        ll l,r;
        cin>>l>>r;
        lr[i]={r,l};
    }
    sort(lr.begin(),lr.end());
    vector<ll> Llmax(n),Lrmin(n),Rlmax(n),Rrmin(n);
    Llmax[0]=lr[0].second;
    Lrmin[0]=lr[0].first;
    Rlmax[n-1]=lr[n-1].second;
    Rrmin[n-1]=lr[n-1].first;
    for(int i=1; i<n; i++){
        Llmax[i]=max(Llmax[i-1],lr[i].second);
        Lrmin[i]=min(Lrmin[i-1],lr[i].first);
        Rlmax[n-i-1]=max(Rlmax[n-i],lr[n-i-1].second);
        Rrmin[n-i-1]=min(Rrmin[n-i],lr[n-i-1].first);
    }
    ll ans = 0;
    for(int i=1; i<n; i++){
        ll contest1 = max(0LL,Lrmin[i-1]-Llmax[i-1]+1);
        ll contest2 = max(0LL,Rrmin[i]-Rlmax[i]+1);
        ans = max(ans,contest1+contest2);
    }
    for(int i=0; i<n; i++){
        ll ans1 = lr[i].first-lr[i].second+1;
        ll ans2;
        if(i==0)ans2=Rrmin[1]-Rlmax[1]+1;
        else if(i==n-1)ans2=Lrmin[n-2]-Llmax[n-2]+1;
        else ans2 = min(Rrmin[i+1],Lrmin[i-1])-max(Rlmax[i+1],Llmax[i-1])+1;
        ans = max(ans,ans1+max(0LL,ans2));

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

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  bool findSet(int x,int y){
    return find(x) == find(y);
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n,m;
  cin >> n >> m;
  UnionFind uni(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;b--;
    uni.unite(a,b);
  }
  set<int> st;
  rep(i,n){
    st.insert(uni.find(i));
  }
  cout << st.size() - 1 << endl;
}

Measured memory_bytes: 7588
MAX = 10000
NIL = -1

class Node:
    def __init__(self):
        self.parent = NIL
        self.left = 0
        self.right = 0

# ノード毎の深さ
D = [None for i in range(MAX)]
# ノード毎の高さ
H = [None for i in range(MAX)]

# 深さセット
def setDepth(u,d):
    if u == NIL: return
    D[u] = d
    setDepth(T[u].left, d + 1)
    setDepth(T[u].right, d + 1)

# 高さセット
def setHeight(u):
    h1 = 0
    h2 = 0
    if T[u].left != NIL:
        h1 = setHeight(T[u].left)+1
    if T[u].right != NIL:
        h2 = setHeight(T[u].right)+1
    H[u] = max(h1,h2)
    return H[u]

# 兄弟取得
def getSibling(u):
    if T[u].parent == NIL:
        return NIL
    if T[T[u].parent].left != u and T[T[u].parent].left != NIL:
        return T[T[u].parent].left
    if T[T[u].parent].right != u and T[T[u].parent].right != NIL:
        return T[T[u].parent].right
    return NIL

n = int(input())

T = []
# n個のノードを用意
for loop in range(n):
    node = Node()
    T.append(node)


def printNode(u):
    deg = 0
    if T[u].left != NIL:
        deg += 1
    if T[u].right != NIL:
        deg += 1
    print("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, "%(u, T[u].parent,  getSibling(u), deg, D[u], H[u]),end = "")

    if T[u].parent == NIL:
        print("root")
    elif T[u].left == NIL and T[u].right == NIL:
        print("leaf")
    else:
        print("internal node")

for i in range(n):
    v,l,r = map(int,input().split())
    T[v].left = l
    T[v].right = r
    if l != NIL:
        T[l].parent = v
    if r != NIL:
        T[r].parent = v


for i in range(n):
    if T[i].parent == NIL:
        root = i
        setDepth(root,0)
        setHeight(root)

for i in range(n):
    printNode(i)



Measured memory_bytes: 5764
//ABC049-D(連結/Connectivity)
#include<iostream>
#include<vector>
#include<map>
using namespace std;

//道路,鉄道それぞれについてUnion-Find木を作る

//素集合データ構造
struct UnionFind
{
    //par[i]:データiが属する木の親の番号。i==par[i]の時、データiは木の根である
    vector<int> par;
    //sizes[i]:根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
    vector<int> sizes;
    
    UnionFind(int n):par(n),sizes(n,1){
        //最初は全てのデータiがグループiに存在しているものとして初期化する
        for(int i=0; i<n; i++) par[i]=i;
    }
    
    //データxが属する木の根を得る
    int find(int x){
        if(x==par[x]) return x;//xが木の根の場合はそれを返す
        return par[x]=find(par[x]);//根を張り替えながら再帰的に根を探す
    }
    
    //2つのデータx,yを同じ木にする(マージする)
    void unite(int x,int y){
        //データの根ノードを得る
        x=find(x);
        y=find(y);
        
        //既に同じ木に属している場合は何もしない
        if(x==y) return;
        
        //xの木がyの木より大きくなるようにする
        if(sizes[x]<sizes[y]) swap(x,y);
        
        //xがyの親になるように連結する
        par[y]=x;
        sizes[x]+=sizes[y];
        //この時sizes[y]は無意味な値となる(yが根ではなくなるため)
    }
    
    //2つのデータx,yが属する木が同じならtrueを返す
    bool same(int x,int y){
        return find(x)==find(y);
    }
    
    //データxが含まれる木の大きさを返す
    int size(int x){
        return sizes[find(x)];
    }
};

int main(){
    int N,K,L;
    cin>>N>>K>>L;
    UnionFind road(N),train(N);
    int a,b;
    for(int i=0; i<K; i++){
        cin>>a>>b;
        a--;b--;//1から始まる数字なので--して0から始まる数字に直す(segmentation fault回避)
        road.unite(a,b);
    }
    for(int i=0; i<L; i++){
        cin>>a>>b;
        a--;b--;
        train.unite(a,b);
    }
    
    //それぞれについて道路,都市で連結しているか調べる
    map<pair<int,int>,int> mp;//キーがpair型、値がint型のmapを定義
    for(int i=0; i<N; i++){
        mp[{road.find(i),train.find(i)}]++;//キーはそれぞれの根(それぞれの木のiについて根を求める)
    }
    for(int i=0; i<N; i++){
        int ans=mp[{road.find(i),train.find(i)}];//ansはiが共通の根を持つ時のそれらの総和となる
        cout<<(i!=0 ? " " : "")<<ans;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<endl
#define f first
#define s second
#define endl '\n'
#define sq(x) (x)*(x)*1ll
typedef long long ll;
typedef pair<int,int> pii;

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do something instead of nothing and stay organized
*/

int mas[3]{-1,-1,-1};
int main () {
      int n ,m;
      cin>>n>>m;
      while (m--) {
            int a,b;
            cin>>a>>b; a--;
            if (mas[a] != -1 && mas[a] != b) {
                  cout << -1 << endl;
                  return 0;
            }
            mas[a]=b;
      }

      int start = pow(10,n-1);
      if (start == 1) start--;
      for (int i=start; i<pow(10,n); i++) {
            string cur = to_string(i);
            bool ok=true;
            for (int j = 0; j<cur.size(); j++) {
                  if (mas[j] == -1) continue;
                  if (mas[j] != cur[j] - '0') ok=false;
            }

            if (ok) {
                  cout << i << endl;
                  return 0;
            }
      }

      NO: cout << -1 << endl;
      return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int a=s.nextInt();
		int b=s.nextInt();
		int c=s.nextInt();
		if(a>=0 && b>=0 && c>=0 && a<=100 && b<=100 && c<=100){
			if(a<b && b<c ){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}

	}

}



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

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            //string s = Console.ReadLine();

            // 整数の入力
            long a = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            //var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long result = a + a * a + a * a * a;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

int main() {
	cin>>n>>m;
	ll sum = (n - m) * 100 + m * 1900;
	ll p = 1;
	for(int i=1;i<=m;i++) {
		p = p * 2;
	}	
	cout<<sum * p<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int arr[7];
long long f(int x)
{
	if (x<0)
	return -1e9;
	return x-x%2;
}
int main()
{
	for (int i=0;i<7;i++)
	scanf("%d",&arr[i]);
	printf("%lld",arr[1]+max(f(arr[0])+f(arr[3])+f(arr[4]),f(arr[0]-1)+f(arr[3]-1)+f(arr[4]-1)+3));
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  int max_n = 100000;
  int A[max_n];
  for(int i=0; i<max_n; i++)
    A[i] = 0;

  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    int index;
    cin >> index;
    A[index]++;
  }

  int max = 0;
  for(int i=0; i<max_n-2; i++){
    int sum_3 = A[i] + A[i+1] + A[i+2];
    if(sum_3 > max)
      max = sum_3;
  }

  cout << max << endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int flag;
int a[10000005];
int ans;
int main(){
	cin >> n;
	cin >> flag;
	for(int i = 1; i <= n;i++){
		cin >> a[i];
		if(a[i] >= flag) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

// 一行の文字列を読み込む
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

// 数値（INT）を読み込む
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := nextInt(), nextInt()

	tap := 0
	kuchi := 1
	for b > kuchi {
		tap++
		kuchi += a - 1
	}
	fmt.Println(tap)
}


Measured memory_bytes: 640
#include <iostream>
#define ans(a,t) (a&(UINT64_MAX<<(t)))<<1
#define cut2(a,t) ((a>>(t+1)==0)?ans(a,t):ans(a,t+1))
#define cut4(a,t) ((a>>(t+2)==0)?cut2(a,t):cut2(a,t+2))
#define cut8(a,t) ((a>>(t+4)==0)?cut4(a,t):cut4(a,t+4))
#define cut16(a,t) ((a>>(t+8)==0)?cut8(a,t):cut8(a,t+8))
#define cut32(a,t) ((a>>(t+16)==0)?cut16(a,t):cut16(a,t+16))
#define cut2L(a) ((a>>32==0)?cut32(a,0):cut32(a,32))
using namespace std;
int main() {
	long h;
	cin >> h;
	cout << ((cut2L(h)) - 1) << endl;
	return 0;
}

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

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

int main()
{
  int a[4], b[4], s = 0, t = 0, i;

  REP(i, 4) cin >> a[i];
  REP(i, 4) cin >> b[i];
  REP(i, 4){
    s += a[i];
    t += b[i];
  }
  cout << max(s, t) << endl;
}

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

#define int long long 

int32_t main()
{
    ios_base::sync_with_stdio(false),cin.tie(nullptr);
    int n=0;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin>>v[i];

    int sum=0;
    for(auto u:v) sum+=u;

    vector<vector<int>> dp(n,vector<int> (n,-1));
    
    for(int i=0;i<n;i++) dp[i][i]=v[i];
    for(int i=0;i<n-1;i++) dp[i][i+1]=max(v[i],v[i+1]);

    for(int d=2;d<n;d++)
    {
        for(int i=0;i+d<n;i++)
        {
            int j=i+d;
            dp[i][j]=max(v[i]+min(dp[i+2][j],dp[i+1][j-1]),v[j]+min(dp[i+1][j-1],dp[i][j-2]));
        }
    }

    int ans=dp[0][n-1]-(sum-dp[0][n-1]);
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 70784
import sys

cnt = {}

for line in sys.stdin:
    for c in line:
        if c.isalpha():
            cl = c.lower()
            cnt[cl] = cnt.get(cl, 0) + 1

for i in range(97, 97 + 26):
    c = chr(i)
    print("{0} : {1}".format(c, cnt.get(c, 0)))


Measured memory_bytes: 5568
import math
import decimal

def main():
    n = int(input())
    x = n / 108 * 100

    x_int_list = [math.ceil(x), math.floor(x)]
    for temp_x in x_int_list:
        temp_n1 = temp_x * 1.08
        temp_n2 = int(temp_n1)
        # temp_n2 = decimal.Decimal(str(temp_n1)).quantize(decimal.Decimal('0'), rounding=decimal.ROUND_HALF_UP)
        if temp_n2 == n:
            print(temp_x)
            return
    print(':(')


if __name__ == '__main__':
    main()


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

const int lim = 10000;
bool prime[lim+10];

int main(){
    int n;
    memset(prime,-1,sizeof(prime));
    for(int i = 3; i <= lim; i += 2)
        if(prime[i])
            for(int j = i*2 ; j <= lim; j += i)
                prime[j] = 0;

    while(cin >> n && n){
        if(n % 2 == 0) n--;
        for(int i = n; i >= 5; i -= 2){
            if(prime[i] && prime[i-2]){
                cout << i-2 << " " << i << endl;
                break;
            }
        }
    }
    return 0;
}

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

typedef long long ll;

ll LCM(ll a, ll b) {
    ll x=a*b,r;
    if(a<b)
        swap(a, b);

    r = a%b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }

    return x/b;
}

int RR(int x) {
    int r=0;
    while(x%2 == 0) {
        x /= 2;
        r++;
    }
    return r;
}

int main() {
    ll N,M,i,x=1,t;
    cin >> N >> M;
    vector<ll> a(N);

    for(i=0; i<N; i++) {
        cin >> a.at(i);
        if(a.at(i)%2 == 1) {
            cout << 0 << endl;
            return 0;
        }
        a.at(i) /= 2;
    }

    t = RR(a.at(0));
    for(i=0; i<N; i++) {
        if(RR(a.at(i)) != t) {
            cout << 0 << endl;
            return 0;
        }
        a.at(i) >>= t;
    }
    M >>= t;
    
    for(i=0; i<N; i++) {
        x = LCM(x, a.at(i));
        if(x > M) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << (M/x+1)/2 << endl;
}

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

struct Game {
    int a, b;
    Game() {
        a = 0;
        b = 0;
    }
    void score(int card_a, int card_b) {
        if (card_a > card_b)
            a += card_a + card_b;
        else if (card_a < card_b)
            b += card_a + card_b;
        else {
            a += card_a;
            b += card_b;
        }
    }
    void board() {
        cout << a << " " << b << endl;
    }
};

int main()
{
    for (int n; cin >> n && n;) {
        Game game;
        for (int a, b; n-- && cin >> a >> b;)
            game.score(a, b);
        game.board();
    }

    return 0;
}

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

#define mp       make_pair
#define mt       make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string w;
map<char, int> deg;
int main(){
  cin >> w;
  for_each(w.begin(), w.end(), [&](char &c){
      deg[c]++;
    });
  bool ok = true;
  for (auto &val : deg){
    if (val.second % 2 != 0){
      ok = false;
    }
  }
  if (ok)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <iostream>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
#include <cmath>

using namespace std;

char arr[100010];
int res[100010];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, i;
    scanf("%d%s", &n, arr);

    for(int bb = 0; bb < 4; bb++)
    {
        res[0] = bb & 1;
        res[1] = bb >> 1;
        for(i = 2; i < n; i++)
        {
            int t = res[i - 2] + res[i - 1];
            if(arr[i - 1] == 'o' && t % 2 == 1 || arr[i - 1] == 'x' && t % 2 == 0)
                res[i] = 1;
            else
                res[i] = 0;
        }

        {
            int t = res[n - 1] + res[0] + res[1];
            if(arr[0] == 'o' && t % 2 == 1 || arr[0] == 'x' && t % 2 == 0)
                continue;
        }

        {
            int t = res[n - 2] + res[n - 1] + res[0];
            if(arr[n - 1] == 'o' && t % 2 == 1 || arr[n - 1] == 'x' && t % 2 == 0)
                continue;
        }

        for(i = 0; i < n; i++)
        {
            if(res[i])
                printf("W");
            else
                printf("S");
        }
        puts("");
        return 0;
    }

    puts("-1");
    return 0;
}

Measured memory_bytes: 768
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi

sum=sum(a)
rui=[0]
n.times do |i|
  rui<<rui[-1]+a[i]
end

putsend 0 if rui.index(sum/2)

rui2=[0]
ar=a.reverse
n.times do |i|
  rui2<<rui2[-1]+ar[i]
end

min=2020202020
(n+1).times do |i|
  d=(rui[i]-rui2[n-i]).abs
  min=d if min>d
end

# puts rui.to_s
# puts rui2.to_s
# puts ar.to_s

puts min


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

#define ALL(V) (V).begine(),(V).end()
#define SORT(V) sort(ALL(V))
#define REV(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REV(V)

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

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

#define SZ(x) ((int)(x).size())

typedef vector<int> vi;
typedef long long ll;

double PI = 3.1415;

/* 入力 */
int N,M;

void calc()
{
    cin >> N;
    map<int,int> m;
    rep(i,N - 1)
    {
        int tmp;
        cin >> tmp;
        if(m.count(tmp) == 0)
        {
            m.insert(make_pair(tmp,1));   
        }
        else
        {
            m[tmp]++;
        }
    }
    rep(i,N)
    {
        if(m.count(i + 1) == 0)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << m[i + 1] << endl;
        }
    }
}

int main()
{
    calc();
}

Measured memory_bytes: 12848
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static int n;
	static int[] an;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			n = in.nextInt();
			an = in.nextIntArray(n);

			Set<Integer> set = new HashSet<>();
			dfs(0, 0, set);

			int q = in.nextInt();
			for (int i = 0; i < q; i++) {
				int m = in.nextInt();
				if (set.contains(m)) {
					out.println("yes");
				} else {
					out.println("no");
				}
			}

		}

		static void dfs(int now, int sum, Set<Integer> set) {

			if (now >= an.length) {
				set.add(sum);
				return;
			}

			// n を足さない場合
			dfs(now + 1, sum, set);

			// n を足す場合
			dfs(now + 1, sum + an[now], set);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



Measured memory_bytes: 43756
from collections import Counter

n = int(input())
A = list(map(int, input().split()))


D = Counter(A)
A = set(A)
if len(A) == 1 and 0 in A:
	print("Yes")
elif len(A) == 2 and 0 in A and n % 3 == 0:
	for k, v in D.items():
		if k != 0:
			cnt_else = v
		
	if cnt_else == n * 2 // 3:
		print("Yes")
	else:
		print("No")
elif len(A) == 3 and n % 3 == 0:
	if len(set(D.values())) == 1:
		A = list(A)
		if A[0] ^ A[1] ^ A[2] == 0:
			print("Yes")
		else:
			print("No")
	else:
		print("No")		
else:
	print("No")
			

Measured memory_bytes: 14468