akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const long long INF = 10100100100100;
using namespace std;

int N, M;

typedef struct Edge{
  int from;
  int to;
  int w;
} Edge;

long long d[1100];
Edge edges[2100];

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

  rep(i,M){
    int a, b, c;
    cin >> a >> b >> c;
    a--;b--;
    edges[i] = {a,b,-c};
  }


  rep(i,N) d[i]= INF;
  d[0] = 0;
  int count = 0;
  
  rep(i,N) {
    for(auto it: edges){
      int from = it.from;
      int to = it.to;
      int w = it.w;
      if(d[from] != INF && d[to] > d[from] + w){
        d[to] = d[from] + w;
      }
    }
  }

  bool negative[1100];
  rep(i,N) negative[i] = false;

  rep(i,M) {
    Edge e = edges[i];
    if(d[e.to] > d[e.from] + e.w){
      d[e.to] = d[e.from] + e.w;
      negative[e.to] = true;
    }
  }

  if(negative[N-1]) cout << "inf" << endl;
  else cout << -d[N-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
struct wo{
	long long x;
	long long y;
}a[10001];
long long ans,n,t;
int main(){
    cin>>n>>t;
    for(int i=1;i<=n;i++){
    	cin>>a[i].x>>a[i].y;
	}
	ans=9111111111111111111;
	long long b,c,d,e;
	long long sum=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				for(int l=1;l<=n;l++){
					b=a[i].x,c=a[j].x,d=a[k].y,e=a[l].y;
					sum=0;
					if(b>c)swap(b,c);
					if(d>e)swap(d,e);
					for(int m=1;m<=n;m++){
						if(b<=a[m].x&&c>=a[m].x&&d<=a[m].y&&e>=a[m].y){
							sum++;
						}
					}
					if(sum>=t)ans=min(ans,(c-b)*(e-d));
				}
			}
		}
	}
    cout<<ans;
}

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

#define imie(...) " [" <<#__VA_ARGS__<<':'<<(__VA_ARGS__)<<"] "

const int MAX = 1e5;
int arr[MAX+5][3];
int dp[MAX+5][3];
int n;

int go(int i,int T){
	if(i == n-1) return arr[i][T];
	if(dp[i][T]) return dp[i][T];

	int ans = INT_MIN;
	for(int t:{0,1,2}){
		if(t != T){
			ans = max(ans,go(i+1,t));
		}
	}
	return dp[i][T] = ans + arr[i][T];
}
int main () {
	#ifndef ONLINE_JUDGE
	    freopen("in.txt","r",stdin);
	    freopen("out.txt","w",stdout);
    #endif
	cin>>n;

	for(int i=0;i<n;i++){
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	int ans = INT_MIN;
	for(int i=0;i<3;i++) {
		ans=max(ans,go(0,i));
	}
	cout<<ans;
	
	

}

Measured memory_bytes: 13752
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
 
int main()
{
 
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int x,n,s,i,j;
    vii v;
    cin>>n>>s;
    int dp[n+1][s+1];
    for(i=0;i<n;++i){
    	cin>>x;
    	v.pb(x);
    }
    for(i=0;i<=n;++i){
    	for(j=0;j<=s;++j){
    		dp[i][j]=0;
    	}
    }
    // base case
    dp[0][0]=1;
    
    for(i=0;i<n;++i){
    	for(j=0;j<=s;++j){
    		// first choice that we don't take the ith element
    		dp[i+1][j] = (dp[i+1][j] + ((2 % mod * dp[i][j] % mod) % mod)) % mod;
            dp[i+1][j] %= mod;
           // second choice that we take the ith element into the subset which contains sum j 
    	   // the resultant subset will be of sum previous subset sum + v[i]
    		if((j + v[i]) <= s){
               dp[i+1][j + v[i]] = (dp[i+1][j + v[i]] + dp[i][j]) % mod;
    		}
    		// here when we take extra one element the number of subsets which will contain this subset
    		// will be half of what it was for previous subset
    	}
    }
    cout<<dp[n][s];
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++){
    cin >> d.at(i);
  }
  long int out = 0;
  for(int i = 0; i < n-1; i++){
    for(int j = i+1; j < n; j++){
      out += d.at(i) * d.at(j);
      
    }
  
  }
  cout << out;
}

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

int main() {
  uint64_t n;
  std::cin >> n;

  uint64_t h[5] = {0, 0, 0, 0, 0};

  for (uint64_t i = 0; i < n; i++) {
    std::string s;
    std::cin >> s;
    switch (s[0]) {
      case 'M':
        h[0]++;
        break;
      case 'A':
        h[1]++;
        break;
      case 'R':
        h[2]++;
        break;
      case 'C':
        h[3]++;
        break;
      case 'H':
        h[4]++;
        break;
      default:
        break;
    }
  }
  uint64_t count = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      for (int k = j + 1; k < 5; k++) {
        count += h[i] * h[j] * h[k];
      }
    }
  }
  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void){

    int a[5]={0};
    while(scanf("%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4])!=EOF){
        string str="null";
        sort(a,a+5);
        if(((a[0]==a[1])&&(a[2]==a[3])&&(a[2]==a[1]))||((a[1]==a[2])&&(a[2]==a[3])&&(a[3]==a[4])))str="four card";
        else if(((a[0]==a[1])&&(a[1]==a[2])&&(a[3]==a[4]))||((a[0]==a[1])&&(a[2]==a[3])&&(a[3]==a[4])))str="full house";
        else if(((a[0]==1)&&(a[1]==10)&&(a[2]==11)&&(a[3]==12)&&(a[4]==13))||((a[0]+1==a[1])&&(a[1]+1==a[2])&&(a[2]+1==a[3])&&(a[3]+1==a[4])))str="straight";
        else if(((a[0]==a[1])&&(a[1]==a[2]))||((a[1]==a[2])&&(a[2]==a[3]))||((a[2]==a[3])&&(a[3]==a[4])))str="three card";
        else if(((a[0]==a[1])&&((a[2]==a[3])||(a[3]==a[4])))||((a[1]==a[2])&&(a[3]==a[4])))str="two pair";
        else if((a[0]==a[1])||(a[1]==a[2])||(a[2]==a[3])||(a[3]==a[4]))str="one pair";

        cout<<str<<endl;
    }
	return 0;
}

Measured memory_bytes: 1236
import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 7 || n == 5 || n == 3) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }
}


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

