akhauriyash/Code-Regression huggingface dataset:
//بسم الله الرحمن الرحيم
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define el << endl
#define PI 3.141592653589793238
#define _test_ int t; cin >> t; while(t--)
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
ll gcd ( ll  a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }
int dx[]={0,0,+1,-1,+1,-1,-1,+1};
int dy[]={+1,-1,0,0,+1,-1,+1,-1};
///*......................*//* LET'S BEGIN (-_^) *//*............................///
const int mx= 2e6+123;
int n,a[mx];
ll ans,m,k=0;

void _case_()
{
   cin >> n;
   for(int i=0;i<n;i++)
       ans+=i;
   cout  <<  ans ;
}

int main()
{

    optimize();
    //_test_
    _case_();
    return 0;

}

///////////*  N A Y E M  *///////////

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b+c || b == a+c || c == a+b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashSet;
// use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        K: usize,
        LRs: [(usize, usize); K],
    }

    const MOD: i64 = 998244353;

    // let mut dp = vec![0i64; N];
    // dp[0] = 1;

    // acc[0] := 0
    // acc[i+1] := acc[i] + dp[i]
    let mut acc = vec![0i64; N + 1];
    acc[0] = 0;
    acc[1] = 1; // dp[0]

    for n in 1..N {
        let mut cand: i64 = 0;

        for &(l, r) in LRs.iter() {
            if n < l {
                continue;
            }

            // === 累積和で表現しないver ===
            // let mut acc : i64 = 0;
            // for i in l..=min(r,n) {
            //     // MODを消してたら累積和に気付けたかも?
            //     // acc += dp[n - i];
            //     acc = (acc + dp[n - i]) % MOD;
            // }
            // cand = (cand + acc) % MOD;
            // === ここまで ===

            // dp[n-r] + dp[n-(r-1)] + ... dp[n-l]
            cand = (cand + acc[n - l + 1] - acc[n - min(r, n)] + MOD) % MOD;
        }

        // dp[n] = cand;
        acc[n + 1] = (acc[n] + cand) % MOD;
    }

    let ans = (acc[N] - acc[N - 1] + MOD) % MOD;
    println!("{}", ans);
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>
#include <map>
#include <tuple>
#include <complex>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;
typedef vector<vs> vvs;

typedef vector<pll> vvpl;
typedef vector<vpi> vvpi;

typedef queue<ll> ql;
typedef queue<int> qi;
typedef queue<pll> qpl;
typedef queue<pi> qpi;

template <typename T>
void printv(const vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        printf("[%d] %d\n", i, v[i]);
    }
}

template <typename T>
void printvv(const vector<T> &vv)
{
    for (int i = 0; i < vv.size(); ++i)
    {
        for (int j = 0; j < vv[i].size(); ++j)
        {
            printf("[%d][%d] %d\n", i, j, vv[i][j]);
        }
    }
}

template <typename T, typename U>
void printp(const pair<T, U> &p)
{
    cout << p.first << " " << p.second << endl;
}

template <typename T>
void printvp(const vector<pair<T, T>> &vp)
{
    for (int i = 0; i < vp.size(); ++i)
    {
        printf("[%d] %d, %d\n", vp[i].first, vp[i].second);
    }
}

template <typename T>
void printvvp(const vector<vector<pair<T, T>>> &vvp)
{
    for (int i = 0; i < vvp.size(); ++i)
    {
        for (int j = 0; j < vvp[i].size(); ++j)
        {
            printf("[%d][%d] %d, %d\n", i, j, vvp[i][j].first, vvp[i][j].second);
        }
    }
}

int main()
{
    string s, t;
    cin >> s >> t;
    const int l = s.size();
    int ans = 0;
    for (int i = 0; i < l; ++i)
    {
        if (s[i] != t[i])
            ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    int in[n] = {};
    rep(i, 0, m) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        in[y]++;
    }

    int dist[n] = {};
    int mx = -1;
    bool visited[n] = {};
    rep(i, 0, n) {
        if (in[i] == 0 && !visited[i]) {
            queue<int> que;
            que.push(i);
            visited[i] = true;
            while (!que.empty()) {
                int now = que.front();
                que.pop();
                for (int next : g[now]) {
                    in[next]--;
                    if (in[next] == 0) {
                        que.push(next);
                        visited[next] = true;
                    }
                    if (dist[next] < dist[now] + 1) {
                        dist[next] = dist[now] + 1;
                        mx = max(dist[next], mx);
                    }
                }
            }
        }
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 6656
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
      	PrintWriter out = new PrintWriter(System.out);
		String str = bfr.readLine();
		String[] wa = str.split(" ");
		int N = Integer.parseInt(wa[0]);
		int a = Integer.parseInt(wa[1]);
		int b = Integer.parseInt(wa[2]);
		int sum = 0;
		for(int i=1; i<=N; i++) {
			int tmpSum = 0;
			int num = i;
			while(num != 0) {
				tmpSum += num %10;
				num /= 10;
			}
			if(tmpSum >= a && tmpSum <= b) {
				sum += i;
			}
		}
		out.println(sum);
      	out.flush();
	}
}

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

