akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9) + 7;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int nextPos = 1;
		boolean[] visited = new boolean[n+1];
		int step = 0;
		int[] buttons = new int[n];
		
		for (int i = 0; i < n; i++) {
			buttons[i] = sc.nextInt();
		}
		while (!visited[nextPos]) {
			step++;
			visited[nextPos] = true;
			nextPos = buttons[nextPos-1];
			if (nextPos == 2) {
				System.out.println(step++);
				System.exit(0);
			}
		}
		System.out.println(-1);
	}
  
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 36740
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b>c+d) cout<<"Left"<<endl;
    if(a+b==c+d) cout<<"Balanced"<<endl;
    if(a+b<c+d) cout<<"Right"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//priority_queue<int> pque;
//priority_queue<int, vector<int>, greater<int>> pque;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;


int main(void){
    int N;
    cin >> N;
    int Ans = 0;
    for(int i = 1; i < 300000; i++){
        int I = i;
        int M = 0;
        int cnt = 0;
        bool a = false, b = false, c = false;
        bool l = false;
        while(I != 0){
            if(I % 4 == 1){
                M += 3 * pow(10, cnt);
                a = true;
            }else if(I % 4 == 2){
                M += 5 * pow(10, cnt);
                b = true;
            }else if(I % 4 == 3){
                M += 7 * pow(10, cnt);
                c = true;
            }else{
                l = true;
                break;
            }
            I /= 4;
            cnt++;
        }
        if(l) continue;
        if(a == 1 && b == 1 && c == 1){
            if(M <= N) Ans++;
        }
        if(M > N){
            break;
        }
    }
    cout << Ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int N = sc.nextInt();
        int K = sc.nextInt();

        /*calculate K*(K - 1)^(N - 1)*/
        long result = K;
        for (int i = 1; i <= N - 1 ; i++) {
            result = result * (K - 1);
        }
        System.out.println(result);
    }
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n + 1; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    rep(i, n) {
        rep(j, n) {
            if ((n - i * r - j * g) % b == 0 && n - i * r - j * g >= 0)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		char[] s = in.next().toCharArray();
		StringBuilder ans = new StringBuilder();
		for (int i = 0; i < s.length; i++) {
			if (s[i] == 'B') {
				if (ans.length() > 0) {
					ans.delete(ans.length() - 1, ans.length());
				}
			} else {
				ans.append(s[i]);
			}
		}
		System.out.println(ans.toString());
		in.close();
	}
}

Measured memory_bytes: 22868
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstdlib>
using namespace std;
 const int N=2010;
const int mod=1e9+7;
int n;
int a[N];
long long sum;
int main()
{
    cin>>n;
    sum=0;
    for(int i=1;i<=2*n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+(2*n));
    for(int k=1;k<=2*n;k++)
    {
        if(a[k]<=a[k+1])
          sum+=a[k];
        else if(a[k]>a[k+1])
            sum+=a[k+1];
        k++;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
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;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int n,x,t;
  cin>>n>>x>>t;
  if(n%x==0) out(t*n/x);
  else out(t*(n/x+1));
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3640
import java.util.*;
 
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    if(A==2 && B==2){
    	System.out.println("Yes");
    }else if(A==2 && B!=2){
        System.out.println("No");
}
    if(A==4 || A==6 || A==9 || A==11){
        if(B==4 || B==6 || B==9 || B==11){
        System.out.println("Yes");
    }else if(A==4 || A==6 || A==9 || A==11){
        if(B!=4 || B!=6 || B!=9 || B!=11){
        System.out.println("No");
    }
}
}
    if(A==1 || A==3 || A==5 || A==7 || A==8 || A==10 || A==12){
        if(B==1 || B==3 || B==5 || B==7 || B==8 || B==10 || B==12){
        System.out.println("Yes");
    }else if(A==1 || A==3 || A==5 || A==7 || A==8 || A==10 || A==12){
        if(B!=1 || B!=3 || B!=5 || B!=7 || B!=8 || B!=10 || B!=12){
        System.out.println("No");
        }
    }
    }
}
}