int main(){
	int A,B,bener=1;
	scanf("%d %d", &A,&B);
	char S[A+B+1];
	scanf("%s",&S);
	int len=strlen(S);
	for (int i=0;i<len;i++){
		if (!(S[i]>='0'&&S[i]<='9') && i!=A){
			bener = 0;
		} 
		
	}
	if (!(A+B+1<=len&&S[A]=='-')){
		bener = 0;
	}
	bener==0?printf("No\n"):printf("Yes\n");
	
	return 0;
}

Measured memory_bytes: 1616
use std::cmp;

use num_integer::{gcd, div_floor};
use proconio::input;

#[proconio::fastout]
fn main() {
    input! {
        N: i128,
        M: i128
    }
    if N == 1 {
        println!("{}", M);
        return;
    }
    let mut max = 1;
    let mut x = 2;
    while x * x <= M {
        if M % x == 0 {
            if div_floor(M, N) >= x {
                max = cmp::max(max, x);
            }
            if div_floor(M, N) >= M / x {
                max = cmp::max(max, M / x);
            }
        }
        x += 1;
    }
    println!("{}", max);
}


Measured memory_bytes: 2160
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<vector>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
typedef long long ll;
using namespace std;
char c[100];
int main()
{	scanf("%s",c+1);
	int n=strlen(c+1);
	for(rint i=1;i<n;i++)
	if(c[i]=='A'&&c[i+1]=='C'){cout<<"Yes"<<endl;return 0;}
	cout<<"No"<<endl;
 	return 0;
}


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

long long P[5010];
long long C[5010];

int main() {
	long long N, K;
	cin >> N >> K;
	for (long long i = 1; i <= N; i++) {
		cin >> P[i];
	}
	for (long long i = 1; i <= N; i++) {
		cin >> C[i];
	}

	long long nmax = -1000000000;//各Nについてのmax
	long long ntemp = 0;//各Nについての途中得点
	long long allmax = -1000000000;//全部の最大値
	int flag;
	int cnt;

	//全マスについて最大値を計算する
	for (int i = 1; i <= N; i++) {
		nmax = -1000000000;
		ntemp = 0;
		flag = 1;//サイクルを回ったかどうかのフラグ
		cnt = 1;//サイクルの数 最初の１回は動いてからスタート
		int temp = i;//最初のマスを記録
		int now = temp;//現在のマス
		//最初の移動をする
		now = P[now];
		ntemp += C[now];
		nmax = max(nmax, ntemp);
		//スタート
		do {
			if (cnt == K) {
				flag = 0;//サイクルを回らずに終わった場合
				//cout<<"サイクルを回らずに終わった場合"<<endl;
				break;
			}
			now = P[now];
			ntemp += C[now];
			nmax = max(nmax, ntemp);
			cnt++;

		} while (now != temp);
		//cout<<now<<" "<<cnt<<"flag"<<nmax<<"ntemp"<<ntemp<<endl;

		//サイクルを回らずに終わった場合
		if (flag != 1) {
			allmax = max(allmax, nmax);
			continue;
		}

		//サイクルした場合
		  //サイクル後スコアが減少している場合
		if (ntemp <= 0) {
			allmax = max(allmax, nmax);
			//cout<<nmax<<"$"<<allmax<<endl;
			continue;
		}

		//サイクル後スコアが増加している場合
		if (ntemp > 0) {
			long long sc = K / cnt;//何サイクル回ったか
			//サイクルを回った余りの数　zc
			long long zc = K - (sc - 1) *cnt;//残り回数を計算 1周余計に回す
			ntemp = (sc - 1)*ntemp;
			nmax = max(nmax, ntemp);
			//cout<<"sc"<<sc<<"zc"<<zc<<"ntemp"<<ntemp<<endl;
			for (int j = 0; j < zc; j++) {
				now = P[now];
				ntemp += C[now];
				//cout<<i<<"###"<<ntemp<<endl;
				nmax = max(nmax, ntemp);
			}
			//cout<<nmax<<"*"<<allmax<<endl;
			allmax = max(allmax, nmax);
			continue;
		}
	}
	//cout<<flag<<" "<<cnt<<endl;
	cout << allmax << endl;
	return 0;
}


