akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	int A,B,m = 0;
    char a[105],b[105];
    cin>>a>>b;
	A = strlen(a);
	B = strlen(b);
     if(A>B)
    	printf("GREATER");
    if(A<B)
    	printf("LESS");
    if(A==B)
    	for(int i = 0;i <= (A-1);i++){
    		if(a[i]>b[i])
    		{	printf("GREATER");
    			break;}
    	    else if(a[i]<b[i])
    		{	printf("LESS");
    			break;}
    	    else m++;}
    	if(m == A)
    		printf("EQUAL");
}



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


def solve():
    n = int(input())
    if n < 105:
        print(0)
        return

    ans = 0
    for i in range(105, n + 1, 2):
        t = 0
        for j in range(1, n + 1, 2):
            if i % j == 0:
                t += 1
        if t == 8:
            ans += 1
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
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++)
#define _GLIBCXX_DEBUG
static const int MAX = 200000;

int main(){
  int a, b, t, x;
  cin >> a >> b >> t;
  x = t / a;
  cout << b * x << endl;
}

Measured memory_bytes: 256
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(b<=a)  cout<<"delicious"<<endl;
    else if(b-a<=x) cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>=22){
  cout<<"bust";}
  else{cout<<"win";}
    return 0;
}

Measured memory_bytes: 256
import java.lang.Math.abs

fun main(args: Array<String>) {
    val input = readLine()!!.split(" ")
    val n = input[0].toInt()
    val l = input[1].toInt()
    var eat = 0
    if (!(l <= 0 && n + l - 1 >= 0)){
        eat = if (abs(l) > abs(n + l - 1)) n + l - 1 else l
    }
    print((n + l ) * (n + l - 1) / 2 - l * (l - 1) / 2 - eat)
}

Measured memory_bytes: 36012
def count_div(number, divisor):
    counter = 0
    while number % divisor == 0:
        counter += 1
        number = number // divisor
    return counter


if __name__ == '__main__':
    n = int(input())
    number_list = list(map(int, input().split()))

    count = 0
    for number in number_list:
        count += count_div(number, 2)

    print(count)


Measured memory_bytes: 4148
R, G, B, N = map(int, input().split())
number = [R, G, B]
number = sorted(number)
M = N // number[2]
ans = 0

