akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    vector<vector<int>> nums(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> nums[i][j];

    int line_min[3];
    rep(i, 3) line_min[i] = *min_element(all(nums[i]));

    int a[3] = {0}, b[3] = {0};
    for(a[0] = line_min[0]; a[0] >= 0; a[0]--){
        for(a[1] = line_min[1]; a[1] >= 0; a[1]--){
            for(a[2] = line_min[2]; a[2] >= 0; a[2]--){
                bool success_flag = true;
                b[0] = max(0, nums[0][0] - a[0]);
                b[1] = max(0, nums[1][1] - a[1]);
                b[2] = max(0, nums[2][2] - a[2]);
                rep(i, 3) rep(j, 3) if(a[i] + b[j] != nums[i][j]) success_flag = false;

                if(success_flag){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

struct edge{int to,cap,rev;};

vector<edge> G[10000];
bool used[10000];
void add_edge(int from,int to,int cap){
    G[from].pb((edge){to,cap,(int)G[to].size()});
    G[to].pb((edge){from,0,(int)(G[from].size())-1});
}

// テ・ツ「ツ療・ツ環?」ツδ妥」ツつケテ」ツつ奪FSテ」ツ?ァテヲツ篠「テ」ツ??
int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap)); if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
// sテ」ツ?凝」ツつ液テ」ツ?クテ」ツ?ョテヲツ慊?・ツ、ツァテヲツオツ?」ツつ津ヲツアツづ」ツつ?」ツつ?
int max_flow(int s, int t) {
    int flow = 0; for (;;) {
        memset(used, 0, sizeof(used)); int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}



int main(){
    int m,n;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        rep(i,10000)G[i].clear();
        rep(i,10000)used[i]=false;
        int x[600];
        int y[600];
        rep(i,n) cin>>x[i];
        rep(i,m) cin>>y[i];
        
        rep(i,n){
            rep(j,m){
                if(__gcd(x[i],y[j])>1){
                    add_edge(i,n+j,1);
                }
            }
        }
        int s=n+m,t=s+1;
        rep(i,n){
            add_edge(s,i,1);
        }
        rep(i,m){
            add_edge(n+i,t,1);
        }
        cout<<max_flow(s,t)<<endl;
    }
}

Measured memory_bytes: 7868
#include <cstdio>
int main()
{
    int h, w;
    int i, j;
    int count = 0;
    char s[10] = {0};
    scanf("%d %d", &h, &w);
    for(i = 0; i < h; i++){
        scanf("%s", s);
        for(j = 0; j < w; j++){
            if(s[j] == '#'){
                count++;
            }
        }
    }
    if(count == h + w -1){
        printf("Possible\n");
    } else {
        printf("Impossible\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

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

using namespace std;

int main(){
	string str;
	int K;
	cin >> str >> K;
	rep(i,str.size()){
		if(K<=0){
			break;
		}
		if(str[i]=='a'){
			continue;
		}
		int l='z'-str[i]+1;
		if(K-l>=0){
			str[i] = 'a';
		}else{
			continue;
		}
		K-=l;
	}
	if(K>0){
		int e=str.size()-1;
		str[e]=(str[e]-'a'+K)%26+'a';
	}
	cout << str << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,d;
  cin >> n >>d ;

  ll s=0;
  for(ll i=0;i<n;i++){
    ll x,y;
    cin >> x >> y;
    if(x*x+y*y<=d*d)s++;
  }
  cout << s << endl;

}

Measured memory_bytes: 3620
using System;

class T1PBCA
{
	static public void Main(string[] args)
	{
		string S = Console.ReadLine();
		int ans = 0;
		for(int i=0; i < 6; i++)
		{
			if(S[i] == '1')
				ans++;
		}
		Console.WriteLine(ans);
	}
}


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


int main(){
    int64_t N,D,D_2,X,Y;
    int64_t cnt = 0;
    cin >> N >> D;
    D_2 = D*D;
    for(int64_t i = 0; i < N; i++){
        cin >> X >> Y;
        if(X*X + Y*Y > D_2){
        }else{
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3628
n=int(input())
m=0
a=0
r=0
c=0
h=0
for i in range(n):
  w=input()
  if w[0]=="M":
    m+=1
  elif w[0]=="A":
    a+=1
  elif w[0]=="R":
    r+=1
  elif w[0]=="C":
    c+=1
  elif w[0]=="H":
    h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String x = sc.next();
		String y = sc.next();

		int comp = x.compareTo(y);

		if (comp < 0) {
			System.out.println("<");
		} else if (comp == 0) {
			System.out.println("=");
		} else {
			System.out.println(">");
		}

		sc.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
char s[102];
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	bool flag1=true,flag2=true;
	for(int i=0;i<len;i++)
	{
		if(s[i]=='C')
			flag1=false;
		if(s[i]=='F' && !flag1)
			flag2=false;
		if(!flag1 && !flag2)
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

double pi = 3.141592653589793;

double cos_theo(int a, int b, double diff){
    if(diff > 180){
        diff = 360 - diff;
    }
    double cos_diff = cos(diff/180*pi);
    double dist = a*a + b*b - 2*a*b*cos_diff;
    return sqrt(dist);
}

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double min_arg, long_arg;
    min_arg = 6.0 * m;
    long_arg = 0.5*(60*h+m);

    double diff = abs(min_arg - long_arg);

    double dist = cos_theo(a, b, diff);

    printf("%.15f\n", dist);
    return 0;
}

Measured memory_bytes: 4156
# coding: UTF-8
#@document_it
def document_it(func):
    def new_function(*args,**kwargs):
        print('Running function:', func.__name__)
        print('Positional arguments:', args)
        print('Kewword arguments:', kwargs)
        result = func(*args,**kwargs)
        print('Result:', result)
        return result
    return new_function

def divide(n):
    import math
    m = math.ceil(math.sqrt(n))
    d = 2
    while d <= m:
        if n % d == 0:
            return d,n//d
        d += 1
    return n,1

def exe():
    string = input()
    n = int(string)
    factors=[]
    d,a = divide(n)
    factors.append(str(d))
    while a != 1:
        d,a = divide(a)
        factors.append(str(d))
    ans = string + ': ' + ' '.join(factors)
    print(ans)
 
if __name__ == '__main__':
    exe()



Measured memory_bytes: 5676
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,t,i,j,s=0,x,y;
    cin>>n;
    map <ll,ll> m;
    for(i=0;i<n;++i){
    	cin>>x;
    	m[x]++;
    	s+=x;
	}
	cin>>t;
	while(t--){
		cin>>x>>y;
		s = s - m[x] * x + m[x] * y;
		m[y]+=m[x];
		m[x]=0;
		cout<<s<<'\n';
	}
}

Measured memory_bytes: 9536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define per(i,s,t) for(int i=((t)-1);i>=(s);--i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
#define mst(a,b) memset(a,b,sizeof(a))
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'
#define fi first
#define se second
#define sq(x) ((x)*(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int inf = 0x3f3f3f3f;
const ll inff = 4557430888798830399ll;
const db eps = 1e-12;
const db pi = acos(-1.0);
const ll mod = 998244353;

#define maxn 100005
char s[maxn],t[maxn];

int main()
{
	ll n,m,g,a,b;
	scanf("%lld%lld%s%s",&n,&m,s,t);
	if(s[0]!=t[0])return !printf("-1\n");
	if(__gcd(n,m)==1)printf("%lld\n",n*m);
	else
	{
		g=__gcd(n,m);
		if(n>m)swap(n,m),swap(s,t);
		a=n/g;b=m/g;
		rep(i,0,g)if(s[i*a]!=t[i*b])return !printf("-1\n");
		printf("%lld\n",n*m/g);
	}
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    string s;
    cin >> n >> s;
    ll res = 0;
    vector<int> r(n + 1), g(n + 1), b(n + 1);
    rep (i, n) {
        if (s[i] == 'R') r[i]++;
        else if (s[i] == 'G') g[i]++;
        else b[i]++;
    }
    FOR (i, 1, n + 1) {
        r[i] += r[i - 1];
        g[i] += g[i - 1];
        b[i] += b[i - 1];
    }
    rep (i, n - 2) {
        FOR (j, i + 1, n - 1) {
            if (s[i] == s[j]) continue;
            int diff = j - i;
            int next = j + diff;
            int cnt = 0;
            if (s[i] == 'R' && s[j] == 'G') {
                cnt = b[n] - b[j];
                if (next < n) {
                    if (s[next] == 'B') cnt--;
                }
            } else if (s[i] == 'R' && s[j] == 'B') {
                cnt = g[n] - g[j];
                if (next < n) {
                    if (s[next] == 'G') cnt--;
                }
            } else if (s[i] == 'G' && s[j] == 'B') {
                cnt = r[n] - r[j];
                if (next < n) {
                    if (s[next] == 'R') cnt--;
                }
            } else if (s[i] == 'G' && s[j] == 'R') {
                cnt = b[n] - b[j];
                if (next < n) {
                    if (s[next] == 'B') cnt--;
                }
            } else if (s[i] == 'B' && s[j] == 'R') {
                cnt = g[n] - g[j];
                if (next < n) {
                    if (s[next] == 'G') cnt--;
                }
            } else if (s[i] == 'B' && s[j] == 'G') {
                cnt = r[n] - r[j];
                if (next < n) {
                    if (s[next] == 'R') cnt--;
                }
            }
            res += cnt;
        }
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

int main() {
	set<int> A;
	int n, m;
	int x;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		A.insert(x);
	}

	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> x;
		A.insert(x);
	}
	   
	for (auto it = A.begin(); it != A.end(); it++) 
		cout << *it << endl;
}


Measured memory_bytes: 21836
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            int ans = 1;

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

            Console.WriteLine(ans);
        }
    }
}



Measured memory_bytes: 11232
#include <stdio.h>
#include <stdlib.h>

int main(){
  int N, K, x;
  int i;
  scanf("%d%*c", &N);
  scanf("%d%*c", &K);
  int sum = 0;

  for( i = 0; i < N; i++){
    scanf("%d%*c", &x);
    if(2*x > K){
      sum += (K-x)*2;
    }else{
      sum += 2*x;
    }
  }
  printf("%d\n", sum);
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    rep(i,s.size()){
        if(i % 2 == 0){
            cout << s.at(i);
    }else{
        continue;
    }
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

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

const int MOD = 1e9 + 7;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  vector<int> x(n);
  vector<int> y(m);
  for(int i = 0; i < n; i++)
  {
    cin >> x[i];
  }
  for(int i = 0; i < m; i++)
  {
    cin >> y[i];
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  for(int z = X + 1; z < Y + 1; z++)
  {
    if(z > x[n - 1] && z <= y[0])
    {
      cout << "No War";
      return 0;
    }
  }
  cout << "War";

  return 0;
}


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

int main() {
  long long N;
  cin>>N;
  long long A=sqrt(N);
  long long ans=N;
  for(int i=A;i>0;i--){
    if(N%i==0){
      ans=i+N/i-2;
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int A,B,C,X,Y = 0;
    int min_price = 0;

    //A -> Aピザの枚数
    //B -> Bピザの枚数
    //C -> ABピザの枚数⇒2枚買えばAピザ1Bピザ1になる
    //X -> Aピザの必要枚数
    //Y -> Bピザの必要枚数
    cin >> A >> B >> C >> X >> Y;

    //A+B>2Cなら、X,Yのうち小さい数まではABピザで買うのが最小
    if( 2*C < (A+B) )
    {
        int lower_num = min(X,Y);
        min_price = C*(2*lower_num); //ABピザは2枚単位で買わないとA/Bピザを生成できない
        X = X - lower_num; //必要枚数更新
        Y = Y - lower_num; //必要枚数更新

        //残りはAピザ
        if(X > 0)
        {
            if( 2*C < A )
            {
                //ABピザ2枚の方が安いのでABピザで揃える
                min_price += C*2*X;
            }
            else
            {
                //個別に買う
                min_price += A*X;
            }

            X = 0; //必要枚数更新
        }
        
        //残りはBピザ
        if(Y > 0)
        {
            if( 2*C < B )
            {
                //ABピザ2枚の方が安いのでABピザで揃える
                min_price += C*2*Y;
            }
            else
            {
                //個別に買う
                min_price += B*Y;
            }

            Y = 0; //必要枚数更新
        }

        cout << min_price << endl;
        return 0;
    }

    //該当しない場合、それぞれ個別に買う
    min_price += A*X;
    min_price += B*Y;

    cout << min_price << endl;

    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

g = [[0 for _ in range(W)] for _ in range(H)]
h = 0
w = 0
for i in range(1, N+1):
    for _ in range(A[i-1]):
        g[h][w] = i
        if h % 2 == 0:
            w += 1
            if w > W-1:
                h += 1
                w = W-1
        else:
            w -= 1
            if w < 0:
                h += 1
                w = 0

for i in range(H):
    print(*g[i])


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

ll knapsack(ll n,ll w,ll wght[],ll val[])
{
	ll dp[n+1][w+1];
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=w;j++)
		{
			if(i==0 || j==0)
				dp[i][j]=0;
			else if(wght[i-1]>j)
				dp[i][j]= dp[i-1][j];
			else
				dp[i][j]= max( dp[i-1][j] , dp[i-1][j-wght[i-1]] + val[i-1] );
		}
	}
	return dp[n][w];
}

int main()
{
  ll n,W;
  cin>>n>>W;

  ll wght[n],val[n];
  
  for(ll i=0;i<n;i++)
  {
  	cin>>wght[i]>>val[i];
  }
  
  ll ans=knapsack(n,W,wght,val);

  cout<<ans<<endl;
  
  return 0;
}
  

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

#pragma GCC optimize(2)

#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

int gi() {
	int f = 1, x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 1) + (x << 3) + ch - '0';
		ch = getchar();
	}
	return f * x;
}

int main() {
	int a = gi(), b = gi();
	string t = "", t1 = "";
	rep (i, 1, a) t.push_back(b + '0');
	rep (i, 1, b) t1.push_back(a + '0');
	cout << (t < t1 ? t : t1) << endl; 
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
s = input()

num = []
temp = 0
count = 0
flag = True
while temp < len(s):
    if flag == True:
        if s[temp] == "1":
            count += 1
            temp += 1
        else:
            num.append(count)
            count = 1
            temp += 1
            flag = False
    else:
        if s[temp] == "0":
            count += 1
            temp += 1
        else:
            num.append(count)
            count = 1
            temp += 1
            flag = True
num.append(count)
num2 = [sum(num[:min(2 * k + 1, len(num))])]
temp = min(2 * k + 1, len(num))
temp2 = 0
while temp < len(num):
    temp3 = num2[-1] - num[temp2] - num[temp2 + 1] + num[temp]
    if temp + 1 < len(num):
        temp3 += num[temp + 1]
    temp += 2
    temp2 += 2
    num2.append(temp3)
print(max(num2))

Measured memory_bytes: 11060
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

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

int main()
{
  int n;
  cin >> n;
  vector<vector<pair<int, bool>>> c(n);
  REP(i, n) c[i] = {};
  REP(i, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    bool dif = w % 2 == 1;
    c[u].pb(make_pair(v, dif));
    c[v].pb(make_pair(u, dif));
  }
  vector<int> found(n, -1);
  found[0] = 0;
  vector<int> s = {0};
  while(s.size() > 0) {
    int a = s[s.size() - 1], b = found[a];
    s.pop_back();
    for(auto p : c[a]) {
      if (found[p.first] < 0) {
        found[p.first] = p.second ? abs(b - 1) : b;
        s.pb(p.first);
      }
    }
  }
  for (auto i : found) {
    cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 6784
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int l[202];
    for (i = 0; i < 2 * n; i++)
        scanf("%d", &l[i]);
    int x;
    for (i = 0; i < 2 * n - 1; i++)
    {
        if (l[i] < l[i + 1])
        {
            x = l[i];
            l[i] = l[i + 1];
            l[i + 1] = x;
            if (i > 0)
                i -= 2;
        }
    }
    int ans = 0;
    for (i = 1; i < 2 * n; i += 2)
        ans += l[i];
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    double d = Integer.parseInt(sc.next());
    double t = Integer.parseInt(sc.next());
    int s = Integer.parseInt(sc.next());
    pw.println(d / s <= t ? "Yes" : "No");
  }
}


Measured memory_bytes: 35572
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int A,B;cin >> A >> B;
    cout << max(0,A - 2*B) << endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    
    private static int N;
    private static String[] Ss;
    private static int[] Cs;
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        N = sc.nextInt();
        Ss = new String[N];
        Cs = new int[N];
        
        for (int i = 0; i < N; i++) {
            Ss[i] = sc.next();
            Cs[i] = sc.nextInt();
        }
        
        long min = Long.MAX_VALUE;
        
        // 単体で回文になっているものがあるか調べる
        for (int i = 0; i < N; i++) {
            if (isPalindrome(Ss[i]) && Cs[i] < min) {
                min = Cs[i];
            }
        }
        
        // 左端と右端の文字列を選び、その場合の最小コストを調べる
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                long cost = cost(Ss[i], Ss[j]);
                if (cost < min - Cs[i] - Cs[j]) {
                    min = cost + Cs[i] + Cs[j];
                }
            }
        }
        
        System.out.println(min == Long.MAX_VALUE ? -1 : min);
    }
    
    private static boolean isPalindrome(String str) {
        int i = 0;
        int j = str.length() - 1;
        while (i < j) {
            if (str.charAt(i) != str.charAt(j)) {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
    
    private static boolean isSameEdge(String left, String right) {
        int i = 0;
        int j = right.length() - 1;
        while (i < left.length() && 0 <= j) {
            if (left.charAt(i) != right.charAt(j)) {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
    
    private static final Map<String, Long> costs = new HashMap<>();
    
    private static long cost(String left, String right) {
        String key = left + "_" + right;
        if (costs.containsKey(key)) {
            return costs.get(key);
        } else {
            costs.put(key, Long.MAX_VALUE);
        }
        
        if (!isSameEdge(left, right)) {
            return Long.MAX_VALUE;
        }
        if (left.length() == right.length()) {
            costs.put(key, 0L);
            return 0;
        }
        
        String rem = left.length() < right.length()
                ? right.substring(0, right.length() - left.length())
                : left.substring(right.length());
        if (isPalindrome(rem)) {
            costs.put(key, 0L);
            return 0;
        }
        
        long min = Long.MAX_VALUE;
        
        if (left.length() < right.length()) {
            for (int i = 0; i < N; i++) {
                long cost = cost(Ss[i], rem);
                if (cost < min - Cs[i]) {
                    min = cost + Cs[i];
                }
            }
            
        } else {
            for (int i = 0; i < N; i++) {
                long cost = cost(rem, Ss[i]);
                if (cost < min - Cs[i]) {
                    min = cost + Cs[i];
                }
            }
        }
        costs.put(key, min);
        return min;
    }
}


Measured memory_bytes: 48384
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
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(){
    int n;
    cin>>n;
    vector<string> S(n);
    vector<int> alpha(26,1e9);
    rep(i,n) cin>>S.at(i);
    string s;
    rep(i,n){
        vector<int> tmp_alpha(26,0);
        rep(j,S.at(i).size()){
            tmp_alpha.at(S.at(i).at(j)-'a')++;
        }
        rep(j,26){
            alpha.at(j) = min(alpha.at(j),tmp_alpha.at(j));
        }
    }
    rep(i,26){
        rep(j,alpha.at(i)){
            cout<<(char)('a'+i);
        }
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int dp[100000][3];
int main(){
  int N;cin >> N;
  int happy[3][100000];
  for(int i = 0;i < N;++i){
    cin >> happy[0][i] >> happy[1][i] >> happy[2][i];
  }
  for(int i = 0;i < N;++i){
    for(int j = 0;j < 3;++j){
      dp[i + 1][j] =max(dp[i][(j + 1)%3] + happy[j][i], dp[i][(j + 2)%3] + happy[j][i]);
    }
  }
  if(max(dp[N][0],dp[N][1]) > max(dp[N][1],dp[N][2])){
    cout << max(dp[N][0],dp[N][1]);
  }else{
    cout << max(dp[N][1],dp[N][2]);
  }
}


Measured memory_bytes: 2560
a,v = gets.split.map &:to_i
b,w = gets.split.map &:to_i
t = gets.to_i

if a == b then
	puts 'YES'
elsif v <= w then
	puts 'NO'
else
	if (b-a).abs <= (v - w) * t then
		puts 'YES'
	else
		puts 'NO'
	end
end


Measured memory_bytes: 14420
#include <stdio.h>
main(){
	int data[4];
	scanf("%d",&data[0]);
	scanf("%d",&data[1]);
	scanf("%d",&data[2]);
	scanf("%d",&data[3]);
	int goukei=data[0]+data[1]+data[2]+data[3];
	printf("%d\n%d\n",goukei/60,goukei%60);
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string.h>
#define MAX_NUMBER 2000010
 
struct Data{
    int num;
    int next;
    int before;
};
 
Data data[MAX_NUMBER];
int head = -1,tail = -1,cp = 0;
 
void insert(int x){
    data[cp].num = x;
    data[cp].next = head;
    data[cp].before = -1;
    if(head!=-1){
        data[head].before = cp;
    }else{
        tail = cp;
    }
    head = cp++;
}
 
void delete1(int x){
    int p = head;
    if(data[p].num == x){
        head = data[p].next;
        data[data[p].next].before = -1;
    }else{
        while(p != -1){
            int tmp = data[p].next;
            if(tmp == tail && data[tmp].num == x){
                data[p].next = -1;
                tail = p;
            }else if(data[tmp].num == x){
                data[p].next = data[tmp].next;
                data[data[tmp].next].before = p;
                return;
            }
            p = data[p].next;
        }
    }
}
             
 
void deleteFirst(){
    int tmp=data[head].next;
    if(tmp==-1){
        head=-1;
        tail=-1;
    }else{
        data[tmp].before = -1;
        head = tmp ;
    }
}
 
void deleteLast(){
    int tmp = data[tail].before;
    if(tmp==-1){
        head = -1;
        tail = -1;
    }else{
        data[tmp].next = -1;
        tail = tmp;
    }
}
 
int main(){
    int n,x;
    char command[20];
    std::cin >> n;
    for(int i=0;i<n;i++){
        std::cin >> command ;
        if(strcmp(command,"insert")==0){
            std::cin >> x;
            insert(x);
        }else if(strcmp(command,"delete")==0){
            std::cin >> x;
            delete1(x);
        }else if(strcmp(command,"deleteFirst")==0){
            deleteFirst();
        }else if(strcmp(command,"deleteLast")==0){
            deleteLast();
        }
    }
    int p = head;
    if(p!=-1){
        std::cout << data[p].num ;
    }
    p = data[p].next;
    while(p!=-1){
        std::cout << ' ' << data[p].num ;
        p = data[p].next;
    }
    std::cout << '\n';
    return 0;
}



Measured memory_bytes: 15996
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
  int x;
  cin >> x;
  int i = x;
  while(1){
    if(IsPrime(i)){
      cout << i << endl;
      return 0;
    }else{
      i++;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N;
      cin >> N;
      int a1,a2,a3,a4;
      a1=N/1000;
      a2=(N%1000)/100;
      a3=((N%1000)%100)/10;
      a4=((N%1000)%100)%10;
     
      if (a1 == a2 && a2 == a3) {
        cout << "Yes" << endl;
      }
      else if(a2 == a3 && a3 == a4){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
          
    }

Measured memory_bytes: 3644
from collections import defaultdict
from operator import itemgetter

N = int(input())
p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))
p.sort(key=itemgetter(0), reverse=True)

if N == 1:
    print(1)
else:
    d = defaultdict(int)
    for i, pp1 in enumerate(p):
        for j in range(i + 1, N):
            pp2 = p[j]
            d[(pp1[0] - pp2[0], pp1[1] - pp2[1])] += 1
        # print(d)

    cnt = 0
    keys = tuple(d.keys())
    for k in keys:
        x, y = k
        cnt = max(cnt, d[k] + d[(-x, -y)])

    print(N - cnt)


Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=5005,P=1e9+7,oo=P;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
void upd(int &a,int b){ a=add(a,b); }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int n,a,b,f[N][2],g[N][2],g2[N][2],ans;

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in","r",stdin); 
#endif
	scanf("%d%d%d",&n,&a,&b);
	if(a>b)swap(a,b); 
	g[0][0]=1;
	lop(i,0,b-1){
		//add1
		rep(j,1,b-1-i)upd(g[i+j][1],g[i][0]);
		//add0
		rep(j,a,b-1-i)upd(g[i+j][0],g[i][1]); 
	}
	g2[0][1]=1;
	lop(i,0,b-1){
		//add1
		rep(j,1,b-1-i)upd(g2[i+j][1],g2[i][0]);
		//add0
		rep(j,a,b-1-i)upd(g2[i+j][0],g2[i][1]); 
	}
	f[0][0]=1,f[0][1]=1;
	rep(j,a,n-1)f[j][1]=g2[j][1];
	f[n][1]=g2[n][1]; 
	f[n][0]=g2[n][0];
	lop(i,0,n){
		//add0
		lop(j,1,min(a,n-i+1)){
			upd(f[i+j][0],f[i][1]);
		}
		lop(j,1,min(b,n-i+1)){
			upd(f[i+j][1],mul(g[j][1],f[i][0])); 
		}
		upd(f[n][0],mul(g[n-i][0],f[i][0])); 
	}
	ans=1; 
	rep(i,1,n)ans=mul(ans,2); 
	ans=sub(ans,add(f[n][1],f[n][0])); 
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MAXN = 2e5+7;
int n;
long long ans[MAXN], soma=0, freq[MAXN], a[MAXN];
int main(){
	fastio; cin>>n;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		freq[a[i]]++;
	}
	for(int i=1; i<=n; i++){
		ans[i] = freq[a[i]] - 1;
		soma += ans[i];
	}
	for(int i=1; i<=n; i++){
		cout<< soma/2 - ans[i] << endl;	
	}
}

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

using namespace std;

int main(){
	int n = 3;
	int c[3][3];
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			cin >> c[i][j];
		}
	}
	int a[3];
	for(int i = 0; i <= 100; ++i){
		for(int j = 0; j <= 100; ++j){
			for(int k = 0; k <= 100; ++k){
				a[0] = i;
				a[1] = j;
				a[2] = k;
				set<int> b[3];
				bool ok = 1;
				for(int x = 0; x < 3; ++x){
					for(int y = 0; y < 3; ++y){
						c[x][y] -= a[x];
						if(c[x][y] < 0){
							ok = 0;
						}
						b[y].insert(c[x][y]);
						c[x][y] += a[x];
					}
				}
				for(int x = 0; x < 3; ++x) if(b[x].size() > 1) ok = 0; 
				if(ok){
					//cout << i << ' ' << j << ' ' << k << '\n';
					cout << "Yes\n";
					return 0;
				}
			}
		}
	}
	cout << "No\n";
}

Measured memory_bytes: 256
from itertools import accumulate
from collections import Counter

mod = 2019
s = input()
keta = len(list(s))
JJ = [0 for i in range(keta + 2)]
JJ[0] = 1
JJG = [0 for i in range(keta + 2)]
JJG[0] = 1
for i in range(1, keta + 2):
    JJ[i] = (10 * JJ[i - 1]) % mod
    JJG[i] = pow(JJ[i], mod - 2, mod)

S = [0] * (keta)


for i in range(keta - 1, -1, -1):

    S[i] = int(s[keta - 1 - i]) * JJ[i]
    S[i] %= mod

SA = [0] * (keta)
SA[0] = S[0]
for i in range(keta - 1):
    SA[i + 1] = SA[i] + S[i + 1]
    SA[i + 1] %= mod


ans = 0

SC = Counter(SA)
for e, i in Counter(SA).items():
    if e > 0:
        ans += i * (i - 1) // 2
    else:
        ans += i
        ans += i * (i - 1) // 2

print(ans)


Measured memory_bytes: 38344
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long N, K;
    vector<long long> A;

    cin >> N >> K;
    for (long long i = 0; i < N; i++)
    {
        long long t;
        cin >> t;
        A.push_back(t - 1);
    }

    vector<long long> d(N, -1);
    d[0] = 0;
    long long l = 0;
    long long c = 0;
    while (true)
    {
        if (d[A[l]] != -1)
            break;
        c++;
        l = A[l];
        d[l] = c;
        if(c >= K){
            cout << l + 1 << endl;
            return 0;
        }
    }

    long long dd = c - d[A[l]] + 1;
    K = (K - d[A[l]]) % dd;
    c = 0;
    l = A[l];
    while (c < K)
    {
        l = A[l];
        c++;
    }

    cout << l + 1 << endl;

}

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

int main() {
  int n, m, max=0;
  cin >> n;  
  vector<string> blue(n);
  for(int i=0; i<n; i++) cin >> blue.at(i);
  cin >> m;
  vector<string> red(m);
  for(int i=0; i<m; i++) cin >> red.at(i);
  
  for(int i=0, count=0; i<n-1; count=0, i++){
    for(int j=i; j<n; j++) if(blue.at(i) == blue.at(j)) count++;
    for(int j=0; j<m; j++) if(blue.at(i) == red.at(j)) count--;
    if(max < count) max = count;
  }
  cout << max;
}

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

string easy(){
	for(i=1;i<t.size();i++){
    	if(t[i]=='?'){
    		t[i]='D';
		}
	}
	return t;
}

int main(){
    cin>>t;
    int s=0;
    for(i=0;i<t.size();i++){
    	if(t[i]=='P')break;
    	else easy();
	}
	for(i=1;i<t.size();i++){
	    if(t[i]=='D'&&t[i-1]=='?'){
	    	t[i-1]='P';
		}	 	
		if(t[i]=='?'&&t[i-1]=='P'){
			t[i]='D';
		}
	}	
	for(i=0;i<t.size();i++){
		if(t[i]=='?') t[i]='D';
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 3900
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    string S;
    cin>>S;
    reverse(S.begin(), S.end());
    vector<int> arr(S.size());
    map<int, int> map;
    int tmp = 10;
    arr[0] = S[0]-'0';
    for(int i=1;i<S.size();++i){
        arr[i] = arr[i-1] + tmp*(S[i]-'0');
        arr[i] %= 2019;
        tmp *= 10;
        tmp %= 2019;
    }
    for(int i=0;i<arr.size();++i){
        map[arr[i]]++;
    }
    int ans = 0;
    map[0]++;
    for(int i=0;i<=2019;++i){
        ans += map[i]*(map[i]-1)/2;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder_ensyuu1
{
    class Program
    {
        private static void Main(string[] args)
        {
            int[] values = GetConsole();
            int intRating = 0;
            if (values[0] >= 10)
            {
                intRating = values[1];                
            }
            else
            {
                intRating = values[1] + 100 * (10 - values[0]);
            }
            Console.WriteLine(intRating);
        }
      
        private static int[] GetConsole()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
int u[1100000];
vector<int> y;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0;
  string s;
  cin >>s;
  for(int n=0;n<4;n++){
    if(s[n]=='+') d++;
    else d--;
  }
  cout <<d<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>

using namespace std;

int cost(int n, int x, int y)
{
  int m = int(n/x);
  if(n%x!=0) {
    m += 1;
  }
  return m*y;
}

int main()
{
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  
  cout << min(cost(n, a, b), cost(n, c, d)) << endl;
  return 0;
}


Measured memory_bytes: 3120
// 28.01.2018

/*


*/

# include <iostream>
# include <iomanip>
# include <cstdio>
# include <cstdlib>
# include <cmath>
# include <cstring>
# include <vector>
# include <stack>
# include <queue>
# include <algorithm>


//# define __TRR__


# define lint  long long int


using namespace std;


const int N = 111;

int n, m, k, a [2][N], a0, a1;
bool ok;


int main ()
{
# ifdef __TRR__
   freopen ("A.TXT", "r", stdin);
   freopen ("A.OUT", "w", stdout);
# endif

   cin >> n;
   for ( int i (0); i < n; i++ )
      cin >> a [0][i];
   for ( int i (0); i < n; i++ )
      cin >> a [1][i];

# ifdef __TRR__
   cout << "n = " << n << endl;
   for ( int i (0); i < n; i++ )
      cout << a [0][i] << " ";
   cout << endl;
   for ( int i (0); i < n; i++ )
      cout << a [1][i] << " ";
   cout << endl;
# endif

   a0 = a [0][0], a1 = a [0][0] + a [1][0];

# ifdef __TRR__
   cout << "0 a0 = " << a0 << "   a1 = " << a1 << endl;
# endif

   for ( int i (1); i < n; i++ )
   {
      a0 += a [0][i];
      a1 = max (a0, a1) + a [1][i];

# ifdef __TRR__
   cout << i << " a0 = " << a0 << "   a1 = " << a1 << endl;
# endif
   }

   cout << a1;

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;
int main() {
ll A;cin >> A;
if((A/10)%111 == 0){cout << "Yes";exit(0);}
if((A - (A/1000)*1000)%111 == 0){cout << "Yes";exit(0);}
cout << "No";
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

bool check(vector<string> a, vector<string> b, int x, int y) {
    for(int i=0;i<b.size();i++) {
        for(int j=0;j<b[0].size();j++) {
            if(a[i+x][j+y]!=b[i][j]) {
                return false;
            }
        }
    }
    return true;
}

void solve() {
    int n, m;
    cin>>n>>m;
    vector<string> a(n), b(m);
    for(string& i:a) cin>>i;
    for(string& i:b) cin>>i;
    for(int i=0;i< n-m+1;i++) {
        for(int j=0;j< a[0].size()-b[0].size()+1;j++) {
            if(a[i][j]==b[0][0]) {
                if(check(a,b,i,j)) {
                    cout<<"Yes";
                    return;
                }
            }
        }
    }
    cout<<"No";
}

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

Measured memory_bytes: 3640
//When Can We Meet?
#include <stdio.h>
int main(void){
    int N, Q;
    int M, m[100] = {};
    int count[100] = {};
    int max = 0 ,l;
    
    for ( int i = 0;; i++){
        scanf ("%d%d", &N, &Q);
        if (N == 0) break;
        max = 0;
        for (int h = 0; h < 100; h++) count[h] = 0;
        for ( int j = 0; j < N; j++){
            scanf ("%d", &M);
            for ( int k = 0; k < M; k++){
                scanf ("%d", &m[k]);
                count[m[k]]++;
                if (max < count[m[k]]) max = count[m[k]];
            }
        }
        for ( l = 0; l < 100; l++){
            if (count[l] >= Q && count[l] == max ){
                printf ("%d\n", l);
                break;
            }
        }
        if (l == 100) printf ("0\n");
    }
}

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

using namespace std;

typedef unsigned long long ull;

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ull sum=0;
    ull k;
    cin>>k;
    for(ull a=1;a<=k;a++){
        for(ull b=1;b<=k;b++){
            for(ull c=1;c<=k;c++){
                sum+=__gcd(a,__gcd(b,c));
            }
        }
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3648
#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; }
//---------------------------------------------------------------------------------------------------
vector<string> rotateClockwise(vector<string> g) {
    int n = g.size();
    int m = g[0].size();
    vector<string> res(m, string(n, '#'));
    rep(i, 0, n) rep(j, 0, m) res[j][n - i - 1] = g[i][j];
    return res;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 
 
 
 
 
int H, W;
vector<string> B;
//---------------------------------------------------------------------------------------------------
int solve() {
	int ma = -1, mi = inf;

	rep(y, 0, H) rep(x, 0, W) if (B[y][x] == 'B') {
		chmax(ma, y + x);
		chmin(mi, y + x);
	}

	return ma - mi;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W;
	rep(y, 0, H) {
		string s; cin >> s;
		B.push_back(s);
	}

	int ans = 0;

	rep(d, 0, 4) {
		// rotate
		B = rotateClockwise(B);
		swap(H, W);

		chmax(ans, solve());
	}

	cout << ans << endl;
}
 


Measured memory_bytes: 5156
#include<bits/stdc++.h>
using namespace std;
#define sc cout<<"success"<<endl
int main()
{
    //cin>>tc;for(int t=1;t<=tc;t++){ }
    double n,d;
    cin>>n>>d;
    d=d*2+1;

    cout<<ceil((double)n/d)<<endl;
}



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

int n, m;
int c[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

const int INF = 1e9;

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

  vector<int> a(m);
  rep(i,m) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());

  vector<int> dMax(n+1, -INF);
  dMax[0] = 0;

  for(int i = 1; i <= n; i++) {
    rep(j,m) {
      if(i >= c[a[j]]) dMax[i] = max(dMax[i], dMax[i-c[a[j]]] + 1);
    }
  }

  int rest = n;
  rep(i,m) {
    while(rest - c[a[i]] >= 0 && dMax[rest - c[a[i]]] == dMax[rest] - 1) {
      cout << a[i];
      rest -= c[a[i]];
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
const int N = 200000+10;
char s[N];
int main() {
    int res=0,n;
    cin>>n;
    scanf(" %s",s+1);
    int l=1,r=n;
    while(s[l]=='R') l++;
    while(s[r]=='W') r--;
    while(l<r) {
        res++;
        l++,r--;
        while(s[l]!='W'&&l<r) l++;
        while(s[r]!='R'&&l<r) r--;
    }
    printf("%d",res);
    return 0;
}


Measured memory_bytes: 3448
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
def main():
    s=S()
    b_start=0
    w_start=1
    num_whenbstart=0
    num_whenwstart=0
    for i in range(len(s)):
        if int(s[i])!=b_start:
            num_whenbstart+=1
        if int(s[i])!=w_start:
            num_whenwstart+=1
        b_start=0 if b_start%2==1 else 1
        w_start=0 if w_start%2==1 else 1
    print(min(num_whenwstart,num_whenbstart))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, A, B = list(map(int, sys.stdin.readline().split()))
print(min(A, B), max(0, A+B-N))


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

int main(void){
 long long N;
  cin >> N;
  long long temp = N;
  int  c = 10;
  int sum = 0;
  while(temp > 0){
    sum += temp % c;
    temp /= 10;
  }
  if(N % sum == 0) cout << "Yes";
  else cout << "No";
  
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env pypy

import sys
input = sys.stdin.buffer.readline
INF = float("inf")

def main():
    N,M = map(int,input().split())

    # dp[i][j] : i番目の鍵までを使い, j の組み合わせの箱を開けるのに必要な最小費用
    dp = [[INF for _ in range(2**N)] for _ in range(M+1)]
    dp[0][0] = 0

    for i in range(M):
        a,b =map(int,input().split())
        c = list(map(int,input().split()))

        # 開錠可能な箱をbitで表現する
        bit = 0
        for x in c:
            bit |= 1 << (x-1)
        
        for j in range(2**N):
            # 鍵を使う場合
            dp[i+1][j | bit] = min(dp[i+1][j | bit], dp[i][j] + a)
            # 鍵を使わない場合
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    
    if dp[-1][-1] == INF:
        print(-1)
    else:
        print(dp[-1][-1])

if __name__ == "__main__":
    main()

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

using namespace std;
using ll = long long int;
#define long ll

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

    ll n;
    cin >> n;
    vector<vector<ll>> G(n);
    for(ll i=0; i<n-1; i++) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    bool ng = false;
    vector<tuple<ll,ll,ll>> mm(n, make_tuple(-1e9, 1e9, 2));
    {

        ll k;
        cin >> k;
        while(k--) {
            ll v, p;
            cin >> v >> p;
            v--;
            mm[v] = make_tuple(p, p, p&1);
        }

        auto dfs = [&](auto dfs, ll cur, ll pre) -> void {
            ll &m = get<0>(mm[cur]);
            ll &M = get<1>(mm[cur]);
            ll &oe = get<2>(mm[cur]);
            for(auto &v: G[cur]) {
                if(v == pre) continue;
                dfs(dfs, v, cur);
                ll _m, _M, _oe;
                tie(_m, _M, _oe) = mm[v];
                m = max(m, _m-1);
                M = min(M, _M+1);
                if(oe&2) oe = _oe^1;
                else if(~_oe&2 && oe==_oe) ng = true;
            }
            if(m > M) ng = true;
        };
        dfs(dfs, 0, -1);
    }

    if(ng) {
        cout << "No" << endl;
        return 0;
    }

    vector<ll> res(n);
    {
        auto dfs = [&](auto dfs, ll cur, ll pre) -> void {

            for(auto &v: G[cur]) {
                if(v == pre) continue;

                ll m, M, oe;
                tie(m, M, oe) = mm[v];
                res[v] = m <= res[cur]-1 && res[cur]-1 <= M ? res[cur]-1 : res[cur]+1;
                dfs(dfs, v, cur);
            }
        };
        res[0] = get<0>(mm[0]);
        dfs(dfs, 0, -1);
    }

    cout << "Yes" << endl;
    for(auto &e: res) cout << e << endl;
}


Measured memory_bytes: 14720