akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

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

		String keyBoard = sc.next();
		int inputSize = keyBoard.length();
		String output = "";

		for(int i = 0; i < inputSize; i++) {
			String word = keyBoard.substring(i, i+1);
			if (word.equals("0") || word.equals("1")) {
				output += word;
			} else {
				if (!"".equals(output)) {
					output = output.substring(0, output.length() - 1);
				}
			}
		}

		System.out.println(output);

		sc.close();
	}
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x, y; cin >> x >> y;
  ll mn = longinf;
  if(x <= y) mn = min(y-x, mn);
  if(-x <= y) mn = min(y+x+1, mn);
  if(x <= -y) mn = min(-y-x+1, mn);
  if(-x <= -y) mn = min(-y+x+2, mn);
  cout << mn << "\n";
  return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int x,i=0;
        
        
        int[] c=new int[10001];
        for(;;){
        	x=sc.nextInt();
        	c[i]=x;
        	i=i+1;
        	if(x==0)break;
        }
        
        
        
        
        
        for(int a=0;a<i-1;a++)
        	System.out.println("Case"+" "+(a+1)+":"+" "+c[a]);
        sc.close();
 }
    
    
}


Measured memory_bytes: 42856
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);++i)


int main() {
	string S;
	cin >> S;
	string T = { "AKIHABARA" };
	int j = 0;
	int i;
	int Anum = 0;
	for (i = 0;  j < T.length();) {
		if (i < S.length() && S[i] == T[j]) {
			j++;
			i++;
			continue;
		}
		if (T[j] == 'A') {
			j++;
			Anum++;
			continue;
		}
		else {
			cout << "NO";
			return 0;
		}
	}
	if (j == T.length() && S.length() + Anum == T.length()) {
		cout << "YES";
		return 0;
	}
	cout << "NO";
	return 0;
}

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

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

typedef pair<int,pair<int,pair<int,int> > > pp;

