akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;

typedef long long ll;
const ll INF = 1e15;

vector<ll> S;

inline bool can_beat(ll l, ll x, ll s)
{
  return (s < l + x);
}

ll near(ll n)
{
  ll ok = S.size()-1, ng = -1;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    (S[mid] >= n ? ok : ng) = mid;
  }
  return ok;
}

bool check(ll X, ll M)
{
  int m = 0, l = 1;
  while (m < M) {
    if (can_beat(l, X, S.back())) {
      // cerr << "m+1 = " << m+1 << endl;
      // cerr << "m =" << m << endl;
      return (m+1 >= M ? true : false);
    }

    // cerr << "A " << m << endl;
    // vector<ll>::iterator it = lower_bound(S.begin(), S.end(), l);
    // rep(i, 1e6) lower_bound(S.begin(), S.end(), l);
    int idx = near(l);
    // cerr << "B " << m << endl;

    ll diff = INF;
    if (can_beat(l, X, S[idx])) {
      diff = min(diff, abs(l - S[idx]));
    }
    if (idx-1 >= 0 && can_beat(l, X, S[idx-1])) {
      diff = min(diff, abs(l - S[idx-1]));
    }

    l += max(1LL, X - diff);

    m++;
  }
    // cerr << "m =" << m << endl;
  return true;
}

int main()
{
  int N, M;
  while (cin >> N >> M, N || M) {
    // cerr << "================" << endl;

    S.resize(N);
    rep(i, N) cin >> S[i];

    // sort(S.begin(), S.end());

    ll ok = S[0], ng = S.back();

    if (!check(ok, M)) {
      cout << -1 << endl;
    } else {
      while (abs(ok - ng) > 1) {
        // cerr << "ok, ng = " << ok << ", " << ng << endl;
        ll mid = (ok + ng) / 2;
        (check(mid, M) ? ok : ng) = mid;
      }
      cout << ok << endl;
    }
  }
}

Measured memory_bytes: 4108
from collections import deque
k=int(input())
dist=[float('inf') for _ in range(k)]
dist[1]=1
q=deque()
q.append(1)
while len(q)>0:
    r=q.popleft()
    s=(r+1)%k
    if dist[r]+1<dist[s]:
        dist[s]=dist[r]+1
        q.append(s)
    t=(r*10)%k
    if dist[r]<dist[t]:
        dist[t]=dist[r]
        q.appendleft(t)
print(dist[0])

Measured memory_bytes: 8304
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;


bool solve(string s, string t, int SorT){
    int sp, tp, p;
    bool ans = false;
    sp = tp = p = 0;

    while(sp < s.size() && tp < t.size()){
        if(SorT == 0){
            if(s[sp] == s[p]){
                p++;
                SorT = 1;
            }
            sp++;
        }else{
            if(t[tp] == s[p]){
                p++;
                SorT = 0;
            }
            tp++;
        }
        if(p == s.size()){
            ans = true;
            break;
        }
    }
    return ans;
}

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

    if(solve(s, t, 0) ||  solve(s, t, 1)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int K;
    int[] a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.K = sc.nextInt();
    }
    
    //解答処理
    private int solve() {
        int answer = a[K-1];
        
        return answer;
    }
    
    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35760
x, n = map(int, input().split())
if n == 0: print(x); exit()
C = [0]*(101+1) # candidate:[0,101]
for p in map(int, input().split()): C[p] = 1
for d in range(100):
    c = x - d
    if not C[c]: print(c); exit()
    c = x + d
    if not C[c]: print(c); exit()


Measured memory_bytes: 9196
k, n = map(int, input().split())
a = sorted(list(map(int, input().split())))
distance = []
for i in range(len(a)):
    if i == 0:
        distance.append(a[i] + (k - a[len(a) - 1]))
    else:
        distance.append(a[i] - a[i - 1])
distance.remove(max(distance))
print(sum(distance))

Measured memory_bytes: 26444
from sys import stdin
import fractions
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
kouyaku = fractions.gcd(c, d)
koubai = c * d // fractions.gcd(c, d)
b_s = b - b//c - b//d + b//koubai
a_s = a-1 - (a-1)//c - (a-1)//d + (a-1)//koubai
print(b_s - a_s)

Measured memory_bytes: 5048
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc169/tasks/abc169_f

//参考：
//https://note.com/tanon_cp/n/neda8607cfa7b#5FTIT

