akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
char s1[101],s2[101];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s1>>s2,cout<<s2<<s1<<'\n';
	cout<<flush;	
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        float E = sc.nextFloat();
        int F = sc.nextInt();
        float x;
        float y;
        float ans = 1;
        float sugar = 0;
        //water
        for(int i = 0;i <= F/100;i++){
            for(int j = 0;j <= F/100;j++){
                x = 100*A*i + 100*B*j;
                if(x == 0 || x > F){
                    continue;
                }
                //sugar
                for(int k = 0;k <= F;k++){
                    for(int l = 0;l <= F;l++){
                        y = C*k + D*l;
                        if(x + y <= F && y/(x + y) <= E / (E + 100) && y/(x + y) >= sugar/ans){
                            ans = x + y;
                            sugar = y;
                        }
                    }
                }
            }
        }
        System.out.println((int)ans + " " + (int)sugar);
    }
}


Measured memory_bytes: 25172
a = [list(map(int, input().split())) for i in range(3)]
for i in range(1):
    for j in range(len(a)-1):
        b = a[j+1][i] - a[j][i]
        if a[j+1][i+1] - a[j][i+1] != b or a[j+1][i+2] - a[j][i+2] != b:
            print("No")
            exit()
print("Yes")

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

int main(){
    int n,k;
    
    while(1){
        cin >> n >> k;
        int N[n],sum[n-k+1];
        if(n==0 && k==0) break;
        for(int i=0; i<n-k+1; i++){
            sum[i] = 0;
        }
        
        for(int i=0; i<n; i++){
            cin >> N[i];
        }
        for(int i=0; i<=n-k; i++){
            for(int j=0; j<k; j++){
                sum[i] += N[i+j];
            }
        }
        int max = 0;
        for(int i=0; i<=n-k; i++){
            if(max < sum[i]){
                max = sum[i];
            }
        }
        cout << max << endl;
    }
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 300
#define X 998244353
#define Inc(x,y) ((x+=(y))>=X&&(x-=X))
using namespace std;
int n,m,a[N+5],f[N+5][N+5][N+5];char s[N+5];
int main()
{
	RI i,j,k,cnt=1;for(scanf("%s",s+1),n=strlen(s+1),i=1;i<=n;++i) s[i]^'0'?++a[cnt]:++cnt;
	RI p;scanf("%d",&m),m=min(n,m),f[0][0][0]=1;
	for(i=0;i^cnt;++i) for(j=0;j<=m;++j) for(k=0;k<=m;++k) if(f[i][j][k])
	{
		Inc(f[i+1][j][k],f[i][j][k]);
		for(p=m-j;p;--p) Inc(f[i+1][j+p][k+p],f[i][j][k]);
		for(p=min(a[i+1],k);p;--p) Inc(f[i+1][j][k-p],f[i][j][k]);
	}
	RI t=0;for(i=0;i<=m;++i) Inc(t,f[cnt][i][0]);return printf("%d\n",t),0;
}

Measured memory_bytes: 58220
#include<bits/stdc++.h>
using namespace std;
string s,e,ss[200001];
int ans;
int main()
{
	cin>>s;
	if(s.size()==1)
	{
		cout<<1;
		return 0;
	}
	e+=s[1];
	ss[0]=s[0];
	for(int i=1;i<s.size()-1;i++)
	{
		if(e!=ss[ans])
		{
			ss[ans+1]=e;
			ans++;
			e=s[i+1];
		}
		else
		{
			e+=s[i+1];
		}
	}
	if(e==ss[ans])
	{
		ans--;
	}
	cout<<ans+2;
	return 0;
}

Measured memory_bytes: 11012
def e_flatten_prime_factorization(MOD=10**9 + 7):
    N = int(input())
    A = [int(i) for i in input().split()]

    def prime_factorization_dict(n):
        from collections import defaultdict
        """nを素因数分解したときの素数とその指数の辞書"""
        if n == 1:
            return {2: 0}  # 1は素数の0乗の積とみなす
        i, table = 2, defaultdict(int)
        while i**2 <= n:
            while n % i == 0:
                table[i] += 1
                n //= i
            i += 1
        if n > 1:
            table[n] = 1
        return table

    def prime_table(n):
        """n以下の素数のリスト(エラトステネスの篩)"""
        is_prime = [True] * (n + 1)
        is_prime[0] = is_prime[1] = False  # 0と1は素数でない
        for j in range(2, int(n**0.5) + 1):
            if not is_prime[j]:
                continue
            for k in range(j * 2, n + 1, j):
                is_prime[k] = False  # jの倍数は素数でない
        return {i: 0 for i in range(n + 1) if is_prime[i]}

    lcm_prime = prime_table(10**6)
    for a in A:
        for base, exp in prime_factorization_dict(a).items():
            lcm_prime[base] = max(lcm_prime[base], exp)
    lcm = 1
    for base, exp in lcm_prime.items():
        lcm *= pow(base, exp, MOD)
        lcm %= MOD
    coefficient = sum(pow(a, MOD - 2, MOD) for a in A)
    return (lcm * coefficient) % MOD

print(e_flatten_prime_factorization())


Measured memory_bytes: 58456
def main():
    A, B, K = map(int, input().split())
    count = 0
    number = min(A, B)
    while True:
        if A % number == 0 and B % number == 0:
            count += 1
            if count == K:
                break
        number -= 1
    print(number)

if __name__ == "__main__":
    main()


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

int main()
{
  stack<char> w;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++)
  {
    switch (s.at(i))
    {
    case '0':
      w.push('0');
      break;
    case '1':
      w.push('1');
      break;
    default:
      if (w.size() > 0)
        w.pop();
    }
  }
  string ans;
  while (w.size() > 0)
  {
    ans += w.top();
    w.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
  double a,b,c,d,e,f;

 
  while( cin>>a>>b>>c>>d>>e>>f){
  
    double x,y;
  
    y=(c*d-a*f)/(b*d-a*e);
    x=(c-b*y)/a;
  
    //cout<<x<<' '<<y<<endl;
    printf("%.3lf %.3lf",x,y);
    cout<<endl;
  }
}

Measured memory_bytes: 1264
import math

N, A, B = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))


