akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func Max(a, b int) int {
	if a >= b {
		return a
	} else {
		return b
	}
}

func main() {
	var A,B int
	fmt.Scan(&A, &B)
	
	add := A + B
	sub := A - B
	mul := A * B
	
	fmt.Println(Max(Max(add,sub),mul))
}

Measured memory_bytes: 512
from sys import stdin
N = int(stdin.readline().rstrip())
AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
ans = 0
for i in range(N-1, -1, -1):
  a, b = AB[i]
  ans += (b - (a + ans) % b) % b
print(ans)

Measured memory_bytes: 27380
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int n_max = 1e5 + 5;

int n;
int h[n_max];

int dp[n_max]; //足場iにいるときのコストの最小値

int rec(int i) {
  if(i==0) dp[i] = 0;
  else if(i==1) dp[i] = abs(h[i] - h[i-1]);
  else dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]));
  if(i<n-1) rec(i+1);
  return 0;
}

int main() {
  rep(i,n_max) dp[i] = INF;
  cin >> n;
  rep(i,n) cin >> h[i];
  rec(0);
  cout << dp[n-1] << endl;
}


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

int main() {
  vector<int> a(3);
  for(int i=0;i<3;i++){
    cin>>a.at(i);
  }int b=0;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(a.at(i)==a.at(j)){
        b++;
      }
    }
  }
  if(b==5){
   cout<<"Yes"<<endl; 
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
n = gets.chomp.to_i
s = gets.chomp

left_b = Array.new(n, 0)
right_w = Array.new(n, 0)

left_b[0] = 1 if s[0] == '#'
for i in 1..(n-1)
  if s[i] == '#'
  	left_b[i] = left_b[i-1] + 1
  else
    left_b[i] = left_b[i-1]
  end
end

right_w[n-1] = 1 if s[n-1] == '.'
for i in 1..(n-1)
  if s[n-1-i] == '.'
  	right_w[n-1-i] = right_w[n-i] + 1
  else
    right_w[n-1-i] = right_w[n-i]
  end
end

sum = Array.new(n+1, 0)
sum[0] = right_w[0]
sum[n] = left_b[n-1]
for i in 0..n-2
  sum[i+1] = left_b[i] + right_w[i+1]
end
puts sum.min


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

int main(){
   string s,t;
   cin >> s >> t;
   int ans;
   rep(i,3) if(s[i]==t[i])ans ++;
   cout << ans;
 }
   

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
	int n,k;
	cin>>n>>k;
	int arr[n];
	fr(i,0,n)
	cin>>arr[i];
	vector<bool> dp(k+1,false);
	fr(i,1,k+1)
	fr(j,0,n){
		if(i<arr[j])
			break;
		if(dp[i-arr[j]]==false)
			dp[i]=true;
	}
	cout<<(dp[k]?"First":"Second")<<endl;
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

Measured memory_bytes: 3588
pre = input().split()
X = int(pre[0])
N = int(pre[1])

if N == 0:
  print(X)
else:
  pre = input().split()
  p = [int(s) for s in pre]

  list = [0] * 102

  for i in range(len(p)):
    list[p[i]] = 1
  

  for i in range(55):
    if list[X-i] == 0:
      print(X-i)
      break
    if list[X+i] == 0:
      print(X+i)
      break
    
    
    
    
    
    
    
  







Measured memory_bytes: 9132
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, p;
  cin >> n >> p;
  bool odd = false;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    odd |= x & 1;
  }
  if (odd) cout << (long long) pow(2, n - 1) << endl;
  else {
    if (p == 0) cout << (long long) pow(2, n) << endl;
    else cout << 0 << endl;
  }
  return 0;	
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    string n;
    cin>>n;
    for(int i=0;i<3;i++){
        if(n[i]=='1') n[i]='9';
        else if(n[i]=='9') n[i]='1';
    }
    cout<<n<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;



