akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846

int main()
{
  ll N,M;cin>>N>>M;
  Graph G(N+1);
  for (int i=1;i<=M;i++)
  {
    ll a,b; cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  vector<ll> dist(N+1,-1);
  vector<ll> light(N+1,-1);
  queue<ll> q;
  q.push(1);
  while (!q.empty())
  {
    int v = q.front();
    q.pop();
    for (auto nv : G[v])
    {
      if (dist[nv]!=-1)continue;
      dist[nv]=dist[v]+1;
      light[nv]=v;
      q.push(nv);
    }
  }
  
  for (int i=2;i<=N;i++)
  {
    if (dist[i]==-1)
    {
      cout<<"No"<<endl;
      return (0);
    }
  }
  
  cout<<"Yes"<<endl;
  
  for (int i=2;i<=N;i++)
    cout<<light[i]<<endl;
}

Measured memory_bytes: 13664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a == 7 && b == 5 && c == 5) cout << "YES" << endl;
  else if (a == 5 && b == 7 && c == 5) cout << "YES" << endl;
  else if (a == 5 && b == 5 && c == 7) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

int main(){

  int n,m;
  vector<int> mem;
  int turn,pot;
  while( cin >>n >>m , n&&m){
    
    mem.resize(n);
    for(int i=0; i<n; i++)mem[i]=i+1;
    
    pot = 0;
    turn = 1;
    
    while(mem.size()>1){
      if(turn%m == 0){
	mem.erase(mem.begin()+pot);
      }
      else{
	pot = (pot+1)%mem.size();
      }
      turn ++;
    }
    
    cout << mem[0] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> correct(N, 0);
	for (int i = 0; i < Q; i++) {
		int A;
		cin >> A;
		A--;
		correct[A]++;
	}
	for (int i = 0; i < N; i++) {
		if (correct[i] > (Q - K)) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

int main()
{
    int N;
    int M;
    cin >> N >> M;
    int A[M];
    int A_Sum = 0;
    for (int i = 0; i < M; i++)
    {
        cin >> A[i];
        A_Sum += A[i];
    }

    if (N < A_Sum)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << N - A_Sum << endl;
    }
}


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

using namespace std;
#define int int64_t
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

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

   int n, cnt = 0, wa;
   cin >> n;
   vector<int> x(n);

   rep(i, n)
   {
      cin >> x[i];
   }

   sort(all(x));

   wa = x[x.size() - 1];

   for (int i = 0; i < n - 1; ++i)
   {
      cnt += x[i];
   }

   if (wa < cnt)
   {
      cout << "Yes" << '\n';
   }
   else
   {
      cout << "No" << '\n';
   }
}

Measured memory_bytes: 256
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength

#素因数分解
def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a

#重複を検出
def has_duplicates(seq):
  return len(seq) != len(set(seq))



#X = str(input()).split()
#a = [int(x) for x in input().split()]


N = int(input())
S = str(input())

c = S.count("E")

if(S[0] == "E"):
  c -= 1

ans = 0

temp = c

for i in range(1, N):
  if(S[i-1] == "E"):
    if(S[i] == "E"):
      c -= 1
      if(c<temp):
        ans = i
        temp = c
  else:
    if(S[i] == "W"):
      c += 1




print(temp)



Measured memory_bytes: 41708
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


int main(){
  string s;
  cin >> s;
  int n = s.size();
  bool kaibun(string);
  string t,u;
  rep1(i, (n-1)/2){
    t.push_back(s[i]);
  }
  rep1(i, (n-1)/2){
    u.push_back(s[(n+3)/2 - 1 + i]);
  }
  if(kaibun(s) && kaibun(t) && kaibun(u)){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

bool kaibun(string s){
  rep1(i, (s.size())/2){
    if(s[i] != s[s.size()-1-i]){
      return false;
    }
  }
  return true;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	
	public static void main (String[] args) {
		
        Scanner sc = new Scanner(System.in);
        
        int temp = sc.nextInt();
        if(temp >= 30 )
        {
                System.out.println("Yes");
        }else
        {
                System.out.println("No");
        }
        
        
	}
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int ans = 1e9;
    for (int i = -100; i < 101; i++) {
        int s = 0;
        rep(j, N) {
            s += (i - a[j]) * (i - a[j]);
        }
        ans = min(ans, s);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
//#include"functions.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define INF 1e9
#define EPS 1e-5
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define FOR(a,b) for(int a=0;a<b;a++)
#define FORN(a,m,n) for(int a=0;a<m;a+=n)
#define REP(a,m,n) for(int a=m;a<n;a++)
#define REPN(a,m,n,p) for(int a=m;a<n;a+=p)
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdfopen(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define ifopen(a) freopen(a,"r",stdin);
#define ofopen(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
using namespace std;

bool isp(ll n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0)return 0;
	}
	return 1;
}
int main(){
	int n,a;
	cin>>n>>a;
	a=a*2+1;
	cout<<(n+a-1)/a;
	return 0;
}


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

int main(int argc, char const* argv[]) {
	int N;
	int a[110];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + N, greater<int>());

	int Alice = 0;
	int Bob = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			Alice += a[i];
		} else {
			Bob += a[i];
		}
	}
	printf("%d", Alice - Bob);

	return 0;
}


Measured memory_bytes: 3844
struct Card {
	char pat;
	int num;

	string toString() {
		return pat ~ num.to!string;
	}
}

Card[] bubbleSort(Card[] cards) {
	ulong N = cards.length;
	foreach(i; 0..N) foreach_reverse(j; i+1..N) {
		if(cards[j].num < cards[j-1].num) swap(cards[j], cards[j-1]);
	}
	return cards;
}

Card[] selectionSort(Card[] cards) {
	ulong N = cards.length;
	foreach(i; 0..N) {
		ulong minj = i;
		foreach(j; i..N) {
			if(cards[j].num < cards[minj].num) minj = j;
		}
		swap(cards[i], cards[minj]);
	}
	return cards;
}

void main() {
	auto N = ri;
	Card[] cards;
	auto S = readln.split;
	foreach(i; S) {
		cards ~= Card(i[0], i[1].to!string.to!int);
	}
	// Bubble sort is always stable
	auto A = cards.dup.bubbleSort;
	writefln("%(%s %)\nStable", A);
	auto B = cards.dup.selectionSort;
	writefln("%(%s %)", B);
	writeln(A == B ? "Stable" : "Not stable");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 2520
def factorial(a):
    if(a==1 or a==0):return 1
    else:
        return a*factorial(a-1)

def comb(a,b):
    return factorial(a)//factorial(a-b)//factorial(b)

while True:
    try:
        st=input()
        ans=0
        for i in range(len(st)):
            n=int(st[i])
            ans+=n*comb(9,i)
        print(ans%10)

    except:
        break

Measured memory_bytes: 7648
#include <bits/stdc++.h>
#define INF 1e18
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define MAX 1000
using namespace std;
const int mod = 1000000007;
char c[MAX][MAX];
int step[MAX][MAX];
int H,W,N; 
int vy[4] ={1,-1,0,0}, vx[4] = {0,0,-1,1}; //up,down,left,right 

signed main(){
    int k,a,b; cin >> k >> a >> b;
    for(int i=a;i<b+1;i++){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
    n:usize,
    s:Chars,
    t:Chars,
     }
    for i in 0..n {
        print!("{}{}", s[i], t[i]);
    }
}


Measured memory_bytes: 2124
#include<iostream>
using namespace std;
int main()
{
	long long h,a;
  	cin>>h>>a;
  	if(h<a) 
    {
      cout<<"1"<<endl;
      return 0;
    }
  	else
    {
      	cout<<(h+a-1)/a<<endl;
      return 0;
    }
}

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  string s;cin>>s;
  bool e=false;
  rep(i,0,s.size()){
    if(s[i]=='7')e=true;
  }

  if(e)out("Yes");
  else out("No");



  return 0;
}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

int dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};

