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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 998244353;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    string s;
    cin >> n >> s;
    int r = 0,g = 0,b = 0;
    vector<int> a(3*n);
    vector<int[3]> c(n);
    ll ans = 1;
    for (int i = 0;i < 3*n;++i) {
        if (s[i] == 'R') {
            c[r][0] = i;
            r++;
        } else if (s[i] == 'G') {
            c[g][1] = i;
            g++;
        } else {
            c[b][2] = i;
            b++;
        }
    }
    for (int i = 0;i < n;++i) {
        int mn = *min_element(c[i],c[i]+3),mx = *max_element(c[i],c[i]+3),mid = c[i][0]+c[i][1]+c[i][2]-mn-mx;
        a[mn] = 0;
        a[mid] = 1;
        a[mx] = 2;
    }
    int cnt[2] = {0,0};
    for (int i = 0;i < 3*n;++i) {
        if (a[i] == 0) cnt[0]++;
        else if (a[i] == 1) {
            (ans *= cnt[0]) %= mod;
            cnt[0]--;
            cnt[1]++;
        } else {
            (ans *= cnt[1]) %= mod;
            cnt[1]--;
        }
    }
    for (int i = 1;i <= n;++i) (ans *= i) %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b ; cin>>a>>b;

    if((b-1)%(a-1)==0) cout<<(b-1)/(a-1)<<endl;
    else cout<<(b-1)/(a-1)+1<<endl;

    return  0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
