akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define rep(i,a) for(i = 0 ; i < a ; i++)
#define repr(i,a) for(i = a ; i >= 0 ; i--)
#define REP(i,a,b) for(i = a ; i <= b ; i++)
#define REPR(i,a,b) for(i = a ; i >= b ; i--)

#define scan(N) scanf("%lld",&N)
#define print(N) printf("%lld",N)
#define scan2(N1,N2) scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2) printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define mem(a,b)memset(a,b,sizeof(a))
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

#define endl '\n'

const long long INF = 2000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

template<class T> bool is_prime(T n)
{
	if((n%2 == 0 and n > 2) or n < 2 )
		return false;
	for(T i = 3; i*i <= n ; i += 2)
	{
		if( n % i == 0)
			return false;
	}
	return true;
}
lli power(lli a,lli b)
{
    lli value;
    if(!b)
    	return 1;
    else if(b%2==0) {
        value = power(a,b/2)%MOD;
        return (value * value)%MOD;
    }
    else {
        value = power(a,b/2)%MOD;
        return ((a*value)%MOD*(value))%MOD;
    }
}

int main()
{
	opt;
	lli n;
    lli cnt[5];
    lli i,j,k;
    rep(i,5) cnt[i] = 0;
    cin >> n;
    string s;
    rep(i,n)
    {
        cin >> s;
        if(s[0] == 'M') cnt[0]++;
        else if(s[0] == 'A') cnt[1]++;
        else if(s[0] == 'R') cnt[2]++;
        else if(s[0] == 'C') cnt[3]++;
        else if(s[0] == 'H') cnt[4]++;
    }
    lli ans = 0;
    rep(i,5)
    {
        REP(j,i+1,4)
        {
            REP(k,j+1,4)
                ans += cnt[i]*cnt[j]*cnt[k];
        }
    }
    cout << ans << endl;
	return 0;
}










Measured memory_bytes: 256
# vim: fileencoding=utf-8


def main():
    n = int(input())
    li = list(map(int, input().split()))
    li.sort(reverse=True)
    a = sum(li[::2])
    b = sum(li[1::2])
    ans = a - b
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61944
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 +7
inner = 0

for i in range(n):
    for j in range(i+1,n):
        if a[i] > a[j]:
            inner += 1
            inner %= mod
inner *= k
inner %=mod

outer = 0

for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            outer +=1
            outer %= mod
outer *= (k*(k-1)//2)
outer %= mod

print((inner + outer) % mod )



Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))
minus_count = 0
minimum = float("inf")
S = 0
for a in A:
    if a < 0:
        minus_count += 1
        a *= -1
    minimum = min(a, minimum)
    S += a
if minus_count % 2 == 1:
    S -= 2*minimum

print(S)


