akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7)
n,m=map(int,input().split())
root_kouho=set(list(range(n)))
leaf=set(list(range(n)))
ki=[[] for _ in range(n)]
for i in range(n-1+m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  root_kouho.discard(b)
  leaf.discard(a)
  ki[b].append(a)
root=root_kouho.pop()
ans=[-1]*n
dp=[-1]*n # 根までの最長距離
ans[root]=0
dp[root]=0
def func(v):
  if dp[v]>=0:
    return dp[v]
  else:
    ret=-1
    for nv in ki[v]:
      tmp=func(nv)
      if ret<tmp:
        ret=tmp
        ans[v]=nv+1
    dp[v]=ret+1
    return ret+1
while leaf:
  l=leaf.pop()
  func(l)
print(*ans,sep='\n')
#print(dp)

Measured memory_bytes: 117148
#include <stdio.h>
#include <math.h>

long long max_divisor(long long n)
{
    long long max_div = 1;
    long long max_len = (long long)sqrt(n);

    for (int i=max_len; i>=1; i--)
    {
        if (n % i == 0) return n / i;
    }

    return 1;
}

int main()
{
    long long n; scanf("%lld", &n);
    long long max_div = max_divisor(n);

    printf("%lld\n", max_div + n/max_div - 2);
}

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

using namespace std;

int main()
{
  int x[10][10];
  for(int i = 0; i < 10; i++) {
    for(int j = 0; j < 10; j++) cin >> x[i][j];
  }
  int ans = 0;
  for(int i = 0; i < 10000; i++) {
    char id[6];
    sprintf(id, "%04d0", i);
    int res = 0;
    for(int j = 0; j < 4; j++) res = x[res][id[j]-'0'];
    id[4] = res + '0';
    bool flag = false;
    for(int j = 0; j < 5; j++) {
      char c = id[j];
      for(int k = 0; k < 10; k++) {
	if(c-'0' == k) continue;
	id[j] = k+'0';
	int tmp = 0;
	for(int l = 0; l < 5; l++) tmp = x[tmp][id[l]-'0'];
	if(tmp == 0) flag = true;
      }
      id[j] = c;
    }
    char s[6]; strcpy(s, id);
    for(int j = 0; j < 4; j++) {
      swap(id[j], id[j+1]);
      if(strcmp(s, id) == 0) {
	swap(id[j], id[j+1]);
	continue;
      }
      int tmp = 0;
      for(int k = 0; k < 5; k++) tmp = x[tmp][id[k]-'0'];
      if(tmp == 0) flag = true;
      swap(id[j], id[j+1]);
    }
    if(flag) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3220
import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
a = list(map(lambda x: x*(-1), a))  # 各要素を-1倍

heapq.heapify(a)

for i in range(m):
    minimum=heapq.heappop(a)
    mini=((minimum*(-1))//2)*(-1)
    heapq.heappush(a,mini)
    
print(-sum(a))
    



Measured memory_bytes: 14180
import sys

input = sys.stdin.readline


def main():
    H, W, K = [int(x) for x in input().split()]
    MOD = 10 ** 9 + 7

    if W == 1:
        print(1)
        return

    cnt = [0] * (W - 1)
    cntz = [0] * W
    for i in range(2 ** (W - 1)):
        tmp = [0] * (W - 1)
        for j in range(W - 1):
            if i >> j & 1:
                tmp[j] += 1
        # 2辺連続で引かれていないかをチェック
        for j, k in zip(tmp, tmp[1:]):
            if j == k == 1:
                break
        else:
            # チェックをパスした状態をカウント
            for j in range(W - 1):
                cnt[j] += tmp[j]
            for j in range(W):
                if j == 0:
                    if tmp[j] == 0:
                        cntz[j] += 1
                elif j == W - 1:
                    if tmp[j - 1] == 0:
                        cntz[j] += 1
                else:
                    if tmp[j] == tmp[j - 1] == 0:
                        cntz[j] += 1

    dp = [[0] * W for j in range(H + 1)]
    dp[0][0] = 1

    for j in range(H):
        for i in range(W):
            if i == 0:
                dp[j + 1][i] += dp[j][i] * cntz[i]
                dp[j + 1][i + 1] += dp[j][i] * cnt[i]
                dp[j + 1][i] %= MOD
                dp[j + 1][i + 1] %= MOD
            elif i == W - 1:
                dp[j + 1][i] += dp[j][i] * cntz[i]
                dp[j + 1][i - 1] += dp[j][i] * cnt[i - 1]
                dp[j + 1][i] %= MOD
                dp[j + 1][i - 1] %= MOD
            else:
                dp[j + 1][i] += dp[j][i] * cntz[i]
                dp[j + 1][i + 1] += dp[j][i] * cnt[i]
                dp[j + 1][i - 1] += dp[j][i] * cnt[i - 1]
                dp[j + 1][i] %= MOD
                dp[j + 1][i + 1] %= MOD
                dp[j + 1][i - 1] %= MOD

    print(dp[-1][K - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3192
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        String C = sc.next();
        char[]c = C.toCharArray();
        
        if(c[0]=='a' || c[0]=='i' || c[0]=='u' || c[0]=='e' | c[0]=='o') {
            System.out.println("vowel");
        }else {
        	System.out.println("consonant");
             }
     }
}

Measured memory_bytes: 35672
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

#n = int(input())
#n,m = [int(i) for i in readline().split()]
s = input()
l = len(s)

def calc(a,b):
    c = max(a,b)
    d = min(a,b)
    return c*(c+1)//2 + (d-1)*d//2

#0: < 1: >
now = ">"
ans = 0

cnt0 = 0 #<
cnt1 = 0 #>
for i in s:
    if now != i:
        now = i
        if i == "<":
            ans += calc(cnt0,cnt1)
            cnt0 = 1
            cnt1 = 0
        else: cnt1 += 1
    else:
        if i == ">": cnt1 += 1
        else: cnt0 += 1


if s[-1] == "<":
    ans += cnt0*(cnt0+1)//2
else:
    ans += calc(cnt0,cnt1)

print(ans)



Measured memory_bytes: 4212
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

M = []
for i in range(0, X):
    for j in range(0, Y):
        for k in range(0, Z):
            if (i+1) * (j+1) * (k+1) <= K:
                M.append(A[i] + B[j] + C[k])
            else:
                break

M.sort(reverse=True)
for i in range(0, K):
    print(M[i])


Measured memory_bytes: 8764
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int[] x = nextInts();
		Arrays.sort(x);
		int ans=0 ;
		if(x[1]==x[2])
			ans=x[0];
		if(x[0]==x[1]){
			ans=x[2];
		}


		System.out.println(ans);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 23124
package main

import "fmt"

func main() {
	var a, b, c string
	m := map[string]string{}
	fmt.Scan(&a, &b, &c)
	m["a"] = a
	m["b"] = b
	m["c"] = c
	s := string(m["a"][0])
	m["a"] = m["a"][1:]
	for {
		if len(m[s]) == 0 {
			switch s {
			case "a":
				fmt.Println("A")
				return
			case "b":
				fmt.Println("B")
				return
			case "c":
				fmt.Println("C")
				return
			}
		}
		t := s
		s = string(m[s][0])
		m[t] = m[t][1:]
	}
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	long long int a,b,k;
	scanf("%lld %lld %lld",&a,&b,&k);
	if(a>k){
		a=a-k;
	}
	else{
		k=k-a;
		a=0;
		if(k>b){
			b=0;
		}
		else{
			b=b-k;
		}
	}
	printf("%lld %lld\n",a,b);
	return 0;
}


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

typedef long long ll;

const ll PR = 1000000007;

int N;
int A[1<<17];

ll csm[1<<17], fact[1<<17];
ll tot;

ll M(ll x) { return x % PR; }

ll mpow(ll base, ll exp) {
	ll res = 1;
	while (exp) {
		if (exp & 1) res = M(res * base);
		base = M(base * base);
		exp /= 2;
	}
	return res;
}

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%d", A+i);

	fact[0] = 1;
	for (int i = 1; i < (1<<17); ++i) fact[i] = M(fact[i-1] * i);

	for (int i = 0; i < N; ++i) csm[i] = M((i?csm[i-1]:0) + A[i]);

	for (int len = 0; len < N; ++len) {
		ll cnt = M(fact[N] * mpow(len + 1, PR - 2));
		ll sm = M((len ? csm[N-1] - csm[len-1] : 0) + PR + csm[N-len-1]);

		tot = M(tot + cnt * sm);
	}

	printf("%lld\n", tot);
}

Measured memory_bytes: 2432
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        //string input= Console.ReadLine();
        int input =int.Parse(Console.ReadLine());
        Console.WriteLine(input*(input+1)/2);


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

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

int main(int argc, char* argv[]) {
  int n;
  cin >> n;

  int* w = new int[n];

  int overall = 0;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
    overall += w[i];
  }

  int s1, s2;
  int target = overall;
  for (int i = 0; i < n; i++) {
    s1 = 0;
    for (int k = 0; k < i; k++) {
      s1 += w[k];
    }
    s2 = 0;
    for (int j = i; j < n; j++) {
      s2 += w[j];
    }
    target = min(target, abs(s1 - s2));
  }
  cout << target << endl;
}


Measured memory_bytes: 888
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    double s;
    cin>>s;
    printf("%.12f\n",(double)s*s*s/27);
    
    
    

    return 0;
}


Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
            {
                Console.WriteLine("Possible");
            }
            else
            {
                Console.WriteLine("Impossible");
            }
        }
    }
}

