akhauriyash/Code-Regression huggingface dataset:
N = int(input())

ans = [0] * 10001
for x in range(1, 100):
  for y in range(1, 100):
    for z in range(1, 100):
      val = x * x + y * y + z * z + x * y + y * z + z * x
      if val < len(ans):
        ans[val] += 1

for i in range(1, N + 1):
  print(ans[i])

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

int main() {
    int n;
    cin >> n;
    int a[n][3], cnt[3][101] = {};
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> a[i][j]; 
            cnt[j][a[i][j]]++;   
        }
    }
    for(int i = 0; i < n; i++) {
        int ans = 0;
        for(int j = 0; j < 3; j++) ans += (int)(cnt[j][a[i][j]]==1) * a[i][j];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>

 int main()
 {
 	int a, b;
 	scanf("%d",&a);
 	scanf("%d",&b);
	if(a > b)
	{
		printf("a > b\n");
	}
	else if(b > a)
	{
		printf("a < b\n");
	}
	else
	{
		printf("a == b\n");
	}
 	return 0;
 	
 }


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int b[n-1], a[n];
  for(int i = 0; i< n-1; i++){
    cin >> b[i];
  }
  a[0] = b[0];
  int sum = a[0];
  for(int i = 1; i < n-1; i++){
    a[i] = min(b[i-1],b[i]);
    sum += a[i];
  }
  a[n-1] = b[n-2];
  sum += a[n-1];
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int H,N,A,i,sum=0;
	
	scanf("%d %d",&H,&N);
	
	for(i=0;i<N;i++){
		scanf("%d",&A);
		sum = sum + A;
	}
 
	if(H<=sum){
		printf("Yes");
	}else{
		printf("No");
	}
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
sorted_l = sorted(l)
for i in range(n):
  for j in range(i,n):
    tmp = l.copy()
    tmp[i], tmp[j] = tmp[j], tmp[i]
    if tmp==sorted_l:
      print("YES")
      exit()
print("NO")

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if (a==b) {
		cout<<"Draw"<<endl;
	} else if (a==1) {
		cout<<"Alice"<<endl;
	} else if (b==1) {
		cout<<"Bob"<<endl;
	} else if (a>b) {
		cout<<"Alice"<<endl;
	} else {
		cout<<"Bob"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	n=a;
	while(1){
		n+=a;
		if(n>100000){
			printf("NO\n");
			break;
		}
		if((a+n)%b==c){
			printf("YES\n");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
class Combination:
    '''
    計算量：階乗・逆元テーブルの作成O(N)
            nCkを求めるO(1)
    '''

    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [pow(self.fact[i] ,MOD - 2 ,MOD) for i in range(n + 1)]
        self.MOD = MOD

    def factorial(self, k):
        '''k!を求める'''
        return self.fact[k]

    def inverse_factorial(self, k):
        '''k!の逆元を求める'''
        return self.inv_fact[k]

    def combination(self, k, r):
        '''kCrを求める'''
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD


n, a, b, k = map(int, input().split())
MOD = 998244353
comb = Combination(n, MOD)
ans = 0
for i in range(n+1):
    if not(k - a*i >= 0 and (k - a*i) % b == 0 and (k - a*i) // b <= n):
        continue
    else:
        ai = i
        bi = (k - a*i) // b
        ans += comb.combination(n, ai) * comb.combination(n, bi)
        ans %= MOD
print(ans)


Measured memory_bytes: 64992
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class CR
{
    public static string Get() { return Console.ReadLine(); }
    public static IEnumerable<string> GetTexts() { return Console.ReadLine().Split(' '); }
    public static int GetInteger() { return int.Parse(Console.ReadLine()); }
    public static IEnumerable<long> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)); }
}

namespace AtCoderBeginnerContest
{
    internal class Program
    {
        public static long A { get; private set; }
        public static long B { get; private set; }
        public static long K { get; private set; }

        private static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.WriteLine(r); }

        private static object GetResult()
        {
            var inputs = CR.GetIntegers().ToList();
            A = inputs[0];
            B = inputs[1];
            K = inputs[2];

            Do();

            return $"{A} {B}";
        }

        private static void Do()
        {
            if (A > 0)
            {
                if (A > K)
                {
                    A -= K;
                    return;
                }
                else
                {
                    K -= A;
                    A = 0;
                }
            }
            
            if (B > 0)
            {
                if (B > K)
                {
                    B -= K;
                    return;
                }
                else
                {
                    K -= B;
                    B = 0;
                }
            }
        }
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p[][] = new int[10][10];
		for(int i=1;i<=n;i++) {
			String s = Integer.toString(i);
			int l = s.charAt(0)-'0';
			int r = s.charAt(s.length()-1) - '0';
			p[r][l]++;
		}
		long ans = 0;
		for(int i=0;i<10;i++) {
			for(int j=0;j<10;j++) {
				ans += p[i][j] * p[j][i];
			}
		}
		System.out.println(ans);
	}
 
}

Measured memory_bytes: 31828
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define dbg(x) cerr << #x << ":" << x << " "
#define dbgl(x) cerr << #x << ":" << x << "\n"
#define dbgv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbgvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	int n; cin >> n;
	vi S(n); rep(i, n) cin >> S.at(i);
	int q; cin >> q;
	vi T(q); rep(i, q) cin >> T.at(i);
	int ans = 0;
	for (int Ti : T) if(upper_bound(all(S), Ti) - lower_bound(all(S), Ti)) ans++;
	cout << ans << endl;
}


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

