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

using namespace std;

const long long INF = (1LL << 60);

template<typename T>
class MaxFlow {
public:
	explicit MaxFlow(int n) : g(n), level(n), iter(n) {}
    struct Edge {
        Edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {}
        int to, rev;
        T cap;
    };
	vector<vector<Edge>> g;
	vector<int> level;
	vector<int> iter;
	void addEdge(int src, int dst, T cap){
		g[src].emplace_back(dst, cap, g[dst].size());
		g[dst].emplace_back(src, 0, g[src].size()-1);
	}
	T dfs(int pos, int dst, T f){
		if(pos == dst) return f;
		for(int& i=iter[pos];i<g[pos].size();++i){
			Edge& e = g[pos][i];
			if(e.cap == 0 || level[e.to] <= level[pos]) continue;
			int d = dfs(e.to, dst, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
		}
		return 0;
	}
	T maxFlow(int s, int t){
		T res = 0;
		int n = g.size();
		while(true){
            fill(level.begin(), level.end(), -1);
			level[s] = 0;
			queue<int> qu; qu.push(s);
			while(!qu.empty()){
				int p = qu.front(); qu.pop();
				for(const Edge& e : g[p]){
					if(e.cap > 0 && level[e.to] == -1){
						level[e.to] = level[p]+1;
						qu.push(e.to);
					}
				}
			}
			if(level[t] == -1) break;
            fill(iter.begin(), iter.end(), 0);
			for(T f;(f=dfs(s, t, INF)) > 0;res+=f);
		}
		return res;
	}
};

int main(){
    int N; cin >> N;
    long long res = 0;
    MaxFlow<long long> mf(N+2);
    for(int i=1;i<=N;i++){
        int v; cin >> v;
        if(v < 0){
            mf.addEdge(0, i, -v);
        } else {
            mf.addEdge(i, N+1, v);
            res += v;
        }
        for(int j=2*i;j<=N;j+=i) mf.addEdge(i, j, INF);
    }
    cout << res - mf.maxFlow(0, N+1) << endl;
}

Measured memory_bytes: 3644
//In the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define MAX 100011
#define mod 1000000007
#define inf 1000000000000000
#define ll long long
#define endl '\n'
vector<int> g[MAX];
ll dp[MAX][2];
void dfs(int u ,int par = -1){
	dp[u][0] = 1;
	dp[u][1] = 1;
	for(auto v : g[u]){
		if(v != par){
			dfs(v,u);
			dp[u][1] *= dp[v][0];
			dp[u][1] %= mod;
			dp[u][0] *= (dp[v][1] + dp[v][0])%mod;
			dp[u][0] %= mod;
		}
	}
}

int main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,x,y;
	cin>>n;
	for(int i = 0; i < n - 1; i++){
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1);
	cout<<(dp[1][0] + dp[1][1])%mod;
	return 0; 
} 

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

#define gc getchar 
#define pc putchar
#define fRead	freopen("input.txt","r",stdin) 
#define fWrite	freopen ("output.txt","w",stdout)
#define LL              long long
#define PI              acos(-1.0)
#define pb              push_back
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define f              	first
#define s              	second
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define vi              vector <int>
#define vL              vector <LL>

using namespace std;
#define scani2(a,b) scani(a) , scani(b)
#define scani3(a,b,c) scani(a), scani(b), scani(c)
#define scani4(a,b,c,d) scani(a), scani(b), scani(c), scani(d)
#define scani5(a,b,c,d,e) scani(a), scani(b), scani(c), scani(d) , scani(e)
template <typename T> T scani(T &n){n = 0;bool negative = false;char c = gc();while( c < '0' || c > '9'){if(c == '-') negative = true;c = gc();}while(c >= '0' && c <= '9'){n = n*10 + c-48;c = gc();}if(negative) n = ~(n-1);return n;}
template <typename T> void write(T n,int type = true){if(n<0) {pc('-');n = -n;}if(!n) {pc('0');if(type==32) pc(' '); else if(type) pc('\n'); return;}char buff[22];int len = 0;while(n) buff[len++] = n%10+48,n/=10;for(int i=len-1;i>=0;i--) pc(buff[i]);if(type==32) pc(' '); else if(type) pc('\n');}
int scans(char *a){int i=0;char c = 0;while(c < 33) c = gc();while(c > 33){a[i++] = c;c = gc();}a[i] = 0;return i;}
const int MOD = 1e9 + 7;

