akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;



int main() {

    int n; cin >> n;
    string s,t; cin >> s >> t;
    int ans = 0;

    rep(i,n){
        if(s.substr(n-1-i,i+1) == t.substr(0,i+1)) {
            ans = i+1;
        }
    }

    cout <<  n*2-ans;

    return 0;
}











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

bool hamming(int a) {
	while (1) {
		if (a == 1)return true;
		if (a % 2 == 0) a /= 2;
		else if (a % 3 == 0) a /= 3;
		else if (a % 5 == 0) a /= 5;
		else return false;
	}
}
int main()
{
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		int b;
		cin >> b;
		int s = 0;
		for (int c = a; c < b + 1; c++) {
			if (hamming(c))s++;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n=0;
	int ans=0;
	int j=0;
	cin>>n;
	vector<int> dish(n),sa(n),ad_sa(n-1);
	for(int i=0;i<n;i++)
	{
		cin>>dish[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>sa[i];
	}
	for(int i=0;i<n-1;i++)
	{
		cin>>ad_sa[i];
	}
	for(int i=0;i<n;i++)
	{
		ans+=sa[dish[i]-1];
	}
	for(int i=0;i<n-1;i++)
	{
		if(dish[i]+1==dish[i+1])
		{
			ans+=ad_sa[dish[i]-1];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll a[300009],b[300009];
set<pll> nk;
set<ll> sa,sb;
void solve()
{
    ll n,m,q;
    cin>>n>>m>>q;
    ll x,y,ma=0,mb=0;
    for(ll i=0;i<q;i++)
    {
        cin>>x>>y;
        nk.insert({x,y});
        a[x]++;
        ma=max(ma,a[x]);
        b[y]++;
        mb=max(mb,b[y]);
    }
    vll v;
    ll cn=0,cnt=0;
    for(ll i=1;i<=m;i++)
    {
        if(b[i]==mb)
        {
            cn++;
            sb.insert(i);
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        if(a[i]==ma)
        {
            cnt+=cn;
            sa.insert(i);
        }
    }
    for(auto i:nk)
    {
        if((sa.find(i.ff)!=sa.end())&&(sb.find(i.ss)!=sb.end()))
            cnt--;
    }
    ans=ma+mb;
    if(cnt==0)
        ans--;
    cout<<ans;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}



Measured memory_bytes: 55188
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++) 

using namespace std;

int main() {
    string s;
    cin >> s;

    if (s=="ABC") {
        cout << "ARC";
    } else {
        cout << "ABC";
    }
    return 0;
}

Measured memory_bytes: 3548
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(final String[] args) {

		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		Map<Integer, Long> aMap = new HashMap<Integer, Long>();
		int[] data = new int[n];
		for (int i = 0; i < n; i++) {
			data[i] = s.nextInt();
			if (aMap.containsKey(data[i])) {
				aMap.put(data[i], aMap.get(data[i]) + 1);
			} else {
				aMap.put(data[i], 1L);
			}
		}
		Map<Long, Long> map = new HashMap<Long, Long>();
		long total = 0;
		for (Integer k:aMap.keySet()) {
			long m = aMap.get(k);
			map.put((long)k, m * (m - 1) / 2);
		}

		for (Long key : map.keySet())
			total += map.get(key);

		for (int i = 0; i < data.length; i++) {
			long r = total;
			long k = data[i];
			if (aMap.get((int) k) == 1) {
				System.out.println(r);
			} else {
				long value = map.get(k);
				long N = aMap.get(data[i]);
				r -= value;
				r += (N - 1) * (N - 2) / 2;
				System.out.println(r);
			}
		}

	}
}


Measured memory_bytes: 114644
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
const int M=1e5+10;
int n,w[M],r[M];
int main(){
	n=read();
	F(i,1,n) w[i]=read();
	sort(w+1,w+n+1); 
//	int N=unique(w+1,w+n+1)-w-1;
	int N=0,len=1;
	w[n+1]=-1;
	F(i,1,n){
		if (w[i]!=w[i+1]) r[++N]=len,w[N]=w[i],len=0;
		len++;
	}
	if (N==1 && w[1]==0) return puts("Yes"),0;
	if (n%3) return puts("No"),0;
	if (N==2 && w[1]==0 && !((2*r[1])^r[2])) return puts("Yes"),0;
	if (N==3 && !(w[1]^w[2]^w[3]) && !(r[1]^r[2]) && !(r[1]^r[3])) return puts("Yes"),0;
	puts("No");
	return 0;
}



Measured memory_bytes: 896
require "set"

n, k = gets.split.map(&:to_i)
darr = gets.split.map(&:to_i)
uarr = (0..9).to_a - darr
uarr = uarr.to_set

while true
  flag = true
  n.to_s.chars do |c|
    flag = uarr.include?(c.to_i)
    break unless flag
  end

  if flag
    puts n
    break
  end
  
  n += 1
end


Measured memory_bytes: 14452
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

a, b = [int (i) for i in raw_input ().split ()]
l = a * b / g (a, b)
if l == a: print "-1"
elif l == 2 * a: print 3 * a
else: print 2 * a


Measured memory_bytes: 4520
import sys
from itertools import accumulate

import numpy as np


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

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

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


n, k = map(int, input().split())
aaa = [0] + list(map(int, sys.stdin))
acc = [a - i * k for i, a in enumerate(accumulate(aaa))]
values = sorted(set(acc))
dct = {v: i for i, v in enumerate(values, start=1)}
bit = Bit(len(values))
ans = 0
for d in acc:
    i = dct[d]
    ans += bit.sum(i)
    bit.add(i, 1)
print(ans)


Measured memory_bytes: 60272
stdin = open(0).read().split('\n')
A=list(map(int,stdin[0].split()))
A=A+list(map(int,stdin[1].split()))
A=A+list(map(int,stdin[2].split()))
N=int(stdin[3])
l = [0] * 10
for a in range(9):
    for b in range(N):
        if int(stdin[4+b])==A[a]:
            l[a]=1
if l[0]+l[1]+l[2]==3:print('Yes')
elif l[3]+l[4]+l[5]==3:print('Yes')
elif l[6]+l[7]+l[8]==3:print('Yes')
elif l[0]+l[3]+l[6]==3:print('Yes')
elif l[1]+l[4]+l[7]==3:print('Yes')
elif l[2]+l[5]+l[8]==3:print('Yes')
elif l[0]+l[4]+l[8]==3:print('Yes')
elif l[2]+l[4]+l[6]==3:print('Yes')
else:print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
 
using namespace std;
 
int main(void) {
  int N, K, A;
  cin >> N >> K;
  vector<int> d(K);
  vector<bool> has(N, false);

  for(int i = 0; i< K; i++){
    cin >> d[i];
    for (int j = 0; j < d[i]; j++) {
      cin >> A;
      has[A - 1] = true;
    }
  }

  int res = 0;
  for(int i = 0; i< N; i++){
    if(has[i] == false){
      res++;
    }
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <cmath>
#include <algorithm>

const int maxn=100000;

int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
          f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return x*f;
}

struct seg
{
  int l,r,flag;
};

seg s[maxn+10];

bool cmpl(int a,int b)
{
  return s[a].l>s[b].l;
}

bool cmpr(int a,int b)
{
  return s[a].r<s[b].r;
}

int n,a[maxn+10],b[maxn+10];
long long rans;

inline int dist(int now,int to)
{
  if(now<s[to].l)
    {
      return s[to].l-now;
    }
  else if(now>s[to].r)
    {
      return now-s[to].r;
    }
  else
    {
      return 0;
    }
}

inline int getnow(int now,int to)
{
  if(now<s[to].l)
    {
      return s[to].l;
    }
  else if(now>s[to].r)
    {
      return s[to].r;
    }
  else
    {
      return now;
    }
}

int main()
{
  n=read();
  for(int i=1; i<=n; ++i)
    {
      s[i].l=read();
      s[i].r=read();
      a[i]=b[i]=i;
    }
  std::sort(a+1,a+n+1,cmpl);
  std::sort(b+1,b+n+1,cmpr);
  int left=1,right=1,now=0;
  long long ans=0;
  s[a[1]].flag=1;
  ans+=dist(now,a[1]);
  now=getnow(now,a[1]);
  for(int i=1; i<n; ++i)
    {
      while(s[a[left]].flag)
        {
          ++left;
        }
      while(s[b[right]].flag)
        {
          ++right;
        }
      if(dist(now,a[left])>dist(now,b[right]))
        {
          s[a[left]].flag=1;
          ans+=dist(now,a[left]);
          now=getnow(now,a[left]);
        }
      else
        {
          s[b[right]].flag=1;
          ans+=dist(now,b[right]);
          now=getnow(now,b[right]);
        }
    }
  for(int i=1; i<=n; ++i)
    {
      s[i].flag=0;
    }
  rans=ans+abs(now);
  left=right=1;
  now=ans=0;
  s[b[1]].flag=1;
  ans+=dist(now,b[1]);
  now=getnow(now,b[1]);
  for(int i=1; i<n; ++i)
    {
      while(s[a[left]].flag)
        {
          ++left;
        }
      while(s[b[right]].flag)
        {
          ++right;
        }
      if(dist(now,a[left])>dist(now,b[right]))
        {
          s[a[left]].flag=1;
          ans+=dist(now,a[left]);
          now=getnow(now,a[left]);
        }
      else
        {
          s[b[right]].flag=1;
          ans+=dist(now,b[right]);
          now=getnow(now,b[right]);
        }
    }
  printf("%lld\n",std::max(ans+abs(now),rans));
  return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  int A, B, K;
  cin >> A >> B >> K;

  int count = 0;
  int ans = 0;
  int start = max(A, B);
  for(int i = 0; i < start; i++){
    int div = start - i;
    if(B%div == 0 && A%div == 0) count++;
    if(count == K){
		cout << div << endl;
      	return 0;
    }
  }

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    vector<string> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    vector<string> B(M);
    for (int i = 0; i < M; i++) {
        cin >> B.at(i);
    }

    string ans;
    for (int i = 0; i <= N - M; i++) {
        for (int j = 0; j <= N - M; j++) {
            ans = "Yes";
            for (int k = 0; k < M; k++) {
                for (int l = 0; l < M; l++) {
                    if (B.at(k).at(l) != A.at(i + k).at(j + l)) {
                        ans = "No";
                    }
                }
            }
            if (ans == "Yes") {
                cout << ans << endl;
                return 0;
            }
        }
    }

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

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int a, b, t;
  readf("%d %d %d\n", &a, &b, &t);
  int res;
  foreach (i; iota(a, t+1, a)) {
    res += b;
  }
  res.writeln;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
	static PrintWriter out = new PrintWriter(System.out);
	static FastScanner sc = new FastScanner();
	static Scanner stdIn = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		if(n == 0)      out.println("1");
		else if(n == 1) out.println("2");
		else if(n == 2) out.println("1");
		else            out.println("0");
		out.flush();
	}

}

//-----------------Template------------------//
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	 
	public int nextInt() {
		 if (!hasNext()) throw new NoSuchElementException();
		 int n = 0;
		 boolean minus = false;
		 int b = readByte();
		 if (b == '-') {
			 minus = true;
			 b = readByte();
		 }
		 if (b < '0' || '9' < b) {
			 throw new NumberFormatException();
		 }
		 while(true){
			 if ('0' <= b && b <= '9') {
				 n *= 10;
				 n += b - '0';
			 }else if(b == -1 || !isPrintableChar(b)){
				 return minus ? -n : n;
			 }else{
				 throw new NumberFormatException();
			 }
			 b = readByte();
		 }
	}
	 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	 
 
}

Measured memory_bytes: 17352
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin >> d;
  switch(d){
    case 25: cout << "Christmas" << endl;
      break;
    case 24: cout << "Christmas Eve" << endl;
      break;
    case 23: cout << "Christmas Eve Eve" << endl;
      break;
    case 22: cout << "Christmas Eve Eve Eve" << endl;
      break;
  }
  return 0;
}

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

int main() {
  int64_t H, W;
  cin >> H >> W;
  int64_t A = H * W;
  int64_t ans;
  if (H == 1 || W == 1) {
    ans = 1;
  }
  else if (A % 2 == 0) {
    ans = A / 2;
  }
  else {
    ans = (A / 2) + 1;
  }
  cout << ans << endl;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    ll n; cin >> n;
    ll ans = INFL;
    for(ll i=1; i*i <= n; i++){
        if(n%i!=0) continue;
        ll k = n/i;
        ll d = 11;
        for(ll dig=10000000000; dig > 0; dig /= 10){
            if(k/dig>0){
                chmin(ans, d);
                break;
            }
            d--;
        }
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 3584
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		int b[] = new int[10005];
		int length;
		int t[] = new int[10005];

		for (int i = 0; i < 10005; i++) {
			t[i] = i * (i + 1) / 2;
		}

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}

			int sum = 0;
			length = n;
			for (int i = 0; i < n; i++) {
				sum += b[i] = sc.nextInt();
			}
			int f = Arrays.binarySearch(t, sum);

			if (f < 0) {
				System.out.println("-1");
			} else {
				int cnt = 0;
				int id;
				int bottom;
				boolean flag;

				while (true) {
					flag = true;
					for (int i = 0; i < length; i++) {
						if (b[i] != i + 1) {
							flag = false;
						}
					}
					if (flag) {
						break;
					}

					cnt++;
					bottom = length;
					for (int i = 0; i < length; i++) {
						b[i]--;
					}
					int nlen = 0;
					id = 0;
					for (int i = 0; i < length; i++) {
						if (b[i] != 0) {
							b[id] = b[i];
							id++;
							nlen++;
						}
					}
					b[id] = bottom;
					nlen++;
					length = nlen;
					for (int i = 0; i < length; i++) {
						if (b[i] != i + 1) {
							flag = true;
						}
					}
					if (10005 <= cnt) {
						break;
					}
				}
				if (cnt <= 10000) {
					System.out.println(cnt);
				} else {
					System.out.println("-1");
				}
			}
		}
	}
}