ll fastpower (ll b , ll p){
    ll k= p%2 ? b : 1 ;
    return p==0 ? 1 : k*(fastpower(b*b,p/2));
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,ans=0;
	string s,t;
	cin>>s>>t;
	n=s.length();
	for(int i=0;i<n;i++){
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        for(int j=0;j<s.size();j++){
            if(s.at(j)=='Z') s.at(j)='A';
            else s.at(j)++;
        }
    }
    cout<<s;
}


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

int main()
{
    long long k,s,cnt=0;
    cin>>k>>s;
    for(long long i=0;i<=k;i++)
    {
        for(long long j=0;j<=k;j++)
        {
            if(s-i-j>=0 and s-i-j<=k) cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int count = 0;

    REP(i,a,b+1){
        if(c%i==0)
            count++;
    }
    OP(count)

    return 0;
}


Measured memory_bytes: 3116
//#pragma GCC optimize "trapv"
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#define ll long long int
#define fab(a,b,i) for(int i=a;i<b;i++)
#define pb push_back
#define db double
#define mp make_pair
#define endl "\n"
#define f first
#define se second
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define vll vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll power(ll x, ll y) {ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, MOD - 2);}

using namespace std;
const int N=2e5+5;

ll getmax(ll n,ll k)
{
    ll ans= n*(n+1)/2;
    ans-=(n-k)*(n-k+1)/2;
    return ans;
}
ll getmin(ll n,ll k )
{
    return k*(k+1)/2;
}

int main()
{ quick;


    int n,k;
    cin>>n>>k;
    //n++;
    //ll sm=1e15+3,mx=0;
    ll ans=0;
    fab(k,n+2,i)
    {ll sm=(getmin(n,(ll)(i-1)));
    ll mx=(getmax(n,i));
    //cout<<sm<<" "<<mx<<endl;
    ans+=((mx-sm+1))%MOD;
    }
cout<<ans%MOD<<endl;

    

 cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}

Measured memory_bytes: 3784
N,M,Q = map(int, input().split())

LR = [list(map(int, input().split())) for i in range(M)]
pq = [list(map(int, input().split())) for i in range(Q)]

res = [[0]*N for i in range(N)]

def lsadd(L,R):
    L-=1
    R-=1
    for i in range(0,L+1):  
        res[i][R] += 1

for l,r in LR:
    lsadd(l,r)

for p,q in pq:
    print(sum(res[p-1][:q]))


Measured memory_bytes: 114904
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <iostream>
#include <cassert>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

int n;
string a,b,c;

int main(){
	cin>>n>>a>>b>>c;
	int ans=0;
	for(int i=0;i<n;++i){
		if(a[i]==b[i] && b[i]==c[i]) continue;
		if(a[i]==b[i] || b[i]==c[i] || a[i]==c[i])++ans;
		else ans+=2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs

def main(inputs):
	s=inputs[0][0]
	if s[2]==s[3] and s[4]==s[5]: print("Yes")
	else: print("No")


if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size(), K = s.size();
    for(int i=0; i<n-1; i++){
        if(s[i]==s[i+1]){
            K--;
            i += 2;
        }
    }
    cout << K << endl;
    return 0;
}

Measured memory_bytes: 3716
package main

import (
	"fmt"
	"log"
	"reflect"
	"strconv"
)

func main() {
	var length int
	if n, err := fmt.Scanf("%d", &length); n != 1 || err != nil {
		log.Fatalln(n, err)
	}

	array := make([]string, length)
	for i := 0; i < length; i++ {
		if n, err := fmt.Scanf("%s", &array[i]); n != 1 || err != nil {
			log.Fatalln(n, err)
		}
	}

	array2 := make([]string, length)
	copy(array2, array)

	bubbleSort(array, length)
	selectionSort(array2, length)

	printArray(array, length)
	fmt.Println("Stable")

	printArray(array2, length)
	if reflect.DeepEqual(array, array2) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}

func bubbleSort(array []string, length int) {
	for i := 0; i < length-1; i++ {
		for j := length - 1; j > i; j-- {
			num1, _ := strconv.Atoi(array[j][1:])
			num2, _ := strconv.Atoi(array[j-1][1:])
			if num1 < num2 {
				array[j], array[j-1] = array[j-1], array[j]
			}
		}
	}
}

func selectionSort(array []string, length int) {
	for i := 0; i < length-1; i++ {
		min := i
		for j := i + 1; j < length; j++ {
			num1, _ := strconv.Atoi(array[min][1:])
			num2, _ := strconv.Atoi(array[j][1:])
			if num1 > num2 {
				min = j
			}
		}
		if min != i {
			array[min], array[i] = array[i], array[min]
		}
	}
}

func printArray(array []string, length int) {
	fmt.Print(array[0])
	for i := 1; i < length; i++ {
		fmt.Printf(" %s", array[i])
	}
	fmt.Print("\n")
}


Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3+7;
const ll mod = 1e9+7;
const int sz = 62;
#define afdafafafdafaf y1;
int n,m;

int a[maxn], b[maxn], c[maxn];
int main()
{
    scanf("%d", &n);
    for(int i=1;i<n;i++)scanf("%d", a+i);
    int ans = a[1];
    a[n] = a[n-1];
    for(int i=2;i<=n;i++){
        ans += min(a[i], a[i-1]);
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String str = br.readLine();
			
			if(str == null){
				break;
			}
			
			TriangleSequence ts = new TriangleSequence(str);
			
			System.out.println(ts.getBottom());
		}
	}

}

class TriangleSequence{
	int[][] data;
	int n;
	
	public TriangleSequence(String str){
		n = str.length();
		
		data = new int[n][n];
		//??????1??????????????????
		for(int i = 0; i < n; i++){
			data[0][i] = str.charAt(i) - '0';
		}
		//2????????\???
		for(int i = 1; i < n; i++){
			for(int j = 0; j < n - i; j++){
				data[i][j] = (data[i-1][j]+data[i-1][j+1])%10;
			}
		}
	}
	
	public int getBottom(){
		return data[n-1][0];
	}
}

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

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

  bool can = true;
  for (int i = 0; i < N; ++i) {
    int dt = t[i + 1] - t[i];
    int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
    if (dt < dist) can = false;
    if (dist % 2 != dt % 2) can = false;
  }
  if (can)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
    	int a,b,c;
      	cin >> a >> b >> c;
      	bool x=false;
      	for (int i=1;i<=b;i++){
        	if((a*i)%b==c) x=true;
        }
      	if (x==true) cout << "YES"<<endl;
      	else cout <<"NO"<<endl;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
set<ll> st;
ll enum_divisors(long long N) {
    ll a = 1;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) {
            if (st.count(i))
                a = 0;
            if (N / i != i) {
                if (st.count(N / i))
                    a = 0;
            }
        }
    }
    return a;
}
int main(){

ll n;
cin >> n;
map<ll,ll> mp;
vector<ll> a(n);
rep(i,n){
    cin >> a[i];
    st.insert(a[i]);
    mp[a[i]]++;
}
ll ans = 0;
if(mp[1] == 1){
    cout << 1 << endl;
}
if(mp[1] > 2){
    cout << 0 << endl;
}
if(mp[1] == 0) {
    for (auto v : st) {
        if (mp[v] > 1)
            continue;
        ans += enum_divisors(v);
    }
    cout << ans << endl;

}
}