#define int long long

auto main() -> signed {
    int n, a, b;
    cin >> n >> a >> b;
    int mx = a+(n-1)*b;
    int mn = (n-1)*a+b;
    if(mx-mn+1<=0) cout << 0 << endl;
    else
        cout << mx - mn+1 << endl;
    return 0;
}



Measured memory_bytes: 256
let n = stdin.ReadLine() |> int
let s = stdin.ReadLine()
let front = [for i in 0..(n-1) do yield s.[i]]
let back = [for i in 0..(n-1) do yield s.[2 * n - 1 - i]]
let modulo = 1000000007L

let rec f ls acc baisu =
 match ls with
 | [] -> (acc,baisu)
 | hd :: tl -> match hd with
               | 'B' -> if (acc % 2 = 0 && acc >= 0) then f tl (acc + 1) baisu
                        elif (acc % 2 = 1 && acc >= 0) then f tl (acc - 1) (acc :: baisu)
                        else f [] -1 [0]
               | _ -> if (acc % 2 = 1 && acc >= 0) then f tl (acc + 1) baisu
                      elif (acc % 2 = 0 && acc >= 0) then f tl (acc - 1) (acc :: baisu)
                      else f [] -1 [0]

let (front_acc,front_baisu) = f front 0 []
let (back_acc,back_baisu) = f back 0 []

let g(x)= x % modulo

let kaijo y =
 let y_64 = int64 y
 let rec kaijo_pre x accc = (if x <= 1L then accc else kaijo_pre (x - 1L) (g(g(x) * accc)))
 kaijo_pre y_64 1L

let tyukan = if (front_acc >= 0 && front_acc = back_acc) then kaijo front_acc else 0L

let seki ls =
 let rec seki_pre ls acccc =
  match ls with
  | [] -> acccc
  | hd :: tl -> seki_pre tl (g(g(int64 hd) * acccc))
 seki_pre ls 1L

let front_seki = seki front_baisu
let back_seki = seki back_baisu

g(g(g(front_seki * back_seki) * tyukan) * (kaijo n))
|>stdout.WriteLine

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

#define ll long long

using namespace std;

vector<ll>v;
vector<ll>v2;

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

	ll n; cin >> n;

	v.push_back(0);
	v.push_back(1);
	v2.push_back(0);
	v2.push_back(-2);

	ll endd = 2147483648LL;
	set<ll>st;

	for (ll i = 4; i <= endd; i *= 4) {
		int j = v.size();
		for (int k = 0; k < j; k++) {
			v.push_back(v[k] + i);
			v2.push_back((v[k] + i) * -2LL);
		}
	}

	for (int i = 0; i < v2.size(); i++)
		st.insert(v2[i]);

	for (int I = 0; I < v.size(); I++) {
		ll tg = n - v[I];
		if (st.find(tg) == st.end()) continue;

		int ans[50] = { 0 };

		for (ll i = 1, j = 0; j <= 45; i *= 4LL, j+=2) {
			if ((i&v[I]) > 0) ans[j] = 1;
		}

		for (ll i = 2, j = 1; j <= 45; i *= 4LL, j+=2) {
			if (((-tg)&i) > 0) ans[j] = 1;
		}

		int flag = 0;

		for (int i = 45; i >= 0; i--) {
			if (ans[i] == 1) flag = 1;
			if (flag == 1) cout << ans[i];
		}
		if (flag == 0) cout << "0";

		return 0;
	}
	cout << 0;

	return 0;
}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

const int N = 2e3 + 10;

int n, x, y;
int ans;

int dp[N];

vector <int> adl[N];

bool vis[N];
void bfs(int awal){
    fill(vis, vis + n + 2, 0);
    queue <pair<int, int>> qu; // node, dist
    
    qu.push(mp(awal, 0));

    while (!qu.empty()){
        auto fr = qu.front();
        qu.pop();
        if (vis[fr.fi]) continue;
        // cout << fr.fi << " " << fr.se << el;
        dp[fr.se]++;
        vis[fr.fi] = 1;

        // cout << "tetangga => ";
        for (auto x : adl[fr.fi]){
            if (vis[x]) continue;
            // cout << x << " ";
            qu.push(mp(x, fr.se + 1));
        }
        // cout << el;
    }
}

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

    cin >> n >> x >> y;
    for (int i=1;i<n;i++){
        adl[i].pb(i + 1);
        adl[i + 1].pb(i);
    }
    adl[x].pb(y);
    adl[y].pb(x);

    for (int i=1;i<=n;i++){
        bfs(i);
    }
    for (int i=1;i<n;i++){
        cout << dp[i] / 2 << el;
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
string s;
cin>>s;
ll sum=0;
for(ll i=0;i<s.size();i++)
{
    s[i]=s[i]-48;
    sum+=s[i];
    //cout<<sum<<endl;
    //i++;
}
//cout<<sum<<endl;
if(sum%9==0)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3740
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		while(1>0){
			int n=sc.nextInt();
			if(n==0)break;
			int[] d;
			d=new int[n];
			for(int i=0;i<n;i++)d[i]=sc.nextInt();
			Arrays.sort(d);
			int sum=0;
			for(int i=1;i<n-1;i++)sum+=d[i];
			sum/=(n-2);
			System.out.printf("%d\n",sum);
		}
	}
}

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

