akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
int L[100010];
int R[100010];

int main(){

    cin >> N;
    for(int i = 0; i < N; i++) cin >> L[i] >> R[i];
    sort(L, L + N, greater<int>());
    sort(R, R + N);
    ll c = 0;
    ll ans = -1;
    for(int i = 0; i < N; i++){
        c += L[i];
        ans = max(ans, c);
        c -= R[i];
        ans = max(ans, c);
    }
    c = 0;
    for(int i = 0; i < N; i++){
        c -= R[i];
        ans = max(ans, c);
        c += L[i];
        ans = max(ans, c);
    }
    
    cout << ans * 2 << endl;
    

    return 0;
}


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

int main() {
    double a, b, C;
    cin >>a >>b >>C;
    double S2=a*b*sin(C*M_PI/180);
    double S=S2/2;
    double L=a+b+sqrt(a*a+b*b-2*a*b*cos(C*M_PI/180));
    double h=S2/a;
    cout <<fixed <<setprecision(10) <<S <<' ' <<L <<' ' <<h <<endl;
    return 0;
}


Measured memory_bytes: 3600
from collections import deque
if __name__ == "__main__":
    n = int(input())
    graph = []
    for _ in range(n):
        v, k, *tmp = map(int, input().split())
        for j in range(len(tmp)):
            tmp[j] -= 1
        graph.append(tmp)
    visited = [False] * n
    qu = deque()
    qu.appendleft((0, 0))
    ans = [-1] * n
    visited[0] = True

    while qu:
        now, dis = qu.pop()
        ans[now] = dis

        for nei in graph[now]:
            if not visited[nei]:
                visited[nei] = True
                qu.appendleft((nei, dis + 1))
    for i in range(n):
        print(i+1,ans[i])    


Measured memory_bytes: 6028
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt();
		int[] a = new int[n + 1];
		int alice = 0, bob = 0;

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		
		Arrays.sort(a);
		
		for (int i = n; i > 0; i-=2) {
			alice += a[i];
			if (i != 0)
			bob += a[i-1];
		}

		System.out.println(Math.abs(alice - bob));

		sc.close();
	}
}


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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(n), b(n+1);
	for (auto &i : a) cin >> i;

	a.insert(a.begin(), 0);
	vector<int> ans;
	for (int i = n; i >= 1; --i)
	{
		int s = 0;
		for (int j = i; j <= n; j += i)
			s ^= b[j];
		if (s != a[i])
		{
			b[i] = 1;
			ans.push_back(i);
		}
	}

	cout << ans.size() << "\n";
	for (auto &i : ans)
		cout << i << " \n"[&i==&ans.back()];

	return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<ll> vll;

#define pvec(v) for(auto e: v) cout << e << " ";
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forn(s, e) for(int i=s; i<e; ++i)
#define pb push_back
#define INF 1000000000

int main(){
	IO
	int n;
	cin >> n;
	string s;
	cin >> s;

	int preff[3][4005] = {0};
	for(int i=0; i<n; ++i){
		if(s[i] == 'R'){
			preff[0][i+1] = preff[0][i] + 1;
			preff[1][i+1] = preff[1][i];
			preff[2][i+1] = preff[2][i];
		}
		else if(s[i] == 'G'){
			preff[0][i+1] = preff[0][i];
			preff[1][i+1] = preff[1][i]+1;
			preff[2][i+1] = preff[2][i];	
		}
		else{
			preff[0][i+1] = preff[0][i];
			preff[1][i+1] = preff[1][i];
			preff[2][i+1] = preff[2][i]+1;
		}
	}

	ll count = 0LL;
	for(int i = 0; i<n-3; ++i){
		for(int k = i+3; k < n; ++k){
			int j = (i+k)/2;
			if(s[i]!=s[k]){
				if((s[i] == 'R' && s[k]== 'G') || (s[i] == 'G' && s[k] == 'R')){
					count+=(preff[2][k+1] - preff[2][i]);
					if((i+k)%2==0 && s[j] == 'B'){
						--count;
					}
				}
				else if((s[i] == 'R' && s[k]== 'B') || (s[i] == 'B' && s[k] == 'R')){
					count+=(preff[1][k+1] - preff[1][i]);
					if((i+k)%2==0 && s[j] == 'G'){
						--count;
					}
				}
				else if((s[i] == 'G' && s[k]== 'B') || (s[i] == 'B' && s[k] == 'G')){
					count+=(preff[0][k+1] - preff[0][i]);
					if((i+k)%2==0 && s[j] == 'R'){
						--count;
					}
				}
			}
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3708
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

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

	vector<queue<long> > a(n);

	for (int i = 0; i < q; i++) {
		int s, t;
		cin >> s >> t;
		
		if (s == 0) {
			long x;
			cin >> x;
			a[t].push(x);
		}
		else if (s == 1 && !a[t].empty())
			cout << a[t].front() << endl;
		else if (s == 2 && !a[t].empty())
			a[t].pop();
	}

	return 0;
}


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

const int N=2e5+20,MOD=998244353;

int n,k,l[N],r[N],dp[N];
vector <pair <int,int>> v;

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<k;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
		v.push_back({l[i],r[i]});
	}
	sort(v.begin(),v.end());

	vector <queue <int>> vq(k);
	vector <int> vs(k);

	dp[1]=1;
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<k;j++)
		{
			int l=v[j].first,r=v[j].second;

			if(i>l)
			{
				vq[j].push(dp[i-l]);
				vs[j]+=dp[i-l];
				vs[j]%=MOD;
			}
			if(i>r+1)
			{
				vs[j]-=vq[j].front();
				vs[j]%=MOD;
				if(vs[j]<0) vs[j]+=MOD;
				vq[j].pop();
			}
		}

		for(auto j:vs) dp[i]=(dp[i]+j)%MOD;
	}

	printf("%d",dp[n]);
}

