akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
const int N = 1e6;
const int inf = 0x3f3f3f3f;
vector<ll>v;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n, p;
    cin >> n >> p;
    int temp = 1;
    for(int i = 1; i <= n; i++)
        if(temp < p)
            temp *= 2;
        else
            temp += p;
    cout << temp << endl;
    return 0;
}

Measured memory_bytes: 256
#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 <stdlib.h>
#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 rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


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;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

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

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 a, b, c; cin >> a >> b;
	//string s; cin >> s;
	int group[] = { 0,1,3,1,2,1,2,1,1,2,1,2,1 };
	if (group[a] == group[b]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k,q,i,j;
    cin>>n>>k>>q;
  	ll a[q];
  	for(i=0;i<q;i++) cin>>a[i];
  	vector<ll> t(n,k);
    for(i=0;i<q;i++)
    {
      t[a[i]-1]++;
    }
    for(i=0;i<n;i++)
    {
      if(t[i]-q>0) cout<<"Yes\n";
      else cout<<"No\n";
    }
	return 0;
}


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

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

 if(A.size() > B.size()) { cout << "GREATER"; return 0; }
 else if(A.size() < B.size()) { cout << "LESS"; return 0; }
 else {
   for(int i = 0; i < A.size(); i++) {
     if(A[i] > B[i]) { cout << "GREATER"; return 0; }
     else if(A[i] < B[i]) { cout << "LESS"; return 0; }
   }
 }

 cout << "EQUAL";
 
  return 0;
}

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

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

    std::vector<int> h(N);
    for (int i = 0; i < N; i++) std::cin >> h[i];

    int cost[N];
    cost[0] = 0;
    cost[1] = abs(h[1] - h[0]);
    for (int i = 2; i < N; i++)
    {
        int num1 = cost[i-1] + abs(h[i] - h[i-1]);
        int num2 = cost[i-2] + abs(h[i] - h[i-2]);
        cost[i] = std::min(num1, num2);
    }

    // for (int i = 0; i < N; i++) std::cout << cost[i] << " ";
    // std::cout << std::endl;
    std::cout << cost[N-1] << std::endl;

    return 0;
}


Measured memory_bytes: 1024
//Space Coconut Grab
//????????????30???
//x??¨y????±?????????????z????±???????????????????????????????????????????????????£??????
//???????????????????????´??????y??¨???????±?????????????x????±???????????????????????????????????°??????????????????????

