akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define PI 3.141592653589793238
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in3.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    int T=1;
    // cin >> T;
    FOR1(tt, T)
    {
        //cout << "Case #" << tt << ": ";
        int x; cin >> x;
        if(x >= 30) cout << "Yes";
        else cout << "No";
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 3616
using System;
class Code_01
{
    public static void Main()
    {
        string Datas = Console.ReadLine();
        int n = int.Parse(Datas);
        int k = n / 2;
        if (n % 2 == 0)
        {

        }
        else
        {
            k++;
        }
        Console.WriteLine(k);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	bool ok = true;
	sort(a.begin(), a.end());
	if (a.back() - a[0] > 1) { ok = false; }

	if (a[0] == a.back()) {
		ok = ok && (N / 2 >= a[0] || N == a[0] + 1);
	} else {
		int cnt_min = 0, cnt_max = 0;
		for (auto v : a) {
			if (v == a[0]) { ++cnt_min; }
			if (v == a.back()) { ++cnt_max; }
		}
		if (cnt_max < 2 || a.back() <= cnt_min) { ok = false; }
		ok = ok && (cnt_max / 2 >= a.back() - cnt_min);
	}
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 640
n,c = map(int, input().split())
s = [tuple(map(int, input().split())) for _ in range(n)]
lx = [0] + [x[0] for x in s]
rx = [0] + [c-x[0] for x in s[::-1]]
lv = [0] + [x[1] for x in s]
rv = [0] + [x[1] for x in s[::-1]]
lg = [0]*(n+1)
rg = [0]*(n+1)
for i in range(1,n+1):
  lv[i] += lv[i-1]
  rv[i] += rv[i-1]
  lg[i] = lv[i] - lx[i]
  rg[i] = rv[i] - rx[i]
  if lg[i] < lg[i-1]: lg[i] = lg[i-1]
  if rg[i] < rg[i-1]: rg[i] = rg[i-1]

ans = 0
for i in range(n+1):
  ls = lg[i] + rg[n-i] - lx[i]
  rs = rg[i] + lg[n-i] - rx[i]
  if ls > ans: ans = ls
  if rs > ans: ans = rs
print(ans)
  

Measured memory_bytes: 38672
#include<iostream> 
using namespace std; 
typedef long long ll; 
int main() 
{ 
		ios::sync_with_stdio(false); 
		cin.tie(NULL); 
		ll n,m;
		cin>>n>>m; 
		ll a=0; 
		ll input;
		for(ll i=0; i<m; i++) 
		{ 
				cin>>input;
				a+=input; 
		} 
		if(n-a>=0) 
				cout<<n-a; 
		else
				cout<<-1;
		return 0; 
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll mod = 1e9 + 7;

string S;

ll N, K,A,B;
ll ans;





int main() {

	cin >> N >> A >> B;

	cout << min(A*N, B) << endl;


	return 0;
}

Measured memory_bytes: 256
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll x(n), y(n);
  rep(i, n){
    cin >> x[i] >> y[i];
  }
  ll c = 0;
  rep(i, n){
    if(x[i]==y[i]){
      c++;
      if(c >= 3) Pr(1);
    }else c = 0;
  }
  Pr(0);
}


Measured memory_bytes: 3636
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
ac = Counter(A)
comblist = [0 for i in range(max(ac.values())+1)]
if max(ac.values()) == 1:
    for i in range(N):
        print(0)
else:
    comblist[2] = 1
    for i in range(3,max(4,max(ac.values())+1)):
        comblist[i] = comblist[i-1]*i//(i-2)
    ans = {}
    anssum = 0
    for k,v in ac.items():
        if v > 1:
            anssum += comblist[v]
        if k not in ans:
            if v == 2:
                ans[k] = -1
            elif v == 1:
                ans[k] = 0
            else:
                ans[k] = comblist[v-1] - comblist[v]
    for i in A:
        print(anssum+ans[i])

Measured memory_bytes: 32020
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int m = sc.nextInt();
	
	if(n!=m && (n-m != 1 && m-n != 1)) {
	    System.out.println(0);
	    return;
	}
	

	long ans = 1;
	for(int i = 1; i<=Math.max(n,m); i++) {
	    ans *= i;
	    ans = ans % ((long)Math.pow(10,9)+7);
	}
	for(int i = 1; i<=Math.min(n,m); i++) {
	    ans *= i;
            ans = ans % ((long)Math.pow(10,9)+7);
        }
	if(n == m) {
	    ans *= 2;
	    ans = (long)(ans%((long)Math.pow(10,9)+7));
	    System.out.println(ans);
	}else {
	    System.out.println(ans);
	    
	}
	
	
	
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N, ans=0;
  cin >> N;
  for (long i = 1; i*i < N; i++) {
    if (N%i == 0) {
      if (i !=1) {
        if (N%(i-1) == N/(i-1)){
        ans += i-1;
        }
      }
      if (N%(N/i-1) == N/(N/i-1)){
        ans += N/i-1;
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

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

    if (A==B) cout << "Draw" << endl;
    else if (A==1) cout << "Alice" << endl;
    else if (B==1) cout << "Bob" << endl;
    else if (A>B) cout << "Alice" << endl;
    else cout << "Bob" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
			int n = sc.nextInt();
			 calc(n);
	}
	public void calc(int n){
		int[] masu = new int[n];
		for(int i = 0; i < n; i++){
			masu[i] = sc.nextInt();
		}
		
		int[] memo = new int[n];
		Arrays.fill(memo, -1);
		memo[0] = 0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		list.add(0);
		
		int ans = -1;
		while(list.size() != 0){
			int nowMasu = list.get(0);
			list.remove(0);
			for(int m = 1; m < 7; m++){
				int nextMasu = nowMasu + m;
				if(nextMasu >= n-1){
					ans = memo[nowMasu] + 1;
					break;
				}
				if(memo[nextMasu] == -1){
					memo[nextMasu] = memo[nowMasu] + 1;
					if(masu[nextMasu] == 0) list.add(nextMasu);
					while(masu[nextMasu] != 0){
						nextMasu = nextMasu + masu[nextMasu];
						if(nextMasu >= n-1){
							ans = memo[nowMasu] + 1;
							break;
						}
						if(memo[nextMasu] == -1){
							memo[nextMasu] = memo[nowMasu] + 1;
							if(masu[nextMasu] == 0) list.add(nextMasu);
						}
						else break;
					}
				}
				if(ans != -1) break;
			}
			if(ans != -1) break;
		}
		System.out.println(ans);
	}

	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 64376
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var H = input[0];
        var W = input[1];
        var K = input[2];

        var c = new char[H][];
        for (int i = 0; i < H; i++)
        {
            c[i] = Console.ReadLine().ToCharArray();
        }

        var result = 0;
        for (int i = 0; i < Math.Pow(2, H); i++)
        {
            var bH = Convert.ToString(i, 2).PadLeft(H, '0').ToCharArray();
            for (int j = 0; j < Math.Pow(2, W); j++)
            {
                var bW = Convert.ToString(j, 2).PadLeft(W, '0').ToCharArray();
                var black = 0;
                for (int k = 0; k < H; k++)
                {
                    for (int h = 0; h < W; h++)
                    {
                        if (bH[k] == '1' && bW[h] == '1' && c[k][h] == '#')
                        {
                            black++;
                        }
                    }
                }
                if (black == K)
                {
                    result++;
                }
            }
        }
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 28764
t = 0
h = 0

for i in range(int(input())):
    cards = input().split()
    if cards[0] > cards[1]:
        t += 3
    elif cards[0] == cards[1]:
        t += 1
        h += 1
    else:
        h += 3
        
print(str(t) + " " + str(h))

Measured memory_bytes: 7652
#include <iostream>
#include <climits>
#include <cmath>

using namespace std;

int main()
{
  int N;
  cin >> N;
  int T,A;
  double SUB = INT_MAX; // subtract between temp and A
  int H[N];
  cin >> T >> A;
  for(int i = 0; i < N; i++) cin >> H[i];

  int ans = 0;
  for(int i = 0; i < N; i++){
    double tmp = T-H[i]*0.006;
    //    cout << tmp << "\n";
    if(abs(tmp-A) < SUB){
      SUB = abs(tmp-A);
      ans = i+1;
    }
  }

  cout << ans << "\n";

  return 0;
}


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



int main(void){

	char str1[101];
	char str2[101];
	int n,i;

	int taro = 0;
	int hanako = 0;

	scanf("%d",&n);
	//printf("n???= %d\n",n);


	for(i = 0;i < n;i++){

		scanf("%s",str1);
		//printf("str1???= %s\n",str1);

		scanf("%s",str2);
		//printf("str2???= %s\n\n",str2);
		
		//printf("strcmp == %d\n\n",strcmp(str1,str2));
		
		if(strcmp(str1,str2) < 0 ){
			hanako += 3;
			//printf("??±???????????? == %d  \n",hanako);
		}
		else if(strcmp(str1,str2) > 0){
			taro += 3;
			//printf("??????????????? == %d  \n",taro);
		
		}
		else{
			taro += 1;
			hanako += 1;
		}	
		

	}

	printf("%d %d\n",taro,hanako);
	


return 0;

}

Measured memory_bytes: 604
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  ll k, x;
  cin >> k >> x;
  for(int i = - k + 1; i <= k - 1; i++) {
    cout << x + i << " \n"[i == k - 1];
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class  Main{
	public static void main(String[] args) {
		try{
			Scanner s1 = new Scanner(System.in);
			int n = s1.nextInt();
			int m = s1.nextInt();
			if(n == m)
				System.out.println("Yes");
			else
				System.out.println("No");
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
	}
}

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

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

    int L = S / 100;
    int R = S % 100;

    if(1 <= L && L <= 12)
    {
        if(1 <= R && R <= 12)
        {
            cout << "AMBIGUOUS" << endl;
        }

        else
        {
            cout << "MMYY" << endl;
        }
    }

    else if(1 <= R && R <= 12)
    {
        cout << "YYMM" << endl;
    }

    else
    {
        cout << "NA" << endl;
    }

    return 0;
}
        

Measured memory_bytes: 256
from sys import stdin
A,B = [int(x) for x in stdin.readline().rstrip().split()]
sasi = A
ans = 1
for i in range(200):
    if sasi >= B:
        break
    else:
        sasi += (A-1)
        ans += 1
if B == 1:
    ans = 0
print(ans)

Measured memory_bytes: 3060
#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>
using namespace std;

#define ALL(a) (a).begin(), (a).end()
#define INF 1e9
using ll = long long;

int main(){
    ll e;
    while(cin >> e){
        if(e == 0)break;
        ll res = INF * INF;
        for(int z = 0; z <= 100; z++){
            for(int y = 0; y <= 1000; y++){
                ll x = e - (y * y) - (z * z * z);
                if(x < 0)continue;
                res = min(res, x + y + z);
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
template <class T>
vector<ll> countVector(vector<T>v,T guard=0){
    ll size=v.size();
    v.push_back(guard);
    vector<ll>ret;
    ll count=1;
    for(int i=0;i<size;i++){
        if(v[i]==v[i+1]){
            count++;
        }else{
            ret.push_back(count);
            count=1;
        }
    }
    return ret;
}
ll gcd(ll a,ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
	init();
	ll N;cin>>N;
	vector<ll>A(N);
	vector<ll>B(N);
	vector<ll>v;
	ll ans=0;
	for(int i=0;i<N;i++){
		cin>>A[i]>>B[i];
		v.push_back(A[i]+B[i]);
		ans-=B[i];
	}
	sort(v.begin(),v.end(),greater<>());
	
	for(int i=0;i<N;i+=2){
		ans+=v[i];
	}
	cout<<ans<<endl;
}


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

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

    int a=0,b=0,c=0,k=1,counter=0;

    for(int i=s.size()-1;i>=0;i--)
    {
        if(s[i]!='/')
        {
           if(counter==0)
                {
                   a+=((s[i]-48)*k);
                    k*=10;
                }
                else if(counter==1)
                {
                    b+=((s[i]-48)*k);
                    k*=10;
                }
                else if(counter==2)
                {
                    c+=((s[i]-48)*k);
                    k*=10;
                }
        }
        else
        {
            k=1;
            counter++;
        }
    }
   // cout<<a<<" "<<b<<" "<<c;
    if(c<2019)
    {
        cout<<"Heisei"<<endl;
    }
    else if(c==2019&&b<4)
    {
        cout<<"Heisei"<<endl;
    }
    else if(c==2019&&b==4&&a<30)
    {
        cout<<"Heisei"<<endl;
    }
    else if(c==2019&&b==4&&a==30)
    {
         cout<<"Heisei"<<endl;
    }
    else
    {
        cout<<"TBD"<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int mid(int a, int b, int c) {
  int t = a;
  if (a < b) t = b;
  if (t < c) return t;
  else {
    int k = a + b - t;
    if (k > c) return k;
    else return c;
  }
}
int main () {
  int a[21];
  int N;
  cin >> N;
  for (int i = 0; i < N; i ++) cin >> a[i];
  int ans = 0;
  for (int i = 1; i < N - 1; i ++) {
    if (mid(a[i - 1], a[i], a[i + 1]) == a[i]) ans ++;
  }
  cout << ans << endl;
}


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

typedef long long int lld;

int m_flag[100001];
lld m_array[100001][2];

int main()
{
    lld n, x, m, a, answer = 0;
    int count = 1, turn_point;

    scanf("%lld %lld %lld", &n, &x, &m);

    for (int i = 0; i<=m; i++)
    {
        m_flag[i] = 0;
        m_array[i][0] = 0;
    }

    a = x;

    m_flag[count] = x;
    m_array[a][0] = count;
    m_array[a][1] = x;

    for (count = 2; count<=n; count++)
    {
        lld next_a = 0;
        next_a = (a*a)%m;

        if (m_array[next_a][0] == 0)
        {
            m_flag[count] = next_a;
            m_array[next_a][0] = count;
            m_array[next_a][1] = m_array[a][1] + next_a;
            a = next_a;
        } else {
            turn_point = m_array[next_a][0];
            count --;
            break;
        }
    }

    if (count < n)
    {

        lld left_count = n - count;

        answer = m_array[m_flag[count]][1];

        if (turn_point == count)
        {
            answer += left_count*m_flag[count];
        } else {
            answer += ((left_count)/(count - turn_point + 1))*(m_array[m_flag[count]][1] - m_array[m_flag[turn_point - 1]][1]);

            if (((left_count)%(count - turn_point + 1)) != 0)
                answer += m_array[m_flag[((left_count)%(count - turn_point + 1)) + turn_point - 1]][1] - m_array[m_flag[turn_point - 1]][1];
        }

    } else {
        answer = m_array[m_flag[count-1]][1];
    }

    printf("%lld", answer);
    
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define min(a,b) (((a)>(b))?(b):(a))
#define max(a,b) (((a)>(b))?(a):(b))
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
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 main(){
	ll n;
	ll a[5]={0,0,0,0,0};
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s[0]=='M')a[0]++;
		else if(s[0]=='A')a[1]++;
		else if(s[0]=='R')a[2]++;
		else if(s[0]=='C')a[3]++;
		else if(s[0]=='H')a[4]++;
	}
	ll res=0;
	
	for(int i=0;i<3;i++){
		for(int j=i+1;j<4;j++){
			for(int k=j+1;k<5;k++){
				res+=a[i]*a[j]*a[k];
			}
		}
	}
	cout<<res;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<ll> t(n), a(n);
    rep(i, n){
        cin >> t[i] >> a[i];
    }
    rep (i, n - 1){
        if (t[i] > t[i + 1] || a[i] > a[i + 1]){
            ll p = max((t[i] + t[i + 1] - 1)/ t[i + 1], 
                    (a[i] + a[i + 1] - 1) / a[i + 1]);
            t[i + 1] *= p;
            a[i + 1] *= p;
        }
    }
    cout << t[n - 1] + a[n - 1] << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

  vector<string> S(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  sort(S.begin(), S.end());
  
  string res;
  for (auto&& elem : S) {
    res += elem;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
K=int(input())
x=[[0] for _ in range(11)]
y=[ 0 for _ in range(11)]

x[1]=[1,2,3,4,5,6,7,8,9]
y[1]=9

for i in range(2,11):
  x[i].pop()
  for num in x[i-1]:
    last = num%10
    if last==0:
      x[i].append(10*num)
      x[i].append(10*num+1)
      y[i] +=2
    elif last==9:
      x[i].append(10*num+8)
      x[i].append(10*num+9)
      y[i] +=2
    else:
      x[i].append(10*num+(last-1))
      x[i].append(10*num+last)
      x[i].append(10*num+(last+1))
      y[i] +=3
      
#print(y)
#print(sum(y))

z=[0,y[1]]
for i in range(2,11):
 z.append(z[-1]+y[i])
#print(z)

keta=0
for i,num in enumerate(z):
  if num<=K:
    keta=i+1

s= K-z[keta-1]
#print(s)
print(x[keta][s-1])

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 100000
#define vmax 10000
#define sentinel 2000000000
#define INF (1<<29)
constexpr long long int inf = 100000000000000000;
constexpr long long int rinf = -(INT64_MAX);
static const int NIL=-1;

//cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);

vector<int> g[MAX];
int n;
bool visited[MAX];
int prenum[MAX],parent[MAX],lowest[MAX],timer;

void dfs(int current,int prev){
    // ノード current を訪問した直後の処理
    prenum[current]=lowest[current]=timer;
    timer++;

    visited[current]=true;

    for(auto next:g[current]){
        if(!visited[next]){
            //　ノード　current からノード　next へ訪問する直後の処理
            parent[next]=current;

            dfs(next,current);

            // ノード　next の探索が終了した直後の処理
            lowest[current]=min(lowest[current],lowest[next]);
        }else if(next!=prev){
            //　エッジ　current --> next が　back-edge　の場合の処理
            lowest[current]=min(lowest[current],prenum[next]);
        }
    }
    //　ノード　current　の探索が終了した直後の処理
}

void art_points(){
    for(int i=0;i<n;i++){
        visited[i]=false;
    }
    timer=1;
    //loest　の計算
    dfs(0,-1);  // 0==root

    set<int> ap;
    int np=0;
    for(int i=1;i<n;i++){
        int p=parent[i];
        if(p==0){           //rootが子を2つ以上持つかを調べる
            np++;
        }else if(prenum[p]<=lowest[i]){
            ap.insert(p);
        }
    }
    if(np>1) ap.insert(0);
    for(auto it:ap){
        cout<<it<<endl;
    }
}

int main(){
    int m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int s,t;
        cin>>s>>t;
        g[s].push_back(t);
        g[t].push_back(s);
    }

    art_points();

    return 0;
}






Measured memory_bytes: 6924
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,c,k;
    int ans = 0;
    scanf("%d%d%d%d",&a,&b,&c,&k);
    //printf("%d%d%d%d",a,b,c,k);
    if(k <= a)
    {
        ans += k;
    }
    else if(k <= a + b)
    {
        ans += a;
    }
    else
    {
        int d;
        d = k - (a + b);
        ans += a - d;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1700
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<functional>
#include<utility>
#include<string>
#include<cmath>
#include<climits>
#include<complex>
#include<random>
#include<map>
#include<regex>

using namespace std;

typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = 1e-9;    // ?¨±??????????????????????????£????????????
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define rep(i,n) for(int i=0;i<(n);++(i))

stack<string> dfs;

int main()
{
	string c;
	while (cin >> c) {
		if (c != "+"&&c != "-"&&c != "*")
			dfs.push(c);
		else {
			int num[2], r;
			for (int i = 0; i < 2; ++i) {
				stringstream sstr;
				sstr << dfs.top(); dfs.pop();
				sstr >> num[i];
			}
			if (c == "+")r = num[0] + num[1];
			else if(c == "-")r = num[1] - num[0];
			else r = num[0] * num[1];
			dfs.push(to_string(r));
		}
	}
	cout << stoi(dfs.top()) << endl;
}

Measured memory_bytes: 1280
process.stdin.on('data', function(chunk) {
    var inputs = chunk.toString().trim().split(' ');
    var W = Number(inputs[0]);
    var H = Number(inputs[1]);
    var x = Number(inputs[2]);
    var y = Number(inputs[3]);
    var r = Number(inputs[4]);

    var x0 = W - x - r;
    var x1 = W - x + r;
    var y0 = H - y - r;
    var y1 = H - y + r;

   if (x0 >=0 && x1 <= W && y0 >= 0 && y1 <= H) {
        console.log('Yes');

    } else {
        console.log('No');
    }

    // ????????????????????????
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	c := 0
	for {
		f := true
		for i, b := range a {
			if b%2 != 0 {
				f = false
				break
			}
			a[i] /= 2
		}
		if !f {
			break
		}
		c++
	}
	fmt.Println(c)
}

func nextInt() int {
	i, err := strconv.Atoi(nextWord())
	pnc(err)
	return i
}

func nextWord() string {
	sc.Scan()
	return sc.Text()
}

func pnc(err error) {
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  string s, t;
  cin>>s>>t;
  
  int n = s.size(), m = t.size();
  int ans = 2000;
  REP(i, n - m + 1){
    string ss = s.substr(i, m);
    int temp = 0;
    REP(j, m) if(ss[j] != t[j]) temp++;
    ans = min(ans, temp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#import <stdio.h>

long long f(int n, long x) {
    if (n==0) return 1LL;
    if (x<=1) return 0LL;

    long long p = 1LL<<(n+1);

    if (x<p-1LL) {
        return f(n-1,x-1);
    } else if (x==p-1) {
        return p/2LL;
    } else if (x>=2LL*p-3LL) {
        return p-1LL;
    } else {
        return p/2LL+f(n-1,x-p+1);
    }
}

int main(){
    int n;
    long long x;
    scanf("%d %lld",&n,&x);
    printf("%lld\n", f(n,x));
    return 0;
}



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

int main() {
    int k, x;
    scanf("%d%d", &k, &x);
    for (int i = x - k + 1; i < x + k; i++) {
        printf("%d ", i);
    }
    return 0;
}

Measured memory_bytes: 256
import numpy as np
n,k = map(int,input().split())
height = np.array(list(map(int,input().split())))
cost_list = np.zeros(n,dtype = int)

for m in range(1,n+1):
  if m <= k:
    cost_list[m-1] = abs(height[m-1]-height[0])
  else:
    Min = min(cost_list[m-k-1:m-1] + abs(height[m-k-1:m-1] - height[m-1]))
    cost_list[m-1] = Min
              
print(cost_list[-1])

Measured memory_bytes: 22852
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <math.h>
using namespace std;

int main(){
	int N, c = 0;
	cin >> N;
	vector<int> a(N);

	for (int i = 0; i < N; ++i){
		cin >> a[i]; 
	}
	
	for (int i = 0; i < N; ++i){
		while ((a[i] % 2) == 0){
			++c;
			a[i] >>= 1;
		}
	}



	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    char a[105];gets(a);
    for(int i=0;i<strlen(a);i++)if(a[i]=='C')
        for(int j=i+1;j<strlen(a);j++)if(a[j]=='F')
        {printf("Yes\n");return 0;}
    printf("No\n");return 0;
}

Measured memory_bytes: 128
n, k = list(map(int, input().split()))
MAX = 200001
MOD = 1000000007


fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
com = [1 for i in range(MAX)]


def cominit() :
  fac[0] = fac[1] = 1
  finv[0] = finv[1] = 1
  inv[1] = 1
  com[1] = n
  for i in range(2, MAX) :
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * int(MOD / i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD
    com[i] = com[i-1] * (n-(i-1)) * inv[i] % MOD
    
  return fac, finv, inv, com


temp = cominit()
k_1 = k%2
## x 部屋が0人になっているとして数える
ans = 0
for x in range(0, k+1) :
  ## 0人になる部屋数は n(全ての部屋数) よりも小さい
  if(x >= n) :
    break
  y = n - x
  ans += (com[x] * fac[n-1] * finv[x] * finv[y-1]) % MOD

print(ans % MOD)

Measured memory_bytes: 34712
#include<iostream>
using namespace std;
typedef long long ll;
long long a[51], p[51];
ll f(ll n, ll x);
int main() {
    ll n, x;
    cin >> n >> x;
    a[0] = p[0] = 1; //レベル0バーガー Pのみ
    for (int i = 1; i <= n; i++) {
        a[i] = 1 + a[i - 1] + 1 + a[i - 1] + 1;
        p[i] = p[i - 1] + 1 + p[i - 1];
    }
    cout << f(n, x) << endl;
}
ll f(ll n, ll x) {
    //cout << n << " " << x << endl;
    if (n == 0) { //レベル0バーガー
        if (x <= 0) { //下から0層 ないでしょ
            /* <= を == にしたら input 2 7 で事故った
             2 7
             else return p[1] + 1 + f(1, 7 - (1 + a[1] + 1) = 3 + 1 + f(1, 0)
             1 0
             レベル1バーガーの下から0層？ 0
             0 -1 ってことは else if 行ってる
             else if (0 <= 1 + a[0] = 2)
             x < 0 になるうるのか
             */
            return 0;
        } else {
            return 1;
        }
    } else if (x <= 1 + a[n - 1]) { // B + (前のバーガー)
        return f(n - 1, x - 1); //一番下のBを除いた
    } else { //上の P + (前のバーガー) + B
        return p[n - 1] + 1 + f(n - 1, x - (1 + a[n - 1] + 1));
        //下の B + (前のバーガー) + P を除く 一番上のBはどうでもいい
        //1層下のバーガーで下から、上のバーガーで除いた B + () + P を除いた残りの個数をみる
    }
}


Measured memory_bytes: 256
def digitSum(n):
    s = str(bin(n))
    s = s[2:]
    array = list(map(int, s))
    return sum(array)
N = int(input())
A = []
X = []
Y = []
res = 0
for i in range(N):
    a = int(input())
    A.append(a)
    X_temp = []
    Y_temp = []
    for j in range(a):
        x,y = map(int,input().split())
        X_temp.append(x)
        Y_temp.append(y)
    X.append(X_temp)
    Y.append(Y_temp)
for i in range(1 << N):
    judge = True
    for j in range(N):
        if (i >> j) & 1:#もしAjが正直者だったら
            for k in range(A[j]):
                if (i >> X[j][k]-1) & 1 != Y[j][k]:
                    judge = False
        """else:#もしAjが不親切ものだったら。不親切者も正しいことをいうこともある。
            for k in range(A[j]):#
                if (i >> X[j][k]-1) & 1 == Y[j][k]:
                    judge = False"""
    if judge:
        res = max(res,digitSum(i))
print(res)

Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
int main(){
int H,W;
  cin>>H>>W;
  vector<vector<char>>A(H,vector<char>(W));
  for(int i=0;i<H;i++){
  string s;
    cin>>s;
    for(int j=0;j<W;j++)
      A.at(i).at(j)=s.at(j);
  }Graph G(H*W);
  int sx[4]={-1,0,1,0};
  int sy[4]={0,-1,0,1};
  for(int i=0;i<H;i++){
  for(int j=0;j<W;j++){
    for(int k=0;k<4;k++){
    int X=i+sy[k]; int Y=j+sx[k];
      if(0<=X && X<=H-1 && 0<=Y && Y<=W-1)
        G[i*W+j].push_back(X*W+Y);
    }
  }
  }queue<int>que;
  vector<int>dist(H*W,-1);
  for(int i=0;i<H;i++){
  for(int j=0;j<W;j++){
   if(A.at(i).at(j)=='#'){
     que.push(W*i+j);
    dist.at(W*i+j)=0;
   }
  }
  }while(!que.empty()){
  int u=que.front();
    que.pop();
    for(auto v:G[u]){
    if(dist[v]!=-1)
      continue;
      else{
        dist[v]=dist[u]+1;
        que.push(v);
      }
    }
  
  }int ans=0;
  for(int i=0;i<H*W;i++)
    if(ans<dist[i])
      ans=dist[i];
  cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 64000
def solve(h, w):
    ans = float('inf')
    for x in range(1, h):
        a = x * w
        b = ((h - x) // 2) * w
        c = ((h - x) - (h - x) // 2) * w

        minimum = min(a, min(b, c))
        maximum = max(a, max(b, c))
        ans = min(abs(maximum - minimum), ans)

        b = (h - x) * (w // 2)
        c = (h - x) * (w - w // 2)
        minimum = min(a, min(b, c))
        maximum = max(a, max(b, c))
        ans = min(abs(maximum - minimum), ans)
    
    return ans


h, w = map(int, input().split())
print(min(solve(h, w), solve(w, h)))

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    char a;
    cin>>a;
    if(a<97)cout<<'A'<<endl;
    else cout<<'a'<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define INF 2147483647
#define _MATH_DEFINES_DEFINED
#define int long long
#pragma GCC optimize("O2")
using namespace std;
inline int read(void){
	int f=1,n=0;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){n=n*10+(c-'0');c=getchar();}
	return f*n;
}
struct node{
	int x,h;
};
bool cmp(node x,node y){
	return x.x<y.x;
}
int c[200005];
signed main(void){
	int n=read(),d=read(),a=read(),tot=0;
	node edge[n+1];
	for(int i=1;i<=n;i++) edge[i].x=read(),edge[i].h=read();
	sort(edge+1,edge+n+1,cmp);
	for(int i=1,j=1;i<=n;i++){
		while(j<=n&&edge[j].x<=edge[i].x+2*d) j++;
		int bomb=max((edge[i].h-c[i]*a+a-1)/a,(int)0);
		tot+=bomb;
		c[i]+=bomb;
		c[j]-=bomb;
		c[i+1]+=c[i];
	}
	cout<<tot<<endl;
	return 0;
}

Measured memory_bytes: 4992
from Queue import PriorityQueue
INF = 1<<31
v, e, r = map(int, raw_input().split())
edge = [[] for i in range(v)]
for i in xrange(e):
    a, b, w = map(int, raw_input().split())
    edge[a].append((b,w))
q = PriorityQueue()
q.put((0,r))
dist = [INF]*v
visited = [False]*v
dist[r] = 0
while not q.empty():
    d, V = q.get()
    visited[V] = True
    for t, w in edge[V]:
        if visited[t] or dist[t] < d + w: continue
        dist[t] = d + w
        q.put((d + w, t))
for i in dist:
    print "INF" if i == INF else i

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
//const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
// #define endl '\n'


ll l, a, b, MOD;

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  vector<string> v;
  for (int i = 0; i + m - 1 < n; i++) {
    string s2 = s;
    bool flag = true;
    rep (j, n) {
      if (in(j, i, i + m)) {
        if (s2[j] == '?') {
          s2[j] = t[j - i];
        }
        else {
          if (s2[j] != t[j - i]) {
            flag = false;
            break;
          }
        }
      }
      else {
        if (s2[j] == '?') s2[j] = 'a';
      }
    }
    if (flag) {
      v.push_back(s2);
    }
  }
  sort(all(v));
  if (v.size() == 0) {
    cout << "UNRESTORABLE" << endl;
  }
  else {
    cout << v[0] << endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>

int insertion_sort(long *A, int N, int g)
{
    int i, cnt = 0;
    for (i = g; i < N; i++) {
        long v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
           A[j + g] = A[j];
           j = j - g;
           cnt++;
        }
        A[j + g] = v;
    }
    return cnt;
}

int shell_sort(long *A, int N, int *G, int m)
{
    int i, cnt = 0;
    for (i = m - 1; i >= 0; i--) {
       cnt += insertion_sort(A, N, G[i]);
    }
    return cnt;
}

int main(int argc, char** argv)
{
    int i, num, g[100], m = 0; 
    long arr[1000000];
 
    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        scanf("%ld", &arr[i]);
    }

    g[0] = 1;
    for (i = 1; i < 100; i++) {
        g[i] = 3 * g[i - 1] + 1;
        if (num < g[i]) {
            m = i;
            break;
        }
    }
    
    int cnt = shell_sort(arr, num, g, m);

    printf("%d\n", m);
    for (i = m - 1; i >= 0; i--) {
        if (i == 0) {
            printf("%d\n", g[i]);
        }
        else {
            printf("%d ", g[i]);
        }
    }
    printf("%d\n", cnt);

    for (i = 0; i < num; i++) {
        printf("%ld\n", arr[i]);
    }
    return 0;
}

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

using namespace std;

typedef	unsigned long long	ull;

int main()
{
	ull N;
	ull A, B;	// A:青いボール、B:赤いボール

	cin >> N;
	cin >> A >> B;

	// 青いボールカウント
	ull tmp = N / (A + B);	// 繰り返し回数
	ull ans = tmp * A;	// 青いボールの数

	// 余りを足す
	if(N % (A + B) <= A)
		ans += N % (A + B);
	else
		ans += A;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import math, sys
MAX = pow(2, 31) - 1

#??°????????????????????§????°????????????¨???????????°??????????????????????§????
class SegmentTree():
    def __init__(self, n):
        self.TreeRange = pow(2, math.ceil(math.log2(n)))
        self.List = [MAX] * (2 * self.TreeRange - 1)

    def update(self, i, x):
        i += self.TreeRange - 1
        self.List[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.List[i] = min (self.List[i * 2 + 1], self.List[i * 2 + 2])

    def find(self, s, t, i=0, left=0, right=float("inf")):
        #??¢?´¢????±?????????????????????§????????°?????§???????????????
        if right <= s or t <= left:
            return MAX
        #??¢?´¢????±?????????????????????§????????°??????????????????????????????
        elif s <= left <= right <= t:
            return self.List[i]
        #??¢?´¢????±????????????????????????????????????°????????????????????°
        else:
            l = self.find(s, t, i * 2 + 1, left, (left + right) // 2)
            r = self.find(s, t, i * 2 + 2, (left + right) // 2, right)
            return min(l, r)

_input = sys.stdin.readlines()
n,q = map(int, _input[0].split())
qlist = map(lambda x:x.split(), _input[1:])
ST = SegmentTree(n)

for q in qlist:
    cmd, x, y = map(int, q)
    if cmd == 0:
        ST.update(x, y)
    elif cmd == 1:
        print(ST.find(x,y + 1, right = ST.TreeRange))

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
const long long INFLL = 1e18;

using namespace std;

const int MAXN = 1000;

int a[MAXN + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("input.txt", "w", stdout);

    int n;
    cin >> n;

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

    int cur = -1;
    int ans = 0;

    for (int i = 1; i < n; i++) {
        if (a[i - 1] == a[i]) {
            a[i] = cur;
            --cur;
            ++ans;
        }
    }

    cout << ans << "\n";
    return 0;
}

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

const int N = 1e5 + 5, mod = 1e9 + 7;

bool check(int a[], int n)
{
    for (int i = 1; i < n; i++)
        if (a[i] <= a[i - 1])
            return false;
    return true;
}

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    int a[52];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            swap(a[i], a[j]);
            if (check(a, n))
                return cout << "YES", 0;
            swap(a[i], a[j]);
        }
    }
    cout << "NO";
    return 0;
}

Measured memory_bytes: 256
X, Y = map(int, input().split())

def gcd(_x, _y) :
    x = min(_x, _y)
    y = max(_x, _y)
    
    if x == 0 or y == 0 :
        return 0
    if x == y :
        return X
    elif y % x == 0 :
        return min(x, y)
    elif y % x != 0 :
        return gcd(y % x, x)
        
print(gcd(X, Y))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,W;cin>>N>>W;
    long w[N],v[N];
    for(int i=0;i<N;i++){
        cin>>w[i]>>v[i];
    }long dp[N+1][W+1];
    for(int i=0;i<=W;i++){
        dp[0][i]=0;
    }for(int j=0;j<N;j++){
        for(int k=0;k<=W;k++){
            if(w[j]>k){
                dp[j+1][k]=dp[j][k];
            }else{
                dp[j+1][k]=max(dp[j][k],dp[j][k-w[j]]+v[j]);
            }
        }
    }cout<<dp[N][W]<<endl;
}

Measured memory_bytes: 79104
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int[] a = new int[N];
    boolean fg = true;
    int count = 0;
    
    for (int i=0;i<a.length; i++) {
      a[i] = sc.nextInt();
    }
    
    do {
      for (int j=0; j<a.length; j++) {
          if (a[j]%2 != 0) {
              fg = false;
          }
      }

      if (fg == true) {
        for (int i=0; i<a.length; i++) {
          a[i] = a[i]/2;
        }
        count++;
      }
    }while(fg == true);
    
    System.out.println(count);
  }
}

Measured memory_bytes: 35928
# import numpy as np
# import math
import sys
input = sys.stdin.readline


def main():
    N,x = map(int,input().split())
    a = list(map(int,input().split()))

    res = 0

    if a[0] >= x:
        res += a[0] - x
        a[0] = x
        # print(res)
    # print(res)

    temp = a[0] + a[1] - x
    if temp >= 0:
        res += temp
        a[1] -= temp
    # print(res)

    for i in range(1,N-1):
        temp = a[i] + a[i+1] - x
        if temp > 0:
            res += temp
            if a[i+1] >= temp:
                a[i+1] -= temp
            elif a[i+1] < temp:
                a[i+1] = 0
                a[i] -= temp - a[i+1]



    # print(a)
    print(res)



main()


Measured memory_bytes: 14776