akhauriyash/Code-Regression huggingface dataset:
import copy
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

L,A,B,mod = na()

low = 1
high = 10


def matpow(M, v, e, mod):
    A = copy.deepcopy(M)
    w = copy.deepcopy(v)
    while e > 0:
        if e&1:
            w = mulv(A, w, mod)
        A = mul(A, A, mod)
        e >>= 1
    return w


def mulv(M, v, mod):
    n = len(M)
    m = len(v)
    ret = [0] * n
    for i in range(n):
        s = 0
        for j in range(m):
            s += M[i][j] * v[j]
        ret[i] = s % mod
    return ret


def mul(A, B, mod):
    n = len(A)
    m = len(B)
    o = len(B[0])
    ret = [[0] * o for _ in range(n)]
    for i in range(n):
        for j in range(o):
            s = 0
            for k in range(m):
                s += A[i][k] * B[k][j]
            ret[i][j] = s % mod
    return ret


# x = x * high + val
# val += B
# (high 1 0)
# (0 1 1)
# (0 0 1)

v = [0, A, B]
ra = A

while low < 1e18:
    mat = [[high%mod, 1, 0], [0, 1, 1], [0, 0, 1]]
    step = max(0, min(L, (high-ra+B-1)//B))
    v = matpow(mat, v, step, mod)
    # print(low, high, step, ra + B*step, v)
    ra = ra + B * step
    L -= step

    low *= 10
    high *= 10

print(v[0])


Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    map<int,int> mp;
    int cnt = 0;
    for(int i = 0; i < n-1; i++){
        mp[i] = cnt;
        if(s[i] == 'A' && s[i+1] == 'C') cnt++;
        
    }    
    mp[n-1] = cnt;
    vector<int> ans;
    for(int i = 0; i < q; i++){
        int l,r;
        cin >> l >> r;
        l--;r--;
        ans.push_back(mp[r]-mp[l]);
    }
    for(auto p:ans) cout << p << endl;
    return 0;
}

Measured memory_bytes: 6136
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

min = 999
min_i = -1
for i in range(N):
  if abs(A-(T-H[i]*0.006))<min:
    min = abs(A-(T-H[i]*0.006))
    min_i = i

print(min_i+1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> state;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }
int ceil(int a,int b){
  // a/bの切り上げを考える
  return (a+b-1)/b;
}

int main() {
  int x;
  cin >> x;
  cout << ((x >= 30)?"Yes":"No") << endl;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){
    int N,ans=0;
    cin>>N;
    for(int i=1;i<=N;++i){
        if(i<10){
            ans++;
        }
        else if (i>99&&i<1000){
            ans++;
        }
        else if(i>9999&&i<100000){
            ans++;
    }
}
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = 0;

    array<int64_t, 3> cs{ 0, 0, 0 };

    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < s.size() - 1; j++)
        {
            if (s.substr(j, 2) == "AB")
            {
                ans++;
            }
        }
        if (s.front() == 'B' && s.back() == 'A')
        {
            cs[0]++;
        }
        else if (s.front() == 'B')
        {
            cs[1]++;
        }
        else if (s.back() == 'A')
        {
            cs[2]++;
        }
    }

    if (cs[0] == 0)
    {
        cout << ans + min(cs[1], cs[2]) << endl;
    }
    else
    {
        if (cs[1] + cs[2] > 0)
        {
            cout << (ans + cs[0] + min(cs[1], cs[2])) << endl;
        }
        else
        {
            cout << (ans + cs[0] - 1 + min(cs[1], cs[2])) << endl;
        }
    }
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		int r =scan.nextInt();
		int c =scan.nextInt();
		int num[][] = new int[100][101]; //num[???][?¨?]
		int sumsum[] = new int [101];
		int sum = 0;
		
		for(int i =0; i<r; i++){
			sum = 0;
			for(int ii=0;ii<c;ii++){
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			}
			System.out.println(sum);
		}
		
		for(int i =0; i<r; i++){
			for(int ii=0;ii<c;ii++){
				sumsum[ii] += num[ii][i];
			}
		}
		
		sum = 0;
		for(int i=0; i<c; i++){
			sum += sumsum[i];
			System.out.print(sumsum[i]+" ");
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 41708
N, Q = map(int, input().split(" "))
S = input()
ac_cnts = [0]
ac_cnt = 0
for i in range(N-1):
    if S[i:i+2] == "AC":
        ac_cnt += 1
    ac_cnts.append(ac_cnt)
for j in range(Q):
    l, r = map(int, input().split(" "))
    print(ac_cnts[r-1] - ac_cnts[l-1])


Measured memory_bytes: 6100
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define LargeNum 1000000007;
ull GCD (ull a, ull b){
    if (b==0) return a;
    GCD(b, a % b);
}
ull LCM (ull a, ull b){
    ull gcd = GCD(a, b);
    return a / gcd * b;
}
int main(){
    int N;
    cin >> N;
    ull T[N];
    rep(i, N) cin >> T[i];
    ull l = T[0];
    rep(i, N-1){
        l = LCM(l, T[i+1]);
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	bool flag=false;
	FOR(i,1,4){
		if(a*b*i%2==1){
			flag=true;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
// AOJ 1553: Manhattan Warp Machine 1
// 2019.2.22 bal4u

#include <stdio.h>
#include <stdlib.h>

#define MAX 1300000
typedef struct { int x, c; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].c < que[i].c) min = l; else min = i;
	if (r < qsize && que[r].c < que[min].c) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int x, int c)
{
	int i, min;
	QUE qt;

	i = qsize++, que[i].x = x, que[i].c = c;
	while (i > 0 && que[min = PARENT(i)].c > que[i].c) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

int N;
int D[20], C[20];
char visited[200005];

int dijkstra(int start, int goal)
{
	int i, x, y, c;
	int lim = goal << 1;

	qsize = 0;
	enq(start, 0);
	while (qsize) {
		x = que[0].x, c = que[0].c; deq();
		if (x == goal) return c;
		if (visited[x]) continue;
		visited[x] = 1;
		for (i = 0; i < N; i++) {
			y = x + D[i];
			if (y < 200005 && visited[y] == 0) enq(y, c+C[i]);
			y = x - D[i];
			if (y > 0 && visited[y] == 0) enq(y, c+C[i]);
		}
	}
	return -1;
}

typedef struct { int d, c; } T;
T tbl[20];

int cmp(const void *a, const void *b)
{
	return ((T *)a)->c - ((T *)b)->c;
}

int main()
{
	int i, X;

	scanf("%d%d", &N, &X);
	for (i = 0; i < N; i++) scanf("%d%d", &tbl[i].d, &tbl[i].c);
	qsort(tbl, N, sizeof(T), cmp);
	for (i = 0; i < N; i++) D[i] = tbl[i].d, C[i] = tbl[i].c;
	printf("%d\n", dijkstra(0, X));
	return 0;
}



Measured memory_bytes: 11720
#include <iostream>
#include <map>
#include <vector>
#include <set> 
#include <iterator> 

using namespace std;

int main() {
	// your code goes here
	int d,x,i;
	long long int r;
	cin >> r >> d >> x;

	long long int ans = x;
	
	for(i=1;i<=10;i++){

		ans = r*ans - d;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int h,i,n,c = 0;
  cin  >> h >> n;
  int a[n];
  for ( i = 0; i < n; i++){
    cin >> a[i];
    c += a[i];
  }
  if (c >= h){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }
  return 0;   
}

Measured memory_bytes: 640
// ConsoleApplication7.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<iomanip>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int a, b;
	while (cin>>a>>b)
	{
		if (a != b)
		{
			cout << "No\n";
		}
		else
		{
			cout << "Yes\n";
		}
	}
}



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

int main(){
  ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  ll n,i,k,c;
  string a,b;
  cin>>a>>b;
  ll ans=0;
  for(i=0;i<a.size();i++)
  ans+=(a[i]!=b[i]);
  cout<<ans;
  
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (double i = (a); i < (b); i++)
typedef long long ll;

int main (void)
{
    boost::multiprecision::cpp_int a, b, ans;
    cin >> a >> b;
    ans = a % b;
    cout << ans << endl;
}


Measured memory_bytes: 3276
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

const ll mod = 1e9+7;

// mod pにおけるi(1<=i<=n)の逆元
vector<ll> list_minv(ll n, ll m) {
    vector<ll> inv(n + 1);
    inv[1] = 1;
    for (int i = 2; i <= n; ++i) {
        inv[i] = inv[m % i] * (m - m / i) % m;
    }
    return inv;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    int mx = 1;
    rep(i,n) cin >> a[i], chmax(mx, a[i]);

    auto prime_factrize = [&](ll a) -> map<ll,ll> {
        map<ll, ll> m;
        for (ll i = 2; i*i <= a; i++) {
            if (a%i != 0) continue;
            ll cnt = 0;
            while (a%i == 0) {
                cnt++;
                a /= i;
            }
            m[i] += cnt;
        }
        if (a > 1) m[a]++;
        return m;
    };

    map<ll, ll> p;
    map<ll, ll> t;
    rep(i,n) {
        t = prime_factrize(a[i]);
        for (auto v : t) {
            if (p[v.first] < v.second) p[v.first] = v.second;
        }
    }

    ll ans = 0;

    ll lcm = 1;
    for(auto v: p) {
        rep(i,v.second) (lcm*=v.first)%=mod;
    }

    vector<ll> minv = list_minv(mx, mod);

    rep(i,n) {
        ll tmp = 1;

        (ans += lcm*minv[a[i]]) %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8704
n=7**6;P=[0,0]+[1]*n;S=[0]*n
for i in range(2,n):
  for j in range(2*i,n,i):P[j]=0
  S[i]+=(P[i]==P[(i+1)//2]==1)+S[i-1]
for _ in "_"*int(input()):l,r=map(int,input().split());print(S[r]-S[l-1])

Measured memory_bytes: 13320
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll n,b=0,a=0,sum=0;
    string s;
    cin>>s;
    cin>>n;
    int cost=0;
    for(auto i=s.begin();i!=s.end();i++){
        if(*i!='a'){
            if(cost+'z'+1-*i>n){
            }
            else{
                cost+='z'+1-*i;
                *i='a';
            }
        }
    }
    (*(s.end()-1))+=((n-cost)%26);
    if(*s.end()>'z')*s.end()-=26;
    cout<<s<<endl;
}

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

//#define int long long
typedef long long ll;
const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i=0;i<26;i++) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    for (int i=0;i<D;i++){
        for (int j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    vector<int> t(D);
    //初期t[i]の決定
    for (int i=0;i<D;i++) {
        t[i] = i % 26;
    }

    ll oldsum = -INF;
    for (int m=0;m<100000;m++){
        //ここでt[i]を更新していく
        int dd = rand()%D;
        int qq = rand()%26;
        int oldval = t[dd];
        t[dd] = qq;
        //=======================
        ll sum = 0;
        vector<int> last(26);
        for (ll i=0;i<D;i++){
            sum += s[i][t[i]];
            last[t[i]] = i+1;
            for (int j=0;j<26;j++){
                sum -= c[j]*(i+1-last[j]);
            }
        }
        if (sum > oldsum) {
            oldsum = sum;
        } else {
            t[dd] = oldval;
        }
    }
    for (int i=0;i<D;i++){
        cout << t[i]+1 << "\n";
    }
}

Measured memory_bytes: 3676
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<cmath>

#define rep(i,n) for(int i = 0;i < n;++i)
#define rep2(i,n,m) for(int i = n;i < m;++i)
#define all(v) v.begin(),v.end()

using namespace std;
using ll = long long;


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

    int n,m;
    string s;
    int b,c=0,sum=0;
    cin >> s;
    if(s.at(2) == s.at(3) && s.at(4) == s.at(5))
    {
        cout << "Yes" <<endl;

    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int W,H,x,y,r;

    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

    if (W-r>=x&&r<=x&&H-r>=y&&r<=y)//&&??§????????????!!??§????????????!??§??????
    printf("Yes\n");
else
    printf("No\n");

    return 0;

}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int a,b;
	std::cin >> a >> b;
	if (a <= b) {
		std::cout << a << '\n';
	}
	else {
		std::cout << a-1 << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
function Scanner(input) {
	var self = this;
	self.itemNo = 0;
	self.orgStr = input;
	self.splitedStrs = (function(target) {
		var result = [];
		var target = target.replace(/[\n \t]+/g, " ");
		var strs = target.split(" ");
		for (var i = 0, len = strs.length; i < len; i++) {
			result.push(strs[i]);
		}
		return result;
	}(input));

	self.next = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? result : null;
	}

	self.nextInt = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseInt(result) : null;
	}

	self.nextBigDecimal = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseFloat(result) : null;
	}
	
	self.nextByte = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? new Int8Array(result) : null;
	}

}

function Main(sc) {

	var A = sc.nextInt();
	var B = sc.nextInt();
	var N = sc.nextInt();
	var max = 0;
	
	if (A > B) {
		var wk = 0;
		for (var x = 0; x <= N && x <= 100000; x++) {
			wk = Math.floor((A * x)/ B) - A * Math.floor(x / B);
			if (wk > max) max = wk;
		}
	}
	else {
		var x = (N >= B) ? B - 1 : N;
		max = Math.floor((A * x)/ B) - A * Math.floor(x / B);
	}
	
	console.log(max);
}
Main(new Scanner(require("fs").readFileSync("/dev/stdin", "utf8")));
// Main(new Scanner("33"));

// var str1 = sc.next(); // Stringで取得
// var int1 = sc.nextInt(); // intで取得
// var bd1 = sc.nextBigDecimal(); // BigDecimalで取得
// var byte1 = sc.nextByte(); // byteで取得
// for (var i = 0; i < 1000000000; i++) var toDelay = "aaa"; // 1000msくらいの遅延


Measured memory_bytes: 33112
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 100000

typedef long long ll;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};


int main(){
    string s,t;
    cin >> s >> t;
    vector<char> _s(s.length());
    vector<char> _t(t.length());
    for(int i = 0; i < s.length(); i++) _s[i] = s[i];
    for(int i = 0; i < t.length(); i++) _t[i] = t[i];
    sort(_s.begin(),_s.end());
    sort(_t.begin(),_t.end(),greater<>());
    int flag = 0;
    for(int i = 0; i < min(s.length(),t.length()); i++){
        if(_s[i] > _t[i]){
            flag = -1;
            break;
        }
        if(_s[i] < _t[i]){
            flag = 1;
            break;
        }
    }
    if(flag == 1) cout << "Yes" << endl;
    else if(flag == 0 && s.length() < t.length()) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int N;
typedef pair<int, int> point;
typedef tuple<int, point, vector<point>> redp;
vector<redp> redv;
vector<point> bluev;
map<point, int> bmap; //各青点が何個の赤点とペアになりうるかの個数

void delCandidate(point bp, vector<redp> &rpv){
	for(int i = 0; i < rpv.size(); i++){
		vector<point> &v = get<2>(rpv[i]);
		for(int j = 0; j < v.size(); j++){
			if(v[j] == bp){
				v.erase(v.begin() + j);
				get<0>(rpv[i]) -= 1;
				break;
			}
		}
		get<0>(rpv[i]) = v.size();
	}
	bmap[bp] = 0;
}

void initRedPoints(){
	for(int i=0; i<redv.size(); i++){
		point rp = get<1>(redv[i]);
		vector<point> &v = get<2>(redv[i]);
		for(int j=0; j<bluev.size(); j++){
			point bp = bluev[j];
			if(bp.first > rp.first && bp.second > rp.second){
				v.push_back(bp);
				bmap[bp]++;
			}
		}
		get<0>(redv[i]) = v.size(); 
	}
	int ezero = 1;
	while(ezero == 1){
		for(int i=0; i<redv.size(); i++){
			int cand = get<0>(redv[i]);
			if(cand == 0){
				redv.erase(redv.begin() + i);
				break;
			}
		}
		ezero = 0;
		for(int i=0; i<redv.size(); i++){
			int cand = get<0>(redv[i]);
			if(cand == 0){
				ezero = 1;
				break;
			}
		}
	}
}

//候補の数がcandである中で重複が最小の青点候補を探す。
void searchBestBluePoint(vector<redp> &v, int cand, int &min_r, int &min_b, int &bx, int &by){
	int min_cand = 100;
	for(int i=0; i<v.size(); i++){
		if(get<0>(v[i]) == 0) continue;
		if(get<0>(v[i]) > cand) break;
		vector<point> w = get<2>(v[i]);
		for(int j=0; j<w.size(); j++){
			if( min_cand > bmap[w[j]] ){
				min_cand = bmap[w[j]];
				bx = w[j].first;
				by = w[j].second;
				min_r = i;
				min_b = j;
			}
		}
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N ;
	for(int i=0; i<N; i++){
		int a, b;
		cin >> a >> b;
		vector<point> v;
		redv.push_back( make_tuple(0, make_pair(a, b), v) );
	}
	for(int i=0; i<N; i++){
		int c, d;
		cin >> c >> d;
		bluev.push_back( make_pair(c, d) );
		bmap[make_pair(c, d)] = 0;
	}

	initRedPoints();
	sort(redv.begin(), redv.end());

	int ans = 0;
	int count = 100;
	while(count > 0){
		for(int i=0; i<redv.size(); i++){
			if(get<0>(redv[i]) == 0){
				continue;
			}
			int min_r, min_b;
			int bx, by;
			int cand = get<0>(redv[i]);
			searchBestBluePoint(redv, cand, min_r, min_b, bx, by);
			point candp = make_pair(bx, by);
			delCandidate(candp, redv);
			bmap[candp] = 0;
			ans++;
			redv.erase(redv.begin() + min_r);
			break;
		}
		sort(redv.begin(), redv.end());
		count = 0;
		for(int i=0; i<redv.size(); i++){
			count += get<0>(redv[i]);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

    int sum=0;
    for (int i=1; i<=N; i++) {
      int n=i;
      int digSum=0;
      while (n>0) {
        digSum+=n%10;
        n/=10;
      }
      if (digSum>=A && digSum<=B)
        sum+=i;
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 35552
#include <stdio.h>

int main(void) {
	int w,h,x,y,r;
	scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
	if(0 <= (x-r) && w >= (x+r) && 0 <= (y-r) && h >= (y+r))
		printf("Yes\n");
	else 
		printf("No\n");
	return 0;
}

Measured memory_bytes: 584
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    K = int(input())
    A,B = map(int,input().split())

    res = 'NG'

    for i in range(A,B+1):
        if i % K == 0:
            res = 'OK'

    print(res)



main()


Measured memory_bytes: 9172
#include<iostream>
using namespace std;
int dp[50];
int fib(int n) {
	if (dp[n]) return dp[n];
	return dp[n] = fib(n - 1) + fib(n - 2);
}
int main(void) {
	dp[0] = 1;
	dp[1] = 1;
	int n;
	cin >> n;
	cout << fib(n)<<endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <fstream>
#include <map>

using namespace std;

int main(){
	int N, S, W, Q;
	static int a[100000];
	while(cin >> N >> S >> W >> Q, N){
		map<int, int> mp;
		for(int i=0;i<N;i++){
			a[i] = (S/7)%10;
			if(S%2 == 0) S /= 2;
			else         S = (S/2)^W;
		}
		int res = 0, cur = 0, mul = 1, cnt = 0;
		for(int i=N-1;i>=0;i--){
			if(Q == 2 || Q == 5){
				if(a[i]%Q == 0) cnt++;
				if(a[i] != 0) res += cnt;
			} else {
				cur = (a[i]*mul+cur)%Q;
				if(!mp.count(cur)) mp[cur] = 1;
				else               mp[cur]++;
				mul = (10*mul)%Q;
				if(a[i] != 0) res += mp[cur]-(cur!=0);
			}
		}
		cout << res << endl;
	}
}

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

int main(void){
    int n;
    cin >> n;
    map<pair<int, int>, int> mp;
    rep1(i,n){
        string s = to_string(i);
        mp[{s.back()-'0', s.front()-'0'}]++;
    }
    ll sum = 0;
    rep1(i,n){
        string s = to_string(i);
        sum += mp[{s.front()-'0', s.back()-'0'}];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
N,L=map(int,input().split())
wa=(L-1)*(N-1)+N*(N+1)//2
mi=L+1-1
ma=L+N-1
if mi>=0:
    eat=1
    
elif ma<=0:
    eat=N
else:
    eat=1-L
print(wa-eat)
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int a,b,ans=-1;
    cin >>a >>b;
for(int i=1;i<=1500;i++){
    int x=(8*i)/100;
    int y=(10*i)/100;
    if(x==a && y==b){ans=i;break;}
}
cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
int t[20],cnt,n,re[1000005];
bool vis[1000004];
int dfs(int x)
{
	//cout<<x<<endl;
	if(x<6) return x;
	int now=1;
	int ans=1e9;
	while(now*6<=x)
	{
		now*=6;
	}
	ans=min(ans,1+dfs(x-now));
	now=1;
	while(now*9<=x)
	{
		now=now*9;
	}
	ans=min(ans,1+dfs(x-now));
	//cout<<ans<<endl;
	return ans;
}
int main(){
	cin>>n;
	printf("%d",dfs(n));
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
tree = [[] for _ in range(N)]
cost_from_k = [0]*N

def calcurate_cost(fr, to, cost):
  cost_from_k[to] += cost_from_k[fr]+cost
  for n_to, n_cost in tree[to]:
    if n_to == fr:
      continue
    if K != n_to:
      calcurate_cost(to, n_to, n_cost)
      
for i in range(N-1):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1
  tree[a].append((b,c))
  tree[b].append((a,c))

  
Q, K = map(int, input().split())
K -= 1
calcurate_cost(K, K, 0)

for j in range(Q):
  x, y = map(int, input().split())
  print(cost_from_k[x-1]+cost_from_k[y-1])
 

Measured memory_bytes: 131772
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;
	int A[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	long long res = 0;
	long long sum = 0;
	int left = 0, right = left;
	for (left = 0; left < N; left++) {
		while (right < N && (sum^A[right]) == (sum + A[right])) {
			sum += A[right];
			right++;
		}
		res += right - left;
		if (left == right) right++;
		else sum -= A[left];
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
import atexit
import io
import sys

buff = io.BytesIO()
sys.stdout = buff


@atexit.register
def write():
    sys.__stdout__.write(buff.getvalue())

s = raw_input()
cnt1 = 0
cnt2 = 0
l1 = []
l2 = []
for i in xrange(len(s)):
	if i%2 == 0:
		l1.append('1')
		l2.append('0')
	else:
		l1.append('0')
		l2.append('1')
for i in xrange(len(s)):
	if l1[i] != s[i]:
		cnt1 += 1
	if l2[i] != s[i]:
		cnt2 += 1
print min(cnt1, cnt2)

Measured memory_bytes: 44908
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(long long i=j;i<(n);++i)
#define bk(i,j,n)   for(long long i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define srt(x) sort(x.begin(),x.end());
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}



int main()
{
    run;
    ll h,w;
    cin>>h>>w;
    if(h==1 || w==1)
    {
        cout<<1<<endl;
        return 0;
    }
    h*=w;
    if(h%2)
    {
        cout<<h/2+1;

    }else{
    cout<<h/2;}


    return 0;


}


Measured memory_bytes: 256
def main():
  n, m = list(map(int, input().split()))
  
  if n == 1 and m == 1:
    return 0
  if n+m == 2:
    return 1
  
  total = factorial(n+m) / (factorial(n+m-2) * 2)
  return int(total - (n*m))

def factorial(value):
  result = value
  for i in range(1, value-1):
    result *= (value-i)

  return result

print(main())

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int n,flag=0;
    cin >>n;
    while(n>0){
        int u=n%10;
        if(u==7){
            flag=1;
            break;
        }
        n /= 10;
    }
    if(flag==1)
        cout << "Yes" << endl;
        else
            cout << "No" <<endl;
}

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

stack<int> st;

int main() {
	
	int m, tmp;
	
			while (cin >> m){
			
				if(m > 0)  {
					st.push(m);
				}
				else if(m == 0)  {
					cout << st.top() << endl;
					st.pop();
				}
			}
			
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int MAX_M=100000;

int main(){
    ios::sync_with_stdio(false);
    int n,m;
    int a[MAX_M],b[MAX_M];
    cin >> n >> m;
    rep(i,m){
        cin >> a[i] >> b[i];
    }
    P bridge[MAX_M];
    rep(i,m){
        bridge[i].first=b[i];
        bridge[i].second=a[i];
    }
    sort(bridge,bridge+m);
    int ans=0,now=0;
    rep(i,m){
        if(now<=bridge[i].second){
            now=bridge[i].first;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <string>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define mp(a,b)	make_pair(a,b)
#define fst	first
#define scn second

int main() {
	ll x, y;	cin >> x >> y;
	if (max(x, y) - min(x, y) <= 1)	cout << "Brown" << endl;
	else	cout << "Alice" << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <random>
#include <sstream>

using namespace std;

#define int long long
#define ull unsigned long long
#define double long double
#define time time228
#define left left228
#define right right228


template<typename T> void uin(T &a, T b) {
    if (b < a) a = b;
}

template<typename T> void uax(T &a, T b) {
    if (b > a) a = b;
}

const int maxn = 111;

int a[maxn];
bool used[maxn];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    vector<int> res;
    for (int it = 0; it < n; ++it) {
        int ind = 0;
        int last = 0;
        for (int i = 1; i <= n; ++i) {
            if (used[i]) continue;
            ++ind;
            if (a[i] == ind) {
                last = i;
            }
        }
        if (last == 0) {
            cout << -1 << endl;
            return 0;
        }
        used[last] = 1;
        res.push_back(a[last]);
    }
    reverse(res.begin(), res.end());
    for (int i : res) {
        cout << i << '\n';
    }
    return 0;
}








Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    string s;
    cin >> s;
    if(s.size()%2==0 ^ s[0]==s[s.size()-1]){
        puts("Second");
    }else{
        puts("First");
    }
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string s;
  cin >> s;
  char ans[100] = { 0 };
  long i = 0;
  for (char c: s) {
    if (c == 'B') {
      if (i > 0) ans[--i] = 0;
    }
    else ans[i++] = c;
  }
  puts(ans);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()

	T := sc.NextIntArray()
	N := sc.NextInt()

	Q := make([]int, 4)
	Q[0] = T[0] * 4
	Q[1] = T[1] * 2
	Q[2] = T[2] * 1

	mi := 0
	mv := Q[0]
	for i := 0; i < 3; i++ {
		if mv > Q[i] {
			mv = Q[i]
			mi = i
		}
	}
	A := T[mi] * int(1<<(2-uint(mi)))

	ans := A * N

	if 2*A > T[3] {
		ans = N / 2 * T[3]
		if N%2 == 1 {
			ans += A
		}
	}

	fmt.Println(ans)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
fun main(args: Array<String>) = yorukatsu14f()

fun yorukatsu14f() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() - 1 }.toLongArray()

    val cSumMod = LongArray(n + 1)
    for (i in 0 until n) cSumMod[i + 1] = (cSumMod[i] + aList[i]) % k

    var answer = 0L
    val curr = mutableMapOf<Long, Long>()

    for ((index, cs) in cSumMod.withIndex()) {
        answer += curr[cs] ?: 0
        curr[cs] = (curr[cs] ?: 0) + 1
        if (index + 1 >= k)
            curr[cSumMod[index + 1 - k]] = curr[cSumMod[index + 1 - k]]!! - 1
    }

    println(answer)
}


Measured memory_bytes: 104240
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
string s;
cin>>s;
cin>>s;
cout<<"A"<<s[0]<<"C"<<endl;
cin>>s;
}

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

int n,p;
struct data{
	string name;
	int h,m;
	data(){}
	data(string s,int hh,int mm){
		name=s;
		h=hh;
		m=mm;
	}
};

bool comp(const data& d1,const data& d2){
	if(d1.h==d2.h)return d1.m<d2.m;
	return d1.h<d2.h;
}

data d[7][501];
int dcnt[7];
set<string> fav;
bool used[7][30][61];

bool check(){
	for(int i=0;i<7;i++){
		for(int j=0;j<dcnt[i];j++){
			if(fav.find(d[i][j].name)!=fav.end()){
				int k=0,nh=d[i][j].h,nm=d[i][j].m;
				while(k<30){
					if(used[i][nh][nm])return false;
					used[i][nh][nm]=true;
					k++;
					nm++;
					if(nm==60){
						nm=0;
						nh++;
					}
				}
			}
		}
	}
	return true;
}
int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(dcnt,0,sizeof(dcnt));
		for(int i=0;i<n;i++){
			int w,s;
			string str;
			cin >> str >> w >> s;
			d[w][dcnt[w]]=data(str,s/100,s%100);
			dcnt[w]++;
		}
		fav.clear();
		scanf("%d",&p);
		for(int i=0;i<p;i++){
			string str;
			cin >> str;
			fav.insert(str);
		}
		memset(used,false,sizeof(used));
		if(!check()){
			printf("-1\n");
			continue;
		}
		int cnt=0;
		for(int i=0;i<7;i++){
			sort(d[i],d[i]+dcnt[i],comp);
			for(int j=0;j<dcnt[i];j++){
				if(fav.find(d[i][j].name)!=fav.end())continue;
				int k=0,nh=d[i][j].h,nm=d[i][j].m;
				while(k<30){
					if(used[i][nh][nm])break;
					k++;
					nm++;
					if(nm==60){
						nm=0;
						nh++;
					}
				}
				if(k==30){
					k=0,nh=d[i][j].h,nm=d[i][j].m;
					cnt++;
					while(k<30){
						if(used[i][nh][nm])return false;
						used[i][nh][nm]=true;
						k++;
						nm++;
						if(nm==60){
							nm=0;
							nh++;
						}
					}
				}
			}
		}
		printf("%d\n",cnt+p);
	}
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i,n)cin >> a[i];
   int ans = 1;
   int i = a[0];
   int cnt = 0;
   while(i != 2 && cnt < n){
      i = a[i-1];
      cnt++;
      ans++;
   }
   if(cnt >= n)cout << -1 << endl;
   else cout << ans << endl;
   return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    A[i] = x + y, B[i] = x - y;
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  cout << max(A.back() - A.front(), B.back() - B.front()) << '\n';
  return 0;
}


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

int main()
{
   int n;cin>>n;
  int h[n];
  for(int i=0;i<n;i++)
  cin>>h[i];
  vector<int>dp(n,INT_MAX);
  dp[0]=0;
  for(int i=0;i<n;i++)
  {
    if(i+1<n)
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
    if(i+2<n)
    dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    
}
 cout<<dp[n-1];
 return 0;

}

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

string tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

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

    rep(i, S.size()) {
        int num = S[i] - 'A';
        num += N;
        num %= tmp.size();
        char a = num + 'A';
        cout << a;
    }
    cout << endl;
}


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

int main() {
  int N; // 餅の枚数
  cin >> N;
  
  int mochimax = 100; // 餅のサイズのバリエーション
  
  // サイズごとの餅の有無を格納する配列
  vector<int> mochisize(mochimax + 1);
  
  // 標準入力から読み込み、餅サイズ有無を保存
  for (int i = 0; i < N; i++) {
    int cur_mochisize;
    cin >> cur_mochisize;
    mochisize.at(cur_mochisize) = mochisize.at(cur_mochisize) + 1;
//    cout << i << " " << mochisize.at(cur_mochisize) << endl;
  }
  
  // 餅サイズのサイズのバリエーションをカウント
  int mochicnt = 0;
  for (int i = 0; i < mochimax + 1 ; i++) {
    if (mochisize.at(i) > 0) {
      mochicnt++;
    }
  }
  
  // 餅サイズのバリエーションを出力
  cout << mochicnt << endl;
  
  return 0;
}

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

int main(){
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    char a=s1.at(s1.size()-1);
    char b=s2.at(0);
    char c=s2.at(s2.size()-1);
    char d=s3.at(0);
    if(a==b&&c==d){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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

using namespace std;

typedef long long ll;

int g[3][3];

int a[3];
int b[3];
void compute(int aa, int bb) {
	a[0] = aa;
	b[0] = bb;
	a[1] = g[1][0] - b[0];
	a[2] = g[2][0] - b[0];
	b[1] = g[0][1] - a[0];
	b[2] = g[0][2] - a[0];
}
bool verify() {
	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 3; j++) {
			if(a[i] + b[j] != g[i][j]) return false;
		}
	}
	return true;
}
int main() {
	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 3; j++) {
			scanf("%d", &g[i][j]);
		}
	}
	for(int a = -100; a <= 200; a++) {
		for(int b = -100; b <= 200; b++) {
			compute(a, b);
			if(verify()) {
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
}

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

int main() {
    int r, d, x; cin >> r >> d >> x;
    rep(i,10){
        x = r*x-d;
        cout << x << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second
#define pr priority_queue
#define ump  unordered_map
#define prg priority_queue<ll, vec<ll> ,greater<ll> >
#define pb  push_back;
//parent finding
ll find(vector<ll> &v, ll n)
{
  if (v[n] == n)
    return n;
  return v[n] = find(v, v[n]);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s; cin >> s;
  ll n = s.length(), sum = 0;
  for (ll i = 0; i < n; i++)
  {
    sum += (s[i] - '0');
  }
  if (sum % 9 == 0) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    ll n,m;
    scanf("%lld%lld",&n,&m);


    ll ans = 0;

    if(n*2>=m){
        ans = m/2;
    }else{
        ans += n;
        //n = 0;
        m -= n*2;
        ans += m/4;
    }
    
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
def dist(x1, y1, x2, y2)
  (x1 - x2).abs + (y1 - y2).abs
end

n = gets.to_i
table = n.times.map { gets.split.map(&:to_i) }
table.unshift([0, 0, 0])
if table.each_cons(2).all? { |(t1, x1, y1), (t2, x2, y2)|
     d = dist(x1, y1, x2, y2)
     dt = t2 - t1
     dt >= d && (dt - d).even?
   }
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 9724
n = int(input())

x = 1
for i in range(1, n+1):
    x *= i

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

import collections
c = collections.Counter(prime_factorize(x))
y = list(c.values())

z = 1
for j in range(len(y)):
    z *= (y[j]+1)

print(z % (10**9+7))

Measured memory_bytes: 3316
import Control.Monad (replicateM)

main = do
    n <- readLn
    if n == 0 then return () else do
        replicateM n readLn >>= return . solve >>= print
        main

solve :: [Int] -> Int
solve = maximum . scanl1 accumMax
    where
    accumMax a b = max (a+b) b

Measured memory_bytes: 5200
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)1e9+7)
#define MAX ((ull)1e9)

int main(){
	int n;
	cin >> n;
	int d1[n+1], d2[n+1], d3[n+1];
	d1[0]=0, d2[0]=0, d3[0]=0;
	for(int i=1; i<=n; i++){
		int a, b, c;
		cin >> a >> b >> c;
		d1[i]=a+max(d2[i-1], d3[i-1]);
		d2[i]=b+max(d1[i-1], d3[i-1]);
		d3[i]=c+max(d1[i-1], d2[i-1]);
	}
	cout << max(max(d1[n], d2[n]), d3[n]) << endl;
	return 0;
}

Measured memory_bytes: 1408