akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    bool B[N] = {false};
    int C[N];
    int T;
    int rest = -1;

    int position = 0;
    for(int i = 0; i < K; i++){
        position = A[position] - 1;
        if(B[position]){
            T = i - C[position];
            rest = (K - i - 1)%T;
            break;
        }
        else{
            B[position] = true;
            C[position] = i;
        }
    }
    if(rest != -1){
        for(int i = 0; i < rest; i++){
            position = A[position] - 1;
        }
    }

    cout << position + 1 << endl;


}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	cout<<360/__gcd(360, n)<<endl;

	return 0;
}

Measured memory_bytes: 3632
use std::io::stdin;
fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let s:Vec<char> = st.trim().chars().collect();
    let mut t = 1;
    let mut c:usize = 0;
    let mut r:[usize;2020] = [0;2020];
    let m = s.len() as usize;
    for i in 1..m+1 {
        let x = (s[m-i] as usize)-48;
        c = (c+x*t)%2019;
        r[c] += 1;
        t = (t*10)%2019;
    };
    c = 0;
    for i in 0..2019 {
        if &1 < &r[i] {
            c += (r[i]-1)*r[i]/2
        };
    };
    c += r[0];
    println!("{}", c);
}

Measured memory_bytes: 2964
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int a, b;
	cin >> a >> b;
	if(b%a==0){
		cout << a+b << endl;
	} else {
		cout << b-a << endl;
	}

	return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
int k;