Measured memory_bytes: 13140
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
//#define inp(X) cin>>X;
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define vst(A) sort(A.begin(),A.end());
#define rvst (A) sort(A.rbegin(),A.rend());
#define pbp(a,b) push_back.make_pair(a,b)
#define vect(A) vector<long long> A;
#define ivect(A,n,p) vector<long long> A(n,p);
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long mod=(long long)(1e9+7);

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll a,ll p)
{
   return power(a,p-2,p);
}

int main()
{
    /*
    #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    */
    fio;
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        ivect(a,3,0);
        forin(i,0,2)
        cin>>a[i];
        vst(a);
        ll e=0;
        if(a[0]==a[1] && a[1]!=a[2])
        {
            
        }
        else if(a[1]==a[2] && a[1]!=a[0])
        {
            
        }
        else
        {
            e++;
        }
        if(e)
        cout<<"No"<<endl;
        else
        {
            cout<<"Yes"<<endl;
        }
        
        
        

    }
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    auto a = find(begin(s), end(s), 'A');
    auto z = find(rbegin(s), rend(s), 'Z');
    cout << (int) s.size() - distance(begin(s), a) - distance(rbegin(s), z) << endl;
}


Measured memory_bytes: 640
s = input().rstrip()
t = input().rstrip()
len_s = len(s)
len_t = len(t)

