akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
using namespace std;

int main(){
    int K;
    cin>>K;
    int even=K/2;
    int odd=K-even;
    cout<<even*odd;
    
    return 0;
}

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

int main(){
  int isPrime[1000000];
  for(int i = 2; i < 1000000 ; i++)isPrime[i] = 1;
  isPrime[0]  = isPrime[1] = 0; 
  for(int i = 2 ; i*i < 1000000 ; i++ ){
    if(isPrime[i])for(int j = i*2 ; j < 1000000 ; j+=i)isPrime[j] = 0;
}

  int n;
  while(  cin >> n ){
    int cnt = 0;
    for(int i = 2 ; i <= n ; i++  ){
      if(isPrime[i])cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 5064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <numeric>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

#define rep(i,n) for(int i = 0; i<n ; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)
#define REPSTR(i,s) for(int i=0; (s)[i]; i++)
#define REPITR(i,s) for(auto i=(s)begin(); i!=(s).end();i++)

#define RANGE(a,i,b) ((a)<=(i)&&(i)<=(b))

#define pb push_back
#define mp make_pair

#define ALL(a) (a).begin(), (a).end()

#define EXIST(s,x) ((s).find(x)!=(s).end())

#define SET(a,c) memset(a,c,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))

#define DEBUG(x) cerr<<#x<<":"<<x<<endl
#define PRINTJOIN(x,n) rep(i,n){if(i)cout<<" ";cout<<x[i];}cout<<endl 

#define INF 1001001001
#define LLINF 1001001001001001001LL

typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef stringstream SS;

#define PQ priority_queue

#define FST first
#define SEC second

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

//------------------HEAD---------------------

struct edge{int to,cost;};
vector<edge> G[100000];
VI _G[100000];
long long d[100000];
int N,M,K,S;
int P,Q;
int state[100000];
bool danger[100000];

ll dijkstra(int s, int g){
    PQ<PII,vector<PII>,greater<PII>>Q;
    fill(d,d+N,LLINF);
    d[s]=0;
    Q.push(PII(0,s));
    while(!Q.empty()){
        PII p=Q.top();Q.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                Q.push(PII(d[e.to],e.to));
            }
        }
    }
    return d[g];
}

void setstate(int a, int depth){
    //cerr<<"set "<<a<<endl;
    if(state[a]!=0)return;
    state[a]=2;//dangerous
    if(depth<S){
        for(int i:_G[a]){
            setstate(i,depth+1);
        }
    }
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>M>>K>>S;
    cin>>P>>Q;
    VI zomb;
    
    queue<ll> q;
    rep(i,K){
        int t;
        cin>>t;
        state[t-1]=1;//zombie;
        zomb.pb(t-1);
        q.push(t-1);
    }
    rep(i,M){
        int a,b;
        cin>>a>>b;
        _G[a-1].pb(b-1);
        _G[b-1].pb(a-1);
    }/*
    for(int a:zomb){
        //cerr<<"zombied: "<<a<<endl;
        for(int i:_G[a]){
            //cerr<<"goto "<<i<<endl;
            setstate(i,1);
        }
    }*/
    for(ll i = 0;i <= S;i++){
		if(q.empty())break;
		
		for(ll j = q.size() - 1;j >= 0;j--){
			ll from = q.front();q.pop();
			if(danger[from])continue;
			danger[from] = true;
			for(ll k = 0;k < _G[from].size();k++){
				q.push(_G[from][k]);
			}
		}
	}
    rep(i,N){
        for(int v:_G[i]){
            if(v==0||state[v]==1)continue;
            edge e;
            e.to=v;
            if(!danger[v])e.cost=P;
            //if(state[v]==1)e.cost=INF;
            if(danger[v])e.cost=Q;
            if(v==N-1)e.cost=0;
            G[i].pb(e);
        }
    }
    cout<<dijkstra(0,N-1)<<endl;

    return 0;
}


Measured memory_bytes: 18592
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n // r + 1):
  for j in range((n - r * i) // g + 1):
    if (n - r * i - g * j) % b == 0 and (n - r * i - g * j) // b >= 0:
      ans += 1
print(ans)

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

int main(){
  int N;
  cin >> N;
  
  int A[N];
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  
  sort(A, A+N);
  cout << A[N-1] - A[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 1010;
const int MAXM = 1000010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, m;
ll dp[MAXN][MAXN];
char ch[MAXN][MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,n) FOR(j,1,m) cin >> ch[i][j];
    dp[1][1] = 1;
    FOR(i,1,n)
        FOR(j,1,m) {
            if (i == 1 && j == 1) continue;
            if (ch[i][j] == '#') continue;
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MODBASE;
        }
    cout << dp[n][m];
    return 0;
}


Measured memory_bytes: 9088
//only consider the lowest volume of traffic
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int cnt = 0;
	int oddBlack = 0;
	int evenBlack = 0;
	int oddWhite = 0;
	int evenWhite = 0;

	for(int i = 0; i < s.size(); i += 1)
	{
		if(i % 2 == 1)
		{
			if(s[i] == '1')
			{
				oddWhite += 1;
			}
			else
			{
				oddBlack += 1;
			}
		}
		else
		{
			if(s[i] == '1')
			{
				evenWhite += 1;
			}
			else
			{
				evenBlack += 1;
			}
		}
	}
	cnt = min(oddWhite + evenBlack, oddBlack + evenWhite);

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 512
n = int(input())
cnt = 0

for i in range(1, n + 1):
    count = 0
    if i % 2 != 0:
        for j in range(1, i + 1):
            if i % j == 0:
                count += 1

        if count == 8:
            cnt += 1

print(cnt)

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

int main()
{
ll n , m ;
cin >> n >> m ;
vector<ll> num(n,1);
vector<bool> ok(n);
ok[0]=1;
rep(i,m){
  ll x , y ;
  cin >> x >> y ;
  x--;y--;
  if(num[x]>1&&ok[x]){
    num[x]--;
    num[y]++;
    ok[y]=1;
  }
  else if(num[x]==1&&ok[x]){
    num[x]--;
    ok[x]=0;
    num[y]++;
    ok[y]=1;
  }
  else{
    num[x]--;
    num[y]++;
  }
}
for(auto an:ok)if(an)ans++;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
B=sum(A)
result=0
for i in range(0,N-1):
  #print(i)
  #print(A[i])
  #print(A[i+1])
  if A[i]>A[i+1]:
    #result=result+(A[i]-A[i+1])
    A[i+1]=A[i]
    #print(result)

print(sum(A)-B)


Measured memory_bytes: 105364
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  vi t(N);
  rep(i,N) cin >> s[i] >> t[i];
  string X;
  cin >> X;
  
  int a;
  rep(i,N) {
    if(X==s[i]) {
      a=i;
      break;
    }
  }
  int ans=0;
  rep2(i,a+1,N) ans+=t[i];
  
  cout << ans << endl;
}

Measured memory_bytes: 256
program Switches
    implicit none
    integer(4):: n,m
    integer(4):: i,cnt
    integer(4),allocatable:: k(:), s(:,:),p(:)

    read*, n,m
    allocate(k(m), s(n,n), p(m))
    do i=1,m
        read*, k(i), s(1:k(i),i)
    end do
    read*, p(:)

    cnt = 0
    do i=0,2**(n)-1
        if (all_light(i)) cnt=cnt+1
    end do
    print*, cnt

contains
function all_light(num) result(ret)
    integer(4):: num
    integer(4):: i
    logical:: ret
    
    ret = .true.
    do i=1,m
        if (.not. lon(s(1:k(i),i),num,p(i))) ret = .false.
    end do
end function

function lon(ar,num,p) result(ret)
    integer(4):: ar(:),num,p
    integer(4):: i,cnt=0
    logical:: ret

    cnt=0
    do i=1,size(ar)
        if (mod(rshift(num,ar(i)-1),2) == 1) cnt=cnt+1
    end do
    ret = .false.
    if (mod(cnt,2) == p) ret = .true.
end function
end program Switches

Measured memory_bytes: 384
import Text.Printf

norm :: [Double]->Double
norm v = (sum $ map (**2.0) v)**0.5

dist :: [Double]->[Double]->Double
dist v1 v2 = norm $ zipWith (-) v1 v2

heron :: Double->Double->Double->Double
heron a b c = (z*(z-a)*(z-b)*(z-c))**0.5
    where z = (a+b+c)/2.0

heron' :: [Double]->[Double]->[Double]->Double
heron' pa pb pc = heron a b c
    where a = dist pb pc
          b = dist pa pc
          c = dist pa pb

center :: [[Double]] -> [Double]
center plst = map (/np) $ [sum $ map (\p->p!!0) plst, sum $ map (\p->p!!1) plst]
    where np = realToFrac(length plst)

area :: [[Double]] -> Double
area plst = sum $ map (\i->heron' pc (plst'!!i) (plst'!!(i+1))) [0..((length plst')-2)]
    where plst' = plst ++ [head plst]
          pc = center plst

main :: IO ()
main = do
    str<-getContents::IO String
    let plst = map (\x->read ("["++x++"]")::[Double]) . lines $ str
    printf "%.6f\n" (area plst)

Measured memory_bytes: 4292
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=100000 +117;
const int MM=100000 +117;
const int mod=1e9+7;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
struct BIAN{
	int x,y,v;
	bool on;
}e[2*NN]={};
struct edge{
	int to,len;
};
vector<edge> p[NN]={};
LL lim;
LL real=0;
int bel[NN]={};
void initi(int n){
	for(int i=1;i<=n;++i)bel[i]=i;
}
int getfa(int x){
	return x==bel[x]?x:bel[x]=getfa(bel[x]);
}
bool link(int x,int y){
	if(getfa(x)==getfa(y))return false;
	bel[bel[x]]=bel[y];
	return true;
}
bool cmp(BIAN a,BIAN b){
	return a.v<b.v;
}
void gettree(){
	initi(n);
	sort(e+1,e+1+m,cmp);
	for(int i=1;i<=m;++i){
		if(link(e[i].x,e[i].y)){
			edge tp;
			tp.len=e[i].v;
			tp.to=e[i].y;
			p[e[i].x].push_back(tp);
			tp.to=e[i].x;
			p[e[i].y].push_back(tp);
			real+=e[i].v;
			e[i].on=1;
		}
	}
}
LL ksm(LL a,LL b){
	LL ret=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)ret=ret*a%mod;
	return ret;
}
int dep[NN]={};
int fa[NN]={};
int vfa[NN]={};
void dfs(int x,int f){
	fa[x]=f;
	dep[x]=dep[f]+1;
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i].to;
		if(cur!=f){
			vfa[cur]=p[x][i].len;
			dfs(cur,x);
		}
	}
}
int getmax(int x,int y){
	int ans=0;
	while(x!=y){
		if(dep[x]<dep[y])swap(x,y);
		ans=max(ans,vfa[x]);
		x=fa[x];
	}
	return ans;
}
int main(){
	//open();
	n=read();
	m=read();
	scanf("%lld",&lim);
	for(int i=1;i<=m;++i){
		e[i].x=read();
		e[i].y=read();
		e[i].v=read();
	}
	gettree();
	if(real>lim){
		printf("0\n");
		return 0;
	}
	dfs(1,0);
	int sam=0;
	int rem=0;
	LL v=lim-real;
	for(int i=1;i<=m;++i){
		if(!e[i].on){
			if(v==e[i].v-getmax(e[i].x,e[i].y)){
				++sam;
			}
			if(v<e[i].v-getmax(e[i].x,e[i].y)){
				++rem;
			}
		}
	}
	LL ans=0;
	if(lim==real){
		ans=(ksm(2,n-1)-2)*ksm(2,m-n+1)%mod;
	}
	ans+=2*(ksm(2,sam)-1)*ksm(2,rem)%mod;
	ans%=mod;
	ans=(ans+mod)%mod;
	printf("%lld\n",ans);
	close();
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  vector<int> P;
  vector<bool> Pb(111111, false);
  Pb.at(2) = true;
  for (int p = 3; p < 111111; p += 2)
  {
    bool ok = true;
    for (int i = 0; i < P.size(); i++)
    {
      int PP = P.at(i);
      if (PP * PP > p) break;
      if (p % PP == 0)
      {
        ok = false;
        break;
      }
    }
    if (ok)
    {
      P.push_back(p);
      Pb.at(p) = true;
    }
  }
  
  vector<int> ans(111111, 0);
  for (int n = 3; n < 111111; n += 2)
  {
    ans.at(n) = ans.at(n - 2);
    if (Pb.at(n) && Pb.at((n + 1) / 2)) ans.at(n)++;
  }
  
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++)
  {
    int l, r;
    cin >> l >> r;
    cout << ans.at(r) - ans.at(max((int)1, l - 2)) << endl;
  }
}

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

