akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,w;cin>>n>>w;
    long long int wt[n],vl[n];
    for(int i=0;i<n;i++){
        cin>>wt[i]>>vl[i];
    }
     long long ans[100001]={0};
    for(int i=1;i<=100000;i++)
        ans[i]=INT_MAX;
    for(long long int i=0;i<n;i++){
        for(long long int j=100000;j>=vl[i];j--){
            ans[j]=min(ans[j],wt[i]+ans[j-vl[i]]);
        }
    } 
    for(int i=100000;i>=0;i--)
	{
    	if(ans[i]<=w)
		{
			cout<<i;
    		return 0;
		}
	}
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  int hMax = 0;
  rep(i, n) hMax = max(hMax, h[i]);
  int ans = 0;
  vector<bool> done(n, false);
  rep(i, hMax) {
    bool before = true;
    rep(j, n) {
      if (h[j] <= i) {
        done[j] = true;
      }
      if (before == true && done[j] == false) ans++;
      before = done[j];
    }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define all(a) a.begin(),a.end()
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//sort 降順
//reverse 逆順
 
int main() {
  ll a,b,c,d;
  ll x=0;
  ci(a>>b>>c>>d);
  for(i,0,a){
    if(i<b)
      x+=c;
    else
      x+=d;
  }
  co(x);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 9e5 + 5, MOD = 1e9 + 7;
int fac[N], rev[N];
int mpow(int x, int n) {
	int res = 1;
	while (n) {
		if (n & 1) res = 1LL * res * x % MOD;
		x = 1LL * x * x % MOD;
		n >>= 1;
	}
	return res;
}
int C(int n, int m) {
	return 1LL * fac[n] * rev[m] % MOD * rev[n - m] % MOD;
}
int main() {
	fac[0] = rev[0] = 1;
	for (int i = 1; i < N; ++ i) {
		fac[i] = 1LL * fac[i - 1] * i % MOD;
		rev[i] = mpow(fac[i], MOD - 2);
	}
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	int ans = 0;
	int l = 0, r = 0, sum = 1;
	for (int s = 0; s <= m + k; ++ s) {
		int res = 1LL * C(s + n - 1, s) * mpow(3, m + k - s) % MOD;
		int L = max(0, s - k), R = min(m, s);
		while (l > L) (sum += C(s, -- l)) %= MOD;
		while (r < R) (sum += C(s, ++ r)) %= MOD;
		while (l < L) (sum += MOD - C(s, l ++)) %= MOD;
		while (r > R) (sum += MOD - C(s, r --)) %= MOD;
		(ans += 1LL * res * sum % MOD) %= MOD;
		sum = (2LL * sum + MOD - C(s, l) + MOD - C(s, r)) % MOD;
		l ++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int x,n,ans;
    cin>>x>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<105;i++){
        if(!binary_search(a,a+n,x-i)){
            ans=x-i;
            break;
        }
        if(!binary_search(a,a+n,x+i)){
            ans=x+i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    int N;
    cin >> N;

    unsigned int a[200000];
    unsigned int num[200000];
    unsigned int all = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        all ^= a[i];
    }
    for(int i = 0; i < N; i++){
        num[i] = all ^ a[i];
    }

    for(int i = 0; i < N - 1; i++){
        cout << num[i] << " ";
    }
    cout << num[N-1] << endl;
}


Measured memory_bytes: 5184
import heapq
N = int(input())
h = list(map(int, input().split()))
heapq.heapify(h)

while len(h) > 1:
  monster = heapq.heappop(h)
  tmp = [monster]
  heapq.heapify(tmp)
  while len(h) > 0:
    num = heapq.heappop(h) % monster
    if num != 0:
      heapq.heappush(tmp, num) 
  h = tmp
print(heapq.heappop(h))

Measured memory_bytes: 14184
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    cout << (x<1200 ? "ABC" : "ARC") << endl;
}


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

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

    int A[10];
    A[9] = 1111;
    for (int i = 1; i < 10; i++) A[i - 1] = 111 * i;

    int result = 0;
    for (int i = 0; i < 10 && result == 0; i++) {
        if (N <= A[i]) result = A[i];
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
book = [list(map(int, input().split())) for i in range(n)]

min_num = 10**18

for i in range(1<<n):
    cost = 0
    l = [0]*m
    for j in range(n):
        if (i>>j)&1:
            c, *a = book[j]
            cost += c
            for k ,ak in enumerate(a):
                l[k] += ak
    if all(lj >= x for lj in l):
        min_num = min(min_num,cost)

print(-1 if min_num == 10**18 else min_num)


Measured memory_bytes: 9208
#include "bits/stdc++.h"
using namespace std;

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 <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int N; 

int main(){
  cin >> N;
  vector<int> vec(N);
  rep(i,N) cin >> vec[i];
    
  vector<int> vec_sorted(vec.begin(), vec.begin()+N);
  sort(vec_sorted.begin(), vec_sorted.end());
  
  int count = 0;
  bool flag=true;
  rep(i,N){
    if(vec[i]!=vec_sorted[i]){
      count++;
      if(count>2){flag=false; break;}
    }
  }
  cout << (flag ? "YES\n" : "NO\n"); 
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
  int d[100]={0};
  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> d[i];
  }
  for(int i=n-1; i>=0; i--){
    cout << d[i];
    if(i) cout << ' ';
  }
  cout << endl;
  return 0;
}



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

int main()
{
	int x;
	bool flag = false;
	cin >> x;
	if (x <= 99)
	{
		cout << 0 << endl;
		return 0;
	}
	
	int check = x / 100;
	
	for (int i = check * 100; i <= check * 105; ++i)
	{
		if (i == x)
		{
			flag = true;
		}
	}
	
	if (flag)
	{
		cout << 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python

import sys

if True:
    from sys import stdin as inputs
else:
    from test_aoj0502 import inputs

class Die:
    def __init__(self, **argv):
        if argv:
            self.faces = dict(argv)
        else:
            self.faces = dict(top=1,
             north=5,
             east=3,
             south=2,
             west=4,
             bottom=6)

    def North(self):
        return Die(
                top=self.faces["south"],
                north=self.faces["top"],
                east=self.faces["east"],
                west=self.faces["west"],
                south=self.faces["bottom"],
                bottom=self.faces["north"])
    def East(self):
        return Die(
                top=self.faces["west"],
                north=self.faces["north"],
                east=self.faces["top"],
                west=self.faces["bottom"],
                south=self.faces["south"],
                bottom=self.faces["east"])
    def South(self):
        return Die(
                top=self.faces["north"],
                north=self.faces["bottom"],
                east=self.faces["east"],
                west=self.faces["west"],
                south=self.faces["top"],
                bottom=self.faces["south"])
    def West(self):
        return Die(
                top=self.faces["east"],
                north=self.faces["north"],
                east=self.faces["bottom"],
                west=self.faces["top"],
                south=self.faces["south"],
                bottom=self.faces["west"])
    def Right(self):
        return Die(
                top=self.faces["top"],
                north=self.faces["west"],
                east=self.faces["north"],
                west=self.faces["south"],
                south=self.faces["east"],
                bottom=self.faces["bottom"])
    def Left(self):
        return Die(
                top=self.faces["top"],
                north=self.faces["east"],
                east=self.faces["south"],
                west=self.faces["north"],
                south=self.faces["west"],
                bottom=self.faces["bottom"])


for line in inputs:
    line = line.strip()
    try:
        n = int(line)
    except:
        n = None
    if n is None:
        count -= 1
        f = getattr(die, line)
        die = f()
        s += die.faces["top"]
        if count == 0:
            print s
    elif n == 0:
        sys.exit()
    else:
        die = Die()
        count = n
        s = 0
        s += die.faces["top"]

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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 60;
const int maxN = 400;

int dp[maxN][maxN];
int a[maxN];

int rec(int l, int r) {
	if (l == r) return 0;
	if (dp[l][r]) return dp[l][r];
	int sum = 0;
	dp[l][r] = INF;
	for (int i = l; i <= r; i++) {
		sum += a[i];
		if(i < r) dp[l][r] = min(dp[l][r], rec(l, i) + rec(i + 1, r));
	}
	dp[l][r] += sum;
	return dp[l][r];
}

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

	cout << rec(0, n - 1);
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}


Measured memory_bytes: 1664
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scan s = new Scan();
        long N = s.nL();
        long A = s.nL();
        long B = s.nL();
        if(A == 0){
            System.out.println(0);
        }else{
            long rest = N % (A+B);
            long result = rest - A <= 0 ? A * (N / (A+B)) + rest : A * (N / (A+B)) + A;
            System.out.println(result);
        }
    }
    
    static class Scan{
        private static Scanner sc = new Scanner(System.in);
        public static int nI(){
            return Integer.parseInt(sc.next());
        }
        public static long nL(){
            return Long.parseLong(sc.next());
        }
        public static String nS(){
            return sc.next();
        }
        public static double nD(){
            return Double.parseDouble(sc.next());
        }
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(void){
    int n, tmp;cin>>n;
    vector<int> p, q, array1, array2;
    rep1(i,n){array1.emplace_back(i);}
    rep1(i,n){array2.emplace_back(i);}
    rep(i,n){cin>>tmp;p.emplace_back(tmp);}
    rep(i,n){cin>>tmp;q.emplace_back(tmp);}
    int cntp=0, cntq=0;
    do{
        cntp++;
        if(array1==p)break;
    }while(next_permutation(array1.begin(), array1.end()));

    do{
        cntq++;
        if(array2==q)break;
    }while(next_permutation(array2.begin(), array2.end()));

    co(abs(cntp-cntq));

}


Measured memory_bytes: 256
# coding: utf-8

H = int(input().rstrip())
Ai = [int(i) for i in input().rstrip().split()]

def maxHeapify(A, i):
    l = 2*i
    r = 2*i+1
    if l <= H and Ai[l-1] > Ai[i-1]:
        largest = l
    else:
        largest = i
    if r <= H and A[r-1] > A[largest-1]:
        largest = r
    
    if largest != i:
        Ai[i-1], Ai[largest-1] = Ai[largest-1], Ai[i-1]
        maxHeapify(A, largest)

def buildMaxHeap(A):
    for i in range(H//2,0,-1):
        maxHeapify(A, i)

buildMaxHeap(Ai)
for a in Ai:
    print(" "+str(a),end="")
print()


Measured memory_bytes: 63972
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}
long long gcd(long long a,long long b){
  if(b==0){
    return a;
  }
  return gcd(b,a%b);
}
long long lcm(long long a,long long b){
  long long g=gcd(a,b);
  return a/g*b;
}
long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}







int main(){
  long long N,M;
  cin>>N>>M;
  if(abs(N-M)>1){
    cout<<0<<endl;
  }else{
    long long NN=kaijo(N);
    long long MM=kaijo(M);
    if(N==M){
      long long ans=NN*MM;
      if(ans>10*10*10*10*10*10*10*10*10+7){
        ans%=10*10*10*10*10*10*10*10*10+7;
      }
      ans*=2;
      if(ans>=10*10*10*10*10*10*10*10*10+7){
        ans%=10*10*10*10*10*10*10*10*10+7;
      }
      cout<<ans<<endl;

    }else{
      long long ans=NN*MM;
      if(ans>10*10*10*10*10*10*10*10*10+7){
        ans%=10*10*10*10*10*10*10*10*10+7;
      }
      cout<<ans<<endl;
    }


  }

}



  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a - 1) * (b - 1) << endl;
  return 0;
}

