akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (long long i = (s); i < (long long)(n); i++)

int main() {
    long long n,x;
    cin >>n>>x;

    vector<long long>a(n);
    rep(i,0,n){
        cin>>a[i];
    }

    long long cnt=0;

    for(int i=1;i<n;i++){
        int sum=a[i]+a[i-1];
        if(sum>x){
            cnt+=(sum-x);
            a[i]-=(sum-x);
            if(a[i]<0){
                a[i]=0;
            }
        }
    }

    cout<<cnt<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    int A, B;
    cin >> A >> B;
    int tmp, cnt1, cnt2, cnt3 = 0;
    for(int i = A; i <= B; i++)
    {   
        tmp = i;
        cnt1 = 0;
        while(tmp > 0)
        {
            cnt1++;
            tmp /= 10;
        }
        int d[cnt1];
        for(int j = 0; j < cnt1; j++)
            d[j] = 0;
        tmp = i;
        for(int j = cnt1 - 1; j >= 0; j--)
        {
            d[j] = tmp % 10;
            tmp /= 10;
        }
        cnt2 = 0;
        for(int j = 0; j < cnt1 / 2; j++)
        {
            if(d[j] == d[cnt1 - 1 - j])
                cnt2++;
        }
        if(cnt2 == cnt1 / 2)
            cnt3++;
    }
    cout << cnt3 << endl;
    return 0;
}

Measured memory_bytes: 256
W,H,N=map(int,input().split())
udrl=[H,0,W,0]
for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    udrl[3]=max(udrl[3],x)
  elif a==2:
    udrl[2]=min(udrl[2],x)
  elif a==3:
    udrl[1]=max(udrl[1],y)
  else:
    udrl[0]=min(udrl[0],y)
print((max(0,udrl[0]-udrl[1])) * (max(0,udrl[2]-udrl[3])))
    
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define inf 1e9+1
struct ka{

int val;
int wt;};
int main() {
	//code

	int N,W;
	    cin>>N>>W;
	    vector<ka>arr(N+1);
	    for(int i=1;i<=N;i++)
	    {
	        cin>>arr[i].wt;
	        cin>>arr[i].val;
	    }
ll maxval=N*1000;

	    ll dp[N+1][maxval+1];
	    for(int val=0;val<=maxval;val++)
	    {
	    dp[1][val]=inf;
	    }

	    dp[1][0]=0;
	    dp[1][arr[1].val]=arr[1].wt;


	    for(int i=2;i<=N;i++)
	    {
	    for(int w=0;w<=maxval;w++)
	    {
	    dp[i][w]=dp[i-1][w];
	    if(arr[i].val <= w)
	    {
	    dp[i][w]=min(dp[i][w],arr[i].wt+dp[i-1][w-arr[i].val]);
	    }
	    }
	    }
int ans=0;
	    for(int i=0;i<=maxval;i++)
	    {
	    if(dp[N][i]<=W)
	    ans=i;
	    }


    cout<<ans;




}


Measured memory_bytes: 78336
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<typeof((c).front())>())
#define SZ(x) ((int)(x).size())
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1e9;
// const ll INF = 1e15;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


int main() {
  int N;
  set<int> num;
  cin >> N;

  REP(i, N) {
    int A;
    cin >> A;
    auto itr = num.find(A);
    if (itr == num.end()) {
      num.insert(A);
    } else {
      num.erase(itr);
    }
  }

  cout << SZ(num) << endl;

  return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int a,b,c;cin >>a>>b>>c;
    ll s=a+b;
    if(s>=c)puts("Yes");
    else puts("No");
    return 0;
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == 0) {
        v.clear();
        return 0;
    }
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

int solve(int N, vi& a) {
    sort(ALL(a));
    int h=N/2;
    int lo=a[h-1]+1, hi=a[h];
    if (lo > hi) return 0;
    return hi - lo + 1;
}

int main() {
    vi a;
    int N = loadvec(a);
    cout << solve(N,a) << endl;
    return 0;
}


Measured memory_bytes: 1152
<?php