def enough(T):
    h2 = list(map(lambda x: x - B * T, h))
    return sum(map(lambda x: max(0, math.ceil(x / (A - B))), h2)) <= T


def solver(inf, sup):
    mid = (inf + sup) // 2
    if inf == sup:
        return mid
    elif enough(mid):
        return solver(inf, mid)
    else:
        return solver(mid + 1, sup)


t = 10 ** 9

print(solver(0, t))


Measured memory_bytes: 11036
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
namespace mp = boost::multiprecision;
using namespace std;
typedef mp::cpp_int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;


int dfs(int start, int distance, int parent, vi &dist,
        vvi &G) {
    dist[start] = distance;
    for (auto s : G[start]) {
        if (s == parent) continue;
        dfs(s, distance + 1, start, dist, G);
    }
}

int main() {
    int n, u, v;
    cin >> n >> u >> v; ++n;
    vvi G(n);

    int a, b;
    rep(i, n - 2) {
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vi distu(n, -1);
    vi distv(n, -1);

    dfs(u, 0, -1, distu, G);
    dfs(v, 0, -1, distv, G);

    int ret = 0;
    rep (i, n) {
        if (distv[i] > distu[i]) ret = max(ret, distv[i] - 1);
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 12928
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
using namespace std;
typedef pair<int, int> P;
typedef long long LL;

#define _CRT_SECURE_NO_WARNINGS
int n;
int main() {
	scanf("%d",&n);
	printf("%d",24-n+24);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,s;
	cin>>n>>s;
	int y10000,y5000,y1000,i,j,f;
	f=0;
	for (i=0;i<=n;i++)
	{
		y10000=i;
		for (j=0;j<=n-i;j++)
		{
			y5000=j;
			y1000=n-i-j;
			if ((10000*y10000+5000*y5000+1000*y1000)==s)
			{
				cout<<y10000<<" "<<y5000<<" "<<y1000<<endl;
				f=1;
				break;
			}
		}
		if (f==1)
		{
			break;
		}
	}
	if (f==0)
	{
		cout<<"-1 -1 -1"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)

const int N = (int) 1e5 + 5, mod = 0;
pair<int, int> p[N];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> p[i].first, p[i].second = i;
    sort(p, p + n);
    int cnt = 0;
    for (int i = 0; i < n; i += 2)
        cnt += p[i].second & 1;
    cout << cnt << endl;






}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

int main() {
  int n;
  R n;
  int a[n];
  rep(i,n) R a[i];
  int x[n+1],y[n+1],ans=0;
  x[0]=(!a[0])?MAX:-MAX;
  REP(i,1,n) {
    x[i]=x[i-1]-1;
    if(!a[i]) x[i]=MAX;
    if(a[i]<0) x[i]=min(x[i],-a[i]-1);
  }
  y[n]=-MAX;
  rrep(i,n) {
    y[i]=y[i+1]-1;
    if(!a[i]) y[i]=MAX;
    if(a[i]<0) y[i]=min(y[i],-a[i]-1);
  }
  rep(i,n) {
    if(a[i]<=0) continue;
    int z=max(x[i],y[i])+1;
    ans+=max(min(a[i],z),0);
  }
  pr(ans);
  return 0;
}


Measured memory_bytes: 2332
#include <stdio.h>

int main(){
	for(int i = 0; i < 5000000; ++i) putchar('(');

	int a, b, c, d;
	while(1){
		scanf("%d%d%d%d", &a, &b, &c, &d);
		if(a == 0){ break; }
		printf("%d+%d+%d+%d\n", a, b, c, d);
	}
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>n>>s;
    for0(n)
    {
        if(s[i]=='W')c++;
    }
    for(i=n-1;c--;i--)
    {
        if(s[i]=='R')d++;
    }
    cout<<d<<endl;
//    else cout<<0<<endl;
}



Measured memory_bytes: 3732
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

Z = (H + W) * 80 + 10

dp = [[0] * (W + 1) for _ in range(H + 1)]
dp[0][0] = (1 << Z)

for h in range(H):
    for w in range(W):
        d = dp[h][w]
        k = abs(A[h][w] - B[h][w])

        dp[h + 1][w] |= (d << k) | (d >> k)
        dp[h][w + 1] |= (d << k) | (d >> k)

ans = 10**18
for a in (dp[H][W - 1], dp[H - 1][W]):
    for d in range(Z * 2 + 10):
        if a & (1 << d) != 0:
            ans = min(ans, abs(d - Z))
print(ans)


Measured memory_bytes: 20980
let cnt = ref 0

let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> List.rev (s :: acc)
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  doit str []

let print_array a =
  Array.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) a;
  print_newline ()

let bubble_sort a n =
  let rec bubble j flag =
    if j <= 0 then flag
    else begin
      if a.(j - 1) <= a.(j) then bubble (j - 1) flag
      else begin
        let tmp = a.(j) in
        a.(j) <- a.(j - 1);
        a.(j - 1) <- tmp;
        incr cnt;
        bubble (j - 1) true;
      end
    end
  in
  let rec doit flag =
    if not flag then ()
    else doit (bubble (n - 1) false)
  in
  doit true

let () =
  let n = read_int () in
  let a = Array.of_list (List.map int_of_string (split (read_line ()) ' ')) in
  bubble_sort a n;
  print_array a;
  Printf.printf "%d\n" !cnt

Measured memory_bytes: 2364
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  int TH,TA,AH,AA;
  cin >> TH >> TA >> AH >> AA;
  while(true){
    AH-=TA;
    if(AH<=0){
      cout << "Yes" << endl;
      return 0;
    }
    TH-=AA;
    if(TH<=0){
      cout << "No" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

LL dp[2000009];
LL rs[2000009];

LL gs(int a,int b){
	if(a>b)return 0;
	if(a==0)return rs[b];
	return rs[b]-rs[a-1];
}

int main(){
	DRI(n);
	dp[0]=1;rs[0]=1;
	REPP(i,1,2*n+1){
		if(i<=n)dp[i]=dp[i-1];
		int jmin=max(3,i-n+2);
		int jmax=min(i+1,n+2)-1;
		dp[i]=((dp[i]+gs(i-jmax,i-jmin))%MOD+MOD)%MOD;
		rs[i]=(rs[i-1]+dp[i])%MOD;
	}
	//REP(i,2*n+1)printf("%lld ",dp[i]);
	LL ans=0;
	REP(i,n){
		ans=(ans+dp[i]*(n-1))%MOD;
	}
	REP(i,n-1){
		ans=(ans+(dp[i]*(n-1))%MOD*(n-2))%MOD;
	}
	REPP(j,n,2*n+1)ans=(ans+dp[j])%MOD;
	printf("%lld",ans);
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> data(H);
    vector<bool> row(H, false);
    vector<bool> col(W, false);

    REP(i, H)
    {
        cin >> data.at(i);

        REP(j, W)
        {
            if (data.at(i).at(j) == '#')
            {
                row.at(i) = true;
                col.at(j) = true;
            }
        }
    }

    REP(i, H)
    {
        if (row.at(i) == true)
        {
            REP(j, W)
            {
                if (col.at(j) == true)
                {
                    cout << data.at(i).at(j);
                }
            }

            cout << endl;
        }
    }
}

Measured memory_bytes: 256
# encoding: utf-8
N, K = map(int, input().split())
D = list(map(int, input().split()))

Db = []
for Di in range(10):
    if Di not in D: Db.append(Di)
# print("#", Db)

for level in range(6):
    if N // (10 ** level) < 1: break
# print("#", level)
    
memo = [None] * ((level + 1) * 10000)
    
def pay(pos, tmp):
    # print("##", pos, tmp)
    if pos > level or tmp >= N:
        if tmp >= N:
            # print("###", tmp)
            return tmp
        else: return 10000
    elif memo[pos * 10000 + tmp] != None: return memo[pos * 10000 + tmp]
    rets = []
    for Dbi in Db:
        add = Dbi * (10 ** pos)
        rets.append(pay(pos + 1, tmp + add))
    ret = min(rets)
    if memo[pos * 10000 + tmp] == None: memo[pos * 10000 + tmp] = ret    
    return ret

print(pay(0, 0))

Measured memory_bytes: 3648
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.bigint;
import std.math;

void main()
{
	while (1) {
    auto x = readln.chomp.split.map!(to!int);
    if (x[0] == 0) break;
    foreach (i; 0..x[0]) {
      foreach (j; 0..x[1]) {
        if ((i+j)%2) write(".");
        else write("#");
      }
      writeln("");
    }
    writeln("");
  }
}

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


using namespace std;

int main(){
    string S;
    long N;
    cin>>N>>S;

long i=1;

while (i<S.size())
{
    if (S[i]==S[i-1])
    {
        S.erase(S.begin()+i);
    }else
    {
        i++;
    }
    
    
}


cout<<S.size()<<endl;
    

}

Measured memory_bytes: 512
// D - Simple Knapsack

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

using Weight = int;
using Values = vector<ll>;
using Items = map<Weight, Values>;

int N, W;
Items items;
ll ans = 0;

void dfs(Items& items, Items::iterator itr, vector<int>& nums) {
	if (itr == items.end()) {
		ll value_sum = 0;
		ll weight_sum = 0;

		int i=0;
		for (auto& itr : items) {
			ll w = itr.first;
			Values values = itr.second;
			for (int j=0; j<nums[i]; j++) {
				value_sum += values[j];
				weight_sum += w;
			}
			i++;
		}

		if (weight_sum <= W) {
			ans = max(ans, value_sum);
		}

		return;
	}

	for (int n=0; n <= itr->second.size(); n++) {
		nums.push_back(n);
		dfs(items, next(itr), nums);
		nums.pop_back();
	}
}

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

	ll w, v;
	for (int i=0; i<N; i++) {
		cin >> w >> v;
		items[w].push_back(v);
	}

	for (auto& itr : items) {
		sort(itr.second.begin(), itr.second.end(), greater<ll>());
	}

	vector<int> nums;
	dfs(items, items.begin(), nums);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (Math.abs(x - a) < Math.abs(x - b)) {
      System.out.println("A");
    } else {
      System.out.println("B");
    }

  }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

int main(){
  ll N, K; cin>>N>>K;
  ll ans;
  
  ans=N%K;
  ans=min(ans,abs(ans-K));
  /*
  while(N>K/2){
    N=abs(N-K);
  }*/
  cout << ans;
}

Measured memory_bytes: 3620
import java.util.Scanner;

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

		int ok = (int) Math.pow(100, d);
		int ng = (int) Math.pow(100, d + 1);
		int cnt = 0;
		for (int i = 0; i < 2000000; i+=ok) {
			if (i % ng != 0) {
				cnt++;
			}
			if (cnt == n) {
				System.out.println(i);
				return;
			}
		}
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int n, i;

    int x = 0;

    int m = 0;

    char s;
         
   
    scanf("%d", &n );
   

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

         scanf("%c", &s );

         if( s == 'I' ) x += 1;

         else if( s == 'D' ) x -= 1;

         if( m < x ) m = x;

         }

 

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


    return 0;
                                                          
}

Measured memory_bytes: 128
import collections
n = int(input())
s = []
for i in range(n):
    s.append(input())
s = collections.Counter(s)
ans = []
k = list(s.most_common())
k_len = k[0][1]
for i in k:
    word, count = i
    if count == k_len:
        ans.append(word)
ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 46180
#include<stdio.h>

int func1(int a,int b){
	return a/b;
}
int func2(int a,int b){
	return a%b;
}

double func3(int a,int b){
	return (double)a/b;
}
int main(){
	int A,B;
	int i;
	
	scanf("%d%d",&A,&B);
	
	
	printf("%d %d %0.5lf\n",func1(A,B),func2(A,B),func3(A,B));
	
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  auto fitr=s.begin();
  auto bitr=s.rbegin();
  for(;fitr!=s.end();fitr++,bitr++){
    if(*fitr!=*bitr)
      ++ans;
  }
  cout << ans/2 << endl;
}

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

int main(){
  int n,a[3];
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++)cin >> a[j];
    sort(a,a+3);
    if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2])cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 1168