string a,b;
cin>>a>>b;
if(a=="H"&&b=="D") cout<<"D"<<endl;
else if(a=="D"&&b=="H") cout<<"D"<<endl;
else if(a=="H") cout<<"H"<<endl;
else if(a=="D") cout<<"H"<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  for(ll i=0;i<k;i++) {
    if(s[i]!='1') {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << s[k-1] << endl;
}

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

bool solve() {
        int D, E; cin >> D >> E;
        if (D == 0 && E == 0) return (false);
        double err = 1e10;
        for (int x = 0; x <= D; x++) {
                int y = D-x;
                err = min(err, abs(sqrt(x*x + y*y) - (double)E));
        }       
        cout << err << endl;
        return (true);
}

int main() {
        cout << fixed << setprecision(20);
        while (solve());
        return (0);
}



Measured memory_bytes: 3180
#include <iostream>

using namespace std;

int main()
{
  int n; cin >> n;
  int n_init = n;
  int harshad = 0;

  while (n) {
    harshad += n % 10;
    n /= 10;
  }

  if (n_init % harshad == 0) cout << "Yes" << endl;
  else                       cout << "No" << endl;

  return 0;
}


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

using namespace std;

int res=0;
int num[10]={0};
long long c;
long long ans=0;
string S;

void   dfs(long long flag,int index){
    if(index==S.size()-1){
        string temp;
        
        for(int i=0;i<S.size();i++){
            temp = temp + S[i];
            if((flag&(1<<i))||i==S.size()-1){
                ans += stol(temp);
                temp="";
            }
        }
        return ;
    }
    
    
    
    
    
    
    /*
     if(
     char cc= S[i];
     temp = cc + temp;
     //temp.insert(temp.begin(),S[i]);
     for(int j=i-1;j>=0;j--){
     if(flag&(1<<j)){
     break;
     }
     else {
     cc=S[j];
     temp = cc + temp ;
     //temp.insert(temp.begin(),S[j]);
     }//100
     
     }
     long long tem = stol(temp);
     ans += tem;
     }
     */
    
    
    flag ^= 1<<index;
    dfs(flag,index+1);
    flag ^= 1<<index;
    dfs(flag,index+1);
    return ;
}

int main(){
    
    cin>>S;
    
    dfs(0,0);
    
    cout<<ans<<endl;
    
    
    return 0;
    
}

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

int main()
{
    int n, x, t;
    cin >> n >> x >> t;

    int ans;

    ans = (n/x) * t;
    if (n%x > 0) ans += t;

    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
int32_t main()
{  
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   ll t; t=1;
   while(t--)
   {
       int n; cin>>n;
       if(n==0) cout<<"1"<<"\n";
       else cout<<"0"<<"\n";
    
       
   }
}

Measured memory_bytes: 3608
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <queue>
using namespace std;

const int maxn = 507;

int h, w, a[maxn][maxn], ans, op[5][maxn * maxn];

inline void add(int i, int j) {
	ans++, op[1][ans] = i, op[2][ans] = j;
	if(i & 1) {
		if(j < w) op[3][ans] = i, op[4][ans] = j + 1;
		else op[3][ans] = i + 1, op[4][ans] = j;
	}
	else {
		if(j > 1) op[3][ans] = i, op[4][ans] = j - 1;
		else op[3][ans] = i + 1, op[4][ans] = j;
	}
	if(i == h && ((h & 1 && j == w) || (!(h & 1) && j == 1))) ans--;
}

int main() {
	scanf("%d%d", &h, &w);
	for(int i = 1;i <= h;i++) {
		for(int j = 1;j <= w;j++) {
			scanf("%d", &a[i][j]);
			if(a[i][j] & 1) a[i][j] = 1;
			else a[i][j] = 0;
		}
	}
	for(int i = 1, mv = 0;i <= h;i++) {
		for(int j = (i & 1) ? 1 : w;i & 1 && j <= w || !(i & 1) && j >= 1;j += (i & 1) ? 1 : -1) {
			if(a[i][j]) {
				mv = ~mv;
			}
			if(mv) add(i, j);
		}
	}
	printf("%d\n", ans);
	for(int i = 1;i <= ans;i++) {
		for(int j = 1;j < 4;j++) printf("%d ", op[j][i]);
		printf("%d\n", op[4][i]);
	}
	return 0;
}

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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

int main() {
   ll i,j,k;
    ll a,b;
    cin >> a>>b;

    if(a>b)
    {
      for(i=0; i<a; i++)
      {
        cout<<b;
      }
    }else
    {
      for(i=0; i<b; i++)
      {
        cout <<a;
      }
    }
  
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define ALL(a) a.begin(),a.end()
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100 + 47;
const int ALP = 'z' - 'a' + 1;
string A[MAX];
int C[MAX];
int N[5];

void no()
{
	cout << "No" << endl;
	exit(0);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	FOR(i, 0, n)
	{
		cin >> A[i];
		FOR(j, 0, m) C[A[i][j] - 'a']++;
	}

	if (n % 2 && m % 2) N[1] = 1;
	if (n % 2) N[2] += m / 2;
	if (m % 2) N[2] += n / 2;

	int cnt = 0;
	FOR(i, 0, ALP)
	{
		if (C[i] % 2 == 1)
		{
			C[i]--;
			cnt++;
		}
	}

	if (cnt > 1 || cnt == 1 && N[1] == 0) no();
	cnt = 0;
	FOR(i, 0, ALP)
	{
		if (C[i] % 4 != 0 && C[i] % 2 == 0)
		{
			cnt++;
			C[i] -= 2;
		}
	}

	if (cnt > N[2] || (N[2] - cnt) % 2 == 1) no();
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
n = int(input())

keta = len(str(n))

fugo =[0]*pow(2,keta-1)
for i in range(pow(2,keta-1)):
  temp = [0]*(keta-1)
  for j in range(keta-1):
    if (i>>j)&1 == 1:
      temp[j] = "+"
    else:
      temp[j] = ""
  fugo[i] = temp

ans = 0
for i in range(pow(2,keta-1)):
  shiki = str(n)[0]
  for j in range(keta-1):
    shiki += fugo[i][j]+str(n)[j+1]
  ans += eval(shiki)
print(ans)
             

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	string s, ans = "None";
	int a[26] = {0};
	cin >> s;
	
	REP(i, 0, (int)s.size()) a[s[i] - 'a']++;
	
	REP(i, 0, 26){
		if(a[i] == 0){
			ans = 'a' + i;
			break;
		}
	}
	cout << ans;
}


Measured memory_bytes: 512
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

N = input()
N = int(N)
l = [int(input()) for i in range(N)]
a = 0
for i in range(0,len(l)):
    if is_prime(l[i]) == True:
         a += 1
print(a)





Measured memory_bytes: 6008
#include<stdio.h>

#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	int n,abc[3][100001],i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d%d%d",&abc[0][i],&abc[1][i],&abc[2][i]);
	long dp[3][100001]={0},ans=0;
	dp[0][1]=abc[0][1];
	dp[1][1]=abc[1][1];
	dp[2][1]=abc[2][1];
	for(i=2;i<=n;i++){
		dp[0][i]=max(dp[1][i-1]+abc[0][i],dp[2][i-1]+abc[0][i]);
		dp[1][i]=max(dp[0][i-1]+abc[1][i],dp[2][i-1]+abc[1][i]);
		dp[2][i]=max(dp[0][i-1]+abc[2][i],dp[1][i-1]+abc[2][i]);
	}
	for(i=0;i<3;i++)ans=max(ans,dp[i][n]);
	printf("%ld\n",ans);
	return 0;
}

Measured memory_bytes: 3712
#include<stdio.h>
int main(void)
{
	int n,c,p[100],x,y,i;
	scanf("%d %d",&n,&c);
	y=0;
	for(i=0;i<c;i++){
		scanf("%d",&p[i]);
		y=y+p[i];
	}
	x=y/(n+1);
	if(y%(n+1)!=0){
		printf("%d\n",x+1);
	}
	else{
		printf("%d\n",x);
	}
	return 0;
}	


Measured memory_bytes: 2760
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    ll N;
    ll cnt[10][10];
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N;
        for(int u=1;u<=N;u++){
            ll t=u%10,h;
            int v=u;
            while(v){
                h=v%10;
                v/=10;
            }
            cnt[h][t]++;
        }
        ll ans=0;
        for(int u=0;u<10;u++){
            for(int v=0;v<10;v++)
                ans+=cnt[u][v]*cnt[v][u];
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 256
#48
N = int(input())
h = list(map(int,input().split()))
move = 0
num = 0

for i in range(N-1):
    if h[i] >= h[i+1]:
        num += 1
    else:
        if move < num:
            move = num
        num = 0
            
if move < num:
    move = num
        
print(move)


Measured memory_bytes: 20488
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<algorithm>
#include<set>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
#include<functional>
#include<stack>
using namespace std;
typedef long long LL;
int main()
{
    int a[3];
    for (int i=0;i<3;i++)
        cin>>a[i];
    sort(a,a+3);
    int flag=0;
    if(a[0]==a[1] && a[1]!=a[2])flag=1;
    if(a[0]!=a[1] && a[1]==a[2])flag=1;
    if(flag)cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
        int y = sc.nextInt();

        if(x < y){
            int tmp = y;
            y = x;
            x = tmp;
        }

        System.out.println(GCD(x, y));
    }

    static int GCD(int a, int b){
        if(a == 0)
            return b;
        else
            return GCD(b % a, a);
    }
}



Measured memory_bytes: 26348
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
	Node *cur = nil->next;
	while ( cur != nil && cur->key != key ) {
		cur = cur->next;
	}
	return cur;
}

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList() {
	Node *cur = nil->next;
	int isf = 0;
	while ( 1 ) {
		if ( cur == nil ) break;
		if ( isf++ > 0 ) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t) {
	if ( t == nil ) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	deleteNode(listSearch(key));
}

void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for ( i = 0; i < n; i++ ) {
		scanf("%s%d", com, &key);
		if ( com[0] == 'i' ) { insert(key); np++; size++; }
		else if ( com[0] == 'd' ){
			if ( strlen(com) > 6 ) {
				if ( com[6] == 'F' ) deleteFirst();
				else if ( com[6] == 'L' ) deleteLast();
			} else {
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}

Measured memory_bytes: 33864
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; ll x; cin >> N >> x;
	vector<ll> a(N, 0);
	rep (i, N){
		cin >> a[i];
	} // end rep

	ll res = 0LL;
	for (int i = 0; i < N - 1; ++i){
		ll curr = a[i] + a[i+1];
		if (curr > x){
			if (curr - x <= a[i+1]){
				res += (curr - x);
				a[i+1] -= curr - x;
			}else{ // if (curr - x > a[i+1])
				ll remain = curr - x - a[i+1];
				res += (a[i+1] + remain);
				a[i+1] = 0LL;
				a[i] -= remain;
			} // end if
		} // end if
//		cerr << "curr: " << curr << " res: " << res << endl;
	} // end for
/*
	rep (i, N){
		cerr << setw(2) << a[i];
	} // end rep
	cerr << endl;
*/
	cout << res << endl;
			
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    std::map<std::string, std::vector<int>> point;  // name, vec<point>
    std::map<int, int> index;  // point, index
    for(int i=0; i<n; i++){
        std::string s;
        int p;
        cin >> s >> p;
        point[s].push_back(p);
        index[p] = i + 1;
    }
    
    std::map<std::string, std::vector<int>>::iterator itr = point.begin();
    while(itr != point.end()){
        std::vector<int> tmp = itr->second;
        std::sort(tmp.begin(), tmp.end(), std::greater<int>());
        for(int i=0; i<tmp.size(); i++){
            cout << index[tmp[i]] << endl;
        }
        ++itr;
    }
    return 0;
}

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

int main(){
	int H,W;
	int i,j;

	while(1){
	cin >> H >> W;
	if (H==0&&W==0) break;

	
	for (i=0;i<H;i++){
		for (j=0;j<W;j++){
			if((i+j)%2==0){
				cout << "#";
			}
			else cout << ".";
		}
		cout << endl;
	}
	cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3100
n,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    c=0
    if n-a>b-1:
            c+=a-1
            c+=1
            c+=((b-1-c)//2)
    else:
            c+=n-b
            c+=1
            c+=((n-a-c)//2)
    print(c)

Measured memory_bytes: 38384
#119_D
A,B,Q=map(int,input().split())
INF=10**15
S=[-INF]+[int(input()) for _ in range(A)]+[INF]
T=[-INF]+[int(input()) for _ in range(B)]+[INF]

from bisect import bisect_left

for _ in range(Q):
    x=int(input())
    s=bisect_left(S,x)
    t=bisect_left(T,x)
    
    sr=abs(S[s]-x)
    sl=abs(S[s-1]-x)
    tr=abs(T[t]-x)
    tl=abs(T[t-1]-x)
    
    Ans=min(max(sr,tr),max(sl,tl),2*sr+tl,sr+2*tl,2*tr+sl,tr+2*sl)
    
    print(Ans)

Measured memory_bytes: 12804
#include <stdio.h>
#include <stdlib.h>

#define INIT_CAP 10
#define INF 1000000000

#define min(a, b) (((a) < (b)) ? (a) : (b))

const int di[2][9] = {{-2, -1, -1, 0, 0, 0, 1, 1, 2}, {-2, -1, -1, 0, 0, 0, 1, 1, 2}};
const int dj[2][9] = {{1, 1, 2, 1, 2, 3, 1, 2, 1}, {-1, -2, -1, -3, -2, -1, -2, -1, -1}};

typedef struct {
	int to, w;
} Edge;

typedef struct {
	Edge *elem;
	int cap, size;
} VecEdge;

typedef struct {
	int num, d;
} PNumDis;

VecEdge adj[3600];
PNumDis heap[32400];
int hsize;
int d[3600];

void init(int n) {
	while (n--)
		adj[n] = (VecEdge){malloc(sizeof(Edge) * INIT_CAP), INIT_CAP, 0};
}

inline void add(int from, int to, int w) {
	if (adj[from].size == adj[from].cap) {
		adj[from].cap <<= 1;
		adj[from].elem = realloc(adj[from].elem, sizeof(Edge) * adj[from].cap);
	}
	adj[from].elem[adj[from].size++] = (Edge){to, w};
}

void freeAll(int n) {
	while (n--)
		free(adj[n].elem);
}

inline void insert(int num, int d) {
	int i;
	for (i = hsize++; i > 0 && d < heap[i - 1 >> 1].d; i = i - 1 >> 1)
		heap[i] = heap[i - 1 >> 1];
	heap[i] = (PNumDis){num, d};
}

inline int calcNextIdx(int i) {
	return i * 2 + 1 + (i * 2 + 2 < hsize && heap[i * 2 + 1].d > heap[i * 2 + 2].d);
}

inline PNumDis delete(void) {
	int i;
	int nextIdx;
	const PNumDis root = heap[0], last = heap[--hsize];

	for (i = 0; i * 2 + 1 < hsize && last.d > heap[nextIdx = calcNextIdx(i)].d; i = nextIdx)
		heap[i] = heap[nextIdx];
	heap[i] = last;

	return root;
}

void dijkstra(int n, int s) {
	int i;

	for (i = 0; i < n; i++)
		d[i] = INF;

	d[s] = 0;
	insert(s, 0);
	while (hsize > 0) {
		const PNumDis fromP = delete();

		if (fromP.d > d[fromP.num])
			continue;

		for (i = 0; i < adj[fromP.num].size; i++) {
			const Edge e = adj[fromP.num].elem[i];
			if (fromP.d + e.w < d[e.to]) {
				d[e.to] = fromP.d + e.w;
				insert(e.to, d[e.to]);
			}
		}
	}
}

char field[60][30];

int main(void) {
	int i, j, k, l;
	int w, h;
	int min;

	while (scanf("%d %d", &w, &h), w) {
		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				scanf(" %c", field[i] + j);

		init(h * w * 2);
		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				for (k = 0; k < 2; k++)
					for (l = 0; l < 9; l++) {
						const int ni = i + di[k][l], nj = j + dj[k][l];
						if (ni >= 0 && ni < h && nj >= 0 && nj < w && field[ni][nj] != 'X')
							add(i * w + j + k * h * w, ni * w + nj + (k ^ 1) * h * w, field[ni][nj] <= '9' ? field[ni][nj] - '0' : 0);
					}

		min = INF;
		for (i = 0; i < w; i++)
			if (field[h - 1][i] == 'S')
				for (j = 0; j < 2; j++) {
					dijkstra(h * w * 2, (h - 1) * w + i + j * h * w);
					for (k = 0; k < w; k++)
						if (field[0][k] == 'T') {
							min = min(min, d[k]);
							min = min(min, d[k + h * w]);
						}
				}

		printf("%d\n", min == INF ? -1 : min);

		freeAll(h * w * 2);
	}

	return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define t(x) cerr<<#x<<":"<<x<<'\n';
#define t2(a,n) { cerr<<#a<<" = "; for(int i=0; i<n; ++i){ cerr << a[i] << ' '; } ; cerr <<'\n'; }
#define t3(a){ cerr<<#a<<" = "; for(auto i: a){ cerr<<i<<" "; } cerr<<'\n'; }



int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m;
	cin>>n>>m;
	vector<pair<ll,int>> data(n);
	for(int i=0; i<n; ++i){
		cin>>data[i].first>>data[i].second;
	}
	sort(data.begin(),data.end());
	ll cost = 0;
	for(auto i: data){
		if( m < i.second ){
			cost += m * i.first;
			break;
		}else{
			cost += i.first * i.second;
			m -= i.second;
		}
	}
	cout<<cost<<endl;

	#ifdef LOL
	    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
using ll = long long int;

const int N_MAX = 100005;
int n, m;
vector<ll> a;

template< typename T >
T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if(b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int main(){
    cin >> n >> m;
    int e;
    bool ans = true;
    for(int i = 0; i < n; i++){
        ll ai;
        cin >> ai;
        a.push_back(ai);
        int num = 0;
        while(!(ai & 1)){
            ai = ai >> 1;
            num++;
        }
        if (i == 0)e = num;
        else{
            if (e != num)ans = false;
        }
    }
    if (!ans){
        cout << 0 << endl;
        return 0;
    }

    ll L = a[0];
    for(int i = 1; i < n; i++){
        ll x, y;
        if (L <= 2 * m){
            ll gcd = extgcd(L, a[i], x, y);
            L = L * a[i] / gcd;
        }
    }
    ll ansn = 0;
    ll now = L / 2;
    while(now <= m){
        ansn++;
        now += L;
    }
    cout << ansn << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>
int main(void){
  int n,x,m[101],i,sum=0,min=9999999;
  scanf("%d%d",&n,&x);
  for(i=0;i<n;i++){
    scanf("%d",&m[i]);
    if(min>m[i]) min=m[i];
    sum+=m[i];
  }
  int count=n;
  x-=sum;
  count+=(x/min);
  printf("%d",count);
  return 0;
}

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

int main()
{
	string S;
	cin>>S;
	if (S[2]==S[3]&& S[4] == S[5])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
K, A, B = map(int, input().split())

if A + 1 >= B:
    ans = K + 1
else:
    rem = K - (A - 1)
    double = rem // 2
    remrem = rem - double * 2
    ans = B + (double - 1) * (B - A) + remrem
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
string s;
bool f;
int main()
{
    f = false;
    map<char,int>mp;
    map<char,bool>mark;
    cin>>s;
    for (int i = 0; i < s.size(); i++)
    {
        mp[s[i]]++;
        mark[s[i]] = 1;
    }
    for (int i = 0; i < 26; i++)
    {
        if(mark[i+'a'] == 0)
        {
            f = true;
            printf("%c\n",i+'a');
            break;
        }
    }
    if(!f)
        printf("None\n");
    return 0;
}

Measured memory_bytes: 512
# 最大公約数
def gcd(a,b):
    while b != 0:
        a,b = b, a%b
    return a

# 最小公倍数

def lcm(a,b):
    return a*b // gcd(a,b)


a,b = map(int,input().split())
print(lcm(a,b))

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <stack>
#include <tuple>

using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    int sNum = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'S') sNum++;
        else if (sNum > 0)
        {
            sNum--;
            ans++;
        }
    }
    cout << s.size() - 2 * ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void) {
	int n, a[100];
	int i, count = 0;

	scanf("%d", &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)
				) {
				count = 1;
			}
		}
	}

	if (count==1)
		printf("DENIED\n");

	else
		printf("APPROVED\n");


	return 0;			
	
}

Measured memory_bytes: 128
moji_list =sorted(list('abcdefghijklmnopqrstuvwxyz'))
n = int(input())
S = [input() for i in range(n)]
moji_con = [0] * len(moji_list)
ans = ''

for i in range(len(moji_list)):
    MM = []
    moji = moji_list[i]
    
    for word in S:
        MM.append(word.count(moji))
    
    moji_con[i] = min(MM)
    
for i in range(len(moji_con)):
    if moji_con[i] != 0:
        ans += moji_con[i]*moji_list[i]
print(ans)

Measured memory_bytes: 3064
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	string s;
	cin>>s;
	s=" "+s;
	ll i,j;
	for(i=1;i<s.size()-1;i++){
		if(s[i]==s[i+1]){
			cout<<i<<" "<<i+1;return 0;
		}
		if(s[i-1]==s[i+1]){
			cout<<i-1<<" "<<i+1;return 0;
		}
	}
	cout<<"-1 -1";
	return 0;
}

Measured memory_bytes: 512
fn main() {
    proconio::input! {
        s: proconio::marker::Chars,
    }
    if *s.last().unwrap() == 's' {
        println!("{}{}", s.iter().collect::<String>(), "es");
    } else {
        println!("{}{}", s.iter().collect::<String>(), "s");
    }
}


Measured memory_bytes: 2152
N = int(input())
R = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[1])
B = sorted([list(map(int, input().split())) for _ in range(N)])

cnt = 0
for i in range(N):
	temp_y = -1
	temp_ind = -1
	for j in range(len(R)):
		if R[j][0] < B[i][0] and R[j][1] < B[i][1] and R[j][1] > temp_y:
			temp_y = R[j][1]
			temp_ind = j
	if temp_ind != -1:
		cnt += 1
		R.pop(temp_ind)
print(cnt)

Measured memory_bytes: 3064
import math

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

def division_enumeration(num):
	ans = []
	d = math.floor(float(num)**(1/2))
	for i in range(1,d+1):
		if num % i == 0:
			ans.append(i)
			ans.append(num//i)

	return ans

trgs = sorted(set(division_enumeration(A[0]) + division_enumeration(A[1])), reverse = True)

for trg in trgs:
	cnt = 0
	cond = True
	for i in range(N):
		if A[i] % trg != 0:
			cnt += 1
			if cnt > 1:
				cond = False
				break
	if not cond:
		continue
	
	ans = trg
	break

print(ans)

Measured memory_bytes: 63984
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef long long ll;
char str[100005];
int main(void)
{
	int p = 0, r = 0;
	scanf("%s", str);
	int len = strlen(str);
	for (int i = 0; i < len; i++)
		str[i] == 'p' ? p++ : r++;
	int max = len / 2;
	max = max > p ? max - p : 0;
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 256
n = int(input())

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

cnt_1 = 0
cnt_2 = 0
for i in a:
    if i%4 == 0:
        cnt_1 += 1
    elif i%2 == 0:
        cnt_2 += 1
    
cnt_2 //=2

total = cnt_1 + cnt_2

if len(a)//2 <= total:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 15020
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<double> a(n);
	double sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];

		sum += a[i];
	}

	ll c = 0;
	for (double it : a)
	{
		if (it >= (sum / (4.0 * m)))
		{
			c++;
		}
	}

	println((c >= m ? "Yes" : "No"));
}

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


public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(s.readLine());
		int[] A = new int[n];
		for(int i=0 ; i<n ; i++) {
			A[i] = Integer.parseInt(s.readLine());
		}
		shellSort(A, n);
		for(int i=0 ; i<n ; i++)
			System.out.println(A[i]);
	}

	public static void shellSort(int[] A, int n) {
		int m = 0;
		for(int i=1 ; i<=n ; i=i*3+1){
			m++;
		}
		System.out.println(m);
		int[] G = new int[m];
		for(int i=0 ; i<G.length ; i++) {
			if(i==0)
				G[i] = 1;
			else
				G[i] = 3*G[i-1] + 1;
		}
		StringBuilder sb = new StringBuilder();
		int cnt = 0;
		for(int i=m-1 ; i>=0 ; i--) {
			sb.append(G[i] + " ");
			int re = insertionSort(A, n, G[i]);
			cnt += re;
		}
		System.out.println(sb.toString().trim());
		System.out.println(cnt);
	}

	public static int insertionSort(int[] A, int n, int g) {
		int cnt = 0;
		for(int i=g ; i<n ; i++) {
			int v = A[i];
			int j = i - g;
			while(j >= 0 && A[j] > v) {
				A[j+g] = A[j];
				j -= g;
				cnt++;
			}
			A[j+g] = v;
		}
		return cnt;
	}

}