Measured memory_bytes: 3468
import sys
sys.setrecursionlimit(500000)
N = int(input())
A = [list(map(int,input().split())) for _ in range(2)]
ans = 0
for i in range(2):
    for j in range(N):

        ans = max(ans, sum(A[0][:j+1])+sum(A[1][j:]))
print(ans)

Measured memory_bytes: 3064
x, y = map(int, input().split())

ans = 'No'

for a in range(1, x+1):
    b = x - a
    if b == x:
        break
    if 2*a + 4*b == y or 2*b + 4*a == y:
        ans = 'Yes'
        break

print(ans)

Measured memory_bytes: 9180
n = int(input())
a = [i for i in map(int, input().split())]

if a.count(0) != 0:
    print(0)
else:
    result = 1
    for i in range(n):
        result *= a[i]
        if result > (10**18):
            print(-1)
            break
        else:
            continue
    else:
        print(result)

Measured memory_bytes: 21616
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n;
    vl v;
    cin >> n ;
    forn(i , 1 , n ) {
       ll x;
       cin >> x;
       v.pb(x) ;
    }
    sort(all(v));
    unordered_map<ll , ll > cnt , cntt;
    for(auto &x : v){
        cnt[x]++;
    }
    vl vv ;
    ll flag = -1;
    for(auto &x : cnt){
        ll val = x.fi ;
        ll times = x.se ;
        if(times % 2 == 1){
            cntt[val] = 1;
            vv.pb(val);
            con ;
        }
        else if(times % 2 == 0){
            cntt[val] = 2 ;
            ++flag ;
            vv.pb(val);
            vv.pb(val) ;
        }
    }
    sort(all(vv));
    if(flag == -1){
        cout << vv.sz << el ;
        ro ;
    }
    else {
        ll nos = 0 ;
        for(auto &x : cntt){
            if(x.se == 2) ++nos;
        }
        ll nn = vv.sz ;
        if(nos == 1){
            nn = nn - 2 ;
            cout << nn << el ;
            ro ;
        }
        else{
            if(nos % 2 == 0 ){
                nn = nn - nos ;
                cout << nn << el ;
                ro;
            }
            else if(nos % 2 == 1){
                ll tot = 2*nos ;
                ll rem = nn - tot;
                tot = tot / 2 ;
                rem = rem - 1 ;
                ll ns = tot + rem;
                cout << ns << el ;
                ro ;
            }
        }
    }
    ro ;
}