//新たに出てきたものを使う、使わないで分岐するのがdpの基本かも

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL unsigned long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
//const LL mod = 1000000007ll;
const int mod_int = 1000000007;

const LL mod = 998244353ll;

LL N,S;
LL A[3000];

LL ans = 0;

void solve(){
	vector<vector<LL>> dp(N+1,vector<LL>(3001,0));
	dp[0][0] += 1LL;
	//ばらまく
	for(int i=0;i<N;i++){
		for(int j=0;j<=3000;j++){
			if(dp[i][j]==0) continue; 
			//末尾に新しく出現した数をつけるかつけないかでまず*2通り
			//(末尾に出現した数を使わないような、条件を満たす数列を含む数列の数)
			dp[i+1][j] = (dp[i+1][j] + 2*dp[i][j])%mod; 
			if(j+A[i]<=3000){
				//末尾に出現した数を使って和がj+A[i]になるようなものを作る
				//(末尾に出現した数を絶対に使うような、条件を満たす数列を含む数列の数)
				dp[i+1][j+A[i]] = (dp[i+1][j+A[i]] + dp[i][j])%mod;
			}
		}
	}
	// for(int i=0;i<=N;i++){
	// 	cout << "i=" << i << ":";
	// 	for(int j=0;j<=S;j++) cout << dp[i][j] << " ";
	// 	cout << endl;
	// }
	ans = dp[N][S];
}

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

    solve();

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

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> graph(N, vector<int>(0));
  for (int i=0; i<M; i++) {
    int a, b;
    cin >> a >> b;
    graph.at(a-1).emplace_back(b-1);
    graph.at(b-1).emplace_back(a-1);
  }
  vector<int> path(N-1);
  int count = 0;
  for (int i=1; i<N; i++) path.at(i-1) = i;
  do {
    for (int i=0; i<N-1; i++) {
      bool flag = false;
      if (i == 0) {
        for (auto link : graph.at(0)) {
          if (link == path.at(i)) {
            flag = true;
            break;
          }
        }
      }
      else {
        for (auto link : graph.at(path.at(i-1))) {
          if (link == path.at(i)) {
            flag = true;
            break;
          }
        }
      }
      if (!flag) break;
      if (i == N-2) count++;
    }
  } while (next_permutation(path.begin(), path.end()));
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
//BIAR MANTAB LAH YA
#define Willy using
#define Indrayana namespace
#define Komara std
 
using namespace std;

int main()
{
    int n;
    cin >> n;
    map<string, int> vote;
    vector<string> kode;
    for (int i = 0; i < n; i++)
    {
        string input;
        cin >> input;
        vote[input]++;
        if (vote[input] == 1) kode.push_back(input);
    }
    int maks = -1;
    vector<string> maks_str;
    for (int i = 0; i < kode.size(); i++)
    {
        if (maks < vote[kode[i]])
        {
            maks_str.clear();
            maks_str.push_back(kode[i]);
        }
        else if (maks == vote[kode[i]])
        {
            maks_str.push_back(kode[i]);
        }
        maks = max(maks, vote[kode[i]]);
    }
    //cout << "Jawaban: " << maks_str.size() << endl;
    if (maks_str.size() == 1) cout << maks_str[0] << '\n';
    else
    {
        sort(maks_str.begin(), maks_str.end());
        for (int i = 0; i < maks_str.size(); i++)
        {
            cout << maks_str[i] << '\n';
        }
    }



}

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

using namespace std;
typedef pair<int,int> pii;
const int N = 1010;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int _w;

int n, m;
char str[N][N];
int dis[N][N];
queue<pii> q;

bool inside( int x, int y ) {
	return x >= 1 && x <= n && y >= 1 && y <= m;
}

