akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 7;
int main(){
	int n;
	cin >> n;
	long long dp[401][401];
	vector<long long> a(n + 1), pref(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		pref[i] = pref[i - 1] + a[i];
	}
	for(int i = 1; i <= n; i++) dp[i][i] = 0;
	for(int l = 1; l < n; l++){
		for(int i = 1; i + l <= n; i++){
			//cout << i << ' ' << i + l << endl;
			dp[i][i + l] = inf;
			for(int j = i; j < i + l; j++){
				//cout << i << ' ' << j << endl;
				//cout << j + 1 << ' ' << i + l << endl;
				dp[i][i + l] = min(dp[i][i + l], dp[i][j] + dp[j + 1][i + l]);
			}
			dp[i][i + l] += pref[i + l] - pref[i - 1];
			//cout << i << ' ' << i + l << ' ' << dp[i][i + l] << endl;
		}
	}
	cout << dp[1][n] << endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes\n";
string no = "No\n";

int  main()
{
	int a,b,c,d; cin >> a >> b >> c >> d;
	if (a + b > c + d)
		cout << "Left\n";
	else if (a + b < c + d)
		cout << "Right\n";
	else 
		cout << "Balanced\n";
	return (0);
}

Measured memory_bytes: 384
fn main() {
    use std::io;
    let mut input1 = String::new();
    let mut input2 = String::new();
    let _ = io::stdin().read_line(&mut input1);
    let _ = io::stdin().read_line(&mut input2);

    let inputs: Vec<isize> = input2.trim()
        .split_whitespace()
        .map(|x| x.parse::<isize>().unwrap())
        .collect::<Vec<_>>();

    let mut min = 1000;
    let mut max = 0;
    for val in &inputs {
        if min > *val {
            min = *val;
        }
        if max < *val {
            max = *val;
        }
    }
    println!("{}", max - min);
}


Measured memory_bytes: 4352
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    s = [input() for _ in range(n)]
    s = set(s)

    print(len(s))


if __name__ == '__main__':
    main()


Measured memory_bytes: 37188
def dfs(i,cnt):
    d[i] = cnt
    cnt += 1
    for j in edge[i]:
        if d[j] == -1:
            cnt = dfs(j,cnt)
    f[i] = cnt
    cnt += 1
    return cnt

n = int(input())
edge = [[] for i in range(n)]
for not_used in range(n):
    of_children, not_used, *v = map(lambda x: int(x)-1,input().split())
    edge[of_children] = sorted(v)
c = 1
d = [-1]*n
f = [-1]*n

for i in range(n):
    if d[i] == -1:
        c = dfs(i,c)
for i ,(d,f) in enumerate(zip(d,f)):
    print(i+1,d,f)


Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 10101010;

using pi = pair<int,int>;

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

    int a[2][2];
    rep(i,2)rep(j,2){
        cin >>a[i][j];
        --a[i][j];
    }

    int ans = INF;
    for(int h=1; h<=100; ++h)for(int w=1; w<=100; ++w){
        auto IN = [&](pi p){
            return 0<=p.fi && p.fi<h && 0<=p.se && p.se<w;
        };

        auto GET = [&](int id){
            return pi(id/w, id%w);
        };

        auto DIST = [&](pi p, pi q){
            return abs(p.fi-q.fi) + abs(p.se-q.se);
        };

        auto CALC = [&](){
            rep(i,2)rep(j,2)if(!IN(GET(a[i][j]))) return INF;

            int ret = 0;
            rep(i,2) ret += DIST(GET(a[i][0]), GET(a[i][1]));
            return ret;
        };

        ans = min(ans, CALC());
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3104
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;



int main(){


	int n;
	int k;
	int l[51];
	int s=0;

	cin>>n>>k;

	for(int i=0; i<n; i++){
		cin>>l[i];
	}
	sort(l, l + n, greater<int>());
	for(int i=0; i<k; i++){
		s+=l[i];
	}
		cout<<s<<endl;






}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    string s;
    cin >> s;
    long long int state = 0, result = 0;

    REP(i,(long long int)s.size()){
        if(s[i]=='R'){
            state++;
        }else{
            state--;
        }
        if(state==4){
            result++;
        }
        state %= 4;
    }
    cout << result << endl;
    return 0;
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)

#define BITREP(BIT, NUM) REP(BIT, 1 << (NUM))
#define ISBIT(BIT, INDEX) ((BIT) & (1 << (INDEX)))

template <typename T>
T gcd(T a, T b)
{
	if (a < b)
		swap(a, b);
	return b ? gcd(b, a % b) : a;
}
template <typename T>
T divisibleNum( T n, const vector<T>& a )
{
	T res = 0;
	BITREP( bit, a.size() ) if( bit != 0 ) // O( 2 ^ a.size() )
	{
		T lcm = 1;
		REP( j, a.size() ) if( ISBIT( bit, j ) ) // O( a.size() )
		{
			lcm = lcm / gcd( lcm, a[j] ) * a[j];
			if( lcm > n ) break; // Overflow対策
		}

		T elementNum = n / lcm;
		if( __builtin_popcountll( bit ) % 2 == 0 ) res -= elementNum;
		else res += elementNum;
	}
	return res;
}

int main()
{
	ll a,b,c,d;cin>>a>>b>>c>>d;
	ll bb = b - divisibleNum( b, { c, d } );
	ll aa = (a-1) - divisibleNum( a-1, { c, d } );
	cout << bb - aa << endl;
	return 0;
}

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

int main(){
 	string s;
 	cin>>s;
 	for(int i=0;i<s.length();++i)
 	    if(i!=3) cout<<s[i];
 	    else cout<<8;
 	cout<<endl;
 	return 0;
 }

Measured memory_bytes: 256
x = int(input())
u = 0
def a(x,u):
    if x>=500:
        u+=1000 * (x // 500)
        x = x % 500
        a(x,u)
    elif x>=5:
        u+=5 * (x // 5)
        x = x % 5
        a(x,u)
    else:
        print(u)
a(x,u)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define MAX(x,y) ((x>y)?x:y)

int num[3][205],ans[205];
int main(){
	int i,j,k,n;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		ans[i]=0;
		for(j=0;j<3;j++)scanf("%d",&num[j][i]);
	}
	for(k=0;k<3;k++){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(i==j)continue;
				if(num[k][i]==num[k][j])break;
			}
			if(j==n)ans[i]+=num[k][i];
		}
	}
	for(i=0;i<n;i++)printf("%d\n",ans[i]);
	
	return 0;
}