int N,K,arr[50],zero;

int main(){
  cin >> N >> K;
  for (int i=0;i<N;i++){
    cin >> arr[i];
  }
  sort(arr,arr+N);
  cout << accumulate(arr+N-K,arr+N,zero);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    string s,t;
    cin>>s>>t;
    vector<vector<pair<int,pii>>> dp(s.length(),vector<pair<int,pii>>(t.length(),{0,{-1,-1}}));
    if(s[0]==t[0]) dp[0][0]={1,{0,0}};
    for(int i=0; i<s.length(); i++){
        for(int j=0; j<t.length(); j++){
            if(i+j==0) continue;
            if(i>0 && dp[i][j].ff<dp[i-1][j].ff) dp[i][j]=dp[i-1][j];
            if(j>0 && dp[i][j].ff<dp[i][j-1].ff) dp[i][j]=dp[i][j-1];
            if(s[i]==t[j]){
                if(i>0 && j>0) dp[i][j].ff=dp[i-1][j-1].ff+1;
                else dp[i][j].ff=1;
                dp[i][j].ss={i,j};
            }
        }
    }
    pii now={s.length()-1,t.length()-1};
    string answer;
    while(now.ff!=-1 && now.ss!=-1){
        now=dp[now.ff][now.ss].ss;
        if(now.ff==-1 || now.ss==-1) break;
        answer+=s[now.ff];
        now.ff-=1;
        now.ss-=1;
    }
    reverse(answer.begin(),answer.end());
    cout<<answer;

    return 0;
}


Measured memory_bytes: 108748
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	while (cin >> n&&n) {
		long long member[4001] = {};
		bool flag[4001] = {};
		for (int i = 1; i <= 4000; i++) {
			member[i] = 0;
			flag[i] = false;
		}
		long long a, b, c;
		int count = 0;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			member[a] += b*c;
			if (member[a] >= 1000000&&!flag[a]) {
				count++;
				flag[a] = true;
				cout << a << endl;
			}
		}
		if (count == 0)cout << "NA" << endl;
	}
}

Measured memory_bytes: 3128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        s = s.replaceAll("0", "");
        System.out.println(s.length());
//        int ans  = 0;
//        for (char a: s.toCharArray()){
//        	if (a == '1'){
//        		ans ++;
//        	}
//        }
//        System.out.println(ans);
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
int main(){
  long double N, K, ans=0;
  cin >> N >> K;
  int count=0, n=N;
  while(K>0.5){
    long double sub=K+0.9999999999, temp=0;
    int k=(int)sub;
//    cout<<"k:"<<k<<" n:"<<n<<" count:"<<count<<endl;
    if(n>=k){
      temp+=(n-k+1)/N;
      for(int i=0; i<count; i++){
        temp/=2;   
      }
      n-=(n-k+1);  
    }
    ans+=temp;
//    cout<<"temp:"<<temp<<" ans:"<<ans<<endl;
    K/=2;
//    cout<<" K:"<<K<<endl;
    count++;
  }
  cout <<setprecision(20)<< ans << endl;
}

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

using namespace std;
int main(){
	string s;
	int a;
	int b = 0;
	int c = 0;
	cin >> a;
	cin >> s;
	for (int i = 0; i < s.size(); i++){
		if(s[i] == 'I'){
			b = b + 1;
		}
		if(s[i] == 'D'){
			b = b - 1;
		}
		if(b > c){
			c = b;
		}
	}
	
	cout << c << endl;
	return 0;
}



Measured memory_bytes: 256
using System;