Measured memory_bytes: 5408
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include <map>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()


int main() {
	int n, m, x;
	cin >> n >> m >> x;
	ll c[n];
	ll a[n][m];
	rep(i, n) {
		cin >> c[i];
		rep(j, m) {
			cin >> a[i][j];
		}
	}

	ll ans = LONG_MAX;
	ll sum = 0;
	for (int i = 0; i < (1 << n);i++) {
		sum = 0;
		vector<ll> X(m, 0);
		for (int j = 0; j < n; j++) {
			if (i & (1<<j)) {
				sum += c[j];
				rep(k, m) {
					X[k] += a[j][k];
				}
			}
		}
		bool tmp = true;
		//cout << sum << " ";
		rep(j, m) {
			//cout << X[j] << " ";
			if (X[j] < x) {
				tmp = false;
			}
		}
		//cout << endl;
		if (tmp && sum < ans) {
			ans = sum;
		}
		//cout << ans << endl;
	}
	if (ans != LONG_MAX) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}
}


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

int gcd(int X,int Y){
    int x=min(X,Y);
    int y=max(X,Y);
    int r=y%x;
    while(r!=0){
        y=x;
        x=r;
        r=y%x;
    }
    return x;
}

int main() {
    int N; cin>>N;
    vector<int> a(N);
    rep(i,N)cin>>a[i];
    int q =gcd(a[0],a[1]);
    for(int i=2;i<N;i++){
        q =gcd(q,a[i]);
    }
    cout<<q<<endl;
}

Measured memory_bytes: 640
#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>;
using vv = vector<vector<ll>>;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;} template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};int dy[4] = {0,-1,0,1};
using Graph = vector<vector<int> >;

int main() {
    int n,m,x;cin >> n >> m >> x;
    vector<int> C(n);
    vector<vector<int>>A(n,vector<int>(m));
    for(int i=0;i<n;i++){
	cin >> C[i];
	for(int j=0;j<m;j++){
	    cin >> A[i][j];
	}
    }
    int ans = 10000000;
    for(int bit = 0;bit<(1<<n);bit++){
	int tmp = 0;
	vector<int> k(m,0);
	for(int i=0;i<n;i++){
	    if(bit & (1<<i)){
		for(int j =0;j<m;j++){
		    k[j] += A[i][j];
		}
		tmp += C[i];
	    }
	}
	bool ok = true;
	for(int t=0;t<m;t++){
	    if(k[t]<x) ok = false;
	}
	if(ok) ans = min(ans,tmp);
    }
    if(ans==10000000)cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n;cin>>n;
    string s;cin>>s;
    vector<ll> w(n),e(n);
    ll w_count=0,e_count=0;
    REP(i,n){
        s[i]=='W'?w_count++:e_count++;
        w[i]=w_count;
        e[i]=e_count;
    }
    ll min=n;
    REP(i,n){
        ll left = (i==0)? 0 :w[i-1];
        ll right= e[n-1]-e[i];
        ll sum=left+right;
        if(min>sum){
            min=sum;
        }
    }
    cout<<min;
    return 0;
}


Measured memory_bytes: 8200
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using Graph = vector<vector<int>>;
using ll = long long;

int main() {
  int a[3];rep(i,3) cin>>a[i];
  sort(a,a+3);
  bool ans = a[0]==5 && a[1]==5 && a[2]==7;
  cout << (ans?"YES":"NO") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <cstring>
#include <algorithm>
using namespace std;

string s1,s2;
int main(){

    cin>>s1;
    cin>>s2;
    int len1=s1.length();
    int len2=s2.length();
    int i=0;
    bool flag=false;
    while(i<len1){
        if(s1==s2){
            flag=true;
            break;
        }
        else{
            string temp=s1.substr(0,len1-1);
            s1=s1[len1-1]+temp;
        }
        i++;
    }
    if(flag==false) cout<<"No";
    else cout<<"Yes";
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 30, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N >> M;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; }
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }

