akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

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

const long long inf = 1LL << 60;

int N,W;
long long dp[110][100010];

int main(){
  cin >> N >> W;
  vector<int> w(N),v(N);
  for(int i=0;i<N;++i){
    cin >> w[i] >> v[i];
  }
  for(int i=0;i<=W;++i){
    dp[0][i]=0;
  }
  for(int i=0;i<N;++i){
    for(int j=0;j<=W;++j){
      if(j>=w[i])dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 80128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		long s = sc.nextLong();//s
		long c = sc.nextLong();//c
		//s+2c = scc
		if(2*s >= c) {
			System.out.println(c/2);
		} else {//2s < c
			long ans = s;
			c -= 2*s;
			s = 0;
			ans += c/4L;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int a[100001] = { 0 };

int main(void) {
	int N;
	int i, ans = 0;

	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &a[i]);

	for (i = 1; i <= N; i++) {
		if (a[a[i]]==i) {
			ans++;
			a[a[i]] = 0;
		}
	}

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

	return 0;
}

Measured memory_bytes: 512
loop do
  h, w = gets.split.map(&:to_i)
  break if h == 0 && w == 0
  (1..h).each do |y|
    line = '#.' * w
    line =
    if y.odd?
      line[0..w - 1]
    else
      line[1..w]
    end
    puts line
  end
  puts
end

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

void print_threeish_nats_upto(int n) {
    int i = 1;
    do {
        int x = i;

        if (x % 3 == 0) {
            cout << " "  << i;
            continue;
        }
        do {
            if (x % 10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        } while (x);
    } while (++i <= n);
    cout << endl;
}

int main()
{
    int n ;
    cin >> n;
    print_threeish_nats_upto(n);
}

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

vector<int> graph[100010];

int main(){
  int n, m, k, s;
  int p, q;
  cin >> n >> m >> k >> s;
  cin >> p >> q;

  bool den[100010] = {};

  int t;
  queue<pair<int, int> > denque;
  for(int i = 0;i < k;i++){
    cin >> t;
    t--;
    den[t] = true;
    denque.push(make_pair(t,s));
  }

  int a, b;
  for(int i = 0;i < m;i++){
    cin >> a >> b;
    a--; b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  int money[100010];
  for(int i = 0;i < n;i++) money[i] = p;

  int tmp[100010];
  memset(tmp,-1,sizeof(tmp));
  pair<int, int> tm;
  while(!denque.empty()){
    tm = denque.front();
    denque.pop();
    if(tmp[tm.first] != -1) continue;

    money[tm.first] = q;
    tmp[tm.first] = tm.second;
    tm.second--;
    if(tm.second != -1){
      for(int i = 0;i < graph[tm.first].size();i++){
        denque.push(make_pair(graph[tm.first][i],tm.second));
      }
    }
  }

  long long v[100010] = {};
  for(int i = 0;i < n;i++) v[i] = LLONG_MAX;
  v[0] = 0;

  priority_queue<pair<int, long long>, vector<pair<int, long long> >, greater<pair<int, long long> > > que;

  que.push(make_pair(0, 0));

  pair<int, long long> tg;
  while(!que.empty()){
    tg = que.top();
    que.pop();
    for(int i = 0;i < graph[tg.first].size();i++){
      if(!den[graph[tg.first][i]]){
        if(v[graph[tg.first][i]] > tg.second + money[graph[tg.first][i]]){
          v[graph[tg.first][i]] = tg.second + money[graph[tg.first][i]];
          que.push(make_pair(graph[tg.first][i], v[graph[tg.first][i]]));
        }
      }
    }
  }

  cout << v[n-1]-money[n-1] << endl;

  return 0;
}






Measured memory_bytes: 11612
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int f[10*maxn]={0};
int pre[10*maxn]={0};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,res=0;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;++i)
    {
    	cin>>a[i];
    	++f[a[i]];
    }
    for(int i=1;i<10*maxn;++i)
    {
    	for(int j=i;j<10*maxn;j+=i)
    		pre[j]+=f[i];
    }
    for(int i=0;i<n;++i)
    	if(pre[a[i]]==1)
    		++res;
    cout<<res<<endl;
}

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

int main(void) {
   char a[7];
   char b[4];
   int i = 0;
   int j = 0;
   int num;

   scanf("%s%s", a, b);

   while ('\0' != a[i]) {
       i++;
   }
   while ('\0' != b[j]) {
       a[i] = b[j];
       i++;
       j++;
   }

    num = atoi(a);
    for (i = 0; num/2 > i; i++) {
        if (num == i*i) {
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cout << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();    
    return 0;   
}
 
const int MOD = 1e9 + 7, MAXN = 5e5 + 10, INF = 2e9 + 10, BASE = 37; 

void solve() {
    int n;
    cin >> n;
    vec<int> cnt(n + 1);
    for (int x = 1; x <= 100; ++x) {
        for (int y = 1; y <= 100; ++y) {
            for (int z = 1; z <= 100; ++z) {
                int val = x * x + y * y + z * z + x * z + x * y + z * y;
                if (val <= n) {
                    cnt[val]++;
                }
            }
        }
    }

    for (int i = 1; i <= n; ++i) {
        cout << cnt[i] << endl;
    }
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = "";
            var array = new int[2];
            while (!string.IsNullOrEmpty(read = Console.ReadLine()))
            {
                array = read.Split().Select(s => int.Parse(s)).ToArray();
                var intVal = array[0] / array[1];
                var remVal = array[0] % array[1];
                var floatVal = ((double)array[0] / array[1]).ToString("F8");

                Console.WriteLine($"{intVal} {remVal} {floatVal}");
            }

        }
    }
}



Measured memory_bytes: 18480
#include <bits/stdc++.h>
#include <queue>
#include <string>
#include <algorithm>

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)

typedef long long ll;
const ll MOD = 1000000007; // 10^9+7
const ll INF = 10000000000;

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

    ll r=0,g=0,b=0;
    rep(i,n){
        if(s[i] == 'R') r++;
        if(s[i] == 'G') g++;
        if(s[i] == 'B') b++;
    }

    ll cnt = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(2*j-i >= n) continue;
            if(s[i] != s[j] && s[j] != s[2*j-i] && s[2*j-i] != s[i]) cnt++;
        }
    }

    cout << r*g*b - cnt << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    int a, b, h;
    cin >> a >> b >> h;

    cout << (a+b)*h/2 << endl;

    return 0;
}