ll gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main() {
    cout<<fixed<<setprecision(10);

    ll t; cin>>t;
    while(t>0){
        t--;
        ll a,b,c,d; cin>>a>>b>>c>>d;

        if(d < b){
            puts("No");
            continue;
        }
        if(a < b){
            puts("No");
            continue;
        }

        if(c >= b) puts("Yes");
        else{
            ll e = a%b;
            ll g = gcd(b,d);
            ll n3 = (c-e)/g + 1;
            if(c < e || n3*g < b-e) puts("No");
            else puts("Yes");
        }
    }

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;cin>>s;
    ll a = (s[0]-'0')*10+s[1]-'0';
    ll b = (s[2]-'0')*10+s[3]-'0';

    bool isym = (1<=b&&b<=12);
    bool ismy = (1<=a&&a<=12);

    if(isym){
        if(ismy)cout<<"AMBIGUOUS";
        else cout<<"YYMM";
    }
    else{
        if(ismy)cout<<"MMYY";
        else cout<<"NA";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)

#define SUPL 10002

int main(){
	int cl,maxg,T,U,V,L;
	cin>>cl>>maxg>>T>>U>>V>>L;
	int cs[cl+1];
	REP(ci,cl) cin>>cs[ci];
	cs[cl]=-1;

	double t=0;
	int x=0;
	int ci=0;
	double boostingX=0;
	int g=0;

	while(x<L){		//x tuuka tyokugo no joutai
		x++;
		if(boostingX>1){
			boostingX-=1;
			t+=1.0/V;
		}else{
			if(g==0){
				t+=boostingX/V+(1-boostingX)/U;
				boostingX=0;
			}else{
				g--;
				t+=1.0/V;
				boostingX+=T*V-1;
			}
		}

		if(x==cs[ci]){
			ci++;
			if(g==maxg){
				boostingX=T*V;
			}else{
				g++;
			}
		}

		//cout<<x<<" "<<t<<" "<<ci<<" "<<g<<" "<<boostingX<<endl;

	}

	cout.precision(20);
	cout<<t<<endl;



}

Measured memory_bytes: 1240
#1_10_B
import math
a , b , c = map(int,input().split())
if c == 90:
    S =( a * b ) / 2
    L = a + b + math.sqrt(a**2 + b **2)
    h = b

elif c == 60:
    S = math.sqrt(3) / 4 * a**2
    L = a * 3
    h = math.sqrt(3) / 2 * a
else:
    h = b * math.sin(math.radians(c))
    S = a * h / 2
    L = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(c)))
    
