akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {
	int n, l; cin >> n >> l;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	ssort(s);
	string ans;
	for (int i = 0; i < n; i++) {
		ans+= s[i];
	}
	cout << ans;

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int N, D;
	scanf("%d%d", &N, &D);
	int cur = D;
	vector<int> d(N + 1), pref(N + 1, D);
	vector<ll> suf(N + 2);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &d[i]);
		cur = min(cur, abs(cur - d[i]));
		pref[i] = cur;
	}
	for (int i = N; i >= 1; --i) {
		suf[i] = (suf[i + 1] + 1) * 2 <= d[i] ? suf[i + 1] : suf[i + 1] + d[i];
	}
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		int q;
		scanf("%d", &q);
		int pos = pref[q - 1];
		if (suf[q + 1] < pos) printf("YES\n");
		else printf("NO\n");
	}
}


Measured memory_bytes: 9728
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define io std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int mo=998244353; const int mod=1000000007;

const int manx=100000+5;

set<string>s;

int main(){
    io;
    ll n; cin>>n;
    while(n--){
        string sb; cin>>sb;
        s.insert(sb);
    }
    cout<<s.size();
    return 0;
}


Measured memory_bytes: 19252
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int n, k;
vector<int> w;

void input() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    w.push_back(t);
  }
}

bool check(int p) {
  int c = 0;
  int t = 0;
  for(auto x : w) {
    if (x > p) {
      return false;
    }
    if (t + x > p) {
      ++c;
      t = x;
    } else {
      t += x;
    }
  }
  if (t > 0) {
    ++c;
  }
  return c <= k;
}

int solve() {
  int s = 0;
  for (auto x : w) {
    s += x;
  }

  int l = 1;
  int r = s;
  int a = s;
  while (l < r) {
    int m = (l + r) / 2;
    if (check(m)) {
      a = m;
      r = m;
    } else {
      l = m + 1;
    }
  }

  return a;
}

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

  input();
  int ans = solve();
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a,b;cin>>a>>b;
  string ans;
  if(a>b) rep(i,a) ans+=to_string(b);
  if(b>a) rep(i,b) ans+=to_string(a);
  if(a==b) rep(i,a) ans+=to_string(b);
  print(ans);
  return 0;
}

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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
int X, Y;

int main(void) {
    scanf("%d %d", &X, &Y);

    if (X==1) ans += 300000;
    else if (X==2) ans += 200000;
    else if (X==3)ans += 100000;

    if (Y==1) ans += 300000;
    else if (Y==2) ans += 200000;
    else if (Y==3) ans += 100000;

    if (X==1 && Y==1) ans += 400000;        

  
    printf("%d\n", ans);

	return 0;
}


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

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = ReadInt();
            if (r < 1200) WriteLine("ABC");
            else if (r < 2800) WriteLine("ARC");
            else WriteLine("AGC");

        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
import java.util.*;
//import java.lang.Math;
public class Main{

    public static int ten[]={1,10,100,1000,10000,100000,1000000,10000000};

    public static int digit(int N,int K){
        return (N/ten[7-K])%10;
    }
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        Map<Integer,Integer> pz=new HashMap<Integer,Integer>();
        Map<Integer,Boolean> reach=new HashMap<Integer,Boolean>();
        pz.put(1234567,0);
        reach.put(1234567,true);
        Queue<Integer> q=new ArrayDeque<Integer>();
        q.add(1234567);
        while(q.size()>0){
            int now=q.poll();
            int dis=pz.get(now);
            int cnt=0;
            for(int i=0;i<10;i++){
                int p=now;
                if(i<3 ||(i>=4 && i<=6)){
                    int a=digit(p,i);
                    int b=digit(p,i+1);
                    if(a!=0 && b!=0) continue;
                    int minus=a*ten[7-i]+b*ten[7-i-1];
                    p-=minus;
                    p+=b*ten[7-i]+a*ten[7-i-1];
                    if(reach.containsKey(p)) continue;
                    else{
                        pz.put(p,dis+1);
                        reach.put(p,true);
                        q.add(p);
                    }
                }
                else{
                    int a=digit(p,cnt);
                    int b=digit(p,cnt+4);
                    int s=cnt;
                    cnt++;
                    if(a!=0 && b!=0) continue;
                    int minus=a*ten[7-s]+b*ten[7-s-4];
                    p-=minus;
                    p+=b*ten[7-s]+a*ten[7-s-4];
                    if(reach.containsKey(p)) continue;
                    else{
                        pz.put(p,dis+1);
                        reach.put(p,true);
                        q.add(p);
                    }
                }
            }
        }
        while(sc.hasNext()){
            int N=0;
            for(int i=0;i<8;i++){
                int a=sc.nextInt();
                N+=a*ten[7-i];
            }
            System.out.println(pz.get(N));
        }
    }
}