using namespace std;

typedef pair<double, int> P;
const int INF = numeric_limits<int>::max() / 2;

struct cell {
	double x, y, z, r;
};

double calc(cell p, cell q) {
	double tmp = sqrt((p.x - q.x)*(p.x - q.x) + (p.y - q.y)* (p.y - q.y) + (p.z - q.z)*(p.z - q.z));
	if (tmp <= p.r + q.r) return 0;
	else return (-p.r - q.r + tmp);
}

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

	while (true) {
		int n; cin >> n;
		if (n == 0) break;
		vector<cell> cells;
		for (int i = 0; i < n; i++) {
			cell c;
			cin >> c.x >> c.y >> c.z >> c.r;
			cells.push_back(c);
		}
		vector<vector<double> > dis(n, vector<double>(n, INF));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i == j) dis[i][j] = 0;
				else {
					dis[i][j] = calc(cells[i], cells[j]);
				}
			}
		}
		vector<bool> used(n, false);
		priority_queue<P,vector<P>,greater<P> > que;
		double res = 0;
		que.push(P(0, 0));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			if (used[p.second]) continue;
			used[p.second] = true;
			res += p.first;
			for (int i = 0; i < n; i++) {
				if (!used[i]) {
					que.push(P(dis[p.second][i], i));
				}
			}
		}
		cout << fixed<<setprecision(3)<<res << endl;
	}
}