const int N = 1e5+10;
struct vertex {
	LL dist;
	set<pii> adjs;
	vertex():dist(1LL<<50){}
} V[N];

void root_k(int k, LL dist = 0LL, int parent = -1) {
	vertex *kn = &V[k];
	if(parent == -1) {
		kn->dist = dist;
	} else {
		kn->dist = min(kn->dist, dist + V[parent].dist);
	}
	for(auto v : kn->adjs) {
		if(v.f != parent)
			root_k(v.f,v.s,k);
	}
}

int main() {
	int n,a,b,c; scani(n);
	for(unsigned i = 0; i < n-1; ++i) {
		scani3(a,b,c);
		V[a].adjs.insert({b,c});
		V[b].adjs.insert({a,c});
	}

	int q,k,x,y; scani2(q,k);
	root_k(k);

	for(unsigned i = 0; i < q; ++i) {
		scani2(x,y);
		write(V[x].dist+V[y].dist);
	}


	return 0;
}

Measured memory_bytes: 21376
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,b,a) for(i=b-1;i>=(ll)a;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  if(n<r)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll i,N,f=1,ans=0;
  cin>>N;
  vec a(N),b(N);
  rep(i,N){
    cin>>a[i]>>b[i];
    f&=a[i]==b[i];
    ans+=a[i];
  }
  if(f){
    print(0);
    return 0;
  }
  f=inf;
  rep(i,N)if(a[i]>b[i])chmin(f,b[i]);
  print(ans-f);
  return 0;
}

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

typedef long long ll;

const int N = 1e5 + 5;

