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

#define int long long
//typedef long long ll;
#define double long double
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
typedef vector<int> vi;
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e6 + 3;
const double EPS = static_cast<double>(1e-9);
#define min(a, b) (((a)<(b))?(a):(b))
#define max(a, b) (((a)>(b))?(a):(b))

//************************************
#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(false); cin.tie();
	//auto beginProgram = chrono::steady_clock::now();
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);

	int n; cin >> n;
	vi a(n,0), pre(n, 0), suf(n, 0);
	FOR(i, 0, n) { cin >> a[i]; }
	if(n==2) { cout << max(a[0], a[1]) << endl; return 0;}
	
	pre[0] = a[0];
	FOR(i, 1, n) { pre[i] = __gcd(pre[i-1], a[i]); }
	reverse(a.begin(), a.end());
	suf[0] = a[0];
	FOR(i, 1, n) { suf[i] = __gcd(suf[i-1], a[i]); }
	reverse(suf.begin(), suf.end());
	
//	FOR(i, 0, n) cout << pre[i] << "  " ;
//	cout << endl;
//	FOR(i, 0, n) cout << suf[i] << " - " ;
//	cout << endl;
	
	int ans = -1;
	FOR(i, 0, n) {
		if(i==0) {ans = suf[1]; continue;} 
		if(i==n-1) {ans = max(ans, pre[n-2]); continue; }
		ans = max(ans, __gcd(pre[i-1], suf[i+1]));
		
//		cout << "i = " << i << ", ans = " << ans << endl;
		
	}
	
	cout << ans << endl;
	
  //auto endProgram = chrono::steady_clock::now();
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)

bool debug=true;

/*    *************************************
	  * Written in New Computer           *
	  * The following code belongs to     *
	  * XiaoGeNintendo of HellHoleStudios *
	  *************************************
*/
template<typename T1,typename T2>ostream& operator<<(ostream& os,pair<T1,T2> ptt){
	os<<ptt.first<<","<<ptt.second;
	return os;
}
template<typename T>ostream& operator<<(ostream& os,vector<T> vt){
	os<<"{";
	for(int i=0;i<vt.size();i++){
		os<<vt[i]<<" ";
	}
	os<<"}";
	return os;
}

ll A,B,C,D,N;

map<ll,ll> dp;

const ll inf=1e18;

ll dfs(ll x){
	if(dp.count(x)){
		return dp[x];
	}
	
	if(x==0){
		return 0;
	}
	if(x==1){
		return D;
	}
	
	ll ans=inf;
	
	ans=min(ans,x%2*D+dfs(x/2)+A);
	if(x%2!=0)ans=min(ans,(2-x%2)*D+dfs(x/2+1)+A);
	
	ans=min(ans,x%3*D+dfs(x/3)+B);
	if(x%3!=0)ans=min(ans,(3-x%3)*D+dfs(x/3+1)+B);
	
	ans=min(ans,x%5*D+dfs(x/5)+C);
	if(x%5!=0)ans=min(ans,(5-x%5)*D+dfs(x/5+1)+C);
	
	if(x*D>=0 && x*D<=ans){
		ans=x*D;
	}
	
	return dp[x]=ans;
}
int main(int argc,char* argv[]){
	int T;
	cin>>T;
	while(T--){
		cin>>N>>A>>B>>C>>D;
		dp.clear();
		cout<<dfs(N)<<endl;
	}
	return 0;
}



Measured memory_bytes: 4448
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  ll N;
  cin >> N ;
  ll a[1000000] ;
  cinf(3*N,a) ;
  ll max ;
  sort(a,a +3*N,greater<int>()) ;
  for(int i=1;i<2*N;i +=2){
    max += a[i] ;
  }
  cout << max << endl;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  
  int ans=0;
  for(int a=0; a<=A; a++){
    for(int b=0; b<=B; b++){
      for(int c=0; c<=C; c++){
        int total = 500*a + 100*b + 50*c;
        if(total == X){
          ans++;
        }
      }
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;
void swap(int &a, int &b);

int main()
{
	int n;
	cin >> n;
	int count = 1;
	while (count <= n)
	{
		int x = count;
		if (x % 3 == 0 || x % 10 == 3)
		{
			cout << " " << x;
			count++;
			continue;
		}

		do
		{
			x /= 10;
			if (x % 10 == 3)
			{
				cout << " " << count;
				break;
			}
			
		} while (x >= 1);
		count++;
	}
	cout << endl;

	//for (int i = 0; i < 200; ++i)
	//{
	//	int x = i;
	//	x /= 10;
	//	if (x)
	//		if (x % 10 == 3)
	//			cout << x << " " << i << endl;
	//}

	return 0;
}




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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara,x) memset((ara),x,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];


	cin>>s1>>s2;

	if(s1.size()!=s2.size()) cout<<"No"<<endl;
	else{
        for(i=0;i<s1.length();i++){
            if(s1==s2) cout<<"Yes"<<endl,exit(0);
            else{
                s1=s1.back()+s1;
                s1.pob();
                //cout<<s1<<endl;
            }
        }
        cout<<"No"<<endl;
	}


}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2,62);


