akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <cassert>
#include <unordered_map>
#include <numeric>

using namespace std;


class Solution{

private:
    const int MOD = 1e9 + 7;
    int N, X, Y, Z;
    vector<vector<int>> dp;

public:
    int num(int N, int X, int Y, int Z){

        this->N = N, this->X = X, this->Y = Y, this->Z = Z;

        long long res = 1ll;
        for(int i = 0; i < N; i ++) res *= 10ll, res %= MOD;

        dp = vector<vector<int>>(N, vector<int>(1 << (X + Y + Z), -1));
        res -= go(0, 0);
        if(res < 0) res += MOD;
        return res;
    }

private:
    int go(int index, int state){

        if(index == N) return 1;
        if(dp[index][state] != -1) return dp[index][state];

        int res = 0;
        for(int i = 1; i <= 10; i ++){
            int nextstate = ((state << i) + (1 << (i - 1))) & ((1 << (X + Y + Z)) - 1);
            if(!(nextstate & (1 << (Z - 1))) || !(nextstate & (1 << (Y + Z - 1))) || !(nextstate & (1 << (X + Y + Z - 1))))
                res += go(index + 1, nextstate), res %= MOD;
        }
        return dp[index][state] = res;
    }
};

int main() {

//    printf("%d\n", Solution().num(3, 5, 7, 5));
//    // 1
//
//    printf("%d\n", Solution().num(4, 5, 7, 5));
//    // 34
//
//    printf("%d\n", Solution().num(37, 4, 2, 3));
//    // 863912418
//
//    printf("%d\n", Solution().num(40, 5, 7, 5));
//    // 562805100

    int N, X, Y, Z;
    scanf("%d%d%d%d", &N, &X, &Y, &Z);
    printf("%d\n", Solution().num(N, X, Y, Z));

    return 0;
}


Measured memory_bytes: 23976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )
#define SORT(x) sort(x.begin(), x.end())

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


int ans = 0, N;

void dfs(ll x, ll mask) {
    if (x > N) return;
    if (mask == 7) ans++;
    dfs (x * 10 + 3, mask | 1);
    dfs (x * 10 + 5, mask | 2);
    dfs (x * 10 + 7, mask | 4);
}

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

    cin >> N;
    dfs(0, 0);
    COUT(ans);
}

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

struct edge {
	int u, v, w;
};

vector <edge> ans;

void add(int a, int b, int c) {
	ans.push_back({a, b, c});
}