Measured memory_bytes: 10100
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
ll x, k, d;
ll ans = llinf;

inline void solve()
{
    cin >> x >> k >> d;
    ll cnt = min(k, abs(x) / d);
    k -= cnt;
    ll now = (x < 0) ? x + cnt * d : x - cnt * d;
    ans = abs(now);
    x = now;
    if (k)
    {
        if (k & 1)
            ans = abs((x < 0) ? x + d : x - d);
    }
    cout << ans << endl;
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
        solve();
    TIME__END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
char s[10010];
int ans;
bool C=false,F=false;
int main()
{
	gets(s);
	int len=strlen(s);
	for (int i=0;i<len;i++)
	{
		if(s[i]=='C')
			C=true;
		if(s[i]=='F' && C)
			F=true;
	}
	if(C && F)
		puts("Yes");
	else
		puts("No");
	
	
		
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
def solve(h, w):
    res = 10 ** 9
    for i in range(1, h):
        s1 = i * w
        h1 = h - i
        w1 = w // 2
        w2 = w - w //2
        s2 = h1 * w1
        s3 = h1 * w2
        diff = max([s1, s2, s3]) - min([s1, s2, s3])
        if res > diff:
            res = diff
        h2 = h1 // 2
        h3 = h1 - h1 // 2
        s2 = h2 * w
        s3 = h3 * w
        diff = max([s1, s2, s3]) - min([s1, s2, s3])
        if res > diff:
            res = diff
    return res
print(min(solve(H, W), solve(W, H)))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

ll f(ll A, ll B) {
    ll lim = A*B;
    ll ok = 0, ng = B;
    while (ng - ok > 1) {
        ll mid = (ok + ng) / 2;
        bool f = true;
        if (mid * (A + 1) >= lim)f = false;
        ll x = (A + mid + 1) / 2;
        ll y = x*(A + 1 + mid - x);
        if (x <= mid && y >= lim)f = false;
        (f ? ok : ng) = mid;
    }
    RT ok;
}

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

    int Q;
    cin >> Q;
    while (Q--) {
        ll A, B;
        cin >> A >> B;
        ll bb = f(A, B);
        ll aa = f(B, A);
        ll ans = aa + bb;
        ll x = B - bb - 1, y = A - aa - 1;
        ans += min(x, y);
        cout << ans << endl;
    }
}

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

using namespace std;

#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//Debug
string to_string(const string& s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A, typename B>
string to_string(pair<A, B> p) {return "("+to_string(p.fi)+", "+to_string(p.se)+")";}
template <typename A>
string to_string(A v) {
	if(v.begin()==v.end()) return "";
	return accumulate(++v.begin(), v.end(), "{"+to_string(*v.begin()),
			[](const string& a, auto b){ return a + ", " + to_string(b);})+"}";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) false
#endif


double PI=3.141592653589793;


int h,w,kmod,s[2][2];

vector<vector<int>> dis[4];
vector<vector<bool>> in;

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

void solve(){
	cin >> h >> w >> kmod;
	forn(i,2) forn(j,2){ cin >> s[i][j];s[i][j]--;}

	in.resize(h,vector<bool>(w));
	forn(k,4) dis[k].resize(h,vector<int>(w));

	forn(i,h){
		forn(j,w){
			char k;cin >> k;
			in[i][j]=(k=='.');
		}
	}

	queue<pair<pii,int>> proc;	
	forn(k,4){
		forn(i,h){
			forn(j,w){
				dis[k][i][j]=INT_MAX;
			}
		}

	   	dis[k][s[0][0]][s[0][1]]=0;
		proc.push({{s[0][0],s[0][1]},k});
	}


	while(!proc.empty()){
		auto tp=proc.front();
		proc.pop();
		int i=tp.fi.fi,j=tp.fi.se,ki=tp.se;
		int cdis=dis[ki][i][j];
		forn(k,4){
			int ni=i+dx[k],nj=j+dy[k];
			if(ni<0||ni>=h||nj<0||nj>=w) continue;
			if(!in[ni][nj]) continue;

			int ndis;
			if(ki!=k) ndis=(cdis+kmod-1)/kmod*kmod+1;
			else ndis=cdis+1;


			if(ndis>=dis[k][ni][nj]) continue;

			dis[k][ni][nj]=ndis;
			proc.push({{ni,nj},k});
		}
	}

	int mn=INT_MAX;
	forn(k,4){
		int cur=dis[k][s[1][0]][s[1][1]];
	   	if(cur!=INT_MAX) mn=min(mn,(cur+kmod-1)/kmod);
	}
	if(mn==INT_MAX) cout << -1;
	else cout << mn;

}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
		//	cout << "Case #" << cid << ": ";
		solve();
	}
}


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