# Get longest LCS num
dp = [[0] * (len_t+1) for _ in range(len_s+1)]
for i in range(1, len_s+1):
    for j in range(1, len_t+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

# Restore LCS
h, w = len_s, len_t
ans = ""
while dp[h][w] != 0:
    while dp[h][w] == dp[h-1][w]:
        h -= 1
    while dp[h][w] == dp[h][w-1]:
        w -= 1
    h -= 1
    w -= 1
    ans += t[w]

print(ans[::-1])

Measured memory_bytes: 112348
<?php

$day = array('Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday');
$days = array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$sum = array(0);
for ($i = 1; $i < 12; $i++) {
    $sum[$i] = $sum[$i - 1] + $days[$i - 1];
}
while (TRUE) {
    fscanf(STDIN, '%d %d', $m, $d);
    if ($m === 0) {
        break;
    }
    $d = ($sum[$m - 1] + $d) % 7;
    echo $day[$d];
    echo PHP_EOL;
}

Measured memory_bytes: 6600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			if (a < c && c < b) {
				System.out.println("Yes");
			} else if (b < c && c < a) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
/*
int main(){
  int H, W;
  cin >> H>>W;
  int i;
  string s[51];
  for (int j = 0; j<W+2;j++){
    s[0]+=".";
    s[H+1]+=".";
  }
  for (int j=1; j<H+1;j++){
    cin >> s[j];
    s[j]="."+s[j]+".";
  }
  int j;
  string c[51][51];
  for (int k= 0; k<H+2; k++){
    for (int l =0;l<W+2; l++){
      c[k][l]=s[k].at(l);
    }
  }
  int count[51][51];
  for (int k= 1; k<H+1; k++){
    for (int l =1;l<W+1; l++){
      if (c[k][l]=="#"){
      }
      else{
        
        for (int m =k-1;m<=k+1;m++){
          for (int n=l-1;n<=l+1;n++){
            if (c[m][n]=="#"){
              count[k][l]++;
            }
          }
        }
      }
    }
  }
  for (int k= 1; k<H+1; k++){
    for (int l =1;l<W+1; l++){
      if (c[k][l]=="#"){
        cout << c[k][l];
      }
      else{
        cout << count[k][l];
      }
    }
    cout << ""<<endl;
  }
}
*/

int main() {
  int H, W;
  cin >> H>>W;
  string s[50];
  int dy[8]={-1, 0, 1, -1, 1, -1, 0, 1};
  int dx[8]={-1, -1, -1, 0, 0, 1, 1, 1};
  string c[50][50];
  for (int i=0; i<H;i++){
    cin >> s[i];
    for (int j=0;j<W;j++){
      c[i][j]=s[i].at(j);
    }
  }
  
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      if (c[i][j]=="#"){
        cout <<c[i][j];
      }
      else{
        int num=0;
        for (int k=0;k<8;k++){
          if (i==0){
            if(k==0||k==1||k==2){
              continue;
            }
          }
          if (i==H-1){
            if(k==5||k==6||k==7){
              continue;
            }
          }
          if (j==0){
            if(k==0||k==3||k==5){
              continue;
            }
          }
          if (j==W-1){
            if(k==2||k==4||k==7){
              continue;
            }
          }  
          
          if (c[i+dx[k]][j+dy[k]]=="#"){
            num++;
          }
        }
        cout << num;
      }
    }
    cout <<""<<endl;
  }
}

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

int main()
{
  int n;
  cin>>n;
  int arr[n+5];
  for(int i=0;i<n;i++)cin>>arr[i];
  for(int i=n-1;i>=0;i-=2)cout<<arr[i]<<" ",arr[i]=-1;
  for(int i=0;i<n;i++)
  {
      if(arr[i]!=-1)cout<<arr[i]<<" ";
  }
}


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

using namespace std;

typedef long long ll;


const int INF = 1e9;
const ll MOD = 1e9 + 7;  

