akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
main(){
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  int e=0;
  int f=0;
  int g=0;
  char taro[101];
  char hanako[101];
  scanf("%d",&a);
  for(b=0;b<a;b++){
    scanf("%s %s",&taro,&hanako);
    if(strcmp(taro,hanako)==0){
      c=c+1;
      d=d+1;
    }
    else if(strcmp(taro,hanako)>0){
      c=c+3;
    }
    else if(strcmp(taro,hanako)<0){
      d=d+3;
    }
  }
  printf("%d %d\n",c,d);
  return 0;
}

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

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        int N = in.i();
        int[] d = in.ii();
        int ans = 0;
        for(int i = 0; i < N; i++){
            for(int j = i+1; j < N; j++){
                ans += d[i]*d[j];
            }
        }
        out.println(ans);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
    ll ans = 0;
    int N;
    cin >> N;
    int ketaN = log10(N) + 1;
    rep2(i, 1, N + 1)
    {
        if (i > 10)
        {
            int ti = 0;
        }
        int a0 = i % 10;
        int ak = to_string(i).front() - '0';

        int keta = to_string(i).size();
        int tmp = 0;

        for (int nowketa = 1; nowketa <= ketaN; nowketa++)
        {
            if (a0 != 0)
            {
                if (nowketa == 1)
                {
                    if ((a0 == ak) and a0 <= N)
                    {
                        ans++;
                    }
                }
                else if (nowketa == 2)
                {
                    if (a0 * 10 + ak <= N)
                    {
                        ans++;
                    }
                }
                else
                {

                    tmp = a0 * pow(10, nowketa - 1) + ak;
                    if (N - tmp >= 0)
                    {
                        ans += min((N - tmp) / 10, (int)pow(10, nowketa - 2) - 1) + 1;
                    }
                }
            }
        }
    }

    cout << ans;
    return 0;
}

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

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if((a+b)%2 == 0){
    cout <<(a+b)/2<<endl;
    }else{
        cout<<(a+b)/2 + 1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e10;
const ll MOD = 1e9 + 7;

bool isprime(int n){
	if (n == 1){
		return false;
	}
	if (n == 2){
		return true;
	}
	int sq = (int)sqrt(double(n));
	for (int i = 2; i <= sq; i++){
		if (n%i == 0){
			return false;
		}
	}
	return true;
}

int main(){
	int N;
	cin >> N;
	vi A;
	int five = 5;
	int count = 0;
	while (count < N){
		if (isprime(five - 1)){
			A.push_back(five - 1);
			count++;
		}
		five += 5;
	}

	for (int i = 0; i < N; i++){
		cout << A[i] << " ";
	}

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 11;
struct ddd{
    int x, y, id, tp;
    bool operator < (const ddd &a) const{
        if(tp != a.tp)return tp < a.tp;
        else{
            if(tp == 1)return y < a.y;
            else if(tp == 2)return x < a.x;
            else if(tp == 3)return y > a.y;
            else if(tp == 4)return x > a.x;
        }
    }
};
vector<ddd> nd;
int n, r, c;
int zh[N], tp;
bool mark[N];
bool check(int x, int y){
    if(x > 0 && x < r && y > 0 && y < c)return 0;
    return 1;
}
void get(int x, int y, int id){
    ddd now;
    now = (ddd){x, y, id, 0};
    if(x == 0 && y < c)now.tp = 1;
    else if(x < r && y == c)now.tp = 2;
    else if(x == r && y > 0)now.tp = 3;
    else now.tp = 4;
    nd.push_back(now);
}
int main(){
    //freopen("arc076e.in", "r", stdin);
    cin>>r>>c>>n;
    int x1, x2, y1, y2;
    for(int i = 1;i <= n; i++){
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        if(check(x1, y1) && check(x2, y2)){
            get(x1, y1, i); get(x2, y2, i);
        }
    }
    sort(nd.begin(), nd.end());
    int s = nd.size();
    for(int i = 0;i < s; i++){
        if(tp == 0){
            zh[++tp] = nd[i].id;
            mark[nd[i].id] = 1;
        }
        else{
            if(mark[nd[i].id]){
                if(zh[tp] == nd[i].id)tp--;
                else {
                    puts("NO");
                    return 0;
                }
            }
            if(!mark[nd[i].id]){
                mark[nd[i].id] = 1;
                zh[++tp] = nd[i].id;
            }
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 6512
[N,M] = list(map(int,input().split()))
H = list(map(int,input().split()))

AB = []
for i in range(M):
    AB.append(list(map(int,input().split())))

flag=[]
for j in range(M):
    hikaku1 = H[AB[j][0]-1]
    hikaku2 = H[AB[j][1]-1]
    if hikaku1<hikaku2:
        #H[AB[j][0]-1] = hikaku2
        #H[AB[j][0]-1] = 0
        flag.append(AB[j][0]-1)
    elif hikaku1>hikaku2:
        #H[AB[j][1]-1] = hikaku1
        #H[AB[j][1]-1] = 0
        flag.append(AB[j][1]-1)
    else:
        #H[AB[j][0]-1] = 0
        #H[AB[j][1]-1] = 0
        flag.append(AB[j][0]-1)
        flag.append(AB[j][1]-1)

#print(flag)
for i in range(len(flag)):
    H[flag[i]]=0

#print(H)
print(len(H) - H.count(0))


Measured memory_bytes: 101384
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1]*(n+1)#それぞれの要素がどの要素の子であるか

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]#それぞれの要素の根を再帰的に求める

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

    def same(self, x, y):
        return self.find(x) == self.find(y)#x,yが同じ集合に属するかどうか
    
    def size(self, x):
        return -self.par[self.find(x)]
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if root == self.find(i)]

def main():
    n, q = map(int, input().split())
    union = UnionFind(n)
    
    for i in range(q):
        query = list(map(int, input().split()))
        if query[0] == 0:
            union.union(query[1], query[2])
        else:
            print(int(union.same(query[1], query[2])))
    
    
if __name__ == "__main__":
    main()
    
    

Measured memory_bytes: 11460
s=list(input())
n=len(s)
ans=0
for i in range(2**(n-1)):
    f=s[0]
    for j in range(n-1):  
        if i&(1<<j):
            f=f+"+"
            
            
        f=f+s[j+1]
        
    
    ans=ans+sum(map(int,f.split("+")))
  
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int x; cin >> x;
    cout << 10 - x/200 << endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int sum = 0;
        int vote = 0;
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scanner.nextInt();
            vote += a[i];
        }
        for(int i = 0; i < n; i++){
            if(a[i] >= (double)vote/(4*m)){sum++;}
        }
        if(sum >= m){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        return;
    }
}