n=int(input())
s=[0]*n
for i in range(n):
  s[i]=list(input())
a=s[0]
a=sorted(list(set(a)))
b=[]
for j in range(len(a)):
  x=float("inf")
  for k in range(n):
    x=min(x,s[k].count(a[j]))
  for l in range(x):
    b.append(a[j])
print("".join(b))

Measured memory_bytes: 3064
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,c,k = map(int, input().split())
    t = [int(input()) for _ in range(n)]
    t.sort()
    res = 1
    time, hito = t[0], 0
    for i in range(n):
        if t[i] - time > k:
            time = t[i]
            res += 1
            hito = 1
        elif hito + 1 > c:
            time = t[i]
            res += 1
            hito = 1
        else:
            hito += 1

    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 43996
import sys


n = int(input())
c = sorted([int(_) for _ in input().split()], reverse=True)
mod = 10**9+7
ans = 0
if n == 1:
    ans += c[0] * 2
    ans %= mod
    print(ans)
    sys.exit()
for i in range(n):
    ans += (c[i] * (pow(2, n-1, mod) + pow(2, n-2, mod) * i)) % mod
    ans %= mod
ans *= pow(2, n, mod)
ans %= mod
print(ans)


Measured memory_bytes: 89164
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    vi V(3);
    cin >> V[0] >> V[1] >> V[2];
    sort(V.begin(), V.end());
    if (V[0]+V[1] == V[2]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

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

int main(){
    int n;
    ll a[100005];
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    
    
    ll x=0,y=0;
    int j;
    sort(a,a+n);
    reverse(a,a+n);
    for(int i=1;i<n;i++){
        if(a[i-1]==a[i]){
            x=a[i];
            j=i;
            break;
        }
    }
    for(int i=j+2;i<n;i++){
        if(a[i-1]==a[i]){
            y=a[i];
            break;
        }
    }
    cout<<x*y<<endl;
    return 0;
}


Measured memory_bytes: 1024
#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++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

int main() {
    int N, K; cin >> N >> K;
    vector<int> h(N+1);
    h[0] = 0;
    REP(i, N) cin >> h[i+1];
    // dp[i][j][k] : iまでで,使ったもので一番右のindexがjで,k回消した時の解
    vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(N + 1, vector<ll>(K+1, LLINF)));
    dp[0][0][0] = 0;
    FOR(i,1,N+1) {
        REP(j, N+1) {
            REP(k, K+1) {
                dp[i][i][k] = min(dp[i][i][k],dp[i - 1][j][k] + max(0,h[i]-h[j]));//使う
                if (k > 0) dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k - 1]); //使わない
            }
        }
    }
    ll ans = LLINF;
    REP(j, N + 1) {
        REP(k, K+1) {
            ans = min(ans, dp[N][j][k]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 216832
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        Read read = new Read();
        string s;

        while ((s = Console.ReadLine()) != "0 0")
        {
            int[] t = Array.ConvertAll(s.Split(), int.Parse);
            int A = t[0];
            int B = t[1];
            int[] a = new int[A];
            int[] b = new int[B];
            for (int i = 0; i < A; i++) { a[i] = read.NextInt(); }
            for (int i = 0; i < B; i++) { b[i] = read.NextInt(); }
            BipartiteMatching bm = new BipartiteMatching(A + B);

            for (int i = 0; i < A; i++)
            {
                for (int j = 0; j < B; j++)
                {
                    if (GCD(a[i], b[j]) > 1)
                    {
                        bm.AddEdge(i, A + j);
                    }
                }
            }
            int ans = bm.Run();
            Console.WriteLine(ans);
        }

        Console.ReadLine();
    }

    static long GCD(long i, long j)
    {
        while (j != 0) { long t = i % j; i = j; j = t; }
        return i;
    }

    class BipartiteMatching
    {
        readonly int V;
        List<int>[] edges;
        bool[] used;
        int[] match;

        public BipartiteMatching(int V)
        {
            this.V = V;
            match = Enumerable.Repeat(-1, V).ToArray();
            edges = Enumerable.Range(0, V).Select(i => new List<int>()).ToArray();
        }

        public void AddEdge(int a, int b)
        {
            edges[a].Add(b);
            edges[b].Add(a);
        }

        public int Run()
        {
            int res = 0;
            for (int i = 0; i < V; i++)
            {
                if (match[i] < 0)
                {
                    used = new bool[V];
                    if (DFS(i)) { res++; }
                }
            }
            return res;
        }

        private bool DFS(int i)
        {
            used[i] = true;
            foreach (int j in edges[i])
            {
                int k = match[j];
                if (k < 0 || !used[k] && DFS(k))
                {
                    match[i] = j;
                    match[j] = i;
                    return true;
                }
            }
            return false;
        }
    }


    class Read
    {
        Queue<string> que = new Queue<string>();
        
        public int NextInt()
        {
            if (que.Count == 0) { Enqueue(); }
            return int.Parse(que.Dequeue());
        }

        private void Enqueue()
        {
            foreach (string s in Console.ReadLine().Split())
            {
                que.Enqueue(s);
            }
        }
    }
}

Measured memory_bytes: 14544
import sys

def generate_frog_positions(x, y):
    positions = [(x - 1, y - 2), (x, y - 2), (x + 1, y - 2),
                 (x + 2, y - 1), (x + 2, y), (x + 2, y + 1),
                 (x - 1, y + 2), (x, y + 2), (x + 1, y + 2),
                 (x - 2, y - 1), (x - 2, y), (x - 2, y + 1)]
    return [(a, b) for (a, b) in positions if 0 <= a <= 9 and 0 <= b <= 9]

def is_near_sprinkler(frog, sprinkler):
    dx = frog[0] - sprinkler[0]
    dy = frog[1] - sprinkler[1]
    return -1 <= dx <= 1 and -1 <= dy <= 1

while True:
    frog_pos = tuple([int(i) for i in sys.stdin.readline().split()])
    if frog_pos == (0, 0):
        break
    num_sprinklers = int(sys.stdin.readline())
    tmp = [int(i) for i in sys.stdin.readline().split()]
    sprinklers = zip(tmp[::2], tmp[1::2])

    positions = [frog_pos]
    for sprinkler in sprinklers:
        next_positions = []
        for pos in positions:
            next_positions += generate_frog_positions(pos[0], pos[1])
            next_positions = [pos for pos in next_positions if is_near_sprinkler(pos, sprinkler)]
        positions = next_positions
    if positions:
        print("OK")
    else:
        print("NA")

Measured memory_bytes: 6768
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<functional>
using namespace std;

const int dev = 1e9+7;
typedef long long ll;

const int MAX_N = 1e5;


struct Edge{
    int s, t, w;
    bool operator<( const Edge& right ) const {
        return w < right.w;
    }
};

struct UnionFind{
    int N;
    int par[MAX_N];

    UnionFind(int N): N(N){
        for (int i=0;i<N;i++){
            par[i] = i;
        }
    }

    int root(int x){
        if(par[x] == x) return x;
        int rx = root(par[x]);
        par[x] = rx;
        return rx;
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx==ry) return;
        par[rx] = ry;
    }

    bool find(int x, int y){
        return root(x) == root(y);
    }
};

