akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
const int N=4e3+5;
long long n,b,r,jc[N],invjc[N];
long long ksm(long long a,long long n)
{
    long long res=1;
    while(n)
    {
        if(n&1)res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}
long long C(long long m,long long n)
{
    return jc[n]*invjc[m]%mod*invjc[n-m]%mod;
}
int main()
{
    cin>>n>>b;
    r=n-b;
    jc[0]=invjc[0]=1;
    for(long long i=1;i<=n;i++)
    {
        jc[i]=i*jc[i-1]%mod;
        invjc[i]=ksm(jc[i],mod-2);
    }

    for(long long m=1;m<=b;m++)
    {
        if(m>r+1||m>b)
        cout<<0<<endl;
        else
        cout<<C(m,r+1)*C(m-1,b-1)%mod<<endl;
    }
    return 0;
}


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

int N,a,b;
ll K;
ll A[100010] = {0};

int main(){
	cin >> N >> K;
	for(int i=0;i<N;i++){
		cin >> a >> b;
		A[a] += b;
	}
	ll sum = 0;
	for(int i=1;i<=1e5;i++){
		sum += A[i];
		if(K<=sum){
			cout << i << endl;
			return 0;
		}
	}
}

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

int main() {
    int x, y;
    cin >> x >> y;
    for(int i = 0; i <= x; ++i) {
        int sum = 2*i + 4*(x-i);
        if(sum == y) {
            cout << "Yes" << '\n';
            return 0; 
        }
    }

    cout << "No" << '\n';
}


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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1e9+7
#define PI              2*acos(0.0)


int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n,k;
        cin>>n>>k;
        ll a[n],mn=INT_MAX;
        for(ll i=0;i<n;i++)
        {
            cin>>a[i];
            mn=min(a[i],mn);
        }
        for(ll i=0;i<n;i++)
        {
            a[i]=a[i]-mn+1;
        }
        for(ll i=1;i<n;i++) a[i]=(a[i]+a[i-1]);
        ll x=a[k-1];
        for(ll i=k;i<n;i++)
        {
            if(a[i]-a[i-k]>x)
                cout<<"Yes";
            else cout<<"No";
            nl;
            x=a[i]-a[i-k];
        }

    }
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  sort(d.begin(), d.end());
  int ans = d[n/2]-d[n/2-1];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;


signed main()
{

  int N;
  int minusCount = 0;
  i64 sum = 0;
  i64 minv = (1LL << 62);

  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    sum += abs(a);

    if (a < 0) {
      ++minusCount;
    }
    if (abs(a) < abs(minv)) {
      minv = a;
    }
  }

  clog << sum << ' ' << minv << endl;

  if (minusCount % 2 == 0) {
    cout << sum << endl;
  } else {
    cout << sum - 2 * abs(minv) << endl;
  }


  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 12;