Measured memory_bytes: 22740
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const long double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//







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

    cout << 3 * (r*r) << endl;
    return 0;
}





































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

using namespace std;

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

	if (S == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}




}


Measured memory_bytes: 3640
input()
int_list = list(map(int, input().split()))
max_num = 10**18
ans = 1
for i in int_list:
    ans *= i
    if ans > max_num:
        if min(int_list) == 0:
            print(0)
        else:
            print(-1)
        break
else:
    print(ans)


Measured memory_bytes: 21596
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
	int n,m;
	cin>>n>>m;
	char d[101][101];
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>d[i][j];
	int pf;
	for(int i=0;i<n;i++)
	{
		pf=0;
		for(int j=0;j<m;j++)
		{
			int f=0;
			int ff=0;
			for(int a=0;a<n;a++)
			{
				if(d[a][j]!='.')f=1;
			}
			if(f==0)ff=1;
			f=0;
			for(int a=0;a<m;a++)
			{
				if(d[i][a]!='.')
				{
					//cout<<d[i][a];
					f=1;
				}
			}
			if(f==0)pf=1;
			//cout<<endl;
			//cout<<ff<<endl;
			if(f==0)ff=1;
			if(!ff)cout<<d[i][j];
		}
		if(!pf)
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include <functional>
#include <queue>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

int main() {

	int n, m; cin >> n >> m;

	if (abs(n - m) > 1) {
		cout << "0" << endl;
	}
	else if (abs(n - m) == 1) {
		long long x = 1;
		while (n) {
			x = (x * n) % MOD;
			n--;
		}
		while (m) {
			x = (x * m) % MOD;
			m--;
		}
		cout << x << endl;
	}
	else {
		long long x = 1;
		while (n) {
			x = (x * n) % MOD;
			n--;
		}
		while (m) {
			x = (x * m) % MOD;
			m--;
		}
		cout << (2 * x)%MOD << endl;

	}









}

Measured memory_bytes: 256
import java.util.*;


/**
 * Created by santa on 2016/10/16.
 */

public class Main {

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

        int N = scanner.nextInt();
        int[] a = new int[N];

        for (int i = 0; i < N; i++) {

            a[i] = scanner.nextInt();

        }
        Arrays.sort(a);
        System.out.println(a[N-1] - a[0]);

    }// mainMethod




} // MainClass


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    string S,T;
    cin >> S >> T;
    int ct = 0;
    rep(i,3) if(S[i] == T[i]) ct++;
    pr(ct);
}


