akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Numerics;

class Program
{
    const int MOD = 1000000007;
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    void Solve()
    {
        Scanner cin = new Scanner();
        int n = cin.NextInt();

        List<Tuple<int, int>> tasks = new List<Tuple<int, int>>();

        for (int i = 0; i < n; i++)
        {
            int a = cin.NextInt();
            int b = cin.NextInt();
            tasks.Add(Tuple.Create(a, b));
        }

        var sorted = tasks.OrderBy(e => e.Item2);
        long elapsedTime = 0;
        bool isSucceeded = true;
        foreach(var task in sorted)
        {
            elapsedTime += task.Item1;
            if (elapsedTime > task.Item2)
            {
                isSucceeded = false;
                break;
            }
        }

        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        if (isSucceeded)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }

        Console.Out.Flush();
        
    }
}


class Scanner
{
    string[] s;
    int i;

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

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

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public char[] ArrayChar()
    {
        return Next().ToCharArray();
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 30892
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]

ren=[[] for _ in range(N)]
for a,b in AB:
  ren[a-1].append(b)
  ren[b-1].append(a)

def dfs(p):
  seen.append(p)
  for i in ren[p-1]:
    if i not in seen:
      dfs(i)

ans=0
for a,b in AB:
  seen=[]
  ren[a-1].remove(b)
  ren[b-1].remove(a)
  dfs(a)
  ren[a-1].append(b)
  ren[b-1].append(a)
  if len(seen)<N:
    ans+=1
print(ans)

Measured memory_bytes: 3064
#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;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// A : 解毒剤入りの美味しくないクッキー
	// B : 解毒剤入りの美味しいクッキー
	// C : 毒入りクッキー

	ll A, B, C; cin >> A >> B >> C;
	ll res = 0LL;

	if (A + B >= C){
		res = B + C;
	}else{ // if (A + B < C)
		ll remain = C - (A + B);
		res = B + C - remain + (ll)(remain != 0LL);
	} // end if

	cout << res << endl;

	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<ll> a(N);
	vector<ll> b(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i] >> b[i];
	}

	ll res = 0;
	for (int i = N - 1; i >= 0; --i) {
		if ((a[i] + res) % b[i] == 0) { continue; }

		ll x = b[i] - (a[i] + res) % b[i];
		res += x;
	}

	cout << res << endl;

	return 0;
}


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

