akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include <functional>
#include <queue>

using namespace std;

#define MOD 1000000007
#define INF 1050000000

int main() {
	int A, B; cin >> A >> B;

	if (A == B) {
		cout <<  A* 2 << endl;
	}
	else {
		cout << 2 * max(A, B) - 1;
	}






}

Measured memory_bytes: 256
#!/usr/bin/python3

import os
import sys


def main():
    T = read_int()
    print(solve(T))


def solve(T):
    if T <= 3:
        return T

    sec = 1
    T -= 1
    f = 3
    while T >= 2 * f:
        T -= 2 * f
        f *= 3
        sec += 2

    if T >= f:
        T -= f
        sec += 1
    else:
        f //= 3

    while T > 0:
        t = T // f
        T -= t * f
        sec += t
        f //= 3

    return sec


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5612
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int s;
    cin>>s;
    vector<ll> v(2001,0);
    rep(i,7){
        v[i+3]=1;
    }
    for(int i=6;i<=2001;i++){
        v[i]=v[i-1]+v[i-3];
        v[i]%=MOD;
    }
    cout<<v[s]<<endl;


    
return 0;
}


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

 int find_z(int n, int x, int y){
        int l = 1, r = n, res = -1, mid;
        while(l <= r){
            mid = l + (r-l)/2;
            int val = (x*x + y*y + mid*mid + x*mid + y*mid + x*y );
            if(val == n){
                return mid;
            }
            else if(val < n)
                l = mid+1;
            else
                r = mid - 1;
        }
        return -1;
    }

void process(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
         int cnt = 0;
         for(int x = 1; x <= 100; x++){
            for(int y = 1; y <= 100 && (x*x + y*y + x*y) < n ; y++){
                int z = find_z(i, x, y);
                if(z != -1)
                    cnt++;
            }
        }
        cout<<cnt<<"\n";
    }
}

int main()
{
	//int t;
	//cin >> t;
	process();
}

