akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)




int main(){

ll N,H;
cin>>N>>H;
vector<ll> a(N);
vector<ll> b(N);
for(ll i=0;i<N;i++){
    cin>>a[i]>>b[i];

}

ll mmax = *max_element(ALL(a));
sort(ALL(b));
reverse(ALL(b));

ll ind = -1;
for(ll i=0;i<N;i++){
    if(b[i]>mmax){
        ind = i;
    }
    else{
        break;
    }
}

ll cn =0;
for(ll i=0;i<=ind;i++){
    H-=b[i];
    cn++;
    if(H<=0){
        break;
    }
}
if(H<=0){
        cout<<cn<<endl;
        return 0;
    }

    cn += H/mmax;
    if(H%mmax!=0){
        cn++;
    }
cout<<cn<<endl;
    return 0;






}


Measured memory_bytes: 1792
n=int(input())
s=[0]*100
for i in range(1,10):
  for j in range(1,10):
    s[10*i+j]=i*j
p=81
for k in range(0,100):
  if s[k]==n:
    p=p-1
if p==81:
  print('No')
else:
  print('Yes')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int n;
ll dp[3005][3005], a[3005];

ll rec(int len, int i) {
	int j = i + len;
	if (dp[i][j] != -1) return dp[i][j];
	if (len == 0) return dp[i][j] = 0;

	ll res;
	if ((n - len) % 2 == 0) {
		res = max(a[i] + rec(len - 1, i + 1), a[j - 1] + rec(len - 1, i));
	}
	else {
		res = min(-a[i] + rec(len - 1, i + 1), -a[j - 1] + rec(len - 1, i));
	}
	return dp[i][j] = res;
}

int main() {
	cin >> n;
	rep (i, n) cin >> a[i];

	memset(dp, -1, sizeof(dp));

	cout << rec(n, 0) << endl;
	return 0;
}

Measured memory_bytes: 71040
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    s = str(input())
    t = str(input())
    cnt=0
    for i in range(3):
        if s[i]==t[i]:
            cnt+=1
    print(cnt)



    
resolve()

Measured memory_bytes: 38512
#include<bits/stdc++.h>
#define endl '\n'
#include <math.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    if(s == "ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
    return 0;
}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

vector< ll >adj[100001];
int visited[100001];
ll p[100001],cc[100001];
ll colour = 1;