Measured memory_bytes: 3356
import sys,math
try:sys.stdin,sys.stdout=open('input.txt','r'),open('out.txt','w')
except:pass
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt,log
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(arr, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if arr[mid] == val:return mid
        elif arr[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,arr):
    for i in range(1,n):arr[i]+=arr[i-1]
    return arr;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;
# code start from here-

s=is1()
if s[0]==s[1]==s[2]=='R':
    print(3)
elif s[0]==s[1]=='R' or s[1]==s[2]=='R' :
    print(2)
elif s[0]=='R' or s[1]=='R' or s[2]=='R':
    print(1)
else:
    print(0)


Measured memory_bytes: 10900
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	A, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	scanner.Scan()
	B, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}
	scanner.Scan()
	C, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	if !(A == B && B == C && C == A) {
		if A == B || B == C || C == A {
			fmt.Println("Yes")
			os.Exit(0)
		}
	}

	fmt.Println("No")

}


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


int dfs(int now,
        vector<vector<int> >& adjlist,
        vector<bool>& used){
  int ans = 1;
  for(size_t i = 0; i < adjlist[now].size(); i++){
    int next = adjlist[now][i];
    if(!used[next]){
      used[next] = true;
      ans += dfs(next, adjlist, used);
    }
  }
  
  return ans;
}