int main()
{
    #ifdef TooLazy
        freopen("in.txt", "r", stdin);
    #endif // TooLazy

    string s;
    cin >> s;
    string ans = "";
    int n = s.size();
    for(int i=0; i<n; i++) {
        if( i % 2 == 0 ) {
            ans += s[i];
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 512
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def f():
    s = input()
    r = 0
    tt = ['g','p']
    t = 'g'
    i = 0
    for c in s:
        if c != t:
            if t == 'p':
                r += 1
            else:
                r -=1
        i += 1
        t = tt[i%2]
    return r

print(f())


Measured memory_bytes: 7840
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

char table[] = {'M', 'A', 'R', 'C', 'H'};

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];

    map<char, int> mp;

    rep(i, n) {
        char c = s[i][0];
        mp[c]++;
    }

    lint res = 0;

    rep(i, 5) {
        for (int j = i+1; j < 5; j++) {
            for (int k = j+1; k < 5; k++) {
                lint t = 1;
                t *= mp[table[i]];
                t *= mp[table[j]];
                t *= mp[table[k]];
                res += t;
            }
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6144
/* atcoder */
#include "bits/stdc++.h"
using namespace std;

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<vector<int>> vvi;           // intの2次元vector
typedef vector<vector<double>> vvd;        // doubleの2次元vector
typedef vector<vector<ll>> vvll;           // llの2次元vector
typedef vector<vector<ld>> vvld;           // ldの2次元vector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* stringstream */
stringstream ss;
stringstream init_ss; // save default formatting

/* main */
void Main(void)
{
    int m, f, c;
    while (true)
    {
        cin >> m >> f >> c;
        int score = m + f;
        if (m == -1 && f == -1)
        {
            return;
        }
        else if (m == -1 || f == -1)
        {
            cout << 'F' << endl;
            continue;
        }
        else if (80 <= score)
        {
            cout << 'A' << endl;
            continue;
        }
        else if (65 <= score && score < 80)
        {
            cout << 'B' << endl;
            continue;
        }
        else if (50 <= score && score < 65)
        {
            cout << 'C' << endl;
            continue;
        }
        else if (30 <= score && score < 50)
        {
            if (c < 50)
            {
                cout << 'D' << endl;
                continue;
            }
            else
            {
                cout << 'C' << endl;
                continue;
            }
        }
        else
        {
            cout << 'F' << endl;
            continue;
        }
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}



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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())

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


////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin>>n>>m;
	if(n>m) cout<<"safe"<<endl;
	else cout<<"unsafe"<<endl;
}

Measured memory_bytes: 3648
N = int(input())
A = [int(i) for i in input().split()]
col = [0] * 8
red = 0
minn = 0
maxx = 0

for i in A:
    if i <= 399:
        col[0] = 1
    elif i <= 799:
        col[1] = 1
    elif i <= 1199:
        col[2] = 1
    elif i <= 1599:
        col[3] = 1
    elif i <= 1999:
        col[4] = 1
    elif i <= 2399:
        col[5] = 1
    elif i <= 2799:
        col[6] = 1
    elif i <= 3199:
        col[7] = 1
    else:
        red += 1
if red == 0:
    minn = sum(col)
    maxx = sum(col)
elif red >= 1 and sum(col) == 0:
    minn = 1
    maxx = red
else:
    minn = sum(col)
    maxx = sum(col)+red

print(minn, maxx)

Measured memory_bytes: 3064
n = int(raw_input())
N = 100
WHITE = 0
GRAY = 1
BLACK = 2
Color = [WHITE for i in range(n)]
#M = [[0 for i in range(N)] for j in range(N)]
tt = 0
d = [0 for i in range(n)]
f = [0 for i in range(n)]
def dfs_visit(u):
    Color[u] = GRAY
    global tt
    tt += 1
    d[u] = tt
    for v in range(n):
        if M[u][v] == 0:
            continue
        if Color[v] == WHITE:
            dfs_visit(v)
    Color[u] = BLACK 
    tt += 1
    f[u] = tt
 
def dfs():
    #Color = [WHITE for i in range(n)]
    tt = 0
     
    for u in range(n):
        if Color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])
 
M = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
    tmp = map(int, raw_input().split())
    u = tmp[0]
    k = tmp[1]
    u -= 1
    for j in range(k):
        v = tmp[j + 2]
        v -= 1
        M[u][v] = 1
dfs()

Measured memory_bytes: 6604
#include<stdio.h>

int main(){
    int n, a, b;
    int s, t;
    scanf("%d %d %d", &n, &a, &b);
    s = n * a;
    if(s < b){
        printf("%d\n", s);
    }else
    {
        printf("%d\n", b);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int dp[11][1000];
int main(){
	int n,s;
	int d[10];
	rep(i,1<<10){
		int c = 0;
		rep(j,10)if(i&(1<<j))d[c++] = j;	
		do{
			int r = 0;
			rep(j,c) r += (d[j])*(j+1);
			dp[c][r]++;
		}while(next_permutation(d,d+c));
	}
	while(cin >> n >> s){
		int ans = 0;
		if(s >= 0 && s < 1000 && n <= 10 && n > 0) ans = dp[n][s];
		cout << ans << endl;
	}
}

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

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

    int N, X; cin >> N >> X;

    int sum = 0;
    int i = 0;
    for (i = 0; i < N; i++) {
        int L; cin >> L;
        if (sum + L <= X) sum += L;
        else break;
    }

    cout << i + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		//数取得
		int N = sc.nextInt();
		sc.close();

		String answer = "No";

		for(int i = 1; i <= 9; i++) {
			for(int j = 0; j <= 9; j++) {
				if(i * j == N) {
					answer = "Yes";
				}
			}
		}

		System.out.println(answer);

	}

}


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

using namespace std;

using ll = long long;

int main(){
  ll n;
  vector <ll> d;
  cin >> n;
  cin.ignore();
  ll temp;
  for(ll i = 0; i < n; i++){
    cin >> temp;
    d.push_back(temp);
  }
  cin.ignore();

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

  // d[n/2] と d[n/2 - 1]の差

  cout << d[n/2] -  d[n/2 - 1] << endl;
  return 0;
}


Measured memory_bytes: 1400
x = int(input())

num = x / 100

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

for i in range(1, x + 1):
    if i <= 99:
        dp[i] = 0
    elif i in (100, 101, 102, 103, 104, 105):
        dp[i] = 1
    else:
        if 1 in (dp[i - 100], dp[i - 101], dp[i - 102], dp[i - 103], dp[i - 104], dp[i - 105]):
            dp[i] = 1
        else:
            dp[i] = 0

print dp[x]


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

using namespace std;

#define DEBUG 0
#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define ZERO 0
#define ONE  1

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

	lli data[2]={0};
	REP(i,str.size()){
		data[str.at(i)-'0']++;
	}
	cout << min(data[0],data[1])*2<<endl;

	return 0;
}