Measured memory_bytes: 100724
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  double A, B, N;
  cin >> A >> B >> N;
  double x = min(B-1, N);
  double res = floor(A*x/B);
  cout << res << endl;
}

Measured memory_bytes: 3776
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		int X = in.nextInt();
		int Y = in.nextInt();
		int B = Y - 2*X;
		if(B>=0 &&  B%2==0) {
			int b = B/2;
			if(X-b >= 0) {
				System.out.println("Yes");
				System.exit(0);
			}
		}
		System.out.println("No");
		
		in.close();
	}
}


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

int main(){
    int r,D,x;
    cin >> r >> D >> x;
    long long X[10];
    X[0] = x * r - D;
    for (int i = 0;i < 10;i++){
        X[i + 1] = X[i] * r - D;
    }
    for (int i = 0;i < 10;i++){
        cout << X[i] << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

M = 10**6+5

count = [0]*M

for x in range(n):
    if count[a[x]] != 0:
        count[a[x]] = 2
        continue

    for i in range(a[x], M, a[x]):
        count[i] += 1

ans = 0
for x in range(n):
    if count[a[x]] == 1:
        ans += 1

print(ans)


Measured memory_bytes: 32164
#include <iostream>
using namespace std;
 
int main(){
	int a,b,c;
	
	cin >> a >> b >> c ;
	if(a<b && b<c){
		cout<< "Yes" <<endl;
	}else if(a==b || c==b ){
		cout<< "No" <<endl;
	}else if(a>b || b>c){
		cout<< "No" <<endl;
	}
	
return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef long long LL;
typedef pair<int , int > P;
const int maxn=5005;
const LL INF=1e13+5;
using i64 = long long;
int n, k, i, j, x, p[maxn], c[maxn];
LL a[maxn], b[maxn];
int main() {
    cin >> n >>k;
    LL ans=-INF;
    for (i = 1; i <= n; ++i)
        cin >> p[i];
    for (i = 1; i <= n; ++i)
        cin >> c[i];
    for(int i=1;i<=n;i++)
        for(int x=p[i], cnt=1;cnt<=k;cnt++, x=p[x])
    {
        a[cnt]=a[cnt-1]+c[x];
        b[cnt]=max(b[cnt-1], a[cnt]);
        ans=max(ans, a[cnt]);
        if(cnt==k)
            break;
        if(i==x)
        {
            ans=max(ans, a[cnt]*(k/cnt)+b[k%cnt]);
            ans=max(ans, a[cnt]*(k/cnt-1)+b[cnt]);
            break;
        }
    }



    cout <<ans;
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
#define countDigit(n)   floor(log10(n)+1)
int main()
{
    long long k, bal;
    cin >> k;

    long long x = 7;
    for(int i=1; i<k+20; i++)
    {
        if(!(x%k))
        {
            cout << i << endl;
            return 0;
        }
        x %= k;
        x = x*10+7;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n, d, a;
    cin >> n >> d >> a;
    vector<vector<int>> v(n, vector<int>(2)); // v[i][0]:場所, v[i][1]:体力
    rep(i, n) cin >> v[i][0] >> v[i][1];
    sort(all(v));

    vector<vector<int>> query;
    int nextQuery = 0;
    int nowDamage = 0;
    int ret = 0;
    rep(i, n) {
        while(query.size() > nextQuery && query[nextQuery][0] < v[i][0]) {
            nowDamage -= query[nextQuery][1];
            nextQuery++;
        }

        if(nowDamage < v[i][1]) {
            int count = mod(v[i][1] - nowDamage, a);
            query.push_back({v[i][0] + d * 2, a * count});
            nowDamage += a * count, ret += count;
        }
    }

    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 23212
#include<bits/stdc++.h>
using namespace std;
const int N=4010;
int n;char s[N];
int hed[N],to[N],nxt[N],cnt;
inline void adde(int u,int v){
	++cnt;to[cnt]=v,nxt[cnt]=hed[u];hed[u]=cnt;
}
int dep[N];
int L[N],R[N],sz[N];
int ans=-1;
inline void dfs(int x,int pre){
	if(!pre)dep[x]=0;
	sz[x]=s[x]=='1'?1:0;
	L[x]=R[x]=0;
	int hvy=0;
	for(int i=hed[x];i;i=nxt[i]){
		int v=to[i];if(v==pre)continue;
		dep[v]=dep[x]+1;
		dfs(v,x);
		sz[x]+=sz[v];
		L[v]+=sz[v];
		R[v]+=sz[v];
		R[x]+=R[v];
		if(!hvy || L[v]>L[hvy])hvy=v;
	}
	for(int i=hed[x];i;i=nxt[i]){
		int v=to[i];if(v==pre||v==hvy)continue;
		L[x]+=R[v];
	}
	L[x]=max(L[hvy]-L[x],R[x]&1);
}

int main()
{
	cin >> n;
	scanf("%s",s+1);
	for(int i=1;i<n;i++){
		int u,v;scanf("%d%d",&u,&v);
		adde(u,v);adde(v,u);
	}
	int ans=0x3f3f3f3f;
	for(int i=1;i<=n;i++){
		dfs(i,0);
		if(!L[i])ans=min(ans,R[i]>>1);
	}
	printf("%d\n",ans==0x3f3f3f3f?-1:ans);
	return 0;
}

Measured memory_bytes: 512
# むずい。総当たりしてもよい母数だが、わからない。

# https://www.planeta.tokyo/entry/3963/
# 多重キーでのソートを使えばよいみたい。

N = int(input())

rest_list = []

for i in range(N):
  city, score = input().split()
  rest_list.append([city, int(score), (i+1)])


ans_list = sorted(rest_list, key = lambda x: (x[0], -x[1]))

for i in range(N):
  print(ans_list[i][2])

  

Measured memory_bytes: 3068
import sys
def solve(n, lst_a):
    s= max(lst_a)
    c= min(lst_a)
    return s-c 

def readQuestion():
    line1 = sys.stdin.readline().rstrip()
    n = int(line1)
    line2 = sys.stdin.readline().rstrip()
    lst_a = [int(s) for s in line2.split(' ')]
    return (n, lst_a)

def main():
    n, lst_ab = readQuestion()
    answer = solve(n, lst_ab)
    print(answer)
    
if __name__ == '__main__':
    main()

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

int main() 
{
	long long int x;
	cin>>x;
	
	long long int temp = 100 , temp1 , count = 0;
	while(temp < x){
			temp1 = temp / 100;
			temp += temp1;
			count++;
	}
	
	cout<<count<<endl;
}
 
 
 


Measured memory_bytes: 3636
import Control.Applicative
import Data.List

solve :: Int -> String -> Int
solve n s = maximum (map (\i -> numContainedBoth (take i s) (drop i s)) [1..n-1])

numContainedBoth :: (Eq a) => [a] -> [a] -> Int
numContainedBoth x y = length (intersect (nub x) (nub y))

main :: IO ()
main = do
    n <- readLn
    s <- getLine
    putStrLn $ show (solve n s)


Measured memory_bytes: 1020
T = int(input())
for i in range(T):
    n = int(input())
    A = list(map(int, input().split()))
    S = input()
    dp = []
    for j in reversed(range(n)):
        a = A[j]
        for x in dp:
            a = min(a, a^x)
        if a > 0:
            if S[j] == '0':
                dp.append(a)
            elif not A[j] in dp:
                print(1)
                break
    else:
        print(0)


Measured memory_bytes: 9096
L,R=map(int,input().split())
if R-L>2018:
    print(0)
else:
    res=2020
    L%=2019
    R%=2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            res=min(res,i*j%2019)
    print(res)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (cin >> n, n) {
		int x = -n;
		for (int i = 1; i <= sqrt(n); i++) {
			if (n%i == 0) {
				x += i;
				x += n / i;
			}
		}

		int i;
		for (i = 1; i*i <= n; i++) {
			if (i*i == n)x -= i;
		}


		if (x == n)cout << "perfect number" << endl;
		else if (x < n)cout << "deficient number" << endl;
		else cout << "abundant number" << endl;
	}
	return 0;
}

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

int main(){
  ll N,K,one,co,co2;
  cin >> N >> K;
  
  vector <int> A(N);
  
  rep(i,N){
    cin >> A.at(i);
    if(A.at(i)==1)
      one=i;
  }
  if((N-1)%(K-1)==0)
    N=(N-1)/(K-1);
  else
    N=(N-1)/(K-1)+1;
  
 /* if(one<K || (one>=N-K && one<=N-1)){
    if((N-K)%(K-1)==0)
    	N=(N-K)/(K-1)+1;
    else
      N=(N-K)/(K-1)+2;
   }else{
    
    if((one+1-K)%(K-1)==0)
      co=(one+1-K)/(K-1)+1;
    else
      co=(one+1-K)/(K-1)+2;
    
    if((N-one-K)%(K-1)==0)
      co2=(N-one-K)/(K-1)+1;
    else
      co2=(N-one-K)/(K-1)+2;
    
    
    N=co+co2;
    
  }

  */
  
  
  
  cout << N << endl;
  
}

Measured memory_bytes: 640
S = input()
T = input()

def check(a, b, l):
    ans = 0
    for i in range(l):
        if a[i] != b[i]:
            ans += 1
    return ans

l_S = len(S)
l_T = len(T)
ans = l_T
for i in range(l_S - l_T + 1):
    S2 = S[i:i+l_T]
    ans = min(ans, check(S2, T, l_T))

print(ans)

Measured memory_bytes: 9060
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int a[200],b,c=0;
string s;
signed main()
{
	cin>>s;
	rep(i,4){
		a[s[i]]++;
	}
	rep(i,200){
		if(a[i]==2){
			c++;
		}
	}
	if(c==2){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
use std::io;


fn main() {
    let (n, m) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    println!("{}", (n - 1) * (m - 1));
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

const int m = 2019;

int main()
{
	string s;
	cin >> s;
	reverse(s.begin(), s.end());

	ll sum = s[0] - '0';
	vector<ll> cnt(m);
	cnt[0] = 1;
	ll ans = 0;
	ll x = 10;
	for (int i = 1; i < s.size(); i++) {
		cnt[sum]++;
		sum += (s[i] - '0')*x;
		sum %= m;
		x = x * 10 % m;
		ans += cnt[sum];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3680
from fractions import gcd
n=int(input())
ans=0
for i in range(1,n+1):
  for k in range(i,n+1):
    gc=gcd(i,k)
    for _ in range(k,n+1):
      g=gcd(gc,_)
      if i==_:
        ans+=g
      elif i==k or k==_:
        ans+=g*3
      else:
        ans+=g*6
print(ans)

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

int digit(int num){
    int ret = 0;
    while(num != 0){
        num /= 10;
        ret++;
    }

    return ret;
}

//no.2
int main(int argc, const char * argv[]) {
    int n = 0;
    cin >> n;

    int count = 0;
    for(int i = 1; i <= n; i++){
        if(digit(i) % 2 == 0){
            continue;
        }
        count++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
namespace fast {
    const int BSZ = 1 << 15; ////// INPUT
    char ibuf[BSZ];
    int ipos, ilen;

    char nc() { // next char
        if (ipos == ilen) {
            ipos = 0;
            ilen = fread(ibuf, 1, BSZ, stdin);
            if (!ilen)
                return EOF;
        }
        return ibuf[ipos++];
    }

    void rs(string &x) { // read string
        char ch;
        while (isspace(ch = nc()))
            ;
        do {
            x += ch;
        } while (!isspace(ch = nc()) && ch != EOF);
    }

    template <class T> void ri(T &x) { // read int or ll
        char ch;
        int sgn = 1;
        while (!isdigit(ch = nc()))
            if (ch == '-')
                sgn *= -1;
        x = ch - '0';
        while (isdigit(ch = nc()))
            x = x * 10 + (ch - '0');
        x *= sgn;
    }

    template <class T, class... Ts> void ri(T &t, Ts &... ts) {
        ri(t);
        ri(ts...);
    } // read ints
////// OUTPUT (call initO() at start)
    char obuf[BSZ], numBuf[100];
    int opos;

    void flushOut() {
        fwrite(obuf, 1, opos, stdout);
        opos = 0;
    }

    void wc(char c) { // write char
        if (opos == BSZ)
            flushOut();
        obuf[opos++] = c;
    }

    void ws(string s) {
        for (char c : s)
            wc(c);
    } // write string
    template <class T> void wi(T x, char after = '\0') { /// write int
        if (x < 0)
            wc('-'), x *= -1;
        int len = 0;
        for (; x >= 10; x /= 10)
            numBuf[len++] = '0' + (x % 10);
        wc('0' + x);
        for (int i = len - 1; i >= 0; i--)
            wc(numBuf[i]);
        if (after)
            wc(after);
    }

    void initO() { assert(atexit(flushOut) == 0); } /// auto-flush output
} // namespace fast
using namespace fast;

void solve() {
    string s;
    rs(s);
    ws(s + (s[s.size() - 1] == 's' ? "es" : "s"));
}

signed main() {
    initO();
        solve();
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num,init) vector<ll> name((num),(init));
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define mat(name,fnum,snum,init); vector<vector<ll>> name((fnum),vector<ll>((snum),(init)));
vec(s,10,0);
int Ans=INT_MIN;
int n;
vector<vector<vector<int>>> f(101,(vector<vector<int>>(5,vector<int>(2))));
mat(p,101,11,0);
int fst=1;

void cal(){
    if(fst){fst=0;return;}
    int ans=0;
    rep(i,n){
        int cnt=0;
        int sp=0;
        rep(j,5){
            rep(k,2){
                if(f[i][j][k]==1&&s[sp]==1){
                    cnt++;
                    
                }
                sp++;
            }
        }
        //cout<<cnt<<endl;
        ans+=p[i][cnt];
    }
    /*rep(j,10)cout<<s[j]<<" ";
    cout<<endl;
    cout<<ans<<" "<<endl;
    int kk;
    cin>>kk;
    */Ans=max(Ans,ans);
    return;
}

void dfs(int d){
    if(d==10){
        cal();
        return;
    }
    rep(x,2){
        s[d]=x;
        dfs(d+1);
    }
}

int main(){
    ip(n);
    rep(i,n){
        rep(j,5){
            rep(k,2){
                ip(f[i][j][k]);
            }
        }
    }
    
    rep(i,n){
        rep(j,11){
            ip(p[i][j]);
        }
    }
    dfs(0);
    op(Ans);
    return 0;

}

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

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

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


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

  if(d[0] != 0) {
    cout << 0 << endl;
    return 0;
  } 

  vector<lint> e(n,0);
  for(lint i=0;i<n;i++) { e[d[i]]++; }

  if(e[0] != 1) {
    cout << 0 << endl;
    return 0;
  }

  lint ans=1;
  for(lint i=2;i<n;i++) {
    for(int j=0;j<e[i];j++) {
      ans *= e[i-1]%998244353;
      ans %= 998244353;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

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

int n;
int s[100];
int dp[100][100];
ll sum;
bool flg[100];

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

	cin >> n;
	REP(i,n) cin >> s[i];
	REP(i,100) flg[i]=false;
	sort(s,s+n);
	REP(i,n) {
		sum+=s[i];
		if (s[i]%10==0) flg[i]=true;
	}
	if (sum%10==0) {
		bool ok=true;
		REP(i,n) {
			if(!flg[i]) {
				sum-=s[i];
				if (sum%10!=0) {
					ok=false;
					break;
				}
			}
		}
		if (ok) {
			cout << '0' << endl;
			return 0;
		}
	}

	cout << sum << endl;

	return 0;
}


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

int main() {
    int x1, y1, x2, y2;

    cin >> x1 >> y1 >> x2 >> y2;

    int x3, y3, x4, y4;
    x3 = x2 - (y2 - y1);
    y3 = y2 + (x2 - x1);

    x4 = x1 - (y2 - y1);
    y4 = y1 + (x2 - x1);

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define INF (1<<21)
#define N 100
 
int main(){
  int i,j,k,l,n;
  int p[N+1],m[N+1][N+1];
 
  scanf("%d",&n);
  for(i=1; i<=n; i++) scanf("%d %d",&p[i-1],&p[i]);
 
  for(i=1; i<=n; i++) m[i][i] = 0;
 
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i; k<j; k++)
	if(m[i][j] > m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]){
	  m[i][j] = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	}
    }
  }
 
  printf("%d\n", m[1][n]);
 
  return 0;
}

Measured memory_bytes: 636