int main(){
    int V, E, s, t, w;
    cin >> V >> E;
    vector<Edge> edges;
    for (int i=0;i<E;i++){
        Edge e;
        cin >> e.s >> e.t >> e.w;
        edges.push_back(e);
    }
    sort(edges.begin(), edges.end());

    UnionFind uf(V);
    int res = 0;
    for (int i=0;i<E;i++){
        Edge e = edges[i];
        if (!uf.find(e.s, e.t)){
            res += e.w;
            uf.unite(e.s, e.t);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4508
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c1 = 0;
        int c2 = 0;
        int c3 = 0;
        for (int i = 0; i < 2; i++) {
            int n = sc.nextInt();
            switch(n) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                c1++;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                c2++;
                break;
            default:
                c3++;
                break;
            }
        }
        if(c1 >= 2 || c2 >= 2 || c3 >= 2) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 35932
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
int n, k, ans = 1;
scanf("%d%d",&n, &k);
for (int i = 0; i < n; i++)
{
if (ans < k) ans *= 2;
else ans += k;
}
printf("%d\n", ans);
return 0;
}

Measured memory_bytes: 256
def inside_polygon(p0, qs):
    cnt = 0
    L = len(qs)
    x, y = p0
    for i in range(L):
        x0, y0 = qs[i-1]; x1, y1 = qs[i]
        x0 -= x; y0 -= y
        x1 -= x; y1 -= y

        cv = x0*x1 + y0*y1
        sv = x0*y1 - x1*y0
        if sv == 0 and cv <= 0:
            return 1

        if not y0 < y1:
            x0, x1 = x1, x0
            y0, y1 = y1, y0

        if y0 <= 0 < y1 and x0*(y1 - y0) > y0*(x1 - x0):
            cnt += 1
    return 2 if cnt % 2 == 1 else 0

def solve():
    N = int(input())
    qs = [list(map(int, input().split())) for i in range(N)]

    Q = int(input())
    for i in range(Q):
        *p0, = map(int, input().split())
        print(inside_polygon(p0, qs))
solve()


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define maxn 1005
using namespace std;

const int mod = 1e9 + 7;

int dp[maxn][maxn] = {};
string mp[maxn];
int H, W;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> H >> W;
    for(int i = 0; i < H; i++) {
        cin >> mp[i];
    }
    dp[0][0] = 1;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(!dp[i][j]) continue;
            dp[i][j] %= mod;
            if(i + 1 < H && mp[i + 1][j] == '.') dp[i + 1][j] += dp[i][j];
            if(j + 1 < W && mp[i][j + 1] == '.') dp[i][j + 1] += dp[i][j];
        }
    }
    cout << dp[H - 1][W - 1] << '\n';
    return 0;
}