[$H, $W, $K ] = fscanf(STDIN, "%d%d%d");
$ans= 0;
for($i=0;$i<$H;$i++){
    [$S] = fscanf(STDIN, "%s");
    $map[$i] = str_split($S);
    foreach($map[$i] as $value){
        if($value === "#"){
            $ans++;
        }
    }
}
$goal = 0;
for($i=0;$i<pow(2, $H + $W);$i++){
    $sans = $ans;
    $smap = $map;
    for($k=0;$k<($H+$W);$k++){
        if(($i & pow(2, $k)) > 0 ){
            if($k >= $H){
                //$W;
                $target = $k - $H;
                for($j=0;$j<$H;$j++){
                    if($smap[$j][$target] == "#"){
                        $smap[$j][$target] = ".";
                        $sans--;
                    }
                }
            }else{
                $target = $k;
                for($j=0;$j<$W;$j++){
                    if($smap[$target][$j] == "#"){
                        $smap[$target][$j] = ".";
                        $sans--;
                    }
                }
            }

        }
    }
    if($sans === $K){
        $goal++;
    }
}
echo $goal;

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

using namespace std;

int main()
{
  int N;
  while(cin >> N,N)
    {
      int G[N+1][N+1];
      for(int i=1;i<=N;i++)
	for(int j=0;j<=N;j++)
	  cin >> G[i][j];

      int dp[(1<<17)];
      for(int i=0;i<(1<<17);i++)
	dp[i] = (1<<29);

      dp[0] = 0;

      for(int i=0;i<=(1<<(N+1))-2;i++)
	for(int j=1;j<=N;j++)
	  if(!((i>>j)&1))
	    for(int k=0;k<=N;k++)	      
	      if(k == 0 || ( (i>>k)&1 ))
		dp[i|(1<<j)] = min(dp[i|(1<<j)],dp[i]+G[j][k]);
      cout << dp[(1<<(N+1))-2] << endl;
    }
  return 0;
}

Measured memory_bytes: 1668
#include <bits/stdc++.h>
using namespace std;
#define MAXN 128
#define MAXV 100010
	
unsigned long long dp[MAXN][MAXV];

int main() {
	ios::sync_with_stdio(false);
	unsigned long long N, W;
	cin >> N >> W;
	memset(dp, 127, sizeof(dp));
	unsigned long long cw, cv;
	cin >> cw >> cv;
	dp[0][0] = 0;
	dp[0][cv] = cw;
	for(unsigned long long i=1; i<N; i++) {
		cin >> cw >> cv;
		for(unsigned long long v=0; v<MAXV; v++) {
			dp[i][v] = cv<=v ? min(dp[i-1][v], dp[i-1][v-cv]+cw) : dp[i-1][v];
		}
	}
	unsigned long long rst = 0;
	for(unsigned long long v=0; v<MAXV; v++) {
		rst = dp[N-1][v]<=W ? v : rst;
	}
	cout << rst << "\n";
	return 0;
}


Measured memory_bytes: 100224
import java.util.*;
import java.io.*;