Measured memory_bytes: 35356
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(ll i = a; i<=b; ++i)
#define NFOR(i,a,b) for(ll i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll N = 1e5 + 10;
inline ll add(ll x,ll y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline ll mul(ll x,ll y){
  x = (1LL * x * y) % mod;
  return x;
}

ll min(ll a,ll b){
	if(a<b)return a;
	return b;
}

int main()
{
	fast;

	int n,k;cin>>n>>k;
	vector<int>pos;
	vector<int>neg;
	FOR(i,1,n){
		int x;cin>>x;
		if(x<0)neg.pb(-x);
		else pos.pb(x);
	}
	if(neg.size())
	sort(all(neg));
	ll ans = 1e18;
	FOR(i,0,k){
		if(pos.size()>=i && neg.size()>=(k-i)){
			if(i==0)ans = min(ans,neg[k-i-1]);
			else if(k-i==0)ans = min(ans,pos[i-1]);
			else
			ans = min(ans, min(2*pos[i-1]+neg[k-i-1],2*neg[k-i-1]+pos[i-1]));
		}
	}

	cout << ans;

	return 0;
}

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

class CELL;
typedef vector<vector<CELL>> MAP;

class CELL{
	int A;
	int x, y;
	int collect;
public:
	CELL(int i, int j, int a) :x(i), y(j), A(a), collect(0) {}
	int getX() { return x; }
	int getY() { return y; }
	int getA() { return A; }
	void setC(int c) { collect = c; }
	int getC() { return collect; }
};
int main() {
	int N;
	cin >> N;
	MAP map;
	for (int i = 0; i < 2; i++) {
		vector<CELL> tv;
		for (int j = 0; j < N; j++) {
			int a;
			cin >> a;
			CELL tc(i, j, a);
			tv.push_back(tc);
		}
		map.push_back(tv);
	}
/*
	for (int i = 0; i < map.size(); i++) {
		for (int j = 0; j < map[i].size(); j++) {
			cout << map[i][j].getA() << '\t';
		}
		cout << endl;
	}

	*/
	queue<CELL*> q;
	map[0][0].setC(map[0][0].getA());
	q.push(&map[0][0]);
	while (!q.empty()) {
		CELL temp = *q.front();
		CELL *next = 0;
		q.pop();
		/*
		for (int i = 0; i < map.size(); i++) {
			for (int j = 0; j < map[i].size(); j++) {
				cout << map[i][j].getC() << '\t';
			}
			cout << endl;
		}
		cout << endl;
		*/
		if (temp.getX() + 1 < 2) {
			next = &map[temp.getX() + 1][temp.getY()];
			if (next->getC() == 0) {
				next->setC(temp.getC() + next->getA());
				q.push(next);
			}
			else if (next->getC() < temp.getC() + next->getA()) {
				next->setC(temp.getC() + next->getA());
			}
		}
		if (temp.getY() + 1 < N) {
			next = &map[temp.getX()][temp.getY() + 1];
			if (next->getC() == 0) {
				next->setC(temp.getC() + next->getA());
				q.push(next);
			}
			else if (next->getC() < temp.getC() + next->getA()) {
				next->setC(temp.getC() + next->getA());
			}
		}
	};

	cout << map[1][N - 1].getC() << endl;

	return 0;
}

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

int main(){
	int a[5],b[5];
	while(cin >> a[0] >> b[0] && (a[0]||b[0])){
		int best = 0;
		for(int i = 1 ; i <= 4 ; i++){
			cin >> a[i] >> b[i];
			if( a[i]+b[i] >= a[best] + b[best] ){
				best = i;
			}
		}
		cout << (char)('A'+best) << " "<< a[best]+b[best] << endl;
		
	}
}

Measured memory_bytes: 1160
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use proconio::marker::{Isize1, Usize1, Bytes, Chars};
#[proconio::fastout]
fn main() {
    proconio::input!{
        x: i128,
    }
    for i in -200i128..=200i128 {
        for j in -200i128..=200i128 {
            if i.pow(5) - j.pow(5) == x {
                println!("{} {}", i, j);
                return;
            }
        }
    }
}


Measured memory_bytes: 2164
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int po[]=new int[n];
        for(int i=0;i<n;i++){
            po[i]=(i==0)?sc.nextInt():sc.nextInt()+po[i-1];
        }
        int ans=Integer.MAX_VALUE;
        for(int i=0;i<n-1;i++){
            ans=Math.min(ans,Math.abs(po[i]-(po[n-1]-po[i])));
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    const ll big = 1000000000000000000;

    if (K % 2 == 0) {
        ll ans = abs(A - B);
        if (ans > big) {
            cout << "Unfair" << endl;
        } else {
            cout << A - B << endl;
        }
    } else {
        ll ans = abs(A - B);
        if (ans > big) {
            cout << "Unfair" << endl;
        } else {
            cout << B - A << endl;
        }
    }


    return 0;
}


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

static const int NMAX = 100;
static const int AMAX = 1000;


void bubbleSort(const int N, int* A)
{
    int flag = 1;
    int nswaps = 0;

    while(flag) {
        flag = 0;
        for (int j=N-1; j > 0; j--) {
            if ( A[j] < A[j-1] ) {
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                nswaps++;
            }
        }
    }

    for (int k=0; k < N-1; k++) cout << A[k] << " ";
    cout << A[N-1] << endl;
    cout << nswaps << endl;
}

int main (void) {

    int N;
    int A[NMAX];

    cin >> N;
    for (int i=0; i < N; i++) cin >> A[i];
    
    bubbleSort(N, A);
}



Measured memory_bytes: 3116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC148
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }
        
        public static void b()
        {
            string ans = "";
            int n = int.Parse(Console.ReadLine());
            string[] st = Console.ReadLine().Split(' ');
            string s = st[0];
            string t = st[1];
            for(int i = 0; i < n; i++)
            {
                ans += s[i];
                ans += t[i];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <queue>
#include <set>
using namespace std;

int main(){
    string S;
    std::cin >> S;
    bool isGood = true;
    for (int i = 1; i < 4; ++i)
    {
        if (S[i] == S[i-1])
        {
            isGood = false;
        }
    }
    if (isGood)
    {
        /* code */
        std::cout << "Good" << "\n";
    }else{
        std::cout << "Bad" << "\n";
    }
}

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

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

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

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

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

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

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

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

fn max(a: i64, b: i64) -> i64 {
    if a >= b {a} else {b}
}

fn main() {
    input!{
        A: i64,
        B: i64,
        K: i64,
    }
    let ans = if A >= K { (A - K, B) } else { (0,  max(0, B - (K - A))) };
    println!("{} {}", ans.0, ans.1);
}


Measured memory_bytes: 4352
Module C
    Sub Main()
        Dim input As String = Console.ReadLine()
        Dim arr() As String = Split(input, " ")
        Dim a, b As Integer
        a = arr(0) : b = arr(1)
        Dim wk As Integer = -1
        For i As Integer = 1 To 1000
            If Math.Floor(i * 0.08) = a AndAlso Math.Floor(i * 0.1) = b Then
                wk = i
                Exit For
            End If
        Next
        Console.WriteLine(wk)
    End Sub
End Module

Measured memory_bytes: 13524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace Topic01
{
    class ALDS1_1_C
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());

            int[] M = new int[N];
            for (int i = 0; i < N; i++)
            {
                M[i] = int.Parse(ReadLine());
            }
            Array.Sort(M);
            ALDS1_1_C my = new ALDS1_1_C();
            bool[] IsPrime = my.GetPrimes(M.Last());

            int result = 0;
            for (int i = 0; i < N; i++)
            {
                if (IsPrime[M[i]]) result++;
            }

            WriteLine(result.ToString());
            ReadKey();
        }

        bool[] GetPrimes(int N)
        {
            bool[] IsPrime = new bool[N + 1];
            for (int i = 2; i <= N; i++)
            {
                IsPrime[i] = true;
            }

            for (int i = 2; i * i <= N; i++)
            {
                if (IsPrime[i])
                {
                    for (int j = 2 * i; j <= N; j += i)
                    {
                        IsPrime[j] = false;
                    }
                }
            }

            return IsPrime;
        }
    }
}