Measured memory_bytes: 8536
import java.util.*

private data class Work(val start: Int, val end: Int, val dist: Int)
private data class Position(val pos: Int, val index: Int)

fun main(args: Array<String>) {

    /**
     * 同等のデータ構造, ロジックを実装しているが TLE で通らない,, java と kotlin の速度差?? どう分析するべきか
     * WAをあえて出すと実行時間を出力できる
     *
     * -> !! 最後の出力形式を for 文から　joinToString に変えると一気に早くなってAC
     */
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }

    // 工事を格納 O(N)
    var workList = mutableListOf<Work>()

    for (i in 0 until n) {
        val (s, t, x) = readLine()!!.split(" ").map { it.toInt() }

        // 切り上げ，切り捨てをして閉区間で考える
        var start = Math.ceil(s - 0.5 - x).toInt()
        var end = Math.floor(t - 0.5 - x).toInt()

        workList.add(Work(start, end, x))
    }

    // 工事を距離が近い順にソート O(NlogN)
    workList.sortBy { it.dist }

    // スタート地点を配列に保持する（最初からソートされて渡されるのでソートの必要なし） O(N)
    // スタート地点の中で，ある工事区間に含まれるものを取り出し，配列から削除,
    var posSet = TreeSet<Position> { a, b -> a.pos - b.pos } // Comparator をラムダ式で渡す
    for (i in 0 until q) {
        posSet.add(Position(readLine()!!.toInt(), i))
    }


    // 答えにはデフォルトで -1 を設定 (選ばれなかったものは工事に合わない = -1 )
    val ans = IntArray(q) { -1 }


    for (work in workList) {

        // work.start よりも大きな開始地点を持つ posList 内の 最初の要素を指す イテレータを取得
        // O(logN)
        val comp = Position(work.start, -1)
        var iter = posSet.tailSet(comp).iterator()

        // 工事に含まれる位置にいる posList の要素を取得し，削除
        while (iter.hasNext()) {
            val position = iter.next()

            if (position.pos > work.end) {
                break
            }

            // O(logN)
            iter.remove()

            // O(1)
            ans[position.index] = work.dist
        }
    }

    println(ans.joinToString("\n"))
}