public class Main {
    public static boolean solve(String s){
        if(s.charAt(0)!='A')return false;
        if(s.charAt(1)=='C'||s.charAt(s.length()-1)=='C') return false;
        int countC = 0;
        for(int i=1;i<s.length();i++){
        	char ith = s.charAt(i);
        	if((ith<'a'||ith>'z')&&ith!='C')return false;
        	if(ith=='C')countC++;
        }
        return countC==1;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        System.out.println(solve(s) ? "AC" : "WA");
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

void prework(){

}

void read(){

}

class BITree{
public:
    static const int SIZE = 100010, BIAS = 5;
    long long u[SIZE];
    void clear(){
        memset(u,0,sizeof(u));
    }
    void modify(int x, long long v){
        for(x+=BIAS;x<SIZE;x+=x&-x) u[x]+=v;
    }
    long long getsum(int x){
        long long s=0;
        for(x+=BIAS;x;x-=x&-x) s+=u[x];
        return s;
    }
} hnk;

int a[MAXN];
int f[MAXN];
ll g[MAXN];

void solve(int casi){
	scanf("%d", &n);
	map<int, int> nico;
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		nico[a[i]] = 1;
	}
	int cnt = 0;
	for(auto &x : nico){
		x.second = ++cnt;
	}
	
//	for(auto &x : nico){
//		cout<<x.first<<' '<<x.second<<endl;
//	}
	
	hnk.clear();
	for(int i = 1; i <= n; i++){
		hnk.modify(1, 1);
		hnk.modify(nico[a[i]] + 1, -1);
	}
	cnt = 0;
	for(auto &x : nico){
		++cnt;
		f[cnt] = x.first;
		g[cnt] = hnk.getsum(x.second);
	}
	f[0] = 0;
	/*
	for(int i = 1; i <= cnt; i++){
		cout<<f[i]<<' ';
	} cout<<endl;
	for(int i = 1; i <= cnt; i++){
		cout<<g[i]<<' ';
	} cout<<endl;
	*/for(int i = 1, j = 1; i <= n; i++){
		ll ans = 0;
		while(j <= cnt && a[i] >= f[j]){
			ans += g[j] * (f[j] - f[j-1]);
			j++;
		}
		printf("%lld\n", ans);
	}
}

void printans(){

}


int main(){
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}




Measured memory_bytes: 11392
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>

typedef unsigned long long ll;

ll DENOM = 1000000000LL + 7LL;
using namespace std;

int main(){
    ll n;
    cin >> n;
    map<ll,ll> a;
    ll s = 0;
    for(int i=0; i<n; ++i){
        ll at;
        cin >> at;
        a[at] += 1;
        s += at;
    }
    ll q;
    cin >> q;
    vector<pair<ll,ll> > bc;
    for (int i=0; i<q; ++i){
        ll b, c;
        cin >> b >> c;
        bc.push_back(make_pair(b,c));
    }
    for (int i=0; i<q; ++i){
        ll b, c;
        b = bc[i].first;
        c = bc[i].second;
        s += (c - b) * a[b];
        a[c] += a[b];
        a[b] = 0;
        cout << s << endl;
    }
}

Measured memory_bytes: 10304
if __name__ == '__main__':

	n = int(input())
	d = {}