Measured memory_bytes: 26752
#include <iostream>
#include<string.h> 
using namespace std;
 
int main()
{int A,B;
scanf("%d%d",&A,&B);
if(A==B){

printf("Draw");
return 0;}
if(A==1)
printf("Alice");
else if(B==1 )
printf("Bob");
else if (B<A)
printf("Alice");
else if (B>A)
printf("Bob");}

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

const int N = 1000002, P = 1e9 + 7;
int T, n, m, a[N], p[N], sz, cnt[N];
int type;
bool st[N];

int main()
{
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
	for(int i = 2; i <= 1000; ++i)
		if(!st[i])
		{
			p[sz++] = i;
			for(int j = 2; j <= 1000 / i; ++j)
				st[i * j] = true;
		}
	int mcnt = 0;
	for(int i = 0, cnt; p[i] < 1000 && i < sz; ++i)
	{
		cnt = 0;
		for(int j = 0; j < n; ++j)
			if(a[j] % p[i] == 0)
			{
				++cnt;
				while(a[j] % p[i] == 0)
					a[j] /= p[i];
			}
		mcnt = max(cnt, mcnt);
	}
	sort(a, a + n);
	int cnt = 1;
	for(int i = 1; i < n; ++i) if(a[i] != 1)
	{
		if(a[i] == a[i-1]) ++cnt;
		else
		{
			mcnt = max(cnt, mcnt);
			cnt = 1;
		}
	}
	mcnt = max(cnt, mcnt);
	if(mcnt == n) puts("not coprime");
	else if(mcnt == 1) puts("pairwise coprime");
	else puts("setwise coprime");
	return 0;
}