int main() {

	cin >> k;

	cout << a[k - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
  int N,i,key,A[105],j,n;
  scanf("%d",&N);
  //  A=(int*)malloc(N);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
  for(i=0;i<N;i++){
    key=A[i];
    j=i-1;
    while(j>=0 && A[j]>key){  
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    for(n=0;n<N;n++){
      printf("%d",A[n]);
      if(n<N-1)
	printf(" ");
    }
    printf("\n");
  }
  //  free(A);
  return 0;
}

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

int main() {
	ll h, w, k;
	cin >> h >> w >> k;
	vector<string> v(h);
	for (ll i = 0; i < h; ++i) cin >> v[i];
	ll ans = 0;
	for (ll hbit = 0; hbit < (1 << h); ++hbit) {
		for (ll wbit = 0; wbit < (1 << w); ++wbit) {
			ll cnt = 0;
			for (ll i = 0; i < h; ++i) {
				for (ll j = 0; j < w; ++j) {
					if (v[i][j] == '#') {
						if (!(hbit & (1 << i)) && !(wbit & (1 << j))) {
							++cnt;
						}
					}
				}
			}
			if (cnt == k)++ans;
		}
	}
	cout << ans << endl;
}


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

int main(int argc, char *argv[]){

	int i;
	int c;
	int count=0;
	int o_flag=-10, x_flag=-10;
	int n;

	scanf("%d",&n);
	for(i=0;i<=n;i++){
		c=getchar();
		switch(c){
			case 'O':
				o_flag=i;
				if(i-x_flag==1){
					count++;
					o_flag=-10;
					x_flag=-10;
				}
				break;
			case 'X':
				x_flag=i;
				if(i-o_flag==1){
					count++;
					o_flag=-10;
					x_flag=-10;
				}
				break;
			default: break;
		}

	}

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


Measured memory_bytes: 2148
#include <bits/stdc++.h>
int main(int argc, char** argv)
{
    using namespace std;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string a, b;
    cin >> a >> b;
    for (int i = 0; i != 3; ++i)
    {
        if (a.at(i) != b.at(2 - i))
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(a,i,n) for(int i=(a);i<(n);i++)
#define ZERO 0
typedef long long ll;
using namespace std;

void set_one(ll *a,ll n){
	rep(0,i,n){
		a[i] = 1;
	}
}

int main(){
	ll n,m,count=0;
	cin >> n >> m;

	ll h[n];
	rep(0,i,n){
		cin >> h[i];
	}

	ll a[m],b[m];
	rep(0,i,m){
		cin >> a[i] >> b[i];
	}

	ll s[n];
	set_one(s,n);

	rep(0,i,m){
		if(h[a[i]-1] > h[b[i]-1])
			s[b[i]-1] = ZERO;
		else if(h[a[i]-1] < h[b[i]-1])
			s[a[i]-1] = ZERO;
		else if(h[a[i]-1] == h[b[i]-1]){
			s[a[i]-1] = ZERO;
			s[b[i]-1] = ZERO;
		}
	}

	rep(0,i,n){
		if(s[i] != ZERO)
			count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 6720
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


enum Type{
	COLLISION,
	SHRINK,
};

struct Info{
	double first_x,first_y,first_z,v_x,v_y,v_z,r,v_r;
};

struct Data{
	Data(Type arg_type,int arg_id_1,int arg_id_2,double arg_time){
		type = arg_type;
		id_1 = arg_id_1;
		id_2 = arg_id_2;
		time = arg_time;
	}
	bool operator<(const struct Data &arg) const{
		return time > arg.time;
	}
	Type type;
	int id_1,id_2;
	double time;
};

int N;
Info info[200];
bool deleted[200];
double ans[200];
priority_queue<Data> Q;


double calc(double a,double b,double c){
	if(fabs(a) < EPS)return DBL_MAX;
	if(b*b-4.0*a*c < 0)return DBL_MAX; //解なし
	double ans_1 = (-b+sqrt(b*b-4.0*a*c))/(2.0*a);
	double ans_2 = (-b-sqrt(b*b-4.0*a*c))/(2.0*a);

	if(ans_1 <= 0)ans_1 = DBL_MAX;
	if(ans_2 <= 0)ans_2 = DBL_MAX;
	return min(ans_1,ans_2);
}


void func(){

	for(int i = 0; i < N; i++)deleted[i] = false;

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&info[i].first_x,&info[i].first_y,&info[i].first_z,&info[i].v_x,
				&info[i].v_y,&info[i].v_z,&info[i].r,&info[i].v_r);
		Q.push(Data(SHRINK,i,-1,info[i].r/info[i].v_r)); //縮んで消える時刻をpush
	}

	double first_x_diff,v_x_diff,first_y_diff,v_y_diff,first_z_diff,v_z_diff,first_r_sum,v_r_sum;
	double tmp_time;

	//衝突で消える時刻を計算
	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){
			first_x_diff = info[i].first_x-info[k].first_x;
			first_y_diff = info[i].first_y-info[k].first_y;
			first_z_diff = info[i].first_z-info[k].first_z;

			v_x_diff = info[i].v_x-info[k].v_x;
			v_y_diff = info[i].v_y-info[k].v_y;
			v_z_diff = info[i].v_z-info[k].v_z;

			first_r_sum = info[i].r+info[k].r;
			v_r_sum = info[i].v_r+info[k].v_r;

			tmp_time = calc(v_x_diff*v_x_diff+v_y_diff*v_y_diff+v_z_diff*v_z_diff-v_r_sum*v_r_sum,
					2.0*(first_x_diff*v_x_diff+first_y_diff*v_y_diff+first_z_diff*v_z_diff+first_r_sum*v_r_sum),
					(first_x_diff*first_x_diff+first_y_diff*first_y_diff+first_z_diff*first_z_diff)-first_r_sum*first_r_sum);

			Q.push(Data(COLLISION,i,k,tmp_time));
		}
	}

	while(!Q.empty()){

		if(Q.top().type == SHRINK){
			if(deleted[Q.top().id_1] == false){
				deleted[Q.top().id_1] = true;
				ans[Q.top().id_1] = Q.top().time;
			}
		}else{ //COLLISION
			if(deleted[Q.top().id_1] == false && deleted[Q.top().id_2] == false){
				deleted[Q.top().id_1] = true;
				deleted[Q.top().id_2] = true;
				ans[Q.top().id_1] = Q.top().time;
				ans[Q.top().id_2] = Q.top().time;
			}
		}

		Q.pop();
	}

	for(int i = 0; i < N; i++){
		printf("%.10lf\n",ans[i]);
	}
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}




Measured memory_bytes: 3816
S = input()
left = int(S[0:2])
right = int(S[2:4])

if 1 <= left <= 12 and 1 <= right <= 12:
    print("AMBIGUOUS")
elif 0 <= left <= 99 and 1 <= right <= 12:
    print("YYMM")
elif 1 <= left <= 12 and 0 <= right <= 99:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D;
cin>>A>>B>>C>>D;
int area1,area2;
area1=A*B;
area2=C*D;
if(area1>area2){
	cout<<area1<<endl;
}
if(area1<area2){
	cout<<area2<<endl;
}
if(area1==area2){
cout<<area1<<endl;
}
return 0;

}

Measured memory_bytes: 256
s = input().strip()
n = len(s)
s = {i + 1 for i in range(n) if s[i] == '1'}

if n in s or 1 not in s or any(n - x not in s for x in s):
    print(-1)
else:
    s = sorted(s)
    c = 1
    e = []
    for i in range(1, len(s)):
        while c < s[i]:
            e.append((c, s[i]))
            c += 1
    e.append((c, n))
    e = [str(u) + ' ' + str(v) for u, v in e]
    print(*e, sep='\n')


Measured memory_bytes: 24676
///******* In the name of Allah *******///

#include <bits/stdc++.h>
using namespace std;

long long int opponent[300013];
void Ok()
{
    long long int a,b,c = 0,d,e,f,g,h,t,s,i,j,k,l1,l2,m,n,r,sum,ans_1,ans_2,ans_3,cnt = 0,Max,Min,flag,swi1,swi2;
    double aa,bb,cc,dd,ee,tot;
    char aaa[1013],bbb[1013],ccc[1013];

    cin>>h>>k;
    for(i=1;;i++)
    {
        if(h<=0)
        {
            break;
        }
        else
        {
            h -= k;
            cnt++;
        }
    }
    cout<<cnt<<endl;

    return;
}

int main()
{
    Ok();

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0;i<n;++i) cin >> a[i];
  
  int ans = 0;
  while (1){
    bool odd=false;
    for (int i=0;i<n;++i){
       if (a[i]%2==1) {
         odd=true;
       }
    }
    if (odd) break;
    ans++;
    for (int i=0;i<n;++i) {
      a[i]/=2;
    }
  }
  cout << ans << endl;
  return 0;
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,v[109],sm;
ll dp[109][100009],a[109],k;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>v[i];
        sm+=v[i];
    }
    memset(dp,-1,sizeof(dp));
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=sm;j++)
        {
            if(dp[i-1][j]==-1)continue;
            if(dp[i][j]==-1)dp[i][j]=dp[i-1][j];
            else dp[i][j]=min(dp[i][j],dp[i-1][j]);
            if(dp[i-1][j]+a[i]<=k)dp[i][j+v[i]]=dp[i-1][j]+a[i];
        }
    }
    /*for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=sm;j++)
        {
            cout<<dp[i][j]<<" ";
        }cout<<"\n";
    }*/
    for(int i=sm;i>=0;i--)
    {
        if(dp[n][i]==-1)continue;
        if(dp[n][i]>k)continue;
        cout<<i;
        return 0;
    }
}