long long int edgesize_K(long long int n){
  if((n - 1) % 2 == 0)
    return n * ((n - 1) / 2);
  else
    return edgesize_K(n - 1) + (n - 1);
}


int main(void){
  int n, m;
  cin >> n >> m;
  
  int a, b;
  vector<vector<int> > adjlist(n);
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    --a;
    --b;
    adjlist[a].push_back(b);
    adjlist[b].push_back(a);
  }

  vector<bool> used0(n, false);
  used0[0] = true;
  int size0 = dfs(0, adjlist, used0);

  vector<bool> used1(n, false);
  used1[1] = true;
  int size1 = dfs(1, adjlist, used1);

  if(size0 > size1)
    size0 += n - (size0 + size1);
  else
    size1 += n - (size0 + size1);

  long long int ans =
    edgesize_K(size0)
    + edgesize_K(size1)
    - m;
  cout << ans << endl;
  
  return 0;
}


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

int main(void)
{
    int n;
    int c, *v;
    int x = 0;

    cin >> n;
    v = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c;
        if (v[i] - c > 0) {
            x += v[i] - c;
        }
    }
    cout << x << endl;

    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
#include <atcoder/math>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()


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

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

	//vector<long long> r = { 2,3 }, m={ 5,7 };

	//auto p = atcoder::crt(r, m);

	//cout << p.first << ' ' << p.second << endl;

	vector<long long> r = {0, -1}, m(2);
	long long n;
	cin >> n;
	long long ans = 1LL << 60;

	for (long long i = 1; i * i <= 2 * n ; i++) {
		if ((2 * n) % i == 0) {
			long long x = i;
			long long y = 2 * n / i;
			m[0] = x;
			m[1] = y;
			auto p = atcoder::crt(r, m);
			if (p.first != 0)ans = min(ans, p.first);

			m[0] = y;
			m[1] = x;
			p = atcoder::crt(r, m);
			if (p.first != 0)ans = min(ans, p.first);
		}
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3648
n = int(input())
ans = [0 for _ in range(n + 1)]
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            v = i*i + j*j + k*k +i*k +k*j+j*i
            if v < n+1:
                ans[int(v)] += 1
for i in range(n):
    print(ans[i+1])

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main()
{
    int N;
    int a = 0,b = 0;
    string S;
    cin >> N;
    cin >> S;
    for(int i = 0; i < N; i++)
    {
        if(S[i] == 'R')a++;
        else b++;
    }
    if(a > b)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

int f(int a,int b,int x){
    return (a*x)/b - a*(x/b);
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,n,ans;
    cin>>a>>b>>n;
    if(n<b){ans = f(a,b,n);}
    else{ans = f(a,b,b-1);}
    cout<<ans<<endl;
}

Measured memory_bytes: 3652
import sys, bisect
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))

N = read_int()[0]
A = sorted(read_int())
B = sorted(read_int())
C = sorted(read_int())

def solve():
    ans = 0
    # memo
    memo = [0 for _ in range(N + 1)]
    for i in range(N - 1, -1, -1):
        lbc = bisect.bisect_right(C,B[i])
        memo[i] += N - lbc
        if i > 0:
            memo[i - 1] = memo[i]
    for i in range(N):
        lbb = bisect.bisect_right(B,A[i])
        ans += memo[lbb]
    return ans


if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 23908
#include<stdio.h>
#define  _CRT_SECURE_NO_WARNINGS