Measured memory_bytes: 3712
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W, K = map(int, input().split())
for h in range(H+1):
    for w in range(W+1):
        if (W-w)*h+(H-h)*w == K:
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
long long a[10010],b[10010];
long long tot,suma,sumb;
int main()
{
    int n;
    cin >> n;
    for (int k = 1;k <= n;k++)
    {
        cin >> a[k];
        suma += a[k];
    }
    for (int k = 1;k <= n;k++)
    {
        cin >> b[k];
        sumb += b[k];
    }
    if (suma > sumb)
    {
        cout << "No";
        return 0;
    }
    long long d = sumb - suma;
    for (int k = 1;k <= n;k++)
    {
        if (b[k] > a[k])
            tot += (b[k] + 1 - a[k])/2;
    }
    if(tot > d)
        cout<<"No";
    else
        cout << "Yes";
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int e=(a+d-1)/d,f=(c+b-1)/b;
	if(e>=f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

int main() {
    char a;
    cin >> a;
    if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pct __builtin_popcount

#define N 100100
int n, a[N];

int main () {
	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	int S = 0;
	for (int i = 1; i <= n; i ++)
		if (a[a[i]] == i) S ++;
	cout << S/2 << endl;
	return 0;
}

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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b){
    cout<<c<<endl;
  }
  else if(a==c){
    cout<<b<<endl;
  }
  else{
    cout<<a<<endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
int main (void) {
    int N;
    int a[N_MAX];
    ll X = 0;
    ll xi = 0;
    ll ans = LLONG_MAX;

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

    for (int i = 0; i < N - 1; i++) {
        xi += a[i];
        ans = min(ans, abs(X - 2 * xi));
    }

    cout << ans << endl;

    return 0;
}

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

class Program {

    const int BuildNum = 4;
    const int FloorNum = 3;
    const int RoomNum = 10;

    private static int Main() {
        var input = Console.ReadLine();
        var values = input.Split( ' ' );

        int n = int.Parse( values[ 0 ] );
        int m = int.Parse( values[ 1 ] );

        List<List<int>> a = new List<List<int>>();
        for( int i = 0; i < n; ++i ) {
            input = Console.ReadLine();
            values = input.Split( ' ' );

            a.Add( values.Select( _ => int.Parse( _ ) ).ToList() );
        }
        
        int[] b = new int[ m ];
        for( int i = 0; i < m; ++i ) {
            input = Console.ReadLine();
            b[ i ] = int.Parse( input );
        }


        for( int i = 0; i < n; ++i ) {
            int sum = 0;
            for( int j = 0; j < m; ++j ) {
                sum += a[ i ][ j ] * b[ j ];
            }

            Console.WriteLine( sum );
        }
        
        return 0;
    }
}

Measured memory_bytes: 7976
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int a,b;
  cin>>a>>b;
  if(a==b) cout<<a+b<<endl;
  else cout<<2*max(a,b)-1<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
bool hate[10];

bool Check(int x) {
  if (x < 10 && !hate[x]) {
    return true;
  }
  if (hate[x%10]) {
    return false;
  } else {
    return Check(x/10);
  }
}

int main() {
  int i, j, k, l;
  int N, K;
  int D[10];
  bool flag = false;
  for (i = 0; i < 10; i++) {
    hate[i] = false;
  }
  vector<int> possible;
  scanf("%d", &N);
  scanf("%d", &K);
  for (i = 0; i < K; i++) {
    scanf("%d", &D[i]);
    hate[D[i]] = true;
  }
  int ans = 0;
  for (i = N; i < 99999 && !flag; i++) {
    if (Check(i)) {
      ans = i;
      break;
    }
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 128
package main
 
import (
  "bufio"
  "fmt"
  "os"
  "strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
 
func next() int {
  sc.Scan()
  i, _ := strconv.Atoi(sc.Text())
  return i
}
 
func main() {
  sc.Split(bufio.ScanWords)
  n := next()
  arrP:= make([]int, n, n)
  minP := n + 1
  i := 0
  for k := 0; k < n; k++ {
    arrP[k] = next()
    if arrP[k] < minP {
      minP = arrP[k]
      i++
    }
  }
  fmt.Println(i)
}

Measured memory_bytes: 3584
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  int x,n,tmp;
  char c[10];
  int p[101]={0};

  scanf("%d %d",&x,&n);
  if(n==0)
  {
    fgets(c,10,stdin);
    fgets(c,10,stdin);
  }
  for(int i=0;i<n;i++)
  {
    scanf("%d",&tmp);
    p[tmp]=1;
  }

  for(int i=0;i<51;i++)
  {
    if(p[x-i]==0)
    {
      printf("%d\n",x-i);
      break;
    }
    if(p[x+i]==0)
    {
      printf("%d\n",x+i);
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 1772
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  // 'E'の累積和
  int E[N];
  int L = 0, R = 0, ans = 0;
  S[0] == 'E' ? E[0] = 1 : E[0] = 0;
  for (int i = 1; i < N; i++) {
    if (S[i] == 'E')
      E[i] = E[i - 1] + 1;
    else
      E[i] = E[i - 1];
  }
  // 0番目がリーダー
  ans = E[N - 1];

  // i番目がリーダー
  for (int i = 1; i < N; i++) {
    L = i - E[i - 1];
    R = E[N - 1] - E[i];
    int cur = L + R;
    ans = min(cur, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1796
/* ****Shrey97**** */

#include <bits/stdc++.h>

#define hell 1000000007
#define N 100005

using namespace std;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    int a[n], b[n];
    for(int i=0;i<n-1;i++)
    {
        cin >> b[i];
    }   
    a[0] = b[0];
    b[n-1] = hell;
    int s = b[0];
    for(int i=1;i<n;i++)
    {
        a[i] = min(b[i], b[i-1]);
        s += a[i];
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define ordered_set tree<int , null_type,less<int , rb_tree_tag,tree_order_statistics_node_update>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 100000000
// order_of_key and *find_by_order

int32_t main() {
	fast;
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != t[i]) {
			cnt++;
		}
	}
	cout << cnt;







}

Measured memory_bytes: 3884
import java.util.*

fun main(args : Array<String>) {
    val scanner = Scanner(System.`in`)
    println(inOutExec(scanner))
}

fun inOutExec(scanner: Scanner): String {
    val num = scanner.nextInt()
    scanner.nextInt()

    val strList = mutableListOf<String>()
    repeat(num) {
        strList.add(scanner.next())
    }
    strList.sort()
    return strList.joinToString(separator = "")
}

Measured memory_bytes: 31388
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c,d = 0,e;
    cin >>a>>b;
    
    for(int i = 0; i < b; i++){
        
        cin >>c;
        d += c;
    }
    
    e = d / (a + 1);
    
    if(d % (a + 1)){
        e = e + 1;
    }
    
    
    cout <<e<<endl;
}



Measured memory_bytes: 3100
N,K= map(int,input().split())
rich_boy = set()
all_boy = set([n for n in range(1,N+1)])
for k in range(K):
    d = input()
    A = set(map(int,input().split()))
    rich_boy=rich_boy.union(A)
print(len(all_boy-rich_boy))

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

int N;
int L[8];
int A, B, C;

int dfs(int k, int a, int b, int c){
    if(k == N){
        if(!a || !b || !c) return 1e9;
        return abs(a-A) + abs(b-B) + abs(c-C);
    }
    int ans = 1e9;
    ans = min(ans, dfs(k+1, a+L[k], b, c) + (a ? 10 : 0));
    ans = min(ans, dfs(k+1, a, b+L[k], c) + (b ? 10 : 0));
    ans = min(ans, dfs(k+1, a, b, c+L[k]) + (c ? 10 : 0));
    ans = min(ans, dfs(k+1, a, b, c));
    return ans;
}

int main(){
    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; i++) cin >> L[i];
    cout << dfs(0, 0, 0, 0) << endl;
}


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

int main() {
    int a, b, k;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main() {
	int a[5] , i, j;
	int max, db, f;
	// get the data
	while( scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4])!=EOF ){
		int c[13] = {0};
		int m[5] = {0};
		f = 0;
		
		// make card list
		for(i=0; i<5; i++) {
			c[ a[i]-1 ] += 1;
		}
		
		// make the number of card list
		for(i=0; i<13; i++) {
			m[ c[i] ] += 1;
		}
		
		// examine the role
		while(1){
			// --- four card
			if (m[4]==1) {
				printf("four card");
				break;
			}

			// --- full house
			if ( (m[3]==1)&&(m[2]==1) ) {
				printf("full house");
				break;
			}

			// --- straight
			for(i=0; i<9; i++) {
				if ( (c[i])&&(c[i+1])&&(c[i+2])&&(c[i+3])&&(c[i+4]) ) {
					f = 1;
					break;
				}
			}
			// 10 J Q K A
			if ( (c[9])&&(c[10])&&(c[11])&&(c[12])&&(c[0]) ) f = 1;
			
			if (f==1) {
				printf("straight");
				break;
			}

			// --- three card
			if (m[3]==1) {
				printf("three card");
				break;
			}

			// --- two pair
			if (m[2]==2) {
				printf("two pair");
				break;
			}

			// --- one pair
			if (m[2]==1) {
				printf("one pair");
				break;
			}

			// --- none
			printf("null");
			break;
		}
		printf("\n");
	}
	return 0;
}

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

typedef long long ll;
#define rep(i, n) for(i = 0; i < n; i++)
const int maxn = 100000;

int N, M;
int P[maxn], Y[maxn];
vector<int> yd[maxn+1];

int main()
{
	cin >> N >> M;
	int i;
	rep(i, M) cin >> P[i] >> Y[i], yd[P[i]].push_back(Y[i]);
	rep(i, N) sort(yd[i+1].begin(), yd[i+1].end());
	rep(i, M) printf("%012lld\n", ll(P[i])*1000000+int(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i])-yd[P[i]].begin())+1);
}

Measured memory_bytes: 7808
#include <stdio.h>

void euc(int, int);

int main(void) {
  int a, b;
  while(1) {
    scanf("%d %d", &a, &b);
    if (a == 0 && b == 0)
      break;
    euc(a, b);
  }
  return 0;
}

void euc(int a, int b){
  int c = 0, r = 1, tmp;
  if(a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while(1) {
    r = a % b;
    c++;
    if (r == 0)
      break;
    else {
      a = b;
      b = r;
    }
  }
  printf("%d %d\n", b, c);
}



Measured memory_bytes: 2056
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define MAXN ((int)4e3+5)
#define MOD ((int)1e9 + 7) 
#define ll long long
#define _ << " " <<
#define TRACE(x) cerr << #x << " = " << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"


string s,t;
vector <char> w;
int dp[MAXN][MAXN];
pair <int,int> par[MAXN][MAXN];

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

	cin >> s >> t;

	dp[0][0] = (s[0] == t[0]);
	for (int j = 1; j < t.size(); ++j)
	{
		if(s[0] == t[j])
		{
			dp[0][j] = 1;
			par[0][j] = {-1,-1};
		}
		else
		{
			dp[0][j] = dp[0][j-1];		
			par[0][j] = {0,j-1};
		}
	}
	for (int i = 1; i < s.size(); ++i)
		if(t[0] == s[i])
		{
			dp[i][0] = 1;
			par[i][0] = {-1,-1};
		}
		else
		{
			dp[i][0] = dp[i-1][0];		
			par[i][0] = {i-1,0};
		}

	for (int i = 1; i < s.size(); ++i)
		for (int j = 1; j < t.size(); ++j)
		{
			if(s[i] == t[j])
			{
				dp[i][j] = dp[i-1][j-1] + (s[i]==t[j]);
				par[i][j] = {i-1,j-1};
			}
			else
			{
				if(dp[i-1][j] > dp[i][j-1])
				{
					dp[i][j] = dp[i-1][j];
					par[i][j] = {i-1,j};
				}
				else
				{
					dp[i][j] = dp[i][j-1];
					par[i][j] = {i,j-1};
				}
			}
		}

	int p1 = s.size()-1;
	int p2 = t.size()-1;
	int ans = dp[p1][p2];

	par[0][0] = {-1,-1};

	while(p1 >= 0 && p2 >= 0)
	{
		// cout << p1 _ p2 << endl; 
		if(s[p1] == t[p2])
			w.pb(s[p1]);

		auto tmp = par[p1][p2];
		p1 = tmp.first;
		p2 = tmp.second;
	}

	// cout << endl << "    ";
	// for (int i = 0; i < t.size(); ++i)
	// 	cout << i << " ";
	// cout << endl << "    ";
	// for (int i = 0; i < t.size(); ++i)
	// 	cout << t[i] << " ";
	// cout << endl;
	// for (int i = 0; i < s.size(); ++i)
	// {
	// 	cout << i _ s[i] << " ";
	// 	for (int j = 0; j < t.size(); ++j)
	// 		cout << dp[i][j] << " ";
	// 	cout << endl;
	// }

	reverse(all(w));
	for (int i = 0; i < w.size(); ++i)
		cout << w[i];

	return 0;
}


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

int main(){
  ll h,w;
  cin >> h >> w;
  if(h==1||w==1){
    cout << 1 << endl;
  	return 0;
  }
  cout << (h*w+1)/2;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int x;
int main() {
    cin >> x;
    int m = x / 500;
    m *= 1000;
    int n = (x % 500) / 5;
    m += n*5;
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vector<int> x(N), y(N);
    rep(i,N) {
        cin>>x[i]>>y[i];
    }
    map<P, int> mp;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            P p = make_pair(x[j]-x[i], y[j]-y[i]);
            if(p.first<0 && p.second<0){
                p.first*=-1;
                p.second*=-1;
            }
            if(p.first<0 && p.second>0){
                p.first*=-1;
                p.second*=-1;
            }
            if(p.first == 0 && p.second<0){
                p.second*=-1;
            }
            if(p.first<0 && p.second==0){
                p.first*=-1;
            }
            mp[p]++;
        }
    }
    int mx = 0;
    for(auto a : mp){
        chmax(mx, a.second);
    }
    cout<<N-mx<<endl;
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, Q) = Scanner.Scan<int, int>();
            var A = Scanner.ScanEnumerable<int>().ToArray();
            var ft = new FenwickTree(N);
            for (var i = 0; i < N; i++)
            {
                ft.Add(i, A[i]);
            }

            for (var i = 0; i < Q; i++)
            {
                var (t, p, x) = Scanner.Scan<int, int, int>();
                if (t == 0) ft.Add(p, x);
                else Console.WriteLine(ft.Sum(p, x));
            }
        }

        public class FenwickTree
        {
            private readonly int _n;
            private readonly long[] _data;

            public FenwickTree(int n = 0)
            {
                _n = n;
                _data = new long[n];
            }

            public void Add(int p, long x)
            {
                // if (p < 0 || _n <= p) throw new ArgumentException(nameof(p));
                p++;
                while (p <= _n)
                {
                    _data[p - 1] += x;
                    p += p & -p;
                }
            }

            public long Sum(int l, int r)
            {
                // if (0 > l || l > r || r > _n) throw new ArgumentException();
                return Sum(r) - Sum(l);
            }

            private long Sum(int r)
            {
                var s = 0L;
                while (r > 0)
                {
                    s += _data[r - 1];
                    r -= r & -r;
                }

                return s;
            }
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 86128
from itertools import accumulate

def solve():
    INF = 10**15

    N = int(input())
    As = list(map(int, input().split()))

    accAs = list(accumulate([0]+As))

    dp = [[INF]*(N) for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0

    for L in reversed(range(N)):
        dpL = dp[L]
        for R in range(L+1, N):
            dpL[R] = min([dpL[k-1] + dp[k][R] for k in range(L+1, R+1)]) + accAs[R+1] - accAs[L]

    print(dp[0][-1])


solve()


Measured memory_bytes: 6936
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


struct LCA {
	vector<vector<int>>table;
	vector<int>dep;
	vector<vector<int>>e;
	const int LOG = 25;
	void dfs(int now, int par, int d) {
		table[now][0] = par;
		dep[now] = d;
		fore(x, e[now]) {
			if (x != par)dfs(x, now, d + 1);
		}
	}
	//0-indexed
	//edgesは双方向
	void lcainit(int n, int root, vector<int>edges[]) {
		e.resize(n);
		dep.resize(n);
		table.resize(n);
		for (int i = 0; i < n; i++) {
			fore(x, edges[i])e[i].pb(x);
		}
		for (int i = 0; i < n; i++)table[i].resize(LOG);
		dfs(root, -1, 0);
		for (int k = 0; k + 1 < LOG; k++) {
			for (int i = 0; i < n; i++) {
				if (table[i][k] == -1)table[i][k + 1] = -1;
				else table[i][k + 1] = table[table[i][k]][k];
			}
		}
	}

	int query(int u, int v) {
		if (dep[u] > dep[v])swap(u, v);
		for (int i = LOG - 1; i >= 0; i--) {
			if (((dep[v] - dep[u]) >> i) & 1)v = table[v][i];
		}
		if (u == v)return v;
		for (int i = LOG - 1; i >= 0; i--) {
			if (table[u][i] != table[v][i]) {
				u = table[u][i];
				v = table[v][i];
			}
		}
		return table[u][0];
	}
};

vector<int>E[101010];
int d[101010];
set<int>st;


void dfs(int now,int pa,int depth){
	int cnt = 0;
	d[now] = depth;
	fore(x, E[now]) {
		if (x != pa) {
			cnt++;
			dfs(x,now,depth+1);
		}
	}
	if (cnt == 0)st.insert(now);
}

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

	int N, u, v;
	cin >> N >> u >> v;
	u--, v--;
	for (int i = 0; i < N - 1; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		E[A].pb(B);
		E[B].pb(A);
	}
	dfs(v,-1,0);

	LCA lca = LCA();
	lca.lcainit(N,v,E);

	int ans = -1;
	fore(x, st) {
		int l = lca.query(x,u);
		int d1 = d[l];
		int d2 = d[u] - d[l];
		if (d2 >= d1)continue;
		ans = max(ans,d[x]-1);
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 30848
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    ll a, b;
    cin >> n;
    vector<vector<ll>> arr;
    for(int i =0; i < n; i++) {
        cin >> a >> b;
        arr.push_back({a, b});
    }
    sort(arr.begin(), arr.end(), [](vector<ll> pre, vector<ll> post){
        return pre[0] + pre[1] > post[0] + post[1];
    });
    ll bob = 0, alice = 0;
    for(int i = 0; i < n; i+= 2)
        bob += arr[i][0];
    for(int i = 1; i < n; i+= 2)
        alice += arr[i][1];
    cout << bob - alice << endl;
    return 0;
}




Measured memory_bytes: 6708
#include<stdio.h>
#define NTL -1
#define M 25
typedef struct tree{
  int p;
  int l;
  int r;
}tree;
void pre(int,tree *);
void in(int,tree *);
void post(int,tree *);
int main(){
  int n,i,now,rt;
  /*scan n*/
  scanf("%d",&n);
  tree t[n];
  /*NTL*/
  for(i=0;i<n;i++){
    t[i].p=NTL;
  }
  /*scan tree*/
  for(i=0;i<n;i++){
    scanf("%d",&now);
    scanf("%d %d",&t[now].l,&t[now].r);
    if(t[now].l!=NTL) t[t[now].l].p=now;
    if(t[now].r!=NTL) t[t[now].r].p=now;
  }
  for(i=0;i<n;i++){
    if(t[i].p == NTL) rt =i;
  }
  printf("Preorder\n");
  pre(rt,t);
  printf("\n");
  printf("Inorder\n");
  in(rt,t);
  printf("\n");
  printf("Postorder\n");
  post(rt,t);
  printf("\n");
  return 0;
}

void pre(int now,tree *t){
  if(now == NTL) return;
  printf(" %d",now);
  pre(t[now].l,t);
  pre(t[now].r,t);
}
void in(int now,tree *t){
  if(now == NTL) return;
  in(t[now].l,t);
  printf(" %d",now);
  in(t[now].r,t);
}
void post(int now,tree *t){
  if(now == NTL) return;
  post(t[now].l,t);
  post(t[now].r,t);
  printf(" %d",now);
}


Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<complex>
#include<string>
#include<vector>
#include<numeric>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
using namespace std;
typedef pair<int,int> pii;
const int maxn = 200050;
int n,m;
vector<int> g[maxn];
int ok = 0;
bool seen[maxn];
void dfs(int u,int dep)
{
	if(seen[u])
		return;
	if(dep > 2)
		return;
	seen[u] = 1;
	REP(i,g[u]) if(!seen[g[u][i]]) dfs(g[u][i],dep + 1);
}
int main()
{
	scanf("%d %d",&n,&m);
	int u,v;
	for(int i = 0 ; i < m ; ++i)
	{
		scanf("%d %d",&u,&v);
		--u; --v;
		g[u].pb(v); g[v].pb(u);
	}
	dfs(0,0);
	if(seen[n - 1])
		puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}


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

long long gcd(long long n, long long m){
  if(n % m == 0) return m;
  n = n % m;
  return gcd(m, n);
}

long long lcm(long long n, long long m){
  return m * n / gcd(n, m);
}

int main() {
  long long n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  
  bool ok = true;
  long long mul = n * m;
  for(long long i = 0; i < n; i++){
    if(i * m % n) continue;
    long long num = i * m / n;
    if(num >= m) break;
    char sc = s.at(i), tc = t.at(num);
    if(sc != tc) ok = false;
  }
  
  if(ok) cout << lcm(n, m) << endl;
  else cout << -1 << endl;
}

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

struct State{
  int r, d, c;
};



int main(){
  
  int D,N;
  int a[101], e[101], r[101];
  
  while(1){
    cin >> D >> N;
    if( D==0 && N==0) break;
    
    for(int i = 0; i < N; i++){
      cin >> a[i] >> e[i] >> r[i];
    }
    
    queue<State> q;
    q.push((State){0,D,0});
    bool flag[101][101];
    memset(flag, 0, sizeof(flag));
    flag[0][D] = true;
    bool visit = false;
    while(!q.empty()){
      State s = q.front();q.pop();
      if(s.d == 0){
	visit = true;
	cout << s.c << endl;
	break;
      }
      for(int i = 0; i < N; i++){
	State next;
	if(s.r >= r[i]){
	  next.c = s.c+1;
	  next.d = max(0,s.d-a[i]);
	  next.r = min(100,s.r + e[i]);
	  if(flag[next.r][next.d]) continue;
	  flag[next.r][next.d]=true;
	  q.push(next);
	}
      }

    }
    if(!visit) cout << "NA" << endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 1256
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(a,b):#gcd :: greatest common divisor(最大公約数) :: G
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(X,Y):#lcm :: least common multiple(最小公約数)) :: L
    return X*Y // gcd(X,Y) # XY = GL

ans = 1

for t in T:
    ans = lcm(ans, t)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 2005;

LL f[N][N];
int main() {
    int n;
    cin >> n;
    LL ans = 0;
    f[0][0] = 1;
    for (int i = 1; i <= n / 3; i++) {
        LL now = 0;
        for (int j = 3; j <= n; j++) {
            now += f[i - 1][j - 3];
            f[i][j] = (f[i][j] + now) % mod;
        }
        ans += f[i][n];
    }
    cout << ans % mod << endl;
    return 0;
}


Measured memory_bytes: 14048
import sys
import itertools

def peeks(f):
    readline = f.readline
    n, m = map(int, readline().split())
    h = tuple(itertools.chain(
        [0],
        map(int, readline().split())))
    observatories = tuple(tuple(map(int, line.split())) for line in f)
    # print(n, m)
    # print(f'{h=}')
    # print(f'{observatories=}')

    L = [0] * (n + 1)
    for a, b in observatories:
        L[a] = max(L[a], h[b])
        L[b] = max(L[b], h[a])

    # print(f'{L=}')
    ans = sum(1 for index, elevation in enumerate(L[1:], 1) if h[index] > elevation)

    return ans


def main():
    ans = peeks(sys.stdin.buffer)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 28096
using System;
using System.Collections.Generic;

class Program
{
    public void Proc()
    {
        string[] inpt = Console.ReadLine().Split(' ');
        int W = int.Parse(inpt[0]);
        int H = int.Parse(inpt[1]);
        int x = int.Parse(inpt[2]);
        int y = int.Parse(inpt[3]);
        int r = int.Parse(inpt[4]);
        // x ??????????????????
        int xMin = r;
        int xMax = W - r;

        // y ??????????????????
        int yMin = r;
        int yMax = H - r;

        bool isIn = (x >= xMin) && (x <= xMax) && (y >= yMin) && (y <= yMax);
        Console.WriteLine(isIn ? "Yes" : "No");
    }



    static void Main(string[] args)

    {

        Program prg = new Program();
        prg.Proc();

    }
}

Measured memory_bytes: 8868
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b[111111];
  int cnt[100001]={};
  int h=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=1;i<=n;i++){
    cin>>a,cnt[a]++;
  }
  for(int i=1;i<=n;i++)if(cnt[i]==0)h=i;
  if(h){
    cout<<"No"<<endl;
    for(int i=1;i<=n;i++){
      if(i-1)cout<<" ";
      cout<<i;
    }
    cout<<endl;
     for(int i=1;i<=n;i++){
      if(i-1)cout<<" ";
      if(b[i-1]==h)cout<<i%n+1;
      else cout<<i;
    }
    cout<<endl;
  }else cout<<"Yes"<<endl;
  return 0;
}



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

int main(){
	long long int x[5];
  	int ck=0;
  	for(int i=0;i<5;i++){
    	cin>>x[i];
      	if(x[i]==0) ck=i;
    }
  	
  	cout<<ck+1<<endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6;
int n,i,l,r,mid,sum[N],c[N],x;
signed main(){
	scanf("%lld",&n);
	for (i=1;i<=n;i++) 
		scanf("%lld",&x), ++sum[++c[x]];
	for (i=1;i<=5e5;i++) sum[i]+=sum[i - 1];
	for (i=1;i<=n;i++){
		l = 1, r = 4e5;
		while (l <= r) {
			mid = (l + r) >> 1;
			(mid * i <= sum[mid])? l = mid + 1: r = mid - 1;
		}
		printf("%lld\n", l - 1);
	} return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>
#include<stdlib.h>
#define max 100


int main()
{
  int i,N,v,j,k;
  int A[max];

  scanf("%d",&N);
   if( N < 1 || 100 < N ) exit(2);

   for( i = 0 ; i < N ; i++ ){
     scanf("%d",&A[i]);
     if( A[i] < 0 || 1000 < A[i] ) exit(3);
   }

for( k = 0 ; k < N-1 ; k++)
      printf("%d ",A[k]);
 printf("%d\n",A[k]);

  for( i = 1 ; i <= N-1 ; i++ ){

    v = A[i];
    j = i-1;
    while( j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
}   
for( k = 0 ; k < N-1 ; k++)
      printf("%d ",A[k]);
 printf("%d\n",A[k]);
  }

   return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main(int argc, char** argv, char** opt) {
#if 1
        long N,M;
        cin >> N >> M;
#else
        //long N = 1;                                                                                                                          
        //long M = 6;                                                                                                                          
        long N = 12345;
        long M = 678901;
#endif
        long res = 0;
        if (N > M/2) {
		res = M/2;
	} else if (N == M/2) {
		res = N;
	} else {
                res = N + (M - 2 * N) / 4.0;
	}
        cout << res << endl;
}


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

string s;

int m=1e9+7,dp[10009][2][100],p,d;


int dfs(int idx,int z,bool tight){
  if(idx==s.size())return !z;
  int &res=dp[idx][tight][z];
  if(~res)return res;
  res=0;
  int r=(tight?9:s[idx]-48);
  for(int i=0;i<=r;i++){
    res+=dfs(idx+1,(z+i)%d,tight||i<r);
    res%=m;
  }
  return res;
}

int main(){
  memset(dp,-1,sizeof dp);
  getline(cin,s);
  cin>>d;
  cout<<(dfs(0,0,0)-1+m)%m<<endl;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 8832
<?php
$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($N,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

//次の日が上がる＝買う
//下がる＝売る

$kabutan = 0;
$kabumai = 0;
$money = 1000;
for($i=0;$i<$N-1;$i++) {
  //翌日値上がりする。
  if ($A[$i]<$A[$i+1]) {
    if (intdiv($money,$A[$i])>0) {
      $kabutan = $A[$i];
      $kabumai = intdiv($money,$A[$i]);
      $money = $money-$kabutan*$kabumai;
    }
  }
  else {
    //翌日値下がりする=売却
    if ($kabumai > 0) {
      $money += $A[$i]*$kabumai;
      $kabumai = 0;
      $kabutan = 0;
    }
  }
}
if ($kabumai > 0) {
  $money += $A[$i]*$kabumai;
}
printf("%d\n",$money);


Measured memory_bytes: 16108
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat Dec  8 21:13:28 2018
//
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)

	arr := make([]int, N)
	for i := range arr {
		fmt.Scan(&arr[i])
	}
	sort.Ints(arr)
	ans := 0
	for i := 0; i < N-1; i++ {
		ans += arr[i]
	}
	ans += arr[len(arr)-1] / 2

	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        System.out.println(Answer(N));
    }
    
    public static long Answer(long x){
        
        int rx = (int) Math.sqrt(x);
        int A = 1;
        
        for(int i = rx; i >= 2; i--){
            if (x % i == 0){
                A = i;
                break;
            }
        }
        
        return A + (x / A) -2;
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
  ll A,B,C,X,Y,co=0;cin >> A >> B >> C >> X >> Y;
  if(A+B<=2*C){
    cout << A*X+B*Y <<endl;
    return 0;
  }
  else{
    if(X<Y){
      cout << min(X*2*C+B*(Y-X),Y*2*C) << endl;
    }
    else{
      cout << min(Y*2*C+A*(X-Y),X*2*C) << endl;
    }
  }
}

Measured memory_bytes: 256
import sys
import itertools
import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())

A = [int(x) for x in readline().split()]
B = [int(x) for x in readline().split()]

ans1 = 0
ans2 = 0
ans4 = 0
ans3 = 0

for i, j in zip(A, B):
    ans1 += abs(i - j)
    ans2 += (i - j) ** 2
    ans3 += (abs(i - j)) ** 3
    ans4 = max(ans4, abs(i - j))
print(ans1 * 1.0, ans2 ** .5, ans3 ** (1 / 3), ans4 * 1.0, sep='\n')



Measured memory_bytes: 5740
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;

char ch;

int main(){
	cin >> ch;
	cout << (char)(ch + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
A, B, C = map(int, input().split(' '))
K = int(input())

while K > 0:
    if B > A:
        break
    B *= 2
    K -= 1

while K > 0:
    if C > B:
        break
    C *= 2
    K -= 1

if A < B < C:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9108
import sys
sys.setrecursionlimit(10**7)
 
N, Q = map(int, input().split())
root = [[] for _ in range(N)]
ans = [0]*N
 
for _ in range(N-1):
  a,b=map(int, input().split())
  a,b=a-1,b-1
  root[a].append(b)
  root[b].append(a)

for _ in range(Q):
  p,x=map(int, input().split())
  ans[p-1]+=x
  
visited=[False]*N
def dfs(v):
  visited[v] = True
  for go in root[v]:
    if visited[go]:
      continue
    ans[go] += ans[v]
    dfs(go)

dfs(0)
print(*ans)


Measured memory_bytes: 223348
#include<stdio.h>
#define N 100

int min(int,int);

int main(){
  int i,k,l,ntw,ptw[N+1],mtw[N+1][N+1];
  scanf("%d",&ntw);
  for(i=1;i<=ntw;i++){
    scanf("%d %d",&ptw[i-1],&ptw[i]);
  }

  for(i=1;i<=ntw;i++)mtw[i][i]=0;
  for(l=2;l<=ntw;l++){
    for(i=1;i<=ntw-l+1;i++){
      int j=i+l-1;
      mtw[i][j]=(1<<21);
      for(k=i;k<=j-1;k++){
	mtw[i][j]=min(mtw[i][j],mtw[i][k]+mtw[k+1][j]+ptw[i-1]*ptw[k]*ptw[j]);
      }
    }
  }

  printf("%d\n",mtw[1][ntw]);

  return 0;
}

int min(int a,int b){
  if(a<=b)return a;
  else return b;
}



Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VII;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  VI A(N),B(N),C(N-1);
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>B[i];
  rep(i,N-1) cin>>C[i];
  ll ans=0;
  rep(i,N) ans+=B[i];
  rep(i,N){
    if(i) if(A[i]==A[i-1]+1) ans+=C[A[i-1]-1];
  }
  cout<<ans<<endl;
}




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

using namespace std;

int main (int argc, char const* argv[])
{
	int w,d;
	cin >> w >> d;
	while(w||d)
	{
		int s = 0;
		auto count = vector<int>(21,0);
		for (unsigned int i = 0; i < w; i += 1)
		{
			int n;
			cin >> n;
			s += n;
			count[n]++;
		}
		for (unsigned int i = 0; i < d; i += 1)
		{
			int n;
			cin >> n;
			if(count[n] <= 0)
			{
				s += n;
			}
			count[n]--;
		}
		cout << s << endl;
		cin >> w >> d;
	}
	return 0;
}

Measured memory_bytes: 1192
using System;

namespace ABC_119_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split('/');
            int a = int.Parse(word[0]);
            int b = int.Parse(word[1]);
            int c = int.Parse(word[2]);
            if (b <= 4)
            {
                Console.WriteLine("Heisei");
            }
            else
            {
                Console.WriteLine("TBD");
            }
            Console.ReadKey();
        }
    }
}


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

int main() {
	vector <int> val(5);
	vector <int> val_(5);
	int x=0;

	for (int i = 0; i < 5; i++) {
		cin >> val[i];
		val_[i] = val[i] % 10;
		x += val[i] - val_[i] + 10;
		if (val_[i] == 0) {
			x -= 10;
			val_[i] += 10;
		}
	}

	x = x + *min_element(val_.begin(), val_.end()) -10;


	cout << x << endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
dp=[0]*10
for i in range(10):
    dp[i]+=c[i][1]
for _ in range(11):
    for j in range(10):
        for k in range(10):
            dp[j]=min(dp[j],dp[k]+c[j][k])
count=0
for _ in range(h):
    a=list(map(int,input().split()))
    for l in a:
        if l!=-1:
            count+=dp[l]
print(count)


Measured memory_bytes: 73736