akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(void){
	int n;
	while(cin >> n){
		if(!n) break;
		int d[15][15] = {0};
		int nx = (n-1)/2;
		int ny = (n+1)/2;
		for(int i=0; i<n*n; ++i){
			if(nx < 0) nx = n-1;
			if(nx >= n) nx = 0;
			if(ny >= n) ny = 0;
			while(d[ny][nx]){
				nx--, ny++;
				if(nx < 0) nx = n-1;	
				if(nx >= n) nx = 0;
				if(ny >= n) ny = 0;
			}
			d[ny][nx] = i+1;
			nx++, ny++;
		}
		for(int i=0; i<n; ++i){
			for(int j=0; j<n; ++j){
				if(j != n-1) printf("%4d", d[i][j]);
				else printf("%4d\n", d[i][j]);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
n,c,k=map(int,input().split())
T=[int(input()) for i in range(n)]
T.sort()
ans=0; now=0; nowc=0
for  ii in range(n):
    if now>=T[ii] and nowc<c: nowc+=1; continue
    now=T[ii]+k
    nowc=1
    ans+=1
print(ans)

Measured memory_bytes: 81100
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>        P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int A, B;
	string S;
	cin >> A >> B >> S;

	int i = 0;
	string ans = "Yes";
	REP(i, A) {
		if (!isdigit(S[i])) {
			ans = "No";
		}
	}
	if (S[A] != '-') {
		ans = "No";
	}
	REPN(i, A + 1, A + B + 1) {
		if (!isdigit(S[i])) {
			ans = "No";
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  n %= 10;
  if (n == 3)
    cout << "bon" << endl;
  else if (n == 0 || n == 1 || n == 6 || n == 8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
  return 0;
}

Measured memory_bytes: 3652
def main():
    N = int(input())
    As = [int(v) for v in input().split()]
    count = 0
    while all(x % 2 == 0 for x in As):
        count += 1
        As = [x // 2 for x in As]

    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    rep (i,0,m)
    {
        ll x;
        cin>>x;
        sum+=x;
    }
    if (n-sum<0)
    {
        cout<<"-1\n";
    }
    else
    {
        cout<<n-sum<<"\n";
    }
    
}


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

int main(){
    
    ios_base::sync_with_stdio(NULL);
    int n;
    cin>>n;
    long long sum=0;
    int arr[100010];
    fill(arr,arr+100010,0);
    
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        arr[a]++;
        sum+=a;
    }
    
    int q;
    cin>>q;
    while(q--){
        int r,s;
        cin>>r>>s;
        int temp= arr[r];
        arr[r]=0;
        arr[s]+=temp;
        sum+=(s*temp-r*temp);
        cout<<sum<<endl;
    }
    
    
    
}

Measured memory_bytes: 4044
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

int N;
int a[100010];

int main(){
	scanf("%d" , &N);
	repp(i,0,N){
		int x;
		scanf("%d" , &x);
		++a[x];
	}
	if(N%2==1&&a[0]!=1){
		printf("0\n");
		return 0;
	}
	for(int i = N%2+1 ; i < N ; i += 2){
		if(a[i] != 2){
			printf("0\n");
			return 0;
		}
	}
	int p = 1;
	int mod = 1e9 + 7;
	repp(i,0,N/2){
		(p *= 2) %= mod;
	}
	printf("%d\n" , p);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main() {
    int n; cin >> n;
    vector<int> dp(100100);
    dp[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        int num;
        dp[i] = i;
        num = 1;
        while (num <= i) {
            dp[i] = min(dp[i], dp[i-num]+1);
            num *= 6;
        }
        num = 1;
        while (num <= i) {
            dp[i] = min(dp[i], dp[i-num]+1);
            num *= 9;
        }

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

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

void solve();
int main() {
	solve();
#ifdef DBG
	while (true);
#endif
}

void solve() {
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%d\n", (a - 1) + (a <= b));
}

Measured memory_bytes: 128
# coding: utf-8
import sys
from itertools import product

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
XYZ = [lr() for _ in range(N)]
answer = 0
for a, b, c in product([-1, 1], repeat=3):
    cand = list(x*a + y*b + z*c for x, y, z in XYZ)
    cand.sort(reverse=True)    
    temp = sum(cand[:M])
    if temp > answer:
        answer = temp

print(answer)


Measured memory_bytes: 40944
use std::io::{self, BufRead};

fn dfs(es: &Vec<Vec<(usize, usize)>>, colors: &mut Vec<bool>, visited: &mut Vec<bool>, n: usize) {
  visited[n] = true;
  for &(u, w) in &es[n] {
    if !visited[u] {
      colors[u] = if w % 2 == 0 { colors[n] } else { !colors[n] };
      dfs(es, colors, visited, u);
    }
  }
}

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
  let mut es: Vec<Vec<(usize, usize)>> = vec![Vec::new(); n];
  for _ in 0..(n-1) {
    let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
    let (u, v, w) = (xs[0] - 1, xs[1] - 1, xs[2]);
    es[u].push((v, w));
    es[v].push((u, w));
  }
  let mut colors: Vec<bool> = vec![false; n];
  let mut visited: Vec<bool> = vec![false; n];
  dfs(&es, &mut colors, &mut visited, 0);
  for c in colors {
    println!("{}", if c { "1" } else { "0" });
  }
}

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

int main()
{
    int K, X; cin >> K >> X;
    cout << ((K * 500 >= X) ? "Yes" : "No");
}


Measured memory_bytes: 256
#B
a, b, c = map(int, input().split())
K=int(input())
for i in range(K):
    if a>=c:
        c=2*c
    elif a>=b:
        b=2*b
    elif b>=c:
        c=2*c
    else:
        c=2*c
if a<b and b<c:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9124
import fractions
N = int(input())
A = [int(i) for i in input().split()]
def lcm(a,b):
  return a*b//fractions.gcd(a,b)
a_lcm = A[0]
for a in A[1:]:
  a_lcm = lcm(a_lcm, a)
ans = 0
for a in A:
  ans += a_lcm//a
print(ans%(10**9+7))

Measured memory_bytes: 6072
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
	int n, b[100], ans = 0;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		cin >> b[i];
	}
	for (int j = 0; j < n-2; j++) {
		if (b[j] >= b[j + 1]) {
			ans += b[j + 1];
		}
		else {
			ans += b[j];
		}
	}
	ans += b[0];
	ans += b[n - 2];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    P = LI_()
    C = LI()
    G = [-1 for _ in range(N)]
    for i, p in enumerate(P):
        G[i] = p
    seen = set()

    loop_score = []
    loop_size = []
    loop_id2node = collections.defaultdict(list)

    _id = 0
    def calc_one_loop(v):
        nodes = set()
        if G[v] == -1:
            return -1, -1
        # calc loop, and return score
        score = 0
        size = 0
        while G[v] not in seen:
            v = G[v]
            seen.add(v)
            nodes.add(v)
            score += C[v]
            size += 1
        return score, size, nodes

    for i in range(N):
        if i in seen:
            continue
        score, size, nodes = calc_one_loop(i)
        if score == -1 and size == -1:
            continue
        loop_score.append(score)
        loop_size.append(size)
        loop_id2node[_id].extend(list(nodes))
        seen.add(i)
        _id += 1

    # print('loop_size: ', loop_size)
    # print('loop_score: ', loop_score)
    ans = -inf
    for i in range(_id):
        # i: id
        n_loop = K // loop_size[i]

        # score_afterを作る
        score_after = [[0] for _ in range(N)]
        for v in loop_id2node[i]:
            max_move_cnt = loop_size[i] + 1
            move_cnt = 0
            cum_score = 0
            cur_v = v
            while move_cnt < max_move_cnt:
                cur_v = G[cur_v]
                cum_score += C[cur_v]
                score_after[v].append(cum_score)
                move_cnt += 1
        # print('score_after: ', score_after)
        if loop_score[i] <= 0:
            max_step = min(K, loop_size[i])
            score = 0
        else:
            # 先に回る
            # ちょうど1周だったら、回らない
            score = 0
            max_step = loop_size[i]

            # if K == loop_size[i]:
            #     max_step = K
            #     score = 0
            # else:
            #     K -= n_loop * loop_size[i]
            #     max_step = K
            #     score = n_loop * loop_score[i]

        # loop_size[i]より小さい数で全探索
        for l in range(1, max_step + 1):
            for v in loop_id2node[i]:
                cp_score = score
                cnt = 0
                cp_score += score_after[v][l]
                # 実現不可能なら飛ばす
                if l > K:
                    continue
                # 回った時も試してみる
                if K - l >= loop_size[i]:
                    cp_score = max(cp_score, cp_score + loop_score[i] * ((K - l) // loop_size[i]))
                ans = max(ans, cp_score)
    print(ans)

main()



Measured memory_bytes: 301132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
// Welcome to my source code!

const int MOD = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> oks(n+1, true);
    int a;
    for (int i = 0; i < m; i++) {
        cin >> a;
        oks[a] = false;
    }
    ll dp[101000];
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j <= min(n, i+2); j++) {
            if (oks[j]) {
                dp[j] += dp[i];
                dp[j] %= MOD;
            }
        }
    }
    cout << dp[n] << endl;
}

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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if((A+D-1)/D>=(C+B-1)/B){
    cout<<"Yes"<<endl;
  }
 
  
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3620
n,y=map(int,input().split())
for i in range(0,n+1):
        for j in range(0,n-i+1):
                z=n-i-j
                if y==i*10000+j*5000+z*1000:
                        print(str(i)+' '+str(j)+' '+str(z))
                        exit()
print('-1 -1 -1')



Measured memory_bytes: 2940
import sys
t = [0 for i in range(10000)]
c = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            for l in range(10):
                t[c] = i + j + k + l
                c += 1
for line in sys.stdin:
    print(t.count(int(line)))

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

int main(){
  int H,N;
  cin>> H>>N;
  int total=0;
  int A;
  for (int i=0;i<N;i++){
    cin>>A;
    total=total+A;
  }
  if(H<=total){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;

}


Measured memory_bytes: 256
N = int(input())
S = []

for n in range(N):
    S.append(int(input()))

total = sum(S)

if total % 10:
    print(total)
    exit()

S2 = [x for x in S if x % 10]
if S2:
    print(total - min(S2))
else:
    print(0)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,k=0;
    string s;
    cin>>n;
    cin>>s;
    if(n%2!=0)
        cout<<"No";
    else
    {
        for(i=0;i<(n/2);i++)
        {
            if(s[i]==s[(n/2)+i])
                k++;
        }
        if(k==(n/2))
            cout<<"Yes";
        else
            cout<<"No";
    }
}


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

//a*b = nを満たす(a, b)の個数を計算
int calc(int n) {
    int count = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (i * i == n) {
                count++;
            }
            else {
                count += 2;
            }
        }
    }
    return count;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n - 1; i++) {
        ans += calc(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

int inf = std::numeric_limits<int>().max();

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define ll long long
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> v(n+1);
	for(int i=1; i<=n; i++) {
		cin >> v[i]; 
	}

	vector<int> w(n+1, inf);
	w[1] = 0;

	for(int i=1; i<=n; i++) {
		for(int j=1; j<=k; j++) {
			if (i+j<=n) {
				w[i+j] = min(w[i+j], w[i] + abs(v[i] - v[i+j]));	
			}
		}
	}
	cout << w[n] << endl;
}


Measured memory_bytes: 1024
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <iomanip>
#include <random>
#include <numeric>

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

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int> > min_heap;

// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

const int maxn = 2e5 + 5;
int loc[maxn]; //loc[val] = node

ll par[maxn];
ll sz[maxn];
ll val[maxn];
ll sm = 0;

ll find(int u) {
    if (u == par[u]) return u;
    return par[u] = find(par[u]);
}

void unite(int u, int v) {
    u = find(u);
    v = find(v);
    // elements of u get replaced to elements of v
    // cout << "sm before: " << sm << "\n";
    sm += (val[v] - val[u]) * sz[u];
    // cout << "val[v]: " << val[v] << ", val[u]: "  << val[u] << "\n";
    // cout << "sm after: " << sm << "\n";

    loc[val[u]] = 0;
    // loc[val[v]] = v;
    val[u] = val[v];

    if (sz[u] > sz[v]) swap(u, v);
    par[u] = v;
    sz[v] += sz[u];

    loc[val[v]] = find(v);

}

int n, q;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    
    for (int i = 1; i <= n; i++) {
        cin >> val[i];
        sz[i] = 1;
        par[i] = i;
        if (loc[val[i]]) {
            unite(i, loc[val[i]]);
        } else {
            loc[val[i]] = i;
        }
    }

    cin >> q;

    sm = 0;
    for (int i = 1; i <= n; i++) {
        sm += val[i];
    }

    // for (int i = 1; i <= n)

    for (int i = 1; i <= q; i++) {
        ll b, c;
        cin >> b >> c;
        // cout << "loc[b]: " << loc[b] << ", loc[c]: " << loc[c] << "\n";
        if (loc[b] and loc[c]) unite(loc[b], loc[c]);
        else {
            if (loc[b]) {
                loc[c] = loc[b];
                val[loc[c]] = c;
                loc[b] = 0;
                sm += (c - b) * sz[loc[c]];
            }
        }
        cout << sm << "\n";
    }
    

}
/*
    Potential bugs:
    - Not resetting the arrays properly
    - Out of bounds
*/

Measured memory_bytes: 6388
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

char s[1001];

int ans;

int main()
{
	scanf("%s",s);
	int n=strlen(s);
	bool flag=true;
	for(int i=1;i<n;i++)
		if(s[i]!='9')
			flag=false;
	if(flag)
		printf("%d",s[0]-'0'+(n-1)*9);
	else
		printf("%d",s[0]-'0'+(n-1)*9-1);
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int balls[10];

bool dfs(int n, int left, int right) {
	if(n == 10) return true;
	if(balls[n] > left && dfs(n + 1, balls[n], right)) return true;
	if(balls[n] > right && dfs(n + 1, left, balls[n])) return true;
	return false;
}

int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 10; j++) {
			cin >> balls[j];
		}
		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<vector<ll>> c(n,vector<ll>(n));
	REP(i,n) REP(j,n) cin>>c[i][j];
	ll ans=0;
	REP(i,n) {
		FOR(j,i,n) {
			ans+=min(c[i][j],c[j][i]);
		}
	}
	cout<<ans<<endl;
}




Measured memory_bytes: 3284
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int m, n;; cin >> n >> m;
	vector<vector<char>>x(n,vector<char>(n));
	vector<vector<char>>y(m,vector<char>(m));
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> x[i][j];
		}
	}
	for (int i = 0; i < m; ++i)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> y[i][j];
		}
	}



	for (int i = 0; i <= n - m ; i++) {
		for (int j = 0; j <= n - m ; j++) {
			bool xx = true;
			for (int k = 0; k < m; k++) {
				for (int l = 0; l < m; l++) {
					if (x[i + k][j + l] != y[k][l]) {
						xx= false;
					}
				}
			}
			if (xx) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;


	
}

Measured memory_bytes: 3536
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    if(x>=400 && x<=599){
      System.out.println(8);
    }
    else if(x>=600 && x<=799){
      System.out.println(7);
    }
    else if(x>=800 && x<=999){
      System.out.println(6);
    }
    else if(x>=1000 && x<=1199){
      System.out.println(5);
    }
    else if(x>=1200 && x<=1399){
      System.out.println(4);
    }
    else if(x>=1400 && x<=1599){
      System.out.println(3);
    }
    else if(x>=1600 && x<=1799){
      System.out.println(2);
    }
    else if(x>=1800 && x<=1999){
      System.out.println(1);
    }
  }
}