int main() {
	int a, b;
	scanf("%d %d", &a, &b);

	int d = a / b;
	int r = a % b;
	double f = (1.0 * a / b);

	printf("%d %d %.8lf\n", d, r, f);
        return 0;
}

Measured memory_bytes: 640
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 1001000
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    cin.sync_with_stdio(false);
    ll a,b,c;cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
global opposite
opposite = {"S": "W",
            "W": "S"}

def generate(ans,s,N):
  global opposite
  for i in range(1,N-1):
    if ans[i] == "S" and s[i] == "o":
      ans += ans[i-1]
    elif ans[i] == "S" and s[i] == "x":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and s[i] == "o":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and s[i] == "x":
      ans += ans[i-1]
  
  if ans[-1] == "S":
    if (s[-1] == "o" and ans[-2] != ans[0]) or (s[-1] == "x" and ans[-2] == ans[0]):
      return True
  if ans[-1] == "W":
    if (s[-1] == "o" and ans[-2] == ans[0]) or (s[-1] == "x" and ans[-2] != ans[0]):
      return True
  if ans[0] == "S":
    if (s[0] == "o" and ans[-1] != ans[1]) or (s[0] == "x" and ans[-1] == ans[1]):
      return True
  if ans[0] == "W":
    if (s[0] == "o" and ans[-1] == ans[1]) or (s[0] == "x" and ans[-1] != ans[1]):
      return True
  print(ans)

N = int(input())
S = input()
if generate("SS",S,N):
  if generate("SW",S,N):
    if generate("WS",S,N):
      if generate("WW",S,N):
        print(-1)




Measured memory_bytes: 3572
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define ll long long
#define vi vector <int>
#define vvi vector <vector<int> >
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>=b;i--)
#define init(i,k) memset(i,k,sizeof i)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
inline ll add(ll a, ll b){ return ((a%MOD)+(b%MOD))%MOD;}
inline ll mul(ll a, ll b){ return ((a%MOD)*(b%MOD))%MOD;}
inline ll sub(ll a, ll b){ return ((a%MOD)-(b%MOD)+MOD)%MOD;}
// const int N = 1e5+7;
 
#define deb(x) {x}
#ifndef local
	#define deb(x) ;
#endif
///---------------------------------------------------------------

void solve()
{
	int n;cin>>n;
	string s;cin>>s;
	// cout<<s<<endl;
	vi r(n,0),g(n,0),b(n,0);
	if(s[0]=='R')r[0]++;
	if(s[0]=='G')g[0]++;
	if(s[0]=='B')b[0]++;
	rep(i,1,n){
		if(s[i]=='R')r[i]++;
		if(s[i]=='G')g[i]++;
		if(s[i]=='B')b[i]++;
		r[i]+=r[i-1];
		g[i]+=g[i-1];
		b[i]+=b[i-1];
	}
	// rep(i,0,n)cout<<r[i]<<" ";cout<<endl;
	// rep(i,0,n)cout<<g[i]<<" ";cout<<endl;
	// rep(i,0,n)cout<<b[i]<<" ";cout<<endl;
	vi a(n);
	rep(i,0,n){
		if(s[i]=='R')a[i]=0;
		if(s[i]=='G')a[i]=1;
		if(s[i]=='B')a[i]=2;
	}
	// rep(i,0,n)cout<<a[i]<<" ";cout<<endl;
	int ans=0;
	rep(i,0,n-3){
		rep(j,i+3,n){
			if(s[i]!=s[j]){
				// cout<<i<<" "<<j<<" ";
				if(3-(a[i]+a[j]) == 0){
					int k = r[j-1]-r[i];
					if((i+j)%2==0&&a[(i+j)>>1]==0)k--;
					// cout<<k<<endl;
					ans+=k;
				}
				if(3-(a[i]+a[j]) == 1){
					int k = g[j-1]-g[i];
					if((i+j)%2==0&&a[(i+j)>>1]==1)k--;
					// cout<<k<<endl;
					ans+=k;
				}
				if(3-(a[i]+a[j]) == 2){
					int k = b[j-1]-b[i];
					if((i+j)%2==0&&a[(i+j)>>1]==2)k--;
					// cout<<k<<endl;
					ans+=k;
				}
			}
		}
	}
	cout<<ans<<endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	
	#ifdef local
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	clock_t qwertyuiop = clock();
	#endif
 
	int t=1;
	// cin>>t;
	rep(a,0,t)
	{
		// cout<<"Case #"<<a+1<<": ";
		solve();
	}

	// solve();
	
	#ifdef local
	{qwertyuiop = clock() - qwertyuiop;
	double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;
	cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "
	<<time_taken<<" seconds\n";}
	#endif
}