Measured memory_bytes: 3592
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    S = [input() for _ in range(N)]
    dict1 = collections.Counter(S)

    print('AC x', dict1['AC'])
    print('WA x', dict1['WA'])
    print('TLE x', dict1['TLE'])
    print('RE x', dict1['RE'])

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 16620
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,m,a,aa[110000];
pair<int,int> p[220000];
string s;
char c;
signed main(){
    cin>>n>>m>>a;
    if((n==m&&n!=a)||(n==a&&n!=m)||(m==a&&n!=m)){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>

int testcase_ends() {
  size_t D, N;
  scanf("%zu %zu", &D, &N);

  std::vector<int> T(D);
  for (auto& ti: T) scanf("%d", &ti);

  std::vector<std::tuple<int, int, int>> abc(N);
  int max_c = 0;
  for (auto& abci: abc) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    abci = std::make_tuple(a, b, c);
    max_c = std::max(max_c, c);
  }

  int inf = 1e8;
  std::vector<std::vector<int>> dp(D, std::vector<int>(max_c+1, -inf));

  for (size_t j = 0; j < N; ++j) {
    int a, b, c;
    std::tie(a, b, c) = abc[j];
    if (!(a <= T[0] && T[0] <= b)) continue;
    dp[0][c] = 0;
  }

  for (size_t i = 1; i < D; ++i) {
    for (size_t j = 0; j < N; ++j) {
      int a, b, c;
      std::tie(a, b, c) = abc[j];
      if (!(a <= T[i] && T[i] <= b)) continue;
      for (int k = 0; k <= max_c; ++k) {
        dp[i][c] = std::max(dp[i][c], dp[i-1][k] + std::abs(k-c));
      }
    }
  }

  int res = *std::max_element(dp[D-1].begin(), dp[D-1].end());
  printf("%d\n", res);
  return 1;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2832
#include <iostream>
#include <string>
#define llint long long

using namespace std;

llint n;
llint k[105];
string s;

int main(void)
{
	while(1){
		cin >> n;
		if(n == 0) break;
		for(int i = 0; i < n; i++) cin >> k[i];
		cin >> s;
		
		string ans;
		for(int i = 0; i < s.size(); i++){
			int c = s[i]-'a';
			if(s[i] < 'a') c = s[i]-'A'+26;
			c += 52-k[i%n];
			c %= 52;
			if(c < 26) ans += c+'a';
			else ans += (c-26)+'A';
		}
		cout << ans << endl;
	}
	return 0;
}


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

#define ll long long



void solve(){
    int n, k, x, y; cin>>n>>k>>x>>y;
    if(n>k) cout<<k*x+(n-k)*y<<endl;
    else cout<<n*x<<endl;
}

signed main(){
    //while(1)
    solve();
}

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

using namespace std;
char a[10];
int main(){
    scanf("%s", a);
    int ans = 0;
    for(int i = 0; i < 4; i++){
        if(a[i] == '+') ans++;
    }
    printf("%d\n", ans - (4 - ans));
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
	int i, j, k;
	int N,M;
	string a[100];
	string b[100];
	cin >> N;
	for (i = 0;i < N;i++)
		cin >> a[i];
	cin >> M;
	for (i = 0;i < M;i++)
		cin >> b[i];
	
	int counter = 0;
	int old_counter = 0;
	for (i = 0;i < N;i++) {
      counter = 0;
		for (j = 0;j < N;j++) {
			if (a[i] == a[j])
				counter++;
		}
		for (k = 0;k < M;k++) {
			if (a[i] == b[k])
				counter--;
		}
		if (counter > old_counter)
			old_counter = counter;
	}
	cout << old_counter << endl;
}

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;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	double ans =  2.0 * n * 3.141592;
	
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 3772
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int k=sc.nextInt();
    int sum=0;
    for(int i=0;i<k;i++)
    {
      if(a!=0)
      {
        sum++;
        a--;
      }
      else 
      {
        if(b!=0)
        {
          b--;
        }
        else
        {
          c--;
          sum--;
        }
      }
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 27140
import java.util.*;
 
class Main{
  static Scanner sc = new Scanner(System.in);
  public static void main(String args[]){
    int n=sc.nextInt();
    int a[] = new int[n+1];
    a[0]=0;
    for(int i=1;i<=n;i++){
      a[i]=a[i-1]+sc.nextInt();
    }
    int min=10000000;
    for(int t=1;t<n;t++){
      min=Math.min(Math.abs((a[t]-a[0])-(a[n]-a[t])),min);
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 22996
// https://atcoder.jp/contests/abc173/tasks/abc173_b 
#include <bits/stdc++.h>
using namespace std ;
int main() 
{
    long long n ;
    cin >> n ;
    string a ="AC" , b = "WA" , c = "TLE" , d = "RE" ;
    int aa = 0 , bb = 0 , cc = 0 , dd = 0 ;
    while(n--) {
        string s ;
        cin >> s ;
        if (s == a) aa++ ;
        if (s == b) bb++ ;
        if (s == c) cc++ ;
        if (s == d) dd++ ;
    }
    cout << "AC x " << aa << endl ;
    cout << "WA x " << bb << endl ;
    cout << "TLE x " << cc << endl ;
    cout << "RE x " << dd << endl ;
}
/*  CODED BY:-
 ___________________________________
|                       ___         |
|  /\   /\  \ /  |  |  |___   |__|  |        
| /~~\ /~~\  |   |__|   ___|  |  |  |
|___________________________________|
 
*/

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

int main() 
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string r, b, g;
  cin >>r >> b >> g;

  string a = b + g;
  
  int x = stoi(a);
  
  if (x % 4 == 0)
  {
     cout << "YES" << endl;
  }
  else cout << "NO" << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

struct UnionFind{
    vector<int> d;
    UnionFind(int n = 0): d(n, -1){}
    int find(int x){
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {return find(x) == find(y);}
    int size(int x){return -d[find(x)];}
};


int main(){
    int n, m;
    cin >> n >> m;
    VVI g(n);
    VP e(m);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        e[i].first = a;
        e[i].second = b;
    }
    reverse(all(e));

    UnionFind uf(n);
    VL ans = {n * (n-1LL) / 2};
    rep(i,m){
        int a, b;
        a = e[i].first;
        b = e[i].second;
        if (uf.same(a, b)) {
            ans.push_back(ans.back());
            continue;
        }
        ll szA = uf.size(a);
        ll szB = uf.size(b);
        ans.push_back(ans.back() - (szA * szB));
        uf.unite(a, b);
    }
    ans.pop_back();
    reverse(all(ans));
    rep(i,m) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 7784
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 105
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

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

/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	// WF("output.txt");
	DF("err.txt");

	int N;
	scanf("%d", &N);
	vector <int> A(N);
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);
	vector <int> sorted;
	for (int i = N - 1; i >= 0; i--) {
		if (sorted.empty() or A[i] >= sorted.back()) {
			sorted.push_back(A[i]);
		}
		else {
			int lb = 0, rb = sorted.size();
			int pos = 0;
			while (lb < rb) {
				int mid = (lb + rb) >> 1;
				if (A[i] < sorted[mid]) {
					rb = mid;
					pos = mid;
					
				}
				else lb = mid + 1;
			}
			sorted[pos] = A[i];
		}
	}
	printf("%d\n", (int)sorted.size());
	return 0;
}

Measured memory_bytes: 1404
#include<iostream>
using namespace std;
int main(){
	int H,W,i,j;
	for(;;){
		cin>>H>>W;
		if(W==0&&H==0)
			break;
		for(i=1;i<=H;i++){
			for(j=1;j<=W;j++)
				if(j==1||j==W||i==1||i==H){
					cout<<"#";
				}else{
				cout<<".";
				}
				cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

ll n;
vll h(500005);

void maxHeapify(ll i) {
  ll l, r, largest;
  l = 2*i; r = 2*i+1;
  if (l <= n && h.at(l) > h.at(i)) largest = l;
  else largest = i;
  if (r <= n && h.at(r) > h.at(largest)) largest = r;

  if (largest != i) {
    swap(h.at(i), h.at(largest));
    maxHeapify(largest);
  }
}

int main() {
  cin >> n;
  REP(i, n) cin >> h.at(i+1);
  for(ll i=n/2; i>=1; i--) {
    maxHeapify(i);
  }
  rep(i, 1, n+1) cout << " " << h.at(i);
  cout << endl;
  return 0;
}



Measured memory_bytes: 6592
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    long n = sc.nextLong();

    long a = (long)Math.sqrt(n);
    long ans = 0;
    for (long i = a + 1; i > 0; i--) {
      if (n % i == 0) {
        ans = i + (n / i) - 2;
        break;
      }
    }
    
    System.out.println(ans == 0 ? n - 1 : ans);
  }
}


Measured memory_bytes: 23380
//
//  main.cp;
//  ABC_173_B
//
//  Created by Joe Mori on 2020/07/05.
//  Copyright © 2020 Joe Mori. All rights reserved.
//

#include <iostream>
#include<bits/stdc++.h>
int main() {
    // insert code here...
    int H,W,K,count=0,ans=0;;
    std::cin>>H>>W>>K;
    std::vector<std::vector<char> >c(H,std::vector<char>(W));
    for(int i=0;i<H;i++){
        for (int j=0; j<W; j++) {
            std::cin>>c[i][j];
        }
    }
    for (int bit = 0; bit < (1<<H); ++bit) {
        for(int bit1=0;bit1<(1<<W);bit1++){
            count=0;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(bit&(1<<i)&&bit1&(1<<j)){
                        if(c[i][j]=='#')count++;
                    }
                }
            }
                if(count==K)ans++;
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}



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

class UnionFind {
	vector<long long> Root, Rank, Size;
public:
	UnionFind(long long N) {
		Root.resize(N);
		for (int i = 0; i < N; i++) Root[i] = i;
		Rank.assign(N, 1);
		Size.assign(N, 1);
	}
	long long Find(long long N) {
		if (Root[N] == N) return N;
		return Root[N] = Find(Root[N]);
	}
	bool Same(long long X, long long Y) {
		return Find(X) == Find(Y);
	}
	long long Large(long long N) {
		return Size[Find(N)];
	}
	void Union(long long X, long long Y) {
		X = Find(X), Y = Find(Y);
		if (X == Y) return;
		if (Rank[X] > Rank[Y]) Root[Y] = X, Size[X] += Size[Y];
		else if (Rank[X] < Rank[Y]) Root[X] = Y, Size[Y] += Size[X];
		else {
			Root[Y] = X;
			Size[X] += Size[Y];
			Rank[X]++;
		}
	}
};

int main() {
	long long N, M, K;
	cin >> N >> M >> K;
	UnionFind UF(N);
	vector<long long> ANS(N);
	for (int i = 0; i < M; i++) {
		long long A, B;
		cin >> A >> B;
		A--, B--;
		ANS[A]--, ANS[B]--;
		UF.Union(A, B);
	}
	for (int i = 0; i < N; i++) {
		ANS[i] += UF.Large(i) - 1;
	}
	for (int i = 0; i < K; i++) {
		long long C, D;
		cin >> C >> D;
		C--, D--;
		if (UF.Same(C, D)) ANS[C]--, ANS[D]--;
	}
	for (int i = 0; i < N; i++) {
		cout << ANS[i];
		if (i == N - 1) cout << endl;
		else cout << " ";
	}
}

Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstring>
#include<functional>

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)

using namespace std;

int main(){
	int N;
	cin >> N;
	rep(i,1,10){
		if(N % i == 0 && N / i < 10){
			cout << "Yes" << endl;
			break;
		}
		if(i == 9) cout << "No" << endl;
	}
	
}

Measured memory_bytes: 256
from collections import defaultdict
v_num = int(input())
connect = defaultdict(list)
for v in range(v_num):
    inp = [int(n) - 1 for n in input().split(" ")]
    connect[inp[0]].extend(inp[2:])
answer = [[m + 1, -1] for m in range(v_num)]
queue = [0]
visited = [0 for n in range(v_num)]
visited[0] = 1
time = 0
while queue:
    new_queue = []
    for q in queue:
        answer[q][1] = time
        for c in connect[q]:
            if not visited[c]:
                visited[c] = 1
                new_queue.append(c)
    queue = new_queue
    time += 1
for v in range(v_num):
    print(*answer[v])

Measured memory_bytes: 8104
//NAME-ADITYYA OJHA
                                               /*
                                                      GURU(MENTOR)-AARADHYA
                                               */
/*
 *     Heart beats fast
 *         Colors and promises
 *             How to be brave
 *                 How can I love when I am afraid to fall...
                                             (courtesy-amnesiac_dusk)
 */

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define forin for(int i=0;i<n;i++)
#define forjn for(int j=0;j<n;j++)
#define pb push_back
#define vx vector<ll> x
#define vy  vector<ll> y
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  f   first
#define  s   second
#define mod 1000000007
 const int N=1e6+5;
 const ll N1=1e15 + 5;

using namespace std;

//check for corner cases(for n==1)
// check for int overflow
// run on some sample cases before submitting

   ll a[N];
   ll freq[N];
int main()
{
  fast;
   ll n;
   cin>>n;
memset(freq,0,sizeof(freq));
   forin
   {
       cin>>a[i];
       freq[a[i]]++;
   }
   sort(a,a+n);
   if(freq[1]==1)
   {
       cout<<1<<endl;
       return 0;
   }
   if(freq[1]>1)
   {
       cout<<0<<endl;
       return 0;
   }

   ll cnt=0;
   for(int i=0;i<n;i++)
   {

        ll z=a[i];
       ll flag=0;
           for(int j=2;j<=int(sqrt(a[i]));j++)
           {
               if(z%j==0)
               {
                   ll z1=z/j;
                   if((freq[j])|| (freq[z1])){flag=1;break;}


               }
           }
           if((freq[1]) || (freq[z]>1) || (flag))
            continue;
            else
                cnt++;


   }

     cout<<cnt<<endl;
}













Measured memory_bytes: 13076
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

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

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


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

int main() {

ll k=1;
int fin=0;
	for(int i=1;i<=10;i++){
if(i>=2) k*=10;
cout<<'?'<<" "<<k<<endl;
cout<<flush;
char q;
cin>>q;
if(q=='N') break;
if(i==10) fin=1;
	}


	if(fin){
		k=0;
for(int i=1;i<=10;i++){
 k=k*10+9;
cout<<'?'<<" "<<k<<endl;
cout<<flush;
char q;
cin>>q;
if(q=='Y'){
	if(i==1) {cout<<'!'<<" "<<1<<endl;
cout<<flush;
return 0;}
cout<<'!'<<" "<<(k+1)/10<<endl;
cout<<flush;
return 0;
}
}


	}


ll left=k/10;
ll right=k-1;
ll v=0;

for(int w=1;w<=40;w++){
	ll mid=(left+right)/2;
	v=mid;
	ll u=(ll)10000000000000/k;
	ll e=mid;
	e*=u;
	e+=u-1;
	cout<<'?'<<" "<<e<<endl;
cout<<flush;
char q;
cin>>q;
if(q=='Y') right=mid;
else left=mid;
}

if(v+1<k){
ll u=(ll)10000000000000/k;
ll y=v;
y*=u;
y+=u-1;
cout<<'?'<<" "<<y<<endl;
cout<<flush;
char q;
cin>>q;
if(q=='N') v++;
}


cout<<'!'<<" "<<v<<endl;
cout<<flush;

return 0;
}




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

using namespace std;
int a[110];
int main(){
	int n;
	scanf("%d",&n);
	for(int i = 0;i < n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int ans = 0;
    for(int i = 0;i < n - 2;i++)
        for(int j = i + 1;j < n - 1;j++)
        for(int k = j + 1;k < n;k++)
    {
        //cout<<a[i]<<" "<<a[j]<<" "<<a[k];
        if(a[i] + a[j] > a[k]&&a[i]!=a[j]&&a[j]!=a[k])ans++;//cout<<endl;
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int N, K; cin >> N >> K;

    vector<int> ans_c(N, 0);

    rep(i, K) {
        int d; cin >> d;
        rep(j, d) {
            int a; cin >> a;
            a--;
            ans_c[a] += 1;
        }
    }

    int ans = 0;
    rep(i, N) {
        if (ans_c[i] == 0) {
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

string change_to_s(int n){
   stringstream ss; ss<<n;
   return ss.str();
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<P> > d(n, vector<P>());
    rep(i, 0, m){
        int p, y;
        cin >> p >> y;
        p--;
        d[p].push_back({y, i});
    }
    vector<string> ans(m);
    rep(i, 0, n){
        sort(d[i].begin(), d[i].end());
        string pre = change_to_s(i + 1);
        while(pre.size() < 6) pre = "0" + pre;
        rep(j, 0, d[i].size()){
            string tmp = change_to_s(j + 1);
            while(tmp.size() < 6) tmp = "0" + tmp;
            string now = pre + tmp;
            ans[d[i][j].second] = now;
        }
    }
    for(int ii = 0; ii < ans.size(); ii++){
        cout << ans[ii] << endl;
    }
}

Measured memory_bytes: 12416
#include <iostream>
#include <algorithm>

int main() {
	long long int n, k;
	std::cin >> n >> k;
	if (n == k || n == 0) std::cout << "0\n";
	else {
		if (n > k) {
			if (n % k == 0) std::cout << "0\n";
			else std::cout << std::min(k - n % k,n%k) << '\n';
		}
		else std::cout << std::min(k - n, n) << '\n';
	}

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n;
	cin >> n;
	int max=0, sum=0;
	for(int i=0; i<n; i++){
		int tmp;
		cin >> tmp;
		sum+=tmp;
		if(tmp>max)
			max=tmp;
	}
	if((sum-max)-max>0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
const int N=2e5+5;
int n,d[N];
long long c[N];
int main() {
    scanf("%d",&n);
    long long ans=-1,sd=0;
    for(int i=1;i<=n;i++) {
        scanf("%d%lld",d+i,c+i);
        ans+=c[i];
        sd+=d[i]*c[i];
    }
    printf("%lld\n",ans+(sd-1)/9);
    return 0;
}


Measured memory_bytes: 2560
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

n = readi()
s = input()

def no():
  print('No')
  exit()

if n%2>0:
  no()

for i in range(0, n//2):
  if s[i]!=s[i+n//2]:
    no()

print('Yes')


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((abs(a - c) <= d) || (abs(a - b) <= d && abs(c - b) <= d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve(vector<int>&v,int ,int);

int main(){
int n;
  cin>>n;
  int m;
  cin>>m;
  vector<int>v;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
      v.push_back(x);  
  }
  solve(v,n,m);
  return 0;
}
void solve(vector<int>&v,int n,int m){
int sum = accumulate(v.begin(),v.end(),0);
  int count = 0;
  for(int i=0;i<n;i++){
  if(v[i] * 4 * m >=sum)
    count++;
  }
  if(count>=m)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
L =[]
for i in range(3):
    a,b,c = map(int,input().split())
    L.append([a,b,c])

n = int(input())
li = []
for i in range(n):
    d = int(input())
    for j in range(3):
        for k in range(3):
            if d ==L[j][k]:
                L[j][k] = 0
for i in range(3):
    if not any((L[i][j] for j in range(3))):
        print("Yes")
        exit()
    if not any((L[j][i] for j in range(3))):
        print("Yes")
        exit()
if not any((L[i][2-i] for i in range(3))):
        print("Yes")
        exit()
if not any((L[i][i] for i in range(3))):
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 3064
mod = 10**9+7

def mod_factorial(n):
  ret = 1
  for i in range(1, n+1):
    ret = ret * i % mod
  return ret
  
def main():
  n, m = map(int, input().split())
  if abs(n-m) > 1:
    return 0
  
  l = min(n, m)
  f = mod_factorial(l)
  
  if n == m:
    return(2*f*f%mod)
  else:
    return(f*f*(l+1)%mod)

print(main())

Measured memory_bytes: 3064
def main():
    N = int(input())
    count = 0

    for i in range(1,N+1):
        S = str(i)
        s_len = len(S)
        if is_even(s_len) == False:
            count = count + 1
            #print(S)

    print(count)

def is_even(num):
    if num % 2 == 0:
        return True
    else:
        return False

if __name__ == '__main__' :
    main()

Measured memory_bytes: 3060
/*****Here we go again!******/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.1415926535
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define llu unsigned long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define tc int test_case; cin >> test_case; while(test_case--)
#define f(i,a,n) for(int i = a ; i < n ; i++)
#define rf(i,n,a) for(int i = n-1 ; i >= a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define get(a,n) f(i,0,n) cin >> a[i];
#define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl;
#define fast ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) cerr << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cerr<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

const int inf = 1e9;
const ll inf64 = 1e18;
const int mod = inf + 7;
const int N = 1e5 + 10;

int main()
{
    fast;
    string s, t;
    cin >> s >> t;
    int n = sz(s), m = sz(t);
    int dp[n+1][m+1];

    f(i,0,n+1)
        dp[i][0] = 0;
    f(i,0,m+1)
        dp[0][i] = 0;

    f(i,1,n+1)
    {
        f(j,1,m+1)
        {
            if(s[i-1] == t[j-1])
                dp[i][j] = 1 + dp[i-1][j-1];
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    string ans;

    int i = n, j = m;
    while(i > 0 and j > 0)
    {
        if(s[i-1] == t[j-1])
        {
            ans += s[i-1];
            i--, j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
            i--;
        else
            j--;
    }
    reverse(all(ans));
    cout << ans;
}


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

int main(){
  int n;
  long long int ans[30];
  for(int i =0;i < 30; i++){
    if(i == 0)ans[i] = 1;
    else if(i == 1)ans[i] = ans[i-1] + 1;
    else if(i == 2)ans[i] = ans[i-1] + ans[i-2] + 1;
    else ans[i] = ans[i-1] + ans[i-2] + ans[i-3];
  }
  while(1){
    cin >> n;
    if(n == 0)break;
    if(ans[n-1]%3650 == 0) cout<<ans[n-1]/3650 << endl;
    else  cout << ans[n-1]/3650 + 1 <<endl;
  }
}




Measured memory_bytes: 3084
#include<iostream>
int main()
{
	int N;
	std::cin >> N;
	char*S = new char[N];
	std::cin >> S;
	int head = 0;
	int opener = 0;
	for(int i = 0; S[i] != '\0'; i++)
	{
		switch(S[i])
		{
			case '(':
				opener++;
				break;
			case ')':
				if(opener > 0)
				{
					opener--;
				}
				else
				{
					head++;
				}
				break;
		}
	}
	for(int i = 0; i < head; i++)
	{
		std::cout << '(';
	}
	std::cout << S;
	for(int i = 0; i < opener; i++)
	{
		std::cout << ')';
	}
	std::cout << std::endl;
	return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

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

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
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);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while(A > 0 && C > 0) {
    C -= B;
    A -= D;
  }
  if(C <= 0) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3640
N,M=map(int,input().split())
num=[0]*(N+1)
num[0]=1
num[1]=1

A=[]
for i in range(M):
    A.append(int(input()))

P=10**9+7
index=0

if 1 in A:
    num[1]=0
    index+=1


if N>=2:
    for i in range(2,N+1):
        num[i]=(num[i-1]+num[i-2])%P
        if index<=M-1 and i==A[index]:
            num[i]=0
            index+=1

print(num[N])

Measured memory_bytes: 7844
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scan =new Scanner(System.in);
        int N=scan.nextInt();   //数列の長さ
        int[] num=new int[100000];
        int diviteby4=0;
        int diviteby2=0;
        int areaby4=0;
        int areaby2=0;
        for(int i=0;i<N;i++)
        {
            num[i]=scan.nextInt();
            if(num[i]%4==0) diviteby4++;
            if(num[i]%2==0 && num[i]%4!=0) diviteby2++;
        }

        areaby4=diviteby4*2;
        if(diviteby2==0) areaby2=0;
        else areaby2=diviteby2-1;

        if(areaby2+areaby4>=N-1) System.out.println("Yes");
        else System.out.println("No");

    }
}


Measured memory_bytes: 50772
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+4;
int n;
char ss[N];
int l[N],s1;
int r[N],s2;
int cnt[N];
inline int find1(int pos) {
	int ll=1,rr=s1;
	while (ll<=rr) {
		int mid=ll+rr>>1;
		if (l[mid]<pos) ll=mid+1;
		else rr=mid-1;
	}
	return rr;
}
inline int find2(int pos) {
	int ll=1,rr=s2;
	while (ll<=rr) {
		int mid=ll+rr>>1;
		if (r[mid]>pos) rr=mid-1;
		else ll=mid+1;
	}
	return ll;
}
int main() {
	scanf("%s",ss+1);
	n=strlen(ss+1);
	for (register int i=1;i<n;++i) {
		if (ss[i]=='R'&&ss[i+1]=='L') {
			l[++s1]=i+1;
			r[++s2]=i;
			++cnt[i],++cnt[i+1];
		}
	}
	for (register int i=1;i<=n;++i) {
		if (ss[i]=='R') {
			if (ss[i+1]=='L') continue;
			int id=find2(i);
			int dis=r[id]-i;
			if (dis&1) ++cnt[r[id]+1];
			else ++cnt[r[id]];
		} else {
			if (ss[i-1]=='R') continue;
			int id=find1(i);
			int dis=l[id]-i;
			if (dis&1) ++cnt[l[id]-1];
			else ++cnt[l[id]];
		}
	}
	for (register int i=1;i<=n;++i)
		printf("%d ",cnt[i]);
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define se second
#define fi first
#define int long long 
#define pi pair<int,int>
#define vpi vector<pi>
#define vvpi vector<vpi>
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define For(i,n) for(int i=0;i<n;i++)
#define Forn(i,a,n) for(int i=a;i<n;i++)
#define pie =3.14159265358979323846264338327950;
const int mod= 1e9+7;

vector<int> graph[100005];
vector<int> dp(100005,-1);

void dfs(int i){
	int ans=0;
	for(int j:graph[i]){
		if(dp[j]==-1){
			dfs(j);
		}
		ans=max(dp[j],ans);
	}
	dp[i]=ans+1;
}
	
void solve(){
	fio;
  	int n,m;
  	cin>>n>>m;
  	for(int i=0;i<m;i++){
  		int a,b;
  		cin>>a>>b;a--;b--;
  		graph[a].pb(b);
  	}
  	for(int i=0;i<n;i++){
  		if(dp[i]==-1){
  			dfs(i);
  		}
  	}
  	int ans=0;
  	for(int i=0;i<n;i++){
  		//cout<<dp[i]<<" ";
  		ans=max(ans,dp[i]);
  	}
  	cout<<ans-1<<endl;
}

int32_t main(){
	fio;
	#ifndef ONLINE_JUDGE
  		freopen("input.txt", "r", stdin);
  		freopen("output.txt", "w", stdout);
  	#endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){ 
		//cout<<"Case #"<<i<<":\n";
		solve();
	}
	return 0;
}


Measured memory_bytes: 12172
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  char prev[2];
  cin >> s;
  prev[0] = s[1];//1つ前
  prev[1] = s[0];//2つ前
  if(s.size() == 2 && prev[0] == prev[1]){
    cout << "1 2" << endl;
    return 0;
  }
  for(int i = 2; i < s.size(); i++){//長さ3以上
    if(prev[0] == s[i] || prev[1] == s[i]){
      cout << i-1 << " " << i+1 << endl;
      return 0;
    }
    prev[1] = prev[0];
    prev[0] = s[i];
  }
  cout << "-1 -1" << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

typedef long long ll;
#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

int main(){
	char A, B;
	cin >> A >> B;
	
	if(A == B) cout << '=' << endl;
	else if(A < B) cout << '<' << endl;
	else cout << '>' << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
int x,k,q,r[100010],maxn[100010],mini[100010],c[100010];
char buffer[10000010],*hd;
char Getchar(){
	return *hd++;
}
int rd(){
	int x=0;
	char c;
	do c=Getchar();
	while(!isdigit(c));
	do{
		x=(x<<1)+(x<<3)+(c^48);
		c=Getchar();
	}while(isdigit(c));
	return x;
}
void InitInput(){
	fread(buffer,1,10000000,stdin);
	hd=buffer;
	x=rd(),k=rd();
	for(int i=1;i<=k;i++)
		r[i]=rd();
	maxn[0]=x,r[0]=mini[0]=c[0]=0;
	for(int i=1;i<=k;i++){
		maxn[i]=maxn[i-1];
		mini[i]=mini[i-1];
		if(i&1){
			mini[i]=max(mini[i],min(r[i]-r[i-1]-c[i-1],maxn[i]));
			c[i]=max(c[i-1]+mini[i-1]-r[i]+r[i-1],0)-mini[i];
		}else{
			maxn[i]=min(maxn[i],max(x-r[i]+r[i-1]-c[i-1],mini[i]));
			c[i]=min(c[i-1]+maxn[i-1]+r[i]-r[i-1],x)-maxn[i];
		}
	}
	return;
}
void Ask(){
	q=rd();
	for(int i=1;i<=q;i++){
		int t=rd(),a=rd();
		int pos=upper_bound(r+1,r+k+1,t)-r-1,ans=c[pos];
		if(a<=mini[pos])
			ans+=mini[pos];
		else if(a>=maxn[pos])
			ans+=maxn[pos];
		else
			ans+=a;
		if(pos&1)
			ans=min(x,ans+t-r[pos]);
		else ans=max(0,ans-t+r[pos]);
		printf("%d\n",ans);
	}
}
int main(){
	InitInput();
	Ask();
	return 0;
}

Measured memory_bytes: 8320
def q2():
    N, X = (int(i) for i in input().split())
    L = [int(i) for i in input().split()]

    D = [0]
    for i in range(1, N+1):
        D.append(D[i-1] + L[i-1])

    ans = 0
    for d in D:
        if d <= X:
            ans += 1

    print(ans)


if __name__ == '__main__':
    q2()


Measured memory_bytes: 3060
A,B,K=[int(x) for x in input().rstrip().split()]
import sys
# A=[int(x) for x in input().rstrip().split()]
# if A==0 and B==0:
#   print(0,0)
#   sys.exit()
ans=0
if 0<=A-K:
  print(A-K,B)
else:
  if B+(A-K)<0:
    ans=0
  else:
    ans=B+(A-K)
  print(0,ans)



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

int main()
{
	int a;
	cin >> a;

	int b = 0;
	if (400 <= a && a <= 599) {
		b = 8;
	}else if(600 <= a && a <= 799) {
		b = 7;
	}
	else if (800 <= a && a <= 999) {
		b = 6;
	}
	else if (1000 <= a && a <= 1199) {
		b = 5;
	}
	else if (1200 <= a && a <= 1399) {
		b = 4;
	}
	else if (1400 <= a && a <= 1599) {
		b = 3;
	}
	else if (1600 <= a && a <= 1799) {
		b = 2;
	}
	else if (1800 <= a && a <= 1999) {
		b = 1;
	}

	cout << b << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <math.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main()
{
int m,f,r;
cin >> m >> f >> r;
while (m!=-1||f!=-1||r!=-1)
{
if(m==-1||f==-1)
{
cout << "F" << endl;
cin >> m >> f >> r;
continue;
}
if(m==-1)m=0;
else if(f==-1)f=0;
else if(r==-1)r=0;
if (m+f>=80)cout << "A" << endl;
else if(m+f>=65)cout << "B" << endl;
else if(m+f>=50)cout << "C" << endl;
else if(m+f>=30)
{
if(r>=50)cout << "C" << endl;
else cout << "D" << endl;
}
else cout << "F" << endl;
cin >> m >> f >> r;
}
}



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

int main(void) {
  int k;
  int a[3];
  int other = 0;
  int max = 0;
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  scanf("%d",&k);
  for (int i = 0;i < 2;++i) {
    if (i == 0) {
      if (a[i] > a[i + 1]) {
        max = a[i];
        other += a[i + 1];
      } else {
        max = a[i + 1];
        other += a[i];
      }
    } else {
      if (max > a[i + 1]) {
        other += a[i + 1];
      } else {
        other += max;
        max = a[i + 1];
      }
    }
  }
  for (int j = 0;j < k;++j) {
    max = max*2;
  }
  printf("%d",other + max);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
int main(void){
  int a ,i ,j ;
  double diff = 1000.0 , re;
  scanf("%d", &a);
  if(a == 1 || a == 2 || a == 3){
    printf("1\n");
  }else{
  for(i = 2; i < 32; i++){
    for (j = 2; j < 10 ; j++) {
    double x  = pow((double)i ,(double)j);
  //  printf("as%.0f\n",x);
    if(x > (double)a){
      break;
    }else if(diff >= (double)a - x){
      diff = (double)a - x;
      re = x;
    }
    }
    }
  }
  if(a != 1 && a != 2 && a && 3)
  printf("%.0f\n",re);
  return 0;
  }


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
ll N;
ll dist[805];
ll p[805];
ll d[805];
vector<l_l> pathes[805];

void dfs(int now, int from) {
    for(int i = 0; i < pathes[now].size(); i++) {
        int to = pathes[now][i].first;
        if(to == from) continue;
        ll newcost = dist[now] + pathes[now][i].second;
        dist[to] = newcost;
        dfs(to, now);
    }
}

int main() {
    while(true) {
        cin >> N;
        if(N == 0) break;
        for(int i = 1; i <= N; i++) {
            pathes[i].clear();

        }
        ll sum = 0;
        for(int i = 2; i <= N; i++) cin >> p[i];
        for(int i = 2; i <= N; i++) cin >> d[i];
        for(int i = 2; i <= N; i++) {
            sum += 3 * d[i];
            pathes[p[i]].push_back({i, d[i]});
            pathes[i].push_back({p[i], d[i]});
        }
        for(int i = 1; i <= N; i++) {
            if(pathes[i].size() != 1) continue;
            sum -= pathes[i][0].second * 2;
        }
        //cerr << sum << endl;
        ll ans = sum;
        for(int i = 1; i <= N; i++) {
            if(pathes[i].size() == 1) continue;
            dist[i] = 0;
            dfs(i, -1);
            for(int j = i + 1; j <= N; j++) {
                if(pathes[j].size() == 1) continue;
                ans = min(ans, sum - dist[j]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
	int N;
	long long A,B,ans=0;
	cin >> N >> A >> B;
	vector<long long> X(N);
	for(auto &i:X)cin >> i;
	
	for(int i=0;i<N-1;i++){
		ans+=min(A*(X[i+1]-X[i]),B);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
H,W,K=list(map(int,input().split()))
board = [list(input()) for i in range(H)]
ans = 0
for paint_h in range(2**H):
  for paint_w in range(2**W):
    cnt = 0
    for i in range(H):
      for j in range(W):
        if (paint_h>>i)&1==0 and (paint_w>>j)&1==0:
          if board[i][j]=='#':
            cnt+=1
    if cnt==K:
      ans+=1
print(ans)

Measured memory_bytes: 9132
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll pow(ll a, ll n)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x;
        }
        a = a * a;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    ll H;
    input(H);

    ll d = 0;
    while (H > 1)
    {
        H /= 2;
        d++;
    }

    ll res = 0;
    rep(i, 0, d + 1)
    {
        res += pow(2, i);
    }

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

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

#define mp make_pair
#define pb push_back

const int mod = (int)1e9+7;
using namespace std;

int fastp(int a, int b){
    int res = 1;
    a %= mod;
    while(b){
        if(b&1) res = (res * a) % mod;
        a *= a; a %= mod;
        b >>= 1;
    }
    return res%mod;
}
signed main(){
    int n,a;
    cin >> n >> a;
    vector<vector<int> > graph(n);
    for(int i =0;i<a;i++){
        int x,y;
        cin >> x >> y;
        --x;
        --y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int cnt[n];
    memset(cnt,-1,sizeof cnt);
    int used[n];
    memset(used,0,sizeof used);
    used[0] = 1;
    queue<int> q;
    q.push(0);
    while(q.size()){
        int x = q.front();
        q.pop();
        for(auto it:graph[x]){
            if(used[it]) continue;
            cnt[it] = x;
            used[it] = 1;
            q.push(it);
        }
    }
    if(count(used,used+n,0) > 0){
        cout << "No";
        return 0;
    }
    cout << "Yes\n";
    for(int i = 1;i<n;i++) cout << cnt[i]+1 << "\n";
}


Measured memory_bytes: 13736