int dfs(ll curr)
{
    visited[curr] = 1; cc[curr]=colour;
    for(ll i = 0; i < adj[curr].size(); i++)
    {
        ll j = adj[curr][i];
        if(!visited[j])
        {
            dfs(j);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ll n,m,u,v;
    cin >> n >> m;
    for(ll i = 0; i < n; i++)cin >> p[i];
    for(ll i = 0; i < m; i++)
    {
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(ll i = 0; i < n; i++)
    {
        if(!visited[i])
        {
            dfs(i);
            colour++;
        }
    }
    /*
    for(ll i = 0; i < colour; i++)
    {
        for(ll j = 0; j < cc[i].size(); j++)
        {
            cout << cc[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;

    for(ll i = 0; i < n; i++)cout << cc[i] << " ";
    cout << endl;*/
    ll ans(0);
    for(ll i = 0; i < n; i++)
    {
        //cout << cc[p[i]] << " " << cc[i+1] << endl;
        if(cc[p[i]]==cc[i+1])ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll x;
  cin >> x;
  
  if (x % 11 == 0){
    cout << 2*(x / 11) << endl;
  }
  else if (x % 11 < 7){
    cout << 2*(x / 11) + 1 << endl;
  }
  else {
    cout << 2 * (x / 11 + 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 3576
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;

int main(){



                    int n,m;
                    cin>>n>>m;
                    if(m%n==0){
                        cout<<n+m;
                    }
                    else{
                        cout<<m-n;
                    }


}
//Pavel


Measured memory_bytes: 3604
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
	static void Main(string[] args)
	{

		int[] S = new int[13];
		int[] H = new int[13];
		int[] C = new int[13];
		int[] D = new int[13];


		int N = int.Parse(Console.ReadLine());

		for (int i = 0; i < N; i++)
		{
			string[] s = Console.ReadLine().Split(' ');
            char[] s1 = s[0].ToCharArray();
			int s2 = int.Parse(s[1]);

			switch (s1[0])
			{
				case 'S':

                    S[s2-1] = 1;
					break;
				case 'H':
					H[s2- 1] = 1;
					break;
				case 'C':
					C[s2- 1] = 1;
					break;
				case 'D':
					D[s2- 1] = 1;
					break;
				default:
					break;

			}
		}

		for (int i = 0; i < 13; i++)
		{
			if (S[i] != 1)
			{
				Console.WriteLine("S {0}", i+1);
			}
		}

		for (int i = 0; i < 13; i++)
		{
			if (H[i] != 1)
			{
				Console.WriteLine("H {0}", i+ 1);
			}
		}

		for (int i = 0; i < 13; i++)
		{
			if (C[i] != 1)
			{
				Console.WriteLine("C {0}", i+ 1);
			}
		}

		for (int i = 0; i < 13; i++)
		{
			if (D[i] != 1)
			{
				Console.WriteLine("D {0}", i+ 1);
			}
		}



		return;
		//Console.WriteLine("");

	}
}

Measured memory_bytes: 9068
N, X = map(int, input().split())
a, p = [1], [1]
for i in range(N):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)
def f(N, X):
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])
print(f(N, X))

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

namespace Ex160424_1{
    public class Program{
        public static void Main(string[] args){
            var i = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            Action<int, int> gcd = null;
            gcd = (x, y) =>{
                if(y == 0) Console.WriteLine(x);
                else gcd(y, x % y);
            };
            gcd(i[0], i[1]);
        }
    }
}

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

using namespace std;

int main()
{
    long a, b, c;
    cin >> a >> b >> c;

    if (a == b && b == c && c == a) {
        cout << "No" << endl;
    }
    else if (a != b && b != c && c != a) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N, W, D = map(int, input().split())
    if N == 0 and W == 0 and D == 0:
        exit()
    L = []
    L.append((W, D))

    for _ in range(N):
        op, le = map(int, input().split())
        cut_cake_W, cut_cake_D = L.pop(op-1)
        le = le % (cut_cake_W+cut_cake_D)
        if le < cut_cake_W:
            new_W1 = min(le, cut_cake_W-le)
            new_W2 = max(le, cut_cake_W-le)
            new_D1 = cut_cake_D
            new_D2 = cut_cake_D
        else:
            le = le-cut_cake_W
            new_W1 = cut_cake_W
            new_W2 = cut_cake_W
            new_D1 = min(le, cut_cake_D-le)
            new_D2 = max(le, cut_cake_D-le)
        L.append((new_W1, new_D1))
        L.append((new_W2, new_D2))
    L = sorted(L, key=lambda x: x[0]*x[1])
    print(" ".join(map(str, [a*b for a, b in L])))


while True:
    solve()



Measured memory_bytes: 5648
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <cmath>
#include <cstdio>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()

using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

int main(){
	int n;
	cin >> n;
	rep(i, n){
		int h, m;
		char c;
		cin >> h >> c >> m;
		int l = 60*h+m;
		int s = 12*m;
		if(l < s) swap(l, s);
		int dif = min(l-s, s-l+720);
		string mes;
		if(dif < 60) mes = "alert";
		else if(dif >= 180) mes = "safe";
		else mes = "warning";
		cout << mes << endl;
	}



    return 0;
}

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

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var cin = new MyInputStream();
            var N = cin.ReadInt();
            var T = cin.ReadInt();
            var t = new int[N];
            for (int i = 0; i < N; ++i)
                t[i] = cin.ReadInt();

            var sum = (long)T;
            var time = T;
            for (int i = 1; i < N; ++i)
            {
                if (time <= t[i])
                {
                    sum += T;
                    time = T + t[i];
                }
                else
                {
                    sum += T - time + t[i];
                    time = T + t[i];
                }
            }
            WriteLine(sum);
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() => Console.ReadLine();
        public int ReadInt() => int.Parse(Read());
        public long ReadLong() => long.Parse(Read());
        public double ReadDouble() => double.Parse(Read());
    }
}


Measured memory_bytes: 32132
import java.util.Scanner;

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

        int[] sizes = new int[n];

        for(int i = 0; i < sizes.length; i++) sizes[i] = sc.nextInt();

        int ans = 0;

        for(int e : sizes) if(e >= k) ans++;

        System.out.println(ans);
    }
}


Measured memory_bytes: 47944
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int nax = 1e6+1;


int main(){

   ll n;
   cin>>n;
   ll mi = 2*n;
   for(ll i=1;i*i<=n;i++){
    if(n%i==0){
        ll k = n/i;

        ll sum = i+k;
        mi = min(mi,sum);
    }
   }
cout<<mi-2;

return 0;
}



Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define INF 2000000000

vector <int> a;
int c;

int solve(int N)
{
    int dp[N+1];

    dp[0] = 0;
    for (int i = 1; i <= N; i++)
        dp[i] = INF;

    for (int i = 0; i < c; i++)
    {
        for (int j = a[i]; j <= N; j++)
        {
            int d = dp[j - a[i]];
            if ((d < INF) && (d + 1 < dp[j]))
            {
                dp[j] = d + 1;
            }
        }
    }

    return dp[N];
}

int main()
{
    int N;
    
    a.push_back(1);

    for (int i = 6; i <= 100000; i *= 6)
        a.push_back(i);

    for (int i = 9; i <= 100000; i *= 9)
        a.push_back(i);

    sort(a.begin(), a.end());

    c = (int)a.size();

    cin >> N;

    int j = (int)a.size()-1;
    int ans = 0;

    cout << solve(N) << endl;

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}