Measured memory_bytes: 3716
#include<stdio.h>

int main()
{
  int k;

  scanf("%d", &k);

  int i, gusuu = 0, kisuu = 0;
  for(i = 1; i <= k; ++i){
    if(i%2 == 0) ++gusuu;
    else ++kisuu;
  }

  printf("%d\n", gusuu * kisuu);

  return 0;
}


Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DRemainderReminder solver = new DRemainderReminder();
        solver.solve(1, in, out);
        out.close();
    }

    static class DRemainderReminder {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextInt();
            long k = in.nextInt();

            if (k == 0) {
                out.println(n * n);
                return;
            }

            long answer = 0;
            for (long b = 1; b <= n; b++) {
                if (k > b - 1)
                    continue;
                long intervals = n / b;
                answer += intervals * (b - k);
                answer += Math.max(0, (n % b) - k + 1);
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main() {
  int N,K;
  cin >> N >> K;
  int d = 0;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    if(x <= K-x){
      d += 2*x;
    }else{
      d += 2*(K-x);
    }
  }
  cout << d << endl;
}




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

int main() {
    string s;
    cin >> s;
    bool hasC = false;
    bool hasF = false;
    for (auto c: s) {
        if (c == 'C') {
            hasC = true;
        }
        if (c == 'F' && hasC) {
            hasF = true;
        }
    }
    cout << (hasC && hasF ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int A, B, K;
  cin >> A >> B >> K;
  
  if(A > K){
    A -= K;
  }
  else {
    K -= A;
    A = 0;
    B -= K;
  }
  
  if(B < 0){
    B = 0;
  }
    
  
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length
    val ans = IntArray(n)

    var teamHE = 0
    var teamHO = 0
    var teamTE = 0
    var teamTO = 0

    repeat(n) {
        val e = it % 2 == 0
        if (s[it] == 'R') {
            if (e) teamHE++
            else teamHO++
        } else{
            if (e) {
                ans[it] += teamHE
                ans[it-1] += teamHO
            } else {
                ans[it] += teamHO
                ans[it-1] += teamHE
            }
            teamHE = 0
            teamHO = 0
        }
        if (s[n - it - 1] == 'L') {
            if (e) teamTE++
            else teamTO++
        } else {
            if (e) {
                ans[n - it - 1] += teamTE
                ans[n - it] += teamTO
            } else {
                ans[n - it - 1] += teamTO
                ans[n - it] += teamTE
            }
            teamTE = 0
            teamTO = 0
        }
    }
    println(ans.joinToString(" "))

}


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

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

  int A, B, C, D;
  int ans = 0;
  cin >> A >> B >> C >> D;
  ans += min(A, B);
  ans += min(C, D);
  cout << ans << endl;
}


Measured memory_bytes: 256
// abca32b.cpp : Ordinary Number
#include <bits/stdc++.h>
using namespace std;
#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define in(x) cin>>(x)
#define oute(x) cout<<(x)<<endl

int main(){
  int n; in(n);
  int a,b,c,count=0;
  in(a);in(b);
  upto(i,2,n,1){
    in(c);
    if(min(a,c)<b && b<max(a,c)) count++;
    a=b;b=c;
  }
  oute(count);
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n  = Integer.parseInt(sc.next());
		int[] a = new int[n + 1];
		for (int i = 1; i <= n; i++)
			a[i] = Integer.parseInt(sc.next());
		int tem = a[1];
		int ans = 1;
		while (tem != 2) {
			tem = a[tem];
			ans++;
			if (ans > n) {
				ans = -1;
				break;
			}
		}
		System.out.println(ans);
	}
}

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

using namespace std;
#define INF 1000007
#define MOD 1000000007
#define maxn 101
#define maxh 1001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
const int dx[4] = {0, 1, -1, 0}, dy[4] = {1, 0, 0, -1};
typedef std::pair<int, int> P;

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

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

int a, b;

void f(int x) {
    while (x) {
        a++;
        b = x;
        x /= 10;
    }
}

signed main() {
    int AB, BC, CA;
    cin >> AB >> BC >> CA;
    cout << AB * BC / 2 << endl;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
using LL = long long;
using ULL = unsigned long long;
#define NUM 1000000007

int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    std::cout << "例外：数字ではない文字をintに変換しようとしました";
    throw;
}

using namespace std;

