akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
vector< ll > divisor(ll n) {  //約数の列挙
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool IsPrime(ll num)//素数
{
    if (num < 2ll) return false;
    else if (num == 2ll) return true;
    else if (num % 2ll == 0ll) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3ll; i <= sqrtNum; i += 2ll)
    {
        if (num % i == 0ll)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}



int main(){
    ll n,m;
    std::cin >> n>>m;
    std::vector<ll> dm=divisor(m),dn=divisor(n);
    std::vector<ll> dd;
    erep(i,dm)erep(j,dn){
        if(i==j)dd.pb(i);
    }
    int ans=1;
    erep(i,dd)if(IsPrime(i))ans++;
    std::cout << ans << std::endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int n = 0;
    
    for(int i=0; i<100; i = i+2){
        if(s[i]=='R' || s[i]=='U' || s[i]=='D'){
            n = n+1;
        }
    }
    for(int j=1; j<100; j = j+2){
        if(s[j]=='L' || s[j]=='U' || s[j]=='D'){
            n = n+1;
        }
    }
    
    if(n == s.length()){
        cout << "Yes" << endl;
    }
    if(n != s.length()){
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;
use std::cmp::min;

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();
    if b - a == c - b {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>
int main(void){
    int D,T,S;
    int time;
    scanf("%d",&D);
    scanf("%d",&T);
    scanf("%d",&S);
    time=T*S;
    if (time>=D)
        printf("Yes");
    else
        printf("No");
}

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

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

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

  int d1 = 0;
  int d2 = 0;
  long long d3 = 0;
  int dmax = 0;
  for (int i = 0; i < n; i++) {
    d1 += abs(x[i] - y[i]);
    d2 += (x[i] - y[i]) * (x[i] - y[i]);
    d3 += abs((x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]));
    dmax = max(abs(x[i] - y[i]) , dmax);
  }
  cout << fixed << setprecision(6);
  cout << d1 << endl;
  cout << sqrt(d2) << endl;
  cout << cbrt(d3) << endl;
  cout << dmax << endl;
} 


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






#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define pii                 pair<int,int>
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define pbp(a,b)            push_back({a,b})
#define db                  double
#define ft                  float
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define N                   100007
#define inf                 100000008
#define mod                 1000000007

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/





ll a[N];


int main()
{
    string g;
    ll n,i,k=1;
    cin>>n>>g;
    for(i=0;i<n-1;i++)
    {
        if(g[i]==g[i+1])
        {
            continue;
        }
        else
        {
            k++;
        }
    }
    cout<<k<<endl;
    return 0;

}
































Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i,n){cin>>a[i];}
  ll ans = 0;
  for (ll i = 0; i <n-1; i++) {
    if (a[i ] > a[i+1]) {
      ans += (a[i] - a[i + 1]);
      a[i +1] += (a[i] - a[i +1]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4832
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

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

struct node
{
  string s;
  int index;
  int val;
};

bool myfun(node p,node q)
{
    if(p.s==q.s)
    {
        if(p.val>q.val)
        return true;
        else
        return false;
    }
    else
    if(p.s<q.s)
    return true;
    
    return false;
}

int main()
{
    fsscan();
    int n;
    cin>>n;
    node a[n+1];
    for(int i=1;i<=n;i++)
    {
        string str;
        int y;
        cin>>str;
        cin>>y;
        a[i].s=str;
        a[i].val=y;
        a[i].index=i;
    }
    
    sort(a+1,a+n+1,myfun);
    
    for(int i=1;i<=n;i++)
    {
        cout<<a[i].index<<endl;
    }
    
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[100100];
int H[50];
ll N, K;

ll calc(ll X){
    ll num = 0;
    for(int i = 0; i < N; i++){
        num += X ^ A[i];
    }
    return num;
}

int main(){
    cin >> N >> K;
    REP(i, N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    int keta = 0;
    ll tmpK = K;
    while(tmpK > 0){
        tmpK /= 2;
        keta++;
    }


    for(int k = 0; k < 50; k++){
        int hbit = 0;
        for(int i = 0; i < N; i++){
            ll a = A[i];
            int bit = (a >> k) & 1;
            hbit += bit;
        }
        H[k] = hbit;
    }

    ll ans = calc(K);
    for(int i = 0; i < keta; i++){
        if(!((1LL<<i) & K)) continue;
        //printf("%lld\n", )
        ll X = 0;
        int j;
        for(j = 0; j < i; j++){
            //if(H[j] <= N/2){
            //    X += (1LL << j);
            //}
            if(H[j] <= N - H[j])
                X += (1LL << j);
        }
        for(j = j+1; j < keta; j++){
            if((1LL<<j) & K) X += (1LL<<j);
        }

        ans = max(ans, calc(X));
    }


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


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int w,l[31],n;
	int tmp,i,a,b;
	
	scanf("%d", &w);
	for (i = 1; i <= w; i++){
		l[i] = i;
	}
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d,%d", &a, &b);
		tmp = l[a];
		l[a] = l[b];
		l[b] = tmp;
	}
	for (i = 1; i <= w; i++){
		printf("%d\n", l[i]);
	}
	
	return (0);
}

Measured memory_bytes: 596
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <queue>

using namespace std;

int r,c;
int a[10005];
int b[10005];

//1 -> 0 , 1&0 , 1^1
//0 -> 1 , 0|1 , 0^1
// 1^0 = 1
// 0^0 = 0


int main()
{
    while(cin>>r>>c){
        if(r==0||c==0) break;
        memset(a,0,sizeof(a));
        int tmp;
        for(int i=0;i<r;++i){
            for(int j=0;j<c;++j){
                cin>>tmp;
                a[j] |= (tmp<<i);
            }
        }
        tmp = 1 << r;
        int m_max = 0;
        for(int i=0;i<tmp;++i){
            memcpy(b,a,c*sizeof(a[0]));
            int mm = 0;
            int shift = 0;
            int ii = i;
            while(ii){
                if(ii&1){
                    for(int j=0;j<c;++j){
                        b[j] ^= (1<<shift);
                    }
                }
                ii >>= 1;
                ++shift;
            }
            for(int j=0;j<c;++j){
                int num = 0;
                while(b[j]){
                    if(b[j]&1) num++;
                    b[j]>>=1;
                }
                mm += (num > (r-num)? num:(r-num));
            }
            if(mm>m_max) m_max = mm;
        }
        cout<<m_max<<endl;
    }
    return 0;
}



Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x);
#define rl(x) scanf("%lld",&x);
#define pi(x) printf("%d",x);
#define pl(x) printf("%lld",x);
#define lfd() printf("\n");
#define sp() printf(" ");
int n;
int f[120][12];
int p[120][12];
int exist[12];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=10;j++){
			cin>>f[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<=10;j++){
			cin>>p[i][j];
		}
	}
	int res=-2147483647;
	for(int i=1;i<1024;i++){
		for(int j=1;j<=10;j++)
			exist[j]=(i>>(j-1))&1;
		int cand=0;
		for(int j=1;j<=n;j++){
			int c=0;
			for(int k=1;k<=10;k++)
				c+=(exist[k]&&f[j][k]);
			cand+=p[j][c];
		}
		res=max(res,cand);
	}
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 256
from collections import Counter  # https://note.nkmk.me/python-scipy-connected-components/
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        N = int(input())
        D = list(map(int, input().split()))
        M = int(input())
        T = list(map(int, input().split()))

        DD = Counter(D)
        TT = Counter(T)

        for key, value in TT.items():
            if DD[key] < value:
                return 'NO'
        return 'YES'

    print(main())


resolve()

Measured memory_bytes: 123784
declare var require: (x: string) => any;

const MOD = 1000000007;

function mul(x: number, y: number){
  if (x == 1) return y;
  if (y == 1) return x;
  if (x == 0 || y == 0) return 0;
  let ans = 0;
  while(y > 0){
    ans += x * (y%100) % MOD;
    ans %= MOD;
    x = x * 100 % MOD;
    y = Math.floor(y/100);
  }
  return ans;
}

function Main(input: string[]) {
  const s = input[0];
  const n = s.length;

  let aa = new Float64Array(n);
  let cc = new Float64Array(n);
  let qq = new Float64Array(n);

  let totalq = s[0]=='?' ? 1 : 0;

  aa[0] = s[0]=='A' ? 1 : 0;
  qq[0] = s[0]=='?' ? 1 : 0;
  for(let i = 1; i < n; i++){
    if (s[i] == 'A'){
      aa[i] = aa[i-1] + 1;
    } else {
      aa[i] = aa[i-1];
    }

    if(s[i] == '?'){
      qq[i] = qq[i-1] + 1;
      totalq++;
    } else {
      qq[i] = qq[i-1];
    }
  }

  cc[n-1] = s[n-1]=='C' ? 1 : 0;
  for(let i = n - 2; i >= 0; i--){
    if (s[i] == 'C'){
      cc[i] = cc[i+1] + 1;
    } else {
      cc[i] = cc[i+1];
    }
  }

  let pow3 = new Float64Array(n);
  pow3[0] = 1;
  for(let i = 1; i < n; i++) {
    pow3[i] = pow3[i-1]*3;
    while(pow3[i] >= MOD) pow3[i] -= MOD;
  }

  let ans = 0;
  for (var i = 1; i < n-1; i++) if(s[i]=='?' || s[i]=='B'){
    let lv = mul(aa[i-1], pow3[qq[i-1]]);
    if(qq[i-1] > 0) lv += mul(qq[i-1], pow3[qq[i-1]-1]);
    lv %= MOD;

    let rq = totalq - qq[i];
    let rv = mul(cc[i+1], pow3[rq]);
    if(rq > 0) rv += mul(rq, pow3[rq - 1]);
    rv %= MOD;

    ans += mul(lv, rv);
    ans %= MOD;
  }

  console.log(ans);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'));


Measured memory_bytes: 13772
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VVC = vector<VC>;
using VS = vector<string>;
using VVS = vector<VS>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

int fact(int n)
{
  if (n == 0) return 1;
  return n * fact(n-1);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  VVB G(n, VB(n, false));
  REP(i, m)
  {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a][b] = true;
    G[b][a] = true;
  }
  int ans = 0;
  VVI PER;
  MAKE_PERMUTATION(n-1);
  REPx(x, PER)
  {
    if (!G[0][x[0]]) continue;
    bool flg = true;
    REP(i, n-2)
    {
      if (!G[x[i]][x[i+1]])
      {
        flg = false;
        break;
      }
    }
    if (flg) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("Os")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
}
ll ncr(ll n, ll r)
{
    if(n<r)
    {
        return 0;
    }
    if(r==0)
    {
        return 1;
    }
    ll ret=1LL;
    loop(i,0,r)
    {
        ret*=(n-i);
        ret%=mod;
        ret*=P(i+1,mod-2,mod);
        ret%=mod;
    }
    return ret;
}
int main()
{
    vok();
    int t;
    IN t;
    while(t--)
    {
        ll n;
        IN n;
        ll ans=0LL;
        loop(i,(n+1)%2,12)
        {
            ans+=((ncr(11,i)*ncr((n-i+25)/2,15))%mod);
            ans%=mod;
            i++;
        }
        OUT ans<<endl
    }
    return 0;
}

Measured memory_bytes: 3656
N = int(input())
a = list(map(int, input().strip().split()))
rel = 0
counter = 0
for i in range(0, N):
    minj = i
    for j in range(i+1,N):
        if(a[j]<a[minj]):
            minj = j
            rel += 1
    a[i],a[minj]=a[minj],a[i]
    if(rel>0):
      counter += 1
    rel = 0
print(*a)
print(counter)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    a = root(a);
    return -Parent[a];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }
};

int main(){
  ll n; cin >> n;
  string s = to_string(n);
  int cnt = s.size() - 1;
  int top = s[0] - '0';

  int ans = cnt*9 + top-1;
  bool ok = true;
  for(int i = 1; i < s.size(); i++){
    if(s[i] != '9'){
      ok = false;
    }
  }
  //全部９だったらtopはそのままで良い
  if(ok) ans++;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll x[200005], y[200005];

int main(void)
{
    ll n, d, cnt=0;

    scanf("%lld %lld" ,&n, &d);
    for(ll i=1; i<=n; i++)
    {
        scanf("%lld %lld" ,&x[i], &y[i]);
        if(x[i]*x[i]+y[i]*y[i]<=d*d)
            cnt++;
    }

    printf("%lld" ,cnt);
    return 0;
}


Measured memory_bytes: 6944
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
long long modpow(long long n, int k) {
	long long r = 1;
	while (k > 0) {
		if (k & 1) r = (r * n) % mod;
		n = (n * n) % mod;
		k >>= 1;
	}
	return r;
}
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> D;
	for (int i = 1; i*i <= N; ++i) if (N % i == 0) {
		D.push_back(i);
		if (N/i > i) D.push_back(N/i);
	}
	sort(D.begin(), D.end());
	map<int, int> num;
	long long res = 0;
	for (int i = 0; i < D.size(); ++i) {
		int d = D[i];
		long long r = modpow(K, (d + 1) / 2);
		for (int j = 0; j < i; ++j) if (d % D[j] == 0) {
			r = (r - num[D[j]] + mod) % mod;
		}
		num[d] = r;
		if (d % 2) {
			res = (res + r * d) % mod;
		} else {
			res = (res + r * (d / 2)) % mod;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 256
// Aizu Vol0 0078: Magic Square
// 2017.7.29

#include <stdio.h>
#include <stdlib.h>

char *gets(char *);
char buf[100];

#define MAX 15

int table[MAX + 1][MAX + 1];

int main()
{
	int r, c;
	int i, n, n2;

	while (1) {
		gets(buf);
		if ((n = atoi(buf)) == 0) break;
		for (r = 0; r < n; r++) for (c = 0; c < n; c++) table[r][c] = 0;
		r = n / 2 + 1, c = n / 2;
		table[r][c] = i = 1; n2 = n*n;
		while (i < n2) {
			r++, c++;
		Next:
			if (c >= n) c = 0;
			else if (c < 0) c = n - 1;
			if (r >= n) r = 0;
			if (table[r][c] == 0) {
				table[r][c] = ++i;
				continue;
			}
			r++, c--;
			goto Next;
		}
		for (r = 0; r < n; r++) {
			for (c = 0; c < n; c++)
				printf("%4d", table[r][c]);
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 536
#include <stdio.h>
int main()
{
    int a[100],i,n,m,j=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
       for(m=i+1;m<n;m++){
        j+=a[i]*a[m];
       }
    }
    printf("%d",j);
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
	char  n[5];
	scanf("%s", &n);
	if((n[0]==n[1]&&n[1]==n[2])||(n[1]==n[2]&&n[2]==n[3])){
		printf("Yes\n");
	} else {
		printf("No\n");
	}
  return 0;
}

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

int N;
long long S[200001];
long long P[4];
long long R = 1LL << 60;

void cut(int l, int r,
 long long& a, long long& b) {
  int i = lower_bound(
    S + l + 1, S + r, (S[l] + S[r] + 1) / 2) - S;
  if(i == r ||
    (i > l + 1 &&
      abs(S[l] + S[r] - 2 * S[i - 1])
      < abs(S[l] + S[r] - 2 * S[i]))) --i;
  a = S[i] - S[l]; b = S[r] - S[i];
}
int main() {
  cin >> N;
  for(int i = 0; i < N; ++i) {
    cin >> S[i + 1]; S[i + 1] += S[i];
  }
  for(int i = 2; i <= N - 2; ++i) {
    cut(0, i, P[0], P[1]);
    cut(i, N, P[2], P[3]);
    sort(P, P + 4);
    R = min(R, P[3] - P[0]);
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 1792
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn get_result(a_vec: &mut Vec<i32>) -> (i32, i32) {
    let mut alice_sum = 0;
    let mut bob_sum = 0;
    let mut cnt = 2;
    loop {
        let a = a_vec.pop();
        cnt = cnt + 1;
        match a {
            Some(a) => {
                if cnt % 2 == 1 {
                    alice_sum = alice_sum + a;
                } else {
                    bob_sum = bob_sum + a;
                }
            },
            None => {
                return (alice_sum, bob_sum);
            }
        }
    }
}

fn alice_vs_bob(a_vec: &mut Vec<i32>) -> Result<i32, String> {
    let (alice_sum, bob_sum) = get_result(a_vec);
    println!("{}", alice_sum - bob_sum);
    return Ok(0);
}

fn main() {
    input! {
        n: i32,
        a_vec_src: [i32; n]
    }
    let mut a_vec = a_vec_src.clone();
    a_vec.sort();
    match alice_vs_bob(&mut a_vec) {
        Ok(_) => {},
        Err(e) => {
            println!("{:?}", e);
        }
    }
}

Measured memory_bytes: 4352
#include<cstdio>
int n,dp[3001][3001],t[3001][3001],mi[3001],mo,xi,yi,sum,m,a[3001];
int main()
{
	scanf("%d%d",&n,&m);
	mo=1000000007;
	mi[0]=1;
	for(int i=1;i<=m;i++)mi[i]=(mi[i-1]*2)%mo;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)t[i][j]=dp[i][j]=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)if(j!=i)
	{
		if(a[i]>a[j])dp[i][j]=dp[i][j]+1;
	}
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&xi,&yi);
		for(int j=1;j<=n;j++)
		{
			if((j!=xi)&&(j!=yi))
			{
				dp[xi][j]=(1ll*dp[xi][j]*mi[i-t[xi][j]-1])%mo;
				dp[yi][j]=(1ll*dp[yi][j]*mi[i-t[yi][j]-1])%mo;
				sum=(dp[xi][j]+dp[yi][j])%mo;
				dp[xi][j]=dp[yi][j]=sum;
				t[xi][j]=t[yi][j]=i;
				dp[j][xi]=(1ll*dp[j][xi]*mi[i-t[j][xi]-1])%mo;
				dp[j][yi]=(1ll*dp[j][yi]*mi[i-t[j][yi]-1])%mo;
				sum=(dp[j][xi]+dp[j][yi])%mo;
				dp[j][xi]=dp[j][yi]=sum;
				t[j][xi]=t[j][yi]=i; 
			}
			
		}
		dp[xi][yi]=(1ll*dp[xi][yi]*mi[i-t[xi][yi]-1])%mo;
		dp[yi][xi]=(1ll*dp[yi][xi]*mi[i-t[yi][xi]-1])%mo;
		sum=(dp[yi][xi]+dp[xi][yi])%mo;			
		dp[yi][xi]=dp[xi][yi]=sum;
		t[yi][xi]=t[xi][yi]=i; 
	}
	sum=0;
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++)sum=(sum+1ll*dp[i][j]*mi[m-t[i][j]])%mo;
	printf("%d\n",sum);
}

Measured memory_bytes: 70528
N = gets.to_i
num = gets.split.map(&:to_i)
kanri = []
ans = 0

(0..num.length - 1).each do |cnt|
  if cnt % 2 == 0
    kanri.push(cnt)
  end
end

kanri.each do |no|
  if num[no] % 2 == 1
    ans += 1
  end
end

puts ans


Measured memory_bytes: 14288
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

    string str;
    cin >> str;
    
    if(str[0] == str[1] && str[2] == str[3] && str[0] != str[2]){
    }else if(str[0] == str[2] && str[1] == str[3] && str[0] != str[1]){
    }else if(str[0] == str[3] && str[1] == str[2] && str[0] != str[1]){
    }else{
      COUT("No");
      return 0;
    }
  
    COUT("Yes");
  
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
map<string, int> m;
int main() {
	string s;
	string t;
	int a, b;
	cin >> s >> t;
	cin >> a >> b;
	m[s] = a;
	m[t] = b;
	string u;
	cin >> u;
	m[u]--;
	cout << m[s] << " " << m[t] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<algorithm> 
#define int long long
using namespace std;

signed main() {
	int n, m; cin >> n >> m;
	if (n == 1) { cout << m << endl; return 0; }
	int ans = 1;
	for (int i = 2; i*i <= m; i++) {
		if (i*n<=m&&m%i == 0) {
			ans = max(ans, i);
			int j = m / i;
			if (j*n <= m&&m%j == 0) {
				ans = max(ans, j);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())

A = list(map(int, raw_input().split()))

(dp0, dp1) = (1, 0)
for x in A:
    (ndp0, ndp1) = (0, 0)
    for y in range(x - 1, x + 2):
        if y % 2 == 0:
            ndp1 += dp0
            ndp1 += dp1
        else:
            ndp0 += dp0
            ndp1 += dp1
    (dp0, dp1) = (ndp0, ndp1)
print dp1


Measured memory_bytes: 2568
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
long long n,com[30][30],dp[1<<22],c[1<<22];
vector<int> G[1<<22];
int main()
{
	cin >> n;
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			cin >> com[i][j];
	for(int i=0; i<(1<<n); i++) for(int j=0; j<n; j++) if(i&(1<<j)) G[i].push_back(j),c[i]++;
	for(int i=0; i<n; i++) dp[1<<i]=com[0][i];
	for(int i=1; i<n; i++)
		for(int j=0; j<(1<<n); j++) if(c[j] == i+1)
			for(auto k:G[j])
				if(com[i][k])
					dp[j]=(dp[j]+dp[j&~(1<<k)])%MOD;
					
	cout << dp[(1<<n)-1];
	return 0;
}

Measured memory_bytes: 286348
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())
ans = 0
for i in range(1, N+1, 2):
    if len(make_divisors(i)) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
class Card
{
public: char v1, v2;
};
int main()
{
    int n;
    scanf("%d\n", &n);
    vector<Card> a(n);
    for (int i = 0; i < n - 1; i++)
    {
        scanf("%c%c ", &a[i].v1, &a[i].v2);
    }
    scanf("%c%c", &a[n - 1].v1, &a[n - 1].v2);
    vector<Card> b = a;
    bool bubble = true;
    while (bubble)
    {
        bubble = false;
        for (int i = n - 1; i >= 0; i--)
        {
            if(a[i - 1].v2 > a[i].v2)
            {
                swap(a[i - 1], a[i]);
                bubble = true;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        int mini = i;
        for (int j = i + 1; j < n; j++)
        {
            if(b[mini].v2 > b[j].v2)
            {
                mini = j;
            }
        }
        swap(b[i], b[mini]);
    }
    for (int i = 0; i < n - 1; i++)
    {
        printf("%c%c ", a[i].v1, a[i].v2);
    }
    printf("%c%c\nStable\n", a[n - 1].v1, a[n - 1].v2);
    bool check = true;
    for (int i = 0; i < n; i++)
    {
        if(check && a[i].v1 != b[i].v1)
        {
            check = false;
        }
        if(i < n - 1)
        {
            printf("%c%c ", b[i].v1, b[i].v2);
        }
        else
        {
            if(check)
            {
                printf("%c%c\nStable\n", b[n - 1].v1, b[n - 1].v2);
            }
            else
            {
                printf("%c%c\nNot stable\n", b[n - 1].v1, b[n - 1].v2);
            }
        }
    }
}


Measured memory_bytes: 3260
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    

    ll n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    int flag = 0;
    for (ll m=0;m<n;m++){
        if(b-a >= c*(n-1-m) - d*m and b-a <= -c*m +(n-1-m)*d){
            cout << "YES" << endl;
            flag = 1;
            break;
        }
    }
    if(flag == 0){
        cout << "NO" << endl;
    }

}




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

using namespace std;

int main(){
    int N;

    cin >> N ;

    int ans = 0;
    int cnt = 0;
    for(int i = 1; i <= N; i += 2){
        for(int j = 1; j <= i; j++){
            if( i % j == 0 ) cnt++;
        }
        if( cnt == 8 ) ans++;
        cnt = 0;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main( )
{
	int a[10001],k,n;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	int sum=0;
	sort(a+1,a+n+1);
	for(int i=n-k+1;i<=n;i++) sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int a, b, c;
int main(){
    int s=0,i;
    scanf("%d %d",&a, &b);
    for(i=0;i<b;i++){
        scanf("%d",&c);
        if(c>(a+1)/2)s=(c-(a+1)/2)*2-1;
    }
    printf("%d",s);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>
#include <bitset>

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<long long int, P> P2;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[2100][2100];

int main(){
	int N;
	cin >> N;
	vector<P> v;
	for(int i = 0; i < N; i++){
		P p;
		cin >> p.first;
		p.second = i;
		v.push_back(p);
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	for(int i = 0; i < N; i++){
		P p = v[i];
		DP[i + 1][0] = DP[i][0] + p.first * (p.second - i);
		DP[0][i + 1] = DP[0][i] + p.first * (N - 1 - p.second - i);
		for(int j = 1; j < i + 1; j++){
			DP[j][i + 1 - j] = max(
				DP[j - 1][i + 1 - j] + p.first * (p.second - (j - 1)),
				DP[j][i - j] + p.first * (N - 1 - p.second - (i - j))
			);
		}
	}
	long long int ans = 0;
	for(int i = 0; i <= N; i++){
		ans = max(ans, DP[i][N - i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 26568
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  if (unique(s.begin(), s.end())==s.end()) cout << "yes" << endl;
  else cout << "no" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N	100000

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

int main() {
	static int tt[N + 1], ll[N + 1], rr[N + 1], xx[N + 1];
	int n, q, x_, i, x, l, r;

	scanf("%d%d", &x_, &n);
	for (i = 1; i <= n; i++)
		scanf("%d", &tt[i]);
	l = r = x = 0;
	for (i = 0; i <= n; i++) {
		if (i > 0)
			x += (i % 2 == 0 ? 1 : -1) * (tt[i] - tt[i - 1]);
		ll[i] = l = min(l, x);
		rr[i] = r = max(r, x);
	}
	x = 0;
	for (i = 0; i <= n; i++) {
		if (i > 0)
			x = min(max(x += (i % 2 == 0 ? 1 : -1) * (tt[i] - tt[i - 1]), 0), x_);
		xx[i] = x;
	}
	scanf("%d", &q);
	i = 0;
	while (q--) {
		int t, a, ans;

		scanf("%d%d", &t, &a);
		while (i < n && tt[i + 1] <= t)
			i++;
		if (rr[i] - ll[i] > x_ || a + ll[i] < 0)
			ans = xx[i];
		else if (a + rr[i] >= x_)
			ans = xx[i] + (x_ - (rr[i] - ll[i]));
		else
			ans = xx[i] + a + ll[i];
		ans = min(max(ans + ((i + 1) % 2 == 0 ? 1 : -1) * (t - tt[i]), 0), x_);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 3296
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()

edges = [[] for _ in range(N)]

for _ in range(N-1):
    u,v,w = imn()
    u -= 1
    v -= 1
    edges[u].append((v,w))
    edges[v].append((u,w))

colors = [None] * (N)

def set_color(vertex, color):
    colors[vertex] = color
    for v, w in edges[vertex]:
        if colors[v] == None:
            next_color = color
            if w % 2 == 1:
                next_color = (next_color+1)%2
            set_color(v, next_color)
set_color(0, 0)

for c in colors:
    print(c)


Measured memory_bytes: 81388
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

func Factorial(N int) (F, Finv, Inv []int) {
  F = make([]int, N + 1)
  Finv = make([]int, N + 1)
  Inv = make([]int, N + 1)
  F[0] = 1
  F[1] = 1
  Finv[0] = 1
  Finv[1] = 1
  Inv[0] = 1
  Inv[1] = 1
  for i := 2; i < N + 1; i++ {
    F[i] = F[i - 1] * i % p
    Inv[i] = p - Inv[p % i] * (p / i) % p
    Finv[i] = Finv[i - 1] * Inv[i] % p
  }
  return
}

func Comb(Finv []int, n, a int) int {
  C := 1
  for i := 0; i < a; i++ {
    C = C * (n - i) % p
  }
  return C * Finv[a] % p
}

const p = 1000000007

func Solve() {
  var n, a, b int
  NextInt(&n, &a, &b)
  _, Finv, _ := Factorial(b)
  k := 1
  for _n := 1; _n < n; _n *= 2 { k++ }
  B := make([]int, k)
  B[0] = 2
  for i := range B[1:] {
    B[i + 1] = B[i] * B[i] % p
  }
  N := 1
  for i, _n := 0, n; 0 < _n; i++ {
    if 0 < _n % 2 { N = (N * B[i]) % p }
    _n /= 2
  }
  N--
  Write((N + 2 * p - Comb(Finv, n, a) - Comb(Finv, n, b)) % p)
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

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

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;cin>>N>>K;
    vector<ll> A,B,C,D,a,b,c;
    for(int i=0;i<N;i++){
        ll a;cin>>a;
        
        D.push_back(a);
    }
    
    sort(all(D),[](auto a,auto b){
        return abs(a)>abs(b);
    });
    
    ll ans=1;
    
    int cnt=0;
    for(int i=0;i<K;i++){
        ans*=abs(D[i]);
        ans%=mod;
        if(D[i]<0) cnt++;
    }
    
    if(D[K-1]==0){
        cout<<0<<endl;
        return 0;
    }
    
    if(cnt&1){
        if(N==K){
            cout<<(mod-ans)%mod<<endl;
        }else{
            for(int i=K-1;i>=0;i--){
                if(D[i]>0) a.push_back(D[i]);
                if(D[i]<0) b.push_back(-D[i]);
                if(D[i]==0) c.push_back(D[i]);
            }
            
            for(int i=K;i<N;i++){
                if(D[i]>0) A.push_back(D[i]);
                if(D[i]<0) B.push_back(-D[i]);
                if(D[i]==0) C.push_back(D[i]);
            }
            
            pair<pair<ll,ll>,int> ma={mp(0,1),-1};
            
            if(si(A)&&si(b)){
                if(ma.fi.fi*b[0]<ma.fi.se*A[0]){
                    ma=mp(mp(A[0],b[0]),0);
                }
            }
            if(si(B)&&si(a)){
                if(ma.fi.fi*a[0]<ma.fi.se*B[0]){
                    ma=mp(mp(B[0],a[0]),1);
                }
            }
            
            if(ma.se!=-1){
                if(ma.se==0){
                    ans*=rui(b[0],mod-2);
                    ans%=mod;
                    
                    ans*=A[0];
                    ans%=mod;
                    
                    cout<<ans<<endl;
                }else{
                    ans*=rui(a[0],mod-2);
                    ans%=mod;
                    
                    ans*=B[0];
                    ans%=mod;
                    
                    cout<<ans<<endl;
                }
            }else{
                if(si(C)) cout<<0<<endl;
                else{
                    ans=1;
                    for(int i=0;i<K;i++){
                        ans*=abs(D[N-1-i]);
                        ans%=mod;
                    }
                    cout<<(mod-ans)%mod<<endl;
                }
            }
        }
    }else{
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 8112