int main(){
    int K,A,B;
    cin >> K >> A >> B;
    for(int i = 1; i <= 1000 ; i++){
        if(K * i >= A && K * i <= B){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}



Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    pair<int, int> P[n]; for (int i = 0; i < n; i++) cin >> P[i].first >> P[i].second;
    sort(P, P+n, [](auto x, auto y) { return x.first + x.second < y.first + y.second; });
    long long dp[2][n+1], cur = 0, prev = 1, inf = 1LL<<60;
    fill(dp[prev], dp[prev]+n+1, inf);
    fill(dp[cur], dp[cur]+n+1, inf);
    dp[prev][0] = 0;
    for (int i = 0; i < n; i++) {
        int hi = P[i].first, pi = P[i].second;
        dp[cur][0] = 0;
        for (int j = 1; j <= i+1; j++) {
            dp[cur][j] = dp[prev][j];
            long long hz = dp[prev][j-1];
            if (hz <= hi && dp[cur][j] > hz + pi) dp[cur][j] = hz + pi;
        }
        swap(cur, prev);
    }
    cout << lower_bound(dp[prev], dp[prev]+n+1, inf) - dp[prev] - 1 << endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
  unsigned int a, b, k;
  cin >> a >> b >> k;

  for (size_t i=0; i<k; ++i) {
    if (0 == i%2) {
      if (0 != a%2)
        --a;
      a /= 2;
      b += a;
    } else {
      if (0 != b%2)
        --b;
      b /= 2;
      a += b;
    }
  }

  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;

#[allow(unused_imports)]
use std::collections::*;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(non_snake_case)]
fn main() {
    let N: i64 = read();
    let mut m = 1i64 << 60;
    for _ in 0..5 {
        let tmp: i64 = read();
        m = min(m, tmp);
    }
    println!("{}", N/m+5-(N%m==0) as i64);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int W,a,b,maxi,mini;

int main(){
    cin >> W >> a >> b ;
    maxi=max(a+W,b+W);
    mini=min(a,b);
    if(maxi-mini>2*W)
    {
        printf("%d",maxi-mini-2*W);
    }
    else
    {
        printf("0");
    }
}
    
    
    
    

  

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

int main(void){
  int n, k, h, count = 0;
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    cin >> h;
    if(h >= k) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()

t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)

for i in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])


Measured memory_bytes: 7748
#include<cstdio>

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

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#define f first
#define s second
using namespace std;

int INF = (1<<21);
typedef pair<int,int> P;// f=to s=cost
vector<P> info[22];
int m_cost[22];
priority_queue<P, vector<P>, greater<P> > que;//queueに入るコストは合計コスト
int n, m;
int x1, x2;
int ans, y2;

void dijkstra(){
  while(!que.empty()){
    P now = que.top(); que.pop();
    int size = info[now.f].size();
    for(int i = 0; i < size; i++){
      if(info[now.f][i].s + now.s < m_cost[info[now.f][i].f]){
	m_cost[info[now.f][i].f] = info[now.f][i].s + now.s;
	P next;
	next.f = info[now.f][i].f;
	next.s = m_cost[info[now.f][i].f];
	que.push(next);
      }
    }
  }
  return;
}
    
int main(){
  for(int i = 0; i < 22; i++) m_cost[i] = INF;
  cin >> n;
  cin >> m;
  for(int i = 0; i < m; i++){
    P p;
    int a, b, c, d;
    scanf("%d,%d,%d,%d", &a, &b, &c, &d);
    p.f = b; p.s = c;
    info[a].push_back(p);
    p.f = a; p.s = d;
    info[b].push_back(p);
  }

  scanf("%d,%d,%d,%d", &x1, &x2, &ans, &y2);
  ans -= y2; 
  P p; p.f = x1; p.s = 0;
  que.push(p);
  dijkstra();
  
  ans -= m_cost[x2];

  for(int i = 0; i < 22; i++) m_cost[i] = INF;
  p.f = x2; p.s = 0;
  que.push(p);
  dijkstra();
  
  ans -= m_cost[x1];

  cout << ans << endl;
}

Measured memory_bytes: 1244
A = int(input())
B = int(input())
C = int(input())
X = int(input())

num = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if X == 500 * a + 100 * b + 50 * c:
                num+=1

print(num)


Measured memory_bytes: 3060
#include <iostream>

#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

long long MOD = 1000000007;

