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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
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; }
//template end

char res[1010][1010];
string div_3_1[]={
    "aab",
    "b.b",
    "baa"
};
string div_3_2[]={
    "cc.",
    "..d",
    "..d"
};
string div_4[]={
    "aacd",
    "bbcd",
    "cdaa",
    "cdbb"
};
string div_6[]={
    "aacd..",
    "bbcd..",
    "..aacd",
    "..bbcd",
    "cd..aa",
    "cd..bb"
};
string rem_5[]={
    "aabbc",
    "cxx.c",
    "c..yd",
    "d..yd",
    "daabb"
};
string is_7[]={
    "aac...h",
    "bbc...h",
    ".ddffg.",
    "a.ee.g.",
    "a..aabb",
    "....ghi",
    "....ghi",
};


int main(){
    int n; scanf("%d",&n);
    rep(i,0,n)rep(j,0,n)res[i][j]='.';
    if(n%3==0){
        rep(rot,0,n/3){
            res[rot*3][rot*3]='a';
            res[rot*3][rot*3+1]='a';
            res[rot*3+1][rot*3+2]='b';
            res[rot*3+2][rot*3+2]='b';
        }
    }
    else if(n%4==0){
        rep(rot,0,n/4){
            rep(i,0,4)rep(j,0,4)res[rot*4+i][rot*4+j]=div_4[i][j];
        }
    }
    else if(n==2){printf("-1\n"); return 0;}
    else if(n==7){
        rep(i,0,7)rep(j,0,7)res[i][j]=is_7[i][j];
    }
    else if(n%12==2){
        int k=(n-8)/3;
        rep(rot,0,k){
            rep(i,0,3)rep(j,0,3)res[rot*3+i][rot*3+j]=div_3_1[i][j];
            rep(i,0,3)rep(j,0,3)res[rot*3+i][(rot*3+j+3)%(n-8)]=div_3_2[i][j];
        }
        rep(i,0,4)rep(j,0,4)res[n-8+i][n-8+j]=div_4[i][j];
        rep(i,0,4)rep(j,0,4)res[n-4+i][n-4+j]=div_4[i][j];
    }
    else if(n%6==1){
        int k=(n-4)/3;
        rep(rot,0,k){
            rep(i,0,3)rep(j,0,3)res[rot*3+i][rot*3+j]=div_3_1[i][j];
            rep(i,0,3)rep(j,0,3)res[rot*3+i][(rot*3+j+3)%(n-4)]=div_3_2[i][j];
        }
        rep(i,0,4)rep(j,0,4)res[n-4+i][n-4+j]=div_4[i][j];
    }
    else if(n%6==5){
        rep(rot,0,n/6){
            rep(i,0,6)rep(j,0,6)res[rot*6+i][rot*6+j]=div_6[i][j];
        }
        rep(i,0,5)rep(j,0,5){
            res[(n/6)*6+i][(n/6)*6+j]=rem_5[i][j];
        }
    }
    else if(n%12==10){
        int k=(n-4)/3;
        rep(rot,0,k){
            rep(i,0,3)rep(j,0,3)res[rot*3+i][rot*3+j]=div_3_1[i][j];
            rep(i,0,3)rep(j,0,3)res[rot*3+i][(rot*3+j+3)%(n-4)]=div_3_2[i][j];
        }
        rep(i,0,4)rep(j,0,4)res[n-4+i][n-4+j]=div_4[i][j];
    }
    rep(i,0,n)cout<<res[i]<<endl;
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include<string>
#include<list>

using namespace std;

int main()
{
	list<int> num;
	int n;
	cin >> n;

	string command;
	int comnum;

	for (int i = 1; i <= n; i++) {
		cin >> command;

		if (command == "insert") {
			cin >> comnum;
			num.push_front(comnum);
		}
		else if (command == "delete") {
			cin >> comnum;
			for (list<int>::iterator j = num.begin(); j != num.end(); j++) {
				if (*j == comnum) {
					num.erase(j);
					break;
				}
			}
		}
		else if (command == "deleteFirst") {
			num.pop_front();
		}
		else if (command == "deleteLast") {
			num.pop_back();
		}
	}

	for (list<int>::iterator i = num.begin(); i != num.end(); i++) {
		cout << *i;
		if (i != --num.end()) {
			cout << " ";
		}
	}

	cout << endl;

	return 0;
}



Measured memory_bytes: 34280
#include "bits/stdc++.h"
using namespace std;
const double PI = acos(-1);

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

    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double th = double(h * 60 + m) / 720 * 2 * PI;
    double tm = double(m) / 60 * 2 * PI;
    double xh = a * cos(th);
    double yh = a * sin(th);
    double xm = b * cos(tm);
    double ym = b * sin(tm);
    double dx = xh - xm;
    double dy = yh - ym;
    double ans = sqrt(dx * dx + dy * dy);
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 4108
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <algorithm>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=100010;
const int P=1000000007;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)b - *(long long int*)a;
}
//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ
//	cout<<(n-2)*180<<endl;
//	string s="hoge";
//	cout<<ans<<endl;
//	int  n  ,a  ,b  ,c  ,d  ,e  ,f  ;
//	cin  >>n  >>a  >>b  >>c  >>d  >>e  >>f  ;