#define ll long long
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main()
{
    fast();
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n,m,k;
        cin>>n>>m;

        set<int>s1;
        set<int>s2;

        for(ll i=0;i<n;i++)
        {
            cin>>k;
            if(i==0)
            {
                for(ll j=0;j<k;j++)
                {
                    int x;
                    cin>>x;
                    s1.insert(x);
                }
            }

            else
            {
                for(ll j=0;j<k;j++)
                {
                    int x;
                    cin>>x;

                    if(s1.find(x)!=s1.end())
                        s2.insert(x);
                }
                s1.swap(s2);
                s2.clear();
            }
        }
        cout<<s1.size();
    }
}


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

const int N = 1e5 + 10;

int pre[N];
int suf[N];
int n, a[N];

int Gcd(int a, int b) {
    if (b == 0) return a;
    else return Gcd(b, a%b);
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    pre[0] = 0, suf[n+1] = 0;
    for (int i = 1; i <= n; i++) {
        pre[i] = Gcd(pre[i-1], a[i]);
    }
    for (int i = n; i >= 1; i--) {
        suf[i] = Gcd(suf[i+1], a[i]);
    }
    int ans = -1;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, Gcd(pre[i-1], suf[i+1]));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1408
a,b,c,d=map(int,input().split())

if a >= 0:
  if c>=0:
    ans = b*d
  elif d >=0:
    ans=b*d
  else:
    ans=a*d
