akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s;
    cin >> s;
    map<char, vector<int>> mp;
    rep(i,s.size()){
        if (mp[s[i]].size() == 0){
            mp[s[i]].push_back(0);
        }
        mp[s[i]].push_back(i+1);
    }
    int ans = 100;
    for(char c = 'a'; c <= 'z'; c++){
        if (mp.find(c) == mp.end()) continue;
        mp[c].push_back(s.size()+1);
        int num = 0;
        rep(i, mp[c].size()-1){
            num = max(num, mp[c][i+1] - mp[c][i]-1);
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
    return 0;
}   

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  string s;cin>>s;
  ll k;cin>>k;
  if(k>(ll)s.size())k=(ll)s.size()+1;
  int index=-1, not_one;
  for(int i=0;i<(int)s.size();i++){
  	if(s[i]!='1'){
      index = i;not_one=s[i]-'0';
      break;
    }
  }
  if(index==-1)cout<<1<<endl;
  else cout<<(index<(int)k?not_one:1)<<endl;
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a=max(a,c);
    b=min(b,d);
    cout<<max(b-a,0)<<"\n";
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

#############
# Main Code #
#############

N, M = getNM()
A = set(getArray(M))

dp = [0] * (N + 1)
dp[0] = 1

for i in range(1, N + 1):
    if not i in A:
        if i == 1:
            dp[i] = dp[i - 1] % mod
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print(dp[N] % mod)

Measured memory_bytes: 72280
list_num = list(map(int, input().split()))
list_num.sort()
dif_1 = list_num[-1] - list_num[0]
dif_2 = list_num[-1] - list_num[1]
if (dif_1 - dif_2) % 2 == 0:
  result = dif_1 + (dif_2 - dif_1) // 2
else:
  result = dif_1 + (dif_2 - dif_1) // 2 + 2
print(result)

Measured memory_bytes: 3060
#include <stdio.h>
typedef long long int ll;
const int MOD=1e9+7;
const int N=2e3+10;
ll fac[N];
ll pow(ll a,ll t){
    if(t==0)return 1;
    ll temp=pow(a,t/2);
    temp*=temp;
    temp%=MOD;
    if(t&1){
        temp*=a;
        temp%=MOD;
    }
    return temp;
}
ll rev(ll n){return pow(n,MOD-2);}
ll C(int n,int k){return (fac[n]*((rev(fac[k])*rev(fac[n-k]))%MOD))%MOD;}
ll H(int n,int k){return C(n+k-1,k);}
void init(){
    fac[0]=fac[1]=1;
    for(int i=2;i<N;i++)fac[i]=(fac[i-1]*i)%MOD;
    return ;
}
int main(){
    int n,k,now=1;
    ll ans=0;
    scanf("%d%d",&n,&k);
    init();
    printf("%lld\n",H(k,n));
    
}


Measured memory_bytes: 2764
MOD = 10**9+7
# 逆元を前計算しておくことでクエリをO(1)で返す
MAX = 10**6
fac = [0]*MAX  # fac[n]:  (n!) mod p
finv = [0]*MAX # finv[n]: (n!)^-1 mod p
inv = [0]*MAX  # inv[n]:  (n)^-1 mod p

def comb_init():
    global fac, finv, inv
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD//i)%MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def comb(n:int, r:int)->int:
    global fac, finv
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

if __name__ == '__main__':
    N,M = map(int, input().split())
    ans = 1
    comb_init()
    
    #  素因数分解
    i=2
    nokori = M
    while i*i <= nokori:
        if nokori%i==0:
            cnt = 0
            while nokori%i==0:
                cnt += 1
                nokori //= i
            ans *= comb(N+cnt-1, N-1)
            ans %= MOD
        i += 1
            
    if nokori != 1:
        ans *= comb(N+1-1, N-1)
        ans %= MOD
        
    print(ans)


Measured memory_bytes: 121716
import java.util.Scanner;

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

		long sum = 0;
		for(int i=1; i<=N; i++){
			boolean bFizz = false;
			if(i%3==0){
				bFizz = true;
				continue;
			}
			boolean bBuzz = false;
			if(i%5==0){
				bBuzz = true;
				continue;
			}
			sum += i;
		}
		
		System.out.printf("%d\n", sum);
	}
}

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

int main(){
  int i,l;
  char s[21];
  char res[21];

  memset(s,'\0',21);
  memset(res,'\0',21);
  scanf("%s",s);
  l = strlen(s);
  for(i=0;i<l;i++){
    res[i] = s[l-i-1];
  }
  printf("%s\n", res);

  return 0;
}



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