Measured memory_bytes: 85376
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define pb push_back
#define ri(x) scanf("%d",&x)
#define rii(x,y) ri(x),ri(y)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define ms2(obj,val,sz) memset(obj,val,sizeof(obj[0])*sz)
#define FOR(i,f,t) for(int i=f;i<(int)t;i++)
#define FORR(i,f,t) for(int i=f;i>(int)t;i--)

typedef long long ll;
typedef vector<int> vi;

const int MAXN=2e5;

int N,A[MAXN],B[MAXN],j;

int main() {
	ri(N);
	FOR(i,0,N) ri(A[i]);
	j = N-1;
	FOR(i,0,(N+1)/2) B[i] = A[j], j-=2;
	j = 1 - (N%2 == 0);
	FOR(i,(N+1)/2,N) B[i] = A[j], j+=2;
	FOR(i,0,N) printf("%d ",B[i]);
	printf("\n");
}


Measured memory_bytes: 3712
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	long long ans = b - a + 1LL;
	ans -= b / c - (a-1) / c;
	ans -= b / d - (a - 1) / d;
	long long e = c * d / gcd(c, d);
	ans += b / e - (a - 1) / e;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll power(ll x, ll y, ll p)
{ll res = 1;x = x % p;while (y > 0){if (y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
ll modInverse(ll n, ll p)
{return power(n, p-2, p);}
ll nCr(ll n, ll r, ll p)
{if (r==0) return 1;ll fac[n+1];fac[0] = 1;for(ll i=1 ; i<=n; i++)fac[i] = fac[i-1]*i%p;return (fac[n]*modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p;}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll i, j, k, n, m, t, p, temp, flag, x, y, z, count, a, b, c, d, sum, ans;
	cin >> n;
	string str;
	i=0;
	while(n)
	{
		n--;
		str[i]=(n)%26+'a';
		i++;
		n/=26;
	}
	//cout << i << endl;
	i--;
	for(; i>=0; i--)
		cout << str[i];
	cout << endl;
	return 0;
}



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

int main(){
  int N, M, K; cin >> N >> M >> K;
  vector<int> A(N); rep(i, N) cin >> A[i];
  vector<int> B(M); rep(i, M) cin >> B[i];
  A.push_back(K + 1);
  B.push_back(K + 1);

  int t = 0, Ai = 0, Bi = 0;
  while (true) {
    if (t + A[Ai] > K) break;
    t += A[Ai];
    Ai++;
  }
  while (true) {
    if (t + B[Bi] > K) break;
    t += B[Bi];
    Bi++;
  }
  int ans = Ai + Bi;
  while (Ai >= 0) {
    Ai--;
    t -= A[Ai];
    while (true) {
      if (t + B[Bi] > K) break;
      t += B[Bi];
      Bi++;
    }
    ans = max(ans, Ai + Bi);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5552
from collections import Counter

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

d = Counter(A)
k = d.keys()

# print(d, k)


def nC2(x):
    return x * (x - 1) // 2


total = 0
for kk in k:
    total += nC2(d[kk])

# print(total)

for a in A:
    res = total
    res -= d[a] - 1
    print(res)


Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;cin>>K;
  int a=-1,m=0;
  for(int i=1;i<=1000000;i++){
    m=(m*10+7)%K;
    if(m==0){a=i;break;}
  }
  cout<<a<<endl;
}


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

int main() {
int A,B ;
    cin >> A >> B ;
  int priceAmin, priceAmax;
  int priceBmin, priceBmax;
  
  if(A%2==0){
  priceAmin=A/0.08;
  priceAmax=(A+1)/0.08;
  }
  if(A%2==1){
  priceAmin=A/0.08+1;
  priceAmax=(A+1)/0.08-1;
  }
  priceBmin=B/0.1;
  priceBmax=(B+1)/0.1-1;
  
int price=-1;
  if (priceAmin>=priceBmin&&priceAmin<=priceBmax){
   price=priceAmin;
  }
  else if (priceBmin>=priceAmin&&priceBmin<=priceAmax){
   price=priceBmin;
  }
  
  /*
   for(int i=priceAmin; priceAmax;i++){
   	for (int j=priceBmin; priceBmax; j++){
	 if (i==j){
     price=i;
       break;
     }
    }
   }
 */
  cout << price<< endl;  
}


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

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    if (A < K)
    {
        B -= min(K - A, B);
        A = 0;
    }
    else
    {
        A -= K;
    }
    cout << A << " " << B << endl;
    return 0;
}


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

int main(){
  int n;

  while(cin>>n, n){
    int c,max=0;
    for(int i=0; i<=100; i++){
      if(i*i*i > n) break;
      else {
	for(int j=0; j<=150; j++) {
	  if( (c=i*i*i + j*(j+1)*(j+2) /6) > n) {
	    break;
	  }else if(c > max) {
	    max = c;
	  }
	}
      }
    }

    cout<<max<<endl;
  }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    string s;
    cin >> s;
    cout << ((s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
const int mod = 1000000007;

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

int main()
{
    int n; cin >> n;
    VI a(n); rep(i, n) cin >> a[i];
    ll aa = 0;
    rep(i, n) {
        aa += a[i]*a[i];
        aa %= mod;
    }
    ll suma = 0;
    rep(i, n) {
        suma += a[i];
        suma %= mod;
    }
    ll ans = suma*suma - aa;
    ans %= mod;
    ans *= modinv(2, mod);
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
long long dp[100010];
long long h[100010];
const int MOD = 1000000007;

ll GCD(ll a, ll b)
{
    if (b == 0) return a;
    else return (GCD(b, a % b));
}

int main()
{
    int a, b, c; cin >> a >> b >> c;
    if (c % GCD(a, b) == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main() {
  int N; cin >> N;
  vector<int> v;
  for (int i=0; i<N; i++) {
    int x; cin >> x;
    v.push_back(x);
  }
  sort (v.begin(), v.end());
  int a=0;
  for (int i=0; i<N-1; i++) {
    if (v.at(i)!=v.at(i+1)) a++;
  }
  cout << a+1 << endl;
}

Measured memory_bytes: 256
// kayseekay :)
#include<bits/stdc++.h>
using namespace std;	
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;	
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n;
		cin >> n ;
		int ans =0 ;
		fn1{
			int x;
			cin >> x;
			if((x&1) && (i&1) )ans++;
		}

		cout <<ans;
	
	}
	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,a,num=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a;
        num+=a;
    }
    if(num<=n) cout<<n-num;
    else cout<<"-1";
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define int long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int mod = 1e9+7;

int32_t main(){
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	int x,y;
	cin>>x>>y;
	cout<<x+y/2<<"\n";	
	return 0;
}

Measured memory_bytes: 3560
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
    int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
		int[] answers = new int[n*n];
    int[][] numPositions = new int[n][];
    for(int i = 0; i < n; i++)
    {
      numPositions[i] = new int[2];
      numPositions[i][0] = i;
      numPositions[i][1] = nums[i]-1;
    }
    Array.Sort(numPositions, (a, b) => a[1].CompareTo(b[1]));
    bool answer = true;

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

    int leftNum = 0;
    int rightNum = n*n-1;
    for(int i = 0; i < n; i++)
    {
      for(int j = 0; j < numPositions[i][0]; j++)//置く個数
      {
        while(answers[leftNum] != 0)
        {
          if(leftNum < n*n-1) leftNum++;
        }
        
        if(leftNum >= numPositions[i][1])
        {
          answer = false;
          break;
        }else
        {
          answers[leftNum] = numPositions[i][0]+1;
          //Console.WriteLine(leftNum +" "+(numPositions[i][0]+1));
          leftNum++;
        }
      }
    }

    for(int i = n-1; i >= 0; i--)
    {
      for(int j = 0; j < n-numPositions[i][0]-1; j++)//置く個数
      {
        while(answers[rightNum] != 0)
        {
          if(rightNum > 0) rightNum--;
        }
        
        if(rightNum <= numPositions[i][1])
        {
          answer = false;
          break;
        }else
        {
          answers[rightNum] = numPositions[i][0]+1;
          //Console.WriteLine(rightNum +" "+(numPositions[i][0]+1)+"r");
          rightNum--;
        }
      }
    }

    if(answer)
    {
      Console.WriteLine("Yes");
		  Console.WriteLine(string.Join(" ", answers));
    }else Console.WriteLine("No");
	}
}

Measured memory_bytes: 22748
#include<stdio.h>
#include<string.h>

typedef struct{
  int t[6];
}sDice;


sDice d;

void f(int dire){
  int work;
  if(dire == 0){//S
    work = d.t[5];
    d.t[5] = d.t[1];
    d.t[1] = d.t[0];
    d.t[0] = d.t[4];
    d.t[4] = work;
  }else if(dire == 1){//W
    work = d.t[5];
    d.t[5] = d.t[3];
    d.t[3] = d.t[0];
    d.t[0] = d.t[2];
    d.t[2] = work;
  }else if(dire == 2){//N
    work = d.t[5];
    d.t[5] = d.t[4];
    d.t[4] = d.t[0];
    d.t[0] = d.t[1];
    d.t[1] = work;
  }else{
    work = d.t[5];
    d.t[5] = d.t[2];
    d.t[2] = d.t[0];
    d.t[0] = d.t[3];
    d.t[3] = work;
  }
}

int main(){
  int i;
  sDice d2;
  
  for(i=0; i<6; ++i) scanf("%d", &d.t[i]);
  for(i=0; i<6; ++i) scanf("%d", &d2.t[i]);

  
  if(d.t[2] == d2.t[1]){
    f(3),f(2);
  }else if(d.t[3] == d2.t[1]){
    f(1),f(2);
  }else{
    for(i=0; i<4; ++i){
      if(d2.t[1] == d.t[1]) break;
      f(0);
    }
  }
    
  for(i=0; i<4; ++i){
    if(d2.t[0] == d.t[0]) break;
    f(1);
  }

  for(i=0; i<6; ++i){
    if(d2.t[i] != d.t[i]){
      printf("No\n");
      break;
    }else if(i == 5){
      printf("Yes\n");
    }
  }
    
  return 0;
}



Measured memory_bytes: 2680
import sys
input = sys.stdin.readline

def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split())) + [0]

    ans = 0
    for i in range(N-1, -1, -1):
        tmp = a[i] + a[i+1] - x
        if tmp > 0:
            a[i] -= tmp
            ans += tmp
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14252
#include<iostream>
#include<queue>

using namespace std;

priority_queue<double> pq;

int main(void)

{
    double N, a, i, vol, b;
    cin>>N;
    for(i = 0; i < N; i++){
        cin>>a;
        a *= (-1);
        pq.push(a);
    }
    b = pq.top();
    b *= (-1);
    pq.pop();
    a = pq.top();
    a *= (-1);
    pq.pop();
    vol = (a+b)/2.0;
    while(!pq.empty()){
        a = pq.top();
        a *= (-1);
        pq.pop();
        vol = (a+vol)/2.0;
    }
    cout<<vol<<"\n";
    return 0;
}


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

#define int long long int
using namespace std;

signed main()
{
    int s, c;
    cin >> s >> c;

    int ans = min(s, c / 2);

    s -= ans;
    c -= 2 * ans;
    ans += c / 4;

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
typedef long long ll;

int n,m,q;
vector<int> a,b,c,d;

int dfs(int depth, vector<int> &A){
	if(depth==n){
		int ans=0;
		REP(i,q){
			if(A[b[i]-1] - A[a[i]-1] == c[i]) ans += d[i];
		}
		return ans;
	}
	
	int ans=0;
	if(depth==0){
		for(int i=1; i<=m; i++){
			A[depth] = i;
			ans = max(ans, dfs(depth+1, A));
		}
		return ans;
	}else{
		for(int i=A[depth-1]; i<=m; i++){
			A[depth] = i;
			ans = max(ans, dfs(depth+1, A));
		}
		return ans;
	}
	
	
	
}

int main(){
	cin >> n >> m >> q;
	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);
	REP(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
	
	vector<int> A(n);
	int ans = dfs(0,A);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};


const ll MaxN=201001;

ll f[MaxN], rf[MaxN];
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    REP(i, 1, MaxN) f[i] = (f[i - 1] * i) % mod;
    REP(i, 0, MaxN) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(ll n, ll k) {
    if(k<=0) return 0;
    if(n<=0) return 0;
    if(n<k) return 0;
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * bc) % mod;
}


int main(){
    init();
    ll N; cin>>N;
    vec Space(N+1,-1);
    ll A;
    ll m0,m1;
    rep(i,N+1){
        ll x; cin>>x;
        
        if(Space.at(x)==-1) Space.at(x)=i;
        else {m0=Space.at(x); m1=i; A=x;}
    }
    ll R=m1-m0+1;
    //cout<<A<<' '<<R<<endl;
    
    vec ans;
    if(N==1) rep(i,2) ans.pb(1);
    else {
        ans.pb(N);
        REP(i,2,N+2){
            ll ret=C(N+1,i);
            ret+=mod;
            ret-=C(N+1-R,i-1);
            ret=(ret%mod);
            ans.pb(ret);
            //cout<<i<<':'<<C(N+1,i)<<' '<<C(N+1-R,i-1)<<endl;
        }
    }
    rep(i,ans.size()) cout<<ans.at(i)<<endl;



}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    cout << (N / 2) * ((N+1) / 2) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
char s[100005],s1[100005];
int main()
{
    int flag = 0;
    int t = 0;
    scanf("%s",s);
    scanf("%s",s1);
    int len = strlen(s);
    int len1 = strlen(s1);
    if(len > len1) flag = 1;
    else if(len < len1) flag = 2;
    else 
        {
            for(int i = 0; ; i++){
                if(s[i] > s1[i]){
                    flag = 1;
                    break;
                }
                else if(s[i] < s1[i]) {
                    flag = 2;
                    break;
                }
                else if(s[i] == s1[i]){
                    t++;
                    if(t == len) break;
                }
            }
        }

        if(flag == 1) printf("GREATER\n");
        else if(flag == 2) printf("LESS\n");
        else if(t == len) printf("EQUAL\n");
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    long long N, M;
    cin >> N >> M;

    long long A = max(N, M);
    long long B = min(M, N);

    M = 1000000007;
    long long ans = 0;

    if (A - B == 1){
        ans = 1;
        for (int i = 1; i <= B; i++){
            ans = ans * i;
            ans = ans % M;
        }
        ans = ans * ans;
        ans = ans % M;

        ans = ans * A;
        ans = ans % M;
        
    }else if(A == B){
        ans = 1;
        for (int i = 1; i <= A; i++){
            ans = ans * i;
            ans = ans % M;
        }
        ans = 2 * ans * ans;
        ans = ans % M;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N, *L,  = [list(map(int, s.split())) for s in open(0)]
cnt = 0
for i in range(len(L) - 1):
    for j in range(i+1, len(L)):
        dist = 0
        for d in range(N[1]):
            dist += (L[i][d] - L[j][d]) ** 2
        if (dist ** (0.5)) % 1 == 0:
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
def main():
  ## IMPORT MODULE
  #import sys

  #sys.setrecursionlimit(100000)
  #input=lambda :sys.stdin.readline().rstrip()

  #f_inf=float("inf")
  MOD=998244353
  
  if 'get_ipython' in globals(): 
    ## SAMPLE INPUT
    n, m, k = 60522, 114575, 7559

  else:
    ##INPUT 
    #n = input()
    n, m, k = map(int, input().split())

  ## SUBMITION CODES HERE
  ans, N, K = 0, 1, 1
 
  for i in range(k+1):
    ans += N * pow(K, MOD-2, MOD) * pow(m-1, n-1-i, MOD)
    ans %= MOD
    N *= n-1-i
    N %= MOD
    K *= i+1
    K %= MOD
  
  ans *= m
  ans %= MOD
  print(ans)

main()

Measured memory_bytes: 9204
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <random>
#include <vector>
//#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
 
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()
 
int main()
{
  int a,b;
  cin>>a>>b;
  if(b<a){
  	cout<<a-1<<endl;
  }else{
  	cout<<a<<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	set<char> st;
	for (int i = 0; i < s.size(); ++i) { st.insert(s[i]); }

	cout << (st.size() > 1 ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> x(n),y(n),h(n);
  int m=0;
  for(int i=0;i<n;i++){
    cin>>x.at(i)>>y.at(i)>>h.at(i);
    m=(h.at(i)>h.at(m)?i:m);
  }
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      int he=h.at(m)+abs(x.at(m)-i)+abs(y.at(m)-j);
      bool f=1;
      for(int k=0;k<n&&f;k++)
        if(h.at(k)!=max(he-abs(x.at(k)-i)-abs(y.at(k)-j),0))
          f=0;
      if(f){
        cout<<i<<' '<<j<<' '<<he<<endl;
        i=101;
        j=101;
      }
    }
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

X = INT()

dp = [0] * (X+1)
dp[0] = 1
for i in range(X):
    for j in range(100, 106):
        if i+j > X:
            break
        dp[i+j] |= dp[i]
print(dp[X])


Measured memory_bytes: 41196
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  string s;
  int Q;
  cin>>s>>Q;
  string t;
  for(int i=0;i<Q;i++){
    int T,F;
    char C;
    cin>>T;
    if(T==1){
      swap(t,s);
    }
    else{
      cin>>F>>C;
      if(F==1){t.push_back(C);}
      else{s.push_back(C);}
    }
  }
  reverse(t.begin(),t.end());
  t+=s;
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 4000
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;//ハッシュテーブル用
using System.Linq;

class Program
{
    //Hashtable ht = new Hashtable();
    static List<int> s = new List<int>();
    static List<int>[] sl;
    static decimal result;
    static int N,K;
    //StringBuilder strresult= new StringBuilder("");//Append(str ○○)関数で文字を追加していく



    static void Main()
    {
        //Modular mo = new Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方：Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる（powべき乗、Fac累乗、nCr組み合わせも関数として存在）
        //Node<> no = new Node<>();//UnionFind★Find関数で根っこの値を返す（根っこの値が一緒なら同グループ）、Unite関数で二つの木をくっつける
        //Permutation<> pe = new Permutation<>();//配列＆リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
        //Treap<> tr = new Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
        //PriorityQueue<int,int> pr = new PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
 string tmp = Console.ReadLine();
      if(tmp=="Sunny"){Console.WriteLine("Cloudy");}
              if(tmp=="Cloudy"){Console.WriteLine("Rainy");}
      if(tmp=="Rainy"){Console.WriteLine("Sunny");}
        //Console.WriteLine(result.ToString());
    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }

    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
        N = int.Parse(tmp[0]);
        K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {
        sl = new List<int>[N];
        for (int i = 0; i < N; i++) {
            sl[i] = new List<int>();
            string[] tmp = Console.ReadLine().Split(' ');
            for (int j = 0; j < K; j++) {
                sl[i].Add(int.Parse(tmp[j]));
            }
        }

    }
}

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

int main(){
  int k;
  cin >> k;
  string s;
  cin >> s;
  if(s.size()<=k) cout << s << endl;
  else{
    rep(i,0,k) cout << s[i];
    cout << "..." << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

vector<vector<char> > g;
vector<bool> type;           // 0:L 1:R

string parse(string s) {
  REP(i, g.size()) {
    int start = 0, end = s.size(), d = 1;
    if (type[i]==0) start = s.size()-1, end = 0, d = -1;
    int a = 0;
    for (int j=start; j!=end; j+=d) {
      if (s[j] == '(') a++;
      else if(s[j] == ')') a--;
      else if (a==0) {
        FOR(it, g[i]) {
          if (s[j] == *it)
            return "("+ parse(s.substr(0,j)) + string(1,*it) + parse(s.substr(j+1)) + ")";
        }
      }
    }
  }
  if (s[0] == '(') {
    return parse(s.substr(1,s.size()-2));
  }
  return s;
}

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

  REP(t,T) {
    if (t) cout << endl;
    int G;cin >> G;
    g.resize(G);
    type.clear();
    REP(i,G) {
      char A; cin >> A;
      int M; cin >> M;
      type.push_back(A=='R');
      vector<char> tmp(M);
      REP(j,M) cin>>tmp[j];
      //g[G-i-1] = tmp;
      g[i] = tmp;
    }
    int n;cin >> n;
    REP(i,n) {
      string e;
      cin >> e;
      cout << parse(e) << endl;
    }
  }
  
  
}

Measured memory_bytes: 932
def solve(a, m):
	dict = {}
	return solve_(a, 0, m, dict)

def solve_(a, i, m, dict):
	res = False
	key = str(i) + '-' + str(m)
	if key in dict:
		res = dict[key]
	elif m == 0:
		res = True
	elif i >= len(a):
		res = False
	else:
		res1 = solve_(a, i + 1, m, dict)
		res2 = solve_(a, i + 1, m - a[i], dict)
		res = res1 or res2
	dict[key] = res
	return res

n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
for i in range(q):
	if solve(a, m[i]):
		print('yes')
	else:
		print('no')



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

int main() {
    int H, W;
    cin >> H >> W;

    map<int, int> s;
    multiset<int> vals;

    rep(i, W) s[i] = i;
    rep(i, W) vals.insert(0);

    rep(i, H) {
        int l, r;
        cin >> l >> r;
        l--;
        auto it = s.lower_bound(l);
        int mr = -1;
        while (it != s.end() && it->first <= r) {
            mr = max(mr, it->second);
            int x = it->first - it->second;
            vals.erase(vals.find(x));
            s.erase(it++);
        }
        if (mr != -1 && r < W) {
            vals.insert(r - mr);
            s[r] = mr;
        }
        int ans = -1;
        if (vals.size() > 0) {
            ans = *vals.begin() + (i + 1);
        }
        printf("%d\n", ans);
    }

    return 0;
}

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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }

void Solve()
{
	ll N;
	cin >> N;
	ll ans = CeilN(N, 1000) - N;
	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstring>
#include <string>

#define loop for (;;)
#define repeat(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  loop {
    int H, W;
    cin >> H >> W;
    if (!H && !W) return 0;
    string room[H];
    bool visited[H][W];
    memset(visited, 0, sizeof visited);
    int x = 0, y = 0;
    repeat(i, H)
      cin >> room[i];
    for (bool finish = false; !finish;) {
      if (visited[y][x]) {
        cout << "LOOP" << endl;
        finish = true;
      } else
        visited[y][x] = true;
      switch (room[y][x]) {
      case '>': x++; break;
      case '<': x--; break;
      case '^': y--; break;
      case 'v': y++; break;
      case '.':
        cout << x << ' ' << y << endl;
        finish = true;
        break;
      default: break;
      }
    }
  }
}

Measured memory_bytes: 0
import std;

void main() {
    int r; scan(r);
    writefln("%.10f", 2 * PI * r);
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


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

int main()
{
	char s[200005];
	int n = 0;
	scanf("%s", s);
	for (int i = strlen(s)-1; i >= 0; --i) n = (n+s[i]-'0')%9;
	puts(n ? "No" : "Yes");
}

Measured memory_bytes: 3840
# include<iostream>
# include<queue>
# include<stack>
# include<algorithm>
# include<cmath> 
# include<cstring>
using namespace std;
const int INF =pow(10,9)+7;
int a[1000000];

struct P{
	int x,y;
};
bool cmp(P a,P b)
{
	 return 1;
}

void update(int a,int b,int k,int l,int r)
{
	 
}

int main ()
{
	 int t=1;
	 //cin>>t;
	 while(t>0)
	 {
	 	  t--;
	      string s;
	      cin>>s;
	      for(int i=0;i<s.length();i++)
	      {
	      	  cout<<"x";
		  }
		  cout<<endl;
	 }
    	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
map<string,int> dp;
int direction[]={1,-1,4,-4};
//分别代表右移、左移、下移、上移
void bfs()
{
    queue<string> que;
    que.push("01234567");
    dp["01234567"]=0;
    while(!que.empty()){
        string now=que.front();
        que.pop();
        //p是字符串中0的位置
        int p=0;
        for(int i=0;i<8;i++){
            if(now[i]=='0'){
                p=i;
                break;
            }
        }
        for(int i=0;i<4;i++){
            int n=p+direction[i];
            if(n>=0&&n<8&&!(p==3&&i==0)&&!(p==4&&i==1)){
                //右上角不能向右移、左下角不能向左移
                string next=now;
                swap(next[p],next[n]);
                if(dp.find(next)==dp.end()){
                    dp[next]=dp[now]+1;
                    que.push(next);
                }
            }
        }
    }
}
int main()
{
    bfs();
    string s;
    while(getline(cin,s)){
       s.erase(remove(s.begin(),s.end(),' '),s.end());
       cout<<dp[s]<<endl;
    }
    return 0;
}


Measured memory_bytes: 5180
// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
		int k = parseInt(sc.next());
		int s = parseInt(sc.next());
		sc.close();
        int ans=0;
        for (int a=0;a<=k;a++){
            for (int b=0;b<=k;b++){
                if (s-a-b<=k && s-a-b>=0){
                    ans++;
                }
            }
        }
     
		System.out.println(ans);        
    
    }
}



Measured memory_bytes: 23764
#include <cstdio>
#include <cstdlib>
#define AMAX 90001
int main() {
  int h, w, d;
  scanf("%d %d %d", &h, &w, &d);
  int x[AMAX];
  int y[AMAX];
  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      int tmp;
      scanf("%d", &tmp);
      x[tmp] = i;
      y[tmp] = j;
    }
  }
  bool b[AMAX];
  for(int i=0; i<AMAX; i++) {
    b[i] = false;
  }
  int acc[AMAX];
  for(int i=0; i<AMAX; i++) {
    acc[i] = 0;
  }
  for(int i=1; i<=h*w; i++) {
    if(b[i]) continue;
    b[i] = true;
    int c = i;
    int next = i+d;
    while(next<=h*w) {
      b[next] = true;
      int dis = std::abs(x[c]-x[next])+std::abs(y[c]-y[next]);
      //      printf("cost of %d -> %d = %d\n", c, next , dis);
      acc[next] = dis+acc[c];
      next += d;
      c += d;
    }
  }
  // for(int i=1; i<=h*w; i++) {
  //   printf("A(i=%d, j=%d)=%d\n", x[i], y[i], i);
  // }
  // printf("@@@@@@@@@@\n");
  // for(int i=0; i<=h*w; i++) {
  //   printf("acc[%d]=%d\n", i, acc[i]);
  // }
  // printf("@@@@@@@@@\n");
  int q;
  scanf("%d", &q);
  for(int _i=0; _i<q; _i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    if(acc[l]==0) {
      printf("%d\n", acc[r]);
    } else {
      printf("%d\n", acc[r]-acc[l]);
    }
  }
  return 0;
}


Measured memory_bytes: 2304