Measured memory_bytes: 21780
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t gcd(int64_t a, int64_t b)
{
    if (a == 0) {
        return b;
    }
    return gcd(b % a, a);
}

int64_t t[100];

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

    rep(i, n)
    {
        cin >> t[i];
    }

    int64_t d;
    rep(i, n)
    {
        if (i == 0) {
            d = t[i];
        } else {
            int64_t cd = gcd(d, t[i]);
            d = d / cd * t[i];
        }
    }
    cout << d << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n2,s,n;
int main(){
	scanf("%d",&n2);
	n=n2;
	while(n>0){
		s+=n%10;
		n/=10;
	}
	if(n2%s==0)printf("Yes");
	else printf("No");
}

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed(n) fixed << setprecision(n)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   int n,m,ans=0;
   double cnt=0;
   cin>>n>>m;
   vector<int> x(n),y(n);

   rep(i,0,n){
      cin>>x[i];
      cnt += x[i];
   }

   //cout<<cnt;
   rep(i,0,n){
      if(x[i] >= (cnt/(4*m))){
         ++ans;
      }
   }

   if(ans >= m){
      cout<<"Yes\n";
   }else cout<<"No\n";
   return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
  
int a[4];
int c[8];
int k;
  
int calc(){
    int op = c[k++];
    int ret = 0;
    if(op >= 0){
        ret = op;
    }
    else if(op >= -3){
        int x = calc();
        int y = calc();
        if(op == -1){
            ret = x + y;
        }
        else if(op == -2){
            ret = x - y;
        }
        else{
            ret = x * y;
        }
    }
    else{
        throw 0;
    }
    return ret;
}
  