Measured memory_bytes: 596
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}

long long getDigit(long long num){
    long long digit = 0;
    while(num != 0){
        num /= 10;
        ++digit;
    }
    return digit;
}

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

    int minn = INT_MAX;
    for (long long a = 1; a <= sqrt(n); a++){
        long long  b = n  / a;
        if (n == a * b){
            long long  maxn = max(getDigit(a),getDigit(b));

            if (maxn < minn){
                minn = maxn;
            }
        }
    }

    cout << minn << endl;

}


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

#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define display(x) {}
#define eprintf(...) do {} while(0)
#endif

template<typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template<typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }
template<typename T>
ostream& operator << (ostream& out, const vector<T> &v) {
	int n = v.size();
	out << "{";
	for(int i = 0; i < n; ++i) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "}";
}
template<typename A, typename B>
ostream& operator << (ostream& out, const pair<A, B> &v) {
	return out << "(" << v.first << ", " << v.second << ")";
}

typedef long long LL;

const int maxN = (1 << 18) + 5;
const LL P = 1000000007;
int n, h, p[maxN];

LL val[maxN];

LL prod = 1, sum = 0;
void mark(int u, LL coef) {
	coef = coef * u % P;
	if(u < n / 2) {
		mark(u * 2, coef);
		mark(u * 2 + 1, coef);
	} else {
		int x = p[u];
		while(x) {
			val[x] = (val[x] + coef) % P;
			coef = coef * x % P;
			x /= 2;
		}
	}
}
LL count(int u, LL coef) {
	coef = coef * u % P;
	if(u < n / 2) {
		return (count(u * 2, coef) + count(u * 2 + 1, coef)) % P;
	} else {
		int x = p[u];
		LL sum = 0, ref = 0;
		while(x) {
			ref = ref * x % P;
			coef = coef * x % P;
			(sum += val[x] * coef - ref) %= P;
			(ref += val[x] * coef - ref) %= P;
			ref = ref * x % P;
			x /= 2;
		}
		return (sum + P) % P;
	}
}
void unmark(int u) {
	if(u < n / 2) {
		unmark(u * 2);
		unmark(u * 2 + 1);
	} else {
		int x = p[u];
		while(x) {
			val[x] = 0;
			x /= 2;
		}
	}
}
LL ans = 0;
void dfs(int u) {
	if(u < n / 2) {
		mark(u * 2, u);
		(ans += count(u * 2 + 1, 1)) %= P;
		unmark(u * 2);
		dfs(u * 2);
		dfs(u * 2 + 1);
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#endif
	cin >> h;
	n = (1 << h);
	for(int i = n / 2; i < n; ++i) cin >> p[i], p[i] += n / 2 - 1;
	memset(val, 0, sizeof(val));
	dfs(1);
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 6192
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],pos,pos2;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	reverse(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	{
		if(a[i+1]<=i||i==n)
		{
			pos=i-1;
			break;
		}
	}
	pos2=n;
	for(int i=pos+1;i<=n;i++)
	{
		if(a[i]<=pos)
		{
			pos2=i-1;
			break;
		}
	}
	if(((a[pos+1]-pos)&1)&&((pos2-pos)&1)) puts("Second");
	else puts("First");
	return 0;
}

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

typedef int in; 

in a[105],n,k,mik,dp[10000005];

in fun(in k)
{
    if(k<mik)
    return 1;

    for(in i=0;i<n;++i)
    if(k-a[i]>=0)
    {
        if(dp[k-a[i]]==-1)
        {
            dp[k-a[i]]=fun(k-a[i]);
        }
        
        if(dp[k-a[i]]==2)
        return 1;
    }
    
    return 2;
}

int main() 
{
    in i;
    cin>>n>>k;
    
    for(i=0;i<10000005;++i)
    dp[i]=-1;
    
    for(i=0;i<n;++i)
    {
        cin>>a[i];
        mik=min(mik,a[i]);
        dp[a[i]]=1;
    }
    
    in val=fun(k);
    
    if(val==1)
    cout<<"First";
    else
    cout<<"Second";
	return 0;
}


Measured memory_bytes: 44032
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int main(){
  string s; int t=0; cin>>s;
  rep(i,3) if(s[i]=='o')t=t+100;
  cout<<700+t;
} 


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int selectionsort(int a[],int n)
{
  int min,ans = 0,j,t;
  for(int i = 0;i<n-1;i++)
    {
      min = i;
      for( j = i;j<n;j++)
      {
        if(a[j]<a[min])
           min = j;
         }
    t = a[i];a[i] = a[min]; a[min] = t;
    if(i!=min) ans+=1;
    }
   return ans;
}
int main ()
{
  int a[103],n,sw;
  scanf("%d",&n);
  for(int i = 0;i<n;i++)
    scanf("%d",&a[i]);
  sw = selectionsort(a,n);
  for(int i = 0;i<n;i++)
    {
      if(i<n-1) printf("%d ",a[i]);
      else printf("%d",a[i]);
      }
  printf("\n");
  printf("%d\n",sw);
  return 0 ;
}



Measured memory_bytes: 3212
#include <stdio.h>

int main(){
    int n, k;
    scanf("%d", &n);
    scanf("%d", &k);

    int x = 1;

    for(int i=0;i<n;i++){
        if (x*2 < x+k)
            x *= 2;
        else
            x += k;
    }

    printf("%d\n", x);

    return 0;
}


Measured memory_bytes: 128
n,k=map(int,input().split())
d=set(map(int,input().split()))
i=n
while True:
    temp=i
    flag=1
    while temp>0:
        if temp%10 in d:
            flag=0
            break
        temp//=10
    if flag:
        print(i)
        break
    i+=1

Measured memory_bytes: 9104
#include<iostream>
using namespace std;
int main(){
	int w;
	while(cin>>w){
		int cost=1150;
		if(w==-1)break;
		for(int i=10;i<w;i++){
			if(i<20)cost+=125;
			else if(i<30)cost+=140;
			else cost+=160;
		}
		cout<<4280-cost<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)
	a := make([]int64, n)
	for i := int64(0); i < n; i++ {
		a[i] = nextInt(sc)
	}

	cnt := 0

	for i := int64(0); i <= n-1; i++ {
		minJ := i
		for j := int64(i); j <= n-1; j++ {
			if a[j] < a[minJ] {
				minJ = j
			}
		}
		if minJ != i {
			t := a[minJ]
			a[minJ] = a[i]
			a[i] = t
			cnt++
		}
	}

	fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	fmt.Println(cnt)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



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

int main(){
    int n;
    string s;
    cin >> n >> s;
    if(n%2==1){
        cout << "No" << endl;
        return 0;
    }else{
        string s1,s2;
        s1 = s.substr(0,n/2);
        s2 = s.substr((n/2),n);
        //cout << s1 << " " << s2 << endl;
        if(s1==s2){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" << endl; 
            return 0;
        }
    }

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

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


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

using namespace std;

int main ()
{
	int a, b;
	scanf ("%d %d", &a, &b);
	int answer = -1;
	int max = a;
	if (b>max){
		max=b;
	}
	for (int k=0; k<=max; k++){
		if (abs(a-k)==abs(b-k)){
			answer=k;
			break;
		}
	}
	if (answer==-1){
		printf ("IMPOSSIBLE");
	}
	else{
		printf ("%d\n", answer);
	}
}

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

int main(){
	long n;
  	cin >> n;
  	int h[n];
  
  	for(int i=n-1; i>=0; i--){      
		cin >> h[i];
    }
  
  	for(int i=0; i<n-1; i++){
    	if(h[i+1] - h[i] >= 2){
			cout << "No" << endl;
	        return 0;          
        }
      	else if(h[i+1] > h[i])
          h[i+1]--;
    }
  
	cout << "Yes" << endl;  	
	
 	return 0; 
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))

nums = [0]*N

for val in A:
    nums[val-1] += 1

choices = 0
for num in nums:
    choices += int(num * (num - 1) / 2)

for val in A:
    print(choices - nums[val - 1] + 1)

Measured memory_bytes: 32184
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int d1, d2;
    int count = 0;
    bool zoro = false;
    
    for(int i=1; i <= n; i++){
        cin >> d1 >> d2;
        if(d1 == d2) count++;
        else count = 0;
        
        if(count == 3) zoro = true;
    }
    
    if(zoro) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;



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

	int n;cin>>n;

	vector<ll> A(n);

	ll a =0;
	for(int i=0; i<n; i++){
		cin>>A[i];

		if(i%2 ==0){
			a +=A[i];
		}else {
			a -=A[i];
		}
	}
	vector<ll> ans;
	ans.push_back(a);
	ll tmp =a;
	for(int i=0; i<n-1; i++){
		 tmp = 2*A[i]-tmp;
		 ans.push_back(tmp);
	}

	for(auto e: ans){
		cout<<e<<" ";
	}
	cout<<endl;





}




Measured memory_bytes: 3060
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N, K = input_nums()
    H = input_nums()
    res = len([h for h in H if h >= K])
    print(res)

if __name__ == '__main__':
    main()

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


int main()
{
	int h,n,a;
	scanf("%d%d",&h,&n);
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		sum+=a; 
	}
	if(sum>=h) printf("Yes");
	else printf("No");
	return 0;
}

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

