akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=2e5+100;
vector <int> g[N];
ll dp[N][2];

ll dfs(ll v,ll p){
    ll p1=0;
    for (int i=0;i<g[v].size();i++){
        ll u=g[v][i];
        if (u==p){
            continue;
        }
        dfs(u,v);
        dp[v][1]+=dp[u][1];
        if (dp[u][1]==0){
            p1++;
        }
    }
    p1=max(p1-1,(ll)0);
    dp[v][1]+=p1;

    //cout << v << " " << dp[v][0] << " " << dp[v][1] << endl;
}
int32_t main(){
    ll n;
    cin >> n;
    ll ans=0;
    for (int i=0;i<n-1;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    //cout << ans+1 << endl;
    vector <int> b;
    for (int i=0;i<n;i++){
        if (g[i].size()==1){
            b.pb(i);
        }
    }

    ll mi=1e9+100;
    for (int i=0;i<min((ll)10,(ll)b.size());i++){
        ll v=b[i];
        memset(dp,0,sizeof dp);
        dfs(v,v);
        
        mi=min(mi,dp[g[v][0]][1]+1);
    }
    cout << mi;
}


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

int main() {
  int K,A,B,M;
  cin >> K >> A >> B;
  M = (B/K) * K;
  if (M >= A){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int main(){
    int n;cin>>n;
    int a[110];
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    int mi=INF;int ans=0;
    for(int i=0;i<n;i++){
        if(mi>abs(sum-a[i]*n)){
            mi=abs(sum-a[i]*n);
            ans=i;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import deque

N, M = map(int, input().split())
adj = [[1 for _ in range(N + 1)] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    adj[a][b] = 0
    adj[b][a] = 0
adj_inv = [[] for _ in range(N + 1)]
for i in range(1, N+1):
    for j in range(i+1, N+1):
        if adj[i][j] == 1:
            adj_inv[i].append(j)
            adj_inv[j].append(i)

seen = [0] * (N+1)
num = []
for i in range(1, N+1):
    if seen[i] == 0:
        plus = 0
        minus = 0
        que = deque()
        que.append(i)
        seen[i] = 1
        plus += 1
        while que:
            v = que.pop()
            u_list = adj_inv[v]
            for u in u_list:
                if seen[u] == 0:
                    que.append(u)
                    seen[u] = -seen[v]
                    if seen[u] == 1:
                        plus += 1
                    else:
                        minus += 1
                else:
                    if seen[u] == seen[v]:
                        print(-1)
                        exit()
        num.append((min(plus, minus), max(plus, minus)))

min_sum = 0
add = []
for i in range(len(num)):
    min_sum += num[i][0]
    add.append(num[i][1] - num[i][0])

dp = [[0 for _ in range((N // 2) + 1)] for _ in range(len(add) + 1)]
dp[0][min_sum] = 1
for i in range(len(add)):
    for j in range(min_sum, (N // 2) + 1):
        if dp[i][j] == 1:
            if j + add[i] <= (N // 2):
                dp[i+1][j+add[i]] = 1
            dp[i+1][j] = 1

dp_last = dp[-1]
for i in range(len(dp_last)-1, -1, -1):
    if dp_last[i] == 1:
        N1 = i
        break

print((N1 * (N1 - 1)) // 2 + ((N - N1) * (N - N1 - 1)) // 2)


Measured memory_bytes: 53084
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 10

bool used[MAX_N];
int N, S;
int count;

bool
permutation(int n, int lv)
{
	static int perm[MAX_N];
	int memo[MAX_N];
	int i, j;

	perm[lv] = n;

	int s = 0;
	for (i = 1; i <= lv + 1; ++i)
	{
		s += i * perm[i - 1];
		if (s > S)
			return false;
	}

	if (lv >= N - 1)
	{
		if (s == S)
			count++;

		return true;
	}

	used[n] = true;
	for (i = 0, j = 0; i < MAX_N; ++i)
	{
		if (!used[i])
			memo[j++] = i;
	}

	for (i = 0; i < j; ++i)
	{
		if (!permutation(memo[i], lv + 1))
			break;
	}

	used[n] = false;
	return true;
}

int
main(int argc, char **argv)
{
	int i;

	while (scanf("%d %d", &N, &S) != EOF)
	{
		count = 0;
		for (i = 0; i < MAX_N; ++i)
			permutation(i, 0);

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

	return 0;
}

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long
typedef pair<int, int> P;

int main(){
  ll N, H;
  cin >> N >> H;
  ll a[N], b[N], ans = 0;
  rep(i, N){
    cin >> a[i] >> b[i];
  }
  sort(a, a+N, greater<ll>());
  sort(b, b+N, greater<ll>());
  rep(i, N){
    if (b[i] > a[0]) {
      H -= b[i];
      ans += 1;
    }
    if (H <= 0) {
      break;
    }
  }
  if (H >= 0) {
    ans += H/a[0];
    if (H % a[0] != 0) {
      ans += 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
n, m = map(int, input().split())
x = list(map(int, input().split()))

xSort = sorted(x)

dif = [0] * (m - 1)
for i in range(m - 1):
    dif[i] = xSort[i + 1] - xSort[i]
ans = sum(dif)

if (n == 1 or m == 1):
    print(ans)

elif (n >= m):
    print('0')
else:
    tar = len(dif) - n + 1
    difSort = sorted(dif)
    difS_2 = difSort[:tar]
    ans = sum(difS_2)
    print(ans)
'''  
    for j in range(n - 1):
        tar = j + 1
        tarInd = tar * -1
        tarVal = sorted(dif)[tarInd]
        ans -= tarVal
'''
# print(ans)
# >>>TLE
#
# n番目の要素を取得
# sorted(list)[-1] > 1番大きい
# sorted(list)[-２] > 2番大きい
'''
  import numpy as np
  difArray = np.array(dif)
  difIndex = difArray.argsort()

  for i in range(n - 1):
    tar = m - i
    maxIndex = difIndex[tar]
    maxVal = diff
'''


Measured memory_bytes: 13968
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
    int n,m,c,tmp,ans(0);
    cin >> n >> m >> c;
    int a[n][m];
    int b[m];
    for(int i = 0;i < m;i++){
        cin >> b[i];
    }
    for(int i =0;i < n;i++){
        for(int j = 0;j < m;j++){
            cin >> a[i][j];
        }
    }
    for(int i =0; i < n;i++){
        for(int j =0;j < m;j++){
            tmp += a[i][j] * b[j];
        }
        tmp =tmp + c;
      	//cout << tmp << endl;
        if(tmp > 0)ans++;
        tmp = 0;
    }
    cout << ans;
}
   


Measured memory_bytes: 3640
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n<105) printf("0\n");
        else
        {
            int ans=1;
            for(int i=106;i<=n;++i)
            {
                int num=0;
                for(int j=1;j<=i;++j)
                {
                    if(i%j==0)
                    {
                        num++;
                    }
                }
                if(num==8&&i&1)
                    ans++;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::Read;

const MOD: i64 = 998244353;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut ds: Vec<usize> = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect();

    let mut invalid = ds[0] != 0;
    for i in 1..n {
        if ds[i] == 0 {
            invalid = true;
        }
    }

    if invalid {
        println!("0");
    } else {
        ds.sort();
        let mut max = 0;
        let mut count: Vec<i64> = vec![0; n];
        for i in 0..n {
            max = std::cmp::max(max, ds[i]);
            count[ds[i]] += 1;
        }

        let mut res = 1;
        for i in 1..max + 1 {
            if count[i] == 0 {
                res = 0;
                break;
            }
            for _ in 0..count[i] {
                res *= count[i - 1];
                res %= MOD;
            }
        }

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


Measured memory_bytes: 6396
#include <iostream>    // cin, cout
#include <string>    // string, stoi, to_string
#include <algorithm>    // sort, lower_bound, heap, min, next_permutation 
#include <functional>    // greater, less
#include <vector>    // vector
#include <stack>    // stack
#include <queue>    // queue
#include <list>    // list
#include <map>    // map
#include <set>    // set
#include <tuple>    // tuple
#include <bitset>    // bitset
#include <cstdio>  // fopen, printf, scanf, puts
#include <cmath>    // sin, exp, log, pow, sqrt
#include <iomanip>    // setfill, setbase

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n/2), b(n/2);
    vector<int> ac(100001), bc(100001);
    for(int i=0; i<n; i++)
    {
        if(i%2 == 0)
        {
            cin >> a.at(i/2);
            ac.at(a.at(i/2))++;
        }
        else
        {
            cin >> b.at(i/2);
            bc.at(b.at(i/2))++;
        }
    }
    int maxa = 0, maxb = -1, maxa2 = 0, maxb2 = -1, ansa, ansb;
    for(int i=1; i<100001; i++)
    {
        if(ac.at(i) > maxa)
        {
            maxa2 = maxa;
            maxa = ac.at(i);
            ansa = i;
        }
        else if(ac.at(i) > maxa2) maxa2 = ac.at(i);
        if(bc.at(i) > maxb)
        {
            maxb2 = maxb;
            maxb = bc.at(i);
            ansb = i;
        }
        else if(bc.at(i) > maxb2) maxb2 = bc.at(i);
    }
    if(ansa != ansb) cout << n - maxa - maxb << endl;
    else cout << min(n - maxa2 - maxb, n - maxa - maxb2) << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(void) {
  int K, S;
  scanf("%d %d", &K, &S);

  int ANS = 0;
  for(int x = 0; x <= K; x++) {
    for(int y = 0; y <= K; y++) {
      int z = S - x - y;
      if(0 <= z && z <= K)
	ANS++;
    }
  }
  printf("%d\n", ANS);
  return 0;
}


Measured memory_bytes: 128
//Code By CXY07
#include<bits/stdc++.h>
using namespace std;

//#define int long long

const int MAXN = 1010;
const int INF = 2e9;
const int mod = 1e9 + 7;

int n,m,k,ans = INF,cnt;
int a[MAXN][MAXN],s[MAXN][MAXN];
char tmps[MAXN];

inline int sum(int x2,int y2,int x1,int y1) {
	if(x1 > x2 || y1 > y2) return 0;
	return s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
}

signed main () {
	cin >> n >> m >> k;
	for(register int i = 1;i <= n; ++i) {
		cin >> tmps + 1;
		for(register int j = 1;j <= m; ++j) {
			a[i][j] = tmps[j] - '0';
			s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
		}
	}
	for(register int p = 0,pre,pred,flag,id;p < (1 << (n - 1)); ++p) {
		cnt = 0;
		pre = pred = flag = 1;
		for(register int j = 0;j < n; ++j)
			if(p & (1 << j)) cnt++;
		for(register int i = 1;i <= m; ++i) {
			id = false;
			pred = 1;
			for(register int j = 0;j < n; ++j) {
				if(!(p & (1 << j))) continue;
				if(sum(j + 1,i,pred,pre) > k) {
					if(!id) {
						if(i == pre) {flag = false; break;}
						id = true;
						cnt++;
						pre = i;
					}
				}
				pred = j + 2;
			}
			if(sum(n,i,pred,pre) > k) {
				if(!id) {
					if(i == pre) {flag = false; break;}
					id = true;
					cnt++;
					pre = i;
				}
			}
			if(!flag) break;
		}
		if(sum(n,m,pred,pre) > k) flag = 0;
		if(flag) ans = min(ans,cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2304
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

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

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC 163 -A 
int main(void) {
	int a, b, rc;

	scanf("%d %d", &a,&b);
    rc  = (a + b) % 2;
	if (a == b || rc == 0) printf("%d\n", (a + b) / 2);
	else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 128
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> A, B;
  
  for (int i = 1; i <= 20000; i++) {
    int ka = (int)((double)i * 0.08), kb = (int)((double)i * 0.1);
    if (ka == A && kb == B)
      return i;
  }
  
  return -1;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}





Measured memory_bytes: 256
N, A, B = map( int, input().split() )
MOD = 10 ** 9 + 7

def comb( n, r ):
  c = 1
  m = 1
  r = min( r, n - r )
  for i in range( r ):
    c = ( c * ( n - i )) % MOD
    m = ( m * ( i + 1 )) % MOD 
  return c * pow( m, MOD - 2, MOD ) % MOD

n = pow( 2, N, MOD ) - 1
a = comb( N, A )
b = comb( N, B )
print(( n - a - b ) % MOD )

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
 
  int n,l; cin >> n >> l;
  int sum=0;
  rep(i,0,n){
    sum+=l+i; 
  }  
  int ans=mod;
  rep(i,0,n){
  	int t=sum-l-i;
    if(abs(ans-sum)>abs(t-sum)) ans=t;
  }
   cout << ans << endl;  
 }

Measured memory_bytes: 256
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,h,w;
	cin >> n >> h >> w;
	int sum = 0;
	rep(i,n){
		int a,b;
		cin >> a >> b;
		sum += (a / h && b / w);
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;

int pl,cn,w,sp;
int W,page,line,col;
vector<vector<string> > ans;

void out(string s)
{
	if(col==0&&line==0)
	ans.pb(vector<string>(pl,string(W,'.')));
			
	int x=(w+sp)*col,l=s.size();
	rep(i,min(l,w))ans[page][line][x+i]=s[i];
	if(++line==pl)
	{
		line=0;
		if(++col==cn)col=0,page++;
	}
	if(l>w)out(s.substr(w));
}
int main()
{
	while(cin>>pl,pl)
	{
		cin>>cn>>w>>sp; cin.ignore();
		
		W=cn*w+sp*(cn-1); page=line=col=0;
		ans.clear();
		
		string str;
		while(getline(cin,str),str!="?")out(str);
		rep(i,ans.size())
		{
			rep(j,pl)cout<<ans[i][j]<<endl;
			cout<<"#"<<endl;
		}
		cout<<"?"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,k;
  bool flag = false;
  cin >> n >> m >> k;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      if(i*m+j*n-2*i*j == k) flag = true;
    }
  }
  cout << (flag?"Yes":"No") << endl;
}

Measured memory_bytes: 256
N, = list(map(int,input().split()))
h  = list(map(int,input().split()))
c = [0 for i in range(N)]
c[1] = abs(h[0]-h[1])
for i in range(2, N):
  c[i] = min(c[i-2]+abs(h[i]-h[i-2]), c[i-1]+abs(h[i]-h[i-1]))
print(c[-1])

Measured memory_bytes: 13928
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main()
{
	long int m,n,x,i,b;
	scanf("%ld",&n);
	m=n;
	x=sqrt(n);
	for(i=x;i>=1;i--)
	{
		if(n%i==0)
		{
			b=n/i;
			break;
		}
	}
	long long int c=b+i-2;
	printf("%ld",c);
	return 0;
}

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

int main(){
	int n,i,a=100000,b;
	std::cin>>n;
	for(i=0;i<n;i++){
		a=a*1.05;
		if(a%1000!=0){
			b=a%1000;
			b=1000-b;
			a=a+b;
			}
		}
	std::cout<<a<<std::endl;

	
	
	return 0;
	}

Measured memory_bytes: 1160
from scipy.special import comb
s = int(input())
mod = 10**9 + 7
ans = 0
if s > 2:
    max_size = s // 3
    for i in range(max_size):
        bumpai = int(s - (i+1)*3)
        if i == 0:
            ans += 1
        else:
            c = comb(bumpai+i, i, exact=True)
            ans += c
ans = int(ans % mod)
print(ans)

Measured memory_bytes: 42072
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
//#define MOD (1000000007)
#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

int fr[1000005];

int nCr(int n,int r){
    if(n<r)return 0;
    if(n-r<r)r=n-r;
    int ans=1;
    for(int i=1;i<=r;i++){
        ans=(ans*(n-i+1)/i);
    }
    return ans;
}

signed main(){
    FASTER;
    int n;cin>>n;
    vi v(n);cin>>v;
    for(int i=0;i<n;i++)fr[v[i]]++;
    
    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=nCr(fr[i],2);
    }
    for(int i:v){
        ans-=nCr(fr[i],2);
        ans+=nCr(fr[i]-1,2);
        cout<<ans<<"\n";
        ans-=nCr(fr[i]-1,2);
        ans+=nCr(fr[i],2);
        
    }
    
}

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

int main(){
  int n, i;
  string taro, hanako;
  int t_point = 0;
  int h_point = 0;
  cin >> n;
  for(int n_i=0; n_i<n; n_i++){
    cin >> taro >> hanako;
    i=0;
    while(1){
      if(taro[i] > hanako[i]){
         t_point +=3;
         break;
      }else if(taro[i] < hanako[i]){
         h_point +=3;
         break;
      }
      i++;
      if(taro[i] && !hanako[i]){
        t_point +=3;
        break;
      }else if(!taro[i] && hanako[i] ){
        h_point +=3;
        break;
      }else if(!taro[i] && !hanako[i]){
        t_point +=1;
        h_point +=1;
        break;
      }
    }
  }
  cout << t_point << " " << h_point << endl;
  return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int r;
    cin >> r;
    if(r < 1200)
        cout << "ABC";
    else if(r < 2800)
        cout << "ARC";
    else
        cout << "AGC";
    return 0;
}

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

int main()
{
  char alpha;
  // A-Z 65 - 90
  // a-z 97 -122
  char ans;

  cin >> alpha;

  // printf("%d", alpha);

  if ((int)alpha >= 65 && (int)alpha <= 90)
  {
    cout << "A" << endl;
  }
  else
  {
    cout << "a" << endl;
  }

  // cout << ans << endl;
}


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



// 左左、左右、右左、右右 の4択
int n, m, q, a[100100], b[100100], x;

signed main() {
	cin >> n >> m >> q;
	rep(i,n) cin >> a[i];
	rep(i,m) cin >> b[i];
	while (q--) {
		cin >> x;
		int res = 1ll<<60;
		int ra = lower_bound(a,a+n,x) - a, rb = lower_bound(b,b+m,x) - b;
		int la = ra-1, lb = rb-1;
		if (la>=0 && lb>=0) chmin(res, max(abs(x-a[la]), abs(x-b[lb])));
		if (la>=0 && rb<m) chmin(res, max(abs(x-a[la]), abs(x-b[rb])) + min(abs(x-a[la]), abs(x-b[rb]))*2);
		if (ra<n && lb>=0) chmin(res, max(abs(x-a[ra]), abs(x-b[lb])) + min(abs(x-a[ra]), abs(x-b[lb]))*2);
		if (ra<n && rb<m) chmin(res, max(abs(x-a[ra]), abs(x-b[rb])));
		cout << res << endl;
	}
}

Measured memory_bytes: 2944
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))
  else:
    # N = 3
    # V = [10,2,5]
    # C  = [6,3,4]
    # N = 4
    # V = [13,21,6,19]
    # C  = [11,30,6,15]
    N = 1
    V = [1]
    C  = [50]
  i = 0
  ans = 0
  D = []
  for i in range(N):
    tmp = V[i] - C[i]
    if tmp > 0:
      ans += tmp
    
  print(ans)
  
main()

Measured memory_bytes: 3064
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};

template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

int dfs(int v, const WeightedGraph<int> &G, vector<int> &dp) {
  if (dp[v] != -INF<int>) {
    return dp[v];
  }

  int res = 0;
  for (auto e : G[v]) {
    chmax(res, dfs(e.to, G, dp) + e.cost);
  }

  return dp[v] = res;
}

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

  int N, M;
  cin >> N >> M;
  WeightedGraph<int> G(N);
  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a].emplace_back(b, c);
  }

  vector<int> dp(N, -INF<int>);

  int ans = 0;
  REP(i, N) { chmax(ans, dfs(i, G, dp)); }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3212
#include<iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c)
    cout<<"No";
    else if(a==b || b==c || a==c)
    cout<<"Yes";
    else 
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010

int main(){
	IOS;
	ll n;cin>>n;
	ll a[n];rep(i,0,n)cin>>a[i];
	int f=1;
	if(n==1)cout<<"Yes";
	else{
		rep(i,1,n){
			if(a[i]<a[i-1]){
				if(a[i-1]-a[i]>1)f=0;  
				if(a[i-1]-a[i]==1)a[i]++;
		}
		}
		if(f)cout<<"Yes";
		else cout<<"No";
	}
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int n, a, maior = -10000, menor = 10000;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a > maior){
      maior = a;
    }
    if(a < menor){
      menor = a;
    }
  }
  cout << maior - menor;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
const int MAXN=310;
long double f[MAXN][MAXN][MAXN];
int n,tot[4];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;scanf("%d",&x);
		tot[x]++;
	}
	for(int k=0;k<=n;k++)
		for(int j=0;j<=n;j++)
			for(int i=0;i<=n;i++)
				if(i|j|k){
					f[i][j][k]=n/(long double)(i+j+k);
					if(i)
						f[i][j][k]+=f[i-1][j][k]*i/(long double)(i+j+k);
					if(j)
						f[i][j][k]+=f[i+1][j-1][k]*j/(long double)(i+j+k);
					if(k)
						f[i][j][k]+=f[i][j+1][k-1]*k/(long double)(i+j+k);
					// printf("(%d %d %d) %.12Lf\n",i,j,k,f[i][j][k]);
				}
	// for(int i=0;i<=1;i++)for(int j=0;j<=1;j++)for(int k=0;k<=1;k++)printf("(%d,%d,%d) %.12Lf\n",i,j,k,f[i][j][k]);
	printf("%.16Lf\n",f[tot[1]][tot[2]][tot[3]]);
	return 0;
}

Measured memory_bytes: 452736
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    A = list(map(int, readline().rstrip().split()))
    if K <= N:
        pre = 1
        for _ in range(K):
            pre = A[pre-1]
        print(pre)
        return

    pre = 1
    visited_set = set([1])
    visited = [1]
    for i in range(N):
        pre = A[pre-1]
        if pre in visited_set:
            break
        visited_set.add(pre)
        visited.append(pre)
    
    loop_start = visited.index(pre)
    loop = i - loop_start + 1

    num_loop = (K - loop_start) // loop
    now = loop_start + num_loop * loop
    for i in range(now+1, K+1):
        pre = A[pre-1]
    
    print(pre)

if __name__ == '__main__':
    main()

Measured memory_bytes: 33432
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
bool bn[220001][3];
int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		if (a == 1)bn[b][0] = true;
		else if (a == n)bn[b][1] = true;
		if (b == 1)bn[a][0] = true;
		else if (b == n)bn[a][1] = true;
	}
	for (int i = 1; i < n; i++) {
		if (bn[i][0] && bn[i][1]) {
			cout << "POSSIBLE\n";
			return 0;
		}
	}
	cout << "IMPOSSIBLE\n";
	return 0;
}

Measured memory_bytes: 768
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 11:57:51 2020

@author: shinba
"""

A = list(map(int,input().split()))

B = [[5,5,7],[5,7,5],[7,5,5]]

if A in B:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 2940
str=input()
n=len(str)
evenzero=0
evenone=0
oddzero=0
oddone=0
count=0
for x in range(n):
    if x%2==0:
        if str[x]=="0":
            evenzero +=1
        else:
            evenone +=1
    else:
        if str[x]=="0":
            oddzero +=1
        else:
            oddone +=1

t=max(evenzero+oddone,evenone+oddzero)

if t==evenzero+oddone:
    for x in range(n):
        if x % 2 == 0:
            if str[x] != "0":
                count += 1
        else:
            if str[x] != "1":
                count += 1
elif t==evenone+oddzero:
    for x in range(n):
        if x % 2 == 0:
            if str[x] != "1":
                count += 1
        else:
            if str[x] != "0":
                count += 1

print(count)


Measured memory_bytes: 3188
/*{{{*/
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>

#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

typedef long long ll;
typedef std::pair<int, int> pii;

std::string Name = __FILE__;
std::string iput = Name.substr(0, Name.length() - 4) + ".in";
std::string oput = Name.substr(0, Name.length() - 4) + ".out";

template <class T> inline bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template <class T> inline bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }

template <class T> inline T &read(T &x)
{
    static int f;
    static char c; 
    for (f = 1; !isdigit(c = getchar()); ) {
        if (c == '-')
            f = -1;
    }
    for (x = 0; isdigit(c); c = getchar()) {
        x = x * 10 + c - 48;
    }
    return x *= f;
}
 
template <class T> inline void write(T x, const char p = '\n')
{
    static int top;
    static int s[30];
    if (x < 0) {
        x = -x;
        putchar('-');
    }
    do s[++ top] = x % 10 + 48;
    while (x /= 10);
    while (top)
        putchar(s[top --]);
    putchar(p);
}
/*}}}*/
 
const int maxn = 100 + 5;
 
long long n;
long long W;
long long w[maxn], ww[maxn], v[maxn];
long long f[maxn][3 * maxn];

long long check(long long K)
{
    memset(f, 0, sizeof f);
    long long rem = std::min(W - K * w[1], 3 * K);
    if (rem < 0) return 0;
    for (int i = 1; i <= n; ++ i)
        for (int j = i; j; -- j)
            for (int k = rem; k >= ww[i]; -- k)
                chkmax(f[j][k], f[j - 1][k - ww[i]] + v[i]);
    long long ret = 0;
    for (int j = 0; j <= rem; ++ j) chkmax(ret, f[K][j]); 
    return ret;
}

void exec()
{
    read(n), read(W);
    for (int i = 1; i <= n; ++ i) {
        read(w[i]);
        read(v[i]);
        ww[i] = w[i] - w[1];
    }
    int l = 1, r = n, mid1, mid2;
    while (l + 5 < r) {
        mid1 = (l + l + r) / 3;
        mid2 = (l + r + r) / 3;
        if (check(mid1) < check(mid2))
            l = mid1;
        else
            r = mid2;
    }
    long long ans = 0;
    for (int i = l; i <= r; ++ i) chkmax(ans, check(i));
    write(ans);
}

/*{{{*/
int main() 
{
    if (fopen(iput.c_str(), "r") != NULL) {
        freopen(iput.c_str(), "r", stdin);
        freopen(oput.c_str(), "w", stdout);
    }

    exec();

    fclose(stdin);
    fclose(stdout);

    return 0;
}
/*}}}*/




Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	long long  a,b,c,x,y,sum;
	while(scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y)!=EOF)
	{
		sum=max(x,y)*2*c;
    sum=min(sum,min(x,y)*2*c+(y>x?(y-x)*b:(x-y)*a));
    sum=min(sum,a*x+b*y);
    printf("%lld\n",sum);
	}
	return 0;
}

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

using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

int main() {
  int N; cin >> N;
  vector<int> A(N);
  vector<vector<int>> x(N), y(N);
  REP(i, N) {
    cin >> A[i];
    REP(k, A[i]) {
      int tmp_x, tmp_y;
      cin >> tmp_x >> tmp_y;
      x[i].push_back(tmp_x);
      y[i].push_back(tmp_y);
    }
  }

  int ans = 0;
  for(int bit = 0; bit < (1 << N); ++bit) {
    bool flag = false;
    REP(i, N) {
      if(!(bit & (1 << i))) continue;
      REP(k, A[i]) {
        if(y[i][k] == 1) {
          if( !(bit & (1 << (x[i][k] - 1))) ) {
            flag = true;
          }
        } else if(y[i][k] == 0) {
          if(bit & (1 << (x[i][k] - 1))) {
            flag = true;
          }
        }

        // cout << bitset<16>(bit) << " " << (x[i][k] - 1) << endl;
      }

      if(flag) break;
    }

    if(flag == false) {
      int check = __builtin_popcount(bit);
      if(ans < check) {
        ans = check;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int N,a,b,c;
	cin>>N;
	a=N/100;
	b=(N%100)/10;
	c=N-100*a-10*b;
	if(c==a)
	{
		cout<<"Yes"<<endl;
	}
	else if(c!=a)
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;

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

	rep(i, n-k) {
		if (a[i] < a[k + i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


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

int main() {
  int n, v;
  bool y = false;
  cin >> n;  
  for (int i = 0; i < n; i++) {    
  	int l, r;
    cin >> l >> r;
    v += r - l + 1;
  }
  cout << v << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	string S;
	cin >> S;


	vbool check(4);
	for (int i = 0; i < 4; i++) {
		check[i] = false;
	}


	for (int i = 0; i < S.length(); i++) {
		if (S[i] == 'N') {
			check[0] = true;
		}
		else if (S[i] == 'S') {
			check[1] = true;
		}
		else if (S[i] == 'W') {
			check[2] = true;
		}
		else {
			check[3] = true;
		}
	}


	if (check[0] == check[1] && check[2] == check[3]) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}


}


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

int main(){
  int n,i,j;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  int b=1,cnt=0;
  for(i=0;i<n;i++){
  	b=a[b-1];
    cnt++;
    if(b==2){
      cout<<cnt;
      return 0;
    }
  }
  cout<<-1;
}

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

void sieve(int n,vector<char>& v){
    v.resize(n+1);
    fill(v.begin(),v.end(),true);
    v[0]=v[1]=false;

    for(int i=2;i*i<=n;i++){
        if(v[i]){
            for(int j=2*i;j<=n;j+=i){
                v[j]=false;
            }
        }
    }
}

int main(){
    vector<char> prime_list;
    int n;

    sieve(1<<22,prime_list);

    while(cin>>n,n){
        int sum=0;
        for(int i=2;n;i++){
            if(prime_list[i]){
                sum+=i;
                n--;
            }
        }

        cout<<sum<<endl;
    }

    return 0;
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef long double ld;
#define mkp make_pair
int main()
{
	string s;
	cin>>s;
	if(s[2] == s[3]&&s[4] == s[5])
	{
		cout<<"Yes\n";
	}
	else
		cout<<"No\n";
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int mod=1e9+7;
using namespace std;
int n;
int a[200];
int main()
{
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin>>n;
    double sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    int ans;
    if(sum>0)
       ans=sum/n+0.5;
    else
        ans=sum/n-0.5;
    int t=0;
    for(int i=0;i<n;i++)
    {
        t+=(a[i]-ans)*(a[i]-ans);
    }
    cout<<t<<endl;
}



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

int A[2000];

int toSolve(int,int);

int n;
int q;

int i,j;

int main(){

  int solve;
  int m;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(j = 0;j < q;j++){
    scanf("%d",&m);

    solve = toSolve(0,m);
    if(solve == 1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}


int toSolve(int i,int m){

  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;
  res = toSolve(i+1,m)||toSolve(i + 1,m - A[i]);
     return res;
}

Measured memory_bytes: 584
from collections import Counter
import string
import re

c = Counter()

N = int(re.split('\s', raw_input())[0])

for i in range(N):
  l = sorted([int(i) for i in re.split('\s', raw_input())[0:3]])
  c[frozenset(l)] += 1

print(len(list(c.elements())) - len(list(c)))


Measured memory_bytes: 5396
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif // __GNUC_

int main() {

    int N, M;
    std::cin >> N >> M;
    int left = 0;
    int right = N;
    for (int i = 0; i < M; ++i) {
        int L, R;
        std::cin >> L >> R;
        left = std::max(left, L-1);
        right = std::min(right, R);
    }

    std::cout << std::max(right - left, 0) << std::endl;

}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    int ans = 0;
    vector<int> V(N), C(N);
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }
    for (int i = 0; i < N; i++) {
        if (V[i] - C[i] < 0) continue;
        ans += V[i] - C[i];
    }
    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
import sys
from math import*
for e in sys.stdin:
 a,b,c,d,e,f=map(float,e.split(','))
 z,w,q=complex(a,b),complex(c,d),complex(e,f)
 z+=((z-w)/abs(z-w))**2*(q-z).conjugate()
 print(z.real,z.imag)


Measured memory_bytes: 5648
import math
#試し割法
def trial_division(n):
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    if not factor:
        factor.append(1)
        factor.append(n)
        return factor
    else:
        factor.append(1)
        factor.append(n)
        return factor
A,B=map(int,input().split())
A_primes=trial_division(A)
B_primes=trial_division(B)
primes=[]
for p in A_primes:
  if p in B_primes:
    primes.append(B_primes.pop(B_primes.index(p)))
print(len(list(set(primes))))


Measured memory_bytes: 8908
a = [[]*3]*3

for i in range(3):
  a[i] = [int(i) for i in input().split()]

n = int(input())

for i in range(n):
  b = int(input())
  for j in range(3):
    if b in a[j]:
      for k in range(3):
        if b == a[j][k]:
          a[j][k] = 0
          break
b = 0          
for i in range(3):
  if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0:
    b += 1
    break
  elif a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0:
    b += 1
    break
  elif a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    b += 1
    break
  elif a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0:
    b += 1
    break

if b == 1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,x,kids=0;
    cin >> N >> x;
    vector<int>a(N);
    for(int i=0;i<N;i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    for(int i=0;i<N;i++){
        if(x < a.at(i))break;
        x-=a.at(i);
        if(i!=N-1 || x==0)kids++;
    }
    cout << kids;
}

Measured memory_bytes: 256
s=input()
n=len(s)
ans="Yes"
if n%2==0:
    for i in range(n//2):
        if s[2*i]=="L":
            ans="No"
            break
        if s[2*i+1]=="R":
            ans="No"
            break
else:
    if s[0]=="L":
        ans="No"
    for i in range(1,n//2+1):
        if s[2*i]=="L":
            ans="No"
            break
        if s[2*i-1]=="R":
            ans="No"
            break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>


int main() {
	int n; std::cin >> n;
	std::vector<long double> nums(n); for (auto& a : nums) std::cin >> a;
	long double result = 0;
	for (const auto a : nums) {
		result += 1 / a;
	}
	std::cout << std::fixed << std::setprecision(15) << 1 / result << std::endl;
}



Measured memory_bytes: 384
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

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

const ll mod = 1e9 + 7;
const int N = 2e5 + 10, M = 1e3 + 10;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;

#define pi acos(-1)

char str[N << 1];

int main()
{
    int flag = 1;
    string s;
    cin >> s;
    int t;
    cin >> t;
    int cnt1 = N;
    int cnt2 = N + 1;
    while(t--)
    {
        int ti, fi;
        char c[2];
        scanf("%d", &ti);
        if(ti == 1)
        {
            flag ^= 1;
        }
        else
        {
            scanf("%d%s", &fi, c);
            if(fi == 1)
            {
                if(flag)
                {
                    str[cnt1--] = c[0];
                }
                else
                {
                    str[cnt2++] = c[0];
                }   
            }
            else
            {
                if(!flag)
                {
                   str[cnt1--] = c[0];
                }
                else
                {
                    str[cnt2++] = c[0];
                }   
            }       
        } 
    }
    if(!flag)
        reverse(s.begin(), s.end());
    if(flag)
    {
        for(int i = cnt1 + 1; i <= N; i++)
        {
            printf("%c", str[i]);
        }
        cout << s;
        for(int i = N + 1; i < cnt2; i++)
           printf("%c", str[i]);
    }
    else
    {
        for(int i = cnt2 - 1; i > N; i--)
             printf("%c", str[i]);
        cout << s;
        for(int i = N; i > cnt1; i--)
             printf("%c", str[i]);
    }
    return 0;
}

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

using namespace std;

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

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1.0);

ll n;
string s;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n >> s;
    if (n < 3200)
        cout << "red" << endl;
    else
        cout << s << endl;
}

Measured memory_bytes: 256