public class Program
{
    public static void Main()
    {
        var inputs = Console.ReadLine().Split(" ");
        var x = int.Parse(inputs[0]);
        var y = int.Parse(inputs[1]);
        
        if((y - 2 * x >= 0) &&
           (y - 2 * x) % 2 == 0 &&
           (y - 4 * x <= 0))
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 27532
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int L, cop;
    cin >> L;
    cop = L;
    cout << 20 << ' ';
    int kol = 19;

    int P = 0;
    for (int i = 0; i < 20; i++)
        if (((1 << i) & cop) != 0 && (((1 << i) & (cop - 1)) != 0)) P = (1 << i);
    for (int i = 0; i < 19; i++)
        if ((1 << i) < cop && (1 << i) != P) kol++;
    cop -= (1 << (kol - 19));

    if (cop != 0)
    {
        int cop1 = cop;
        for (int i = 19; i > 0; i--)
            if ((1 << (i - 1)) <= cop) kol++, cop -= (1 << (i - 1));
        cout << kol << '\n';
        for (int i = 1; i < 20; i++)
            cout << i << ' ' << i + 1 << ' ' << 0 << '\n';
        for (int i = 0; i < 19; i++)
            if ((1 << i) < L && (1 << i) != P) cout << i + 1 << ' ' << i + 2 << ' ' << (1 << i) << '\n';
        for (int i = 19; i > 0; i--)
            if ((1 << (i - 1)) <= cop1) cout << i << ' ' << 20 << ' ' << L - (1 << (i - 1)) << '\n', cop1 -= (1 << (i - 1)), L -= (1 << (i - 1));
    }
    else
    {
        cout << kol << '\n';
        for (int i = 1; i < 20; i++)
            cout << i << ' ' << i + 1 << ' ' << 0 << '\n';
        for (int i = 0; i < 19; i++)
            if ((1 << i) < L && (1 << i) != P) cout << i + 1 << ' ' << i + 2 << ' ' << (1 << i) << '\n';
    }
    return 0;
}



Measured memory_bytes: 256
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define debug(x)			{ cerr << #x << " = " << x << endl; }
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define vi					vector<int>
#define vii					vector<vi>
#define mid(s,e)			(s+(e-s)/2)

using namespace std;

int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	int n,d;
	cin>>n>>d;
	int x[11][11];
	for(int i=0; i<n; i++){
		for(int j=0; j<d; j++) {
			cin>>x[i][j];
		}
	}
	int ans = 0;
	for(int i=0; i<n; i++) {
		for(int j=i+1;j<n; j++) {
			double dis = 0;
			for(int k=0; k<d; k++) {
				dis += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
			
			}	
			if(sqrt(dis) == (int)sqrt(dis)) {
				ans++;
			}
		}
	
	}
	cout<<ans;
	return 0;
}



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

int main(){
    long long  N;
    long long K;
    cin >> N >> K;
    map<long long , long long> mp;
    long long  a,b;                                                                                                                                                                                         
    for(int i=0; i<N;i++){
        cin >> a >> b;
        if(mp.find(a) == mp.end()){
            mp[a] = b;
        }else{
            mp[a] += b;
        }   
    }   

    long long sum = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        sum += itr->second;
        if(sum >= K){ 
            cout << itr->first << endl;
            return 0;
        }   
    }   
    return 0;
}

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

struct Data {
    int x, y, z;
    ll p;
};

bool searched[1000][1000][1000];

int main()
{
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    ll A[X], B[Y], C[Z];
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];

    sort(A, A + X, greater<ll>());
    sort(B, B + Y, greater<ll>());
    sort(C, C + Z, greater<ll>());

    auto compare = [](const Data& d1, const Data &d2) {
        return d1.p < d2.p;
    };

    vector<ll> answers;
    priority_queue<Data, vector<Data>, decltype(compare)> queue(compare);
    queue.push({0, 0, 0, A[0] + B[0] + C[0]});

    while (queue.size() > 0) {
        Data d = queue.top();
        queue.pop();

        if (searched[d.x][d.y][d.z]) {
            continue;
        }
        searched[d.x][d.y][d.z] = true;
        answers.push_back(d.p);
        if (answers.size() == K) {
            break;
        }

        if (d.x < X - 1) {
            ll aa = A[d.x + 1] + B[d.y] + C[d.z];
            queue.push({d.x + 1, d.y, d.z, aa});
        }
        if (d.y < Y - 1) {
            ll aa = A[d.x] + B[d.y + 1] + C[d.z];
            queue.push({d.x, d.y + 1, d.z, aa});
        }
        if (d.z < Z - 1) {
            ll aa = A[d.x] + B[d.y] + C[d.z + 1];
            queue.push({d.x, d.y, d.z + 1, aa});
        }
    }
    rep (i, K) {
        cout << answers[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 973440
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))


N = int(input())
ans = 10 ** 12
for i in range(1, math.ceil(N**0.5)+1):
    if N / i == N // i:
        # print(i, N // i)
        ans = min(ans, i + N // i - 2)
print(ans)


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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
	if (l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve() {
	pos = 0;
	rec(0, pre.size());
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << post[i];
	}
	cout << endl;
}

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

	for (int i = 0; i < n; i++) {
		cin >> k;
		pre.push_back(k);
	}

	for (int i = 0; i < n; i++) {
		cin >> k;
		in.push_back(k);
	}

	solve();

	return 0;
}


Measured memory_bytes: 3164
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Builder     as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Internal    as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import qualified System.IO                   as IO
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    xs <- U.unfoldr parseInt <$> C.getLine
    ys <- U.unfoldr parseInt <$> C.getLine
    print $ solve n xs ys

solve :: Int -> U.Vector Int -> U.Vector Int -> Int
solve n xs ys = go 0 0 (U.toList ys) (U.toList xs)
  where
    go !res !carry (x:xs) (m:ms)
        | m <= carry = go (res + m) x xs ms
        | z <- min m (x + carry) = go (res + z) (x - (z - carry)) xs ms
    go res carry [] [m] = res + min carry m