if number[2] == 1:
    print((N+2)*(N+1)//2)
else:
    for i in range(0, M+1):
        value1 = i * number[2]
        L = (N-value1) // number[1]
        for j in range(0, L+1):
            value2 = j * number[1]
            if N-value1-value2 >= 0 and (N-value1-value2) % number[0] == 0:
                ans += 1
                continue
    
    print(ans)

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

typedef long long ll;

const int MAXN = 300 + 10;

int n;
ll arr[MAXN], X, D, S, ans;

int main() {
    IO::read(n);
    rep(i, 1, n) IO::read(arr[i]), X ^= arr[i];
    X ^= arr[1] ^ arr[2];
    S = arr[1] + arr[2];
    if ((S - X) & 1) { puts("-1"); return 0; }
    D = (S - X) >> 1;
    ans = D;
    if (ans > arr[1]) { puts("-1"); return 0; }
    per(i, 40, 0) {
        if (D & (1ll << i) && X & (1ll << i)) { puts("-1"); return 0; }
        if (D & (1ll << i)) continue;
        if (ans + (1ll << i) <= arr[1] && X & (1ll << i)) ans += (1ll << i);
    }
    if (ans > arr[1] || ans == 0) { puts("-1"); return 0; }
    printf("%lld\n", arr[1] - ans);
    return 0;
}

Measured memory_bytes: 3744
#include <cstdio>
#include <algorithm>

int h1, h2, m1, m2, k;

int main(){
  scanf("%d%d%d%d%d", &h1, &m1, &h2, &m2, &k);
  int l = h2*60+m2 - (h1*60+m1);
  printf("%d\n", std::max(0, l-k));
  return 0;
}



Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define mp make_pair
#define ss second
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repp(i,a,b) for(int i = a; i <= b; i++)
#define endl '\n'
#define mod 1000000007
#define mod_in(a) bin(a, mod - 2)
#define fact(n) rep(i, 1, n+1) ft.pb((ft[i-1] * i) % mod)
#define ncr(n, r) (n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n)-(r)]) % mod)) % mod) : 0LL)
#define pi 3.14159265358979323
#define INF 1e15
#define lb(v, a) lower_bound(v.begin(), v.end(), a)
#define ub(v, a) upper_bound(v.begin(), v.end(), a)

int power(int x, int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return res;
}

int bin(int x, int n){
    int res=1; x%=mod;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}

set<int> v[26];
int flag=0;
int vis[26]={0}, par[200001]={0}, top[500001], a[200006], b[200006];

void dfs(int n){
    vis[n] = 1;
    cout<<char(n + 'a');
    for(auto i: v[n]){
        if(!vis[i]) dfs(i);
    }
}

// vector<int> adj[2000005];
// vector<int> pr(2000005, 1), xx[2000005];
// void sieve(int n){ 
//     for(int p=2; p<n; p++){ 
//         if(pr[p]){ 
//             for(int i=p; i<n; i += p){
//                 pr[i]=0;
//                 xx[i].pb(p);
//             }
//         } 
//     } 
// }  
// vector<int> ft(40);

void solve(){
    int n, ans=-1, k=0; cin>>n;
    rep(i,1,1000001){
        k*=10;
        k+=7;
        k %= n;
        if(k==0){
            ans=i; break;
        }
    }
    cout<<ans<<endl;
}

signed main(){
    fast
    int t=1;
    // cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 3664
K, N = map(int, input().split())
A = [int(i) for i in input().split()]

A_dist = [0 for i in range(N)]
for i in range(N):
    if i == 0:
        A_dist[0] = A[0] + (K - A[-1])
    else:
        A_dist[i] = A[i] - A[i-1]

print(K - max(A_dist))

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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int count = 0;
  rep(i, a+1) {
    rep(j, b+1) {
      rep(k, c+1) {
        if (500 * i + 100 * j + 50 * k == x) {
          count++;
        }
      }
    }
  }
  cout << count << endl;  
}

      

Measured memory_bytes: 256
import copy
from itertools import combinations
h, w, k = map(int, input().split())
c =[input() for i in range(h)]
ans = 0
y = []
for i in range(h):
    y.append(i)
x = []
for i in range(w):
    x.append(i)
for i in range(h+1):
    ty = list(combinations(y, i))
    for j in range(w+1):
        tx = list(combinations(x, j))
        for l in ty:
            for m in tx:
                cnt = 0
                for p in l:
                    for q in m:
                        if c[p][q] == '#':
                            cnt += 1
                if cnt == k:
                    ans += 1
print(ans)

Measured memory_bytes: 9272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define str string
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 1e5 + 10;
const ll LINF = LLONG_MAX;
int main() {
    fast();

    ll n;
    cin >> n;
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    f(i,1,n)
    {
        if((1<<i)>n)
        {
            cout<<(1<<i-1)<<edl;
            break;
        }
    }   


    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

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

int main()
{
	string s,t;
	cin >> s >> t;
	
	int cnt=0;
	
	for(int i=0; i<s.length(); i++){
		if(s[i] != t[i]) 
			cnt++;
	}
	cout << cnt <<endl;
	return 0;
}


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

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

    unordered_map<char, int> mp;
    for(int i = 0; i < S[0].size() ;i++) mp[S[0][i]]++;

    for(int i = 1; i < S.size(); i++){
        unordered_map<char,int> tmp;
        for(auto e: S[i]){
            tmp[e]++;
        }
        for(auto e: mp){
            mp[e.first] = min(mp[e.first], tmp[e.first]);
        }
    }
    string ans;
    for(auto e: mp){
        for(int i = 0; i < e.second; i++){
            ans += e.first;
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans << endl;
}

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

int main(){
  int i,count=0;
  scanf("%d%d",&A,&B);
  for(i=A;i<=B;i++){
    if((i/10000)%10==i%10&&(i/1000)%10==(i/10)%10)count++;
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
using namespace std;

ll div_ceil(ll a, ll b)
{
    ll s = a / b;
    if (a % b != 0) s++;
    return s;
}

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

    ll ans = 0;
    ll prevA = 1, prevB = 1;
    while(n --)
    {
    	ll a, b;
    	cin >> a >> b;
    	
    	ll fact = max(div_ceil(prevA, a), div_ceil(prevB, b));
    	prevA = fact * a;
    	prevB = fact * b;

    }
    ans = prevA + prevB;
    cout << ans << endl;
}

Measured memory_bytes: 256
/**
*    created: 10.05.2020 21:11:42
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int n, m, x;

void sort2vectors(vector<int> &av, vector<vector<int>> &bv)
{
        int n = av.size();
        vector<int> p(n), av2(n);
        vector<vector<int>> bv2(n);
        iota(p.begin(), p.end(), 0);
        sort(p.begin(), p.end(), [&](int a, int b) { return av[a] < av[b]; });
        for (int i = 0; i < n; i++) {
                av2[i] = av[p[i]];
                bv2[i] = bv[p[i]];
        }
        av = av2;
        bv = bv2;
}


int main() {
    


    cin >> n >> m >> x;
        vector<int> c(n);
    vector<vector<int>> a(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            int y;
            cin >> y;
            a[i].push_back(y);
        }
    }
    //sort2vectors(c, a);
    int q=inf;
    for (int bit = 0; bit < (1 << n);bit++){
        vector<int> s(m);
        int ans = 0;
        for (int i = 0; i <n; i++)
        {
            if (bit & (1 << i))
            {
                ans += c[i];
                rep(k, m) s[k] += a[i][k];
                //cout << 1 ;
            }else{
                //cout << 0  ;
            }
        }
                 //   cout <<" "<<ans<< endl;
        int h = 0;
        rep(j,m){
            if(s[j]>=x){
                h++;
            }
        }
        if(h==m){
            q = min(ans, q);
        }
    }
    if(q!=inf){
        cout << q << endl;
    }else{
        cout << -1 << endl;
    }
}

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

typedef pair <int,int>  PII;
const int mo=int(1e9+7);
struct node{int c,w;}a[200010];
int n,X,Y,m1,m2,fac[200010],mn[200010],tot,mul;

bool cmp(node x,node y){return (x.c<y.c)||((x.c==y.c)&&(x.w<y.w));}

int qpow(int a,int b)
{
	int x=a;  a=1;
	while (b)
		{
			if (b&1)  a=1LL*a*x%mo;
			x=1LL*x*x%mo,b>>=1;
		}
	return a;
}

void work()
{
	scanf("%d %d %d",&n,&X,&Y),fac[0]=1,mul=1,m1=m2=Y;
	for (int i=1; i<=n; i++)
		{
			scanf("%d %d",&a[i].c,&a[i].w);
			if (a[i].w<m2)  m2=a[i].w;
			if (m2<m1)  swap(m1,m2);
		}
	for (int i=1; i<=n; i++)  fac[i]=1LL*fac[i-1]*i%mo;
	sort(a+1,a+n+1,cmp),a[n+1].w=Y;
	if (m1+m2>Y)  puts("1"),exit(0);
	for (int i=1,j=0,k=0,p; i<=n+1; i++)
		{
			if (a[i].c!=a[j].c)  mul=1LL*mul*fac[k]%mo,j=i,k=0,p=0;
			if (a[j].w!=m1)
				{
					if ((a[i].w+m1<=Y)||((p)&&(a[j].w+a[i].w<=X)))  tot++,k++,p=1;
				}else  if ((a[i].w+m1<=X)||(a[i].w+m2<=Y))  tot++,k++;
		}
	printf("%d",int(1LL*fac[tot]*qpow(mul,mo-2)%mo));
	
}

int main()
{
	work();
	return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a < b){
        for(int i=1;i<=b;i++)cout << a;
    }else{
        for(int i=1;i<=a;i++)cout << b;
    }
    cout << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
 
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    /*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        k: isize,
        s: isize,
    }

    let mut ans = 0;
    for x in 0..k+1{
        for y in 0..k+1{
            let z = s - (x + y);
            if z <= k && z >= 0 {
                ans += 1;
            }  
        }
    }
    println!("{}",ans);


}  


Measured memory_bytes: 4352
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    cin >> a;
    sort(all(a));
    int s = 0;
    forn (i, 0, k)
        s += a[i];
    cout << s;
    return 0;
}

Measured memory_bytes: 3640
//【ライブラリここから】
// 1. 入力の容易化（https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8）
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//【ライブラリここまで】

fn main() {
    input! {n: i32, x: i32, t: i32};
    let result = t * (n / x + if n % x > 0 { 1 } else { 0 });
    println!("{}", result);
}


Measured memory_bytes: 2176
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
using namespace std;
int main(){
    int N,S,x;
    cin >> N >> S;
    priority_queue<int> que;
    vector<int> vec(N+5); 
    que.push(S);
    REP(i,N){
        cin >> x;
        que.push(x);
    }
    int c,d,i=0;
    c = que.top();
    que.pop();
    while(!que.empty()){
        d = que.top();
        que.pop();
        vec[i] = d-c;
        c = d;
        i++;
    }
    for(int i=0;i<N-1;i++){
        x = gcd(vec[i],vec[i+1]);
        vec[i+1] = x;
    }

    cout << -1*vec[N-1]<<endl;;
    //this

}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> dp(n+1, INF);
	dp[0] = 0;
	for (int i = 0, c; i < m; i++) {
		cin >> c;
		for (int j = c; j <= n; j++) {
			if (dp[j - c] != INF && dp[j] > dp[j - c] + 1) {
				dp[j] = dp[j - c] + 1;
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 3172
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];

        for (int i = 0; i < N; i++) {
            p[i] = sc.nextInt();
        }

        Arrays.sort(p);

        p[N - 1] /= 2;

        int sum = 0;

        for (int i = 0; i < N; i++) {
            sum += p[i];
        }

        System.out.println(sum);

    }
}




Measured memory_bytes: 21844
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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


int main()
{
    //cout << fixed << setprecision(10);
    int N, M, X;
    cin >> N >> M >> X;

    vector<ll> C(N);
    vector<vector<ll>> A(N, vector<ll>(M));

    rep(i,N){
        cin >> C[i];
        rep(j,M){
            cin >> A[i][j];
        }
    }

    ll minc = 100100100100;
    bool f = false;

    for (ll bit = 0; bit < (1 << N) ; bit++){
        ll sumofc = 0;
        vector<ll> rikai(M);
        for (int i = 0; i < N; i++)
        {
            if((bit>>i)&0x1){
                sumofc += C[i];
                for(int j=0;j<M;j++){
                    rikai[j] += A[i][j];
                }
            }
        }

        bool tassei = true;
        for (int j = 0; j < M; j++)
        {
            if(rikai[j] < X){
                tassei = false;
            }
        }
        if(tassei){
            f = true;
            chmin(minc, sumofc);
        }
    }

    if(f){
        cout << minc << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3616
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] setting = line.split(" ");
      
        int deskA = Integer.parseInt(setting[0]);
        int deskB = Integer.parseInt(setting[1]);
        int time = Integer.parseInt(setting[2]);
      List<Long> booksA = new ArrayList<Long>();
      List<Long> booksB = new ArrayList<Long>();
      
      line = sc.nextLine();
      String[] inputA = line.split(" ");
      booksA.add(Long.parseLong("0"));
      booksB.add(Long.parseLong("0"));
      for(int i=0;i<inputA.length;i++){
        booksA.add(Long.parseLong(inputA[i]) + booksA.get(i));
      }
      line = sc.nextLine();
      String[] inputB = line.split(" ");
      for(int i=0;i<inputB.length;i++){
        booksB.add(Long.parseLong(inputB[i]) + booksB.get(i));
      }
      
      int max = 0;
      int now = deskB;
      for(int i=0;i<=deskA;i++){
        if(booksA.get(i) > time){
          break;
        }
        while(now >= 0 && time < booksA.get(i) + booksB.get(now)){
          now--;
        }
        max = Math.max(max,i+now);
      }
      
      System.out.println(String.valueOf(max));
    }
}

Measured memory_bytes: 106008
#include<bits/stdc++.h>
#define ll long long
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> h(N);
    REP(i, N) cin >> h[i];

    vector<int> dp(N);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < N; ++i) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    print(dp[N-1]);
}

int main() {

    solve();
    return 0;
}


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

using namespace std;

int ans, N, M, cst[609][309], dp[309][309];
char sir[309][309], A[309], B[309];

int solve ()
{
    for (int i=0; i<=2 * N; i++)
        for (int j=0; j<=N; j++)
            cst[i][j] = 0;
    for (int i=1; i<=N; i++)
        for (int j=1; j<=N; j++)
            cst[j - i + N][N - i] += (A[i] == B[j]);
            ///trebuie ca sa fie considerat in cost[i1][i2] ca: i1 - i2 = j - i
            ///si ca i + i1 <= N-> i1 <= N - i
    for (int i=0; i<=2 * N; i++)
        for (int j=N; j>0; j--)
            cst[i][j - 1] += cst[i][j];
    ///dp[i1][i2] daca am dat de i1 in jos primul sir si de i2 in jos pe al doilea
    dp[0][0] = cst[N][0];
    for (int i=0; i<=N; i++)
        for (int j=0; j<=N; j++)
            if (i + j)
            {
                int curr = cst[i - j + N][i];
                if (i == 0) dp[i][j] = dp[i][j - 1];
                else
                if (j == 0) dp[i][j] = dp[i - 1][j];
                else dp[i][j] = min (dp[i][j - 1], dp[i - 1][j]);
                dp[i][j] += curr;
            }
    return dp[N][N];
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d\n", &N, &M);
for (int i=1; i<=N; i++)
    scanf ("%s", sir[i] + 1);
for (int j=1; j<M; j++)
{
    for (int i=1; i<=N; i++)
        A[i] = sir[i][j], B[i] = sir[i][j + 1];
    ans += solve ();
}
printf ("%d\n", ans);

return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double a,b,c,d,e,f,g,h;
    while(cin>>a>>b>>c>>d>>e>>f){
            h=0;g=0;
    h=(d*c-a*f)/(b*d-a*e);
    g=(c-b*h)/a;
    printf("%.3lf %.3lf\n",g,h);
    }
    return 0;

}

Measured memory_bytes: 3192
using System;
using System.Linq;
using System.Numerics;

class B
{
	static void Main()
	{
		var M = 1000000007;
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int n = h[0];
		BigInteger k = h[1];

		var m1 = new int[n];
		var m2 = new int[n];
		for (int i = 0; i < h[0]; i++)
		{
			for (int j = 0; j < i; j++) if (a[j] < a[i]) m1[i]++;
			for (int j = i + 1; j < n; j++) if (a[j] < a[i]) m2[i]++;
		}
		Console.WriteLine((k * (k - 1) / 2 * m1.Aggregate((x, y) => (x + y) % M) + k * (k + 1) / 2 * m2.Aggregate((x, y) => (x + y) % M)) % M);
	}
}


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

using ll = long long;

const ll nax = 2e5 + 2;
vector<ll> edges[nax];
bool visited[nax];

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> aa(n + 1);

    for(ll i = 1; i <= n; ++i) {
        ll x;
        cin >> x;
        aa[i] = x;

        edges[i].push_back(aa[i]);
    }
    for(ll i = 1; i <= n; ++i) {
        visited[i] = false;
    }
    ll a = 1;
    ll cnt = 0;

    while(1) {

        if(cnt == k) {
            cout << a << "\n";
            break;
        }

        visited[a] = true;
        ll b = edges[a][0];


        if(a == b) {
            cout << a << "\n";
            return 0;
        }

        if(visited[b]) {

            bool vis[n + 1];
            for(ll i = 1; i <= n; ++i) {
                vis[i] = false;
            }

            ll len = 1;

            vis[a] = true;

            while(!vis[edges[a][0]]) {
                a = edges[a][0];
                ++len;
                vis[a] = true;
            }


            ll rem = (k - cnt) % len;
            ++rem;

            while(rem--) {
                a = edges[a][0];
            }

            cout << a << "\n";
            break;

        }else {
            a = edges[a][0];
        }
        ++cnt;
    }
}

Measured memory_bytes: 16080
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int pos[10][10];
/*void p(){
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			cout<<pos[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
}*/
main(){
	int tmp[3],ink2[3]={1,1,2};
	int ink[3][5][5]={
		{{0,1,0,0,0},{1,1,1,0,0},{0,1,0,0,0},{0,0,0,0,0},{0,0,0,0,0}},
		{{1,1,1,0,0},{1,1,1,0,0},{1,1,1,0,0},{0,0,0,0,0},{0,0,0,0,0}},
		{{0,0,1,0,0},{0,1,1,1,0},{1,1,1,1,1},{0,1,1,1,0},{0,0,1,0,0}}
	};
	for(int i=0;i<10;++i)
		for(int j=0;j<10;++j)
			pos[i][j]=0;
	while(cin>>tmp[0]){
		scanf(",%d,%d",&tmp[1],&tmp[2]);
		for(int i=0;i<5;++i){
			for(int j=0;j<5;++j){
				int t[2]={tmp[0]-ink2[tmp[2]-1]+i,tmp[1]-ink2[tmp[2]-1]+j};
				if(t[0]>=0 && t[0]<=9 && t[1]>=0 && t[1]<=9){
					pos[t[0]][t[1]]+=ink[tmp[2]-1][i][j];
				}
			}
		}
	}
	int ans[2]={0,0};
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			if(pos[i][j]==0)ans[0]++;
			ans[1]=max(pos[i][j],ans[1]);
		}
	}
	cout<<ans[0]<<endl<<ans[1]<<endl;
}

Measured memory_bytes: 1244
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int a, b;
    std::cin>>a>>b;

    std::cout<<((a * b) % 2 == 1 ? "Odd" : "Even")
        <<std::endl;
    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
N=int(input())
alist=list(map(int,input().split()))

cmat=[]
for i in range(H):
  cmat.append([-1]*W)

x,y=0,0
c=1
for a in alist:
  while a:
    if y<W:
      #print(x,y)
      cmat[x][y]=c
      y+=1
      a-=1
    
    if y==W:
      x+=1
      y=0
  
  c+=1
      
#print(cmat)
for i in range(1,H,2):
  cmat[i].reverse()
#print(cmat)
      
for i in range(H):
  print(*cmat[i])

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

int main() {
	
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	cout << a + b + c + max({a, b, c}) * ( (int) pow(2, k) - 1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
my ($X,$Y,$n)=+<<get.words;
my ($x,$y)=(0,0);
lines.map({
	my ($a,$b,$c)=+<<.words;
	('$x max=$a','$X min=$a','$y max=$b','$Y min=$b')[$c-1].EVAL
});
say ($X-$x max 0)*($Y-$y max 0)

Measured memory_bytes: 104544
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
#define ll long long
ll ar[N][3]; ll dp[3][N]; ll n;
ll solve(ll prev, ll row) {
	if (row >= n) {
		return 0;
	}
	if (dp[prev][row] != 0) {
		return dp[prev][row];
	}
	ll sum = 0;
	if (prev != 0) {
		sum = max(sum, ar[row][0] + solve(0, row + 1));
		//dbgm(sum);
	}  
	if (prev != 1) {
		sum = max(sum, ar[row][1] + solve(1, row + 1));
	} 
	if (prev != 2) {
		sum = max(sum, ar[row][2] + solve(2, row + 1));
	} 	
	return dp[prev][row] = sum;

}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> ar[i][j];
		}
	}
	memset(dp, 0, sizeof dp);
	ll ans = solve(3, 0);
	/*f (i, 0, 3) {
		f (j, 0, n) {
			cout << dp[i][j] << " ";
		} cout << endl;
	}*/
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <utility>

using namespace std;

// ???????????????
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=jp
//

template<typename T> 
void buble_sort(int n, T ar[]){
    bool next = true;
    while (next) {
        next = false;
        for (int i = 0; i < n - 1; i++) {
            if(ar[i] > ar[i+1]){
                swap(ar[i], ar[i+1]);
                next = true;
            }
        }
    }
}

template<typename T>
void selection_sort(int n, T ar[]){
    for (int i = 0; i < n - 1; i++) {
        int minj = i;
        for (int j = i + 1; j < n ; j++) {
            if(ar[j] < ar[minj]){
                minj = j;
            }
        }
        if(minj != i){
            swap(ar[i], ar[minj]);
        }
    }
}

class Card {
    public:
        int value;
        char suit;
        Card(){};
        Card(char suit, int value) : suit(suit), value(value){}

        bool operator >(const Card &c){
            return this->value > c.value;
        }

        bool operator <(const Card &c){
            return this->value < c.value;
        }

        bool operator ==(const Card &c){
            return this->suit == c.suit && this->value == c.value;
        }

        bool operator !=(const Card &c){
            return ! (*this == c);
        }

        friend ostream& operator << (ostream &os, const Card &c){
            os << c.suit << c.value;
            return os;
        }

        friend istream& operator >> (istream &is, Card &c){
            char s;
            int v;
            cin >> s;
            cin >> v;
            c.suit = s;
            c.value = v;
            return is;
        }
};

int main(int argc, char const* argv[])
{
    const int N = 36;
    int n;
    Card ar_b[N], ar_s[N];

    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> ar_b[i];
        ar_s[i] = ar_b[i];
    }

    buble_sort(n, ar_b);
    selection_sort(n, ar_s);

    for (int i = 0; i < n - 1; i++) {
        cout << ar_b[i] << " ";
    }
    cout << ar_b[n-1] << endl;
    cout << "Stable" << endl;

    bool is_stable = true;

    for (int i = 0; i < n - 1; i++) {
        cout << ar_s[i] << " ";
        if(ar_b[i] != ar_s[i]) is_stable = false;
    }
    cout << ar_s[n-1] << endl;

    if(is_stable){
        cout << "Stable";
    }else{
        cout << "Not stable";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		if (B%A == 0) {
			System.out.println(A+B);
		}
		else {
			System.out.println(B-A);
		}
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n; Edg
int dp[SZ][2];
void dfs(int x,int f=0)
{
	int mi=-1;
	for esb(x,e,b) if(b!=f)
	{
		dfs(b,x), dp[x][1]+=dp[b][0];
		mi=max(mi,dp[b][1]-dp[b][0]);
	}
	dp[x][0]=dp[x][1]+mi+1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1,a,b;i<n;++i)
		scanf("%d%d",&a,&b),adde(a,b);
	dfs(1);
	if(max(dp[1][0],dp[1][1])*2==n)
		puts("Second");
	else puts("First");
}


Measured memory_bytes: 9216
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &stream, const std::vector<T> &vec) {
  for (auto val : vec) {
    if (std::is_fundamental<T>::value)
      stream << " " << val;
    else
      stream << std::endl << val;
  }
  return stream;
}

int main() {
  int N;
  std::cin >> N;
  std::vector<int> X(N);
  for (int i = 0; i < N; ++i)
    std::cin >> X[i];

  int res = IINF;
  for (int x = 1; x <= 100; ++x) {
    int sum = 0;
    for (int i = 0; i < N; ++i) {
      sum += (X[i] - x) * (X[i] - x);
    }
    chmin(res, sum);
  }
  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 256
# 振るのは最強のやつだけ
# 投げるのは強い順

N,H = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
A,B = zip(*AB)

a = max(A) # 振る
B = [b for b in B if b > a] # 投げる価値あり
B.sort(reverse = True)

answer = 0
hp = H
attack_cnt = 0

for b in B:
  if hp <= 0:
    break
  attack_cnt += 1
  hp -= b

if hp > 0:
  attack_cnt += (hp-1)//a + 1

print(attack_cnt)

Measured memory_bytes: 29868
// template version 1.13
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_pair(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  string s;cin>>s;
  if (n%2!=0){
    cout << "No" << endl;
    return 0;
  }
  else{
    rep(i, n/2){
      if (s[i]!=s[i+n/2]){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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


int main() {
  int N,x;
  x = 0;
  cin >> N;
  for(int i = 0;i < N;i++){
    int a,b;
    cin >> a >> b;
    x += b-a+1;
  }
  cout << x;
}



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

namespace AABC
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] k = Console.ReadLine().Split(' ');
            int[] xy = new int[4];
            for(int i = 0; i < k.Length; i++)
            {
                xy[i] = int.Parse(k[i]);
            }

            //xyの距離
            int xd = xy[2] - xy[0];
            int yd = xy[3] - xy[1];

            int x3 = xy[2] - yd;
            int y3 = xy[3] + xd;

            int x4 = x3 - xd;
            int y4 = y3 - yd;




            Console.WriteLine(x3 + " " + y3 + " " + x4 + " " + y4);

        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main(){



int a[1000];
    int n;
    
    cin>>n;
    int i;
    for(i=0;  i<=n; i=i+1){
        cin>>a[i];
    }

    int j;
    for(j=n-1;j>-1; j=j-1){
      
      cout << a[j];
      if(j>0){ cout <<" ";}
      if(j==0){ cout<<endl;}
        
    }

}


Measured memory_bytes: 3088
#include <iostream>
#include <queue>
#include <utility>
#include <algorithm>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ff first
#define ss second

using namespace std;

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

    int n; cin >> n;
    int A[n], B[n];
    for(int i = 0; i < n; ++i) cin >> A[i];
    for(int i = 0; i < n; ++i) cin >> B[i];

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

    priority_queue<pii> Q;
    for(int i = 0; i < n; ++i)
        if(A[i] != B[i]) Q.push({B[i], i});

    long long ans = 0;
    while(!Q.empty())
    {
        pii tmp = Q.top(); Q.pop();

        int x = (tmp.ss + n - 1) % n;
        int y = tmp.ss;
        int z = (tmp.ss + 1) % n;

        int cnt = (B[y] - A[y]) / (B[x] + B[z]);
        int tar = B[y] - cnt * (B[x] + B[z]);
        ans += cnt;
        if(tar == B[y]) {ans = -1; break;}
        B[y] = tar;
        if(tar != A[y]) Q.push({B[y], y});
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 3956
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n, m;
long long target;
long long a[200010];
long long b[200010];

long long sumA[200010];
long long sumB[200010];

int main()
{
	scanf("%d%d%lld", &n, &m, &target);
	
	sumA[0] = 0;
	for (int i = 1 ; i <= n ; i++) {
		scanf("%lld", &(a[i]));
		sumA[i] = sumA[i - 1] + a[i];
	}
		
	sumB[0] = 0;
	for (int i = 1 ; i <= m ; i++) {
		scanf("%lld", &(b[i]));
		sumB[i] = sumB[i - 1] + b[i];
	}
	
	int pA = 0;
	while (((pA + 1) <= n) && (sumA[pA + 1] <= target)) {
		pA++;
	}
	
	long long left = target - sumA[pA];
	int pB = 0;	
	while (((pB + 1) <= m) && (sumB[pB + 1] <= left)) { 
		pB++;
	}
	
	int maxCount = pA + pB;
	while (pA >= 0) {
		left = target - sumA[pA];
		while (((pB + 1) <= m) && (sumB[pB + 1] <= left)) { 
			pB++;
		}
		
		int curCount = pA + pB;
		if (curCount > maxCount)
			maxCount = curCount;
		pA--;
	}
	
	printf("%d\n", maxCount);

	return 0;
}


Measured memory_bytes: 7976
from collections import Counter
def comb(n, r = 2):
    if n < 2:
        return 0
    return n * (n - 1) // 2
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    All = [0] * (n + 1)
    All_1 = [0] * (n + 1)
    for k, v in C.items():
        All[k] = comb(v)
        All_1[k] = comb(v - 1)
    sum_all = sum(All)
    for a in A:
        print(sum_all - (All[a] - All_1[a]))
solve()


Measured memory_bytes: 25896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;cin>>n;
    int tmp,result=0;
    REP(i,n){
        cin>>tmp;
        result+=tmp-1;
    }
    cout<<result<<endl;
    return 0;
}


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

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

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

	string ans = "No";
	if (x >= 30) ans = "Yes";
	cout << ans << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

template <typename T>
T pow(T x, T n )
{
	T res = 1;
	while (n > 0)
	{
		if (n & 1)
			res = (res * x);
		x = (x * x);
		n >>= 1;
	}
	return res;
}

int main()
{
	int m,k; cin>>m>>k;
	int m2 = pow(2,m);

	if( m == 1 )
	{
		if(k == 0 ) REP( i, m2 )
		{
			cout << i << " " << i << " ";
		}
		else cout << -1;
	}
	else if( !( 0 <= k && k < m2 ) ) cout << -1 << endl;
	else
	{
		cout << k;
		REP(i,m2) {
			if( i == k ) continue;
			cout << " " << i;
		}
		cout << " " << k;
		BREP(i,m2) {
			if( i == k ) continue;
			cout << " " << i;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
#define INF 1 << 30
#define MOD 1000000007;
#define pi 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
static const int dx[] = {0, 0, 1, -1};
static const int dy[] = {-1, 1, 0, 0};

int main() { 
  int n;
  cin >> n;
  ll a[3 * n];
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }

  sort(a, a + 3 * n);

  int f = 0;
  int e = 3 * n - 1;

  ll ans = 0;
  while (f < e) {
    e--;
    ans +=a[e];
    e--;
    f++;
  }

  D(ans);

  return 0;
}



Measured memory_bytes: 2560
#include <cstdio>
#include <cmath>

int main() {
  int D, E;
  while (true) {
    scanf("%d %d", &D, &E);
    if (D == 0 && E == 0) break;
    double d = 20000;
    for (int x=0;x<=D;x++) {
      const int y = D-x;
      d = fmin(fabs(sqrt(x*x+y*y)-E), d);
    }
    printf("%f\n", d);
  }
  return 0;
}

Measured memory_bytes: 2588
/* BABA JAGAAAAAA  */  

#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define fast ios:: sync_with_stdio(false);cin.tie(NULL)
#define l1 long 
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;
 int check(vector<char>v1, vector<char>v2)
 {
     int count=0;
      for(int i=0; i<min(v1.size(),v2.size()); i++)
      {
           if(v1[i]!=v2[i])
           {
               continue;
           }
           count++;
      }
      return count;
      
 }
 int main()
 {
     fast;  
    // 2nd//
    string s,t;
     cin>>s>>t;
     int l,r;
     l=0;
     r=0;
     vector<char> v;
     vector<char>v1;
      for(char f:t)
      v1.pb(f);
     
      int maxi=0;
     while(r<t.size())
     {
             v.pb(s[r]);
             r++;
     }
     int n= check(v,v1);
    //  cout<<n;
    //   for(int i=0; i<v.size(); i++)
    //   cout<<v[i]<<" ";
     maxi=max(maxi,n);
    //   cout<<maxi;


     while(r<s.size())
     {
         v.pb(s[r]);
         v.erase(v.begin()+l);
         
        //  for(int i=0; i<v.size(); i++)
        //   cout<<v[i];
        //   cout<<endl;
         int n= check(v,v1);
         maxi=max(maxi,n);
        //  l++;
         r++;
         
     }
     
  cout<<t.size()-maxi<<endl;
     
    
       return 0;
     
 }
  

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

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

int n, m, p[1001];

void solve() {
  rep(i,n) cin>>p[i];
  
  int rest = n, res = 0;
  while (rest >= m) {
    rep(z,m-1) {
      int l, most = 0;
      rep(i,n) if (most < p[i]) {
        l = i; most = p[i];
      }
      res += p[l]; p[l] = -1; rest--;
    }
    int l, most = 0;
    rep(i,n) if (most < p[i]) {
      l = i; most = p[i];
    }
    p[l] = -1; rest--;
  }
  
  rep(i,n) if (p[i] != -1) {
    res += p[i];
  }
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n>>m, n||m) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 0