Measured memory_bytes: 59740
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

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

    bool flag=true;
    REP(i, 0, s.size()){
        if(i%2!=0){
            if(s[i]=='R'){
                flag=false;
                break;
            }
        }
        else{
            if(s[i]=='L'){
                flag=false;
                break;
            }
        }
    }

    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int main(){
    char S[15];
    char T[15];
    cin >> S >> T;
    int l = strlen(S);
    bool ans = true;
    for(int i = 0; i < l; i++){
        if (S[i] != T[i]) ans = false;
    }
    if (strlen(T) != l+1) ans = false;
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
using namespace std;
int main(){
    int n,i,cnt=0,a;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&a);
        if(i%2!=0&&a%2!=0) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 1720
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

int main(){
    string S;
    cin>>S;
    if(S=="Sunny")cout<<"Cloudy"<<endl;
    if(S=="Cloudy")cout<<"Rainy"<<endl;
    if(S=="Rainy")cout<<"Sunny"<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(raw_input())
#array=[[0]*n]*n
arr=[[0 for i in range(n)] for j in range(n)]


for i in range(n):
	a=list(map(int,raw_input().split()))
	if a[1]>0:
		for j in range(2,len(a)):
			arr[i][a[j]-1]=1
for i in range(n):
	for j in range(n):
		print arr[i][j],
	print

Measured memory_bytes: 4288
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> sosu(60000, 1);

void eratos() {
  for(int i = 2; i < 30000; i++) {
    sosu[2*i] = 0;
  }
  for(int i = 3; i < sqrt(60000); i+=2) {
    if(sosu[i] == 1) {
      for(int j = 1; i*(j+2) < 60000; j++) {
	sosu[i*(j+2)] = 0;
      }
    }
  }
}

int main() {
  eratos();
  int n, i;

  while(cin >> n) {
    
    for(i = n-1; i >= 0; i--){
      if(sosu[i] == 1) {
	cout << i << ' ';
	break;
      }
    }
   
    for(i = n+1; i < 60000; i++){
      if(sosu[i] == 1) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}


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

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

int main(void){
  int N; cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  int ans = A[0];
  for(int i = 0; i < N; i++){
    ans = gcd(ans, A[i]);
  }
  cout << ans << endl;
}


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

using namespace std;

char str[100005];

int main()
{
	int i,res=0;
	cin >> str;

	for (i = 1; str[i] != '\0'; i++) {
		if (str[i - 1] != str[i]) {
			res++;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t N,K,j=0; cin>>N>>K;
  vector<pair<int64_t,int64_t>> S(N);
  rep(i,N){
    int64_t a,b; cin>>a>>b;
    S.at(i)=make_pair(a,b);
  }
  sort(S.begin(),S.end());
  while(true){
    K-=S.at(j).second;
    if(K<=0){
      cout<<S.at(j).first;
      break;
    }
    j++;
  }
}

Measured memory_bytes: 4844
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int n = Integer.parseInt(sc.next());
            long ans = 0;

            for(int i = 1; i <= n; i++){
                if(i % 3 != 0 && i % 5 != 0){
                    ans += i;
                }
            }

            System.out.println(ans);
            

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 35744
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
int one,two;
int a,b,c,d;
void Min(int &x,int y)
{
    x=min(x,y);
}
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&d);
    one=INF; two=INF;
    Min(one,a*4); Min(one,b*2); Min(one,c);
    Min(two,a*8); Min(two,b*4); Min(two,c*2); Min(two,d);
    ll n;
    //scanf("%I64d",&n);
    scanf("%lld",&n);
    ll ans=1LL*(n/2)*two+1LL*(n%2)*one;
    //cout<<ans<<"\n";
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <regex>


int main(void) {
    
    using namespace std;
    
    int a, b, c = 0;
    int  num = 0;
    cin >> a >> b;
    
    while(1){
        num++;
        
        c = (a - 1) * (num - 1) + a;
        
        if(c >= b) break;
        
    }
    
    if(b==1) num = 0;
    cout << num << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main(){
  int i,j,temp,tamp,c=1;
  while(1){
    int ans[3000],ansp=0;
    scanf("%d %d",&temp,&tamp);
    if(temp==0 && tamp==0){
      break;
    }
    if(c==1){
      c=0;
    }
    else{
      puts("");
    }

    for(i=temp;i<=tamp;i++){
      if(i%400==0 || (i%100!=0 && i%4==0)){
	ans[ansp]=i;
	ansp++;
      }
    }
    if(ansp==0){
      puts("NA");
    }
    else{
      for(i=0;i<ansp;i++){
	printf("%d\n",ans[i]);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
      Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      int legs=sc.nextInt();
      if(legs<=(n*4)&&legs>=(n*2)&&(legs%2)==0)
        System.out.println("Yes");
      else
        System.out.println("No");
    }
}


Measured memory_bytes: 35708
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    long long N, T, t[200001], i, sum=0;

    cin >> N >> T;

    for(i=1; i<=N; i++){
        cin >> t[i];

        sum += T;
    }

    for(i=2; i<=N; i++){
        if(t[i]-t[i-1] < T){
            sum -= T-(t[i]-t[i-1]);
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int temp;

        if(a > b){
          temp = a;
          a = b;
          b = temp;
        }
        if(b > c){
          temp = b;
          b = c;
          c = temp;
        }
        if(a > b){
          temp = a;
          a = b;
          b = temp;
        }

                
        System.out.println(a + " " + b + " " + c);
    }
}

Measured memory_bytes: 26300
import java.util.Scanner;
import java.util.Stack;

//Setting Go Stones
public class Main{

	class R{
		int id;
		boolean white;
		public R(int id, boolean white) {
			this.id = id;
			this.white = white;
		}
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			Stack<R> s = new Stack<R>();
			for(int i=1;i<=n;i++){
				boolean w = sc.nextInt()==0;
				if(s.isEmpty()){
					s.add(new R(i,w));
					continue;
				}
				if(i%2==1&&s.peek().white!=w)s.add(new R(i,w));
				else if(i%2==0&&s.peek().white!=w){
					R r = s.pop();
					s.push(new R(r.id,w));
					while(s.size()>=2){
						R a = s.pop();
						if(a.white!=s.peek().white){
							s.push(a);
							break;
						}
					}
				}
			}
			int c = 0;
			int p = n+1;
			while(!s.isEmpty()){
				R r = s.pop();
//				System.out.println("INDEX:" + r.id + " WHITE:" + r.white);
				if(r.white)c+=p-r.id;
				p = r.id;
			}
			System.out.println(c);
		}
	}

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

Measured memory_bytes: 0
module Main where

import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust, mapMaybe)
import Control.Monad (replicateM, forM_, foldM)
import qualified Data.Vector.Mutable as MV
import Data.List (sortOn, sort)
import Debug.Trace

readTuple2 :: IO (Int, Int)
readTuple2 = do
    [x, y] <- readInts
    pure (x, y)

readInts :: IO [Int]
readInts = do
    is <- BC.words <$> BC.getLine
    pure $ fst <$> mapMaybe BC.readInt is

main = do
    (n, k) <- readTuple2
    vs <- readInts
    let maxOpTimes = min n k
    let reversedVs = reverse vs
    let ab = [(a, b)|a <- [0..maxOpTimes], b <- [0..(maxOpTimes - a)]]
    let points = fmap (\(a, b) -> let
            av = (take a vs)
            bv = (take b reversedVs)
            v = sort $ av ++ bv
            minusNum = length $ filter (<0) v
            droppableTimes = k - a - b
            dropTimes = min minusNum droppableTimes
            in
                sum $ drop dropTimes v
         ) ab
    print $ maximum points

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#include <string>
#include <ctime>
#include <stack>
#include <set>
#include <stdio.h>
#include <locale>
#define y1 y3278
#define y2 y4368
#define y y4368232
#define x x43682322
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(),a.end()
#define tm tm3278
#define left left3278
#define right right3278
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
template <class T> using Pair_indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const long long INF = 2000000000000000000;
const long long Maxll = 9223372036854775807;
const long long MOD = 1000000000000037;
const long long q0 = 31;
const int differ = 'a' - 'A';
template <class T>
istream& operator >> (istream &in, vector <T> &a)
{
    for (T &i: a) in >> i;
    return in;
}
template <class T>
ostream& operator << (ostream &out, vector <T> &a)
{
    for (T &i: a) out << i << ' ';
    out << '\n';
    return out;
}
template <class T>
ostream& operator << (ostream &out, set <T> &a)
{
    //out << a.size() << '\n';
    for (T i: a) out << i << ' ';
    return out;
}
/// Actual code starts here
string str;

ll n;

void PYPY()
{
    cin >> n;
    ll ans = 0;
    for (int i = 1;i <=n;i++)
        if (i % 3 != 0 && i % 5 != 0)
            ans+=i;
    cout << ans;

}

int main()
{
     ios::sync_with_stdio(0);
     cin.tie(0);
     cout.tie(0);
    ll t = 1;
    // cin >> t;
     while (t--)
         PYPY();
}


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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C;
  cin >> K;
  bool b = false;
  for(int i = 0; i < K; i++) {
    int p = A;
    int q = B;
    int r = C;
    q *= pow(2,i);
    r *= pow(2,K-i);
    if(p < q && q < r) {
      b = true;
      break;
    }
  }
  if(b) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

typedef unsigned long long ull;


ull gcd(ull x, ull y){
  return y == 0 ? x : gcd(y,x % y);
}

ull lcm(ull x, ull y){
  return x/gcd(x,y)*y;
}

int main(){
  ull a,b;
  while(cin >> a >> b){
    cout << gcd(a,b) << " " << lcm(a,b) << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
 
using namespace std;

int main(){
  int n;
  cin>>n;
  int t[110000],x[110000],y[110000];
  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 able=true;
  for(int i=0;i<n;++i){
    int delta_time=t[i+1]-t[i];
    int distance=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(delta_time<distance)able=false;
    if(delta_time%2!=distance%2)able=false;
  }
  if (able) cout << "Yes" << endl;
    else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 1408
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

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

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

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

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

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

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

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

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

fn main() {
    input!{
        a: u64,
        b: u64,
        x: u64,
    }
    let ans_all = b / x;
    let ans_less = if a == 0 { 0 } else { (a - 1) / x + 1 };

    println!("{}", ans_all - ans_less + 1);
}


Measured memory_bytes: 4352
from collections import deque


def solver(K):
    q = deque([i for i in range(1, 10)])

    if K <= 9:
        ans = q[K - 1]

    else:
        cnt = 9
        for i in range(1, K):
            c = q.popleft()

            if c % 10 != 0:
                q.append(c * 10 + (c % 10) - 1)
                cnt += 1
                if cnt >= K:
                    break

            q.append(c * 10 + (c % 10))
            cnt += 1
            if cnt >= K:
                break

            if c % 10 != 9:
                q.append(c * 10 + (c % 10) + 1)
                cnt += 1
                if cnt >= K:
                    break

        ans = q[-1]
    return ans


def run():
    K = int(input())
    ans = solver(K)

    print(ans)


run()


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

int main(){
    char s[4];
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]==s[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
a = int(sys.stdin.readline().strip())
vals = [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]
print (vals[a-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
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;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, T;
  cin >> N >> T;
  vector<pair<ll, ll>> AB(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> AB.at(i).first >> AB.at(i).second;
    AB.at(i).second *= -1;
  }
  sort(AB.begin(), AB.end());
  cerr << endl;
  for (ll i = 0; i < N; i++)
  {
    AB.at(i).second *= -1;
    cerr << AB.at(i).first << " " << AB.at(i).second << endl;
  }

  vector<vector<ll>> dp(3333, vector<ll>(6333, 0));
  for (ll i = 0; i < N; i++)
  {
    for (ll j = 0; j < 6300; j++)
    {
      chmax(dp.at(i + 1).at(j), dp.at(i).at(j));

      if (j < T)
        chmax(dp.at(i + 1).at(j + AB.at(i).first), dp.at(i).at(j) + AB.at(i).second);
    }
  }

  ll ans = 0;
  for (ll i = 0; i < 6300; i++)
  {
    chmax(ans, dp.at(N).at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 165376
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int  T,X;
    cin >> T >> X;
    cout << ((X % T == 0)? (T+X) : (X-T));
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 100005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(a>b)swap(a,b);if(!a)return b;return gcd(b%a,a);}
int n,m;
vector<int>ed[N];
int vis[N][3];
struct st{
	int v,d,i;
	st(){}
	st(int a,int b,int c){v=a;d=b;i=c;}
};
vector<st>q;
void solve(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		ed[u].pb(v);
	}
	int s,t;
	cin>>s>>t;
	q.pb(st(s,0,0));
	int e=0;
	while(e<q.size()){
		int u=q[e].v;
		int d=q[e].d;
		int i=q[e].i;
		int x=(i+1)%3;
		if(u==t&&!i)break;
		//vis[u][i]=1;
		for(int j:ed[u]){
			if(vis[j][x])continue;
			q.pb(st(j,d+1,x));
			vis[j][x]=1;
		}
		e++;
	}
	if(!vis[t][0])cout<<-1;
	else cout<<q[e].d/3;
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 14832
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
long long i[300000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=1,f=0;
  cin >>a>>b>>c;
  for(int n=0;n<10;n++){
    cout <<c*a-b<<'\n';
    c=c*a-b;
  }
  return (0);
}



Measured memory_bytes: 256
import math

n = int(input())
a = list(map(int,input().split(' ')))

a.sort()

ai = a[n-1]
mid = ai/2
diff = ai
aj = 0

for i in range(n-1):
    if abs(a[i] - mid) < diff:
        aj = a[i]
        diff = abs(a[i]-mid)

print(ai,aj)


Measured memory_bytes: 14180
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using System.Text;
     
    public class Program
    {
        public void Proc() {
            // A>B のときGREATER、A<B のときLESS、A=B のときEQUALと出力せよ。
            Reader.IsDebug = false;
            string numA = Reader.ReadLine();
            string numB = Reader.ReadLine();
            int maxLength = Math.Max(numA.Length, numB.Length);

            numA = numA.PadLeft(maxLength, '0');
            numB = numB.PadLeft(maxLength, '0');

            string ans = "EQUAL";
            for(int i=0; i<maxLength; i++) {
                if(numA[i]>numB[i]) {
                    ans = "GREATER";
                    break;
                } else if(numA[i]<numB[i]) {
                    ans = "LESS";
                    break;
                }
            }
            Console.WriteLine(ans);


        }

        public class Reader {
            public static bool IsDebug = true;
            private static System.IO.StringReader SReader;
            private static string InitText = @"




9720246
22516266





";
            public static string ReadLine() {
                if(IsDebug) {
                    if(SReader == null) {
                        SReader = new System.IO.StringReader(InitText.Trim());
                    }
                    return SReader.ReadLine();
                } else {
                    return Console.ReadLine();
                }
            }
        }
        public static void Main(string[] args)
        {
            Program prg = new Program();
            prg.Proc();
        }
    }

Measured memory_bytes: 13140
h,w = gets.chomp.split.map(&:to_i)
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

t = []
a.each_with_index do |v, i|
    v.times {t << i+1}
end

h.times do |i|
    if i % 2 == 0
        puts t[i*w, w].join(" ")
    else
        puts t[i*w, w].reverse.join(" ")
    end
end


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


int main()
{
	int n;
	scanf("%d", &n);
	int z = 0;
	for (int i = 0; i < n; i++)
	{
		int tmp;
		scanf("%d",&tmp);
		z += tmp & 1;
	}
	if (z % 2 == 0) printf("YES\n");
	else printf("NO\n");
}

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


// 数列dp：i番目の項は足場iへ行くために必要最低限のコスト

// L_n = min(L_n-2 + |h_n-2 - h_n|, L_n-1 + |h_n-1 - h_n|)
// L_2 = |h_2|
// L_1 = 0
// (L_0 = 0)

int main(){

	int n;
	cin >> n;
	
	int dp[100001];
	dp[0] = 0;
	dp[1] = 0;

	int h[100001];
	for(int i = 1; i <= n; i++){
		cin >> h[i];
	}
	h[0] = h[1];

	for(int i = 2; i <= n; i++){
		dp[i] = min(
			dp[i-2] + abs(h[i] - h[i-2]),
			dp[i-1] + abs(h[i] - h[i-1]));
	}

	cout << dp[n];

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int main(){
	int n;
	cin>>n;
	string a;
	cin>>a;
	if(n==0){
		cout<<a;
	return 0;
	}
	for(int i=0; i<a.size(); i++){
		if(char(a[i]+n)<=90 && char(a[i]+n)>=65){
			cout<<char(a[i]+n);
		}
		else{
			cout<<char(65+abs(90-(a[i]+n))-1);
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >>a>>b;
  int kotae=0;
  if(a>b){
    kotae+=a;
    a--;
  }else{
    kotae+=b;
    b--;
  }
  kotae+=max(a,b);
  cout<<kotae<<endl;
  return 0;
}

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

using namespace std;
using ll = long long;

ll N, X;
vector<ll> zeros, ones;

ll dfs(ll p, int L) {
  if (L == 0) return ones[0];

  ll sum = zeros[L] + ones[L];
  if (p == 1) return 0;
  if (p == sum / 2 + 1) return ones[L] / 2 + 1;
  if (p == sum) return ones[L];

  if (p < sum / 2 + 1) {
    return dfs(p - 1, L - 1);
  } else {
    return ones[L] / 2 + 1 + dfs(p - sum / 2 - 1, L - 1);
  }
}

int main() {
  cin >> N >> X;
  zeros.resize(N + 1);
  ones.resize(N + 1);
  zeros[0] = 0;
  ones[0] = 1;
  for (int i = 1; i < N + 1; i++) {
    zeros[i] = zeros[i - 1] * 2 + 2;
    ones[i] = ones[i - 1] * 2 + 1;
  }
  cout << dfs(X, N) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<assert.h>

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;
const int mod=1e9+7;

int qpow(int x,int y) {
	int ans=1;
	while (y) {
		if (y&1) ans=1LL*ans*x%mod;
		x=1LL*x*x%mod;y>>=1;
	}
	return ans;
}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

namespace io {
	const int L=(1<<21)+1;
	char ibuf[L],*iS,*iT,obuf[L],*oS=obuf,*oT=obuf+L-1,c,st[55];int f,tp;
#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,L,stdin),(iS==iT?EOF:*iS++)):*iS++)
	inline void flush() {
		fwrite(obuf,1,oS-obuf,stdout);
		oS=obuf;
	}
	inline void putc(char x) { *oS++=x; if (oS==oT) flush(); }
	template<class I> inline void gi(I&x) {
		for (f=1,c=gc();c<'0'||c>'9';c=gc()) if (c=='-') f=-1;
		for (x=0;c<='9'&&c>='0';c=gc()) x=x*10+(c&15); x*=f;
	}
	template<class I> inline void print(I x) {
		if (!x) putc('0');
		if (x<0) putc('-'),x=-x;
		while (x) st[++tp]=x%10+'0',x/=10;
		while (tp) putc(st[tp--]);
	}
	inline void gs(char*s, int&l) {
		for (c=gc();c<'a'||c>'z';c=gc());
		for (l=0;c<='z'&&c>='a';c=gc()) s[l++]=c;
		s[l]=0;
	}
	inline void ps(const char*s) { for (int i=0,n=strlen(s);i<n;i++) putc(s[i]); }
	struct IOFLUSHER{ ~IOFLUSHER() { flush(); } } _ioflusher_;
};
using io::putc;
using io::gi;
using io::gs;
using io::ps;
using io::print;


int main()
{
	int n,sum=0;gi(n);
	while (n) sum+=n%10,n/=10;
	if (sum==1) sum=10;
	print(sum);
	return 0;
}


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

int par[MAX];
 
void init(int);
int depth(int);
int input(void);

char *p;
char in[MAX*100];
int tree[MAX][20],idx[MAX];

int main(){
  int n,i,j;

  fread(in,sizeof(in),1,stdin);  
  p = in;

  n = input(); init(n);
  for(i = 0 ; i < n ; i++){
    int id,k,c;
 
    id = input();
    k = input();
    for(j = 0 ; j < k ; j++){
      c = input();
      par[c] = id;
      tree[id][idx[id]++] = c;
    }
  }
 
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, depth = %d, "
           ,i,par[i],depth(i));
    
    if(par[i] == -1){
      printf("root, [");
    }else if(!idx[i]){
      printf("leaf, [");
    }else{
      printf("internal node, [");
    }

    for(j = 0 ; j < idx[i] ; j++){
      printf("%d",tree[i][j]);
      if(j < idx[i]-1) printf(", ");
    }
    puts("]");
  }
 
  return 0;
}

void init(int n){
  int i;
  for(i = 0 ; i < n ; i++){
    par[i] = -1;
  }
}

int depth(int x){
  if(par[x] == -1){
    return 0;
  }
  return depth(par[x]) + 1;
}

int input(){
  int val = 0;
  while(!isdigit(*p)) ++p;
  val = *p++&15;
  while(isdigit(*p)){
    val = (val<<3)+(val<<1)+(*p++&15);
  }
  return val;
}

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

using namespace std;
typedef long long ll;

constexpr ll MOD = 1e9 + 7;

ll calc_pow(ll x, ll pow) {
    if (pow == 0) return 1;
    ll a = calc_pow(x, pow / 2);
    a = a * a % MOD;
    if (pow % 2 == 1) a *= x;
    return a % MOD;
}

ll calc_div(ll a, ll b) {
    return a * calc_pow(b, MOD - 2) % MOD;
}

bool cmp(const int a, const int b) { return abs(a) > abs(b); }

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x != 0)a.push_back(x);
    }
    if (a.size() < k) {
        cout << 0 << endl;
        return 0;
    }

    sort(a.begin(), a.end(), cmp);
    ll lastPlus = -1, lastMinus = 1;
    ll result = 1;
    for (int i = 0; i < k; i++) {
        result *= a[i], result %= MOD;
        if (a[i] > 0)lastPlus = a[i];
        else lastMinus = a[i];
    }

    if (result > 0) {
        cout << result << endl;
        return 0;
    }

    ll nextPlus = -1, nextMinus = 1;
    for (int i = k; i < a.size(); i++) {
        if (nextPlus < 0 && a[i] > 0)nextPlus = a[i];
        if (nextMinus > 0 && a[i] < 0) nextMinus = a[i];
    }

    bool PtoM = lastPlus > 0 && nextMinus < 0;
    bool MtoP = lastMinus < 0 && nextPlus > 0;
    if (PtoM && MtoP) {
        if (lastMinus * nextMinus > lastPlus * nextPlus) {
            cout << calc_div(-result, lastPlus) * -nextMinus % MOD << endl;
        } else {
            cout << calc_div(-result, -lastMinus) * nextPlus % MOD << endl;
        }
    } else if (PtoM) {
        cout << calc_div(-result, lastPlus) * -nextMinus % MOD << endl;
    } else if (MtoP) {
        cout << calc_div(-result, -lastMinus) * nextPlus % MOD << endl;
    } else if (a.size() != n) {
        cout << 0 << endl;
    } else {
        reverse(a.begin(), a.end());
        result = 1;
        for (int i = 0; i < k; i++) {
            result *= a[i], result %= MOD;
        }
        cout << result + MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 4320
#include <stdio.h>
int main(){
int n;
scanf("%d",&n);
if(n%4==0){
printf("Yes\n");
return 0;
}
while(n>0){
if(n%7==0){
printf("Yes\n");
return 0;
}
n-=4;
}
printf("No\n");
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String str_scan = scan.nextLine();
    // スペース区切りで分ける
    var str = str_scan.split(" ");
    // long型へ変換
    long a = Long.parseLong(str[0]);
    long b = Long.parseLong(str[1]);
    long c = Long.parseLong(str[2]);
    long d = Long.parseLong(str[3]);

    long aminus = 0;
    long bminus = 0;
    long cminus = 0;
    long dminus = 0;

    long ans = 0;

    if ( a < 0 ){
      aminus = 1;
    }
    if ( b < 0 ){
      bminus = 1;
    }
    if ( c < 0 ){
      cminus = 1;
    }
    if ( d < 0 ){
      dminus = 1;
    }

    if (aminus == 0){
      if (dminus == 1){
        ans = a * d;
      }else{
        ans = b * d;
      }
    }else if (bminus == 1){
      if (cminus == 1){
        ans = a * c;
      }else{
        ans = b * c;
      }
    }else{
      if (cminus == 0){
        ans = b * d;
      }else if(dminus == 1){
        ans = a * c;
      }else{
        long ac = a * c;
        long bd = b * d;
        if (ac < bd){
          ans = bd;
        }else{
          ans = ac;
        }
      }
    }

    System.out.println(ans);
    scan.close();
  }
}

Measured memory_bytes: 35600
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
fn main() {
    input! { n: usize, mut v: [i32;n] }
    v.sort(); 
    if v[n-1] < v.iter().take(n-1).sum() {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<int> odd,even,v,out;
int main()
{
	int s,n,a,it=0,i2=0;
	scanf("%d %d",&s,&n);
	rep(i,n){
		scanf("%d",&a);
		if(a%2>0) odd.pb(a);else even.pb(a);
	}
	if(odd.size()>2){
		cout<<"Impossible"<<endl;return 0;
	}
	rep(i,n){
		if((i==0 || i==n-1) && it<odd.size()){
			v.pb(odd[it]);it++;
		}
		else{
			v.pb(even[i2]);i2++;
		}
	}
	if(odd.size()==2){
		rep(i,v[0]/2) out.pb(2);
		REP(i,1,n-1) out.pb(v[i]);
		rep(i,(v[n-1]+1)/2) out.pb(2);
	}
	else if(odd.size()==1){
		rep(i,v[0]/2) out.pb(2);
		REP(i,1,n) out.pb(v[i]);
		out.pb(1);
	}
	else{
		int x=v[0]/2;
		rep(i,x/2) out.pb(2);
		out.pb(1);
		rep(i,(x-1)/2) out.pb(2);
		REP(i,1,n) out.pb(v[i]);
		out.pb(1);
	}
	rep(i,v.size()){
		printf("%d",v[i]);
		if(i<v.size()-1) printf(" ");else printf("\n");
	}
	printf("%d\n",out.size());
	rep(i,out.size()) printf("%d\n",out[i]);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string othree[3]={
  "a..",
  "a..",
  ".bb",
};
const string dtrhee[3]={
  "abb",
  "a.c",
  "ddc"
};
const string tfour[4]={
  "aabc",
  "ddbc",
  "efgg",
  "efhh"
};
const string tfive[5]={
  "abbcc",
  "a.dee",
  "ffdgg",
  "hij..",
  "hij..",
};
const string tsix[6]={
  "a..bbc",
  "a..d.c",
  ".eedff",
  "gghi..",
  "j.hi..",
  "jkk.ll",
};
const string tseven[7]={
  "aabbcc.",
  "d..e..f",
  "d..e..f",
  ".gg.hhi",
  "j..k..i",
  "j..k..n",
  ".ll.mmn",
};
const string tnine[9]={
  "a..b..c..",
  "a..b..c..",
  ".dd.ee.ff",
  "g..h..i..",
  "g..h..i..",
  ".jj.kk.ll",
  "m..n..o..",
  "m..n..o..",
  ".pp.qq.rr",
};
void solve(long long N){
  if(N<3){
    cout<<-1<<endl;
    return;
  }
  if(N==3){
    REP(N){
      cout<<othree[i]<<endl;
    }
    return;
  }
  ll n=N%4+4;
  ll NN=N-n;
  REP(NN/4){
    For(j,4){
      For(k,4*i){
        cout<<'.';
      }
      cout<<tfour[j];
      For(k,N-4*(i+1)){
        cout<<'.';
      }
      cout<<endl;
    }
  }
  switch (n%4)
  {
  case 0LL:
    For(j,4){
      For(k,NN){
        cout<<'.';
      }
      cout<<tfour[j];
      cout<<endl;
    }
    break;
  case 1LL:
    For(j,5){
      For(k,NN){
        cout<<'.';
      }
      cout<<tfive[j];
      cout<<endl;
    }
    break;
  case 2LL:
    For(j,6){
      For(k,NN){
        cout<<'.';
      }
      cout<<tsix[j];
      cout<<endl;
    }
    break;
  case 3LL:
    For(j,7){
      For(k,NN){
        cout<<'.';
      }
      cout<<tseven[j];
      cout<<endl;
    }
    break;
  }
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 1280
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

vector<vector<ll>> graph;
vector<bool> leg;


int main()
{
  ll N; cin>>N;
  graph=vector<vector<ll>>(N,vector<ll>(0));
  vector<ll> deg(N,0);
  leg=vector<bool>(N,false);
  rep(i,N){
    ll u,v; cin>>u>>v; u--; v--;
    graph.at(u).push_back(v);
    graph.at(v).push_back(u);
    deg.at(u)++; deg.at(v)++;
  }
  
  //後退解析
  queue<ll> que;
  rep(i,N){
    if(deg.at(i)==1){
      leg.at(i)=true;
      que.push(i);
    }
  }
  while(!que.empty()){
    ll v=que.front(); que.pop();
    for(auto nv:graph.at(v)){
      if(leg.at(nv)) continue;
      deg.at(nv)--;
      if(deg.at(nv)==1){
        leg.at(nv)=true;
        que.push(nv);
      }
    }
  }
  
  ll Q; cin>>Q;
  rep(i,Q){
    ll a,b; cin>>a>>b; a--; b--;
    if(!leg.at(a)&&!leg.at(b)) cout<<2<<endl;
    else cout<<1<<endl;
  }
    
  return 0;
}


Measured memory_bytes: 12416
def resolve():
    s = input()
    lens = len(s)

    mod1 = []
    for i in reversed(range(lens)):

        mod1.append((int(s[i]) * pow(10, lens-i-1, 2019))%2019)
    mod2 = {}
    sums = 0
    for i in range(lens):
        sums += int(mod1[i])
        sums %= 2019
        if sums in mod2:
            mod2[sums] += 1
        else:
            mod2[sums] = 1
    if 0 in mod2:
        mod2[0] +=1

    keys = list(mod2.keys())
    ans = 0
    for i in range(len(mod2)):
        if mod2[keys[i]] >1:
            test = mod2[keys[i]]
            ans += test*(test-1)//2
    print(ans)
resolve()

Measured memory_bytes: 76992
# きりみんちゃんのtwから来ました
# サンプルを眺めて、mがなんなのかはわからんけどとりあえずai(0<=i<n)ごとの ai mod mの最大値はai-1ということが生える（生えたよ）
# なので、mがなんなのかはわからんけど、とりあえずaiそれぞれの最大値を足した
n = int(input())
print(sum(list(map(lambda x: int(x) - 1, input().split()))))



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

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		
		//キーがStringで中身がintのHashMapを作る
		HashMap<String, Integer> count = new HashMap<String, Integer>();
		
		for (int s=0; s<N; s++) {
			String S = br.readLine();
			if (count.containsKey(S)) { //HashMapに既にキーがあるとき
				int now = count.get(S); //キーSに紐づく中身のintを取得
				count.replace(S, now + 1);
			}
			else {
				count.put(S, 1); //まだHashMapにキーが登録されていないなら、登録する
			}
		}
		
		int Max = 0;
		for (int val: count.values()) { 
			if (Max <= val) {
				Max = val;
			}
		}
		
		List<String> print = new ArrayList<String>();
		for (String s: count.keySet()) { 
			int now = count.get(s);
			if (now == Max) {
				print.add(s);
			}
		}
		Collections.sort(print);
		
		StringWriter s = new StringWriter();
	    for (int i = 0 ; i < print.size() ; i++){
	        String ans = print.get(i);
	        s.append(ans + '\n');
	    }
	    System.out.println(s.toString());
	}
	
}


Measured memory_bytes: 74320
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b;
    if(a*-1==b)Cout(0);
    else{
        if(a<0&&abs(a)>b)Cout(-1);
        else Cout(1);
    }
    return 0;
}



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

int main() {
	string a;
	cin >> a;
	int n = a.size();
	std::map<char, int> m;
	ll ans = 1;
	m[a[0]] += 1;
	for (int i = 1; i < n; ++i)
	{
		ans += i - m[a[i]];
		m[a[i]] += 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
// Takahashi is going to set a 3-character password. How many possible passwords are there if each of its characters must be a digit between 1 and N (inclusive)?
// 1 ≤ N ≤ 9
// N is an integer.

int main() {
    int n;
    
    scanf("%d", &n);
    printf("%d\n", n*n*n);

    return 0;
}

Measured memory_bytes: 1704
using System;
using System.Collections.Generic;
using System.Linq;
using BI = System.Numerics.BigInteger;

class Program
{
	public static void Main(String[] args)
	{
		var inputList = new List<int>();

		for (int i = 0; i < 3; i++)
		{
			// スペース区切りの整数の入力
			var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			inputList.Add(input[0]);
			inputList.Add(input[1]);
		}

		var resultGroup = inputList.GroupBy(x => x).Select(x => new { x.Key, Count = x.Count() });
		if (resultGroup.Any(x => x.Count == 3))
			Console.WriteLine("NO");
		else
			Console.WriteLine("YES");
	}
}



Measured memory_bytes: 13532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
//const ll MOD=1000000007LL;
const ll MOD=998244353;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}

long long floor_sum(long long n, long long m, long long a, long long b) {
	long long ans = 0;
	if (a >= m) {
		ans += (n - 1) * n * (a / m) / 2;
		a %= m;
	}
	if (b >= m) {
		ans += n * (b / m);
		b %= m;
	}

	long long y_max = (a * n + b) / m, x_max = (y_max * m - b);
	if (y_max == 0) return ans;
	ans += (n - (x_max + a - 1) / a) * y_max;
	ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
	return ans;
}


int main(){

	ll T;
	cin >> T;
	ll n,m,a,b;
	FOR(t,0,T){
		cin >> n >> m >> a >> b;
		cout << floor_sum(n,m,a,b) << endl;
	}

}



Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll r[8888];
ll rL[8888];
ll rR[8888];
ll g[8888];
ll gL[8888];
ll gR[8888];
ll b[8888];
ll bL[8888];
ll bR[8888];


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

	ll n;cin >> n;
	string str;cin >> str;

	REP(i, n){
		if(str[i] == 'R')r[i]++;
		if(str[i] == 'G')g[i]++;
		if(str[i] == 'B')b[i]++;
	}

	REP(i, n){
		rL[i] += r[i];rL[i+1] += rL[i];
		gL[i] += g[i];gL[i+1] += gL[i];
		bL[i] += b[i];bL[i+1] += bL[i];
	}

	REV(i, n){
		rR[i] += r[i];rR[i] += rR[i+1];
		gR[i] += g[i];gR[i] += gR[i+1];
		bR[i] += b[i];bR[i] += bR[i+1];
	}

	ll ans = 0;
	for(ll i = 1;i < n;i++){
		REP(j, i){
			if(str[j] == str[i])continue;
			if(str[j] != 'R' && str[i] != 'R'){
				ans += rR[i+1];
				ans -= r[i + (i - j)];
			}
			if(str[j] != 'G' && str[i] != 'G'){
				ans += gR[i+1];
				ans -= g[i + (i - j)];
			}
			if(str[j] != 'B' && str[i] != 'B'){
				ans += bR[i+1];
				ans -=b[i + (i - j)];
			}
		}
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3932