namespace AizuOnlineJudge {
    class Program {
        static void Main() {
            var nq = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var vec = Enumerable.Range(0, nq[0]).Select(_ => new StringBuilder()).ToArray();
            for (var i = 0; i < nq[1]; ++i) {
                var query = Console.ReadLine().Split();
                switch (query[0]) {
                    case "0":
                        vec[int.Parse(query[1])].Append(query[2] + " ");
                        break;

                    case "1":
                        Console.WriteLine(vec[int.Parse(query[1])].ToString().TrimEnd());
                        break;

                    case "2":
                        vec[int.Parse(query[1])].Length = 0;
                        break;
                }
            }
        }
    }
}



Measured memory_bytes: 50820
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll N, M; cin >> N >> M;
	ll m[50][50] = {};
	rep(i, 0, M) {
		ll a, b; cin >> a >> b;
		m[a - 1][b - 1]++;
		m[b - 1][a - 1]++;
	}
	rep(i, 0, N) {
		ll cnt = 0;
		rep(j, 0, N) {
			if (i != j) {
				cnt += m[i][j];
			}
		}
		cout << cnt << endl;
	}

	return 0;
}

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

int main(){
  int n,k;
  ll ans = 1;
  int i;

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

  ans = k;
  for(i = 1;i < n;i++){
    ans *= k - 1;
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
	int X;
	cin >> X;
	bool ok = false;
	for (int i = 1; i <= X; ++i) {
		if (i * 100 <= X && X <= i * 105) ok = true;
	}
	cout << (ok ? 1 : 0) << endl;
	return 0;
}

Measured memory_bytes: 256
str = gets
expr = str.split
stack = []

expr.each do |c| 
  case c
  when '+'
    b = stack.pop.to_i
    a = stack.pop.to_i
    stack.push(a+b)
  when '-'
    b = stack.pop.to_i
    a = stack.pop.to_i
    stack.push(a-b)
  when '*'
    b = stack.pop.to_i
    a = stack.pop.to_i
    stack.push(a*b)
  else
    stack.push(c.to_i)
  end
end

puts stack.pop

Measured memory_bytes: 8636
import java.util.*

data class Component(val size: Int, val bipartite: Boolean)

// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

data class BFSState(val v: Int, val c: Int)

fun main(args: Array<String>) {
  val (n, m) = fastReadInts(2)
  val graph = Array(n, { mutableListOf<Int>() })
  repeat(m) {
    val (v1Raw, v2Raw) = fastReadInts(2)
    val v1 = v1Raw - 1
    val v2 = v2Raw - 1
    graph[v1].add(v2)
    graph[v2].add(v1)
  }

  val colors = IntArray(n, { -1 })
  val components = mutableListOf<Component>()
  var numIsolated = 0
  for (s in 0 until n) {
    if (colors[s] >= 0) continue
    if (graph[s].isEmpty()) {
      colors[s] = 0
      numIsolated += 1
      continue
    }

    var componentSize = 0
    var isBipartite = true

    // BFS
    val queue = ArrayDeque<BFSState>()
    componentSize += 1
    colors[s] = 0
    queue.offerLast(BFSState(s, 0))
    while (queue.isNotEmpty()) {
      val state = queue.pollFirst()
      val v = state.v
      val c = state.c
      val nextC = (c + 1) % 2

      // Bipartite check
      for (u in graph[v]) {
        if (colors[u] >= 0 && colors[u] == c) {
          isBipartite = false
        }
      }

      for (u in graph[v]) {
        if (colors[u] >= 0) continue
        componentSize += 1
        colors[u] = nextC
        queue.offerLast(BFSState(u, nextC))
      }
    }

    components.add(Component(componentSize, isBipartite))
  }

//  println("components: " + components)
//  println("numIsolated: " + numIsolated)

  var ans = 0L
  
  val numBipartite = components.count { it.bipartite }
  // val numNonBipartite = components.count { !it.bipartite }
  ans += components.size.toLong() * components.size.toLong() +
      numBipartite.toLong() * numBipartite.toLong()

  ans += 2L * n.toLong() * numIsolated.toLong() - numIsolated.toLong() * numIsolated.toLong()

  println(ans)
}


Measured memory_bytes: 62168
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

struct UF {
  int n,c;
  vector<int> p;
  UF(int n) : n(n), c(n), p(n,-1) {}
  int find(int x) {
    return (p[x] < 0 ? x : p[x] = find(p[x]));
  }
  void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (p[x] > p[y]) swap(x,y);
    p[x] += p[y];
    p[y] = x;
    c--;
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int size(int x) {
    return -p[find(x)];
  }
  int count() {
    return c;
  }
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n,q;
  cin >> n >> q;
  UF uf(n);
  REP(i,q) {
    int c,x,y;
    cin >> c >> x >> y;
    if (c == 0) uf.unite(x,y);
    else cout << uf.same(x,y) << endl;
  }

  return 0;
}


Measured memory_bytes: 3304
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    A = set([int(input()) for _ in range(M)])

    mod = 10**9 + 7
    dp = [0] * (N + 1)
    dp[0] = 1

    for i in range(1, N + 1):
        if i in A:
            continue

        if i == 1:
            dp[1] = dp[0]
            continue

        dp[i] = dp[i - 1] + dp[i - 2]
        dp[i] %= mod

    print(dp[N])


if __name__ == "__main__":
    main()


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

// clang-format off
#define forn(i, x, y) for(int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
// clang-format on

const long long MOD = 1000000007;

using LL = long long;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;

void add(LL &a, LL b)
{
  a += b;
  if (a >= MOD)
    a -= MOD;
}

int main()
{
  IOS;

  string K;
  cin >> K;
  int D;
  cin >> D;

  int n = K.size();
  VVVLL dp(10001, VVLL(2, VLL(100)));
  dp[0][0][0] = 1;

  forn(i, 0, n) forn(s, 0, 2) forn(d, 0, D)
  {
    for (int x = 0; x <= (s ? 9 : K[i] - '0'); x++)
      add(dp[i + 1][s || x < K[i] - '0'][(d + x) % D], dp[i][s][d]);
  }
  LL res = dp[n][0][0] + dp[n][1][0] - 1;
  if (res < 0)
    res += MOD;

  cout << res % MOD << endl;

  return 0;
}


Measured memory_bytes: 20196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int GCD(int a, int b) {
  if(a == 0 || b == 0)
    return max(a, b);
  else
    return __gcd(a, b);
}

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  vi lgcd(n), rgcd(n);
  lgcd[0] = rgcd[n - 1] = 0;
  rep2(i, 1, n) lgcd[i] = GCD(lgcd[i - 1], a[i - 1]);
  for(int i = n - 2; i >= 0; i--) rgcd[i] = GCD(rgcd[i + 1], a[i + 1]);
  int ans = 0;
  rep(i, n) {
    int num = GCD(lgcd[i], rgcd[i]);
    ans = max(num, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    string s; int k;
    cin >> s >> k ; 
    for (int i=0;i<sz(s)-1;i++){
        int x = s[i] - 'a' + 1 ; 
        if (x != 1 and  k >= 27-x ){ 
            k -= (27-x);
            s[i] = 'a';
        }
    }
    int x = s[sz(s)-1]-'a'+k+1 ; 
    x %= 26;
    if (x==0) s[sz(s)-1] = 'z';
    else  s[sz(s)-1] = x+'a'-1;
    cout << s << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3756
Scanf.scanf "%d" (fun n ->
    let a = Array.init (n + 1) (fun i -> if i = n then max_int else Scanf.scanf " %d" (fun a -> a)) in
    let b = Array.init n (fun _ -> Scanf.scanf " %d" (fun b -> b)) in
    let c = Array.init (n + 1) (fun i -> if i = n then max_int else Scanf.scanf " %d" (fun c -> c)) in
    Array.sort compare a;
    Array.sort compare b;
    Array.sort compare c;
    let lower arr target =
        let rec bin left right =
            if left = right then left else
                let m = (left + right) / 2 in
                if arr.(m) < target then bin (m + 1) right
                                    else bin left m
        in
        bin 0 n
    in
    let rec loop i acc =
        if i = n then acc else
            let acc = acc + lower a b.(i) * (n - lower c (b.(i) + 1)) in
            loop (i + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 6400
N, D = map(int, input().split())
P = [list(map(int, input().split())) for n in range(N)]

def dis(A, B):
    s = 0
    for a, b in zip(A, B):
        s += (b - a) ** 2
    return s ** 0.5

res = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dist = dis(P[i], P[j])
        if dist - int(dist) < 10 ** -8:
            res += 1
print(res)

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int a = sc.nextInt();
        int b = sc.nextInt();

        long[] x = {a, 1};
        long[] y = {b, 1};
        while (x[0] != y[0]) {
            if (x[0] > y[0]) {
                y[0] = b * ++y[1];
            } else {
                x[0] = a * ++x[1];
            }
        }

        System.out.println(x[0]);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;

int table[2][4010][4010];
int val(int x1, int y1, int x2, int y2, int l)
{
	return table[l][x2][y2] - (x1 > 0 ? table[l][x1 - 1][y2] : 0) - (y1 > 0 ? table[l][x2][y1 - 1] : 0)
			+ (x1 > 0 && y1 > 0 ? table[l][x1 - 1][y1 - 1] : 0);
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, k;
	cin>>n>>k;
	int sk = 2 * k;
	char ch;
	int x, y;
	while(n--)
	{
		cin>>x>>y>>ch;
		table[ch == 'B'][x % sk][y % sk]++;
	}
	fore(i, 0, sk)
		fore(j, 0, sk)
			fore(l, 0, 2)
				fore(x, 0, 2)
					fore(y, 0, 2)
						table[l][i + x * sk][j + y * sk] = table[l][i][j];
	fore(l, 0, 2)
	fore(i, 0, 2 * sk)
	{
		fore(j, 0, 2 * sk)
		{
			if(i > 0)
				table[l][i][j] += table[l][i - 1][j];
			if(j > 0)
				table[l][i][j] += table[l][i][j - 1];
			if(i > 0 && j > 0)
				table[l][i][j] -= table[l][i - 1][j - 1];
		}

	}
	int res = 0, su;
	fore(i, 0, sk)
	fore(j, 0, sk)
	{
		fore(l, 0,  2)
		{
			su = val(i, j, i + k - 1, j + k - 1, l % 2 == 0);
			su += val(i + k , j + k, i + 2 * k - 1, j + 2 * k - 1, l % 2 == 0);
			su += val(i + k, j, i + 2 * k - 1, j + k - 1, l % 2 == 1);
			su += val(i, j + k, i + k - 1, j + 2 * k - 1, l % 2 == 1);
			res = max(res, su);
		}
	}
	cout<<res<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 128952
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <functional>
 
using namespace std;
 
int main() {
    int n;
    string s;
    cin>>n;
    if (n<3){
        cout<<0;
        return 0;
    }
    cin>>s;
    long long r=0,g=0,b=0;
    for (char c : s) {
        r+=c=='R';
        g+=c=='G';
        b+=c=='B';
    }
    long long cnt=r*g*b;
    for (int p=1;p<n;++p){
        for (int i=0,j=p,k=2*p;k<n;++i,++j,++k){
            if (s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i])
                --cnt;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
const ll MOD = 1e9 + 7;

void mainsolve(){

	ll a,b;
	cin >> a >> b;
	string res1 = "", res2 = "";

	rep(i,a) res1 += to_string(b);
	rep(i,b) res2 += to_string(a);

	cout << min(res1, res2) << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

vector<vector<int> > graph;

int main(){
    int n; cin >> n;
    graph = vector<vector<int> >(n);
    vector<vector<int> > lis(n-1, vector<int>(3, 0));
    map<int, int> mp;
    map<Pii, int> anslis;
    mp[0] = -1;
    REP(i, 0, n-1){
        int a, b; cin >> a >> b;
        a--; b--;
        graph[a].pb(b);
        graph[b].pb(a);
        lis[i][0] = a; lis[i][1] = b;
    }
    queue<int> q;
    int max = 1;
    vector<int> flag(n, 0);
    flag[0] = 1;
    q.push(0);
    while(!q.empty()){
        int now = q.front();
        q.pop();
        int keycolor = mp[now];
        int color = 1;
        REP(i, 0, graph[now].size()){
            int next = graph[now][i];
            if(flag[next] == 0){
                int a, b;
                if(next > now){
                    a = now;
                    b = next;
                }else{
                    a = next;
                    b = now;
                }
                while(color == keycolor){
                    color++;
                }
                anslis[Pii(a, b)] = color;
                mp[next] = color;
                chmax(max, color);
                color++;
                q.push(next);
                flag[next] = 1;
            }
        }
    }
    cout << max << endl;
    REP(i, 0, n-1){
        cout << anslis[Pii(lis[i][0], lis[i][1])] << endl; 
    }
}

Measured memory_bytes: 25604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int main()
{
	int d, t, s;
	cin >> d >> t >> s;

	if (d > t * s) {
		printf("No");
	} else {
		printf("Yes");
	}

	
	return 0;
}


Measured memory_bytes: 3760
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<vector>
using namespace std;
int n,a[100010],x,ans,mx=1000000000;
int main()
{
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	if (n==2){
		cout<<a[1]<<' '<<a[0]<<endl;
		return 0;
	}
	int x=(a[n-1]+1)/2;
	for (int i=n-1;i>0;i--)
		if (abs(x-a[i])<mx){
			mx=abs(x-a[i]);
			ans=a[i];
		}
	cout<<a[n-1]<<' '<<ans<<endl;
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

using namespace std;
using ll = long long;

string S;

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

    std::cin >> S;
    int f = atoi(S.substr(0, 2).c_str());
    int b = atoi(S.substr(2, 2).c_str());

    bool f_is_m = (0 < f && f <= 12);
    bool b_is_m = (0 < b && b <= 12);

    if(f_is_m && b_is_m) {
        std::cout << "AMBIGUOUS" << std::endl;
    }
    else if(f_is_m && !b_is_m) {
        std::cout << "MMYY" << std::endl;
    }
    else if(!f_is_m && b_is_m) {
        std::cout << "YYMM" << std::endl;
    }
    else {
        std::cout << "NA" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int A[2000000],C[10001],B[2000000];
int main(){
  int i,n;
  scanf("%d",&n);
 
  for(i=0;i<n;i++) scanf("%d",&A[i]);


  for(i = 0;i<10001;i++)
    C[i] = 0;

  for(i=0;i<n;i++)
    C[A[i]]++;

  for (i = 1;i<10001;i++)
    C[i] = C[i] + C[i-1];

  for (i=n-1;i>=0;i--){
    B[C[A[i]]-1] = A[i];
    C[A[i]]--;
	  }
  for(i=0;i<n-1;i++)
    printf("%d ",B[i]);
 printf("%d\n",B[n-1]);
return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n][3];
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<3; j++)
            cin>>arr[i][j];
    }
    int dp[n][3];
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];

    for(int i=1; i<n; i++)
    {
        for(int j=0; j<3; j++)
        {
            if(j == 0)
                dp[i][j] = arr[i][j] + max(dp[i-1][j+1], dp[i-1][j+2]);
            else if(j == 1)
                dp[i][j] = arr[i][j] + max(dp[i-1][j-1], dp[i-1][j+1]);
            else
                dp[i][j] = arr[i][j] + max(dp[i-1][j-1], dp[i-1][j-2]);
        }
    }
    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int n,m;
    long long k;
    long long a[200005];
    long long b[200005];
    vector<long long> asum;
    vector<long long> bsum;
    
    asum.push_back(0);
    bsum.push_back(0);
    
    cin >> n >> m >> k;
    for (int i = 0;i < n;i++){
        cin >> a[i];
        if (i == 0){
            asum.push_back(a[i]);
        }
        else {
            asum.push_back(asum[i] + a[i]);
        }
    }
    for (int i = 0;i < m;i++){
        cin >> b[i];
        if (i == 0){
            bsum.push_back(b[i]);
        }
        else {
            bsum.push_back(bsum[i] + b[i]);
        }
    }
    
    if (k  >= asum[n-1] + bsum[m-1]){
        cout << n+m << endl;
    }
    else {
        long long ans = 0;
        long long res;
        for (int i = 0;i <= n;i++){
            long long t = k - asum[i];
            if (t < 0){
                res = 0;
            }
            else if ( t == 0){
                res = i;
            }
            else {
                auto iter = upper_bound(bsum.begin(),bsum.end(),t);
                long long x = iter - bsum.begin() - 1;
                res = x + i;
            }
            ans = max(res,ans);
        }
        cout << ans << endl;
    }
}


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

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

const long long INF = 1LL << 60;

int N;
vector<long long> H(100010) , dp(100010);

int main() {
	int N ; cin >> N;
	for(int i = 0 ; i < N ; i++){
		cin >> H[i];
	}
	
	for(int i = 0 ; i < 100010 ; i++){
		dp[i] = INF;
	}
	
	dp[0] = 0;
	
	for(int i = 1 ; i < N ; i++){
		chmin(dp[i] , dp[i-1] + abs(H[i] - H[i-1]));
		if(i > 1)
		chmin(dp[i] , dp[i-2] + abs(H[i] - H[i-2]));
	}
	cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#define ll long long
#define pb push_back
#define make_pair mp
#define first f
#define second s
#define upper_bound ub
#define lower_bound lb
#define MOD 1000000007
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;


#define ordered_set tree<pair<ll,ll> , null_type,less<pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update>ll fn


void solve(){
    ll n;cin>>n;
    ll a[n+1],freq[1000006];
    memset(freq,0,sizeof(freq));
    ll gcd=0;
  	bool f=1;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        if(gcd==0){
            gcd=a[i];
        }
        else{
            gcd = __gcd(gcd,a[i]);
        }
        for(ll d=1;d*d<=a[i]&&f==1;d++){
            if(a[i]%d==0){
                freq[d]++;
                if(a[i]/d!=d){
                    freq[a[i]/d]++;
                }
              	if((freq[d]>1&&d!=1)||(freq[a[i]/d]>1&&(a[i]/d!=1))){
                	f=0;
                }
            }
        }
    }
    if(f){
        cout<<"pairwise coprime";return;
    }
    if(gcd==1){
        cout<<"setwise coprime";return;
    }
    cout<<"not coprime";
    return;
}

int main ()
{
  ios_base::sync_with_stdio (false);
  cin.tie (NULL);
  ll t;
  //cin>>t;
  t = 1;
  while (t)
    {
      solve();t--;
      //cout<<"end of test case"<<endl;
    }
  return 0;
}


Measured memory_bytes: 19232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Saizo
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int n = parseInt(br.readLine());

		for (int i = 0; i < n; i++) {

			int t = parseInt(br.readLine());

			StringTokenizer st = new StringTokenizer(br.readLine());
			int up = 0, down = 0;
			int prev = parseInt(st.nextToken()), next, diff;

			for (int j = 1; j < t; j++) {
				next = parseInt(st.nextToken());
				diff = prev - next;
				if (diff < 0) {
					if (diff < up) up = diff;
				} else if (diff > 0) {
					if (diff > down) down = diff;
				}
				prev = next;
			}
			System.out.println(-up + " " + down);
		}
	}
}

Measured memory_bytes: 20144
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
int c[n];int s[n];int f[n];
  for(int i=1;i<=(n-1);i++){
    cin >> c[i] >> s[i] >> f[i];
  }
  for(int i=1;i<=n;i++){
    int ans=0;
    for(int j=i;j<=(n-1);j++){
    if(ans<s[j]) ans=s[j];
     else if(ans%f[j]!=0){
       ans=(ans+f[j])-(ans%f[j]);//ans%f[j]で到着時間の前に行った最新の列車時刻へ戻る
     }
     ans+=c[j];
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef long long unsigned int llu;
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define YUGEN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lp(i,start,end) for(int i=start;i<end;i++)
#define MAX 105
#define test() ll t; cin>>t; while(t--)
using namespace std;
ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}
int main()
 {
    YUGEN;
    string s;
    cin>>s;
    ll sum=0;
    for(int i=0;i<s.size();i++)
        sum+=(s[i]-'0');
    if(sum%9==0)
        cout<<"Yes";
    else
        cout<<"No";






 }


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    vint A(N,-1),B(N,-1);
    int cur = 0;
    for (size_t i = 0; i < K; i++)
    {
        while (S[cur] == 'x')
        {
            cur++;
        }
        A[i]=cur;
        cur += C + 1;
    }
    cur = N - 1;
    for(int i = K-1;i>=0;i--)
    {
        while (S[cur] == 'x')
        {
            cur--;
        }
        B[i]=cur;
        cur -= C + 1;
    }

    for (size_t i = 0; i < N; i++)
    {
        if (A[i] == B[i] and A[i] != -1)
            cout << A[i] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5176