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

#define M 100005
#define MOD 100000000
#define PI 3.14159265358979323846
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> PII;
typedef pair<lli,lli> PLL;

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

	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);

	string s;
	cin>>s;

	int n = (int)s.size();

	string res = "";
	for(int i=0;i<n;i++)
	{
		if(s[i]=='?')
		{
			if(i==0)
				res += "D";
			else
			{
				if(s[i-1]=='P')
					res += "D";
				else if(s[i+1]=='D')
					res += "P";
				else
					res += "D";
			}
		}
		else
			res += s[i];
	}

	cout<<res<<"\n";
}


Measured memory_bytes: 3820
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000002
#define MAX2 10000

int main(){
  unsigned short *A, *B;

  int arr[MAX2+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for ( i = 0; i <= MAX2; i++ ) arr[i] = 0;

  for ( i = 0; i < n; i++ ){
    scanf("%hu", &A[i + 1]);
    arr[A[i + 1]]++;
  }

  for ( i = 1; i <= MAX2; i++ ) arr[i] = arr[i] + arr[i - 1];

  for ( j = 1; j <= n; j++ ){
    B[arr[A[j]]] = A[j];
    arr[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 8460
import collections

n,m = map(int,raw_input().split())

arr = map(int,raw_input().split())

sums = []
sums.append(arr[0]%m)

for i in range(1,n):
	sums.append((sums[i-1] + arr[i])%m)



c = collections.Counter(sums)
ans = 0
ans += sums.count(0)
for i in c.values():
	ans += i*(i-1)/2

print ans

Measured memory_bytes: 16540
import java.io.*;
import java.util.*;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;


class Main {
	public static void main(String[] a) throws IOException {
		Scanner scan = new Scanner(System.in);
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String brf;
		int num[] = new int [101];
		int max = 0;
	
		while((brf = br.readLine())!=null){
			num[Integer.parseInt(brf)]++;
		}
		for(int i = 1;i < 101;i++){
			if(num[i] > max){
				max = num[i];
			}
		}
		for(int i = 1; i < 101; i++){
			if(num[i] == max){
				System.out.println(i);
			}
		}
	}	
}

Measured memory_bytes: 26212
#include<stdio.h>
#include<string.h>
char change(int a)
{
	char b;
	if(a==0)b='0';
	if(a==1)b='1';
	if(a==2)b='2';
	if(a==3)b='3';
	if(a==4)b='4';
	if(a==5)b='5';
	if(a==6)b='6';
	if(a==7)b='7';
	if(a==8)b='8';
	if(a==9)b='9';
	return (b);
}
struct SAO
{
	char lei[55];
	int flag[55];
}sao[55];
int main()
{
	int h,w;
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++)
	{
		memset(sao[i].flag,0,sizeof(sao[i].flag));
		scanf("%s",sao[i].lei);
		for(int j=0;j<w;j++)
		{
			if(sao[i].lei[j]=='.')
			{
				sao[i].flag[j]=2;
			}
			else if(sao[i].lei[j]=='#')
			{
				sao[i].flag[j]=1;
			}
		}	
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			int temp=0;
			if(sao[i].flag[j]==2/*&&j!=w-1&&i!=h-1&&i!=0&&j!=0*/)
			{
				if(sao[i-1].flag[j-1]==1)temp++;
				if(sao[i-1].flag[j]==1)temp++;
				if(sao[i-1].flag[j+1]==1)temp++;
				if(sao[i].flag[j-1]==1)temp++;
				if(sao[i].flag[j+1]==1)temp++;
				if(sao[i+1].flag[j-1]==1)temp++;
				if(sao[i+1].flag[j]==1)temp++;
				if(sao[i+1].flag[j+1]==1)temp++;
				sao[i].lei[j]=change(temp);
			}
		/*	else if(sao[i].flag[j]==2&&j==w-1&&i!=h-1&&i!=0)
			{
				if(sao[i-1].flag[j-1]==1)temp++;
				if(sao[i-1].flag[j]==1)temp++;
				if(sao[i].flag[j-1]==1)temp++;
				if(sao[i+1].flag[j-1]==1)temp++;
				if(sao[i+1].flag[j]==1)temp++;
				sao[i].lei[j]=change(temp);
			}
			else if(sao[i].flag[j]==2&&j!=w-1&&i==h-1&&j!=0)
			{
				if(sao[i-1].flag[j-1]==1)temp++;
				if(sao[i-1].flag[j]==1)temp++;
				if(sao[i-1].flag[j+1]==1)temp++;
				if(sao[i].flag[j-1]==1)temp++;
				if(sao[i].flag[j+1]==1)temp++;
				sao[i].lei[j]=change(temp);
			}
			else if(sao[i].flag[j]==2&&j==w-1&&i==h-1)
			{
				if(sao[i-1].flag[j-1]==1)temp++;
				if(sao[i-1].flag[j]==1)temp++;
				if(sao[i].flag[j-1]==1)temp++;
				sao[i].lei[j]=change(temp);
			}
			else if(sao[i].flag[j]==2&&j==w-1&&i==0)
			{
				if(sao[i].flag[j-1]==1)temp++;
				if(sao[i+1].flag[j-1]==1)temp++;
				if(sao[i+1].flag[j]==1)temp++;
				sao[i].lei[j]=change(temp);
			}
			else if(sao[i].flag[j]==2&&j!=w-1&&i==0&&j!=0)
			{
				if(sao[i].flag[j-1]==1)temp++;
				if(sao[i].flag[j+1]==1)temp++;
				if(sao[i+1].flag[j-1]==1)temp++;
				if(sao[i+1].flag[j]==1)temp++;
				if(sao[i+1].flag[j+1]==1)temp++;
				sao[i].lei[j]=change(temp);
			}
			else if(sao[i].flag[j]==2&&i!=0&&i!=h-1&&j==0)
			{
				if(sao[i-1].flag[j]==1)temp++;
				if(sao[i-1].flag[j+1]==1)temp++;
				if(sao[i].flag[j+1]==1)temp++;
				if(sao[i+1].flag[j]==1)temp++;
				if(sao[i+1].flag[j+1]==1)temp++;
				sao[i].lei[j]=change(temp);
			}
			else if(sao[i].flag[j]==2&&i==0&&j==0)
			{
				if(sao[i].flag[j+1]==1)temp++;
				if(sao[i+1].flag[j]==1)temp++;
				if(sao[i+1].flag[j+1]==1)temp++;
				sao[i].lei[j]=change(temp);
			}
			else if(sao[i].flag[j]==2&&i==h-1&&j==0)
			{
				if(sao[i-1].flag[j]==1)temp++;
				if(sao[i-1].flag[j+1]==1)temp++;
				if(sao[i].flag[j+1]==1)temp++;
				sao[i].lei[j]=change(temp);
			}*/
		}
	}
	for(int i=0;i<h;i++)
	{
		printf("%s\n",sao[i].lei);
	}
	return 0;
 } 

Measured memory_bytes: 128
//katakuri
#include <bits/stdc++.h>
#define taka ""
#define nmax 100005
#define S second
#define F first
#define reset(x) memset(x,0,sizeof(x))
#define oo 1000000009
#define PB push_back

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
int n;

struct ed{ int u, v, w; };
ed e[2 * nmax], A[nmax];

struct cmp1 {
    bool operator ()(ed a, ed b) {
        return a.u < b.u;
    }
};

struct cmp2 {
    bool operator ()(ed a, ed b) {
        return a.v < b.v;
    }
};

struct cmp3 {
    bool operator ()(ed a, ed b) {
        return a.w < b.w;
    }
};

struct DSU {
    vector<int> par;
    int n;
    DSU (int n) : n(n) {
        par = vector<int>(n + 1, -1);
    }
    bool Find(int u, int v) {
        return root(u) == root(v);
    }
    int root(int u) {
        if(par[u] < 0)
            return u;
        return par[u] = root(par[u]);
    }
    void Union(int u, int v) {
        int i = root(u);
        int j = root(v);
        if(i == j)
            return;
        if(par[i] > par[j])
            swap(i, j);
        par[i] += par[j];
        par[j] = i;
    }
};

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen(taka".inp","r",stdin);
    //freopen(taka".out","w",stdout);
    cin >> n;
    for(int u, v, i = 1; i <= n; i++) {
        cin >> u >> v;
        A[i] = {u, v, i};
    }
    sort(A + 1, A + n + 1, cmp1());
    int cnt = 0;
    for(int i = 1; i < n; i++)
        e[++cnt] = {A[i].w, A[i + 1].w, min(abs(A[i].u - A[i + 1].u), abs(A[i].v - A[i + 1].v))};
    sort(A + 1, A + n + 1, cmp2());
    for(int i = 1; i < n; i++)
        e[++cnt] = {A[i].w, A[i + 1].w, min(abs(A[i].u - A[i + 1].u), abs(A[i].v - A[i + 1].v))};
    sort(e + 1, e + cnt + 1, cmp3());
    DSU d(cnt);
    int res = 0;
    for(int i = 1; i <= cnt; i++) {
        if(!d.Find(e[i].u, e[i].v)) {
            d.Union(e[i].u, e[i].v);
            //cout << e[i].u << ' ' << e[i].v << '\n';
            res += e[i].w;
            //cout << e[i].w << ' ';
        }
    }
    cout << res;
}


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

#define N 10
#define INF (1 << 30)

using std::cin;
using std::cout;
using std::endl;

using std::vector;
using std::min;

void dump(const vector<int>& v){
    for(int i : v){
        cout << i << " ";
    }
    cout << endl;
}

int dijkstra(const int c[N][N], int s, int t){
    vector<int> d(N);
    for(int i = 0; i < N; i++){
        d[i] = INF;
    }
    d[s] = 0;

    vector<int> q;
    for(int i = 0; i < N; i++){
        q.push_back(i);
    }

    while (q.size() != 0) {
        int v = q[0];
        for(int u : q){
            if(d[u] < d[v]){
                v = u;
            }
        }
        q.erase(remove(q.begin(), q.end(), v), q.end());

        for(int u = 0; u < N; u++){
            d[u] = min(d[u], d[v] + c[v][u]);
        }
    }

    return d[t];
}

int main() {
    int h, w;
    cin >> h >> w;

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

    vector<int> cost(N);
    for(int i = 0; i < N; i++){
        cost[i] = dijkstra(c, i, 1);
    }

    int sum = 0;
    for (int q = 0; q < h * w; q++) {
        int x;
        cin >> x;
        if(x == -1){
            continue;
        }
        sum += cost[x];
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 5e3 + 9;
int dp[maxn][maxn], n;
string s;

int solve(int i, int j){
    if (i == n || j == n) return 0;
    if (dp[i][j] != -1) return dp[i][j];
    if (s[i] != s[j]) return 0;
    return dp[i][j] = min(j - i, 1 + solve(i + 1, j + 1));
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    cin >> n >> s;
    memset(dp, -1, sizeof dp);
    int res = 0;
    rep(i, 0, n){
        rep(j, i + 1 ,n){
            res = max(res, solve(i, j));
        }
    }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 98560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k;
    long long int a,b,c,t,n,ar[1000],br[1000],count,p=0;
    while(cin>>t)
    {
        for(i=0; i<t; i++)
        {
            cin>>ar[i];
            br[i]=-1;
        }


        for(i=0; i<t; i++)
        {
            count=1;
            for(j=i+1; j<t; j++)
            {
                if(ar[i]==ar[j])
                {
                    count++;
                    br[j]=0;          //count holeiee tar position 0 hbe...
                   // cout<<count<<endl;
                }
            }

            if(br[i]!=0)
            {
                br[p]=count;
                p++;
               // cout<<br[i]<<" "<<count<<" "<<p<<endl;
            }

        }


        cout<<p<<endl;
        p=0;
    }
}


Measured memory_bytes: 256
/**
 * Title: E - Double Factorial
 * Url: https://atcoder.jp/contests/abc148/tasks/abc148_e
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    ll N; cin >> N;
    if(N==0) {
        cout << 0 << endl;
        return 0;
    }
    if(N%2==1) {
        cout << 0 << endl;
    } else {
        ll n = N/2;
        ll k = log2(n)*(1.0/log2(5.0));
        ll ans = 0;
        for(ll i=1; i<=k; i++) {
            ans += n/(ll)pow((ll)5, i);
        }
        cout << ans << endl;
    }


    return 0;
}

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

int main() {
	string S,T;
	cin>>S>>T;
	vector<char> vecs(S.size());
	vector<char> vect(T.size()*2);
	bool Bo=false;
	int k;
	for(int i=0;i<S.size();i++){
		vecs.at(i)=S.at(i);
		vect.at(i)=T.at(i);
		vect.at(S.size()+i)=T.at(i);
	}
	for(int i=0;i<S.size();i++){
		for(int j=0;j<S.size();j++){
			//cout<<i<<j<<endl<<vecs.at(j)<<vect.at(i+j)<<endl;
			if(!(vecs.at(j)==vect.at(i+j))){
				Bo=false;
				break;
			}
			else if(j==S.size()-1){
				Bo=true;
				break;
			}
		}
		if(Bo){
			break;
		}
	}
	if(Bo){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
abcd = []
for i in range(q):
    abcd.append(list(map(int, input().split())))

ans = 0
for v in combinations_with_replacement(range(1, m+1), n):
    A = list(v)
    tmp = 0
    for a, b, c, d in abcd:
        if A[b-1] - A[a-1] == c:
            tmp += d
    ans = max(ans, tmp)
print(ans)


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

// 
// 以下はアウトになるコード
// 

int N;
map<int,int> mp;

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

    int cnt = 0;

    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if(itr->second%2 == 1) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=55;
int n,m,a[N],b[N],ans,forbid1,forbid2;
bool visit[N];
vector<int>v[N];
void dfs(int now)
{
	visit[now]=true;
	for(int i=0;i<v[now].size();i++)
	{
		if(visit[v[now][i]])continue;
		if((forbid1==now&&forbid2==v[now][i])||(forbid2==now&&forbid1==v[now][i]))continue;
		dfs(v[now][i]);
	}
}
bool check()
{
	memset(visit,false,sizeof(visit));
	dfs(0);
	for(int i=0;i<n;i++)
		if(!visit[i])
			return false;
	return true;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
		v[a[i]].pb(b[i]);
		v[b[i]].pb(a[i]);
	}
	for(int i=0;i<m;i++)
	{
		forbid1=a[i];
		forbid2=b[i];
		if(!check())ans++;
	}
	cout<<ans;
}
/*
7 7
1 3
2 7
3 4
4 5
4 6
5 6    
6 7
*/

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout << ((h2 - h1) * 60 + (m2 - m1)) - k;
	return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>
int main(){
	int l,r,d;
	scanf("%d%d%d",&l,&r,&d);
	int n=d;
	int sum=0;
	while(n<=r){
		if(n>=l){
			sum++;
		}n=n+d;
	}
	printf("%d",sum);
} 

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

int main() {
  long long int n;
  scanf("%lld",&n);
  long long int q[4] = {0,3,5,7};
  long long int t = 0;
  long long int i = 0;
  long long int ans = 0;
  long long int qdig[10] = {0,0,0,0,0,0,0,0,0,0};
  long long int j;
  while (t <= n) {
    long long int dig = t;
    long long int c0 = 0;
    long long int c3 = 0;
    long long int c5 = 0;
    long long int c7 = 0;
    while(dig > 0) {
      //printf("CH\n");
      if(dig%10 == 0) {
        c0++;
      }
      if(dig%10 == 3) {
        c3++;
      }
      if(dig%10 == 5) {
        c5++;
      }
      if(dig%10 == 7) {
        c7++;
      }
      dig = dig/10;
    }
    if(c0 == 0 && c3 > 0 && c5 > 0 && c7 > 0) {
      ans++;
    }
    i++;
    dig = i;
    long long int co = 9;
    while(dig > 0) {
      qdig[co] = dig%4;
      dig = dig / 4;
      co--;
    }
    t = 0;
    for(j=0;j<10;j++) {
      t = 10*t + q[qdig[j]];
    }
    //printf("t = %lld\n",t);
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! { n: usize, m: usize, lr: [(usize, usize); m] };
    let (mut l, mut r) = lr[0].clone();
    for i in 1 .. m {
        let (l2, r2) = &lr[i];
        l = l.max(*l2);
        r = r.min(*r2);
    }
    let mut c = 0;
    for i in 1 ..= n {
        if i >= l && i <= r {
            c += 1;
        }
    }
    println!("{}", c);
}


Measured memory_bytes: 4640
/*Arnab's Code
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define vii vector<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define take(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define takes(a,n,st) for(ll i=st;i<n+st;i++)cin>>a[i]
ll sum(ll a[],ll n,ll s){ for(ll i=0;i<n;i++)s+=a[i]; return s;}
#define mod 1000000009
ll power(ll x, ll y, ll p)  {  
    ll res = 1;  
    x = x % p;   
    if (x == 0) return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
void solve(){
    ll a;
	cin>>a;
  	cout<<a + (a*a)+(a*a*a);
	return;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ll t,T;
//	cin>>T;
	T=1;
	for(t=1;t<=T;t++){
//		cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,W,w[105],v[105],dp1[100005],dp2[100005];
  cin>>n>>W;
  for(int i=0;i<n;i++)
    cin>>w[i]>>v[i];
  for(int i=0;i<n;i++){
    for(int j=0;j<=W;j++){
      if(w[i]<=j){
	dp2[j]=max(dp1[j],dp1[j-w[i]]+v[i]);
      }
      else
	dp2[j]=max(dp1[j],dp2[j]);
    }
    for(int j=0;j<=W;j++){
      dp1[j]=dp2[j];
      dp2[j]=0;
    }
  }
  cout<<dp1[W]<<endl;
      return(0);
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include<assert.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
const int inf = 1e17;
const int mod = 998244353;
typedef pair<int, int> P;
struct edge {
	int to, dir;
};

signed main(){
	int a, b, c; cin >> a >> b >> c;
	if (c - a - b < 0)puts("No");
	else if (4 * a*b < (c - a - b)*(c - a - b))puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//(*'ω'*)ACください
int main(){
    int h,n;cin>>h>>n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    vector<int> minMP(h+1,1000000000);
    minMP[0]=0;
    for(int i=1;i<=h;i++){
        for(int j=0;j<n;j++){
            int from=i-a[j];
            if(from<0)from=0;
            minMP[i]=min(minMP[i],minMP[from]+b[j]);
        }
    }
    cout<<minMP[h]<<endl;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int gcd(long long n ,long long m){
    while(1) {
        if(n < m) return gcd(m, n);
        long long r;
        while ((r=n%m)) {
          n = m;
          m = r;
        }
        return m;
      }
  }
int main(){
    long long a,b;
    cin>>a>>b;
    long long ans=a*b;
    long long c=gcd(a,b);
    ans/=c;
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const ll rem = 200;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, A;
  cin >> N >> A;
  Vll x(N+1);
  REP2(i, 1, N+1)
  {
    cin >> x[i];
    x[i] -= A;
  }
  vector<VVll> dp(N+1, VVll(N+1, Vll(2*rem, 0)));
  REP2(i, 1, N+1)
  {
    ll idx_k;
    if (x[i] >= 0) idx_k = x[i];
    else idx_k = rem - x[i] - 1;
    dp[i][1][idx_k] += 1;
  }

  REP2(i, 1, N+1) REP2(j, 1, N+1)
  {
    if (j > i) break;
    REP(k, 2*rem)
    {
      dp[i][j][k] += dp[i-1][j][k];
      ll kk;
      if (k >= rem) kk = rem - k - 1;
      else kk = k;
      if (kk-x[i] < -rem || kk-x[i] >= rem) continue;
      if (kk-x[i] >= 0) dp[i][j][k] += dp[i-1][j-1][kk-x[i]];
      else dp[i][j][k] += dp[i-1][j-1][rem - kk + x[i] - 1];
    }
  }
  ll ans = 0;
  REP2(j, 1, N+1) ans += dp[N][j][0];
  cout << ans << endl;

  return 0;
}

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

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

// chmax, chmin
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N, long long K, std::vector<long long> p) {
    sort(p.begin(), p.end());
    p.resize(K);
    cout << accumulate(p.begin(), p.end(), 0ll) << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> p(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &p[i]);
  }
  solve(N, K, std::move(p));
  return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int x,n, cc=-1;cin >>x >> n;
    int arr[n];
    fo(i,n){
        cin >> arr[i];
    }
    sort(arr, arr+n);
    fo(i,n){
        if(arr[i]==x){
            cc =i;
        }
    }
    if(cc==-1){
        cout << x;
        return 0;
    }
    int c = arr[cc];
    for(int i = 0; i < min(cc, n-cc);++i){
        if(c-i-1 != arr[cc-i-1]){
            cout << c-i-1;
            return 0;
        }
        if(c+i+1 != arr[cc+i+1]){
            cout << c+i+1;
            return 0;
        }   
    }
    (n-cc<cc)?cout << int(arr[n-1])+1:cout << int(arr[0])-1; 
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main() {
	int i, j, k, ip;
	int h_array[300], w_array[300];

	for (i = 0; i < 300; i++) {
		scanf("%d %d", &h_array[i], &w_array[i]);

		if (h_array[i] == 0 && w_array[i] == 0) {
			ip = i;
			break;
		}

	}
	for (k = 0; k < ip; k++) {
		for (i = 0; i < h_array[k]; i++) {
			for (j = 0; j < w_array[k]; j++) {
				if (i == 0 || i == (h_array[k]-1)) {
					printf("#");
				}
				else if (j == 0 || j == (w_array[k]-1)) {
					printf("#");
				}
				else {
					printf(".");
				}
			
			}
			printf("\n");
			if (h_array[k] == 0 && w_array[k] == 0) {
				break;
			}
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14
 
signed main(){
    char x, y;
    cin >> x >> y;
    if(x == y)cout << '=' << endl;
    else{
    cout << (x > y ? '>' : '<') << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
using namespace std;

typedef ostringstream oss;
typedef istringstream iss;
typedef stringstream ioss;

int main(void) {
	int Q;
	cin >> Q;
	for (; Q; Q--) {
		long n;
		cin >> n;

		int cnt = 0;
		vector<long> his;
		
		while (n / 10) {
			if (find(his.begin(), his.end(), n) != his.end()) {
				cnt = -1;
				break;
			}
			
			int m = 0;
			ioss is;
			is << n;
			string str = is.str();
			for (int i = 1; i < str.size(); i++) {
				int a = atoi(str.substr(0, i).c_str());
				int b = atoi(str.substr(i).c_str());
				m = max(m, a * b);
			}

			n = m;
			cnt++;
		}

		cout << cnt << endl;

	}

	return 0;
}

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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)

//MIN-MAX
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
 const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];
bool visited[MAXN];
ll dp[MAXN];

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

void dfs(ll par)
{
    visited[par]=true;

    for(ll child:adj[par])
    {
        if(!visited[child])
            dfs(child);

        dp[par]= max(dp[par],1+dp[child]);

    }

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

	 f(i,0,m)
	 {
	     ll x,y;
	      cin>>x>>y;
	      adj[x].push_back(y);

	 }

	 for(ll i=1;i<=n;i++)
     {
        if(!visited[i])
            dfs(i);

     }
     ll ans=0;

     for(ll i=0;i<=n;i++)
     {
         ans=max(ans,dp[i]);
     }

     cout<<ans<<"\n";

	return 0;
}













Measured memory_bytes: 8576
package main

import (
	"fmt"
)

func main() {
	var X int
	fmt.Scan(&X)

	lcm := X * 360 / GCD(360, X)
	fmt.Println(lcm / X)
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}


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

int main() {
    string str;
    cin >> str;
    int ss = str.size();
    int bc = 0;
    int hc = 0;
    for(int i = 0; i < ss; i++) {
        if (str.at(i) == '0') bc++;
        else hc++;
    }
    int a = 0;
    int b = 0;
    char bh[] = {'0', '1'};

    int f = 0;
    for(int i = 0; i < ss; i++) {
        if (str.at(i) != bh[f]) a++;
        f = 1 - f;
    }
    f = 1;
    for(int i = 0; i < ss; i++) {
        if (str.at(i) != bh[f]) b++;
        f = 1 - f;
    }
    int ans = a > b ? b : a;
    cout << ans << endl;
}

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

using namespace std;

int const N = 1e6 + 5;

int cnt1[N], cnt2[N], n, m, u, v;

int main()
{
  //  freopen("inp.txt", "r", stdin);
  //  freopen("out.txt", "w", stdout);
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        cin >> u >> v;
        if(u == 1)  cnt1[v]++;
        if(v == n)  cnt2[u]++;
    }
    for(int i=1; i<=n; i++){
        if(cnt1[i] && cnt2[i]){
            cout << "POSSIBLE";
            return 0;
        }
    }
    cout << "IMPOSSIBLE";
}


Measured memory_bytes: 5120
# coding:utf-8

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


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

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

for i in range(N-2):
    if(D[i][0] == D[i][1]):
        if(D[i+1][0] == D[i+1][1]):
            if(D[i+2][0] == D[i+2][1]):
                count = 1

if(count==1):
    print("Yes")
else:
    print("No")

#print(ans)


Measured memory_bytes: 74876
import heapq
N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heapq.heapify(A)

ans = 0
for i in range(M):
    most_expensive = -heapq.heappop(A)
    most_expensive //= 2
    heapq.heappush(A, -most_expensive)

print(-sum(A))


Measured memory_bytes: 20476
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=10000;

int main(){
	int N,K;
	cin>>N>>K;
	int one=1;
	rep(i,N){
		int x;
		cin>>x;
		if(x==1) break;
		one++;
	}
    	cout<<(N-2)/(K-1)+1;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N=500010;
const int mod=1000000007;
struct data1{int l,r,sum;}T[N*4];
struct line{int k,b,id;}a[N];
int i,j,k,n,m,x,y,t,b[N],pos[N];
struct data{int l,r;}e[N];
double p[N];
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){f=ch=='-'?-f:f;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
bool cmp1(const line&a,const line&b){return a.b<b.b;}
bool cmp2(const data&a,const data&b){return a.r==b.r?a.l<b.l:a.r<b.r;}
bool cmp3(const line&a,const line&b){return a.k==b.k?a.b>b.b:a.k>b.k;}
void pushup(int i){T[i].sum=(T[i*2].sum+T[i*2+1].sum)%mod;}
void build(int i,int l,int r){
	T[i]={l,r,0};
	if (l==r)return;
	int mid=l+r>>1;
	build(i*2,l,mid);build(i*2+1,mid+1,r);
}
int query(int i,int l,int r){
	if (T[i].l==l&&T[i].r==r)return T[i].sum;
	int mid=T[i].l+T[i].r>>1;
	if (r<=mid)return query(i*2,l,r);
	else if (l>mid)return query(i*2+1,l,r);
	else return (query(i*2,l,mid)+query(i*2+1,mid+1,r))%mod;
}
void change(int i,int x,int v){
	if (T[i].l==T[i].r){T[i].sum=(T[i].sum+v)%mod;return;}
	int mid=T[i].l+T[i].r>>1;
	if (x<=mid)change(i*2,x,v);else change(i*2+1,x,v);
	pushup(i);
}
int main(){
	n=read();for (i=1;i<=n;i++)a[i].b=read(),a[i].k=read();
	sort(a+1,a+1+n,cmp3);
	for (i=1;i<=n;i++)a[i].id=i;
	sort(a+1,a+1+n,cmp1);
	int ex,id;
	ex=-1013687232;id=0;for (i=1;i<=n;i++){if (a[i].k==ex)e[i].l=id=a[i].id;else {if (a[i].k>ex)ex=a[i].k,id=a[i].id;e[i].l=id;}}
	ex=1013687232;id=n+1;for (i=n;i>=1;i--){if (a[i].k==ex)e[i].r=id=a[i].id;else {if (a[i].k<ex)ex=a[i].k,id=a[i].id;e[i].r=id;}}
//	for (i=1;i<=n;i++)printf("%d %d %d %d\n",a[i].k,a[i].b,e[i].l,e[i].r);
	sort(e+1,e+1+n,cmp2);
//	for (i=1;i<=n;i++)printf("%d %d\n",e[i].l,e[i].r);
	build(1,0,n);
	change(1,0,1);
	for (i=1;i<=n;i++)change(1,e[i].r,query(1,e[i].l-1,e[i].r));
	printf("%d\n",query(1,n,n));
	return 0;
}
//100

Measured memory_bytes: 16640
N, A, B = gets.split(/ /).collect{|n| n.to_i}

if A > B
	puts 0
elsif N < 2
	if A == B
		puts 1
	else
		puts 0
	end
else
	puts (B * (N - 1) + A) - (B + A * (N - 1)) + 1
end




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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long i64;
typedef pair<i64, i64> P;


int a[5], k;

int main(){
	for(int i = 0; i < 5; i++) cin >> a[i];
	cin >> k;
	
	sort(a,a+5);
	
	if(a[4]-a[0] > k) cout << ":(" << endl;
	else cout << "Yay!" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int n, m;

const int MAXN = 100005;
LL values[MAXN]; int visited[MAXN];

vector<vector<int>> adj;

vector<LL> component;
vector<LL> remaining;

void dfs(int u)
{
    visited[u] = 1;
    component.PB(values[u]);

    for (auto v : adj[u])
    {
        if (!visited[v])
        {
            dfs(v);
        }
    }
}

int main() {
    GI(n);
    GI(m);

    FORN(i, n)
    {
        GLL(values[i]);
    }

    int u, v;

    adj.resize(n);

    while (m--)
    {
        GI(u);
        GI(v);

        adj[u].PB(v);
        adj[v].PB(u);
    }

    memset(visited, 0, sizeof visited);

    int components = 0;
    LL res = 0;

    for (int i = 0; i < n; i++)
    {
        if (!visited[i])
        {
            component.clear();
            dfs(i);

            components++;
            sort(component.begin(), component.end());

            res += component[0];
//            DEBUG(component[0]);

            for (int j = 1; j < component.size(); j++)
            {
                remaining.PB(component[j]);
            }
        }
    }

//    DEBUG(components);

    if (components <= 1)
    {
        cout << 0 << "\n";
        return 0;
    }
    else
    {
        if (remaining.size() < components - 2)
        {
            cout << "Impossible\n";
        }
        else
        {
            sort(remaining.begin(), remaining.end());
            for (int i = 0; i < components - 2; i++)
            {
                res += remaining[i];
            }
            cout << res << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 9208
nums = [n for n in input()]
ope = ["+", "-"]
for b in range(2 ** 3):
    temp = nums[0]
    for i in range(3):
        temp += ope[bool(b & (1 << i))] + nums[i + 1]
    if eval(temp) == 7:
        print(temp+"=7")
        break

Measured memory_bytes: 3060
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c, i, ans;
    cin >> a >> b >> c;
    ans = 0;
    for(i=a; i<=b; i++)
    {
        if(c % i == 0)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3100
N=int(input())
f=0
fnew=0
A=list(map(int,input().split()))
cnt=0
i=0
l=0
r=0
downflag=0
upflag=0
ma=A[i]
mi=A[i]
while i<N:
 if ma>A[i]:
  downflag=1
 elif ma<A[i]:
  upflag=1
 if (upflag==1)and(A[i]>ma):
  ma=A[i]
 if (downflag==1)and(mi>A[i]):
  mi=A[i]
 if (ma+mi)!=(A[l]+A[i]):
  ma=A[i]
  mi=ma
  cnt=cnt+1
  l=i
  i=i-1
  upflag=0
  downflag=0
 i=i+1
print(cnt+1)

Measured memory_bytes: 62704
import sys
from collections import defaultdict


class SegTree:
    def __init__(self, n, s):
        """
        :param n: 要素数
        :param INF: 初期値（入りうる要素より十分に大きな数）
        """
        n2 = 1 << (n - 1).bit_length()
        self.offset = n2
        self.tree = [None] * n2 + [{} for _ in range(n2)]
        self.lmd0 = lambda: 0

        for i, c in enumerate(s):
            x = ord(c) - 97
            i += self.offset
            self.tree[i][x] = 1
        for i in range(self.offset - 1, 0, -1):
            sti = self.tree[i] = defaultdict(self.lmd0, self.tree[i << 1])
            stj = self.tree[(i << 1) + 1]
            for x in stj:
                sti[x] += stj[x]
        # print(*(dict(t) for t in self.tree), sep='\n')

    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.offset
        if x in self.tree[i]:
            return
        y, _ = self.tree[i].popitem()
        self.tree[i][x] = 1
        i >>= 1
        while i > 0:
            sti = self.tree[i]
            sti[x] += 1
            if sti[y] == 1:
                del sti[y]
            else:
                sti[y] -= 1
            i >>= 1

    def get_types(self, a, b):
        """
        [a, b)の最小値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        result = set()

        l = a + self.offset
        r = b + self.offset
        while l < r:
            if r & 1:
                result.update(self.tree[r - 1].keys())
            if l & 1:
                result.update(self.tree[l].keys())
                l += 1
            l >>= 1
            r >>= 1

        return len(result)


n = int(input())
s = input()
st = SegTree(n, s)
q = int(input())
ans = []
for line in sys.stdin:
    i, j, k = line.rstrip().split()
    if i == '1':
        j = int(j) - 1
        k = ord(k) - 97
        st.update(j, k)
    else:
        l = int(j) - 1
        r = int(k)
        ans.append(st.get_types(l, r))
print('\n'.join(map(str, ans)))


Measured memory_bytes: 453288
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	string S;
	getline(cin, S);
	for (int i = 0; i < S.length(); i++) {
		if (islower(S[i]))
			S[i] = toupper(S[i]);
		else
			S[i] = tolower(S[i]);
	}
	cout << S << endl;
}

Measured memory_bytes: 3136
S = list(input())
N = len(S)

p = 0 #スライス前
o = 0 #変更回数
u = N #スライス後


if N % 2 == 0:
    #('偶数処理開始')
    for i in range(int(N/2)):
        if S[p] == S[u-1]:
            #print('偶数で一致'+ str(S[p]) + str(S[u-1]))
            p += 1
            u -= 1
        else:
            #print('偶数で不一致'+ str(S[p]) + str(S[u-1]))
            o += 1
            p += 1
            u -= 1
else:
    N -= 1
    #print('奇数処理開始')
    for i in range(int(N/2)):
        if S[p] == S[u-1]:
            #print('奇数で一致' + str(S[p]) + str(S[u-1]))
            p += 1
            u -= 1
        else:
            #print('奇数で不一致'+ str(S[p]) + str(S[u-1]))
            o += 1            
            p += 1
            u -= 1
print(o)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int array[] = new int[100000 + 100];
        int cnt = 0;
        for(int i = 1;i <= n;i++){
            int a = Integer.parseInt(st.nextToken());
            array[a]++;
        }
        for(int i = 1;i < array.length;i++){
            if(array[i] == 0)continue;
            cnt += array[i] - 1;
        }
        int left = n - cnt;
        if(cnt % 2 == 1)--left;
        System.out.println(left);
    }
}


Measured memory_bytes: 22440
# -*- coding: utf-8 -*-
from itertools import product
from heapq import heappop, heappush

def solve():
    N = int(input())
    A0, A1 = [], []
    for a in map(int, input().split()):
        if a >= 0:
            heappush(A0,a)
        else:
            heappush(A1,-a)
    if A0 and A1:
        S = sum(A0) + sum(A1)
        res_l = [str(S)]
        b = heappop(A0)
        while len(A1) > 1:
            a = -heappop(A1)
            res_l.append('{} {}'.format(b, a))
            b -= a
        c = b
        b = -heappop(A1)
        while A0:
            a = heappop(A0)
            res_l.append('{} {}'.format(b, a))
            b -= a
        res_l.append('{} {}'.format(c, b))                
    else:
        if A0:
            S = sum(A0)
            b = heappop(A0)
            S -= 2*b
            res_l = [str(S)]
            for _ in range(N-2):
                a = heappop(A0)
                res_l.append('{} {}'.format(b, a))
                b -= a
            a = heappop(A0)
            res_l.append('{} {}'.format(a, b))
        else:
            S = sum(A1)
            b = -heappop(A1)
            S = S+2*b
            res_l = [str(S)]
            for _ in range(N-1):
                a = -heappop(A1)
                res_l.append('{} {}'.format(b, a))
                b -= a
    res =  '\n'.join(res_l)

    return res
if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 15556
#define ll long long int
#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n, y; cin>>n>>y;
	y = y/1000;
	for(int i=0; i<=y/10; i++)
	{
		for(int j=0; j<=y/5; j++)
		{
			int k = y - i*10 - j*5;
			if(k<0)
				continue;
			if(i+j+k == n)
			{
				cout<<i<<" "<<j<<" "<<k;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        Array.Sort(ar);
        var tail = 3 * num - 2;
        var result = 0L;
        for(var i = 0; i < num; i++)
        {
            result += ar[tail];
            tail -= 2;
        }
        WriteLine(result);
    }
}

Measured memory_bytes: 38604
N=int(input())
S=input()
a=0
l=[0]*26
for i in S:
    t=1
    for j in range(26):
        if j!=ord(i)-97:
            t*=(l[j]+1)%(10**9+7)
    a=(a+t)%(10**9+7)
    l[ord(i)-97]+=1
print(a)

Measured memory_bytes: 3188
// AtCoder Beginner Contest - Problem B: 754 (https://atcoder.jp/contests/abc114/tasks/abc114_b)
#include <bits/stdc++.h>

using namespace std;

#define REPN(i, N) for (int (i) = 0; (i) < N; (i)++)

const int oo { 2000000010 };

void solve(const string& S)
{
    auto ans = oo;

    REPN(i, (int) S.size() - 2)
    {
        auto X = stoi(S.substr(i, 3));
        auto diff = abs(X - 753);

        ans = min(ans, diff);
    }

    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    solve(S);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+100;
int mark[maxn];
//int deg[maxn];
int head[maxn];
int tot;
int n,k;
const int mod=1e9+7;
struct node
{
    int v,next;
}arr[maxn*2];
void add(int u,int v)
{
    arr[tot].v=v;
    arr[tot].next=head[u];
    head[u]=tot++;
}
void init(int n)
{
    for(int i=0;i<=n;++i)
        head[i]=-1;
}
struct tree
{
    int f,v;
};
long long int fac(int n,int m)
{
    long long int ans=1;
    if(m>n)
        return 0;
    for(int i=n;m--;--i)
    {
        ans*=i;
        ans%=mod;
    }
    return ans;
}
long long int cal(int i)
{
    tree t,y;
    t.v=i;
    t.f=1;
    long long int ans=k;
    queue<tree>q;
    q.push(t);
    int v;
    bool flag=true;
    while(!q.empty())
    {
        int cnt=0;
        t=q.front();
        mark[t.v]=1;
        q.pop();
        for(int j=head[t.v];j!=-1;j=arr[j].next)
        {
            v=arr[j].v;
            if(!mark[v])
            {
                ++cnt;
                y.f=t.f+1;
                y.v=v;
                q.push(y);
            }
        }
        if(flag)
        {
            ans*=fac(k-1,cnt);
            ans%=mod;
            flag=false;
        }
        else
        {
            ans*=fac(k-2,cnt);
            ans%=mod;
        }
    }
    return ans;
}
int main()
{
    int a,b;
    cin>>n>>k;
    init(n);
    for(int i=1;i<n;++i)
    {
        cin>>a>>b;
        //++deg[a];
        //++deg[b];
        add(a,b);
        add(b,a);
    }
    cout<<cal(1)<<endl;
    /*for(int i=1;i<=n;++i)
    {
        if(deg[i]==1)
        {
            //cout<<cal(i)<<endl;
            break;
        }
    }*/
    return 0;
}


Measured memory_bytes: 3456
#include <stdio.h>

int main(){


    int W,H,x,y,r;


    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);


    if (W-r>=x&&r<=x&&H-r>=y&&r<=y)
        printf("Yes\n");
    else
        printf("No\n");


    return 0;


}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll N;
  cin >> N;
  ll ans = N-1;
  for (ll i = 1; i * i <= N; i++) {
    if (N%i) continue;
    ll temp = i-1;
    temp += (N/i) - 1;      
    if (temp < ans) ans = temp;
  }
  cout << ans << '\n';  
  return 0;
}

Measured memory_bytes: 3636
from sys import stdin
import sys
sys.setrecursionlimit(10**7)


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, K = list(map(int, _in[0].split(' ')))  # type:list(int)
    L_R_arr = []
    for i in range(K):
        _ = list(map(int, _in[i+1].split(' ')))  # type:list(int)
        L_R_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    dp = [0] * N
    sdp = [0] * (N+1)
    dp[0] = 1
    for i in range(N):
        for L, R in L_R_arr:
            right = max(0, i-L+1)
            left  = max(0, i-R)
            dp[i] += sdp[right] - sdp[left]
        else:
            sdp[i+1] = (sdp[i] + dp[i]) % 998244353
    ans = dp[-1] % 998244353
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 76848
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	ll n;
	cin >> n;
	ll ans=0;
	if (n % 2 == 0) {
		n /= 2;
		while (n >= 5) {
			ans += n / 5;
			n /= 5;
		}
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  int a = in();
  int b = in();
  cout << ((a * b % 2 == 0) ? "Even" : "Odd") << endl;
}


Measured memory_bytes: 256
# 解答
def abc173_a(lines):
    L, R, d = map(int, lines[0].split(' '))
    answer = 0
    for i in range(L, R+1):
        if i % d == 0:
            answer += 1
    return [answer]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5 10 2']
        lines_export = [3]
    elif pattern == 2:
        lines_input = ['6 20 7']
        lines_export = [2]
    elif pattern == 3:
        lines_input = ['1 100 1']
        lines_export = [100]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = abc173_a(lines_input)

    for line_result in lines_result:
        print(line_result)

    if mode > 0:
        print(f'lines_input=[{lines_input}]')
        print(f'lines_export=[{lines_export}]')
        print(f'lines_result=[{lines_result}]')
        if lines_result == lines_export:
            print('OK')
        else:
            print('NG')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9264
#include<stdio.h>
#include<math.h>
int main(){
    int N,i,j,num=0,y;
	scanf("%d",&N);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	/*prime number check*/
	for(i=0;i<N;i++){
		y=0;
		if(A[i]==2){
			num++;
			continue;
		}
		if((A[i]%2)==0)continue;
		for(j=3;j<=sqrt(A[i]);j+=2){
			if((A[i]%j)==0){
				y=1;
				break;
			}
		}
		if(y==0)num++;
	}
	printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 2056