akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

bool test() {
	
	ll n; cin >> n;
	vl d(n);
	FOR(i,0,n) cin >> d[i];
	sort(all(d));
	vl cnt(n);
	FOR(i,0,n) cnt[d[i]]++;
	
	ll len = d[n-1];
	if (len & 1) {
		if (cnt[(len+1)/2] != 2) return false;
		FOR(i,(len+1)/2,len+1) if (cnt[i] < 2) return false;
		FOR(i,0,(len+1)/2) if (cnt[i]) return false;	
	} else {
		if (cnt[len/2] != 1) return false;
		FOR(i,len/2+1,len+1) if (cnt[i] < 2) return false;
		FOR(i,0,len/2) if (cnt[i]) return false;
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << (test() ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
#include <iostream>


using namespace std;
int main(){

    int a,b,c;
    cin>>a>>b>>c;
    if(b>=8)
{
    int r=b/a;
    if(r<=c)
     cout<<r;
     else {
        cout<<c;
     }
}
else {
    cout<<0;
}


    return 0;
}

Measured memory_bytes: 256
C = []
for i in range(3):
    C.append([int(c) for c in input().split()])

ans = "Yes"
for i in range(3):
    temp = C[i][0]-C[(i+1)%3][0]
    for j in range(3):
        if C[i][j]-C[(i+1)%3][j] != temp:
            ans = "No"
for j in range(3):
    temp = C[0][j]-C[0][(j+1)%3]
    for i in range(3):
        if C[i][j]-C[i][(j+1)%3] != temp:
            ans = "No"
            
print(ans)

Measured memory_bytes: 3064
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
#include <assert.h>
#include <complex.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define FILL(A,val) memset(A,val,sizeof(A))

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double Pi = acos(-1.0);
const int INF = 1000000000;
const Int INF2 = Int(INF) * 5000;
const Int INF3 = Int(INF) * INF;
const int MAX = 777;
const int MAXE = 2007000;
const int MAXV = 5000;
const int BASE = 1000000000;
const int ST = 1000000007;

const int MOD = 1000000007;

bool A[MAX][MAX];

VI G[MAX];


int dp[MAX][MAX];

int C[MAX];

bool ok = true;

int cnt[2];

void dfs(int v, int c)
{
    C[v] = c;
    cnt[c] ++ ;
    
    FOR(i,0,SZ(G[v]))
    {
        int to = G[v][i];
        if (C[to] == c)
        {
            ok = 0;
            return;
        }
        
        if (C[to] == -1)
        {
            dfs(to, c ^ 1);
        }
        
    }
    
    
}

int main()
{
    //freopen("in.txt", "r", stdin);
    
    int n , m;
    cin >> n >> m;
    FOR(i,0,m)
    {
        int a , b;
        cin >> a >> b;
        --a;--b;
        A[a][b] = A[b][a] = 1;
    }
    
    FOR(i,0,n)
        FOR(j,i + 1 , n)
            if (A[i][j] == 0)
            {
                G[i].push_back(j);
                G[j].push_back(i);
            }
    FILL(C, -1);
    dp[0][0] = 1;
    int cur = 0;
    
    FOR(i,0,n)
    {
        if (C[i] == -1)
        {
            FILL(cnt , 0);
            
            dfs(i, 0);
            
            FOR(j,0,n + 1)
            {
                if (dp[cur][j])
                {
                    FOR(t,0,2)
                    {
                        dp[cur + 1][j + cnt[t]] = 1;
                    }
                }
            }
            
            ++ cur;
        }
    }
    
    if (!ok)
    {
        cout << -1 << endl;
        return 0;
    }
    
    int res = INF;
    
    FOR(i,0,n + 1)
    {
        if (dp[cur][i])
        {
            res = min(res , i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
        }
            
        
    }
    
    cout << res << endl;
    
    
    
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define endl "\n"
#define ll long long
#define pb emplace_back
#define fi first
#define se second
#define pll pair<ll, ll>
#define ull unsigned long long
#define ld long double

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=n-1; i>=0; i--)
#define repa(i,a,b) for(ll i=(a);i<=(b);i++)
#define all(x) (x).begin(), (x).end()
#define ordered_set tree<int , null_type, less<int> , rb_tree_tag, tree_order_statistics_node_update>
/*
 Ordered set docs:
 order_of_key (k) : Number of items strictly smaller than k .
 find_by_order(k) : K-th element in a set (counting from zero).
*/
#define blc boost::lexical_cast<long long>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
const int MOD = 1e9+7;
const ll INF = 1e18;
ll add(ll x, ll y) {ll res=x+y; return(res>=MOD?res-MOD:res);}

ll sub(ll x, ll y) {ll res=x-y; return(res<0?res+MOD:res);}

ll lcm(ll x, ll y) {ll res=(x*y)/__gcd(x,y); return res;}

ll powerLL(ll x, ll n, ll mod) 
{ 
    ll result = 1; 
    while (n) { if (n & 1) result = (result%mod * x%mod) % mod; n = n / 2; x = (x%mod * x%mod) % mod; } return result; 
} 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve()
{
    ll n, w;
    cin>>n>>w;
    vector<ll> wei(n);
    vector<ll> val(n);
    ll s = 0;
    rep(i,n)
    {
    	cin>>wei[i]>>val[i];
    	s+=val[i];
    }
    ll dp[n+5][s+5];
    rep(i,s+5)
    	dp[0][i] = INF;
    dp[0][0] = 0;
    ll maxi = 0;
    for(ll i=1; i<=n; i++)
    {
    	for(ll j=0; j<=s; j++)
    	{
    		if(val[i-1]<=j)
    			dp[i][j] = min(dp[i-1][j], dp[i-1][j-val[i-1]]+wei[i-1]);
    		else
    			dp[i][j] = dp[i-1][j];
    		if(dp[i][j]<=w)
    			maxi = max(maxi, j);	
    	}
    }
    cout<<maxi<<endl;
}
int32_t main()
{
    fast;
    int t;
    t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0; 
}
/*
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/

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

namespace ABC127D34
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int N = int.Parse(str[0]);//カードの枚数
            long M = long.Parse(str[1]);//操作の回数
            long[] A = new long[N];
            string[] str2 = Console.ReadLine().Split();
            for (int i = 0; i < N; i++)
            {
                A[i] = long.Parse(str2[i]);//カードの値
            }
            //Console.WriteLine(N+" "+M);
            //Array.Sort(A, (x, y) => x.CompareTo(y));
            //Array.Sort(A);

            long[][] B = new long[M][];
            for (int i = 0; i < M; i++)
            {
                string[] str3 = Console.ReadLine().Split();
                B[i] = new long[2];
                B[i][0] = long.Parse(str3[0]);//B枚
                B[i][1] = long.Parse(str3[1]);//置き換える値
            }
            Array.Sort(B, (x, y) => y[1].CompareTo(x[1]));//置き換える値の大きい順にソート
            var list = new List<long> ();
            int ct = 0;
            for (int i = 0; i < M; i++)
            {
                for (long j = 0; j < B[i][0]; j++)
                {
                    list.Add(B[i][1]);
                    ct++;
                    if (ct > N)
                    {
                        break;
                    }
                }
            }
            for (int i = 0; i < N; i++)
            {
                list.Add(A[i]);
            }
            list.Sort();
            long ans = 0;
            for (int i = list.Count-1; i >=list.Count-N ; i--)
            {
                ans += list[i];
            }

            /*
            for (int i = 0; i < Math.Min(N,list.Count); i++)
            {
                ans += Math.Max(A[i], list[i]);
            }
            for (long i = Math.Min(N,list.Count); i < N; i++)
            {
                ans += A[i];
            }
            */

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 37448
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;


#define MAX 500000
#define SENTINEL 2000000000
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int A[300];


int main(){
  int n; cin >> n;
  for (int i=0; i<n; i++){
    cin >> A[i];
  }
  bool parameter = true;
  int cnt=0;
  while(parameter){
    for (int i=0; i<n; i++){
      if (A[i] % 2 == 0 ){
        A[i] /= 2;
      } else {
        parameter = false;
      }
      
    }
    if (parameter == false) break;
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 100005
using namespace std;
 
struct Node { int p; int id;} x[MAX], y[MAX];
struct Edge { int id1; int id2; int d; } e[MAX*2];
bool cmpp(const Node &a, const Node &b){return a.p < b.p;}
bool cmpd(const Edge &a, const Edge &b){return a.d < b.d;}
int p[MAX];
int find(int x){return (x == p[x] ? x : p[x] = find(p[x]));}

int main(){
  int n, i, j;
  long long ans = 0;
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    p[i] = i;
    scanf("%d%d", &x[i].p, &y[i].p);
    x[i].id = y[i].id = i;
  }
  sort(x, x+n, cmpp);
  sort(y, y+n, cmpp);
  
  j = 0;
  for(i = 1; i < n; i++){
    e[j++] = {x[i].id, x[i-1].id, x[i].p - x[i-1].p};
    e[j++] = {y[i].id, y[i-1].id, y[i].p - y[i-1].p};
  }
  sort(e, e+2*n, cmpd);
  
  for(i = 0; i < 2*n; i++){
    if(find(e[i].id1) == find(e[i].id2)) continue;
    ans += e[i].d;
    p[p[e[i].id1]] = p[e[i].id2];
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 4608
import sys
sys.setrecursionlimit(1000000)
MOD = 10**9 + 7

def main():
    l = input()
    dp1 = 0
    dp2 = 1
    for i in range(len(l)):
        dp1 = 3 * dp1
        if l[i] == '0':
            dp2 = dp2
        else:
            dp1 += dp2
            dp2 = 2 * dp2
        dp1 %= MOD
        dp2 %= MOD
    print((dp1 + dp2) % MOD)

main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int N, Q, B[500010]; 
void add(int a, int b){
	int x = a; 
	while(x <= N){
		B[x] += b; x += x & -x; 
	}
}
int sum(int a){
	int res = 0; 
	int x = a; 
	while(x > 0){
		res += B[x]; x -= x & -x;
	}
	return res; 
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N >> Q; 
	int C[500010] = {}; 
	for(int i = 1; i <= N; i++) cin >> C[i]; 
	pair<pair<int, int>, int> I[500010]; // ((右, 左), 順番)
	for(int i = 0; i < Q; i++){
		cin >> I[i].first.second >> I[i].first.first; 
		I[i].second = i; 
	}
	sort(I, I + Q); 
	int A[500010] = {}; // 色iが最後に現れる添字
	int ans[500010] = {}; 
	int r = 1; 
	for(int i = 0; i < Q; i++){
		for(int j = r; j <= I[i].first.first; j++){
			if(A[C[j]] > 0) add(A[C[j]], -1); 
			add(j, 1); 
			A[C[j]] = j; 
		}
		r = I[i].first.first + 1; 
		ans[I[i].second] = sum(I[i].first.first) - sum(I[i].first.second - 1); 
	}
	for(int i = 0; i < Q; i++){
		cout << ans[i] << "\n"; 
	}
}

Measured memory_bytes: 17424
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 N, M;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    cin >> N;
    vector<int> a(N);
    REP(i, N) { cin >> a.at(i); }

    deque<int> deq;
    REP(i, N) {
        if (i % 2 == 0)
            deq.push_front(a[i]);
        else
            deq.push_back(a[i]);
    }

    if (N % 2 == 0) reverse(ALL(deq));

    REP(i, N) {
        cout << deq[i];
        if (i < N - 1) cout << " ";
    }
    cout << endl;

    return 0;
}


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

typedef vector<vector<int>> graph;
typedef pair<char, int> query;


vector<int> mark_parent;
vector<int> marked;
graph g;


void walk_graph(int v, int mark_p) {
    mark_parent[v] = mark_p;

    if (marked[v]) {
        mark_p = v;
    }

    for (int& nv : g[v]) {
        walk_graph(nv, mark_p);
    }
}


int find_mark_parent(int v) {
    if (marked[v]){
        // cout << endl;
        return v;
    }
    // cout << v << "->";
    return mark_parent[v] = find_mark_parent(mark_parent[v]);
}


long long solve(int N, int Q, vector<int>& parent, vector<query>& queries) {
    mark_parent = vector<int>(N, 0);
    marked = vector<int>(N, 0);

    g = graph(N, vector<int>());

    for (int j = 1; j < N; ++j) {
        g[parent[j]].push_back(j);
    }

    marked[0] = 1;
    for (query& q : queries) {
        if (q.first == 'M') {
            ++marked[q.second];
        }
    }

    walk_graph(0, 0);
    
    long long ret = 0;

    for (int j = Q-1; j >= 0; --j) {
        char ch = queries[j].first;
        int v = queries[j].second;


        if (ch == 'Q') {
            int ind = find_mark_parent(v) + 1;
            ret += ind;
        }

        if (ch == 'M') {
            --marked[v];
        }
    }

    return ret;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, Q;
    vector<int> parent;
    vector<query> queries;

    while (true) {
        cin >> N >> Q;
        if (N == 0 && Q == 0) {
            break;
        }

        parent.resize(N);
        parent[0] = 0;
        for (int j = 1; j < N; ++j) {
            cin >> parent[j];
            --parent[j];
        }

        queries.resize(Q);
        for (query& q : queries) {
            cin >> q.first >> q.second;
            --q.second;
        }

        cout << solve(N, Q, parent, queries) << endl;
    }
    return 0;
}

Measured memory_bytes: 14816
#include <iostream>
#include <string>
using namespace std;
int main(void){
	int n;
	string str, al = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
	cin >> n >> str;
	for (int i = 0; i < str.size(); i++){
		for (int j = 0; j < 26; j++)if (str[i] == al[j]) cout << al[j + n];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        long lcm = lcm(n, m);
        int lIndex = 1;
        while (lcm * lIndex < Math.max(n, m)) {
            lIndex++;
        }
        lcm = lIndex * lcm;
        HashMap<Long, Character> map = new HashMap<>();
        int index = -1;
        long nl = lcm / n;
        while (++index < n) {
            long key = index * nl;
            map.put(key, s.charAt(index));
        }
        index = -1;
        long nm = lcm / m;
        while (++index < m) {
            long key = index * nm;
            if (map.containsKey(key)) {
                if (!map.get(key).equals(t.charAt(index))) {
                    System.out.println(-1);
                    return;
                }
            }
        }

        System.out.println(lcm);
    }

    private static long lcm(long a, long b) {
        return Math.max(a, b) / gcd(a, b) * Math.min(a, b);
    }

    private static long gcd(long a, long b) {
        long temp;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return b;
    }
}

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

int main() {
int k=0,b;
int a[1000000];
while(cin>>b){
	if(b!=0){
		a[k]=b;
		k=k+1;
	}
	if(b==0){
		cout<<a[k-1]<<endl;
		k=k-1;
	
}
}
	return 0;
}

Measured memory_bytes: 1164
# ABC 166 C

N,M =map(int,input().split())
H= [int(j) for j in input().split()]
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    AB.append([a,b])
    AB.append([b,a])
AB.sort(key=lambda s:s[0])
cnt =0
last_a = AB[0][0]
a_cnt = [0] *N
h_cnt = [0] *N
for a,b in AB:
    a-=1
    b-=1
    a_cnt[a] =a_cnt[a]+1
    if H[a] >H[b]:
        h_cnt[a]=h_cnt[a]+1
    
for i,a in enumerate(a_cnt):
    if h_cnt[i]==a:
        cnt+=1
print(cnt)  

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

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

int N;
vint G[111111];
int par[20][111111],dep[111111];
void dfs(int v,int p,int d){
    par[0][v]=p;
    dep[v]=d;
    for(auto u:G[v]){
        dfs(u,v,d+1);
    }
}
int lca(int u,int v){
    if(dep[u]<dep[v])swap(u,v);
    rep(i,20)if((dep[u]-dep[v])>>i&1)u=par[i][u];
    if(u==v)return u;
    for(int i=19;i>=0;i--)if(par[i][u]!=par[i][v])u=par[i][u],v=par[i][v];
    return par[0][u];
}

signed main(){
    cin>>N;
    for(int i=1;i<N;i++){
        int j;cin>>j;j--;
        G[j].pb(i);
    }
    rep(i,N)sort(all(G[i]));
    vint vec={0};
    rep(i,N){
        for(auto u:G[vec[i]])vec.pb(u);
    }
    dfs(0,-1,0);
    rep(i,19)rep(j,N){
        if(par[i][j]==-1)par[i+1][j]=-1;
        else par[i+1][j]=par[i][par[i][j]];
    }

    int ans=0;
    for(int i=0;i<N-1;i++){
        int p=lca(vec[i],vec[i+1]);
        ans+=dep[vec[i]]+dep[vec[i+1]]-2*dep[p];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 30508
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

H, W = list(map(int, sys.stdin.buffer.readline().split()))
S = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(H)]


# ペアのとり方は 10395 通り
# a = math.factorial(12) / (2 ** 6) / math.factorial(6)
# print(a)  # 10395

def test(groups):
    seen = [False] * 6
    order = [-1] * len(groups)
    for i, g in enumerate(groups):
        if g == -1:
            # 真ん中
            order[W // 2] = i
            continue
        if not seen[g]:
            order[g] = i
            seen[g] = True
        else:
            order[~g] = i

    # print(groups, order)
    # return False

    rows = []
    for s in S:
        row = ''
        for i in order:
            row += s[i]
        rows.append(row)
    ok = [False] * H
    for i in range(H):
        if ok[i]:
            continue
        rev = rows[i][::-1]
        for j in range(i + 1, H):
            if not ok[j] and rows[j] == rev:
                ok[i] = ok[j] = True
                break
    ng_cnt = ok.count(False)
    if ng_cnt == 0:
        return True
    if ng_cnt == 1:
        i = ok.index(False)
        return rows[i] == rows[i][::-1]
    return False


def solve(groups, depth=0):
    if depth == W // 2:
        return test(groups)

    i = 0
    for _ in range(2 if W % 2 == 1 else 1):
        while groups[i] != -1:
            i += 1

        groups[i] = depth
        for j in range(i + 1, W):
            if groups[j] != -1:
                continue
            groups[j] = depth
            if solve(groups, depth + 1):
                return True
            groups[j] = -1
        groups[i] = -1
        i += 1

    return False


groups = [-1] * W
ok = solve(groups)
if ok:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 48476
import math

x,k,d = map(int,input().split())

if x < 0:
    x *= -1

if x-k*d < 0:
    if (k-(math.floor(x/d)))%2 == 0:
        print(x%d)
    else:
        print(abs(x%d-d))
else:
    print(x-k*d)

Measured memory_bytes: 9172
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const ll mod = (ll) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>


int main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  ll h, n;
  cin >> h >> n;
  ll s = 0;
  for (int i = 0; i < n; i++) {
    ll p;
    cin >> p;
    s += p;
  }
  if (s >= h) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n, a;
  cin >> n >> a;
  
  cout << n * n - a << endl;

  return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
typedef long long ll;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 300 + 5;
const int MAX_N = 1e5 + 5;

vector<int> divisor(int n) {
    vector<int> res;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int m = 0;
    vector<int> b(n, 0);
    vector<bool> push(n, false);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] != b[i]) {
            push[i] = true;
            vector<int> div = divisor(i + 1);
            for (int j = div.size() - 1; j >= 0; j--) {
                auto e = div[j];
                b[e - 1] = (b[e - 1] + 1) % 2;
            }
        } else
            continue;
    }
    for (auto e : push) {
        if (e) m++;
    }
    cout << m << endl;
    for (int i = 0; i < n; i++) {
        if (push[i])
            cout << i + 1 << " ";
        else
            continue;
    }
    cout << endl;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		if(S.equals("ABC")) {
			System.out.println("ARC");
		}else {
			System.out.println("ABC");
		}
	}
}

Measured memory_bytes: 35672
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var H = int.Parse(Console.ReadLine().Split()[0]);
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Console.WriteLine(H <= A.Sum() ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 18784
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

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

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************
ll mod=1000000007;
void solve()
{
    ll n;
    cin >> n;
    map<string,int> m;
    m["AC"]=m["WA"]=m["TLE"]=m["RE"]=0;
    for(int i=0;i<n;i++)
    {
        string s;
        cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

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

    vector<LL> B(N+1);
    REP(i,N){
        B[i+1] = B[i] + A[i];
    }

    int last = A[N-1];
    vector<int> eat(N);
    REP(i,N){
        int j = N-1-i;
        int p = upper_bound(ALL(A), B[j+1]*2) - A.begin();
        //cerr << p << "," << A[p-1] << "," << eat[p-1] << endl;
        if(last <= B[p] || eat[p-1])eat[j] = 1;
    }

    int res = 0;
    REP(i, N)res += eat[i];
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 2176
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let w: usize = iterator.next().unwrap().parse().unwrap();
    let h: usize = iterator.next().unwrap().parse().unwrap();
    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut matrix: Vec<Vec<usize>> = vec![vec![1; w]; h];

    for _ in 0..n {
        let xi: usize = iterator.next().unwrap().parse().unwrap();
        let yi: usize = iterator.next().unwrap().parse().unwrap();
        let a: u8 = iterator.next().unwrap().parse().unwrap();
        for y in 0..h {
            for x in 0..w {
                if a == 1 && x < xi {
                    matrix[y][x] = 0;
                } else if a == 2 && x >= xi {
                    matrix[y][x] = 0;
                } else if a == 3 && y < yi {
                    matrix[y][x] = 0;
                } else if a == 4 && y >= yi {
                    matrix[y][x] = 0;
                }
            }
        }
    }

    let mut ans: usize = 0;
    for y in 0..h {
        for x in 0..w {
            ans += matrix[y][x];
        }
    }
    return ans.to_string();
}


Measured memory_bytes: 4352
S = input()
N = len(S)

p = 2019
X = [0 for _ in range(p)]
X[0] = 1

dp = X[:]
ans = 0
for i in range(N):
    v = int(S[i])
    np = X[:]
    for k in range(p):
        x = (k * 10 + v) % p
        np[x] += dp[k]
    dp = np[:]
    ans += dp[0] - 1
print(ans)


Measured memory_bytes: 87716
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;


using std::endl;

bool IsBoin(char c){
  return c=='a'||c=='i'||c=='u'||c=='e'||c=='o';
}

std::string MakeCode(std::string s){
  std::string result;

  result+=s[0];
  for(int i=0;i<s.size();i++){
    if(IsBoin(s[i])){
      if(i+1<s.size()){
        result+=s[i+1];
      }
    }
  }

  // cerr<<result<<endl;

  return result;
}

std::string MakeMini(std::string s,int k){
  std::string result;
  for(int i=0;i<k&&i<s.size();i++){
    result+=s[i];
  }
  return result;
}

int Solve(int n){
  std::vector<std::string> s(n);
  for(int i=0;i<n;i++){
    cin>>s[i];
  }

  std::vector<std::string> code(n);
  for(int i=0;i<n;i++){
    code[i]=MakeCode(s[i]);
  }

  for(int k=1;k<=50;k++){
    std::vector<std::string> minicode(n);
    for(int i=0;i<n;i++){
      minicode[i]=MakeMini(code[i],k);
    }
    bool isOK=true;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        if(minicode[i]==minicode[j]){
          isOK=false;
          break;
        }
      }
      if(!isOK) break;
    }
    if(isOK){
      return k;
    }
  }

  return -1;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  while(1){
    int n;
    cin>>n;
    if(n==0){
      break;
    }
    cout<<Solve(n)<<endl;
  }

  return 0;
}



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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int fie[200][200];
int color;
int w,h;
int sx,sy,gx,gy,n;

void dfs(int y,int x){
    int dx[]={1,0,-1,0};
    int dy[]={0,1,0,-1};
    fie[y][x]=9;
    
    rep(i,4){
        if( 0<=x+dx[i] && x+dx[i]<w  &&  0<=y+dy[i] && y+dy[i]<h  &&  fie[ y+dy[i] ][ x+dx[i] ]==color ){
            dfs(y+dy[i],x+dx[i]);
        }
    }
}



int main(){
    while(cin>>w>>h){
        if(w==0&&h==0)break;
        rep(i,200)rep(j,200)fie[i][j]=0;
        
        cin>>sx>>sy>>gx>>gy>>n;
        sx--,sy--,gx--,gy--;
        rep(i,n){
            int c,d,x,y;
            cin>>c>>d>>x>>y;
            x--,y--;
            
            if(d==0){
                int dx[]={0,0,1,1,2,2,3,3};
                int dy[]={0,1,0,1,0,1,0,1};
                rep(i,8) fie[y+dy[i]][x+dx[i]]=c;
            }else{
                int dx[]={0,1,0,1,0,1,0,1};
                int dy[]={0,0,1,1,2,2,3,3};
                rep(i,8) fie[y+dy[i]][x+dx[i]]=c;
            }
        }
        
        color=fie[sy][sx];
        dfs(sy,sx);
        if(fie[gy][gx]==9)cout<<"OK"<<endl;
        else cout<<"NG"<<endl;

    }
}

Measured memory_bytes: 1324
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
diff = 1000
ans = 0

for i in range(n):
    if diff > abs(a - (t - h[i]*0.006)):
        diff = abs(a - (t - h[i]*0.006))
        ans = i + 1

print(ans)

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

int n;
vector<int> a, b, c;
template <class T>
void readVector(int n, vector<T> &v){
	for(int i=0; i<n; ++i){
		T t;
		cin >> t;
		v.push_back(t);
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	readVector(n, a);
	readVector(n, b);
	readVector(n, c);
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	vector<long long> x(n, 0ll);
	long long ans = 0;
	int p = -1;
	for(int i=0; i<n; ++i){
//		cout << i << "\n";
		while(p < n-1 && b[i] > a[p+1]) ++p;
		x[i] = p+1;
		if(i != 0) x[i] += x[i-1];
	}
	p = -1;
	for(int i=0; i<n; ++i){
//		cout << i << "\n";
		while(p < n-1 && c[i] > b[p+1]) ++p;
		if(p > -1) ans += x[p];
	}
	cout << ans << "\n";
//	for(int i=0; i<n; ++i)
//		cout << x[i] << "\t" << y[i] << "\n";
}

Measured memory_bytes: 2296
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Stirbul
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoToJail solver = new BGoToJail();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoToJail {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();

            int[] a = new int[n];
            int[] b = new int[n];


            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
                b[i] = in.nextInt();
            }

            int count = 0;
            for (int i = 0; i < n; ++i) {
                if (a[i] == b[i]) {
                    count++;
                    if (count == 3) {
                        break;
                    }
                } else {
                    count = 0;
                }
            }

            if (count == 3) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}



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

int main(){
  int n,k;
  string s;
  cin>>n>>k>>s;
  if(s.at(k-1)=='A') s.at(k-1)='a';
  if(s.at(k-1)=='B') s.at(k-1)='b';
  if(s.at(k-1)=='C') s.at(k-1)='c';
  cout<<s;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------

//NoSub

int main(){//ていしゅつしないで！！！！！！！！！！！！
    int n,d,x;
    int a[110];

    cin>>n>>d>>x;
    REP(i,n)cin>>a[i];

    //なげるな
    int sum=0;
    REP(i,n){
        sum+=(d-1)/a[i]+1;
    }
    cout<<sum+x<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    // dp[i][j] : 上位i桁で，あまりがjである個数
    ll dp[s.size()+1][13] = {};
    dp[0][0] = 1;

    rep(i, s.size()){
        if(s[i] == '?'){
            rep(j, 13){
                rep(k, 10){
                    dp[i+1][(j*10+k) % 13] += dp[i][j];
                    dp[i+1][(j*10+k) % 13] %= MOD;
                }
            }
        }
        else {
            ll digit = s[i] - '0';
            rep(j, 13){
                dp[i+1][(j*10+digit) % 13] += dp[i][j];
                dp[i+1][(j*10+digit) % 13] %= MOD;
            }
        }
    }

    cout << dp[s.size()][5] << endl;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    rep(i, s.size()) {
        if ( s[i] == '-' && i != a || (s[i] != '-' && i == a) ) {
            cout << "No" << endl;
            return 0;
        }
        
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main()
{
    int N;
    scanf("%d\n", &N);
    int *L = malloc(sizeof(int) * N);

    for(int ni=0; ni<N; ni++){
        scanf("%d", L+ni);
    }

    int res = 0;
    for(int ni=0; ni<N; ni++){
        for(int nj=ni+1; nj<N; nj++){
            for(int nk=nj+1; nk<N; nk++){
                if(
                        L[ni] + L[nj] > L[nk]
                        && L[nj] + L[nk] > L[ni]
                        && L[nk] + L[ni] > L[nj]){
                    res++;
                }
            }
        }
    }

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

    return 0;
}


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

using namespace std;

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

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

  int ans = A - B * 2;
  if (ans >= 0) cout << ans << endl;
  else cout << 0 << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> P;
typedef pair<ll,pair<ll,ll>> p;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
static const int MAX_SIZE = 1 << 17; //segment tree のサイズ。この実装では2べきにする必要がある。 2^17 ≒ 1.3 * 10^5

int dp[110000][2];

bool flag[110000];
int C[110000];

int main(){
    for(int i=0;i<110000;i++) flag[i]=false;
    int N,M,x[110000],y[110000];
    cin>>N>>M;

    for(int i=0;i<M;i++) cin>>x[i]>>y[i];

    for(int i=1;i<=N;i++) C[i]++;
    flag[1]=true;
    for(int i=0;i<M;i++){
        C[x[i]]--; C[y[i]]++;
        if(flag[x[i]]){
            if(C[x[i]]==0) flag[x[i]]=false;
            flag[y[i]]=true;
        }
    }
    int count=0;
    for(int i=1;i<=N;i++){
        if(flag[i]) count++;
    }
    cout<<count<<endl;
}



Measured memory_bytes: 1536
#include<stdio.h>
int d1,d2,n,f[2001][2001],a=0,now=0;

void color(int x){
	if(x%2==1){
		for(int i=0;i<n<<1;++i){
			for(int j=0;j<n<<1;++j){
				if(((i>>now)+(j>>now))%2)f[i][j]=1;
			}
		}
	}else if(x%4==2){
		for(int i=0;i<n<<1;++i){
			for(int j=0;j<n<<1;++j){
				if((i>>now)%2)f[i][j]=1;
			}
		}
	}else{ 
		++now;
		color(x/4);
	}
}

int main(){
	scanf("%d%d%d",&n,&d1,&d2);
	color(d1);
	now=0;
	color(d2);
	for(int i=0;i<n<<1;++i){
		for(int j=0;j<n<<1;++j){
			if(f[i][j]==0){
				printf("%d %d\n",i,j);
				if(++a==n*n)return 0;
			}
		}
	}
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint d(n);
  int ans = 0;
  rep(i, n) cin >> d[i];
  d.push_back(0);
  n++;
  sort(all(d));

  auto check = [&](int m) {
    int now = 0;
    int curr = 0;
    vint used(n, 0);
    used[now] = 1;
    rep(i, n-1) {
      int nex = -1;
      int val = 0;
      rep(j, n) {
	if(used[j]) continue;
	if(nex == -1) {
	  int a = d[j];
	  int b = 24-d[j];
	  if(a > b) swap(a, b);
	  if(a >= curr+m) {
	    nex = j;
	    val = a;
	  } else if(b >= curr+m) {
	    nex = j;
	    val = b;
	  }
	} else {
	  int a = d[j];
	  int b = 24-d[j];
	  if(a > b) swap(a, b);
	  if(a >= curr+m && a < val) {
	    nex = j;
	    val = a;
	  } else if(b >= curr+m && b < val) {
	    nex = j;
	    val = b;
	  }
	}
      }
      if(nex == -1) return false;
      used[nex] = 1;
      now = nex;
      curr = val;
    }
    return min(abs(d[now]-d[0]), abs(24-(d[now]+d[0]))) >= m;
  };
  int lb = 0, ub = 13;
  while(lb+1 < ub) {
    int mb = (lb+ub)/2;
    if(check(mb)) lb = mb;
    else ub = mb;
  }
  cout << lb << endl;

  return 0;
}


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < n; i++)
#define REP(n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using INT64 = long long;
using UINT64 = unsigned long long;

int main(void)
{
    IOS
    int n;
    cin >> n;
    vector<int> v(n);
    REP(n) cin >> v[i];

    int ans = 100000;
    REP(n) {
        int w1 =0;int w2=0;
        FOR(j,0,i) w1 +=v[j];
        FOR(j,i,n) w2 +=v[j];
        int w = w1 -w2;
        if (w < 0) w = -w;
        if(ans > w) ans = w;
    }

    cout << ans << endl;


    return 0;
}


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

int main() {
    int n;
    cin >> n;
    cin.ignore();
    for (int i=0; i<n; ++i) {
        string res(100, ' '), s;
        getline(cin, s);
        int k = 50;
        res[k] = s[0];
        for (int j=3; j<(int)s.size(); j+=3) {
            if (s[j-1] == '>') {
                k ++;
            } else {
                k --;
            }
            res[k] = s[j];
        }
        string res2 = "";
        for (int i=0; i<100; ++i) {
            if (res[i] != ' ') {
                res2 += res[i];
            }
        }
        cout << res2 << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n,s=get_i
a=get_i
MAX_N=10**5+1
ans=MAX_N
head=0
tail=0
t=0
cnt=0
while true
  while tail<n and t<s
    t+=a[tail]
    cnt+=1
    tail+=1
  end
  break if t<s or head>=tail
  if ans>cnt and t>=s
    ans=cnt
  end
  t-=a[head]
  head+=1 
  cnt-=1
end
if ans==MAX_N
  puts 0
else
  puts ans
end


Measured memory_bytes: 14552
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 0;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[3000];
signed main() {
	n = read();
	int sum = 0;
	bitset<5000000>dp, dp2;
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		sum += a[i];
	}
	int res = sum / 2;
	int ma = 0;
	dp.set(0);
	for (int i = 0; i < n; i++) {
		dp2 = dp;
		dp2 <<= a[i];
		dp |= dp2;
	}
	int ans = 0;
	for (int i = 0; i <= res; i++) {
		if (dp.test(i)) ans = i;
	}
	printf("%lld\n", sum - ans);
}

Measured memory_bytes: 1536
#include<algorithm>
#include<iostream>
#include<functional>
using namespace std;
int main(){
  int num[200];
  int n,count=0,ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  sort(num,num+n);
  reverse(num,num+n);
  for(int j=0;j<n;j++){
    if(ans!=num[j]){
      count++;
    }
    ans=num[j];
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll res(string s){
    ll ans = 0;
    for(ll i = 0; i < s.size();){
         ll cnt = 0;
        while(s[i] == s[i+cnt+1]){
            cnt++;
        }
        ans += (cnt+1)/2;
        i += cnt+1;
    }
    return ans;
}
int main(){
    cout << fixed << setprecision(10);

    string s;
    cin >> s;
    ll k;
    cin >> k;
    map<char,int> mci;
    for(auto u : s){
        mci[u]++;
    }
    if(mci.size() == 1){
        cout << s.size()*k/2 << endl;
        return 0;
    }
    if(s[0] != s[s.size()-1]){
        cout << res(s)*k << endl;
        return 0;
    }
    ll sub = res(s+s) - res(s);
    //cout << res(s) << endl;
    //cout << sub << endl;
    cout << res(s) + sub*(k-1) << endl;
    return 0;
}

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

int main() {
	int n, i;
	double dp[30];
	while (cin >> n, n){
		dp[1] = 1;
		dp[2] = 2;
		dp[3] = 4;
		for (i = 4; i <= n; i++) {
			dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
		}
		cout << ceil(dp[n] / 3650) << endl;
	}
}

Measured memory_bytes: 1232
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, mut k) = (v[0], v[1]);
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut spans = vec![];

    let mut cur = 1;
    for i in 0..n - 1 {
        if s[i] != s[i + 1] {
            spans.push(cur);
        } else {
            cur += 1;
        }
    }
    spans.push(cur);

    spans.sort();

    let mut ans = n - spans.len() + 2 * k;
    println!("{}", min(ans, n - 1));
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352