/*
	memset(b, '\0', sizeof(b));
初期化*/
/*
	len = strlen(s);
文字列長さ*/
/*
	string s;
	s.size()
*/
/*
	char s[N];
	strlen(s)
/*
	if(  <  )puts("YES");
	else puts("NO");
*/

int main(){
	char s[]="wawa";
//	memset(s, '\0', sizeof(s));


	cin>>s;
	if( (s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2])||(s[0]==s[2]&&s[1]==s[3]&&s[1]!=s[2])||(s[0]==s[3]&&s[1]==s[2]&&s[1]!=s[3])){
//	if(s[0]==s[2]){
	puts("Yes");
	}else{
		puts("No");
	}


}

Measured memory_bytes: 256
import java.util.Scanner;



public class Main {
	static boolean brute(int[] A,int i,int x){
		if(x==0){
			return true;
		}
		if(i==A.length){
			return false;
		}
		if(brute(A,i+1,x)) return true;
		if(brute(A,i+1,x-A[i])) return true;
		return false;
	}
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int n,q;
		n=scan.nextInt();
		int[] A=new int[n];
		for(int i=0;i<n;i++) A[i]=scan.nextInt();
		q=scan.nextInt();

		for(int i=0;i<q;i++){
			if(brute(A,0,scan.nextInt()) ) System.out.println("yes");
			else System.out.println("no");
		}
		
		
		
		scan.close();
	}
}

Measured memory_bytes: 20284
//notepad
#include<iostream>
#include<vector>
#include<algorithm>
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 = 100;
typedef pair<int,int> pii;
const int inf = 1000001;
vector<pii> edge[N];
bool e[N][N];

int ans;
void search(int n,int last,bool *used){
  int ret=0;
  rep(i,last+1){
    if (!used[i])continue;
    int tmp=inf;
    rep(j,(int)edge[i].size()){
      int next=edge[i][j].first;
      if(!used[next])continue;
      tmp=min(tmp,edge[i][j].second);
    }
    if (tmp == inf)continue;
    ret+=tmp;
  }
  ans=max(ans,ret);
  REP(i,last+1,n){
    bool isPG=true;
    rep(j,last+1){
      if (!used[j])continue;
      if (!e[i][j]){isPG=false;break;}
    }
    if (!isPG)continue;
    used[i]=true;
    search(n,i,used);
    used[i]=false;
  }
}

main(){
  int n,m;
  while(cin>>n>>m){
    bool used[n];
    rep(i,n)used[i]=false;
    rep(i,n)edge[i].clear();
    rep(i,n)rep(j,n)e[i][j]=false;
    rep(i,m){
      int f,t,c;
      cin>>f>>t>>c;
      f--;t--;
      e[f][t]=e[t][f]=true;
      edge[f].push_back(make_pair(t,c));
      edge[t].push_back(make_pair(f,c));
    }
    ans=0;
    search(n,-1,used);
    cout << ans << endl;
  }
  return false;
}

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

#define Uni All right
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i)
#define DREP(i,a,b) for(int i=(a),i##_end_=(b);i>i##_end_;--i)
#define LREP(i,a) for(int i=Head[a];i;i=Next[i])
#define LL long long
#define Mod 1000000007 
 
static const int M=100004;
int n,Cnt[26],Ans[26];
char S[M];
int main(){
	scanf("%d%s",&n,S);
	REP(i,0,n)++Cnt[S[i]-'a'];
	int v=1;
	REP(i,0,26){
		v=(LL)v*(Cnt[i]+1)%Mod;
	}
	printf("%d\n",(v+Mod-1)%Mod);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int64)n;i++)
#define FORr(i,k,n)  for(int64 i=(int64)k;i>=n;i--)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACHr(it, l) for (auto it = l.rbegin(); it != l.rend(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}


int main(){
	//in_o();
	int n;
	cin>>n;
	int a[n];
	FOR(i,0,n){
		cin>>a[i];
	}
	int cnt[8]={0};int x=0;
	FOR(i,0,n){
		if(a[i]<400) cnt[0]=1;
		else if(a[i]<800) cnt[1]=1;
		else if(a[i]<1200) cnt[2]=1;
		else if(a[i]<1600) cnt[3]=1;
		else if(a[i]<2000) cnt[4]=1;
		else if(a[i]<2400) cnt[5]=1;
		else if(a[i]<2800) cnt[6]=1;
		else if(a[i]<3200) cnt[7]=1;
		else x++;
	}
	int ans=0;
	FOR(i,0,8)	ans+=cnt[i];
	cout<<max(1,ans)<<" "<<ans+x<<endl; 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int a[n],i,dp[n];
		for(i=0;i<n;i++)cin>>a[i];
		dp[0]=0;
		dp[1]=abs(a[1]-a[0]);
		for(i=2;i<n;i++)
		{
			dp[i]=min((dp[i-1]+abs(a[i]-a[i-1])),(dp[i-2]+abs(a[i]-a[i-2])));
		}
		cout<<dp[n-1]<<"\n";
	}
	return 0;
}

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