int div2count(int n) {
  int ret = 0;
  if (!n) return 0;
  for (;;) {
    if (n & 1) {
      return ret;
    }
    ret++;
    n >>= 1;
  }
}
void solve() {
  each(x, va) {
    x >>= 1;  // ぐうすうなので
  }

  int cnt2 = div2count(va[0]);
  for (auto x : va) {
    if (cnt2 != div2count(x)) {
      cout << 0 << endl;
      return;
    }
  }

  int al = 1;
  rep(i, 0, N - 1) { al = lcm(al, va[i]); }
  if (al > M) {
    cout << 0;
    return;
  }
  M += al;
  cout << M / 2 / al << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

#define MAXN 1005
#define MOD 1000000007

using namespace std;

char mat[MAXN][MAXN];
int dp[MAXN][MAXN];

int solve(int y, int x) {
    if(y == 0 && x == 0) {
        return 1;
    }
    if(y < 0 || x < 0 || mat[y][x] == '#') {
        return 0;
    }
    if(dp[y][x] != -1) {
        return dp[y][x];
    }
    return dp[y][x] = (solve(y, x - 1) % MOD + solve(y - 1, x) % MOD) % MOD;
}

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

    memset(dp, -1, sizeof(dp));

    int h, w;
    cin >> h >> w;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> mat[i][j];
        }
    }
    cout << solve(h - 1, w - 1) << '\n';

    return 0;
}

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

int main() {

  int N;
  cin >> N;

  vector<int> V(N);
  vector<int> C(N);

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

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

  int answer = 0;

  for (int i = 0; i < N; i++) {
    if (0 < V[i] - C[i]) {
      answer += V[i] - C[i];
    }
  }

  cout << answer << endl;

}

Measured memory_bytes: 256
double d[3],e[3],s[99][3];main(T,n,i,j,k,l){for(scanf("%d",&T);T;T--){
for(scanf("%lf%lf%lf%d",d,d+1,d+2,&n),i=0;i<n;i++)scanf("%lf%lf%lf",s[i],s[i]+1,s[i]+2);
for(i=0;i<n;i++)for(j=0;j<n;j++)for(*e=sqrt(pow(*s[j]-*s[i],2)+pow(s[j][1]-s[i][1],2)+pow(s[j][2]-s[i][2],2)),k=0;k<n;k++)if(i-j&&j-k&&k-i){
	e[1]=sqrt(pow(*s[k]-*s[j],2)+pow(s[k][1]-s[j][1],2)+pow(s[k][2]-s[j][2],2));
	e[2]=sqrt(pow(*s[i]-*s[k],2)+pow(s[i][1]-s[k][1],2)+pow(s[i][2]-s[k][2],2));
	for(l=0;l<3;l++)if(d[l]/d[(l+1)%3]-e[l]/e[(l+1)%3]>1e-3)break;
	if(l>2)printf("%d %d %d\n",k+1,i+1,j+1);
}
}exit(0);}

Measured memory_bytes: 644
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;