Measured memory_bytes: 115480
#include <iostream>
#include <string>

using namespace std;

int main(){

  int N,i;
  int A[100];
  //  string S,A;
  
  cin>>N;
  for(i=0;i<N;i++){
    cin>>A[i];
  }

  //int size = S.length();

  for(i=0;i<N;i++){
    if((A[i]%2)==0){
     if(A[i]%3>0){
      if(A[i]%5>0){
       cout<<"DENIED"<<endl;
       break;
      }
     }
    }
    if(i==N-1){
      cout<<"APPROVED"<<endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    vector<int> dp(k+1,0);
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i-a[j]>=0&&!dp[i-a[j]])
            {
                dp[i]=1;
            }
        }
    }
    if(dp[k])
    cout<<"First"<<endl;
    else
    {
        cout<<"Second"<<endl;
    }
    
}

Measured memory_bytes: 3756
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def calc(n):
    ret = 0
    for i in range(1, 1000):
        n -= i
        if n == 0:
            ret = i
            break
        elif n < 0:
            ret = i-1
            break
    return ret

N = int(input().rstrip())
d = {}
for x in prime_factorize(N):
    if x not in d.keys():
        d[x] = 1
    else:
        d[x] += 1
ret = 0
for x in d.values():
    ret += calc(x)
print(ret)


Measured memory_bytes: 9228
n,a,b = map(int, input().split())
M = 10**9 + 7
from math import factorial
from functools import reduce
A = pow(2,n,M) - 1

q = r = 1
for i in range(a):
    q = q * (n - i) %  M
for j in range(b):
    r = r * (n - j) %  M

B = q * pow(factorial(a), M - 2, M) % M
C = r * pow(factorial(b), M - 2, M) % M
print((A-B-C)%M)

Measured memory_bytes: 5944
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin >> s;
  int ans1 = 0, ans2 = 0;
  
  for (int i = 0; i < s.length(); i++) {
    if (i & 1) {
      if (s[i] == '0') ans1++; else ans2++;
    } else {
      if (s[i] == '1') ans1++; else ans2++;
    }
  }
  
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 512
d,n=map(int,input().split())
if d==0:
    if n==100:
        print(101)
    else:
        print(n)
elif d==1:
    if n==100:
        print(100*101)
    else:
        print(100 * n)