int main()
{
	int n,l,p,a,u;
	while(cin >> n && n)
	{
		int univ[1001] = {};
		map<pp,int> m;
		REP(n)
		{
			cin >> l >> u >> a >> p ;
			m[pp(-a,make_pair(p,make_pair(l,u)))] = l;
		}
		int y = 0;
		for(map<pp,int>::iterator it = m.begin();it!=m.end();++it)
		{
			int j = it->first.second.second.second;
			if(y<10&&univ[j]<3 || y<20&&univ[j]<2 || y<26&&univ[j]<1)
			{
				y++;univ[j]++;
				cout << it->second << endl;
			}

		}

	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,cnt=0,x,y;
double k;
signed main()
{
;;;;;
cin>>n>>k;
while (n--)
{
cin>>x>>y;
double dis=sqrt(x*x+y*y);
if (dis<=k) cnt++;
}
cout<<cnt<<endl;
return 0;
}



Measured memory_bytes: 3776
#include <iostream>
using namespace std;
const int N = 10000001;
long long tbl[N];
int main(){
  for(int i=1;i<=N;++i){
    for(int j=1;i*j<=N;++j){
      tbl[i*j]++;
    }
  }
  int n;
  cin >> n;
  long long ans = 0LL;
  for(long long i=1;i<=n;++i)
    ans+=i*tbl[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 81760
n=int(input())
a=input().split()
numbers=[b for b in a]
n=len(numbers)
if n%2==0:
    kisuu=numbers[1::2]
    guusuu=numbers[0::2]
    kisuu.reverse()
    kotae=kisuu+guusuu
else:
    kisuu=numbers[1::2]
    guusuu=numbers[0::2]
    guusuu.reverse()
    kotae=guusuu+kisuu
answer=''
for z in kotae:
    answer+=str(z)
    answer+=' '
print(answer)


Measured memory_bytes: 27972
n = int(input())
binary = []

if n == 0:
    print(0)
    exit()

while n != 0:
    if n % -2 != 0:
        binary.append('1')
        n //= -2
        n += 1
    else:
        binary.append('0')
        n //= -2
        
binary.reverse()

print(''.join(binary))

Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var ai = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(ai);
            var tmp = ai.Append(0).ToArray();
            var answer = 0;
            var count = 0;
            var x = 0;
            for (var i = 0; i < tmp.Length; i++)
            {
                if (tmp[i] == x)
                {
                    count++;
                }
                else
                {
                    if (count < x) answer += count;
                    else answer += count - x;
                    x = tmp[i];
                    count = 1;
                }
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 39720
import java.util.*;

public class Main {
	static int N;
	static long A, B;
	static long[] S;
	static long[][] dpA;
	static long[][] dpB;
	static BinaryIndexedTree bitA;
	static BinaryIndexedTree bitB;
	static final long MOD = 1_000_000_000 + 7;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = sc.nextLong();
		B = sc.nextLong();
		S = new long[N];
		bitA = new BinaryIndexedTree(N);
		bitB = new BinaryIndexedTree(N);
		Stack<Query> stackA = new Stack<>();
		Stack<Query> stackB = new Stack<>();
		for (int i = 0; i < N; ++i) {
			S[i] = sc.nextLong();
		}
		Arrays.sort(S);

		bitA.addVal(0 + 1, 1);
		bitB.addVal(0 + 1, 1);
		stackA.push(new Query(0 + 1, 1));
		stackB.push(new Query(0 + 1, 1));
		int leftA = -1;
		int leftB = -1;
		for (int i = 0; i + 1 < N; ++i) {
			long sA = 0;
			long sB = 0;
			while (S[i + 1] - S[leftA + 1] >= A)
				++leftA;
			while (S[i + 1] - S[leftB + 1] >= B)
				++leftB;
			sB = bitA.getVal((leftB + 1) + 1);
			sA = bitB.getVal((leftA + 1) + 1);
			if (S[i + 1] - S[i] < A) {
				while (!stackA.isEmpty()) {
					Query q = stackA.pop();
					bitA.addVal(q.pos, -q.val);
				}
			}
			if (S[i + 1] - S[i] < B) {
				while (!stackB.isEmpty()) {
					Query q = stackB.pop();
					bitB.addVal(q.pos, -q.val);
				}
			}
			bitA.addVal((i + 1) + 1, sA);
			bitB.addVal((i + 1) + 1, sB);
			stackA.add(new Query((i + 1) + 1, sA));
			stackB.add(new Query((i + 1) + 1, sB));
		}
		System.out.println((bitA.getVal(N) + bitB.getVal(N)) % MOD);
	}

	static class BinaryIndexedTree {
		int n;
		long[] val;

		public BinaryIndexedTree(int n) {
			this.n = n;
			val = new long[n + 1];
		}

		void addVal(int k, long v) {
			while (k <= n) {
				val[k] += v;
				val[k] = (val[k] + MOD) % MOD;
				k += k & -k;
			}
		}

		long getVal(int k) {
			long s = 0;
			while (k > 0) {
				s += val[k];
				s = (s + MOD) % MOD;
				k -= k & -k;
			}
			return s;
		}

		void clear() {
			val = new long[n + 1];
		}
	}

	static class Query {
		int pos;
		long val;

		public Query(int pos, long val) {
			this.pos = pos;
			this.val = val;
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 54436
class PrimeChecker:

    def __init__(self):
        self.primes = [2,3]

    def isPrime(self, n):
        if n in self.primes:
            return True
        else:
            for i in self.primes:
                if n % i == 0:
                    return False

        i = 5
        w = 2

        while i * i <= n:
            if n % i == 0:
                return False

            i += w
            w = 6 - w

        self.primes.append(n)

        return True

primeChecker = PrimeChecker()
count = 0
N = int(input())
for _ in range(N):
    if primeChecker.isPrime((int(input()))):
        count += 1
print(count)
        


Measured memory_bytes: 5612
n = int(input())
ans = [0]*n
for x in range(1,10**2):
    for y in range(1,10**2):
        for z in range(1,10**2):
            f = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if f <= n:
                ans[f-1] += 1
print("\n".join(str(i) for i in ans))


Measured memory_bytes: 68160
N, C = map(int, input().split())
accu = [[0]*(10**5+10) for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    accu[c-1][s] += 1
    accu[c-1][t+1] -= 1
for i in range(C):
    for j in range(1, 10**5+10):
        accu[i][j] += accu[i][j-1]
ans = 0
for i in range(10**5+10):
    tmp = 0
    for j in range(C):
        tmp += accu[j][i]>0
    ans = max(ans, tmp)
print(ans)

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

const int N = 110;

int a[N];

int main(){
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i){
        scanf("%d", &a[i]);
    }
    int pre = 0, ans = 0;
    for (int i = 0; i < n; ++ i){
        if (a[i] != a[i + 1]){
            ans += i - pre + 1 >> 1;
            pre = i + 1;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

int N,L,Q,X[100006],J[100006][17];

int main()
{
	scanf ("%d",&N);
	for (int i=0;i<N;i++) scanf ("%d",&X[i]);
	scanf ("%d %d",&L,&Q);

	for (int i=0;i<N-1;i++) J[i][0] = upper_bound(X,X+N,X[i]+L) - X - 1;
	J[N-1][0] = N;
	for (int j=0;j<17;j++) J[N][j] = N;
	for (int i=N-1;i>=0;i--){
		for (int j=1;j<17;j++) J[i][j] = J[J[i][j-1]][j-1];
	}

	while (Q--){
		int a,b; scanf ("%d %d",&a,&b); a--; b--;
		if (a > b) swap(a,b);
		int s = 0;
		for (int i=16;i>=0;i--){
			if (J[a][i] < b) a = J[a][i], s += (1 << i);
		}
		s++;
		printf ("%d\n",s);
	}

	return 0;
}

Measured memory_bytes: 7808
#include <stdio.h>
int main(void){
  char input[10] = {0};
  fgets(input, 10, stdin);
  for(int i = 0; i < 3; i++){
    if(input[i] == input[i + 1]){
    	printf("Bad\n");
      return 0;
    }
  }
  printf("Good\n");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define reg register
#define chkmin(a,b) ((b)<(a)?(a)=(b):0)
typedef long long ll;
using namespace std;
const int inf=1e9;
const int MN=2005;
int n,a[MN<<1],B[MN<<1][MN],W[MN<<1][MN],p[2][MN],f[MN][MN];
bool t[MN<<1];
char ch[5];
int main(){
	scanf("%d",&n);
	for(reg int i=1,x;i<=n*2;i++){
		scanf("%s%d",ch,a+i);
		t[i]=(ch[0]=='B');p[t[i]][a[i]]=i;
	}
	for(reg int i=1;i<=n*2;i++)
		for(reg int j=0;j<=n;j++)
			W[i][j]=W[i-1][j]+(!t[i-1]&&a[i-1]>j),
			B[i][j]=B[i-1][j]+(t[i-1]&&a[i-1]>j);
	for(reg int i=0;i<=n;i++)
		for(reg int j=0;j<=n;j++){
			if(!i&&!j)continue;f[i][j]=inf;
			if(i)chkmin(f[i][j],f[i-1][j]+W[p[0][i]][i-1]+B[p[0][i]][j]);
			if(j)chkmin(f[i][j],f[i][j-1]+W[p[1][j]][i]+B[p[1][j]][j-1]);
		}printf("%d\n",f[n][n]);
	return 0;
}

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

typedef long long ll;
void solve()
{
	int i,j,n,k;
	cin>>n>>k;
	vector <int> v(n);
	for(i=0;i<n;i++)
		cin>>v[i];
	vector <bool> dp(k+1,false);
	for(i=0;i<=k;i++)
	{
		for(j=0;j<n;j++)
		{
			if(i>=v[j] && dp[i-v[j]]==false)
				dp[i]=true;
		}
	}
	if(dp[k]==true)
		cout<<"First\n";
	else
		cout<<"Second\n";
}
int main()
{

	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N;
  cin >> N;
  
  vector<int> P(N);
  REP(i, N) cin >> P[i];

  int MIN = INF;
  int ans = 0;
  REP(i, N){
    if(MIN >= P[i]){
      ans++;
      MIN = P[i];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab.sort()
ans = 0

for i in range(n):
    if m == 0:
        break
    if m - ab[i][1] >= 0:
        ans += ab[i][0] * ab[i][1]
        m -= ab[i][1]
    else:
        ans += m * ab[i][0]
        break
print(ans)


Measured memory_bytes: 27756
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	string s; cin >> s;
	int n = s.size();
	for(int i = 0; i < n; ++i) {
		if(i % 2 == 0) {
			if(s[i] == 'L') {
				cout << "No" <<endl;
				return 0;
			}
		}
		if(i % 2 == 1) {
			if(s[i] == 'R') {
				cout << "No" <<endl;
				return 0;
			}
		}
	}
	cout << "Yes" <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define deb(x) cout << #x << "=" << x << endl;
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int main() {
    fastio
    ll n;
    cin>>n;
    vector<ll> vec(n);
    for(auto& it : vec) cin>>it;

    ll tot = accumulate(all(vec), 0ll)%mod;
    ll ans = 0;
    ll pref = 0;
    for(int i = 0; i<n; ++i) {
        pref += vec[i];
        pref %= mod;
        ll cur = (tot-pref+mod)%mod;
        ans += cur*vec[i];
        ans %= mod;
    }
    cout<<ans<<endl;
}

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

int main() {
    int X, A, B;
    std::cin >> X >> A >> B;

    if ((B - A) <= 0) {
        std::cout << "delicious\n";
    } else if ((B - A) > X) {
        std::cout << "dangerous\n";
    } else {
        std::cout << "safe\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

int n, k;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

void add(int &a, int b){
    a += b;
    if(a >= mod)
        a -= mod;
}

int a[maxn];
int dp[105][maxn];
int pre[105][maxn];

int main(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        scanf("%d", &a[i]);
    }
    dp[0][0] = 1;
    for(int i = 0;i <= k;i++){
        pre[0][i] = dp[0][i];
        if(i > 0)
            add(pre[0][i], pre[0][i - 1]);
    }
    for(int i = 1;i <= n;i++){
        for(int j = 0;j <= k;j++){
            int lb = max(0, j - a[i]);
            if(lb == 0){
                dp[i][j] = pre[i - 1][j];
            }else{
                dp[i][j] = (pre[i - 1][j] - pre[i - 1][lb - 1] + mod) % mod;
            }
            pre[i][j] = dp[i][j];
            if(j > 0)
                add(pre[i][j], pre[i][j - 1]);
        }
    }
    cout << dp[n][k] << endl;
    return 0;
}


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

class Dice{
public:
  int face[6];
  int top(){return face[0];}
  void setFace(int i, int num);
  void moveFloor(char dir);
};

void Dice::setFace(int i, int num){
  face[i] = num;
  return;
}

void Dice::moveFloor(char dir){
  int temp=face[5];
  if(dir == 'E'){
    face[5]=face[2]; face[2]=face[0];
    face[0]=face[3]; face[3]=temp;
  }else if(dir == 'N'){
    face[5]=face[4]; face[4]=face[0];
    face[0]=face[1]; face[1]=temp;
  }else if(dir == 'S'){
    face[5]=face[1]; face[1]=face[0];
    face[0]=face[4]; face[4]=temp;
  }else if(dir == 'W'){
    face[5]=face[3]; face[3]=face[0];
    face[0]=face[2]; face[2]=temp;
  }
}

int main(){
  int num;
  Dice d;
  for(int i=0; i<6; i++){
    cin >> num;
    d.setFace(i, num);
  }

  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++)
    d.moveFloor(s[i]);

  cout << d.top() << endl;
  return 0;
}



Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;

int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;

	string s;
	cin >> s;
	s.assign(s.size(), 'x');
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

int main(void){
  int a, b, c;
  vector<int> num(3);
  rep(i, 3) cin >> num[i];

  SORT(num);
  int cnt = 0;
  cnt += num[2] - num[1];
  num[0] += cnt;
  num[1] += cnt;
  int tmp = num[1] - num[0];
  if(tmp % 2 == 0) cnt += tmp / 2;
  else  cnt += tmp / 2 + 2;
  cout << cnt << endl;

  return 0;
}


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

const long long INF = 1e12;
const int MAX_V = 1000;
const int MAX_E = 2000;

long long d[MAX_V][MAX_V];
int V, E;

void warshall_floyd() {
	for (int k = 0; k < V; k++)
		for (int i = 0; i < V; i++)
			for (int j = 0; j < V; j++)
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
int main() {
	cin >> V >> E;
	for (int i = 0; i < MAX_V; i++) {
		for (int j = 0; j < MAX_V; j++) {
			if(i != j) d[i][j] = INF;
			else d[i][j] = 0;
		}
	}
	for (int i = 0; i < E; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		d[a][b] = c;
	}
	warshall_floyd();
	for (int i = 0; i < V; i++) {
		if (d[i][i] != 0) {
			cout << "NEGATIVE CYCLE" << endl;
			return 0;
		}
	}
	for (int i = 0; i < V; i++) {
		for (int j = 0; j < V; j++) {
			if (j) cout << " ";
			if (d[i][j] > 1e10) cout << "INF";
			else cout << d[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 10896
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n <= 111) {
        	System.out.println(111);
        } else if (n <= 222) {
        	System.out.println(222);
        } else if (n <= 333) {
        	System.out.println(333);
        } else if (n <= 444) {
        	System.out.println(444);
        } else if (n <= 555) {
        	System.out.println(555);
        } else if (n <= 666) {
        	System.out.println(666);
        } else if (n <= 777) {
        	System.out.println(777);
        } else if (n <= 888) {
        	System.out.println(888);
        } else {
        	System.out.println(999);
        }
    }
}

Measured memory_bytes: 21588
#include <iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

const int inf=1<<20;

bool dist[110][55][55];
int all[55],nall[55];

int main(void){
	int n,m,a,b,c;
	cin >> n >> m >> a >> b >> c;
	rep(i,m){
		int u,v;
		cin >> u >> v;
		dist[1][u-1][v-1]=true;
	}

	for(int d=2;d<=100;++d)rep(k,n)rep(i,n)rep(j,n) dist[d][i][j]|=(dist[d-1][i][k]&dist[1][k][j]);
	
	all[n-1]=7;
	
	int ans=-1;
	for(int turn=1;turn<=100;++turn){
		rep(i,n) nall[i]=all[i];
		rep(i,n)rep(j,n)if(all[j]==7&&dist[a][i][j]) nall[i]|=1;
		rep(i,n)rep(j,n)if(all[j]==7&&dist[b][i][j]) nall[i]|=2;
		rep(i,n)rep(j,n)if(all[j]==7&&dist[c][i][j]) nall[i]|=4;

		if(nall[0]==7){
			ans=turn;
			break;
		}
		rep(i,n) all[i]=nall[i];
	}

	if(ans==-1)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3420
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision

using namespace std;
using pint = pair<int,int>;
int main(){
    int  n ; cin >> n;
    int bit;
    int a,x,y;
    vector<vector<pint>> v;
    v.resize(n);
    for (int i = 0; i < n; i++) //全員の証言を聞く
    {
        cin >> a;
        v[i].resize(a);
        for (int j = 0; j < a; j++) //iのaコの証言
        {
            cin >> v[i][j].first >> v[i][j].second;
        }
    }

    int count ;
    int max=0;
    int nflag;
    for ( bit = 0; bit < (1<<n); bit++) //（bit全探索）決め打ちと証言間の整合性のチェック
    {
        count =0;
        nflag =0;
        for (int i = 0; i < n; i++)
        {   
            if(bit&(1<<i)){ //選んだ人の話だけ聞く      
                for(auto xy : v[i]){
                    int x = xy.first-1;
                    int y = xy.second;
                    if(y==1 && !(bit&(1<<x))) {
                        nflag++;
                        break;
                    }
                    if(y==0 && bit&(1<<x)) {
                        nflag++;
                        break;
                    }
                }
                if(nflag) break;   //整合性が取れなかったので次の決め打ちへ
                count++;     
            }
        }
        if(!nflag && count > max) max = count;
    }

    cout << max << endl;


    return 0;
}

Measured memory_bytes: 3164
#include <iostream>

using namespace std;

long long csum[2010][2010] = {0};
long long dp[2010][2010] = {0};
long denom = 1000000007;
int main() {
  int S[2001] = {0}, T[2001] = {0};
  int N, M;
  int _i, _j, i, j;
  cin >> N >> M;
  for (i = 1; i < N + 1; i ++) cin >> S[i];
  for (i = 1; i < M + 1; i ++) cin >> T[i];
  dp[0][0] = 1;

  for (i = 0; i < N + 1; i ++) csum[i][0] = 1;
  for (i = 0; i < M + 1; i ++) csum[0][i] = 1;

  for (i = 1; i < N + 1; i ++) {
    _i = i - 1;
    for (j = 1; j < M + 1; j ++) {
      _j = j - 1;
      if (S[i] == T[j]) {
        dp[i][j] = csum[_i][_j];
      }
      csum[i][j] = -csum[_i][_j];
      csum[i][j] = (csum[i][j] + csum[_i][j]) % denom;
      csum[i][j] = (csum[i][j] + csum[i][_j]) % denom;
      csum[i][j] = (csum[i][j] + dp[i][j]) % denom;
      if (csum[i][j] < 0) {
        csum[i][j] += denom;
      }
    }
  }
  cout << (csum[N][M]) % denom<< endl;;

  return 0;
}


Measured memory_bytes: 63104
from collections import deque
N,M=map(int,input().split())
adjacent=[set() for x in range(N)]
for m in range(M):
    A,B=map(int,input().split())
    adjacent[A-1].add(B-1)
    adjacent[B-1].add(A-1)
ans=[0]*N
deque1=deque()
already=set()
already.add(0)
num_already=1
for j in adjacent[0]:
    deque1.append(j)
    already.add(j)
    num_already+=1
    ans[j]=1
while(num_already!=N):
    now=deque1.popleft()
    for k in adjacent[now]:
        if k not in already:
            num_already+=1
            already.add(k)
            ans[k]=now+1
            deque1.append(k)
print("Yes")
for i in range(1,N):
    print(ans[i])

Measured memory_bytes: 71420
import java.io.FileNotFoundException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

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

	void run() throws FileNotFoundException {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] a = new char[H][W];
		for (int i = 0; i < H; ++i) {
			a[i] = sc.next().toCharArray();
		}
		int o = Math.max(H, W);
		MF mf = new MF(2 * o + 3);
		int s = 2 * o + 1;
		int t = 2 * o + 2;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				if (a[i][j] == 'S') {
					mf.ae(s, i, 999999);
					mf.ae(s, o + j, 999999);
				} else if (a[i][j] == 'T') {
					mf.ae(i, t, 999999);
					mf.ae(o + j, t, 999999);
				} else if (a[i][j] == 'o') {
					mf.ae(i, o + j, 1);
					mf.ae(o + j, i, 1);
				}
			}
		}
		int tot = mf.solve(s, t);
		if (tot >= 999999) {
			System.out.println(-1);
		} else {
			System.out.println(tot);
		}
	}

	class MF {
		int n;
		int[][] cap;
		int[][] flow;
		ArrayList<Integer>[] g;

		public MF(int n) {
			this.n = n;
			cap = new int[n][n];
			flow = new int[n][n];
			g = new ArrayList[n];
			for (int i = 0; i < n; ++i) {
				g[i] = new ArrayList<>();
			}
		}

		void ae(int a, int b, int w) {
			cap[a][b] = w;
			g[a].add(b);
		}

		int solve(int s, int t) {
			int tot = 0;
			int[] pre = new int[n];
			while (true) {
				Arrays.fill(pre, -1);
				ArrayDeque<Integer> que = new ArrayDeque<>();
				que.add(s);
				out: while (!que.isEmpty()) {
					int v = que.poll();
					for (int i = 0; i < n; ++i) {
						if (cap[v][i] - flow[v][i] > 0 && pre[i] == -1 && i != s) {
							pre[i] = v;
							que.add(i);
							if (i == t) {
								break out;
							}
						}
					}
				}
				if (pre[t] == -1)
					break;
				int inc = Integer.MAX_VALUE / 16;
				for (int i = t; pre[i] != -1; i = pre[i]) {
					inc = Math.min(inc, cap[pre[i]][i] - flow[pre[i]][i]);
				}
				for (int i = t; pre[i] != -1; i = pre[i]) {
					flow[pre[i]][i] += inc;
					flow[i][pre[i]] -= inc;
				}
				tot += inc;
			}
			return tot;
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 25364
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
rem = a[0]
for i in range(n):
    ans += min(rem+a[i+1], b[i])
    if rem-b[i]<0:
        rem = max(rem+a[i+1]-b[i], 0)
    else:
        rem = a[i+1]
print(ans)

Measured memory_bytes: 18624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll s, t, d;
    cin >> s >> t >> d;
    vector<ll> w(d);
    ll sum = 0;
    ll mn = 1LL << 60;
    s -= t;
    REP(i, 0, d) {
        cin >> w[i];
        sum += w[i];
        mn = min(mn, sum);
        if (s + sum <= 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    if (sum >= 0) {
        cout << -1 << endl;
        return 0;
    }

    dump(mn);
    dump(sum);
    ll ans = max((s + mn - sum) / (-sum), 0LL);
    dump(ans);
    s += sum * ans;
    ans *= d;
    if (s <= 0) {
        cout << ans << endl;
        return 0;
    }
    dump(s);
    REP (i, 0, d) {
        s += w[i];
        if (s <= 0) {
            cout << ans + i + 1 << endl;
            return 0;
        }
    }
    dump(s);
    return 0;
}



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


int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin>>s;
	string s1 = "", s2 = "";
	int a1 = 0, a2 = 0;
	for(int i = 0;i<s.length();i++){
		s1 += char((i%2) +'0');
		s2 += char((i+1)%2 + '0');
	}
	for(int i =0;i<s.length();i++){
		if(s1[i] == s[i])
			a2++;
		else
			a1++;
	}
	cout<<min(a1,a2);
	return 0;
}

Measured memory_bytes: 720
n=int(input())
s=list(input())
count=0

for i in range(1000):
    if len(str(i))==1:
        i=str(0)+str(0)+str(i)
    elif len(str(i))==2:
        i=str(0)+str(i)
    else:
        i=str(i)
    x=0
    for j in range(n):
        if s[j]==i[x]:
            x+=1
            if x==3:
                count+=1
                break
print(count)
            



Measured memory_bytes: 42732
N = int(input())
dpa = 0
dpb = 0
dpc = 0
for i in range(N):
  a, b, c = map(int, input().split())
  xa = dpb + a
  ya = dpc + a
  xb = dpc + b
  yb = dpa + b
  xc = dpa + c
  yc = dpb + c
  dpa = xa if xa >= ya else ya
  dpb = xb if xb >= yb else yb
  dpc = xc if xc >= yc else yc
print(max(dpa, dpb, dpc))

Measured memory_bytes: 3188
from itertools import product

def solve(NUM, LIST):
    lst = [l[i] for i, t in enumerate(LIST) if t == NUM]
    if len(lst) == 0:
        return 10 ** 5
    ANS = (len(lst) - 1) * 10
    ANS += abs(sum(lst) - tgt[NUM])
    return ANS

tgt = list(map(int, input().split()))
l = [int(input()) for _ in range(tgt[0])]

ans = 10 ** 5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
    tmp = sum(solve(i + 1, pttn) for i in range(3))
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 78016
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  ll ans = llINF;
  for(auto &a:A)cin>>a;
  for(ll i=-111;i<111;i++){
    ll sum = 0;
    for(auto a:A){
      sum += (a-i)*(a-i);
    }
    ans = min(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

unordered_map<int, int> factorization(int n) {
    unordered_map<int, int> factors;
    for (int p=2; p <= n; p++) {
        while(n % p == 0) {
            factors[p]++;
            n /= p;
        }
    }
    return factors;
}
bool is_prime(int n) {
    if (n<2) return false;
    for (int i=2;i*i<=n;i++) {
        if (n%i == 0) return false;
    }
    return true;
}

int n;
int factors[101];
int ans;
signed main() {
    cin >> n;
    unordered_map<int, int> di;
    for (int i=1;i<=n;i++) {
        di = factorization(i);
        for (int j=0;j<n;j++) {
            factors[j] += di[j];
        }
    }
    for (int i=2;i<n;i++) {
        if (!is_prime(i)) continue;
        if (factors[i]>=74) ans++;
        for (int j=2;j<i;j++) {
            if (!is_prime(j)) continue;
            if (factors[i]>=24 && factors[j]>=2) ans++;
            if (factors[i]>=2 && factors[j]>=24) ans++;
            if (factors[i]>=14 && factors[j]>=4) ans++;
            if (factors[i]>=4 && factors[j]>=14) ans++;
            for (int k=0;k<j;k++) {
                if (!is_prime(k)) continue;
                if (factors[i]>=4 && factors[j]>=4 && factors[k]>=2) ans++;
                if (factors[i]>=4 && factors[j]>=2 && factors[k]>=4) ans++;
                if (factors[i]>=2 && factors[j]>=4 && factors[k]>=4) ans++;
            }
        }
    }

    cout << ans << endl;
}

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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    int H, W;
    cin >> H >> W;
    vector <string> s(H);
    for (int i = 0; i <H; ++i) {
        cin >> s[i];
    }
    for (int i = 0; i <H; ++i) {
        cout << s[i] << endl;
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    string S;
    cin>>S;
    int ans=0;
    rep(i,6){
        if(S[i]=='1'){
            ans++;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	string s;
	cin >> s;
	if (s[s.size() - 1] == 's') {
		s += "es";
	}
	else {
		s += 's';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
main(){
 int a,b,c,n,t[10001]={0},p=0,i,j;
 for(cin>>n>>a>>b,i=0;n--;)
  for(cin>>c,j=c-a;j<=c+a-1&&j<b;)if(!(t[j++]++))p--;
 cout<<b+p<<endl;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i=2; i<n+1; i++){
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 24028
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


DIV=10**9+7

#N,A,B,C = ints_raw()
ESP_C = "$"
S=input()

def main():
    nS = S.replace("BC",ESP_C)
    ans =0
    a_buf =0
    for idx,c in enumerate(nS):
        if c == "A":
            a_buf+=1
        elif c == ESP_C:
            ans+=a_buf
        else:
            a_buf =0
    return ans

print(main())


Measured memory_bytes: 42312
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100010
#define M 400010
#define ll long long
using namespace std;
struct edge{int x, y, next;}a[M];
int n, m, p[N], l, x, y, flag[N], sn, ff, s1, s2, s3, size1, size2, size3, def[N];
ll ans;
inline void add(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=p[x]; p[x]=l;}
inline void dfs(int x, int fa){
	flag[x]=1; sn++;
	for(int i=p[x]; i; i=a[i].next)if(i!=(fa^1)){
		if(!flag[a[i].y]){def[a[i].y]=def[x]+1; dfs(a[i].y, i);}
		else if(!((def[x]-def[a[i].y])&1))ff=0;
	}
}
int main(){
	scanf("%d%d", &n, &m);
	l=1; memset(p, 0, sizeof(p));
	for(int i=1; i<=m; i++){scanf("%d%d", &x, &y); add(x, y); add(y, x);}
	memset(flag, 0, sizeof(flag));
	for(int i=1; i<=n; i++)if(!flag[i]){
		sn=0; ff=1; def[i]=1; dfs(i, 0);
		if(sn==1){s1++; size1+=sn;}
		else if(ff){s2++; size2+=sn;}
		else{s3++; size3+=sn;}
	}
	ans=(ll)s1*s1+(ll)2*s2*s2+(ll)s3*s3+(ll)2*s1*size2+(ll)2*s1*size3+(ll)2*s2*s3;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = tuple<ll,ll,int>;

int main(){
    int n,k; cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(ALL(p));
    int ans = 0;
    rep(i,k) ans += p[i];
    cout << ans << endl;
}

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

int sort(int a[],int n){
  
  int v;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j>0;j--){
      while(a[j]>a[j-1]){
        v=a[j];
        a[j]=a[j-1];
        a[j-1] = v;
      }
    }
  }
  return 0;
}

int main(){
  int n,a,b;
  a=0;
  b=0;
  cin>>n;
  int vec[n];
  
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  
 sort(vec,n);
  
  for(int i=0;i<n;i++){
    if(i%2==0) a += vec[i];
    else b += vec[i];
  }
  
  cout<<a-b<<endl;
  return 0;
}

 

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

using namespace std;

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a.back() == b.front() && b.back() == c.front()) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}


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

int main() 
{
	int N;

	cin >> N;

	switch (N % 10) {
	case 0:	cout << "pon\n";	break;
	case 1:	cout << "pon\n";	break;
	case 2:	cout << "hon\n";	break;
	case 3:	cout << "bon\n";	break;
	case 4:	cout << "hon\n";	break;
	case 5:	cout << "hon\n";	break;
	case 6:	cout << "pon\n";	break;
	case 7:	cout << "hon\n";	break;
	case 8:	cout << "pon\n";	break;
	case 9:	cout << "hon\n";	break;
	}

	return 0;
}

Measured memory_bytes: 3624
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class SegmentTree():
    '''
    RMQ　の実装
    '''

    def __init__(self, n, inf=float('inf')):
        '''
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(n-1).bit_length()
        self.inf = inf
        self.data = [inf]*(2*self.n)

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n-1] = v

    def build(self):
        for k in reversed(range(self.n-1)):
            self.data[k] = gcd(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = gcd(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のminを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.inf
        while L < R:
            if R & 1:
                R -= 1
                ret = gcd(ret, self.data[R-1])
            if L & 1:
                ret = gcd(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


N = int(input())
L = list(map(int, input().split()))
T = SegmentTree(N, 0)
# for i, l in enumerate(L):
#    T.set(i, l)
# T.build()
for i, l in enumerate(L):
    T.update(i, l)

ans = 0
for i in range(N):
    l = i
    r = i+1
    ans = max(ans, gcd(T.query(0, l), T.query(r, N)))
print(ans)


Measured memory_bytes: 62828
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const A = arg[0].split("");
    const B = arg[1].split("");
    
    const length = A.length;
    let answer   = [];
    
    for(let i=0; i<length; i++) {
        answer.push(A[i]);
        
        if(B[i]) {
            answer.push(B[i]);
        }
    }
    
    console.log(answer.join(""));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <list>
#include <cstdio>

int main()
{
	int n, v;

	char c[12];

	std::list<int> l;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%s", c);

		if (c[0] == 'i')
		{
			scanf("%d", &v);

			l.push_front(v);
		}
		else if (c[6] == 'F')
		{
			l.pop_front();
		}
		else if (c[6] == 'L')
		{
			l.pop_back();
		}
		else
		{
			scanf("%d", &v);

			std::list<int>::iterator it = l.begin();

			while (it != l.end())
			{
				if (*it == v)
				{
					l.erase(it); break;
				}

				it++;
			}
		}
	}

	std::list<int>::iterator it = l.begin();

	while (it != l.end())
	{
		if (it == l.begin())
		{
			printf("%d", *it);
		}
		else
		{
			printf(" %d", *it);
		}

		it++;
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 33928
#include <bits/stdc++.h>
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long int
    #define ld long double
    #define f(a, b) for (ll i = a; i < b; i++)
    #define in(a, b) (b.find(a) != string::npos)
    #define X first
    #define Y second
    #define vi vector<int>
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define el "\n"
    const ll M = 1e9 + 7;
    using namespace std;

    int main() {
    fio;
    int n;cin>>n;
    int a[n]={0};
    int b[n]={0};
    for(int i=0;i<n;i++)cin>>a[i];
    b[0]=a[0];
    for(int i=1;i<n;i++)b[i]=max(b[i-1],a[i]);
    int cnt=0;
    for(int i=0;i<n;i++){
        if(b[i]==a[i])cnt++;
    }
    cout<<cnt<<el;
    return 0;
    }


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<set>
#include<map>

#define MAX 512
using namespace std;

struct State{
  int now;
  int depth;
  State(int n,int d):now(n),depth(d){}
};

int main()
{
  while(true){
    int ans = 0;
    int n,m;
    bool vis[MAX]={false,};
    map<int,set<int> > adj;
    scanf("%d%d", &n, &m);
    if(n==0&&m==0)break;
    for(int i = 0; i < m; ++i){
      int a,b;scanf("%d%d",&a,&b);
      adj[a].insert(b);
      adj[b].insert(a);
    }
    
    queue<State> qs;
    qs.push( State(1,0) );
    vis[1]=true;
    while(!qs.empty()){
      State ns=qs.front();
      qs.pop();
      for(set<int>::iterator its=adj[ns.now].begin();
	  its!=adj[ns.now].end();++its){
	if(ns.depth<=1&&!vis[*its]){
	  vis[*its]=true;
	  qs.push( State( *its, ns.depth+1 ) );
	  ++ans;
	}
      }
    }
    
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import math
N = int(input())
ls = []
for i in range(N):
    ls.append(list(map(int,input().split())))

T = 1
A = 1
for i in range(N):
    bai = max(-(-T//ls[i][0]),-(-A//ls[i][1]))
    T = bai * ls[i][0]
    A = bai * ls[i][1]
print(T+A)

Measured memory_bytes: 9200
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        if (k > (n - 1) * (n - 2) / 2) {
            System.out.println(-1);
            return;
        }
        StringBuilder sb = new StringBuilder();
        int count = 0;
        for (int i = 2; i <= n; i++) {
            sb.append(1).append(" ").append(i).append("\n");
            count++;
        }
        int total = (n - 1) * (n - 2) / 2;
        for (int i = 2; i <= n && total > k; i++) {
            for (int j = i + 1; j <= n && total > k; j++) {
                sb.append(i).append(" ").append(j).append("\n");
                count++;
                total--;
            }
        }
        System.out.println(count);
        System.out.print(sb);
    }
}

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

const int ac = 1e6 + 10;
ll A[ac];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll a, b; cin >> a >> b;
	cout << a + (b - a) * 2 << '\n';
}


Measured memory_bytes: 256
h,w = map(int,input().split())
s=[[x for x in input()] for i in range(h)]
for i in range(h):
	for j in range(w):
		if s[i][j]=='.':
			count=0
			for di in range(-1,2):
				for dj in range(-1,2):
					if not(0<=i+di<h and 0<=j+dj<w): pass
					elif s[i+di][j+dj]=="#":
						count += 1
			s[i][j]=str(count)
	print(''.join(s[i]))

Measured memory_bytes: 3188
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

ll dp[90];

int main() {
  dp[0] = 2;
  dp[1] = 1;
  int n;
  scanf("%d", &n);
  for(int i = 2; i <= n; i++) {
    dp[i] = dp[i-1] + dp[i-2];
  }
  printf("%lld\n", dp[n]);
}


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

int main(){
  	int X, num, calc, cnt=0;
  	cin >> X;
  	num = X/100;
  	calc = X%100;
	while(calc>=5&&num>cnt){
    	calc-=5;
      	cnt++;
    }
  	while(calc>=4&&num>cnt){
    	calc-=4;
      	cnt++;
    }
  	while(calc>=3&&num>cnt){
    	calc-=3;
      	cnt++;
    }
  	while(calc>=2&&num>cnt){
    	calc-=2;
      	cnt++;
    }
  	while(calc>=1&&num>cnt){
    	calc-=1;
      	cnt++;
    }
  	while(calc==0&&num>cnt){
    	calc-=0;
      	cnt++;
    }
  	if(calc==0 && cnt==num){
    	cout << 1 << endl;
    }else{
    	cout << 0 << endl;
    }
	return 0;
}

Measured memory_bytes: 256
module Main where

    import Debug.Trace
    import Text.Printf

    solve :: Double -> String
    solve r = (a ++ " " ++ c) where
        a = printf "%.6f" ((pi * r * r)::Double)
        c = printf "%.6f" ((fromIntegral 2 * pi * r)::Double)

    readLine:: IO [Double]
    readLine = fmap (map read . words) getLine
    
    main :: IO() 
    main = do
        [r]    <- readLine
        let ans = solve r
        putStrLn ans
    


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

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

int main() {
    string s; cin >> s;
    int n = s.size();
    int ans = 0;
    for(int i = 1; i < n / 2; i++){
        if(s.substr(0, i) == s.substr(i, i)){
            ans = max(ans, i * 2);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256