Measured memory_bytes: 256
class UnionFind():
    n=1
    par=[0]
    rnk=[0]
    siz=[0]
    def __init__(self,size):
        self.n=size
        self.par=[i for i in range(self.n)]
        self.rnk=[0 for i in range(self.n)]
        self.siz=[1 for i in range(self.n)]
    def find(self,vertex1):
        if self.par[vertex1]==vertex1:
            return vertex1
        else:
            self.par[vertex1]=self.find(self.par[vertex1])
            return self.par[vertex1]
    def unite(self,vertex1,vertex2):
        vertex1=self.find(vertex1)
        vertex2=self.find(vertex2)
        if vertex1==vertex2:
            return
        if (self.rnk[vertex1]<self.rnk[vertex2]):
            self.par[vertex1]=vertex2
            self.siz[vertex2]+=self.siz[vertex1]
        else:
            self.par[vertex2]=vertex1
            self.siz[vertex1]+=self.siz[vertex2]
            if(self.rnk[vertex1]==self.rnk[vertex2]):
                self.rnk[vertex1]+=1
    def same(self,vetrex1,vertex2):
        return self.find(vetrex1)==self.find(vertex2)
    def size(self,vertex1):
        return self.siz[self.find(vertex1)]

N,M,K=map(int,input().split())
friends=[0 for i in range(N)]
F=UnionFind(N)
for i in range(M):
    a,b=map(int,input().split())
    friends[a-1]+=1
    friends[b-1]+=1
    F.unite(a-1,b-1)
blocks=[0 for i in range(N)]
for i in range(K):
    c,d=map(int,input().split())
    if F.same(c-1,d-1):
        blocks[c-1]+=1
        blocks[d-1]+=1
#print([F.find(i) for i in range(N)])
#print([F.size(i) for i in range(N)])
ans=[0 for i in range(N)]
for i in range(N):
    ans[i]=F.size(i)-friends[i]-blocks[i]-1
print(*ans)

Measured memory_bytes: 16540
W,H,x,y,r=map(int,input().split())
if x>=0 and y>=0:
    if W>x+r:
        if H>y+r:
                print("Yes")
        elif H<y+r:
                print("No")
    elif W<x+r:
        print("No")
elif x<0 and y<0:
    if W<x+r:
        print("Yes")
    elif W>x+r:
        print("No")
if W==x+r:
    if H>=y+r:
        print("Yes")
    if H<y+r:
        print("No")
elif W>0 and H>0:
    if x>0 and y<0:
        print("No")
    elif x<0 and y>0:
        print("No")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define VI vector<int>
#define PII pair<int, int>
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30;
const ll LINF=1LL<<60 ;
const ll MOD=1e9+7 ;
///////////////////

int zero = int('0');