static void ABC099C_StrangeBank();

#if 1
int main()
{
	ABC099C_StrangeBank();
	fflush(stdout);
	return 0;
}
#endif

static void ABC099C_StrangeBank()
{
	const int ABC099C_Max = 100000;
	int N;
	get1int(N);

	std::vector<int> opeVec;
	opeVec.push_back(1);
	int exp6 = 6, exp9 = 9;
	while ((exp6 <= N) || (exp9 <= N)) {
		if (exp6 <= N) {
			opeVec.push_back(exp6);
			exp6 *= 6;
		}
		if (exp9 <= N) {
			opeVec.push_back(exp9);
			exp9 *= 9;
		}
	}
	//	こりゃやっぱりDPやね
	std::sort(opeVec.begin(), opeVec.end());

	auto dp = new int[opeVec.size() + 1][ABC099C_Max + 2];
	std::fill(&dp[0][0], &dp[opeVec.size()][N + 1], ABC099C_Max);
	dp[0][0] = 0;
	
  	int opeCount = 0;
	int size = opeVec.size();
	for (int i = 0; i < size; i++) {
		for (int j = 0; j <= N; j++) {
			if (j - opeVec[i] >= 0) {
				dp[i + 1][j] = dp[i + 1][j - opeVec[i]] + 1;
			}
			dp[i + 1][j] = tp_min(dp[i][j], dp[i + 1][j]);
		}
	}

	printf("%d\n", dp[size][N]);// ABC099C_dfs(opeVec, 0, 0, 0, N));
	delete[] dp;
}


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