Measured memory_bytes: 130344
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace io{
	const int l=1<<19;
	char *s,*t,buf[l],c;
	char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	template<class IT>void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gc();}
	}
}
using io::gc;
using io::gi;
template<class IT>void chkmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>void chkmax(IT &a,IT b){if(a<b)a=b;}

const int N=200005;

int n,v,u,s;
vector<int>e[N];
int dfs(int v,int fa){
	int u,x=0,y;
	for(int i=0;i<(int)e[v].size();i++){
		u=e[v][i];
		if(u!=fa){
			y=dfs(u,v)+1;
			chkmax(s,x+y);
			chkmax(x,y);
		}
	}
	return x;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&v,&u);
		e[v].push_back(u);
		e[u].push_back(v);
	}
	dfs(1,0);
	if(s%3==1)puts("Second");
	else puts("First");
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	int cnt=0;
	
	cin>>N;
	for(i=1;i<=9;i++) if(i<=N) cnt++;
	for(i=100;i<=999;i++) if(i<=N) cnt++;
	for(i=10000;i<=99999;i++) if(i<=N) cnt++;
	cout<<cnt<<endl;
}



int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define irep(i,a)for(int i=1;i<=a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll long long 

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define MAX_SIZE 1010
int n, m;
LL r, a;
LL x[MAX_SIZE], y[MAX_SIZE], z[MAX_SIZE], t[MAX_SIZE];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		cin >> x[i] >> y[i] >> z[i];

	int P[8][3] = { { 1,1,1 },{ 1,1,-1 },{ 1,-1,1 },{ 1,-1,-1 },{ -1,1,1 },{ -1,1,-1 },{ -1,-1,1 },{ -1,-1,-1 } };
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < n; ++j)
			t[j] = x[j] * P[i][0] + y[j] * P[i][1] + z[j] * P[i][2];
		sort(t, t + n);
		a = 0;
		for (int k = n - m; k < n; ++k)
			a += t[k];
		if (r < a)
			r = a;
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int main(){
  int n,k,i=0;
  scanf("%d %d\n",&n,&k);
  while(n>=k){
    n=n/k;
    i++;
  }
  printf("%d\n",i+1);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  cin >> A;
  int B;
  cin >> B;
  int n = 0;
  int P = 1;
  while(P < B){
  P = P - 1 + A;
  n = n + 1;
  }
  cout << n << endl;
}
  

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>
#include <fstream>

