akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
typedef struct{
	int card[10000];
	int sum;
}PLAYER;

void game(int n){
	int i;
	PLAYER player_a,player_b;
	player_a.sum = 0;
	player_b.sum = 0;
	for(i=0;i<n;i++){
		scanf("%d %d",&(player_a.card[i]),&(player_b.card[i]));
	}
	for(i=0;i<n;i++){
		if(player_a.card[i] > player_b.card[i]){
			player_a.sum += player_a.card[i] + player_b.card[i];
		}else if(player_a.card[i] < player_b.card[i]){
			player_b.sum += player_a.card[i] + player_b.card[i];
		}else{
			player_a.sum += player_a.card[i];
			player_b.sum += player_b.card[i];
		}
	}
	printf("%d %d\n",player_a.sum,player_b.sum);
}

int main(void) {
	int n;
	scanf("%d",&n);
	while(n != 0){
		game(n);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 676
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n,d,ans=0,cnt=0,sum=0;
    scanf("%d%d",&n,&d);
    int mat[n][d];
    int i,j,k;
    for(i=0;i<n;++i)
    {
      for(j=0;j<d;++j) 
      {
        scanf("%d",&mat[i][j]);
      }
      
      
    }
    
   
  
   for(i=0;i<n;++i)
   {
     
     for(k=i+1;k<n;++k)
     {sum=0;
       for(j=0;j<d;++j)
       {
          sum=sum+(pow((mat[i][j]-mat[k][j]),2));
       }
     
       ans=sqrt(sum);
       if((ans*ans)==sum)
           cnt++;
     }
   }
  
  printf("%d",cnt);
       
  
}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;
#define vv vector

/////////////////////////////////////////////////////

#define isIn(x,y) 0<=x&&x<H&&0<=y&&y<W

ll H, W, M;
pll hw[303030];

ll mkh[303030], mkw[303030];
ll i, j, k;

int main(){
    scanf("%lld%lld%lld", &H, &W, &M);
    rep(i,0,M){
        ll h, w;
        scanf("%lld%lld", &h, &w);
        hw[i] = {h-1, w-1};
        ++mkh[h-1];
        ++mkw[w-1];
    }

    ll hmx = 0, wmx = 0, hn = 0, wn = 0;

    rep(i,0,H){
        //printf("%lld ", mkh[i]);
        hmx = max(hmx, mkh[i]);
    }
    rep(i,0,H){
        if(hmx==mkh[i])
        ++hn;
    }
    rep(i,0,W){
        //printf("%lld ", mkw[i]);
        wmx = max(wmx, mkw[i]);
    }
    rep(i,0,W){
        if(wmx==mkw[i])
        ++wn;
    }
    //printf("%lld,%lld\n", hmx, wmx);

    j = hn * wn;
    rep(i,0,M){
        ll h = hw[i].fi;
        ll w = hw[i].se;
        if(mkh[h]==hmx&&mkw[w]==wmx){
            --j;
            //printf("b%lld,%lld\n", h, w);
        }
    }
    
    if(j==0){
        printf("%lld\n", hmx + wmx - 1);
    }else{
        printf("%lld\n", hmx + wmx);
    }
    
    return 0;
}

Measured memory_bytes: 13144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int n;
set<string> ans;

void dfs(int d,string now,int pre,char c){
	now+=c;
	if(d==n){
		ans.insert(now);
		return ;
	}
	rep(i,pre+2){
		char ne='a'+i;
		dfs(d+1,now,max((int)i,pre),ne);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n;
	dfs(1,"",0,'a');
	for(auto itr:ans){
		cout<<itr<<endl;
		//if(itr=="abcac") cout<<"hei"<<endl;
	}
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int n,t;
    cin >> n >> t;
    vector<pair<int, int> >c(n);
    vector<pair<int, int> > ans;

    rep(i,n) cin >> c[i].second >> c[i].first;
    sort(c.begin(),c.end());
    rep(i,n)
    {
        if(c[i].first <= t) ans.push_back(make_pair(c[i].second,c[i].first));
    }
    if(ans.size() ==0) cout << "TLE" << endl;
    else
    {
        sort(all(ans));
        //rep(i,n) cout << ans[i].first << endl;
        cout << ans[0].first << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int gcd(int a, int b) {
	int bigger = max(a, b);
	int smaller = min(a, b);
	if (bigger % smaller == 0)
		return smaller;
	else
		return gcd(smaller, bigger % smaller);
}
		

int main(int argc, char *argv[])
{
	int l, m, n;
	int k;
	int tmp, answer;
	cin >> k;
	answer = 0;

	for (l = 1; l <= k; l++) {
		for (m = 1; m <= k; m++) {
			for (n = 1; n <= k; n++) {
				tmp = gcd(l, m);
				answer += gcd(tmp, n);
			}
		}
	}
	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

ll n,m,ans;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    if(n>m)swap(n,m);

    if(n==1 && m==1){ans=1;}
    else if(n==1){ans=m-2;}
    else{
        ans = (n-2)*(m-2);
    }
    cout<<ans<<newl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int n;
  cin >> n;
  int d;
  cin >> d;
  int x = 2 * d + 1;
  if (n % x == 0 ) {
    cout << n / x ; }
  else {
    cout << n / x + 1; } }
    

Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i)

num = Array.new(100000, 0)
A.each do |a|
	num[a-1] += 1
end
ans = 0
m = 0

num.each do |i|
	if i > 1 then
		ans += (i-1) / 2 * 2
		m += (i-1)%2
	end
end

ans += (m+1)/2 * 2 ;
print N-ans, "\n"


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

using namespace std;

int main(void){
    int a,b;
    int num=0;
    int prag = 1;
    cin >> a >> b;
    
    while(prag < b){
     	prag +=(a-1);
        num += 1;
    }
    cout << num <<endl;
  
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
int main(){
  int a,b,c; cin >> a >> b >> c;
  int ans=c-a+b;
  if(ans<0) cout << 0;
  else cout << ans;

    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD				1000000007
#define MOD1			998244353
#define EPS				1e-9
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)

using namespace std;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int tam = 10000010;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("asd.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, su[3];
	cin>>n;
	fore(i, 0, 3) cin>>su[i];
	int ar[n];
	fore(i, 0, n) cin>>ar[i];
	int ord[] = {0, 1, 2};
	int res = MOD;
	do
	{
		int cos1 = MOD, ind1;
		fore(i, 1, 1 << n)
		{
			if(__builtin_popcount(i) < n - 1)
			{
				int parcos = (__builtin_popcount(i)-1) * 10, parsu = 0;
				fore(j, 0, n)
				{
					parsu += (((1 << j) & i) ? 1 : 0)*ar[j];
				}
				parcos += abs(parsu - su[ord[0]]);
				vector<int> segu;
				fore(j, 0, n)
				{
					if(!((1 << j) & i))
						segu.pb(ar[j]);
				}
				int ta = segu.size();
				fore(j, 1, 1 << ta)
				{
					if(__builtin_popcount(j) < ta)
					{
						int parcos2 = (__builtin_popcount(j)-1) * 10, parsu2 = 0;
						fore(k, 0, ta)
						{
							parsu2 += (((1 << k) & j) ? 1 : 0)*segu[k];
						}
						parcos2 += abs(parsu2 - su[ord[1]]);
						vector<int> ter;
						fore(k, 0, ta)
						{
							if(!((1 << k) & j))
								ter.pb(segu[k]);
						}
						int ta2 = ter.size();	
						fore(k, 1, 1 << ta2)
						{
								int parcos3 = (__builtin_popcount(k)-1) * 10, parsu3 = 0;
								fore(l, 0, ta2)
								{
									parsu3 += (((1 << l) & k) ? 1 : 0)*ter[l];
								}
								parcos3 += abs(parsu3 - su[ord[2]]);
								res = min(res, parcos + parcos2 + parcos3);
						}
					}
				}
			}
		}
	}
	while(next_permutation(ord, ord + 3));
	cout<<res<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string b;
  cin >> b;

  if (b == "A") {
    cout << "T" << endl;
  } else if (b == "T") {
    cout << "A" << endl;
  } else if (b == "C") {
    cout << "G" << endl;
  } else {
    cout << "C" << endl;
  }
 
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, p; cin>>n>>p;
	string s; cin>>s;
	ll ans=0;
	if(p==2 || p==5){
		for(int i=0; i<n; i++){
			int x=s[i]-'0';
			if(x%p==0){
				ans+=i+1;
			}
		}
		cout<<ans<<endl;
		return 0;
	}
	ll a[200020]; a[0]=0;
	reverse(s.begin(), s.end());
	ll q=1;
	for(int i=0; i<n; i++){
		int x=s[i]-'0';
		a[i+1]=(a[i]+q*x)%p;
		q=q*10%p;
	}
	map<int, int> mp;
	for(int i=0; i<=n; i++){
		mp[a[i]]++;
	}
	for(auto q:mp){
		ans+=(ll)q.second*(q.second-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2436
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  int n;
  P team[1000010];
  while(cin >> n , n){
    for(int i=0;i<n;i++){
      cin >> team[i].second;
      team[i].first = 0;
      for(int j=0;j<8;j++){
	int a; cin >> a;
	if(j % 2 == 0) team[i].first += a*60;
	else team[i].first += a;
      }
    }
    sort(team,team+n);
    cout << team[0].second << endl;
    cout << team[1].second << endl;
    cout << team[n-2].second << endl;
  }  
}

Measured memory_bytes: 8972
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = readline().rstrip().decode() + chr(96)
for i, ss in enumerate(s[::-1]):
    for m in range(ord(ss) + 1, 123):
        if chr(m) not in list(s[:-(i + 1)]):
            print(s[:-(i + 1)] + chr(m))
            exit()
print(-1)


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

int main(void) {
    long long a, b;
    int k;
    cin >> a >> b >> k;
    for(int i = 0; i < k-1; i = i + 2){
        a = a / 2;
        b = b + a;
        b = b / 2;
        a = b + a;
    }
    if(k%2 == 1){
        a = a / 2;
        b = b + a;
    }
    cout << a << " " << b << endl;
    return 0;
}

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

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

  int n, k;
  cin >> n >> k;
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }
  sort(l.begin(), l.end(), greater<int>());
  cout << accumulate(l.begin(), l.begin() + k, 0) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int i,a,b,c,d,e,f,g,h,j,x=0,y=0;
    long long int n;
    scanf("%lld",&n);
    {
    for(i=1;i<=9;i++)
    {
        a=i*1;
        b=i*2;
        c=i*3;
        d=i*4;
        e=i*5;
        f=i*6;
        g=i*7;
        h=i*8;
        j=i*9;
        if(a==n||b==n||c==n||d==n||e==n||f==n||g==n||h==n||j==n)
        {
            x=1;
        }
    }
    if(x==1)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
using namespace std;
const int MAX=50;
int main(){
    int n,m,a[MAX],b[MAX],c[MAX],d[MAX],l[MAX];
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
        cin>>b[i];
    }
    for(int i=0;i<m;i++){
        cin>>c[i];
        cin>>d[i];
    }
    int min;
    int index;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
         l[j]=abs(a[i]-c[j])+abs(b[i]-d[j]);   
        }
        for(int j=0;j<m;j++){
            if(0==j||min>l[j]){
                min=l[j];
                index=j;
            }
        }
        cout<<index+1<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] x = new int[n];
    int[] y = new int[n];
    for (int i = 0; i < n; i++) {
      x[i] = sc.nextInt();
    }
    for (int i = 0; i < n; i++) {
      y[i] = sc.nextInt();
    }
    System.out.println(distance1(x, y));
    System.out.println(distance2(x, y));
    System.out.println(distance3(x, y));
    System.out.println(distanceInf(x, y));
  }
  static double distance1(int[] x, int[] y) {
    double d = 0.0;
    for (int i = 0; i < x.length; i++) {
      d += (double)Math.abs(x[i] - y[i]);
    }
    return d;
  }
  static double distance2(int x[], int y[]) {
    double d = 0.0;
    for (int i = 0; i < x.length; i++) {
      d += (double)(Math.abs(x[i] - y[i]) * Math.abs(x[i] - y[i]));
    }
    d = Math.sqrt(d);
    return d;
  }
  static double distance3(int x[], int y[]) {
    double d = 0.0;
    for (int i = 0; i < x.length; i++) {
      d += (double)(Math.abs(x[i] - y[i]) * Math.abs(x[i] - y[i]) * Math.abs(x[i] - y[i]));
    }
    d = Math.cbrt(d);
    return d;
  }
  static double distanceInf(int x[], int y[]) {
    double d = (double)Math.abs(x[0] - y[0]);
    if (x.length > 1) {
      for (int i = 1; i < x.length; i++) {
        if (d < (double)Math.abs(x[i] - y[i])) d = (double)Math.abs(x[i] - y[i]);
      }
    }
    return d;
  }
}



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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll A, B;
    cin >> A >> B;
    cout << std::max(0LL, A - 2 * B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<mod>;

int main(){
    int n,m;cin >>n>>m;
    int d=abs(n-m);
    mint ans=0;
    if(n>m)swap(n,m);
    mint dog=1;
    mint mon=1;
    if(d==1){
        for (int i = 1; i <=n; ++i) {
            dog*=i;
        }
        for (int i = 1; i <=m; ++i) {
            mon*=i;
        }
        ans=dog*mon;
    }
    else if(d==0){
        for (int i = 1; i <=n; ++i) {
            dog*=i;
        }
        for (int i = 1; i <=m; ++i) {
            mon*=i;
        }
        ans=dog*mon*2;
    }
    cout <<ans <<endl;
}



Measured memory_bytes: 3608
def func(n):
    if n==1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True

num = int(input())
hantei = False
while hantei == False:
    hantei = func(num)
    num+=1
print(num-1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
bool used [8];
int perm[8];
int a[28], b[28];

int permutation(int pos, int n, int m){
	if(pos == n){
		bool check = true;
		for(int i=0;i<n-1;i++){
			bool check2 = false;//辺がないときにfalse
			for(int j=0;j < m;j++){
				if(a[j]-1 == perm[i] && b[j]-1 == perm[i+1]) check2 = true;
				if(b[j]-1 == perm[i] && a[j]-1 == perm[i+1]) check2 = true;
			}
			check = check2;
			if(!check) break;
		}
		if(check) return 1;
		else return 0;
	}
	int ans = 0;
	for(int i=0; i<n;i++){
		if(!used[i]){
			perm[pos] = i;
			used[i] = true;
			ans += permutation(pos + 1, n, m);
			used[i] = false;
		}
	}
	return ans;
}
int main(){
	int N, M;
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> a[i] >> b[i];
	}
	used[0] = true;
	perm[0] = 0;
	cout << permutation(1,N,M) << endl;
}

Measured memory_bytes: 256
# include <iostream>


using namespace std;


int main() {
    long long n; cin >> n;

    if (n % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }

    long long k = 10;

    long long ans = 0;
    while (n >= k) {
        ans += n/k;
        k *= 5;
    }

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



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int main(){
    int a,b;cin>>a>>b;
    REP(i,1,1e6){
        if(i*8/100 == a && i*10/100 == b){cout<<i<<endl;return 0;}
    }
    cout<<-1<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000000+7;
#define INF 100000000000000000;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N,a,over=0;cin>>N;
  vector<int> ranks(8,0);
  REP(i,0,N){
    cin>>a;
    if(1<=a&&a<400)ranks[0]=1;
    if(400<=a&&a<800)ranks[1]=1;
    if(800<=a&&a<1200)ranks[2]=1;
    if(1200<=a&&a<1600)ranks[3]=1;
    if(1600<=a&&a<2000)ranks[4]=1;
    if(2000<=a&&a<2400)ranks[5]=1;
    if(2400<=a&&a<2800)ranks[6]=1;
    if(2800<=a&&a<3200)ranks[7]=1;
    if(3200<=a)over++;
  }
  int ans=0;
  REP(i,0,8){
    ans+=ranks[i];
  }
  int min_ans=max(ans,(int)1);
  int max_ans=ans+over;
  //int max_ans=min(ans+over,(int)8);

  cout<<min_ans<<" "<<max_ans<<"\n";

}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int a, b;
  cin >> a >> b;
  if(a % 2 == 1 && b % 2 == 1)cout << "Yes" << endl;
  else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,p;
vector<int>v;
long long dp[100][5001];
long long calc(int u,int sum){
	if(u == v.size())return sum%2 == p;
	long long &ref = dp[u][sum];
	if(ref != -1)return ref;
	return ref = calc(u + 1,sum) + calc(u + 1,sum + v[u]);
}
int main(){
	//freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&p);
	memset(dp,-1,sizeof dp);
	for(int i = 0;i < n;i++){
		int a;
		scanf("%d",&a);
		v.push_back(a);
	}
	cout << calc(0,0) << endl;
}

Measured memory_bytes: 4096
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string s;  cin >> s;
  deque<char> dq;
  ll ans = 0;
  rep0(i,s.size()){
    if(dq.empty()){
      dq.push_front(s[i]);
    }else{
      if(dq.front() != s[i]){
        ans += 2;
        dq.pop_front();
      }else{
      	dq.push_front(s[i]);
      }
    }
  } 
  cout << ans;
}
      


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

ll b[114];

int main() {
	IOS();
	ll n;
	cin >> n;
	Fill(b, INF);
	for (int i = 1; i <= n - 1; i++) {
		cin >> b[i];
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += min(b[i - 1], b[i]);
	}
	dump(ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];

        for (int i = 0; i < n; i++) {
            A[i] = sc.nextInt();
        }

        int ans = solve(A);

        System.out.println(ans);
    }

    public static int solve(int[] A) {
        int ans = 0;
        boolean tf = true;

        for (int a: A) {
            if (a % 2 != 0) {
                tf = false;
            }
        }

        while (tf) {
            for (int i = 0; i < A.length; i++) {
                A[i] = A[i] / 2;
            }
            ans++;

            for (int a: A) {
                if (a % 2 != 0) {
                    tf = false;
                }
            }
        }

        return ans;
    }



}


Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int[] a = new int[4];
		for(int i = 0 ; i < s.length() ; i++) {
			if(s.charAt(i) == 'S') a[0]++;
			else if(s.charAt(i) == 'N') a[1]++;
			else if(s.charAt(i) == 'W') a[2]++;
			else a[3]++;
		}
		if((a[0] >= 1 && a[1] >= 1 || a[0] == 0 && a[1] == 0) && (a[2] >= 1 && a[3] >= 1 || a[2] == 0 && a[3] == 0)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <string.h> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;



int main(){
    //std::ifstream in("resource/input.txt");
    //std::cin.rdbuf(in.rdbuf());

    string a;
   	getline(cin,a);

	//a = "fAIR, LATER, OCCASIONALLY CLOUDY.";

	REP(i,a.size())
	{
		if(islower(a[i]))
		{
			a[i] = toupper(a[i]);
		}
		else if(isupper(a[i]))
		{
			a[i] = tolower(a[i]);
		}
		cout << a[i];
	}
	cout << endl;

    return 0;    
}




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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

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

void solution() {
  int n;
  cin >> n;
  vector<int> lb, ub;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    lb.pb(a);
    ub.pb(b);
  }
  sort(all(lb));
  sort(all(ub));
  if(n%2){
    cout << ub[n / 2] - lb[n / 2] + 1 << endl;
  }
  else cout << ub[n/2] + ub[n/2-1] - lb[n/2] - lb[n/2-1] + 1 << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  solution();
}

Measured memory_bytes: 6724
use proconio::input;
use proconio::fastout;

#[fastout]
fn main(){

    input!{
        n: usize,
        x: usize,
        t: usize,
    }

    let ans = if n%x == 0 {
       n/x * t
    }else{
         (n / x + 1) * t 
    };

    println!("{}",ans);


}

Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(void){
    int a,b;cin>>a>>b;
    if(a+b==3)co(3);
    if(a+b==4)co(2);
    if(a+b==5)co(1);   
}


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

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

using namespace std;

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

  rep(i,w+2)cout<<"#";
  cout<<endl;

  rep(i,h){
    cout<<"#";
    string s;cin>>s;
    cout<<s;
    cout<<"#"<<endl;
  }

  rep(i,w+2)cout<<"#";

  return 0;
}

Measured memory_bytes: 256
require "prime"

# n - 1 の約数で、１以外であれば題意を満たす
def solve_1(n)
  Prime.prime_division(n-1)
    .map(&:last)
    .map(&:succ)
    .inject(1,:*) - 1
end

# 約数列挙
def divisions(n)
  1.upto(n) do |i|
    break if i*i > n
    if n % i == 0
      yield i
      yield n/i if i != n/i # 平方数の場合
    end
  end
end

# nの約数について、割りきれなくなるまで破った後、mod==1なら題意を満たす
# また、n,n-1の両方に含まれる約数は無い
def solve_2(n)
  ans = 0
  divisions(n) do |i|
    next if i == 1
    m = n
    m /= i while m % i == 0
    ans += 1 if m % i == 1
  end
  ans
end

n = gets.to_i
ans = solve_1(n) + solve_2(n)
puts ans

Measured memory_bytes: 14436
#include <iostream>
#include <vector>
#include <atcoder/segtree>
using namespace std;
int64_t op(int64_t a, int64_t b) {
    return a + b;
}
int64_t e() {
    return (int64_t)0;
}
int main() {
    int64_t n, q;
    cin >> n >> q;
    vector<int64_t> a(n);
    for (auto& i : a) cin >> i;
    atcoder::segtree<int64_t, op, e> seg(a);
    for (int64_t i = 0; i < q; i++) {
        int64_t t, p, x;
        cin >> t >> p >> x;
        if (t == 0) {
            auto v = seg.get(p);
            seg.set(p, v + x);
        }
        else if (t == 1) {
            cout << seg.prod(p, x) << endl;
        }
    }
}


Measured memory_bytes: 16396
// https://atcoder.jp/contests/abc146/tasks/abc146_a

#include "algorithm"
#include "cmath"
#include "functional"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  string S;
  cin >> S;

  if (S == "SUN") drop(7);
  if (S == "MON") drop(6);
  if (S == "TUE") drop(5);
  if (S == "WED") drop(4);
  if (S == "THU") drop(3);
  if (S == "FRI") drop(2);
  if (S == "SAT") drop(1);
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vl a(4, 0);
  rep(i,n){
    string s;
    cin >> s;
    if(s=="AC"){
      a[0]++;
    }
    else if(s=="WA"){
      a[1]++;
    }
    else if(s=="TLE"){
      a[2]++;
    }
    else{
      a[3]++;
    }
  }
  cout << "AC x " << a[0] << endl;
  cout << "WA x " << a[1] << endl;
  cout << "TLE x " << a[2] << endl;
  cout << "RE x " << a[3] << endl;
}