Measured memory_bytes: 35656
import java.lang.Math;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        Set<Integer> gates = new HashSet<>();

        for (int i = 0; i < m; i++) {
            gates.add(sc.nextInt());
        }

        int left_cost = 0;
        for (int i = 0; i < x; i++) {
            if (gates.contains(i)) { left_cost++; };
        }

        int right_cost = 0;
        for (int i = x + 1; i <= n; i++) {
            if (gates.contains(i)) { right_cost++; };
        }

        System.out.println(Math.min(left_cost, right_cost));
    }
}


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

int N;
int A[110];
vector<int> V;

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

    for(int i = 0; i < N; i++)if(A[i] > i + 1)
    {
        cout << -1 << endl;
        return 0;
    }

    for(int i = 0; i < N; i++)V.push_back(A[i]);

    vector<int> ans;
    for(int i = 0; i < N; i++)
    {
        int next = -1;
        for(int j = 0; j < V.size(); j++)
        {
            if(j + 1 == V[j])next = j;
        }
        if(next == -1)
        {
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(V[next]);
        V.erase(V.begin() + next);
    }

    reverse(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++)
    {
        cout << ans[i];
        if(i + 1 != ans.size())cout << " " << endl;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <algorithm>
#define CHAR_NUM 1001

using namespace std;

int main(void) {
    int i;
    char str[CHAR_NUM] = {'\0'};
    
    fgets(str, sizeof(str), stdin);
    int len = (int)strlen(str);
    
    
    
    for(i = 0; i < len; i++) {
        if(str[i] == 'a') {
            if(str[i + 1] == 'p')
                if(str[i + 2] == 'p')
                    if(str[i + 3] == 'l')
                        if(str[i + 4] == 'e') {
                            str[i]     = 'p';
                            str[i + 1] = 'e';
                            str[i + 2] = 'a';
                            str[i + 3] = 'c';
                            str[i + 4] = 'h';
                        }
        }
        else if(str[i] == 'p')
            if(str[i + 1] == 'e')
                if(str[i + 2] == 'a')
                    if(str[i + 3] == 'c')
                        if(str[i + 4] == 'h') {
                            str[i]     = 'a';
                            str[i + 1] = 'p';
                            str[i + 2] = 'p';
                            str[i + 3] = 'l';
                            str[i + 4] = 'e';
                        }
    }
    
    printf("%s", str);
    
    
    return(0);
}

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

int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  int a[n];
  for(int i = 0; i < m; ++i) cin >> a[i];
  
  int pos = m;
  for(int i = 0; i < m; ++i)
  {
    if(x <= a[i])
    {
      pos = i;
      break;
    }
  }
  
  int ans = min(pos, m - pos);
  cout << ans << endl;
}

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

const int maxn = 100+5;
int n, m, t[maxn], p[maxn], x[maxn];

int main(){
	scanf("%d", &n);
	int suma_tiempos = 0;
	for(int i = 1; i<=n; i++) {
		scanf("%d", &t[i]);
		suma_tiempos += t[i];
	}
	scanf("%d", &m);
	for(int i = 1; i<=m; i++) {
		scanf("%d %d", &p[i], &x[i]);
		int suma_nueva = suma_tiempos;
		suma_nueva -= t[p[i]];
		suma_nueva += x[i];
		printf("%d\n", suma_nueva);
	}
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stack>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <bitset>
#include<unordered_map>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
#define endl '\n'
#define exit(s) return cout<<s,0;
#define sz(s) (int)(s.size())
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(), s.rend()
#define watch(x) cout << (#x) << " = " << x << endl
#define DNT ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	

int main() {
	DNT;
	ll a, b, c, k, sum = 0;
	cin >> a >> b >> c >> k;
	if (k > a)
	{
		sum += a;
		k -= a;

		if (k > b)
		{
		
			k -= b;

			if (k > c)
			{
				sum += -1 * c;
			}
			else
			{
				sum += -1 * k;
			}

		}
		else
		{
			sum += b * 0;
		}

	}
	else
	{
		sum += k;

	}
	cout << sum << endl;

	return 0;
}

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

/*freopen("testcases/17.in", "r", stdin);
    freopen("output.txt", "w", stdout);*/

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	if(s=="AAA" || s=="BBB")
        cout << "No";
    else
        cout << "Yes";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
int main(){
  string s, t;
  cin >> s >> t;
  int N_s = s.size();
  int count = 0;
  rep(i, N_s) {
    if (s == t) {
      count ++;
      break;
    }
    else{
      char ps = s[N_s-1];
      string p(1, ps);
      s = s.erase(N_s-1);
      s = p + s;
    }
  }
  if (count == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    int sum, n;
    sum = 0;
    while(cin >> n) {
        sum += n;
    }

    cout << sum / 60 << endl << sum % 60 << endl;

     
    return 0;
}

Measured memory_bytes: 0
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N;
  ll ans = 0;

  scanf("%d", &N);

  // nodes
  for (int i = 1; i <= N; i++) {
    ans += (ll)(N - i + 1) * i;
  }

  for (int i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);

    if (u > v) swap(u, v);
    ans -= (ll)u * (N - v + 1);
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define N 20

const int mod=1000000007;
int a[N][N],f[1<<N],g[1<<N],tr[N][1<<N][2],ans,n,m,p;

void upd(int &x,int y){x=(x+y)%mod;}

int main(){
	scanf("%d%d%d",&n,&m,&p); --n;
	memset(a,-1,sizeof a);
	for (int i=1;i<=p;++i){
		int x,y,z; scanf("%d%d%d",&x,&y,&z);
		a[--x][--y]=z;
	}
	for (int i=0;i<1<<n;++i){
		int k=0;
		for (int j=0;j<n;++j){
			tr[j][i][0]=(i>>j&1)?-1:i;
			for (;k<j;++k);
			for (;k<n&&!(i>>k&1);++k);
			tr[j][i][1]=i^(1<<j)^(k<n?(1<<k):0);
		}
	}
	f[0]=1;
	
	for (int i=0;i<m;++i){
		for (int j=0;j<n;++j){
			memcpy(g,f,sizeof g);
			memset(f,0,sizeof f);
			for (int k=0;k<1<<n;++k){
				if (a[i][j]!=1&&~tr[j][k][0]) upd(f[tr[j][k][0]],g[k]);
				if (a[i][j]!=0&&~tr[j][k][1]) upd(f[tr[j][k][1]],g[k]);
			}
		}
	}
	for (int i=0;i<1<<n;++i) upd(ans,f[i]);
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 125184
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef vector<LL> VL;

int main() {
	LL n; cin >> n;
	vector<VL> a(5, VL(n)); rep(i, 3)rep(j, n)cin >> a[i][j];
	rep(i, 3)SORT(a[i]);

	LL ans = 0;
	rep(j, n) {
		LL b = a[1][j];
		auto ita = lower_bound(all(a[0]), b);
		LL acnt = ita - a[0].begin();
		auto itc = upper_bound(all(a[2]), b);
		LL ccnt = n - (itc - a[2].begin());

		ans += acnt * ccnt;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	sa := getNextString(scanner)
	sb := getNextString(scanner)
	sc := getNextString(scanner)
	la := 0
	lb := 0
	lc := 0
	p := 0
	for {
		switch p {
		case 0:
			if len(sa) == la {
				fmt.Fprintln(writer, "A")
				return
			}
			p = int(sa[la] - 'a')
			la++
		case 1:
			if len(sb) == lb {
				fmt.Fprintln(writer, "B")
				return
			}
			p = int(sb[lb] - 'a')
			lb++
		case 2:
			if len(sc) == lc {
				fmt.Fprintln(writer, "C")
				return
			}
			p = int(sc[lc] - 'a')
			lc++
		}
	}
}


Measured memory_bytes: 1820
/*
ACplease
　　 ●
　　/⌒ヽ
　 ｜ 　|/⌒ヽ(ヽ
　 (｀　∥ー⌒) |
　|￣||￣￣￣￣￣|
　|―||―――――|
　|　Ｕ　　　　　|
　|￣￣￣￣￣￣￣|
　|＿＿＿＿＿＿＿|
　　|―――――|
　　|―――――|
ｗｗＷｗｗＷｗＷＷｗ
*/
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    VI a(3); VIin(a);
    map<int,int> b;
    rep(i,3){
        b[a[i]]++;
    }
    rep(i,10){
        if(b[i] == 2){
            Yes;
            return 0;
        }
    }
    No;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a %b);
}

int main()
{
    int n;
    int sum = 0;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j<=n; j++)
            for(int k = 1;  k <=n; k++)
    {
        sum += gcd(i,gcd(j,k));
    }

    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
  
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
  
typedef long long ll;
typedef pair<int, int> ii;
 
#define DEBUG false
 
#define MAX_V 1100
 
int V;
vector<vector<int>> G(1100);
int match[MAX_V];
bool used[MAX_V];
 
bool dfs(int v){
    used[v] = true;
    rep(i, G[v].size()){
        int u = G[v][i], w = match[u];
        if(w < 0 || !used[w] && dfs(w)){
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}
 
ll solve(){
    ll ret = 0;
    memset(match, -1, sizeof(match));
    rep(v, V){
        if(match[v] < 0){
            memset(used, 0, sizeof(used));
            if(dfs(v)) ret++;
        }
    }
    return ret;
}
 
int main(){
 
    ll n, m;
    /*
    vector<int> prime;
    vector<bool> used(10000001);
    REP(i, 2, 10000001){
        if(!used[i]) prime.push_back(i);
        for(int j = 2; i * j < 10000001; j++) used[i*j] = true;
    }
    */
     
    while(cin >> n >> m){
        if(n == 0 && m == 0) break;
         
        rep(i, MAX_V) G[i].clear();
        V = n + m;
        vector<ll> b(n), r(m);
        rep(i, n) cin >> b[i];
        rep(i, m) cin >> r[i];
         
        rep(i, n){
            rep(j, m){
                if(__gcd(b[i], r[j]) != 1){
                        G[i].push_back(n+j);
                        G[n+j].push_back(i);
                }
            }
        }
     
        cout << solve() << endl;
     
         
    }
     
    return 0;
}

Measured memory_bytes: 5208
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] c = new int[3][3];
        int[][] c2 = new int[3][3];        
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                c[i][j] = sc.nextInt();
                c2[i][j] = c[i][j];
            }
        }

        for(int i=0; i<3; i++){
            c[i][2] -= c[i][0];
            c[i][1] -= c[i][0];
        }
        for(int i=0; i<2; i++){
            if(c[0][i+1] != c[1][i+1] || c[2][i+1] != c[1][i+1]){
                System.out.println("No");
                return;
            }
        }

        for(int i=0; i<3; i++){
            c2[2][i] -= c2[0][i];
            c2[1][i] -= c2[0][i];
        }
        for(int i=0; i<2; i++){
            if(c2[i+1][0] != c2[i+1][1] || c2[i+1][2] != c2[i+1][1]){
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
    }   
}

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

using namespace std;

char s[3100], t[3100];

void LCS(int n, int m) {
	int lembra[n+1][m+1]; 
	for(int i = 0; i <= n; ++i) {
		for(int j = 0; j <= m; ++j) {
			if(i == 0 || j == 0)
				lembra[i][j] = 0;
			else if (s[i-1] == t[j-1]) {
				lembra[i][j] = lembra[i-1][j-1] + 1;
			} else {
				lembra[i][j] = max(lembra[i-1][j], lembra[i][j-1]);
			}
		}
	}
	int i = n, j = m;
	int k = lembra[n][m];
	char * ans = (char *) malloc((n+1) * sizeof(char));
	ans[k] = '\0';
	while(i > 0 && j > 0) {

		if(s[i-1] == t[j-1]) {
			ans[k-1] = s[i-1];
			--i; --j; --k;
		} else {
			(lembra[i][j-1] > lembra[i-1][j]) ? --j:--i;
		}
	}


	printf("%s\n", ans);
}



int main() {

	scanf(" %[^\n]", s);
	scanf(" %[^\n]", t);
	int tams = strlen(s), tamt = strlen(t);
	LCS(tams, tamt);
	return 0;
}

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

int w;
int dp[15];
int ans;
const int g[3] = {2, 3, 5};
const int v[3] = {380, 550, 850};
const int n[3] = {5, 4, 3};
const double t[3] = {0.8, 0.85, 0.88};
void rec1(int p, int value, int weight) {
  bool flag = false;
  for(int i = p; i < 3; ++i) {
    if(weight + g[i]*n[i] <= w) {
      rec1(i, value + (int)(v[i]*n[i]*t[i]+0.5), weight + g[i]*n[i]);
    } else {
      flag = true;
    }
  }
  if(flag) ans = min(ans, value + dp[w - weight]);
}

void solve() {
  w /= 100;
  ans = 99999999;
  rec1(0, 0, 0);
  cout << ans << endl;
}

void make() {
  dp[0] = 0;
  for(int i = 1; i <= 14; ++i) {
    dp[i] = 99999999;
    for(int j = 0; j < 3; ++j) {
      if(i-g[j] >= 0) dp[i] = min(dp[i], v[j] + dp[i-g[j]]);
    }
  }
}

main() {
  make();
  while((cin >> w) && w) solve();
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=100003,INF=1<<30;

int main(){
    
    int N;cin>>N;
    string S;cin>>S;
    ll mu=N,B=0,R=0,G=0,BR=0,RG=0,GB=0;
    ll ans=1;
    
    for(int i=0;i<3*N;i++){
        if(S[i]=='B'){
            if(RG){
                ans*=RG;
                RG--;
            }else if(G){
                ans*=G;
                G--;
                GB++;
            }else if(R){
                ans*=R;
                R--;
                BR++;
            }else{
                ans*=mu;
                mu--;
                B++;
            }
        }
        if(S[i]=='R'){
            if(GB){
                ans*=GB;
                GB--;
            }else if(G){
                ans*=G;
                G--;
                RG++;
            }else if(B){
                ans*=B;
                B--;
                BR++;
            }else{
                ans*=mu;
                mu--;
                R++;
            }
        }
        if(S[i]=='G'){
            if(BR){
                ans*=BR;
                BR--;
            }else if(B){
                ans*=B;
                B--;
                GB++;
            }else if(R){
                ans*=R;
                R--;
                RG++;
            }else{
                ans*=mu;
                mu--;
                G++;
            }
        }
        ans%=mod;
    }
    
    cout<<ans<<endl;
    
}





Measured memory_bytes: 900
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, Q, k;
char S[1000000];

inline ll solve(void) {
    int i, j;
    ll cd = 0, cm = 0, cdm= 0, ans = 0;
    for(i = 0; i < k - 1; i++) {
        if(S[i] == 'D') {
            cd++;
        } else if(S[i] == 'M') {
            cm++;
            cdm += cd;
        } else if(S[i] == 'C') {
            ans += cdm;
        }
    }
    for(j = 0; i < N; i++, j++) {
        if(S[i] == 'D') {
            cd++;
        } else if(S[i] == 'M') {
            cm++;
            cdm += cd;
        } else if(S[i] == 'C') {
            ans += cdm;
        }
        if(S[j] == 'D') {
            cd--;
            cdm -= cm;
        } else if(S[j] == 'M') {
            cm--;
        }
    }
    return ans;
}

int main() {
    scanf("%d\n", &N);
    scanf("%s\n", S);
    scanf("%d\n", &Q);
    REP(i, Q) {
        scanf("%d", &k);
        printf("%lld\n", solve());
    }
	return 0;
}

Measured memory_bytes: 1280
// https://atcoder.jp/contests/abc082/tasks/abc082_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  string s, t;

  cin >> s >> t;

  sort(ALL(s));
  sort(ALL(t));
  reverse(ALL(t));

  string r = "No";
  REP(i, max(s.length(), t.length()))
  {
    if (s.length() <= i)
    {
      r = "Yes";
      break;
    }
    if (s[i] == t[i])
      continue;
    r = s[i] < t[i] ? "Yes" : "No";
    break;
  }

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
#define INF 1e9+7


int main(){

    ll n;
    cin >> n;
    vector<ll> a(n),b(n);
    ll a_sum = 0,b_sum = 0;

    REP(i,n){
        cin >> a[i];
        a_sum += a[i];
    }
    REP(i,n){
        cin >>  b[i];
        b_sum += b[i];
    }
    ll times = b_sum-a_sum;/*操作回数*/
    ll a_times = 0,b_times = 0;

    REP(i,n){

        if(a[i] < b[i]){
            a_times += (b[i]-a[i]+1)/2;
        }else if(a[i] > b[i]){
            b_times += (a[i]-b[i]);
        }
    }

    if(a_times <= times && b_times <= times){/*操作回数を超えたらNo*/
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }



    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sheep = sc.nextInt();
        int wolf = sc.nextInt();
        if (sheep <= wolf) {
            System.out.println("unsafe");
        } else {
            System.out.println("safe");
        }
    }
}

Measured memory_bytes: 35872
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
bool hurui[1000000];
int main(){
    int n;
    while(scanf("%d",&n) != EOF){
        for(int i = 0;i <= n;i++)
            hurui[i] = true;

        for(int i = 2;i <= (int)sqrt(n);i++) {
            if(!hurui[i])
                continue;
            int m = i * 2;
            while(m <= n) {
                hurui[m] = false;
                m += i;
            }
        }
        int cou = 0;
        for(int i = 2;i <= n;i++) {
            if(hurui[i]) {
                cou++;
            }
        }
        printf("%d\n",cou);
    }
    return 0;
}

Measured memory_bytes: 4152