int main() {
	int L;
	scanf("%d", &L);
	
	int N = 0;
	for (; 1 << N + 1 <= L; N++) {
		add(N, N + 1, 0);
		add(N, N + 1, 1 << N);
	}
	
	L -= 1 << N;
	
	int curr = 1 << N;
	for (int i = 0; i < N; i++)
		if (L >> i & 1) {
			add(i, N, curr);
			curr += 1 << i;
		}
	
	printf("%d %d\n", N + 1, ans.size());
	for (auto it : ans)
		printf("%d %d %d\n", it.u + 1, it.v + 1, it.w);
			
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>

using namespace std;

#define N 100008
#define INF 0x3f3f3f3f

int n;
int dp[N], v[N], p[N];

int dfs(int s)
{
    if (!s) return 0;
    if (dp[s] != INF) return dp[s];
    for (int i = 0; i <= 15; i++)
    {
        for (int j = 0; j <= 15; j++)
        {
            if (i == j) continue;
            if ((s & p[i]) && (s & p[j]))
            {
                int temp = i ^ j;
                if (p[temp] & s)
                    dp[s] = min(dp[s], dfs(s^p[temp]^p[i]^p[j])+2);
                else
                    dp[s] = min(dp[s], dfs(s^p[temp]^p[i]^p[j])+1);
            }
        }
    }
    return dp[s];
}

int main()
{
    int x, y, z;
    p[0] = 1;
    for (int i = 1; i <= 20; i++)
        p[i] = p[i-1] * 2;
    while (~scanf("%d", &n))
    {
        memset(v, 0, sizeof(v));
        memset(dp, 0x3f, sizeof(dp));
        for (int i = 1; i < n; i++)
        {
            scanf("%d%d%d", &x, &y, &z);
            v[x+1] ^= z;
            v[y+1] ^= z;
        }
        int start = 0, ans = 0;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == 0) continue;
            if (start & p[v[i]])
                ans++;
            start ^= p[v[i]];                
        }
        ans += dfs(start);
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

#include<string>
using namespace std;
char q[666][300];
string ans;
string s[666];
int n;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        for(int j=0;j<s[i].size();j++){
            q[i][(int)s[i][j]-'a']++;
        }
    }
    for(int i=0;i<26;i++){
        int num=2e9;
        for(int j=0;j<n;j++){
            if(num>q[j][i]){
                num=q[j][i];
            }
        }
        for(int j=0;j<num;j++){
            ans+=(char)('a'+i);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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


int main() {
    string N;
    cin >> N;
    if (N[0]==N[1]) {
        cout << "Bad" << endl;
    }else if (N[1]==N[2]) {
        cout << "Bad" << endl;
    }else if (N[2]==N[3]) {
        cout << "Bad" << endl;
    }else {
        cout << "Good" << endl;
    }
}

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

int main() {
  long n,m,x,ans=999999999999;
  cin >> n >> m >> x;
  vector<long> c(n);
  vector<vector<long>> a(n,vector<long>(m));
  for(long i=0;i<n;i++) {
    cin >> c[i];
    for(long j=0;j<m;j++) cin >> a[i][j];
  }
  for(long bit=0;bit<(1<<n);bit++) {
    vector<long> rikai(m);
    long aaa=0;
    for(long i=0;i<n;i++) {
      if(bit&(1<<i)) {
        for(long j=0;j<m;j++) {
          rikai[j]+=a[i][j];
        }
        aaa+=c[i];
      }
    }
    for(long i=0;i<m;i++) {
      if(rikai[i]<x) break;
      if(i+1==m) ans=min(ans,aaa);
    }
  }
  if(ans==999999999999) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 3600
# coding: UTF-8
# sample code

v = list(map(int, input().split()))
n, m = v[0], v[1]

l, r = [], []
for i in range(m):
	v = list(map(int, input().split()))
	l.append(v[0])
	r.append(v[1])

min = 1
max = n
for i in range(m):
	if l[i] > min:
		min = l[i]
	if max > r[i]:
		max = r[i]

num = max-min+1
if num < 0:
	print(0)
else:
	print(num)

Measured memory_bytes: 11072
#include <algorithm>
#include <string.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9 + 7;
const int N = 3e5 + 10;
ll x[N], p[64], sum1[N], sum0[N];
int main()
{
    p[0] = 1;
    for (int i = 1; i <= 63; i++)
        p[i] = (p[i - 1] * 2ll) % mod;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> x[i];
    ll ans = 0;
    for (int i = 0; i < 63; i++)
    {
        memset(sum1, 0, sizeof(sum1));
        memset(sum0, 0, sizeof(sum0));
        for (int j = n; j >= 1; j--)
        {
            sum1[j] = sum1[j + 1];
            sum0[j] = sum0[j + 1];
            if ((x[j] >> i) & 1)
                sum1[j]++;
            else
                sum0[j]++;
            if ((x[j] >> i) & 1)
                ans = (ans + (sum0[j + 1] * p[i]) % mod) % mod;
            else
                ans = (ans + (sum1[j + 1] * p[i]) % mod) % mod;
        }
    }
    cout << ans % mod << endl;
    return 0;
}


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

using namespace std;

int main(){
    int A,B,C;

    scanf("%d%d%d",&A,&B,&C);
    if(A==B)
        printf("%d\n",C);
    else if(B==C)
        printf("%d\n",A);
    else
        printf("%d\n",B);
                
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
  int N, L;
  cin >> N >> L;
  int sum = 0;
  for (int i = 1; i <= N; i++) {
	  sum += L + i - 1;
	}
  int eat = abs(L) < abs(L + N - 1) ? L : L + N - 1;
  if (L * (L + N - 1) < 0) {
	  eat = 0;
	}
  cout << sum - eat << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var w string
	fmt.Scan(&w)

	list := map[string]int{}
	for _, c := range w {
		list[string(c)]++
	}

	result := "No"
	for _, v := range list {
		if v%2 == 0 {
			result = "Yes"
		} else {
			result = "No"
			break
		}
	}
	fmt.Println(result)

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1; while(t--) solve()
 
void solve(){
    int n, ans = 0; cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                int gd = 0;
                gd = __gcd(i, j);
                gd = __gcd(gd, k);
                ans += gd;
            }
        }
    }
    cout<<ans<<endl;
}
 
signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST; return 0;
}