Measured memory_bytes: 3612
#こういう問題で実際に動かすやつはあほ、普通にチェンジするとこまで行って、どっちか(偶数だけ離れてるとこ)に集まるやろ
s=input()
n=len(s)
#変わる点というより変わる点にくる集まりを考えるべき
d=0
a=[]
ax=[0]

for i in range(n):
    l=len(ax)
    if l==1:
        if s[i]=="L":
            ax.append(i-1)
            ax.append(i)
        if i==n-1:
            ax.append(i)
            a.append(ax)
    elif l==3:
        if s[i]=="R":
            ax.append(i-1)
            a.append(ax)
            ax=[i]
        elif i==n-1:
            ax.append(i)
            a.append(ax)
m=len(a)
c=[0]*n
for i in range(m):
    #print(type(a[i][1]))
    #print(type(c[a[i][1]]))
    c[a[i][1]]=(a[i][1]-a[i][0])//2+(a[i][3]-a[i][1])//2+1
    c[a[i][2]]=(a[i][2]-a[i][0])//2+(a[i][3]-a[i][2])//2+1

print(" ".join(list(map(str,c))))


Measured memory_bytes: 22796
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 200000;

char x[26];

int main() {
	string s,t;cin>>s>>t;
	bool ans=true;
	rep(i,26) x[i]=0;
	rep(i,s.size()){
		if(x[t[i]-'a']==0) x[t[i]-'a']=s[i];
		else if(x[t[i]-'a']!=s[i]) ans=false;
		if(!ans) break;
	}
	rep(i,26) x[i]=0;
	rep(i,s.size()){
		if(x[s[i]-'a']==0) x[s[i]-'a']=t[i];
		else if(x[s[i]-'a']!=t[i]) ans=false;
		if(!ans) break;
	}

	if(ans) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n;
		n = sc.next();
		char ans[];
		ans = new char[n.length()];

		for (int i = 0; i < n.length(); ++i) {
			if (n.charAt(i) == '1') {
				ans[i] = '9';
			} else if (n.charAt(i) == '9') {
				ans[i] = '1';
			}
		}

		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 22868
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		//65~90 A~Z
		int N = scan.nextInt();
		String S = scan.next();
		
		StringBuilder sb = new StringBuilder();
		char[] charArray = S.toCharArray();
		for(char c: charArray) {
			int targetIndex = c + N;
			if(targetIndex > 90) {
				targetIndex -= 26;
			}
			char changedChar = (char)targetIndex;
			sb.append(changedChar);
		}
		
		System.out.println(sb);
		scan.close();
	}
}




Measured memory_bytes: 23892
l,r=map(int,input().split())
MOD= 2019 
if r-l>=2018:
    print(0)
    exit()
else:
    ltemp=l%MOD
    rtemp=r-l+ltemp
    ans=2019 
    for i in range(ltemp,rtemp):
        for j in range(i+1,rtemp+1):
            ans=min(ans,i*j%MOD)
    print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long

/*
3 100
1 2
2 3
*/
vector<vector<ll> >adjlist;
vector<ll>dp2asroot;
vector<ll>dp1nonroot;
ll m;