int main(){
	int n;
	cin >> n;
	ll  x[87];
	x[0]= 2;
	x[1]= 1;

	for (int i = 2; i < 87; i++){
		x[i] = x[i - 2] + x[i - 1];
	}
	cout << x[n] << endl;



	return 0;
}

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
#define N 3010
#define INF 2147483647
inline int read() {
    int x=0;
    char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x;
}
int tot=1;
int fir[N],nex[N<<1],got[N<<1];
inline void AddEdge(int x,int y) { 
    nex[++tot]=fir[x],fir[x]=tot,got[tot]=y; 
}
char s[N];
int siz[N],dis[N],f[N],a[N];
inline void dfs(int x,int fa) {
    siz[x]=a[x],dis[x]=f[x]=0; int p=0;
    for (int i=fir[x];i;i=nex[i]) {
        if (got[i]==fa) continue;
        dfs(got[i],x),dis[got[i]]+=siz[got[i]];
        dis[x]+=dis[got[i]],siz[x]+=siz[got[i]];
        if (dis[p]<dis[got[i]]) p=got[i];
    }
    if (!p) return;
    if (dis[x]>=2*dis[p]) f[x]=dis[x]/2;
    else f[x]=dis[x]-dis[p]+min(f[p],(2*dis[p]-dis[x])/2);
}
int main() {
    int n=read(); scanf("%s",s+1);
    for (int i=1;i<=n;i++) a[i]=s[i]-'0';
    for (int i=1;i<=n-1;i++) {
        int x=read(),y=read();
        AddEdge(x,y),AddEdge(y,x);
    }
    int ans=INF;
    for (int i=1;i<=n;i++) {
        dfs(i,0);
        if (f[i]*2==dis[i]) ans=min(ans,f[i]);
    }
    printf("%d\n",ans==INF?-1:ans);
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f3f3f3f3f
#define pi 3.1415926535898
#define N 200050
using namespace std;
char a[200050];
int c[200050];
int main()
{
    int n,p;
    cin>>n>>p;
    cin>>(a+1);
    long long int  ans=0;
    if(p==2||p==5)
    {
        for(int i=1; i<=n; i++)
        {
            if((a[i]-'0')%p==0)
                ans+=i;
        }
        cout<<ans<<endl;
        return 0;
    }
    int   t=1;
    int sum=0;
    c[0]=1;
    for(int i=n; i>=1; i--)
    {
        sum=(sum+(a[i]-'0')*t)%p;
		
		ans+=c[sum];
		c[sum]++;

		t=t*10%p;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3852
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef int value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

void quicksort(value_type a[], int left, int right,value_type index[])
/* クイックソート
 * a     : ソートする配列 
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 * index: index配列
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = index[i]; index[i] = index[j]; index[j] = tmp;
            i++; j--;
        }
        quicksort(a, left, i - 1,index);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right,index); /* 分割した右を再帰的にソート */
    }
}


int dfs(int n,int N){
    if (n>N){
        return 0;
    }
    

    int ret;
    
    return ret;
}
int main(){
    double T,X;
    //string S;
    cin >>T>>X;
    

    double ans=(T/X);
    
    std::cout <<setprecision(16)<< ans<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int N,M;
bool isUsed[8];
bool g[8][8];

int dfs(int x, int nokori){
    if(nokori==0) return 1;
    int ret = 0;
    isUsed[x] = true;
    //次
    FOR(i, 0, N){
        if(g[x][i] && !isUsed[i]){
            //trueにしとく
            isUsed[i] = true;
            ret += dfs(i, nokori-1);
            //調べ終わったらfalseにしとく
            isUsed[i] = false;
        }
    }
    return ret;
}

int main(){
    cin>>N>>M;
    FOR(i, 0, 8) FOR(j, 0, 8) g[i][j] = false;
    FOR(i, 0, 8) isUsed[i] = false;
    FOR(i, 0, M){
        int a, b;
        cin>>a>>b;
        a--;b--;
        g[a][b] = g[b][a] = true;
    }
    cout << dfs(0, N-1) << endl;
}

Measured memory_bytes: 256
#include <functional>
#include <fstream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <deque>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>

typedef long long ll;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

ll h, w, n;
ll ans[11];
std::map<std::pair<int, int>, bool> cnt;
std::map<std::pair<int, int>, bool> vis;
std::vector<std::pair<int, int>> ed;

int check(int x, int y) {
    int fix = 0;
    for(int i=x; i<x+3; i++) {
        for(int j=y; j<y+3; j++) {
            fix += cnt[std::make_pair(i,j)];
        }
    }
    return fix;
}

bool in(int x, int y)
{
    return (x>0 && y>0 && x<=h && y<=w) && (x+2<=h && y+2<=w && x+2>0 && y+2>0);
}

void solve() {
    std::cin >> h >> w >> n;
    for(int i=0; i<n; i++) {
        std::pair<int, int> a;
        std::cin >> a.first >> a.second;
        ed.push_back(a);
        cnt[a] = 1;
    }
    for(int i=0; i<n; i++) {
        std::pair<int, int> a = ed[i];
        int x = a.first, y = a.second;
        //std::cout << "point " << i << " " << x << " " << y << std::endl;
        for(int cur=x; cur>x-3; cur--) {
            for(int nxt=y; nxt>y-3; nxt--) {
                if(vis[std::make_pair(cur,nxt)]) continue;
                if(!in(cur,nxt)) continue;
                //std::cout << "3x3: " << cur << " " << nxt << " count: " << check(cur,nxt) << std::endl;
                ans[check(cur,nxt)]++;
                vis[std::make_pair(cur,nxt)] = 1;
            }
        }
    }
    ll sum = 0;
    for(int i=1; i<10; i++) sum += ans[i];
    ans[0] = (h-2)*(w-2) - sum;
    for(int i=0; i<10; i++) std::cout << ans[i] << std::endl;
}

int main () {
    int t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 216536
"""
A = a1,a2,a3,a4,...
同じ色のとき、i<jならai<aj

が成り立つときの最小の色の数

2 1 4 5 3

8
5 
4 
3 
2 
1 
3 
2 
1

5
4
3
2 3
1 2
1



"""

from bisect import bisect_right

prev = 10**9+7
cnt = 0
As = [-prev]
n = int(input())
for _ in range(n):
    a = int(input())
    update = bisect_right(As,-a)
    if update-1 == cnt:
        As.append(-a)
        cnt += 1
    else:
        As[update] = -a 
    prev = a

print(cnt)



Measured memory_bytes: 51108
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b,sum,zz=1;
    scanf("%d%d%d",&k,&a,&b);
    sum=k;
    if(sum>=a&&sum<=b)
    {
        cout<<"OK"<<endl;
        return 0;
    }
    while(sum<=b)
    {
        zz++;
        sum=zz*k;
        //cout<<sum<<endl;
        if(sum>=a&&sum<=b)
        {
            cout<<"OK"<<endl;
            return 0;
        }

    }
    cout<<"NG"<<endl;
}


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

int main(){
    long long int N;
    cin >> N;
    
    vector<long long int> A(N);
    
    map<long long int, long long int> cnt;

    rep(i,N){
        cin >> A.at(i);

    }

    for(int x : A){
        if(cnt.count(x)){
            cnt.at(x)++;
        } else {
            cnt[x] = 1;
        }
    }

    long long int sum = 0;
    for(auto p : cnt){
        auto v = p.second;
        if(v>=2){
            sum += v*(v-1)/2;
        }

    }

    rep(i,N){
        long long int tmp = cnt.at(A.at(i));
        long long int ans = sum;
        if(tmp>=2){
            ans = sum - tmp*(tmp-1)/2 + (tmp-1)*(tmp-2)/2;
        }
        
        cout << ans;
        cout << endl;
    }


}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    string s;
    cin >> s;
    vector<int> a(4);
    repeat(i, 4) {
        a[i] = s[i] - '0';
    }
    repeat(i, 8) {
        int t = a[0];
        bitset<3> bs(i);
        t = (bs[0] ? t + a[1] : t - a[1]);
        t = (bs[1] ? t + a[2] : t - a[2]);
        t = (bs[2] ? t + a[3] : t - a[3]);
        if (t == 7) {
            repeat(i, 3) {
                cout << a[i] << (bs[i] ? '+' : '-');
            }
            cout << a[3] << "=7";
            return 0;
        }
    }
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=true;
    long double ans=0,sum=0;

    int n,m;
    cin>>n>>m;

    vector<int> a(n,0);
    rep(i,n){
        cin>>a[i];
        sum += a[i];
    }
    sort(all(a),greater<int>());

    rep(i,m){
        if(a[i] < sum/(4.0*m))flag=false;
    }
    //cout <<fixed<<setprecision(16)<< << endl;

    if(flag)cout << "Yes" <<endl;
    else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}
bool f(pll a , pll b){
	return a.y < b.y ;
}

//check modulo
int main(){
	IOS;
	cout.precision(30) ;
    int h ,w ;  cin >> h >> w ;
    vector<string> a(h);for(int i = 0 ; i < h ; i++) cin >> a[i] ;
    vector<vi> lfou9(h , vi(w , -1)) ;
    vector<vi> imin(h , vi(w , -1)) ;
    vector<vi> isar(h , vi(w , -1)) ;
    vector<vi> louta(h , vi(w , -1)) ;
    for(int i = 0 ; i < h ; i++){
		for(int j = 0 ; j < w ; j++){
			if(i == 0) lfou9[i][j] = -1 ;
			if(j == 0) isar[i][j] = -1 ;
			if(a[i][j] == '#'){
				lfou9[i][j] = i ;
				isar[i][j] = j ;
				continue ;
			}
			if(i) lfou9[i][j] = lfou9[i - 1][j] ;
			if(j) isar[i][j] = isar[i][j - 1] ;
		}
	}
	for(int i = h - 1 ; i >= 0 ; i--){
		for(int j = w - 1 ;  j >= 0 ; j--){
			if(a[i][j] == '#'){
				louta[i][j] = i ;
				imin[i][j] = j ;
				continue ;
			}
			if(i == h - 1) louta[i][j] = h ;
			else louta[i][j] = louta[i + 1][j] ;
			if(j == w - 1) imin[i][j] = w ;
			else imin[i][j] = imin[i][j + 1] ;
		}
	}
	vector<vi> ans(h , vi(w , 0)) ;
	for(int i = 0 ; i < h ; i++){
		for(int j = 0 ; j < w ; j++){
			if(a[i][j] !='#'){
				ans[i][j] = (i - lfou9[i][j]) + (louta[i][j] - i) + (imin[i][j] - j) + (j - isar[i][j]) ;
			}
		}
	} 	
	ll aans = 0 ;
	for(int i = 0 ; i < h ; i++){
		for(int j = 0 ; j < w ; j++){
			aans = max(aans , (ll)ans[i][j] - 3) ;
		}
		
	}
	cout << aans << endl ;
	return 0;
}


Measured memory_bytes: 83072
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>

int main()
{
	int H, A;
	std::cin >> H >> A;
	
	int count = (H % A) ? H / A + 1 : H / A;

	std::cout << count;

	return 0;
}

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

int main() {
  int N, n, x = 0;
  cin >> N;
  n = N;
  
  for (int i = 0; i < 8; i++) {
    x += n % 10;
    n /= 10;
  }
  
  if (N % x == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long W = sc.nextLong();
        long H = sc.nextLong();
        long x = sc.nextLong();
        long y = sc.nextLong();

        double area = W * H / 2.0;
        int multiple = (x*2==W && y*2==H) ? 1 : 0;

        System.out.printf("%f %d\n", area, multiple);

    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int h,w,n;
int a[10010],mp[110][110];

int main()
{
    scanf("%d%d",&h,&w);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    int k=1;
    for(int i=1;i<=h;i++)
    {
        int j;
        if(i%2==1) j=1;
        else j=w;
        while(j>=1&&j<=w)
        {
            while(a[k]<=0) k++;
            if(a[k]>0)
            {
                mp[i][j]=k;
                a[k]--;
                if(i%2==1) j++;
                else j--;
            }
        }
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            printf("%d ",mp[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1137&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
map<char,int> mp;
map<int,char> mpmp;
int mcxi2int(const string& s){
    int ret = 0;
    string MCXI = "1" + s;
    for(int i = 0; i < MCXI.length();i++){
        if(isdigit(MCXI[i])) continue;
        ret += mp[MCXI[i]]*(isdigit(MCXI[i-1])?(MCXI[i-1]-'0'):1);
    }
    return ret;
}
string int2mcxi(int val){
    string ret;
    string vals = to_string(val);
    reverse(vals.begin(),vals.end());
    for(int i = 0; i < vals.length();i++){
        int V = pow(10,i);
        if(vals[i] == '0') continue;
        string T;
        if(vals[i] != '1') T += vals[i];
        T += mpmp[V];
        ret = T + ret;
    }
    return ret;
}
string solve(){
    string res;
    string a,b; cin >> a >> b;
    int vala = mcxi2int(a),valb = mcxi2int(b);
    int val = vala + valb;
    res = int2mcxi(val);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    mp['m'] = 1000; mp['c'] = 100; mp['x'] = 10; mp['i'] = 1;
    mpmp[1000] = 'm'; mpmp[100] = 'c'; mpmp[10] = 'x'; mpmp[1] = 'i';
    int n; cin >> n;
    while(n--){
        cout << solve() << endl;
    }
    return 0;
}



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

int main()
{
    ll n,vf[NMAX];
    cin>>n;
    memset(vf,0,sizeof(ll)*(n+5));
    ll x;
    for(int i=1; i<n; i++)
    {
        cin>>x;
        vf[x]++;
    }
    for(int i=1; i<=n; i++)
        cout<<vf[i]<<'\n';
    return 0;
}


Measured memory_bytes: 5184
fun main() {
	val n = readLine()!!.toInt()
	val s = readLine()!!
	var (c,l,r) = listOf(-1,-1,n)
	do {
		++c
		l = s.indexOf('W',l+1)
		r = s.lastIndexOf('R',r-1)
	} while(l!=-1&&r!=-1&&l<r)
	println(c)
}


Measured memory_bytes: 44328
while True:
    line = input().split()
    a,b,c= line[0],line[1],line[2]
    if b=="?":
        break
    elif b =="*":
        print(int(a)*int(c))
    elif b == "+":
        print(int(a)+int(c))
    elif b == "-":
        print(int(a)-int(c))
    elif b == "/":
        print(int(int(a)/int(c)))


Measured memory_bytes: 5600
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

vector<int> cut(vector<int> yama, int p, int c)
{
	int n = yama.size();
	vector<int> tmp;

	rep(i,c){
		int index = n-p;
		tmp.push_back(yama[index-i]);
	}

	reverse(ALL(tmp));

	rep(i,c){
		int index = n-p-i;	
		yama.erase(yama.begin()+index);
	}

	yama.insert(yama.end(),ALL(tmp));

	return yama;
}

int main() {
	int N,R;

	while(cin >> N >> R && N && R)
	{
		vector<int> yama;
		REP(i,1,N+1){ yama.push_back(i); }

		int P,C;
		rep(i,R)
		{
			cin >> P >> C;
			yama = cut(yama, P, C);
		}
		cout << yama[yama.size()-1] << endl;
	}
	return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int max = -1;
    bool left,right;
    int count;
    for(int i = 1; i < s.size(); ++i){
        count = 0;

        for(char c = 'a'; c <= 'z'; ++c){
            left = false;
            right = false;

            for(int j = 0; j < i; ++j) if(s[j] == c) left = true;

            for(int j = i; j < s.size(); ++j) if(s[j] == c) right = true;

            if(left && right) count++;
        }

        if(max < count) max = count;
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  vl a(3);
  cin>>a;
  rep(ti,MX) {
    rep(i,3) if (a[i]&1) {
      printf("%d\n",ti);
      return 0;
    }
    ll sum = 0;
    rep(i,3) sum += a[i];
    sum /= 2;
    rep(i,3) {
      a[i] = sum-a[i]/2;
    }
  }
  cout<<-1<<endl;
  return 0;
}






















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

using namespace std;

int main() {
	int n;
	cin >> n;
	int m[101];
	int M[101][101];
	for (int i = 1; i <= n; i++) {
		cin >> m[i-1] >> m[i];
	}
	for (int i = 1; i <= n; i++) {
		M[i][i] = 0;
	}
	for (int l = 2; l <= n; l++) {
		for (int i= 1; i <= n - l + 1; i++) {
			int j = i+l - 1;
			M[i][j] = 100000000000000000;
			for (int k = i; k < j; k++) {
				M[i][j] = min(M[i][j], M[i][k] + M[k + 1][j] + m[i - 1] * m[k] * m[j]);
			}
		}
	}
	cout << M[1][n] << endl;
	return 0;
}


Measured memory_bytes: 3128
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define pa pair<int,int>
using namespace std;


int main(){
int n,w;
int va[110],we[110];
cin>>n>>w;
for(int i=0;i<n;i++) cin>>va[i]>>we[i];
int dp[10010]={0};
for(int i=0;i<n;i++){
for(int j=0;j<=w;j++){
if(j-we[i]>=0) dp[j]=max(dp[j-we[i]]+va[i],dp[j]);
}
}


cout<<dp[w]<<endl;
return 0;
}

Measured memory_bytes: 1208
n=int(input())
s_1=str(input())
s_2=str(input())
i=0
if s_1[0]==s_2[0]:
    ans=3
    c=1
    i+=1
else:
    ans=6
    c=2
    i+=2
while i<n:
    if s_1[i]==s_2[i]:
        if c==1:
            ans=ans*2%(1000000007)
        c=1
        i+=1
    else:
        if c==2:
            ans=ans*3%(1000000007)
        else:
            ans=ans*2%(1000000007)
        c=2
        i+=2
print(ans%(1000000007))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,x,ans;
int main()
{
	scanf("%d",&n);
	scanf("%d",&x);
	ans=x;
	for(int i=1;i<n;i++)
	{
		scanf("%d",&x);
		ans=__gcd(ans,x);
	}
	printf("%d\n",ans);
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    
    ll max_number = 1e5;
    vector<bool> era(max_number+1, true);
    era.at(0) = false;  era.at(1) = false;
    for(i = 2;i <= max_number;++i){
        if(era.at(i)){
            for(j = 2*i;j <= max_number;j += i){
                era.at(j) = false;
            }
        }
    }
    vector<ll> like(1e5+1,0);
    for(i = 1;i < like.size();i += 2){
        if(era.at(i) && era.at((i+1)/2)) ++like.at(i);
    }
    for(i = 1;i < like.size();++i){
        like.at(i) += like.at(i-1);
    }
    ll q;
    cin >> q;
    for(i = 0;i < q;++i){
        ll l,r;
        cin >> l >> r;
        cout << like.at(r) - like.at(l-1) << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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やllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N,M;
  cin >> N >> M;
  vector<set<int>> se(M);
  vector<int> p(M);
  for(int i=0; i<M; i++){
    int num;
    cin >> num;
    for(int j=0; j<num; j++){
      int a;
      cin >> a;
      a--;
      se[i].insert(a);
    }
  }
  for(int i=0; i<M; i++){
    cin >> p[i];
  }
  int ans = 0;
  for(int bit=0; bit<(1<<N); bit++){
    vector<int> cnt(M,0);
    for(int i=0; i<M; i++){
      for(int j=0; j<N; j++){
        if(se[i].count(j) && bit & 1<<j){
          cnt[i]++;
        }
      }
    }
    bool can = true;
    for(int i=0; i<M; i++){
      if(cnt[i]%2 != p[i]) can = false;
    }
    if(can) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<long> A(N);
  rep (i, N) cin >> A[i];
  vector<long> B = A;
  sort(B.begin(), B.end());
  rep (i, N) {
    auto it = B.end();
    it--;
    if (*it == A[i]) it--;
    cout << *it << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";

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

char ch[] = { 'N','S','E','W' };



template <class T> inline T biton(T n, T pos)
{
	return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
	return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
	return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
	while (b)
	{
		a = a % b;
		swap(a, b);
	}
	return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
	T ret = 1;
	for (; e > 0; e >>= 1)
	{
		if (e & 1)
			ret = (ret * p) % m;
		p = (p * p) % m;
	}
	return (T)ret;
};


#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif

void solve()
{
	string str, str2;
	cin >> str >> str2;
	str2.pop_back();
	if (str == str2) {
		cout << "Yes" << nl
	}
	else {
		cout << "No" << nl;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);
	cout.tie(nullptr);
	cin.tie(nullptr);

	int t = 1;

	while (t--)
	{
		solve();
	}

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int64_t> H(N);
    for(int i=0; i<N; i++) {
        cin >> H[i];
    }

    sort(H.begin(), H.end());
    
    cout << accumulate(H.begin(), H.end()-min(K, N), 0LL) << endl;
    return 0;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end())

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using vstr = std::vector<std::string>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int n, k, q;
    cin >> n >> k >> q;
    vint a(q);
    rep(i, q)cin >> a[i], --a[i];

    vint p(n, 0);
    rep(i, q) {
        ++p[a[i]];
    }

    rep(i, n) {
        int point = k - (q - p[i]);
        if (point > 0)Yes;
        else No;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



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

const ll MX = 1e18;

int main(){
  int n;
  cin >> n;
  ll ans =1;
  bool ng = false;
  
  rep(i, n){
    ll a;
    cin >> a;
    if(a == 0){
     cout << 0 << endl;
      return 0;
    }
  
   if(ng || MX/ans < a){
     ng = true;
   }
    ans *= a;
  }
  if(ng) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


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

int main(){
     string s;
cin >> s;
set<char>l;
for(int i=0;i<s.size();i++)
{
l.insert(s[i]);
}
if(l.size()!=3)puts("No");else puts("Yes");
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstring>

using namespace std;

queue<pair<int, int>> q;
int H, W;
int grid[1005][1005], shortestPath[1005][1005];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

bool inside(int row, int col){
  if (row < 0 || row >= H || col < 0 || col >= W) return false;
  return true;
}

int bfs(){
  int ans = 0;
  while(!q.empty()){
    pair<int, int> now = q.front();
    q.pop();

    int row = now.first;
    int col = now.second;

    ans = max(ans, shortestPath[row][col]);

    for(int i=0; i<4; i++){
      int nextRow = row + dx[i];
      int nextCol = col + dy[i];

      if(inside(nextRow, nextCol) && grid[nextRow][nextCol] != 1 && shortestPath[nextRow][nextCol] == -1){
        shortestPath[nextRow][nextCol] = 1 + shortestPath[row][col];
        q.push(make_pair(nextRow, nextCol));
      }
    }

  }
  return ans;
}

int main(){
  memset(shortestPath, -1, sizeof(shortestPath));
  cin >> H >> W;

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      char c;
      cin >> c;
      if(c == '#'){
        grid[i][j] = 1;
        q.push(make_pair(i, j));
        shortestPath[i][j] = 0;
      }
    }
  }

  cout << bfs() << endl;

}

Measured memory_bytes: 19096
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef pair<string, int> psi;

signed main(){
    int n;
    while(cin >> n, n){
        vector<int> d(n);
        int sum = 0;
        rep(i, 0, n){
            cin >> d[i];
            sum += d[i];
        }
        int ans = 1e9;
        for(int i = 0; i < 1<<n; i++){
            int tmp = 0;
            rep(j, 0, n){
                if(i & 1<<j) tmp += d[j];
            }
            ans = min(ans, abs(sum - 2*tmp));
        }
        cout << ans << endl;
    }
}

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

int main() {
  int x,n;
  cin >> x >> n;
  vector<int> p(n);
  vector<int> a(100);
  if(n==100){
    if(x>50){
    cout << 101 << endl;
    return 0;
  }
    else{ 
    cout << 0 << endl;
    return 0;
  }
  }
  for(int i=0;i<100;i++){
    a.at(i)=i+1;
  }
  for(int i=0;i<n;i++){
    cin >> p.at(i);
    a.erase(remove(a.begin(), a.end(), p.at(i)), a.end());
  }
  vector<int> b(100-n);
  for(int i=0;i<100-n;i++){
    b.at(i)=abs(x-a.at(i));
  }
  sort(b.begin(),b.end());
  int q=x+b.at(0);
  if(q>101){
    cout << 101 << endl;
    return 0;
  }
  int w=x-b.at(0);
  if(w<1){
    cout << 0 << endl;
    return 0;
  }
  for(int i=0;i<100-n;i++){
    if(w==a.at(i)){
      cout << w << endl;
      return 0;
    }
  }
  cout << q << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    string s;
    cin>>s;
    int i=0,j=s.size()-1;
    while(true){
        if(s[i]=='A'){
            break;
        }
        i++;
    }
    while(true){
        if(s[j]=='Z'){
            break;
        }
        j--;
    }
    cout<<j-i+1<<endl;

    
    
    return 0;
}


Measured memory_bytes: 640
import sys
def main():
  k, t = map(int, input().split())
  a = list(map(int, input().split()))
  if t == 1:
    print(a[0]-1)
    sys.exit()
  a.sort(reverse = True)
  key = [0, 1]
  num = 0
  while True:
    k = num%2
    a[key[k]]-=1
    sub = 0
    if a[key[k]] == 0:
      key[k] = max(key) + 1
      if key[k] < t:
        if a[key[0]] >= a[key[1]]:k=0
        else:k = 1
        num = k-1
      else:
        sub = 1
        break
    num += 1
  print(sum(a)-sub)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 9096
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
// using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define bug2(v1,v2)               cerr<<#v1<<" = "<<(v1)<< ' ' << #v2<<" = "<<(v2)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const double pi = 3.14159265359;
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
//const ll mod = 998244353;
const ll mod = 1000000007;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return (((a+mod)%mod)*(b+mod)%mod)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline ll modInverse(ll n, ll p){ return power(n, p-2)%p; }

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 
void stArt()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}
void eNd()
{
	#ifndef ONLINE_JUDGE
  	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  	#endif
}

//////////////////// start /////////////////////////////////
 

ll i,j,k,l,m,r,n;
ll a[MAX],b[MAX];


int main()
{
 
stArt();
fast
//cout << setprecision(15) << fixed;

ll N,X,T;
cin >> N >> X >> T;
k = ceil(N/(ld)X);
cout << T*k;

  
 eNd();
  return 0;
 
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(){
    int N, keys[100], ans = 0;
    for(int i = 0; i < 100; i++){
        keys[i] = 0;
    }

    scanf("%d", &N);

    int d[N];
    for(int i = 0; i < N; i++){
        scanf("%d", &d[i]);
    }

    for(int i = 0; i < N; i++){
        keys[d[i] - 1]++;
    }

    for(int i = 0; i < 100; i++){
        if(keys[i] != 0){
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	char c;
	cin >> c;

	if (isupper(c)){
       cout << "A" << endl;
	}
	else{
       cout << "a" << endl;
	}

	return 0;
}

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

using namespace std;

int main() {
	cin.sync_with_stdio(false);

	int A, B;
	char op;
	cin >> A >> op >> B;
	if (op == '+') {
		cout << A + B << endl;
	}
	else {
		cout << A - B << endl;
	}
	return 0;
}

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

int solve(vector<int>& v, int k) {
  int n = v.size();
  vector<int> dp(n, INT_MAX);
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= k; ++j) {
      if (i - j >= 0) {
        dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j]));
      }
    }
  }
  return dp[n - 1];
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for(auto& e: v) {
    cin >> e;
  }
  cout << solve(v, k) << '\n';
  return 0;
}



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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);


    ll n;
    cin >> n;
    vector<ll> a(n+1);
    for(auto &e: a) cin >> e;

    vector<ll> d(n+1);
    {
        ll s = 1;
        for(ll i=0; i<=n; i++) {
            d[i] = s;
            s -= a[i];
            if(s < 0) {
                cout << -1 << endl;
                return 0;
            }
            if(s<1e15)
                s *= 2;
        }
    }

    ll r = 0, s = 0;
    for(ll i=0; i<=n; i++) {
        s += a[n-i];
        s = min(s, d[n-i]);
        r += s;
    }
    cout << r << endl;
}


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

int n;
int cnt[2][100005];

signed main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    cnt[i%2][a]++;
  }
  
  typedef pair<int,int> P;
  
  vector<P> A, B;
  
  for(int i=0;i<100005;i++){
    A.push_back(P(cnt[0][i], i));
    B.push_back(P(cnt[1][i], i));
  }
  
  sort( A.begin(), A.end(), greater<P>() );
  sort( B.begin(), B.end(), greater<P>() );
    
  int even = (n-1)/2+1, odd = n-even;
  int ans = 1e9;
  
  for(int i=0;i<min(2LL,(int)A.size());i++){
    
    for(int j=0;j<min(2LL,(int)B.size());j++){
      
      if( A[i].second == B[j].second ) continue;
      
      ans = min( ans, even-A[i].first + odd-B[j].first );
      
    }
      
  }

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


Measured memory_bytes: 5100