else:
  if b>=0:
    if c>=0:
      ans = b*d
    elif d >=0:
      if a*c < b*d:
        ans = b*d
      else:
        ans= a*c
    else:
      ans=a*c
  elif c>=0:
    ans=b*c
  else:
    ans= a*c
print(ans)

Measured memory_bytes: 9132
#include <iostream>
#include <stack>
//#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int,int> > S2;
  char ch;
  int sum=0;
  for (int i=0; cin >> ch; i++) {
    if (ch=='\\') {
      S1.push(i);
    } else if (ch=='/' && S1.size()>0) {
      int j=S1.top();
      S1.pop();
      sum+=i-j;
      int a=i-j;
      while (S2.size()>0 && S2.top().first>j) {
	a+=S2.top().second;
	S2.pop();
      }
      S2.push(make_pair(j,a));
    }
  }
  vector<int> ans;
  while (S2.size()>0) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(),ans.end());
  cout << sum << endl;
  cout << ans.size() << flush;
  for (int i=0; i<ans.size(); i++) {
    cout << " " << flush;
    cout << ans[i] << flush;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3188
import java.util.*;

public class Main {


    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int[] arr = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

        int k = sc.nextInt();

        System.out.print(arr[k-1]);


    }
}



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

int main() {
int N;
  cin >> N;
  int i;
  for(i=0; i<N; i++){
    string X;
    cin >> X;
      
    if(X == "Y"){
      cout << "Four" << endl;
    break;
    }
    else if(i == N-1)
      cout << "Three" << endl;
    
    else; 
  }
}

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