Measured memory_bytes: 512
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as C8

type Pair = (Int, Int)

main :: IO ()
main = do
  [n,m] <- readInts
  ps <- sortOn fst <$> replicateM n readPair
  print $ solve 0 m ps


solve :: Int -> Int -> [Pair] -> Int
solve _ _ [] = 0
solve !n m ((a,b):ps)
    | n == m    = 0
    | c > m     = a*(m-n)
    | otherwise = a*b + solve (n+b) m ps
  where
    c = n+b

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readPair :: IO Pair
readPair = do
  [x,y] <- readInts
  return (x,y)

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    REP(i, n) cin >> h[i];

    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for(int i=2; i<n; i++) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#![allow(unused_imports)]
#![allow(unused_macros)]
// use proconio::input;
use std::cmp::{Ordering::*, Reverse};
use std::collections::{BTreeMap, BTreeSet};
use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};

// I have no idea what I'm doing

macro_rules! answer {
    ($out:ident, $ans:expr) => {
        writeln!($out, "{}", $ans)
    };
}

fn main() -> Result<(), io::Error> {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let (n, m) = scan.pair::<i32>();

    answer!(out, (n == m).yes())
}

///////////////////////////////////////////////////////////////////////////////////////////////////

/// Mostly copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse [Scanner]");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}

// aka #![feature(bool_to_option)]
trait BoolThen {
    fn then_<T>(self, f: impl FnOnce() -> T) -> Option<T>;
}

impl BoolThen for bool {
    fn then_<T>(self, f: impl FnOnce() -> T) -> Option<T> {
        if self {
            Some(f())
        } else {
            None
        }
    }
}

trait BoolToYes {
    fn yes(self) -> &'static str;
}

impl BoolToYes for bool {
    fn yes(self) -> &'static str {
        match self {
            true => "Yes",
            false => "No",
        }
    }
}


Measured memory_bytes: 2064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;