int main() {
int a,b;
  cin>>a>>b;
  int cnt=0;
  if(a>=b){
    cnt+=a;
    a--;}
  else{
    cnt+=b;
    b--;}

cout<<cnt+max(a,b)<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll vec_sum(vector<ll> &vec) {
  ll res = 0;
  for (auto i : vec) {
    res += i;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  ll asum = vec_sum(a);
  ll bsum = vec_sum(b);
  if (bsum > asum) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0;
  ll lack = 0;
  vector<ll> extra;
  for (int i = 0; i < n; i++) {
    if (a[i] > b[i]) {
      extra.push_back(a[i] - b[i]);
    } else if (a[i] < b[i]) {
      lack += b[i] - a[i];
      ans++;
    }
  }
  sort(extra.begin(), extra.end(), greater<int>());
  for (auto i : extra) {
    if (lack <= 0) {
      break;
    }
    lack -= i;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2428
#include<stdio.h>
int main(void)
{
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0)break;
		for(i = 0;i < H;i++){
		 for(j = 0;j < W;j++){
		 	if((i != 0 && i != H-1) && (j != 0 && j != W-1)){
		 		printf(".");
		 	}else{
			 	printf("#");
			 }
		 }
		 printf("\n");
	 }
	 printf("\n");
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  string ans;
  
  if (s[0] == s[1] && s[0] == s[2]) ans = "Yes";
  else if (s[1] == s[2] && s[1] == s[3]) ans = "Yes";
  else { 
    ans = "No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int r, g, b, k;

void sk(int i, int r, int g, int b)
{
    if (i > k)
    {
        if (r < g && g < b)
        {
            puts("Yes");
            exit(0);
        }
        return;
    }
    sk(i + 1, r * 2, g, b);
    sk(i + 1, r, g * 2, b);
    sk(i + 1, r, g, b * 2);
}

int main()
{
    scanf("%d%d%d%d", &r, &g, &b, &k);
    sk(1, r, g, b);
    puts("No");
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    cout << h*w - (a*w + b*h - a*b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <cmath>

using namespace  std;// namespace 

int main()
{
        int q;
        cin >> q;
        list<int> A;
        list<int>::iterator cursor = A.end();
        int command,value;
        for (int i = 0; i < q; i++) {
                cin >> command;
               if(command==0){
                       cin >> value;
                        cursor=A.insert(cursor,value);
               }
               else if(command==1){
                       cin >> value;
                       for (int j = 0; j < abs(value); j++) {
                               if(value>0){
                                       cursor++;
                               }
                               else{
                                       cursor--;
                               }
                       }
               }
               else{
                       cursor=A.erase(cursor);
               }
        }
        list<int>::iterator it = A.begin();
        for(;it!=A.end();it++){
                cout << *it << endl;
        }
        return 0;
}



Measured memory_bytes: 18604
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
	int x, y; cin>>x>>y;
	if(y&1){
		cout<<"No"<<endl;
		return;
	}
	int b = (y/2) - x;
	int a = (2*x) - (y/2);
	if(a<0 || b<0) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 3688
import sys
input = sys.stdin.readline

a, b, n = map(int, input().replace("\n","").split())

ans = 0

#bがnよりも大きい時
if b > n:
    ans = int(a*n/b)
    print(ans)
    exit()

#b==nのときは、終了間際の2個だけ比較する
elif b == n:
    for i in range(n-1,n+1):
        tmpans = int(a*i/b) - (a*int(i/b))
        if tmpans >= ans:
            ans = tmpans
    print(ans)
    exit()

#これ以外の時は、nはb値ごとにスキップする。
else:
    for i in range(int(n/b),n+1,b):
        tmpans = int(a*(i-2)/b) - (a*int((i-2)/b))
        if tmpans >= ans:
            ans = tmpans

print(ans)

Measured memory_bytes: 61952
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<ll> T(N), A(N);
  ll tmpT = 1, tmpA = 1;
  rep(i, N) {
    cin >> T[i] >> A[i];
    // ll tmp = max((tmpT + T[i] - 1) / T[i],
    //              (tmpA + A[i] - 1) / A[i]);
    ll tmp = max(ceil((long double)tmpT / T[i]),
                 ceil((long double)tmpA / A[i]));
    tmpT = tmp * T[i];
    tmpA = tmp * A[i];
  }
  cout << tmpT + tmpA << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
void chmin(ll &x, ll y) { x = min(x, y); }
void chmax(ll &x, ll y) { x = max(x, y); }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<ll> v;
    rep(i, s.size()){
        char c = s[i];
        int cnt = 0;
        while(i < s.size() && c == s[i]){
            cnt++;
            i++;
        }
        v.push_back(cnt);
        i--;
    }
    cout << v.size() << endl;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1e9+7
using namespace std;

int vote[1010];

int main(){
  int N,M,A,B,ma=0,ans;
  cin >> N >> M;
  vector<pair<int,int> > v;
  REP(i,N-1){
    cin >> A;
    v.push_back(make_pair(i,A));
  }
  sort(v.begin(),v.end());
  FOR(i,0,M){
    cin >> B;
    int voteto;
    for(auto x:v)if(x.second <= B)voteto = N - x.first;
    vote[voteto]++;
  }
  FOR(i,0,1010){
    if(ma < vote[i]){
      ma = vote[i];
      ans = i;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3104
#include<iostream>

using namespace std;

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int cnt = 0;
	while (b <= a) {
		b *= 2;
		cnt++;
	}
	while (c <= b) {
		c *= 2;
		cnt++;
	}
	if (cnt <= k) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 3104
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;
const int MAXN = 205;
const int INF = (int)1e8;

int dist[MAXN][MAXN];

int main() {
  int n, m, R;
  scanf("%d %d %d", &n, &m, &R);

  vector<int> r(R);
  for (int i = 0; i < R; ++i) {
    scanf("%d", &r[i]);
    r[i]--;
  }
  
  sort(r.begin(), r.end());

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) dist[i][j] = 0;
      else dist[i][j] = INF;
    }
  }

  for (int i = 0; i < m; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--; b--;
    dist[a][b] = min(dist[a][b], c);
    dist[b][a] = min(dist[b][a], c);
  }

  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
	dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int ans = INF;
  do {
    int sum = 0;
    for (int i = 1; i < R; ++i) {
      sum += dist[r[i - 1]][r[i]];
    }
    ans = min(ans, sum);
  } while (next_permutation(r.begin(), r.end()));

  printf("%d\n", ans);
  return 0;
}



Measured memory_bytes: 384
n = int(input())
S = [s for s in input()]
e,w = [0],[0]
for i in range(n):
    if S[i] is 'W': e.append(e[i]+1)
    else:   e.append(e[i])
    if S[n-i-1] is 'E': w.append(w[i]+1)
    else:   w.append(w[i])
w = w[::-1]
ans = float('inf')
for i in range(n+1):
    ans = min(ans,e[i]+w[i])
print(ans)


Measured memory_bytes: 22640
#include <iostream>
#include <map>
#include <string>
#include <queue>
#include <string.h>
#include <math.h>
#define ll long long
using namespace std;
int p,q;
int dp[20][20];
string s;
int dfs(int l,int r)
{
	if(dp[l][r] != -1) return dp[l][r];
	if(l>=p||r<=q) return dp[l][r] = 3;
	if( (s[l] == '{' && s[r] =='}') || (s[l] == '}' && s[r] =='{') || ( (s[l] == '[' && s[r] ==']') || (s[l] == ']' && s[r] =='[') ) || ( (s[l] == '(' && s[r] ==')') || (s[l] == ')' && s[r] =='(') ) )
		 return dp[l][r] = (2 + dfs(l+1,r-1)) ;
	else return dp[l][r] = max( dfs(l+1,r) , dfs(l,r-1) );		
}
int main()
{
	std::ios::sync_with_stdio(false);
	
	while(cin>>s)
	{
		int len = s.length();
		p = q = -1;
		for(int i=0;i<len;i++)
		{
			if(s[i] == 'i')
				if(p == -1)
					p = i;
				else 
				{
					q = i;
					break;
				}
		}
		memset(dp,-1,sizeof(dp));
		cout<<dfs(0,len-1)<<endl;
	}
	return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int atcoder;
  char s;
  int contest;
  cin >> atcoder >> s >>contest;
  int answer;
  if(s == '+'){
  answer = atcoder + contest;
  }
  if(s == '-'){
  answer = atcoder - contest;
  }
 cout << answer << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
string s;
int len;
int main(){
	cin>>s;
	len=s.size();
	for (int i=0;i<len-1;i++){
		if (s[i]==s[i+1]){
			cout<<i+1<<" "<<i+2;
			return 0;
		}
	}
	for (int i=0;i<len-2;i++){
		if (s[i]==s[i+2]){
			cout<<i+1<<" "<<i+3;
			return 0;
		}
	}
	cout<<"-1 -1";
	return 0;
}

Measured memory_bytes: 512
n, k = map(int, input().split())
h = list(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0

for i in range(n - 1):
    for j in range(1, k + 1):
        if i + j >= n:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))

print(dp[-1])


Measured memory_bytes: 55008
/*       _________
        /|______/ \
        ||  _|_|\  |
        || |_|   | /
        ||    _ / |
        ||  _| \\  \    
        ||_|_|\ || |
        |/_|/ | /|_/
              /__/      Written by: Rishabh Roshan
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int            	long long
#define tree            ped
#define integer        	int32_t
#define mod         	1000000007
#define vint        	vector<int>
#define pint        	pair<int, int>
#define umint        	unordered_map<int, int>
#define mint        	map<integer, integer>
#define in(x)        	int x; cin>>x
#define setbits(x)    	__builtin_popcountll(x)
#define zerobits(x)    	__builtin_ctzll(x)
#define w(x)        	int x; cin>>x; while(x--)
#define sp(x, y)    	fixed<<setprecision(y)<<x
#define poll(x)        	x.front(); x.pop()
#define f(x)        	for(int i=0; i<x; i++)
#define fj(x)			for(int j=0; j<x; j++)
#define fn(n, x)		for(int i=n; i<x; i++)
#define endl         	'\n'
#define inf         	1e9 
#define order_set     	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

void om_shree_ganeshaya_namah(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {

    om_shree_ganeshaya_namah();

    in(a); in(b); in(c); in(d);
    int x1 = a*c, x2 = a*d;
    int y1 = b*c, y2 = b*d;
    int ans = max(x1, max(x2, max(y1, y2)));
    cout<<ans;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0; i<n; i++)
int main()
{
	ll N;
	cin >> N;
	vector<ll> A(N);
	rep(i,N)
		cin >> A[i];

	ll ans = 0;

	for(int i = 1; i<N; i++){
		if(A[i-1] > A[i]){
			ans = ans + A[i-1] - A[i];
			A[i] = A[i-1];
		}
	}

	cout << ans;

	cin >> N;
	
	return 0;	
}


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

// Macros
#define F  first
#define S  second
#define PB push_back

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// HELPERS
//  Tedious Grid Movements
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
inline bool move_okay(int x, int y, int n, int m) { return 0 <= x and x < n and 0 <= y and y < m; }
//  Remember:
//   * vec.assign() GOOD; vec.resize() BAD
//   * comparator uses <

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const set<T> &v)    { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T,S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T,S> &v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef SANYAM1101
	#define trace(args...) do{ cerr << "TRACE ON! (Line: " << __LINE__ << ")\n"; auto _stream = istringstream{string{#args}}; d_f(_stream, args); } while(0)
	void d_f(__attribute__((unused)) istringstream& _stream) {}
	template<typename Head, typename... Tails> void d_f(istringstream& _stream, Head H, Tails... T) { string _name; _stream >> _name; if(_name.back() == ',') _name.pop_back(); cerr << "\t" << _name << " <=> [" << H << "]\n"; d_f(_stream, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

void solve(){
	int num = 0;

	for(int i = 0; i < 3; ++i){
		int x; cin >> x;
		num = num * 10 + x;
	}

	cout << (num % 4 ? "NO\n" : "YES\n");
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


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

using namespace std;

int main() {
        int a1,a2,a3;
        cin >> a1 >> a2 >> a3;
        
        if(a1 + a2 + a3 >= 22) cout << "bust" << endl;
        else cout << "win" << endl;
        
        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define int ll


const int MAX=510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        //???
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}


//n!
ll fact_mod(ll n) {
    ll ret=1; 
    for(ll i=2;i<=n;i++) ret=ret*(i%mod)%mod;
    return ret;
}
 
// 繰り返し二乗法 
ll pow_mod(ll x, ll n){
    if(n==0) return 1;
    ll ret=pow_mod((x*x) % mod, n/2);
    if(n&1) ret=(ret*x)%mod;
    return ret;
}
 
//nCr O(r) nがでかくても安心
ll combination_mod(ll n, ll r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    ll a=1;
    //a=n!/(n-r)!=n~n-r+1までの総積->O(r)
    for(ll i=0;i<r;i++) a=a*((n-i)%mod)%mod;
    //b=inv(r!)
    ll b=pow_mod(fact_mod(r), mod-2);
    return (a%mod)*(b%mod)%mod;
}
 
ll inv_mod(ll n){
    // フェルマーの小定理
    return pow_mod(n,mod-2);
}


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

    COMinit();

    int n;cin>>n;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];


    /*
    O->O->O->O->O
    みたいなグラフを考え，矢印のとる順番が(n-1)!通り
    仮に上のグラフの辺を左から1,2,3,4とし，2,1,3,4ととると，
    O->O->O->O->O
    O---->O->O->O
          O->O->O
             O->O
                O
    となる．(n-1)!通りで移動した総和を求める
    上のような辺が4本あるとき，一番右の辺がとられる回数は
    右から2番目のスライムの移動によるもの->4!
    右から3番目  -> 一番右の辺より後に右から二番目の辺をとれればいいので
                        4!/2!
    右から4番目  -> 一番右の辺と右から二番目の辺の後にとれればいいので
                        (4!/3!)*2!=4!/3
    右から5番目  ->  (4!/4!)*3!=4!/4
    */

    vector<ll> sum(n);
    sum[0]=0;
    for(int i=1;i<n;i++){
        sum[i]=fac[n-1]*inv[i]%mod+sum[i-1];
    }
    ll ans=0;
    rep(i,n-1){
        ll dis=v[i+1]-v[i];
        ans+=dis*sum[i+1]%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main()
{
    string s,t;
    cin >>s;
    cin >> t;
    int co=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i])co++;
    }
    cout << co << endl;
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i = a;i<=b;++i)
#define For_(i,a,b) for(int i = a;i>=b;--i)
#define endl '\n'
typedef long long LL;
inline int read(){
    int r = 0,f = 1;
    char c = getchar();
    while(c<'0' || c >'9'){
        if(c =='-') f = -1;
        c = getchar();
    }
    while(c>='0' && c<='9'){
        r = (r<<1) + (r<<3) + c - '0';
        c = getchar();
    }
    return r * f;
}

const int N = 9,Mod = 1e9 + 7;
LL ans;

LL mpow(LL x,LL y,LL m = Mod){
    LL res = 1%m;
    while(y){
        if(y & 1) res = res * x%m;
        x = x * x % m;
        y >>= 1;
    }
    return res;
} 
int main(){
    int n = read();
    LL ans = mpow(10,n);
    ans = (ans - mpow(9,n))%Mod;
    ans = (ans - mpow(9,n))%Mod;
    ans = (ans + mpow(8,n))%Mod;
    ans %= Mod;
    if(ans < 0) ans += Mod;
    cout<<ans<<endl;
    system("pause"); 
    return 0;
}

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

int main () {
  int A, B, C;
  cin >> A >> B >> C;
  for (int i = 1; i < B; i++) {
    if (A*i%B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
 int H,W,h,w,s=0,s2=0,s3=0;

 scanf("%d %d %d %d",&H,&W,&h,&w);

 s=H-h;

 s2=W-w;

 s3=s*s2;

 printf("%d",s3);

 return 0;}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n; cin >> n;

    vector<ll> x(n);
    for (ll i = 0; i < n; ++i) {
        cin >> x[i];
    }

//    sort(x.begin(), x.end());

    ll ans = LINF;

    for (ll i = 1; i <= 100; ++i) {
        ll sum = 0;

        for (ll j = 0; j < n; ++j) {
            sum += (x[j] - i) * (x[j] - i);
        }

        ans = min(ans, sum);
    }

    cout << ans << endl;
}

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

int n, m;
int d[100];

bool check(int x)
{
	string s = to_string(x);
	for(int i = 0; i < s.size(); i++)
	{
		if(d[i] == -1) continue;
		if(d[i] != s[i] - '0') return false;
	}
	return true;
}

int32_t main()
{   
	memset(d, -1, sizeof(d));
	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		if(d[x - 1] != -1 and d[x - 1] != y) return puts("-1"), 0;
		d[x - 1] = y;
	}
	int l = 1, u;
	for(int i = 0; i < n - 1; i++)
		l *= 10;
	u = l * 10;
	
	if(l == 1) l = 0;
	
	for(int i = l; i < u; i++)
		if(check(i))
			return cout << i << '\n', 0;

	puts("-1");
	
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long

int main(){

    int n;cin >> n;
    ll int a[n],ans = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        ans += a[i]-1;
    }
    cout << ans << endl;

    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var S = ReadLine();
        var T = ReadLine();

        static int GetDiff(string s, string t) => s.Zip(t, (_s, _t) => _s != _t ? 1 : 0).Sum();

        var ans = Enumerable.Range(0, S.Length - T.Length + 1).Select(i => GetDiff(S.Substring(i, T.Length), T)).Min();

        WriteLine(ans);
    }
}


Measured memory_bytes: 27156
#include<iostream>
using namespace std;
int main()
{
  long int n;
  for(;cin>>n,n;)
    {
      int i=0;
      for(;n!=1;)
      {
	if(n%2==0)
	  n/=2;
	else
	  n=n*3+1;
	i++;
      }
      cout<<i<<endl;
    }
}

Measured memory_bytes: 1160
<?php
// Your code here!
$n = fgets(STDIN);
$a = explode(" ",fgets(STDIN));
$ans = 1000;
foreach($a as $d)
{
    $c = 0;
    while($d%2 == 0)
    {
        $c += 1;
        $d /= 2;
    }
    $ans = min($c ,$ans);
}
echo($ans)
?>


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 12800;

#define forn(i, n) for(int i = 0; i < n; i++)
#define forsn(i, s, n) for(int i = s; i < n; i++)

void dfs(int node, int par, vvi &edges, vi &parent, vi &height){
	height[node] = 0;
	for(int child : edges[node]){
		if(child != par){
			parent[child] = node;
			dfs(child, node, edges, parent, height);
			height[node] = max(height[node], height[child] + 1);
			// trace1(height[node]);
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n, u, v;
	cin >> n >> u >> v;
	// swap(u, v);
	// cout << "Takahashi: " << u << " Aoki: " << v << endl;
	vvi edges(n + 1);
	forn(i, n - 1){
		int x, y;
		cin >> x >> y;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	vi parent(n + 1, 0);
	parent[v] = v;
	vi height(n + 1);
	dfs(v, v, edges, parent, height);
	// debugtwo(height);
	// int dist1 = height[v] - height[u];
	int current = u;
	int dist1 = 0;
	while(current != v){
		dist1++;
		current = parent[current];
	}
	int ans = 0;
	// trace2(height[v], height[u]);
	if(dist1 % 2 == 1){
		// cout << "here" << endl;
		// trace1(dist1);
		int move = (dist1 - 1) / 2;
		move = max(move, 0);
		ans += move;
		int curnode = u;
		while(move--){
			curnode = parent[curnode];
		}
		ans += height[curnode];
	}
	else{
		int move = (dist1 - 2) / 2;
		move = max(move, 0);
		ans += move;
		int curnode = u;
		while(move--){
			curnode = parent[curnode];
		}
		ans += height[curnode] + 1;
	}
	cout << ans << endl;
}		

Measured memory_bytes: 14208
n = gets().to_i
ans = 0
a = gets.split(" ").map{|e|e.to_i}
gets.split(" ").map{|e|ans += e.to_i}
c = gets.split(" ").map{|e|e.to_i}

0.upto(n-2) do |i|
	if a[i]+1 == a[i+1] then 
		ans += c[a[i]-1]
	end
end

p(ans)

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

char stk[128];
int sp;

void push(char c){
  stk[sp++] = c;
}
int pop(){
  if (sp==0) return -1;
  return stk[--sp];
}

int main(void){
  string buf;
  int flg, t;
  
  while (true){
    getline(cin, buf);
    if (buf==".") break;
    sp = 0;
    flg = 1;
    for (int i=0; i<buf.size(); i++){
      if (buf[i]=='(' || buf[i]=='['){
        push(buf[i]);
      } else if (buf[i]==')' || buf[i]==']'){
        t = pop();
        if ((buf[i]==')' && t!='(') || (buf[i]==']' && t!='[')){
          flg = 0;
          break;
        }
      }
    }
    if (sp) flg = 0;
    cout << (flg?"yes":"no") << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

    int A, B;

    cin >> A >> B;

    if(A >= 13){
        cout << B << endl;
    }else if( A >= 6){
        cout << B/2 << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int dp[3100][3100];

int main(){
    string s,t; cin >> s >> t;
    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j < t.size(); j++){
            if(s[i]==t[j]) dp[i+1][j+1] = dp[i][j]+1;
            else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        }
    }
    //復元
    string res = "";
    int i = (int)s.size(), j = (int)t.size();
    while(i > 0 && j > 0){
        if(dp[i][j]==dp[i-1][j]){
            --i;
        }else if(dp[i][j]==dp[i][j-1]){
            --j;
        }else{
            res = s[i-1] + res;
            --i,--j;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 37120
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

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

  int totaltime = 0;
  vi tn;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    tn.pb(k);

    totaltime += k;
  }

  cin >> m;
  vii dr;
  for (int i = 0; i < m; ++i) {
    int pi, xi;
    cin >> pi >> xi;
    dr.pb(mp(pi, xi));
  }

  for (int i = 0; i < m; ++i) {
    int p = dr.at(i).first-1;
    int x = dr.at(i).second;
    cout << totaltime-tn.at(p)+x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int ask(int x){
    if(x&1) return x+n;
    return x;
}
int main(){
    scanf("%d",&n);
    if(n<3) return printf("No\n"),0;
    int y=n,flag=0;
    while(y>1){
    flag|=y&1;
    y>>=1;
    }
    if(!flag) return printf("No\n"),0;
    printf("Yes\n");
    printf("%d %d\n",n+1,n+2);
    for(int i=2;i<n;i+=2){
    printf("%d %d\n",1,i);
    printf("%d %d\n",i,i+1);
    printf("%d %d\n",1,i+n+1);
    printf("%d %d\n",i+n,i+n+1);
    }
    if(n%2==0){
    for(int i=2;i<n;i++){
        if(((n^1^i)<n)&&((n^1^i)>1)&&(n^1^i)!=i){
        printf("%d %d\n",ask(i),n);
        printf("%d %d\n",ask(n^1^i),2*n);
        return 0;
        }
    }
    }
}


Measured memory_bytes: 2304
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<complex>
#define EQ(x,y) (fabs((x)-(y))<EPS)
#define pb push_back
#define sq(x) ((x)*(x))
using namespace std;
const double EPS=1e-8;
const double INF=1e12;
double PI=3.14159265359;
typedef complex<double> P;
namespace std{
	bool operator< (const P& a,const P& b){
		return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
	}
}
struct C{
	P p;double r;
	C(const P &p,double r):p(p),r(r){}
};
vector<P>crosspointCC(const C &c1,const C &c2){
	vector<P>res;
	P v=c2.p-c1.p;
	double d=abs(v);
	if(d<EPS){
		if(EQ(c1.r,c2.r)){
			res.pb(c1.p+P(c1.r,0));
		}
		return res;
	}
	vector<double>thetas;
	if(EQ(d,c1.r+c2.r)){//return res;
		thetas.pb(0);
	}else if(EQ(c1.r-c2.r,d)){//return res;
		thetas.pb(0);
	}else if(EQ(c2.r-c1.r,d)){//return res;
		thetas.pb(PI);
	}else if(d>c1.r+c2.r||d<abs(c1.r-c2.r)){
		return res;
	}else{
		//printf("%f\n",((sq(c1.r)+sq(d)-sq(c2.r))/(2.0*c1.r*d)));
		double t=acos((sq(c1.r)+sq(d)-sq(c2.r))/(2.0*c1.r*d));
		thetas.pb(t);
		thetas.pb(-t);
	//}
	//printf("%f %f \n",real(c1.p),imag(c1.p));
	for(int i=0;i<thetas.size();i++){
		res.pb(c1.p+c1.r/d*v*P(cos(thetas[i]),sin(thetas[i])));

		//printf("%f %f %f\n",thetas[i],real(res[i]),imag(res[i]));
	}}
	return res;
}
double x[10];
double y[10];
double l[10];

int main(){
	int a;
	//printf("%f %f\n",real(crosspointCC(C(P(0,0),2),C(P(1,0),2))[0]),imag(crosspointCC(C(P(0,0),2),C(P(0,1),2))[0]));
	//return 0;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%lf%lf%lf",x+i,y+i,l+i);
		double left=0;
		double right=10000;
		for(int i=0;i<100;i++){
			double M=(left+right)/2;
			bool dame=false;
			vector<P> una;
			for(int j=0;j<a;j++){
				for(int k=j+1;k<a;k++){
					if(M*M>l[j]*l[j]||M*M>l[k]*l[k]||sqrt(sq(x[j]-x[k])+sq(y[j]-y[k]))>sqrt(sq(l[k])-sq(M))+sqrt(sq(l[j])-sq(M))){
						dame=true;
						continue;
					}
					//if()
					vector <P> fox=crosspointCC(C(P(x[j],y[j]),sqrt(l[j]*l[j]-M*M)),C(P(x[k],y[k]),sqrt(l[k]*l[k]-M*M)));
					//if(fox.size()==0)dame=true;
					for(int m=0;m<fox.size();m++)una.push_back(fox[m]);
				}
			}
			una.push_back(P(0.0,0.0));
			for(int j=0;j<a;j++)una.push_back(P(x[j],y[j]));
			//printf("%f :",M);
			//if(dame)printf("dame\n");
			//else printf("\n");
			if(dame){
				right=M;
				continue;
			}

			bool ok=false;
			for(int k=0;k<una.size();k++){
				bool OK=true;
				
				
			//	if(M>72.2&&M<72.4)printf("%d %f %f\n",k,real(una[k]),imag(una[k]));
				if(isnan((long double)real(una[k]))||isnan((long double)imag(una[k])))continue;
				for(int j=0;j<a;j++){
				
					if(abs(P(x[j],y[j])-una[k])*abs(P(x[j],y[j])-una[k])>EPS+(l[j])*(l[j])-M*M){
					if(M>72.2&&M<72.4){
				//		printf("%f %f %d %f %f\n",real(una[k]),imag(una[k]),j,abs(P(x[j],y[j])-una[k])*abs(P(x[j],y[j])-una[k]),(l[j])*(l[j])-M*M);
					}					
					OK=false;
					}
				}
				if(OK)ok=true;
			}
			if(ok)left=M;
			else right=M;
		}
		printf("%.9f\n",left);
	}
}

Measured memory_bytes: 1204