akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <sstream>

using namespace std;

typedef pair<int, int> P;
typedef pair<P, P> RECT;

int INF = 100000;

int main(){
	
	int N;
	
	cin >> N;
	
	for(int piyo = 0; piyo < N; piyo++){
		
		int H, W;
		
		cin >> H >> W;
		
		if(H == 0 && W == 0){
			break;
		}
		
		string map[100];
		
		for(int i = 0; i < H; i++){
			cin >> map[i];
		}
		
		RECT rect[26];
		
		for(int i = 0; i < 26; i++){
			rect[i].first.first = INF;
			rect[i].first.second = INF;
			rect[i].second.first = 0;
			rect[i].second.second = 0;
		}
		
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(map[i][j] != '.'){
					rect[map[i][j] - 'A'].first.first = min(i, rect[map[i][j] - 'A'].first.first);
					rect[map[i][j] - 'A'].first.second = min(j, rect[map[i][j] - 'A'].first.second);
					rect[map[i][j] - 'A'].second.first = max(i, rect[map[i][j] - 'A'].second.first);
					rect[map[i][j] - 'A'].second.second = max(j, rect[map[i][j] - 'A'].second.second);
				}
			}
		}
		
		for(int loop = 0; loop < 10; loop++){
			for(int i = 0; i < 26; i++){
				bool flag = true;
				for(int y = rect[i].first.first; y <= rect[i].second.first; y++){
					for(int x = rect[i].first.second; x <= rect[i].second.second; x++){
						if(map[y][x] != 'A' + i && map[y][x] != 'a'){
							flag = false;
						}
					}
				}
				
				if(flag){
					for(int y = rect[i].first.first; y <= rect[i].second.first; y++){
						for(int x = rect[i].first.second; x <= rect[i].second.second; x++){
							map[y][x] = 'a';
						}
					}
				}
			}
		}
		
		bool ans = true;
		
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(map[i][j] != '.' && map[i][j] != 'a'){
					ans = false;
				}
			}
		}
		
		if(ans){
			cout << "SAFE" << endl;
		}else{
			cout << "SUSPICIOUS" << endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,x,y;
lol i[101];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    lol c,d=0,e=0,f=0,g=1,h=0;
    cin >>a>>b;
    c=min(a,b);
    a-=c,b-=c;
    if(max(a,b)%2==0) cout <<c+max(a,b)/2<<'\n';
    else cout <<"IMPOSSIBLE\n";
    return (0);
}


Measured memory_bytes: 256
#140b
N = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))

#print("0 :",list_A[0],"…",list_B[list_A[0]-1])
ans = list_B[list_A[0]-1]

for i in range(1,N,1):
    #print(i,":",list_A[i],"…",list_B[list_A[i]-1])
    ans += list_B[list_A[i]-1]
    
    if list_A[i-1]+1 == list_A[i]:
        ans += list_C[list_A[i]-2]
        
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>

using ll = long long;

using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if (1 <= a and a <= 9)
		if (1 <= b and b <= 9) {
			cout << a * b;
			return 0;
		}
	
	cout << "-1";
}




Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

ll mod=998244353;
const int SIZE=510000;
ll fac[SIZE], finv[SIZE], inv[SIZE];
void COMinit(ll m){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2; i<SIZE; ++i){
        fac[i]=(fac[i-1]*i)%m;
        inv[i]=m-(inv[m%i]*(m/i))%m;
        finv[i]=(finv[i-1]*inv[i])%m;
    }
}
ll COM(int n, int k, ll m){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return (fac[n]*((finv[k]*finv[n-k])%m))%m;
}

