akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int N, k, l, n;
const int MAX_N = 1<<17;
int ord[18][MAX_N+1], sa[18][MAX_N+1];
int SA[MAX_N+1], ORD[MAX_N+1];

bool comp(int i, int j){
    if(ord[l][i] != ord[l][j]) return ord[l][i] < ord[l][j];
    int ri = (i+k <= N) ? ord[l][i+k] : -1;
    int rj = (j+k <= N) ? ord[l][j+k] : -1;
    return ri < rj;
}

bool comp2(int i, int j){
    int sum = 0;
    rep(a, 18){
        if(!(n&(1<<a))) continue;
        int ri = (i+sum <= N) ? ord[a][i+sum] : -1;
        int rj = (j+sum <= N) ? ord[a][j+sum] : -1;
        if(ri != rj) return ri < rj;
        sum += 1<<a;
    }
    return false;
}

void build(string s){
    rep(i, N+1){
        sa[0][i] = i;
        ord[0][i] = (i < N) ? s[i] : -1;
    }
    for(l = 0; l < 17; l++){
        k = 1<<l;
        rep(i, N+1) sa[l+1][i] = sa[l][i];
        sort(sa[l+1], sa[l+1]+N+1, comp);
        ord[l+1][sa[l+1][0]] = 0;
        rep2(i, 1, N){
            int a = sa[l+1][i-1], b = sa[l+1][i];
            ord[l+1][b] = ord[l+1][a] + comp(a, b);
        }
    }
    rep(i, N+1) SA[i] = i;
    sort(SA, SA+N+1, comp2);
    ORD[SA[0]] = 0;
    rep2(i, 1, N){
        ORD[SA[i]] = ORD[SA[i-1]] + comp2(SA[i-1], SA[i]);
    }
}

int main(){
    int K; string S;
    cin >> K >> S;
    N = sz(S);
    n = (N+K)/(K+1);
    int sum = N-(n-1)*(K+1);
    build(S);
    int l = -1, r = N+1; //(l, r]
    while(r-l > 1){
        int m = (l+r)/2;
        int cnt = 0;
        for(int i = 0; i < N;){
            if(ORD[i] <= ORD[SA[m]] && i+n <= N) cnt++, i += n;
            else{
                if(n-1 > 0) i += n-1;
                else break;
            }
        }
        if(cnt >= sum) r = m;
        else l = m;
    }
    cout << S.substr(SA[r], n) << endl;
}

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