int main(){
    ll n;cin >> n;
    vec2 A(n,vector<ll>(2));
    rep(i, n){
        cin >> A[i][0] >> A[i][1];
    }
    bool p = false;
    for(int i = 0;i < n-2;i++){
        if(A[i][0] == A[i][1] && A[i+1][0] == A[i+1][1]){
            if(A[i+1][0] == A[i+1][1] && A[i+2][0] == A[i+2][1]){
            p = true;
            break;
            }
        }
    }
    if(p){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())

    n26 = 1
    keta = 0
    while n > 0:
        n26 *= 26
        n -= n26
        keta += 1
    n = n + n26 - 1
    r = []
    for i1 in range(keta):
        t1 = n % 26
        r.append(chr(t1 + 97))
        n = n // 26
    print("".join(r[::-1]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 61716
import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    A=list(map(int,input().split()))
    B = sum(A)
    if B > 21 :
        print('bust')
    else :
        print('win')
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<stdio.h>

int main(void){
    int n,m,l;
    int i,j,k;

    scanf("%d %d %d",&n,&m,&l);
    long long A[n][m],B[m][l],sum;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%lld",&A[i][j]);
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%lld",&B[i][j]);
        }
    }

    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            sum=0;
            for(k=0;k<m;k++){
                sum+=A[i][k]*B[k][j];
            }
            if(j==0) printf("%lld",sum);
            else printf(" %lld",sum);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,l,sum=0,res=1000000009,luu;
  cin>>n>>l;
  vector<int> A(n+1);
  for(int i=1;i<n+1;i++){
    A[i]=l+i-1; 
    sum+=A[i];
}
  
  for(int i=1;i<n+1;i++){
   //res=min(res,abs(A[i]));
   if(abs(A[i])<res) {luu=A[i],res=abs(A[i]);}
}
  //for(int i=1;i<n+1;i++) cout<<A[i]<<" ";
  //cout<<'\n';
   cout<<sum-luu;
  return 0;
}

Measured memory_bytes: 256
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;

int main()
{
	int n,m;
	cin >> n >> m;
	

	int s = n * 3 + m;
	int ans = s / 2;
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
n=int(input())
lis=list(map(int,input().split()))
an=0
ans=0
for i in range(n-1):
  if lis[i]>=lis[i+1]:
    an += 1
  else:
    ans =max(ans,an)
    an=0
ans=max(ans,an)
print(ans)


Measured memory_bytes: 14224
r,c=[int(i) for i in input().split()]

data=[]
sum_row =[0]*(c+1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c+1):
        sum_row[ci] += data[ri][ci]

print(" ".join([str(s) for s in sum_row]))

Measured memory_bytes: 7688
// ABC176A.cpp
//#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
	int n, x, t;
	cin >> n >> x >> t;
	int cnt = n / x;
	int over = n % x;
	if (over > 0) cnt++;
	cout << cnt*t << endl;
}


Measured memory_bytes: 3196
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
using namespace std;

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
  int H;
  cin >> H;
  int A[2*H];
  A[0]=0;
  for(int i=1;i<=H;i++) cin >> A[i];
  for(int i=1;i<=H;i++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(parent(i)>=1) cout << "parent key = " << A[parent(i)] << ", ";
    if(left(i)<=H) cout << "left key = " << A[left(i)] << ", ";
    if(right(i)<=H) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <cstring>
using namespace std;
int main() {
    int a, b, c, k, ans;
    cin >> a >> b >> c >> k;
    if(k<=a)
        ans = k;
    else if(k<=a+b)
        ans = a;
    else
        ans = 2*a + b - k;
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[100], b[100];
    for(int i=0; i<n; i++) cin >> a[i];

    int cnt=1, ans=0;
    for(int i=1; i<n; i++) {
        if(a[i]==a[i-1]) cnt++;
        else {
            ans += cnt/2;
            cnt=1;
        }
    }
    ans += cnt/2;

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


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
int main(){
  int n;cin>>n;
  multiset<ll,greater<ll>> a;
  for(int i=0;i<n;i++){
    ll m;cin>>m;
    a.insert(m);
    }
  vector<ll> p2;
  for(int i=0;i<32;i++)p2.push_back((1ll<<i));
  ll ans=0;
  while(!a.empty()){
    ll t=*a.begin();
    a.erase(a.begin());
    for(int i=31;i>=0;i--){
      ll tmp=p2[i]-t;
      if(tmp<0)break;
      auto ite=a.find(tmp);
      if(ite!=a.end()){
        a.erase(ite);
        ans++;
        break;
        }
        }
        }
        cout<<ans<<endl;
}


Measured memory_bytes: 9600
import sys
raw_input = sys.stdin.readline
N = int(raw_input())
dp = [[0,0,0] for x in range(N+1)]
for i in range(N):
    li = map(int,raw_input().split())
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1][k] = max(dp[i+1][k],dp[i][j]+li[k])
print max(dp[N])

Measured memory_bytes: 43164
#include <iostream>
#include <algorithm>
#include <cmath>

int arr[8];
int brr[8];
int tem[8];

int main()
{
	int N, a = 0, b = 0;
	std::cin >> N;
	for (int i = 0; i < N; ++i)
	{
		std::cin >> arr[i];
		tem[i] = arr[i];
	}
	std::sort(tem, tem + N);
	for (int i = 0; i < N; ++i)
		std::cin >> brr[i];
	int var = 1;
	bool ae = true;
	bool be = true;
	do
	{
		bool af = true;
		bool bf = true;
		for (int i = 0; i < 8; ++i)
		{
			if (af && arr[i] != tem[i])
				af = false;
			if (bf && brr[i] != tem[i])
				bf = false;
		}
		if (ae && af)
		{
			ae = false;
			a = var;
		}
		if (be && bf)
		{
			be = false;
			b = var;
		}
		++var;
	} while (std::next_permutation(tem, tem + N));
	std::cout << std::abs(a - b) << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define HpOut(S) cout << setprecision(20) << S << endl;
#define print(x) cout << (x) << endl;
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

 
int main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S;
    cin >> S;
    for (auto i = 0; i < (int)S.size()-1; i++) {
      if (S[i] == S[i+1]) {
        cout << i+1 << " " << i+2 << endl;
        return 0;
      }
    }
    for (auto i = 0; i < (int)S.size()-2; i++) {
      if (S[i] == S[i+2]) {
        cout << i+1 << " " << i+3 << endl;
        return 0;
      }
    }
    cout << "-1 -1" << endl;
}

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

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

    vector<int> L(N, 0);
    for(int i=0; i<N; i++){
        cin >> L.at(i);
    }

    int cnt=0;
    sort(L.begin(), L.end());

/*
    if(N==3){
        if((L.at(0) + L.at(1) > L.at(2)) && (L.at(0) < L.at(1) + L.at(2)) && (L.at(0) + L.at(2) > L.at(0))){
            cnt++;
        }
        cout << cnt << endl;
        return 0;
    }
*/
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            for(int k=j+1; k<N; k++){
                    if((L.at(i) + L.at(j)) - L.at(k) > 0){
                        cnt++;
                    }
                    else{
                        break;
                    }
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;

  if(a == b && b == c) {
    cout << 1 << endl;
  }
  else if(a == b || b == c || c == a) {
    cout << 2 << endl;
  }
  else {
    cout << 3 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<cassert>
#include<algorithm>
#include<cassert>
#include<map>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 3010;

int dp[N][N];//i-th,time = max fun
int y[N];
int solve(int n,int s,int T,vector<int> &t,vector<int> &f){
  rep(i,N)rep(j,N)dp[i][j] = -1;

  if (t[0] <= s)dp[0][t[0]] = f[0];
  dp[0][0] = 0;
  REP(i,1,n){
    y[0] = -1;
    rep(j,T+1){
      dp[i][j] = dp[i-1][j];
      if (j-t[i] >= 0 && y[j-t[i]] != -1 && (s <= j-t[i] || j <= s)){
	dp[i][j] = max(dp[i][j] ,y[j-t[i]] + f[i]);
      }
      if (j)y[j] = max(y[j-1],dp[i-1][j]);
      else y[j] = dp[i-1][j];
    }
  }
  int ret = 0;
  rep(j,T+1)ret = max(ret,dp[n-1][j]);
  return ret;
}

main(){
  int n,T,s;
  while(cin>>n>>T>>s){
    vector<int> f(n),t(n);
    rep(i,n)cin>>f[i]>>t[i];
    cout << solve(n,s,T,t,f) << endl;
  }
}

Measured memory_bytes: 35000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
	
	static Map<Integer, Card> cardMap = new HashMap<Integer, Card>();
	static Map<Integer, Integer> numMap = new HashMap<Integer, Integer>();
	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			String[] str = br.readLine().split(" ");
			Card card = new Card(str[0], Integer.parseInt(str[1]), i);
			cardMap.put(i, card);
			numMap.put(i, card.num);
			a[i] = i;
		}
		quickSort(a, 0, n - 1);
		boolean flag = true;
		
		Card card = cardMap.get(a[0]);
		int num = card.num;
		int order = card.order;
		//System.out.println(card.mark + " " + card.num + " " + card.order);
		for (int i = 1; i < n; i++) {
			int k = a[i];
			card = cardMap.get(k);
			if(num == card.num && card.order < order){
				flag = false;
			}
			num= card.num;
			order = card.order;
			//System.out.println(card.mark + " " + card.num + " " + card.order);
		}
		if(flag == true){
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}
		for (int i = 0; i < n; i++) {
			int k = a[i];
			card = cardMap.get(k);
			if(num == card.num && card.order < order){
				flag = false;
			}
			num= card.num;
			order = card.order;
			System.out.println(card.mark + " " + card.num);
		}
	} 

	static int partition(int[] a, int p, int r) {
		int x = numMap.get(a[r]);
		int i = p - 1;
		int tmp;
		for (int j = p; j < r; j++) {
			if (numMap.get(a[j]) <= x) {
				i = i + 1;
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
		tmp = a[i + 1];
		a[i + 1] = a[r];
		a[r] = tmp;
		return i + 1;
	}
	static void quickSort(int[] a, int p, int r){
		int q = 0;
		if(p < r){
			q = partition(a, p, r);
			quickSort(a, p, q-1);
			quickSort(a, q+1, r);
		} else {
			return;
		}
	}
}
//??????????????????????????????????????????
class Card{
	
	String mark;
	int num;
	int order;
	
	Card(String mark, int num, int order){
		this.mark = mark;
		this.num = num;
		this.order = order;
	}
}

Measured memory_bytes: 96620
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

int main() {

	int n;
	cin >> n;
	REP(i, n) {
		string s;
		cin >> s;
		if (s[0] == 'Y')
		{
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long W = sc.nextLong();
    int[] r = new int[N];
    int[] v = new int[N];
    long w0 = sc.nextLong();
    v[0] = sc.nextInt();
    for(int i = 1; i < N; i++) {
      long w = sc.nextLong();
      r[i] = (int)(w - w0);
      v[i] = sc.nextInt();
    }
    // dp[i][j][k]は物0～iまでからrの和がk以下となるようにj個選んだときの価値の最大値
    int[][][] dp = new int[N][N + 1][3 * N];
    for(int k = 0; k < 3 * N; k++) {
      dp[0][1][k] = v[0]; 
    }
    for(int i = 1; i < N; i++) {
      for(int j = 1; j < N + 1; j++) {
        for(int k = 0; k < 3 * N; k++) {
          if(r[i] <= k) {
            dp[i][j][k] = Math.max(dp[i - 1][j][k], dp[i - 1][j - 1][k - r[i]] + v[i]);
          } else {
            dp[i][j][k] = dp[i - 1][j][k];
          }
        }
      }
    }
    int ans = 0;
    for(int j = 1; j < N + 1; j++) {
      if(W - w0 * j >= 0) {
        int re = Math.min((int)(W - w0 * j), 3 * N - 1);
        ans = Math.max(ans, dp[N - 1][j][re]);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35156
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

#define debug(x) cout << #x << ": " << x << endl;
#define ll long long
#define mod 1000000007

int N, A[1<<20];

int main() {
//  freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);
  cin >> N;
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }
  int start = 1;
  for(int i = 0;i < N;i++) {
    if(A[i] == start) start++;
  }

  if(start == 1) {
    cout << -1 << endl;
  } else {
    start -= 1;
    cout << N - start << endl;
  }




  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include <stdio.h>
using namespace std;

int pow(int n){

        int ans = 1;
        for(int i=0;i<n;i++){
            ans *= 10;
        }

    return ans;

}

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

    int P[N];

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

    int min=1000000;
    int ans=0;

    for(int i=0;i<N;i++){
        if(P[i]<=min){
            min = P[i];
            ans += 1;
        }
    }    

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void printVec(vector<int> &vec)
{
    for(int i = 0; i < vec.size(); ++i)
      cout << (i == 0 ? "" : " ") << vec[i];
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    
    for(int i = 0; i < N; ++i)
      cin >> A[i];
    
    vector<int> B = A;
    
    if(prev_permutation(B.begin(), B.end()))
        printVec(B);
        
    printVec(A);
    
    B = A;
    if(next_permutation(B.begin(), B.end()))
        printVec(B);
    
    return 0;
    
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
const int INF = 1<< 28;
int main() {
  long long t,d;
  long long ta,tb;
  long long da,db;
  cin >> t >> d >> ta >> tb >> da >> db;
  long long sa = -1;
  long long amount = 0;
  for(int i = 0; i <= d;i+=da){
    for(int j = 0;j+i <= d;j+=db){
      if(i  == 0 && j == 0)continue;
      long long tmp = (ta*i + tb*j);
      long long tmp2 = i+j;
      if(sa == -1){
	sa = abs(tmp2*t - tmp);
	amount = tmp2;
      }
      if(sa*tmp2 > abs(tmp2*t-tmp)*amount){
	sa = abs(tmp2*t - tmp);
	amount = tmp2;
      }
    }
  }
  cout << fixed << setprecision(5) << (double)sa/(double)amount << endl;
  return 0;
}

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

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

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int CountBit(int x){
  if(x == 0)return 0;
  return CountBit(x>>1) + (x&1);
}

int n;
int v[20][20];
int main(){
  Fill(v,-1);
  cin >> n;
  for(int i = 0; i < n; ++i){
    int a; cin >> a;
    for(int j = 0; j < a; ++j){
      int x,y; cin >> x >> y; x--;
      v[i][x] = y;
    }
  }
  int ans = 0;
  for(int bit = 0; bit < (1<<n); ++bit){
    bool flag = true;
    for(int i = 1, idx = 0; i < (1<<n); (i<<=1), idx++){
      if(bit&i){
	for(int j = 0; j < 20; ++j){
	  if(v[idx][j] != -1 && (v[idx][j]^((bit&(1<<j))>0)))flag = false;
	}
      }
    }
    if(flag){
      ChangeMax(ans, CountBit(bit));
    }
  }
  cout << ans << endl;
}


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

namespace ABC
{
    class ABC172A
    {
        const string FILE = "/tmp/data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            long N = RL();
            Console.WriteLine(N + N * N + N * N * N);




#if DEBUG
            Console.WriteLine("*** end ***");
            Console.SetIn(Console.In);
            Console.ReadKey();
#endif
        }

        static long RL()
        {
            return long.Parse(Console.ReadLine());
        }

        static long[] RLa(long n)
        {
            string[] sa = Console.ReadLine().Split(' ');
            long[] la = new long[n];
            for (int i = 0; i < n; ++i)
            {
                la[i] = long.Parse(sa[i]);
            }
            return la;
        }
    }
}


Measured memory_bytes: 27484
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100005;
int n,m,id[maxn];long long K,a[maxn],b[maxn];
inline char nc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline long long read(){
	long long ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
struct ltl{
	int p[maxn];
	ltl (){}
	ltl (int x){for (int i=1;i<=x;i++) p[i]=i;}
	ltl operator *(ltl b){
		ltl c;
		for (int i=1;i<=n;i++) c.p[i]=b.p[p[i]];
		return c;
	}
}E,ans,w;
int main(){
	E=n=read();
	for (int i=1;i<=n;i++) a[i]=read(),id[i]=i;
	for (int i=n;i>1;i--) a[i]=a[i]-a[i-1];
	m=read(),K=read();
	for (int i=1,j;i<=m;i++)
	j=read(),swap(id[j],id[j+1]);
	ans=E;
	for (int i=1;i<=n;i++) w.p[id[i]]=i;
	while(K){
		if(K&1) ans=ans*w;
		K>>=1;w=w*w;
	}
	for (int i=1;i<=n;i++) b[ans.p[i]]=a[i];
	for (int i=1;i<=n;i++) printf("%lld\n",b[i]+=b[i-1]);
	return 0;
}

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

#define rep(i, n) for (int i = 0; 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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector <int64_t> v(n);
  rep(i, n) cin >> v.at(i);
  if (n%2 == 0) {
    rep(i, n/2) {
      cout << v.at(n-1-2*i) << ' ';
    }
    rep(i, n/2) {
      if (i == n/2-1) {
        cout << v.at(2*i) << endl;
      } else {
        cout << v.at(2*i) << ' ';
      }
    }
  } else {
    rep(i, n/2+1) {
      cout << v.at(n-1-2*i) << ' ';
    }
    rep(i, n/2) {
      if (i == n/2-1) {
        cout << v.at(1+2*i) << endl;
      } else {
        cout << v.at(1+2*i) << ' ';
      }
    }
  }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll a,b,c;
  cin>>a>>b>>c;
  cout << a*b/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;

ll a[55];
ll dp[55][55];
map<ll, ll, std::greater<ll> >mp;
int main(int argc, char const *argv[])
{
    // freopen("input.txt", "r", stdin);
    int N, A, B;
    cin >> A >> B;
    if((A + B)% 2 == 0)cout << (A == B ? 0 : (A+B)/2) << endl;
    else cout << "IMPOSSIBLE\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int N;
	int masu[3][150] = {0}; 
	int i, j;
	int max = 0;
	int count = 0;


	scanf("%d", &N);
	for (i = 0; i < 2; i++){
		for (j = 0; j < N; j++){
			scanf("%d", &masu[i][j]);
		}
	}

	for (i = 0; i < N; i++){
		count = 0;
		for (j = 0; j <= i; j++){
			count += masu[0][j];
		}
		for (j -= 1; j < N; j++){
			count += masu[1][j];
		}

		if (count >= max)
			max = count;
	}

	printf("%d", max);

	return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    a,b=map(int,input().split())
    if a==1:
        a+=13
    if b==1:
        b+=13
    if a>b:
        print('Alice')
    elif a==b:
        print('Draw')
    else:
        print('Bob')    

if __name__ == '__main__':
    main()


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

using namespace std;

void solve() {
    int n, k; cin >> n >> k;
    vector<int> nums(n);
    vector<int> ord(n, 1);
    set<int> st;
    bool flag = 0;
    for (int i = 0; i < n; ++i) cin >> nums[i];
    for (int i = n-2; i >= 0; --i) {
        if (nums[i] < nums[i+1]) ord[i] = ord[i+1] + 1;
        else ord[i] = 1;
        if (ord[i] >= k) flag = true;
    }
    for (int i=0; i < k; ++i) {
        st.insert(nums[i]);
    }
    int ret = ord[0] >= k ? 0 : 1;// ord[0] < k;
    for (int i=k; i < n; ++i) {
        st.insert(nums[i]);
        int mx = *st.rbegin(), mi = *st.begin();
        if (nums[i] != mx || nums[i-k] != mi){
            if (ord[i-k+1] < k) {
                ret++;
            }
        }
        st.erase(nums[i-k]);
    }
    cout << (ret + flag) << endl;
}

int main() {
    int n; n = 1;
    while (n--) {
        solve();
    }
}

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

int main(){
    string s;
    cin >> s;
    int k = (int)s.size();
    vector<bool> check(26, true);
    if (k < 26){
        for (int i = 0; i < k; i++){
            check[s[i] - 'a'] = false;
            cout << s[i];
        }
        for (int i = 0; i < 26; i++){
            if (check[i]) {
                cout << (char)(i + 'a') << endl;
                exit(0);
            }
        }
    }
    else {
        vector<bool> check(26, false);
        for (int i = 25; i > 0; i--){
            check[s[i] - 'a'] = true;
            if (s[i] > s[i-1]){
                for (int j = s[i-1] - 'a'; j < 26; j++){
                    if (check[j]) {
                        s[i-1] = (char)(j + 'a');
                        for (int t = 0; t < i; t++) cout << s[t];
                        cout << endl;
                        exit(0);
                    }
                }
            }
        }
        cout << -1 << endl;
    }
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
using namespace std;

const int maxn=3010, maxm=2022000;
const long long inf=9999999999;
typedef long long LL;

struct Edge{
	Edge(){};
	Edge(int a,int b,LL c,int d){v=a;f=b;w=c;nxt=d;};
	int v,f,nxt;
	LL w;
};

int n,lmt;
int g[maxn+10];
Edge e[maxm+10];
int nume;
int src,sink;

void addedge(int u,int v,int c,LL w){
	e[++nume]=Edge(v,c,w,g[u]);
	g[u]=nume;
	e[++nume]=Edge(u,0,-w,g[v]);
	g[v]=nume;
}

queue<int> que;
bool inQue[maxn+10];
LL dist[maxn+10];
int pren[maxn+10];
int pree[maxn+10];

bool findPath(){
	while(!que.empty())que.pop();
	que.push(src);
	memset(dist,0x3f,sizeof(dist));
	dist[src]=0;inQue[src]=true;
	while(!que.empty()){
		int u=que.front();
		//cout<<u<<endl;
		que.pop();
		for(int i=g[u];i;i=e[i].nxt){
			if((e[i].f>0) && (dist[u]+e[i].w<dist[e[i].v])){
				dist[e[i].v]=dist[u]+e[i].w;
				pren[e[i].v]=u;pree[e[i].v]=i;
				if(!inQue[e[i].v]){
					inQue[e[i].v]=true;
					que.push(e[i].v);
				}
			}
		}
		inQue[u]=false;
	}
	if(dist[sink]<dist[3001])return true;
	return false;
}

LL augment(){
	int u=sink;
	LL delta=inf;
	while(u!=src){
		if(e[pree[u]].f<delta)delta=e[pree[u]].f;
		u=pren[u];
	}
	u=sink;
	while(u!=src){
		e[pree[u]].f-=delta;
		e[pree[u]^1].f+=delta;
		u=pren[u];
	}
	return dist[sink]*delta;
}

LL mincostflow(){
	LL cur=0;
	while(findPath()){
		cur+=augment();
		//rep(i,1,2*n+1)cout<<i<<" "<<dist[i]<<endl;
	}
	return cur;
}

LL RX[1010],RY[1010],BX[1010],BY[1010];
int RC[1010],BC[1010];
int A,B,C,D;
int main() {
	std::ios::sync_with_stdio(false);
	//freopen("ttt.txt","r",stdin);
	cin>>n;
	rep(i,1,n)cin>>RX[i]>>RY[i]>>RC[i];
	rep(i,1,n)cin>>BX[i]>>BY[i]>>BC[i];
	sink=1;src=0;nume=1;

	memset(g,0,sizeof(g));
	rep(i,1,n)addedge(0,i+1,RC[i],0);
	rep(i,1,n)addedge(i+n+1,1,BC[i],0);
	A=2*n+2;B=A+1;C=B+1;D=C+1;
	rep(i,1,n){
		addedge(i+1,A,10,RX[i]+RY[i]);
		addedge(i+1,B,10,RX[i]-RY[i]);
		addedge(i+1,C,10,-RX[i]+RY[i]);
		addedge(i+1,D,10,-RX[i]-RY[i]);
	}
	rep(i,1,n){
		addedge(A,i+n+1,10,-BX[i]-BY[i]);
		addedge(B,i+n+1,10,-BX[i]+BY[i]);
		addedge(C,i+n+1,10,BX[i]-BY[i]);
		addedge(D,i+n+1,10,BX[i]+BY[i]);
	}
	
	//cout<<"prep"<<endl;
	cout<<-mincostflow()<<endl;
	return 0;
}

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

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

Measured memory_bytes: 256
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll d;
    cin>>d;
    V C(26);
    rep(i,26)cin>>C[i];
    VV S(d,V(26));
    rep(i,d){
        rep(j,26)cin>>S[i][j];
    }
    V T(d);
    rep(i,d)cin>>T[i];
    V prev(26,-1);
    ll res=0;
    rep(i,d){
        res+=S[i][T[i]-1];
        prev[T[i]-1]=i;
        rep(j,26){
            res-=C[j]*(i-prev[j]);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3708
package main

import (
	"fmt"
	"log"
)

func main() {
	var N int = 0
	_, err := fmt.Scan(&N)
	if err != nil {
		log.Println(err)
	}
	var answer int
	for {
		if N > 1000 {
			N -= 1000
		} else {
			answer = 1000 - N
			break
		}

	}
	fmt.Printf("%d\n", answer)
}


Measured memory_bytes: 1836
import numpy as np
import sys
#import copy


def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


def sp_xnxn(n=0):
    """
    args:
        int n: a number of lows to read
    example
        input   1
        retrun  [1]

        input   123
        return  [1,2,3]

        input   123
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        return [int(k) for k in xsxs()]
    else:
        return [[int(k) for k in xsxs()] for _ in range(n)]


def xsxs(n=0):
    """
    args:
        int n: a number of lows to read 
    example:
        input   AA
        retrun  AA

        input   A BBB CC
        return  ["A","BBB","CC"]

        input   A BB CCC
                D
        return  [["A","BBB","CC"],
                ["D"]]
    """
    if n == 0:
        temp = list(input().split())
        if len(temp) == 1:
            return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        return [list(input().split()) for _ in range(n)]


def sp_xsxs(n=0):
    """
    args:
        int n: a number of lows to read 
        example:
            input   A
            retrun  ["A"]

            input   ABC
            return  ["A","B","C"]

            input   ABC
                    D
            return  [["A","B","C"],
                    ["D"]]
    """
    if n == 0:
        return [s for s in xsxs()]
    else:
        return [[s for s in xsxs()] for _ in range(n)]


k = xnxn()
s = xsxs()

if len(s) <= k:
    print(s)
else:
    print(s[0:k] + "...")


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

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

    double cnt;
    double ma = n;
    for(int i = 1;i <= n;i++){
        if(i % 2 == 1) cnt+=1;
    }

    printf("%.12lf\n", cnt/ma);

    return 0;
}

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

 int main() {
	for(int N, M; cin >> N >> M && N; ) {
		vector<pair<int, int>> roads;
		
		int danger = 0;
		
		for(int i = 0; i < N; i++) {
			int d, p;
			cin >> d >> p;
			
			roads.push_back(make_pair(p, d));
			danger += d * p;
		}
		
		sort(roads.begin(), roads.end(), greater<pair<int, int>>());
		
		for(int i = 0; i < N; i++) {
			danger -= min(M, roads[i].second) * roads[i].first;
			M = max(M - roads[i].second, 0);
		}
		
		cout << danger << endl;
	 }
 }

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> x(n);
  for(int i=0;i<n;i++)
    cin>>x.at(i);
  int p=1000000007;
  int64_t f=1;
  for(int i=1;i<n;i++)
    f=f*i%p;
  vector<int64_t> in(n,1);
  int q=p-2;
  vector<bool> b;
  while(q>0){
    b.push_back(q%2==1);
    q/=2;
  }
  reverse(b.begin(),b.end());
  for(int i=2;i<n;i++){
    for(int d=0;d<b.size();d++){
      in.at(i)=in.at(i)*in.at(i)%p;
      if(b.at(d))
        in.at(i)=in.at(i)*i%p;
    }
  }
  int64_t s=0;
  int64_t c=0;
  for(int i=1;i<n;i++){
    c=(c+f*in.at(i))%p;
    s=(s+c*(x.at(i)-x.at(i-1)))%p;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 4264
import collections
from sys import stdin
n = int(stdin.readline().rstrip())
ass = list(map(int, stdin.readline().rstrip().split()))

c = collections.Counter(ass)

cnum =[0]*len(c)
keys = c.keys()

cs = {}
for i in keys:
    key = c[i]
    combi = key *(key-1) / 2
    cs[i] = combi

sum = sum(cs.values())

for i in range(n):
    add = c[ass[i]]-1
    adds = add *(add-1) / 2
    ans = sum - cs[ass[i]] + adds
    print(int(ans))


Measured memory_bytes: 35272
from collections import Counter
import sys
sys.setrecursionlimit(1000000)

global color 
global adlist

def make_adlist(N, AB):
  global adlist
  for a, b in AB:
    adlist[a] += [b]
    adlist[b] += [a]

def dfs(v, c):
  color[v] = c
  for u in adlist[v]:
    if color[u] == c:
      return False
    if color[u] == 0 and dfs(u, -c)==False:
      return False
  return True

def main():
  global color 
  global adlist
  N, M = map(int, input().split())
  AB = [list(map(lambda x:int(x)-1, input().split())) for _ in range(M)]
  color = [0 for _ in range(N)]
  adlist = [[] for _ in range(N)]
  make_adlist(N, AB)
  if dfs(0, 1):
    B = color.count(-1)
    W = color.count(1)
    print(B*W-M)
  else:
    print(N*(N-1)//2-M)

if __name__ == "__main__":
  main()



Measured memory_bytes: 47724
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]
#CW = [list(map(int, list(input()))) for _ in range(H)]


N, D = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(N)]
ans = 0

for i in range(N):
  temp = math.ceil(math.sqrt(XY[i][0]**2 + XY[i][1]**2))
  if(D>=temp):
    ans +=1

print(ans)


Measured memory_bytes: 104716
import sys

x,n = map(int,input().split())
p = list(map(int,input().split()))

t = True
i,j=0,0

if x not in p:
    print(x)
    sys.exit()

i,j=1,1

while t:
    ans = x+i*(-1)**j
    if ans in p:
        if j == 2:
            j = 1
            i += 1
        else:
            j += 1    
    else:
        t = False

print(ans)

Measured memory_bytes: 9156
Row = int(input())
List = []
for i in range (Row):
  List.append(int(input()))
s = 1
res = 0
flag = False
for i in range(Row):
  s = List[s-1]
  res += 1
  if s == 2:
    flag=True
    break
if not flag:
  print(-1)
else:
  print(res)

Measured memory_bytes: 12988
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0; i<n; i++) {
      cin >> v[i];
  }
  int q;
  cin >> q;
  vector<int> vc(q);
  for(int i=0; i<q; i++) {
      cin >> vc[i];
  }
  for(int i=0; i<q; i++) {
      if(binary_search(v.begin(),v.end(),vc[i])) {
          cout << 1 << endl;
      }
      else {
          cout << 0 << endl;
      }
  }
}


Measured memory_bytes: 3884
#include<stdio.h>
#define LARGE 100001
#define MIN(a,b) ((a) < (b) ? (a) : (b))

int getAns(int a[],int n,int s){
	int i=0,j=0,k;
	int sum=0;
	int ans=LARGE;
	
	for(i=1;i<=n;i++){
		sum+=a[i-1];
		if(sum >= s){
			ans=MIN(i-j,ans);
			while(sum >= s){
				sum-=a[j];
				if(sum >= s){
					ans=MIN(i-j-1,ans);
					j++;
				}
				else 
					j++;
			}
			
		}
	}
	
	if(ans==LARGE)
		ans=0;
	
	return ans;
}


int main(){
	int a[LARGE];
	int n,i,s;
	int ans=0;
	int sum=0;
	
	scanf("%d %d",&n,&s);
	
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);

	printf("%d\n",getAns(a,n,s));
	
	return 0;
	
}


Measured memory_bytes: 2252
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
xyz = []
for _ in range(n):
    xyz.append(tuple(li()))
    
ans = -10**18
for i in range(-1,2,2):
    for j in range(-1,2,2):
        for k in range(-1,2,2):
            temp = sorted([i*x+j*y+k*z for x,y,z in xyz], reverse=True)
            ans = max(ans, sum(temp[:m]))
            
print(ans)

Measured memory_bytes: 3316
let () =
  let a,b,k = Scanf.scanf "%d %d %d " (fun a b c -> a,b,c) in

  let los = Array.init k (fun i -> a+i) in
  let his = Array.init k (fun i -> b-i) in

  let lst = Array.to_list @@ Array.concat [los;his] |>
            List.filter (fun x -> x >= a && x <= b) |>
            List.sort_uniq compare
  in
  List.iter (fun x -> Printf.printf "%d\n" x) lst



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

int main() {
    int n, a[100010];
    map<int, int> mp{};

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

    int ans = 0;
    for (auto u:mp) if(u.second % 2 != 0) ans++;

    cout << ans << endl;

}

Measured memory_bytes: 8504