int b[5];
int main()
{
    cin >> b[0] >> b[1] >> b[2];
    sort(b, b + 3);
    if (b[0] + b[1] == b[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    int ans = 0;
    vector<int> A(N);
    int total = 0;
    for(int i=0;i<N;i++) {
        cin >> A[i]; 
        total += A[i];
    }
    for(int i=0;i<N;i++) if(A[i] >= total*(1/(4.0*M))) ans++;

    cout << (ans >= M ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int N;
	cin >> N;
	int count = 0, count_max = 0, max_i = 1, tmp;
	for(int i = 1; i <= N; i++) {
		tmp = i;
		while(tmp % 2 == 0) {
			tmp /= 2;
			count++;
		}
		if(count > count_max) {
			count_max = count;
			max_i = i;
		}
		count = 0;
	}

	cout << max_i << endl;
}


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

public class Main {
	
	public static class Team implements Comparable<Team>{
		int id, attr, ac, wa;

		public Team(int id, int attr, int ac, int wa) {
			super();
			this.id = id;
			this.attr = attr;
			this.ac = ac;
			this.wa = wa;
		}

		@Override
		public int compareTo(Team arg0) {
			if(this.ac != arg0.ac){
				return arg0.ac - this.ac;
			}else if(this.wa != arg0.wa){
				return this.wa - arg0.wa;
			}else{
				return this.id - arg0.id;
			}
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			Team[] teams = new Team[n];
			for(int i = 0; i < n; i++){
				teams[i] = new Team(sc.nextInt(), sc.nextInt() - 1, sc.nextInt(), sc.nextInt());
			}
			
			Arrays.sort(teams);
			
			int[] attr_count = new int[1000];
			
			int count = 0;
			for(int i = 0; i < n; i++){
				final int safe = count < 10 ? 3 : count < 20 ? 2 : count < 26 ? 1 : 0;

				if(attr_count[teams[i].attr] < safe){
					count++;
					attr_count[teams[i].attr]++;
					System.out.println(teams[i].id);
					//System.out.println(teams[i].ac + " " + teams[i].wa);
				}
			}
		}
	}

}

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 200111, inf = 1000111222;

int model(vector<ll> v) {
    int ans = 0;
    while (true) {
        int posmax = 0;
        for (int i = 1; i < v.size(); ++i) {
            if (v[i] > v[posmax]) {
                posmax = i;
            }
        }
        if (v[posmax] >= v.size()) {
            ++ans;
            v[posmax] -= v.size();
            for (int j = 0; j < v.size(); ++j) {
                if (j != posmax) {
                    v[j]++;
                }
            }
        } else break;
    }
    return ans;
}

void solve(ll k) {
    vector<ll> ans;
    ll fst = k / 50;
    for (int i = 0; i < 50; ++i) {
        ans.PB(fst + i);
    }
    ll ost = k % 50;
    for (int i = 0; i < ost; ++i) {
        ans[ans.size() - 1 - i]++;
    }
    cout << 50 << endl;
    for (int i = 0; i < ans.size(); ++i) {
        cout << ans[i] << ' ';
    }
    cout << endl;
    //if (model(ans) == k) cout << "TRUE" << endl;
}

int main()
{
    ll n;
    cin >> n;
    solve(n);
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    ll X, Y;
    cin >> X >> Y;

    ll res = 0;
    ll now = X;
    while (now <= Y) {
        ++res;
        now *= 2;
    }

    cout << res << "\n";
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<int,int>p;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
	vector< long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
long long mod = 1e9 + 7;
vector<p> graph[100004];
int color[100004] = { 0 };
void dfs(int now, int par) {
	for (int i = 0; i < graph[now].size(); i++) {
		int to = graph[now][i].first;
		if (to != par) {
			if (graph[now][i].second % 2)color[to] = 1 - color[now];
			else color[to] = color[now];
			dfs(to, now);
		}
	}
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout <<fixed<< setprecision(16);
	int n;
	cin >> n;
	int u, v, w;
	for (int i = 0; i < n - 1; i++) {
		cin >> u >> v >> w;
		graph[u].push_back(p(v, w));
		graph[v].push_back(p(u, w));
	}
	dfs(1,-1);
	for (int i = 1; i <= n; i++) {
		cout << color[i] << "\n";
	}
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vi a(N);
    rep(i,N) cin>>a[i];
    int ans=0;
    rep(i,N)if(i%2==0 && a[i]%2==1){
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
from itertools import permutations
N = int(input())
P = tuple(list(map(int,input().split())))
Q = tuple(list(map(int,input().split())))
cnt = 0
for x in permutations(range(1,N+1),N):
    if P==x:
        indP = cnt
    if Q==x:
        indQ = cnt
    cnt += 1
print(abs(indP-indQ))

Measured memory_bytes: 73360
import fractions
n = int(input())
ans = 0
AB = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n - 1, -1, -1):
    AB[i][0] += ans
    if AB[i][0] % AB[i][1] != 0:
        ans += AB[i][1] - AB[i][0] % AB[i][1]
        AB[i][0] += AB[i][1] - AB[i][0] % AB[i][1]
    #print(AB, ans)
print(ans)


Measured memory_bytes: 33336
def floorsum(n,m,a,b):
  ans=0
  if a>=m:
    ans+=(n-1)*n*(a//m)//2
    a%=m
  if b>=m:
    ans+=n*(b//m)
    b%=m
  y_max=(a*n+b)//m; x_max=(y_max*m-b)
  if y_max==0:return ans
  ans+=(n-(x_max+a-1)//a)*y_max
  ans+=floorsum(y_max,a,m,(a-x_max%a)%a)
  return ans
n=int(input())
ans=[]
for _ in range(n):
  n,m,a,b=map(int,input().split())
  ans+=[floorsum(n,m,a,b)]
print(*ans,sep='\n')

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

using namespace std;

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

  int count = 0;
  for(int i = 0; i < N - 1; i++) {
    if(a[i] == a[i + 1]) {
      count++;
      a[i + 1] = 110;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int N, K;
vector<int> a;

int dp[100010];

bool Solve(int k)
{
    if (dp[k] >= 0) return dp[k];

    bool win = false;
    rep(i, 0, N)
    {
        if (k - a[i] >= 0)
        {
            win |= !Solve(k - a[i]);
        }
    }

    return dp[k] = win;
}

void _main()
{
    memset(dp, -1, sizeof(dp));

    cin >> N >> K;
    a.resize(N);
    rep(i, 0, N) cin >> a[i];
    cout << (Solve(K) ? "First" : "Second") << endl;
}


Measured memory_bytes: 5376
K,N =(int(x) for x in input().split())
array = list(map(int, input().strip().split()))
between = [0] * N
for i in range(N-1):
    between[i] = array[i+1] -array[i]
between[N-1] = K- array[N-1]  + array[0]

print(K-max(between))

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

int main()
{
   int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (a*b >= c*d)
    {
        printf("%d", a*b);
    }
    else 
    {
        printf("%d", c*d);
    }
   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int N;
    double p[3100];
    double dp[3100][3100];
    double ans = 0.0;
    int i, j, k;

    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%lf", &p[i]);
    }
    dp[0][0] = 1.0;
    for(i=0; i<N; i++){
        for(j=0; j<=i; j++){
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] *(1.0 -p[i]);
        }
    }

    for(i=(N+1)/2; i<=N; i++){
        ans += dp[N][i];
    }

    printf("%.10lf", ans);

    return 0;
}

Measured memory_bytes: 74112
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

ll x;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> x;
	ll ma = 0;
	for (int i = 0; i <= 100000000; i++) {
		ma += i;
		if (x <= ma) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

namespace AtCoderBeginnerContest152
{
	class Program
	{
		static void Main(string[] args)
		{
			var number = int.Parse(Console.ReadLine());
			var numbers = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

			var result = 0;
			var min = int.MaxValue;
			for(var i = 0; i < number; i++)
			{
				if(numbers[i] <= min)
				{
					min = numbers[i];
					result++;
				}
			}
			Console.WriteLine(result);
		}
	}
}


Measured memory_bytes: 34508
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

// i番目まで選んだ時、合計jになるのがいくつあるか。
ll dp[55][5000];

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

    int N, A;
    cin >> N >> A;
    vector<ll> x(N);
    rep(i, N) {
        cin >> x[i];
        x[i] -= A;
    }

    memset(dp, 0, sizeof(dp));
    dp[0][2500] = 1;

    rep(i, N) {
        rep(j, 5000) {
            if (dp[i][j] == 0)
                continue;
            dp[i + 1][j] += dp[i][j];
            if (j + x[i] >= 0)
                dp[i + 1][j + x[i]] += dp[i][j];
        }
    }

    ll ans = dp[N][2500] - 1;
    cout << ans << endl;
}

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

using namespace std;

const int maxn = 1e5 + 5;
int n;
int a[maxn];
int main() {
    scanf("%d", &n);
    int cnt4 = 0;
    int cnt2 = 0;
    int cnt1 = 0;
    for(int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        if(x % 4 == 0) cnt4++;
        else if(x % 2 == 0) cnt2++;
        else cnt1++;
    }
    if(cnt2 == 0) {
        if(cnt4 >= cnt1 - 1)
            printf("Yes\n");
        else
            printf("No\n");
    } else {
        if(cnt4 >= cnt1)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    map<int,int> a;
    int n;
    cin >> n;
   for(int i=1;i<=100;i++){
       for(int j=1;j<=100;j++){
           for(int k=1;k<=100;k++){
               if(i*i+j*j+k*k+i*j+j*k+k*i>10000) continue;
               a[i*i+j*j+k*k+i*j+j*k+k*i]++;
           }
       }
   }
   for(int i=1;i<=n;i++){
       cout << a[i] << endl;
   }
}


Measured memory_bytes: 3964
//by Sshwy
//#define DEBUGGER
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)

#ifdef DEBUGGER

#define log_prefix() { fprintf(stderr, "\033[37mLine %-3d [%dms]:\033[0m  ", __LINE__,(int)clock()/1000);  }
#define ilog(...)    { fprintf(stderr, __VA_ARGS__); }
#define llog(...)    { log_prefix(); ilog(__VA_ARGS__); }
#define log(...)     { log_prefix(); ilog(__VA_ARGS__); fprintf(stderr,"\n");  }
#define red(...)     { log_prefix(); ilog("\033[31m"); ilog(__VA_ARGS__); ilog("\033[0m\n"); }
#define green(...)   { log_prefix(); ilog("\033[32m"); ilog(__VA_ARGS__); ilog("\033[0m\n"); }
#define blue(...)    { log_prefix(); ilog("\033[34m"); ilog(__VA_ARGS__); ilog("\033[0m\n"); }

#else

#define log_prefix() ;
#define ilog(...)    ;
#define llog(...)    ;
#define log(...)     ;
#define red(...)     ;
#define green(...)   ;
#define blue(...)    ;

#endif

namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=105;
int n,m;
char a[N][N];
int f[N][N];

int main(){
    cin>>n>>m;
    FOR(i,1,n)cin>>a[i]+1;
    FOR(i,1,n)FOR(j,1,m){
        if(i==1&&j==1)f[i][j]=1;
        else if(i==1)f[i][j]=f[i][j-1]+(a[i][j]!=a[i][j-1]);
        else if(j==1)f[i][j]=f[i-1][j]+(a[i-1][j]!=a[i][j]);
        else f[i][j]=min(f[i-1][j]+(a[i-1][j]!=a[i][j]),f[i][j-1]+(a[i][j-1]!=a[i][j]));
    }
    if(a[1][1]=='.' && a[n][m]=='.'){
        cout<<f[n][m]/2;
    }else if(a[1][1]=='.' && a[n][m]=='#'){
        cout<<(f[n][m]+1)/2;
    }else if(a[1][1]=='#' && a[n][m]=='.'){
        cout<<(f[n][m]+1)/2;
    }else {
        cout<<(f[n][m]+2)/2;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	public static void main(String[] args) { 
		/*
		 * */
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String S = I.next();
		int N = S.length();
		if (S.charAt(N-1)=='s') S+="es";
		else S+="s";
		O.pln(S);
	}
	public static double max(double a, double b) {return Math.max(a, b);}
	public static double min(double a, double b) {return Math.min(a, b);}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static int min(int a, int b) {return Math.min(a,b);}
	public static int max(int a, int b) {return Math.max(a,b);}
	public static long abs(long x) {return Math.abs(x);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(min(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 25572
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	ll sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;

	ll X = abs(sx - tx);
	ll Y = abs(sy - ty);
	rep(i, 0, X)  cout << 'R';
	rep(i, 0, Y)  cout << 'U';
	rep(i, 0, X)  cout << 'L';
	rep(i, 0, Y) cout << 'D';
	cout << 'D';
	rep(i, 0, X) cout << 'R';
	cout << 'R';
	rep(i, 0, Y) cout << 'U';
	cout << 'U';
	cout << 'L';
	cout << 'U';
	rep(i, 0, X) cout << 'L';
	cout << 'L';
	cout << 'D';
	rep(i, 0, Y) cout << 'D';
	cout << 'R';
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

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

int main()
{
	ll a, b;
	cin >> a >> b;
	ll c = f(a, b);
	cout << a * b / c << "\n";

	return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#include <ext/numeric>
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))
#define     pii       pair<int,int>
#define     N         100005
using namespace std;


int main(){
    __;

#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif

    int a,p;

    cin>>a>>p;

    cout<< ((3*a)+p)/2;

   return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

template<class T>
struct SWAG {
  using FX = function<T(T, T)>;
  stack<pair<T, T>> frst, bcst;
  FX fx;
  const T ex;
  SWAG(FX fx_, T ex_):fx(fx_), ex(ex_) {}
  void push(T x) {
    bcst.emplace(x, fx(x, (bcst.empty()?ex:bcst.top().second)));
  }
  void pop() {
    if(frst.empty()) {
      while(!bcst.empty()) {
        frst.emplace(bcst.first, fx(bcst.first, (frst.empty()?ex:frst.top().second)));
        bcst.pop();
      }
    }
    else frst.pop();
  }
  T clac() {
    return fx(frst.empty()?ex:frst.top().second, bcst.empty()?ex:bcst.top().second);
  }
};

//head



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  string s;
  cin >> n >> m >> s;
  stack<int> st;
  for(int i = n; i > 0;) {
    for(int j = m; j > 0; j--) {
      if(i-j >= 0 and s[i-j] == '0') {
        st.emplace(j);
        i -= j;
        break;
      }
      if(j == 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  while(!st.empty()) {
    cout << st.top() << (st.size() == 1?'\n':' ');
    st.pop();
  }
}

Measured memory_bytes: 4108
A,B,C,D = map(int, input().split())

def gcd(a, b):
    while b > 0:
        a,b = b, a%b
    return a

def count(n):
    c = n//C
    d = n//D
    g = gcd(C, D)
    l = C*D//g
    return n -c -d +n//l

print(count(B) - count(A-1))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define pb push_back

int p[100100];
int par(int x){return x == p[x] ? x : p[x] = par(p[x]) ;}
int N,M,a,b;
int A[100100];
vector<int> V[100100];

int main(){
  cin>>N>>M;
  for (int i=1;i<=N;++i)cin>>A[i];
  for (int i=1;i<=N;++i)p[i] = i;
  for (int i=0;i<M;++i){
    cin>>a>>b;
    p[par(a)] = par(b);
  }
  for (int i=1;i<=N;++i){
    V[par(i)].pb(i);
  }
  map<int,int> M;
  int ans = 0;
  for (int i=1;i<=N;++i){
    for (auto it : V[i])M[it] = 1;
    for (auto it : V[i]) ans += M[A[it]];
    M.clear();
  }
  cout<<ans;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


string numToChar(int num){
    if(num == 0) return "A";
    else if(num == 1) return "B";
    else return "C";
}

int main()
{
    int N;
    vector<int> num(3);
    cin >> N >> num[0] >> num[1] >> num[2];
    vector<string> s(N);
    REP(i, N) cin >> s[i];


    vector<char> ans;
    REP(i, N){
        // 選ばれているものを数字に変換
        int c1 = s[i][0] - 'A';
        int c2 = s[i][1] - 'A';
        int c3 = 3-c1-c2;
        if(num[c1]+num[c2] == 0){
            cout << "No" << endl;
            return 0;
        }
            bool flag = true;
            for(auto c: s[i]){
                int idx = c-'A';
                if((num[idx] == 0) or (i+1 < N and num[idx] == 1 and num[c3] == 0 and (s[i+1] == numToChar(idx)+numToChar(c3) or s[i+1] == numToChar(c3)+numToChar(idx)))){
                    ans.push_back(c);
                    ++num[idx];
                    --num[(idx == c1)? c2: c1];
                    flag = false;
                    break;
                }
            }
            if(flag){
                ans.push_back(s[i][0]);
                ++num[c1];
                --num[c2];
            }
            if(num[0] < 0 or num[1] < 0 or num[2] < 0){
                cout << "No" << endl;
                return 0;
            }
    }
    cout << "Yes" << endl;
    for(auto c: ans) cout << c << endl;

    return 0;
}

Measured memory_bytes: 5564
import java.io.*;
import java.lang.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Task task = new Task(in, out);
        task.solve();
        out.close();
	}

	static class Task {
		
		private InputReader in;
		private PrintWriter out;

		public Task(InputReader in, PrintWriter out) {
			this.in = in;
			this.out = out;
		}

		public void solve() {
			String S = in.next();
			boolean ok = true;
			if (S.length() % 2 == 1) {
				out.println("No");
				return;
			}
			for (int j = 0; j < S.length(); j++) {
				char l = S.charAt(j);
				char r = S.charAt(S.length() - j - 1);
				if (!((l == 'b' && r == 'd') || (l == 'd' && r == 'b') || (l == 'p' && r == 'q') || (l == 'q' && r == 'p'))) {
					ok = false;
					break;
				}
			}
			out.println(ok ? "Yes" : "No");
		}
	}

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
	
}


Measured memory_bytes: 10964
#include <iostream>
 
using namespace std;
 
int main(){
  int a;
  int n5=0;
  int n7=0;
  for(int ii=0; ii<3; ii++){
    cin >> a;
    n5 += (a==5) ? 1 : 0;
    n7 += (a==7) ? 1 : 0;
  }
  cout << ((n5==2)&&(n7==1) ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N, p[51];
vector<int> v;
int main() {
	scanf("%d",&N);
  	for (int i = 1; i <= N; i++) scanf("%d",&p[i]);
  	for (int i = 1; i <= N; i++) if (i != p[i]) v.push_back(i);
  	if (v.empty() || v.size() == 2) {
      	cout << "YES\n";
    } else {
      	cout << "NO\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    int n; cin >> n;
    int a = 0, b = 0, c = 0, d = 0;
    rep(i,n){
        string s; cin >> s;
        if(s == "AC") ++a;
        else if(s == "WA") ++b;
        else if(s == "TLE") ++c;
        else ++d;
    }

    cout << "AC x " << a << endl << "WA x " << b << endl << "TLE x " << c << endl << "RE x " << d << endl;


    return 0;
}

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


Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int x = 0, y = 0;
	for (int i = 0 ; i < s.length() ; i++) {
		if (s[i] == 'g') x++;
		else y++;
	}
	cout << (x - y) / 2;
}   

Measured memory_bytes: 512
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	int max_can = max(max(a,b),c);
	int sum = a+b+c;
	cout << ((sum-max_can == max_can)?"Yes":"No") << endl;

	return 0;
}

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

int main(){
  int n,m;
  cin>>n>>m;
  ll p[m],y[m];
  rep(i,m) cin>>p[i]>>y[i];
  vector<ll> yd[n+1];
  rep(i, m) yd[p[i]].push_back(y[i]);
  rep(i, n) sort(yd[i+1].begin(),yd[i+1].end());
  rep(i, m) printf ("%012lld\n",ll(p[i])*1000000+lower_bound(yd[p[i]].begin(),yd[p[i]].end(),y[i])-yd[p[i]].begin()+1); 
}

Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <iomanip>
#define inf 1000000007
using namespace std;
 
int main(void){
    long long int n, m;
    cin >> n >> m;
    vector<vector<long long int>> data(m, vector<long long int>(2));
    vector<vector<long long int>> answer(m, vector<long long int>(2));
    string check[m];
    long long int count = 1;
    long long int a = -10;
    answer.at(0).at(1) = 0;  
    for (int i = 0; i < m; i++){
        for (int j = 0; j < 2; j++){
            cin >> data.at(i).at(j);
            answer.at(i).at(0) = data.at(i).at(0)*10000000000+data.at(i).at(1);
        }
        if(i != 0)    
            answer.at(i).at(1) = answer.at(i-1).at(1) +1;
        //cout << answer.at(i).at(0) << " " << answer.at(i).at(1) << endl;
    }
    string str, stra, strb, strc = "000000";
    sort(answer.begin(), answer.end());
    for(int i = 0; i < m; i++){
        stra = strc + to_string((answer.at(i).at(0))/10000000000);
        if((answer.at(i).at(0))/10000000000 != a)
            count = 1;
        else
            count++;
        strb = strc + to_string(count);
        a = (answer.at(i).at(0))/10000000000;
        check[answer.at(i).at(1)] = stra.substr(stra.length()-6, 6) + strb.substr(strb.length()-6, 6);
    }
    for(int i = 0; i < m; i++)
        cout << check[i] << endl;
    return 0;
}

Measured memory_bytes: 17920
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    int[] junban = new int[number];
    int[] manzoku = new int[number];
    int[] addManzoku = new int[number-1];
    int sumManzoku = 0;
    for(int i = 0; i < number; i++){
    	junban[i] = sc.nextInt();
    }
    for(int j = 0; j < number; j++){
    	manzoku[j] = sc.nextInt();
        sumManzoku += manzoku[j];
    }
    for(int k = 0; k < number-1; k++){
    	addManzoku[k] = sc.nextInt();
    } 
    for(int l = 1; l < number; l++){
      if(junban[l]-1 == junban[l-1]){
      	sumManzoku += addManzoku[junban[l-1]-1];
      }
    }
    System.out.println(sumManzoku);
    }
}

Measured memory_bytes: 21844
//FINISH WHAT YOU START!
#include<bits/stdc++.h>

#define fileIO freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define inf ((long long) 1e18 )
#define mod 1000000007
#define int long long
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define debug(x) cout << '>' << #x << ':' << x << '\n';
#define debug2(x,y) cout << '>' << #x << " = " << x << " & "<< #y <<" = "<< y << '\n';

using namespace std;

const int N = 1e5 + 7;

int32_t main() {
	IOS
#ifndef ONLINE_JUDGE
	fileIO
#endif
	auto start = std::chrono::high_resolution_clock::now();
	int test;
	test = 1;
	// cin >> test;
	while (test--) {
		string a, b;
		cin >> a >> b;
		int n = a.size();
		int m = b.size();
		int ans = inf;
		if (n == m) {
			int count = 0;
			for (int i = 0 ; i < n ; i++) {
				if (a[i] != b[i])
					count++;
			}
			cout << count << endl;
			continue ;
		}
		for (int i = 0 ; i < n - m ; i++) {
			int count = 0;
			for (int j = i; j < i + m; j++) {
				if (a[j] != b[j - i])
					count++;
			}
			ans = min(ans, count);
		}
		cout << ans << endl;
	}

	auto stop = std::chrono::high_resolution_clock::now();
	auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);

	cerr << "Time taken : " << ((long double)duration.count()) / ((long double) 1e9) << "s " << endl;

	return 0;
}


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

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

int main()
{

    lint n;
    cin >> n;
    lint ans, tmp;

    FOR(i, 1, 10)
        FOR(j, 1, 10){
            if(i*j==n){
                cout
                    << "Yes" << "\n";
                return 0;
            }
        }
                cout
        << "No" << "\n";

    return 0;
}

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

void z_algorithm(int *s,int *z,int n){
    int c=0;
    for(int i=1;i<n;i++){
        if(i+z[i-c]<c+z[c]){
            z[i]=z[i-c];
        }else{
            int j=max(0,c+z[c]-i);
            while(i+j<n&&s[j]==s[i+j])j++;
            z[i]=j;
            c=i;
        }
    }
    z[0]=n;
}

int n;
int a[200005],pa[200005];
int b[200005],pb[200005];
int s[600005],z[600005];

int main(){

    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",a+i);
    for(int i=0;i<n;i++)scanf("%d",b+i);
    a[n]=a[0];
    b[n]=b[0];
    for(int i=0;i<n;i++){
        pa[i]=a[i]^a[i+1];
        pb[i]=b[i]^b[i+1];
    }
    memcpy(s,pb,n<<2);
    memcpy(s+n,pa,n<<2);
    memcpy(s+n+n,pa,n<<2);
    z_algorithm(s,z,n*3);
    for(int i=n;i<n<<1;i++){
        if(z[i]>=n)printf("%d %d\n",i-n,a[i-n]^b[0]);
    }

    return 0;
}

Measured memory_bytes: 11264
# 問題: https://atcoder.jp/contests/abc144/tasks/abc144_c

import math

n = int(input())
a = int(math.sqrt(n))
b = 0
while b == 0:
    if n % a > 0:
        a -= 1
        continue
    b = n / a

res = a + b - 2
print(int(res))



Measured memory_bytes: 9168
#include <iostream>
// #include<bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

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

	long long res = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 15 == 0) {}
		else if (i % 5 == 0) {}
		else if (i % 3 == 0) {}
		else {
			res += i;
		}
	}

	cout << res << endl;
}


Measured memory_bytes: 3176
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main() {
	int i;
	int n;
	cin >> n;
	vector<double> v(n);
	for (i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	for (i = 0; i < n - 1; i++) {
		v[i + 1] = (v[i] + v[i + 1]) / 2;
	}
	cout << v[n - 1] << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(),a.end(),greater<int>());
  
  int ans=0;
  for(int i=0;i<N;i++){
    ans+=a.at(i)*((i%2==0)?1:-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
int main()
{
  int a=0;
 std::cin >> a;
  char szbuf[1024];
  sprintf(szbuf,"%d",a);
  int ii=0;
  for(ii=0;ii<100;ii++)
  {
    if(szbuf[ii+1]==0x00)
      break;   
  }
  if(szbuf[ii]=='3')std::cout << "bon";
  else
  if(szbuf[ii]=='0'||szbuf[ii]=='1'||szbuf[ii]=='6'||szbuf[ii]=='8')std::cout << "pon";
  else
    std::cout << "hon";
  
  return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vll;
ll digit(ll x){ll c=0;while(x>0){x=x/10;c++;}return c;}
int main(){
  ll n;
  cin >> n;
  ll d = digit(n);
  if (d < 3) {
    cout << 0 << endl;
    return 0;
  }
  
  ll ans = (pow(3,d)-3)/2 + 3*(d+1-pow(2,d));
  
  vll v, t(d);
  for (ll x = 1; x <= d - 2; x++) {
    for (ll y = 1; y <= d - x - 1; y++) {
      for (ll i = 0; i < d; i++) {
        if (i < x) t[i] = 3;
        else if (i < x + y) t[i] = 5;
        else t[i] = 7;
      }
      do {
        ll c = 0;
        for (ll i = 0; i < d; i++) {
          c += t[i] * pow(10, i);
        }
        v.push_back(c);
      } while (next_permutation(t.begin(), t.end()));
    }
  }
  
  sort(v.begin(), v.end());
  
  for (ll i = 0; i < v.size(); i++) {
    if (n >= v[i]) ans++;
  }
  
  cout << ans << endl;
}

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

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

    long long i = 0;
    long long val = 0;

    while (true) {
        i++;
        val = val * 10 + 7;
        long long rem = val % k;
        if (rem == 0) {
            break;
        }
        if (i > k) {
            i = -1;
            break;
        }
        val = rem;
    }
    cout << i << endl;

    return 0;
}


Measured memory_bytes: 3592
n=int(input())
b=list(map(int,input().split()))
a=[]
a.append(b[0])
for i in range(n-2):
  if b[i]>b[i+1]:
    a.append(b[i+1])
  else:
    a.append(b[i])
a.append(b[-1])
print(sum(a))

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

using namespace std;

#define ll long long
#define fo(i,b,n) for(int i=(b); i<(n) ; i++)
#define xx first
#define yy second
#define pb push_back
#define sz(n) int(n.size())
#define pii pair
#define MP make_pair

#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define readl(x) scanf("%lld",&x)
#define readl2(x,y) scanf("%lld%lld",&x,&y)
#define readd(x) scanf("%lf",&x)
#define readd2 scanf("%lf%lf",&x,&y)

#define pr(n) printf("%d",n)
#define prn(n) printf("%d\n",n)
#define prl(n) printf("%lld",n)
#define prln(n) printf("%lld\n",n)
#define prd(x) printf("%lf",x)
#define prdn(x) printf("%lf\n",x)



int main()
{
    string x,y,z;
    cin>>x;
    cin>>y;
    cin>>z;
    reverse(x.begin(),x.end());
    reverse(y.begin(),y.end());
    reverse(z.begin(),z.end());


    stack<char>a,b,c;
    fo(i,0,sz(x))a.push(x[i]);
    fo(i,0,sz(y))b.push(y[i]);
    fo(i,0,sz(z))c.push(z[i]);

    char ans;
    char ch='a';

    while(true)
    {
        if(ch=='a')
        {
            if( a.empty() )
            {
                ans='A';
                break;
            }
            else{
                ch=a.top();
                a.pop();
            }
        }
        else if(ch=='b')
        {
            if(b.empty() )
            {
                ans='B';
                break;
            }
            else{
                ch=b.top();
                b.pop();
            }
        }
        else
        {
            if(c.empty() )
            {
                ans='C';
                break;
            }
            else{
                ch=c.top();
                c.pop();
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}

















Measured memory_bytes: 256
#include <cstdio>

int main(void) {
	while(1) {
		int n, q, days, day, max = 0, max_day = 0;
		int num[128] = {0};
		scanf("%d %d", &n, &q);
		if(!n && !q) break;
		for(int i = 0; i < n; i++) {
			scanf("%d", &days);
			for(int j = 0; j < days; j++) {
				scanf("%d", &day);
				num[day]++;
			}
		}
		for(int i = 1; i <= 100; i++) {
			if(num[i] > max) {
				max = num[i];
				max_day = i;
			}
		}
		if(max < q) max_day = 0;
		printf("%d\n", max_day);
	}
	return 0;
}

Measured memory_bytes: 1028
N,K = map(int,input().split())
A = list(map(int,input().split()))
numbers = {}
for a in A:
    if not a in numbers:
        numbers[a] = 1
    else:
        numbers[a] += 1
numbers = sorted(numbers.items(),key=lambda x: -x[1])
sum = 0
for i,k in enumerate(numbers):
    if i < K:
        continue
    sum += numbers[i][1]
print(sum)

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  ll n, m;
	cin >> n >> m;
  map<int, int> mp;
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    if (a == 1) mp[b]++;
    if (b == n) mp[a]++;
  }
  for (auto i : mp) {
    if (i.second >= 2) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
   cout << "IMPOSSIBLE" << endl;
}

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
  int64_t x, a=100, ct=0;
  cin >> x;
  while(a<x){
    a*=1.01;
    ct++;
  }
  cout << ct << endl;
  return 0;
}


Measured memory_bytes: 3632