Measured memory_bytes: 3652
ABCD = list(map(int,input().split()))

while True:
    ABCD[2] = ABCD[2] - ABCD[1]
    if ABCD[2] <= 0:
        print("Yes")
        break

    ABCD[0] = ABCD[0] - ABCD[3]
    if ABCD[0] <= 0:
        print("No")
        break

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)(1e9+1)
#define MOD (long long)(1e9+7)
#define INF64 (long long)(1e18+1)

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

llint my_binary_search(llint ary[], llint key, llint left, llint right);




int main (void)
{
  //INPUT
  llint N,M;
  cin >> N >> M;
  char S[N+1];
  rep(i,0,N+1) {
    cin >> S[i];
  }

  //SOLVE
  vector<llint> ans;
  llint ng_f = 0;
  for(llint i=N; i>0;) {
    // cout << "i" << i << endl;
    for(llint j=i-M; j<i; j++) {
      if (j<0)  j=0;

      if(S[j] == '0') {
        // cout << "j" << j << endl;
        ans.push_back(i-j);
        i = j;
        break;
      } else {
        if (j==(i-1)) {
          ng_f = 1;
          break;
        }
      }
    }

    if (ng_f == 1)  break;
  }

  //OUTPUT
  if (ng_f == 0) {
    for(llint i=ans.size()-1; i>=0; i--) {
      cout << ans[i];
      if (i!=0) {
        cout << " ";
      }
    }
  } else {
    cout << "-1";
  }
  cout << endl;

  return 0;
}






llint my_binary_search(llint ary[], llint key, llint left, llint right) {
  llint middle;
  if (right < left) {
      return -(INF64);
  } else {
      middle = left + (right - left) / 2;
      if (ary[middle] > key) {
          return my_binary_search(ary, key, left, middle - 1);
      } else if (ary[middle] < key) {
          return my_binary_search(ary, key, middle + 1, right);
      } else {
          return middle;
      }
  }
}


Measured memory_bytes: 1528
#include <stdio.h>