int main () {
  int n; cin >> n;
  int ans = 0;
  
  for (int i = 0; i < 4; i++) {
    int a;
    if (i == 0) a = 0;
    else a = (i * 2 + 1) * pow(10, 8);
    if (a > n) break;
    
    for (int j = 0; j < 4; j++) {
      int b = a;
      if (j == 0) b += 0;
      else b += (j * 2 + 1) * pow(10, 7);
      if (b > n) break;
      
      for (int k = 0; k < 4; k++) {
        int c = b;
        if (k == 0) c += 0;
        else c += (k * 2 + 1) * pow(10, 6);
        if (c > n) break;
        
        for (int l = 0; l < 4; l++) {
          int d = c;
          if (l == 0) d += 0;
          else d += (l * 2 + 1) * pow(10, 5);
          if (d > n) break;
          
          for (int m = 0; m < 4; m++) {
            int e = d;
            if (m == 0) e += 0;
            else e += (m * 2 + 1) * pow(10, 4);
            if (e > n) break;
            
            for (int o = 0; o < 4; o++) {
              int f = e;
              if (o == 0) f += 0;
              else f += (o * 2 + 1) * pow(10, 3);
              if (f > n) break;
              
              for (int p = 0; p < 4; p++) {
                int g = f;
                if (p == 0) g += 0;
                else g += (p * 2 + 1) * pow(10, 2);
                if (g > n) break;
                
                for (int q = 0; q < 4; q++) {
                  int h = g;
                  if (q == 0) h += 0;
                  else h += (q * 2 + 1) * pow(10, 1);
                  if (h > n) break;
                  
                  for (int r = 0; r < 4; r++) {
                    int num = h;
                    if (r == 0) num += 0;
                    else num += (r * 2 + 1);
                    if (num <= n) {
                      vector<bool> fit(10, false);
                      while(num) {
                        fit[num % 10] = true;
                        num /= 10;
                      }
                      if (!fit[0] && fit[3] && fit[5] && fit[7]) ans++;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int m, f, b;
    cin >> m >> f >> b;
    if (m + f < b) {
        cout << "NA\n";
    } else {
        cout << max(0, b - m) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3108
# P=0 -> 奇数を偶数個といくつかの偶数個
# P=1 -> 奇数を奇数個といくつかの奇数個
# 1000回くらいWAしたのでどんどんアドホックになっていった

n, p = map(int, input().split())
odds = n - len(list(filter(lambda x: int(x) % 2 == 0, input().split())))
evens = n - odds


def ncr(n, r):
    res = 1
    for i in range(1, r + 1):
        res = res * (n - i + 1) // i
    return res


ans = 0
if p == 0:
    for i in range(0, odds + 1, 2):
        ans += ncr(odds, i)
    if evens > 0:
        ans *= max(1, 2 ** evens)
else:
    if odds > 0:
        for i in range(1, odds + 1, 2):
            ans += ncr(odds, i)
        ans *= max(1, 2 ** evens)
print(ans)


Measured memory_bytes: 3064
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()

a = LIST()
a.sort()
if(0 in a):
    print(0)
else:
    ans = 1
    for el in a:
        ans*=el
        if(ans>10**18):
            break
    if(ans>10**18):
        print(-1)
    else:
        print(ans)

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO  = "No";

int func(int n, vi s) {
    rep(i, n - 1) {
        if (s[i] <= s[i + 1]) {
            continue;
        } else {
            if (s[i + 1] - s[i] == -1) {
                s[i + 1]++;
				
            } else {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

int main() {
    int n;
    cin >> n;
    vi s(n);
    rep(i, n) { cin >> s[i]; }
    func(n, move(s));
    return 0;
}


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  char a,b ;
  cin>>a>>b;
  if(a == 'H')
    cout<<b<<endl;
  else
  {
    if(b == 'H') cout<<'D'<<endl;
    else cout<<'H'<<endl;
  }
  return 0;
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
string S;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> S;
    int cnt = 0;
    for(int i = 0; i < N - 2; i++){
        if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int n;
	string s;
	cin >> n >> s;
	int i = 0, j = s.size() - 1, res = 0;

	while (i < j)
	{
		while (i < j && s[i] == 'R')
			++i;
		while (i < j && s[j] == 'W')
			--j;
		if (i < j && s[i] == 'W' && s[j] == 'R')
		{
			s[i] = 'R';
			s[j] = 'W';
			++i;
			--j;
			++res;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3772
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  int n,a;
  cin>>n>>s;
  a=n/2;
  if(s.substr(0,a)==s.substr(a)&&n%2!=1){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

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

using namespace std;

#define arraySize(A) (sizeof(A)/sizeof(A[0]))
#define FOR(i,n) for(int i=0;i<n;i++)
#define LOOP(n) for(int __loopCountNum=0;__loopCountNum<n;__loopCountNum++)


int main(){//DMC
    int N;
    char *S;
    int Q;
    int *k_in;
    
    cin >> N; S = new char[N+1];
    cin >> S; S[N] = '\0';
    cin >> Q; k_in = new int[Q];
    FOR(i,Q){
        cin >> k_in[i];
    }
    
    FOR(_loop, Q){
        int k = k_in[_loop];
        long long count = 0;
        
        long long *Mnum = new long long[N];
        {
            long long c = 0;
            FOR(i,N){
                if(S[i] == 'M'){
                    c++;
                }
                Mnum[i] = c;
            }
        }
        long long Msum=0;
        long long Dnum=0;
        for(int C = 0;C<N;C++){
            if(S[C]=='D'){
                Dnum++;
                Msum+=Mnum[C];
            }
            if(C-k>=0 && S[C-k]=='D'){
                Dnum--;
                Msum -= Mnum[C-k];
            }
            if(S[C]=='C'){
                count += Dnum*Mnum[C]-Msum;
            }
        }
        cout<<count<<endl;
        delete[] Mnum;
    }
    
    delete[] S;
    delete[] k_in;
    return 0;
}


Measured memory_bytes: 9088
#include<stdio.h>
int main()
{

    long long int a,b,i,j,k=1,p=0,q=0;
    scanf("%lld",&a);
    long long int ara[a];
    for(i=0;i<a;i++)
    {
        scanf("%lld",&ara[i]);
        if(ara[i]==0){
         q=1;
        }
    }
    if(q!=1){
    for(j=0;j<a;j++)
    {
        if(ara[j]<=(1000000000000000000/k))
        {
        k=k*ara[j];
        p=j;
        }

        else
        {
            q=2;
            break;

        }
    }
    if(p==a-1)
    {
        printf("%lld",k);
    }
    else if(q==2){

     printf("-1\n");
    }
    }
    else{
       printf("0\n");
    }
}





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

int main() {
  string sa,sb,sc;
  cin>>sa>>sb>>sc;
  int sza=sa.size(),szb=sb.size(),szc=sc.size();
  int na=0,nb=0,nc=0;
  char who='a';
  while(sza-na>=0&&szb-nb>=0&&szc-nc>=0){
    if(who=='a'){
      who=sa[na];
      na++;
    }
    else if(who=='b'){
      who=sb[nb];
      nb++;
    }
    else{
      who=sc[nc];
      nc++;
    }
  }
  if(sza-na<0) puts("A");
  if(szb-nb<0) puts("B");
  if(szc-nc<0) puts("C");
  return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let h: usize = iterator.next().unwrap().parse().unwrap();
    let w: usize = iterator.next().unwrap().parse().unwrap();
    let mut c: Vec<Vec<usize>> = vec![vec![0; 10]; 10];
    for i in 0..10 {
        for j in 0..10 {
            c[i][j] = iterator.next().unwrap().parse().unwrap();
        }
    }
    let mut a: Vec<usize> = Vec::new();
    for _ in 0..(h * w) {
        let ai: isize = iterator.next().unwrap().parse().unwrap();
        if ai >= 0 {
            a.push(ai as usize);
        }
    }

    // ワーシャルフロイド法
    let mut d: Vec<Vec<usize>> = c.clone();
    for k in 0..10 {
        for i in 0..10 {
            for j in 0..10 {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    let mut ans = 0;
    for ai in a {
        ans += d[ai][1];
    }
    return ans.to_string();
}


Measured memory_bytes: 4352
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int main()
{
    long long int n,m;cin >> n >> m;
    if(n==1 && m==1){
        p(1)
    }
    else if(n==1){
        p((m-2))
    } else if(m==1){
        p((n-2))
    } else {
        p((n-2)*(m-2))
    }
} 

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

using namespace std;

#define MAX_N 110

const int MOD = 1e9 + 7;

int dp[MAX_N][4][4][4];

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

	// A -> 0
	// G -> 1
	// C -> 2
	// T -> 3

	dp[0][3][3][3] = 1;

	// 文字列の文字数
	for (int len = 0; len < N; len++) {
		// 最後から1文字目の文字
		for (int i = 0; i < 4; i++) {
			// 最後から2文字目の文字
			for (int j = 0; j < 4; j++) {
				// 最後から3文字目の文字
				for (int k = 0; k < 4; k++) {
					// 条件に当てはまるものがない
					if (dp[len][i][j][k] == 0)
						continue;

					for (int a = 0; a < 4; a++) {
						if (a == 2 && i == 1 && j == 0)
							continue;
						if (a == 2 && i == 0 && j == 1)
							continue;
						if (a == 1 && i == 2 && j == 0)
							continue;
						if (a == 2 && i == 1 && k == 0)
							continue;
						if (a == 2 && j == 1 && k == 0)
							continue;

						dp[len + 1][a][i][j] +=
						    dp[len][i][j][k];
						dp[len + 1][a][i][j] %= MOD;
					}
				}
			}
		}
	}

	int ans = 0;

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				ans += dp[N][i][j][k];
				ans %= MOD;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int n;
vector<int> v;

ll dp(int b, int e, int p){
  static ll mm[3001][3001][2];
  static bool used[3001][3001][2];

  if(used[b][e][p]) return mm[b][e][p];
  else used[b][e][p] = true;
  
  if(b == e) return 0;

  if(p == 0) mm[b][e][p] = min(dp(b,e-1,1)-v[e-1],dp(b+1,e,1)-v[b]);
  else       mm[b][e][p] = max(dp(b,e-1,0)+v[e-1],dp(b+1,e,0)+v[b]);
  
  return mm[b][e][p];
}

int main(){
  cin >> n;
  v = vector<int>(n); cin >> v;
  cout << dp(0,n,1) << endl;
  return 0;
}


Measured memory_bytes: 158592
#include<stdio.h>
#include<stdlib.h>

typedef struct TREE{
	int id;
	int depth;
	int k;
	struct TREE *parent;
	struct TREE **child;
}Tree;

Tree tree[100000];

void setDepth(Tree *nt, int depth){
	int i;
	if( nt == NULL ){ return; }
	nt->depth = depth;
	for( i = 0; i < nt->k; i++ ){
		setDepth(nt->child[i], depth+1);
	}
	return;
}

void print(Tree *p){
	int parent, nodetype, i;
	char *nodename[] = {"root", "internal node", "leaf"};
	if( p == NULL ){ return; }
	if( p->parent == NULL ){
		parent = -1;
	}else{
		parent = p->parent->id;
	}
	if( parent == -1 ){
		nodetype = 0;
	}else if( p->k > 0 ){
		nodetype = 1;
	}else{
		nodetype = 2;
	}
	printf("node %d: parent = %d, depth = %d, ", p->id, parent, p->depth);
	printf("%s, ", nodename[nodetype]);
	printf("[");
	if( p->k > 0 ){
		printf("%d", p->child[0]->id);
		for( i = 1; i < p->k; i++ ){
			printf(", %d", p->child[i]->id);
		}
	}
	printf("]\n");
	return;
}

int main(){
	int n, id, id2, i, j;
	scanf("%d", &n);
	Tree *root = NULL;
	for( i = 0; i < n; i++ ){
		tree[i].id = i;
		tree[i].parent = NULL;
		tree[i].child = NULL;
		tree[i].k = -1;
		tree[i].depth = -1;
	}
	for( i = 0; i < n; i++ ){
		scanf("%d", &id);
		scanf("%d", &tree[id].k);
		tree[id].child = (Tree**)malloc(sizeof(Tree*)*tree[id].k);
		for( j = 0; j < tree[id].k; j++ ){
			scanf("%d", &id2);
			tree[id].child[j] = &tree[id2];
			tree[id].child[j]->parent = &tree[id];
		}
	}
	//???????±??????????
	for( i = 0; i < n; i++ ){
		if( tree[i].parent == NULL ){
			root = &tree[i];
			break;
		}
	}
	//??±???????±??????????
	setDepth(root, 0);
	//???????????????
	for( i = 0; i < n; i++ ){ print(&tree[i]); }
	return 0;
}

Measured memory_bytes: 7648
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    cout << s.substr(0,3) << endl;


    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int INF=0x3f3f3f3f;
int main()
{
	int a,b,c,d,e,f,ans1=0,ans2=0;
	double ans=-1;
	cin>>a>>b>>c>>d>>e>>f;
	for(int u=0;u*a*100<=f;u++)
	{
		for(int v=0;u*a*100+v*b*100<=f;v++)
		{
			for(int x=0;u*a*100+v*b*100+x*c<=f;x++)
			{
				for(int y=0;u*a*100+v*b*100+x*c+y*d<=f;y++)
				{
					if(x*c+y*d>(u*a+v*b)*e)break;
					double res=(1.0)*(x*c+y*d)/(u*a*100+v*b*100+x*c+y*d);
					if(res>ans)
					{
						ans=res;
						ans1=(u*a*100+v*b*100+x*c+y*d);
						ans2=x*c+y*d;
					}
				}
			}
        }
    }
    cout<<ans1<<" "<<ans2<<endl;
    return 0;
}

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

namespace AOJ
{
    class Program
    {
        static int Add(int lhs, int rhs)
        {
            return lhs + rhs;
        }
        static int Sub(int lhs, int rhs)
        {
            return lhs - rhs;
        }
        static int Mul(int lhs, int rhs)
        {
            return lhs * rhs;
        }

        static private Func<int, int, int>[] ops = { Add, Sub, Mul };
        private static string[] opsString = {"+", "-", "*"};

        static bool OpsA(int[] nums)
        {
            for(int i = 0; i < 3; i++)
            for(int j = 0; j < 3; j++)
            for(int k = 0; k < 3; k++)
            {
                if (ops[k](ops[j](ops[i](nums[0], nums[1]), nums[2]), nums[3]) == 10)
                {
                    Console.WriteLine("(({0} {4} {1}) {5} {2}) {6} {3}", nums[0], nums[1], nums[2], nums[3], opsString[i], opsString[j], opsString[k]);
                    return true;
                }
            }
            return false;
        }

        static bool OpsB(int[] nums)
        {
            for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
            for (int k = 0; k < 3; k++)
            {
                if (ops[k](ops[i](nums[0], nums[1]), ops[j](nums[2], nums[3])) == 10)
                {
                    Console.WriteLine("({0} {4} {1}) {6} ({2} {5} {3})", nums[0], nums[1], nums[2], nums[3], opsString[i], opsString[j], opsString[k]);
                    return true;
                }
            }
            return false;
        }

        static void Main(string[] args)
        {
            string line;
            while((line = Console.ReadLine()) != null)
            {
                if (line == "0 0 0 0") break;
                var d = line.Split(' ').Select(int.Parse).ToArray();
                if (!Permutation(d).Any(ints => OpsA(ints) || OpsB(ints)))
                    Console.WriteLine("0");
            }
        }

        static IEnumerable<int[]> Permutation(int[] source)
        {
            var used = new bool[source.Length];
            for (int i = 0; i < source.Length; i++)
            for (int j = 0; j < source.Length - 1; j++)
            for (int k = 0; k < source.Length - 2; k++)
            for (int l = 0; l < source.Length - 3; l++)
            {
                Array.Clear(used, 0, used.Length);
                var ints = new int[source.Length];
                GetValue(source, used, i, ints, 0);
                GetValue(source, used, j, ints, 1);
                GetValue(source, used, k, ints, 2);
                GetValue(source, used, l, ints, 3);
                yield return ints;
            }
        }

        private static void GetValue(int[] source, bool[] used, int j, int[] ints, int level)
        {
            for(int i = 0, index = -1; i < source.Length; i++)
            {
                if (!used[i]) index++;
                if (index != j) continue;
                ints[level] = source[i];
                used[i] = true;
                break;
            }
        }
    }
}

Measured memory_bytes: 6056
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, sub

sys.setrecursionlimit(10000)

mod = 10**9 + 7


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y//2)**2 % mod
    else:
        return power(x, y//2)**2 * x % mod


def div(a, b):
    return mul(a, power(b, mod-2))


@mt
def slv(N, A):

    def perm(n):
        p = 1
        for i in range(1, n+1):
            p *= i
            p %= mod
        return p

    pn = perm(N)
    sp = [0]
    for i in range(1, N+1):
        sp.append((sp[-1] + div(pn, i)) % mod)

    ans = mul(sp[-1], A[0])
    for i in range(1, N):
        ans += mul(sp[i+1] - sp[1], A[i])
        ans %= mod
        ans += mul(sp[N-i] - sp[0], A[i])
        ans %= mod
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16636
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL
string n;

int main()
{
  int x=0;

  cin >> n;

  for (int i=0; i<(int)n.size(); i++) {
    x += n[i]-'0';
    x %= 9;
  }
  if (x==0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 3740
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		String result = "";
		while (N > 0) {
			result = N % K + result;
			N /= K;
		}

		out.println(result.length());
		out.flush();
	}
}

Measured memory_bytes: 39396
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[])
{
  char a, b;
  cin >> a >> b;

  string ab(b - '0', a);
  string ba(a - '0', b);

  cout << min(ab, ba) << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

vll v;
ll n, ans;
void bfs() {
	queue<ll> task;
	for (ll i = 0; i < v.size(); i++) {
		if (v[i] >= n) {
			ans = v[i];
			return;
		}
		task.push(v[i]);
	}
	ll depth = 5;
	while (depth--) {
		ll sz = task.size();
		while (sz--) {
			ll x = task.front() * 10;
			task.pop();
			for (ll i = 0; i < v.size(); i++) {
				if (x + v[i] >= n) {
					ans = x + v[i];
					return;
				}
				task.push(x + v[i]);
				xout << x + v[i] << endl;
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll k;
	cin >> n >> k;
	vll d(k);
	for (ll i = 0; i < k; i++) cin >> d[i];

	vector<bool> ok(10, true);
	for (ll i = 0; i < k; i++) ok[d[i]] = false;
	for (ll i = 0; i < 10; i++) {
		if (ok[i]) v.push_back(i);
	}

	bfs();
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int N;
	    Scanner in = new Scanner(System.in);
	    N = Integer.parseInt(in.next());
	    int cnt;
	    int ans = 0;
	    for (int i = 1; i <= N; i+=2) {
	    	cnt = 0;
			for (int j = 1; j*j <= i; j++) {
				if(i%j==0) {
					if(j*j == i) {
						cnt++;
					}else {
						cnt+=2;
					}
				}
			}
			if(cnt == 8) {
				ans++;
			}
		}
	    System.out.println(ans);
	}
}

Measured memory_bytes: 21460
#include<stdio.h>

int main(void){
int W,H,x,y,r;
scanf("%d",&W);
scanf("%d",&H);
scanf("%d",&x);
scanf("%d",&y);
scanf("%d",&r);
if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H){
printf("Yes\n");
}
else{
printf("No\n");
}
return 0;
}

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

using namespace std;

int n, x[505], y[505], k, s, ans;

void test(int a) {
	long long nd = 0;
	for (int i = 0; i < n; i++)
		y[i] = x[i] % a;
	sort(y, y + n);
	int ta = 0, tb = n - 1;
	while (ta != tb) {
		int tmp = min(y[ta], a - y[tb]);
		y[ta] -= tmp;
		y[tb] += tmp;
		nd += tmp;
		if (y[ta] == 0)
			ta++;
		else
			tb--;
	}
	if (nd > k)
		return;
	ans = max(ans, a);
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", x + i);
		s += x[i];
	}
	for (int i = 1; i * i <= s; i++) {
		if (s % i)
			continue;
		test(i);
		test(s / i);
	}
	printf("%d\n", ans);
}


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

template<typename T> inline void fastin(T& num) {
  T c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

int main() {
  int N;
  fastin(N);

  vector<int> L(N);
  for (int i = 0; i < N; i++) fastin(L.at(i));
  sort(L.begin(), L.end());

  long long ans = 0;

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int k = lower_bound(L.begin(), L.end(), L.at(i) + L.at(j)) - L.begin();
      ans += max(0, k - j - 1);
    }
  }

  cout << ans << "\n";
}

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

int main()
{
    int N; cin >> N;
    vector<int> A{};
    long long sum_A = 0;
    for (int i = 1; i <= N; i++)
    {
        int a; cin >> a;
        A.push_back(a);
        sum_A += a;
    }

    sort(A.begin(), A.end(), greater<int>());

    int x = 0, ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (x <= sum_A * 2) ans++;
        else break;
        
        x = A[i];
        sum_A -= A[i];
    }

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

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int SZ = 100005;
ll arr[SZ];
int main(void){
	int n; ll k; scanf("%d %lld",&n,&k);
	for(int i=0;i<n;i++) scanf("%lld",&arr[i]);
	ll ans = 0LL, chk = 0LL;
	for(int i=62;i>=0;i--){
		int zero=0, one=0;
		for(int j=0;j<n;j++){
			if((arr[j]&(1LL<<i))==0) zero++;
			else one++;			
		}
		if(zero>one){
			if((chk|(1LL<<i))>k) ans += (long long)one * (1LL<<i);
			else{
				chk |= (1LL<<i);
				ans += (long long)zero * (1LL<<i);
			}
		}
		else ans += (long long)one*(1LL<<i);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 5100000
#define MOD 1000000007
#define INF 100000000000000

int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }

  vector<vector<int>> a(N,vector<int>(20,0));
  for(int i=0;i<N;i++){
    ll B=A.at(i);
    for(int j=0;j<20;j++){
      a.at(i).at(j)=B%2;
      B>>=1;
    }
  }
  ll left=0;
  ll right=0;
  ll ans=0;
  vector<int> count(20,0);
  while(left<N){
    bool flag=true;
    for(int i=0;i<20&&right<N;i++){
      count.at(i)+=a.at(right).at(i);
      if(count.at(i)>1){
        flag=false;
      }
    }
    if(flag&&right<N){
      right++;
    }else{
      ans+=right-left;
      for(int i=0;i<20;i++){
        count.at(i)-=a.at(left).at(i);
        if(right<N){
          count.at(i)-=a.at(right).at(i);
        }
      }
      left++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 25216
fun main(args: Array<String>) {
    val (N, K) = listOfInt()
    val H = listOfInt()
    val ans = H.count { it >= K }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }

Measured memory_bytes: 48048
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <stack>
using namespace std;
 
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,-1,1,-1,1};
 
 
int main() {
int n,m;
int pr,di;
while(cin>>n>>m && n){
int ans=0;
vector<pair<int,int> > ve;
for(int i=0;i<n;i++){
cin>>di>>pr;
ve.push_back(make_pair(pr,di));
ans=ans+pr*di;
}
sort(ve.begin(),ve.end(),greater<pair<int,int> >());
for(int i=0;i<n;i++){
if(m<=0) break;
else if(m<=ve[i].second){
ans=ans-ve[i].first*m;
m=0;
}
else{
ans=ans-ve[i].first*ve[i].second;
m=m-ve[i].second;
}


}

cout<<ans<<endl;
}

	return 0;
 
   }

Measured memory_bytes: 3196
Scanf.scanf "%d" (fun t ->
    let rec gcd a b = if b = 0 then a else gcd b (a mod b) in
    for i = 1 to t do
        Scanf.scanf " %d %d %d %d" (fun a b c d ->
            print_endline @@
                if d < b then "No" else
                if a < b then "No" else
                if c + gcd b d >= b + (a mod gcd b d) then "Yes" else "No"
        )
    done
)

Measured memory_bytes: 3872
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  int a, b, c, d;
  a = S[0]-'0';
  b = S[1]-'0';
  c = S[2]-'0';
  d = S[3]-'0';
  int tmp;
  char op[2]={'+', '-'};
  for(int i=0;i<2;++i) {
    for(int j=0;j<2;++j) {
      for(int k=0;k<2;++k) {
        tmp = a;
        if(i==0) tmp += b;
        else tmp -= b;
        if(j==0) tmp += c;
        else tmp -= c;
        if(k==0) tmp += d;
        else tmp -= d;
        if(tmp==7) {
          cout<<a<<op[i]<<b<<op[j]<<c<<op[k]<<d<<"=7"<<endl;
          return 0;
        }
      }
    }
  }
}



Measured memory_bytes: 3608
#include <stdio.h>

int main(void) {
	int i=1,n,x;
	scanf("%d",&n);
	for(;i<=n;++i){
		x=i;
		if(x%3==0)printf(" %d",i);
		else {
			do{
				if(x%10==3){
					printf(" %d",i);
					break;
				}
				x/=10;
			}while(x);
		}
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 2040
import sys
N=int(input())
a=list(map(int,input().split()))
ans=1
l=[0,0,0]
mod=10**9+7
for i in range(N):
  ans*=(l.count(a[i]))
  if a[i] not in l:
    print(0)
    sys.exit()
  index=l.index(a[i])
  l[index]+=1
print(ans%mod)

Measured memory_bytes: 14056
//集計処理　バケット法 std::map

#include<iostream>
#include<map>
#include<string>
using namespace std;

int main()
{
    int n,m;
    string tmp;
    map<string,int> mp;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>tmp;
        mp[tmp]+=1;
    }

    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>tmp;
        mp[tmp]-=1;
    }

    int ans=-1000;
    /* 
    mapのiteration
    key,valueそれぞれにitr->first,itr->secondでアクセスできる
    */
    for(auto itr=mp.begin();itr != mp.end(); ++itr)
    {
        ans=max(ans,itr->second);
    }

    if(ans<=0)cout<<0<<endl;
    else cout<<ans<<endl;;

    
}

Measured memory_bytes: 256
/*
 *  A - Password
 * author: roy4801
 * (C++)
 */
#include <bits/stdc++.h>

using namespace std;

#define PROB "A"
#define TESTC ""

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;
#define F first
#define S second
#define INF 0x3f3f3f3f
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PPB pop_back
#define PF push_front
#define PPF pop_front
int n;
int main()
{
	#ifdef DBG
	freopen("./testdata/" PROB TESTC ".in", "r", stdin);
	freopen("./testdata/" PROB ".out", "w", stdout);
	#endif
	while(cin >> n)
	{
		cout << n * n * n << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll n, k;    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n)   cin >> a[i], a[i]--;
    vector<ll> path;
    vector<bool> town(n, true);
    ll next=0;
    path.push_back(0);  town[0] = false;
    while(town[a[next]]){
        path.push_back(a[next]);
        town[a[next]] = false;
        next = a[next];
    }
    ll itr = find(ALL(path), a[next])-path.begin();
    vector<ll> cp;
    for(ll i=itr; i<path.size(); i++){
        cp.push_back(path[i]);
    }
    if(k<path.size()){
        cout << path[k]+1 << endl;
    }else{
        k -= itr;
        k = k%cp.size();
        cout << cp[k]+1 << endl;
    }

}


Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll k,n;
    cin>>n>>k;
    vector<ll> xs,ys;
    ll xy[n][2]={};
    rep(i,n){
        ll tx,ty;
        cin >> tx >> ty;
        xs.push_back(tx);
        ys.push_back(ty);
        xy[i][0]=tx;
        xy[i][1]=ty;
    }
    sort(xs.begin(),xs.end());
    sort(ys.begin(),ys.end());
    map<ll, ll> xmp,ymp;
    bool poll[n][n]={};
    rep(i,n){
        xmp[xs[i]]=i;
        ymp[ys[i]]=i;
    }
    rep(i,n){
        poll[xmp[xy[i][0]]][ymp[xy[i][1]]]=true;
    }
    ll sum[n][n+1]={};
    rep(i,n){
        ll tmp=0;
        rep(j,n){
            if (poll[i][j])tmp++;
            sum[i][j+1]=tmp;
        }
    }
    ll res=1LL<<62;
    rep(pivot_x,n)rep(pivot_y,n){
        for(ll width=1;pivot_x+width<n;width++){
            for(ll height=1;pivot_y+height<n;height++){
                ll np=0;
                for(ll i=0;i<=width;i++){
                    np+=sum[pivot_x+i][pivot_y+height+1]-sum[pivot_x+i][pivot_y];
                }
                DEBUG{
                    cout << np << endl;
                }
                if(np==k)res=min(res, ll(xs[pivot_x+width]-xs[pivot_x])*ll(ys[pivot_y+height]-ys[pivot_y]));
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
lv, le = map(int, input().split())
inf = 1e10

d = [[inf] * lv for _ in range(lv)]
for v in range(lv):
    d[v][v] = 0
for _ in range(le):
    s, t, c = map(int, input().split())
    d[s][t] = c

for k in range(lv):
    for i in range(lv):
        for j in range(lv):
            if d[i][k] < inf and d[k][j] < inf:
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

isneg = False
for v in range(lv):
    if d[v][v] < 0:
        isneg = True
if isneg:
    print('NEGATIVE CYCLE')
else:
    for i in range(lv):
        print(' '.join([str(d[i][j]) if d[i][j] < inf else 'INF' for j in range(lv)]))


Measured memory_bytes: 6052
package main

import "fmt"

var dp [10010]bool

func main() {
	var n int
	fmt.Scan(&n)
	dp[0] = true;
	for i := 0; i < n; i++ {
		var v int
		fmt.Scan(&v)
		for j := 10000-v; j >= 0; j-- {
			dp[j+v] = dp[j+v] || dp[j]
		}
	}
	var maxi int = 0
	for i := 0; i <= 10000; i++ {
		if dp[i] && i % 10 != 0 {
			maxi = i
		}
	}
	fmt.Printf("%d\n", maxi)
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
 
using namespace std;
 
vector<int> vec[200002];
vector<int> ans;
 
void dfs(int v, int p){
  for(auto u : vec[v]){
    if(u == p)continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main(){

  int a,b,i,n,p,q,x;
 
  cin >> n >> q;
  ans.resize(n);
  for(i=0;i<n-1;++i){
    cin >> a >> b;
    --a;--b;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  for(i=0;i<q;++i){
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0,-1);
 
  for(i=0;i<n;++i)cout << ans[i] << endl;
 
  return 0;
 
}

Measured memory_bytes: 23424
# 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>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int a, b;

int main() {
	cin >> a >> b;
	if (a + b == 15) {
		cout << "+" << endl;
	}
	else if (a*b == 15) {
		cout << "*" << endl;
	}
	else {
		cout << "x" << endl;
	}
}

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

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

    vector<long long> a(n);
    for (int i = 0; i < n; i++)
        cin >> a.at(i);

    int cnt = 0;
    while (true) {
        bool can_operate = true;
        for (int i : a)
            if (i % 2 == 1) {
                can_operate = false;
                break;
            }

        if (!can_operate)
            break;

        cnt++;
        for (int i = 0; i < n; i++)
            a.at(i) /= 2;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int n, m, d[20004], u, v, o[20004][204];
map<int, int> p[20004];
string s[102];
pii g[20004][204];

int DFS(int x, int c) {
    if (x == v || !c) return c;
    for (int i = 0; i <= n + m; i++) {
        if (d[o[x][i]] == d[x] + 1 && g[x][i].first != g[x][i].second) {
            int df = DFS(o[x][i], min(g[x][i].first - g[x][i].second, c));
            if (df) {
                g[x][i].second += df;
                g[o[x][i]][p[o[x][i]][x]].second -= df;
                return df;
            }
        }
    }
    d[x] = -1;
    return 0;
}

bool BFS() {
    for (int i = 1; i <= n * m * 2; i++) d[i] = -1;
    d[u] = 0;
    queue<int> q;
    q.push(u);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (int i = 0; i <= n + m; i++) if (d[o[x][i]] == -1 && g[x][i].first != g[x][i].second) d[o[x][i]] = d[x] + 1, q.push(o[x][i]);
    }
    return d[v] != -1;
}

int maxflow() {
    int flow = 0, df;
    while (BFS()) while ((df = DFS(u, 890328))) flow += df;
    return flow;
}

int main() {
    ios::sync_with_stdio(false);
    int c;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        for (int j = 0; j < m; j++) {
            if (s[i][j] == 'S') u = i * m + j + n * m + 1;
            if (s[i][j] == 'T') v = i * m + j + 1;
        }
    }
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (s[i][j] != '.') {
        if (i * m + j + 1 != u && i * m + j + 1 != v) g[i * m + j + 1][n + m] = {1, 0};
        o[i * m + j + 1][n + m] = i * m + j + n * m + 1;
        for (int k = 0; k < n; k++) if (s[k][j] != '.' && i != k) g[i * m + j + n * m + 1][k] = {1328, 0}, o[i * m + j + n * m + 1][k] = k * m + j + 1;
        for (int k = 0; k < m; k++) if (s[i][k] != '.' && j != k) g[i * m + j + n * m + 1][k + n] = {1328, 0}, o[i * m + j + n * m + 1][k + n] = i * m + k + 1;
        for (int k = 0; k <= n + m; k++) if (g[i * m + j + 1][k].first) p[i * m + j + 1][o[i * m + j + 1][k]] = k;
        for (int k = 0; k <= n + m; k++) if (g[i * m + j + n * m + 1][k].first) p[i * m + j + n * m + 1][o[i * m + j + n * m + 1][k]] = k;
    }
    int z = maxflow();
    cout << (z < 1328 ? z : -1) << '\n';
}



Measured memory_bytes: 142464
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int dp[102][100005],n;
int a[102],k;
signed main()
{
    cin>>n>>k;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    dp[0][0]=1;
    for(int j=0;j<=k;j++)
    {
    for(int i=1;i<=n;i++)
    {
            dp[i][j]=dp[i-1][j];
            if(j)
                dp[i][j]+=dp[i][j-1];
                dp[i][j]%=mod;
            if(j-a[i]-1>=0)
            dp[i][j]=(dp[i][j]+mod-dp[i-1][j-a[i]-1])%mod;
            dp[i][j]%=mod;
    }
    }
    cout<<dp[n][k]<<endl;
	return 0;
}


Measured memory_bytes: 42520