int main(){
  int n;
  int t[3];
  cin >> n;

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

  for(int i = 1; i < 100000000; i++){
    bool flg = true;

    for(int j = 0; j < n; j++){
      if(t[j] % i != 0){
        flg = false;
        break;
      }
    }

    if(flg){
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 1160
#include<stdio.h>
 #include<string.h>
#include "iostream"
#include "algorithm"
#include "math.h"
using namespace std;
int N;
string S;
 
void solve() {
    cin >> N >> S;
    S.erase(unique(S.begin(), S.end()), S.end());
    cout << S.size() << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    ll N,K;
    cin>>N>>K;
    vector<int> A(N);
    rep(i,N)cin>>A.at(i);
    ll ans=0;
    rep(i,N){
        ll bef=0,aft=0;
        rep(j,N){
            if(A.at(j)<A.at(i)){
                if(j<i){
                    bef++;
                }
                else{aft++;}
            }
        }
        ll plu=(K+1)*K/2;
        plu%=MOD;
        plu*=(bef+aft);
        plu-=K*bef;
        plu%=MOD;
        ans+=plu;
        ans%=MOD;
    }
    ans+=MOD;
    ans%=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

X, Y, A, B, C = lr()
P = lr(); P.sort(reverse=True)
Q = lr(); Q.sort(reverse=True)
R = lr(); R.sort(reverse=True)
P = P[:X]
Q = Q[:Y]
Z = P + Q + R
Z.sort(reverse=True)
answer = sum(Z[:X+Y])
print(answer)


Measured memory_bytes: 95648
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll, ll>
#define pb push_back
#define rep0(i, n) for(ll i = 0;i<n;i++)
#define rep1(i, n) for(ll i = 1;i<n;i++)
#define all(v) v.begin(),v.end()
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
const int N = 1e6 + 5;

void solve(){
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i=0; i<n; i++){cin >> arr[i];}
    int ans = 0;
    for(int i=1; i<n-1; i++){
        if((arr[i]>arr[i-1] && arr[i]<arr[i+1]) || (arr[i]<arr[i-1] && arr[i]>arr[i+1])){
            ans++;
        }
    }
    cout << ans;
}
 
int main()
{
    fast;
    solve();
    // int t;
    // cin >> t;
    // while(t--){
    //     solve();
    // }
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, ans = 0;
  cin >> n;
  vector<int> l(n);
  for(int i = 0; i < n; i++){
    cin >> l[i];
  }
  sort(l.begin(), l.end());
  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      int k = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();
      ans += max(k - (j + 1), 0);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
a = list(map(int, input().split()))
a += list(map(int, input().split()))
a += list(map(int, input().split()))

for i in [1, 2, 3, 4]:
    if 1 <= a.count(i) <= 2:
        continue
    else:
        print('NO')
        sys.exit()
print('YES')


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const int N = 1e5 + 18;


int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        //for (int tt = 1; tt <= t; tt++) {
        int n; cin >> n;
        int a[n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sum = 0;
        sort(a, a + n);
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    if (a[i] == a[j] || a[j] == a[k]) continue;
                    if (a[i] + a[j] > a[k]) sum++;
                }
            }
        }
        cout << sum;
    }
    return 0;

}




Measured memory_bytes: 3644
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 998244353
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple

#define MAX 5000

int pascal[MAX][MAX], fac[MAX], inv[MAX], finv[MAX] ;