int main() {
	_w = scanf( "%d%d", &n, &m );
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%s", str[i]+1 );
	memset(dis, -1, sizeof dis);
	for( int i = 1; i <= n; ++i )
		for( int j = 1; j <= m; ++j )
			if( str[i][j] == '#' )
				dis[i][j] = 0, q.push( pii(i, j) );
	int ans = 0;
	while( !q.empty() ) {
		pii now = q.front(); q.pop();
		ans = max(ans, dis[now.first][now.second]);
		for( int i = 0; i < 4; ++i ) {
			int nx = now.first + dx[i];
			int ny = now.second + dy[i];
			if( inside(nx, ny) && dis[nx][ny] == -1 ) {
				dis[nx][ny] = dis[now.first][now.second] + 1;
				q.push( pii(nx, ny) );
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 16348
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int array[200005];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>array[i];
  }
  
  sort(array,array+n);
  bool distinct=true;
  for(int i=0;i<n-1;i++){
    if(array[i]==array[i+1]){
      distinct=false;
    }
  }
  if(distinct){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return(0);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;bool mmp(int a,int b){return a>b;}int main(){int n,k,ass=0;int a[51];cin>>n>>k;for(int i=1;i<=n;i++)cin>>a[i];sort(a+1,a+n+1,mmp);for(int i=1;i<=k;i++)ass+=a[i];cout<<ass<<endl;return 0;}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

unsigned long  gcd(unsigned long x, unsigned long y)
{
        if (y == 0) {
                return x;
        } else {
                return gcd(y, x % y);
        }
}




char check[60][60];

int main(void){
    int n;
    unsigned long long t[100];
    unsigned long long lcm;
    int i;
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%lld", &t[i]);
    }
    if (n == 1){
        printf("%lld\n", t[0]);
        return 0;
    }
    lcm = t[0];

    for (i = 1; i < n; i++){
        if (lcm >= t[i]){
            lcm = lcm*(t[i]/gcd(lcm, t[i]));
        }else if (lcm <= t[i]){
            lcm = lcm*(t[i]/gcd(t[i], lcm));
        }
    }

    printf("%lld\n", lcm);



}


Measured memory_bytes: 128
X,N = map(int,input().split())
p = list(map(int,input().split()))
i = X + 1
j = X - 1
if X not in p:
    print(X)
    exit()
    
while True:
    if j not in p:
        print(j)
        break
    elif j in p and i not in p:
        print(i)
        break
    i += 1
    j -= 1


Measured memory_bytes: 9188
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;

#define MAX 256
#define S(x) (x*x)

int f(int z){
	if (z < 10)return 1;
	return 1 + f(z / 10);
}

int main(void){
	
	int ans[MAX];
	for (int i = 0; i < MAX; i++){
		ans[i] = 0;
	}

	int d;
	int i = 0;

	while (scanf("%d", &d) != EOF){
		for (int j = d; j <= 600 - d; j += d){
			ans[i] += S(j)*d;
		}
		i++;
	}

	for (int j = 0; j < i; j++){
		printf("%d\n", ans[j]);
	}

	return 0;
}

Measured memory_bytes: 3028
import math
n = int(input())
mindigit = len(str(n))
for i in range(int(math.sqrt(n))):
    q, mod = divmod(n, i+1)
    if mod == 0:
        tmp = max(len(str(i+1)), len(str(q)))
        if mindigit > tmp:
            mindigit = tmp
print(mindigit)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include<algorithm>
#include <math.h>
#include <string.h>
#define eps 1e-9
typedef long long int ll;
using namespace std;
string a;
string b;
string c;
int main()
{
    int n,m;
    cin>>a;
    cin>>b;
    cin>>n>>m;
    cin>>c;
    if(c==a)
    {
        n--;
    }
    if(c==b)
    {
        m--;
    }
    cout<<n<<" "<<m;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int n,i;

scanf("%d",&n);

int a[n];

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

for(i=0;i<n;i++){
if(a[i]%2==0){
if(a[i]%3!=0&&a[i]%5!=0){break;}
}
}

if(i==n){printf("APPROVED");}
else if(i!=n){printf("DENIED");}

return 0;
}

Measured memory_bytes: 2152
#include <stdio.h>

int main(void) {

	int i = 0;
	int x = 0;
	int y = 0;

	do{
		scanf("%d",&x);
		scanf("%d",&y);
		
		if( x > y){
			i = x ;
			x = y ;
			y = i ;
		}
		
		if(x || y){
			printf("%d %d\n", x, y);
		}
		
	}while(x || y);


	return 0;
}

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

typedef struct{
    int a;
    char s[15];
    int p;
}Restaurant_t;

int strsort(const void *A, const void *B){
    long long P=strcmp(((Restaurant_t*)A)->s,((Restaurant_t*)B)->s);
    long long Q=((Restaurant_t*)B)->p-((Restaurant_t*)A)->p;
    if (P!=0){
        return P;
    } else if (Q!=0){
        return Q;
    } else {
        return 0;
    }
}

int main(void){
    int n;
    scanf("%d",&n);
    Restaurant_t Restaurant[n];
    for (int i=0; i<n; i++){
        scanf("%s %d",Restaurant[i].s,&Restaurant[i].p);
        Restaurant[i].a=i+1;
    }
    qsort (Restaurant,n,sizeof(Restaurant_t),strsort);
    for (int i=0; i<n; i++){
        printf("%d\n",Restaurant[i].a);
    }
    
    return 0;   
}

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


def main():
    A, B, C, D = map(int, input().split())
    while A > 0:
        C = C - B
        if C <= 0:
            print("Yes")
            exit()
        A = A - D
    print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9104
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>

using namespace std;

int search(int i, char c);

char str[200];
int l;

int main()
{
	while(1){
		fgets(str, sizeof(str), stdin);
		if(str[0] == '.') break;
		int ans = 1;
		l = strlen(str);
		for(int i = 0; i < l; i++){
			if(str[i] == '(' || str[i] == '['){
				ans = search(i, str[i]);
				if(ans == 0) break;
			} else if(str[i] == ')' || str[i] == ']'){
				ans = 0;
				break;
			}
		}
		if(ans == 1) cout << "yes" << endl;
		else if(ans == 0) cout << "no"<< endl;
	}
	return 0;
}

int search(int i, char c)
{
	if(i == l-2) return 0;
	char d, e;
	if(c == '('){
		d = ')';
		e = ']';
		}else if(c == '['){
			d = ']';
			e = ')';
		}
		str[i] = '0';
	for(int j = i+1; j < l; j++){
		if(str[j] == '(' || str[j] == '['){
			if(search(j, str[j]) == 0) return 0;
			else continue;
		} else if(str[j] == d){
			str[j] = '0';
			return 1;
		} else if(str[j] == e){
			str[j] = '0';
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1120
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int r;
	cin >> r;
	cout << 3 * r * r << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

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

const int MOD = 1000000007;
#define p(var)  std::cout<<var<<std::endl
#define pp(var) std::cout<<#var" = "<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for (int i = 0; i <  (n); i++)
#define repeq(i, n) for (int i = 1; i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
inline double isint(double a) { return a>=0 && ceil(a)==floor(a); }

/*-----8<-----8<-----*/


int main(){
    int A,B,C;
    cin >> A >> B >> C;


    if(A<C && C<B){
        p("Yes");
        return 0;
    }
    if(B<C && C<A){
        p("Yes");
        return 0;
    }


    cout <<"No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = 500;
int res[N][N];

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

	int n;
	cin >> n;

	for (int b = 0; (1<<b) <= n; ++b) {
		for (int i = 0; i < n; ++i) {
			for (int j = i+1; j < n; ++j) {
				if ((i ^ j) & (1<<b)) {
					if (res[i][j] == 0) res[i][j] = b+1;
				}
			}
		}
	}
	for (int i = 0; i+1 < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			cout << res[i][j] << ' ';
		}
		cout << '\n';
	}
	
}


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

int main()
{
	int n,l;
	cin>>n>>l;
	
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	
	int ind=-1;
	for(int i=0;i<n-1;i++)
	{
		if(arr[i]+arr[i+1]>=l)
		{
			ind =i;
			break;
		}
	}
	
	if(ind==-1)
	{
		cout<<"Impossible"<<endl;
	}
	else
	{
		cout<<"Possible"<<endl;
		
		for(int i=1;i<=ind;i++)
		{
			cout<<i<<endl;
		}
		
		for(int i=n-1;i>=ind+2;i--)
		{
			cout<<i<<endl;
		}
		cout<<ind+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 4000
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        
        int[] love = new int[m];
        int k, a;
        for(int i = 0; i < n; i++){
            k = Integer.parseInt(sc.next());
            for(int j = 0; j < k; j++){
                a = Integer.parseInt(sc.next());
                love[a-1]++;
            }
        }
        
        int count = 0;
        for(int i = 0; i < m; i++){
            if(love[i] == n){
                count++;
            }
        }
        
        System.out.println(count);
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n,m;cin>>n>>m;
	int x[m];
	rep(i,m) cin>>x[i];

	sort(x,x+m);
	int l[m-1];
	rep(i,m-1) l[i]=x[i+1]-x[i];//lは間の距離

	sort(l,l+m-1);
	ll sum=0,mn=m-n;
	if(mn<0) mn=0;
	rep(i,mn) sum+=l[i];//n個埋めて残りm-n個を移動して埋める

	cout<<sum<<endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }

template<unsigned MOD>
class Modint {
    public:
        using uint = unsigned;
        using u64 = uint64_t;
        using i64 = int64_t;

        Modint (const i64 dat = 0) : dat(dat >= 0 ? dat % MOD : (MOD - (-dat) % MOD) % MOD) {}

        constexpr Modint operator + (const Modint &v) const { return ( Modint(dat + v.dat) ); }
        constexpr Modint operator - () const { return ( Modint(-((i64)dat)) ); }
        constexpr Modint operator - (const Modint &v) const { return ( (*this) + -v ); }
        constexpr Modint operator * (const Modint &v) const { return ( Modint((u64)dat * v.dat) ); }

        constexpr Modint operator ~ () const {
            i64 a = dat, b = MOD, x1 = 1, x2 = 0, t;

            while ( b > 0 ) {
                t = a / b;
                swap(a -= t * b, b);
                swap(x1 -= t * x2, x2);
            }

            return ( Modint(x1) );
        }

        constexpr Modint operator / (const Modint &v) const { return ( (*this) * ~v ); }

        Modint &operator = (const i64 &v) { return ( (*this) = Modint < MOD > (v) ); }
        Modint &operator += (const Modint &v) { return ( (*this) = (*this) + v ); }
        Modint &operator -= (const Modint &v) { return ( (*this) = (*this) - v ); }
        Modint &operator *= (const Modint &v) { return ( (*this) = (*this) * v ); }
        Modint &operator /= (const Modint &v) { return ( (*this) = (*this) / v ); }

        constexpr Modint operator ^ (u64 n) const {
            Modint < MOD > ret(1), mul(dat);
            while ( n > 0 ) {
                if ( n & 1 ) ret *= mul;
                mul *= mul;
                n >>= 1;
            }
            return ( ret );
        }

        bool operator == (const Modint &v) { return ( dat == v.dat ); }
        bool operator != (const Modint &v) { return ( dat != v.dat ); }

        friend ostream& operator << (ostream &os, const Modint &p ) {
            return ( os << p.dat );
        }

        friend istream& operator >> (istream &is, Modint &p ) {
            i64 data;
            is >> data;
            p = Modint < MOD >(data);
            return ( is );
        }

    private:
        uint dat;
};

Modint<mod> dp[5005][5005];

int main() {
    int N;
    string S;
    cin >> N >> S;
    dp[0][0] = 1;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= N; j++) {
            dp[i + 1][j + 1] += dp[i][j] * Modint<mod>(2);
            dp[i + 1][max(0, j - 1)] += dp[i][j];
        }
    }

    cout << dp[N][S.size()] / (Modint<mod>(2)^(((uint64_t)S.size()))) << el;
    
    return (0);
}

Measured memory_bytes: 98048
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S, T;
	cin >> S >> T;
	S += S;

	for (int i = 0; i != S.size(); i++)
	{
		for (int j = 0; j != T.size(); j++)
		{
			if (S[i + j] != T[j])
			{
				break;
			}
			if (j == T.size() - 1)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

std::vector<int> prime;
void MakePrime(int n) {
	prime.emplace_back(2);
	for (int i = 3; i < n; i += 2) {
		bool a = false;
		for (int j = 3; j <= std::sqrt(i); j += 2) {
			if (i%j == 0) {
				a = true;
			}
		}
		if (a == false) {
			prime.emplace_back(i);
		}
	}
}

LL calc_opponent(LL x){
    LL ret = 1;
    for(auto p : prime){
        LL cnt = 0;
        while(x % p == 0) ++cnt, x /= p;
        if(cnt == 0)continue;
        else if(cnt == 1)ret *= p * p;
        else ret *= p;
    }
    LL l = 1, r = 1000000LL;
    while(r - l > 1){
        LL mid = (l + r)/2;
        if(mid * mid > x)r = mid;
        else l = mid;
    }
    if(l * l == x){
        ret *= l;
    }else{
        if(x > 1000000LL)return -1;
        ret *= x * x;
        if(ret > 10000000000LL)return -1;
    }
    return ret;
}

int n;
LL a[101010];

int main(){
    cin >> n;
    REP(i, n)cin >> a[i];
    int ans = 0;
    MakePrime(2155);
    map<LL, int>mp;
    REP(i, n){
        LL num = 1;
        for(auto p : prime){
            int cnt = 0;
            while(a[i] % p == 0)++cnt, a[i] /= p;
            cnt %= 3;
            REP(j, cnt)num *= p;
        }
        num *= a[i];
        if(num == 1)ans = 1;
        else mp[num]++;
    }
    for(auto it = mp.begin(); it != mp.end();++it){
        LL val = it->first;
        LL opponent = calc_opponent(val);
        int num = max(it->second, mp[opponent]);
        it->second = mp[opponent] = 0;
        ans += num;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11392
#include<bits/stdc++.h>
using namespace std;
int n,ans=0,a[10005];
int main(void){
	cin>>n;
	for(int i=1;i<=n*2;++i){
		cin>>a[i];
	}
	sort(a+1,a+2*n+1);
	for(int i=1;i<=n*2;i+=2){
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if(e - a <= k)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, m, p; cin >> n >> m >> p;
    vector<pair<int, int> > adj[n];
    while (m--) {
        int a, b, c; cin >> a >> b >> c;
        adj[a-1].push_back({b-1, p-c});
    }
    int save;
    long long dist[n];
    long long INF = 1LL<<50;
    fill(dist, dist+n, INF);
    dist[0] = 0;
    for (int t = 0; t < n; t++) {
        for (int i = 0; i < n; i++)
            for (auto &e : adj[i]) {
                int j = e.first, w = e.second;
                if (dist[i] < INF && dist[j] > dist[i] + w) {
                    dist[j] = dist[i] + w;
                }
            }
    }
    for (int t = 0; t < n; t++) {
        for (int i = 0; i < n; i++)
            for (auto &e : adj[i]) {
                int j = e.first, w = e.second;
                if (dist[i] < INF && dist[j] > dist[i] + w) {
                    dist[j] = -INF;
                }
            }
    }
    if (dist[n-1] > -INF) {
        cout << max(-dist[n-1], 0LL) << endl;
    } else {
        cout << -1 << endl;
    }
}


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

int main(){
    int n; cin >> n; //店の個数
    vector<pair<pair<string , int>,int>> list(n); //店の場所と評価点

    for(int i=0; i<n; i++){
        string name; //市名
        int score; //評価点
        cin >> name >> score;

        list[i] = make_pair(make_pair(name,-score),i+1);
    }

    sort(list.begin(),list.end());

    for(int i=0; i<n; i++){
        cout << list[i].second << endl;
    }
}

Measured memory_bytes: 256
# python 3.8.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
import numpy as np
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def lcm(a,b):return (a*b) // gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

import numpy as np
import decimal

a,b = input().split()
a = decimal.Decimal(a)
b = decimal.Decimal(b)

print(math.floor(a*b))

Measured memory_bytes: 27396
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

ll f(ll x){
    if(x == 1) return 1;
    return f(x / 2)* 2 + 1;
}

int main(){
    ll H;
    cin >> H;
    cout << f(H) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >>a>>b>>c;
    int maxn =a;
    if(b>maxn)maxn=b;
    if(c>maxn)maxn=c;
    printa(a+b+c-maxn);
    return 0;
}

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

int main(){
    int n; cin >> n;
    map<int,int> mp;
    bool ok = true;
    rep(i,n) {
        ll a; cin >> a;
        if(mp[a] > 0) ok = false;
        mp[a]++;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 0x3f3f3f3f

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll>A(n+1),B(m+1);
    for(int i=1; i<=n; i++)
        cin>>A[i],A[i]+=A[i-1];
    for(int i=1; i<=m; i++)
        cin>>B[i],B[i]+=B[i-1];

    ll res = 0;
    for(int i=0; i<=n; i++)
        if(A[i] <= k)
        {
            auto it = upper_bound(B.begin(),B.end(),k-A[i]);
            it--;
            ll books = it - B.begin();
            res=max(res, i + books);
        }
    cout<<res;
}


Measured memory_bytes: 6364
<?php
$sum = [0 => PHP_INT_MAX];
$ans = 0;
$mmax = 0;
fscanf(STDIN, "%d %d", $N, $M);
$arr = array_fill(1, $M, []);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d", $A, $B);
    $arr[$A][] = $B;
}

for ($i = 1; $i <= $M; $i++) {
    foreach ($arr[$i] as $v) {
        if (!isset($sum[$v])) {
            $sum[$v] = 1;
        } else {
            ++$sum[$v];
        }
        $mmax = $mmax > $v ? $mmax : $v;
    }

    $ans += $mmax;
    if ($sum[$mmax] === 1) {
        unset($sum[$mmax]);
        $mmax = max(array_keys($sum));
    } else {
        --$sum[$mmax];
    }
}
echo $ans;

Measured memory_bytes: 47608
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,m=mii()

def dfs(mat,v):
    seen[v]+=1
    for pv in mat[v]:
        if seen[pv]:
            continue
        dfs(mat,pv)

ans=0
arr=[]
for i in range(m):
    x,y=mii()
    arr.append([x-1,y-1])

for i in range(m):
    seen=[0]*n
    mat=[[] for _ in range(n)]
    for j,k in enumerate(arr):
        if i!=j:
            a,b=k
            mat[a].append(b)
            mat[b].append(a)
    dfs(mat,1)
    if sum(seen)!=n:
        ans+=1

print(ans)

Measured memory_bytes: 67288
#define _[2<<17]
n,i;A _,B _,T _,F _;long M,D _,P _,R _;s(u,i,p,I){i?s(u,T[i],p),R[i]=(I=B[i])-p?s(I,F[I],u),D[u]=D[u]*-~D[I]%M:D[u]:++D[u];return 0;}S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,F[1]);for(S(1,1,0);i++<n;)printf("%d ",P[i]);}

Measured memory_bytes: 15360
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int arr[] = {1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1000};
            int x = Integer.parseInt(br.readLine());
            for (int i = arr.length -1 ; i >= 0; i--) {
                if (x >= arr[i]) {
                    System.out.println(arr[i]);
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


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

int main(void)
{
    int N,A,B;
    cin >> N >> A >>B;

    if((B-A)%2 == 0) cout << "Alice" << endl;
    else cout << "Borys" << endl;

    return 0;
}

Measured memory_bytes: 3556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			long[] a = in.nextLongArray(n);
			long[] b = in.nextLongArray(n);

			long ans = 0;
			for (int k = 30; k >= 0; k--) {
				long count = 0;
				long t = 1 << (k + 1);
				for (int i = 0; i < n; i++) {
					a[i] %= t;
					b[i] %= t;
				}

				Arrays.sort(b);

				for (int j = 0; j < n; j++) {
					long T = 1 << k;
					count += lowerBound(b, 2*T - a[j]) - lowerBound(b, 1*T - a[j]);
					count += lowerBound(b, 4*T - a[j]) - lowerBound(b, 3*T - a[j]);
				}

				if (count % 2 == 1) {
					ans |= 1 << k;
				}

			}
			out.println(ans);

		}
	}
	public static int lowerBound(long[] a, long obj) {
		int l = 0, r = a.length - 1;
		while (r - l >= 0) {
			int c = (l + r) / 2;
			if (obj <= a[c]) {
				r = c - 1;
			} else {
				l = c + 1;
			}
		}
		return l;
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

	static void print(int[][] dp) {
		int n = dp.length;
		int m = dp[0].length;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				System.out.print(dp[i][j] + " ");
			}
			System.out.print("\n");
		}
		System.out.print("\n");
	}
}


Measured memory_bytes: 73260
#include<stdio.h>
#define MAX 2000000

int size, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest, t;
  l = 2*i;
  r = 2*i+1;
  if ( l <= size && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= size && A[r] > A[largest] ) largest = r;
  if ( largest != i ){
    t = A[i]; A[i] = A[largest]; A[largest] = t;
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if ( size < 1 ) return;
  maxv = A[1];
  A[1] = A[size--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  int tmp;
  if ( key < A[i] ) return;
  A[i] = key;
  while ( i > 1 && A[i/2] < A[i] ){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
  }
}

void insert(int key){
  size++;
  A[size] = -1000000001;
  increaseKey(size, key);
}


main(){
  int key;
  char com[20];
  while(1){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &key);
      insert(key);
    } else if ( strcmp(com, "extract") == 0  ){
      printf("%d\n", extract());
    } else break;
  }
  
  return 0;
}

Measured memory_bytes: 4696
while True:                                                                                      
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    countl = 0
 
    while True:
        if W == 0:
            break
        if countl == H:
            break
        elif countl % 2 == 0:
            countll = 0
            while True:
                if countll % 2 == 0:
                    print('#', end='')
                    countll += 1
                else:
                    print('.', end='')
                    countll += 1
                if countll == W:
                    print()
                    break
        elif countl % 2 == 1:
            countll = 0
            while True:
                if countll % 2 == 0:
                    print('.', end='')
                    countll += 1
                else:
                    print('#', end='')
                    countll += 1
                if countll == W:
                    print()
                    break
        countl += 1
    print()

Measured memory_bytes: 9064
#include<iostream>
#include<cstdio>
using namespace std;
int n,f[101],p[101],k;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&f[i]);
		k=max(k,f[i]);
		p[f[i]]++;
	}
	if(k%2){
		for(int i=1;i<=k/2;i++){
			if(p[i]){
				printf("Impossible\n");
				return 0;
			}
		}
		if(p[k/2+1]!=2){
			printf("Impossible\n");
			return 0;
		}
		for(int i=k/2+2;i<=k;i++){
			if(p[i]<2){
				printf("Impossible\n");
				return 0;
			}
		}
	}else{
		for(int i=1;i<k/2;i++){
			if(p[i]){
				printf("Impossible\n");
				return 0;
			}
		}
		if(p[k/2]!=1){
			printf("Impossible\n");
			return 0;
		}
		for(int i=k/2+1;i<=k;i++){
			if(p[i]<2){
				printf("Impossible\n");
				return 0;
			}
		}
	}
	printf("Possible\n");
}

Measured memory_bytes: 3748
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0

for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i + 100*j + 50*k == X:
        cnt += 1
print(cnt)



Measured memory_bytes: 3060
from collections import Counter
n = int(input())
S = [input() for _ in range(n)]

count = Counter(S[0])
for s in S[1:]:
  c = Counter(s)
  count = count & c
  
ls = sorted(count.items())

ans = ""
for i, j in ls:
  ans += i * j
  
print(ans)

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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	FOR(i,0,n){
		int ai;
		cin >> ai;
		a[i] = ai - i - 1;
	}
	sort(ALL(a));
	int b = a[n/2];
	ll ans = 0;
	FOR(i,0,n){
		ans += abs(a[i] - b);
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<bits/stdc++.h>
#define fori(j,n) for(long long  i=j;i<n;i++)
#define pb push_back
#define ss string
#define ll long long
#define li  long
#include<string.h>
#define pf printf
#define sf scanf
bool isvowel(char s){ if(s=='a'||s=='A'||s=='e'||s=='E'||s=='i'||s=='I'||s=='o'||s=='O'||s=='u'||s=='U') return true;  else  return false;}
 ll fact(ll  n){ll mul=1;for(ll i=1;i<=n;i++)mul=mul*i;return mul;}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
using namespace std;
bool sortas(const pair<ll,ll> &a,const pair<ll,ll> &b){return a.second<b.second;}
ll fast(ll a,ll n)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    ll r=fast(a,n/2);
    if(n&1)
        return a*r*r;
    else return r*r;
}
int main()
{

    ll a,b;
    cin>>a>>b;
    double d=(a+b)/2.0;
    ll ans=d;
    if(ans==d)
        cout<<ans<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


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

int main() {
  long long a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  long long l=abs(a-b);
  long long x=v-w;
  if(x*t>=l) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define MAXN 50
vector<pair<int,int> > res;
int arr[MAXN+5],xam,xin,cm,cp,n;
int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &arr[i]);
        if(xam < arr[i]){
            xam = arr[i];
            cp = i;
        }
        if(xin > arr[i]){
            xin = arr[i];
            cm = i;
        }
    }
    if(xam < abs(xin)){
        for(int i = 0; i < n; i++){
            if(arr[i] > 0){
                arr[i] += xin;
                res.push_back(make_pair(cm,i));
            }
        }
        for(int i = n-1; i > 0; i--){
            if(arr[i-1] > arr[i]){
                arr[i-1] += arr[i];
                res.push_back(make_pair(i,i-1));
            }
        }
    } else {
        for(int i = 0; i < n; i++){
            if(arr[i] < 0){
                arr[i] += xam;
                res.push_back(make_pair(cp,i));
            }
        }
        for(int i = 0; i < n-1; i++){
            if(arr[i] > arr[i+1]){
                arr[i+1] += arr[i];
                res.push_back(make_pair(i,i+1));
            }
        }
    }
    printf("%d\n", res.size());
    for(int i = 0; i < res.size(); i++){
        printf("%d %d\n", res[i].first+1, res[i].second+1);
    }
}


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

using namespace std;

int main()
{
	int n;
	while(cin>>n,n){
		map<int,long long> mp;
		bool flag=false;
		while(n--){
			int id,unit,num;
			cin>>id>>unit>>num;
			if(mp[id]<1000000 && 1000000<=mp[id]+(long long)unit*num){
				cout<<id<<endl;
				flag=true;
			}
			mp[id]+=(long long)unit*num;
		}
		if(!flag)	cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0