void print(){
    int op = c[k++];
    if(op >= 0){
        printf("%d", op);
    }
    else{
        char ch;
        if(op == -1){ ch = '+'; }
        else if(op == -2){ ch = '-'; }
        else{ ch = '*'; }
  
        putchar('(');
        print();
        printf(" %c ", ch);
        print();
        putchar(')');
    }
}
  
void solve(int i, int S, int oprem, int numrem){
    if(i == 6){
        for(int j = 0; j < 4; ++j){
            if(S >> j & 1){
                c[6] = a[j];
            }
        }
        try{
            k = 0;
            if(calc() == 10 && k == 7){
                k = 0;
                print();
                puts("hogehoge");
                throw "";
            }
        }catch(int){}
        return;
    }
  
    if(oprem > 0){
        for(int op = -1; op >= -3; --op){
            c[i] = op;
            solve(i + 1, S, oprem - 1, numrem + 1);
        }
    }
  
    if(numrem > 0){
        for(int j = 0; j < 4; ++j){
            if(S >> j & 1){
                c[i] = a[j];
                solve(i + 1, S ^ 1 << j, oprem, numrem - 1);
            }
        }
    }
}
  
int main(){
    while(1){
        for(int i = 0; i < 8; ++i){
            c[i] = -9;
        }
        for(int i = 0; i < 4; ++i){
            scanf("%d", &a[i]);
        }
        if(a[0] == 0){ break; }
        try{
            solve(0, 15, 3, 0);
            puts("0");
        }catch(...){}
    }
}

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