int main() {
	char s[4]; scanf("%s",&s);
	string ans; ans+=s[0];
	int t[4]; bool a[3];
	rep(i,0,4) t[i]=s[i]-'0';
	rep(i,0,8){
		int sub=t[0];
		rep(j,0,3){
			if(i>>j&1){
				a[j]=true;
				sub+=t[j+1];
			}
			else{
				a[j]=false;
				sub-=t[j+1];
			}
		}
		if(sub==7){
			rep(j,0,3){
				if(a[j]) ans+='+';
				else ans+='-';
				ans+=s[j+1];
			}
			cout<<ans<<"=7"<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
class Main{
 
    public static void main(String args[]){
    //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    Scanner in= new Scanner(System.in);
    int[] vec = new int[10];
    for(int i=0;i<10;i++)vec[i] = in.nextInt();
    Arrays.sort(vec);
    for(int i=9;i>=7;i--){
        System.out.println(vec[i]);
    }
    }
 
}


Measured memory_bytes: 26272
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    int n,cnt = 0;
    cin >> n;
    int a[n];
    vector<int> yakusuu;
    
    rep(i,0,n){
        cin >> a[i];    
    }
    
    sort(a,a+n);
    
    rep(i,1,sqrt(a[n-1])+1){
        if(!(a[n-1] % i)){
            yakusuu.push_back(i);
            yakusuu.push_back(a[n-1]/i);
        }
    }
    
    sort(yakusuu.begin(),yakusuu.end());
    
    rep(i,0,n-1){
        rep(j,0,yakusuu.size()){
            if(a[i] <= yakusuu[j]){
                cnt += yakusuu[j]-a[i];
                break;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(a + b, min(b + c, c + a)) << endl;
}

Measured memory_bytes: 256
import sys

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    a, b, c, d = read_int_list()
    res = abs(max(a, c) - min(b, d))
    if c >= b or a >= d:
        res = 0
    print(res)


main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll a,b,c;
	cin >> a >> b >> c;
	ll ct = 0;
	ll g = min(b,c);
	ct += 2*g;
	b-=g;c-=g;
	ll f = min(a,c);
	ct += f;
	c -= f;a -= f;
	ct += b;
	if(c > 0) {ct++;}
	cout << ct << '\n';
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll X, Y, A, B, C; 
  cin >> X >> Y >> A >> B >> C;
  
  vector<ll> p(A), q(B), r(C);
  FOR(i,A){ cin >> p[i]; }
  FOR(i,B){ cin >> q[i]; }
  FOR(i,C){ cin >> r[i]; }
  
  sort(all(p),greater<ll>());
  sort(all(q),greater<ll>());
  sort(all(r),greater<ll>());
  
  vector<ll> pqr;
  FOR(i,X){ pqr.pb(p[i]); }
  FOR(i,Y){ pqr.pb(q[i]); }
  FOR(i,C){ pqr.pb(r[i]); }
  sort(all(pqr),greater<ll>());
  
  ll ans = 0;
  FOR(i,X+Y){ ans += pqr[i]; }
  
  // output
  cout << ans << endl;

  return 0;
}

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

int main(){
    ll K, A ,B;
    cin >> K >> A >> B;
    
    for(ll i = A; i <= B; i++){
        if(i % K ==0){
            cout << "OK" <<endl;
            return 0;
        }
    }
    cout << "NG" <<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sstream>

using namespace std;

long long gcd(long long x, long long y){
    return y ? gcd(y, x % y) : x;
}

int main(){
    long long n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;

    long long a = n / gcd(n, m);
    long long b = m / gcd(n, m);

    bool isOK = true;
    for(long long i = 0; i < gcd(n, m); ++i){
        if(s[a * i] != t[b * i]){
            isOK = false;
            break;
        }
    }
    if(isOK) cout << (n * m / gcd(n, m)) << endl;
    else     cout << -1 << endl;

    return 0;
}

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

using namespace std;

#define MAX_N 100005

int df[MAX_N], ds[MAX_N];
int n,a,b,p1,p2;
vector<int> v[MAX_N];
queue<int> q;

void calc(int from,int to,int d[]) {
	fill(d+1,d+n+1,INT_MAX);
	q.emplace(from);
	d[from] = 0;
	while((int)q.size()) {
		int cur = q.front();
		q.pop();
		for(auto p : v[cur]) {
			if(p != to && d[p] == INT_MAX) {
				q.emplace(p);
				d[p] = d[cur]+1;
			}
		}
	}
}

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

	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a >> b;
		v[a].emplace_back(b);
		v[b].emplace_back(a);
	}
	calc(1,n,df);
	calc(n,1,ds);

	for(int i = 1; i <= n; i++) {
		if(i == 1 || i == n) continue;
		if(df[i] <= ds[i]) p1++;
		else p2++;
	}
	if(p1 > p2) {
		cout << "Fennec";
	} else {
		cout << "Snuke";
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 6656
import numpy as np

H,W,K=map(int,input().split())
c=[]
for i in range(H):
    c.append(list(input()))
ans = 0
for i in range(2**H):
    for j in range(2**W):
        count = 0
        for ii in range(H):
            for jj in range(W):
                if (i>>ii&1)==0 and (j>>jj&1)==0 and c[ii][jj]=='#':
                    count +=1
        if count == K:
            ans += 1

print(ans)   

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

int asc(const void *a, const void *b) {
	long *A = (long *)a;
	long *B = (long *)b;
	if (*A > *B) return 1;
	if (*A < *B) return -1;
	return 0;
}

int main()
{
	long n[3];
	long even = 0;
	long d;
	long sum = 1;
	rep (i , 3)
	{
		cin >> n[i];
		if (n[i] % 2 == 0)
		{
			cout << 0 << endl; return 0;
		}
		sum *= n[i];
	}
	qsort(n, sizeof (n) / sizeof (*n) , sizeof (*n), asc);
	long r = n[0] * n[1];
	long i = 0;
	long min = sum;
	int red;
	while (i < n[2])
	{
		// cout << r << '*' << i <<endl;
		if (labs((r * i) - (sum / 2)) < min)
		{
			min = labs((r * i) - (sum / 2));
			red = r * i;
		}
		i++;
	}
	long blue = sum - red;
	cout << r << endl;
	return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
typedef long long ll;
ll cnt[maxn],dp[maxn];
void init()
{
    memset(cnt,0,sizeof(cnt));
}
signed main()
{
    char s[10];
    while(~scanf("%s",s))
    {
        if(s[2]==s[3]&&s[4]==s[5])
        {
            puts("Yes");
        }
        else puts("No");
    }
    return 0;
}

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

int main(){
  	int N, check, cnt=0;
	cin >> N;
  	int P[N];
  	for(int i=0; i<N; i++){
    	cin >> P[i];
    }
  	check=P[0];
  	for(int i=0; i<N; i++){
    	check=min(check, P[i]);
      	if(check==P[i]){
        	cnt++;
        }
    }
  	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
N = int(input())

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


ans = 0

nows = 0
nowx = 0
l = 0

for r in range(N):

    nows += A[r]
    nowx ^= A[r]

    while nows != nowx:
        nows -= A[l]
        nowx ^= A[l]
        l += 1

    ans += r-l+1

print (ans)


Measured memory_bytes: 77772
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    long double a, b, h, m;
    cin >> a >> b >> h >> m;
    long double o_h = (long double)(h / 12.0 + m / 6.0 / 12.0 / 10.0) * 2.0 * M_PI;
    long double o_m = m / 60.0 * 2.0 * M_PI;

    long double dx = (cos(o_h) * a) - (cos(o_m) * b);
    long double dy = (sin(o_h) * a) - (sin(o_m) * b);


    cout << SP(10) << sqrt(dx * dx + dy * dy) << endl;
}

Measured memory_bytes: 4168
#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,string>;

int main(){
  ll n,m;
  cin >> n >> m;
  //とりあえずi回目にといた問題番号と結果をひかえる
  vector<P> p(m);
  rep(i,m)
    cin >> p[i].first >> p[i].second;
  
  //数える作業
  ll countAC = 0;
  vector<ll> countWA(n,0);
  //既にACされているか否かを判定するベクトル
  vector<ll> AC(n,0);
  rep(i,m){
    if(p[i].second == "WA"){
      //まだACになってなければWAとしてカウント
      if(AC[p[i].first-1] == 0)
        countWA[p[i].first-1]++;
    }
    else     
      //まだACになってなければACとしてカウントして
      if(AC[p[i].first-1] == 0){
        countAC++;
        //問題をもう解いたものとして記録
        //次すでに解いた問題をACした場合ベクトルACの値が1なので
        //countAC++;とはならないはず。
        AC[p[i].first-1] = 1;
      }
  }
  ll penalty = 0;
  rep(i,n){
    if(AC[i] == 1)
      penalty += countWA[i];
  }
  cout << countAC << " " << penalty << endl;
}

Measured memory_bytes: 8064
import sys
from operator import itemgetter

def solve():
    input = sys.stdin.readline
    N = int(input())
    X = [[int(a) for a in input().split()] for _ in range(N)]
    X.sort()
    lower = 0
    if N % 2 == 1: lower = X[N//2][0]
    else: lower = X[(N-1)//2][0] + X[N//2][0]

    X.sort(key = itemgetter(1))
    higher = 0
    if N % 2 == 1: higher = X[N//2][1]
    else: higher = X[(N-1)//2][1] + X[N//2][1]

    print(higher - lower + 1)

    return 0

if __name__ == "__main__":
    solve()

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

typedef long long ll;
int n;
ll a[100005],x,Out1,Out2;
ll b[100005];

int main(){
	cin>>n>>x;
	for(int i = 1; i <= n; i++) cin>>a[i], b[i] = a[i];
	for(int i = 1; i <= n; i++){
		if(a[i] + a[i - 1] > x){
			Out1 += (a[i] + a[i - 1] - x);
			a[i] = x - a[i - 1];
			if(a[i] < 0) a[i] = -a[i];
		}
		if(b[i] + b[i + 1] > x){
			Out2 += (b[i] + b[i + 1] - x);
			b[i] = x - a[i + 1];
			if(b[i] < 0) b[i] = - b[i];
		}
	}
	ll Out = min(Out1, Out2);
	cout<<Out<<endl;
	return 0;
} 

Measured memory_bytes: 1792
"""
title:不足しているカードの発見
memo:
for文で
print(記号, カード番号)で出力すると
求められている出力の形になる
"""
from collections import defaultdict
N = int(input())
# input_cards = [int(input()) for x in range(n)]
input_cards = []  # inputデータを保存
correct_list = []  # トランプのリスト

for i in range(N):  # 入力カードのリストを作成
    suit, num = map(str, input().split())
    input_cards.append(suit + "_" + num)
# print(input_cards)
card_suits = ["S", "H", "C", "D"]  # 出力もこの順で返す
for i in card_suits:  # 本来あるべきカードの組み合わせ（52枚）のデッキのリスト
    for j in range(1, 14):
        correct_list.append(i + "_" + str(j))

diff_list = set(correct_list) - set(input_cards)  # 足りないカードのリストを作成
# print(diff_list)
# print(type(diff_list))
S, H, C, D = [], [], [], []
for i in diff_list:  # diff_listの中からS, H, C, Dの順にカードを取り出す
    if i[0] == "S":
        S.append(int(i[2:]))
    elif i[0] == "H":
        H.append(int(i[2:]))
    elif i[0] == "C":
        C.append(int(i[2:]))
    elif i[0] == "D":
        D.append(int(i[2:]))

S = sorted(S)
H = sorted(H)
C = sorted(C)
D = sorted(D)
# print(S, H, C, D)

for i in S:
    print("S " + str(i))
for i in H:
    print("H " + str(i))
for i in C:
    print("C " + str(i))
for i in D:
    print("D " + str(i))


Measured memory_bytes: 6008
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N, D, X;

    scanf("%d%d%d", &N, &D, &X);

    int A[N];
    int ans = X;

    for(int i = 0; i < N; i++){
        scanf("%d", &A[i]);
        ans += (D-1) / A[i] + 1;
    }

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

    return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
int main() {
    Int h, n;
    cin >> h >> n;
    rep(i, n) {
        Int a;
        cin >> a;
        h -= a;
    }
    puts(h <= 0 ? "Yes" : "No");
}


Measured memory_bytes: 256
# Here your c



n,m,k=gets.split
n=n.to_i
m=m.to_i
k=k.to_i


array=[]
i=n
l=0
n.times{
    kk=m*l

     j=0
    (m+1).times{
        array<<kk
        kk=kk+i
        
        
    }
    
  l=l+1  
 i=i-2 
    
}

array=array.sort.uniq


if array.include?(k)

 puts "Yes"
 
 else 
 puts "No"
end

Measured memory_bytes: 37360
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
using ll=long long;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,k){
    int d;
    cin >> d;
    rep(i,d){
      int a_2;
      cin >> a_2;
      a[a_2-1]+=1;
    }
  }
  int cnt=0;
  rep(i,n){
    if(a[i]==0) cnt+=1;
  }
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=4e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1.0e-14;
ll go(ll n,ll x){
    ll len=(1ll<<(n+1))-3;
    ll p=(1ll<<n)-1;
    if(n==0)return 1;
    if(x==1)return 0;
    else if(x<=len+1)return go(n-1,x-1);
    else if(x==len+2)return p+1;
    else if(x<=(len*2)+2)return p+1+go(n-1,x-len-2);
    else return p*2+1;
}
void solve(){
    ll n,x;
    cin>>n>>x;
    cout<<go(n,x)<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


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


//c++ templte for help............................................................................................................................................
typedef long long ll;

//template<typename... T>
//void print1(T... t){
	//((cout<<t<<" "),...);
//}

//template<typename... T>
//void print2(T... t){
		//vector<vector<ll>> ans={t...};
		//for(ll i=0;i<(ll)ans.size();i++){
			//if(i!=0) cout<<"\t\t";
			//else cout<<"\t";
			//for(ll j=0;j<(ll)ans[i].size();j++){
				//cout<<ans[i][j]<<" ";
			//}
			//if(i!=(ll)ans.size()-1)
			//cout<<endl;
		//}
//}	
//#define deb(...) cout<<" [ "#__VA_ARGS__<<" : "; print1(__VA_ARGS__); cout<<"]"<<endl; 
//#define vdeb(...) cout<<" [ "#__VA_ARGS__<<" : "; print2(__VA_ARGS__); cout<<"]"<<endl;





	
 
//for loop
//#define fo(i,n) for(int i=0;i<(ll)n;i++)
//#define Fo(i,k,n) for(int i=k;i<n;i++)
 
 
//to print vector element 
//template<typename T>
//void printV(T vec){
	//fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
	//cout<<endl;
	//}
	
 
#define M int(1e9+7)
const int INF=1e9+5;
 
//iterate map
//template<typename T>
//void itR(T map){
	 //for(auto itr=map.begin();itr!=map.end();itr++){
				//deb(itr->first,itr->second);
			//}
	//cout<<endl;
//}


 
 
 
//c++ template for help...........................................................................................................................................


ll solve(){
	ll n;
	cin>>n;
	
	if(n<=1) return 0;
	
	multiset<ll,greater<ll>> ms;
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;
		ms.insert(a);
		ms.insert(a);
	}
	
	ll sum=0;
	ll count=0;

	
	for(auto x: ms){
		if(count>0) sum+=x; 
		
		//deb(sum);
		count++;
		if(count==n) break;
	}

	return sum;
	
}


int main() {
	//stringstream ss;
	//ss<<"akhil";
	//cout<<ss.str()<<endl;
	cout<<setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	

	//ll testCase;
	//cin>>testCase;
	//for(ll tt=0;tt<testCase;tt++){
		//solve();
		ll ans=solve();
		cout<<ans<<endl;
	//}
	return 0;
}


Measured memory_bytes: 22340
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  string s;
  int q;
  cin >> s >> q;
  
  int t, f;
  int ord = 1;
  char c;
  rep(i, q){
    cin >> t;
    if(t == 1){
      if(ord) ord = 0;
      else ord = 1;
      continue;
    }
    
    cin >> f >> c;
    if(f == 1){
      if(ord) s = c + s;
      else s.push_back(c);
    }
    else{
      if(ord) s.push_back(c);
      else s = c + s;
    }
  }
  
  if(ord == 0) reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 4580
#include<bits/stdc++.h>
using namespace std;
struct UnionFind{
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int size){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++) r[i]=1,p[i]=i;
  }
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
int main(){
  int n,q,i,a,b,c;cin>>n>>q;
  UnionFind u(n);
  for(i=0;i<q;i++){
    cin>>a>>b>>c;
    if(a) cout<<u.same(b,c)<<endl;
    else u.unite(b,c);
  }
  return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vec(k) vector<k>
#define vecvec(k) vector<vector<k> >
#define pai(k) pair<k,k>
#define mod 1000000007
#define mpai make_pair
#define p1 first
#define p2 second
#define umap(x,y) unordered_map<x,y>
 vector<ll> adj[100001];

ll dp[100001][2];

int solve(int node, int constraint, int parent)
{
	ll ans=0;
	if(dp[node][constraint]!=-1)
		return dp[node][constraint];

	
		ll way1=1;
		for(int child : adj[node])
		{
			if(child!=parent)
				way1=(way1*solve(child, 0,node))%mod;
		}
		ans+=way1;
	
	if(!constraint)
	{
		ll way2=1;
		for(int child : adj[node])
		{
			if(child!=parent)
				way2=(way2* solve(child, 1, node))%mod;
		}
		ans=(ans+way2)%mod;

	}
	return dp[node][constraint]=ans%mod;
}


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

   ll n,a,b;
   cin>>n;
   memset(dp,-1,sizeof(dp));
   for(int i=0;i<n-1;i++)
   {
   	cin>>a>>b;
   	adj[a].push_back(b);
   	adj[b].push_back(a);
   }
   ll ans=solve(1, 0,-1);
   cout<<ans<<"\n";
 

return 0;
}


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

int main() {
  int H,W;
  cin>>H>>W;
  vector<vector<char>>c(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>c.at(i).at(j);
    }
  }
  vector<vector<char>>ans(2*H,vector<char>(W));
  for(int i=0;i<2*H;i++){
    for(int j=0;j<W;j++){
      ans.at(i).at(j)=c.at(i/2).at(j);
    }
  }
  for(int i=0;i<2*H;i++){
    for(int j=0;j<W;j++){
      cout<<ans.at(i).at(j);
      if(j==W-1){
        cout<< endl;
      }
    }
  }
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int A, P; cin >> A >> P;
    P += 3 * A;
    cout << P / 2 << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;


int h, w, n, a, mem, cnt, c[100][100];
bool b;
int main() {
	cin >> h >> w >> n;
	mem = -1;
	cnt = -1;
	bool b = false;
	lp(n) {
		cin >> a;
		LP(a, j) {
			if (cnt == w || cnt == -1) {
				mem++;
				b = !b;
				if (b)
					cnt++;
				else cnt--;
			}
			c[mem][cnt] = i;
			if (b)
				cnt++;
			else
				cnt--;
		}
	}
	lp(h) {
		LP(w, j) {
			cout << c[i][j] + 1 << sp;
		}
		cout << endl;
	}
	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 200000, MAX_Q = 200000;
int n,q;
ll s[MAX_N];
ll t[MAX_N];
ll x[MAX_N];
set<pli, greater<pli>> l;
set<pli, greater<pli>> r;
ll d[MAX_Q];

template <typename T>
struct counter {
  map<T,int> ctr;

  void inc(T v) {
    ctr[v]++;
  }

  void dec(T v) {
    ctr[v]--;
    if (ctr[v] <= 0) ctr.erase(v);
  }

  bool empty() {
    return ctr.empty();
  }

  T front() {
    return ctr.begin()->first;
  }

  T back() {
    return ctr.rbegin()->first;
  }
};

counter<ll> xs;

int main()
{
#define FASTIO
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n >> q;
  forn(i,n) {
    cin >> s[i] >> t[i] >> x[i];
    l.insert(mp(x[i]-s[i],i));
  }

  forn(i,q) cin >> d[i];

  forn(i,q) {
    while (!l.empty() && l.begin()->fst >= -d[i]) {
      int j = l.begin()->snd;
      r.insert(mp(x[j]-t[j],j));
      xs.inc(x[j]);
      l.erase(l.begin());
    }

    while (!r.empty() && r.begin()->fst >= -d[i]) {
      xs.dec(x[r.begin()->snd]);
      r.erase(r.begin());
    }

    if (xs.empty())
      printf("-1\n");
    else {
      printf("%lld\n", xs.front());
    }
  }

  return 0;
}


Measured memory_bytes: 32512
function main(input){
    let args = input.split(" ").map(x=>parseInt(x));
    let W = args[0],
        H = args[1],
        x = args[2],
        y = args[3],
        r = args[4];
    
    let points = [[x+r,y],[x-r,y],[x,y+r],[x,y-r]];
    let ans = "Yes";
    
    for(let i=0;i<4;i++){
        if(points[i][0]>W || points[i][0]<0 ||points[i][1]>H ||points[i][1]<0){
            ans = "No";
            break;
        }
    }
    
    console.log(ans);
        
    
    
    
}



main(require("fs").readFileSync("/dev/stdin","utf-8"));


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

using namespace std;

typedef unsigned long long int ll;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m,ans;
    cin >> n >> m;
    if(n==1 || m==1)
        cout << 1;
    else
      {
       ans = (n*m + 1)/2;
   cout << ans;    
      }  
      

    return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    A,B,M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    waribiki = [list(map(int, input().split())) for _ in range(M)]
    res = min(a) + min(b)
    for i in range(M):
        x, y, c = waribiki[i-1]
        res = min(res, a[x-1] + b[y-1] - c)
    print(res)

if __name__ == '__main__':
    main()

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

int main() {
  long long N, K; cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    int a; cin >> a; a--;
    A.at(i) = a;
  };

  vector<bool> visited(N, false);
  visited.at(0) = true;
  int cnt = 0;
  int cur = 0;
  int right = 0;
  int place = 0;
  bool flag = false;
  for (long long i = 0; i < K; i++) {
    cur = A.at(cur);
    cnt++;
    if (visited.at(cur)) {
      right = cnt;
      place = cur;
      flag = true;
      break;
    }
    visited.at(cur) = true;
  }

  if (!flag) {
    cout << cur + 1 << endl;
    return 0;
  }

  int left = 0;
  cnt = 0;
  cur = 0;
  for (long long i = 0; i < K; i++) {
    if (cur == place) {
      left = cnt;
      break;
    }
    cur = A.at(cur);
    cnt++;
  }

  int cycle = right - left;
  K -= left;
  K %= cycle;
  cnt = 0;
  cur = place;
  for (long long i = 0; i < K; i++) {
    cur = A.at(cur);
    cnt++;
  }
  cout << cur + 1 << endl;

}

Measured memory_bytes: 4052
#include <stdio.h>

int main(void){
	int matrix[11][11],i,j,dataset;
	while(scanf("%d",&dataset)){

		if(dataset==0)break;

		//init add total norm
		for(i=0;i<dataset+1;i++){
			matrix[dataset][i]=0;
			matrix[i][dataset]=0;
		}

		//input and calc
		for(i=0;i<dataset;i++){
			for(j=0;j<dataset;j++){
				scanf("%d",&matrix[i][j]);
				matrix[i][dataset]+=matrix[i][j];
			}
		}

		//calc
		for(j=0;j<dataset+1;j++){
			for(i=0;i<dataset;i++){
				matrix[dataset][j]+=matrix[i][j];
			}
		}

		//output
                for(i=0;i<dataset+1;i++){
                        for(j=0;j<dataset+1;j++){
                                printf("%5d",matrix[i][j]);
                        }
			printf("\n");
                }
	}
}

Measured memory_bytes: 1044
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N;
    cin >> N;
    vector<ll> A;
    rep(i,N){
        ll a;
        cin >> a;
        if(i==0||A[A.size()-1]!=a) A.push_back(a);
    }
    ll out = 1;
    ll n = A.size();
    rep(i,n){
        if(i!=0&&i!=n-1){
            if((A[i]>A[i-1]&&A[i]>A[i+1])||(A[i]<A[i-1]&&A[i]<A[i+1])){
                out++;
                i++;
            }
        }
    }
    cout << out << endl;
    return 0;
}


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

using namespace std;


int main(void){

    long long n, k;
    cin >> n >> k;
    
    map<int, long long> maps;
    
    for(int i=0; i<n; i++) {
        pair<int, int> p;
        cin >> p.first >> p.second;
        if(maps.find(p.first)==maps.end()) {
            maps.insert(p);
        }
        else {
            maps[p.first] += p.second;
        }
    }
    

    for(auto itr = maps.begin(); itr != maps.end(); itr++) {
        if((*itr).second>=k) {
            cout << (*itr).first << endl;
            break;
        }
        else {
            k -= (*itr).second;
        }
//        cout << (*itr).first << " " << (*itr).second << endl;        
    }    


    return 0;
}


Measured memory_bytes: 4224
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

typedef long long ll;

const ll mod=1e9+7;

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rc(x)  return cout<<x<<"\n",0
#define sz(s)  (int) s.size()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

ll x;

int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> x;
	ll n=100,k=0;
	while (n<x) {
		n+=n/100;
		k++;
	}
	cout << k << '\n';
}


Measured memory_bytes: 3652
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B,$C) = explode(" ",trim(fgets(STDIN)));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
//function chmax(&$a,$b) {if ($a<$b){$a=$b;return true;}return false;}
//function chmix(&$a,$b) {if ($a>$b){$a=$b;return true;}return false;}

$res = array();
for($i=0;$i<$N;$i++) {
  $S=trim(fgets(STDIN));
  if (isset($res[$S])) {
    $res[$S]+=1;
  }
  else {
    $res[$S]=1;
  }
}
$maxmatch = max($res);
$rr = array();
foreach($res as $k=>$v) {
  if ($v == $maxmatch) {
    $rr[]=$k;
  }
}
sort($rr);
foreach($rr as $v) {
  printf("%s\n",$v);
}


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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int N, M;
    cin >> N >> M;
    int ans = 1900*M + 100*(N-M);
    while (M--) {
        ans *= 2;
    }
    cout << ans << '\n';

}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] line = Console.ReadLine().Split(' ');
        int[] sticks = new int[2];
        sticks[0] = int.Parse(line[0]);
        sticks[1] = int.Parse(line[1]);

        List<int> list = new List<int>();

        string[] line2 = Console.ReadLine().Split(' ');
        for(int i=0; i<sticks[0]; i++){
            int num = int.Parse(line2[i]);
            list.Add(num);
            if(list.Count > sticks[1]){
                list.Sort();
                list.Remove(list[0]);
            }
        }

        int sum = 0;
        for(int i=0; i<list.Count; i++){
            sum += list[i];
        }

        Console.WriteLine(sum.ToString());
    }
}

Measured memory_bytes: 13268