print('{:.8f}'.format(S))
print('{:.8f}'.format(L))
print('{:.8f}'.format(h))


Measured memory_bytes: 5700
N = int(input())

if N == 2:
    print(2, 3)
    print(5, 4)
    exit()

a = [[1] * N for _ in range(N)]

PN = [2]
L = 3
while len(PN) < N*2:
    c = True
    for p in PN:
        if L % p == 0: c = False
    if c == True: PN.append(L)
    L += 2

def P1(k):
    return PN[(k//2)]

def P2(k):
    if k >= 0:
        return PN[(k//2) + N]
    else:
        return PN[(k//2)]

for i in range(N):
    for j in range(N):
        if (i + j) % 2 == 0:
            a[i][j] = P1(i + j) * P2(i - j)
        else:
            a[i][j] += P1(i + j + 1) * P1(i + j - 1) * P2(i - j + 1) * P2(i - j - 1)

for a_i in a:
    print(*a_i)


Measured memory_bytes: 20676
N = int(input())
inputs = [[int(i) for i in input().split()] for _ in range(N)]

inputs = inputs[::-1]
ans = 0

for input in inputs:
    A, B = input[0], input[1]
    A += ans
    if A % B != 0:
        ans += B - (A % B)

print(ans)


Measured memory_bytes: 21924
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

double calc(int x1, int x2, int y1, int y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }
  vector<int> order(n);
  for (int i = 0; i < n; ++i) {
    order[i] = i;
  }
  double sum = 0;
  do {
    double res = 0.0;
    for (int i = 0; i + 1 < n; ++i) {
      res += calc(x[order[i]], x[order[i + 1]], y[order[i]], y[order[i + 1]]);
    }
    sum += res;
  } while (next_permutation(order.begin(), order.end()));
  for (int i = 0; i < n; ++i) {
    sum /= 1.0 * (i + 1);
  }
  printf("%.10f\n", sum);
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<iostream>
#include<cstdlib>
#include<iomanip>
using namespace std;
const int maxn=1e5+2;
int n,m;
struct date
{
	int p;//分组
	int y;//年
	int num;//
	int number;
};
date a[maxn];
map<int,int>mp;

int cmp1(const date X, const date Y){
	return X.y<Y.y;
}

int cmp2(const date X, const date Y){
	return X.number<Y.number;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a[i].p>>a[i].y;
		a[i].number=i;
	}
	sort(a+1,a+1+m,cmp1);
	
	for(int i=1;i<=m;i++){
		if(mp[a[i].p]==0) mp[a[i].p]=1;
		a[i].num=mp[a[i].p];
		mp[a[i].p]++;
	}

	sort(a+1,a+1+m,cmp2);
	for(int i=1;i<=m;i++){
		cout<<setfill('0')<<setw(6)<<a[i].p;
		cout<<setfill('0')<<setw(6)<<a[i].num;
		cout<<endl;
	}
}




Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
bool sosu(long int n){
	if(n<2) return false;
	else if(n==2) return true;
	else if(n%2==0) return false;
	for(int i=3;i*i<=n;i+=2){
		if(n%i==0){
			return false;
		}
	}
	return true;
}
int main() {
	long int ans[100005];
	long int cnt = 0;
	for(int i=1;i<=100000;i++){
		if(sosu(i)==true && sosu((i+1)/2)==true){
			cnt++;
		}
		ans[i] = cnt;
	}
	long int q; cin >> q;
	for(int i=0;i<q;i++){
		int l, r; cin >> l >> r;
		cout << ans[r]-ans[l-1] << endl;
	}
	return 0;
}

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

int main() 
{
    string X;

    cin >> X;
    
    if(X == "Sunny"){
        cout << "Cloudy" << endl;
    } 

    if(X == "Cloudy"){
        cout << "Rainy" << endl;
    } 

    if(X == "Rainy"){
        cout << "Sunny" << endl;
    } 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define N 1000005
using namespace std;
typedef long long int lo;
const int mod=1000000007;
lo a,b,c,d,e,f,g,h[100005],arr[100005];
string s;
vector<lo>v;
char ch;

int main(){
	// freopen("in.txt","r",stdin);
 //    freopen("out.txt","w",stdout);
    cin >> a;
    for(lo i=1;i<=a;i++){
    	cin >>arr[i];
    }
    sort(arr+1,arr+a+1);
    double x=arr[1];
    for(lo i=2;i<=a;i++){
    	x=(double)(arr[i]+x)/2;
    }
    cout << x <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int h, n, sum = 0;
	cin >> h >> n;

	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		sum += a;
	}
	if(sum>=h)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
//AT3882 people on a line
//2018/6/23 
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#define N 100001
#define M 200001
#define INF 0x7fffffff
#define ri register int
#define in inline
using namespace std;
struct edge
{
    int to,w,next;
}e[M<<1];
//vis数组表示已松弛的点
//book数组表示进入队列的点 
int head[N],vis[N],dis[N];
int m,n;
bool book[N];
in bool spfa(int s);
int main()
{
    ios::sync_with_stdio(false);
    int u,v,w;
    cin>>n>>m;
    for(ri i=1;i<=m;i++)
    {
        cin>>u>>v>>w;
        e[i]=(edge) {v,w,head[u]}; head[u]=i;
        e[i+m]=(edge) {u,-w,head[v]}; head[v]=i+m;
    }
    //关于对dis数组放在外面的理解:
	//从第一个点开始时，如果有的点没有被松弛，即该点无法到达，起点与该点没有关系
	//则从没有被松弛的点开始，则是两个完全无关的图，dis数组有没有置0毫无关系 
    fill(dis+1,dis+n+1,INF);
    //所有约束条件需要考虑到
    //可能有多个分块，前10个约束条件与后10个 无关联 
    for(ri i=1;i<=n;i++)
        if(!vis[i])
        {
            if(spfa(i))
            {cout<<"No"; return 0;}
            vis[i]=1;
        }	
    cout<<"Yes";
    return 0;
}
in bool spfa(int s)
{
    queue <int> q;
    int k;
    q.push(s); book[s]=1;
    dis[s]=0;
    while(q.size())
    {
        k=q.front(); q.pop();
        book[k]=0;//出队列应置为0 
        for(ri i=head[k]; i ;i=e[i].next)
        {
            int v=e[i].to;
            if(!vis[v]&& dis[k]<INF)
            {
                dis[v]=dis[k]+e[i].w;
                if(!book[v])
                {q.push(v); book[v]=1;}
                vis[v]=1;
            }
            else if(dis[k]<INF && dis[v]<INF && dis[v]!=dis[k]+e[i].w) return true;
            //此时相当于自相矛盾
            //思想：即先认定一开始所给条件均正确（此时松弛）
            //最后再来验证接下来的条件是否满足原先条件 
        }
    }
    return false;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define N 100010
using namespace std;
int num[N]={},dp[N]={},n,m,x,y;
vector<int> ft[N];
stack<int> S;
int main(){
	int i,j;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		ft[x].push_back(y);
		num[y]++;
	}
	for(i=0;i<n;i++)
	{
		if(num[i]==0)
		{
			S.push(i);
		}
	}
	while(S.size())
	{
		x=S.top();
		S.pop();
		for(i=0;i<ft[x].size();i++)
		{
			dp[ft[x][i]]=max(dp[ft[x][i]],dp[x]+1);
			num[ft[x][i]]--;
			if(num[ft[x][i]]==0)
			{
				S.push(ft[x][i]);
			}
		}
	}
	cout<<*max_element(dp,dp+n)<<endl;
	return 0;
}

Measured memory_bytes: 6528
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

ull n;
ull x=10;
ull ans;
int main(void) {
    cin >> n;
    if (n%2) {
        cout << 0 << endl;
        return 0;
    }
    while (x <= n) {
        ans += n/x;
        x *= 5;
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i, cc, n) for (int i = cc; i < n; ++i)
using ll = long long;
using namespace std;

int cnt_digits(ll N)
{
    int digits = 0;

    while (N > 0)
    {
        N /= 10;
        digits++;
    }

    return digits;
}
int main()
{
    ll N;
    cin >> N;

    int ans = cnt_digits(N);

    for (ll A = 1; A * A <= N; A++)
    {
        if (N % A != 0)
        {
            continue;
        }

        const int cur = max(cnt_digits(A), cnt_digits(N / A));

        if (cur < ans)
        {
            ans = cur;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x, &y, &r);
	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H) printf("Yes\n");
	else printf("No\n");
    return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

vector<vector<bool>> g(50,vector<bool>(50,false));
bool used[50];
int n,m;

void dfs(int x){
	used[x] = true;
	for(int i = 0; i < n; i++) {
		if (g[x][i] == false){
			continue;
		}
		if (used[i] == true){
			continue;
		}
		dfs(i);
	}
}


int main(){
	cin >> n >> m;
	vector<int> x(m);
	vector<int> y(m);
	for(int i = 0; i < m; i++) {
		cin >> x[i] >> y[i];
		g[x[i] - 1][y[i] - 1] = true;
		g[y[i] - 1][x[i] - 1] = true;
	}

	int ans = 0;
	for(int i = 0;i < m;i++){
		for(int j = 0; j < n; j++) {
			used[j] = false;
		}
		g[x[i] - 1][y[i] - 1] = false;
		g[y[i] - 1][x[i] - 1] = false;
		
		dfs(0);

		bool flag = false;
		for(int j = 0; j < n; j++) {
			// cout << j << endl;
			if (used[j] == false){
				flag = true;
				break;
			}
		}
		if (flag){
			ans++;
		}

		g[x[i] - 1][y[i] - 1] = true;
		g[y[i] - 1][x[i] - 1] = true;
	}
	
	cout << ans << endl;
	return 0;
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var a = int.Parse(ss[0]);
            var b = int.Parse(ss[1]);
            var c = int.Parse(ss[2]);

            Console.WriteLine(b - a == c - b ? "YES" : "NO");
        }
    }
}

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

vector<string> hist;

int main(){
while(1){//start
	
	int l;
	string s;
	cin >> s >> l;
	string cpy = s;
	if(s == "0" and l == 0) break;
	
	for(int i = 0; i < 25; i++){
		int len = s.size();
		hist.push_back(s);
		//padding
		for(int j = 0; j < l - len; j++) s += "0";
		sort(s.begin(), s.end());
		string s_mi = s;
		string s_ma = s_mi;
		reverse(s_ma.begin(), s_ma.end());
		
		int mi = stoi(s_mi);
		int ma = stoi(s_ma);
		//cout << "mi = " << mi << endl;
		//cout << "ma = " << ma << endl;
		int next = ma - mi;
		s = to_string(next);
}
	
	//for(int i = 0; i < (int)hist.size(); i++) cout << hist[i] << endl;
	
	if(cpy == "0") cout << 0 << " " << 0 << " " << 1 << endl;
	else{
		int flag = 0;
		for(int i = 0; i < (int)hist.size(); i++){
			for(int j = 0; j < (int)hist.size(); j++){
				if(i != j and hist[i] == hist[j] and j > i){
					cout << i << " " << hist[i] << " " << j - i << endl;
					flag = 1;
					break;
				}
				if(flag) break;
			}
		}
		
	}
	
	hist.clear();
}//end
	
	return 0;
}


Measured memory_bytes: 3196
n=int(input())
a=list(map(int,input().split()))

bl=[]
br=[]
if n%2==0:
    for i in range(0,n-1,2):
        bl.append(a[i]) 
        br.append(a[i+1]) 
    br.reverse()
    br=br+bl
else:
    for i in range(0,n-2,2):
        bl.append(a[i]) 
        br.append(a[i+1]) 
    bl.append(a[n-1]) 
    bl.reverse()
    br=bl+br
    
for i in range(len(br)):
    print(br[i],end=" ")
print()


Measured memory_bytes: 26180
def main():
    n = int(input())
    ans = solve(n)
    print(ans)


def solve(n):
    nn = n % 10
    ans = ''
    if nn in [2, 4, 5, 7, 9]:
        ans += 'hon'
    elif nn in [0, 1, 6, 8]:
        ans += 'pon'
    elif nn in [3]:
        ans += 'bon'
    return ans


if __name__ == '__main__':
    main()

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

int main() {
    ll a, b;
    cin >> a >> b;
    a--;
    if (a<0) a++;
    ll va = 0, vb = 0;
    vector<ll> places(44,0);
    for (ll i=1; i<=44; i++) {
        ll x = 1;
        for (ll j=0; j<i; j++) x*=2;
        ll y = b;
        places[i-1] = (b/x)*(x/2);
        y%=x;
        y-=(x/2)-1;
        if (y>0) places[i-1] += y;
        y = a;
        places[i-1] -= (a/x)*(x/2);
        y%=x;
        y-=(x/2)-1;
        if (y>0) places[i-1] -= y;
    }
    for (ll i=0; i<44; i++) places[i]%=2;
    ll res = 0;
    for (ll i=0; i<44; i++) if (places[i]>0) {
        ll x = 1;
        for (ll j=0; j<i; j++) x*=2;
        res+=x;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int M = in.nextInt();
        int S = N*(N-1)/2+M*(M-1)/2;
        System.out.print(S);
    }
 
}

Measured memory_bytes: 23764
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, K] = list(map(lambda x: int(x), inputs[0].split()))
    pattern = K * ((K - 1) ** (N - 1))
    return pattern


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3060
n = int(input())
h = list(map(int, input().split()))
ans, count = 1, 0
for i in range(len(h)-1, 0, -1):
    for j in range(i-1, -1, -1):
        if h[i] >= h[j]:
            count += 1
    if count == i:
        ans += 1
    count = 0
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    string str;
    cin>>str;
    int n=str.size();
    if(str[n-1]=='s')cout<<str<<"es"<<endl;
    else cout<<str<<"s"<<endl;
    return 0;
}

Measured memory_bytes: 3628
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func scanString() (s string) {
	sc.Scan()
	return sc.Text()
}

func main() {
	input := scanString()
	if input[2] == input[3] && input[4] == input[5] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using namespace std;


int main() {


  string s,t;
  cin >> s >> t;


  if(t.length() != s.length()+1){
    cout << "No"<<endl;
    return 0;
  }
    
    for(int i=0 ; i<s.length() ; i++){
      if(s[i]!=t[i]){
          cout << "No"<<endl;
	  return 0;
      }
    }
  


    cout << "Yes"<<endl;
  
  
  return 0;
}



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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

const int INF = 1e9+7;

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

  int k, n;
  cin >> k >> n;
  vector<int> A(n+1);
  rep(i, 0, n) {
    cin >> A[i];
  }

  A[n] = k + A[0];
  sort(All(A));


  vector<int> ans(n);
  rep(i, 0, n) {
    ans[i] = A[i+1] - A[i];
  }

  sort(All(ans));

  cout << k - ans[n-1] << endl;

  return 0;
};


Measured memory_bytes: 1792
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 100000001
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int dp[120][1050];

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    //double mini=INF;
    int maxi=0,f=0,sum=0,mini=INF;
    string str,str1,str2;
    int i;
    int n;
    int a,b,d,c;
    int e,weight;
        ll s;

    ll h,w;
    cin>>str;
    n=0;
    e=0;
    s=0;
    w=0;
    rep(i,str.length()){
        if(str[i]=='N') n=1;
        if(str[i]=='S') s=1;
        if(str[i]=='E') e=1;
        if(str[i]=='W') w=1;
    }
    if(n==1&&e==1&&s==1&&w==1){
        Yes;
    }
    else if(n==0&&e==1&&s==0&&w==1){
        Yes;
    }
    else if(n==1&&e==0&&s==1&&w==0){
        Yes;
    }else{
        No;
    }
    //cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
int n, s, i, j, skip, nextskip;
vector<int> a, sz, top, p, nextp;

int PatienceSorting(int nexti){
// computing |P_k| for all k with [i + 1, min(j, lis(a))] when P_i is given
    int r = -1;
    int l = -1;
    nextskip = -1;
    if(p[0] == -1) r = 0;
    for(int x = 0; x < 2 * s; x++){
        top[x] = INF;
        sz[x] = 0;
    }
    // for(int x = 0; x < p.size(); x++){
    //     cout << " " << p[x];
    // }
    // cout << endl;
    for(int x = 0; x < n; x++){
        // filtering out irrelevant elements
        if(x < skip) continue;
        if(r + 1 < p.size() && a[x] == p[r + 1]){
            r++;
            continue;
        }else if(r == -1 || a[x] < p[r] || (l >= j && a[x] > top[j])){
            continue;
        }
        // push a[x] to the appropriate pile
        int h;
        if(l == -1 || a[x] > top[l]){
            l++;
            h = l;
        }else{
            h = lower_bound(top.begin(), top.end(), a[x]) - top.begin();
        }
        assert(0 <= h && h <= j);
        if(h == nexti){
            if(nextskip == -1) nextskip = x;
            nextp.push_back(a[x]);
        }
        top[h] = a[x];
        sz[h]++;
        // cout << x << ' ' << a[x] << ' ' << h << endl;
    }
    return l;
}

int main(){
    cin >> n;
    s = sqrt(n) + 1;
    a.resize(n);
    sz.resize(2 * s);
    top.resize(2 * s);
    set<int> st;
    for(int x = 0; x < n; x++){
        cin >> a[x];
    }
    i = 0; j = 2 * s - 1;
    int ans = 0;
    p.push_back(-1);
    while(1){
        int l = PatienceSorting(-1);
        if(l < 2 * s - 1){
            ans += l + 1;
            break;
        }
        assert(l == 2 * s - 1);
        int nexti = -1;
        for(int x = 2 * s - 1; x >= s; x--){
            if(sz[x] <= s && sz[x] > 0){
                nexti = x;
                break;
            }
        }
        assert(s <= nexti && nexti < 2 * s);
        nextp.clear();
        PatienceSorting(nexti);
        p = nextp;
        skip = nextskip;    
        // i = 0;
        // j = 2 * s - 1;
        ans += nexti + 1;
        // cout << nexti + 1 << ' ' << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3396
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main ()
{
  prep();
  int n;
  cin >> n;
  int arr[n];
  for (int i=0; i<n; i++){
      cin >> arr[i];
  }
  set<int> st;
  int cnt = 0;
  for (int i=0; i<n; i++){
      st.insert(arr[i]);
      set<int>::iterator it = st.lower_bound(arr[i]);
      if (it == st.begin()){
          cnt++;
      }
  }
  cout << cnt;
  return 0; 
}


Measured memory_bytes: 10368
#include <iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

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

	for (int i = 0; i < 19; i++) {
		if (s[i] == ',') {
			s[i] = ' ';
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, m, a[200], cnt;
long long s;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s += a[i];
    }
    for (int i = 0; i < n; i++) {
        if (a[i] * 1LL * 4 * m >= s) cnt++;
    }
    if (cnt >= m) cout << "Yes" << E;
    else cout << "No" << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1,1,-1,-1,2,2,-2,-2}; //knight moves
///int ky[]={2,-2,2,-2,1,-1,1,-1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};  //eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};  //eight direction
 
///using namespace __gnu_pbds;
using namespace std;
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
    ll n;
    while(sf("%lld",&n)==1)
    {
    	ll ara[n+5];
    	for(ll i=1;i<=n+1;i++)sf("%lld",&ara[i]);
    	ll bra[n+5];
    	for(ll i=1;i<=n;i++)sf("%lld",&bra[i]);

    	ll tot=0;
    	for(ll i=1;i<=n;i++)
    	{
    		ll mn=min(ara[i],bra[i]);
    		tot+=mn;
    		bra[i]-=mn;

    		mn=min(ara[i+1],bra[i]);
    		tot+=mn;
    		ara[i+1]-=mn;
    	}
    	pf("%lld\n",tot);
    }
    return 0;
}
 









 




























Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

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

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int main()
{
	int n;
	ll m;
	cin >> n >> m;
	ll k = sqrt(m) + 1;
	vector<bool> done(k + 1, false);
	list<int> p;
	int ma = 0;
	for (int i = 2; i <= k && m > 1; i++)
	{
		if (done[i])
			continue;
		for (int j = i * 2; j <= k; j += i)
			done[j] = true;
		if (m % i != 0)
			continue;
		int l = 0;
		while (m % i == 0)
			m /= i, l++;
		p.push_back(l);
		if (l > ma)
			ma = l;
	}
	
	if (m != 1)
		p.push_back(1);
	if (ma == 0)
		ma = 1;
	//	n+p[i]-1 C n-1を各iに対して求め、掛け合わせる
	vector<mod> combi(ma + 1);
	combi[1].val = n;
	for (int i = 2, x = n + 1, y = 2; i <= ma; i++, x++, y++)
		combi[i] = combi[i - 1], combi[i] *= x, combi[i] /= y;
	mod r(1);
	for (auto it : p)
		r *= combi[it];

	std::printf("%lld", r.val);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    void solve(){
        String[] D = {"thu", "fri", "sat", "sun", "mon", "tue", "wed"};
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        System.out.println(D[x%7]);
    }

    public static void main(String[] args){ new Main().solve(); }
}




Measured memory_bytes: 26268
N = int(input())
nums = list(map(int, input().split()))

odds = 0
for i in nums:
    if(i%2 != 0):
        odds += 1

if(len(nums) <= 1):
    print('YES')
else:
    if(odds%2 == 0):
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 14112
#include <stdio.h>

int main() {
    int idx = 0;
    char c, str[20];
    while (scanf("%c", &c) && c != '\n') {
        if (c == '0' || c == '1') {
            str[idx++] = c;
        }
        else {
            idx--;
            if (idx < 0) {
                idx = 0;
            }
        }
    }
    str[idx] = '\0';
    printf("%s\n", str);
    return 0;
}


Measured memory_bytes: 1536
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

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

	let mut ans = 0;
	for i in 1..=n {
		let sum = i/10000 + (i%10000)/1000 + (i%1000)/100 + (i%100)/10 + i%10;
		if a <= sum && sum <= b {
			ans += i;
		} 
	}
	println!("{}", ans);
}



Measured memory_bytes: 2156
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String numStr;
		while (true) {
			numStr = sc.next();
			if (numStr.equals("0"))
				break;

			outSumOfNumbers(numStr);

		}

	}

	public static void outSumOfNumbers(String numStr) {
		byte[] sbyte = new byte[numStr.length()];
		int sum = 0;

		for (int i = 0; i < numStr.length(); i++) {
			sbyte[i] = (byte) numStr.charAt(i);
			sbyte[i] -= 48;
			sum += sbyte[i];
		}
		
		System.out.println(sum);
	}

}

Measured memory_bytes: 26280
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
#include <map>
using namespace std;

map<char, char> sym;

void init() {
  sym['i'] = 'i';
  sym['w'] = 'w';
  sym['('] = ')';
  sym[' '] = ' ';
  sym[')'] = '(';
}

int main() {
  init();
  
  string str;
  getline(cin, str);
  
  int n = str.size();
  int cnt = 0;
  if(str == "") goto fin;
  for(int i=0; i<n/2+1; i++) {
    if(sym[str[i]] != str[n-i-1]) cnt ++;
    str[n-i-1] = sym[str[i]];
  }
 fin:
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1184
package main

import (
	"fmt"
	"strings"
)

func another(bef string) string {
	if bef == "0" {
		return "1"
	}
	return "0"
}

func main() {
	var s string
	fmt.Scan(&s)

	slices := strings.Split(s, "")
	
	ans := 0
	for i, v := range slices {
		if i == 0 {
			continue
		}
		
		if v == slices[i-1] {
			slices[i] = another(slices[i])
			ans++
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 2944
while True:
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    a = list(map(int,input().split()))
    
    b = 0
    for i in range(n):
        for j in range(i+1,n):
            if m < a[i] + a[j]:
                continue
            b = max(b,a[i] + a[j])
    if b == 0:
        print("NONE")
    else:
        print(b)


Measured memory_bytes: 5624
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
#include <iostream>

using namespace std;
int main() {
	int num;
	int ans;
	cin >> num;
	ans = (num+1) / 2 ;

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define mod 998244353

using namespace std;
typedef long long ll;
const int MAXN = 405;
int n,a[MAXN],b[MAXN];
ll prb[MAXN],pw[MAXN][MAXN],f[MAXN][MAXN][MAXN],c[MAXN][MAXN],inv[MAXN];
int prea[MAXN],sum,preb[MAXN];
inline ll qpow(ll a, int b)
{
	ll res = 1;
	b = (b+mod-1)%(mod-1);
	for(; b; a = a*a%mod, b >>= 1)
	    if(b&1)
			res = res*a%mod;
	return res; 
}

int main()
{
	cin >> n;
	for(int i = 1; i<=n; i++)
	{
		cin >> a[i] >> b[i];
	    prea[i] = prea[i-1]+a[i], preb[i] = preb[i-1]+b[i];
	}
	sum = prea[n];
	for(int i = 1; i<=n; i++)
	{
		prb[i] = a[i]*qpow(sum,-1)%mod;
		pw[i][0] = 1;
		for(int j = 1; j<MAXN; j++)
			pw[i][j] = pw[i][j-1]*prb[i]%mod;
	}
	for(int i = 0; i<MAXN; i++)
		c[i][0] = c[i][i] = 1;
	for(int i = 2; i<MAXN; i++)
		for(int j = 1; j<i; j++)
			c[i][j] = (c[i-1][j-1]+c[i-1][j])%mod;
	inv[0] = 1;
	for(int i = 1; i<MAXN; i++)
		inv[i] = inv[i-1]*qpow(i,-1)%mod;
	f[0][0][0] = mod-1;
	for(int i = 1; i<=n; i++)
		for(int j = 0; j<=preb[i]; j++)
			for(int k = 0; k<=prea[i]; k++)
			{
				f[i][j][k] = (f[i][j][k]+f[i-1][j][k])%mod;
				if(k-a[i]>=0)
					for(int x = 0; x<b[i]&&x<=j; x++)
						f[i][j][k] = (f[i][j][k]-f[i-1][j-x][k-a[i]]*inv[x]%mod*pw[i][x]%mod+mod)%mod;
			}
	ll ans = 0;
	for(int j = 0; j<=preb[n]; j++)
		for(int k = 0; k<=sum; k++)
			ans = (ans+f[n][j][k]*qpow(inv[j],-1)%mod*qpow(sum*qpow(k,-1)%mod,j+1)%mod)%mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 516864
SA = list(input())
SB = list(input())
SC = list(input())
tmp = SA.pop(0)
while True:
    if tmp == 'a':
        if len(SA) == 0:
            print('A')
            exit()
        tmp = SA.pop(0)
    elif tmp == 'b':
        if len(SB) == 0:
            print('B')
            exit()
        tmp = SB.pop(0)
    elif tmp == 'c':
        if len(SC) == 0:
            print('C')
            exit()
        tmp = SC.pop(0)

Measured memory_bytes: 3064
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]

access = []
for i in 1..N do
  access[i-1] = []
end

for i in 1..M do
  from = lines[i][0]
  to = lines[i][1]
  access[from-1].push(to)
  access[to-1].push(from)
end

visited = []
for i in 1..N do
  visited[i-1] = false
end

num_member = 0
max_num_member = 0
for i in 1..N do
  if visited[i-1] == false then
    num_member = 0
    targets = [i]
    while targets != [] do
      num_member += 1
      j = targets.pop
      visited[j-1] = true
      access[j-1].each do |k|
        if visited[k-1] == false then
          targets.push(k)
          visited[k-1] = true
        end
      end
    end
    if max_num_member < num_member then
      max_num_member = num_member
    end
  end
end
    
puts max_num_member

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

using namespace std;
typedef long long ll;
const int inf=1e9+1;
int main(){

    ll n;
  cin >> n;
  ll ar[n];
  for (ll i=0;i<n;i++)
  {
    cin >> ar[i];
  }
  vector<ll> dp(n);
  dp[0]=0;
  dp[1]=abs(ar[1]-ar[0]);
  for (ll i=2;i<n;++i)
  {
      dp[i]=min(dp[i-1]+abs(ar[i]-ar[i-1]),dp[i-2]+abs(ar[i]-ar[i-2]));
  }
  cout << dp[n-1];

    return 0;
}



Measured memory_bytes: 1792