const int N = 333, M = 333;
int a[N][M];
int deleted[M];
int cnt[M];
int pos[N];
int n, m;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    fill(pos + 1, pos + n + 1, 1);
    int ans = 1000;
    for(int s = 1; s <= m; s++) {
        fill(cnt + 1, cnt + m + 1, 0);
        int maxi = 0, maxis;
        for(int i = 1; i <= n; i++) {
            int sport = a[i][pos[i]];
            cnt[sport]++;
            if(cnt[sport] > maxi) {
                maxi = cnt[sport];
                maxis = sport;
            }
        }
        ans = min(ans, maxi);
        deleted[maxis] = true;
        for(int i = 1; i <= n; i++) {
            while(pos[i] <= m && deleted[a[i][pos[i]]]) {
                pos[i]++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    int four = 0, even = 0, other = 0;
    rep(i,n){
        int num; cin >> num;
        if(num%4==0) four++;
        else if(num%2==0) even++;
        else other++;
    }

    if(four>=n/2) cout << "Yes" << endl;
    else if (other<=four) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int n,m[10]={0};
	scanf("%d",&n);

	for(int x=0;x<n;x++)
	{
		scanf("%d %d %d %d %d %d %d %d %d %d",&m[0],&m[1],&m[2],&m[3],&m[4],&m[5],&m[6],&m[7],&m[8],&m[9]);
		int a=0,b=0,t=0;

		for(t;t<=9;t++)
		{
			if(a>=b)
			{
				if(a<m[t])
				{
					a=m[t];
				}
				else
				{
					if(b<m[t])
					{
						b=m[t];
					}
					else
					{
						t=99;
					}
				}
			}
			else if(a<b)
			{
				if(b<m[t])
				{
					b=m[t];
				}
				else
				{
					if(a<m[t])
					{
						a=m[t];
					}
					else
					{
						t=99;
					}
				}
			}
		}

		if(t==10)
		{
			printf("YES\n");
		}
		else if(t==100)
		{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1008
#include <cstdio>
#include <map>
const int mod=1e9+7;
using namespace std;
map<long long,int> ma;
int Cl(long long x){
	if(ma[x])
		return ma[x];
	if(x&1)
		return ma[x]=((long long)Cl(x/2ll)*2ll+Cl(x/2ll-1ll))%mod;
	return (Cl(x/2ll-1ll)*2ll+Cl(x/2ll))%mod;
}
int main(){
	long long n;
	scanf("%lld",&n);
	ma[0]=1;
	ma[1]=2;
	ma[2]=4;
	ma[3]=5;
	ma[4]=8;
	printf("%d",Cl(n));
	return 0;
}

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

int find_parent(int i, vector<int>& parent){
    if (i == parent[i]) return i;

    return parent[i] = find_parent(parent[i], parent);
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> adress(n);
    for (int i=0; i<n; i++){
        int p;
        cin >> p;
        adress[p-1] = i;
    }
    vector<int> parent(n);
    for (int i=0; i<n; i++) parent[i] = i;
    for (int i=0; i<m; i++){
        int x, y;
        cin >> x >> y;
        x = find_parent(x-1, parent); y = find_parent(y-1, parent);
        parent[max(x, y)] = parent[min(x, y)];
    }
    int ans=0;
    for (int i=0; i<n; i++){
        if (find_parent(i, parent) == find_parent(adress[i], parent)) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4024
#include<stack>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iostream>
#define INF 0x7fffffff//1<<31-1
#define IP 3.141592654
#define LINF 9223372036854775807//1<<63-1
#define rep(i,a,b) for(long long i=a;i<b;i++)
#define per(i,a,b) for(long long i=b-1;i>=a;i--)
using namespace std;
typedef long long LL;
const int maxn=2e5+10;
const int maxm=1e8+10;
int P[maxn];
int Q[maxn];
int main()
{
    int ans=0;
    int n;scanf("%d",&n);
    int a=0,b=0;
    rep(i,1,n+1)
    {
        int k;scanf("%d",&k);
        if(k==i){
            if(a==1){
                ans++;a=0;
            }
            else a=1;
        }
        else{
            if(a){
                ans++;a=0;
            }
        }
    }
    cout<<ans+a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define Rt 1000000000
int main(){
  int i,n,R,max=-Rt,min;
  scanf("%d",&n);
  scanf("%d",&min);
  for(i=1;i<n;i++){
    scanf("%d",&R);
    if(R-min>max)max=R-min;
    if(R<min)min=R;
  }
  printf("%d\n",max);
  return 0;
}

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


void solve(long long N, long long T, std::vector<long long> t){
  long long acc = 0;

  for(long long i = 0; i < N-1; i++) {
    acc += min(T, t[i+1] - t[i]);
  }

  cout << acc+T << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long T;
  scanf("%lld",&T);
  std::vector<long long> t(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&t[i]);
  }
    solve(N, T, std::move(t));
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=("; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vec p(N);
    REP(i, N) {
        cin >> p[i];
    }

    SORT(p);

    ll ans = 0;
    REP(i, N - 1) {
        ans += p[i];
    }

    ans += p[N - 1] / 2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,m=gets.split.map &:to_i
if n%2==0
	(0...m-m/2).each{|i|puts [i+1,n-i]*" "}
	(m-m/2...m).each{|i|puts [i+1,n-i-1]*" "}
else
	m.times{|i|puts [i+1,n-i]*" "}
end

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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x,k,d; cin >> x >> k >> d;
    x=abs(x);
    ll ans=0;
    // if(x/d>k){
    //     ans=x-d*k;
    // }else{
    //     ll e=x/d;
    //     k-=e;
    //     x-=e*d;
    //     if(k%2==1) x=abs(x-d);
    //     ans=x;
    // }

    if(x/d>k){
        ans=x-d*k;
    }else{
        ll m=x/d;
        ll r=k-m;
        x=x-m*d;
        if(r%2==1) x=abs(x-d);
        ans=x;
    }

    cout << ans ENDL;
    // rep(i,0,k){
    //     if(abs(x)<=d) break;
    //     if(x>0){
    //         x=x-d;
    //     }else{
    //         x=x+d;
    //     }
    //     //cout << "now:" << x ENDL;
    // }

    // if(abs(x)==d){
    //     cout << d ENDL;
    // }else if(x>0){
    //     ll temp=(ll)x/d;
    //     if(temp<=k){
    //         if(x%d==0){
    //             cout << 0 ENDL;
    //         }else{
    //             cout << x%d ENDL;
    //         }
    //         //cout << (x-(ll)(temp)*d) ENDL;
    //     }else{
    //         //cout << 
    //         cout << (x-(ll)d*k) ENDL;
    //     }
    // }else if(x<0){
    //     ll temp=(ll)x/d;
    //     if(temp<=k){
    //         if(x%d==0){
    //             cout << 0 ENDL;
    //         }else{
    //             cout << x%d ENDL;
    //         }
    //         //cout << 0-(x+(ll)(temp)*d) ENDL;
    //     }else{
    //         cout << 0-(x+(ll)(d*k)) ENDL;
    //     }
    // }else{
    //     cout << 0 ENDL;
    // }
    //cout << abs(x) ENDL;


    return 0;
}

Measured memory_bytes: 5992
#include<stdio.h>
#include<iostream> 
#include<utility>
#include<map> 
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
 int N; cin >> N;
 long int ans = 0;
 long int prev;
 for(int i=0;i<N;i++){
     long int A_i; cin >> A_i;
     if(i==0) prev = A_i;
     else{
         if(A_i < prev){
             ans+=(prev-A_i);
         }
         else{
             prev = A_i;
         }
     }
 }
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  int x,a;cin>>x>>a;
  cout<<((x<a)?0:10)<<endl;
  //caricurate
  //output
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
    ll n;
    cin >> n;
    const auto &res = prime_factorize(n);
    int ans = 0;
    for(auto a : res) {
        int i = 1;
        while(a.second >= i) {
            a.second -= i;
            ans++;
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
<?php

fscanf(STDIN, "%d", $n);
$b = explode(' ', trim(fgets(STDIN)));
$b2 = $b;

for ($i=0; $i<$n-1; $i++) {
    if ($i == 0) {
        continue;
    }
    if ($b[$i-1] > $b[$i]) {
        $b[$i-1] = $b[$i];
    }
}

$sum = 0;
foreach ($b as $v) {
    $sum += $v;
}

$ans = $sum + $b2[0];
echo $ans;


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;

int n,m,ar[maxn];
char ch[maxn];
int main()
{
    scanf("%d%d",&n,&m);
    scanf("%s",ch+1);
    memset(ar,0,sizeof(ar));
    for(int i=2;i<=n;i++){
        ar[i] = ar[i-1];
        if(ch[i]=='C' && ch[i-1]=='A'){
            ar[i]++;
        }
    }
    while(m--){
        int a,b;scanf("%d%d",&a,&b);
        printf("%d\n",ar[b]-ar[a]);
    }


    return 0;
}


Measured memory_bytes: 1280
a,b,c,d,e,f = map(int, input().strip().split(" "))
a = 100 * a
b = 100 * b
e = e * 100 / (100.0+e)

water = set([])
for i in range((f+a)//a):
    for j in range((f+b)//b):
        w = a * i + b * j
        if w <= f and 0 < w:
            water.add(a * i + b * j)


sugar = set([])
for i in range((f+c)//c):
    for j in range((f+d)//d):
        s = c * i + d * j
        if s <= f:
            sugar.add(c * i + d * j)
density = -1
_s = 0
sw = 0
for w in water:
    for s in sugar:
        _d = 100 * s / (s+w)
        if _d <= e and w + s <= f and density < _d:
            density = _d
            sw = w + s
            _s = s

print(sw, _s)


Measured memory_bytes: 3316
x,y,a,b,c=map(int, input().split())
p=list(map(int, input().split()))
q=list(map(int, input().split()))
r=list(map(int, input().split()))

rest=sorted(p,reverse=True)[:x]+sorted(q,reverse=True)[:y]+r
sorted_rest=sorted(rest,reverse=True)[:x+y]
print(sum(sorted_rest))

Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
typedef pair<int,int> ii;
const int maxn=1e5+5;
int arr[maxn];
ii qr[maxn];
int a[maxn];
int t[maxn];
int ans[maxn];
signed main() {
	//freopen("lon.inp","r",stdin);
	//freopen("lon.out","w",stdout);
	int n,q;
	cin>>n>>q;
	for(int i=1 ; i<=q ; i++) {
		cin>>qr[i].fi;
		qr[i].se=i;
	}
	qr[0]=ii(n,0);
	sort(qr,qr+1+q);
	int sz=0;
	int cur=-1;
	for(int i=0 ; i<=q ; i++) {
		if(qr[i].se>cur) {
			cur=qr[i].se;
			arr[++sz]=qr[i].fi;
			//cout<<"arr "<<sz<<" "<<qr[i].fi<<endl;
		}
	}
	t[sz]=1;
	//cout<<"sz = "<<sz<<endl;
	//cout<<"mark = "<<arr[1]<<endl;
	for(int i=sz ; i>1 ; i--) {
		int k=arr[i]%arr[i-1];
		//cout<<"k = "<<k<<endl;
        while(k>arr[1]) {
            int pos=upper_bound(arr+1,arr+sz+1,k)-arr-1;
            //cout<<"pos = "<<pos<<endl;
            t[pos]+=t[i]*(k/arr[pos]);
            k%=arr[pos];
            //cout<<"t[pos] = "<<t[pos]<<endl;
        }
		//cout<<"k = "<<k<<endl;
		//cout<<"a[k] += "<<t[i]<<endl;
		a[k]+=t[i];
		t[i-1]+=t[i]*(arr[i]/arr[i-1]);
		//cout<<"i = "<<i<<endl;
	}
	a[arr[1]]+=t[1];
	for(int i=arr[1] ; i>=1 ; i--) {
		a[i]+=a[i+1];
	}
	for(int i=1 ; i<=n ; i++) cout<<a[i]<<"\n";
}


Measured memory_bytes: 7508
#include <stdio.h>
#include <limits.h>
#define MAX_N 200000
typedef long long ll;
ll max(ll a, ll b) {
  if(a < b) return b;
  return a;
}
int main() {
  ll n, R[MAX_N], mn = LLONG_MAX/2, ans = -LLONG_MAX;  
  int i;
  scanf("%lld", &n);
  for(i = 0; i < n; i++) scanf("%lld", R+i);
  for(i = 0; i < n; i++) {
    ans = max(ans, R[i] - mn);    
    if(R[i] < mn) mn = R[i];
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 2160
// D - Five, Five Everywhere

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

// n以下の素数をエラトステネスの篩で求めてvectorで返す
vector<int> sieve(int n) {
	vector<int> prime;
	prime.reserve(n);

	vector<bool> is_prime(n+1, true);

	is_prime[0] = is_prime[1] = false;

	for (int i=2; i<=n; i++) {
		if (is_prime[i]) {
			prime.push_back(i);
			for (int j=2*i; j<=n; j+=i) {
				is_prime[j] = false;
			}
		}
	}

	return prime;
}


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

	vector<int> S = sieve(55555);
	vector<int> ans;

	for (int s : S) {
		if (s % 5 == 1) ans.push_back(s);
	}

	for (int i=0; i<N; i++) {
		if (i != 0) cout << " ";
		cout << ans[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(void)
{
    int h, a, i;

    scanf("%d%d",&h,&a);

    i=0;
    i = h / a;
    if(h % a <= 0)
      printf("%d\n",i);
    else if(h % a >= 0)
      printf("%d\n",i+1);

    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        char[] c = sc.next().toCharArray();
        int Q = sc.nextInt();
        for (int i=0;i<Q;i++) {
            int k = sc.nextInt();
            int m_cnt = 0;
            int c_cnt = 0;
            long ans = 0L;
            long tmp = 0L;
            for (int j=0;j<k;j++) {
                if (c[j]=='M') m_cnt++;
                if (c[j]=='C') {
                    c_cnt++;
                    tmp += m_cnt;
                }
            }
            for (int j=0;j<N;j++) {
                if (c[j]=='D') {
                    ans += tmp;
                }
                if (c[j]=='M') {
                    m_cnt--;
                    tmp -= c_cnt;
                }
                if (c[j]=='C') c_cnt--;
                if (j+k<N && c[j+k]=='M') m_cnt++;
                if (j+k<N && c[j+k]=='C') {
                    c_cnt++;
                    tmp += m_cnt;
                }
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 34948
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;



bool solve(){
	while(1){
		int n;
		cin>> n;
		if(!n) break;
		
		vector<int> a(n);
		int sum=0;
		for(int i=0;i<n;i++){
			cin>> a[i];
			sum += a[i];
		}

		sort(a.begin(), a.end());
//		int lsum,hsum;
//		lsum = hsum = 0;
		int sum2 = sum;
		vector<vector<int> > hoge(n+1, vector<int>(sum+1, 0));
		hoge[0][0] = 1;
		for(int i=0;i<n;i++){
			for(int j=0;j<=sum;j++){
				hoge[i+1][j] = hoge[i][j];
				if(j>=a[i] && hoge[i][j-a[i]]){
					hoge[i+1][j] = 1;
					if(abs(j-sum/2) < abs(sum2-sum/2)) sum2 = j;
					if(sum%2 &&  abs(j-sum/2+1) < abs(sum2-sum/2+1)) sum2 = j;
				}
//				cout<< hoge[i+1][j];
			}
//			cout<< "   "<< sum2;
//			cout<< endl;
			if(sum2 == sum/2) break;
		}
		int ans = abs(sum2 - (sum-sum2));
		cout<< ans<< endl;
	}
	return true;
}



int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}



int32_t main()
{
	FIO;
	//c_p_c();
	int n , k;
	cin >> n >> k;
	cout << min(n % k, k - (n % k)) << endl;



}

Measured memory_bytes: 256
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main(void)
{
	double distance, theta, N = 0, E = 0, sum=90;
	int i, j;
	char con;

	while (cin >> distance >> con >> theta)
	{
		if (distance == 0 && theta == 0) break;
		N += sin((sum * M_PI) / 180) * distance;
		E += cos((sum * M_PI) / 180) * distance;
		sum -= theta;
	}
	cout << (int)E << endl << (int)N << endl;
	return 0;
}


Measured memory_bytes: 3516
buf[20000];char*p=buf;
i,w;
main(){
	read(0,buf,10200);
	while(*p>32)p+=1;
	for(p+=1;*p>10;p+=1)w=w*10+*p-48;w+=1;
	for(;i<w;i+=1)putchar_unlocked('#');
	for(;*p>0;p+=1){
		if(*p==10)putchar_unlocked('#'),putchar_unlocked(10),putchar_unlocked('#');
		else putchar_unlocked(*p);
	}
	for(i=0;i<w;i+=1)putchar_unlocked('#');
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] h = new long[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextLong();
        }
        
        boolean ans = true;
        h[0]--;
        for (int i = 1; i < n; i++) {
            if (h[i - 1] > h[i]) {
                ans = false;
                break;
            }
            if (h[i - 1] < h[i]) {
                h[i]--;
            }
        }
        System.out.println(ans?"Yes":"No");
    }
}

Measured memory_bytes: 61796
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N;
    vector<int> P(60), R(60);
    cin >> N;
    for (int i=0;i<N;i++) cin >> P[i];
    iota(R.begin(), R.end(), 1);
    int X = 0;
    for (int i=0;i<N;i++) if (R[i] != P[i]) X++;
    if (X == 2 || X == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


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

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  std::vector<int> B(N);
  for(auto &a:A) std::cin >> a;
  int mcnt = 0;
  int zcnt = 0;
  long long sum = 0;
  int abs_min = 1000000000;
  for(int i=0;i<N;i++){
    if(A[i] < 0) mcnt++;
    if(A[i] == 0) zcnt++;
    B[i] = std::abs(A[i]);
    sum += B[i];
    if(B[i] < abs_min) abs_min = B[i];
  }
  if((mcnt&1) && zcnt==0) sum -= abs_min*2;  
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300;
int n, K, mod;
int f[maxn + 10][maxn + 10], s[maxn + 10][maxn + 10], c[maxn + 10][maxn + 10];
int main() {
	scanf("%d%d%d", &n, &K, &mod);
	c[0][0] = 1;
	for (int i = 0; i <= maxn; ++i) {
		c[i][0] = 1;
		for (int j = 1; j <= i; ++j)
			c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
	}
	for (int i = 0; i <= K; ++i) f[1][i] = 1;
	for (int i = K; i >= 0; --i) s[1][i] = (s[1][i + 1] + f[1][i]) % mod;
	for (int i = 2; i <= n + 1; ++i) {
		for (int j = 0; j <= K; ++j)
			for (int k = 1; k < i; ++k) {
				(f[i][j] += 1ll * f[i - k][j] * s[k][j + 1] % mod * c[i - 2][k - 1] % mod) %= mod;
			}
		for (int j = K; j >= 0; --j)
			s[i][j] = (s[i][j + 1] + f[i][j]) % mod;
	}
	printf("%d", f[n + 1][0]);
}


Measured memory_bytes: 1408
// F - XOR Matching
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int m, k;
	cin >> m >> k;

	if (m == 0) {
		cout << (k == 0 ? "0 0" : "-1") << endl;
	} else if (m == 1) {
		cout << (k == 0 ? "0 0 1 1" : "-1") << endl;
	} else if (k >= (1 << m)) {
		cout << -1 << endl;
	} else {
		for (int i = 0; i < (1 << m); i++) if (i != k) cout << i << ' ';
		cout << k << ' ';
		for (int i = (1 << m) - 1; i >= 0; i--) if (i != k) cout << i << ' ';
		cout << k << endl;
	}

	return 0;
}


Measured memory_bytes: 1792
package main

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

func main() {
	sc := NewScanner(os.Stdin)
	A := sc.NextInt()
	B := sc.NextInt()
	T := sc.NextInt()
	fmt.Println(T / A * B)
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func lcm(x, y int) int {
	x, y = max(x, y), min(x, y)
	if y == 0 {
		return x
	}
	return lcm(y, x%y)
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


Measured memory_bytes: 640