void pre(){
	inv[1]=1;
	for (int i = 2; i <MAX ; i++)
	{
		inv[i]=inv[mod%i]*(mod-mod/i)%mod;
	}
	fac[0]=finv[0]=1;
	for (int i = 1; i < MAX; ++i)
	{
		fac[i]=fac[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ncr(int n, int r){
	if(r<0||r>n)return 0;
	return fac[n]*finv[r]%mod*finv[n-r]%mod;
}

  long long mul(long long a,long long b,long long c){
    long long x = 0,y=a%c;
    while(b > 0){
        if(b%2 == 1){
            x = (x+y)%c;
        }
        y = (y*2)%c;
        b /= 2;
    }
    return x%c;
   }
	long long modpow(long long x, long long y, long long p){
		long long ret = 1, piv = x % p;
		while(y){
			if(y&1) ret = mul(ret, piv, p);
			piv = mul(piv, piv, p);
			y >>= 1;
		}
		return ret;
	}

int k,n,res[5000];

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

cin >> k >> n;
pre();
int p[5000];
p[0]=1;
for(int i=1;i<=4000;i++){
    p[i] = p[i-1]*2%mod;
}
for(int i=2;i<=2*k;i++){
    int ans;
    int y = i;
    if(i>k+1){
        res[i] = res[2*k-i];
        continue;
    }
    if(i%2){
        /*
        ans = modpow(2,i/2,mod);
        //cout << ans << endl;
        ans = ( ans*( ncr(n+k-(y-1)+y/2 -1 , n ) )%mod - (y/2)*(k-(y/2)) + mod )%mod ;
        //cout << ans << endl;
        */
        ans = 0;
        for(int j=0;j<=y/2;j++){
            int temp = p[j]*ncr(y/2,j)%mod;
            int lef = k-(y-1);
            ans = (ans + temp*( ncr(lef + j - 1 + n-j , n-j ) )%mod )%mod ;
        }
        res[i] = ans;
    }
    else {
        ans = 0;
        /*
        ans = modpow(2, (y/2)-1 , mod);
        int temp =  (ncr(n+k-(y-1)+y/2  - 2 , n ) +  ncr(n-1+k-(y-1)+y/2 - 2 , n-1 )) % mod;
        ans = ans*temp%mod;
        */
        for(int j=0;j<=y/2 - 1;j++){
            int temp = p[j]*ncr(y/2-1,j)%mod;
            int lef = k-(y-1);
            ans = (ans + temp*( ncr(lef + j - 1 + n-j , n-j ) + ncr(lef+j-2+n-j , n-j-1) )%mod )%mod ;
        }
        res[i] = ans;

    }
}
for(int i=2;i<=k+1;i++){
    cout << res[i] << endl;
}
for(int i=k;i>=2;i--){
    cout << res[i] << endl;
}


return 0;
}
///....


Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
vector<vector<int> > ans;
vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	int N;
	cin>>N;
	ll q=0;
	VI A(N);
	REP(i,N)cin>>A[i];
	SORT(A);
	int j=0;
	int cnt[100000]={0};
	cnt[0]++;
	FOR(i,1,N){
		//cout<<A[i]<<endl;
		if(A[i-1]!=A[i])j++;
		cnt[j]++;
	}
	ll co=0;
	eREP(i,j)co+=cnt[i];
	co-=j+1;
	//cout<<co<<endl;
	if(co%2==0)cout<<j+1<<endl;
	else cout<<j<<endl;
	
	return 0;
}




















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

int main(){

 ULL a,b,x; cin>>a>>b>>x;
 ULL ans = b/x-a/x;
 if(a%x==0) ans++;
 cout<<ans<<endl;

 return 0;
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  int i;
  int sum;
  sum=0;
  for(i=0; i<N; i++){
    int l,r;
    cin>>l>>r;
    sum+=r-l+1;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int minn[67108864];
int has[200005],f[200005];
char s[200005];
inline int min(int a,int b)
{return a<b?a:b;}
int main (){
	scanf ("%s",s+1);
	int n=strlen(s+1),i,j;
	memset (minn,0x3f,sizeof(minn));
	memset (f,0x3f,sizeof(f));
	for (i=1;i<=n;i++)
	{has[i]=has[i-1]^(1<<(s[i]-'a'));}
	f[0]=0;minn[0]=0;
	for (i=1;i<=n;i++)
	{for (j=0;j<26;j++)
	{f[i]=min(f[i],minn[has[i]^(1<<j)]+1);}
	f[i]=min(f[i],minn[has[i]]+1);
	minn[has[i]]=min(minn[has[i]],f[i]);
	}
	printf ("%d\n",f[n]);
	return 0;
}

Measured memory_bytes: 264192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

     int a = sc.nextInt();
     int b = sc.nextInt();

     if (a < b){
     System.out.println("a < b");
     }else if (a > b){
     System.out.println("a > b");
     }else {
     System.out.println("a == b");
     }

}
}



Measured memory_bytes: 26196
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = -LINF;
    ll N,M; cin >> N >> M;
    vector<ll> x(N),y(N),z(N);
    for(int i = 0; i < N;i++) cin >> x[i] >> y[i] >> z[i];
    vector<ll> val(N);
    for(int i = 0; i < 8;i++){
        for(int j = 0; j < N;j++){
            val[j] = 0;
            val[j] += (i&1?-1:1)*x[j];
            val[j] += (i&2?-1:1)*y[j];
            val[j] += (i&4?-1:1)*z[j];
        }
        sort(val.rbegin(),val.rend());
        res = max(res,accumulate(val.begin(),val.begin()+M,0LL));
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


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

#define fio                           \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
	fio;
	ll t, a, n, q, k, i, m, c, u, f, j, p, x, y, s, b, d;
 
string S;
cin>>S;
 i=0;
for(auto h : S)
{
	i=(i%9+(h-'0'))%9;
}
if(i)cout<<"No"<<endl;
else
	cout << "Yes" << endl;

	 return 0;
}


Measured memory_bytes: 3764
from collections import Counter
def get_primes(targ):
    '''
    素因数分解
    '''
    primes = Counter()

    target = targ
    i = 2
    cnt = 0

    while (i * i) <= target:
        while(target % i) == 0:
            target //= i
            primes[i] += 1
        i += 1

    if target > 1:
        primes[target] += 1

    return primes;

def ABC142D_DisjointSetOf():
    A, B = list(map(int, input().strip().split()))

    prA = get_primes(A)
    prB = get_primes(B)

    ans = 0
    for i in prA.keys():
        if i in prB.keys():
            ans += 1

    print(ans + 1)



def main():
    ABC142D_DisjointSetOf()

if __name__ == "__main__":
    main()


Measured memory_bytes: 38512
/* A / B Problem */
/* 20181119 AOJ */

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(void){
	int a, b;

	scanf("%d %d", &a, &b);
	printf("%d %d %f\n", a / b, a % b, (double)a / b);

	return 0;
}


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



int main() {
int n; cin >> n;
vector<int> v(n);
for(int i =0; i < n; i++){
       cin >> v[i];
}

vector<double> ans(n);
for(int i =0; i < n; i++){
       ans[i] = (double)1/ (double)v[i];
}
double chill =  accumulate(begin(ans), end(ans),0.00);
cout << (double)1/chill;
return 0;

}









  

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int n;
Int a[20][20];
Int cost[1 << 16];
Int dp[1 << 16];

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

    for(int s = 0;s < (1<<n);s++){
        for(int i = 0;i < n;i++){
            if((s >> i) % 2 == 0)continue;
            for(int j = i+1;j < n;j++){
                if((s >> j) % 2 == 0)continue;
                cost[s] += a[i][j];
            }
        }
    }
    
    dp[0] = 0;
    for(int s = 1;s < (1<<n);s++){
        for(int t = s;t > 0;t = (t-1) & s){
            dp[s] = max(dp[s], dp[s-t] + cost[t]);
        }
    }
    cout << dp[(1<<n)-1] << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
int main(void) {
	int a, b, d, r;
	double f;
	scanf("%d", &a);
	scanf("%d", &b);
	d = a / b;
	r = a % b;
	f = (double)a /(double) b;
	printf("%d %d %f", d, r, f);

	return 0;
}


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

int main() {
    ll K, A, B;
    cin >> K >> A >> B;

    ll num = 1LL;
    while (K > 0LL) {
        if (num < A) {
            ++num;
            --K;
        } else if ((num >= A) && (K >= 2LL) && (A + 2LL < B)) {
            num -= A;
            num += B;
            K -= 2LL;
        } else {
            ++num;
            --K;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


void solve() {
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    if ((A - B) % 2 == 0)cout << "Alice" << endl;
    if ((A - B) % 2 != 0)cout << "Borys" << endl;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;

int main(){
	int n,m;
	cin>>n>>m;
	cout<<n*n-m<<endl; 




    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    constexpr int K = 7, L = K * 3, T = (1 << K) - 1;
    constexpr ll S = T | (ll)T << L | (ll)T << (L * 2), X = ((1ULL << (L * 3)) - 1) / T;
    ll p0[L] = {};
    ll r = 0;

    for (int i0 = 0; i0 < n; i0 += T) {
        ll p[K] = {};
        int i1 = min(T, n - i0);
        for (int i = 0; i < i1; i++) {
            ll a;
            cin >> a;

            for (int k = 0; k < K; k++) {
                p[k] += a & X;
                a >>= 1;
            }
        }

        for (int k = 0; k < K; k++) {
            ll c = p[k];
            for (int h = 0; h < 3; h++) {
                p0[K * h + k] += c & S;
                c >>= K;
            }
        }
    }

    for (int k = 0; k < L; k++) {
        ll c = p0[k];
        for (int h = 0; h < 3; h++) {
            ll t = c & ((1LL << L) - 1);
            c >>= L;
            r += (1LL << (L * h + k)) % P * t % P * (n - t) % P;
        }
    }
    r %= P;

    cout << r << endl;

    return 0;
}

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

int main() {
  int M,N;
  cin>>M>>N;
  vector<vector<char>> p(M,vector<char>(M));
  vector<vector<char>> q(N,vector<char>(N));
  for(int i=0;i<M;i++){
    for(int j=0;j<M;j++){
      cin>>p.at(i).at(j);
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>q.at(i).at(j);
    }
  }
  int Z=0;
  for(int i=0;i<=M-N;i++){
    for(int j=0;j<=M-N;j++){
      int A=0;
      for(int k=0;k<N;k++){
        for(int l=0;l<N;l++){
          if(p.at(i+k).at(j+l)!=q.at(k).at(l)){
            A++;
            break;
          }
        }
        if(A==1){
          break;
        }
      }
      if(A==0){
        Z++;
        break;
      }
    }
    if(Z==1){
      break;
    }
  }
  if(Z==1){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}

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

using namespace std;

typedef long long ll;

int N;
string sa, sb;
vector<short> patts;

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

    patts.push_back(0);

    for(int i = 0; i < N;) {
        if(sa[i] == sb[i]) {
            patts.push_back(1);
            i++;
        } else {
            patts.push_back(2);
            i += 2;
        }
    }

    ll result = 1;

    for(int i = 1; i <= N; i++) {
        if(patts[i] == 1) {
            if(patts[i - 1] == 0) {
                result *= 3;
            } else if(patts[i - 1] == 1) {
                result *= 2;
            } else if(patts[i - 1] == 2) {}
        } else if(patts[i] == 2) {
            if(patts[i - 1] == 0) {
                result *= 6;
            } else if(patts[i - 1] == 1) {
                result *= 2;
            } else if(patts[i - 1] == 2) {
                result *= 3;
            }
        }
        result %= 1000000007;
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 200010
using namespace std;
int n;
int a[MAXN];
int sum;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum^=a[i];
	}
	for(int i=1;i<=n;i++){
		sum^=a[i];
		cout<<sum<<" ";
		sum^=a[i];
	}
	return 0;
}

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

using namespace std;

int main(int argc, char const *argv[]) {
	int n,m;
	std::cin >> n >> m;
	std::vector<int> a(m),b(m);
	for (size_t i = 0; i < m; i++) {
		std::cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}

	for (size_t i = 0; i < n; i++) {
		int count = 0;
		for (size_t j = 0; j < m; j++) {
			if (a[j] == i || b[j] == i) {
				count++;
			}
		}
		std::cout << count << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
 {
	
	
	    string s,t;
	    cin>>s>>t;
	    int n=s.length();
	    int m=t.length();
	    int dp[n+1][m+1];
	    string r="";
	    for(int i=0; i<=n; i++){
	    	for(int j=0; j<=m; j++){
	    		if(i==0 || j==0){
	    			dp[i][j]=0;
				}
				else if(s[i-1]==t[j-1]){
					dp[i][j]=1+dp[i-1][j-1];
				}
				else{
					dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
				}
			}
		}
		
		int i=n,j=m;
		while(i>0 && j>0){
			if(s[i-1]==t[j-1]){
				r=s[i-1]+r;
				i--;
				j--;
			}
			else if(dp[i-1][j]>dp[i][j-1]){
				i--;
			}
			else{
				j--;
			}
		}
		cout<<r;
	
	return 0;
}

Measured memory_bytes: 35456
import heapq
N = int(input())
A = [int(item) for item in input().split()]
# N = 10**5
# A = [item for item in range(N)]
A.sort()
M = A.pop()
heapq.heapify(A)
m = heapq.heappop(A)
res = []
while A:
  a = heapq.heappop(A)
  if a < 0:
    res.append((M, a))
    M -= a
  else:
    res.append((m, a))
    m -= a
print(M-m)
for x, y in res:
  print(x, y)
print(M, m)

Measured memory_bytes: 18760
#include<stdio.h>
int main(){
  long long h,w,i,min;
  scanf("%lld%lld",&h,&w);
  min=h*w;
  if(h>=3){
    if(h%3==0)
      min=0;
    else
      min=w;
  }
  if(w>=3){
    if(w%3==0)
      min=0;
    else if(min>h)
      min=h;
  }
  for(i=1;i<=w/2;i++){
    long long a,b,c;
    a=i*h;
    b=(w-i)*(h/2+h%2);
    c=(w-i)*(h/2);
    if(a<c){
      if(b-a<min)
        min=b-a;
    }
    else if(b<a){
      if(a-c<min)
        min=a-c;
    }
    else{
      if(b-c<min)
        min=b-c;
    }
  }
  for(i=1;i<=h/2;i++){
    long long a,b,c;
    a=i*w;
    b=(h-i)*(w/2+w%2);
    c=(h-i)*(w/2);
    if(a<c){
      if(b-a<min)
        min=b-a;
    }
    else if(b<a){
      if(a-c<min)
        min=a-c;
    }
    else{
      if(b-c<min)
        min=b-c;
    }
  }
  printf("%lld\n",min);
  return 0;
}

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//std out
template<typename T>
void print_container(const vector<T> vals) {
    REPinit(i, 0, vals.size() - 1) cout << vals.at(i) << " ";
    cout << vals.back();
}


bool judge(int a, int b, int c) {
    if ((a > b && b > c) || (a < b && b < c)) return true;
    return false;
}

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

    int N;
    cin >> N;

    ll prevH, H;
    cin >> prevH;
    int tmp = 0;
    int ans = 0;

    REPinit(i, 0, N - 1) {
        cin >> H;
        if (prevH >= H) tmp++;
        else tmp = 0;
        ans = max(tmp, ans);
        prevH = H;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
// #include <prettyprint.hpp>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;++i)
#define repi(i,n) for(ll i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<ii,ii>
typedef long long ll;
typedef double lf;

static const ll INF = 1000000000000000;



void Main(){
    ll N;
    sll(N);
    string S;
    map<pair<string, string>, ll> l_status, r_status;
    cin >> S;
    
    ll ans = 0;
    for(ll i=0;i<(1<<N);i++){
        string left_rs = "", left_bs = "";
        for(ll j=0;j<N;j++){
            if((i>>j) & 1){
                left_rs += S[j];
            }else{
                left_bs += S[j];
            }
        }

        pair<string, string> p = make_pair(left_rs, left_bs);
        l_status[p] ++;

    }

    for(ll i=0;i<(1<<N);i++){
        string rs = "", bs = "";
        for(ll j=0;j<N;j++){
            if((i>>j) & 1){
                rs = S[j+N] + rs;
            }else{
                bs = S[j+N] + bs;
            }
        }

        pair<string, string> p = make_pair(bs, rs);
        r_status[p] ++;
    }

    for(auto p:l_status){
        ans += p.second * r_status[p.first];
    }
    cout << ans << endl;

}

int main(){
    Main();

    return 0;

}

Measured memory_bytes: 73984
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
int vis[11];
int main()
{
    int n;
    int k;
    scanf("%d%d",&n,&k);
    for(int i=1; i<=k; i++)
    {
        int x;
        scanf("%d",&x);
        vis[x]=1;
    }
    while(1)
    {
        int k=n;
        int flag=0;
        while(k)
        {
            int y=k%10;
            k/=10;
            if(vis[y]==1)
            {flag=1;break;}
        }
        if(flag==0)
        {cout<<n<<endl;break;}
        n++;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>
#define INF 100000000
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; }

using namespace std;

int main(){
  int i,j,k,n,d,a[30],x;
  cin >>n>>d;
  x=n/(2*d+1);
  if(n-x*(2*d+1)!=0)x++;

  cout<<x<<endl;

  return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    
    if (a * b % 2 == 0){
        cout << "Even" << endl;
    }
    else if (a * b % 2 == 1){
    cout << "Odd" << endl;        
    }
}

Measured memory_bytes: 256
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
#define inf 10000000000000
#define mod 1000000007
using namespace std;
ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
const int N=2e5+10;
const int M=2e5+10;
const int Max=5e5+10;
int vex[Max<<1],R[Max<<1],vis[Max],first[Max],tot;
//!!vex R 长度要Max*2,因为算法特性会生成顶点数两倍的序列
int n;
struct Edge{
    ll cost;
    int to,nxt;
    Edge(){};
    Edge(ll tc,int tt,int tn=0):cost(tc),to(tt),nxt(tn){}
    bool operator < (const Edge &an) const{
        return cost>an.cost;
    }
}Path[M];
int head[N],cnt;
ll dis[N];
void dfs(int u,int deep)
{
    vis[u]=1;
    vex[++tot]=u;   //以tot为编号的的节点
    first[u]=tot;
    R[tot]=deep;
    for(int x=head[u];x;x=Path[x].nxt)
    {
        int v=Path[x].to,c=Path[x].cost;
        if(!vis[v])
        {
            dis[v]=dis[u]+c;
            dfs(v,deep+1);
            vex[++tot]=u;
            R[tot]=deep;
        }
    }
}
int dp[Max<<1][25];
void ST(int n) //n是2*n-1
{
    int x,y;
    for(int i=1;i<=n;i++) dp[i][0]=i;
    for(int j=1;(1<<j)<=n;j++)
    {
        for(int i=1;i+(1<<j)-1<=n;i++)
        {
          x=dp[i][j-1];y=dp[i+(1<<(j-1))][j-1];
          dp[i][j]=(R[x]<R[y]?x:y);
        }
    }
}
int RMQ(int l,int r)
{
    int k=0,x,y;
    while((1<<(k+1))<=r-l+1) k++;
    x=dp[l][k];y=dp[r-(1<<k)+1][k];
    return (R[x]<R[y])?x:y;
}
int lca(int u,int v)
{
    int x=first[u],y=first[v];
    if(x>y) swap(x,y);
    int res=RMQ(x,y);  //在u,v之间的最小深度节点即为lca
    return vex[res];
}
void Init2()
{
    memset(dis,0,sizeof(dis));
    memset(vis,0,sizeof(vis));
}
void Addedge(int u,int v,int w){
    Path[cnt]=(Edge){w,v,head[u]};
    head[u]=cnt++;
}
void Dijkstra(int s,int n)
{
    priority_queue<Edge>que;
    for(int i=1;i<=n;i++) dis[i]=inf;
    dis[s]=0;
    que.push(Edge(0,s));
    while(!que.empty()){
        int cur=que.top().to;que.pop();
        if(vis[cur])continue;
        vis[cur]=true;
        for(int i=head[cur];i;i=Path[i].nxt)
            if(dis[cur]+Path[i].cost<dis[Path[i].to]){
                dis[Path[i].to]=dis[cur]+Path[i].cost;
                que.push(Edge(dis[Path[i].to],Path[i].to));
            }
    }
}
void Init()
{
    memset(head,0,sizeof(head));
    cnt=1;
}
int main()
{
    n=read();
    //while(~scanf("%d",&n))
    {
        Init();
        for(int i=2;i<=n;i++){
            int u=read(),v=read(),w=read();
            Addedge(u,v,w);
            Addedge(v,u,w);
        }
        int q=read(),k=read();
        Dijkstra(k,n);
        Init2();
        dfs(k,1);
        for(int i=1;i<=q;i++){
            int u=read(),v=read();
            printf("%lld\n",dis[u]+dis[v]-dis[lca(u,v)]);
        }
    }
    return 0;
}


Measured memory_bytes: 23680
#include<stdio.h>
 
int main(void){
  int i;
  int n;
  int m;
  int a[10000];
  scanf("%d%d",&n, &m);
  for(i = 0; i < m; i++){
    scanf("%d", &a[i]);
    n -= a[i];
  }
  if (n < -1)
    n=-1;
  printf("%d",n);
}

Measured memory_bytes: 1764
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
using namespace std; 
int main()
{
	long long int a, b, c;
	cin >> a >> b >> c;
	if ((c-1)<=a+b)
	{
		cout << c + b << endl;
	}
	else
	{
		cout << (b + a + 1) + b << endl;
	}
}


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

int h,w;
string s;

int main(){
	scanf("%d%d",&h,&w);
	for(int i=0;i<w+2;i++) printf("#");
		printf("\n");
	for(int i=0;i<h;i++){
		printf("#");
		cin>>s;
		cout<<s;
		printf("#\n");
	}
	for(int i=0;i<w+2;i++) printf("#");
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	if(x+r<=W&&r<=x&&y+r<=H&&r<=y)
	printf("Yes\n");

	else printf("No\n");
	
return 0;
}

Measured memory_bytes: 584
from collections import deque

N,K=map(int,input().split())
V=list(map(int,input().split()))

numofget=min(N,K)
tmp=[]
for i in range(numofget+1):
    A,B=i,numofget-i
    for j in range(B+1):
        q=deque(V)
        bag=[]
        for a in range(A):
            bag.append(q.popleft())
        for b in range(j):
            bag.append(q.pop())
        for _ in range(K-(A+j)):
            if len(bag)>0 and min(bag)<0:
                bag.remove(min(bag))
        tmp.append(sum(bag))
print(max(tmp))

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,ans,temp;
    cin >> n;
    ans = 0;
    ll a[n+5];
    map<ll,ll> hoge;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        hoge[i+a[i]]++;
      }
    for(ll i = 0; i < n; i++){
        ans += hoge[i - a[i]];
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 27932
#include <stdio.h>
#include <stdlib.h>
#define N 500000
#define A 1000000000


int res=0;

void mergesort(int *,int,int);
void merge(int *,int,int,int);

int main(){
  int i,n,S[N];

  scanf("%d",&n); 
  if(n>N){
    printf("error\n");
    exit(1);
  }

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

  mergesort(S,0,n);

  for(i=0 ; i<n-1 ;i++){
    printf("%d " ,S[i]);
  }
  printf("%d",S[n-1]);
  printf("\n%d\n",res);

  return 0;
}

void mergesort(int *S,int left,int right){
    int mid;
    if(left+1 < right){
      mid = (left+right)/2;
      mergesort(S,left,mid);
      mergesort(S,mid,right);
      merge(S,left,mid,right);
    }
}

void merge(int *S,int left,int mid,int right){
  int n1=mid-left,n2=right-mid,i,j,k;
 int L[n1+1],R[n2+1];
  
  for(i=0 ; i<n1 ; i++){
    L[i]=S[left + i];
  }
  
  for(i=0 ; i<n2 ; i++){
    R[i]=S[mid + i];
  }
  
  L[n1]=A;
  R[n2]=A;
  i=0;
  j=0;
  
  for(k=left ; k<right ; k++){
    res++;
    if(L[i]<=R[j]){
      S[k]=L[i];
      i++;
    }
    else{
      S[k]=R[j];
      j++;
    }
    
  }
}

Measured memory_bytes: 4504
n, m = map(int, input().split())
s = input()
t = input()
def gcd(x, y):
    if y == 0: return x
    return gcd(y, x % y)
g = gcd(n, m)
for i in range(0, g):
    if s[i*n//g] != t[i*m//g]:
        print(-1)
        exit()
print(n*m//g)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;

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

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

vector<P> sum(1000010); // 素因数の個数、数字

int main(){
    ll n, p; cin>>n>>p;

    if(n==1){
        cout << p << endl;
        return 0;
    }
    
    ll num=p;
    for(ll i=0; i<1000005; i++){
        sum[i].sc=i;
    }

    bool canans=false;
    for(ll i=2; i*i<=p; i++){
        while(num%i==0){
            canans=true;
            num/=i;
            sum[i].fs++;
        }
    }

    if(!canans) cout << 1 << endl;
    else{
        //sum[num].fs++;
        sort(sum.begin(), sum.end(), greater<P>());
        ll ans=1;
        for(ll i=0; i<1000005; i++){
            //cout << sum[i].fs << " " << sum[i].sc << endl;
            if(sum[i].fs>=n){
                ans*=(ll)pow(sum[i].sc, (sum[i].fs/n));
                //cout << sum[i].fs << " " << sum[i].sc << endl;
            }
            else break;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 16000
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long count = n/(a+b);
		long rest = n%(a+b);
		long blue = 0;
		if(rest < a){
			blue = (a * count) + rest;
		}else {
			blue = a * (count + 1);
		}
		System.out.println(blue);
	}
}

Measured memory_bytes: 22100
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

struct edge {int to,cost;};
typedef pair<int,int> P;
const int MAX = 5001;
const int INF = 1<<29;
int d[MAX];
int V,E;
vector<edge> G[MAX * 2];
vector<int>vv;
P a[MAX];
int A[MAX];

void dijkstra(int s){
  
  priority_queue<P,vector<P>,greater<P> >que;
  fill(d,d+V,INF);
  d[s] = 0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;

    if(A[v] > A[s] + a[s].first){
      vv.push_back(v);
      A[v] = A[s] + a[s].first;
    }

    for(int i=0; i<G[v].size(); i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost && d[v] + e.cost <= a[s].second){
	d[e.to] = d[v] + e.cost;
	que.push(P(d[e.to],e.to));
      }
    }
  }
}



int main(){
  cin >> V >> E;

  for(int i=0; i<V; i++){
    cin >> a[i].first >> a[i].second;
  }

  for(int i=0; i<E; i++){
    int from,to;
    edge e;
    cin >> from >> to;
    from--,to--;
    e.to = to, e.cost = 1;
    G[from].push_back(e);
    e.to = from;
    G[to].push_back(e);
  }

  priority_queue<P,vector<P>,greater<P> >que;
  que.push(P(0,0));


  fill(A,A+MAX,INF);
  A[0] = 0;

  while(!que.empty()){
    P p = que.top();
    que.pop();
    int now = p.second;
    int cost = p.first;

    if(cost > A[now])continue;

    vv.clear();
    dijkstra(now);

    for(int i=0; i<vv.size(); i++){
      que.push(make_pair(A[vv[i]],vv[i]));
    }

    //    cout << "now = " << now << endl;

    //    for(int i=0; i<V; i++) cout << A[i] << " ";
    //    cout << endl;


  }
  cout << A[V-1] << endl;

  return 0;
}

Measured memory_bytes: 2072