int main(int argc, void **arg)
{
    char s[100000+1];
    int count = 0;

    scanf("%s", s);

    for (int i = 1; s[i] != '\0'; i++)
    {
        if( s[i-1] == s[i] )
        {
            s[i] = s[i] == '0' ? '1' : '0';
            count++;
        }
    }

    printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  long h, n;
  cin >> h >> n;
  long asum = 0;
  long tmp = 0;
  for(long i=0; i<n; i++){
    cin >> tmp;
    asum += tmp;
  }
  
  if(asum>=h){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#n = int(input()) #入力
#a, b = (int(x) for x in input().split())
#a, b = map(int, input().split())

#a = [int(x) for x in input().split()]
#a = list(map(int, input().split()))
#a = [list(map(int,input().split(" "))) for i in range(N)]   #2次元


#a.sort() # C++ の sort(a.begin(), a.end());
#a.append(3) # C++ の a.push_back(3);


#exit(0) # return 0 的な。終了できる。
## 整数の切り捨て除算は // (ダブルスラッシュ)


#a[始まりの位置: 終わりの位置: スライスの増分] # (a は配列)


import numpy as np
import math
import copy
import string
#math.gcd(a, b) で、gcd 計算できる。
#math.pi は円周率。

INF = 10**18 #べき乗 C++ の pow(10, 18) or 1e18;
pi = math.pi

MOD = 1000000007
#MOD = 1000000009
#MOD = 998244353




#繰り返し2乗法
#N^aの、Mで割った余りを求める。
def my_pow(N, a, M):
    if(a == 0):
        return 1
    else:
        if(a % 2 == 0):
            tempo = my_pow(N, a/2, M)
            return (tempo * tempo) % M
        else:
            tempo = my_pow(N, a - 1, M)
            return (tempo * N) % M




#N_C_a を M で割った余り
def my_combination(N, a, M):
    res = 1

    for i in range(0, a):
        res *= N - i
        res %= M

    for i in range(0, a):
        res *= my_pow(i + 1, M - 2, M)
        res %= M

    return res




#N_C_i を M で割った余りを、v[i] に代入する。
def my_combination_table(N, M, v):
    if(len(v) < N + 1):
        l = N + 1 - len(v)
        tempo = [1] * l
        v.extend(tempo)

    for i in range(1, N + 1):
        v[i] = v[i - 1] * (N - (i - 1))
        v[i] %= M

        v[i] *= my_pow(i, M - 2, M)
        v[i] %= M

    return




#math.factorial で階乗は計算できる。
#math.gcd で gcd は計算できる。
#np.gcd.reduce(A) #(Aは配列) で、Aの全ての要素の gcd が計算できる。



a, b, c, d = (int(x) for x in input().split())
res = int(b * d)
res = max(res, a * c)
res = max(res, a * d)
res = max(res, b * c)

if(a <= 0 and 0 <= b):
    res = max(res, 0)
if(c <= 0 and 0 <= d):
    res = max(res, 0)


print(res)








Measured memory_bytes: 27184
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

int main(void){
  fast_io
  int h,a;cin>>h>>a;
  int ans = 0;
  while(h > 0){
    h -= a;ans++;
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 256
function main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var values = input[1].split(" ").map(function(v) { return parseInt(v); });
  insertionSort(values);
}
 
function insertionSort(a) {
  for (var i = 0; i < a.length; i++) {
    for (var j = i-1; j >= 0; j--) {
      if (a[j+1] < a[j]) {
        var v  = a[j];
        a[j]   = a[j+1];
        a[j+1] = v;
      }
    }
    console.log(a.join(' '));
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 16668
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <tuple>
#include <set>

constexpr int MAX = 2*1e5+10;

using P = std::tuple<int, int, int>;
using Q = std::pair<int, int>;

int n,q;

std::vector<P> tm;
std::set<Q> cand;

int dis[MAX];

int ans[MAX];


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

	int n,q;

	std::cin>>n>>q;

	for(int i=0;i<n;++i){
		int s,t,x;
		std::cin>>s>>t>>x;
		tm.emplace_back(s-x,0,i);
		tm.emplace_back(t-x,1,i);
		dis[i]=x;
	}

	for(int i=0;i<q;++i){
		int d;
		std::cin>>d;
		tm.emplace_back(d,2,i);
	}

	std::sort(std::begin(tm),std::end(tm));

	for(auto&& p : tm){
		int type, index;
		std::tie(std::ignore, type, index) = p;
		if(type == 0)
			cand.emplace(dis[index],index);
		else if(type == 1)
			cand.erase(Q(dis[index],index));
		else if(!cand.empty())
			ans[index]=cand.begin()->first;
		else
			ans[index]=-1;
		/*std::cerr<<"DEBUG "<<type<<' '<<index<<std::endl;
		for(Q x : cand)
			std::cerr<<x.second<<' ';
		std::cerr<<std::endl;*/
	}

	for(int i=0;i<q;++i)
		std::cout<<ans[i]<<std::endl;
	return 0;
}



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

int main(){
	long long l, r, dif;
	long long nmin;
	cin >> l >> r;
	dif = r-l;
	if(dif >= 2018){
		cout << 0 << endl;
		return 0;
	}

	nmin = 2018;
	for(long long i=l; i<r; i++){
		for(long long j=i+1; j<=r; j++){
			nmin = min(nmin, (i*j)%2019);
		}
	}
	cout << nmin << endl;
	return 0;
}

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

ll dp[101][100001];

int main(){
    int n, w;
    cin >> n >> w;
    vector<ll> wt(n+1) , v(n+1);
    for(int i = 1; i <= n; i++)
        cin >> wt[i] >> v[i];
    
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= w; j++){
            if(wt[i] <= j)
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-wt[i]] + v[i]);
            else  dp[i][j]=dp[i-1][j];
        }
    }
    cout << dp[n][w];
}


Measured memory_bytes: 81712
using System;
using System.Linq;

namespace Structured_Program_I
{
    class Print_a_Chessboard
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var token = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var H = token[0];
                var W = token[1];

                if (H == 0 && W == 0) break;

                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        if ((i+j)%2 == 0) Console.Write("#");
                        else Console.Write(".");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9428
N = int(input())
S = [input() for _ in range(N)]
AC=0
WA=0
TLE=0
RE=0
for i in range(N):
    if S[i]=="AC":
        AC=AC+1
    if S[i]=="WA":
        WA=WA+1
    if S[i]=="TLE":
        TLE=TLE+1
    if S[i]=="RE":
        RE=RE+1
print("AC x",AC)
print("WA x",WA)
print("TLE x",TLE)
print("RE x",RE)

Measured memory_bytes: 16288
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin>>k;
  int l;
  if(k%7==0)l=9*k/7;
  else l=9*k;
  int ans=1;
  int te=10;
  if(k%2==0||k%5==0)cout<<"-1"<<endl;
  else if(k==7||k==1)cout<<1<<endl;
  else{
    while(ans>0){
      if(te%l==1){
        cout<<ans<<endl;
        break;
      }else{
        ans++;
        te=(te%l)*10;
      }
      
    }
  }
}
      
    

Measured memory_bytes: 3616
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY


N,K=get_i
X=get_i
ans=INF
tail=K-1
(N-K+1).times do|head|
    if X[head]<0 and X[tail]>0
        ans=min(ans,X[head].abs+X[tail]+min(X[head].abs,X[tail].abs))
    else
      ans=min(ans,max(X[head].abs,X[tail].abs))
    end
    tail+=1
end
puts ans


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,x; cin>>n>>x;
	vector<int>v(n);
	int64_t ans=0;
	for(auto&i:v)cin>>i;
	for(int i=1;i<n;++i){
		int mx=max(0,v.at(i-1)+v.at(i)-x);
		v.at(i)=max(0,v.at(i)-mx);
		ans+=mx;
	}
	cout<<ans<<"\n"s;
}

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

using ll = long long;
using VI = vector<ll>;
using VVI = vector<VI>;
using P = pair<ll, ll>;

int main() {
  ll a;
  double bf;
  string bs;

  cin >> a >> bs;
  ll b = (bs[0] - '0') * 100 + (bs[2] - '0') * 10 + (bs[3]) - '0';
  a = a * b;

  a = a / 100LL;

  cout << a << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int h,w;
	std::cin >> h >> w;
	std::vector<std::string> g(h);
	rep(i,h) std::cin >> g[i];
	// the min amount of times it switches to black
	const int INF=1e9;
	std::vector<std::vector<int> > dp(h,std::vector<int>(w,INF));
	dp[0][0]=(g[0][0]=='#');
	rep(i,h) {
		rep(j,w) {
			if(i+1<h) {
				int x=(g[i][j]=='.' && g[i+1][j]=='#');
				dp[i+1][j]=std::min(dp[i+1][j],dp[i][j]+x);
			}
			if(j+1<w) {
				int y=(g[i][j]=='.' && g[i][j+1]=='#');
				dp[i][j+1]=std::min(dp[i][j+1],dp[i][j]+y);
			}
		}
	}
	print(dp[h-1][w-1]);
	return 0;
}


Measured memory_bytes: 892
n,k = map(int,input().split())
h = []

for i in range(n):
    h.append(int(input()))

h.sort()

ans = 1000000000

for j in range(n-k+1):
    s = h[j+k-1] - h[j]
    if s < ans:
        ans = s

print(ans)

Measured memory_bytes: 13396
import sys
e=[list(map(int,e.split()))for e in sys.stdin]
n=e[0][0]+1
t=''
for c in e[1:n]:
 for l in zip(*e[n:]):t+=f'{sum(s*t for s,t in zip(c,l))} '
 t=t[:-1]+'\n'
print(t[:-1])


Measured memory_bytes: 6792
import math

N, D = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
cnt = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        total = 0
        for (y, z) in zip(x[i], x[j]):
            total += abs(y - z) ** 2
        dist = math.sqrt(total)
        if dist.is_integer():
            cnt += 1

print(cnt)

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

using namespace std;
typedef long long ll;

int main()
{
    int k, a, b;
    bool flag = false;
    cin >> k >> a >> b;

    for (int i = a; i<=b; i++) {
        if (i % k == 0) {
            flag = true;
        }
    }

    if (flag) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
    return 0;
}



Measured memory_bytes: 3620
N, Y = map(int,input().split())
ans = []

for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y and z >= 0:
            ans = [x,y,z]

if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(str(ans[0]),str(ans[1]),str(ans[2]))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#define MAX_N 3000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll a[MAX_N],dp[MAX_N][MAX_N]={};
bool used[MAX_N][MAX_N]={};
ll eo;
ll n;
ll calc(ll i,ll j){
  ll sig;
  if(used[i][j]){
    return dp[i][j];
  }
  if(i>j){
    return 0;
  }
  used[i][j]=true;
  if(i==j){
    if(eo)sig=1;
    else sig=-1;
    return dp[i][i]=a[i]*sig;
  }else{
    if((j-i)%2!=eo) sig = 1;
    else sig = -1;
    if(sig>0){
      return dp[i][j] = max(calc(i+1,j)+a[i]*sig
          ,calc(i,j-1)+a[j]*sig);
    }else{
      return dp[i][j] = min(calc(i+1,j)+a[i]*sig
          ,calc(i,j-1)+a[j]*sig);
    }
  }
}
signed main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  eo = n%2;
  cout << calc(0,n-1)<<endl;
  /*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cout << dp[i][j]<<" ";
    }
    cout << endl;
  }
  */
}


Measured memory_bytes: 78464
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
table=array(10,0,10)
1.upto(N) do|x|
  x_=x.to_s.split("").map(&:to_i)
  table[x_[0]][x_[-1]]+=1
end
ans=0
10.times do|i|
    10.times do|j|
      ans+=table[i][j]*table[j][i]
    end