void solve1(ll node,ll par){
    ll sz = adjlist[node].size();
    ll w=1;
    for(ll i=0;i<sz;i++){
        ll u = adjlist[node][i];
        if(u!=par){
            solve1(u,node);
            w *= (dp1nonroot[u]+1)%m;
            w %=m;
        }
    }
    dp1nonroot[node] = w;
}
void solve2(ll node,ll par_val,ll par){
    ll sz = adjlist[node].size();
    ll w=1;
    w = (dp1nonroot[node]*((1+par_val)%m))%m;
    dp2asroot[node] = w;
    vector<ll>chld;
    for(ll i=0;i<sz;i++){
        if(adjlist[node][i]==par){
            continue;
        }
        chld.push_back(adjlist[node][i]);
    }
    sz = chld.size();
    vector<ll>prefix(sz,1),suffix(sz,1);
    for(ll i=1;i<sz;i++){
        prefix[i] = (prefix[i-1]*((dp1nonroot[chld[i-1]]+1)%m))%m;
    }
    for(ll i=sz-2;i>=0;i--){
        suffix[i] = (suffix[i+1]*((dp1nonroot[chld[i+1]]+1)%m))%m;
    }

    for(ll i=0;i<sz;i++){
        ll u = chld[i];
        ll pv = (((prefix[i]*suffix[i])%m)*((par_val +1)%m))%m;
        solve2(u,pv,node);
    }
    return;
}

void solve(){
  ll n;cin>>n>>m;
  adjlist.resize(n);
  dp1nonroot.resize(n,-1);
  dp2asroot.resize(n,-1);
  for(ll i=0;i<n-1;i++){
    ll a,b;cin>>a>>b;
    adjlist[a-1].push_back(b-1);
    adjlist[b-1].push_back(a-1);
  }
  solve1(0,-1);
  solve2(0,0,-1);
    for(ll i=0;i<n;i++){
        cout<< dp2asroot[i]<<"\n";
    }
}