-------------------------------------------------------------------------------
type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

Measured memory_bytes: 5628
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
	int x,y,id;
}a[200010];
struct edge
{
	int u,v,d;
	bool operator < (const edge &e) const
	{
		return d<e.d;
	}
}g[300010];
int cmpx(node a,node b)
{
	return a.x<b.x;
}
int cmpy(node a,node b)
{
	return a.y<b.y;
}
int n,m,fa[200010];
int find(int x)
{
	return x==fa[x]?x:fa[x]=find(fa[x]);
}
int main()
{
	int ans=0;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		fa[i]=i;
		scanf("%d%d",&a[i].x,&a[i].y);
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmpx);
	for (int i=1;i<n;i++) g[++m]=(edge){a[i].id,a[i+1].id,a[i+1].x-a[i].x};
	sort(a+1,a+n+1,cmpy);
	for (int i=1;i<n;i++) g[++m]=(edge){a[i].id,a[i+1].id,a[i+1].y-a[i].y};
	sort(g+1,g+m+1);
	for (int i=1;i<=m;i++)
		if (find(g[i].u)!=find(g[i].v))
		{
			ans+=g[i].d;
			fa[fa[g[i].u]]=fa[g[i].v];
		}
	printf("%d\n",ans);
}


Measured memory_bytes: 5888
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);
  int[] b; readA(n, b);

  auto r = 0;
  foreach (k; 0..29) {
    auto t = 2^^k;
    auto am = a.map!(ai => ai%(t*2)).array;
    auto bm = b.map!(bi => bi%(t*2)).array;
    auto bs = bm.sort(), c = 0;
    foreach (ai; am)
      (c += bs.lowerBound(t*2-ai).length - bs.lowerBound(t-ai).length + bs.lowerBound(t*4-ai).length - bs.lowerBound(t*3-ai).length) %= 2;
    if (c) r = r.bitSet(k);
  }

  writeln(r);
}

pragma(inline) {
  pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }
  pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }
  pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }
  pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }

  pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
  pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }
  pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }

  import core.bitop;
  pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }
  pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }
  pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }
}


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

#define fori( tt,aa)      for(int i= tt; i<aa; i++)
#define forj( yy,bb)      for(int j=yy; j<bb; j++)
#define fork( uu,cc)      for(int k=uu; k<cc; k++)
#define all(v)   v.begin(), v.end()
#define endl "\n";
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define EPS 1e-7
#define F first
#define S second
#define JULEE_DO_THE_THING fast()
#define to_str to_string
#define isOdd(n)    (n&1)
#define sc scanf
#define print printf
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMIN INT_MIN
#define IMAX INT_MAX

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string String;
typedef string str;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef pair<int, int> pii;

void fast(){
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(0);
}

ll numOfDigits(ll n);
bool compare(int &a, int &b){
    return a>b;
}

ll pow (ll a, ll b);

dd BN (vector<pii> &v, ll n, ll m);



dd sum(dd mid){
    return ((dd)mid/2)*(mid+1);
}
int  N, M, NUM, mn = IMAX;
#define MAX 1000000
bool visited[15][102];
bool arr[15][102];

bool valid(int r, int c){//if not out of the bounds
    if(r>=N || r<0) return 0;
    if(c>=M || c<0) return 0;
    return 1;
}
void countReachable(int r, int c, int cnt, int i){
    //if out of bounds || visited before
    if(!valid(r, c) || visited[r][c])
        return;

    visited[r][c] = 1; //mark as visited

    if(i==NUM) {mn = min(mn, cnt); return;}
    //try 4 moves
    countReachable(r,c+1, cnt+1, i+arr[r][c]);//right

    countReachable(r,c-1, cnt+1, i+arr[r][c]);//left

    countReachable(r+1,c, cnt+1, i+arr[r][c]);//up
    visited[r][c] = 0;
    countReachable(r-1,c, cnt+1, i+arr[r][c]);//down
    visited[r][c] = 0;

}

int main()
{
    JULEE_DO_THE_THING;
    //freopen("test cases\\.txt", "r", stdin) ;
    ll n; cin>>n;
    ll sum = 0;
    ll i=0;
    while(n){
        n/=2;
        sum+=pow(2, i);
        i++;
    }
    cout<<sum;
    return 0;
}


dd BN (vector<pii> &v, ll n, ll m){
dd low = 0;
dd up = 1e21;
dd ans = 0;
while(low<=up){
    dd mid = trunc((low+ up)/2);
    dd fx = 0;
    fori(0, n){
        fx += max(0.0, mid-v[i].F)*v[i].S;
    }
    if(fx<=m) {
        ans = mid;
        low = mid+1;
    }else up = mid-1;
}
return ans;
}