char s[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> s;
    int n = strlen(s);
    if(n & 1) cout << "No";
    else{
        for(int i = 0; i < n; i += 1)
            if(((i & 1) and s[i] != 'i') or (not (i & 1) and s[i] != 'h')){
                cout << "No";
                return 0;
            }
        cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a, b, c, n, yaku=0;
  scanf("%d %d %d",&a,&b,&c);
  for(n=a ; n<=b ; n++){
    if(c%n==0) yaku++;
  }
  printf("%d\n",yaku);

 return 0;
  }

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

int main() {
  int a = 1;
  int b = 1;
  for (;a < 10 && b <= 9;) {
    cout << b << "x" << a << "=" << a*b << endl;
    ++a;
    if (a == 10 && b <= 8) {
    ++b;
    a = 1;
    }
  }
}

Measured memory_bytes: 3080
#include<stdio.h>
#include<string.h>
int main()
{
    int N,K;
    char s[100];
    scanf("%d%d\n",&N,&K);
    scanf("%s",s);
    s[K-1] = s[K-1] + 32;
    printf("%s",s);
    return 0;
}


Measured memory_bytes: 128
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
def G(x,y):
    if(x<y):
        x,y=y,x
    if(y==0):
        return x
    return G(y,x%y)


a,b,c,d=l()
ans=0
# print(a,b,c,d,b//c,a//c)
ans+=(b//c-a//c+(a%c==0))
# print(ans)
ans+=(b//d-a//d+(a%d==0))
# print(ans)
lcm=c*d//G(c,d)
ans-=(b//lcm-a//lcm+(a%lcm==0))
print(b-a+1-ans)

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

bool solve() {
    ll R, C, N;
    cin >> R >> C >> N;

    auto on_edge = [&](ll x, ll y) {
        return x == 0 || x == R || y == 0 || y == C;
    };
    auto dist = [&](ll x, ll y) {
        if ( y == 0 ) return x;
        else if ( x == R ) return R + y;
        else if ( y == C ) return R + C + (R-x);
        else return R + C + R + (C-y);
    };

    ll x1, y1, x2, y2;
    vector<pair<ll,int>> v;
    for ( int i = 0; i < N; i++ ) {
        cin >> x1 >> y1 >> x2 >> y2;
        if ( on_edge(x1,y1) && on_edge(x2,y2) ) {
            v.emplace_back(dist(x1,y1), i);
            v.emplace_back(dist(x2,y2), i);
        }
    }
    sort(v.begin(), v.end());
    stack<int> s;
    for ( int i = 0; i < v.size(); i++ ) {
        auto vv = v[i].second;
        if (s.empty() || s.top() != vv) {
            s.push(vv);
        } else {
            s.pop();
        }
    }
    return s.empty();
}

int main() {
    string ans = solve() ? "YES" : "NO";
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6384
A, B, C = map(int, input().split())
if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
    print(0)
else:
    print(min(abs((A//2)*B*C-((A//2)+1)*B*C),abs((B//2)*A*C-((B//2)+1)*A*C),abs((C//2)*B*A-((C//2)+1)*B*A)))

Measured memory_bytes: 38256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

A, B, C = mi()

if A*C < B:
    print(C)
else:
    print(B//A)


Measured memory_bytes: 3064
#include <iostream>

int main(void) {
	// input
	int a, b, c;
	std::cin >> a >> b >> c;

	bool is_div = false;
	for(int i = 1; i <= b; ++i) {
		if(a * i % b == c) is_div = true;
	}

	std::cout << (is_div ? "YES" : "NO") << std::endl;

	return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edge[a].append(b)
        edge[b].append(a)
        
    ans = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        p -= 1 
        ans[p] += x
    visited = [False] * N
    Q = deque()
    Q.append(0)
    while Q:
        v = Q.popleft()
        visited[v] = True
        for d in edge[v]:
            if visited[d]:
                continue
            Q.append(d)
            ans[d] += ans[v]

    print(*ans)



if __name__ == "__main__":
    main()

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

int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    int al = f, as = 0;
    set<int> liquid, solid;
    for(int i = 0; i <= f; i += 100*a){
        for(int j = 0; j <= f - i; j += 100*b){
            liquid.insert(i+j);
        }
    }
    for(int i = 0; i <= f; i += c){
        for(int j = 0; j <= f - i; j += d){
            solid.insert(i+j);
        }
    }
    for(int l : liquid){
        for(int s : solid){
            if(l + s <= f && s * 100 <= e * l){
                if(as*(l + s) <= s*(al + as)){
                    al = l;
                    as = s;
                }
            }
        }
    }
    cout << al + as << ' ' << as << endl;
}

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

int b()
{
    int m, n;
    std::cin >> m >> n;
    
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        int temp = 0;
        std::cin >> temp;
        sum += temp;
    }
    
    int ans = std::max(-1, m - sum);
    
    std::cout << ans << std::endl;
    
    return 0;
}


int main(int argc, const char * argv[])
{
    b();
    return 0;
}

Measured memory_bytes: 3636
n=int(input())
num_list=list(map(int,input().split()))

count=0
for i in range(0,len(num_list)):
    minj=i
    for j in range(i+1,len(num_list)):
        if num_list[minj]>num_list[j]:
            minj=j
    tmp=num_list[minj]
    num_list[minj]=num_list[i]
    num_list[i]=tmp
    if minj!=i:
        count+=1

ans=str(num_list[0])
for i in range(1,len(num_list)):
    ans+=" "+str(num_list[i])
print(ans)
print(count)



Measured memory_bytes: 5596
n = int(input())
a = [int(input()) for _ in range(n)]
d = {}
for i in range(n):
  d[i] = a[i]
button = 0
for i in range(n):
  button = d[button] - 1
  if button == 1:
    print(i+1)
    exit()
print(-1)


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
int N;
int la[100000],tte[100000];

signed main(){
    cin>>N;
    rep(i,N){
        int l=i,r=N-1-i;
        la[abs(r-l)]++;
    }

    rep(i,N){
        int a;
        cin>>a;
        tte[a]++;
    }

    int ans=1;
    rep(i,N){
        if(la[i]!=tte[i]){
            cout<<0<<endl;
            return 0;
        }
        if(la[i])ans=ans*la[i]%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
open System

let [|a; b|] = stdin.ReadLine().Split(' ') |> Array.map int64
 
let g (x0: int64) (y0: int64) = 
    let rec loop x y =
        if y % x = 0L then
            x
        else 
            loop (y % x) x
 
    loop (min x0 y0) (max x0 y0)
 
printfn "%d" <| (a * b / (g a b))

Measured memory_bytes: 11996
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int h, a; cin >> h >> a;
	cout << (h + a - 1) / a << endl;
}

Measured memory_bytes: 256
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n; cin >> n;
    string s; cin >> s;

    REP(i, s.size()) {
        s[i] += n;
        s[i] = (s[i] - 'A') % ('Z' - 'A' + 1) + 'A';
    }
    
    cout << s << endl;
    
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
  let mut line: String = String::new();
  io::stdin().read_line(&mut line);
  line.trim().parse().ok().unwrap()
}

fn main() {
  let s: String = input();
  let s_vec:Vec<char> = s.chars().collect();
  //println!("{:?}", s_vec);
  let len = s_vec.len();
  if s_vec[0] != 'A' || s_vec[len-1].is_uppercase() || s_vec[1].is_uppercase() {
    println!("WA");
    return;
  }
  let mut count = 0;
  let mut i = 0;

  for c in s_vec {
    if i > 1 && i != len{
      if c.is_uppercase() {
        if c == 'C' {
          count += 1;
        } else {
          println!("WA");
          return;
        }
        if i == len - 1 {
          println!("WA");
          return;
        }
      }
    }
    i += 1;
  }
  if count != 1 {
    println!("WA");
  } else {
    println!("AC");
  }

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int a,b,c;
  cin >> a >> b >> c;
  int ans=0;
  ans+=c/(7*a+b);
  c-=ans*(7*a+b);
  ans*=7;
  if(6*a>=c)ans+=(c+a-1)/a;
  else ans+=7;
  cout << ans << endl;
}



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

static const int coins[]{500, 100, 50, 10, 5, 1};

int main() {
  while (true) {
    int p;
    cin >> p;
    if (!p)
      break;
    int ans{};
    p = 1000 - p;
    for (int i{}; i < 6; ++i) {
      ans += p / coins[i];
      p %= coins[i];
    }
    cout << ans << endl;
  }

  return 0;
}



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

#define ll long long

int main(){

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

    ll menseki, length;

    menseki = a * b;
    length = 2*a + 2*b;

    cout << menseki << " " << length << endl;

    return 0;
}

Measured memory_bytes: 3036
#include <iostream>
#include <cstdio>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
using namespace std; 
int arr[2005]; 
int main()
{
	// freopen("ARC085-D.in", "r", stdin); 
	int n, z, w, ans = 0; 
	scanf("%d%d%d", &n, &z, &w); 
	for (int i = 0; i < n; i++)
		scanf("%d", arr + i); 
	if (n >= 2)
		ans = max(ans, my_abs(arr[n - 2] - arr[n - 1])); 
	printf("%d\n", max(ans, my_abs(arr[n - 1] - w)));
	return 0; 
}


Measured memory_bytes: 256
import math
def gcd(a,b):
    c=max([a,b])
    d=min([a,b])
    if c%d==0:
        return d
    else:
        return gcd(d,c%d)
N,K=map(int, input().split())
A=[int(i) for i in input().split()]
if max(A)<K:
    print("IMPOSSIBLE")
else:
    G=A[0]
    for i in range(1,N):
        G=gcd(G,A[i])
    if K%G==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


Measured memory_bytes: 14252
x=int(input())
l=[1]
for i in range(2,32):
    for k in range(2,10):
        if i**k<=1000:
            l.append(i**k)
        else:
            break
l=list(set(l))
l.sort()
#print(l)
for i in range(1,len(l)):
    if x<l[i]:
        print(l[i-1])
        break
else:print(1000)


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


int main(void) {
    using namespace std;

    long n;
    cin >> n;
    vector<long> y(n), sy(n);
    for(auto &x: y) cin >> x;
    copy(y.begin(), y.end(), sy.begin());

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

    long l = sy[n/2-1], r = sy[n/2];

    for(int i=0; i<n; i++)
        cout << (y[i] <= l ? r : l) << endl;

}


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

int main(){
    char s[101];
    cin >> s;

    int n = strlen(s);
    rep(i,n){
        if( i % 2 == 0){
            if(s[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }
            else
            {
                if(s[i] == 'R'){
                    cout << "No" << endl;
                    return 0;
                }
            }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   int n;
   cin>>n;
   int mn=INT_MAX;
   int cnt=0;
   rep(i, n){
      int p;
      cin>>p;
      if(p<=mn) cnt++;
      mn=min(mn, p);
   }

   cout<<cnt<<endl;
   return 0;
}


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

const int max_attempt=10000;
const int change_per_attempt=10;

int main()
{
	srand(1);


	int d;
	cin >> d;

	vector<int> c(26+1);
	for (int i=1;i<=26;++i)
	{
		cin >> c[i];
	}

	vector<vector<int>> s(d+1,vector<int>(26+1));
	for (int i=1;i<=d;++i)
	{
		for (int j=1;j<=26;++j)
		{
			cin >> s[i][j];
		}
	}
	vector<int> t(d+1);
	vector<int> t_backup(d+1);
	for (int i=1;i<=d;++i)
	{
		// cin >> t[i];
		t[i]=rand()%26+1;
	}

#ifdef NEVER_DEFINED
	int m;
	cin >> m;
	vector<pair<int,int>> q(m);

	for (int i=0;i<m;++i)
	{
		int dd,qq;
		cin >> dd >> qq;
		q[i]=make_pair(dd,qq);
	}
#endif

	vector<int> last(26+1);
	vector<set<int>> hh(26+1);
	vector<set<int>> hh_backup(26+1);
	for (int i=1;i<=26;++i)
	{
		last[i]=0;
		hh[i].insert(0);
		hh[i].insert(d+1);
	}


	int64_t score=0;
	for (int i=1;i<=d;++i)
	{
		score+=s[i][t[i]];
		last[t[i]]=i;
		hh[t[i]].insert(i);
		for (int j=1;j<=26;++j)
		{
			score-=c[j]*(i-last[j]);
		}
		//cout << score << endl;
	}

	for (int i=0;i<max_attempt;++i)
	{
		t_backup=t;
		hh_backup=hh;
		int prev_score=score;
		for (int j=0;j<change_per_attempt;++j)
		{
			//int dd=q[i].first;
			//int qq=q[i].second;
			int dd=rand()%d+1;
			int qq=rand()%26+1;
			int rr=t[dd];
			//int prev_score=score;

			score-=s[dd][rr];
			score+=s[dd][qq];
			auto it=hh[rr].find(dd);
			auto prev=it;
			--prev;
			auto next=it;
			++next;
			score-=(dd-*prev)*(*next-dd)*c[rr];

			hh[rr].erase(dd);
			t[dd]=qq;

			hh[qq].insert(dd);
			it=hh[qq].find(dd);
			prev=it;
			--prev;
			next=it;
			++next;
			score+=(dd-*prev)*(*next-dd)*c[qq];
		}

		//fprintf(stderr,"%d %lld %lld\n",i,prev_score,score);
		if (score<prev_score)
		{
			// get back to original
#ifdef NEVER_DEFINED
			t[dd]=rr;
			hh[rr].insert(dd);
			hh[qq].erase(dd);
#endif
			t=t_backup;
			hh=hh_backup;
			score=prev_score;
		}
	}

	fprintf(stderr,"%lld\n",score);
	for (int i=1;i<=d;++i)
	{
		cout << t[i] << endl;
	}

}






Measured memory_bytes: 3824
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

// input  aaabaaaab
// output 921034210
int Zargorithm( int n, const int* S, int* A ) {
    A[0] = n;
    int i = 1, j = 0;
    while (i < n) {
        while (i+j < n && S[j] == S[i+j]) ++j;
        A[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i+k < n && k+A[k] < j) A[i+k] = A[k], ++k;
        i += k; j -= k;
    }
    return 0;
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<int> a(n),b(n);
    int N=n*3;
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    for(i=0; i<n; i++) {
        scanf("%d", &b[i]);
    }
    vector<int> S, A(N);
    for(i=0; i<n; i++) {
        int j=(i+1)%n;
        S.push_back(a[i]^a[j]);
    }
    for(i=0; i<n; i++) {
        int j=(i+1)%n;
        S.push_back(b[i]^b[j]);
    }
    for(i=0; i<n; i++) {
        int j=(i+1)%n;
        S.push_back(b[i]^b[j]);
    }
    Zargorithm( N, &S[0], &A[0]);

    vector<pair<int,int> > ans;
    for(i=0; i<n; i++) {
        if(A[n+i]>=n) {
            int k=(n-i)%n;
            int x=b[i]^a[0];
            ans.push_back(make_pair(k,x));
        }
    }
    sort(ans.begin(), ans.end());
    for(i=0; i<(int)ans.size(); i++) {
        printf("%d %d\n", ans[i].first, ans[i].second);
    }

    return 0;
}



Measured memory_bytes: 13932
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){

  int n;
  int p[22];
  int i;
  int cnt = 0;

  scanf("%d", &n);

  for(i = 1;i <= n;i++) scanf("%d", &p[i]);

  for(i = 2;i < n;i++){
    if(p[i - 1] < p[i] && p[i] < p[i + 1]) cnt++;
    if(p[i - 1] > p[i] && p[i] > p[i + 1]) cnt++;
  }

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 128
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string[] str2 =str.Split();
            int W = int.Parse(str2[0]);
            int H = int.Parse(str2[1]);
            int x = int.Parse(str2[2]);
            int y = int.Parse(str2[3]);
            int r = int.Parse(str2[4]);
            if (x - r < 0 || W < x + r || y - r < 0 || H < y + r)
            {
                Console.WriteLine("No");

            }
            else
            {
                Console.WriteLine("Yes");

            }
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 19640
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    bool flag = true;
    for (int i = 1; i <= n; i ++)
    {
        int x;
        scanf("%d", &x);
        if ((x % 2 == 0) && (x % 3) && (x % 5))
        {
            flag = false;
        }
    }
    if (flag)
    {
        printf("APPROVED\n");
    }
    else
    {
        printf("DENIED\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string st;
	cin>>st;
	for(int i=1;;i++){
		st.pop_back();
		if(st.length()%2)continue;
		bool f=false;
		for(int j=0;j*2<st.length();j++){
			if(st[j]!=st[st.length()/2+j]){
				f++;
				break;
			}
		}
		if(!f){
			cout<<st.length()<<endl;
			break;
		}
	}
	return 0;
}


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

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


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

int main()
{
    int n;cin>>n;
    vector<int> a(n);
    int i;
    for(i=0;i<n;i++)cin>>a.at(i);
    for(i=0;i<n;i++)a.at(i)-=i+1;
    sort(a.begin(),a.end());
    long long ans=0;
    for(i=0;i<n;i++)ans+=abs(a.at(i)-a.at(n/2));
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
//confilm 0LL and 1LL
//confilm cornercase such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	Vec a(n);
	rep(i, n) cin >> a[i];

	ll max1 = 0, max2 = 0;
	rep(i, n){
		if(a[i] >= max1){
			max2 = max1;
			max1 = a[i];
		}else if(a[i] > max2){
			max2 = a[i];
		}
	}

	rep(i, n){
		if(a[i] == max1) co(max2);
		else co(max1);
	}

	return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <cmath>
#include <queue>
typedef long long ll;
using namespace std;

int main(void){
    int a, b;
    cin >> a >> b;
    for(int i = 1; i <= 1000; i++){
        int tmp1 = i * 0.08;
        int tmp2 = i * 0.1;
        if(tmp1==a && tmp2==b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc133/tasks/abc133_d

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) cout << a[_i] << (_i + 1 == n ? endl : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) cout << a[_i][_j] << (_j + 1 == m ? endl : ' '); cout << endl

const int N_MAX = 1e5-1;
const int A_I_MAX = 1e9;

int N;
vector<int> A;

int main() {
  cin >> N;
  A = vector<int>(N);
  REP(i, N) cin >> A[i];

  int x = 0;
  REP(i, N) {
    if (i % 2) x -= A[i];
    else x += A[i];
  }
  REP(i, N) {
    cout << x;
    if (i + 1 == N) cout << endl;
    else cout << " ";
    x = A[i] * 2 - x;
  }
}


Measured memory_bytes: 1664
// Template by [thunder_blade]
// IIIT ALLAHABAD
// includes :)

#include <bits/stdc++.h>
#include <ext/rope> 
using namespace __gnu_cxx;
using namespace std;
#define TEST  int test_case; cin>>test_case; while(test_case--)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);  cin.tie(0);  cout.tie(0);
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define pf(x) printf("%f\n",x)
#define ps(x) printf("%s\n",x)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sf(x) scanf("%f",&x)
#define ss(x) scanf("%s",x)
#define pis(x) printf("%d ",x)
#define pls(x) printf("%lld ",x)
#define pfs(x) printf("%f ",x)
#define pss(x) printf("%s ",x)
#define FOR(i,a,b) for(i=a;i<b;i++)
#define mod (1000000007LL)
#define tr(container, it)  for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

const int N = 500005;
int A[N];
int vis[N];
int main()
{
	int n;
	si(n);
	int k = n/2 + 2;
	int lo = k-1;
	int hi = k+1;
	for(int i=0;i<n;i++){
		ll tmp;
		cin>>tmp;
		if(!i){
			vis[k]=1;
			A[k] = tmp;
		}
		else{
			if((n-i)%2){
				vis[lo]=1;
				A[lo--] = tmp;
			}
			else{
				vis[hi]=1;
				A[hi++] = tmp;
			}
		}
	}
	for(int i=0;i<N;i++){
		if(vis[i])
			cout<<A[i]<<" ";
	}
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define mk make_pair
#define se second
#define fi first
using namespace std;
int p[101];
int main(){
  set<int>s;
  int n,a,x=0;
  cin>>n;
  r(i,n){
    cin>>a;
    if(1<=a&&a<=399)p[0]++,s.insert(0);
    else if(400<=a&&a<=799)p[1]++,s.insert(1);
    else if(800<=a&&a<=1199)p[2]++,s.insert(2);
    else if(1200<=a&&a<=1599)p[3]++,s.insert(3);
    else if(1600<=a&&a<=1999)p[4]++,s.insert(4);
    else if(2000<=a&&a<=2399)p[5]++,s.insert(5);
    else if(2400<=a&&a<=2799)p[6]++,s.insert(6);
    else if(2800<=a&&a<=3199)p[7]++,s.insert(7);
    else x++;
  }
  if(s.size()==0)cout<<1<<' ';
  else cout<<s.size()<<' ';
  int sum=s.size();
  sum+=x;
  cout<<sum<<endl;
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))
A = []
for i in range(N):
    if not i == 0 and not i == N - 1:
        A.append(min(B[i - 1], B[i]))
    elif i == 0:
        A.append(B[i])
    else:
        A.append(B[i - 1])
print(sum(A))


Measured memory_bytes: 38384
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			int a = in.nextInt(),b = in.nextInt();
			if(a+b==0)break;
			int x = Math.max(a, b),y = Math.min(a,b);
			int cnt = 0;
			while(y!=0){
				x = x%y;
				int t = x;
				x = y;
				y = t;
				cnt++;
			}
		System.out.println(x+" "+cnt);	
		}
	}
}

Measured memory_bytes: 22900
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  set<int> s;
  rep(i,3){
    int a; cin >> a;
    s.insert(a);
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    string S;
    cin >> S;
    for(int i=0; i<(int)S.size(); i++){
        cout << 'x';
    }
    cout << endl;
}

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

int main(void) {
  int num;
  long long int prime;
  int count_prime = 0;
  int i, j;

  scanf("%d", &num);

  for (i = 0; i < num; i++) {
    int count = 0;
    scanf("%lld", &prime);
    if (prime == 2) {
      count_prime++;
    } else if (prime > 2 && prime % 2 != 0) {
      for (j = 3; j <= sqrt(prime); j += 2) {
        if (prime % j == 0)
          count++;
      }
      if (count == 0)
        count_prime++;
    }
  }

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

  return 0;
}



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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

#define MAX_N 200000
vector<vector<int>> edge(MAX_N + 1);
vector<int> node(MAX_N + 1);

void solve(int now_node, int pre_node);

int main(void){

  int n, q;  cin >> n >> q;
  for(int i = 0 ; i < n - 1; i++){
    int a, b;  cin >> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for(int i = 0 ; i < q ; i++){
    int p, x;  cin >> p >> x;
    node[p] += x;
  }

  solve(1, 0);
  for(int i = 1; i <= n ; i++)
    SCOUT(node[i]);
  
  cout << endl;
  return 0;
}

void solve(int now_node ,int pre_node){

  for(int i = 0 ; i < edge[now_node].size() ; i++){
    int next_node = edge[now_node][i];
    if(next_node == pre_node)  continue;

    node[next_node] += node[now_node];
    solve(next_node, now_node);
  }
}

Measured memory_bytes: 23424
#include<bits/stdc++.h>
using namespace std;
 
const long long N = 2e5+7;
int a[N];
bool b[N];
int n;
 
bool check(int m) {
    for (int i=1; i<2*n; i++)   b[i] = a[i] > m;
 
    int closest[2] = {N, N};
    for (int i=1; i<2*n; i++) {
        if (i > 1 && b[i] == b[i-1])              closest[b[i]] = min(closest[b[i]], abs(n-i));
        if (i + 1 < 2*n && b[i] == b[i+1])        closest[b[i]] = min(closest[b[i]], abs(n-i));
    }
 
    if (closest[0] == closest[1]) {
        assert(closest[0] == N);
        return (1-n%2)^b[n];
    }
    else if (closest[0] > closest[1])   return 1;
    else    return 0;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    cin>>n;
    for (int i=1; i<2*n; i++) cin>>a[i];
 
    int lo = 1, hi = 2*n-1;
    while (lo < hi) {
        int mid = (lo+hi)/2;
        if (check(mid))     lo = mid+1;
        else                hi = mid;
    }
    cout<<lo<<endl;
 
}

Measured memory_bytes: 4620
#include <stdio.h>

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    if(a < b) {
        puts("a < b");
    } else if(a > b) {
        puts("a > b");
    } else {
        puts("a == b");
    }
    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	lli a, b, x, ans; cin >> a >> b >> x;
    ans = ( b / x + 1 ) - ( a==0?0:( a - 1 ) / x + 1 );
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int main(){
	int n, m;
	while(scanf("%d%d", &n, &m), n||m){
		int h1[21],h2[21];
		int ans = 0;
		rep(i,21){
			h1[i] = 0;
			h2[i] = 0;
		}
		rep(i,n){
			int t;
			scanf("%d", &t);
			h1[t]++;
		}
		rep(i,m){
			int t;
			scanf("%d", &t);
			h2[t]++;
		}
		rep(i,21) ans += max(h1[i],h2[i])*i;
		printf("%d\n", ans);
	}
}

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


int main() 
{
    
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    int dp[3][n+1];
    for(int i=0; i<n; i++) 
    {
        cin>>a[i]>>b[i]>>c[i];
    }

    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(int i=1; i<n; i++) {
        dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
    }
    cout << max(max(dp[0][n-1], dp[1][n-1]), dp[2][n-1]);

    return 0;
}

Measured memory_bytes: 2560
//*** 1010101010101010101 ***//
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  t += s;
  cout << t << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int W[100];
int s[101];
int main(){
  int i, res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(W[Lj4PdHRW]);
    }
  }
  for(i=0;i<N;i++){
    s[i+1] = s[i] + W[i];
  }
  {
    int KL2GvlyY, Q5VJL1cS=0, cTE1_r3A, e98WHCEY;
    for(KL2GvlyY=0;KL2GvlyY<(N)+1;KL2GvlyY++){
      cTE1_r3A =  abs(s[N]-2*s[KL2GvlyY]+s[0]) ;
      if(Q5VJL1cS==0 || e98WHCEY>cTE1_r3A){
        e98WHCEY = cTE1_r3A;
        Q5VJL1cS = 1;
      }
    }
    res =e98WHCEY;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190626-1

// --- original code ---
// int N, W[100];
// int s[101];
// {
//   int i, res;
//   rd(N,W(N));
//   rep(i,N) s[i+1] = s[i] + W[i];
//   res = min[i=0---N]( abs(s[N]-2s[i]+s[0]) );
//   wt(res);
// }


Measured memory_bytes: 256
#include <iostream>

#define Vmax 100
int G[Vmax][Vmax];

bool WF(int);

int main(void)
{
  int v, e, s, t, i, j;
  
  std::cin >> v >> e;

 

  for(i=0; i<e; i++)
    {
      std::cin >> s >> t;
      G[s][t] = -1;
    }

  std::cout << WF(v) << std::endl;
  
  return 0;
}





bool WF(int v)
{
  
  int i, j, k;
  
    for(i=0; i<v; i++)
      {
	for(j=0; j<v; j++)
	  {
	    for(k=0; k<v; k++)
	      {
		if(G[j][i] != false && G[i][k] != false && G[j][k] > G[j][i] + G[i][k])
		  G[j][k] = G[j][i] + G[i][k];
	      }
	  }
      }

  for(i=0; i<v; i++)
      {
	if(G[i][i] < 0)
	  return true;
      }
  
  return false;
}


Measured memory_bytes: 3136
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int S[200001];

int main() {
	int N;
	scanf("%d", &N);
	REP(i, N) {
		int t;
		scanf("%d", &t);
		S[i] = t;
	}
	int t = 0;
	REP(i, N / 2+1) {
		if (i == 0)continue;
		if (N%i)continue;
		if (equal(S, S + N - i, S + i)) {
			t = i;
			break;
		}
	}
	if (!t) {
		printf("1\n");
		return 0;
	}
	printf("%d\n", N / t);

	return 0;
}


Measured memory_bytes: 1820
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

struct S {
	int d, v;

	bool operator< (const S &s) const {
		return d < s.d;
	}
};
//0 1 2 3 4 5
//5 4 3 2 1

int ans;
int N, M;
S s[100005];

int main(void) {
    scanf("%d %d", &N, &M);
    REP(i, 0, N) {
    	int A, B;
    	scanf("%d %d", &A, &B);
    	s[i].d = A;
    	s[i].v = B;
    }
    sort(s, s+N);

    int idx = 0;
    priority_queue<int> PQ;
    for (int i = 1; i <= M; i++) {
    	while (s[idx].d <= i && idx < N) PQ.push(s[idx++].v);

    	if (!PQ.empty()) {
    		ans += PQ.top(); PQ.pop();
    	}
    }
    
   

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

	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

LL inv(LL x){
  LL a=MOD-2;
  LL ans=1;
  while(a){
    if(a&1) ans=ans*x%MOD;
    x=x*x%MOD;
    a>>=1;
  }
  return ans;
}

int main(){
  string s;
  cin >> s;
  int n = s.length();
  LL k=1;
  rep(i,n) if(s[i]=='1') k=k*2%MOD;
  LL iv=inv(2);
  LL ans=k;
  LL now=1;
  per(i,n){
    if(s[i]=='1'){
      k=k*iv%MOD;
      ans=(ans+k*now%MOD)%MOD;
    }
    now=now*3%MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_E 200000

struct UnionFind{
    vector<int> par;
    vector<int> rank;

    UnionFind(int n){
        init(n);
    }

    //n要素で初期化
    void init(int n){
        par.resize(n);
        rank.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }

    //木の根を求める
    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    //xとyの属する集合を併合
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y]) par[x] = y;
        else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
};

struct edge { int u, v, cost; };

bool comp(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}

edge es[MAX_E];
int V, E;

int kruskal(){
    sort(es, es + E, comp);
    UnionFind uf(V);
    int res = 0;
    for(int i = 0; i < E; i++){
        edge e = es[i];
        if(!uf.same(e.u, e.v)){
            uf.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

signed main(){
    int n;
    cin >> n;
    vector<P> x(n),y(n);
    REP(i,n){
        cin >> x[i].first >> y[i].first;
        x[i].second = i;
        y[i].second = i;
    }
    sort(ALL(x));
    sort(ALL(y));
    int j = 0;
    REP(i,n - 1){
        es[j] = (edge){x[i].second, x[i + 1].second, x[i + 1].first - x[i].first};
        j++;
    }
    REP(i,n - 1){
        es[j] = (edge){y[i].second, y[i + 1].second, y[i + 1].first - y[i].first};
        j++;
    }
    V = n;
    E = 2 * (n - 1);
    cout << kruskal() << endl;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(){
	char ch;
	while((ch = getchar()) != EOF){
			if(ch >= 97 && ch <= 122)
				printf("%c",ch-32);
			else if(ch >= 65 && ch <= 90)
				printf("%c",ch+32);
			else
				printf("%c",ch);
	}
}



Measured memory_bytes: 2560
/*
    author: Salam_35
    Created at :

*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int t;cin >> t;while(t--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    int a,b,c,d;
    cin>> a>> b>>c>>d;
    int i=0;
    while(1)
    {
        if(i%2==0)
        {
            c-=b;
            if(c<=0){
            cout<<"Yes"<<endl;
            return 0;
            }
        }
        else if(i%2==1)
        {
            a-=d;
            if(a<=0){
                cout<<"No"<<endl;
                return 0;
            }
        }
        i++;
        
    }
    
}


Measured memory_bytes: 3596