int h, w;
char area[20][20];
int dx[] = {
	1, 0, -1, 0
};
int dy[] = {
	0, 1, 0, -1
};

int min_count = 11;

void move(int i, int j, int n){
	if(n >= 10) return;
	for(int k = 0; k < 4; k++){
		int y1 = i;
		int x1 = j;
		if(y1+dy[k] < h && y1 + dy[k] >= 0 && x1+dx[k] < w && x1+dx[k] >= 0)
			if(area[y1+dy[k]][x1+dx[k]] != '1')
				while(y1 < h && y1 >= 0 &&
						x1 < w && x1 >= 0 && area[y1][x1] == '0')
				{
					y1 += dy[k];
					x1 += dx[k];
				}
				if(y1 < h && y1 >= 0 && x1 < w && x1 >= 0){
					if(area[y1][x1] == '3'){
						min_count = min(min_count, n+1);
					}
					if(area[y1][x1] == '1'){
						area[y1][x1] = '0';
						move(y1-dy[k], x1-dx[k], n+1);
						area[y1][x1] = '1';
					}
				}
	}
}


int main(){
	int y, x;
	while(cin >> w >> h){
		if(w == 0 && h == 0) break;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin >> area[i][j];
				if(area[i][j] == '2'){
					y = i;
					x = j;
					area[i][j] = '0';
				}
			}
		}
		min_count = 11;
		move(y, x, 0);
		if(min_count == 11) cout << -1 << endl;
		else cout << min_count << endl;
	}
	return 0;
}

Measured memory_bytes: 864
n=int(input())
a=[int(i) for i in input().split()]
b=[i+1 for i in range(n)]
ct=0
for i in range(n):
    if(a[i]!=b[i]):
        ct+=1
if(ct==0 or ct==2):
    print('YES')
else:
    print('NO')


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;
    cin >> n;
    int count;
    for(int i=1;i<=n;i++){
        count = 0;
        for(int x=1;x<=100;x++){
            for(int y=1;y<=100;y++){
                for(int z=1;z<=100;z++){
                    if(x*x+y*y+z*z+x*y+y*z+z*x==i){
                        count++;
                    }
                    else if(x*x+y*y+z*z+x*y+y*z+z*x>i){
                        break;
                    }
                }
            }
        }
        COUT(count);
    }
}


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

int main()
{
  string s; cin >> s;
  int n = s.size();
  int posA = n, posZ = 0;
  rep(i,n){
    if(s[i] == 'A' && posA > i) posA = i;
    if(s[i] == 'Z' && posZ < i) posZ = i;
  }
  int ans = posZ - posA + 1;
  cout << ans << endl;
}

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

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


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

using namespace std;
using ll = long long;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N+1);
    ll a;
    ll sum = 0ll;
    ll count1 = 0ll;
    ll count2 = 0ll;
    for(int i=1;i<=N;i++){
        cin >> A[i];
    }

    for(int i=1;i<=N;i++){
        sum += A[i];
        if(i%2==0){ // sum > 0
            if(sum <= 0 ){
                count1 += 1 + abs(sum);
                sum = 1;
            }
        }else{ // sum < 0
            if(sum >= 0){
                count1 += sum + 1;
                sum = -1;
            }
        }
    }
    sum = 0ll;
    for(int i=1;i<=N;i++){
        sum += A[i];
        if(i%2==1){ // sum > 0
            if(sum <= 0 ){
                count2 += 1 + abs(sum);
                sum = 1;
            }
        }else{ // sum < 0
            if(sum >= 0){
                count2 += sum + 1;
                sum = -1;
            }
        }
    }
    cout << min(count1, count2) << endl;
}

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