Measured memory_bytes: 3628
N = int(input())
K = int(input())
x = list(map(int,input().split()))

c = 0

for i in range(N) :
    a = x[i]
    b = K - x[i]
    if a <= b :
        c += 2 * a
    else :
        c += 2 * b

print(c)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        ll n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <utility>

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)

typedef long long ll;
using namespace std;

int main() {
    
    int n, h, w;
    cin >> n >> h >> w;
    
    int ans = 0;
    REP(i, n) {
        int a, b;
        cin >> a >> b;
        if (a >= h && b >= w) ans++;
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
// TOPSIC001_0

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _loop_int;
#define REP(i, n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i, a, b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i, a, b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a, b) a=min((a),(b))
#define CHMAX(a, b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a, b) (abs(a-b)<EPS)
typedef complex<Real> P;


int main() {
    int N;
    cin >> N;
    REP(i, 100){
        if(i * 111 >= N){
            cout << i * 111;
            return 0;
        }
    }
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, b int
	fmt.Scan(&n)
	fmt.Scan(&b)

	switch {
	case n < 6:
		fmt.Println(0)
	case n >= 6 && n <= 12:
		fmt.Println(b / 2)
	default:
		fmt.Println(b)
	}
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl b(n-1);
  REP(i,n-1) cin >> b[i];
  ll ans = b[0]+b[n-2];
  REP(i,n-2){
    ans += min(b[i],b[i+1]);
  }
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 256
def setup_edges(matrix)
  edges = []
  matrix.each_with_index do |row, ind_row|
    row.each_with_index do |col, ind_col|
      if col >= 0 then
        edges << [ind_col+1, ind_row+1, col]
      end
    end
  end
  return edges.sort_by {|edge| edge[2]}
end


def solve(edges)
  sum = 0
  vertices = Hash.new
  (edges.size).times do |i|
    vertices[i] = i
  end

  until edges.empty? do
    edge = edges.shift
    v1, v2 = vertices[edge[0]-1], vertices[edge[1]-1]
    next if v1 == v2
    sum += edge[2]
    min_id = [v1, v2].min
    vertices.each do |key, val|
      vertices[key] = min_id if val == v1 || val == v2
    end
  end
  return sum
end


# main
n = gets.chomp.to_i
matrix = []
(n).times do 
  matrix << gets.chomp.split.map(&:to_i)
end

edges = setup_edges(matrix)
puts solve(edges)

Measured memory_bytes: 9364
const main: number = (input) => {
  const input = input.split("\n");
  const N = parseInt(input[0], 10);
  const K = parseInt(input[1], 10);
  const X = parseInt(input[2], 10);
  const Y = parseInt(input[3], 10);
  
  if (N>K) {
      console.log(K*X+(N-K)*Y);
  }else{
    console.log(N*X);
  }
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N;
  int C[50], V[50];
  cin >> N;
  for(int i=0; i<N; ++i)
  {
    cin >> V[i];
  }
  for(int i=0; i<N; ++i)
  {
    cin >> C[i];
  }
  int ans = 0;
  for(int bit=0; bit<(1<<N); ++bit)
  {
    int x = 0, y = 0;
    for(int i=0; i<N; ++i)
    {
      if((1<<i)&bit)
      {
        x += V[i];
        y += C[i];
        if(ans < (x-y))
          ans = x-y;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
int main() {
	ll k, a, b;
	cin >> k >> a >> b;
	ll count = 0;
	if (a < k && a <= b) {
		cout << -1 << endl;
	}
	else {
		if (a >= k) {
			cout << 1 << endl;
		}
		else {
			count = k - a;
			if (count % (a - b) == 0) {
				cout << count / (a - b)*2 + 1 << endl;
			}
			else {
				cout << (count / (a - b)+1)*2 + 1 << endl;
			}
		}
	}
}

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

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

  vector<vector<int>> data(N, vector<int>(2));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> data.at(i).at(j);
    }
  }
  
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    count += data.at(i).at(1)-data.at(i).at(0)+1;
  }

   cout << count << endl;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int re(int a) {
	int ret;
	switch (a) {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		ret = 1;
		break;
	case 4:
	case 6:
	case 9:
	case 11:
		ret = 2;
		break;
	case 2:
		ret = 3;
	}
	return ret;
}

int main() {
	int a, b; cin >> a >> b;
	puts(re(a) == re(b) ? "Yes" : "No");
}

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

using namespace std;

typedef unsigned int uint;
typedef unsigned long long ll;

static const ll mod = 1'000'000'007;

// const char m[4] = { 'T', 'A', 'G', 'C' };

vector<ll> a;
vector<ll> b;
vector<ll> c;

struct eset {
	ll pri;
	int x;
	int y;
	int z;

	eset(ll _pri, int _x, int _y, int _z)
		: pri(_pri), x(_x), y(_y), z(_z)
	{ }

	// bool operator< (const eset& lh)
	// { return this->pri < lh.pri; }

};

struct DT {
	int m_x, m_y, m_z;
	vector<bool> tbl;

	DT(int x, int y, int z) : m_x(x), m_y(y), m_z(z)
		{ tbl.resize(x*y*z, false); }

	void set(int x, int y, int z)
	{ if(x < m_x && y < m_y && z < m_z) tbl[x*m_y*m_z+y*m_z+z] = true; }

	bool nn(int x, int y, int z)
	{ if(x >= m_x || y >= m_y || z >= m_z) return false;
		return ! tbl[x*m_y*m_z+y*m_z+z]; }
};

	bool operator< (const eset& lh, const eset& rh)
	{ return lh.pri < rh.pri; }

int main(int, char**)
{
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	a.resize(x);
	b.resize(y);
	c.resize(z);
	for(int i = 0; i < x; ++i)
		cin >> a[i];
	for(int i = 0; i < y; ++i)
		cin >> b[i];
	for(int i = 0; i < z; ++i)
		cin >> c[i];
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	sort(c.rbegin(), c.rend());

	priority_queue<eset> kh;
	DT dt(x, y, z);

	eset fst(a[0]+b[0]+c[0], 0, 0, 0);
	kh.push(fst);

	for (int i = 0; i < k; ++i) {
		kh.top();
		int x1, y1, z1;
		cout << kh.top().pri << "\n";
		// cout << kh.top().pri << " " << kh.top().x << " " << kh.top().y << " " << kh.top().z << "\n";
		x1 = kh.top().x;
		y1 = kh.top().y;
		z1 = kh.top().z;
		kh.pop();
		if (dt.nn(x1+1, y1, z1)) {
			eset na(a[x1+1]+b[y1]+c[z1], x1+1, y1, z1);
			kh.push(na);
			dt.set(x1+1, y1, z1);
		}
		if (dt.nn(x1, y1+1, z1)) {
			eset na(a[x1]+b[y1+1]+c[z1], x1, y1+1, z1);
			kh.push(na);
			dt.set(x1, y1+1, z1);
		}
		if (dt.nn(x1, y1, z1+1)) {
			eset na(a[x1]+b[y1]+c[z1+1], x1, y1, z1+1);
			kh.push(na);
			dt.set(x1, y1, z1+1);
		}
	}

	cout.flush();
	return 0;
}


Measured memory_bytes: 122624
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int N;
    cin >> N;
    long long int arr[N];
    long long int max;
    long long int result = 0;
    for(long long int i = 0; i < N; i++){
        cin >> arr[i];
    }
    max = arr[0];
    for(long long int i = 0; i < N; i++){
        if(arr[i] > max){
            max = arr[i];
        }
        result += max - arr[i];
    }
    cout << result;
}

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

const int INF = 1e9;
int main()
{
    int n, k;
    cin >> n >> k;
    int h[n+1];
    for(int i = 1; i <= n; i++)
        cin >> h[i];
    int dp[n+1];
    dp[1] = 0;
    dp[2] = abs(h[1]-h[2]);
    for(int i = 3; i <= n; i++){
        dp[i] = INF;
        for(int j = 1; j <= min(i-1, k); j++){
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n] << "\n";
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int  n = sc.nextInt();
     int[] p = new int[n];
     int ans=0,min=n;
     for(int i=0;i<n;i++){
       p[i]=sc.nextInt();
     }
     for(int i=0;i<n;i++){
       if(p[i]<=min){
         ans++;
         min=p[i];
       }
     }
     System.out.println(ans);
   }
}


Measured memory_bytes: 87544