akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
using namespace std;
int main()
{
    char s,k;
    int sum=0;
    scanf("%c",&s);
    printf("%c",s);
    while(scanf("%c",&s)!=-1)
	{
        if(s==' '||s=='\n')break;
        sum++;
        k=s;
    }
    printf("%d%c",sum-1,k);
    return 0;
}

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

using namespace std;

int main() {
  int n, ans = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += (a - 1);
  }

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


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

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(void){
    vector<int> v(3);
    for(int i = 0; i < 3; i++) cin >> v.at(i);
    sort(v.begin(), v.end());
    cout << v.at(0) + v.at(1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

void Eratosthenes(int prime[],int n){
    prime[0]=0;
    prime[1]=0;
    for(int i=2; i<=sqrt(n); i++){
        if (prime[i]){
            for (int j=0; i*(j+2)<n; j++){
                prime[i*(j+2)]=0;
            }
        }
    }
}

int main(){
    int n=100001;
    int prime[n];
    for (int i=0; i<n; i++){
        prime[i]=1;
    }
    Eratosthenes(prime,n);
    int resemble[100001]={0};
    for (int i=3; i<n; i++){
        if (i%2==1){
            if(prime[i]&&prime[(i+1)/2]){
                resemble[i]++;
            }
        }
        resemble[i]+=resemble[i-1];
    }
    int q;
    cin >> q;
    for (int i=0; i<q; i++){
        int l,r;
        scanf("%d %d", &l,&r);
        printf("%d\n", resemble[r]-resemble[l-1]);
    }
}

Measured memory_bytes: 1408
def gcd(x, y):
    '''??????????????????????????????
    x>=y?????¨??????gcd(x, y)??¨gcd(y, x%y)?????????????????¨????????¨??????'''

    if x < y:
        x, y = y, x

    while y > 0:
        x, y = y, x % y

    return x
    
def test():
    '''??? input =
    147 105
    ->
    21'''

    x, y = map(int, input().split())

    result = gcd(x, y)
    print(result)

if __name__ == '__main__':
    test()

Measured memory_bytes: 7692
import math

A, B, H, M = map(int, input().split())

Atheta = H * 30 + 0.5*M
Btheta = M * 6

theta = min(abs(Atheta - Btheta), abs(360 - (Atheta - Btheta)))

C = math.sqrt(pow(A, 2) + pow(B, 2) - 2 * A*B*math.cos(math.radians(theta)))
print(C)


Measured memory_bytes: 9496
#include<stdio.h>

int main(){
  int x,y,z;

  scanf("%d %d",&x,&y);

  if(x < y){
    z = x;
    x = y;
    y = z;
  }
  while(y > 0){
    z = x % y;
    x = y;
    y = z;
  }
  printf("%d\n",x);

  return 0;
}

Measured memory_bytes: 592
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        LinkedList<Character> l = new LinkedList<>();
        boolean isR = false;
        String s = sc.next();
        int q = sc.nextInt();

        for (char c : s.toCharArray()) {
            l.addLast(c);
        }

        for (int i = 0; i < q; i++) {
            int t = sc.nextInt();
            if (t == 1) {
                isR = !isR;
            } else {
                boolean isF = sc.nextInt() == 1;
                char c = sc.next().charAt(0);
                if (isF ^ isR) {
                    l.addFirst(c);
                } else {
                    l.addLast(c);
                }
            }
        }

        PrintWriter out = new PrintWriter(System.out);

        if (isR) {
            Collections.reverse(l);
        }

        for (char c : l) {
            out.print(c);
        }

        out.println();
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

}


Measured memory_bytes: 159328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ARC080
{
    public class D
    {
        private void Run()
        {
            var input = Console.ReadLine().Trim().Split();
            var H = int.Parse(input[0]);
            var W = int.Parse(input[1]);
            var N = int.Parse(Console.ReadLine().Trim());
            var a = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
            var strs = a.SelectMany((x, i) => Enumerable.Repeat(i + 1, x)).ToArray();

            var result = Enumerable.Range(0, H).Select(_ => new int[W]).ToArray();
            for (int i = 0; i < H * W; i++)
            {
                var y = i / W;
                var xx = i % W;
                int x = (y % 2 == 0 ? xx : W - 1 - xx);
                result[y][x] = strs[i];
            }
            Console.WriteLine(string.Join(Environment.NewLine, result.Select(arr => string.Join(" ", arr))));
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new D().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


Measured memory_bytes: 14176
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int x;
	scanf("%d", &x);
	int y = x / 100, z = x % 100;
	while (y && z > 0) {
		z -= 5;
		--y;
	}
	printf("%d\n", (z > 0 ? 0 : 1));
	Please AC;
}


Measured memory_bytes: 888
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=202202;
int a[N];
ll x,k,d;
ll m=1e18,mx,mn;
int main(){
	scanf("%lld%lld%lld",&x,&k,&d);
	x=abs(x);
	ll cnt=min(k,abs(x/d));
	ll pos=x-cnt*d;
	k-=cnt;
	if (k==0){
		printf("%lld\n",pos);
		return 0;	
	}
	ll ans1=fabs(pos),ans2=fabs(pos+d),ans3=fabs(pos-d);
//	printf("%lld %lld %lld\n",ans1,ans2,ans3);
	if (ans1<=ans2&&ans1<=ans3){
		if (k%2)	printf("%lld\n",abs(min(pos+d,pos-d)));
		else printf("%lld\n",abs(pos));
		return 0;
	}
	if (ans2<=ans1&&ans2<=ans3){
		if (k%2)	printf("%lld\n",abs(min(pos,pos-d)));
		else printf("%lld\n",abs(pos+d));
		return 0;
	}
	if (ans3<=ans1&&ans3<=ans2){
		k--;
		if (k%2)	printf("%lld\n",abs(min(pos,pos+d)));
		else printf("%lld\n",abs(pos-d));
		return 0;
	}
    return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>

int main(void) 
{
	int x, y, z;
	int tmp;
	
	scanf("%d %d %d", &x, &y, &z);
		if(x > y)
		{
			tmp = y;
			y = x;
			x = tmp;
		}
		if(y > z)
		{
			tmp = z;
			z = y;
			y = tmp;
		}
		if(x > y)
		{
			tmp = y;
			y = x;
			x = tmp;
		}
	
	printf("%d %d %d\n", x, y, z);
	return 0;
}

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

int main(){
  double a,b,c,d,e,f; cin>>a>>b>>c>>d>>e>>f;
  double water=100*a,sugar=0,rate=0;
  for(int i=0;i<=30;i++){
    for(int j=0;j<=16;j++){
      if(i==0 && j==0) continue;
      if(i*a*100+j*b*100>f) break;
      for(int k=0;k<=100;k++){
        if(c*k>(i*a+j*b)*e) break;
        for(int l=0;l<=100;l++){
          if(k==0 && l==0) continue;
          if(c*k+d*l>(i*a+j*b)*e) break;
          if(i*a*100+j*b*100+c*k+d*l>f) break;
          if(rate<(c*k+d*l)/(c*k+d*l+(i*a+j*b)*100)){
            rate=(c*k+d*l)/(c*k+d*l+(i*a+j*b)*100);
            sugar=c*k+d*l; water=c*k+d*l+(i*a+j*b)*100;
          }
        }
      }
    }
  }
  cout<<int(water)<<' '<<int(sugar)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

int n, z, s, a[N];
int main()
{
	int i;
	cin >> n;
	cin >> a[0];
	for (i = 1; i < n; i++) {
		scanf ("%d", &a[i]);
		if (a[i] > a[i - 1]) {
			if (z == 1) {s++; z = 0;}
			else z = 2;
		} else if (a[i] < a[i - 1]) {
			if (z == 2) {s++; z = 0;}
			else z = 1;
		}
	}
	cout << s + 1;
    return 0;
}


Measured memory_bytes: 640
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
   
    ll n,i,j,k;
    cin>>n;
    ll arr[n+2][4];
    for(i=0;i<n;i++)
    {
    	cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    ll dp[n+2][4];
    memset(dp,0,sizeof dp);
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];
    for(i=1;i<n;i++)
    {
    	for(j=0;j<3;j++)
    	{
    		for(k=0;k<3;k++)
    		{
    			if(k!=j) dp[i][j] = max(dp[i][j],dp[i-1][k] + arr[i][j]);
    		}
    	}
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if(A == B){
        cout << "Draw" << endl;
        return 0;
    }
    if(A == 1)
        cout << "Alice" << endl;
    else if(B == 1)
        cout << "Bob" << endl;
    else if (A > B)
        cout << "Alice" << endl;
    else 
        cout << "Bob" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n;
  cin >> n;
  vl a(n),b(n);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    cin >> b[i];
  }
  ll cnt=0;
  ll num=0,num1=0;
  rep(i,n){
    cnt+=b[i]-a[i];
    num+=max((ll)0,(b[i]-a[i]+1)/2);
    num1+=max((ll)0,(a[i]-b[i]));
  }
  if(cnt>=0&&cnt>=num&&cnt>=num1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
import sys

def p(t):
    for l in t:
        for n in l:
            print("{0:>3}".format(n),end="")
        print("")

c = 0
for n in sys.stdin:
    n = int(n)

    if n == 0:
        break

    t = [ [ 0 for _ in range(n) ] for _ in range(n) ]

    c += 1
    print("Case {}:".format(c))

    x = 0
    y = 0
    up= True
    for i in range(1,n*n+1):
#        print("{} {}".format(x,y))
        t[y][x] = i
        if up:
            if y == 0:
                if x < n-1:
                    x += 1
                    up = False
                else:
                    y += 1
                    up = False
            else:
                if x < n-1:
                    x += 1
                    y -= 1
                else:
                    y += 1
                    up = False
                    
        else:
            if x == 0:
                if y < n-1:
                    y += 1
                    up = True
                else:
                    x += 1
                    up = True
            else:
                if y < n-1:
                    x -= 1
                    y += 1
                else:
                    x += 1
                    up = True

    p(t)

    

Measured memory_bytes: 5652
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(int i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<int,int>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((int)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;




int main(){
	// FILE;
	SPEED;	
	double p;
	cin>>p;
	cout<<setprecision(20);
	cout<<(p/3)*(p/3)*(p/3)<<endl;


}


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

int main() {
  long n;
  cin>>n;
  long ans=0;
  rep2(i,1,360){
    if(360*i%n==0){
      ans=360*i/n;
      break;
    }
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>S>>T;
    bool yes = true;
    rep(i,3) if(S[i] != T[2-i]) yes = false;
    cout<<(yes ? "YES" : "NO")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int


int main()
{
	fast;
	int n;cin>>n;
	string s;cin>>s;
	int i=0,j=s.length()-1;
	int c=0;
	while(i<=j)
	{
		if(s[i]=='W' && s[j]=='R')
		{
			swap(s[i],s[j]);
			i++;
			j--;
			c++;
		}
		if(s[i]=='R')
		{
			i++;
		}
		if(s[j]=='W')
		{
			j--;
		}

	}
	cout<<c;

} 

Measured memory_bytes: 3708
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


ll rui(ll a,ll b){
     ll ans=1;
     while(b>0){
        if(b&1) ans=ans*a%MOD;
        a=a*a%MOD;
        b/=2;
    }
     return ans;
}

ll COM(ll a, ll b){
    ll ans = 1;
    for(ll i=a; i>a-b; i--){
        ans = ans * i % MOD;
    }
    for(ll i=1; i<=b; i++){
        ans =(ans*rui(i, MOD-2)) % MOD;
    }
    return ans;
}

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    rep(i, INF){
        ;
    }

    cout<<(MOD + MOD + rui(2,n)-COM(n,a)-COM(n,b)-1)%MOD<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN   
#define linf LLONG_MAX
#define lninf LLONG_MIN   
const ll mod=1e9+7;
const int N=1e5+4;

int main()
{
	int n; scn(n);

	int a[n];

	rep(i,0,n)
	scn(a[i]);

	int L; scn(L);

	int dp[n][21];

	for(int i=n-1;i>=0;i--)
	{
		int ind = upper_bound(a,a+n,a[i]+L) - a; ind--;

		dp[i][0] = ind;

		// cout<<i<<" "<<ind<<endl;

		for(int j=1;j<21;j++)
		dp[i][j] = dp[dp[i][j-1]][j-1];
	}

	int q; scn(q);

	// cout<<dp[0][1]<<endl;

	while(q--)
	{
		int x,y; scn(x); scn(y); x--; y--;

		if(x > y)
		swap(x,y);

		int cur = x,ans = 0;

		for(int i=20;i>=0;i--)
		if(dp[cur][i] < y)
		cur = dp[cur][i], ans+=(1<<i);

		ans++;

		priln(ans);
	}

	return 0;
}


Measured memory_bytes: 12316
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  var A = Number.parseInt(inputStr[0]);
  var B = Number.parseInt(inputStr[1]);
  var C = Number.parseInt(inputStr[2]);
  var ANS = 0;
  
  if (A > B) { 
	ANS = 0;
  } else if ( A*C <= B) {
    ANS = C;
  } else {
    ANS = Math.floor(B/A);
  }
  console.log(ANS);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
n,m,c=map(int, input().split())
B=list(map(int, input().split()))
g=0
t=0
for i in range(n):
  A=list(map(int, input().split()))
  for i in range(m):
    t+=A[i]*B[i]
  if t+c>0:
    g+=1
  t=0
print(g)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<algorithm>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int d=0;
	int star=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='(')
			d++;
		else if(s[i]==')')
			d--;
		else
			star=d;
	}
	cout << max(0,star-max(0,d)) << endl;




}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9



int main(){
  ll Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  ll sum = 0;
  sum += min(Q*8, min(H*4, min(S*2, D))) *(N/2);
  N = N%2;
  sum += min(Q*4, min(H*2, S)) * N;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n, d;
  cin >> n >> d;

  int ans = n / (2*d+1) + 1;
  if(n % (2*d+1) == 0) --ans;

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

Measured memory_bytes: 3544
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#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 int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int n,k,x = 1;
    cin >> n >> k;
    x = 1;
    rep(i,n-1){
        x *= k - 1;
    }   
    cout << k * x << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#define INF 10000000
using namespace std;
typedef pair<int, int> P;
int h, w, n;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int d[1000][1000];
string field[1000];
P pos[10];
int bfs(P s, P g) {
    queue<P> que;
    for (int i=0; i<h; i++)
        for (int j=0; j<w; j++) d[i][j]=INF;
    que.push(P(s.first, s.second));
    d[s.first][s.second]=0;
    while (!que.empty()) {
        P p = que.front(); que.pop();
        if (p.first==g.first&&p.second==g.second) break;
        for (int i=0; i<4; i++) {
            int nx=p.first+dx[i], ny=p.second+dy[i];
            if (0<=nx&&nx<h&&0<=ny&&ny<w&&field[nx][ny]!='X'&&d[nx][ny]==INF) {
                que.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[g.first][g.second];
}
int main() {
    scanf("%d%d%d",&h,&w,&n);
    for (int i=0; i<h; i++) {
        cin >> field[i];
        for (int j=0; j<w; j++) {
            if (field[i][j]>'0'&&field[i][j]<='9') {
                pos[field[i][j]-'0']=make_pair(i,j);
            } else if (field[i][j]=='S') {
                pos[0]=make_pair(i,j);
            }
        }
    }
    int res=0;
    for (int i=0; i<n; i++) {
        res+=bfs(pos[i], pos[i+1]);
    }
    printf("%d\n",res);
}

Measured memory_bytes: 5848
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++) 
using namespace std;
int total;
void rec(int a,int b,int cnt,int limit){
  if(cnt >= limit)return;
  if(a < b){
    rec(a*10,b,cnt+1,limit);
  }
  else{
    if(cnt != 0)total += a/b;
    rec((a-a/b*b)*10,b,cnt+1,limit);
  }
}

int main(){
  int n; double a,b; 
  while(cin >> a >> b >> n){
    //cout << setiosflags(ios::fixed) << setprecision(10) <<  a/b << endl;
    total = 0;
    rec(a,b,0,n+1);  
    cout << total << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
N,M,Q = map(int,input().split())
ls_rq = [list(map(int, input().split())) for i in range(Q)]

#深さ優先探索により各数列を生成する
As=[]
from queue import LifoQueue as lq
S=lq()
S.put([])
while not S.empty():
  a=S.get()
  if len(a)==N:
    As.append(a)
  else:
    if len(a)==0:
      b=1
    else:
      b=a[-1]
    for  i in range(b,M+1):
      S.put(a+[i])

#各数列のスコアを求める
ls_score=[]
for ls in As:
  score=0
  for j in range(Q):
    if ls[ls_rq[j][1]-1]-ls[ls_rq[j][0]-1]==ls_rq[j][2]:
      score+=ls_rq[j][3]
  ls_score.append(score)    
  score=0

#スコアの最大値を求める  
ans=max(ls_score)  
print(ans)  


Measured memory_bytes: 102960
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 250000
ll MOD=998244353;

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



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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,m; cin>>n>>m;
	char a[n][n], b[m][m];
	for (int i=0; i<n; i++)
		for (int j=0; j<n; j++)
			cin>>a[i][j];
	for (int i=0; i<m; i++)
		for (int j=0; j<m; j++)
			cin>>b[i][j];
	for (int i=0; i<=n-m; i++) for (int j=0; j<=n-m; j++) {
		bool ok=true;
		for (int x=0; x<m; x++) for (int y=0; y<m; y++)
			if(a[i+x][j+y]!=b[x][y]) ok=false;
		if(ok) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


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

int main(){
    ll N;
    cin >> N;
    ll sum=0;
    // rep(i,N){
    //     if(i==N-1){
    //         sum += (i+1)%1;
    //         cout << (i+1)%1 << endl;
    //     }else{
    //         sum += (i+1)%(i+2);
    //         cout << (i+1)%(i+2) << " ";
    //     }
    // }
    ll Sn = (N-1) * N / 2;
    cout << Sn << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <array>
#include <cmath>
#include <random>
#include <functional>
#include <climits>
#include <iomanip>
using namespace std;
using lint=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lint n,sum=0,smax=0;
  cin>>n;
  smax=((1+n)*n)/2;
  for(lint i=1;i<=n;i++) if(i%3==0||i%5==0) sum+=i;
  cout<<smax-sum<<endl;
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	long long sum=0;
	map<string,long long> mp1; 
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		mp1[s]++;
		if(mp1[s]>1){
			sum=sum+mp1[s]-1;
		}
	}
	printf("%lld",sum);
}

Measured memory_bytes: 11136
#include <stdio.h>

int main()
{
    int n, i, j, k, l, ans;
    while(scanf("%d", &n)!=EOF)
    {
        ans=0;
        for(i=0; i<10; i++)
        {
            for(j=0; j<10; j++)
            {
                for(k=0; k<10; k++)
                {
                    for(l=0; l<10; l++)
                    {
                        if(i+j+k+l==n)ans++;
                    }
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 596
#include <vector>
#include <numeric>
#include <iostream>

using namespace std;

int main()
{
	int n, k, m;

	vector<int> stone;

	while (true)
	{
		cin >> n >> k >> m;

		if (n == 0 && m == 0 && k == 0) { break; }

		stone = vector<int>(n);

		iota(stone.begin(), stone.end(), 1);

		int ptr = m - 1;

		while (stone.size() != 1)
		{
			stone.erase(stone.begin() + ptr);

			ptr = (ptr + k - 1) % stone.size();
		}

		cout << stone[0] << endl;
	}

	return 0;
}

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

int main(){
  int N; cin >> N;
  vector<int> MY(N);
  for(int i=0;i<N;i++){
    cin >> MY[i];
  }
  vector<int> ans(N);
  int USI=0;
  int now=0;
  while(true){
    if(MY.size()==0){
      break;
    }
    if(MY[0]!=1){
      cout << -1 << endl;
      return 0;
    }
    for(int i=0;i<MY.size();i++){
      if(i+1==MY[i]){
        USI=i;
      }
    }
    MY.erase(MY.begin()+USI);
    ans[now]=USI+1;
    now++;
  }
  for(int i=N-1;i>=0;i--){
    cout << ans[i] << endl;
  }
}
        

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

int32_t main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int x; cin >> x;
  cout << ((x >= 30) ? "Yes\n" : "No\n");

  return 0;
}

Measured memory_bytes: 3644
n, m = gets.chomp.split.map(&:to_i)
success = 0
penalty = 0
result = {}
m.times do
  p, s = gets.chomp.split.map(&:to_s)
  if s == 'WA'
    if result[p].nil?
      result[p] = {'WA' => 1, 'AC' => 0}
    elsif result[p]['AC'] < 1
      result[p]['WA'] += 1
    end
  else
    if result[p].nil?
      result[p] = {'WA' => 0, 'AC' => 1}
      success += 1
    elsif result[p]['AC'] < 1
      result[p]['AC'] = 1
      success += 1
      penalty += result[p]['WA']
    end
  end
end

puts "#{success} #{penalty}"

Measured memory_bytes: 43004
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

/*bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}*/
ll arr[2010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(8);
    ll N, Z, W;
    cin >> N >> Z >> W;

    for (int i = 0; i < N; ++i)
    {
        cin >> arr[i];
    }
    if (N == 1)
    {
        cout << abs(arr[0] - W) << endl;
        return 0;
    }
    ll ans = 0;

    ans = max(abs(arr[N - 1] - arr[N - 2]), abs(arr[N - 1] - W));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace ALDS1_5_C {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            Print(0.0, 0.0);
            Koch(n, 0.0, 0.0, 100.0, 0.0);
            Print(100.0, 0.0);
        }

        static void Koch(int n,double ax,double ay,double bx,double by) {
            if (n == 0)
                return;
            
            double sx = (2.0 * ax + bx) / 3.0;
            double sy = (2.0 * ay + by) / 3.0;
            double tx = (ax + 2.0 * bx) / 3.0;
            double ty = (ay + 2.0 * by) / 3.0;

            double rad = Math.PI * 60 / 180;
            double sin = Math.Sin(rad);
            double cos = Math.Cos(rad);
            double dx = tx - sx;
            double dy = ty - sy;
            double ux = dx * cos - dy * sin + sx;
            double uy = dx * sin + dy * cos + sy;

            n--;
            Koch(n, ax, ay, sx, sy);
            Print(sx, sy);
            Koch(n, sx, sy, ux, uy);
            Print(ux, uy);
            Koch(n, ux, uy, tx, ty);
            Print(tx, ty);
            Koch(n, tx, ty, bx, by);
        }

        static void Print(double x,double y) {
            Console.WriteLine("{0:f8} {1:f8}", x, y);
        }
    }
}

Measured memory_bytes: 9392
#include <stdio.h>

int N, x;

int main(void)
{
	scanf("%d%d", &N, &x);

	if (x == 1 || x == (2 * N) - 1)
	{
		printf("No\n");
	}
	else if (N == 2)
	{
		printf("Yes\n");
		printf("1\n2\n3\n");
	}
	else
	{
		printf("Yes\n");
		for (int i = 0; i < (2 * N) - 1; ++i)
		{
			printf("%d\n", (i + N + x - 1) % (2 * N - 1) + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 1408
from itertools import permutations

n,m,r=list(map(int,input().split()))
rlst=list(map(int,input().split()))
inf=10**20

d=[[inf]*(n+1) for _ in range(n+1)]

for _ in range(m):
    a,b,c=list(map(int,input().split()))
    d[a][b]=c
    d[b][a]=c

for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
ans=inf
for comb in permutations(rlst,r):
    i=0
    tans=0

    while i+1<r:
        tans+=d[comb[i]][comb[i+1]]
        i+=1
    
    ans=min(ans,tans)

print(ans)

Measured memory_bytes: 76912
N, M, K = map(int, input().split())
block_list = [[i] for i in range(N)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def same(self, x, y):
        return self.find(x) == self.find(y)

uf = UnionFind(N)
for i in range(M):
  a, b = map(int, input().split())
  uf.union(a-1, b-1)
  block_list[a-1].append(b-1)
  block_list[b-1].append(a-1)
for i in range(K):
  a, b = map(int, input().split())
  if uf.same(a-1, b-1):
    block_list[a-1].append(b-1)
    block_list[b-1].append(a-1)
ans = []
for i in range(N):
  ans.append(uf.size(i) - len(block_list[i]))
print(*ans)

Measured memory_bytes: 43736
# -*- coding: utf-8 -*-

def main():
    # 入力
    N = int(input())
    nums = list(map(int, input().split()))

    # 探索
    alice_sum = 0
    bob_sum = 0

    nums.sort(reverse=True)
    for i in range(len(nums)):
        if i % 2 == 0:
            alice_sum += nums[i]
        else:
            bob_sum += nums[i]

    print(alice_sum - bob_sum)


main()


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

int main() {
  int64_t a, b, k;
  cin >> a >> b >> k;
  if(a >= k) cout << a-k << ' ' << b << endl;
  else if (a < k && a+b >= k) cout << 0 << ' ' << a+b-k << endl;
  else cout << 0 << ' ' << 0 << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <functional>

using namespace std;

typedef pair<int, int> P;
typedef pair<double, int> R;
typedef pair<P, R> Q;

int main() {
	int n, hx, hy, dx, dy;
	double r;
	while (cin >> n >> hx >> hy >> dx >> dy) {
		if (n == 0 && hx == 0 && hy == 0 && dx == 0 && dy == 0) {
			break;
		}
		hx -= dx;
		hy -= dy;
		vector<P> data;
		int x, y;
		for (int i = 0; i < n; i++) {
			cin >> x >> y;
			x -= dx;
			y -= dy;
			data.push_back(P(x, y));
		}
		vector< vector<double> > data2(n, vector<double>(n));
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				data2[i][j] = data2[j][i] = sqrt(pow(data[i].first-data[j].first, 2)+pow(data[i].second-data[j].second, 2));
			}
		}
		vector<double> data3(n);
		for (int i = 0; i < n; i++) {
			data3[i] = sqrt(pow(data[i].first, 2)+pow(data[i].second, 2));
		}
		queue<Q> q;
		q.push(Q(P(hx, hy), R(0.0, 0)));
		bool hantei = false;
		while (!q.empty()) {
			Q p = q.front();
			q.pop();
			P xy = p.first;
			R limit = p.second;
			for (int i = 0; i < n; i++) {
				bool hantei2 = true;
				if ((limit.second & (1<<i)) == 0) {
					double dead = limit.first+sqrt(pow(data[i].first-xy.first, 2)+pow(data[i].second-xy.second, 2));
					if (data3[i] > dead) {
						int k = limit.second | (1<<i);
						if (k == (1<<n)-1) {
							hantei = true;
							break;
						}
						for (int j = 0; j < n; j++) {
							if ((k & (1<<j)) == 0) {
								if (data3[j] <= dead+data2[i][j]) {
									hantei2 = false;
									break;
								} 
							}
						}
						if (hantei2) {
							q.push(Q(data[i], R(dead, k)));
						}
					}
				}
			}
			if (hantei) {
				break;
			}
		}
		if (hantei) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

char bl[5]= "([)]";

int main(){
    char str[101];
    while(1){
        cin.getline(str, 101);
        if(str[0]=='.') break;

        stack<char> seq;
        for(int i=0; str[i]!='.'; i++){
            for(int j=0; j<2; j++){
                if(str[i]==bl[j]){
                    seq.push(str[i]);
                }
            }
            for(int j=2; j<4; j++){
                if(str[i]==bl[j]){
                    if(seq.empty() || seq.top()!=bl[j-2]){
                        seq.push(0);
                        break;
                    }else{
                        seq.pop();
                    }
                }
            }
        }
        if(seq.empty()){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3108
h,w = gets.chomp.split(" ").map(&:to_i)
a = h.times.map{gets.chomp.split(" ").map(&:to_i)}
ans = []
for i in 0..h-1
  p = a[i][0]%2
  for j in 1..w-1
    ans << "#{i+1} #{j} #{i+1} #{j+1}" if p == 1
    p = 1-p if a[i][j].odd?
  end
  a[i][-1] = p
end
p = a[0][-1]%2
for i in 1..h-1
  ans << "#{i} #{w} #{i+1} #{w}" if p == 1
  p = 1-p if a[i][-1] == 1
end
puts ans.size,ans

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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	if (k <= a) {
		ans = k;
	} else if (k > a && k <= a + b) {
		ans = a;
	} else {
		ans = a - min(c, k - a - b);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>

using namespace std;

long long n, m, s, t;

int main () {
    cin >> n >> m;
    for ( int i = 1; i <= m; i++) {
        cin >> t;
        s = s + t;
    }
    if ( s < n ) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes";
    }
}


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

int main() {
    int N,X,D=0,count =1;
    cin >> N>>X;
    vector<int> data(N);
    for(int i=2;i<=N+1;i++){
        cin >> data.at(i-2);
        D += data.at(i-2);
        if(D==X){
            count++;break;
        }
        else if(D>X) break;
        count++;
    }
    cout << count <<endl;
}

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


def modify(x):
    return int(x) + 1


l = list(map(modify, input().split()))

s = sum(l[:k])
m = s
for i in range(k, n):
    s += l[i]
    s -= l[i-k]
    m = max(s, m)

print(m/2)

Measured memory_bytes: 25060
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S,False(1,-1);
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

template<typename A,size_t N,typename T>
void Fill(A(&array)[N],const T &val){
    fill((T*)array,(T*)(array+N),val);
}

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


vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}



int main(){
    sieve( 100000 );
    vector<int> Prime;
    rep(i,100001)if(IsPrime[i])Prime.push_back(i);

    vector<ll> v( 100005 );
    REP(i , 1 , 100000){

        if(i == *lower_bound( ALL(Prime) , i )  && (i+1)/2 == *lower_bound( ALL(Prime) , (i+1)/2 )){
            v[i]++;
        }
        v[i] += v[i-1];
    }

    int q;cin >> q;
    rep(i,q){
        int l,r;cin >> l >> r;
        cout << v[r] - v[l-1] << endl;
    }
}

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

int main(){
  
  int x, y;
  cin >> x >> y;
  int ans = 0;
  if(x <= 3) ans += 400000 - x * 100000;
  if(y <= 3) ans += 400000 - y * 100000;
  if(x == 1 && y == 1) ans += 400000;
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N ((ll)101*1000)
#define MOD ((ll)1e9+7)

int n;
ll A,B,a[N],dp[2][N];

int main()
{
	scanf("%lld%lld%lld",&n,&A,&B);
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	dp[0][0]=dp[1][0]=1;
	set <pair<ll,int> > difA,difB;
	for(int i=1,jA=0,jB=0;i<n;i++)
	{
		if(i>=2 && jA<i-1)difA.insert({a[i-1]-a[i-2],i-1});
		if(i>=2 && jB<i-1)difB.insert({a[i-1]-a[i-2],i-1});
		while(jA<i && a[i]-a[jA]>=A)
		{
			difA.erase({a[jA+1]-a[jA],jA+1});jA++;
		}
		while(jB<i && a[i]-a[jB]>=B)
		{
			difB.erase({a[jB+1]-a[jB],jB+1});jB++;
		}
		if(jA==i)dp[0][i]=dp[0][i-1]+dp[1][i-1];
		else if(!difA.size() || difA.begin()->first>=B)dp[0][i]=dp[1][jA];
		if(jB==i)dp[1][i]=dp[0][i-1]+dp[1][i-1];
		else if(!difB.size() || difB.begin()->first>=A)dp[1][i]=dp[0][jB];
		if(dp[0][i]>=MOD)dp[0][i]-=MOD;
		if(dp[1][i]>=MOD)dp[1][i]-=MOD;
	}
	ll ans=(dp[0][n-1]+dp[1][n-1])%MOD;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
#define ll long long int 
#define RD(v,n) for(ll i =0;i<n;i++ ) cin>>v[i]
#define bolt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main()
{
	bolt;
    ll n;
    cin>>n;
    vector<ll> v(n);
    RD(v,n);	
    ll ans = 0;
    ll pointer = 1;
    for(ll i=0;i<n;i++){
        if( pointer == v[i] ){
            pointer++;
        }
        else{
            ans++;
        }
    }
    if( ans == n ){
        cout<<-1<<"\n";
    }
    else{
        cout<<ans<<"\n";
    }
	return 0;
}

Measured memory_bytes: 1792
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

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

int main() {
    char c;
    cin >> c;
    if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') cout << "vowel" << endl;
    else cout << "consonant" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, A, cnt = 0, maxc = 0;
    cin >> N;

    for(int i = 0; i < N; i++) {
        cin >> A;
        if(A == 1) cnt++;
        else {
            maxc = max(maxc, cnt);
            cnt = 0;
        }
    }
    maxc = max(maxc, cnt);

    cout << maxc + 1 << endl;
}


Measured memory_bytes: 3108
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

X = int(input())
ans = 8

X= X-400

while True:
  X -= 200
  if(X<0):
    break
  else:
    ans-=1


print(ans)



Measured memory_bytes: 68712
# ABC138D - Ki
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(v: int, p: int) -> None:
    x = cnt[v]
    for u in T[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += x  # cumulative sum
            dfs(u, v)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    global T, cnt
    N, Q = tuple(map(int, input().rstrip().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().rstrip().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, N+1: 1-idx
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

Measured memory_bytes: 265808