ll pow (ll a, ll b){
    ll pow = 1;
    fori(0,b)
        pow *=a;
    return pow;
}
ll numOfDigits(ll n){
    if(!n) return 1;
    return (ll)(log10(n)+1);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a,b,t,count = 0;
    cin >> a >> b >> t;

    for(int i = 1;i <= t;i++){
        if(i % a == 0){
            count += b;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static int a,b,c;

    public static void main(String[] args){
        input();
        solve();
    }

    private static void solve() {
        if (a + b == c || a + c == b || b + c == a)
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    private static void input() {
        Scanner scanner = new Scanner(System.in);
        a = scanner.nextInt();
        b = scanner.nextInt();
        c = scanner.nextInt();
    }
}


Measured memory_bytes: 9804
#include<iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    int L[N];
    for(int i = 0; i < N; i++) cin >> L[i];
    int j = 1;
    int s = 0;
    for(int i = 0; i < N; i++) s += L[i];
    for(int i = 0; i < N; i++){
        if(L[i] >= s - L[i]){
            j = 0;
            break;
        }
    }
    if(j == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (int)(n) ; i++)

void solve(long long N, vector<long long> d){
	set<long long> w(d.begin(),d.end());
	cout << w.size() << endl;	
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> d(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&d[i]);
	}
	solve(N, d);
	return 0;
}



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 main(){
  char s[105];
  int k;
  int n;
  int i;

    scanf("%d", &k);
  scanf("%s", s);

  n = strlen(s);
  if(n <= k) printf("%s\n", s);

  else{
    for(i = 0;i < k;i++) printf("%c", s[i]);

    printf("...\n");
  }

  return 0;
}


Measured memory_bytes: 3764
#include <iostream>
using namespace std;
 
int main(){
   bool is_prime[1000000];
   is_prime[0]=is_prime[1]=false;
   for(int i=2;i<1000000;i++)
      is_prime[i]=true;
   for(int i=2;i*i<1000000;i++){
      if(is_prime[i]){
         for(int j=i*i;j<1000000;j+=i){
            is_prime[j]=false;
         }
      }
   }
   int n[1000000];
   int count=0;
   for(int i=0;i<1000000;i++){
      if(is_prime[i])
         count++;
      n[i]=count;
   }
   while(true){
      int x;
      cin >> x;
      if(cin.eof())
         break;
      cout << n[x] << endl;
   }
    
   return 0;
}

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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
inline ll ii(){ ll x; cin >> x; return x; }
inline string is(){ string x; cin >> x; return x; }
inline ld id(){ ld x; cin >> x; return x; }
inline void oi(ll x){ cout << x; }
inline void od(ld x){ cout << fixed << setprecision(10) << x; }
inline void os(string x){ cout << x; }
inline void oe(){ cout << endl; }
inline void oie(ll x){ oi(x); oe(); }
inline void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll N=ii();
    oie(8-((N-400)/200));

    return 0;
}


Measured memory_bytes: 3632
n = int(input())
result = n
for x in range(n, 1000):
	k = []
	for _ in range(3):
		k.append(x%10)
		x//=10
	if k[0]==k[1]==k[2]:
		result = k
		break
result = "".join(str(x) for x in result)
print(result)

Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;

int main() {
	int n;
	cin >> n;
	bool flag = false;

	for (int i = 0; i < n; i++)
	{
		char s;
		cin >> s;
		if (s == 'Y') {
			flag = true;
			break;
		}
	}
	if (flag) cout << "Four" << endl;
	else cout << "Three" << endl;
	return 0;
}

Measured memory_bytes: 256
a = int(input())
if a == 1:
  print(3)
elif a == 2:
  print(14)
elif a == 3:
  print(39)
elif a == 4:
  print(84)
elif a == 5:
  print(155)
elif a == 6:
  print(258)
elif a == 7:
  print(399)
elif a == 8:
  print(584)
elif a == 9:
  print(819)
elif a == 10:
  print(1110)


Measured memory_bytes: 9008
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

size_t K;
std::string str;
std::vector<std::string> subs;

int main()
{
	std::cin >> str >> K;
	for (size_t i = 0; i < str.length(); i++)
		for (size_t len = 1; len <= K && i + len <= str.length(); len++)
			subs.push_back(str.substr(i, len));
	
	std::sort(subs.begin(), subs.end());
	std::unique(subs.begin(), subs.end());

	std::cout << subs[K - 1];
	return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mset(s,_) memset(s,_,sizeof s)
using namespace std;
vector<ll>v;
map<string, bool>mp;
void dfs(string s) {
	if (s.size() >= 10||mp[s]) return;
	mp[s] = 1;
	if (s.size() == 1) v.push_back(stoll(s));
	int c = s.size();
	int k = s[c - 1] - '0';
	for (int i = k - 1; i <= k + 1; i++) {
		if (i < 0||i>=10) continue;
		else {
			string l = s;
			l += to_string(i);
			if (mp[l])continue;
			ll d=stoll(l);
			v.push_back(d);
			dfs(l);
		}
	}
}
int main() {
	string s;
	for (int i = 1; i <= 9; i++) {
		s = to_string(i);
		dfs(s);
	}
	sort(v.begin(), v.end());
	unique(v.begin(), v.end());
	int k;
	while(cin >> k)
	cout << v[k-1]<<'\n';
}


Measured memory_bytes: 26352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
 
int n, m;
vector<int> g[55];
bool vis[55];
 
void dfs(int cur) {
	vis[cur] = true;
	FOR(i, g[cur].size()) {
		if (!vis[g[cur][i]]) dfs(g[cur][i]);
	}
}
 
bool check(int s, int t) {
	fill(vis, vis+n, false);
	vis[s] = true;
	FOR(i, g[s].size()) {
		if (g[s][i] == t) continue;
		dfs(g[s][i]);
	}
	return !vis[t];
}
 
int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	vector<pair<int, int> > p(m);
	FOR(i, m) {
		int u, v;
		cin >> u >> v;
		g[u-1].push_back(v-1);
		g[v-1].push_back(u-1);
		p[i] = {u-1, v-1};
	}
	int cnt = 0;
	FOR(i, m) {
		if (check(p[i].first, p[i].second)) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
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; }
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL << 60;

int main(){

  int a,b;cin>>a>>b;

  if(1<=a&&a<=9&&1<=b&&b<=9)out(a*b);
  else out(-1);

  return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin>>s;
  vector<LL> a(26, 0);
  REP(i,s.size()){
    a[s[i] - 'A']++;
  }
  bool flag = true;
  REP(i, a.size())
  {
    if(a[i]==1||a[i]==3||a[i]==4){
      flag = false;
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

a.sort()
ans = 0
while a[-1] >= n:
    k = -(-(a[-1]+1)//n)-1
    ans += k
    for i in range(n-1):
        a[i] += k
    a[-1] -= n*k
    a.sort()

print(ans)

Measured memory_bytes: 40556
#include<stdio.h>
int main()
{
    int a,b,c,d,e,f;
    scanf("%d%d%d",&a,&b,&c);
    d=a+b;
    e=b+c;
    f=c+a;
    if(d<=e&&d<=f)
        printf("%d",d);
    else if(e<=d&&e<=f)
        printf("%d",e);
    else if(f<=d&&f<=e)
        printf("%d",f);
    return 0;
}
//maliangdedidishimadan

Measured memory_bytes: 128
N = int(input())

A=[]
for i in range(N):
    a, b, c = map(int, input().split())
    A.append([a, b, c])

A.sort(key=lambda x:-x[2])

for x in range(0, 101):
    for y in range(0, 101):
        H = A[0][2]+abs(A[0][0]-x)+abs(A[0][1]-y)
        Flag = True
        for i in range(1, N):
            if A[i][2] > 0:
                    if H != A[i][2]+abs(A[i][0]-x)+abs(A[i][1]-y):
                        Flag = False
                        break
            else:
                if H > abs(A[i][0]-x)+abs(A[i][1]-y):
                    Flag = False
                    break
        if Flag == True:
            print(x, y, H)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int[] list = new int[N];
    for(int i = 0; i < N ; i++){
      list[i] = sc.nextInt();
    }
    
    int count = 0;
    int Max = 0;
    for(int i = 1; i < N ; i++){
     if(list[i-1] >= list[i]){
       count++;
       if(Max < count){
         Max = count;
       } 
     }else{
       if(Max < count){
         Max = count;
       }  
       count = 0;
     }
    }
   
     System.out.println(Max);  
   
  }
}

Measured memory_bytes: 59528
N, K = map(int, input().split())
N += 1
mod = 10**9+7

ans = 0
for i in range(N+1-K):
    nowk = K+i
    min_k = nowk*(nowk-1)//2
    max_k = (2*N-nowk-1)*nowk//2
    ans += (max_k-min_k+1)%mod
    ans %= mod
print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main(){
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    ll ans = 0;
    for(int i = 0; i < N; ++i){
        cin >> a[i];
        if(a[i] > x){
            ans += a[i] - x;
            a[i] = x;
        }
    }
    
    for(int i = 0; i < N - 1; ++i){
        int temp = a[i] + a[i + 1];
        if(temp > x){
            temp -= x;
            ans += temp;
            a[i + 1] -= temp;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	string s;
	cin >> s ;
	if (s.size()%2==1) {
		cout << "No"; return 0;
	}
	rep(i, s.size()) {
		if (i % 2 == 0 && s[i] != 'h') {
			cout << "No"; return 0;
		}

		if (i % 2 == 1 && s[i] != 'i') {
			cout << "No"; return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include<stdio.h>

int BubbleSort(int [],int n);

int main()
{
  int n;
  int i;
  int A[110];
  int cnt=0;

  while(scanf("%d",&n),n)
    {
      for(i=0;i < n;i++){
	scanf("%d",&A[i]);
      }
      
      cnt = BubbleSort(A,n);
      printf("%d\n",cnt);
    }
  return 0;
}

int BubbleSort(int A[],int n)
{
  int i,j;
  int cnt = 0;
  int temp;
  
  for(i=0;i < n;i++){
    for(j=n-1;j > i;j--){
      if(A[j-1] > A[j]){
	temp = A[j-1];
	A[j-1] = A[j];
	A[j] = temp;
	cnt++;
      }
    }
  }
  
  /*for(i=0;i < n;i++){
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  */
  return cnt; 
}


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

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

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

const int N = 300000 + 10;
const int MOD = 998244353;
const int LOG = 20;
const int INF = 1000000010;
const int delta = 11353;

int n, b[N], a[N], fac[N], cnt[N], L[N], R[N], l[N], r[N], mx[N], num[N], ps[N], C[N];
multiset<int> st;
vi vl[N], vr[N], koj[N];

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	fac[0] = 1;
	for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * 1ll * i % MOD;
	for (int i = 0; i < n; i++) cin >> b[i];
	int Fi = -1;
	for (int i = 0; i < n; i++){
		if (b[i] == 1 && Fi == -1) Fi = i;
	}
	if (Fi == -1) return cout << 0, 0;
	if (b[0] == 1 && b[n - 1] == 1){
		int cnt2 = 0;
		for (int i = 0; i < n; i++) if (b[i] == 1) cnt2++;
		if (cnt2 == n) return cout << fac[n], 0;
		for (int i = n - 1; i >= 0; i--){
			if (b[i] != 1){
				Fi = i + 1;
				break;
			}
		}
	}	
	for (int i = 0; i < n; i++){
		a[i + 1] = b[(i + Fi) % n];
		if (L[a[i + 1]] == 0) L[a[i + 1]] = i + 1;
		R[a[i + 1]] = i + 1;
		cnt[a[i + 1]]++;
	}
	//for (int i = 1; i <= n; i++) cout << a[i] << '\n';
	for (int i = 1; i <= n; i++) if(cnt[i] != 0 && R[i] - L[i] + 1!= cnt[i]) return cout << 0, 0;
	if (cnt[1] == 0) return cout << 0, 0;
	int d = cnt[1] - 1;
	for (int i = 1; i <= n; i++){
		vl[max(1, i - d)].pb(a[i]);
		vr[i].pb(a[i]);
	}	
	for (int i = 1; i <= n; i++){
		for (auto u:vl[i]) st.insert(u);
		mx[i] = *st.rbegin();
		for (auto u:vr[i]) st.erase(st.find(u));
		//cout << mx[i] << ' ';
		C[mx[i]] ++;
		koj[mx[i]].pb(i);
	}
	for (int i = 1; i <= n; i++) koj[i].pb(INF);
	memset(r, 31, sizeof r);
	for (int i = 1; i <= n; i++){
		l[a[i]] = max(l[a[i]], max(0, i - d));
		r[a[i]] = min(i, r[a[i]]);
	}
	int res = 1;
	for (int i = 1; i <= n; i++){
		ps[i] = ps[i - 1] + C[i];
		if (cnt[i] > 0){
			int kojj = lower_bound(all(koj[i]), l[i]) - koj[i].begin();
			int koj2 = upper_bound(all(koj[i]), r[i]) - koj[i].begin();
			res = res * 1ll * (max(0,koj2 - kojj)) % MOD;
		}else{
			res = res * 1ll * (max(0, ps[i] - i + 1)) % MOD;
		}
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 66136
n, m, l = map(int, input().split())

A = []
B = []

for i in range(n) :
    A.append([int(a) for a in input().split()])
    
for j in range(m) :
    B.append([int(b) for b in input().split()])

C = []
L = []
s = 0

for i in range(l) :
    for j in range(n) :
        for k in range(m) :
            s += A[j][k] * B[k][i]
        
        L.append(s)
        s = 0
    
    C.append(L[i * n : i * n + n])
        
for i in range(n) :
    for j in range(l) :
        if j == l - 1 :
            print(C[j][i])
        else :
            print(C[j][i], end = " ")
    


Measured memory_bytes: 7096
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0

for i in range(N):
  ans += B[A[i]-1]
  if 1 <= i and A[i]-A[i-1] == 1:
    ans += C[A[i-1]-1]
print(ans)

Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>

using lli = long long int;
int inf = 1000000007;
using namespace std;

int N, M;
int u, v;
int S, T;

int main()
{
	cin >> N >> M;
	vector<vector<int>> G(3 * N + 1);
	vector<int> cost(3 * N + 1, -3);
	for (int i = 0; i < M; i++) {
		cin >> u >> v;
		G[u].push_back(v + N);
		G[u + N].push_back(v + 2 * N);
		G[u + 2 * N].push_back(v);
	}
	cin >> S >> T;
	queue<int> q;
	q.push(S);
	cost[S] = 0;
	while (q.size() != 0) {
		int now = q.front();
		q.pop();
		for (auto e : G[now]) {
			if (cost[e] == -3) {
				cost[e] = cost[now] + 1;
				q.push(e);
			}
		}
	}
	cout << cost[T] / 3 << endl;
	return 0;
}

Measured memory_bytes: 17792
#include <stdio.h>
#include <string.h>

char S[30];
int cnt[26];

int main(){

	scanf("%s",S);

	int len=strlen(S);

	int i;

	for(i=0;i<len;i++){
	cnt[S[i]-'a']++;
	}

	int flag=0;

	for(i=0;i<26;i++){
		if(cnt[i]>1){flag=1;}
	}
	if(flag==0){printf("yes\n");}
	else{printf("no\n");}

return 0;
}

Measured memory_bytes: 128