int main()
{
    string s;
    cin >> s;
    int a, b, c, d;
    a = ctoi(s[0]);
    b = ctoi(s[1]);
    c = ctoi(s[2]);
    d = ctoi(s[3]);
    if (a + b + c + d == 7)
    {
        cout << a << '+' << b << '+' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a + b + c - d == 7)
    {
        cout << a << '+' << b << '+' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }

    if (a + b - c + d == 7)
    {
        cout << a << '+' << b << '-' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a + b - c - d == 7)
    {
        cout << a << '+' << b << '-' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }

    if (a - b + c + d == 7)
    {
        cout << a << '-' << b << '+' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a - b + c - d == 7)
    {
        cout << a << '-' << b << '+' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }
    if (a - b - c + d == 7)
    {
        cout << a << '-' << b << '-' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a - b - c - d == 7)
    {
        cout << a << '-' << b << '-' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long INTEGER;
typedef double FLOAT;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int main()
{

  int N; cin >> N;
  rep (n, N) {

    int gx, gy; cin >> gx >> gy;

    int mat[gx+1][gy+1][gx+1][gy+1];
    rep (i, gx + 1) {
      rep (j, gy + 1) {
        rep (i2, gx + 1) {
          rep (j2, gy + 1) {
            mat[i][j][i2][j2] = 0;
          }}}}

    int k; cin >> k;
    rep (i, k) {
      int a, b, c, d; cin >> a >> b >> c >> d;
      if (a < c) mat[a][b][c][d] = 1;
      else if (a > c) mat[c][d][a][b] = 1;
      else if (b < d) mat[a][b][c][d] = 1;
      else mat[c][d][a][b] = 1;
    }

    long c[gx+1][gy+1];
    c[gx][gy] = 1;
    c[0][0] = 1;
    rep (i, gx + 1) {
      rep (j, gy + 1) {
        if (i == 0) {
          if (j == 0) continue;
          assert(j-1 >= 0);
          int b = mat[0][j-1][0][j];
          c[i][j] = b ? 0 : c[i][j-1];
        } else {
          if (j == 0) {
            assert(i-1 >= 0);
            int b = mat[i-1][0][i][0];
            c[i][j] = b ? 0 : c[i-1][j];
          } else {
            assert(i-1 >= 0);
            assert(j-1 >= 0);
            int b1 = mat[i-1][j][i][j];
            int b2 = mat[i][j-1][i][j];
            c[i][j] = (b1 ? 0 : c[i-1][j]) + (b2 ? 0 : c[i][j-1]);
          }
        }
      }
    }

    /*
    rep (i, gx + 1) {
      rep (j, gy + 1) {
        cerr << c[i][j] << ' ';
      } cerr << endl;
    }
    */

    long ans = c[gx][gy];
    if (ans == 0) cout << "Miserable Hokusai!" << endl;
    else cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1420
import itertools

N = int(input())
L = list(map(int, input().split()))

comb = list(itertools.combinations(L, 3))

ans = 0
for a, b, c in comb:
    if a + b > c and b + c > a and c + a > b and a != b and b != c and c != a:
        ans += 1
print(ans)


Measured memory_bytes: 20540
import java.util.*;
import java.io.*;

public class Main {
	
	int max;

	class Data {
		int leftX, rightX;
		int leftConst, rightConst;
		
		public Data(int leftX, int rightX, int leftConst, int rightConst) {
			this.leftX = leftX;
			this.rightX = rightX;
			this.leftConst = leftConst;
			this.rightConst = rightConst;
		}
		
		int get(int x) {
			if (x <= leftX) {
				return leftConst;
			} else if (x >= rightX) {
				return rightConst;
			} else {
				return leftConst + (x - leftX);
			}
		}
		
		Data up(int value) {
			if (leftConst + value >= max) {
				return new Data(0, 0, max, max);
			} else if (rightConst + value >= max) {
				int diff = rightConst + value - max;
				return new Data(leftX, rightX - diff, leftConst + value, max);
			} else {
				return new Data(leftX, rightX, leftConst + value, rightConst + value);
			}
		}
		
		Data down(int value) {
			if (rightConst - value <= 0) {
				return new Data(0, 0, 0, 0);
			} else if (leftConst - value <= 0) {
				int diff = value - leftConst;
				return new Data(leftX + diff, rightX, 0, rightConst - value);
			} else {
				return new Data(leftX, rightX, leftConst - value, rightConst - value);
			}
		}
	}
	
	void solve() {
		max = in.nextInt();
		int k = in.nextInt();
		int[] r = new int[k + 1];
		for (int i = 0; i < k; i++) {
			r[i] = in.nextInt();
		}
		r[k] = (int) 1e9;
		
		
		int q = in.nextInt();
		int[] t = new int[q], a = new int[q];
		for (int i = 0; i < q; i++) {
			t[i] = in.nextInt();
			a[i] = in.nextInt();
		}
		Data cur = new Data(0, max, 0, max);
		
		int ptr = 0;
		for (int i = 0; i < r.length; i++) {
			int prevTime = i == 0 ? 0 : r[i - 1];
			while (ptr < q && t[ptr] <= r[i]) {
				int diff = t[ptr] - prevTime;
				Data ans = null;
				if (i % 2 == 1) {
					ans = cur.up(diff);
				} else {
					ans = cur.down(diff);
				}
				out.println(ans.get(a[ptr++]));
			}
			int diff = r[i] - prevTime;
			prevTime = r[i];
			if (i % 2 == 1) {
				cur = cur.up(diff);
			} else {
				cur = cur.down(diff);
			}
		}
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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


Measured memory_bytes: 49252
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
    optimize();

    char c;
    cin >> c;
    c++;
    cout << c << endl;


    return 0;
}


















Measured memory_bytes: 256
// 6/18 振り返り
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;

    vector<int> L(K), R(K);

    int day = 0;
    int k = 0;
    while (k < K) {
        if (S[day] == 'o') {
            L[k++] = day;
            day += (C + 1);
            // k++;
        } else {
            day += 1;
        }
    }
    // rep(i, K) {
    //     cout << L[i] << endl;
    // }

    day = N - 1;
    k = K - 1;
    while (k >= 0) {
        if (S[day] == 'o') {
            R[k--] = day;
            day -= (C + 1);
        } else {
            day -= 1;
        }
    }

    rep(i, K) {
        if (R[i] == L[i]) {
            cout << R[i] + 1 << endl;
        }
    }
}

Measured memory_bytes: 5088
#include<iostream>

using namespace std;

int main() {
	int a, b, c, x, y,money=0;

	cin >> a >> b >> c >> x >> y;

	if (x > y) {
		if (a+b > c*2) {
			money += y * c * 2;
			x -= y;
		}
		else {
			money += y * b;
		}
		if (a > c*2) 
			money += x * c * 2;
		else
			money += x * a;
	}
	else {
		if (a+b > c*2) {
			money += x * c * 2;
			y -= x;
		}
		else {
			money += x * a;
		}
		if (b > c*2)
			money += y * c * 2;
		else
			money += y * b;
	}

	cout << money;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
template<class T> void chmin(T&x,T y){if(x>y)x=y;}
template<class T> void chmax(T&x,T y){if(x<y)x=y;}

string s;
struct ugraph{
    size_t n;
    vector<vector<int>> e;
    explicit ugraph(int n,int m=0,bool f=true):n(n),e(n){
        if(m) built(m,f);
    }
    void built(int m,bool f=true){
        int a,b;
        fr(i,m){
            cin>>a>>b;
            if(f) --a,--b;
            add(a,b);
        }
    }
    void add(int a,int b){
        e[a].emplace_back(b);
        if(a!=b) e[b].emplace_back(a);
    }
    bool solve(){
        vector<int> a(n),b(n);
        fr(i,n) for(auto&j:e[i]){
                if(s[i]=='A') ++a[j];
                else ++b[j];
        }
        queue<int> q;
        fr(i,n) if(!a[i]||!b[i]) q.push(i);
        auto ans{q.size()};
        while(!q.empty()){
            auto i=q.front();q.pop();
            for(auto&j:e[i]){
                if(!a[j]||!b[j]) continue;
                if(s[i]=='A') --a[j];
                else --b[j];
                if(!a[j]||!b[j]) q.emplace(j),++ans;
            }
        }
        return ans<n;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,m;
    in>>n>>m;
    in>>s;
    ugraph g(n,m);
    puts(g.solve()?"Yes":"No");
}

Measured memory_bytes: 12240
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

ll com[51][51];

int main(){
    com[0][0] = 1;
    for(int i = 1; i < 51; ++i){
        for(int j = 0; j <= i; ++j){
            com[i][j] += com[i-1][j];
            if(j > 0) com[i][j] += com[i-1][j-1];
        }
    }
    int n, a, b; cin >> n >> a >> b;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    sort(RALL(v));
    ll sum = 0;
    rep(i,a) sum += v[i];
    double ave = double(sum)/a;
    ll res = 0;
    int num = 0;
    rep(i,n) if(v[i] == v[a-1]) ++num;
    if(v[0] == v[a-1]){
        for(int i = a; i <= b; i++) res += com[num][i];
    }else{
        int cnt = 0;
        for(int i = 0; i < a; ++i) if(v[i] == v[a-1]) cnt++;
        res = com[num][cnt];
    }
    cout << fixed << setprecision(15) << ave << endl;
    cout << res << endl;
}

Measured memory_bytes: 256
import math;
a,b = map(int,input().split())
x = []
y = []
ans = -1
x.append(math.ceil(a*25/2))
x.append((a+1)*25//2-1)
y.append(b*10)
y.append((b+1)*10-1)
if min(x) < max(y) and min(y) < max(x) and min(y) <= min(x):
  ans = min(x)
elif min(x) < max(y) and min(y) < max(x) and min(x) < min(y):
  ans = min(y)
print(ans)

Measured memory_bytes: 3188