#define SIZE 100005
#define MOD 1000000007

using namespace std;

class CABSubstrings {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int64_t n;
    cin >> n;
    vector<string> vec;
    queue<string> front;
    queue<string> back;
    queue<string> both;
    int res = 0;
    for (int i = 0; i < n; ++i) {
      string item;
      cin >> item;
      {
        bool a_flag = false;
        for (const auto &word : item) {
          if (word == 'A') {
            a_flag = true;
          } else if (word == 'B') {
            if (a_flag)res++;
            a_flag = false;
          } else {
            a_flag = false;
          }
        }
      }
      if (item.front() == 'B' && item.back() == 'A') both.push(item);
      else if (item.front() == 'B') front.push(item);
      else if (item.back() == 'A') back.push(item);
      else vec.emplace_back(item);
    }
//    while(!front.empty() && !back.empty()){
//      res++;
//      front.pop();
//      back.pop();
//    }
    res += min(front.size(), back.size());
    if (both.size() > 0) {
      res += both.size() - 1;
      res += 1 && (front.size() != 0 || back.size() != 0);
    }
    cout << res << endl;
  }
};


int main() {
    CABSubstrings solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int n, m, q;

vector<int> A;
vector<int> a, b, c, d;
int ans = 0;
void dfs(int depth , int s)
{
    if(depth == n){
        int cnt = 0;
        //show(A);
        for (int i = 0; i < q; i++)
        {
            if(A[b[i]] - A[a[i]]==c[i]){
                cnt += d[i];
            }
            chmax(ans, cnt);
        }
      //  cerr << ans << endl;
        return;
    }
    for (int i = s; i <=m; i++)
    {
        A.push_back(i);
        dfs(depth + 1,i);
        A.pop_back();
    }
    return;
}

signed main()
{
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for (int i = 0; i < q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }
    dfs(0,1);
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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; }

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif

#pragma endregion Macros

int main()
{
    int N;
    ll D;
    cin >> N >> D;
    D *= D;

    int ans = 0;
    rep(i, N) {
        ll X,Y;
        cin >> X >> Y;

        if (X * X + Y * Y <= D) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3600
if __name__ == "__main__":
    N = int(input())
    S = input()
    unique_nums = [-1] * N
    for i in range(N):
        left = S[:i]
        # print(left)
        right = S[i:]
        # print(right)
        unique_nums[i] = len(set(left) & set(right))
    print(max(unique_nums))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back

using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }

signed main() {
	ll n, x, t; cin >> n >> x >> t;
	cout << (n + x - 1) / x * t << endl;
	fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
	return 0;
	/* 取模直接除，爆零两行泪
	 * 不开ll见祖宗
	 */
}

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

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

  int count = 0;
  while(a>=b) {
    b *= 2;
    count++;
  }
  while(b>=c) {
    c *= 2;
    count++;
  }

  if(count<=k) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	scanf("%d",&n);
	char str[n+1];
	scanf(" %s ",str);
	int temp=0;int a=0;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='(')
			temp++;
		else if(str[i]==')')
			temp--;
		if(temp<0)
		{
			a++;
			temp=0;
		}
	}
	for(int i=0;i<a;i++)
		printf("(");
	printf("%s",str);
	for(int i=0;i<temp;i++)
		printf(")");
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
while true do
    a, op, b = gets.split
    a = a.to_i
    b = b.to_i
    
    case op
    when "+" then
        puts a + b
    when "-" then
        puts a - b
    when "*" then
        puts a * b
    when "/" then
        puts a / b
    when "?" then
        break
    end
