akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 200
int n,m;
double t[MAX_N];
int G[MAX_N][MAX_N];
bool visited[MAX_N];
int par[MAX_N];
 
void rdfs(int pos,int si){
  visited[pos]=true;
  par[pos]=si;
  for(int i=0;i<n;i++){
    if(G[i][pos]==0)continue;
    if(visited[i])continue;
    rdfs(i,si);
  }
}
 
void dfs(int pos,vector<int> &v){
  visited[pos]=true;
  for(int i=0;i<n;i++){
    if(G[pos][i]==0)continue;
    if(visited[i])continue;
    dfs(i,v);
  }
  v.push_back(pos);
}
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    memset(G,0,sizeof(G));
    for(int i=0;i<n;i++){
      cin>>t[i];
      int k;
      cin>>k;
      for(int j=0;j<k;j++){
        int a;
        cin>>a;
        a--;
        G[i][a]=1;
      }
    }
 
 
    vector<int> v;
    memset(visited,false,sizeof(visited));
    for(int i=0;i<n;i++){
      if(visited[i])continue;
      dfs(i,v);
    }
     
    memset(visited,false,sizeof(visited));
    reverse(v.begin(),v.end());
    for(int i=0;i<(int)v.size();i++){
      int si=v[i];
      if(visited[si])continue;
      rdfs(si,si);
    }
 
    vector<bool> flg(n,false);
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(G[i][j]==0)continue;
        if(par[i]!=par[j]){
          flg[ par[j] ]=true;
        }
      }
    }
 
    double ans=1.0;
    for(int i=0;i<n;i++){
      if(par[i]!=i)continue;
      if(flg[i])continue;
      double p=1.0;
      for(int j=0;j<n;j++){
        if(par[j]!=i)continue;
        p*=t[j];
      }
      ans*=(1.0-p);
    }
 
    printf("%.10f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3448
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		StringBuffer sb = new StringBuffer(N);
		sb = sb.reverse();
		String revN = sb.toString();
		if(N.equals(revN)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int d = sc.nextInt();
			
			for(;;) {
				c-=b;
				if(c<=0) {
					System.out.println("Yes");
					return;
				}
				a-=d;
				if(a<=0) {
					System.out.println("No");
					return;
				}
			}
	    }
				
	}


Measured memory_bytes: 35896
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*考えを書くスペース


*/

//main.cpp----------------------------
bool dfs(int x, int y);

#define MAX 1000

ll n;
string s;

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

  if(a<b) {
    int tmp = a;
    a = b;
    b = tmp;
  }

  if(b<=c && c<=a) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }

  return 0;
}


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

int main() {
	int D;
	double E;
	while (cin >> D >> E) {
		if (D == 0 && E == 0) return 0;
		double ANS = 10000;
		for (double A = 0; A <= D; A++) {
			double B = D - A;
			ANS = min(ANS, abs(sqrt(A * A + B * B) - E));
		}
		printf("%.12lf\n", ANS);
	}
}


Measured memory_bytes: 3216
def main():
  import sys
  input=sys.stdin.buffer.readline
  h,w=map(int,input().split())
  s=[c<46and 1or 0for _ in range(h)for c in input()[:w]]
  dp=[10**9]*h*w
  dp[0]=s[0]
  for i in range(h*w):
    j,k=i//w,i%w
    for y,x in((j+1,k),(j,k+1)):
      if y<h and x<w:
        z=y*w+x
        t=dp[i]+(s[i]^s[z])
        if dp[z]>t:dp[z]=t
  print(dp[-1]+1>>1)