int main() {
  string a;
  cin >> a;
  int o = 0;
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < a.size(); j++) {
      if (i != j) {
      if (a[i] == a[j]) {
        o++;
      }
    }
  }
  }
  if (o == 0) {
    cout << "yes" << endl;
  }
  else {
    cout << "no" << endl;
  }
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  string S; cin >> S;
  string result = "";
  int l = S.length();
  rep(i,l) {
    char pos = S[i] - 'A';
    pos = (pos+N)%26;
    result += 'A'+pos;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
    int X = 0,w = 0 ;
    char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}

ll n,x;
ll sum;
ll b[100005],l[100005];
ll u[100005];
ll num[100005],pfsum[100005];
pair<ll,ll> p[100005];
bool check(ll k)
{
    ll q=k/x;
    ll r=k-q*x;
    for(ll i=0;i<n;i++)
    {
        ll score=min(b[i],r)*l[i]+max(0LL,r-b[i])*u[i];
        if(q-1<num[i])
        {
            if(pfsum[q]+score>=sum)
            {
                return true;
            }
        }
        else
        {
            if(pfsum[q+1]-pfsum[num[i]+1]+pfsum[num[i]]+score>=sum)
            {
                return true;
            }
        }
    }
    return false;
}

int main()
{
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>b[i]>>l[i]>>u[i];
        sum+=b[i]*l[i];
    }
    for(ll i=0;i<n;i++)
    {
        p[i]={b[i]*l[i]+(x-b[i])*u[i],i};
    }
    sort(p,p+n);
    reverse(p,p+n);
    for(ll i=0;i<n;i++)
    {
        num[p[i].second]=i;
        pfsum[i+1]=pfsum[i]+p[i].first;
    }
    ll ok=(ll)n*x;
    ll ng=-1;
    while(abs(ok-ng)>1)
    {
        ll mid=(ok+ng)/2;
        (check(mid)?ok:ng)=mid;
    }
    cout<<ok<<endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>

using namespace std;
typedef long long ll;