Measured memory_bytes: 7532
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
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(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;cin >> n >> m;
	if(n >= 13){
		cout << m << endl;
	}else{
		if(n <= 5){
			cout << "0" << endl;
		}else{
		cout << m/2 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long int
#define ff first
#define pb push_back
#define ss second
#define debug 0
#define ff first
#define mp make_pair

using namespace std;

const ll MOD = 1000000007LL;

ll fact[1000006];
ll ifact[1000006];
ll power2[1000006];

int ar[100056];
int br[100056];
vector<int> adj[100005];
set<int> st;

int vis[100005];


bool prime[10000006];

vector<int> primes;



ll powr (ll a, ll  b)
{
    if (b == 0)
        return 1;
    long long int x = powr(a, b/2);
    if (b % 2 == 0)
        return (x*x)%MOD;
    else
        return ((x*x)%MOD*a%MOD)%MOD;
}
 
inline ll inv(ll x) {
  return powr(x, MOD - 2);
}
 
inline ll mulMod(ll a, ll b) {
  return (a%MOD * b%MOD) % MOD;

}
 
inline void process() {
  fact[0] = 1;
  power2[0] = 1;
  for(int i = 1; i < 1003; i++) {
    fact[i] = mulMod(fact[i - 1], i);
    power2[i] = mulMod(power2[i - 1], 2);
  }
  ifact[1002] = inv(fact[1002]);
  for(int i = 1002 - 1; i >= 0; i--) {
    ifact[i] = mulMod(ifact[i + 1], i + 1);
  }
}

inline ll ncr(ll n, ll r) {
  if(n < r) return 0;
  return mulMod(fact[n], mulMod(ifact[r], ifact[(n - r)]));
}

ll solve(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));
 
    C[0] = 1; 
 
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}

void solve1(vector<ll> price, ll n, ll S[])
{
   
   stack<ll> st;
   st.push(0);
 
   S[0] = 1;
 
   for (ll i = 1; i < n; i++)
   {

      while (!st.empty() && price[st.top()] <= price[i])
         st.pop();
 

      S[i] = (st.empty())? (i + 1) : (i - st.top());
 
      st.push(i);
   }
}

void sieve()
{
    memset(prime,true,sizeof(prime));
    prime[0]=prime[1]=false;
    
    for(ll i=2;i*i<=100006;i++)
    {
        if(prime[i])
        {
            for(ll j=i*2;j<=100006;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    
    for(int i=2;i<=100005;i++)
    {
    	if(prime[i])
    	primes.pb(i);
	}
}

map<int,int> has[100008],occur[1000005];
bool flag;


void dfs(int s, int sum)
{
	
	vis[s]=1;
	vector<int>::iterator it;
	
	for(it=adj[s].begin();it!=adj[s].end();++it)
	{
		if(!vis[*it])
		{
			ar[*it]=sum+has[s][*it];
			dfs(*it,ar[*it]);
		}
		else if(vis[*it])
		{
			int p=sum+has[s][*it];
			
			//cout<<"vis p="<<p<<"\n";
			
			if(p!=ar[*it])
			{
			flag=1;
			}
		}
	}
}




int main() 
{
    int n,m,t,p,q,s,a,b,c,d,e,f,g,h,sum,res,u,v,i,j,l,k,len,ans=0,tot,rad,ds,rs,x,y,r,z,maxm,minm;
    
    string str,ptr;
    
    
    cin>>x>>t;
    
    if(t>=x)
    cout<<0;
    else
    cout<<x-t;
	return 0;
    
}

Measured memory_bytes: 58108
"use strict";
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    var input = input.split("\n");
    if(input[0] === "ABC"){
        console.log("ARC");
    }else{
        console.log("ABC");
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30552
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dsync                         \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define B begin()
#define E end()
typedef long long ll;

using namespace std;

int main()
{
    dsync;
    int n,a[4] {0};
    cin>>n;
    while(n){
        string s;
        cin>>s;
        if(s=="AC"){
            a[0]++;
        }
        else if(s=="WA") a[1]++;
        
        else if(s=="TLE") a[2]++;

        else a[3]++;

        n--;
    }
    cout<<"AC x "<<a[0]<<"\n"<<"WA x "<<a[1]<<"\n"<<"TLE x "<<a[2]<<"\n"<<"RE x "<<a[3]<<"\n";
    return 0;
}


Measured memory_bytes: 3660
use std::io;
fn get_parms() -> Vec<i32> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("stdin error");
    return buf
        .split_whitespace()
        .map(|x| x.parse().expect("Parse failed"))
        .collect();
}

fn main() {
    let parms = get_parms();
    let (a, b, c) = (parms[0], parms[1], parms[2]);
    if a < b && b < c {
        println!("Yes");
    } else {
        println!("No");
    }
}



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

int main(void){
  int N;
  cin >> N;
  vector<long long int> L(N+1);
  L[0] = 2; L[1] = 1;
  for(int i=2;i<=N;i++){
    L[i] = L[i-1] + L[i-2];
  }
  cout << L[N] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(long long N, std::vector<long long> p){
    bool flag = false;
    int ans=0;
    int cnt=0;
    REP(i, N){
        if(p[i] == i+1){
            flag = true;
            cnt++;
        }
        else{
            flag = false;
            ans+= ceil(cnt/(float)2);
            cnt=0;
        }
    }

    flag = false;
    ans+= ceil(cnt/(float)2);
    cnt=0;
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, std::move(p));
    return 0;
}


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

int main(void)
{
    string x;
    cin>>x;
    string ans="";
    for(char c:x)
    {
        if(c=='B')
        {
            if(ans.size())
            {
                ans.pop_back();
            }
        }
        else
        {
            ans.push_back(c);
        }
    }
    cout << ans <<endl;
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<pair<int, int>> R(N), B(N);
  for (int i = 0; i < N; i++)
  {
    cin >> R[i].first >> R[i].second;
  }
  for (int i = 0; i < N; i++)
  {
    cin >> B[i].first >> B[i].second;
  }
  sort(R.begin(), R.end());
  sort(B.begin(), B.end());
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    vector<pair<int, int>>::iterator itr = lower_bound(R.begin(), R.end(), B[i]);
    int max = -1;
    vector<pair<int, int>>::iterator pos;
    for (vector<pair<int, int>>::iterator j = R.begin(); j < itr; j++)
    {
      pair<int, int> p = *j;
      if (p.second > max && p.second < B[i].second)
      {
        max = p.second;
        pos = j;
      }
    }
    if (max != -1)
    {
      R.erase(pos);
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,x,y=0;
	int i,j;
	int all[300]={0},taro[300]={0},hana[300]={0};
	int check_t[300]={0},check_h[300]={0};
	int cnt_t=0,cnt_h=0;
	int stage = 0;
	int flg = 0,f = 0,count = 0;
	while(1){
	scanf("%d",&n);
	if(n == 0)break;
		for(i = 0;i < n; i++){
		scanf("%d",&taro[i]);
		all[taro[i]] = 1;
	}
	j=0;
		for(i = 1;i <= 2*n; i++){
		if(all[i] == 0){
			hana[j] = i;
			j++;
		}
	}
	
	//太郎ソート
	for(i = 0;i < n; i++){
		for(j = 0;j < n; j++){
			if(taro[i] < taro[j]){
				x = taro[i];
				taro[i] = taro[j];
				taro[j] = x;
			}
		}
	}
	//花子ソート
	for(i = 0;i < n; i++){
		for(j = 0;j < n; j++){
			if(hana[i] < hana[j]){
				x = hana[i];
				hana[i] = hana[j];
			hana[j] = x;
			}
		}
	}
	//判定
	for(;;){
		hoge:
		if(cnt_t == n){
			f = 1;
			for(i = 0;i < n; i++){
				//printf("%d\n",check_h[i]);
				if(check_h[i] == 0){
				count++;
			}
			}
			break;
			}
		else if(cnt_h == n){
			for(i = 0;i < n; i++)if(check_t[i] == 0)count++;
			break;
		}
		if(flg == 0){
		for(i = 0;i < n; i++){
			if(check_t[i] == 0){
				if(stage < taro[i]){
					stage = taro[i];
					check_t[i] = 1;
					cnt_t += 1;
					flg = 1;
					y = 0;
					goto hoge;
				}
				else if(y == n){
					stage = 0;
					flg = 1;
					y = 0;
					goto hoge;
				}
				else y++;
			}
		}
		}
		else {
			for(i = 0;i < n; i++){
				if(check_h[i] == 0){
					if(stage < hana[i]){
						stage = hana[i];
						check_h[i] = 1;
						cnt_h += 1;
						flg = 0;
						y = 0;
						goto hoge;
						}
					else if(y == n){
						stage = 0;
						flg = 0;
						y = 0;
						goto hoge;
						}
					else y++;
				}
			}
		}
	}
	
	
	if(f == 1)printf("%d\n0\n",count);
	else printf("0\n%d\n",count);
	flg = 0,f = 0,count = 0;
	cnt_t=0,cnt_h=0;
	stage = 0;
	y = 0;
		for(i = 0;i < 300; i++){
		all[i]=0;
		taro[i]=0;
		hana[i]=0;
		check_h[i]=0;
		check_t[i]=0;
		}
	}
    return 0;
}


Measured memory_bytes: 1932
def calc(s):
    s = s.replace("-", "-~-")
    res = 0
    for bit in range(16):
        a, b, c, d = map(int, format(bit, '04b'))
        if eval(s):
            res += 1 << bit
    return res
base = "abcd10"
L = {}
for e in base:
    state = calc(e)
    L[state] = 1
ALL = 2**16-1
MAX = 10**18
for i in range(6):
    R = dict(L)
    for p in R:
        if R[p] < 16:
            L[p ^ ALL] = min(L.get(p ^ ALL, MAX), R[p] + 1)
        if R[p]+3 < 16:
            for q in R:
                if R[p] + R[q] + 3 <= 16:
                    L[p & q] = min(L.get(p & q, MAX), R[p] + R[q] + 3)
                    L[p ^ q] = min(L.get(p ^ q, MAX), R[p] + R[q] + 3)
while 1:
    s = input()
    if s == '.':
        break
    print(L[calc(s)])

Measured memory_bytes: 7956
N = int(input())
a = [int(x) for x in input().split()]

n4 = 0  # 4の倍数の個数
nodd = 0 # 奇数の個数
for i in range(N):
    nodd += (a[i] % 2 == 1)
    n4 += (a[i] % 4 == 0)

ans = "Yes"
if nodd > (N + 1) // 2:
    ans = "No"
elif n4 < min(nodd, N // 2):
    ans = "No"

print(ans)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vl a(n+1), res;
	FOR(i,1,n+1) cin >> a[i];

	FORD(i,1,n+1) {
		for (ll j = i+i; j <= n; j += i) a[i] ^= a[j];
		if (a[i]) res.pb(i);
	}
	cout << sz(res) << endl;
	for (ll x: res) cout << x << " ";
	cout << endl;
}



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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;
typedef vector<int> vi;
const int maxn = 100 + 10;

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    ll cnt = 0;
    for (auto c : s) {
        if (c == 'B') ++cnt;
        else ans += cnt;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
n=int(input())
ans=[0]*n
x=1
y=1
z=1
c=0
for i in range(1,n+1):
	if 6*i*i>n:
		d=i
		break;
#print(d)

for i in range(1,n+1):
	if 1+2*i*i+i+i+i*i>n:
		e=i
		break;
#print(e)

for i in range(d):
	x=i+1
	y=x
	z=x
	for j in range(i,e):
		y=j+1
		z=y
		for k in range(j,n):
			z=k+1
			#print(x,y,z)
			b=x*x+y*y+z*z+x*y+y*z+z*x
			if b>n:
				c=1
				break;
			if x!=y and y!=z and z!=x:
				ans[b-1]+=6
			elif (x==y and x!=z) or (y==z and x!=y):
				ans[b-1]+=3
			elif x==y and y==z:
				ans[b-1]+=1
		#if c==1:
			#break;
	#if c==1:
		#break;


for i in range(n):
	print(ans[i])

Measured memory_bytes: 9272
using System;
using System.Collections.Generic;

namespace cswork
{

    class Program
    {
        public Program() { }

        Scanner cin;

        void Omame()
        {
            cin = new Scanner();

            int n = cin.nextInt();
            string s = cin.next();

            s = s.Replace("ABC", "");

            Console.WriteLine((n - s.Length) / 3);
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  string s;
  cin >> s;
  int len = 0;
  int ans = 0;
  for(int i = 0; i < s.length(); ++i)
  {
    if (s[i] == 'A') len++;
    else if (s[i] == 'C') len++;
    else if (s[i] == 'G') len++;
    else if (s[i] == 'T') len++;
    else len = 0;

    ans = max(ans, len);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,mod=1e9+7;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    string s;cin>>s;
    deque<char>dq;
    for(auto c:s)
        dq.push_back(c);

    int q;cin>>q;
    bool r=0;
    while(q--)
    {
        int t;cin>>t;
        if(t==1) r^=1;
        else
        {
            int f;
            char c;
            cin>>f>>c;
            f--;
            f^=r;
            if(f==0) dq.push_front(c);
            else dq.push_back(c);
        }
    }
    if(r) reverse(dq.begin(),dq.end());
    for(auto c:dq)cout<<c;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 976
H,W = map(int, input().split())

C = []

for _ in range(H):
    l = list(input())
    C.append(l)
D = []
for i in range(2*H):
    l = []
    for j in range(W):
        l.append(C[i//2][j])

    D.append(l)

for i in range(len(D)):
    print(*D[i],sep="")

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

struct Card { char suit, value; };

void bubble(struct Card a[], int n) {
    
    for (int i = 0; i < n; i ++) {
        
        for (int j = n-1; j >= i; j --) {
            
            if (a[j].value < a[j-1].value) {
                
                Card t = a[j];
                a[j] = a[j-1];
                a[j-1] = t;
                
            }
        }
    }
}

void selection(struct Card a[], int n) {
    
    for (int i = 0; i < n; i ++) {
        
        int minj = i;
        
        for (int j = i; j < n; j ++) {
            
            if (a[j].value < a[minj].value) {
                
                minj = j;
                
            }
        }
        
        Card t = a[i];
        a[i] = a[minj];
        a[minj] = t;
        
    }
}



void print(struct Card a[], int n) {
    
    for (int i = 0; i < n; i ++) {
        
        if (i > 0) {
            
            cout << " ";
            
        }
        
        cout << a[i].suit << a[i].value;
        
    }
    
    cout << endl;
    
}


bool isStable(struct Card C1[], struct Card C2[], int n) {
    
    for (int i = 0; i < n; i ++) {
        
        if (C1[i].suit != C2[i].suit) {
            
            return false;
            
        }
        
    }
    
    return true;
    
}



int main() {
    
    Card C1[100], C2[100];
    int n;
    char ch;
    
    cin >> n;
    
    for (int i = 0; i < n; i ++) {
        
        cin >> C1[i].suit >> C1[i].value;
        
    }
    
    for (int i = 0; i < n; i ++) {
        
        C2[i] = C1[i];
        
    }
    
    bubble(C1,n);
    
    selection(C2,n);
    
    print(C1,n);
    
    cout << "Stable" << endl;
    
    print(C2,n);
    
    if (isStable(C1, C2, n)) {
        
        cout << "Stable" << endl;
        
    } else {
        
        cout << "Not stable" << endl;
        
    }
    
    return 0;
    
}


Measured memory_bytes: 3104
n, h = map(int, input().split())
katana = [list(map(int, input().split())) for i in range(n)]

sw_max = 0
for i in range(n):
    if katana[i][0] > sw_max:
        sw_max = katana[i][0]

count = 0
katana.sort(key=lambda x: x[1], reverse=True)
for i in range(n):
    if katana[i][1] > sw_max:
        h -= katana[i][1]
        count += 1
    if h <= 0:
        print(count)
        exit()

if h % sw_max == 0:
    count += h // sw_max
else:
    count += h // sw_max + 1
print(count)

Measured memory_bytes: 28912
import sys
m,k=map(int,input().split())
if 2**m<=k:
  print(-1)
  sys.exit()
if m==1 and k==1:
  print(-1)
  sys.exit()
if m==1 and k==0:
  print('0 0 1 1')
  sys.exit()
if m==0:
  print('0 0')
  sys.exit()

l=[]
for i in range(2**m):
  if i!=k:
    l.append(str(i))
print(' '.join(l+[str(k)]+list(reversed(l))+[str(k)]))

Measured memory_bytes: 72608
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)



















int main(){
    ll a, b;
    cin >> a >> b;
    cout << ((a <= 9 && b <= 9)? a * b : -1) << endl;
}

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

using namespace std;

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

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

int main(){
	ll N;
	vll P;
	ll i, j;
	cin >> N;
	for (i = 0; i < N; i++){
		ll p;
		cin >> p;
		P.push_back(p);
	}
	vll A(N);
	vll B(N);
	for (i = 0; i < N; i++){
		A[i] = 30000 * (i + 1);
		B[i] = 30000 * (N - i);
	}
	for (i = 0; i < N; i++){
		ll p = P[i] - 1;
		A[p] += i;
	}
	for (i = 0; i < N; i++){
		cout << A[i] << " ";
	}
	cout << endl;
	for (i = 0; i < N; i++){
		cout << B[i] << " ";
	}
	cout << endl;
	return 0;
}



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

using namespace std;
using ll = long long;
int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N);
    for (int i=0;i<N;i++) cin >> A[i];
    map<ll, ll> B;
    for (int i=0;i<N;i++) {
        // auto iter = B.find(A[i]);
        // if (iter != B.end()) B[A[i]]++;
        // else B.emplace(A[i],1);
        B[A[i]]++;
    }
    ll res = 0;
    // for (auto iter = B.begin(); iter != B.end(); iter++) { 
        // res += (iter->second)*(iter->second -1) / 2;         
    // }   
    for (auto iter :B ) res += (iter.second)*(iter.second -1) / 2;

    for (int i=0;i<N;i++){
        // res -= B[A[i]]-1;
        // cout << res << "\n";
        // res += B[A[i]]-1;
        ll val = B[A[i]];
        ll before = val*(val-1)/2;
        ll after = (val - 1)*(val - 2) / 2;
        cout << res + after - before << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IREP(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define IMAX INT_MAX
#define IMIN INT_MIN
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
template<typename T> inline void chmin(T &a, T b){ if(a > b) a = b; }
template<typename T> inline void chmax(T &a, T b){ if(a < b) a = b; }
template<typename T> inline void xch(T &a, T &b){ T w = a; a = b; b = w; }


int main() {
    int H, N;
    cin >> H >> N;
    int A[N], B[N];
    REP(i, N){
        cin >> A[i] >> B[i];
    }
    ll dp[10001];
    REP(i, 10001) dp[i] = (ll)1e10;
    dp[0] = 0;
    REP(i, N){
        REP(j, 10001){
            int next = min(j + A[i], H);
            dp[next] = min(dp[next], dp[j] + B[i]);
        }
    }
    cout << dp[H] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
typedef long long LL;
#define DBG(x) cout<<#x<<": "<<x<<"\n";
#define EOL "\n"

int main(void) {
    LL n, x;
    cin >> n >> x;

    LL len = 0;
    len += x+(n-x);

    LL a, b;
    a = x;
    b = n - x;
    if (a > b) swap(a, b);  // b > a

    while (true) {
        if (b % a == 0) {
            len += (2 * b / a - 1) * a;
            break;
        }
        else {
            len += 2 * (b / a) * a;
        }

        LL tmp = b;
        b = a;
        a = tmp % a;
    }

    cout << len << EOL;

    return 0;
}



Measured memory_bytes: 256
h, w = map(int, input().split(" "))

c = []
for i in range(10):
    c.append(list(map(int, input().split(" "))))
for k in range(10):
    for i in range(10):
        for j in range(10):
            if c[i][k] + c[k][j] < c[i][j]:
                c[i][j] = c[i][k] + c[k][j]

total_mc = 0
for _ in range(h):
    for a in list(map(int, input().split(" "))):
        if a >= 0:
            total_mc += c[a][1]
print(total_mc)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Deque;
import java.util.LinkedList;

public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Deque<Integer> deque = new LinkedList<Integer>();
		String line;
		while ((line = br.readLine()) != null) {
			int num = Integer.parseInt(line);
			if (num == 0) {
				System.out.println(deque.removeLast());
			} else {
				deque.addLast(num);
			}
		}
	}

}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	char x;
	bool flag = true;
	REP(i, N){
		cin >> x;
		if(x=='Y') flag = false;
	}
	cout << (flag?"Three":"Four") << endl;
    return 0;
}

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

main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;
    cin>>n;

    int a[n+1],b[n+1],c[n+1];
    cin>>a[1]>>b[1]>>c[1];

    for(int i=2;i<=n;i++){
        int x,y,z;
        cin>>x>>y>>z;

        a[i]=max(b[i-1],c[i-1])+x;
        b[i]=max(a[i-1],c[i-1])+y;
        c[i]=max(a[i-1],b[i-1])+z;
    }

    cout<<max({a[n],b[n],c[n]});

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())

void Add(ll &a, ll b){a=(a+b)%mod;}
void Pro(ll &a, ll b){a=(a*b)%mod;}


ll N;
ll a,b,Nim,Sum;
void input(){
    cin>>N;
    cin>>a>>b;
    rep(i,N-2) {
        ll x; cin>>x;
        Nim^=x;
    }
    Sum=a+b;
}

ll ruijou(ll x){
    if(!x) return 1;
    ll a=ruijou(x/2);
    return x%2 ? a*a*2 : a*a;
}
ll Solve(){
    ll X=Sum-Nim; // これがa&b*2となるはず
    //cout<<Sum<<' '<<Nim<<' '<<X<<endl;
    if(X%2) return -1;
    X/=2;
    rep(i,42) if((Nim>>i) & 1) if((X>>i) & 1) return -1;
    if(X>a) return -1;
    for(ll i=41; i>=0; i--){
        //cout<<i<<':'<<ruijou(i)<<endl;
        if(ruijou(i)+X>a) continue;
        if(1&(Nim>>i)) X+=ruijou(i);
    }
    if(X==0) return -1;
    return a-X;
}
int main(){
    input();
    cout<<Solve()<<endl;
}

Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;

namespace CsharpProgramTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // n
            var n = int.Parse(Console.ReadLine());
            var oldT = 0;
            var oldX = 0;
            var oldY = 0;

            for(var i = 0; i < n; i++) {
                // 入力取得
                var s = Console.ReadLine().Split(' ');
                var t = int.Parse(s[0]);
                var x = int.Parse(s[1]);
                var y = int.Parse(s[2]);

                // T時間差
                var tSub = t - oldT;
                // 距離
                var dic = Math.Abs(x - oldX) + Math.Abs(y - oldY);
                // 距離が足りない
                if(tSub < dic) {
                    Console.WriteLine("No");
                    return;
                }

                // 偶数奇数判定
                var isTEven = tSub % 2 == 0;
                var isDicEven = dic % 2 == 0;
                // 両方奇か両方偶なら達成
                if(!((isTEven && isDicEven) || (!isTEven && !isDicEven))) {
                    Console.WriteLine("No");
                    return;
                }
                oldT = t;
                oldX = x;
                oldY = y;
            }
            // クリア
            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 15292