int main(){
//    cin.tie(0);
//    cout.tie(0);
//    cin.sync_with_stdio(0);
//    cout.sync_with_stdio(0);

    cout.precision(10);
    int t=1;//cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


Measured memory_bytes: 23040
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int n,T,s,dp[3001],t[3000],v[3000],a;

int main(){
	scanf("%d%d%d",&n,&T,&s);
	rep(i,n) scanf("%d%d",&v[i],&t[i]);
	rep(i,n){
		for(int j = T; j >= 0; j--){
			if((j<s&&j+t[i]>s)||j+t[i]>T)continue;
			dp[j+t[i]]=max(dp[j+t[i]],dp[j]+v[i]);
		}
	}
	rep(i,T+1)a=max(a,dp[i]);
	printf("%d\n",a);
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int n;
string s;
int dp[500500];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> n >> s;

  memset(dp, 0, sizeof(dp));
  reps(i, 1, n-1) {
    chmax(dp[i], dp[i-1]);
    if(s[i-1] != '1' || s[i] != '0' || s[i+1] != '1') continue;
    if(i+2 <= n) {
      int cnt = 0;
      for(int j = i-1; j >= 0; j--) {
	if(s[j] != '1') break;
	cnt++;
	chmax(dp[i+2], dp[j]+cnt);
      }
    }
    if(i-1 >= 0) {
      int cnt = 0;
      for(int j = i+1; j+1 <= n; j++) {
	if(s[j] != '1') break;
	cnt++;
	chmax(dp[j+1], dp[i-1]+cnt);
      }
    }
  }
  int ans = 0;
  rep(i, n+1) chmax(ans, dp[i]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4764
MOD=10**9+7
N=int(input())
alist=list(map(int,input().split()))
#print(alist)

blist=[0]*60
for a in alist:
  bblist=[]
  while a:
    bblist.append(a%2)
    a//=2
    
  #print(bblist)
  for i in range(len(bblist)):
    blist[i]+=bblist[i]
      
#print(blist)
answer=0
pow2=1
for i in range(60):
  answer+=blist[i]*(N-blist[i])*pow2
  answer%=MOD
  pow2=2*pow2%MOD
  
print(answer)

Measured memory_bytes: 122936
# -*- coding: utf-8 -*-
from collections import defaultdict
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

H, W = inpl()
if (min(H, W) == 1):
    print(1)
elif (H%2 == 0):
    print(H*W//2)
else:
    print(H*(W//2) + -(-H//2)*(W%2))

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

int insertionSort(int num[100], int N)
{
	int count = 0;
	for (int i = 0; i < N; i++)
	{
		int min = i;
		for (int j = i + 1; j < N; j++)
		{
			if (num[j] < num[min])
			{
				min = j;
			}
		}
		if (min != i)
		{
			swap(num[min], num[i]);
			count++;
		}
	}
	return count;
}

int main(void)
{
	int N,num[100];
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> num[i];
	}
	int count = insertionSort(num, N);

	for (int i = 0; i < N; i++)
	{
		cout << num[i];
		if (i != N - 1)
		{
			cout << " ";
		}
	}
	cout << endl << count << endl;

	return 0;
}

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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main(){
    int N; cin >> N;
    vector<ll> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H.at(i);
    }
    string ans = "Yes";
    for (int i = N - 2; i >= 0; i--) {
        if (H.at(i) <= H.at(i + 1)) {
        }
        else if (H.at(i) == H.at(i + 1) + 1) {
            H.at(i)--;
        }
        else {
            ans = "No";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1152
#pragma GCC optimize("Ofast") // enable all O3 optimizations
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int k;
    cin >> k;
    int64_t res = 0;
    for (int i = 1; i <= k; ++i) {
    	for (int j = 1; j <= k; ++j) {
    		for (int x = 1; x <= k; ++x) {
    			res += __gcd(i, __gcd(j, x));
    		}
    	}
    }
    cout << res << '\n';
}

Measured memory_bytes: 3644
/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';

using namespace std;

void solve(){
	int i,j;
	int n;cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}

	ll ans=0;
	int mx=a[0];

	for (int i = 1; i < n; ++i)
	{
		ans+=max(0,mx-a[i]);
		mx=max(mx,a[i]);
	}

	printf("%lld\n",ans);
}


int main(){
	// ios_base::sync_with_stdio(false);
 //    cin.tie(0);
    
	int T=1;
	// cin >> T;
	while (T--){
		solve();
	}
}


Measured memory_bytes: 4056
#include <iostream>
#define mod 1000000007
using namespace std;
typedef long long ll;

int main() {
    ll n,m; cin >> n >> m;
    ll ans = 1;
    while(m) {
        if((m&1)==1) ans = ((ans % mod) * (n % mod)) % mod;
        m >>= 1;
        n = ((n % mod) * (n % mod)) % mod;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    ll N,K; cin >> N >> K;

    if(N%K==0){
        cout << 0 << endl;
        return 0;
    }else{
        if(N>K){
            ll res = N / K;
            N = N - res * K;
            //cout << "res= " << res << " N= " << N << " " << K << endl;
        }
        //cout << "N=" << N << " K= " << K << endl; 

        cout << min(min(abs(N-K), abs(K-N)), N) << endl;

    }
    
    return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    height = LI()
    ans = 0
    cnt = 0
    mn = height[0]

    for h in height[1:]:
        if mn>=h:
            cnt += 1
            mn = h
            ans = max(ans, cnt)
        else:
            cnt = 0
            mn = h

    print(ans)
main()


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

# 0-indexでやる

D = int(readline())
C = list(map(int,readline().split())) # 満足度の下がりやすさ
S = [None] * D
sortS = [None] * D
for i in range(D):
  s = list(map(int,readline().split()))
  S[i] = s.copy()
  for j in range(len(s)):
    s[j] = (s[j],j)
  sortS[i] = sorted(s, key = lambda x:x[0], reverse = True)

def make_ans(D,C,limiter = 4, threshold = 2, balance = 0.5):
  ans = []
  last_submit = [0] * 26
  for i in range(D):
    info = sortS[i]
    
    # limiter回以上提出がないものがあれば、threshold回を超えたもののうちCの値が高いものを提出
    if i - min(last_submit) >= limiter:
      ind = -1
      for j in range(len(last_submit)):
        if i - last_submit[j] >= threshold:
          if ind == -1:
            ind = j
          else:
            if C[ind] < C[j]:
              ind = j
      ans += [ind]
      last_submit[ind] = i
      continue
      
    topval = info[0][0]
    for j in range(len(info)):
      val = info[j][0]
      if val < topval * (balance):
        continue # 最高値の半分になるのであればやめよう
      index = info[j][1]
      if i - last_submit[index] < 26:
        continue
      ans += [index]
      last_submit[index] = i
      break
    else:
      ans += [info[0][1]]
  return ans

def calc_score(arr):
  point = 0
  last_submit = [0] * 26
  for i in range(len(arr)):
    # i日目
    point += S[i][arr[i]]
    for j in range(len(last_submit)):
      point -= (i - last_submit[j]) * C[j]
  return point
      
ans = make_ans(D,C)
#print(ans)
best = calc_score(ans)
for limiter in range(36,52):
  for threshold in range(26, limiter):
    for balance in (0.25, 0.5, 0.75):
      new_ans = make_ans(D,C,limiter,threshold,balance)
      new_score = calc_score(new_ans)
      if new_score > best:
        ans = new_ans
        best = new_score
  
def show(arr):
  for a in arr:
    print(a + 1)
    
show(ans)

Measured memory_bytes: 10056
#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)

int main()
{
  string s;
  cin >> s;
  long long res = 0, cnt = 1;
  char last = s[0];
  vector<long> nes;
  rep2(i, 1, s.size() + 1)
  {
    if (s[i] == last)
      cnt++;
    else
    {
      if (last == '>')
        nes.push_back(cnt);
      else
        nes.push_back(cnt * -1);
      last = s[i];
      cnt = 1;
    }
  }
  rep(i, nes.size())
  {
    if (nes[i] >= 0)
      continue;
    else if (i == nes.size() - 1)
      nes[i] = abs(nes[i]);
    else if (abs(nes[i]) <= nes[i + 1])
      nes[i] = abs(nes[i]) - 1;
    else
    {
      nes[i] = abs(nes[i]);
      nes[i + 1] -= 1;
    }
  }
  for (auto n : nes)
  {
    res += n * (n + 1) / 2;
  }
  cout << res << endl;
}

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

using namespace std;

int main() {
	long long a, b, c, counter = 0;
	cin >> a >> b >> c;
	if (a + b == c)cout << "Yes" << endl;
	else if(a + c == b)cout << "Yes" << endl;
	else if(b + c == a)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i, n) for(int i=((int)(n));i>0;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
const long long MOD = 10e9 + 7;
*/
typedef long long ll;

int F(long long A){
	int cnt = 0;
	while(A > 0){
		A /= 10;
		cnt++;
	}
	return cnt;
}

int main(){
	ll N;
	cin >> N;
	int ans = 1000;
	for(int A = sqrt(N); A > 0; A--){
		if(N % A != 0)continue;
		cout << max(F(A), F(N / A)) << endl;
		break;
	}
}

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



int main(){
	int N;
	cin>>N;
	vector<double> p(N);
	for(int i=0;i<N;i++){
		cin>>p[i];
	}
	
	vector<vector<double>> dp(N,vector<double>(N+1,0.0));//dp[i][j] i+1枚中j枚表となる確率
	dp[0][0]=1-p[0];
	dp[0][1]=p[0];
	for(int i=0;i<N;i++){
		for(int j=0;j<=i+1;j++){
			if(i==0)continue;
			dp[i][j]=dp[i-1][j]*(1-p[i]);
			if(j!=0)dp[i][j]+=dp[i-1][j-1]*p[i];
		}
	}
	
	double ans = 0.0;
	for(int i=0;i<N+1;i++){
		if(i*2<N)continue;
		ans += dp[N-1][i];
	}
	
	/*
	for(int i=0;i<N;i++){
		for(int j=0;j<N+1;j++){
			if(j!=0)cout<<' ';
			cout<<dp[i][j];
		}
		cout<<endl;
	}*/
	
	cout<<fixed<<setprecision(15)<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;


int main()
{
	string s;
	cin>>s;
	int sum=0;
	for(int i=0;i<s.size();i++){
		sum+=s[i]-'0';
	}
	if(sum%9==0) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3752
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
#define rep(i, n) for ( int i = 0; i < (int)n; i++)
#define MAX 200
#define INFTY (1<<21)

int N, M, R, L[MAX][MAX], S[MAX][MAX];
vector<int> O;

void floyd(int D[MAX][MAX], int n){
    rep(k, n) rep(i, n){
	if ( D[i][k] == INFTY ) continue;
	rep(j, n){
	    if ( D[k][j] == INFTY ) continue;
	    D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
	}
    }
}

int compute(){
    floyd(L, N);
    floyd(S, N);
    int T[1000][MAX];
    rep(i, O.size()) rep(j, N) T[i][j] = INFTY;
    
    T[0][O[0]] = 0;

    for ( int i = 1; i < R; i++ ){
	for ( int j = 0; j < N; j++ ){
	    T[i][j] = min(T[i][j], T[i-1][j] + L[O[i-1]][O[i]]);
	    //T[i][j] =  T[i-1][j] + L[O[i-1]][O[i]];
	    for ( int k = 0; k < N; k++ ){
		T[i][k] = min(T[i][k], T[i-1][j] + L[O[i-1]][j] + S[j][k] + L[k][O[i]]);
	    }

	}
    }

    int minv = INFTY;
    rep(i, N) minv = min(minv, T[O.size()-1][i]);
    return minv;

}

main(){
    int s, t, c;
    char ch;
    while(cin >> N >> M && N ){
	O.clear();
	rep(i, N) rep(j, N) L[i][j] = S[i][j] = INFTY;
	rep(i, N) L[i][i] = S[i][i] = 0;
	rep(i, M){
	    cin >> s >> t >> c >> ch;
	    s--; t--;
	    if ( ch == 'L' ) L[s][t] = L[t][s] = min(L[s][t], c);
	    else S[s][t] = S[t][s] = min(S[s][t], c);
	}
	cin >> R;
	rep(i, R){
	    cin >> s; s--;
	    O.push_back(s);
	}
	cout << compute() << endl;
    }
}

Measured memory_bytes: 2012
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int n;
int a[100];
int k=0;
int mini;



int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		mini = i;
		for (int j = i; j <= n - 1; j++) {
			if (a[j] < a[mini]) {
				mini = j;
			}
		}
		if (a[i] != a[mini]) {

			swap(a[i], a[mini]);
			k++;
		}
	}
	for (int i = 0; i < n-1; i++) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl << k << endl;
}

Measured memory_bytes: 1160
// atcoder/abc147/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

const lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<lli> a(n);
    cin >> a;

    ull sum = 0;
    for (int i = 0; i < 62; ++i) {
      ull z = 0;
      ull o = 0;
      ull b = 1LL << i;
      each (j, a) {
        if (j & b) ++o;
        else ++z;
      }
      const ull w = b % mod;
      sum += (((z * o) % mod) * w) % mod;
      sum %= mod;
    }
    cout << sum << endl;
  }

  return 0;
}


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


int main() {
    long long n,x,a[100000];
    cin >> n >> x;

    for (int i = 0; i < n; ++i){
        cin >> a[i];
    }

    long long ans=0;
    for (int i = 0; i < n-1; ++i){
            if(a[i]+a[i+1]>x){
                if(a[i]>x){
                    ans+=a[i+1];
                    a[i+1]=0;
                    ans+=a[i]-x;
                }else{
                    ans+=a[i+1]-(x-a[i]);
                    a[i+1]=x-a[i];
                }
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c-(a-b)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int r=0,g=0,b=0;
    for(auto i: s){
        if(i == 'R')r++;
        if(i == 'G')g++;
        if(i == 'B')b++;
    }
    ll ans = 1LL*r*g*b;
    rep(i,n) rep(j,n){
        int k = j+j-i;
        if(j < k && k < n){
            if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int a, b;
	while(1){
		cin >> a >> b;
		if(a == 0 && b == 0)
			break;
		int counter = 0;
		for(int i = 3; i <= a; i++){
			for(int j = 2; j <= i; j++){
				for(int k = 1; k <= j; k++){
					if(i != k && i != j && j != k && i+j+k == b)
						counter++;
				}
			}
		}
		cout << counter << endl;
	}
}


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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int n, a, b, c, d;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	while (n--) {
		string s;
		cin >> s;
		if (s == "AC") a++;
		if (s == "WA") b++;
		if (s == "TLE") c++;
		if (s == "RE") d++;
	}

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

	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

ll n;
ll m;
ll s[200005];
vector<ll> a;

int main() {
  cin >> n >> m;
  rep(i,n){
    int tmp; cin >> tmp;
    a.push_back(tmp);
  }
  sort(a.begin(),a.end());
  ll ok = 0;
  ll ng = 100000 * n + 1;
  while(1<ng-ok){
    ll mid = (ok+ng)/2;
    ll num = 0;
    
    for(int i = n-1; 0 <= i; i--){
      num += a.end() - lower_bound(a.begin(),a.end(), mid - a[i]);
    }
    
    if(m<= num){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  vector<ll> csum(n+1,0LL);
  rep(i,n){
    csum[i+1] = csum[i]+a[i];
  }
  
  ll ans = 0, cnt=0;
  rep(i,n){
    ll v = upper_bound(a.begin(),a.end(), ok - a[i]) - a.begin();
    cnt += n - v;
    ans += a[i] * (n - v) + csum[n] - csum[v];
  }
  
  ans += ok * (m - cnt);
  cout << ans << endl;
  return 0;
  
}


Measured memory_bytes: 2036
import sys


TEST_INPUT = [
    """
    36
    """,
    """
    91
    """,
    """
    314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170
    """
]
ANSWER = [
    "8",
    "3",
    "243"
]


class InputHandler:

    def __init__(self, text_lines="", is_test=False):
        self.data = list(text_lines.split("\n"))
        self.index = 0
        self.is_test = is_test

    def input(self):
        if self.is_test:
            self.index += 1
            return self.data[self.index].strip()
        else:
            return sys.stdin.readline().rstrip()


def solve(n):

    dp = [0, 1]
    for s in n:
        a = int(s)
        dp = [min(dp[0] + a, dp[1] + 10 - a), min(dp[0] + a + 1, dp[1] + 9 - a)]

    return dp[0]


def input_and_solve(ih):
    n = ih.input()
    res = solve(n)
    return res


def main():
    ih = InputHandler()
    res = input_and_solve(ih)
    print(res)


def test():
    for test_input, ans in zip(TEST_INPUT, ANSWER):
        ih = InputHandler(test_input, True)
        res = input_and_solve(ih)
        # print(res, ans)
        assert str(res) == str(ans)


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 5492
using System;    
     
class sample14{    
    static void Main(string[] args){
        
        double r = double.Parse( Console.ReadLine());
        double area = r * r*  Math.PI;
        double around = r * 2* Math.PI;
        
        //バリデーション
        if(r<= 0 || r >= 10000 ){
            
                    Console.WriteLine("入力した値は範囲外です。");
                    Environment.Exit(0);
        } 
            
        Console.WriteLine("{0:f6} {1:f6}",area,around);
    }    
}  



Measured memory_bytes: 17936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int NMAX =1e5 + 10;

struct Node
{
	int a,b,c,d;
}node[55];
int n,m,q;
int ans = 0;
int a[12];
void dfs(int u)
{
	if(u == n)
	{
		int cal = 0;
		for(register int i = 1;i <= q;i++)
			if(a[node[i].b] - a[node[i].a] == node[i].c)
				cal += node[i].d;
		ans = max(ans,cal);
		return;
	}
	for(register int i = max(1,a[u]);i <= m;i++)
		a[u+1] = i,dfs(u+1);
}
int main(int argc, char const *argv[])
{
	
	scanf("%d%d%d",&n,&m,&q);
	for(register int i = 1;i <= q;i++)
		scanf("%d%d%d%d",&node[i].a,&node[i].b,&node[i].c,&node[i].d);
	dfs(0);
	printf("%d\n",ans );
	return 0;
}

Measured memory_bytes: 3836
s = input()
cnt = 1
maxcnt=1
for i in range(1,4):
  if s[i]==s[i-1]:
    cnt += 1
  else:
    maxcnt = max(cnt,maxcnt)
    cnt=1
maxcnt = max(cnt,maxcnt)
if maxcnt>=2:
  print("Bad")
else:
  print("Good")

Measured memory_bytes: 8984
#include <iostream>
#include<algorithm>
#include <vector>
#include<map>
#include<deque>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define max(x,y) (((x)>(y)) ? x:y)
#define min(x,y) (((x)<(y)) ? x:y)
#define FOR(a) for(int i=0;i<a;i++)
#define ender {return 0;}
#define tosasuretu(a) (a*(a+1)/2)
inline ll kaizyo(ll);
ll gcd(ll, ll);
ll combination(ll, ll);
int main() {
	ll n, m;
	cin >> n >> m;
	ll a, b;
	vector<pair<ll, ll>> d;
	FOR(n) {
		cin >> a >> b;
		d.push_back(pair<ll, ll>(a, b));
	}
	sort(d.begin(), d.end(), [](pair<ll,ll> x,pair<ll,ll> y) {
		return x.first < y.first;
	});
	ll check = 0;
	ll total = 0;
	while (true) {
		if (m <= d[check].second) {
			total += (m * d[check].first);
			break;
		}
		else {
			total += (d[check].first*d[check].second);
			m -= d[check].second;
			check++;
		}
	}
	cout << total;
	return 0;
}


inline ll kaizyo(ll x) {
	long ans = 1;
	for (int z = 0; z < x; z++) {
		ans *= (x - z);
	}
	return ans;
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

Measured memory_bytes: 2420
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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(){
  ll N,ans=0;
  cin>>N;
  ll A[N+1],B[N+1],C[N+1];
  REP(i,N+1){
    cin>>A[i];
    B[i]=0;
    C[i]=0;
  }
  bool CAN=true;
  
  if(N==0){
    if(A[0]==1) co(1);
    else co(-1);
    return 0;
  }
  
  B[0]=1;
  for(int i=1; i<=N; ++i){
    B[i]=min((B[i-1]-A[i-1])*2,INF*INF);
    if((B[i]<=A[i]&&i<N)||(B[i]<=0&&i<N)){
      CAN=false;
      break;
    }
  }
  
  C[N]=A[N];
  for(int i=N-1; i>=0; --i){
    C[i]=C[i+1]+A[i];
  }
  
  for(int i=0; i<=N; ++i){
    if(B[i]<C[i]) ans+=B[i];
    else ans+=C[i];
  }
  
  if(A[N]==0) CAN=false;
  if(A[0]>0) CAN=false;
  if(B[N]<A[N]) CAN=false;
  
  
  if(CAN){
    co(ans);
  }
  else co(-1);
  return 0;
}

Measured memory_bytes: 5996
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
signed main(){
  
  string s;
  cin>>s;
  
  int flg = 1;
  
  for(int i=0;i<s.size();i++){
    
    if( i % 2 == 0 && s[i] == 'L' ) flg = 0;
    if( i % 2 == 1 && s[i] == 'R' ) flg = 0;
    
  }
  
  if(flg) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

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

using namespace std;

int main() {
	string s, y="", m="", d="";
	int c = 0;
	cin >> s;


	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '/') {
			c++;
			i++;
		}
		if (c == 0) {
			y += s[i];
		}
		else if (c == 1) {
			m += s[i];
		}
		else {
			d += s[i];
		}
	}

	if (stoi(y) <= 2019 && stoi(m)<=4 && stoi(d)<=30) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int main(void) {
	int n,q,temp;
	cin >> n;
	map<int,bool> memo;
	for (int i = 0; i < n; ++i) {
		cin >> temp;
		memo[temp] = true;
	}
	cin >> q;
	int res = 0;
	for (int i = 0; i < q; ++i) {
		cin >> temp;
		if (memo[temp]) {
			++res;
		}
	}
	cout << res << endl;
	return 0;
}



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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll solve(ll a, ll b, ll c) {
    return abs((a/2)*b*c-(a/2+a%2)*b*c);
}

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a%2==0 or b%2==0 or c%2==0) {
        cout << 0 << endl;
    }
    else {
        ll res = min({solve(a, b, c), solve(b, a, c), solve(c, a, b)});
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

int main() {
  ll n;
  string s;
  string ans = "Yes";
  cin >> n >> s;
  if (n % 2 != 0) ans = "No";
  for (ll i = 0; i < n / 2; i++) {
    if (s.at(i) != s.at(i + n / 2)) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n, a, b = [int(i) for i in input().split()]
mod = 10**9 + 7

total = (2**n - 1) % mod
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

at = combination(n,a)
bt = combination(n,b)

result = total - at - bt
result %= mod
if result < 0:
  result += mod
print(result)

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

int main(void) {
	int w, h, n;
	int x, y, a;
	int ans, xl, xh, yl, yh;

	cin >> w >> h >> n;
	xl = yl = 0;
	xh = w;
	yh = h;

	for (int i = 0; i < n; ++i) {
		cin >> x >> y >> a;
		if (a == 1) {
			if (x > xl)
				xl = x;
		}
		else if (a == 2) {
			if (x < xh)
				xh = x;
		}
		else if (a == 3) {
			if (y > yl)
				yl = y;
		}
		else if (a == 4) {
			if (y < yh)
				yh = y;
		}
	}

	if ((xl >= xh) || (yl >= yh))
		ans = 0;
	else
		ans = (xh - xl) * (yh - yl);

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int

using namespace std;

void solve()
{
  int n,k;
  cin>>n>>k;
  vector<int> v(n+1);
  for(int i=1;i<=n;i++)
    cin>>v[i];
  int i=0;
  int pos=1;
  map<int, int> mp,mp2;
  mp[1]=0;
  mp2[0]=1;
  
  int g=k;
  while(g--)
  {
    int t = v[pos];
    if(mp.find(t)!=mp.end())
      {
        int size = mp.size();
        k++;
        k-=size;
        int j = mp[t];
        int l = i;
        int steps=l-j+1;
        // cout<<j<<" "<<l<<" "<<steps<<endl;
        k%=steps;
        if(k==0)
        {
          cout<<mp2[l]<<endl;
        }
        else
        {
          cout<<mp2[k+j-1]<<endl;
        }
        return;
      }
    mp[t]=++i;
    mp2[i]=t;
    pos=t;
    
  }
  
  cout<<mp2[i]<<endl;





}
signed main()

{
  FAST_IO;
  int t = 1;

  // cin>>t;

  while(t--)
  {
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 24852
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define pb push_back
    #define sz size()
     
    using namespace std;
    using ll = long long int;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using Vl = vector<ll>;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;

//bit全探索
vector<ll>bitSearch(int bit,int n){
    vector<ll>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    S.push_back(1e9);
    return S;
}

ll dp1[3010][2], dp2[3010][2];
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    sort(ALL(a), greater<int>());
    ll al = 0, bo = 0;
    rep(i, n){
        if(i % 2 == 0)al += a[i];
        else bo += a[i];
    }
    cout << al - bo << endl;
}



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

int main(){
  int n,i,j,a=0,b=0,l;
  char as[101],bs[101];

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%s %s",as,bs);
    if(strcmp(as,bs)==0){
      a++;
      b++;
    }
    else{
      l = strlen(as);
      if(l>strlen(bs)){
        l=strlen(bs);
      }
      for(j=0;j<l;j++){
        if(as[j]>bs[j]){
          a+=3;
          break;
        }
        else if(as[j]<bs[j]){
          b+=3;
          break;
        }
      }
      if(j==l){
        if (l==strlen(as)){
          b+=3;
        }
        else{
          a+=3;
        }
      }

    }
  }
  printf("%d %d\n", a, b);

  return 0;
}


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

int main(){
  long long N ;
  cin >> N ;
  int ans=0 ;
  int count;
  for(long long i=2;i*i<=N;i++){
    count = 0;
    while(N%i==0){
      count++;
      N /= i;
    }
    for(int j=1;count-j>=0;j++){
        ans++;
        count -=j;
    }
  }
  if(N>1) ans++;
  cout << ans << endl;
  
}
      
  



Measured memory_bytes: 3596