int main(){
    string s; cin >> s;
    int z=0,o=0;
    int ssize = s.size();
    /*
    for(int j=0;j++;j<ssize){
        cout <<  'i';
        if(int(s[j]) == zero) z += 1;
        else o += 1;
    }
    */
    int i = 0;
    while(true){
        if(i == s.size()) break;
        if(s[i] == '0') z+=1;
        if(s[i] == '1') o+=1;
        i++;
    }

    if(z > o) cout << 2*o << endl;
    else cout << 2*z << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define long long long 
using namespace std;
     
int main() {
    long n, a, b; cin >> n >> a >> b;
    if(n == 1) return !printf("%d\n", a == b);
    if(a > b) return !printf("0");
    long l = a * (n - 1) + b, r = a + (n - 1) * b;
    printf("%lld\n", r-l+1);
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
  ans += min(A[i],B[i])
  ans += min(A[i+1],B[i] - min(A[i],B[i]))
  A[i+1] -= min(A[i+1],B[i] - min(A[i],B[i]))
print(ans)

Measured memory_bytes: 18476
def a(arg):
    for i in range(len(arg)):
        if (i + 1 == int(arg[i])):
            a = i
        if (i + 1 < int(arg[i])):
            return -1

    return int(arg.pop(a))

_ = input()
arg = input().split()

l = []
while (len(arg) > 0):
    b =  a(arg)
    if (b == -1):
        print(-1)
        break
    l.append(b)

if (len(arg) == 0):
    l.reverse()
    for i in l:
        print(i)


Measured memory_bytes: 3064
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
tmpl = list(range(1,N+1))

lines = [[0]*(N+1) for _ in range(N+1)]

def solve(tmpl,cnt):
    global lines

    L = len(tmpl)
    if L == 1:
        return

    aa,bb = tmpl[:L//2],tmpl[L//2:]
    for a in aa:
        for b in bb:
            if a < b:
                lines[a][b] = str(cnt)
            else:
                lines[b][a] = str(cnt)

    solve(aa,cnt+1)
    solve(bb,cnt+1)

solve(tmpl,1)

for i in range(1,N):
    print(' '.join(lines[i][i+1:N+1]))


Measured memory_bytes: 57432
integer N,M
integer,allocatable,dimension(:)::k,p
integer,allocatable,dimension(:,:)::S
integer reader(10)
integer check,on,l,b
integer ans
read*,N,M
allocate(k(M),p(M),S(M,10))

S=0
do i=1,M
  reader=0
  read*,k(i),reader(1:k(i))
  do j=1,k(i)
    S(i,reader(j))=1
  end do
end do
read*,p

ans=0
do i=0,2**N-1
  check=0
  do j=1,M
    b=i
    on=0
    do l=1,N
      if(and(b,1)==1)on=mod(on+S(j,l),2)
      b=b/2
    end do
    if(on/=p(j))check=1
  end do
  if(check==0)ans=ans+1
end do
print"(i0)",ans
end

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

typedef long long ll;

ll n,x,light;

void FindLight(ll Long,ll Short)
{
	if(Long%Short==0)
	{
		light+=((Long<<1)-Short);
		return;
	}
	light+=(Long/Short*Short*2);
	FindLight(Short,Long%Short);
}

int main()
{
	cin>>n>>x;
	light=n;
	if(x>=n-x) FindLight(x,n-x);
		else FindLight(n-x,x);
	cout<<light<<"\n";
}

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

int main() {
  vector<int> x(5);
  rep(i , 5) cin >> x.at(i);
  rep(i , 5)
  {
    if (x.at(i) == 0)
    {
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

n, x, m = list(map(int, input().split()))

data = [-1]*(m+1)

ans = x

num = x
data[x] = (1, 0)
count = 2

flag = 0
while(count <= n):
    # print(count)
    num_new = (num**2) % m
    if data[num_new] == -1 or flag == 1:
        data[num_new] = (count, ans)
        ans += num_new
        num = num_new
    else:
        diff = ans-data[num_new][1]
        frec = count - data[num_new][0]

        kaisuu = (n-(count-1))//frec

        if kaisuu > 0:
            count = count-1 + frec*kaisuu
            ans += kaisuu*diff
        else:
            ans += num
            num = num_new
        flag = 1
    count += 1

# print(count, n)
# print(flag, ans)
print(ans)


Measured memory_bytes: 17216
require 'pp'

A,B,Q = readline.chomp.split.map(&:to_i)
S = A.times.each.map {|i| readline.to_i }
T = B.times.each.map {|i| readline.to_i }
X = Q.times.each.map {|i| readline.to_i }

S.sort!
T.sort!

X.each do |x|
  i1 = S.bsearch_index {|s| s >= x } || 0
  s_e = S[i1]
  s_w = S[i1-1]
  i2 = T.bsearch_index {|t| t >= x } || 0
  t_e = T[i2]
  t_w = T[i2-1]

  #pp [s_e,s_w,t_e,t_w]
  a = [
    (x-s_e).abs + (s_e-t_e).abs,
    (x-s_e).abs + (s_e-t_w).abs,
    (x-s_w).abs + (s_w-t_e).abs,
    (x-s_w).abs + (s_w-t_w).abs,
    (x-t_e).abs + (t_e-s_e).abs,
    (x-t_e).abs + (t_e-s_w).abs,
    (x-t_w).abs + (t_w-s_e).abs,
    (x-t_w).abs + (t_w-s_w).abs
  ]
  puts a.min
end



Measured memory_bytes: 9000
import java.util.*;

import javax.xml.crypto.Data;

import java.math.*;
import java.awt.geom.*;
import java.io.*;
     
     
public class Main {
	static int W;
	static int H;
	static int N;
	static boolean[][] fld;
	static int[] vx = new int[] {0,1,0,-1};
	static int[] vy = new int[] {1,0,-1,0};
	static int id;
	static int P;
	static int Q;
	static int R;
	static String S;
	static int[][] A = new int[][] {{0,1,2},{1,1,2},{2,2,2}};
	static int[][] B = new int[][] {{0,0,0},{0,1,1},{0,1,2}};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			String in = sc.next();
			if(in.equals(".")) break;
			S = in;
			id = 0;
			int count = 0;
			for(P = 0; P < 3; P++) {
				for(Q = 0; Q < 3; Q++) {
					for(R = 0; R < 3; R++) {
						id = 0;
						int ans = formula();
						if(ans == 2) count++;
					}
				}
			}
			System.out.println(count);
			
		}
	}
	static int formula() {
		if(id == S.length()) return 0;
		if(S.charAt(id) == '0') {
			id++;
			return 0;
		}
		if(S.charAt(id) == '1') {
			id++;
			return 1;
		}
		if(S.charAt(id) == '2') {
			id++;
			return 2;
		}
		if(S.charAt(id) == 'P') {
			id++;
			return P;
		}
		if(S.charAt(id) == 'Q') {
			id++;
			return Q;
		}
		if(S.charAt(id) == 'R') {
			id++;
			return R;
		}
		if(S.charAt(id) == '-') {
			id++;
			int ret = formula();
			if(ret == 0) {
				return 2;
			}
			if(ret == 1) {
				return 1;
			}
			if(ret == 2) {
				return 0;
			}
		}
		if(S.charAt(id) == '(') {
			id++;
			int A = formula();
			char K = S.charAt(id);
			id++;
			int B = formula();
			id++;
			if(K == '*') {
				return(Main.B[A][B]);
			}
			else if(K == '+') {
				return Main.A[A][B];
			}
		}
		
		
		return 0;
		
		
		
	}
}

Measured memory_bytes: 28656
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 1e9 + 7;
const int N = 1e5 + 10, M = 1e2 + 30;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

#define pi aaos(-1)
#define mk make_pair

double L;

double f(double x)
{
    double n = L - x;
    double a = -1, b = n;
    return (-b * b / 4 / a) * x;
}
double three(double l, double r)
{
    while (l + eps < r)
    {
        double mid = l + (r - l) / 3;
        double midmid = r - (r - l) / 3;
        if (f(mid) > f(midmid))
            r = midmid;
        else
            l = mid;
    }
    if (f(l) > f(r))
        return f(l);
    else
        return f(r);
}

int main()
{
    cin >> L;
    double ans = three(eps, L);
    printf("%.12f\n", ans);
    return 0;
}

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

#define int long long

int a[200005];

signed main() {
#ifdef _DEBUG
	freopen("in", "r", stdin);
#endif
	int k, n; cin >> k >> n;
	int s = 0, m = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (i > 1) {
			s += a[i] - a[i - 1];
			m = max(m, a[i] - a[i - 1]);
		}
	}
	s += abs(k - a[n] + a[1]);
	m = max(m, k - a[n] + a[1]);
	cout << s - m << '\n';
}


Measured memory_bytes: 1792
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, _A, _B, _C, _D = sc.nextInt()
    val A = _A - 1
    val B = _B - 1
    val C = _C - 1
    val D = _D - 1
    sc.nextLine()
    val S: Array[Char] = sc.nextLine().toCharArray

    // 1マス右か,2マス右にジャンプさせるしかなく
    // 1マス右は,岩が無い時しか選択できず.
    // 2マス右は,岩が1つしか無い時にしか選択できない.
    // 岩が2つある時には必ず右に行くことができない.

    // A < B かつ, 右に行く操作しか許されていないので,
    // 達成可能な時, 必ずBから先に動かすことになる.
    // そのあと, Aから探索する. つまり, AとBは独立して探索可能である.

    // A -> C. B -> Dへの移動を独立して探索する

    // しかし, D < C の可能性がある(先に到着したほうが岩と同様の扱いをされる)
    // なので, D < C の場合において, どこかで A が B を追い越す必要性があり,
    // 追い越せるかどうかは何も無いマスがA < x <= D + 1 のマスにおいて
    // ...のように3以上つ重なっている場合のみであり、追い越せる場合にはその後独立した問題に帰着する
    // 追い越せない場合には必ず満たす

    def solve(): Boolean = {
      def recursive(i: Int, target: Int): Boolean =
        if (i == target) true
        else if ((i + 1) < N && S(i + 1) == '.') // 枠内かつ何もなければ右に移動
          recursive(i+1,target)
        else if ((i + 2) < N && S(i + 2) == '.') // 枠内かつ何もなければ右に移動
          recursive(i+2,target)
        else false // 枠からはみ出る(ありえない) || 一マス右,二マス右に何も無い場合false

      def countContinuous(S: List[Char], count: Int): Boolean =
        if (count >= 3) true
        else if (S.nonEmpty) {
          if (S.head == '.') countContinuous(S.tail, count + 1)
          else countContinuous(S.tail, 0)
        } else false

      if (D < C) {
        if (countContinuous(S.slice(B - 1, D + 2).toList, 0))
          recursive(A, C) && recursive(B, D)
        else false
      } else recursive(A, C) && recursive(B, D)
    }

    if (solve()) println("Yes")
    else println("No")
  }

}


Measured memory_bytes: 31888
#include <iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  int m,h,i;
  while (s!= "-") {
    cin >> m;
    for (i=0;i<m;i++) {
      cin >> h;
      s= s.substr(h, s.length()-h) + s.substr(0,h);
    }
    cout << s << endl;
    cin >> s;
  }
  return 0;
}