#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
	int x, y, z, e, m;
	while (cin >> e && e > 0) {
		m = 10000000;
		for (y = 0; y*y <= e; y++) {
			for (z = 0; z*z*z+y*y <= e; z++) {
				int x = e - y*y - z*z*z;
				m = min(m, x + y + z);
			}
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void){
    int S,h,m,a,b,s;
    scanf("%d", &S);
    h=S/3600;
    a=S-h*3600;
    m=a/60;
    b=S-(h*3600+m*60);
    s=b/1;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <numeric>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <cassert>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef pair<ll, int> pli;
typedef vector<vector<int>> vvi;
#define mod 10000
#define PI acos(-1.0)
#define eps 1e-8
#define e 2.71828

typedef long long ll;

ll n, k, cnt, res;
vector<ll> nums;
unordered_map<ll, ll> helper;

vector<ll> segTree;
#define L (index << 1)
#define R (index << 1 | 1)

void add(ll index, ll l, ll r, ll v) {
    if (v < l || v > r) return;
    ++segTree[index];
    if (l == r) {
        return;
    }
    ll mid = l + (r - l) / 2;
    add(L, l, mid, v);
    add(R, mid + 1, r, v);
}

ll query(ll index, ll l, ll r, ll v) {
    if (l > v) return 0;
    if (r <= v) return segTree[index];
    ll mid = l + (r - l) / 2;
    return query(L, l, mid, v) + query(R, mid + 1, r, v);
}

int main() {
    cin >> n >> k;
    vector<ll> tmp;
    ll s = 0;
    nums.push_back(0);
    tmp.push_back(0);
    for (int i = 1; i <= n; ++i) {
        ll num;
        scanf("%lld", &num);
        s += num;
        nums.push_back(s - k * i);
        tmp.push_back(s - k * i);
    }
    sort(tmp.begin(), tmp.end());
    cnt = 0;
    for (int i = 0; i <= n; ++i) {
        if (i == 0 || tmp[i] != tmp[i - 1]) {
            helper[tmp[i]] = ++cnt;
        }
    }
    for (int i = 0; i <= n; ++i) {
        nums[i] = helper[nums[i]];
    }

    segTree.assign(cnt << 2, 0);
    res = 0;
    for (int i = 0; i <= n; ++i) {
        res += query(1, 1, cnt, nums[i]);
        add(1, 1, cnt, nums[i]);
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 17892
#include <stdio.h>
main(){
  int i=0,j,k,l;
  double x[1000],y[1000],a,b,c,d,e,f;
  while(1){
    scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f);
    if(feof(stdin))break;
    x[i]=(b*f-e*c)/(b*d-e*a)*1000;
    y[i]=(a*f-d*c)/(a*e-d*b)*1000;
    k=(int)x[i];
    l=(int)y[i];
    x[i]=(double)k/1000;
    y[i]=(double)l/1000;
    i++;
  }
  for(j=0;j<i;j++){
    printf("%.3lf %.3lf\n",x[j],y[j]);
  }
  return(0);
}

Measured memory_bytes: 660
#include<iostream>
#include<vector>
using namespace std;
struct square 
{
  int x, y;
  square(int _x, int _y)
  {
    x = _x;
    y = _y;
  }
};

int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
vector<square> sq;

int main()
{
loop:
  sq.clear();
  int n;
  cin >> n;
  if(!n)
    return 0;
  sq.push_back(square(0, 0));
  for(int i = 0; i < n - 1; i++)
  {
    int a, b;
    cin >> a >> b;
    sq.push_back(square(sq[a].x + dx[b], sq[a].y + dy[b]));
  }
  int l = 0, b = 0, r = 0, t = 0;
  for(int i = 0; i < sq.size(); i++)
  {
    l = min(l, sq[i].x);
    b = min(b, sq[i].y);
    r = max(r, sq[i].x + 1);
    t = max(t, sq[i].y + 1);
  }
  cout << r - l << " " << t - b << endl;
  goto loop;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
    using namespace std;
    
    vector<long long> vplus , vminus, vp , vm;
    long long sumplus, summinus , sumlimit;
    
    // vplusのa番目の判断で、a-1番目までの合計がb
    void dfs_p(int a, int b){
        //cout << "a:" << a << " b:" << b << endl; 
        if(b > sumlimit){
            return;
        }
        // a番目を使う場合
        vp[b + vplus[a]] += 1; 
        if( a + 1 < vplus.size()){
            dfs_p(a + 1 , b + vplus[a] );
            // a番目を使わない場合
            dfs_p(a + 1, b);
        }
        return;
    }
    // vminusのa番目の判断で、a-1番目までの合計がb
    void dfs_m(int a, int b){
        if(b > sumlimit){
            return;
        }
        // a番目を使う場合
        vm[b + vminus[a]] += 1; 
        if( a + 1 < vminus.size()){
            dfs_m(a + 1 , b + vminus[a] );
            // a番目を使わない場合
            dfs_m(a + 1, b);
        }
        return;
    }
    
    long long binpow(long long a, long long b) {
        long long res = 1;
        while (b > 0) {
        if (b & 1)
            res = res * a ;
            a = a * a;
            b >>= 1;
        }
        return res;
    }

    int main(){
        long long n , a;
        cin >> n >> a;
        long long x;
        long long zero = 0;
        sumplus = 0;
        summinus = 0;
        vp.assign(2500 , 0);
        vm.assign(2500 , 0);
        for(int i = 0; i < n ; i++){
            cin >> x;
            x -= a;
            if(x > 0) {
                vplus.push_back(x);
                sumplus += x;
            }else if(x < 0){
                vminus.push_back(-x);
                summinus -= x;
            }else if(x == 0){
                zero += 1;
            }
        }
        sumlimit = min(sumplus , summinus);
        long long ans = 0;
        
        if(vplus.size() > 0) dfs_p(0 , 0);
        if(vminus.size() > 0) dfs_m(0 , 0);
        
        for(int i = 0 ; i < vp.size() ; i++){
            ans += vp[i] * vm[i];
        }
        if(zero > 0){
            ans = ans * (binpow(2 , zero) ) + binpow(2 , zero) - 1 ;
        }
        
        cout << ans << endl;
        
        return 0;
    }

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

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

    int ans = 0;
    for(int i=0; i<3; i++){
        ans += (s[i]==t[i])?1:0;
    }

    cout<<ans<<endl;

    return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<pair<LL,LL>> v(n);
  for(int i=0; i<n; i++){
    LL a,b;
    cin>>a>>b;
    v[i]=make_pair(a,b);
  }
  sort(v.begin(),v.end());
  LL ans=0;
  for(auto p:v){
    LL a=p.first;
    LL b=p.second;
    if(b<m){
      ans+=a*b;
      m-=b;
    }else{
      ans+=a*m;
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.*;
import java.math.*;
public class Main{

	static int INF = 2 << 27;
	static int m;
	static int n;
	static int k;
	static int d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			Data[] data = new Data[n];
			for(int i = 0; i < n; i++) {
				data[i] = new Data(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
			}
			for(int i = 0; i < n; i++) {
				for(int j = i + 1; j < n; j++) {
					boolean check = check(data,i,j);
					if(check) data[j].up |= (1 << i);
				}
			}
			boolean[] dp = new boolean[1 << n];
			dp[0] = true;
			for(int i = 0; i < dp.length; i++) {
				if(!dp[i]) continue;
				ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
				for(int j = 0; j < 5; j++) {
					list.add(new ArrayList<Integer>());
				}
				for(int j = 0; j < n; j++) {
					if((i & (1 << j)) != 0) continue;
					if((i & data[j].up) != data[j].up) continue;
					list.get(data[j].c).add(j);
				}
				for(int j = 1; j < 5; j++) {
					for(int k = 0; k < list.get(j).size()-1; k++) {
						for(int l = k + 1; l < list.get(j).size(); l++) {
							int next = i | (1 << list.get(j).get(k) | (1 << list.get(j).get(l)));
							dp[next] = true;
						}
					}
				}
			}
			int max = 0;
			for(int i = 0; i < dp.length; i++) {
				if(dp[i]) max = Math.max(max, Integer.bitCount(i));
			}
			System.out.println(max);
			
		}
	}
	static boolean check(Data[] data, int a, int b) {
		int dis = (int)(Math.pow(data[a].x - data[b].x, 2) + Math.pow(data[a].y - data[b].y, 2));
		return dis < Math.pow(data[a].r + data[b].r,2);
	}
	static class Data {
		int up = 0;
		int x;
		int y;
		int r;
		int c;
		Data(int a, int b, int c, int d) {
			this.x = a;
			this.y = b;
			this.r = c;
			this.c = d;
		}
	}
}

Measured memory_bytes: 241196
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
int gcd(int x, int y)
{
    if(y==0)
        return x;
    return gcd(y, x%y);
}

 long long numbers[500005];

 int main(){

 long long a,b,x,counts=0;
 cin>>a>>b>>x;

 counts = (b/x)-(a/x);

 if(a%x == 0)
    counts++;

 cout<<counts<<endl;

return 0;
 }


Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
int n,i;
char s[101],t[101],u[101];
int main(void){
    scanf("%d %s %s",&n,s,t);
    for (i = 0; i < n; i++)
    {
        printf("%c%c",s[i],t[i]);
    }
    printf("\n");
    return 0;
}

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



#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int>> vvi;
typedef vector<ll>     vl;
typedef vector<vector<ll>> vvl;
const int infi = numeric_limits<int>::max();
const ll infl = numeric_limits<ll>::max();

const   double         eps = 0;
const   int            ms  = 0;

int N;
ll ans=0;
unordered_map<string, ll> ls_n;

string l, r;
void fl(int i, string s0, string s1){
    if(i == N){
        string q = s0 + " " + s1;
        //debug(q);
        ls_n[q]==0?ls_n[q]=1:ls_n[q]++;
        return;
    }
    fl(i+1, s0+l[i], s1);
    fl(i+1, s0, l[i]+s1);
}

void fr(int i, string s0, string s1){
    if(i == N ){
        string q = s0 + " " + s1;
        //debug(q);
        //debug(ls_n[q]);
        ans+=ls_n[s0+" "+s1];
        return;
    }
    fr(i+1, s0+r[N-i-1], s1);
    fr(i+1, s0, r[N-i-1]+s1);
}

int main(){
    string s;
    
    cin >> N;
    cin >> s;
    debug(s);
    l = s.substr(0, N);
    r = s.substr(N, 2*N); 
    debug(l);
    debug(r);
    fl(0, "","");
    fr(0, "","");
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 70900
function main()
    N,X,T = reads(Int,Int,Int)
    println((N÷ X+(N%X != 0 ? 1 : 0))*T)
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


Measured memory_bytes: 192900
import java.util.Arrays;
import java.util.Scanner;

//Luigi's Tavern
public class Main{

	int augumentPath(int v, int t, int f, int[][] cap, boolean[] used){
		if(v==t)return f;
		used[v] = true;
		for(int i=0;i<cap[v].length;i++){
			if(cap[v][i]>0 && !used[i]){
				int d = augumentPath(i, t, Math.min(f, cap[v][i]), cap, used);
				if(d>0){
					cap[v][i] -= d;
					cap[i][v] += d;
					return d;
				}
			}
		}
		return 0;
	}
	
	int maxFlow(int s, int t, int[][] cap){
		int flow = 0;
		int n = cap.length;
		boolean[] used = new boolean[n];
		while(true){
			Arrays.fill(used, false);
			int f = augumentPath(s, t, Integer.MAX_VALUE, cap, used);
			if(f==0)return flow;
			flow += f;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int h = sc.nextInt(), w = sc.nextInt(), c = sc.nextInt(), m = sc.nextInt(), nw = sc.nextInt(), nc = sc.nextInt(), nm = sc.nextInt();
			if(h<0)break;
			int n = h+w+c+m, NW = n, NC = n+1, NM = n+2, N = n+3, S = 2*N, T = 2*N+1;
			int[][] cap = new int[2*N+2][2*N+2];
			for(int i=0;i<n;i++)cap[i+N][i] = 1;
			cap[NW+N][NW] = nw;
			cap[NC+N][NC] = nc;
			cap[NM+N][NM] = nm;
			for(int i=0;i<h;i++){
				cap[S][i+N] = 1; cap[i][NW+N] = 1;
			}
			for(int i=0;i<w;i++){
				int k = sc.nextInt();
				while(k--!=0){
					int id = sc.nextInt()-1;
					cap[id][h+i+N] = 1;
				}
				cap[h+i][NC+N] = 1;
			}
			for(int i=0;i<c;i++){
				int k = sc.nextInt();
				while(k--!=0){
					int id = sc.nextInt()-1+h;
					cap[id][i+h+w+N] = 1;
				}
				cap[h+w+i][NM+N] = 1;
			}
			for(int i=0;i<m;i++){
				int k = sc.nextInt();
				while(k--!=0){
					int id = sc.nextInt()-1+h+w;
					cap[id][i+h+w+c+N] = 1;
				}
				cap[i+h+w+c][T] = 1;
			}
//			cap[NW][NC+N] = nw;
			for(int i=0;i<c;i++)cap[NW][i+h+w+N] = 1;
//			cap[NC][NM+N] = nc;
			for(int i=0;i<m;i++)cap[NC][i+h+w+c+N] = 1;
			cap[NM][T] = nm;
			System.out.println(maxFlow(S, T, cap));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
	int N, M;
	cin >> N >> M;
	int sum = 0;
	for (int i = 0; i < M; i++) {
		int A;
		cin >> A;
		sum += A;
	}
	cout << (sum <= N ? N - sum : -1) << endl;
}


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

int main() {
	// your code goes here
	int n,m,s;
	cin>>n>>m>>s;
	int am=n-m;
	if(am%s==0){
		cout<<"0"<<endl;
	}
	else{
		int lol=am/s;
		cout<<am-(s*lol)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
ab=t3(n-1)

d={i:[] for i in range(1,n+1)}
for a,b in ab:
    d[a].append(b)
    d[b].append(a)

l=list(d.items())
l.sort(key=lambda x:-len(x[1]))
m=len(l[0][1])

d2={line:0 for line in ab}
c={i:[] for i in range(1,n+1)}
for node,list1 in l:
    a=node
    color=1
#     print(node,list1)
    for b1 in list1:
        if node>b1:
            a,b=b1,node
        else:
            a,b=node,b1
#         print(a,b)
        if d2[(a,b)]!=0:
            continue
        else:
            while color in c[a] or color in c[b]:
                color+=1 
            d2[(a,b)]=color
            c[a].append(color)
            c[b].append(color)
            color+=1
#     print(d2)
print(m)
for line in ab:
    print(d2[line])

Measured memory_bytes: 124756
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX 10001
#define true 1
#define false -1
int count=0;
int isprime(int x){
   int i=3,s;
  if(x==2) return true;
  if(x<2 || x%2==0) return false;
  s=sqrt(x);
  while (i<=s) {
    if(x%i==0) return false;
    i=i+2;
  }
  return true;
}

int main() {
int n,count=0,i;
int a[MAX];
scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
  if(isprime(a[i])==true) count++;
}
printf("%d\n",count);

return 0;
}



Measured memory_bytes: 2112
// ソートすると、自分より小さいやつだけが対象となる
// 自分iを割り切るjがいたとき、jはiの約数のどれかである
// エラトステネス的に考えると、min(A)~max(A)までのすべてをA[i]の倍数で埋めていく感じになる？
// 1を含む場合・同じのを複数含む場合みたいな探索上しんどそうなやつは省く（ほかなんかある？）
// ↑まさかの「1を複数含む場合」があって無駄にWAを生やしてしまうの巻

package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	N := nextInt()
	preA := nextInts(N)
	Distinct := make(map[int]bool)
	A := []int{}
	T := make([]bool, int(1e6+100)) // なんか知らんがRE出たのでたぶんこれが怪しいと踏んで余分に増やした
	sort.Ints(A)
	for _, a := range preA {
		if !Distinct[a] {
			Distinct[a] = true
			A = append(A, a)
		} else {
			// 同じのがあったらそれは駄目
			T[a] = true
		}
	}
	if A[0] == 1 {
		if N == 1 {
			fmt.Println(1)
			return
		} else {
			fmt.Println(0)
			return
		}
	}
	for _, a := range A {
		for x := a * 2; x <= int(1e6+10); x += a {
			T[x] = true
		}
	}
	ans := 0
	for _, a := range A {
		if T[a] == false {
			ans++
		}
	}
	fmt.Fprintln(out, ans)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}


Measured memory_bytes: 17344
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	for i := 0; i < 5; i++ {
		x := getNextInt(scanner)
		if x == 0 {
			fmt.Fprintln(writer, i + 1)
		}
	}
}


Measured memory_bytes: 1800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		for(int j = 1; j < n + 1; j++) {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		}
		
		System.out.println();
	}

}

Measured memory_bytes: 29384
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

// ?????°??°???A
void print(int A[],int n) {
	for (int i = 0; i < n; i++)
		printf("%d%c", A[i], i == n - 1 ? '\n' : ' ');
}
// ?????\?????????
void insertsort(int A[], int n) {
	// ????¬¬??????????§?,??????????????????????°??????????
	// ??????????????§????°±???????§??????\????????°?°??????????A[i]???
	for (int i = 1; i < n; i++) {
		int j = i - 1;
		int v = A[i];
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		print(A, n);
	}
}
int main() {
	int n, A[110];
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	print(A, n);
	insertsort(A, n);
	return 0;
}

Measured memory_bytes: 3224
#include <iostream>

int A, B;

int main()
{
	std::cin >> A >> B;

	if (A == 1)
		A += 13;
	if (B == 1)
		B += 13;

	std::cout << (A == B ? "Draw" : A > B ? "Alice" : "Bob") << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 3e5+100;
typedef long long int lld;
typedef long long ll;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
 
 
#define popcount __builtin_popcountll
 
ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}

vector<ll> Ans, Adj[lim];
ll Array[lim], Vis[lim];
pair<ll,ll> P[lim];

ll dfs(ll node,ll Vis[]) {
    Vis[node]=1;
    for(auto i:Adj[node]) {
        if(!Vis[i]) dfs(i,Vis); 
    }

    return 0;
}

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
    lld T,i,p,j,l,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,countA=0,indicator=0,pos,h,minA,maxA,type,n,ans=0,left,right;
    string A,B;
    A = "Yes", B="No";
    cin>>d>>t>>a;
    if(a*t >= d) cout<<A<<endl;
    else cout<<B<<endl;
    return 0;
}
    

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

r = [(a[0]-a[-1])%k]
l = [(a[-1]-a[0])%k]
for i in range(1,n):
	r.append(a[i] - a[i-1])
	l.append(abs(a[-i-1] - a[-i]))

sum_l = sum(l)
sum_r = sum(r)

print(min(sum_l-max(l),sum_r-max(r)))



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

typedef long long ll;
ll ans = 0;

void culc(string s, ll sum, ll x) {
	if (s.size() == 0) {
		ans += sum + x;
	} else {
		ll head = s[0] - '0';
		culc(s.substr(1), sum + x * 10LL + head, 0);
	   	culc(s.substr(1), sum, x * 10LL + head);
	}
}

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

	culc(s, 0, 0);
	cout << ans/2LL << endl;

	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;
const int MSIZE = 100000;
const double Pi = 3.14159265358979323146;

int main(){
  ll x;  cin >> x;
  for(ll a=-1000; a<=1000; a++){
    for(ll b=-1000; b<=1000; b++){
      if(a*a*a*a*a-b*b*b*b*b==x){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}


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

int main() {

  int N;
  cin >> N;
  string A, B, C, D;
  B = "0";
  C = "0";
  D = "0";
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (i == 0){
      A = S;
    }
    else if (A != S) {
      if (B == "0") {
        B = S;
      }
      else if (B != S) {
        if (C == "0") {
          C = S;
        }
        else if (C != S) {
          D = S;
        }
      }
    }   
  }
  
    if (D == "0") {
     cout << "Three" << endl;
    }
    else {
      cout << "Four" << endl;
    }
    
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {

	int m, f, r;
	int score;
	char grade;

	while (1) {
		scanf("%d %d %d", &m, &f, &r);

		score = m + f;

		if (m == -1 && f == -1 && r == -1) break;

		if (m == -1 || f == -1 || score < 30) {
			grade = 'F';
		} else if (score >= 80) {
			grade = 'A';
		} else if (score >= 65 && m + f < 80) {
			grade = 'B';
		} else if (score >= 50 && m + f < 65) {
			grade = 'C';
		} else if (score >= 30 && m + f < 50) {
      if (r >= 50) {
				grade = 'C';
			} else {
				grade = 'D';
			}
		}

		printf("%c\n", grade);

	}
	return 0;
}

Measured memory_bytes: 600
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            if(a==0&&b==0&&c==0) break;
            int array[] = {a, b, c};
            Arrays.sort(array);
            double num = Math.hypot(array[0], array[1])/2;
            int n=sc.nextInt();
            for(int i = 0; i < n; i++){
                 System.out.println(sc.nextInt() > num? "OK" : "NA");
            }
        }
    }
}


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

int main(){
  int n,k;
  cin >>n>>k;
  vector<int>vec(n);
  for(int i=0;i<n;i++) cin >> vec[i];
  sort(vec.begin(),vec.end());
  int p=0;
  for(int i=0;i<k;i++){
    p+=vec[i];
  }
  cout  <<p<<endl;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(void){
	unsigned S, h, m, s;

	cin >> S;
	h = S/60/60;
	m = S/60 - h*60;
	s = S % 60;

	cout << h << ":" << m << ":" << s << endl;

	return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

int mp[110][110];
int main()
{
  int H, W, N;
  cin >> H >> W >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];

  int y = 0, x = 0;
  int dy = 1;
  int idx = 0;
  while (idx < N) {
    mp[y][x] = idx + 1;
    a[idx]--;
    if (a[idx] == 0) idx++;
    y += dy;
    if (y < 0 || H <= y) {
      y -= dy;
      dy *= -1;
      x++;
    }
  }

  REP(i, H) {
    REP(j, W) {
      cout << mp[i][j] << ' ';
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int a; scanf("%d", &a);
  printf("%d\n", a*(1+a*(1+a)));

  return 0;
}

// EOF

Measured memory_bytes: 3788
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n;
    scanf("%d",&n);
    int A[n];
 
    for(int i = 0; i < n; i++) scanf("%d",&A[i]);
 
    for(int i = n-1; i > 0; i--) printf("%d ",A[i]);
    printf("%d\n",A[0]);
}


Measured memory_bytes: 2764
#include <iostream>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int count(int x) {
  if (x % 2 != 0) return 0;
  return count(x / 2) + 1;
}

int main() {
  int n, ans{};
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ans += count(a);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[2000],b[16]={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
	int len,i,s=0;
	cin>>a;
	len=strlen(a);
	for(i=0;i<len;i++){
		if(a[i]!=b[i])s++;
	}
	cout<<s;
}

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

int main(){
    long N;cin>>N;
    queue<string> q;
    q.push("3");
    q.push("5");
    q.push("7");
    long ans=0;
    while(q.size()){
      long a = stol(q.front());
      if(stol(q.front())<=N){
      if((q.front().find("3")!=-1)&&(q.front().find("5")!=-1)&&(q.front().find("7")!=-1))ans++;
      q.push(q.front()+"3");
      q.push(q.front()+"5");
      q.push(q.front()+"7");
      }
      
      q.pop();
    }
    cout<<ans<<endl;
}

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  lint n, m;
  cin >> n >> m;
  vector< tuple< lint, lint > > a(n);
  for (lint i=0; i<n; ++i) {
    lint ai, bi;
    cin >> ai >> bi;
    a[i] = make_tuple(ai, bi);
  }
  sort(a.begin(), a.end());
  lint ans = 0;
  lint p = 0;
  priority_queue< lint > j;
  for (lint i=0; i<=m; ++i) {
    while (p < a.size() && get<0>(a[p]) <= i) {
      j.push(get<1>(a[p]));
      p++;
    }
    if (j.empty()) continue;
    ans += j.top();
    j.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int h,w;cin>>h>>w;
	char g[h][w];
	rep(i,h) rep(j,w) cin>>g[i][j];

	int root[h+w-2];
	rep(i,h+w-2){
		if(i<w-1) root[i]=0;//左に向かう動き
		else root[i]=1;//下に向かう動き
	}
	char ans_real[h+w-1];
	bool bans=0;
	do{
		char ans[h+w-1];ans[0]=g[0][0];
		int hnt=0,wnt=0;
		rep(i,h+w-2){
			if(root[i]==0){
				wnt++;
				ans[i+1]=g[hnt][wnt];
			}
			else{
				hnt++;
				ans[i+1]=g[hnt][wnt];
			} 
		}
		bool chk=1;
		/*
		rep(i,h+w-1) cout<<ans[i];
		cout<<"\n";
*/
		rep(i,h+w-1){
			if(ans[i]=='.'){
				chk=0;
				break;
			}
		}
		if(chk){
			rep(i,h+w-2) ans_real[i]=root[i];
			bans=1;
			break;
		}
	}while(next_permutation(root,root+h+w-2));

	if(bans){
		char ans[h][w];
		rep(i,h) rep(j,w) ans[i][j]='.';
		ans[0][0]='#';
		int hnt=0,wnt=0;
		rep(i,h+w-2){
			if(ans_real[i]==0){
				wnt++;
				ans[hnt][wnt]='#';
			}
			else{
				hnt++;
				ans[hnt][wnt]='#';
			} 
		}
	/*	rep(i,h){
			rep(j,w) cout<<ans[i][j];
			cout<<"\n";
		}
*/
		rep(i,h){
			rep(j,w){
				if(ans[i][j]!=g[i][j]){
					cout<<"Impossible"<<"\n";
					return 0;
				}
			}
		}
		cout<<"Possible"<<"\n";
		return 0;
	}
	cout<<"Impossible"<<"\n";
}

Measured memory_bytes: 256
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int x,y,z; cin >> x >> y >> z;
	x -= z;
	cout << x/(y+z);
}	


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  ll h,w;
  cin >> h >> w;
  ll res = 1ll << 60;
  for(ll i = 1;i < w;i++){
    res = min(res,max({abs(i*h-(w-i)*(h/2)),abs(i*h-(w-i)*((h+1)/2)),abs((w-i)*(h/2)-(w-i)*((h+1)/2))}));
    res = min(res,max({abs(i*h-h*((w-i)/2)),abs(i*h-h*((w-i+1)/2)),abs(h*((w-i+1)/2)-h*((w-i)/2))}));
  }
  for(ll i = 1;i < h;i++){
    res = min(res,max({abs(i*w-(h-i)*(w/2)),abs(i*w-(h-i)*((w+1)/2)),abs((h-i)*(w/2)-(h-i)*((w+1)/2))}));
    res = min(res,max({abs(i*w-w*((h-i)/2)),abs(i*w-w*((h-i+1)/2)),abs(w*((h-i+1)/2)-w*((h-i)/2))}));
  }
  cout << res << endl;





  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long ll;

string bit3(string &res){
	reverse(res.begin(), res.end());
	int i = 0;
	while(1){
		res[i]++;
		if ((res[i]-'0')/3>0) {
			res[i] = '0';
			i++;
		}
		else break;
	}
	reverse(res.begin(), res.end());

	return res;
}

int main(int argc, char const *argv[])
{
	ll n;
	cin >> n;
	string s = to_string(n);

	ll ans = 0;

	if (n<357) ;
	else {
		for (int i = 3; i <= s.size(); ++i) {
			string u(i, '0');
			for (int j = 0; j < pow(3,i); ++j) {
				string t, temp;
				if (j==0) t = u;
				else t = bit3(u);
				for (int k = 0; k < i; ++k) {
					if (t[k]=='0') temp += '3';
					else if (t[k]=='1') temp += '5';
					else temp += '7';
				}
				bool tf = (temp.find('3') != string::npos) && (temp.find('5') != string::npos) && (temp.find('7') != string::npos);
				if (stoll(temp)<=n && tf) ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
template<class T>void sort(vec<T> &v){sort(v.begin(),v.end());}
template<class T>void rsort(vec<T> &v){sort(v.rbegin(),v.rend());}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m,q; cin >> n >> m >> q;
    vec<ll> a(q),b(q),c(q),d(q);
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i]; --b[i];
    }
    queue<string> que; 
    rep(i,m){
        string t = to_string(i);
        que.push(t);
    }

    while(1){
        string s = que.front();
        ll r = s.size();
        if(r == n)break;
        que.pop();
        if(r == n+1)break;
        for(ll i = s[r-1] - '0';i<m;i++){
            string t = to_string(i);
            que.push(s+t);
        }
    }
    ll ans = 0;
    while(!que.empty()){
        string s = que.front();
        que.pop();
        ll sum = 0;
        rep(i,q)if(s[b[i]] - s[a[i]] == c[i])sum += d[i];
        ans = max(ans,sum);
    }
    cout << ans << endl;


}

Measured memory_bytes: 6368
import sys
sys.setrecursionlimit(10**9)
N, M, Q = map(int, input().split())
A = []
B = []
C = []
D = []
ans = 0
def dfs(l):
    if len(l) == N+1:
        global ans
        now = 0
        for i in range(Q):
            if(l[B[i]] - l[A[i]] == C[i]):
                now += D[i]
        ans = max(ans, now)
    else:
        tmp = l[:]
        tmp.append(l[-1])
        while tmp[-1] <= M:
            dfs(tmp)
            tmp[-1] += 1

for i in range(Q):
    a, b, c, d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

dfs([1])
print(ans)

Measured memory_bytes: 9192
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<algorithm>
#include<cstring>
#include<cmath>
 
using namespace std;
 
 
 
int main() {
	int n;
	cin >> n;
	int m = 0;
	while (n > 10) {
		m += n % 10;
		n /= 10;
	}
	m += n;
	cout << m << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int
chk(int m, int f, int r)
{
	if ((m == -1) && (f == -1) && (r == -1))
		return 0;
	return 1;
}

int
main(int argc, char *argv[])
{
	int m, f, r;

	while (scanf("%d %d %d", &m, &f, &r), chk(m, f, r)) {
		if ((m == -1) || (f == -1))
			printf("F\n");
		else if (m + f >= 80)
			printf("A\n");
		else if (m + f >= 65)
			printf("B\n");
		else if (m + f >= 50)
			printf("C\n");
		else if ((m + f >= 30) && (r >= 50))
			printf("C\n");
		else if(m + f >= 30)
			printf("D\n");
		else
			printf("F\n");
	}

	return 0;
}

Measured memory_bytes: 584
//
//  main.cpp
//  aoj0525
//
//  Created by Wenfeng G on 8/8/19.
//  Copyright © 2019 Wenfeng G. All rights reserved.
//

#include <iostream>
#include <bitset>
#include <algorithm>

using namespace std;

bitset<10000> cookie[10];

int main(int argc, const char * argv[]) {
    int r, c;
    while (cin >> r >> c && r != 0 && c != 0) {
        int i, j;
        for (i = 0; i < r; i++) {
            for (j = 0; j < c; j++) {
                bool upwards;
                cin >> upwards;
                cookie[i][j] = upwards;
            }
        }
        
        int permute_r = 1 << r;
        int res = 0;
        
        for (i = 0; i < permute_r; i++) {
            for (j = 0; j < r; j++) {
                if (i & (1 << j)) {
                    cookie[j].flip();
                }
            }
            
            int possible_answer = 0;
            for (j = 0; j < c; j++) {
                int up_cookie_count = 0;
                for (int k = 0; k < r; k++) {
                    if (cookie[k][j]) {
                        up_cookie_count++;
                    }
                }
                possible_answer += max(up_cookie_count, r - up_cookie_count);
            }
            res = max(res, possible_answer);
            
            for (j = 0; j < r; j++) {
                if (i & (1 << j)) {
                    cookie[j].flip();
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 2992
N = gets.chomp!

if N[N.size - 1] == '2' || N[N.size - 1] == '4' || N[N.size - 1] == '5' || N[N.size - 1] == '7' || N[N.size - 1] == '9'
  puts "hon"
elsif N[N.size - 1] == '0' || N[N.size - 1] == '1' || N[N.size - 1] == '6' || N[N.size - 1] == '8'
  puts "pon"
elsif N[N.size - 1] == '3'
  puts "bon"
end


Measured memory_bytes: 14312
#include<cstdio>
#include<cmath>
struct Point
{
    double x;
    double y;
};
void koch(int n,Point a,Point b)
{
    if(n==0) return;
    Point s,t,u;
    double th=M_PI*60.0/180.0;
    s.x=(2.0*a.x+1.0*b.x)/3.0;
     s.y=(2.0*a.y+1.0*b.y)/3.0;
      t.x=(1.0*a.x+2.0*b.x)/3.0;
       t.y=(1.0*a.y+2.0*b.y)/3.0;
       u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
       u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
       koch(n-1,a,s);
       printf("%.8f %.8f\n",s.x,s.y);
       koch(n-1,s,u);
       printf("%.8f %.8f\n",u.x,u.y);
       koch(n-1,u,t);
       printf("%.8f %.8f\n",t.x,t.y);
       koch(n-1,t,b);

}
int main()
{
    int n;
    scanf("%d",&n);
    Point a,b;
    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
    return 0;
}



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

#define ll long long
#define ar array
#define endl "\n"
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

void solve(){
  ll a, b, k;
  cin >> a >> b >> k;
  ll ans = min(a, b);
  for(ll i = min(a, b); i>=1; --i){
    if(a%i == 0 && b%i == 0){
      ans = i;
      --k;
    }
    if(!k)
      break;
  }
  cout << ans << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 3568
#include <iostream>

int main()
{
  int date;
  std::cin >> date;
  switch (date) {
    case 22:
      std::cout << "Christmas Eve Eve Eve\n";
      break;
    case 23:
      std::cout << "Christmas Eve Eve\n";
      break;
    case 24:
      std::cout << "Christmas Eve\n";
      break;
    case 25:
      std::cout << "Christmas\n";
      break;
    default:
      std::cerr << "Unexpected input\n";
  }
  return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int K;
int ans = 0;

void solve(int a, int b, int c, int k) {
    if (k == K) {
        ans = max(ans, a+b+c);
        return;
    }
    solve(a*2, b, c, k+1);
    solve(a, b*2, c, k+1);
    solve(a, b, c*2, k+1);
}

int main() {
    int A, B, C;
    cin >> A >> B >> C >> K;
    solve(A, B, C, 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/9/ITP1_9_D
/*
    print a b
    reverse a b
    replace a b p
*/

#include <iostream>
#include <cstring>
#include <algorithm>

int main()
{
    std::string str, order, repstr;
    int q, a, b;
    std::cin >> str >> q;

    while (q != 0 && std::cin >> order)
    {
        if (order == "print")
        {
            std::cin >> a >> b;
            std::cout << str.substr(a, b - a + 1) << std::endl;
        }
        else if (order == "reverse")
        {
            std::cin >> a >> b;

            std::string tmp = str.substr(a, b - a + 1);
            std::reverse(tmp.begin(), tmp.end());
            str = str.replace(a, b - a + 1, tmp);
        }
        else if (order == "replace")
        {
            std::cin >> a >> b >> repstr;
            str = str.replace(a, b - a + 1, repstr);
        }
        q--;
    }
}


Measured memory_bytes: 3208
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

ll R[101010][2];
ll L[101010][2];
ll ans[101010];

int main(){

    string s;
    cin >> s;
    ll N = s.size();
    s = "@" + s + "@";
    for(ll i = 1, p; i <= N; i++){
        if(s[i] == 'R')p = i;
        else R[p][(i - p) % 2]++;
    }
    for(ll i = N, p; i >= 1; i--){
        if(s[i] == 'L')p = i;
        else L[p][(p - i) % 2]++;
    }
    for(ll i = 1; i <= N; i++){
        ans[i] += R[i][0] + L[i][0];
        ans[i + 1] += R[i][1];
        ans[i - 1] += L[i][1];
    }
    for(ll i = 1; i <= N; i++){
        cout << ans[i];
        if(i == N)cout << endl;
        else cout << " ";
    }

    return 0;
}

Measured memory_bytes: 4604