	for i in range(n):
		cmd = input().split()
		if cmd[0] == "0":
			d[cmd[1]] = cmd[2]
		elif cmd[0] == "1":
			if cmd[1] in d:
				print(d[cmd[1]])
			else:
				print("0")
		else:
			if cmd[1] in d:
				del d[cmd[1]]



Measured memory_bytes: 41632
from collections import Counter
import math

N = int(input())
a = list(map(int,input().split()))

a.sort()

is_prime = [True]*(10**6 + 1)

is_prime[0] = False

maxA = max(a)

for i in set(a):
    for j in range(2 * i, maxA+1, i):
        is_prime[j] = False

result = 0
c = Counter(a)

for e in set(a):
        if is_prime[e] and c[e] == 1:
    #        print('e = {}'.format(e))
             result += 1

print(result)



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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k;
string s;


// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> s;
	cin >> k;
	n = s.length();
	set<string> val;
	for(ll i=1;i<=k;i++) {
		for(ll j=0;j<=n-i;j++) {
			val.insert(s.substr(j,i));
		}
	}
	k--;
	while(k--) val.erase(val.begin());
	cout<<*val.begin();
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 239228
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
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 (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, i;
    cin >> N >> i;
    cout << N - i + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int ms_pilha = 1e5+9, ms_set = 1e2+9;
int pedras_size[ms_set];
int dp[ms_pilha][2];
int n, k;

int solve(int rocks, int player){
  if(rocks == 0)
    return 1 - player;

  int &ans = dp[rocks][player];
  if(~ans)
    return ans;

  ans = 1 - player;

  for(int i = 0; i < n; i++){
    if(pedras_size[i] <= rocks and solve(rocks - pedras_size[i], 1 - player) == player){
      ans = player;
    }
  }

  return ans;
}



int main(){
  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> pedras_size[i];


  memset(dp, -1, sizeof dp);
  if(solve(k, 0) == 0)
    cout<<"First";
  else
    cout<<"Second";
}

Measured memory_bytes: 8832
import collections
N, M = map(int, input().split())
A = [int(i) for i in input().split()]

Cum = [0 for _ in range(N+1)]
for i in range(N):
    Cum[i+1] = Cum[i]+A[i]

C = collections.Counter([x % M for x in Cum])

print(sum([x*(x-1)//2 for x in C.values()]))


Measured memory_bytes: 64536
#include <iostream>
#include <cstdio>
#define int long long
using namespace std;

signed main(){
	int n,sum = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		int t;
		cin >> t;
		sum += t;
	}
	cout << sum / n << endl;
	return 0;
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const ll mod = 1000000007;
int INF = 1001001001;

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


Measured memory_bytes: 3604
import java.util.Scanner

fun main (args: Array<String>) {
  val scn = Scanner(System.`in`)
  val n = scn.nextInt()
  val k = scn.nextInt()
  val x = scn.nextInt()
  val y = scn.nextInt()
  println((1..n).map { if (it <= k) x else y }.sum())
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int)s.size();
  vector<int> v(n + 1, 0);
  for (int i = 0; i < n; i++) {
    if (s[i] == '<') v[i + 1] = v[i] + 1;
  }
  long long ans = v[n];
  for (int i = n - 1; ~i; i--) {
    if (s[i] == '>') v[i] = max(v[i], v[i + 1] + 1);
    ans += v[i];
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 5880
#include <stdio.h>
#include <math.h>
int main(void){
    long int n,m;
    scanf("%ld",&n);
    int x = sqrt(n);
    for(int i=x;i>0;i--){
        if(n%i==0){
            m=n/i;
            printf("%ld",m-1+i-1);
            return 0;
        }
    }
    printf("%ld",n-1);
    return 0;
}


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

using namespace std;

int main() {

	int n;
	vector<int> vec;

	cin >> n;
	vec.resize(n);

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

	int index = 0;
	for (int i = 0; i < n; i++)
	{
		index = vec[index];
		if (index == 1)
		{
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;++i) {
        cin >> a[i];
    }

    ll p = 1000, s = 0;
    for(int i=0;i<n-1;++i) {
        if(a[i] < a[i+1]) {
            ll m = p / a[i];
            p %= a[i];
            s += m;
        } else if(a[i] > a[i+1]) {
            p += s * a[i];
            s = 0;
        }
    }
    p += s * a[n-1];
    cout << p << endl;
}


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

int main(){
  int n,k;
  cin >> n >> k;
  
  vector<int> leg(n);
  for(int i=0; i<n; i++){
    cin >> leg.at(i); 
  }
  
  sort(leg.begin(), leg.end(), greater<int>());
  
  int sum = 0;
  for (int i=0; i<k; i++){
    sum += leg.at(i);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int N = 200005;
int n;
vector<pair<int, int> > v;
ll memo[2000][2000];
ll solve(int *arr, int i, int l, int r) {
if (i==n) {
return 0;
}
if (memo[l][r] != -1) {
return memo[l][r];
}
ll ans1 = solve(arr, i + 1, l + 1, r) + (1LL * v[i].first * abs(v[i].second - l));
ll ans2 = solve(arr, i + 1, l, r - 1) + (1LL * v[i].first * abs(v[i].second - r));
return memo[l][r] = max(ans1, ans2);
 
}
 
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n;
int arr[2005];
for (int i = 0; i < n; i++)
cin >> arr[i];
for (int i = 0; i < n; i++) {
v.push_back({arr[i], i});
}
memset(memo, -1, sizeof memo);
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
// for (int i = 0; i < n; i++) {
// cout << v[i].first << " " << v[i].second << endl;
// }
cout<<solve(arr, 0, 0, n - 1);
//cout<<ans<<endl;
return 0;
 
}

Measured memory_bytes: 35032
#include<stdio.h>
int main() {
    int n, x[111111], i,p,ans=1000000000,l,r,k;
    scanf("%d%d", &n,&k);
    for (i = 0; i < n; i++)
        scanf("%d", &x[i]);
    for (i = 0; i + k - 1 < n; i++) {
        l = x[i];
        r = x[i + k - 1];
        if (l < 0) {
            if (r < 0)
                p = -l;
            else {
                l = -l;
                if (l > r)
                    p = l + r * 2;
                else
                    p = l * 2 + r;
            }
        }
        else
                p = r;
        if (p < ans)
            ans = p;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 512
N = int(input())
x_y = []
for i in range(N):
    x,y = map(int,input().split())
    x_y.append([x,y])

vectors = []
ans_inv = 0
for i in range(N):
    for j in range(i+1,N):
        vector = [x_y[i][0]-x_y[j][0],x_y[i][1]-x_y[j][1]]
#        print(vector)
        if vector[0]<0:
            vector = [x_y[j][0]-x_y[i][0],x_y[j][1]-x_y[i][1]]
        elif vector[0] == 0 and vector[1]<0:
            vector = [x_y[j][0]-x_y[i][0],x_y[j][1]-x_y[i][1]]
        vectors.append(vector)
cnt = 0
for i in range(len(vectors)):
    cnt = max(cnt,vectors.count(vectors[i]))

print(N-cnt)

Measured memory_bytes: 40048
#include <iostream>
#include <stdio.h>
#define FOR(i,a,b) for(long long int i =(a); i <(b);i++)
#define REP(i,N)   FOR(i,0,N)
#define debug(x)   cout << #x << " = " << x << endl;

using namespace std;

int main(void){

    int K,sum;
    cin >> K >> sum;
    int ans = 0;
    REP(i,K+1){
        REP(j,K+1){
            int s = sum - i - j;
            if(0 <= s && s <= K){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    cout << fixed << setprecision(8);
    int n;
    cin >> n;
    int x[100] = {};
    int y[100] = {};

    // ミンコフスキー距離
    double D1 = 0.0;  // マンハッタン距離 p=1
    double D2 = 0.0;  // ユークリッド距離 p=2
    double D3 = 0.0;  // p=3
    double D4 = 0.0;  // チェビシェフ距離 p=4

    int    z   = 0;
    double tmp = 0.0;

    rep(i, n) { cin >> x[i]; }
    rep(i, n) { cin >> y[i]; }

    rep(i, n) {
        z = x[i] - y[i];
        D1 += abs(z);
    }

    rep(i, n) {
        z = x[i] - y[i];
        tmp += abs(z) * abs(z);
    }
    D2 = sqrt(tmp);

    tmp = 0.0;
    rep(i, n) {
        z = x[i] - y[i];
        tmp += abs(z) * abs(z) * abs(z);
    }
    D3 = cbrt(tmp);

    rep(i, n) {
        z   = x[i] - y[i];
        tmp = abs(z);
        if (D4 < tmp) {
            D4 = tmp;
        }
    }

    cout << D1 << "\n";
    cout << D2 << "\n";
    cout << D3 << "\n";
    cout << D4 << "\n";

    return 0;
}



Measured memory_bytes: 3460
#include<stdio.h>

int main(void)


{


int a,b,c;


int count=0;


int i;


scanf("%d %d %d",&a,&b,&c);


for(i=a;i<=b;i++)


{


if(c%i==0)count++;


}


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


return 0;


}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main(){
  //エラトステネスの篩
  int MAX=110000;
  vector<int> is_prime(MAX,1);
  is_prime[0]=0,is_prime[1]=0;
  for(int i=2;i<MAX;i++){
    if(!is_prime[i])continue;
    for(int j=i*2;j<MAX;j+=i){
      is_prime[j]=0;
    }
  }

  //2017に似た数なら1,そうじゃないなら0
  vector<int> a(MAX,0);
  for(int i=0;i<MAX;i++){
    if(i%2==0)continue;
    if(is_prime[i]&&is_prime[(i+1)/2])a[i]=1;
  }

  //累積和
  vector<int>s(MAX+1,0);
  for(int i=0;i<MAX;i++)s[i+1]=s[i]+a[i];

  //クエリ
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    r++;
    cout<<s[r]-s[l]<<endl;
  }
}

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

const double PI =3.14159265359;

int main() {
  
  double A,B,H,M;
  
  cin >> A >> B >> H >> M;
  
  double redi = PI*2.0*((H + M/60)/12 -M/60);
  
  double dis = A*A + B*B - 2.0*A*B*cos(redi);
  
  
  //sqrtl
  printf("%0.20f",(double)sqrtl(dis));
  //cout << sqrtl(dis);
}

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

int main() {
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int h = 0; h < H; h++) {
			for (int w = 0; w < W; w++) {
				if (h % 2 == 0 && w % 2 == 0)cout << "#";
				if (h % 2 == 0 && w % 2 != 0)cout << ".";
				if (h % 2 != 0 && w % 2 == 0)cout << ".";
				if (h % 2 != 0 && w % 2 != 0)cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
a,b,c,d=map(int,input().split())
cwari=b//c-(a-1)//c
dwari=b//d-(a-1)//d
import fractions
l=int(c*d/fractions.gcd(c,d))
cdwari=b//l-(a-1)//l
ans=(b-a)+1-cwari-dwari+cdwari
print(ans)

Measured memory_bytes: 64364
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    D, G = map(int, input().split())
    P = [0] * D
    C = [0] * D
    for i in range(D):
        p, c = map(int,input().split())
        P[i] = p
        C[i] = p * 100 * (i+1) + c

    ret = 1000
    for i in range(2 ** D):
        pt = 0
        ct = 0
        for j in range(D):
            if i >> j & 1:
                pt += C[j]
                ct += P[j]
            else:
                mxi = j
        for j in range(P[mxi]):
            if pt>=G:
                break
            else:
                pt += 100*(mxi+1)
                ct += 1
        if pt>=G:
            ret = min(ret, ct)
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inputs;
		inputs = br.readLine().split(" ");
		int n = Integer.parseInt(inputs[0]), m = Integer.parseInt(inputs[1]);

		// ノード配列作成
		Node[] nodes = new Node[n];
		for ( int i = 0; i < n; i++ ) {
			nodes[i] = new Node();
		}
		for ( int i = 0; i < m; i++ ) {
			inputs = br.readLine().split(" ");
			int x = Integer.parseInt(inputs[0]) - 1, y = Integer.parseInt(inputs[1]) - 1;
			nodes[x].chldList.add(nodes[y]);
			nodes[y].prntCnt++;
		}

		// 始点サーチ
		ArrayDeque<Node> toCheck = new ArrayDeque<>();
		for ( Node node : nodes ) {
			if ( node.prntCnt == 0 ) toCheck.add(node);
		}

		// BFSで距離計算開始
		int lenMax = 0;
		while ( toCheck.size() > 0 ) {
			Node node = toCheck.pollFirst();
			for ( Node chld : node.chldList ) {
				chld.prntCnt--;
				chld.len = Math.max(node.len + 1, chld.len);
				lenMax = Math.max(lenMax, chld.len);
				// 全返をチェックした子はチェックリストへ
				if ( chld.prntCnt == 0 ) {
					toCheck.add(chld);
				}
			}
		}
		System.out.println(lenMax);
	}
}

class Node implements Comparable<Node>{

	int				len			= 0;
	int				prntCnt		= 0;
	ArrayList<Node>	chldList	= new ArrayList<>();

	public Node() {
	}

	@Override
	public int compareTo(Node o) {
		
		return this.prntCnt - o.prntCnt;
	}
}


Measured memory_bytes: 52208
from collections import deque
N,K = map(int, raw_input().split())
V = map(int, raw_input().split())
q = deque([])
nl = []
for i in range(min(K+1,N+1)):
	for j in range(i+1):
		q.append(V[:j]+V[N-i+j:])
	while q:
		q2 = q.popleft()
		q2.sort()
		qlen = len(q2)
		np = sum(q2)
		for j in range(min(qlen,K-i)):
			if(q2[j] < 0):
				np -=q2[j]
		nl.append(np)
print(max(nl))

Measured memory_bytes: 2808
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 :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let 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 ) *} } ;($($r :tt ) *) =>{let 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 ) *} } ;}
fn main() {
    input! { s : {chars: '0'} };
    let n = s.len();
    let m: usize = 2019;
    let mut acc = vec![0; n + 1];
    let mut base = 1;
    for i in (0..n).rev() {
        acc[i] += (acc[i + 1] + s[i] * base % m) % m;
        acc[i] %= m;
        base *= 10;
        base %= m;
    }
    let mut cnt = vec![0; m];
    cnt[0] += 1;
    let mut ans = 0;
    for i in (0..n).rev() {
        ans += cnt[acc[i]];
        cnt[acc[i]] += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 5376
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	int num[6];

	for (int i = 0; i < 6; i++) {
		cin >> num[i];
	}

	char com[101];
	cin >> com;

	int T = num[0];
	int R = num[2];
	int L = num[3];
	int F = num[1];
	int B = num[4];
	int D = num[5];
	int tmp;

	for (int i = 0; com[i] != '\0'; i++) {
		switch (com[i]) {
		case 'E':
			tmp = T;
			T = L;
			L = D;
			D = R;
			R = tmp;
			break;
		case 'N':
			tmp = T;
			T = F;
			F = D;
			D = B;
			B = tmp;
			break;
		case 'W':
			tmp = T;
			T = R;
			R = D;
			D = L;
			L = tmp;
			break;
		case 'S':
			tmp = T;
			T = B;
			B = D;
			D = F;
			F = tmp;
			break;
		}
	}

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

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t1,t2,a1,a2,b1,b2;
    //cin>>t;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    
    if((a1*t1 + a2*t2) == (b1*t1 + b2*t2)){
        cout<<"infinity\n";
    }
    else{
        if((b1*t1+b2*t2)<(a1*t1+a2*t2)){
            swap(a1,b1);
            swap(a2,b2);
        }
        
        ll q1=(a1*t1-b1*t1),q2=((b2*t2+b1*t1)-(a1*t1+a2*t2));
        ll ans=q1/q2;
        if(b1>a1)
            cout<<0;
        else if(q1%q2==0)
            cout<<ans*2;
        else
            cout<<ans*2+1;
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int n;
map<int, int> cnt;

void factor(int x) {
    for (int i = 2; i * i <= x; i++) {
        while (x % i == 0) {
            x /= i;
            cnt[i]++;
        }
    }
    if (x != 1) cnt[x]++;
}

int main() {
    fastio();

    cin >> n;

    for (int i = 1; i <= n; i++) {
        factor(i);
    }

    int ans = 0;
    for (int i = 2; i <= n; i++) {
        if (cnt[i] >= 74) ans++;
        for (int j = 2; j <= n; j++) {
            if (i == j) continue;
            if (cnt[i] >= 4 && cnt[j] >= 14) ans++;
            if (cnt[i] >= 2 && cnt[j] >= 24) ans++;

            for (int k = j + 1; k <= n; k++) {
                if (i == k) continue;
                if (cnt[i] >= 2 && cnt[j] >= 4 && cnt[k] >= 4) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
//#include <stdio.h>
//  int main(){while(1){
//   int a[101]={};
//   int b,c,d;
//   scanf("%d%d",&b,&c);
//   if(b==0 && c==0) break;
//   int i,j;
//   for(i=0;i<b;i++){
//      for(j=1;j<=c;j++){
//         scanf("%d",&d);
//         a[j]+=d;
//      }
//   }
//   int num=0;
//for(i=b;i>=0;i--){
//	for(j=1;j<=c;j++){
//		if(i==a[j]){
//			if(num==0){
//			printf("%d",j);
//			num++;
//			}
//		else{
//			printf(" %d",j);
//			num++;
//		}
//		}
//	}
//}
//printf("\n");
//  }
//return 0;
//  }
#include <stdio.h>
int x(int num, int sum, int n){
	if (num == 0 && sum == 0){ 
		return 1; 
	}     
	if (n > 9){  
		return 0;   
	}     
	return (x(num - 1, sum - n, n + 1) + x(num, sum, n + 1));
} 
int main(void) { 
	int sum, num;    
	while (1){       
		scanf("%d%d", &num, &sum); 
		if (num == 0 && sum == 0) break;   
		printf("%d\n", x(num, sum, 0));  
	}     
	return 0;
}

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

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

    long long ans;
    if ((B - A) % 2 == 0)
    {
        ans = (B - A) / 2;
    }
    else // ((B - A) % 2 == 1)
    {
        long long ans1 = ((N - A) + (N - B) + 1) / 2;
        long long ans2 = ((A - 1) + (B - 1) + 1) / 2;
        ans = min(ans1, ans2);
    }

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

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int x, y;
	scanf("%d%d", &x, &y);
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			if (2 * i + 4 * j == y && i + j == x) {
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

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

int comp(const void* a, const void *b) {
    return *(int*) a - *(int*) b;
}

int main () {
    int N;
    scanf("%d", &N);
    int *d = malloc(N * sizeof(int));
    for (int i = 0; i < N; i++) {
        scanf("%d", &d[i]);
    }
    qsort(d, N, sizeof(int), comp);
    int ans = d[N/2] - d[N/ 2 - 1];
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 892
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, D = MAP()

num_C_yaku = B//C - (A-1)//C  # Cで割り切れる
num_D_yaku = B//D - (A-1)//D  # Dで割り切れる

num_CD_yaku = B//(C*D//int(gcd(C, D))) - (A-1)//(C*D//int(gcd(C, D)))  # CとDの最小公倍数で割り切れる 

# print("C",num_C_yaku)
# print("D",num_D_yaku)
# print("CDの公倍数",num_CD_yaku)
print((B-A+1)-(num_C_yaku+num_D_yaku-num_CD_yaku))


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> s(m),c(m);
    rep(i,m)cin >> s[i] >> c[i];
    int ans = -1;
    rep(x, 1000){
        vector<int> d(1,x%10);
        int nx = x/10;
        int keta =1;
        while(nx){
            keta++;
            d.push_back(nx%10);
            nx/=10;
        } 
        reverse(d.begin(), d.end());
        if(keta != n)continue;
        bool ok = true;
        rep(i,m){
            if(d[s[i]-1] != c[i])ok = false;
        }
        if(ok){
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n;
	int money = 100000;
	cin >> n;
	
	for(int i = 1;i <= n; i++){
		money *= 1.05;
		if(money % 1000 != 0){
			money = money - (money % 1000) + 1000;
		}
	}
	
	cout << money << endl;
	
	return 0;
}

Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
int A,B,C;
int main(){
  cin >> A >> B >> C;
  for(int i=1;i<=B;i++){
    if(A*i%B==C){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
mt19937 _mt(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l,ll r){return uniform_int_distribution<ll>(l,r-1)(_mt);}
/*
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;
*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	cout<<(b%a==0?a+b:-a+b)<<endl;;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x, y;
  cin >> x >> y;
  ll ans = inf;
  if(y >= x) ans = min(y-x, ans);
  if(y >= -x) ans = min(y+x+1, ans);
  if(-y >= x) ans = min(-y-x+1, ans);
  if(-y >= -x) ans = min(-y+x+2, ans);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

#define MAX 25
#define NIL -1

typedef struct{
  int parent,left,right;
}TREE;

void PreParse(TREE [],int);
void InParse(TREE [],int);
void PostParse(TREE [],int);

int main(){
  TREE tree[MAX];
  int i;
  int id,left,right,n;
  int root;

  for (i = 0;i < MAX;i++){
    tree[i].parent = NIL;
    tree[i].left = NIL;
    tree[i].right = NIL;
  }

  scanf("%d",&n);

  for (i = 0;i < n;i++){
    scanf("%d %d %d",&id,&left,&right);
    
    tree[id].left = left;
    tree[id].right = right;

    if (left != NIL)
    tree[left].parent = id;

    if (right != NIL)
    tree[right].parent = id;

  }

  for (i = 0;i < n;i++)
    if (tree[i].parent == NIL)
      root = i;
  
  printf("Preorder\n");
  PreParse(tree,root);
  printf("\nInorder\n");
  InParse(tree,root);
  printf("\nPostorder\n");
  PostParse(tree,root);
  printf("\n");
  
  return 0;
}

void PreParse(TREE tree[],int u){
  if (u == NIL)
    return;

  printf(" %d",u);
  PreParse(tree,tree[u].left);
  PreParse(tree,tree[u].right);
}

void InParse(TREE tree[],int u){
  if (u == NIL)
    return;

  InParse(tree,tree[u].left);
  printf(" %d",u);
  InParse(tree,tree[u].right);
}

void PostParse(TREE tree[],int u){
  if (u == NIL)
    return;

  PostParse(tree,tree[u].left);
  PostParse(tree,tree[u].right);
  printf(" %d",u);
}



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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll N, M, K; cin >> N >> M >> K;
	vi AS (N);
	F0R(i, N) cin >> AS[i];
	vi BS (M);
	F0R(i, M) cin >> BS[i];

	ll ltotal = 0, rtotal = 0;
	int j = 0;
	while (j < M && ltotal + BS[j] <= K) ltotal += BS[j++];
	int best = j;
	F0R(i, N) {
		rtotal += AS[i];
		while (j > 0 && ltotal + rtotal > K) ltotal -= BS[--j];
		if (j == 0 && rtotal > K) break;
		best = max(best, i + 1 + j);
	}
	print(best);
}

Measured memory_bytes: 4788
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
 
		// 読み込み
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        
        int dp[] = new int[N];
        
        for(int i = 1; i < N; i++) {
        	for(int j = i + 1 ; j <= N; j++) {
        		int normal = j - i;
        		int warp = Math.abs(X - i) + 1 + Math.abs(Y - j);
        		int cost = normal > warp ? warp : normal;
        		
        		dp[cost] ++;
        	}
        }
        
        for(int i = 1 ; i< N ; i++)
        	System.out.println(dp[i]);
	}
}

Measured memory_bytes: 23252