Measured memory_bytes: 3124
#include<stdio.h>
#define MAX 100000

int main(){
	int n, i;
	int t[MAX];
  
	scanf("%d", &n);
	for ( i = 1; i <= n; i++ ) {
		scanf("%d", &t[i]);
	}
	
	for ( i = 1; i <= n; i++ ) {
		printf("node %d: key = %d, ", i, t[i]);
		if ( i / 2 >= 1 ){
			printf("parent key = %d, ", t[i/2]);
		} if ( i*2 <= n ) {
			printf("left key = %d, ", t[i*2]);
		} if ( i*2+1 <= n ) {
			printf("right key = %d, ", t[i*2+1]);
		}printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2052
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, A, B, C;
vector<int> l;

int main() {
    cin >> N >> A >> B >> C;
    l.resize(N);
    rep(i, N) cin >> l[i];

    int ans = INF;
    for (int ba = 1; ba < 1 << N; ++ba) {
        int la = 0; int cnta = 0;
        for (int i = 0; i < N; ++i) {
            if ((ba >> i) % 2) {
                cnta++; la += l[i];
            }
        }

        for (int bb = 1; bb < 1 << N; ++bb) {
            int bb_ = bb & (~ba);
            int lb = 0; int cntb = 0;
            for (int i = 0; i < N; ++i) {
                if ((bb_ >> i) % 2) {
                    cntb++; lb += l[i];
                }
            }
            if (cntb == 0) continue;

            for (int bc = 1; bc < 1 << N; ++bc) {
                int bc_ = bc & (~(ba | bb));
                int lc = 0; int cntc = 0;
                for (int i = 0; i < N; ++i) {
                    if ((bc_ >> i) % 2) {
                        cntc++; lc += l[i];
                    }
                }
                if (cntc == 0) continue;

                int p = max(0, la - A) + max(0, lb - B) + max(0, lc - C)
                    + max(0, A - la) + max(0, B - lb) + max(0, C - lc)
                    + (cnta - 1 + cntb - 1 + cntc - 1) * 10;
                chmin(ans, p);
            }
        }
    }
    write(ans);
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    string S; cin >> S;

    int count[2];
    count[0] = 0;
    count[1] = 0;
    int lastPair = -1;
    char cur = 'R';
    int N = sz(S);
    int ans[N]; F0R(i, N) ans[i] = 0;
    F0R(i, N) {
        if (S[i] == cur) {
            count[i%2]++;
        } else {
            if (S[i] == 'L') {
                lastPair = i-1;
                ans[lastPair] += count[lastPair%2];
                ans[lastPair+1] += count[(lastPair+1)%2];
            } else {
                ans[lastPair] += count[lastPair%2];
                ans[lastPair+1] += count[(lastPair+1)%2];
            }
            count[0] = 0;
            count[1] = 0;
            count[i%2]++;
            cur = S[i];
        }

    }

    ans[lastPair] += count[lastPair%2];
    ans[lastPair+1] += count[(lastPair+1)%2];

    F0R(i, N) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343
// license: https://github.com/bqi343/USACO/blob/master/LICENSE


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

int main(){
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    cout << (H-h)*(W-w) << endl;
    return 0;
}


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

int main() {
    string s,t;
    int count=0;

    cin>>s;
    t = s;
    reverse(t.begin(), t.end());

    rep(i,s.size()/2) {
        if (s.at(i) != t.at(i)) count++;
    }

    cout<<count<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define debug(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define debug(...) 
#define end_time()
#endif


#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
inline int gcd(int a, int b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); } 
inline int power(int x, int n, int m = LLONG_MAX)
{  int res=1; x = (x%m + m)%m;
	while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
}
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007

void solve(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	vi w,r;
	for(int i = 0; i<n; i++){
		if(s[i]=='W') w.pb(i);
		else r.pb(i);
	}
	int ans = 0;
	for(auto x : w){
		if(r.size()==0) break;
		int d = r[r.size()-1];
		if(d > x){
			r.pop_back();
			ans++;
		}
		else break;
	}
	cout<<ans<<"\n";
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;++i) {
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	end_time();
	return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=998244353;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int N,S; cin>>N>>S;
    vec A(N);
    rep(i,N) cin>>A[i];
    vector<mat> dp(3010,mat(3010,vec(2)));
    rep(i,S+1){
        rep(j,2){
            dp[0][i][j]=0;
        }
    }
    rep(i,N){
        rep(j,S+1){
            if(j-A[i]>0){
                dp[i+1][j][0]=(dp[i][j][0]+dp[i][j-A[i]][0])%mod;
                dp[i+1][j][1]=(dp[i][j][1]+((N-i)*dp[i][j-A[i]][0])%mod)%mod;
            }
            else if(j==A[i]){
                dp[i+1][j][0]=(dp[i][j][0]+i+1)%mod;
                dp[i+1][j][1]=(dp[i][j][1]+(N-i)*(i+1))%mod;
            }
            else{
                rep(k,2){
                    dp[i+1][j][k]=dp[i][j][k];
                }
            }
        }
    }
    cout<<dp[N][S][1]<<endl;
    return 0;
}

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

int main(){
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  
  if(x-r<0 || W<x+r || y-r<0 || H<y+r)
    cout << "No" << endl;
  else if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H)
    cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;

// ABC086C - Traveling
int main(){
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;

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

    bool sw = true;
    for(int i=0;i<N;++i){
        int dt = t[i+1]-t[i];
        int deltadist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        if(deltadist>dt){
            sw = false;
        }
        if(deltadist%2 != dt%2){
            sw = false;
        }

    }
    string ans = sw?"Yes":"No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    
    if (S=="abc" || S=="acb" || S=="bac" || S=="bca" ||S=="cab" ||S=="cba"){
        cout << "Yes" <<endl;
        
    }else {cout << "No" << endl;}
    
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	c := 0
	for i := 0; i < n; i++ {
		a := nextInt()
		for a % 2 == 0 {
			c++
			a /= 2
		}
	}

	fmt.Println(c)
}

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

int main() {
	string s;
	cin >> s;
	int now = 0;
	ll ans = 0;
	rep(i, s.size()) {
		if (s[i] == 'W') {
			if (now != i) ans += i - now;
			now++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <deque>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = (1LL << 59);
const int iINF = (1 << 31) - 1;
const double dINF = 1000000000000000000.0;
const int MAX_N = 1 << 17;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;

//#define _DEB 0

int h, w,d;
pii a[100000] = {};
ll dist[100000] = {};
int q;

int main(){
	cin >> h >> w >> d;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int t; cin >> t;
			a[t] = make_pair(i, j);
		}
	}
	for (int i = 1; i <= h * w; i++) {
		if (i <= d)dist[i] = 0;
		else {
			int x, y, bx, by;
			x = a[i].fst; y = a[i].snd; bx = a[i - d].fst; by = a[i - d].snd;
			dist[i] = dist[i - d] + abs(x - bx) + abs(y - by);
		}
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		cout<<dist[r] - dist[l]<<endl;
	}
	return 0;
}

Measured memory_bytes: 2560
import numpy as np


N = int(input())

poss, negs = [], []
npos, nneg = 0, 0
for a in input().split():
    ia = int(a)
    if ia < 0:
        negs.append(ia)
        nneg += 1
    else:
        poss.append(ia)
        npos += 1

# import random
# N = 100000
# npos, nneg = 40000, 60000
# poss = [random.randint(1, 1000) for _ in range(npos)]
# negs = [random.randint(-1000, -1) for _ in range(nneg)]
# 
# poss = []
# negs = [-1, -1, -1]
# npos, nneg = len(poss), len(negs)
# N = npos + nneg

if N == 2:
    a1, a2 = (poss + negs)
    if a1 < a2:
        print(a2 - a1)
        print(a2, a1)
    else:
        print(a1 - a2)
        print(a1, a2)
    exit(0)

if nneg == 0:
    print(sum(poss) - min(poss) * 2)
    argmin = np.array(poss).argmin()
    minpos = poss.pop(argmin)
    pos = poss.pop()
    print(minpos, pos)
    negs.append(minpos - pos)
    npos -= 2
    nneg += 1
elif npos == 0:
    print(-sum(negs) + max(negs) * 2)
    argmax = np.array(negs).argmax()
    maxneg = negs.pop(argmax)  # -1とか
    neg = negs.pop()  # -5とか
    print(maxneg, neg)
    poss.append(maxneg - neg)
    nneg -= 2
    npos += 1
else:
    print(sum(poss) - sum(negs))

if npos > nneg:
    for _ in range(npos - nneg):
        pos, neg = poss.pop(), negs.pop()
        print(neg, pos)
        negs.append(neg - pos)
elif npos < nneg:
    for _ in range(nneg - npos):
        pos, neg = poss.pop(), negs.pop()
        print(pos, neg)
        poss.append(pos - neg)

for i in range(min(nneg, npos) - 1):
    pos, neg = poss.pop(), negs.pop()
    print(neg, pos)
    negs.append(neg - pos)
    pos, neg = poss.pop(), negs.pop()
    print(pos, neg)
    poss.append(pos - neg)

pos, neg = poss.pop(), negs.pop()
print(pos, neg)


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

int main(void) {
    int d, n, m;
    while (cin >> d, d) {
        cin >> n >> m;
        vector<int> D(n);
        D[0] = 0;
        for (int i = 1; i < n; i++) cin >> D[i];
        sort(D.begin(), D.end());

        int k;
        int ans = 0;
        for (int i = 0; i < m; i++) {
            cin >> k;
            if (D[n-1] <= k) {
                ans += min(k-D[n-1], d-k);
            } else {
                int left = 0, right = n-1, mid;
                for (int j = 0; j < 64; j++) {
                    mid = (left+right)/2;
                    if (D[mid] < k) {
                        left = mid;
                    } else {
                        right = mid;
                    }
                }
                ans += min(k-D[left], D[right]-k);
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3316
// Beginner163.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main()
{
	//A
    /*double r;
	cin >> r;
	cout << 2 * M_PI * r;*/

	//B
	/*int n, m;
	cin >> n >> m;
	int res = n;
	int a;
	for (int i = 0; i < m; ++i)
	{
		cin >> a;
		res -= a;
	}
	cout << (res >= 0 ? res : -1);*/

	//C
	int n;
	cin >> n;
	vector<int>a(n);
	a[0] = 0;
	map<int, int> res;
	for (int i = 1; i < n; ++i)
	{
		cin >> a[i];
		a[i]--;
		res[a[i]]++;
	}

	for (int i = 0; i < n; ++i)
	{
		cout << res[i] << '\n';
	}
	
}



Measured memory_bytes: 13552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    int n;cin>>n;
    int count = 0;
    while(n>0){
        n-=2;
        count++;
    }
    cout << count <<endl;

}



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

int main() {
  int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K; cin >> K;

  cout << arr[K-1] << endl;

  return 0;
}


Measured memory_bytes: 256
s = [c for c in input()]
k = int(input())

import copy

if len(s) == 1:
    print(k//2)

elif len(s) == len(set(s)):
    print(0)
    
elif s[0] != s[-1]:
    c = 0
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            c = c + 1
            s[i] = 'Z'
    print(c*k)

else: # s[0]==s[-1]
    s2 = copy.copy(s)
    c = 0
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            c = c + 1
            s[i] = 'Z'
    if s[-1] == 'Z':
        print(c*k)
    else:
        c2 = 1
        s2[0] = 'Z'
        for i in range(1, len(s)):
            if s2[i-1] == s2[i]:
                s2[i] = 'Z'
                c2 = c2 + 1
        if s2[-1] == 'Z':
            if k % 2 == 0:
                print(int((c+c2)*(k/2)))
            else:
                print(int((c+c2)*((k-1)/2)+c))
        else:
            print(c + c2*(k-1))


Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

int main(void){
    string s,p;
    cin >> s >> p;
    
    s += s;
    
    for(int i = 0; i < s.size()-p.size(); i++){
        if(p == s.substr(i,p.size())){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    return 0;
}


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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;

#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

int main(){
    ll N, M, V, P;
    cin >> N >> M >> V >> P; 

    vector<ll> A;
    REP(i,0,N){
        ll a;
        cin >> a;
        A.push_back(a);
    } 
    sort(A.begin(), A.end());
    vector<ll> acm;
    ll cur = 0;
    REP(i,0,N){
        cur += A[i];
        acm.push_back(cur);
    }
    ll ok = 0;
    PER(i,N-P-1,0){
        ll point=A[i]+M;
        ll comp=acm[N-P]-acm[i];
        ll comppoint = (comp + max((V - (P + i)) * M, (ll)0));
        if(comppoint > point * (N-P-i) || point < A[N-P]){
            break;
        }
        ok++;
    }

    cout << ok + P << endl;
    return 0;
}


Measured memory_bytes: 2548
a = list(map(int, input().split()))
l = [0, 0]
for i in range(3):
    if a[i] == 5:
        l[0] += 1
    elif a[i] == 7:
        l[1] += 1
if l[0] == 2 and l[1] == 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 39888
import java.util.*;
import java.lang.*;

public class Main{
	static int mod = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[][] dp = new long[2001][2001];
		for (int i = 0; i < 2001; i++) {
			dp[i][0] = 1;
		}
		for (int i = 0; i < 2001; i++) {
			for (int j = i + 1; j < 2001; j++) {
				dp[i][j] = 0;
			}
		}
		for (int i = 1; i < 2001; i++) {
			for (int j = 1; j < 2001; j++) {
				dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod;
			}
		}
		for (int i = 1; i <= k; i++) {
			System.out.println((dp[n - k + 1][i] * dp[k - 1][i - 1]) % mod);
		}
	}
}

Measured memory_bytes: 82388
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(void)
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, k, x, y;
  cin >> n >> k >> x >> y;
  if (n < k)
    cout << n * x << endl;
  else 
    cout << k * x + (n-k) * y << '\n';
  return 0;
}

Measured memory_bytes: 256