int main() {
	int N, M, K;
	cin >> N >> M >> K;
	ll ans=0, mult=M;
	COMinit(mod);
	for(int i=0; i<N-K-1; ++i) (mult *= M-1) %= mod;
	for(int i=K; i>=0; --i){
		(ans += (mult*COM(N-1, i, mod))%mod) %= mod;
		(mult *= M-1) %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15592
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val set = mutableSetOf<Pair<Int,Int>>()
    val a = readLine()!!.split(' ').map { it.toInt() }
    println(a.withIndex().count{ it.index + 1 == a[it.value - 1] } / 2)
}

Measured memory_bytes: 51708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.ReadLineSplitInt32();
            var A = line[0];
            var B = line[1];
            var T = line[2];

            return T / A * B;
        }

        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader)
        {
            this.consoleReader = consoleReader;
        }
        static void Main() => Console.WriteLine(new Program().Calc());
    }

    public class ConsoleReader
    {
        public virtual string ReadLine() => Console.ReadLine();
        public int ReadLineInt32() => int.Parse(ReadLine());
        public long ReadLineInt64() => long.Parse(ReadLine());
        public ulong ReadLineUInt64() => ulong.Parse(ReadLine());
        public double ReadLineDouble() => double.Parse(ReadLine());
        public string[] ReadLineSplit() => ReadLine().Split().ToArray();
        public int[] ReadLineSplitInt32() => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public long[] ReadLineSplitInt64() => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public ulong[] ReadLineSplitUInt64() => ReadLine().Split().Select(s => ulong.Parse(s)).ToArray();
        public double[] ReadLineSplitDouble() => ReadLine().Split().Select(s => double.Parse(s)).ToArray();

        public IEnumerable<string> RepeatReadLines(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLine();
        }
        public IEnumerable<int> RepeatReadLinesInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLineInt32();
        }
        public IEnumerable<string[]> RepeatReadLinesSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLineSplit();
        }
    }
    static class DicExt
    {
        public static double GetOrDefault(this Dictionary<int, double> dic, int key)
        {
            double val;
            return dic.TryGetValue(key, out val) ? val : 1;
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
using namespace std;
int k,s;
int ans;
int main(){
	cin>>k>>s;
	for(int x=0;x<=k;x++)
		for(int y=0;y<=k;y++){
			int z=s-x-y;
			if(z>=0 && z<=k) ans++;
		}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

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

		boolean can = false;
		for (int i = 1; i <= x; i++) {
			int j = x - i;
			if (y == j * 2 + i * 4 || y == i * 2 + j * 4 ) can = true;
		}


		if (can) {
			System.out.println("Yes");
		} else {
			System.out.println("No");

		}

		sc.close();
	}

}


Measured memory_bytes: 35712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;
       
        static void SolveA()
        {
            int n = ReadAndParseInt();
            long[] c = new long[n-1];
            long[] s = new long[n-1];
            long[] f = new long[n-1];
            for(int i=0;i<n-1;++i)
            {
                var tmp = ReadAndParseIntArr();
                c[i] = tmp[0];
                s[i] = tmp[1];
                f[i] = tmp[2];
            }

            for(int i=0;i<n-1;++i)
            {
                long sec = CalcSec(i, c, s, f);



                Console.WriteLine(sec);
            }
            Console.WriteLine(0);
        }
        private static long CalcSec(int startStation, long[] c, long[] s, long[] f)
        {
            long time = 0;
            for(int i = startStation;i<c.Length;++i)
            {
                if(s[i] <= time && (time % f[i] == 0))
                {
                    // 加算無し
                }
                else if (time < s[i])
                {
                    time = s[i];
                }else
                {
                    // 待ち
                    time += f[i] - time % f[i];
                }
                time += c[i];

            }
            return time;
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if( x == 2) { return true; }
            if( x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while( i * i <= x)
            {
                if( x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }

        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

int main(){
  
  int n;
  cin >> n;
  vector<int> v(n,0);
  vector<int> mask(n,0);
  rep(i,n){
    int a;
    cin >> a;
    rep(j,a){
      int x,y;
      cin >> x >> y;
      x --;
      v[i] |= (y << x);
      mask[i] |= (1 << x);
    }
  }
  int ans = 0;
  rep(i,(1 << n)){
    int bits = 0;
    rep(j,n){
      bool bit = (i >> j)&1;
      bits += bit;
      if(bit){
        int check = i^v[j];
        check &= mask[j];
        if(check > 0) break;
      }
      if(j == n-1) ans = max(ans,bits);
    }//j
  }//i
  cout << ans << endl;
}

Measured memory_bytes: 3624
import java.util.*;
import java.lang.Math;

public class Main
{
    static int[] d={-5,-4,-3,-1,0,1,3,4,5};
    static int[] a={0,2,5,7,8,10,13,15,16,18};
    
    public static void main(String[] args)
    {
        ArrayList<Integer> layout;
	Scanner sc=new Scanner(System.in);
	int attend=sc.nextInt();
	for(int i=0;i<attend;i++){
	    layout =new ArrayList<Integer>();
	    for(int j=0;j<4*5;j++){
		layout.add(sc.nextInt());
	    }
	    
	    System.out.println((20-2*solve(layout,0)));
	    
	}
	
    }
    static int solve(ArrayList<Integer> layout,int step)
    {
	int rem=step;
	for(int current=0;current<20;current++){
	    int currentCard =layout.get(current);
	    if(currentCard==0)break;

	    for(int k=0;k<d.length;k++){
		if((current%4==0&&k%3==0)||(current%4==3&&k%3==2)||k==4)continue;
		if((current<4&&k<3)||(current>=16&&k>5))continue;
		int next=current+d[k];
		int nextCard=layout.get(next);
		if(nextCard==0)break;
		if(currentCard==nextCard){
		    ArrayList<Integer> nextLayout=new ArrayList<Integer>(layout);
		    nextLayout.remove(Math.max(current,next));
		    nextLayout.remove(Math.min(current,next));
		    nextLayout.add(0);
		    nextLayout.add(0);
		    //  System.out.println("rem="+rem);
		    rem=Math.max(rem,solve(nextLayout,step+1));
		    if(rem==10)return 10;
		}
	    }
	}
	
	return rem;
    }  
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    lli a[4] ;
  loopcin(4 , a);
  cout << max(a[0] * a[1] , a[2] * a[3]) ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
# 解説AC
N,M = map(int, input().split())
S = [int(i) for i in input().split()]
T = [int(i) for i in input().split()]

MOD = 10 ** 9 + 7

# dp[i][j]: S[:i]とT[:j]の共通部分列のうち、
# S[i - 1] == T[j - 1]で、これを選ぶ場合の個数
dp = [[0] * (M + 1) for _ in range(N + 1)]

# DPの二次元累積和
sdp = [[0] * (M + 1) for _ in range(N + 1)]

# 初期条件
dp[0][0] = 1
for i in range(N + 1):
    sdp[i][0] = 1
for j in range(M + 1):
    sdp[0][j] = 1

for i, s in enumerate(S):
    for j, t in enumerate(T):
        if s == t:
            dp[i + 1][j + 1] = sdp[i][j]
        sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i + 1][j + 1]
        sdp[i + 1][j + 1] %= MOD

print(sdp[N][M])

Measured memory_bytes: 105692
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lloop(i, a, b) for(ll i=a;i<(ll)b; i++)
#define loop(i, a, b) for(int i=a;i<b;i++)

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

int main(){
	int n;
	cin>>n;
	ll sum=0;
	loop(i, 1, n+1){
		loop(j, 1, n+1){
			loop(k, 1, n+1){
				int g=k;
				g=gcd(g, j);
				g=gcd(g, i);
				sum+=g;
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;



int main(){
  ll n,k;
  cin>>n>>k;

  ll ans=0;
  ll cnt=n/k;
  ans+=pow(cnt,3LL);

  if(k%2==1){ cout<< ans <<endl; return 0; }

  cnt=(n+k/2)/k;
  ans+=pow(cnt,3LL);

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long ans = a*c;
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3624
def main():
    n,x,y = map(int,input().split())
    dis = [0 for i in range(n+1)]
    for i in range(1,n+1):
        for j in range(i,n+1):
            tmp = min(j-i,abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x))
            #print(i+1,j+1,tmp)
            dis[tmp] += 1
    for i in range(1,n):
        print(dis[i])
if __name__ == '__main__':
    main()
    

Measured memory_bytes: 9104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int main(void){
    char x, y;
    cin >> x >> y;
    if(x==y){
        cout << "=" << endl;
    }
    if(x<y){
        cout << "<" << endl;
    }
    if(x>y){
        cout << ">" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <iomanip>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
// #define req(j, n) for (ll j = 1; j < (n+1); j++)
// #define rer(k, n) for (ll k = 1; k < (n+1); k++)



int main()
{   
    int a, b;
    int ans;
    cin >> a >> b;
    ans = a * b;
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>S;
    vector<string> wea = {"Sunny", "Cloudy", "Rainy"};
    rep(i,3){
        if(S == wea[i]) cout<<wea[(i+1)%3]<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
vector<vector<ll>> c(55,vector<ll>(55,-1));
long long com(int a,int b){
  if(c[a][b]>=0){
    return c[a][b];
  }
  if(a==b||b==0){
    return 1;
  }
  if(a<b||a<0){
    return 0;
  }
  return c[a][b]=com(a-1,b-1)+com(a-1,b);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;cin >> n >> a >> b;
    vector<ll> v(n);
    map<ll,int> m,p;
    for(int i=0;i<n;i++){
        cin >> v[i];
        m[v[i]]++;
    }
    sort(v.begin(),v.end(),greater<ll>());
    double ans=0;
    for(int i=0;i<a;i++){
        ans+=v[i];
        p[v[i]]++;
    }
    int u=m[v[a-1]],t=p[v[a-1]];
    cout << fixed << setprecision(10) << ans/a << endl;
    if(t==a){
        ll sum=0;
        for(ll i=a;i<=min(u,b);i++){
            sum+=com(u,i);
        }
        cout << sum << endl;
    }
    else{
        cout << com(u,t) << endl;
    }
}

Measured memory_bytes: 256
n = STDIN.gets.to_i
matrix    = Array.new(n) { Array.new(n, false) }
distances = Array.new(n)

n.times do
	vertex, degree, *adj_list = STDIN.gets.split.map(&:to_i)
	degree.times do |i|
		matrix[vertex - 1][adj_list[i] - 1] = true
	end
end

queue = [].push(0)
distances[0] = 0
until queue.empty?
	v = queue.shift
	adj_list = matrix[v].each_index.
		select { |i| matrix[v][i] && distances[i].nil? }.
		each { |adj| distances[adj] = distances[v] + 1; queue << adj }
end

matrix.each_index { |i| puts "#{i + 1} #{distances[i] || -1}" }

Measured memory_bytes: 6184
import java.util.*;

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

        int price = 700;

        if(S.charAt(0) == 'o'){
            price += 100;
        }

        if(S.charAt(1) == 'o'){
            price += 100;
        }

        if(S.charAt(2) == 'o'){
            price += 100;
        }

        System.out.println(price);
    }
}

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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>> g( N );
	for( int i = 0; i < M; i++ ) {
		int A, B;
		cin >> A >> B;
		A--;
		B--;
		g[A].push_back( B );
		g[B].push_back( A );
	}

	const int INF = INT32_MAX / 2;
	typedef pair<int, int> P;
	vector<int> d( N, INF );
	vector<int> nxt( N, -1 );
	priority_queue<P, vector<P>, greater<P>> que;
	d[0] = 0;
	que.push( P(0, 0) );
	while( !que.empty() ) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if( d[v] < p.first ) continue;
		for( int i = 0; i < g[v].size(); i++ ) {
			int e = g[v][i];
			if( d[e] > d[v] + 1 ) {
				d[e] = d[v] + 1;
				nxt[e] = v;
				que.push( P( d[e], e ) );
			}
		}
	}
	int flag = 0;
	for( int i = 1; i < N; i++ ) {
		if( nxt[i] < 0 ) {
			flag = 1;
			break;
		}
	}

	if( flag ) cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		for( int i = 1; i < N; i++ ) {
			cout << nxt[i] + 1 << endl;
		}
	}
}


Measured memory_bytes: 11188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MOD = 1e9 + 7;

template <class T, T MOD>
class ModuloCombination {
 private:
  std::vector<T> factrial, inverse_factrial;
  T Pow(T x, T y) {
    if (y == 0) return 1;
    if (y % 2 == 0) return Pow(x * x % MOD, y / 2);
    return x * Pow(x, y - 1) % MOD;
  }

 public:
  ModuloCombination(T n) : factrial(n + 1), inverse_factrial(n + 1) {
    inverse_factrial[0] = factrial[0] = 1;
    for (T i = 1; i <= n; i++) {
      factrial[i] = factrial[i - 1] * i % MOD;
      inverse_factrial[i] = Pow(factrial[i], MOD - 2);
    }
  }
  T operator()(T n, T k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return factrial[n] * inverse_factrial[k] % MOD * inverse_factrial[n - k] % MOD;
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (auto& e : a) cin >> e;
  sort(a.begin(), a.end());

  ModuloCombination<ll, MOD> c(n);

  ll r = 0;
  for (int i = 0; i < n; i++) {
    r += MOD - c(n - i - 1, k - 1) * a[i] % MOD;
    r %= MOD;
    r += c(i, k - 1) * a[i];
    r %= MOD;
  }
  cout << r << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void pk()
{
    string s;
    cin>>s;
    ll n=s.size();
    if(s[n-1]!='s')
    {
        cout<<s<<"s";
    }
    else
    {
        cout<<s<<"es";
    }
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //a #ifndef ONLINE_JUDGE 
    // freopen("/home/priyanshu/Hackercup/input.txt", "r", stdin); 
    // freopen("/home/priyanshu/Hackercup/output.txt", "w", stdout); 
    // #endif 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        pk();
    }
} 

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const double PI = 3.14159265358979323846;

int main() {
    cout << setprecision(20);
    ll A, B, H, M; cin >> A >> B >> H >> M;
    double m_deg = M * 6;
    double h_deg = ((double)M/60 + H) * 30;
    double diff_deg = abs(m_deg - h_deg);
    diff_deg = min(360 - diff_deg, diff_deg);
    double ans_2 = A * A + B * B - 2 * A * B * cos(diff_deg / 180 * PI);
    cout << pow(ans_2, ((double)1/2)) << endl;
}

Measured memory_bytes: 4356
import fs = require('fs');
const input = fs.readFileSync('/dev/stdin', 'utf8').trim();
const split = input.split(/[\r\n ]/).map(Number);

const [A, B, K] = split;

const answers: number[] = [];
let i=0;
while(++i) {
	if(A%i === 0 && B%i === 0) {
		answers.push(i);
	}
	if(i>=A || i>=B) {
		break;
	}
}
answers.reverse();

console.log(answers[K-1]);

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

int main()
{
  int n,m,ans=0;
  cin >> n>>m;
  vector<int> a(n);
  vector<vector<int>> p(n,vector<int>(n,0));
  rep(i,m){
    int a,b;
    cin>> a>>b;
    a--;b--;
    p[a][b]=p[b][a]=1;
  }
  rep(i,n) a[i]=i;
  do{
        if(a[0]!=0) break;
        bool ok=true;
        rep(i,n-1){
          if(p[a[i]][a[i+1]]==0) ok=false;
        }
        if(ok) ans++;
    } while(next_permutation(a.begin(),a.end()));
    cout<<ans<<endl;
}

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

int main(){
  int a, b, c; cin >> a >> b >> c;
  if(a==b && b==c){
    cout << 1 << endl;
    return 0;
  }
  if(a!=b && b!=c && c!=a){
    cout << 3 << endl;
    return 0;
  }
  cout << 2 << endl;
}

Measured memory_bytes: 256
def yes_no(flg):
    """
        if True return Yes
        if False return No
    """
    if flg:
        print('Yes')
    else:
        print('No')

n = int(input())
flg = False
for y in range(1,10):
    for x in range(1,10):
        if y * x == n:
            flg = True
yes_no(flg) 

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
typedef pair<ll, ll> pint;

const int MOD = 1000000007;
void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }
}

int main(){
    int N, K,d;
    cin >> N >> K;
    bool A[N];
    rep(i, N) {
        A[i] = false;
    }
    rep(i, K) {
        int a;
        cin >> d;
        rep(i, d) {
            cin >> a;
            a--;
            A[a] = true;
        }
    }

    int ans = 0;
    rep(i, N) {
        if (!A[i]) ans++;
    }

    cout << ans << endl;


}

Measured memory_bytes: 3640
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
for i in reversed(range(0, N)):
    diff = A[i+1] - B[i]
    if(diff >= 0):
        count += B[i]
    else:
        B[i] -= A[i+1]
        count += A[i+1]
        diff = A[i] - B[i]
        if(diff >= 0):
            A[i] -= B[i]
            count += B[i]
        else:
            count += A[i]
            A[i] = 0
print(count)

Measured memory_bytes: 18476
import itertools
N,M = map(int,raw_input().split())
lab = [map(float,raw_input().split()) for _ in range(N)]
ans = 0
for ele in itertools.combinations(lab,M):
    ans = max(ans,sum((ele[i][k]-ele[j][k])**2 for k in range(3) for i in range(M) for j in range(i+1,M)))
print "%.7f"%ans

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

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

  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b == c + d) {
    cout << "Balanced" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,s;
ll F(ll i){
    ll cur=n,ans=0;
    while(cur){
        ans+=cur%i;
        cur/=i;
    }
    return ans;
}
int main()
{ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   cin>>n>>s;
    if(s==n){
        cout<<n+1<<endl;
        return 0;
    }
    if(n<s){
        cout<<-1<<endl;
        return 0;
    }
    ll SQ=sqrt(n)+1;
    for(int i=2;i<=SQ;i++){
        if(F(i)==s){
            cout<<i<<'\n';
            return 0;
        }
    }
    SQ=sqrt(n-s)+1;
    ll mn=LLONG_MAX;
    for(ll i=1;i<=SQ;i++){
        if((n-s)%i==0){
            ll b=(n-s)/i+1;
            ll q=n%b;
            if(i+q==s){
                mn=min(mn,b);
            }
        }
    }
    if(mn!=LLONG_MAX)cout<<mn<<'\n';
    else cout<<-1<<'\n';
    return 0;
}


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

void dfs(vector<bool> &flag,int pos,vector<long long> &ans,int par,vector<vector<int>> &tree){
  if(flag[pos]) return;
  if(par!=-1){
    ans[pos]+=ans[par];
  }flag[pos]=true;
  for(int i=0;i<tree[pos].size();i++){
    dfs(flag,tree[pos][i],ans,pos,tree);
  }
  return;
}

int main(){
  int n,q; cin>>n>>q;
  vector<vector<int>> tree(n+1);
  for(int i=0;i<n-1;i++){
    int a,b; cin>>a>>b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }vector<long long> ans(n+1,0);
  vector<bool> flag(n+1,false);
  for(int i=0;i<q;i++){
    int pos,val; cin>>pos>>val;
    ans[pos]+=val;
  }
  dfs(flag,1,ans,-1,tree);
  for(int i=1;i<n;i++){
    cout<<ans[i]<<' ';
  }cout<<ans[n]<<endl;
}

Measured memory_bytes: 27392
#include <bits/stdc++.h>
#include <string>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define SZ(x) ((int)x.size())

using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;

  ll ret = -1;

  REP(i,N+1){
    if((i * 108)/100 == N){
      ret = i;
      break;
    }
  }

  if(ret == -1){
    cout << ":(" << endl;
  }else{
    cout << ret << endl;
  }

  return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        cout << 'x';
    }
    cout << "\n";
    return 0;
}

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



int main() {
  char s[4];
  map<char,int> counter;
  cin >> s;
  bool flag = true;
  rep(i, 4) {
    counter[s[i]] += 1;
  }
  rep(i, 4) {
    if (counter[s[i]] != 2) flag = false;
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
const int N=1e5+5;
char s[N];
ll a[N]={0},tot[N]={0},op[N]={0};
int main()
{
int n=rr,k=rr,len=0,cnt=0;
scanf("%s",s+1);
repb(i,1,1+n)
{
	
 if(s[i]!=s[i-1]&&i-1)	
 {
 	
 	a[++cnt]=len;
 	len=0;
 	op[cnt]=s[i-1]-'0';
  } 
  len++;
}
repb(i,1,cnt)
{
	 if(!op[i])tot[i]=tot[i-1]+1;
	 else tot[i]=tot[i-1];
	 a[i]+=a[i-1];
}
ll ans=0;
for(int l=0,r=1;r<=cnt;r++)
{
	 while(l<r&&tot[r]-tot[l-1]>k)l++;
	 ans=max(ans,a[r]-a[l-1]);
	 
}
cout<<ans;
}



Measured memory_bytes: 2688
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int number[100];

int top = -1;
int pop();
void push(int );


int main(){
    
    char temp[10] = {0};
    char c;
    int i = 0;
    int t1 = 0, t2 = 0;
    while(scanf("%s" ,temp) != EOF) {
        if(temp[0] > 48){
            t1 = atoi(temp);
            push(t1);
        }
        else{
            t1 = pop();
            t2 = pop();
            switch(temp[0]) {
                case '+':
                    push(t1 + t2);
                    break;
                case '-':
                    push(t2 - t1);
                    break;
                case '*':
                    push(t1 * t2);
                    break;
                default:;
            }
        }
   }
   printf("%d\n", number[0]);

}
            
int pop(){
    top--;
    return number[top + 1];
}
    
void push(int a){
    number[top + 1] = a;
    top++;
}


Measured memory_bytes: 2104
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int main() {
  map<pair<int, int>, int> M;
  int H = in();
  int W = in();
  int N = in();

  for (int i = 0; i < N; ++i) {
    int a = in() - 1;
    int b = in() - 1;
    for (int r = max(0, a - 2); r <= min(a, H - 3); ++r) {
      for (int c = max(0, b - 2); c <= min(b, W - 3); ++c) {
        M[make_pair(r, c)]++;
      }
    }
  }

  Int res[10] = {};
  res[0] = (H - 2LL) * (W - 2LL) - M.size();

  for (const auto& p : M) {
    ++res[p.second];
  }

  for (int i = 0; i <= 9; ++i) {
    printf("%lld\n", res[i]);
  }

  return 0;
}


Measured memory_bytes: 56448
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int a[2][105];
int main()
{
	int n,i,j,ans=0,sum=0;
	cin >> n ;
	memset(a,0,sizeof(a));
	for(i=0;i<2;i++)
		for(j=0;j<n;j++)
		{
			cin >> a[i][j];
			sum+=a[1][j];
		}
	sum+=a[0][0];
	ans=sum;
	for(i=1;i<n;i++)
	{
		sum-=a[1][i-1];
		sum+=a[0][i];
		ans=max(ans,sum);
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
//
// Created by rajshah9914 on 09/04/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pp;
vector<ll>visited(200000,0);
vector<ll>adj[200000];
ll prime[2000000];
ll M=1000000007;
void boost() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void sieve(ll ending)
{
    for(ll i=2;i<ending;i++)
        prime[i]=1;
    for(int i=2;i*i<=ending;i++)
    {
        if(prime[i]==1)
        {
            for(int j=2*i;j<=ending;j=j+i)
            {
                prime[j]=0;
            }
        }
    }
    prime[1]=0;
}

ll ncrmodp(ll num,ll r)
{
    ll C[r+1];
    ll i,j;
    memset(C,0,sizeof(C));
    C[0]=1;
    for(i=1;i<=num;i++)
    {
        for(j=min(i,r);j>0;j--)
        {
            C[j]=((C[j])%M+(C[j-1])%M)%M;
        }
    }
    return C[r];
}

ll power(ll x,ll y)
{
    ll res = 1;
    x = x % M;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1; // y = y/2
        x = (x*x) % M;
    }
    return res;
}



void solve()
{
    string s,t;
    cin>>s>>t;
    if(t.length()<s.length())
    {
        cout<<"No"<<endl;
        return;
    }
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
        {
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}

int main()
{
    boost();
//    int t;
//    cin>>t;
//    while(t--)
        solve();
}

Measured memory_bytes: 9404
#include <stdio.h>

typedef struct {
	int t;
	int x;
	int y;
} Tabi;

int main()
{
	int N;
	int i;
	scanf("%d", &N);

	Tabi tabi[N + 1];
	Tabi tsugi;
	Tabi genzai;
	for (i = 0; i < N; i++) {
		scanf("%d %d %d", &(tabi[i].t), &(tabi[i].x), &(tabi[i].y));
	}

	genzai.t = 0;
	genzai.x = 0;
	genzai.y = 0;

	tsugi.t = tabi[0].t;
	tsugi.x = tabi[0].x;
	tsugi.y = tabi[0].y;

	if (((tsugi.t % 2) == ((tsugi.x + tsugi.y) % 2)) && (tsugi.t >= (tsugi.x + tsugi.y)));
	else {
		printf("No");
		return 0;
	}

	for (i = 1; i < N; i++) {
		tsugi.t = tabi[i].t - tabi[i - 1].t;
		tsugi.x = tabi[i].x - tabi[i - 1].x;
		tsugi.y = tabi[i].y - tabi[i - 1].y;

		int hantei = (tsugi.x + tsugi.y);
		if (hantei < 0) hantei = (-1) * hantei;
		if (((tsugi.t % 2) == (hantei % 2)) && (tsugi.t >= hantei));
		else {
			printf("No");
			return 0;
		}
	}

	printf("Yes");
	return 0;
}

Measured memory_bytes: 1280
n,t = map(int,input().split())
tt = list(map(int,input().split()))
tt = [0]+tt
a = 0
for i in range(n):
  if(tt[i+1]-tt[i]>=t):
    a +=t
  else:
    a += tt[i+1]-tt[i]
print(a+t)

Measured memory_bytes: 30864
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = "";
			while ((s = Console.ReadLine()) != null)
			{
				double[] p = s.Split(' ').Select(d => double.Parse(d)).ToArray();
				bool b = f(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
				Console.WriteLine(b ? "YES" : "NO");
			}
		}

		static bool f(double xA, double yA, double xB, double yB, double xC, double yC, double xD, double yD)
		{
			return (((xB - xA) * (xD - xC) + (yB - yA) * (yD - yC)) == 0);
		}
	}
}

Measured memory_bytes: 6020
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> d(h, vector<char>(w));
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin >> d[i][j];
        }
    }
    set<int> l;
    set<int> r;
    
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(d[i][j] == '#')
            {
                l.insert(i);
                r.insert(j);
            }
        }
    }
    for(int i = 0; i < h; i++)
    {
        if(l.find(i) != l.end())
        {
            for(int j = 0; j < w; j++)
            {
                if(r.find(j) != r.end())
                {
                    cout << d[i][j];
                }
            }
            cout << endl;
        }
    }
}


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

using namespace std;
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,c;
	//string ;
	cin >> a >>b >>c;
	if(c<=a+b) puts("Yes");
	else puts("No");
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = INT_MAX;
bool mywish(const pii &a,const pii &b)
  {
    return a.first > b.first;
  }

void solve()
  {
   int n;
   cin>>n;
   string s;
   cin>>s;
   int count = 0;
   loop(i,0,n-2)
    {
      if(s[i] == 'A')
         {
          if(s.substr(i,3) == "ABC")
             {
              count++;
              i+=2;
             }
         }
    }
  cout<<count;
  } 
signed main()
 {
  
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
main()
{
	char s[100];
	char t[100];
	
	scanf("%s",&s);
	scanf("%s",&t);
	
	int k;
	
	int count=0;
	
	k=strlen(s);
	
	int i;
	
	for(i=0;i<k;i++)
	{
		if(s[i]==t[i])
		{
			++count;
		}
	}
	
	if(count==k)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	
	
}

		

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000;
#define all(v) v.begin(), v.end()

//コストなし
//vector<vector<ll>> G(N,vector<ll>(0));
void no_cost_graphmake(ll E,vector<vector<ll>> &G){
  rep(i,E){
    ll a,b;
    cin >> a >> b;
    G.at(a-1).push_back(b-1);
    G.at(b-1).push_back(a-1);//有向なら消す
  }
}

void dfs(ll n,vector<vector<ll>> &G,ll t,vector<ll> &dp,vector<ll> &ans,vector<ll> &a){
  auto x=lower_bound(all(dp),a.at(n));
  if(*x==INF){
    t++;
  }
  ll y=*x;
  *x=a.at(n);
  ans.at(n)=t;
  rep(i,G.at(n).size()){
    if(ans.at(G.at(n).at(i))==0){
      dfs(G.at(n).at(i),G,t,dp,ans,a);
    }
  }
  *x=y;
  return;
}

int main(){
  ll N;
  cin >> N;
  vector<ll> a(N),dp(N),ans(N,0);
  rep(i,N) cin >> a.at(i);
  vector<vector<ll>> G(N,vector<ll>(0));
  no_cost_graphmake(N-1,G);
  rep(i,N) dp.at(i)=INF;
  dfs(0,G,0,dp,ans,a);
  rep(i,N) cout << ans.at(i) << endl;
  
}

Measured memory_bytes: 38648
import math
N = int(input())
X = math.ceil(math.sqrt(N))
li = [0]*N
xyz = []
for i in range(X):
    for j in range(X-i):
        for k in range(X-i-j):
            xyz1 = [i+1,j+i+1,k+j+i+1]
            xyz1.sort()
            if i+1 == j+i+1 == k+j+i+1:xyz1.append(1)
            elif i+1 != j+i+1 and i+1 != k+j+i+1 and j+i+1 != k+j+i+1:xyz1.append(6)
            else:xyz1.append(3)
            xyz.append(xyz1)
xyz.sort()
for l in xyz:
    n = l[0]**2 + l[1]**2 + l[2]**2 + l[0]*l[1] + l[1]*l[2] + l[2]*l[0]
    try:
        li[n-1] += l[3]
    except:pass
for n in li[0:N:]:
    print(n)

Measured memory_bytes: 32308
N = int(input())
A = list(map(int, input().split()))

MOD = 10 ** 9 + 7

def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
  return x * y // gcd(x, y)

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
tmp %= MOD

answer = 0
for a in A:
  answer += tmp * pow(a, MOD - 2, MOD)
  
print(answer % MOD)

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll n,k;
    cin >> n >> k;
    vll a(n), f(n);
    for(ll i=0;i<n;i++) {
    	cin >> a[i];
    }
    for(ll i=0;i<n;i++) {
    	cin >> f[i];
    }
    sort(all(a));
    sort(all(f));
    vpll coss(n);
    for(ll i=0;i<n;i++) {
    	coss[i].first = f[i] * a[n-1-i];
    	coss[i].second = f[i];
    	// cout << coss[i].first << "\n";
    }
    sort(all(coss));
    ll min = 0, max = coss[n-1].first;
    while(min <= max) {
    	ll mid = (min+max)/2;
    	ll temp = 0;
    	for(ll i=0;i<n;i++) {
    		if(coss[i].first > mid) temp += (coss[i].first - mid + coss[i].second - 1)/(coss[i].second);
    	}
    	// cout << mid << " " << temp << "\n";
    	if(temp > k) {
    		min = mid + 1;
    	}
    	else {
    		max = mid - 1;
    	}
    }
    cout << min << "\n";
}

int main()
{
    FAST_IO;
    // #ifndef ONLINE_JUDGE 
    //   OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  queue<int> que;
  int l = k;
  for (int i = 0; i < 30; i++) {
    if (l&1) {
      que.push(i);
    }
    l /= 2;
  }
  vector<pair<int, int>> nbs(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    nbs[i] = {a, b};
  }
  long long ans;
  long long scr = 0;
  for (int i = 0; i < n; i++) {
    int a = nbs[i].first;
    int b = nbs[i].second;
    if (!(a & ~k)) {
      scr += b;
    }
  }
  ans = scr;
  l = k;
  l--;
  while (!que.empty()) {
    scr = 0;
    for (int i = 0; i < n; i++) {
      int a = nbs[i].first;
      int b = nbs[i].second;
      if (!(a & ~l)) {
        scr += b;
      }
    }
    ans = max(ans, scr);
    l -= 1 << que.front();
    que.pop();
  }
  cout << ans << '\n';
  return 0;
}

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

#define MAX 1000000
#define sqrtMAX sqrt(MAX)

int main(void)
{
  int n;
  vector<int> b(MAX+1);
  int i, j;
  int count;

  // ツエツδ可トツスツテツネツスツづ個づ督づゥツつ「
  b[0] = 1;
  b[1] = 1;
  for(i=4; i<=MAX; i+=2)
      b[i] = 1;
  for(i=3; i<sqrtMAX; i+=2)
      for(j=i+i; j<=MAX; j+=i)
          b[j] = 1;

  while(scanf("%d", &n)!=EOF) {
    if(n==0)
      break;
    count = 0;
    for(i=0;i<=n/2;i++)
      if(!b[i]&&!b[n-i]) count++;
    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> l(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> l[i];
    }

    sort(ALL(l));

    ll ans = 0;

    for (ll i = 0; i < n - 2; i++)
    {
        for (ll j = i + 1; j < n - 1; j++)
        {
            for (ll k = j + 1; k < n; k++)
            {
                if (l[i] != l[j] && l[k] != l[j] && l[i] != l[k])
                {
                    if (l[i] + l[j] > l[k])
                    {
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3600
import sys
input = sys.stdin.readline

n,m = map(int,input().split())
H = [0]+ list(map(int,input().split()))
List = [list(map(int, input().split())) for i in range(m)]
A =[0]*(n+1)


for a,b in List:
  for _ in range(2):
    A[a] = max(A[a], H[b])
    a, b = b, a

print(sum(x > y for x, y in zip(H, A)))

Measured memory_bytes: 32052
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

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

	string s;
	int K;
	cin >> s >> K;
	int n = s.size();
	for(int i = 0; i < s.size(); i++) {
		int r = ('a' - s[i] + 26) % 26;
		if(r <= K) {
			K -= r;
			s[i] = 'a';
		}
	}
	K %= 26;
	s[n - 1] += K;
	cout << s << endl;
}

Measured memory_bytes: 640
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[0]
for i in range(n):
  s.append(s[-1]+a[i])
l=[]
for i in range(1,n+1):
  for j in range(i):
    l.append(s[i]-s[j])
l.sort(reverse=True)
m=61
ans=0
chk=0
for i in range(m)[::-1]:
  cnt=0
  chk+=2**i
  for j in l:
    if chk & j == chk:
      cnt+=1
  if cnt < k:
    chk-=2**i
print(chk)

Measured memory_bytes: 76784