else:
    if n==100:
        print(10000*101)
    else:
        print(10000 * n)




Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using i64=long long int;

int main() {
    vector<int> n(4);

    for (auto &e: n) cin >> e;

    sort(n.begin(), n.end());

    if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python

import sys


def check(inp) :
    check_num = [1, 7, 9, 4]

    for a in check_num :
        if a not in inp :
            return "NO"

    return "YES"


if __name__ == '__main__' :
    line = sys.stdin.readline()
    numlist = []

    for a in line.split( ) :
        numlist.append(int(a))

    print(check(numlist))


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

int main() {
  int N, M;
  cin >> N >> M;
  int L = 0;
  int H = N;
  
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    L = max(L, a);
    H = min(H, b);
  }
  
  cout << max(H - L + 1, 0) << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from functools import reduce
table_size = 510000
# table_size = 5100000
mod = 10**9+7


# Combination の計算を最適化する必要がある?
# def nCr(n, r):
#     numerator = reduce(lambda x, y: x * y % mod, range(n, n - r, -1), 1)
#     denominator = reduce(lambda x, y: x * y % mod, range(1, r + 1), 1)
#     return numerator * pow(denominator, mod-2, mod) % mod

class Combination:
    def __init__(self):
        self.fac = [None for _ in range(table_size)]
        self.finv = [None for _ in range(table_size)]
        self.inv = [None for _ in range(table_size)]

        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1

        for i in range(2, table_size):
            self.fac[i] = self.fac[i - 1] * i % mod
            self.inv[i] = mod - self.inv[mod % i] * (mod // i) % mod
            self.finv[i] = self.finv[i - 1] * self.inv[i] % mod

    def nCr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0

        return self.fac[n] * (self.finv[r] * self.finv[n - r] % mod) % mod


n, k = map(int, input().split())
# n, k = 3, 2  # Expected: 10
# n, k = 200000, 1000000000  # Expected: 607923868
# n, k = 15, 6  # Expected: 22583772

c = Combination()

# この分岐がよくわかっていない
if n < k:
    print(c.nCr(2 * n - 1, n))
else:
    total = 0
    for i in range(k + 1):
        total += c.nCr(n - 1, i) * c.nCr(n, i)
        total %= mod

    print(total)


Measured memory_bytes: 64208
n = int(input())
l = list(map(int,input().split()))
s = sum(l)
ans = 10**15
a = l[0]
ans = min(ans,abs((s-a)-a))
for i in range(1,n-1):
  a += l[i]
  ans = min(ans,abs((s-a)-a))
print(ans)

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
long long func(long long a, long long d, long long e, long long z) {
	long long r = z*3;
	a -= z;
	d -= z;
	e -= z;
	r += (a/2)*2 + (d/2)*2 + (e/2)*2;
	return r;
}
int main() {
	long long a,b,c,d,e,f,g;
	cin >> a >> b >> c >> d >> e >> f >> g;
	long long z = min({a,d,e});
	long long r = b + func(a,d,e,z);
	if (z) r = max(r, b + func(a,d,e,z-1));
	cout << r << endl;
}



Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100010
#define NIL (-1)
typedef struct {
    int parent;
    int left;
    int right;
}re;
re T[N];
int n;
int getDepth(re t){
    if(t.parent == NIL){
        return 0;
    }
    else return getDepth(T[t.parent]) + 1;
}

void printChild(re t){
    int firstchild = t.left;
    int res[n];
    int k = 0;
    if(firstchild != NIL){
        res[k++] = firstchild;
        while(T[firstchild].right != NIL){
            res[k++] = T[firstchild].right;
            firstchild = T[firstchild].right;
        }
        printf("[");
        for(int i = 0; i < k; i++){
            if(i == k-1){
                printf("%d]\n", res[i]);
            }
            else printf("%d, ", res[i]);
        }
    }
    else{
        printf("[]\n");
    }
}
int main(){

    scanf("%d", &n);
    for(int i = 0; i < n; i++) T[i].parent = T[i].left = T[i].right = NIL;

    for(int p = 0; p < n; p++){
        int node, time;
        scanf("%d %d", &node, &time);
        int c;
        for(int k = 0; k < time; k++){
            int t;
            scanf("%d", &t);
            if(k == 0){
                T[node].left = t;
            }
            else{
                T[c].right = t;
            }
            c = t;
            T[c].parent = node;
        }
    }

    for(int i = 0; i < n; i++){
        int depth = getDepth(T[i]);
        char s[30];
        if(T[i].parent == NIL){
            strcpy(s, "root");
        }
        else{
            if(T[i].left == NIL){
                strcpy(s, "leaf");
            }
            else{
                strcpy(s, "internal node");
            }
        }

        printf("node %d: parent = %d, depth = %d, %s, ", i, T[i].parent, depth, s);
        printChild(T[i]);
    }
    return 0;
}


Measured memory_bytes: 3260
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;
ll MOD = 1000000007;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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

// ***************************************

int main(void) {

	string s, t;
	cin >> s >> t;

	vector<vector<ll>> dp(s.size() + 1, vector<ll>(t.size() + 1, 0));

	REP(i, s.size()) {
		REP(j, t.size()) {
			chmax(dp[i + 1][j + 1], dp[i + 1][j]);
			chmax(dp[i + 1][j + 1], dp[i][j + 1]);
			if (s[i] == t[j]) {
				chmax(dp[i + 1][j + 1], dp[i][j] + 1);
			}
		}
	}

	ll S = s.size();
	ll T = t.size();
	string ans = "";
	while(S > 0 && T > 0){
		if (dp[S][T] == dp[S - 1][T]) { 
			S--; }
		else if (dp[S][T] == dp[S][T - 1]) {
			T--; }
		else {
			ans = s[S-1] + ans;
			S--; T--;
		}
	}
	cout << ans << endl;
		
	return 0;
}

Measured memory_bytes: 70784
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
const int MR=1e6+10;
typedef long long LL;

int main() {
	LL a,b,x;
	cin>>x;
	for(b=-200;b<=200;b++){
		for(a=b+1;a<=200;a++){
			if(a*a*a*a*a-b*b*b*b*b==x){
				cout<<a<<' '<<b<<endl;
				return 0;
			}
		}
	}
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = S.size();
  int count=0;
  for(int i=1;i<=N;i++){
    if(S[i-1]=='1'){
      count++;
    }
    else{
      count--;
    }
    //cout << count;
  }
  cout << N - abs(count) << endl;
}

Measured memory_bytes: 512
import fractions
A,B,C,D = map(int,input().split())

lcm = int(C*D / fractions.gcd(C,D))
ans_b = B - (B // C) - (B // D) + (B // lcm)
ans_a = A - 1 - ((A - 1)// C) - ((A - 1)// D) + ((A - 1) // lcm)

print(int(ans_b - ans_a))

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N;
    scanf("%d", &N);
    vector<int> A(N);
    REP(int,i,0,N) scanf("%d", &A.at(i));
    vector<int> B(N);
    vector<int> BoxIndex;

    int BoxCount = 0;

    for ( int i = N-1; i >= 0; i-- ){
        int j = 2;
        int Sum = 0;
        while ( j * ( i + 1 ) <= N ){
            Sum += B.at( j * ( i + 1 ) - 1 );
            j++;
        }
        if ( Sum % 2 == A.at(i) ) B.at(i) = 0;
        else{ 
            B.at(i) = 1;
            BoxIndex.push_back(i+1);
            BoxCount++;
        }
    }
    
    printf("%d\n", BoxCount);
    REP(int,i,0,BoxCount){
        if ( i != BoxCount - 1) printf("%d ", BoxIndex.at(i));
        else printf("%d\n", BoxIndex.at(i));
    }

    return 0;
}

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

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

int main() {
  long int N, M;

  char S[MAX], T[MAX];

  long int i;

  long int g, m, n, L;

  scanf("%ld %ld", &N, &M);
  scanf("%s", S);
  scanf("%s", T);

  g = gcd(N, M);
  n = M / g;
  m = N / g;
  L = M * N / g;

  for (i = 0; i < g; i++) {
    if (S[i * m] != T[i * n]) {
      printf("-1\n");
      return 0;
    }
  }

  printf("%ld\n", L);

  return 0;
}


Measured memory_bytes: 384
void main() {
    int[] tmp = readln.split.to!(int[]);
    int x = tmp[0], y = tmp[1], z = tmp[2];
    writeln((x - z) / (y + z));
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N, C;
    cin >> N >> C;
    ll D[C][C];
    for(ll i = 0; i < C; i++) for(ll j = 0; j < C; j++) cin >> D[i][j];
    ll c[N][N];
    for(ll i = 0; i < N; i++) for(ll j = 0; j < N; j++) cin >> c[i][j];
    ll sum[C][3];
    for(ll i = 0; i < C; i++) for(ll j = 0; j < 3; j++) sum[i][j] = 0;
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < N; j++){
            for(ll k = 0; k < C; k++){
                sum[k][(i + j) % 3] += D[c[i][j] - 1][k];
            }
        }
    }
    ll ans = 1145148931919810;
    for(ll i = 0; i < C; i++){
        for(ll j = 0; j < C; j++){
            for(ll k = 0; k < C; k++){
                if(i == j || j == k || k == i) continue;
                ans = min(ans, sum[i][0] + sum[j][1] + sum[k][2]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
D, G = [int(i) for i in input().split()]
PC = [(int(i), int(j)) for (i, j) in [input().split() for _ in range(D)]]

# 十分大きい数を用意する
ans = float("inf")

# それぞれのランクの問題を「完全に解く」 or not -> 2^D通り
for bit in range(1 << D):
    score = 0
    solve = 0
    rest = set(range(1, D + 1))

    for i in range(D):
        # (i+1)番目の問題を完全に解いた場合
        if (bit>>i) & 1:
            # スコア = 基本スコア + コンプリートボーナス
            score += PC[i][0] * (i + 1) * 100 + PC[i][1]
            solve += PC[i][0]
            # 今回解いたランクの問題を削除
            rest.discard(i + 1)

    # 目標点に満たない場合、restの大きいものから順に解く
    if score < G:
        target = max(rest)
        n = min(PC[target - 1][0], -((score-G) // (target*100)))
        score += n * target * 100
        solve += n

    if score >= G:
        ans = min(ans, solve)

print(ans)

Measured memory_bytes: 41584
#include<stdio.h>

int main(){

int min,s,t;
int N;
scanf("%d",&N);
double a[N];
for (int i = 0; i < N; i++)
{
  scanf("%lf",&a[i]);
}

for (int i = 0;i < N;i++) {      
  min=a[i];
  s=i;
  for (int j = i+1; j < N; j++)
  {                   
    if (a[j]<min)
    {
      min=a[j];
      s=j;
    }
  }
  t=a[i];
  a[i]=a[s];
  a[s]=t;               
  if (i!=0)
  {
    a[i] = (a[i]+a[i-1])/2;
  }
}
printf("%f",a[N-1]);
return 0;

}



Measured memory_bytes: 1692
#include<stdio.h>

int main(){
    int count = 0;
    long int sum = 0;

    scanf("%d", &count);

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

    printf("%ld\n", sum);

    return 0;
}

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

using namespace std;

long long a,b,c;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>a>>b>>c;
    for (int it=0;it<=1000000;it++) {
        if (a%2==1 || b%2==1 || c%2==1) {
            cout<<it;
            return 0;
        }
        int ta = (b+c)/2;
        int tb = (a+c)/2;
        int tc = (a+b)/2;
        a=ta,b=tb,c=tc;
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define N 100005
LL a[200005];
vector<pair<LL,pii> > v;
void dc(int l,int r,LL d){
    if(l==r)return;
    int mid=(l+r)/2;
    LL lmin=1e18,li;
    LL rmin=1e18,ri;
    for(int i=l;i<=mid;i++){
        LL val=a[i]+(mid-i)*d;
        if(val<lmin){
            lmin=val;
            li=i;
        }
    }
    for(int i = mid+1;i<=r;i++){
        LL val=a[i]+(i-mid)*d;
        if(val<rmin){
            rmin=val;
            ri=i;
        }
        v.pb(mp(val+lmin,mp(i,li)));
    }
    for(int i = l;i<=mid;i++){
        v.pb(mp(a[i]+(mid-i)*d+rmin,mp(i,ri)));
    }
    dc(l,mid,d);
    dc(mid+1,r,d);
}
int f[200005];
int Find(int x){
    if(f[x]==x)return x;
    return f[x]=Find(f[x]);
}
int main(){
    int n,d;
    scanf("%d %d",&n,&d);
    for(int i = 1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    dc(1,n,d);
    for(int i = 1;i<=n;i++)
        f[i]=i;
    sort(v.begin(),v.end());
    LL ans=0;
    for(auto it:v){
        int a=it.y.x,b=it.y.y;
        int fa=Find(a),fb=Find(b);
        if(fa!=fb){
            f[fa]=fb;
            ans+=it.x;
        }
    }
    printf("%lld\n",ans);
}
/*


     0   
     1   1
     2   3
     3 5  1 0 0
    4*/

Measured memory_bytes: 69472
#include <bits/stdc++.h>
#pragma GCC optmize("O3")
using namespace std;
typedef long long int ll;
int main(){
	ll N;
	cin>>N;
	vector<ll>v(N);
	for(int i=0;i<N;i++){
		cin>>v[i];
	}
	ll cont=0;
	for(int i=0;i<N;i+=2){
		if(v[i]%2==1){
			cont++;
		}
	}
	cout<<cont;
}

Measured memory_bytes: 3588
//Author: Pakhomovee 
#include <iostream> 
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

using namespace std;
using namespace std::chrono;

#define int long long

void solve()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int d = min(k, a);
    k -= d;
    int l = min(k, b);
    k -= l;
    cout << d - k << '\n';
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	auto start = system_clock::now();

    solve();

	auto end = system_clock::now();
	cerr << "Time: " << duration_cast<milliseconds> (end - start).count() << "ms" << endl;
}

Measured memory_bytes: 3640
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

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

		Map<Long, Long> map = new TreeMap<>();

		Long in = sc.nextLong();
		Long count = map.getOrDefault(in, 0L);
		count++;
		map.put(in, count);
		if (in != 0L) {
			System.out.println(0);
			sc.nextLine();
			sc.close();
			return;
		}

		for (long i = 1L; i < n; i++) {
			Long input = sc.nextLong();
			Long c = map.getOrDefault(input, 0L);
			c++;
			map.put(input, c);
		}
		sc.close();
		if (!map.containsKey(0L)) {
			System.out.println(0L);
			return;
		}
		Long before = -1L;
		for (Long key : map.keySet()) {
			if (key != before + 1L) {
				System.out.println(0L);
				return;
			}
			before = key;
		}
		if (map.get(0L) != 1L) {
			System.out.println(0L);
			return;
		}
		Long size = (long) map.values().size();
		Long ans = 1L;
		for (long i = 0L; i < size - 1L; i++) {
			Long a = map.get(i);
			Long b = map.get(i + 1L);
			for (int j = 0; j < b; j++) {
				ans = (ans * a) % 998244353L;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 65808
#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++)
using ll = long long;

int getGcd(int i,int j){
	if (j == 0){
		return i;
	}
    return gcd(j, i % j);
}

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

    ll ans = 0;

    rep(i,K+1){
    	if(i==0){
    		continue;
    	}
    	rep(j,K+1){
    		if(j==0){
    			continue;
    		}
    		rep(k,K+1){
    			if(k==0){
    				continue;
    			}
    			ans += getGcd(getGcd(i,j),k);

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


Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define mp make_pair
#define f first
#define s second
#define mod 1000*1000*1000+7
int32_t main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    int n;cin>>n;
    int ar[10];
    double div=1;
    for(int i=0;i<n;i++)
    {
        ar[i]=i;
        div*=(i+1);
    }
    vector<pair<double,double> > pos;
    for(int i=0;i<n;i++)
    {
        double x,y;cin>>x>>y;
        pos.push_back(mp(x,y));
    }
    double ans=0;
    do{
        for(int i=0;i<n-1;i++)
        {
            ans+=sqrt(pow(pos[ar[i]].f-pos[ar[i+1]].f,2)+pow(pos[ar[i]].s-pos[ar[i+1]].s,2));
        }
    }while(next_permutation(ar,ar+n));
    ans/=div;
    printf("%0.10lf\n",ans);
    return 0;
}


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

int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		string s;
		cin >> s;
		cout << s << endl;
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<utility>

using namespace std;

int main(){

	string s,ans;
	cin>>s;

	for(int i=0;i<s.size();i++){
		if(s[i]=='0')ans+='0';
		else if(s[i]=='1')ans+='1';
		else {
			if(ans.size()==0)continue;
			else ans.erase(ans.size()-1);
		}
	}

	cout<<ans;

	cout<<endl;

	return 0;
}


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

int N;
int L[200];
int main() {
  cin >> N;
  for (int i=0; i<2*N; i++) cin >> L[i];
  sort(L, L+2*N);
  int s = 0;
  for (int i=0; i<N; i++) {
    s += min(L[2*i], L[2*i + 1]);
  }
  cout << s << "\n";
  return 0;
}


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

using namespace std;

using int64 = long long;

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

vector<vector<Edge>> ReadUndirectedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge(v1, v2));
    graph[v2].push_back(Edge(v2, v1));
  }
  return graph;
}

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

  int n;
  cin >> n;
  auto graph = ReadUndirectedGraph(n, n - 1, true);

  function<pair<int, int>(int, int)> dfs =
      [&](int v, int p) -> pair<int, int> {
    auto r = make_pair(v, 0);
    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      auto c = dfs(e.to, v);
      c.second += 1;
      if (r.second < c.second) {
        r = c;
      }
    }
    return r;
  };
  int v;
  tie(v, ignore) = dfs(0, -1);
  int d;
  tie(ignore, d) = dfs(v, -1);
  if (d % 3 == 1) {
    cout << "Second" << endl;
  } else {
    cout << "First" << endl;
  }
}

Measured memory_bytes: 29952
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

# @njit
def solve(k,s):
  res = 0
  for i in range(k+1):
    for j in range(k+1):
      l = s - i - j
      if 0 <= l <= k:
        res += 1

  return res



def main():
  K,S = map(int,input().split())
  # a = list(map(int,input().split()))
  print(solve(K,S))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

void solve() {
	int x, n; cin >> x >> n;
	vector<int> v(n);
	map<int, bool> m;
	for (int &i : v)cin >> i, m[i] = 1;
	vector<int> temp;
	for (int i = 0; i <= 300; i++)if (!m[i])temp.push_back(i);
	int ans = 0, cur = 100;
	sort(temp.rbegin(), temp.rend());
	for (int i : temp) {
		if (abs(i - x) <= cur) {cur = abs(i - x); ans = i;}
	}
	cout << ans;



}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 3640
n = int(input())
csf = [[int(i) for i in input().split()] for j in range(n-1)]

for i in range(n-1):
    cnt = i
    now = 0
    tmp = 0
    while cnt <= n-2:
        if cnt == n-2:
            if now == 0:
                tmp += csf[cnt][0] + csf[cnt][1]
                print(tmp)
                cnt += 1
                now += 1
            else:
                tmp += max((tmp + csf[cnt][2] - 1) // csf[cnt][2] * csf[cnt][2],csf[cnt][1]) - tmp + csf[cnt][0]
                cnt += 1
                print(tmp)
        elif now == 0:
            tmp += csf[cnt][0] + csf[cnt][1]
            cnt += 1
            now += 1
        else:
            tmp += max((tmp + csf[cnt][2] - 1) // csf[cnt][2] * csf[cnt][2],csf[cnt][1]) - tmp + csf[cnt][0]
            cnt += 1
            
    
    
print(0)

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>

int main()
{
    int n;
    std::cin >> n;
    std::cout << abs(10 - int((n % 1000) / 100));
    std::cout << abs(10 - int((n % 100) / 10));
    std::cout << abs(10 - int((n % 10) / 1));
    std::cout << std::endl;
    return 0;
}


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

bool match(string str){
  if(str.size()==1) return true;
  for(int i=0; i<str.size()-1; i++){
    if(str[i]!=str[i+1]) return false;
  }
  return true;
}

int main(){
  string s; cin >> s;
  bool alpha[26];
  for(int i=0; i<26; i++){
    alpha[i]=false;
  }
  for(int i=0; i<s.size(); i++){
    alpha[(s[i]-'a')]=true;
  }
  int mincount=1000000;
  for(int i=0; i<26; i++){
    if(alpha[i]==true){
      string current=s;
      int count=0;
      while(match(current)==false){
        string temp=current.substr(0,current.size()-1);
        for(int j=0; j<temp.size()-1; j++){
          if(current[j+1]==(char)(i+'a')){
            temp[j]=current[j+1];
          }
        }
        current=temp;
        count++;
      }
      mincount=min(count,mincount);
    }
  }
  cout << mincount << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>

#define FOR(n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)

int main(void){
  int n;
  scanf("%d",&n);
  int h[n];
  FOR(n){
    scanf("%d",&h[i]);
    if(i){
      if(h[i-1]-h[i]>1){
        PRS("No\n");
        return 0;
      }else if(h[i-1]-h[i]>0){
        h[i]++;
      }
    }
  }
  PRS("Yes\n");
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int n = Integer.parseInt(as.next());
		String t = as.next();
		int b = Integer.parseInt(as.next());
		int a;
		if(t.equals("+")){
			a=n+b;
		}else{
			a=n-b;
		}
		System.out.println(a);
	}
}

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

int main() {
  int a[9];
  for(int i=0;i<9;i++){
      int l;
      cin>>l;
      a[i]=l;
  }
  int n;
  cin>>n;
  int b[n];
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    b[i]=l;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<9;j++){
      if(b[i]==a[j])a[j]=0;
    }
  }
  if(a[0]==0&&a[1]==0&&a[2]==0||a[3]==0&&a[4]==0&&a[5]==0||a[6]==0&&a[7]==0&&a[8]==0
     ||a[0]==0&&a[3]==0&&a[6]==0||a[1]==0&&a[4]==0&&a[7]==0||a[2]==0&&a[5]==0&&a[8]==0
     ||a[0]==0&&a[4]==0&&a[8]==0||a[2]==0&&a[4]==0&&a[6]==0){
     cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
     
}


Measured memory_bytes: 256
n, yen = map(int, input().split())
x, y, z = -1, -1, -1
for i in range(n+1):
    for j in range(n+1):
        if i+j <= n and 10000*i + 5000*j + 1000*(n-i-j) == yen:
            x, y, z = i, j, n-i-j
            break
print(x, y, z)

Measured memory_bytes: 3060
#include <iostream>
#include <string>

int main() {
    std::string s;
    std::cin >> s;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == "LR"[i % 2]) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}


Measured memory_bytes: 256
import heapq 
N = int(input())
V = list(map(int, input().split()))
heapq.heapify(V)
for i in range(N-1):
    v1 = heapq.heappop(V)
    v2 = heapq.heappop(V)
    heapq.heappush(V, (v1 + v2) / 2)

print(heapq.heappop(V))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string g;
    int y,m,d;
    while (cin>>g>>y>>m>>d) {
        if (g=="#") {
            break;
        } else {
            if (y<31) {
                cout<<g<<" "<<y<<" "<<m<<" "<<d<<endl;
            } else if (y==31) {
                if (m>4) {
                    cout<<"?"<<" "<<1<<" "<<m<<" "<<d<<endl;
                } else {
                    cout<<g<<" "<<y<<" "<<m<<" "<<d<<endl;
                }
            } else {
                cout<<"?"<<" "<<y-30<<" "<<m<<" "<<d<<endl;
            }
        }
    }
}



Measured memory_bytes: 3212