end

Measured memory_bytes: 8648
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;

int main() {
    array<string, 2> s; cin >> s[0] >> s[1];
    array<vector<int>, 2> a_acc;
    repeat (p,2) {
        a_acc[p].resize(s[p].length() + 1);
        repeat (i, s[p].length()) {
            a_acc[p][i+1] = a_acc[p][i] + (s[p][i] == 'A');
        }
    }
    auto pred = [&](int l0, int r0, int l1, int r1) {
        // swap is possible: AB AAA BBAA BAAAA BA
        int a0 = a_acc[0][r0] - a_acc[0][l0];
        int a1 = a_acc[1][r1] - a_acc[1][l1];
        int b0 = (r0 - l0) - a0;
        int b1 = (r1 - l1) - a1;
        assert (a0 or b0);
        if (a0 < a1) { int delta = a1 - a0; a0 += delta; b0 += delta; } // A BB AAB or B AA ABB
        if (b0 < b1) { int delta = b1 - b0; a0 += delta; b0 += delta; } // A BB AAB or B AA ABB
        assert (a1 <= a0 and b1 <= b0);
        int delta = b0 - b1;
        b0 -= delta;
        a0 += 2 * delta;
        return (a0 - a1) % 3 == 0;
    };
    int q; cin >> q;
    while (q --) {
        int l0, r0, l1, r1; cin >> l0 >> r0 >> l1 >> r1; -- l0; -- l1;
        cout << (pred(l0, r0, l1, r1) ? "YES" : "NO") << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    string S; cin >> S;
    
    int ans = 999;
    rep(i,S.length() - 2)  {
        string now = S.substr(i, 3);
        ans = min(ans, abs(stoi(now) - 753));
    }
    cout << ans << endl;

    
}

Measured memory_bytes: 256