int main(void)
{
    ll X, K, D;

    cin >> X >> K >> D;

    ll ans = 0;

    if (X == 0) {
        if (K % 2 == 0) {
            ans = 0;
        } else {
            ans = D;
        }
    } else {
        ll m = 1;
        if (X < 0) {
            m = -1;
        }
        ll n = abs(X) / D;
        if (n >= K) {
            ans = X - m * K * D;
        } else {
            X = X - m * n * D;
            K -= n;
            if (X <= abs(X - m * D)) {
                if (K % 2 == 0) {
                    ans = abs(X);
                } else {
                    ans = abs(X - m * D);
                }
            } else {
                if (K % 2 == 0) {
                    ans = abs(X);
                } else {
                    ans = abs(X - m * D);
                }
            }
        }
    } 
    cout << abs(ans) << endl;

    return 0;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void _dump(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void _dump(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  _dump(s, forward<Tail>(tail)...);
}
// }}} End

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

  VAR(int, N);

  vector<i64> a(N);
  vector<i64> norm(N);
  rep(i, N) {
    IN(a[i]);
    norm[i] = a[i] - (i + 1);
  }

  sort(all(norm));

  i64 mid = (!(norm.size() % 2) ? (norm.size() - 1) / 2 : norm.size() / 2);
  i64 b = norm[mid];
  i64 res = 0;
  rep(i, N) {
    res += abs(a[i] - (b + (i + 1)));
  }

  OUTL(res);

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main(){
    int a, b, c;

    cin >> a >> b >> c;

    if(a == b){
        cout << c << endl;
    }else{
        if(a == c){
            cout << b << endl;
        }else{
            cout << a << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, m;
    cin>>n>>m;
    vector<int> v(m);
    rep(i, m){
        cin>>v[i];
    }
    int now = accumulate(v.begin(), v.end(), 0);
    if(now>n){
        cout<<-1<<endl;
    }
    else {
        cout<<n-now<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
const ll MOD = 1000000007;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
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;}
typedef pair<int, int> P;
typedef pair<ll,ll> PLL;
double rad(double a) {return a * 180 / PI;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//dpTable
int dp[100050];

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    ll sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= MOD;
    }
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        sum -= A[i];
        if (sum < 0) sum += MOD;
 
        ans += A[i] * sum;
        ans %= MOD;
    }
 
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	string s,t="",x;cin>>s;
	rep(i,s.size()){
		if(s[i]!='x'){
			t.PB(s[i]);
		}
	}
	string u=t;
	reverse(all(u));
	if(u!=t){
		cout<<-1<<endl;
	}
	else{
		string v=s;reverse(all(v));
		if(v==s){
			cout<<0<<endl;
			return 0;
		}
		deque<char>d;
		rep(i,s.size())d.PB(s[i]);
		int ans=0;
		while(!d.empty()){
			if(d.size()>1){
             char l=d.front(),r=d.back();
			if(l!=r){
				if(l=='x'){
					ans++;
					d.pop_front();
				}
				else{
					ans++;
					d.pop_back();
				}
			}
			else{
				d.pop_front();
				d.pop_back();
			}
			}
			else break;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int numData = Integer.parseInt(br.readLine());
		String[] input = null;
		for(int i = 0; i < numData; i++){
			input = br.readLine().split(" ");
			double xa = Double.parseDouble(input[0]);
			double ya = Double.parseDouble(input[1]);
			double ra = Double.parseDouble(input[2]);
			double xb = Double.parseDouble(input[3]);
			double yb = Double.parseDouble(input[4]);
			double rb = Double.parseDouble(input[5]);
			System.out.println(checkIntersection(xa, ya, ra, xb, yb, rb));
		}
	}

	public static final int A_INNER_B = -2;
	public static final int B_INNER_A = 2;
	public static final int CROSS = 1;
	public static final int OUTER = 0;
	public static final int WRONG = -100;
	
	public static int checkIntersection(double x1, double y1, double r1,
			double x2, double y2, double r2){
		int intersection = CROSS;
		int stat = 0;
		if((stat = judgeInner(x1, y1, r1, x2, y2, r2)) != WRONG){
			intersection = stat; 
		}else if((stat = judgeOuter(x1, y1, r1, x2, y2, r2)) != WRONG){
			intersection = stat;
		}
		return intersection;
	}
	
	private static int judgeInner(double x1, double y1, double r1,
			double x2, double y2, double r2){
		double lengthAB = Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));
		if(lengthAB + r1 < r2)	return A_INNER_B;
		if(lengthAB + r2 < r1)	return B_INNER_A;
		return WRONG;
	}
	private static int judgeOuter(double x1, double y1, double r1, double x2, double y2, double r2){
		double lengthAB = (y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1);
		if(lengthAB > (r1 + r2) * (r1 + r2))	return OUTER;
		return WRONG;
	}
}

Measured memory_bytes: 16924
require 'time'

def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end

def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def yn(f) return (f)? "Yes": "No" end

def ynb(f) return (f)? "YES": "NO" end

def ap(a) a.each{|u| p u} end

def bit(n) n.to_s(2).split("").map(&:to_i) end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

s = inps[0]
t = inps[0]
dp = na2(26,s.size,nil)
l = s.size
(1..(s.size)).each do |i|
  26.times do |j|
    dp[j][l-i] = dp[j][l-i+1]
  end
  pp = s[l-i].ord - "a".ord
  dp[pp][l-i] = l-i
end
now_index = 0
rc =0
t.each_char do |c|
  cd = c.ord - "a".ord
  if(dp[cd][now_index] == nil)
    if(dp[cd][0] == nil)
      p -1
      exit
    else
      rc += 1
      now_index = dp[cd][0]
    end
  else
    now_index = dp[cd][now_index]
  end
  now_index += 1
end
p rc * s.size + now_index
#puts ()? "Yes" : "No"
#puts ()? "YES" : "NO"
#puts ()? "yes" : "no"

Measured memory_bytes: 22908
#https://atcoder.jp/contests/abc168
n=gets
x=n[-2].to_i
hon=[2,4,5,7,9]
pon=[0,1,6,8]
bon=[3]
#p n[0],n[-2]#-1には\nが入っていた
#p x
for h in hon
  if x==h
    print "hon"
  end
end
for h in pon
  if x==h
    print "pon"
  end
end
for h in bon
  if x==h
    print "bon"
  end
end


Measured memory_bytes: 14296