int main(void){
	long long n,m,ai,a;
	cin >> n >> m;
	map<long long,long long> mp{};

	cin >> a;
	mp[a%m]++;
	for(int i = 1; i < n; ++i){
		cin >> ai;
		a += ai;
		mp[a %= m]++;
	}
	
	long long ans = 0;
	for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
		ans += itr->second * (itr->second - 1) / 2;
		if(itr->first==0){
			ans += itr->second;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <cstdlib>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc122_2(vector<vector<string>> v) {

    string s = v[0][0];

    int cnt = 0;
    int maxdata = 0;

    for (auto v : s) {

        if (v == 'A' || v == 'G' || v == 'C' || v == 'T') {

            cnt += 1;

        } else {

            maxdata = max(maxdata, cnt);
            cnt = 0;

        }
    }

    maxdata = max(maxdata, cnt);

    cout << maxdata << endl;




}

int main() {

    vector<vector < string>> vec_arr_result;
    //    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata();

    abc122_2(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


Measured memory_bytes: 256
#include <iostream>

struct Dice{
    int top, S, E, W, N, bottom;    
    void Set(int *Input);
    void Roll_N();
    void Roll_W();
    void Roll_S();
    void Roll_E();
    void Roll_clockwise();
    int Out_Right(int topface, int front);
};
void Dice::Set(int *Input)
{
    top = Input[0];
    S = Input[1];
    E = Input[2];
    W = Input[3];
    N = Input[4];
    bottom = Input[5];
}

void Dice::Roll_S()
{
    int temp;
    temp = top;
    top = N;
    N = bottom;
    bottom = S;
    S = temp;
}

void Dice::Roll_E()
{
    int temp;
    temp = top;
    top = W;
    W = bottom;
    bottom = E;
    E = temp;
}

void Dice::Roll_N()
{
    int temp;
    temp = top;
    top = S;
    S = bottom;
    bottom = N;
    N = temp;
}

void Dice::Roll_W()
{
    int temp;
    temp = top;
    top = E;
    E = bottom;
    bottom = W;
    W = temp;
}

void Dice::Roll_clockwise()
{
    int temp;
    temp = W;
    W = N;
    N = E;
    E = S;
    S = temp;
}

int Dice::Out_Right(int topface, int front)
{
    int right;   
    //Adjust topface 
    if(bottom == topface){
        Roll_N();
        Roll_N();
    }else if(S == topface){
        Roll_N();
    }else if(E == topface){
        Roll_W();
    }else if(N == topface){
        Roll_S();
    }else if(W == topface){
        Roll_E();
    }
    if(top != topface)
        return -1;
    
    //Adjust front face
    if (E == front)
    {
        Roll_clockwise();
        Roll_clockwise();
        Roll_clockwise();
        
    }
    else if (N == front)
    {
        Roll_clockwise();
        Roll_clockwise();
    }
    else if (W == front)
    {
        Roll_clockwise();        
    }
    if (S != front)
        return -1;
    
    return E;
}

int main(){
    int Input[6], num;
    int topface, front;
    Dice Dice1;
    char command[100];
    //std::string command;
    for (int i = 0; i < 6; i++)
        std::cin >> Input[i];
    Dice1.Set(Input);

    std::cin >> num;    
    for (int i = 0; i < num; i++){
        std::cin >> topface >> front;
        std::cout << Dice1.Out_Right(topface, front) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}



int main(){
    int n;cin >> n;
    
    int t[n+10],x[n+10],y[n+10];
    t[0] = x[0] = y[0] = 0;
    
    rep1(i,n) {
        scanf("%d %d %d",&t[i],&x[i],&y[i]);
        //cin >> t[i] >> x[i] >> y[i];
    }
    bool ans = true;
    for(int i=0; i<n;i++){
        int dt = t[i+1]-t[i];
        int dx = abs(x[i+1]-x[i]);
        int dy = abs(y[i+1]-y[i]);
        
        if(dt < dx+dy or dt%2 != (dx+dy)%2) {
            ans = false;
            break;
        }
    }
    
    cout << yn(ans) << endl;
}



Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int A,B,C;
    scanf("%d %d %d\n",&A,&B,&C);

    printf("%d\n",max(C-(A-B),0));
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<pair<int,int>> num(N);
	for(int i=0;i<N;i++){
		int x;
		cin >> x;
		num[i] = make_pair(x,i);
		}
	sort(num.begin(),num.end());
	int med[N+1];
	for(int i=0;i<=(N-1)/2;i++){
		med[num[i].second] = num[N/2].first;
	}
	for(int i=N/2;i<N;i++){
		med[num[i].second] = num[(N-1)/2].first;
	}
	for(int i=0;i<N;i++){
		cout << med[i] << "\n";
	}
	return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n, k;
	cin>>n>>k;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	for(int i=k; i<n; i++){
		if(arr[i]>arr[i-k]){
			cout<<"Yes"<<"\n";
		}
		else{
			cout<<"No"<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 4404
import sys
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N = int(readline())
S,T = read().decode('utf-8').rstrip().split()
 
ans = []
 
for i in range(N):
  ans.append(S[i])
  ans.append(T[i])


print(''.join(ans))

Measured memory_bytes: 3060
<?php
  $s = fgets(STDIN);
  $a = intval(substr($s,0,3));
  $b = intval(substr($s,1,3));
	if($a % 111 == 0 || $b % 111 == 0){
    	echo "Yes";
    }else{
      	echo "No";
    }
?>

Measured memory_bytes: 3700
import sys
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

def main():
    N = int(input())
    """
    (u, v)での数え上げを(a, b)への数え上げにすり替えることができる。
    (a, b)->(u, v)の対応は単射ではないが、実は
        「a, bのどれかのビットが(0, 1), (1, 0)で入れ替わっているようなものを同一視」
    することでこの対応は単射になる。(すなわちa + b = c + d, a ^ b = c ^ dは
    a, bの各ビットを一部入れ替えたものがc, dになることに同値)

    なので問題は次のように言い変わる：
        「非負整数a, bでa + b <= Nなるものを数え上げよ。
        　ただしa, bの各ビットは(0, 0), (0, 1), (1, 1)の３パターンに限る。」
    これは桁DPをすれば良いが、単純に上の桁からやると繰り上げ処理が扱えない。

    そこでNよりどれだけ小さいかの情報もdpデーブルに持たせる。
        dp[i][j] = (上から0~i桁目まで見たとき値がN - jであるものの個数)
    これによる遷移はiに応じて異なるものの(jに-0, -2^i, -2^{i+1}のどれかが実行される)
    一応解ける。しかし計算量的にはまだ厳しい。

    そもそも計算量が大きい原因は遷移幅が大きすぎるから。そこでキーの持ち方を
        dp[i][j] = (上から0~i桁目まで見たとき(v >> i) = (N >> i) - j)
    と定める。こうすればNのiビット目とa, bのiビット目を見比べて上とほぼ同様に
    dp計算が可能でかつdpテーブルはだいぶ密になる。さらにdp[i + 1][j]でj >= 2の時は
    a, bのiビット目をどう取っても差が2^i以下に縮まることはないため遷移をまとめることができる。

    気持ちとしては上位ビットから考えるんだけど差分はmod 2^iで考えることで差分を0,1,2以上（繰り上がりケース）
    に限定して、(i+1)->iの遷移時に差分が増加するからそれをa, bのビットを選んで差分を抑制するか増大したまま
    放置するかを考えるイメージ。

    それにしても繰り上がりケースをまとめて考えていいのは数式的には明らかだけど、実際に遷移を考える際には
    妙に偶然感があって不思議な感じ。
    """
    n = bin(N)[2:]
    dp = [1, 1, 0]
    for i, c in enumerate(n):
        if i == 0: continue
        if c == '0':
            # dp[0] = (元々差がなくてiビット目が共に0か、元々差が2^(i+1)あって、iビット目が共に1)
            # dp[1] = (元々差が2^(i+1)あってiビット目が0と1)
            # dp[2] = (元々差が2^(i+1)あってiビット目が共に0か、元々差が2^(i+2)以上ある)
            dp = [dp[0] + dp[1], dp[1], dp[1] + dp[2] * 3]
        else:
            # dp[0] = (元々差がなくてiビット目が0と1)
            # dp[1] = (元々差がなくてiビット目が共に0か、元々差が2^(i+1)あってiビット目は共に1)
            # dp[2] = (元々差が2^(i+1)あってiビット目が0,0か0,1、もしくは元々差が2^(i+2)以上ある)
            dp = [dp[0], dp[0] + dp[1], dp[1] * 2 + dp[2] * 3]
        dp = [dp[0] % mod, dp[1] % mod, dp[2] % mod]
    print(sum(dp) % mod)



if __name__ == "__main__":
    main()


Measured memory_bytes: 62368
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long n, k;
    scan(n, k);
    auto h = new long[](n);
    foreach (i; 0 .. n)
    {
        auto H = lread();
        h[i] = H;
    }
    // writeln(h);
    h.sort();
    long ans = long.max;
    foreach (i; 0 .. ((n - k) + 1))
    {
        // writeln(h[i .. i + k]);
        ans = min(ans, (h[(i + k) - 1] - h[i]));
    }
    writeln(ans);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 5312
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

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

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

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, K;
    string S;
    cin >> N >> S >> K;
    char c = S[K - 1];
    REP(i, N) {
        if (S[i] == c)
            cout << c;
        else
            cout << "*";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int a, b; cin >> a >> b;
	Cout((a + b) / 2);
}


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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _i64 S, h, m, s; cin >> S;
        h = S / pow(60, 2); m = S % (_i64)pow(60, 2) / 60; s = S % 60;
        cout << h << ":" << m << ":" << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3216
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
#define MAX_A 1000000

int main(){


    ll n,x;
    cin >> n >> x;
    vector<ll> a(MAX_A,0);
    REP(n){
        cin >> a[i];
    }
    ll count = 0;
    REP(n-1){

        if(a[i+1]+a[i] > x){
            if(a[i] > x){
                count += abs(a[i]-x);
                a[i] = x;
            }
            
            count += abs(a[i+1]+a[i]-x);
            a[i+1]-= a[i+1]+a[i]-x;
            
        }

    }
    /*REP(n){
        cout << a[i] << endl;
    }*/
    cout << count << endl;


    return 0;
}

Measured memory_bytes: 8064
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    ll n, m; cin >> n >> m;
    ll ans = 0;
    if(n > m) {
        ans = m / 2;
    } else {
        ans = min(m / 2, n + (m - (n * 2)) / 4);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
char s[10];

int main(void) {
	scanf("%s", &s);
	string a = (string)s;
	if (a == "ARC") {
		printf("ABC\n");
	}
	else {
		printf("ARC\n");
	}
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
main()
{
	int n,a[105],sum=0;
	while(~scanf("%d",&n))
	{
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i=i+2)
	{
		if(a[i]%2==1)sum++;
	}
	printf("%d\n",sum);
	sum=0;
	}
}

Measured memory_bytes: 3824
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    a, b, c = map(int, input().split())
    k = int(input())
    i = k+1
    for p in range(i):
        for q in range(i-p):
            for r in range(i-p-q):
                aa, bb, cc = a, b, c
                for k in range(p):
                    aa*=2
                for k in range(q):
                    bb*=2
                for k in range(r):
                    cc*=2
                if aa < bb < cc:
                    print("Yes")
                    exit()
    print("No")
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 10448
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  ll ans = n * (n + 1) - 1;
  for(ll i = 2; i <= n / 2; i++) {
    for(ll j = 2; j * i <= n; j++) {
      ans += j * i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1<<17; // = 131072
const ll INF= 0;

/*dat???????????????N?????????*/

class RMQ{
public:
  ll n;
  vector<ll> dat;

  //?????????
  RMQ(){
    dat.resize(2*N-1);
    n=N;
    for(int i=0;i<n;i++) dat[i]=INF;
  }
  
  //k???????????????a????????´
  void update(int k,ll a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  
  //[a,b)???????°????????±??????? query(a,b,0,0,n)
  ll query(int a,int b,int k=0,int l=0,int r=N){
    if(r<=a||b<=l)return INF;
    if(a<=l&&r<=b)return dat[k];
    ll vl=query(a,b,k*2+1,l,(l+r)/2);
    ll vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
};


/*
  i???????????§????????¨???????????????????????´????????§?????§??????
 */
int main(){
  int n;
  cin>>n;
  vector<int> A(n),Idx(n);
  for(int i=0;i<n;i++)cin>>A[i],Idx[i] = A[i];
  sort(Idx.begin(),Idx.end());

  ll ans = INF;
  RMQ rmq;
  for(int i=0;i<n;i++){
    int idx = lower_bound(Idx.begin(),Idx.end(),A[i]) - Idx.begin();
    ll val = rmq.query(0,idx);
    rmq.update(idx,val-1);
    ans = min(ans,val-1);
  }
  cout<<-ans<<endl;
  return 0;
}

Measured memory_bytes: 5708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long double PI = acos(-1);

int main() {
  cout << fixed << setprecision(20);
  long double A,B,H,M;
  cin >> A >> B >> H >> M;
  long double RA = ((H * 60 + M) / 2);
  long double TA = RA * (PI / 180);
  long double AX = A * sin(TA);
  long double AY = A * cos(TA);
  long double RB = M * 6;
  long double TB = RB * (PI / 180); 
  long double BX = B * sin(TB);
  long double BY = B * cos(TB);
  cout << sqrt((AX-BX) * (AX-BX) + (AY-BY) * (AY-BY)) << endl;
}

Measured memory_bytes: 4172
import sys
readline = sys.stdin.readline

S = readline().rstrip()
T = readline().rstrip()

if len(set(T) - set(S)) > 0:
  print(-1)
  exit(0)
  
import bisect
S2 = S * 2
from collections import defaultdict
dic = defaultdict(list)

for i in range(len(S2)):
  dic[S2[i]] += [i]

ind = -1
ans = 0
for t in T:
  targets = dic[t]
  newind = targets[bisect.bisect_left(targets, ind + 1)]
  ans += (newind - ind)
  if newind >= len(S):
    newind -= len(S)
  ind = newind

print(ans)

Measured memory_bytes: 12272
// B - Robot Arms
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<pair<long long, long long> > a(n);
	for (int i = 0; i < n; i++) {
		long long x, l;
		cin >> x >> l;
		a[i] = make_pair(x - l, x + l);
	}
	sort(a.begin(), a.end());
	long long count = 0, r = a[0].second;
	for (int i = 1; i < n; i++)
		if (a[i].first >= r) {
			r = a[i].second;
		} else {
			count++;
			r = min(r, a[i].second);
		}

	cout << (n - count) << endl;

	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << min({a+b,b+c,c+a}) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

bool isPrime(ll a){
	if(a == 1) return 0;
	if(a == 2) return 1;
	for(ll i = 2; i * i <= a; i++){
		if(a % i == 0) return 0;
	}
	return 1;
}

signed main(){
	ll n;
	cin >> n;
	
	if(isPrime(n)) return cout << n - 1, 0;
	ll min_dist = (ll)(1e18 + 7);
	
	for(int i = 2; i < 1000100; i++){
		if(n % i == 0){
			min_dist = min(min_dist, i + n/i);
		}
	}
	
	cout << min_dist - 2;
	
	return 0;
}

Measured memory_bytes: 256
data = STDIN.gets.split(" ").map do |x| x.to_i end
#p data
x = data[0]
y = data[1]

for i in 0..x do
  if (i*2+(x-i)*4 == y) then
#    printf("%d*2 + %d*4 = %d\n", i, x-i, y)
    puts("Yes")
    exit
  end
end
puts("No")

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

vector<int> d(100), f(100), color(100);
vector<vector<int> > adj(100);
int n, m, t;
bool has_loop;

#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs(int i)
{
	if(has_loop) return;
	color[i] = GRAY;
	d[i] = ++t;
	for(int j = 0; j < adj[i].size(); j++){
		if(color[adj[i][j]] == GRAY){ has_loop = true; break; }
		if(color[adj[i][j]] == WHITE){
			dfs(adj[i][j]);
		}
	}
	if(has_loop) return;
	color[i] = BLACK;
	f[i] = ++t;
}

int main()
{
	scanf("%d %d", &n, &m);
	int i, s, t;
	for(i = 0; i < m; i++){
		scanf("%d %d", &s, &t);
		adj[s].push_back(t);
	}
	for(i = 0; i < n; i++){ color[i] = WHITE; }

	t = 0;
	has_loop = false;
	for(i = 0; i < n; i++){ if(color[i] == WHITE){ dfs(i); } if(has_loop) break; }

	(has_loop ? printf("1\n") : printf("0\n"));

	return 0;
}

Measured memory_bytes: 1200