main()

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ProblemC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var roundSqrtN = Math.Round(Math.Sqrt(N));
            var ret = N - 1;
            for (int i = 2; i < roundSqrtN + 1; i++)
            {
                long a = N % i;
                if ( a == 0)
                {
                    ret = Math.Min(ret, i + N / i - 2);
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 13140
#include<cstdio>
#define mid (l+r>>1)
#define L root<<1
#define R root<<1|1 
#define re register signed 
const int inf=1<<29;
const int Maxn=1e5+5;
inline int max(int x,int y){return x>y?x:y;}
inline int min(int x,int y){return x<y?x:y;}
inline int RR()
{
	char c;int res;
	while((c=getchar())>'9'||c<'0');res=c-'0';
	while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
	return res;
}
int s[Maxn*4],a[Maxn],n,d,dp[Maxn];
char c[Maxn];
void build(int root,int l,int r)
{
	if(l==r) 
	{s[root]=a[l];return;}
	build(L,l,mid);build(R,mid+1,r);
	s[root]=max(s[L],s[R]);
}
int query(int root,int l,int r,int x,int y)
{
	if(l>y||r<x) return 0;
	if(l>=x&&r<=y) return s[root];
	return max(query(L,l,mid,x,y),query(R,mid+1,r,x,y));
}
int main()
{
	n=RR();d=RR();int x;
	scanf("%s",c+1);++n;
	for(re i=1;i<=n;i++)
	if(c[i]-'0'==0) a[i]=i;
	build(1,1,n);//以下处理好dp[i],dp[i]表示i到n的最小步数,若到不了,则为inf 
	for(re i=n-1;i>=1;i--)
		if(c[i]-'0') dp[i]=inf;
		else 
		{
			x=query(1,1,n,i+1,min(n,i+d));
			if(!x) dp[i]=inf;
			else dp[i]=dp[x]+1;
		}
	if(dp[1]>=inf) 
	{
		puts("-1");
		return 0;
	}
	int pos=2,pre=1;//从pre跳到pos,其中pos是第一个dp值比pre少1的 
	while(pos<=n)
	{
		while(dp[pos]>=dp[pre]) pos++;
		printf("%d ",pos-pre);
		pre=pos;pos++;
	}
	return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>
#include<math.h>
int main(void)
{
  int i,j,n,max,num,min;
  scanf("%d",&n);
  int R[n];
  for(i=0;i<n;i++) scanf("%d",&R[i]);
  max=R[1]-R[0];
  min=R[0];
  for(i=1;i<n;i++)
  {
    if(max<R[i]-min) max=R[i]-min;
    if(min>R[i]) min=R[i];
  }
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2516
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>

int main() {
    std::string s;
    int n, A, B;

    std::cin >> n >> A >> B;
    std::cin >> s;
    int a, b;
    a = b = 0;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'a') {
            if (a + b < A + B) {
                a++;
                std::cout << "Yes" << std::endl;
            } else {
                std::cout << "No" << std::endl;
            }
        } else if (s[i] == 'b') {
            if (a + b < A + B && b < B) {
                b++;
                std::cout << "Yes" << std::endl;
            } else {
                std::cout << "No" << std::endl;
            }
        } else {
            std::cout << "No" << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

using namespace std;


int main() {
    string s;
    string t;
    cin >> s >> t;
    string new_s = s + t[t.length() - 1];
    if(new_s == t){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3624
h, w = map(int, input().split())
grid = [input() for _ in range(h)]
dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

for i in range(1, h - 1):
    for j in range(1, w - 1):
        if grid[i][j] == '#':
            for a, b in dxy:
                if grid[i + a][j + b] == '#':
                    break
            else:
                print("No")
                exit()

print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

struct SegMax{
    const ll INF=1e18;
    int n;
    vector<ll> dat;
    SegMax(int n_):n(),dat(n_*4,-INF){
        int x=1;
        while(n_>x){
            x*=2;
        }
        n=x;
    }

    void update(int i,ll x){//index iをxに更新する
        i+=n-1;
        dat[i]=x;
        while(i>0){
            i=(i-1)/2;
            dat[i]=max(dat[i*2+1],dat[i*2+2]);
        }
    }

    ll query(int a,int b){//a以上b未満の区間の最大値を求める
        return query_sub(a,b,0,0,n);
    }
    ll query_sub(int a,int b,int k,int l,int r){
        if(r<=a || b<=l){
            return -INF;
        }
        else if(a<=l && r<=b){
            return dat[k];
        }
        else{
            ll vl=query_sub(a,b,k*2+1,l,(l+r)/2);
            ll vr=query_sub(a,b,k*2+2,(l+r)/2,r);
            return max(vl,vr);
        }
    }
};

int main() {
    int N;
    cin>>N;
    vector<int> h(N);
    rep(i,N){cin>>h.at(i);h.at(i)--;}
    vector<ll> a(N);
    rep(i,N)cin>>a.at(i);
    SegMax sm(N);
    rep(i,N){
        ll now=sm.query(0,h.at(i));
        chmax(now,0ll);
        now+=a.at(i);
        sm.update(h.at(i),now);
    }
    ll ans=sm.query(0,N);
    cout<<ans<<endl;
}

Measured memory_bytes: 11960
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int S[1000];
int top;
int pop();
void push(int);
int main(){

  int top=0;
  int a,b;
  char anos[1000];

  while(scanf("%s",anos)!=EOF){

    if(anos[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }

    else if(anos[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }

    else if(anos[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else {
      push(atoi(anos));
    }
  }


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

  return 0;

}

int pop(){

  return S[top--];

}

void push(int x){

   top++;
   S[top]=x;

 }

Measured memory_bytes: 2752
s = [list(input()) for _ in range(3)]

p = 1
while True:
    if len(s[p-1]) == 0:
        break
    c = s[p-1].pop(0)
    if c == 'a':
        p = 1
    elif c == 'b':
        p = 2
    else:
        p = 3
if p == 1:
    print('A')
elif p == 2:
    print('B')
elif p == 3:
    print('C')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int main(){
	int n=read(),a=read(),b=read();
	if(abs(b-a)&1) printf("Borys\n");
	else printf("Alice\n");
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(' ').let { it[0].toInt() to it[1].toLong() }
    val a = readLine()!!.split(' ').map { it.toLong() }
    val b = LongArray(n)
    b[0] = Math.min(a[0], x)
    for (i in 1 until n) {
        b[i] = a[i] - Math.max(b[i - 1] + a[i] - x, 0)
    }
    println((0 until n).map { a[it] - b[it] }.sum())
}


Measured memory_bytes: 72012
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

///////////////////////////
////Prime Creator//////////
///////////////////////////
//bool Prime[100001] = {};
//void createPrime() {
//	ll n = 100001;
//	rep(i, 0, n) Prime[i] = true;
//	Prime[0] = false;
//	Prime[1] = false;
//	rep(i, 2, n) {
//		if (Prime[i]) {
//			rep(j, 2, n) {
//				if (j*i >= n)break;
//				Prime[j*i] = false;
//			}
//		}
//	}
//}
///////////////////////////
///////////////////////////

//Minimum Value
static const ll MIN_LL = (ll)1 << 55;

////Warshall Floyid
////All value should be initialized by MIN_LL
//static const ll wf_size = 300;
//ll wf[wf_size][wf_size];
//void WarshalFloyid() {
//	rep(k, 0, wf_size)rep(i, 0, wf_size)rep(j, 0, wf_size)wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
//}

int main() {
	ll N; cin >> N;
	char c[100] = {};
	ll cntl = 0;
	ll cntr = 0;

	rep(i, 0, N) {
		char s; cin >> s;
		c[i] = s;
		if (s == '(') {
			cntl++;
		}
		else if (s == ')') {
			if (cntl > 0) {
				cntl--;
			}
			else {
				cntr++;
			}
		}
	}

	rep(i, 0, cntr)	cout << '(';
	cout << c;
	rep(i, 0, cntl)	cout << ')';
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  int A, B, X;
  cin >> A >> B >> X;
  if (A <= X && X <= A + B - 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define CL clear()



int main()
{

    string a, b;
    cin >> a >> b;
    int i = 0;
    while(a[0]=='0')
        a.erase(0,1);
    while(b[0]=='0')
        b.erase(0,1);
    if(a.size()>b.size())
        cout <<"GREATER";
    else if(a.size()<b.size())
        cout <<"LESS";
    else
    {
        while(i < a.length()&& a[i]==b[i])
            i++;

        if(i == a.length())
            cout <<"EQUAL";
        else  if(a[i]>b[i])
            cout <<"GREATER";
        else
            cout <<"LESS";
    }



}




Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int N,K;
    cin >> N >> K;
    ll pattern = K * pow(K-1, N-1);
    cout << pattern << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int  long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
 
bool sortby(const pair<pair<string,int>,int> &a, 
              const pair<pair<string,int>,int> &b) 
{ 
    if(a.first.first==b.first.first)
        return (a.first.second > b.first.second); 
    else
        return(a.first.first < b.first.first);
}  
 
void solve(){
    int n,a;
    string s;
    vector<pair<pair<string,int>,int>> v;
    cin>>n;
    rep(i,0,n){
    cin>>s>>a;
    v.pb(mp(mp(s,a),i+1));
    }
    sort(all(v),sortby);
    rep(i,0,n)
        cout<<v[i].second<<"\n";
}
 
signed main(){
    //IOS;
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
     //   cout<<" * "<<t<<"\n";
    }
//    return 0;
}


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

using namespace std;

int main()
{
    char c;
    cin >> c;

    if(c == 'A'){
	cout << 'T' << endl;
    }else if(c == 'T'){
	cout << 'A' << endl;
    }else if(c == 'C'){
	cout << 'G' << endl;
    }else if(c == 'G'){
	cout << 'C' << endl;
    }
    
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input!{
        a: i32, b: i32,
    }

    println!("{}", if (a * b) % 2 == 1 {"Yes"} else {"No"});
}




Measured memory_bytes: 4352
#include <bits/stdc++.h>
using i64 = long long;

i64 dp[404][404];
i64 a[404], s[404];
constexpr i64 inf = std::numeric_limits<i64>::max();

i64 rec(int l, int r) {
    if (r - l == 1) return 0;
    if (dp[l][r]) return dp[l][r];
    i64 ret = inf;
    for (int i = l + 1; i < r; i++) {
        ret = std::min(ret, rec(l, i) + rec(i, r));
    }
    return dp[l][r] = s[r - 1] - s[l - 1] + ret;
}

int main() {
    int n;
    std::cin >> n;
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }

    std::cout << rec(1, n + 1) << std::endl;

    return 0;
}

Measured memory_bytes: 1536
n, x = map(int, input().split())

def func(a, b):
    if a < b:
        if b%a == 0:
            return (b//a*2 - 1)*a
        else:
            q, mod = divmod(b,a)
            return 2*q*a + func(a, mod)
    elif a > b:
        if a%b == 0:
            return (a//b*2 - 1)*b
        else:
            q, mod = divmod(a,b)
            return 2*q*b + func(mod, b)
    else:
        return a

if x == n/2:
    print(3*x)
else:
    print(x+(n-x)+func(x,n-x))

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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    vector<ll> b(n);
    rep(i, n + 1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = 0;
    rep(i, n) {
        int left = min(a[i], b[i]);
        ans += left;
        a[i] -= left;
        b[i] -= left;
        int right = min(a[i + 1], b[i]);
        ans += right;
        a[i + 1] -= right; 
        b[i] -= right;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
N=int(input())
t=0
i=int(N**0.5)+1
while i>=2:
    if N%i==0:
        t=i
        break
    else:
        i-=1
        t=N
if t==N:
    print(t-1)
else:
    print(t-1+N//t-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    int p = 1;
    int ans = 1;
    cin >> N;
    REP(i, N){
        int x;
        cin >> x;
        if(!(x%2)){
            p *= 2;
        }
        ans *= 3;
    }
    cout << ans-p << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
int main() {
    int dd; cin >> dd;
    vector<int> ar(26);
    rep(i,26) cin >> ar[i];
    vector<vector<int>> sc(dd,vector<int>(26));
    rep(i,dd) rep(j,26) cin >> sc[i][j];
    vector<int> la(26,0);
    rep(i,(dd-2)/3){
        int ma = -10000000;
        vector<int> ko(3);
        rep(a,26)rep(b,26)rep(c,26){
            vector<int> nla = la;
            vector<int> im = {a,b,c};
            int ima = 0;
            rep(j,3){
                ima += sc[3*i+j][im[j]];
                nla[im[j]] = 3*i+j+1;
                rep(k,26){
                    ima -= ar[k] * (3*i+j+1-nla[k]);
                }
            }
            if (ma < ima){
                ma = ima;
                ko = im;
            }
        }
        rep(j,3){
            la[ko[j]] = 3*i+j+1;
            cout << ko[j] + 1 << endl;
        }
    }
    rep(i,2){
        int ma = -10000000;
        int as = 0;
        int ima = 0;
        rep(j,26){
            ima += ar[j] * (dd-1+i - la[j]);
        }
        rep(j,26){
            int sp = sc[dd-2+i][j];
            sp -= ima;
            sp += ar[j] * (dd-1+i - la[j]);
            if (ma < sp){
                ma = sp;
                as = j+1;
            }
        }
        la[as-1] = dd-1+i;
        cout << as << endl;
    }
}

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

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

#define INF 100000000

int main() {
  int H, A;
  cin >> H >> A;
  int num = ceil((double)H / A);
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    rep(i, sx, tx){
        cout << 'U';
    }
    rep(i, sy, ty){
        cout << 'R';
    }

    rrep(i, tx, sx + 1){
        cout << 'D';
    }
    rrep(i, ty, sy + 1){
        cout << 'L';
    }

    cout << 'L';
    rep(i, sx, tx + 1){
        cout << 'U';
    }
    rep(i, sy - 1, ty){
        cout << 'R';
    }

    cout << 'D';

    cout << 'R';
    rrep(i, tx, sx){
        cout << 'D';
    }
    rrep(i, ty + 1, sy + 1){
        cout << 'L';
    }

    cout << 'U' << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    int n,k;
    cin >> n >> k;
    int ans = 0;
    REP(i,k){
        int tmp = 1;
        REP(i,n-1) tmp*=k-1;
        ans += tmp;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384
n=int(input())
f=lambda x:sorted([list(map(int,input().split())) for _ in range(n)],key=lambda k:k[x])
qr,qb=f(1)[::-1],f(0)
a=0
for c,d in qb:
  for r in qr:
    if c>r[0] and d>r[1]: qr.remove(r); a+=1; break
print(a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define Maxn 200005
#define rint register int
using namespace std;

char buf[1 << 20], *p1, *p2;
#define gc() ((p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++)
int read() {
	rint s = 0, f = 1; register char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); }
	return s * f;
}

int n, k;

struct Edge { int ver, nxt; } edge[Maxn << 1];
int tot = 0, head[Maxn];
inline void add(int x, int y) { edge[++tot].ver = y, edge[tot].nxt = head[x], head[x] = tot; }

priority_queue<pair<int, int> > q;
int val[Maxn], fa[Maxn];
bool vis[Maxn], valid[Maxn];

void input() {
  n = read();
  for (rint i = 1; i <= n; ++i) valid[i] = true;
  for (rint i = 1; i < n; ++i) {
    int u = read(), v = read();
    add(u, v), add(v, u);
  }
  k = read();
  for (rint i = 1; i <= k; ++i) {
    int u = read(), p = read();
    val[u] = p; vis[u] = true;
  }
}

namespace Solution {
  bool BFS() {
    for (rint i = 1; i <= n; ++i) if (vis[i]) q.push(make_pair(val[i], i));
    while (q.size()) {
      int u = q.top().second; int x = q.top().first; q.pop();
      valid[u] = false;
			for (rint i = head[u]; i; i = edge[i].nxt) {
        int v = edge[i].ver;
        if (!valid[v]) continue;
        if (vis[v]) {
        	if (abs(x - val[v]) != 1) return false;
				} else vis[v] = true, q.push(make_pair(val[v] = val[u] - 1, v));
      }
    }
    return true;
  }
  void solve() {
    if (!BFS()) return void(puts("No"));
    puts("Yes");
    for (rint i = 1; i <= n; ++i) printf("%d\n", val[i]); 
  }
}

signed main() {
	input();
  Solution :: solve();
  return 0;
}

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

int N;
string S;

int main(){
    int count = 0;
    cin >> N >> S;
    for(int i=0; i<S.size(); i++){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
            count += 1;
        } else{
            continue;
        }
    }

    cout << count;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    int n; cin >> n;
    int dp[n][3]; rep(i, n) rep(j, 3) dp[i][j] = 0;
    rep(j, 3) {int tmp; cin >> tmp; dp[0][j] = tmp;}
    rrep(i, 1, n) {
        int a, b, c; cin >> a >> b >> c;
        rep(j, 3) {
            if (j == 0) {dp[i][j] = max(dp[i - 1][2], dp[i - 1][j + 1]) + a; continue;}
            if (j == 2) {dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][0]) + c; continue;}
            dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j + 1]) + b;
            
        }
    }
    cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl;
}


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

#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int INF = 1e9+100;
const ll LINF = 1e18+100;
const int MAXN = 2e5+100;
const double EPS = 1e-6;


int n, k;
ll dp[MAXN];
ll h[MAXN];

void solve() {
	cin >> n >> k;
	for(int i = 1; i <= n; ++i)
		cin >> h[i];
	for(int i = 1; i <= n; ++i)
		dp[i] = LINF;
	dp[1] = 0;
	for(int i = 1; i < n; ++i) {
		for(int j = i+1; j <= i+k; ++j)
			dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
	}
	cout << dp[n];
}

int main() {

//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int t = 1;
//	cin >> t;
	while(t--) {
		solve();
	}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define int long long
#define pb push_back
#define ld long double
#define endl "\n";
#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define vii vector<int>
#define pii pair<int, int>
#define prec(n) fixed << setprecision(n)
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define MOD LLONG_MAX
#define INF 1000000007
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    int t;
    t = 1;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        vector<vii> dp(n, vector<int>(m, 0));
        vector<vector<char>> grid(n, vector<char>(m, 0));
        rep(i, 0, n)
        {
            rep(j, 0, m)
            {
                cin >> grid[i][j];
            }
        }
        dp[0][0] = 1;
        rep(i, 0, n)
        {
            rep(j, 0, m)
            {
                if (i > 0 and grid[i - 1][j] == '.')
                {
                    dp[i][j] += dp[i - 1][j] % INF;
                }
                if (j > 0 and grid[i][j - 1] == '.')
                {
                    dp[i][j] = (dp[i][j] + dp[i][j - 1]) % INF;
                }
            }
        }
        cout << dp[n - 1][m - 1] % INF << endl;
    }
    printclock;
    return 0;
}

Measured memory_bytes: 12088
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
 
// ------------------------------------------------------------------------------------------------

ll n, ans;
vll a, b;

int main() {
    fast_io; cout_precision;
    cin >> n;
    a.resize(n + 1);
    for (ll i = 0; i < n + 1; i++) {
        cin >> a[i];
    }
    b.resize(n + 1);
    for (ll i = 0; i < n; i++) {
        cin >> b[i];
    }
    ans = 0;
    for (ll i = n - 1, x; i >= 0; i--) {
        x = min(a[i + 1], b[i]);
        a[i + 1] -= x; b[i] -= x; ans += x;
        x = min(a[i], b[i]);
        a[i] -= x; b[i] -= x; ans += x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

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

void Main() {
  Cin(int, R, G, B, n);

  int ans = 0;
  for (int r = 0; r * R <= n; ++r) {
    for (int g = 0; r * R + g * G <= n; ++g) {
      int b = (n - r * R - g * G) / B;
      if (r * R + g * G + b * B == n && b >= 0) ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
n,m,x,y=map(int,input().split())
xlist=list(map(int,input().split()))
ylist=list(map(int,input().split()))
flag=False
for z in range(x+1,y+1):
  #print(z)
  if max(xlist)<z and min(ylist)>=z:
    flag=True
    #print(z)
print("No War" if flag else "War")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int ax=0,bx=-1,cx=-1;
char cc;
int main()
{
	string a,b,c;
	cin>>a>>b>>c;
	cc=a[ax];
	while(1)
	{
		if(cc=='a')
		{
			ax++;
			if(a[ax]=='\0')
			{
				cout<<"A";
				return 0;
			}
			cc=a[ax];
		}
		else
		{
			if(cc=='b')
			{
				bx++;
				if(b[bx]=='\0')
				{
					cout<<"B";
					return 0;
				}
				cc=b[bx];
			}
			else if(cc=='c')
			{
				cx++;
				if(c[cx]=='\0')
				{
					cout<<"C";
					return 0;
				}
				cc=c[cx];
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
typedef pair<LL, LL> P;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,m,i,j;
	cin>>n;
	m=n*3;
	int a[m]={},a1[n]={},a2[n]={},a3[n]={};
	FOR(i,0,m){
		//cin>>a[i];
		if(i<m/3)cin>>a1[i];
		else if(i<m*2/3)cin>>a2[i-m/3];
		else cin>>a3[i-m*2/3];
	}
	//sort(a1,a1+n);
	//sort(a3,a3+n);
	priority_queue<int,vector<int>,greater<int>> q1;
	priority_queue<P,vector<P>,greater<P>> q33;
	long pll=0,mnn=0;
	FOR(i,0,n){
		pll+=a1[i];
		//mnn+=a3[i];
		q1.push(a1[i]);
		q33.push(P(a2[i],i));
		q33.push(P(a3[i],n+i));
	}
	int loc[2*n]={};
	FOR(i,0,n){
		P p=q33.top();
		mnn+=p.ST;
		loc[p.ND]=p.ST;
		q33.pop();
	}
	long max=pll-mnn;
	//cout<<pll<<" "<<mnn<<" "<<max<<endl;
	long pl=pll,mn=mnn;
	FOR(i,0,n){

		//priority_queue<int,vector<int>,greater<int>> q1(q11);
		if(loc[i]!=0){
			while(!q33.empty()){
			P p=q33.top();
			q33.pop();
			if(p.ND<=i)continue;
			mn+=p.ST-a2[i];
			loc[p.ND]=p.ST;
			loc[i]=0;
			break;
		}
		}

		q1.push(a2[i]);
		int tmp=q1.top();
		q1.pop();
		pl+=a2[i]-tmp;

		if(max<pl-mn)max=pl-mn;
	}
	cout<<max<<endl;

    return 0;
}


Measured memory_bytes: 9072
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int sum = 700;

		if(s.substring(0,1).equals("o")) {
			sum += 100;
		}
		if(s.substring(1,2).equals("o")) {
			sum += 100;
		}

		if(s.substring(2,3).equals("o")) {
			sum += 100;
		}

		System.out.println(sum);
		//System.out.println(sum);


	}

	public static int res(int n) {
		if(n==1) {
			return 1;
		}

		return n+res(n-1);
	}
}




Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);i++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);i++)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MOD 1000000007
using namespace std;
int main(){
    ll h,n;
    cin>>h>>n;
    vector<int> a(n),b(n);
    rep(i,0,n)cin>>a[i]>>b[i];
    vector<ll> dp(h+1,1e9);
    dp[0]=0;
    rep(i,0,h){
        rep(j,0,n){
            dp[min(h,i+a[j])]=min(dp[min(h,i+a[j])],dp[i]+b[j]);
        }
    }
    cout<<dp[h]<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    int H,A;
    cin >> H >> A;
    
    for(int i=0;i<100000;i++){
        
        H -= A;
        
        if(H<=0){
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
    int n,m,a[1000],b[1000],i,w[1000];
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++){
	    scanf("%d %d",&a[i],&b[i]);
	}
	if(n%2!=0){
		for(i=0;i<m;i++){
//			printf("%d %d %d\n",i,a[i],b[i]);
			if(a[i]>n/2+1){
			    a[i]=n-a[i]+1;
			}
			if(b[i]>n/2+1){
			    b[i]=n-b[i]+1;
			}
//			printf("%d %d %d\n",i,a[i],b[i]);
			if(a[i]>b[i]) w[i]=b[i]%3;
			else w[i]=a[i]%3;
//			printf("%d %d\n",i,w[i]);
		}
	}
	else if(n%2==0){
	    for(i=0;i<m;i++){
		    if(a[i]>n/2){
			    a[i]=n-a[i]+1;
			}
			if(b[i]>n/2){
			    b[i]=n-b[i]+1;
			}
			if(a[i]>b[i]) w[i]=b[i]%3;
			else w[i]=a[i]%3;
//			printf("%d %d\n",i,w[i]);
		}
	}
	for(i=0;i<m;i++) if(w[i]==0) w[i]=3;
	for(i=0;i<m;i++) printf("%d\n",w[i]);
	return 0;
}

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

const int N = 200005;

int n;
int a[N];

int cnt[N];

int solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    ++cnt[a[i]];
  }

  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += 1LL * cnt[i] * (cnt[i] - 1) / 2;
  }

  for (int i = 0; i < n; ++i) {
    int c = cnt[a[i]];
    ans -= 1LL * c * (c-1) / 2;
    ans += 1LL * (c-1) * (c-2) / 2;
    printf("%lld\n", ans);
    ans -= 1LL * (c-1) * (c-2) / 2;
    ans += 1LL * c * (c-1) / 2;
  }
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


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

int main() {
  int N; cin >> N;
  cout << N/2 + (N%2) << endl;
  return 0;
}


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

//ただの辺
struct edge {
    using lint = long long int;
    int to;
    lint cost;
    //引数一つの時は距離1
    edge(int t, lint c = 1) : to(t), cost(c) {
    }
};

// dijkstra
// depend:edge
vector<long long int> dijkstra(vector<vector<edge>>& g, int start) {
    using lint = long long int;
    vector<lint> res(g.size(), LLONG_MAX);
    res[start] = 0;
    // first:距離、second:行き先
    priority_queue<pair<lint, lint>, vector<pair<lint, lint>>,
                   greater<pair<lint, lint>>>
        pq;
    pq.push({0, start});
    while (!pq.empty()) {
        lint dist = pq.top().first, now = pq.top().second;
        pq.pop();
        if (res[now] < dist) continue;
        for (int i = 0; i < (int)g[now].size(); i++) {
            edge e = g[now][i];
            if (res[e.to] > res[now] + e.cost) {
                res[e.to] = res[now] + e.cost;
                pq.push(make_pair(res[e.to], e.to));
            }
        }
    }
    return res;
}

int main() {
    int x;
    cin >> x;
    vector<vector<edge>> g(x + 1);
    for (int i = 0; i <= x; i++) {
        for (int j = 0; j <= 5; j++) {
            if (i + 100 + j <= x) {
                g[i].push_back(edge(i + 100 + j));
            }
        }
    }
    if (dijkstra(g, 0)[x] != LLONG_MAX) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 17408
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		char[] arr = s.toCharArray();
		sc.close();

		int ans = 0;
		int cnt1 = 0;
		int cnt0 = 0;
		TreeSet<Integer> set = new TreeSet<Integer>();
		set.add(0);
		for (int i = 0; i < n; i++) {
			if (arr[i] == '1') {
				cnt0 = 0;
				if (cnt1 == 0) {
					set.add(i);
				}
				Integer idx = set.first();
				ans = Math.max(ans, i - idx + 1);
				cnt1++;
			} else {
				cnt1 = 0;
				if (cnt0 == 0) {
					if (set.size() > k) {
						set.pollFirst();
					}
				}
				Integer idx = set.first();
				ans = Math.max(ans, i - idx + 1);
				cnt0++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 28216
def main():
    n = int(input())
    lr = [list(map(int, input().split())) for _ in [0] * n]
    lr.sort(key=lambda x: (x[0], x[1]))
    min_r = [0] * n
    min_r[0] = lr[0][1]
    min_l = [0] * n
    min_l[n-1] = lr[n-1][1]
    for i in range(1,n):
        min_r[i] = min(min_r[i - 1], lr[i][1])
    for i in range(n-2,-1,-1):
        min_l[i] = min(min_l[i + 1], lr[i][1])
    ans = max([max(min_r[i] - lr[i][0] + 1, 0) + max(min_l[i + 1] - lr[n - 1][0] + 1, 0) for i in range(n - 1)])
    l,r,w=0,10**9+1,0
    for i in range(n):
        l = max(l, lr[i][0])
        r = min(r, lr[i][1])
        w = max(w, lr[i][1] - lr[i][0]+1)
    ans = max(ans, max(r - l + 1, 0) + w)
    print(ans)
main()

Measured memory_bytes: 76120
a, b, c, d = map(int, input().split())

big = max(c, d)
small = min(c, d)
lcm = 0
for i in range(1, 10 ** 8):
    surplus = big % small
    if surplus == 0:
        lcm = c * d // small
        break
    
    big = small
    small = surplus
    

c_num = b // c - (a - 1) // c
d_num = b // d - (a - 1) // d
cd_num = b // lcm - (a - 1) // lcm
num = b - a + 1

#print(num, c_num, d_num, cd_num, lcm)
ans = num - (c_num + d_num - cd_num)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<vector<int> > A(2, vector<int>(N, 0));
  REP(i, 2) REP(j, N){
    cin >> A[i][j];
  }
  int ans = 0;
  REP(i, N){
    int tmp = 0;
    REP(j, N){
      if(j <= i){
        tmp += A[0][j];
      }
      if(j >= i){
        tmp += A[1][j];
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

signed main()
{
	int n,a;
  cin >> n >> a;
  
  cout <<((n%500) <= a ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
  long a,b,c,d;/*a<=x<=b,c<=y<=d*/
  long ac,ad,bc,bd;
  cin >> a>> b>> c>> d;
  ac = a*c;
  ad = a*d;
  bc = b*c;
  bd = b*d;

  if(ac>=ad&&ac>=bc&&ac>=bd&&ac>=0){
    cout << ac<< endl;
  }else if(ad>=ac&&ad>=bc&&ad>=bd&&ad>=0){
    cout << ad<< endl;
  }else if(bc>=ac&&bc>=ad&&bc>=bd&&bc>=0){
    cout << bc<< endl;
  }else if(bd>=ac&&bd>=ad&&bd>=bc&&bd>=0){
    cout << bd<< endl;
  }else if(ac>=ad&&ac>=bc&&ac>=bd&&ac<0){
    cout << ac<< endl;
  }else if(ad>=ac&&ad>=bc&&ad>=bd&&ad<0){
    cout << ad<< endl;
  }else if(bc>=ac&&bc>=ad&&bc>=bd&&bc<0){
    cout << bc<< endl;
  }else if(bd>=ac&&bd>=ad&&bd>=bc&&bd<0){
    cout << bd<< endl;
  }else{
    cout << 0<< endl;
  }
  return 0;
}

Measured memory_bytes: 3616
s = int(input())
a = [s]

i = 1
# print(a)
while a.count(a[i - 1]) == 1:
    # print(a[i - 1])
    if a[i - 1] % 2 == 0:
        a.append(a[i - 1] // 2)
        # a[i] = a[i - 1] // 2
    else:
        # a[i] = 3 * a[i - 1] + 1
        a.append(3 * a[i - 1] + 1)

    i += 1
    # print(a, i)
print(i)


Measured memory_bytes: 2940
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=ja

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int n,x;
    while(1){
        cin >> n >> x;
        if(n==0&&x==0)break;
        ll cnt = 0;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                for(int k=j+1;k<=n;k++){
                    if(i==j||j==k||i==k)continue;
                    if(i+j+k==x)cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3092