int main(void){
  char S[10] = {};
  int num = 0;
  int i, j, k;
  scanf("%s", S);
  for(i = 0; i < 4; i++){
    if(S[i] == '+'){
      num++;
    }else{
      num--;
    }
  }
  printf("%d\n", num);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
using namespace std;
int main(void){
    int h,w;
    cin>>h>>w;
    int c[10][10];
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>c[i][j];
        }
    }
    int a[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<1000;i++){
        for(int j=0;j<10;j++){
            for(int k=0;k<10;k++){
                for(int l=0;l<10;l++){
                    c[j][k]=min(c[j][k],c[j][l]+c[l][k]);
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]!=-1)ans+=c[a[i][j]][1];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;



public class Main {


	public static void main (String[] args)  {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		long k = sc.nextLong();
		
		if (k%2==0) {
			System.out.println(calc(s+s)+(k-2)/2*(calc(s+s+s+s)-calc(s+s)));
		} else {
			System.out.println(calc(s)+(k-1)/2*(calc(s+s+s)-calc(s)));
		}
		
	}
	
	public static long calc (String s) {
		int n = s.length();
		int count = 0;
		boolean change = false;
		for (int i=0;i<n-1;i++) {
			if (change) {
				change=false;
			}else if (s.charAt(i)==s.charAt(i+1)) {
				count++;
				change=true;
			}
		}
		return count;
	}



}

Measured memory_bytes: 23124
///╔══╗
///╚╗╔╝
///╔╝╚(¯`v´¯)
///╚══╝`.¸.´farzin


#include <bits/stdc++.h>

#define int int64_t
#define pb push_back
#define ibsws ios_base::sync_with_stdio
#define gcd __gcd
#define S second
#define F first

using namespace std;

int a,b,c;

int32_t main(){
	ibsws(true==false);
    cin>>a>>b>>c;
    if(c>=a && c<=b){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include <vector>

using namespace std;


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

    // 昇順
    //sort(a.begin(), a.end());

    // 降順
    // sort(a.begin(), a.end(), [](const int x, const int y) { return x > y; });
    sort(a.begin(), a.end(), greater<int>());  // a[0:N] を大きい順にソート

    int alice = 0;
    int bob = 0;
    for (int j = 0; j < N; ++j) {
        if (j % 2 == 0) {
            alice += a[j];
        } else {
            bob += a[j];
        }
    }

    cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,i;cin>>n>>x;
  if(abs(n-x)<n-1){
    cout << "Yes" << endl;
    if(x<n){
      for(i=0;i<x-2;i++) cout << i+1 << endl;
      for(i=x;i<n;i++) cout << i+1 << endl;
      for(i=x-2;i<x;i++) cout << i+1 << endl;
      for(i=n;i<2*n-1;i++) cout << i+1 << endl;
    }
    if(x>n){
      for(i=0;i<n-1;i++) cout << i+1 << endl;
      for(i=x-1;i<x+1;i++) cout << i+1 << endl;
      for(i=n-1;i<x-1;i++) cout << i+1 << endl;
      for(i=x+1;i<2*n-1;i++) cout << i+1 << endl;
    }
    if(x==n){
      for(int i=1;i<2*n;i++){
	cout << i << endl;
      }
    }
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

int main()
{
    int d;

    cin >> d;

    int a = d % 7;
    if( a == 2 )
        cout << "sat";
    else if( a == 3 )
        cout << "sun";
    else if( a == 4 )
        cout << "mon";
    else if( a == 5 )
        cout << "tue";
    else if( a == 6 )
        cout << "wed";
    else if( a == 0 )
        cout << "thu";
    if( a == 1 )
        cout << "fri";
    cout << endl;

    return 0;
}


Measured memory_bytes: 3124
#include<iostream>
#include<cstdio>
using namespace std;
int sz[10];
bool check(int x)
{
	while (x != 0)
	{
		if (sz[x % 10])
			return false;
		else x /= 10;
	}
	return true;
}
int main()
{
	int N, K;
	cin >> N >> K;
	int a;
	for (int i = 1; i <= K; i++)
	{
		cin >> a;
		sz[a] = 1;
	}
	while (1)
	{
		if (check(N)) { cout << N; break; }
		else N++;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  int b=0;
  cin>>a;
  for(int i=0;i<a.size();i++){
    if(a[i]=='x') b++;
  }
  if(b>=8) cout<<"NO";
  else cout<<"YES";
  cout<<"\n";
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 4
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int64, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}

	dp := make([][5]int64, n+1)
	for i := 1; i <= n; i++ {
		for ii := 0; ii < 5; ii++ {
			dp[i][ii] = math.MaxInt64
		}
	}
	for i := 0; i < n; i++ {
		for ii := 0; ii < 5; ii++ {
			for iii := 0; iii <= ii; iii++ {
				if dp[i][iii] == math.MaxInt64 {
					continue
				}
				if aa[i] == 0 {
					switch ii {
					case 0:
						dp[i+1][ii] = minint(dp[i+1][ii], dp[i][iii])
					case 1:
						dp[i+1][ii] = minint(dp[i+1][ii], dp[i][iii]+2)
					case 2:
						dp[i+1][ii] = minint(dp[i+1][ii], dp[i][iii]+1)
					case 3:
						dp[i+1][ii] = minint(dp[i+1][ii], dp[i][iii]+2)
					case 4:
						dp[i+1][ii] = minint(dp[i+1][ii], dp[i][iii])
					}
					continue
				}
				switch ii {
				case 0:
					dp[i+1][ii] = minint(dp[i+1][ii], dp[i][iii]+aa[i])
				case 1:
					dp[i+1][ii] = minint(dp[i+1][ii], dp[i][iii]+aa[i]%2)
				case 2:
					dp[i+1][ii] = minint(dp[i+1][ii], dp[i][iii]+1-aa[i]%2)
				case 3:
					dp[i+1][ii] = minint(dp[i+1][ii], dp[i][iii]+aa[i]%2)
				case 4:
					dp[i+1][ii] = minint(dp[i+1][ii], dp[i][iii]+aa[i])
				}
			}
		}
	}
	var ans int64
	ans = math.MaxInt64
	for ii := 0; ii < 5; ii++ {
		ans = minint(ans, dp[n][ii])
	}

	fmt.Fprintln(writer, ans)
}

func minint(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 13440
import scala.collection.mutable.Stack

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val e = List.fill(m)((sc.nextInt()-1, sc.nextInt()-1, -sc.nextInt()))

  def shortestPath(s: Int, n: Int, edges: Seq[(Int, Int, Int)]): Array[Long] = {
    val adj = Array.fill(n)(List[Int]())
    for ((u, v, _) <- edges) {
      adj(u) ::= v
    }

    val sp = Array.fill(n)(Long.MaxValue)
    sp(s) = 0

    for {
      _ <- 1 until n
      (u, v, l) <- edges if sp(u) != Long.MaxValue
    } {
      sp(v) = sp(v).min(sp(u) + l)
    }

    var visited = Set[Int]()
    val stack = Stack[Int]()
    for ((u, v, l) <- edges if sp(u) != Long.MaxValue) {
      if (sp(v) > sp(u) + l) {
        visited += v
        stack.push(v)
      }
    }

    while (stack.nonEmpty) {
      val u = stack.pop()
      for (v <- adj(u) if !visited(v)) {
        visited += v
        stack.push(v)
      }
    }

    for (u <- visited) {
      sp(u) = Long.MinValue
    }

    sp
  }

  val sp = shortestPath(0, n, e)
  println(if (sp(n-1) == Long.MinValue) "inf" else -sp(n-1))
}


Measured memory_bytes: 60832
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//vector
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int N, M;


int main() {

    cin >> N >> M;

    vvi vec(N);
    int a, b;
    REP(i, M) {
        cin >> a >> b;
        a--; b--;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }

	queue<pair<int, int>> st;
	set<int> used;

    vi ans(N, -1);
    used.insert(0);
    for (auto x : vec[0]) {
        st.push({ 0, x });
        used.insert(x);
    }

    while(!st.empty()){
        auto[parent, x] = st.front(); st.pop();
        
        ans[x] = parent + 1;

        for (int y : vec[x]) {
            if (used.find(y) != used.end()) continue;

            used.insert(y);
            st.push({ x, y });
        }
    }

    cout << "Yes" << endl;
    FOR(i, 1, N) {
        cout << ans[i] << endl;
    }



#ifdef _MSC_VER
    system("PAUSE");
#endif

    return 0;
}

Measured memory_bytes: 15328
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

vector<long long> Lucas(100, -1);

long long L(int i)
{
  if (Lucas.at(i) > -1) return Lucas.at(i);
  if (i == 0) {Lucas.at(i) = 2; return 2;}
  if (i == 1) {Lucas.at(i) = 1; return 1;}
  Lucas.at(i) = L(i - 1) + L(i - 2);
  return L(i - 1) + L(i - 2);
}

int main()
{
  int N;
  cin >> N;
  
  long long ans = L(N);
  
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    set<int> b;
    for(int i = 0; i < n; i++){
    cin >> a[i];
    b.insert(a[i]);
    }

    map<int,int> p;
    for(int i = 0; i < n; i++){
        if(p.count(a[i]))
            p[a[i]]++;
        if(!(p.count(a[i])))
            p[a[i]] = 1;
    }
    int sum = 0;
    for(auto value : b){
        if(p[value] > value)
        sum += p[value] - value;
        if(p[value] < value)
        sum += p[value];
    }
    cout << sum << endl;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
#define s second
#define f first
#define INF 1e9
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
int  n,m,e[201][201],h[201],used2[201];
P h2[201];

int prim(int cnt,int f[201][201]){
  int res=0,used[201]={};
  priority_queue <P,vector<P>,greater<P> > Q;
  Q.push(P(0,h2[n-1].s));
  
  while(!Q.empty()){
    P t=Q.top();Q.pop();
    int cost=t.f,pos=t.s;
    if(used[pos]||used2[pos])continue;
    used[pos]=1,cnt++,res+=cost;
    for(int i=0;i<n;i++)if(f[pos][i]<INF)Q.push(P(f[pos][i],i));
  }
  if(cnt==n)return res;
  return 0;
}


int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)e[i][j]=INF;
    for(int i=0;i<n;i++) cin>>h[i],h2[i]=P(P(h[i],i));
    sort(h2,h2+n);
    for(int i=0,a,b,c;i<m;i++) cin>>a>>b>>c,e[--a][--b]=e[b][a]=c;
    
    
    memset(used2,0,sizeof(used2));
    int res,ans=prim(0,e),H=0,flg=ans;
    for(int i=0;i<n&&(res=prim(i,e));i++){
      int I=h2[i].s;
      ans=res,H=h[I];
      for(int j=i--;j<n&&h[h2[j].s]==H;j++) used2[h2[j].s]=1,i++;
    }
    for(int i=0;i<n;i++) if(h[i]==H) used2[i]=0;
    
    reverse(h2,h2+n);
    for(int i=0;i<n;i++){
      int I=h2[i].s,cnt=i;
      if(!used2[I]) continue;
      while(cnt+1<n&&h[I]==h[h2[cnt+1].s])cnt++;
      while(1){
	int J,mn=INF;
	for(int j=i;j<=cnt;j++)
	  for(int k=0;k<n&&used2[h2[j].s];k++)
	    if(!used2[k]&&mn>e[h2[j].s][k])mn=e[h2[j].s][k],J=h2[j].s;
	if(mn==INF)break;
	ans+=mn;
	used2[J]=0;
      }
      i=cnt;
    }
    
    if(flg) cout <<ans<<endl;
    else cout <<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 2008
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int n; cin >> n;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  for (int i = 0; i < n; ++i) {
    int x, y; cin >> x >> y;
    pq.push({x, y});
  }

  for (int i = 0; i < n; ++i) {
    cout << pq.top().first << " " << pq.top().second;
    pq.pop();
    cout << '\n';
  }

  return 0;
}


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

void call(int n);
void call2(int n);

int main(void) {
    int n;
    
    cin >> n;
    
    call(n);
    
    return 0;
}


void call(int n){
    int i = 1;
    
CHECK_NUM:
    int x = i;
    if ( x % 3 == 0 ){
        cout << " " << i;
        goto END_CHECK_NUM;
    }
    
INCLUDE3:
    if ( x % 10 == 3 ){
        cout << " " << i;
        goto END_CHECK_NUM;
    }
    x /= 10;
    if ( x ) goto INCLUDE3;
    
END_CHECK_NUM:
    if ( ++i <= n ) goto CHECK_NUM;
    
    cout << endl;
}


void call2(int n) {
    for(int i=1; i<=n; i++) {
        if( (i % 3 == 0) || (i % 10 == 3) ) { //3????????° or 1?????????3
            cout << " " << i;
        } else {
            int x = i/10; //????¨????????????????????????°10??§?????£????¬???????????????§??????
            while(x) { //10??§?????£?????????0????????????x???10???????°????????????????????????§??°????????? => ??¨???????????§?????????????????¨?????????
                if( x % 10 == 3 ) {
                    cout << " " << i;
                }
                x /= 10;
            }
        }
    }
    
    cout << endl;
}

Measured memory_bytes: 3100
N,X = map(int, input().split())
L_i = list(map(int, input().split()))

D=[0, 0]
count=1
for n in range(N):
  D[1] = D[0] + L_i[n]
  if D[1] <= X:
    count += 1
    D[0] = D[1]
  else:
    break

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,m;
signed main(){
    cin>>n>>m;
    cout<<(m-1)*m/2+(n-1)*n/2<<endl;
    return 0;
}


Measured memory_bytes: 256
A = [0] * 5
for i in range(5):
    A[i] = int(input())
B = [a % 10 for a in A]
Min = 10
for i in range(5):
    if B[i] != 0:
        Min = min([Min,B[i]])
        A[i] += 10 - B[i]
if Min == 10:
    print(sum(A))
else:
    print(sum(A)-10+Min)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    
    vector<long long int> primes;
    primes.push_back(2);
    
    int num=3;
    while(num<=55555) {
        bool flag=true;
        for(int i=0; (i<primes.size() && primes[i]*primes[i]<=num); i++) {
            if(num%primes[i]==0) {
                flag=false;
                break;
            }
        }
        if(flag) primes.push_back(num);
        
        num++;
    }

    
    for(int i=0; i<primes.size(); i++) {
        if(primes[i]%5!=1) continue;
        if(N==0) break;
        cout << primes[i] << " ";
        N--;
    }
    cout << endl;


    return 0;
    
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMultipleOf9 solver = new BMultipleOf9();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMultipleOf9 {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            String a = in.next();
            int res = 0;
            for (int i = 0; i < a.length(); i++) {
                int val = a.charAt(i) - '0';
                res += val;
                res %= 9;
            }
            out.print(((res == 0) ? "Yes" : "No"));
        }

    }

    static class FastReader {
        public BufferedReader br;
        public StringTokenizer st;
        String context = null;

        public FastReader(InputStream in) {
            this(new InputStreamReader(in));
        }

        public FastReader(InputStreamReader input) {
            br = new BufferedReader(input);
        }

        public String next() {
            if (context != null) {
                System.err.print("[" + context + "] Wait for input ...");
            }
            while (st == null || !st.hasMoreElements()) {
                try {
                    String s = br.readLine();
                    if (s == null)
                        return null;
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new RuntimeException("Could not read");
                }
            }
            String res = st.nextToken();
            if (context != null) {
                System.err.println("[" + context + "] ... received : " + res);
            }
            return res;
        }

    }
}



Measured memory_bytes: 36500
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long int LL;
LL N;
void out(LL a,LL n){
	if(a<=0 || a>n)return;
	cout<<a;
	N++;
	if(n==N)cout<<endl;
	else cout<<" ";
}

int main(){
	LL n,a,b;
	LL i,j,k;
	LL c,d,e;
	cin>>n>>a>>b;
	if(n>a*b || n<a+b-1){
		cout<<"-1"<<endl;
		return 0;
	}
	if(a==1){
		if(n!=b)cout<<"-1"<<endl;
		else{
			for(i=0;i<n;i++){
				printf("%d%c",n-i,(i!=n-1)?' ':'\n');
			}
		}
		return 0;
	}
	if(b==1){
		if(n!=a)cout<<"-1"<<endl;
		else{
			for(i=0;i<n;i++){
				printf("%d%c",i+1,(i!=n-1)?' ':'\n');
			}
		}
		return 0;
	}
	c=(n-b)/(a-1),d=(n-b)%(a-1);
	for(i=0;i<c;i++){
		for(j=n-(i+1)*a;j<n-i*a;j++){
			out(j+1,n);
		}
	}
	e=n-c*a-d-1;
	for(i=e;i<n-c*a;i++){
		out(i+1,n);
	}
	for(i=e-1;i>=0;i--){
		out(i+1,n);
	}
	return 0;
}


Measured memory_bytes: 2176
s = input()
q = int(input())
for i in range(q):
    cmd = input().split()
    if cmd[0] == "print":
        a, b = int(cmd[1]), int(cmd[2])
        print(s[a:b+1])
    elif cmd[0] == "reverse":
        a, b = int(cmd[1]), int(cmd[2])
        s = s[0:a] + s[a:b+1][::-1] + s[b+1:]
    elif cmd[0] == "replace":
        a, b, r = int(cmd[1]), int(cmd[2]), cmd[3]
        s = s[0:a] + r + s[b+1:]



Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define ll long long
#define f first
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define ar array
#define N 100005

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++){
        cin>>a[i];
	}
	map<ll,ll> u;
	for(int i=0;i<n;i++){
        u[i-a[i]]++;
	}
	ll ans = 0;
	for(int i=0;i<n;i++){
        u[i-a[i]]--;
        ans += u[i+a[i]];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 27924
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

int main() {
  int a, b;
  string op;
  cin >> a >> op >> b;
  cout << (op == "+" ? a + b : a - b) << endl;
  return 0;
}

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

namespace ConsoleApp7
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = short.Parse(Console.ReadLine());
			var ls = Console.ReadLine().Split(' ').Select(int.Parse).OrderByDescending(x => x);

			Console.WriteLine((ls.First() < ls.Skip(1).Sum()) ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
static const int giga = pow(10,9);

int main(void){

  string str;
  cin >> str;
  for(int i = 0; i < 19; i++){
    if(i != 5 && i != 13){
      cout << str[i];
    } else {
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}

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

H = list(map(int,input().split()))


pure = int(0)
ans = int(0)

H.append(100000000000)

for i in range(n):
    if H[ i ] >= H[ i + 1 ]:
        pure += 1
        continue
    else:
        if ans <= pure:
            ans = pure
            pure = int(0)
        else:
          pure = int(0)

print(ans)


Measured memory_bytes: 14252
from functools import lru_cache

n = int(input())
A = [int(n) for n in input().split()]
q = int(input())
M = [int(n) for n in input().split()]


@lru_cache(maxsize=2**12)
def makeCombination(i,key):
    if key == 0:
        return True
    if i == n:
        return False
    return makeCombination(i+1,key) or makeCombination(i+1,key-A[i])


for m in M:
    if makeCombination(0,m):
        print("yes")
    else:
        print("no")



Measured memory_bytes: 7664
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++)
            if (in.nextInt() == 0)
                out.println(i + 1);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 32568
#include <algorithm>
#include <iostream>
#include <map>
#define ll long long
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, ll> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    m[s]++;
  }
  ll ans = 0;
  for (auto a : m) {
    ans += (ll)(a.second * (a.second - 1) / 2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int i=0;
  for(i;i*i<=N;i++);
  cout<<(i-1)*(i-1)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdlib>

using namespace std;

string s;
int num1,num2;
bool tag[10000010];

int main()
{
     cin>>s;
     int len=s.size();
     for(int i=0;i<len;i++)
     {
     	if(s[i]=='C') 
     	{
     		num1=i;
     		tag[1]=true;
		 }
     	else if(s[i]=='F')
     	{
     		num2=i;
     		tag[2]=true;
		 }
	 }
	 if(tag[1]==true&&tag[2]==true&&num1<num2)  printf("Yes");
	 else printf("No");
	 return 0;
}

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

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

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;
  int a,b;
  cin >>K;
  cin >>a>>b;
  int count;
  
  for(int i=a;i<=b;i++)
    if(i%K == 0){
      count++;
      
    }
  if(count >= 1){
    cout << "OK"<<endl;
  }
  else{
    cout<<"NG"<<endl;
  }
      

}

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

int main(){
	for(;;){
		int N;
		cin >> N;
		if(N == 0) break;
		for(int i = 0; i < 9; i++){
			int a;
			cin >> a;
			N -= a;
		}
		cout << N << endl;
	}
	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>
#define ALL(V) V.begin(),V.end()
#define f1(a,b) for(int a=1;a<=b;a++)
#define f0(a,b) for(int a=0;a<b;a++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define de(x) cout<<#x<<": "<<x<<endl
using namespace std;
const LL N=1e6+69, base=1024*1024,mod=1e9+7;
LL t[N],n;
pll fun(int l,int p) {
    if(p-l<1) return MP(1e18,1e18);
    LL sr=t[p]-t[l-1];
    sr/=2;
    sr+=t[l-1];
    auto it=lower_bound(t,t+n+1,sr);
    int in=it-t;
    in--;
    in--;
    pll re;
    re=MP(-1e18,1e18);
    f0(i,5) {
        in++;
        if(in<l) continue;
        if(in>=p) continue;
        LL a=t[in]-t[l-1];
        LL b=t[p]-t[in];
        if(a>b) swap(a,b);
        if(b-a<re.s-re.f) re=MP(a,b);
    }
    //cout<<l<<" "<<p<<" "<<re.f<<" "<<re.s<<endl;
    return re;
}
int32_t main(void) {
    boost;
    cin>>n;
    f1(i,n) {
        cin>>t[i];
        t[i]+=t[i-1];
    }
    LL wynik=1e18;
    f1(i,n) {
        vector <LL> vek;
        vek.PB(fun(1,i).f);
        vek.PB(fun(1,i).s);
        vek.PB(fun(i+1,n).f);
        vek.PB(fun(i+1,n).s);
        sort(ALL(vek));
        wynik=min(wynik,vek[3]-vek[0]);
    }
    cout<<wynik<<endl;
}


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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    map<ll,ll> cnt;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        cnt[a[i]]++;
    }
    ll sum = 0;
    for (auto e : cnt) {
        sum += e.second*(e.second-1)/2;
    }
    for (int i = 0; i < n; i++) {
        std::cout << sum-(cnt[a[i]]*(cnt[a[i]]-1)/2-(cnt[a[i]]-2)*(cnt[a[i]]-1)/2) << std::endl;
    }
    
    
}



Measured memory_bytes: 11008
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public struct Pair<T> { public T x, y; public Pair(T x, T y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        string S = NextString();
        char c0 = S[0];
        char c1 = '0';
        if (c0 != S[1]) c1 = S[1];
        if (c0 != S[2]) c1 = S[2];
        if (c0 != S[3]) c1 = S[3];
        Console.WriteLine((S.Count(v => v == c0) == 2 && S.Count(v => v == c1) == 2 ? "Yes":"No"));
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}
public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, A;
    cin >> N >> A;
    if (N % 500 <= A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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


import static java.lang.System.in;

class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int N = Integer.parseInt(reader.readLine());
        switch(N%10){
            case 2:
                System.out.println("hon");
                break;
            case 4:
                System.out.println("hon");
                break;
            case 5:
                System.out.println("hon");
                break;
            case 7:
                System.out.println("hon");
                break;
            case 9:
                System.out.println("hon");
                break;
            case 0:
                System.out.println("pon");
                break;
            case 1:
                System.out.println("pon");
                break;
            case 6:
                System.out.println("pon");
                break;
            case 8:
                System.out.println("pon");
                break;
            case 3:
                System.out.println("bon");
                break;

        }
    }
}


Measured memory_bytes: 32604