end
puts ans

Measured memory_bytes: 14352
#include <stdio.h>

int main(void)
{
	char a[3];
	int i;
	for(i=0;i<3;i++)
	{
		scanf("%c",&a[i]);
	}
	
	int q,qq,qqq;
	q=0;qq=0;qqq=0;
	if(a[0]=='R')
	{
		if(a[1]=='R')
		{
			if(a[2]=='R')
			{
				q=3;
			}
			else
			{
				q=2;
			}
		}
		else
		{
			q=1;
		}
	}
	else if(a[1]=='R')
	{
		if(a[2]=='R')
		{
			qq=2;
		}
		else
		{
			qq=1;
		}
	}
	else if(a[2]=='R')
	{
		qqq=1;
	}
	else
	{
		;
	}
	
	int max=-1;
	if(max<q)
	{
		max=q;
	}
	if(max<qq)
	{
		max=qq;
	}
	if(max<qqq)
	{
		max=qqq;
	}
	printf("%d\n",max);
	
	return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<vector>
#include<string>
#define M 1000000
std::vector <std::vector <std::string>> dic(M);
int hash(char ch){
	if(ch=='A') return 1;
	if(ch=='C') return 2;
	if(ch=='G') return 3;
	if(ch=='T') return 4;
	return 0;
}

long long key(std::string str){
	long long v=0;
	int b=1,n=str.size();
	for(int i=0;i<n;i++){
		v+=b*(hash(str[i]));
		b*=5;
	}
	return v%M;
}

int find(std::string str){
	std::vector <std::string> s;
	s=dic[key(str)];
	int n=s.size();
	for(int i=0;i<n;i++){
		if(s[i]==str) return 1;
	}
	return 0;
}

void insert(std::string str){
	dic[key(str)].push_back(str);
}

int main(){
	int n;
	std::cin>>n;
	for(int i=0;i<n;i++){
		std::string com,str;
		std::cin>>com;
		std::cin>>str;
		if(com[0]=='i') insert(str);
		else if(find(str)) std::cout<<"yes"<<'\n'; else std::cout<<"no"<<'\n';
	}
	return 0;
}


Measured memory_bytes: 65604
#include <iostream>

using namespace std;

double search_num(int *sunuke, int num, int max){
    
    double flag = false;
    
    for(int i=0; i<max; i++){
        if(sunuke[i] == num){
            flag = true;
            break;
        }
    }
    return flag;
}

void array_input(int *array_A, int n){
    for(int i=0; i<n; i++){
        cin >> array_A[i];
    }
}

int main(void){
    
    int N, K;
    cin >> N >> K;
    
    int *sunuke = new int[N];
    int sunuke_i = 0;
    
    for(int i=0; i<K; i++){
        
        int d;
        cin >> d;
        
        int *A = new int[d];
        array_input(A, d);
        
        for(int j=0; j<d; j++){
            if(!search_num(sunuke, A[j], sunuke_i)){
                sunuke[sunuke_i] = A[j];
                sunuke_i++;
            }
        }
        delete[] A;
    }
    
    cout << N - sunuke_i << endl;
    
    delete[] sunuke;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  vector<bool> dp(110, false);
  dp[0] = true;
  REP(i, 100){
    if(!dp[i]) continue;
    dp[i+4] = true;
    dp[i+7] = true;
  }
  if(dp[n]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
A,B,C,K=input().split()
A=int(A)
B=int(B)
C=int(C)
K=int(K)
if abs(A-B)>10**18:
    print('Unfair')
else:
    if K%2==0:
        print(A-B)
    else:
        print(B-A)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>

using namespace std;


int main(){
	int n;
	cin>>n;
	
	int num=n;
	for(int i=0;i<3-1;i++){
		num*=n;
	}
	
	printf("%d",num);
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <tuple>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long int ll;
using namespace std;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main()
{
    int k,t;
    cin >> k >> t;
    int a[t];
    int x = 0;
    REP(i,t){cin >> a[i];if(a[i]>x){x = a[i];}}

    cout << max(0,x - (k-x) -1) << endl;

    return 0 ;

}


Measured memory_bytes: 384
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { //
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		long ans = 0;
		while (N>1) {
			if (Prime(N)) {
				ans++;
				break;
			} 
			for (long i = 2; i <= Math.sqrt(N); i++) {
				long cnt = 0;
				long curTopLimit = 1;
				while (N%i==0) {
					N/=i;
					cnt++;
					if (cnt>=curTopLimit) {
						ans++;
						curTopLimit++;
						cnt=0;
					}
				}
			}
		}
		System.out.println(ans);
	}
	public static boolean Prime(long N) {
		for (long i = 2; i <= Math.sqrt(N); i++) {
			if (N%i==0) return false;
		}
		return true;
	}
}

Measured memory_bytes: 27296
"use strict";
    
const main = arg => {
    const N = parseInt(arg.split("\n")[0]);
    const d = arg.split("\n").slice(1, N+1).map(n=>parseInt(n)).sort((a,b)=>b-a);
    
    const set = new Set(d);
    
    console.log(parseInt(set.size));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
N = input()

if N[len(N)-1] == '3':
  print('bon')
elif N[len(N)-1] == '2' or N[len(N)-1] == '4' or N[len(N)-1] == '5' or N[len(N)-1] == '7' or N[len(N)-1] == '9':
  print('hon')
else:
  print('pon')

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

using namespace std;
using ll = long long;


class Fast_Factorization {
private:
	int n;
	vector<int> factor;
public:
	Fast_Factorization(int _n):n(_n) {
		factor.assign(n, 0);
		iota(factor.begin(), factor.end(), 0);
		for(int i = 2; i < n; i++) {
			if(factor[i] != i)continue;
			for(int j = i + i; j < n; j += i) factor[j] = i;
		}
	}

	//v < nが要求される
	map<int, int> sieve(int v) {
		map<int, int> ret;
		while(v != factor[v]) {
			ret[factor[v]]++;
			v /= factor[v];
		}
		if(v != 1)ret[v]++;
		return ret;
	}


}fact(1000001);


int main()
{
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++)cin >> a[i];
	vector<int> v(1000001);

	for(int i = 0; i < n; i++) {
		auto mp = fact.sieve(a[i]);
		for(auto j : mp)v[j.first]++;		
	}

	int cnt = count_if(v.begin(), v.end(), [](int a){return a > 1;});
	int GCD = accumulate(a.begin(), a.end(), 0, [](int a, int b){return gcd(a, b);});
	cerr << GCD << endl;

	if(cnt == 0) {
		cout << "pairwise coprime" << endl;
	} else if(GCD == 1) {
		cout << "setwise coprime" << endl;
	} else {
		cout << "not coprime" << endl;
	}
	
}

Measured memory_bytes: 14876
<?php
  $x = trim(fgets(STDIN));
  $a = 0;
  if($x%11>0){
      $a += 11-($x%11);
  }
  $x += $a;
  $ans = $x/11;
  $ans *= 2;
  if($a >= 5){
      $ans--;
  }
  echo $ans;

Measured memory_bytes: 4728
s = str(input())
l = len(s)
ans = int(0)
r = l // 2
if l % 2 == 0:
    for i in range(r):
        if s[i] != s[l - i - 1]:
            ans += 1
else:
    for j in range(r):
        if s[j] != s[l - j - 1]:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define LL long long 
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 7, mod = 1000000007;
template<typename A, typename B> inline void chmax(A &x, B y) {
	x = x > y ? x : y;
}
template<typename A, typename B> inline void chmin(A &x, B y) {
	x = x < y ? x : y;
}
template<typename A, typename B> inline int mul(A x, B y) {
	return 1ll * x * y % mod;
}
template<typename A, typename B> inline void add2(A &x, B y) {
	if(x + y < 0) x = x + y + mod;
	else x = (x + y >= mod ? x + y - mod : x + y);
}
template<typename A, typename B> inline int add(A x, B y) {
	if(x + y < 0) return x + y + mod;
	else return x + y >= mod ? x + y - mod : x + y;
}
template<typename A, typename B> inline int fp(A a, B p) {
	int base = 1;
	while(p) {
		if(p & 1) base = mul(base, a);
		a = mul(a, a); p >>= 1;
	}
	return base;
}
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int N, fac[MAXN], ifac[MAXN], f[MAXN];
int C(int N, int M) {
	if(M > N) return 0;
	return mul(fac[N], mul(ifac[M], ifac[N - M]));
}
int main() {
	N = read(); fac[0] = 1;
	for(int i = 1; i <= N; i++) fac[i] = mul(i, fac[i - 1]);
	ifac[N] = fp(fac[N], mod - 2);
	for(int i = N; i >= 1; i--) ifac[i - 1] = mul(ifac[i], i);
	int down = N / 2 + (N & 1);
	for(int i = down; i < N; i++) 
		f[i] = mul(mul(C(i - 1, N - i - 1), fac[i]), fac[N - i - 1]);
	int ans = 0;
	for(int i = down; i < N; i++) add2(ans, mul(i, add(f[i], -f[i - 1])));
	cout << ans;
	return 0;
}
/*
3
0 1 1
5 7 3
*/

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


using namespace std;

int a[210000];

int main() { 
   
   int n; cin >> n;
   
   for (int i=0; i<n; i++) scanf("%d", a+i);
   sort(a, a+n);

   for(int i=0; i<n-1; i++) {
      if(a[i] == a[i+1]) {
         cout << "NO\n"; return 0;
         }
   }  
      cout << "YES\n";

   }

Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
 
#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;
 
typedef long long ll;
const ll mod=1e9+7;
 
using pear = pair<int,int>;
 
int main(){
    ll n; cin >> n;
    cout << (n-1)*n/2 << endl;
}

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

int main() {
  pair<pair<string, int>,int> p[110];
  int N;
  cin >> N;
  for (int i; i < N; i++) {
    cin >> p[i].first.first >> p[i].first.second;
    p[i].first.second = -p[i].first.second;
    p[i].second = i + 1;
  }
  sort(p, p+N);
  for (int i; i< N; i++) cout << p[i].second << endl;
}
    
   

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

// 最大公約数
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  int n, s;
  cin >> n >> s;
  vector<int> x(n);
  rep(i, n) cin >> x[i];

  vector<int> d;
  rep(i, n) d.push_back(abs(s - x[i]));

  int ans = 0;
  rep(i, n) {
    if (ans == 0) {
      ans = d[i];
    } else {
      ans = gcd(ans, d[i]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int N = 300006;

int main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, A, B, C;
    cin >> n >> A >> B >> C;
    vector<string> s(n);
    vector<char> ans;
    for(string& x : s) cin >> x;
    for(int i = 0; i < n; i++) {
        if (s[i] == "AB") {
            if (A == 0 && B == 0) {
                cout << "No\n";
                return 0;
            }
            if(A > B) {
                A--;
                B++;
                ans.pb('B');
                continue;
            }
            if (A < B) {
                A++;
                B--;
                ans.pb('A');
                continue;
            }
            if(i + 1 < n && s[i + 1] == "BC") {
                A--;
                B++;
                ans.pb('B');
                continue;
            }
            A++;
            B--;
            ans.pb('A');
        }
        if(s[i] == "AC") {
            if (A == 0 && C == 0) {
                cout << "No\n";
                return 0;
            }
            if(A > C) {
                A--;
                C++;
                ans.pb('C');
                continue;
            }
            if (A < C) {
                A++;
                C--;
                ans.pb('A');
                continue;
            }
            if(i + 1 < n && s[i + 1] == "BC") {
                A--;
                C++;
                ans.pb('C');
                continue;
            }
            A++;
            C--;
            ans.pb('A');
        }
        if(s[i] == "BC") {
            if (B == 0 && C == 0) {
                cout << "No\n";
                return 0;
            }
            if(B > C) {
                B--;
                C++;
                ans.pb('C');
                continue;
            }
            if (B < C) {
                B++;
                C--;
                ans.pb('B');
                continue;
            }
            if(i + 1 < n && s[i + 1] == "AC") {
                B--;
                C++;
                ans.pb('C');
                continue;
            }
            B++;
            C--;
            ans.pb('B');
        }
    }
    cout << "Yes\n";
    for(auto it : ans) cout << it << '\n';
    return 0; 
}
 

Measured memory_bytes: 6704
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll a,b,n; cin >> a >> b >> n;
  
  if(a + b >= n) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    if (a>b){
        cout << 0 << endl;
        return 0;
    }
    if (n==0){
        cout << 0 << endl;
        return 0;
    }
    if (n==1){
        if (a==b){
            cout << 1 << endl;
            return 0;
        }
        cout << 0 << endl;
        return 0;
    }
    cout << (b-a)*(n-2)+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<stack>
#include<ctime>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<queue>
using namespace std;
typedef int _int;
#define int long long 
inline int read(){
	int num=0,f=1;char x=getchar();
	while(x<'0'||x>'9'){if(x=='-')f=-1;x=getchar();}
	while(x>='0'&&x<='9'){num=num*10+x-'0';x=getchar();}
	return num*f;
}
const int maxn=200005;
struct point{
	int k,d;
}p[maxn],a[maxn],b[maxn];
priority_queue<int, vector<int>, greater<int> > pq;
int n,cnt1,cnt2;
bool cmp1(point a,point b){
	return a.k<b.k;
}
bool cmp2(point a,point b){
	return a.k>b.k;
}
_int main(){
	int T=read();
	while(T--){
		n=read();
		int ans=0;cnt1=cnt2=0;
		for(int i=1,l,r;i<=n;++i){
			p[i].k=read();l=read();r=read();
			p[i].d=l-r;
			if(l-r>0){
				ans+=r;
				a[++cnt1]=p[i];
			}
			else {
				ans+=l;
				b[++cnt2]=p[i];
				b[cnt2].d=-b[cnt2].d;
			}
		}
		sort(a+1,a+cnt1+1,cmp1);
		sort(b+1,b+cnt2+1,cmp2);
		for(int i=1;i<=cnt1;++i){
			pq.push(a[i].d);
			if(pq.size()>a[i].k)pq.pop();
		}
		while(pq.size()){ans+=pq.top();pq.pop();}
		for(int i=1;i<=cnt2;++i){
			pq.push(b[i].d);
			if(pq.size()>n-b[i].k)pq.pop();
		}
		while(pq.size()){ans+=pq.top();pq.pop();}
		printf("%lld\n",ans);
	}
	return 0;
}


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

namespace CodeForce
{



    class CF
    {

        static void Main(string[] args)
        {
            List<int> nums1 = new List<int>(from x in Console.ReadLine().Split(' ') select Convert.ToInt32(x));
            List<int> houses = new List<int>(from x in Console.ReadLine().Split(' ') select Convert.ToInt32(x));
            int lastdistance = houses[houses.Count - 1] - nums1[0];
            var distances = new List<int>(houses.Select(x =>
            {
                int returnvalue = Math.Abs(x - lastdistance);
                lastdistance = x;
                return returnvalue;
            }));

            int maxdistance = distances.Max();

            int answer = distances.Sum() - maxdistance;
            Console.WriteLine(answer);
        }
    }
}

Measured memory_bytes: 35044
#include <bits/stdc++.h>
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N){
    cin >> A[i];
  }
  vector<ll> B(N);
  REP(i, N) cin >> B[i];
  
  ll a = 0;
  vector<ll> b;
  ll c = 0;
  ll cnt = 0;
  REP(i,N){
    if(A.at(i)<B.at(i)){
      cnt++;
      a+=B.at(i)-A.at(i);
    }else{
      b.push_back(A.at(i)-B.at(i));
      c+=A.at(i)-B.at(i);
    }
  }

  sort(ALL(b));
  reverse(ALL(b));
  // REP(i,b.size()){
  //   cout << b[i] << " ";
  // }
  // cout << endl;
  // cout << a << " " << cnt << endl;
  if(cnt==0){
    cout << 0 << endl;
  }else if(c<a){
    cout << -1 << endl;
  }else{
    REP(i,b.size()){
      if(b.at(i)<a){
        cnt++;
      }
      a-=b.at(i);
    }
    cout << cnt + 1 << endl;
  }
}

Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
int main(void){
    // Your code here!
    long double X;
    cin >> X;
    
    
    long double yokin = 100;
    int cnt = 0;
    if(X > 1338876){
        yokin = 1338876;
        cnt = 1012;
    
    }else if(X > 1335850880){
        yokin = 1335850880;
        cnt = 1706;
    }else if(X > 10046857615823){
        yokin = 110046857615823;
        cnt = 2603;
    }
    
    while(yokin < X){
        yokin += (long)(yokin* 0.01);
        cnt++;
    }
    
    cout << cnt << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m;
    static tuple<int64_t,int64_t,int64_t> abc[1000], def[1000];
    static int64_t xv[3000], yv[3000];
    cin >> n >> m;

    map<int64_t, int> xs, ys;
    for(int i=0;i<n;++i){
        int64_t a, b, c;
        cin >> a >> b >> c;
        if(a > b) swap(a, b);
        abc[i] = {a, b, c};
        xs[a] = 0;
        xs[b] = 0;
        ys[c] = 0;
    }
    for(int j=0;j<m;++j){
        int d, e, f;
        cin >> d >> e >> f;
        if(e > f) swap(e, f);
        def[j] = {d, e, f};
        xs[d] = 0;
        ys[e] = 0;
        ys[f] = 0;
    }
    int cx = 0, cy = 0;
    for(auto &x: xs){ xv[cx] = x.first; x.second = cx++; }
    for(auto &y: ys){ yv[cy] = y.first; y.second = cy++; }

    static bool tate[3000][3000], yoko[3000][3000];
    for(int i=0;i<n;++i){
        auto [a, b, c] = abc[i];
        for(int xi=xs[a]+1;xi<=xs[b];++xi){
            tate[xi][ys[c]] = true;
        }
    }
    for(int i=0;i<m;++i){
        auto [d, e, f] = def[i];
        for(int yi=ys[e]+1;yi<=ys[f];++yi){
            yoko[xs[d]][yi] = true;
        }
    }
    /*
    for(int x=0;x<cx;++x){
        if(x > 0){
            for(int y=0;y<cy;++y) cerr << (tate[x][y] ? "| " : "  ");
            cerr << endl;
        }
        for(int y=1;y<cy;++y) cerr << (yoko[x][y] ? " -" : "  ");
        cerr << endl;
    }
    */
    int zxi, zyi;
    zxi = lower_bound(xv, xv+cx, 0) - xv;
    zyi = lower_bound(yv, yv+cy, 0) - yv;
    uint64_t ans = 0;
    static bool checked[3000][3000];
    queue<pair<int, int>> q;
    q.emplace(zxi, zyi);
    checked[zxi][zyi] = true;
    if(zxi <= 0 || zxi >= cx || zyi <= 0 || zyi >= cy) goto l_inf;
    while(!q.empty()){
        auto [xi, yi] = q.front();
        ans += (xv[xi] - xv[xi-1]) * (yv[yi] - yv[yi-1]);
        q.pop();
        if(!yoko[xi-1][yi]){
            if(xi-1 <= 0) goto l_inf;
            if(!checked[xi-1][yi]){
                checked[xi-1][yi] = true;
                q.emplace(xi-1, yi);
            }
        }
        if(!yoko[xi][yi]){
            if(xi+1 >= cx) goto l_inf;
            if(!checked[xi+1][yi]){
                checked[xi+1][yi] = true;
                q.emplace(xi+1, yi);
            }
        }
        if(!tate[xi][yi-1]){
            if(yi-1 <= 0) goto l_inf;
            if(!checked[xi][yi-1]){
                checked[xi][yi-1] = true;
                q.emplace(xi, yi-1);
            }
        }
        if(!tate[xi][yi]){
            if(yi+1 >= cy) goto l_inf;
            if(!checked[xi][yi+1]){
                checked[xi][yi+1] = true;
                q.emplace(xi, yi+1);
            }
        }
    }
    cout << ans << endl;
    return 0;
    l_inf: cout << "INF" << endl; return 0;
}

Measured memory_bytes: 27088
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<long long,int> pli;
int main(){
  int n;
  cin>>n;
  long long a[n];
  pli p[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    p[i]=pli(a[i],i);
    }
  sort(p,p+n);
  reverse(p,p+n);
  long long ans[n];
  int mi=n;
  for(int i=0;i<n;i++)
    ans[i]=0;
  for(int i=0;i<n-1;i++){
    mi=min(mi,p[i].second);
    ans[mi]+=(i+1)*(p[i].first-p[i+1].first);
    }
  ans[0]+=n*p[n-1].first;
  for(int i=0;i<n;i++)
    cout<<ans[i]<<endl;
  return 0;
  }

  

Measured memory_bytes: 4224
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int tc;
	tc=1;
	for(int t=1;t<=tc;t++)
	{
        int a,b;
        cin>>a>>b;
        cout<<a*b<<'\n';
	}

return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    
    int N,M;
    cin >> N >> M;
    
    vi A(N),B(M);
    in(N,A);in(M,B);
    
    vvi G(N,vi(M,infi));
    
    pq2<pair<int,pii>> que;
    rep(i,N) que.push({A[i],{i,-1}});
    rep(i,M) que.push({B[i],{i,1}});
    
    
    while (!que.empty()) {
        pair<int,pii> a = que.top();
        que.pop();
        
        if(a.se.se == -1){
            rep(i,M) {
                
                if(G[a.se.fi][i] == a.fi) G[a.se.fi][i] = -a.fi;
                else chmin(G[a.se.fi][i], a.fi);
            }
            
        }else {
            rep(i,N) {
                if(G[i][a.se.fi] == a.fi) G[i][a.se.fi] = -a.fi;
                else chmin(G[i][a.se.fi], a.fi);
            }
            
        }
        
        
    }
    
    vl f(N*M,0),ff(N*M,0);
    rep(i,N) rep(j,M) {
        if(G[i][j] < 0) ff[-G[i][j]-1] = 1;
        else f[G[i][j]-1]++;
    }
    
    
    ll ans = 1;
    ll b = 0;
    
    for (int i = N*M-1; i >= 0; i--) {
    
        if(!ff[i]){
            //cout << ans csp i << endl;
            if(f[i] > 0){
                ans *= f[i]%mod;
                ans %= mod;
                b += f[i]-1;
                b %= mod;
            }else{
                ans *= b%mod;
                ans %= mod;
                b--;
            }
        }else{
            b += f[i];
            b %= mod;
        }
    }
    
    cout << ans << endl;
    
    //outmat(G);
    
    
    

    return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> a(n);
  std::cin >> a;

  for (const auto i : a) {
    if (i % 2 == 0) {
      if (i % 3 != 0 && i % 5 != 0) {
        std::cout << "DENIED" << std::endl;
        return 0;
      }
    }
  }

  std::cout << "APPROVED" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string S; cin >> S;
    vector<int> A(S.size() + 1, 0);

    REP(i, 0, S.size()) {
        if (S[i] == '<') A[i + 1] = A[i] + 1;
    }

    for (int i = S.size() - 1; i >= 0; i--) {
        if (S[i] == '>' && A[i] < A[i + 1] + 1) A[i] = A[i + 1] + 1;
    }

    ll ans = 0;
    REP(i, 0, A.size()) {
        ans += A[i];
    }

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

Measured memory_bytes: 2820