Measured memory_bytes: 47824
def readinput():
    h=int(input())
    a=list(map(int,input().split()))
    a.insert(0,-1)
    return h,a

def maxHeapify(a,i):
    h=len(a)-1
    l=i*2
    r=i*2+1
    if (l<=h) and (a[l]>a[i]):
        largest=l
    else:
        largest=i
    if (r<=h) and (a[r]>a[largest]):
        largest=r
    
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        maxHeapify(a,largest)

def buildHeap(a):
    h=len(a)-1
    for i in range(h//2, 0, -1):
        maxHeapify(a,i)


def main(h,a):
    buildHeap(a)
    return a

if __name__=='__main__':
    h,a=readinput()
    ans=main(h,a)
    print(' ',end=''); print(' '.join(map(str,a[1:])))


Measured memory_bytes: 64200
#include <iostream>

using namespace std;

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

	long sum = 0;
	for(int i = 1; i <= x; ++i){
		if(i%3 > 0){
			if(i%5 > 0){
				sum += i;
			}
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main (void){
  int a, b;
  if(scanf("%d %d",&a, &b) != 2)
    return -1;
  
  if((a * b) == 15)
    printf("*");
  
  else if ((a + b) == 15)
    printf("+");
  else
    printf("x");
  
  return 0;
}


Measured memory_bytes: 128
H,W,K=map(int,input().split())
c=[list(input()) for i in range(H)]
count=0
for bit_h in range(1<<H):
    for bit_w in range(1<<W):
        black=0
        for shift_h in range(H):
            for shift_w in range(W):
                if c[shift_h][shift_w]=="#" and (bit_h>>shift_h)&1 and (bit_w>>shift_w)&1:
                    black+=1
        if black==K:
            count+=1
print(count)

Measured memory_bytes: 9204
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long int ll;
void swap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
ll asc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
ll desc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
ll max(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y){return x>y?y:x;}

int main(){
    ll a,b,c,d;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);

    ll tmp1,tmp2,tmp3;
    if(c>d){
        tmp1=c;
        tmp2=d;
    }else{
        tmp1=d;
        tmp2=c;
    }
    //printf("tmp1:%lld tmp2:%lld\n",tmp1,tmp2);
    while(1){   
        tmp3=tmp1%tmp2;
        //printf("tmp1:%lld tmp2:%lld tmp3:%lld\n",tmp1,tmp2,tmp3);
        if(tmp3==0)break;
        tmp1=tmp2;
        tmp2=tmp3;

    }
    ll gcd=tmp2;
    ll aaa=(c*d/gcd);

    //printf("gcd:%lld\n",gcd);
    ll a_x,b_x;
    a_x=a-(a/c+a/d-(a/aaa));
    b_x=b-(b/c+b/d-(b/aaa));
    //printf("%lld %lld\n",a_x,b_x);
    //rintf("%lld\n",a_x-b_x);
    ll sa=a_x-b_x;
    if(sa<0)sa=sa*-1;
    if(a%c!=0&&a%d!=0)printf("%lld\n",sa+1);
    else printf("%lld\n",sa);
    
    /*for(int i=1;i<=b;i++){
        
    }*/

}

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

using namespace std;

string s;

typedef long long ll;

ll dp(ll at, ll c, ll sum)
{
	c = c * 10 + s[at]-'0';
	if (at == s.length() - 1) return sum + c;
	return dp(at + 1, c, sum) + dp(at + 1, 0, sum + c);
}

int main()
{
	cin >> s;
	cout << dp(0ll, 0ll, 0ll) << '\n';
	return 0;
}



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

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int k = 0;
	for (int i = 0; i < 1e7 ; i++){
		k = (k * 10 + 7) % n;
		if (k == 0){
			cout << i + 1 << endl;
			return 0;
		}	 
	} 
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

int n, m, k, p;
vector<Pii> e[1000];
vector<Pii> st;

vector<int> dij(int v){
	vector<int> ct(n,0x3f3f3f3f);
	priority_queue < Pii, vector<Pii>, greater<Pii>> pq;
	ct[v] = 0;
	pq.push(Pii(0, v));
	while (!pq.empty()) {
		Pii p = pq.top(); pq.pop();
		if (p.first > ct[p.second]) continue;
		for (auto to : e[p.second]) {
			int nto = to.first;
			int nc = p.first + to.second;
			if (nc < ct[nto]) {
				ct[nto] = nc;
				pq.push(Pii(nc, nto));
			}
		}
	}
	return ct;
}

int main(){
	cin >> n >> m >> k >> p;
	p--;
	FOR(i, m){
		int x, y, w; cin >> x >> y >> w;
		x--; y--;
		e[x].push_back(Pii(y, w));
		e[y].push_back(Pii(x, w));
	}

	FOR(i, k) {
		int s, t; cin >> s >> t;
		s--; t--;
		st.emplace_back(s, t);
	}

	vector<int> use;
	for (auto kv : st) {
		use.push_back(kv.first);
		use.push_back(kv.second);
	}
	use.push_back(p);

	vector<vector<int> > tbl;

	for (auto x : use) {
		auto ct = dij(x);
		tbl.emplace_back();
		for(auto u :use) {
			tbl.back().push_back(ct[u]);
		}
	}

	static int dp[13][1 << 13];
	memset(dp, 0x3f, sizeof(dp));
	dp[sz(use)-1][1 << (sz(use) - 1)] = 0;
	for (int S = 1; S < (1 << sz(use)); S++) {
		FOR(j, sz(use)){
			if (dp[j][S] >= 0x3f3f3f3f) continue;
			FOR(k, sz(use)) {
				// j -> k
				if (k % 2 == 1) {
					if ((S & (1 << k - 1)) == 0) continue;
				}
				dp[k][S | (1 << k)] = min(dp[k][S | (1 << k)], dp[j][S] + tbl[j][k]);
			}
		}
	}

	int ans = 0x3f3f3f3f;
	FOR(i, sz(use)){
		ans = min(ans, dp[i][(1 << sz(use)) - 1]);
	}

	if (ans >= 0x3f3f3f3f) puts("Cannot deliver");
	else cout << ans << endl;
}

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

int main() {
  int X;
  cin >> X;
  
  int amari = X%100;
  int shou = X/100;
  
  if(X>=100 && amari<=shou*5){cout << 1 << endl;}
  else{cout << 0 << endl;}
  
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int n;
vector<ll> ans;

void calc(ll nm, bool b1, bool b2, bool b3) {
        if (nm > 1e9) return;
        if (b1 && b2 && b3)ans.push_back(nm);
        calc(nm * 10 + 3, 1, b2, b3);
        calc(nm * 10 + 7, b1, 1, b3);
        calc(nm * 10 + 5, b1, b2, 1);
        return;
}

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> n;
        calc(0, 0, 0, 0);
        sort(ans.begin(), ans.end());
        cout << upper_bound(ans.begin(), ans.end(), n)-ans.begin()<<"\n";
        return 0;
}


Measured memory_bytes: 640
// https://atcoder.jp/contests/abc088/tasks/abc088_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int n, a;
  string r;

  cin >> n >> a;

  r = (n % 500) - a <= 0 ? "Yes" : "No";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
S = input()
T = input()
 
convert = dict()
 
answer = 'Yes'

for s, t in zip(S, T):
    #同じsに違うt
    if s in convert and convert[s] != t:
        answer = 'No'
        break
    #同じsに同じt
    else:
        convert[s] = t
 
after = convert.values()
#tの要素の総数とtの要素の種類を比べて、相違がある
#=sが全て相違するのに対しtの値が等しいペアがある=同じtに対して違うsが存在する
if len(after) != len(set(after)):
    answer = 'No'
 
print(answer)

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

int main(){
    int s;
    cin >> s;
    int cou=0;
    //string hoge=s;

    int fs,bs;

    fs = bs = s;
    for(int i=0;i<s;i++){
        string fst=to_string(fs);
        //int bst=bs;
        string bst=to_string(bs);
        string hoge=fst;
        string huga=bst;
        reverse(hoge.begin(),hoge.end());
        reverse(huga.begin(),huga.end());
        if(hoge==fst){
            cout << fs << endl;
            break;
        }else if(huga==bst){
            cout << bs << endl;
            break;
        }
        fs--;
        bs++;
    }

}

Measured memory_bytes: 3288
package main
import "fmt"
const mod int64 = 1000000007
func main() {
  var l string
  fmt.Scan(&l)
  same := int64(2)
  diff := int64(1)
  for i:=1;i<len(l);i++ {
    if l[i:i+1] == "1" {
      same,diff = (2*same)%mod,(3*diff+same)%mod
    } else {
      diff = (3*diff)%mod
    }
  }
  fmt.Println((same+diff)%mod)
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N,K;
vector<ll> v;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>K;
    v.resize(N);
    ll S=0;
    rep(i,0,N){
        cin>>v[i];
        S+=v[i];
    }
    ll ans=-1e15;
    rep(i,0,N+1){
        rep(j,0,min(K-i+1, N-i+1)){
            priority_queue<ll> p;
            rep(k,0,i){
                p.push(v[k]);
            }
            rep(k,0,j){
                p.push(v[N-1-k]);
            }
            ll res=0;
            rep(k,0,2*(i+j)-K){
                res+=p.top();
                p.pop();
            }
            while(!p.empty()&&p.top()>0){
                res+=p.top();
                p.pop();
            }
            ans=max(ans,res);
        }
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
d=[]
for i in range(m):
  b,c=map(int,input().split())
  d.append([b,c])
d=sorted(d, key=lambda x: x[1], reverse=True)
i=0
j=d[0][1]
k=0
while a[i]<j:
  a[i]=j
  d[k][0]-=1
  if d[k][0]==0:
    k+=1
    if k==m:
      break
    else:
      j=d[k][1]
  i+=1
  if i==n:
    break
print(sum(a))

Measured memory_bytes: 80748
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

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

    if(N % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    int flag = 1;
    rep(i, N / 2) {
        if(s[i] != s[i + N / 2]) {
            flag = 0;
            break;
        }
    }

    if(flag == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a[13],b,c,i,sum=0,d,e=0;
while(1){
scanf("%d\n",&b);
if(b==0){
break;
}
else{
for(i=0;i<12;i++){
scanf("%d %d\n",&c,&d);
a[i]=c-d;
}
for(i=0;i<12;i++){
if(sum>=b){
break;
}
else{
sum=sum+a[i];
e++;
}
}
if(sum>=b){
printf("%d\n",e);
}
else{
printf("NA\n");
}
sum=0,e=0;
}
}
return 0;
}



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

int main() {
    int n; scanf("%d", &n);
    vector<int> x(n), y(n);
    for (int i = 0; i < n; ++i) scanf("%d%d", &x[i], &y[i]);

    constexpr int kMod = 998244353;
    int ans = 1;
    for (int i = 0; i < n; ++i) ans = (ans + ans) % kMod;
    (ans += kMod - (n + 1)) %= kMod;

    auto GetSlope = [&](int i, int j) {
        int dx = x[i] - x[j], dy = y[i] - y[j];
        if (dx == 0) return make_pair(0, 1);
        if (dy == 0) return make_pair(1, 0);
        int g = __gcd(abs(dx), abs(dy));
        dx /= g, dy /= g;
        if (dx < 0) dx = -dx, dy = -dy;
        return make_pair(dx, dy);
    };

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int cnt = 2;
            auto s = GetSlope(i, j);
            bool ok = true;
            for (int k = 0; k < n; ++k) {
                if (k == i || k == j) continue;
                auto t = GetSlope(i, k);
                if (s == t) {
                    cnt++;
                    ok &= k > j;
                }
            }
            if (!ok) continue;
            int v = 1;
            for (int k = 0; k < cnt; ++k) v = (v + v) % kMod;
            (v += kMod - (cnt + 1)) %= kMod;
            (ans += kMod - v) %= kMod;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

int house[4][3][10];

int main() {
    memset(house, 0, sizeof house);
    int n, b, f, r, v;
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin >> b >> f >> r >> v;
        b--; f--; r--;
        house[b][f][r] += v;
    }
    for (int i=0; i<4; ++i) {
        cout << (i == 0 ? "" : "####################\n");
        for (int j=0; j<3; ++j) {
            for (int k=0; k<10; ++k) {
                cout << " " << house[i][j][k];
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a*b;
        int length = (a+b)*2;
        System.out.println(area + " " + length);
    }
}



Measured memory_bytes: 26128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		long[] t = new long[n];
		for (int i = 0; i < n; i++) {
			t[i] = sc.nextLong();
		}
		long min = 1;
		for (int i = 0; i < n; i++) {
				min = lcm(min, t[i]);
		}
		System.out.println(min);
	}

	private static long lcm(long m, long n) {
		return m / gcd(m, n) * n;
	}

	private static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}
}


Measured memory_bytes: 23124
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s,t;
    cin>>s>>t;
    s+=s;
    for(int i=0;i<t.size();i++){
        if(s.substr(i,t.size())==t){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const long long mod = 998244353;

long long gyakugenn(int n);//計算量O(N^2)->時間切れ
long long modinv(long long a, long long m);//計算量O(logp)->間に合う
long long myModPower(long long a, long long m);//累乗のmodの計算
long long improvedgyakugenn(int n);

int main()
{
	long long N, M, K; cin >> N >> M >> K;
	vector<long long> m(N, 0);
	vector<long long> c(N, 0);
	m.at(N - 1) = M;
	c.at(0) = 1;
	for (int i = N - 1; i > 0; i--) m.at(i - 1) = (M - 1) * m.at(i) % mod;
	for (int i = 1; i < N; i++) {
		int x;
		x = c.at(i - 1) * (N - i) % mod;
		c.at(i) = x * improvedgyakugenn(i) % mod;
	}
	long long ans = 0;
	for (int k = 0; k < K + 1; k++) {
		
		ans =(ans + c.at(k) * m.at(k)) % mod;
	}
	cout << ans << endl;
    return 0;
}

long long gyakugenn(int n) {
	for (int i = 0; i < n; i++) {
		if ((mod*i + 1) % n == 0) return (mod*i + 1) / n;
	}
}

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

long long improvedgyakugenn(int n) {
	return myModPower(n, mod - 2);
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

Measured memory_bytes: 6328
n = gets.to_i

score = 0
out_cnt = 0
base_data = 0
out_cnt_n = 0

loop do
  
  data = gets.chomp
  
  case data
  when "HIT"
    base_data += 1
    if base_data == 4
      score += 1
      base_data = 3
    end
    
  when "HOMERUN"
    score += base_data + 1
    base_data = 0
    
  when "OUT"
    out_cnt += 1
    if out_cnt == 3
      puts score
      out_cnt = 0
      base_data = 0
      score = 0
      out_cnt_n += 1
      if out_cnt_n == n
        break
      end
    end
    
  end
end

Measured memory_bytes: 6092
A= input()
A= int(A)

count = 0
for i in [1,2,3,4,5,6,7,8,9]:
  for j in [1,2,3,4,5,6,7,8,9]:
    if i * j == A:
      count += 1

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

Measured memory_bytes: 38384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int inf=1e9;

int n,x[1005],y[1005];

int head[1005],tot,pre[1005],to[1005];
void addedge(int u,int v) {to[++tot]=v;pre[tot]=head[u];head[u]=tot;}

int dp[5005];
bool o;
void dfs(int u) 
{
	for (int i=head[u];i;i=pre[i]) dfs(to[i]);
	
	for (int i=1;i<=x[u];i++) dp[i]=inf;
	dp[0]=0;
	for (int i=head[u];i;i=pre[i]) 
		for (int v=to[i],tmp,j=x[u];j>=0;j--) 
		{
			tmp=inf;
			if (j>=x[v]) tmp=min(tmp,dp[j-x[v]]+y[v]);
			if (j>=y[v]) tmp=min(tmp,dp[j-y[v]]+x[v]);
			dp[j]=tmp;
		}
	y[u]=inf;
	for (int i=0;i<=x[u];i++) y[u]=min(y[u],dp[i]);
	if (y[u]>=inf) 
	{
		//printf("-%d\n",u);
		o=true;
	}
}

int main()
{
	scanf("%d",&n);
	for (int p,i=2;i<=n;i++) 
	{
		scanf("%d",&p);
		addedge(p,i);
	}
	for (int i=1;i<=n;i++) scanf("%d",&x[i]);
	dfs(1);
	if (o) printf("IMPOSSIBLE");else printf("POSSIBLE");
	return 0;
}


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

int main(void){
    int a,b,k;
    set<int>s;
    cin >> a >> b >> k;
    for(int i=a;i<=min(b,a+k-1);i++){
        s.insert(i);
    }
    for(int i=b;max(a,b-k+1)<=i;i--){
        s.insert(i);
    }
    set<int>::iterator it;
    for(it=s.begin();it!=s.end();it++){
        cout << *it << ' ' << endl;
    }
    return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<double> x(n), y(n);
    REP(i, n) { cin >> x[i]>>y[i];}
    double ans=0;
    REP(i, n)
        FOR(j,i+1, n){
            ans += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        }
        ans = ans * 2 / n;
        cout << std::setprecision(20) << ans << "\n";

        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005,dir[2]={-1,1},inf=1e8;
struct node{int x,y,d;}; vector<node> R1,C1,R2,C2;
int x[N][2],y[N][2],r[N],c[N];
int n,m,Q,a,b,u,v;
char sr[N],sc[N];

void dfs1R(int k,int a,int b,int d);
void dfs1C(int k,int a,int b,int d);
void dfs2R(int k,int a,int b,int d);
void dfs2C(int k,int a,int b,int d);

void dfs1R(int k,int a,int b,int d){
	if(a<1||a>n||b<1||b>m) return;
	R1.pb((node){a,b,d});
	if(!k) return;
	dfs1C(k-1,a,b,d);
	dfs1C(k-1,a,y[b][r[a]],d+abs(y[b][r[a]]-b));
}
void dfs1C(int k,int a,int b,int d){
	if(a<1||a>n||b<1||b>m) return;
	C1.pb((node){a,b,d});
	if(!k) return;
	dfs1R(k-1,a,b,d);
	dfs1R(k-1,x[a][c[b]],b,d+abs(x[a][c[b]]-a));
}
void dfs2R(int k,int a,int b,int d){
	if(a<1||a>n||b<1||b>m) return;
	R2.pb((node){a,b,d});
	if(!k) return;
	dfs2C(k-1,a,b,d);
	dfs2C(k-1,a,y[b][1-r[a]],d+abs(y[b][1-r[a]]-b));
}
void dfs2C(int k,int a,int b,int d){
	if(a<1||a>n||b<1||b>m) return;
	C2.pb((node){a,b,d});
	if(!k) return;
	dfs2R(k-1,a,b,d);
	dfs2R(k-1,x[a][1-c[b]],b,d+abs(x[a][1-c[b]]-a));
}

int main(){
	read(n),read(m),read(Q);
	scanf("%s%s",sr+1,sc+1);
	r[0]=r[n+1]=c[0]=c[m+1]=-1;
	rep(i,1,n) r[i]=(sr[i]=='E');
	rep(i,1,m) c[i]=(sc[i]=='S');
	rep(i,1,n) x[i][0]=(r[i]!=r[i-1]?i-1:x[i-1][0]);
	per(i,n,1) x[i][1]=(r[i]!=r[i+1]?i+1:x[i+1][1]);
	rep(i,1,m) y[i][0]=(c[i]!=c[i-1]?i-1:y[i-1][0]);
	per(i,m,1) y[i][1]=(c[i]!=c[i+1]?i+1:y[i+1][1]);
	while(Q--){
		read(a),read(b),read(u),read(v);
		R1.clear(),C1.clear(),R2.clear(),C2.clear();
		dfs1R(2,a,b,0),dfs1C(2,a,b,0);
		dfs2R(2,u,v,0),dfs2C(2,u,v,0);
		int ans=inf;
		for(auto p:R1) for(auto q:C2){
			int R=(q.y-p.y)*dir[r[p.x]];
			int C=(q.x-p.x)*dir[c[q.y]];
			if(R>=0&&C>=0) ans=min(ans,R+C+p.d+q.d);
		}
		for(auto p:C1) for(auto q:R2){
			int R=(q.y-p.y)*dir[r[q.x]];
			int C=(q.x-p.x)*dir[c[p.y]];
			if(R>=0&&C>=0) ans=min(ans,R+C+p.d+q.d);
		}
		printf("%d\n",ans>=inf?-1:ans);
	}
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <fstream>
#include <sstream>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int) (a).size())

#ifdef CUTEBMAING
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;

int64 go(int64 a, int64 b) {
    if (a == 0 || b == 0) {
        return -(a + b);
    }
    int64 cnt = b / a, ans = cnt * 2 * a;
    return ans + go(b % a, a);
}

int main() {
#ifdef XCODE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int64 n, x; cin >> n >> x;
    if (x > n - x) {
        x = n - x;
    }
    if (x == n - x) {
        cout << 3 * x << endl;
        return 0;
    }
    cout << go(x, n - x) + x + n - x << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
Edge = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    Edge[u].append((v, w))
    Edge[v].append((u, w))

visited = set([0])
Col = [-1]*N
Col[0] = 1
stack = [0]
while stack:
    vn = stack.pop()
    for vf, wf in Edge[vn]:
        if vf in visited:
            continue
        if wf % 2 == 0:
            c = Col[vn]
        else:
            c = 1 - Col[vn]
        visited.add(vf)
        Col[vf] = c
        stack.append(vf)
for c in Col:
    print(c)

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

#define fs first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n = in(), T = in();
	int t[202020];
	rep(i, n) cin >> t[i];

	lint sum = T;
	for (int i = 0; i < n - 1; i++) {
		sum += min(T, t[i + 1] - t[i]);
	}

	cout << sum << endl;
}


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

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999

typedef long long ll;

int main()
{
	ll N, P;
	cin >> N >> P;

	ll res = 1;
	ll e = P;
	for(ll i = 2; i * i <= P; i++){
		int x = 0;
		while(P % i == 0){
			P /= i;
			x++;
		}

		res *= pow(i, x / N);
	}

	if(N >= 2)
		cout << res << endl;
	else
		cout << e << endl;

	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,m,c[26],sum1,sum2;;
char ch[105];
int main(void){
	register int i,j,k;
	scanf("%d%d",&n,&m);
	sum1=((n&1)&(m&1)),
	sum2=m*(n&1)+n*(m&1)-2*sum1;
	for(i=1;i<=n;++i){
		scanf("%s",ch+1);
		for(j=1;j<=m;++j)
			++c[ch[j]-'a'];
	}
	for(i=0;i<26;++i){
		if(c[i]&1)--sum1;
		if(c[i]%4>=2)sum2-=2;
		if(sum1<0||sum2<0){
			puts("No");
			return 0;
		}	
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pi pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,a,b) for(int i = a ; i <= b;i++)
using namespace std;
void debug(int x){
    cerr<<x<<endl;
}
void debug(vector<int> v){
    for(int i = 0 ; i<v.size(); i++) cerr<<v[i]<<" ";
    cerr<<"\n";
}
void debug(vector<ll> v){
    for(int i = 0 ; i<v.size(); i++) cerr<<v[i]<<" ";
    cerr<<"\n";
}
void debug(int *A, int N){
    for(int i = 0 ; i < N;i++) cerr<<A[i]<<" ";
    cerr<<endl;
}
void debug(int *A, int i, int j){
    for(int k = i;k<=j;k++) cerr<<A[k]<<" ";
    cerr<<endl;
}
void scan(vector<int> &h,int N){
    for(int i = 0 ; i < N;i++){
        scanf("%d",&h[i]);
    }
}


void max_self(ll &a, ll b){
    a = max(a,b);
}

int main(){
            //solving 0-1 knapsack
            int N,W;
            cin>>N>>W;
            vector<ll> dp(W+1); 
            //dp[i] is the maximum value with sum exactly equal to i

            for(int i = 0; i< N; i++){
                 ll weight, value;
                 cin>>weight>>value;
                 //using the last computed dp values to update the newer ones using forward dp
                 //inclusion weight will affect the dp values
                 for(int wt_incl = W-weight; wt_incl >0; --wt_incl){
                         if(dp[wt_incl] != 0){
                             dp[wt_incl + weight] = max(dp[wt_incl + weight], dp[wt_incl]  + value);
                         }
                 }
                 
                 dp[weight] = max(dp[weight] , value);
            }

               debug(dp);
               ll answer = 0;
               for(int i = 0 ; i <=W; i++){
                          answer = max(answer, dp[i]);
               }
               cout<<answer<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

template<typename T>
class SegTree {
public:
    explicit SegTree(int n, T def) : N(calcN_(n)), def(def), mVal(2*calcN_(n)+1, def) {}
    void update(int idx, T value){
        int i = N + idx - 1;
        update_(mVal[i], value);
        while(i > 0){
            i = (i-1)/2;
            mVal[i] = operate(mVal[2*i+1], mVal[2*i+2]);
        }
    }
    T get(int l, int r){
        return getImpl_(l, r, 0, 0, N);
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    T getImpl_(int l, int r, int idx, int rangeL, int rangeR){
        if(r <= rangeL || rangeR <= l) return def;
        if(l <= rangeL && rangeR <= r) return mVal[idx];
        int rangeM = (rangeL+rangeR)/2;
        T a = getImpl_(l, r, 2*idx+1, rangeL, rangeM);
        T b = getImpl_(l, r, 2*idx+2, rangeM, rangeR);
        return operate(a, b);
    }
    T update_(T& data, T val) { data = val; }
    T operate(T a, T b) { return min(a, b); }
    const int N;
    const T def;
    vector<T> mVal; 
};

int main(){
    int n, q;
    while(cin >> n >> q){
        const int INF = 0x7FFFFFFF;
        SegTree<int> seg(n, INF);
        for(int i=0;i<q;i++){
            int c, x, y; cin >> c >> x >> y;
            if(c == 0){
                seg.update(x, y);
            } else {
                cout << seg.get(x, y+1) << endl;
            }
        }
    }
}



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

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

int main(){
    int n,m,k;
    m =0 ;
    cin >> n;
    vector<int> li(n),l(n+1,0),r(n+1,0);
    for (int i = 0;i<n;i++) cin >> li[i];
    for (int i = 0;i<n;i++){
        l.at(i+1)=gcd(li[i],l[i]);
        r.at(n-i-1)=gcd(li[n-1-i],r[n-i]);
    }
    for (int i =0 ;i<n;i++){
        k = gcd(l[i],r[i+1]);
        if (k>m) m = k;
    }
    cout << m << endl;
    return 0;
}

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

using namespace std;

/*
 * Union-Find tree
 * header requirement: vector
 */
namespace procon {
class UnionFind {
   private:
    struct nodeinfo {
        int par;
        int rank;
        nodeinfo(int par) : par(par), rank(0) {}
    };
    std::vector<nodeinfo> node;

   public:
    UnionFind(int n) : node() {
        node.reserve(n);
        for (int i = 0; i < n; ++i) {
            node.push_back(nodeinfo(i));
        }
    }
    int root(int x) {
        if (node[x].par == x) {
            return x;
        }
        return node[x].par = root(node[x].par);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (node[x].rank < node[y].rank) {
            node[x].par = y;
        } else {
            node[y].par = x;
            if (node[x].rank == node[y].rank) {
                ++node[x].rank;
            }
        }
    }
    bool is_same_set(int x, int y) { return root(x) == root(y); }
};
}  // namespace procon

namespace std {
template <>
class hash<std::pair<int, int>> {
   public:
    size_t operator()(const std::pair<int, int>& x) const {
        return hash<int>()(x.first) ^ hash<int>()(x.second);
    }
};
}

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

    auto road = procon::UnionFind(N);
    auto rail = procon::UnionFind(N);

    for (int i = 0; i < K; i++) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        road.unite(p, q);
    }
    for (int i = 0; i < L; i++) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        rail.unite(p, q);
    }

    map<pair<int, int>, int> mp;

    for (int i = 0; i < N; i++) {
        mp[make_pair(road.root(i), rail.root(i))]++;
    }
    for (int i = 0; i < N; i++) {
        cout << mp[make_pair(road.root(i), rail.root(i))] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 15104
n, k = [int(i) for i in input().split()]
s = input()
s_split = []
i = 0
while i < n:
    j = i
    while j < n and s[i] == s[j]:
        j += 1
    s_split.append(s[i:j])
    i = j
i_hp = sum([len(ss) - 1 for ss in s_split])
rs = [ss for i, ss in enumerate(s_split) if i != 0 and i != len(s_split) - 1 and ss[0] == 'R']
ls = [ss for i, ss in enumerate(s_split) if i != 0 and i != len(s_split) - 1 and ss[0] == 'L']
initial_good = s_split[0][0] == 'R'
final_good = s_split[-1][-1] == 'L'
max_flip = max(len(rs), len(ls))
if max_flip >= k:
    print(i_hp + 2 * k)
else:
    print(n - 1)

Measured memory_bytes: 5492
#include"bits/stdc++.h"
using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	int count = 0;
	for (int i = A;i <= B;++i) {
		if (i / 10000 == i % 10 && i % 10000 / 1000 == i % 100 / 10) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
    var data = input.split("\n")
	var n =  data[0].split(" ").map((n) => parseInt(n, 10));
	var num =  data[1].split(" ").map((n) => parseInt(n, 10));
	var junban = new Array(n-1);
	
	for(var i=0; i <= n[0];i++){
		junban[num[i-1]] = i;
	}
	junban.shift();
	console.log(junban.join(' '))
}
 
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 42008
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

void solve(long long A, long long B) {
  int cnt = 0;
  if(B==1){
    cout<<0<<endl;
    return;
  }
  else{
    B-=A;cnt=1;
    if(B>0){
      // debug(B);debug(A);
      int c = ceil((float)B/(float)(A-1));
      // debug(c);
      cnt += ceil(B/(float)(A-1));
    }
    cout<<cnt<<endl;
  }
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (LL i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (LL i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

LL const MOD = 1e9+7;
LL const MaxSize = 3e5 + 5;
//LL const MOD = 998244353;

/*

#https://atcoder.jp/contests/abc147/tasks/abc147_d
#Xor Sum 4
"""
iterate over bits
1. calculate how many bits we have on that position
2. for each 1, we need to add num 0s * num 1s * 2s
3. sum them up

1. python version gets TLE due to the IO
2. in c++ version, all needs to be LL
 */


LL N, a[MaxSize];

int main() {
        ios_base::sync_with_stdio(false);
        //freopen("/Users/georgeli/A_1.in", "r", stdin);

        cin >> N;

        LP(i, 0, N){
        	cin >> a[i];
        }

        LL ans = 0;
        int maxS = 61;
        LL base = 1;
        LP(shift, 0, maxS){ //instead of spending time calculating tight boudary, relax it a bit
        	//LL base = 1 << shift;
            base %= MOD;//!!!! this overflow is what got me, also, shift does not work well in 32 bit+ cases
            LL n1 = 0;
            LP(i, 0, N){
                if ((a[i] >> shift) & 1) //this is what got me: I didn't use & 1, shift itself is an assignment which returns no value
                    n1 += 1;
            }


            //cout << "n1: " << n1 << endl;
            LL part = n1 * (N - n1);
            //cout << shift << " " << part << " " << ans << endl;
            part %= MOD;
            part *= base;
            part %= MOD;
            ans += part;
            ans %= MOD;
            base *= 2L;
        }

        cout << ans;
        return 0;
}


Measured memory_bytes: 2560
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b = MAP()
c = a-2*b
if c <= 0:
  print(0)
else:
  print(c)

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

int main(){
    int n,d;
    cin >> n >> d;
    int x[n][d];
    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            cin >> x[i][j];
        }
    }
    int sum=0;
    double ans;
    int kari;
    int cnt=0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            sum=0;
            for(int k=0; k<d; k++){
                sum+=pow(x[i][k]-x[j][k],2);
            }
            ans=sqrt(sum);
            kari=sqrt(sum);
            if(ans==kari)cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256