int main(){
  long long N;
  string S;
  cin >> N >> S;
  // 入力終了

  // アルファベットが何回出現したか
  long long cnt[26] = {0};
  rep(i, N){
    cnt[ S[i]-'a' ]++;
  }

  // 各アルファベットがcnt[i]回出現するので，
  // それを選ぶならcnt[i]通りと，選ばないという1通りがある
  long long ans = 1;
  rep(i, 26)
    ans = ( ans*(cnt[i]+1) )%MOD;

  // 何も選ばないときと，初期化の1を引く
  cout << (ans-1+MOD)%MOD << endl;
    
  return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;

int main(){
    int n,T;
    cin>>n>>T;
    vector<int> c(n),t(n);
    for(int i=0;i<n;i++){
        cin>>c[i]>>t[i];
    }
    int a=100000,cnt=0;
    for(int i=0;i<n;i++){
        if(t[i]<=T){
            cnt++;
            if(i==0){
                a=c[i];
            }else if(c[i]<a){
                a=c[i];
            }
        }
    }
    if(cnt==0){
        cout<<"TLE"<<endl;
    }else{
        cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main
 
import (
	"fmt"
)
 
func main() {
  var sx, sy, tx, ty int
  var ans string
  fmt.Scanf("%d %d %d %d", &sx, &sy, &tx, &ty)
  
  dx:= tx - sx
  dy:= ty - sy
  
  for i := 0; i < dy; i++{
    ans += "U"
  }
  for i := 0; i < dx; i++{
    ans += "R"
  }
  ans += "U"
  for i := 0; i < dx; i++{
    ans += "L"
  }
  ans += "LD"
  for i := 0; i < dy; i++{
    ans += "D"
  }
  ans += "R"
  
  for i := 0; i < dx; i++{
    ans += "R"
  }
  for i := 0; i < dy; i++{
    ans += "U"
  }
  ans += "R"
  for i := 0; i < dy; i++{
    ans += "D"
  }
  ans += "DL"
  for i := 0; i < dx; i++{
    ans += "L"
  }
  ans += "U"
  
  fmt.Printf("%s", ans)
}

Measured memory_bytes: 7336
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  ll n;
  cin>>n;
  if(n<=9){
    cout<<n<<endl;
    return 0;
  }
  ll digit=0;
  ll d;
  bool ans[20];
  for(int i=0;i<20;i++) ans[i]=true;
  int a=0;
  while (n>0){
    d=n%10;
    n/=10;
    digit++;
    if(d!=9) ans[a]=false;
    a++;
  }
  for(int i=0;i<digit-1;i++){
    if(!ans[i]) ans[19]=false;
  }
  if(ans[19]) cout<<d+(digit-1)*9<<endl;
  else cout<<d-1+(digit-1)*9<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	for(int i = 1; i < 1e5; i++) {
		if(A * i % B == C) {
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
	return 0;
}


Measured memory_bytes: 3644
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;

int f[20000];
int N;

int main()
{
	for(int x = 1;x <= 100;++x)
		for(int y = 1;y <= 100;++y)
			for(int z = 1;z <= 100;++z)
			{
				int v = x * x + y * y + z * z + x * y + y * z + z * x;
				if(v <= 10000)
					++f[v];
			}

	scanf("%d", &N);
	for(int i = 1;i <= N;++i)
		printf("%d\n", f[i]);

	return 0;
}

Measured memory_bytes: 3744
from typing import List
from typing import Tuple
from functools import cmp_to_key
import sys

sys.setrecursionlimit(100000)

def find_bridges(adj, n) -> List[Tuple[int, int]]:
    mark = [False for _ in range(n)] 
    edges = []
    low_link = [None for _ in range(n)]
    id = [0]

    for v in range(n):
        if not mark[v]:
            ____find_bridges(v, -1, adj, id, low_link, mark, edges)
    return edges


def ____find_bridges(node: int, parent: int, adj, id: List[int], low_link: List[int], mark: List[bool], edges):

    mark[node] = True
    low_link[node] = id[0]
    node_id = id[0]

    for v in adj[node]:
        if v == parent: continue
        if not mark[v]:
            id[0] += 1
            ____find_bridges(v, node, adj, id, low_link, mark, edges)
        low_link[node] = min(low_link[node], low_link[v])
        if low_link[v] > node_id:
            edges.append([node, v])

def read() -> Tuple[List, int]:

    info = [int(e) for e in input().split()]
    n, e = info[0], info[1]
    adj = [[] for _ in range(n)]
    for _ in range(e):
        edge = [int(i) for i in input().split()]
        adj[edge[0]].append(edge[1])
        adj[edge[1]].append(edge[0])
    
    return adj, n

def custom_cmp(edgeA, edgeB):
    if edgeA[0] == edgeB[0]:
        return edgeA[1] - edgeB[1]
    
    return edgeA[0] - edgeB[0]

def process_output(edges: List[List[int]]) -> List[List[int]]:
    for edge in edges:
        edge.sort()
    n_edges = list(sorted(edges, key=cmp_to_key(custom_cmp)))
    return n_edges

def show(edges):
    for edge in edges:
        print('%d %d' % (edge[0], edge[1]))

adj, n = read()
edges = find_bridges(adj, n)
n_edges = process_output(edges)
show(n_edges)


Measured memory_bytes: 21172
N = int(input())
P = [int(i) for i in input().split()]

count = 0
for i in range(1, N - 1):
    if P[i - 1] < P[i] < P[i + 1] or P[i + 1] < P[i] < P[i - 1]:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  int n = s.length();
  int ans = 0;
  
  for(int i=0;i<n;i++){
    if(s[i] == '2')
      ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}
  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
template <typename T, typename U>
T max(T x, U y)
{
    return x>y ? x : y;
}
template <typename T, typename U>
T min(T x, U y)
{
    return x<y ? x : y;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h,w;cin >>h >>w;
    char a[h][w];
    for (int i = 0; i < h; ++i)
    {
    	for (int j = 0; j < w; ++j)
    	{
    		cin >>a[i][j];
    	}
    }
    ll dp[h][w];
    for (int i = 0; i < h; ++i)
    {
    	for (int j = 0; j < w; ++j)
    	{
    		dp[i][j]=0;
    	}
    }
    for (int i = 0; i < h; ++i)
    {
    	for (int j = 0; j < w; ++j)
    	{
    		if(a[i][j]=='#'){dp[i][j]=0;continue;}
    		if(i==0 and j==0)dp[i][j]=1;
    		else if(i==0)dp[i][j]=dp[i][j-1];
    		else if(j==0)dp[i][j]=dp[i-1][j];
    		else dp[i][j]=((dp[i-1][j])%mod+(dp[i][j-1])%mod)%mod;
    	}
    }
    cout<< dp[h-1][w-1];
    }

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

bool in(ll n, ll mi, ll mx) {
    return mi <= n && n <= mx;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    V<> a(k);
    rep(i, k) cin >> a[i];
    reverse(all(a));
    ll mn = 2, mx = 2;
    rep(i, k) {
        ll s = (mn+a[i]-1)/a[i]*a[i];
        ll t = mx/a[i]*a[i];
        // s, tはそれぞれmn以上で最も小さいkの倍数, mx以下で最も大きいkの倍数
        mn = s;
        mx = t + a[i] - 1;
        if(mn > mx) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << mn << " " << mx << endl;
}

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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    char ch[4];
    cin >> ch;
    if(ch[0]== '7'|| ch[1]== '7' || ch[2]== '7')
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    ll a, b;
    cin >> a >> b;
    ll ans = a;
    if(a%2){
        if((b-a)%2){
            // 差が奇数の場合
            ans ^= b;
            if((b-a-1)%4!=0) ans--;
        }else{
            // 差が偶数の場合
            ans ^= (b-1);
            if((b-a-2)%4!=0) ans--;
            ans ^= b;
        }
    }else{
        if((b-a)%4==1){
            ans = 1;
        }else if((b-a)%4==2){
            ans = b+1;
        }else if((b-a)%4==3){
            ans = 0;
        }else{
            ans = b;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using ll = long long;

int N;
ll A, B;

ll h[100000];

bool C(ll x) {
  ll a_num = x;
  for (int i = 0; i < N; i++) {
    if (x * B >= h[i]) {
      continue;
    }
    ll hp = h[i];
    hp -= x * B;
    a_num -= (hp + (A - B) - 1) / (A - B);
    if (a_num < 0) {
      return false;
    }
  }
  return true;
}

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

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

  ll lb = 0, ub = 1e9;
  while (ub - lb > 1) {
    ll mid = (ub + lb) / 2;
    if (C(mid)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  cout << ub << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    int x;
    cin >> x;
    if(x==3 || x==5 || x==7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    for (int i = 0; i < a; i++) {
        if (!isdigit(s[i])) {
            cout << "No" << endl;
            return 0;
        }
    }
    if (s[a] != '-') {
        cout << "No" << endl;
        return 0;
    }
    for (int i = a + 1; i < a + 1 + b; i++) {
        if (!isdigit(s[i])) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> B(N);
  for (int i = 1; i < N; i++) {
    int A;
    cin >> A;
    B.at(A - 1).push_back(i + 1);
  }
  for (int i = 0; i < N; i++) cout << B.at(i).size() << endl;
}

Measured memory_bytes: 14016
#include <iostream>
#define MAX 2000000+1
#define lim 10000+1
#define INF 2*MAX

int A[MAX], result[MAX], counter[lim];

void CountingSort(int A[], int n){

    /* initialize counter */
    for (int i=0; i<lim; i++) counter[i] = 0;

    /* count number of each value */
    for (int i=0; A[i] != INF; i++) counter[A[i]]++;

    /* generate result array */
    int k=0;
    for (int i=0; i<lim; i++) for (int j=0; j<counter[i]; j++) {
        if (counter[i] != 0) result[k++] = i;
    }
    result[k] = INF;
}

int main() {

    /* input */
    int n;
    std::cin >> n;
    for (int i=0; i<n; i++) std::cin >> A[i];
    A[n] = INF;

    /* counting sort */
    CountingSort(A, n);

    /* output */
    for (int i=0; result[i] != INF; i++) std::cout << result[i] << ( result[i+1] != INF  ? " " : "\n");
}


Measured memory_bytes: 18668
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
int k;
int dist[N];
deque<int> dq;
int main(){
	int n,x,t;
	cin>>k;
	memset(dist,63,sizeof(dist));
	dq.push_front(1);
	dist[1]=1;
	while(!dq.empty())
	{
		x=dq.front();
		dq.pop_front();
		t=(x*10)%k;
		if(dist[t]>dist[x])
		{
			dist[t]=dist[x];
			dq.push_front(t);
		}
		t=(x+1)%k;
		if(dist[t]>dist[x]+1)
		{
			dist[t]=dist[x]+1;
			dq.push_back(t);
		}
	}
	cout<<dist[0]<<endl;
	return 0;
}

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

int M, T, P, R;

struct data{
    int id, ac, pe;
};

bool cmp(data d1, data d2){
    if(d1.ac == d2.ac){
        if(d1.pe == d2.pe) return d1.id > d2.id;
        return d1.pe < d2.pe;
    }
    return d1.ac > d2.ac;
}

int main(){
    while(1){
        cin >> M >> T >> P >> R;
        if(M + T + P + R == 0) break;
        int wa[51][11] = {};
        vector<data> d(T);
        rep(i, 0, T) d[i].id = i;
        rep(i, 0, R){
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--;
            if(j != 0){
                wa[t][p]++;
            }else{
                d[t].ac++;
                d[t].pe += m + 20 * wa[t][p];
            }
        }
        // rep(i, 0, T){
        //     cout << d[i].id << " " << d[i].ac << " " << d[i].pe << endl;
        // }
        sort(d.begin(), d.end(), cmp);        
        rep(i, 0, T){
            if(i != 0 && d[i].ac == d[i - 1].ac && d[i].pe == d[i - 1].pe){
                cout << "=";
            }else if(i != 0){
                cout << ",";
            }
            cout << d[i].id + 1;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3108
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;

string s;
stack<char> st;
int main() {
	int i;
	cin >> s;
	for(i=0; i<s.size(); i++) {
		if(st.empty()) st.push(s[i]);
		else {
			if(s[i]=='T' && st.top()=='S') st.pop();
			else st.push(s[i]);
		}
	}
	cout << st.size();
	return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    int a[n + 1][m + 1];
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int tmp = c;
        for (int j = 0; j < m; j++)
        {
            tmp += a[0][j] * a[i][j];
        }
        if (tmp > 0)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define mem(x,y) memset(x,y,sizeof(x)) //memset array
#define fo(i,r,k)  for((i) = r; (i) < (k); i=i+1)
#define fok(i,k,n) for((i) = k; (i) > n; i=i-1) 
#define deb(x) cout << #x << " = " << x << endl
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define deb3(x, y, z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define bug puts("Hello"); 
#define mp make_pair
#define pb push_back
#define pi pair<int,int> 
#define pl pair<long long,long long>
#define vi vector<int> 
#define vl vector<long long>
#define vpl vector<pair<long long,long long>> 
#define vpi vector<pair<int,int>> 
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define br cout<<"\n";
#define sortall(x) sort(x.begin(),x.end())
#define modexpo poww 
ll modexpo(ll x,ll y,ll m){x=x%m;if(y==0){return 1;}if(y%2==0){return modexpo(x*x,y/2,m); }else{return (x*modexpo(x*x,y/2,m))%m; }}
void io(); 
const int mod  = 1e9+7;
const int maxn = 2e5 + 10;
int n,a[maxn][4]; 
int dp[maxn][4]; 
int maxi(int x,int y,int z) { return (x>y)?((x>z)?x:z):((y>z)?y:z);}
int rec(int n, int ch)
{    
    if(dp[n][ch] != -1) return dp[n][ch]; 
    int ans = 0; 
    if(ch == 1)
    {
       ans = maxi(ans, a[n][2] + rec(n-1,2), a[n][3] + rec(n-1,3) );  
    }
    if (ch == 2)
    {
       ans = maxi(ans, a[n][1] + rec(n-1,1), a[n][3] + rec(n-1,3) );  
    }
    if( ch == 3)
    {
       ans = maxi(ans, a[n][2] + rec(n-1,2), a[n][1] + rec(n-1,1) );  
    }
    return dp[n][ch] = ans; 
}
int main()
{
int i,j;
cin>>n;
fo(i,1,n+1) cin>>a[i][1]>>a[i][2]>>a[i][3]; 
mem(dp,-1); 
dp[0][1] = 0;
dp[0][2] = 0;
dp[0][3] = 0;
int ans = maxi(rec(n-1,1)+a[n][1], rec(n-1,2)+a[n][2], rec(n-1,3)+a[n][3] );
cout << ans; 
return 0;
}

void io()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif 
}


Measured memory_bytes: 12964
import Data.Ord
import Data.List

main :: IO ()
main = do
  _ <- getLine
  [t,a] <- getInts
  hs <- getInts
  print $ solve t a (zip [1..] hs)

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: Int -> Int -> [(Int,Int)] -> Int
solve t a hs = fst $ minimumBy (comparing snd) [(i,abs $ a' - (t' - h'*0.006)) | (i,h) <- hs, let h' = fromIntegral h]
  where t' = fromIntegral t
        a' = fromIntegral a


Measured memory_bytes: 1404
#include <iostream>
#include <algorithm>
int gcd(int a, int b){if(b){return gcd(b,a%b);}else{return a;}}
int main(){
  int n,i=0,g,a[100001]={0};
  std::cin>>n;
  while(std::cin>>a[i])++i;
  std::sort(a, a+n);
  g=a[0];
  for(i=1;i<n;++i){
    g = (gcd(g,a[i])<g?gcd(g,a[i]):g);
    if(g==1)break;
  }
  std::cout<<g<<"\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  long n;
  long a[5];

  cin >> n;
  cin >> a[0];
  cin >> a[1];
  cin >> a[2];
  cin >> a[3];
  cin >> a[4];
  
  sort(a, a+5);
  
  cout << (((n + (a[0] - 1))/ a[0]) + 4) << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.math.*;
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	class SegTree {
		int n = 1;
		int[] v;

		public SegTree(int n) {
			while (this.n < n)
				this.n *= 2;
			v = new int[2 * this.n - 1];
		}

		void set(int k) {
			v[k] = 1;
			while (k > 0) {
				k = (k - 1) / 2;
				v[k] = v[2 * k + 1] + v[2 * k + 2];
			}
		}

		int query(int a, int b) {
			return query(0, n, a, b, 0);
		}

		int query(int l, int r, int a, int b, int k) {
			if (r <= a || b <= l)
				return 0;
			else if (a <= l && r <= b)
				return v[k];
			else {
				int vl = query(l, (l + r) / 2, a, b, 2 * k + 1);
				int vr = query((l + r) / 2, r, a, b, 2 * k + 2);
				return vl + vr;
			}

		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] P = new int[N];
		int min=Integer.MAX_VALUE/3;
		int ans=0;
		for (int i = 0; i < N; ++i) {
			P[i] = sc.nextInt();
			--P[i];
			if(min>=P[i])++ans;
			min=Math.min(min, P[i]);
		}
		System.out.println(ans);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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

int main() {
	int r, g, b, val;
	scanf("%d%d%d", &r, &g, &b);
	
	val = r * 100 + g * 10 + b * 1;
	
	printf("%s", val % 4 == 0 ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int main() {
	ll N, L; cin >> N >> L;
	string s[100];
	rep(i, 0, N) {
		cin >> s[i];
	}
	sort(s, s + N);
	rep(i, 0, N) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
H = tuple(map(int, input().split()))
lst = [0] * N
lst[1] = abs(H[0] - H[1])

for i in range(2, N):
    lst[i] = min(lst[i - 2] + abs(H[i - 2] - H[i]),
                 lst[i - 1] + abs(H[i - 1] - H[i]))
print(lst[N - 1])

Measured memory_bytes: 14056
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int main(){
    IOS;
    in k,n,ans = 999999999;
    cin >> k >> n;
    vector<in> a(n),res;
    rep(i,0,n){
        cin >> a[i];
    }
    rep(i,1,n){
        res.pb(a[i]-a[i-1]);
    }
    res.pb(k-a[n-1]+a[0]);
    sort(all(res));
    cout << k-res[n-1] << "\n";
}

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

int main() {
  string s;
  cin >> s;
  int ret = 700;
  if (s[0] == 'o') ret += 100;
  if (s[1] == 'o') ret += 100;
  if (s[2] == 'o') ret += 100;
  cout << ret << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

struct LoopInfo {
	ll dist_begin_loop;
	ll loop_begin_node;
	ll loop_size;
	LoopInfo(ll d, ll n, ll s)
		: dist_begin_loop(d), loop_begin_node(n), loop_size(s) {}
};

// loopの始点までの距離, loopの始点, loopのサイズ
LoopInfo find_loop(vector<ll>& a) {
	ll n = a.size();
	vector<ll> dist(n, 0);
	ll node = 0;
	ll prev_node = 0;
	ll i = 0;
	dist[0] = -1;
	while(true) {
		// cout << "node: " << node << endl;
		dist[node] = dist[prev_node] + 1;
		prev_node = node;
		node = a[node] - 1;
		if(dist[node] != 0 || (i != 0 && node == 0)) {
			// cout << "node: " << node << ", prev: " << prev_node
			//	 << ", dist[node]: " << dist[node] << endl;
			return LoopInfo(dist[node], node, dist[prev_node] - dist[node] + 1);
		}
		i++;
	}
}

ll find_node(vector<ll>& a, ll count) {
	ll node = 0;
	REP(i, count) { node = a[node] - 1; }
	return node;
}

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	REP(i, n) { cin >> a[i]; }
	LoopInfo li = find_loop(a);
	// cout << "dist: " << li.dist_begin_loop << ", size: " << li.loop_size
	//	 << endl;
	if(k < li.dist_begin_loop) {
		cout << find_node(a, k) + 1 << endl;
	} else {
		cout << find_node(a,
						  li.dist_begin_loop +
							  (k - li.dist_begin_loop) % li.loop_size) +
					1
			 << endl;
	}
	return 0;
}


Measured memory_bytes: 6428