akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main(){
    bool flg = true;
    while(flg){
        int n,k;
        cin >> n >> k;
        if(n==0 && k==0){
            flg = false;
        }
        else{
            int card[100000] = {};
            bool white = false;
            for(int i=0; i<k; i++){
                int tmp;
                cin >> tmp;
                if(tmp == 0){
                    white = true;
                }
                else{
                    card[tmp-1] = 1;
                }
            }

            int max;
            if(white){
                max = 1;
                int now = 0;
                int old = 0;
                bool can = false;
                for(int i=0; i<n; i++){
                    if(card[i]==1){
                        now++;
                        if(can){
                            if(max<old+1+now) max=old+1+now;
                        }
                        else{
                            if(max<now+1) max=now+1;
                        }
                    }
                    else{
                        if(now==0){
                            can = false;
                        }
                        else{
                            can = true;
                            old = now;
                            now = 0;
                        }
                        
                    }
                }
            }
            else{
                max = 0;
                int now = 0;
                for(int i=0; i<n; i++){
                    if(card[i]==1){
                        now++;
                        if(max<now) max=now;
                    }
                    else{
                        now = 0;
                    }
                }
            }
            cout << max << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3376
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        double x1 = scan.nextDouble(), y1 = scan.nextDouble(),
                x2 = scan.nextDouble(), y2 = scan.nextDouble();

        double x;
        x = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
        System.out.println(x);
    }
}

Measured memory_bytes: 27972
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static HashMap<String,Integer> map=new HashMap<String,Integer>();
	static List<String> list=new LinkedList<String>();
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		while(true){
			int lines=Integer.parseInt(cin.nextLine());
			list=new LinkedList<String>();
			map=new HashMap<String,Integer>();
			if(lines==0)break;
			for(int i=0;i<lines;i++){
				String[] s = cin.nextLine().split(" ");
				for(int j=0;j<s.length;j++){
//					System.out.println(s[j]);
					if(map.containsKey(s[j])){
						map.put(s[j], map.get(s[j])+1);
					}
					else{
						list.add(s[j]);
						map.put(s[j], 1);
					}
				}
			}
			char c = cin.nextLine().charAt(0);
			String ans="";
			List<StInt> ansList=new LinkedList<StInt>();
			for(String s:list){
				if(s.charAt(0)!=c)continue;
				ans=s.toString();
				ansList.add(new StInt(ans,map.get(s)));
			}
			Collections.sort(ansList);
			if(ansList.size()==0){
				System.out.print("NA");
			}
			else{
				int cnt=0;
				for(StInt s:ansList){
					if(cnt!=0){
						System.out.print(" ");
					}
					System.out.print(s.s);//+" "+s.a);
					cnt++;
					if(cnt==5)break;
				}				
			}
			System.out.println();
		}

	}
	static class StInt implements Comparable<StInt>{
		String s;
		int a;
		StInt(String ss,int aa){
			s=ss;
			a=aa;
		}
		@Override
		public int compareTo(StInt o) {
			StInt si=(StInt)o;
			if(this.a!=si.a){
				return -(this.a-si.a);
			}
			return (this.s.compareTo(si.s));
		}
		
	}
}

Measured memory_bytes: 38028
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  string s,t;cin>>s>>t;
  int n=s.size();
  rep(i,n){
    s=s.substr(1)+s[0];
    if(s==t){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

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

class main{
  public static void Main(string[] args){
    string[] s = Console.ReadLine().Split(" ");
    int round = int.Parse(s[0]);
    int num = int.Parse(s[1]);
    var houses = System.Console.ReadLine().Split(' ').Select(v => System.Int32.Parse(v)).ToArray();
    int dist = houses[0] + round - houses[num - 1];
    
    for(int i = 1; i < num; i++){
      dist = Math.Max(dist, houses[i] - houses[i-1]);
    }      
    Console.WriteLine(round - dist);
  }
}

Measured memory_bytes: 43836
import sys
sys.setrecursionlimit(10**5+1)

N, M = map(int, input().split())

edge = [[] for i in range(N)]
for i in range(M):
    x, y, _ = map(int, input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)

visited = [False] * N

ans = 0
def dfs(x):
    global ans
    if not visited[x]:
        ans += 1
    visited[x] = True

    for x_next in edge[x]:
        if visited[x_next]:
           continue 
        visited[x_next] = True
        dfs(x_next)

for i in range(N):
    dfs(i)

print(ans)

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

using namespace std;

#define _for(i,j,N) for(int i = (j); i < (N);i++)
#define LL long long
#define MAXN 100005

struct P{
    LL index;
    LL dis;
    P(LL a = 0,LL b = 0):index(a),dis(b){;}
};

P line[MAXN];

LL root(LL &a){
    LL ret_val = 0;
    while(line[a].index != a){
        ret_val += line[a].dis;
        a = line[a].index;
    }
    return ret_val;
}

int main()
{
    int N,M;
    cin >> N >> M;
    _for(i,1,N+1){
        line[i] = P(i,0);
    }
    bool failed = false;
    _for(i,0,M){
        LL l,r,d;
        cin >> l >> r >> d;
        LL d1 = root(l);
        LL d2 = root(r);
        if(l != r){
            if(d1 + d > d2){
                line[r].index = l;
                line[r].dis = d1+d-d2;
            }
            else{
                line[l].index = r;
                line[l].dis = d2-d1-d;
            }
        }
        else if(l == r){
            if(d2 - d1 != d){
                failed = true;
                break;
            }
        }
    }
    if(failed) printf("No\n");
    else printf("Yes\n");
}


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

int main()
{
	
	int n;
	int count = 0;

	cin >> n;

	int A[20];

	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
	}
	
	for (int i = 0; i < n-2; i++)
	{
		if (A[i]<A[i+1] && A[i+1]<A[i+2])
		{
			count++;
		}
		if (A[i] > A[i + 1] && A[i + 1] > A[i + 2])
		{
			count++;
		}
	}
	cout << count << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 12 21:00:00 JST 2020
 **/

signed main() {
    std::string s;
    std::cin >> s;
    std::cout << (std::find(s.begin(), s.end(), '7') != s.end() ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 3624
mod = 10**9+7
N = int(input())
A = [int(i) for i in input().split()]
if N % 2 == 1:
    import collections
    c = collections.Counter(A)
    for i in range(N):
        if i % 2 == 1:
            continue
        if i == 0:
            if c[i] != 1:
                print(0)
                exit()
        else:
            if c[i] != 2:
                print(0)
                exit()
if N % 2 == 0:
    import collections
    c = collections.Counter(A)
    for i in range(1,N):
        if i % 2 == 0:
            continue
        if c[i] != 2:
            print(0)
            exit()
def pow_k(a,n,mod):
    if n == 0:
        return 1
    if n % 2 ==0:
        return pow_k(a*a % mod,n//2,mod)
    else:
        return a * pow_k(a,n-1,mod) % mod
if N % 2 == 1:
    N -=1
print(pow_k(2,N//2,mod))

Measured memory_bytes: 14692
package main

import (
  "fmt"
  "math"
)

func main() {
  var a,b,h,m float64
  var angle, ans float64
  fmt.Scanf("%f %f %f %f", &a, &b, &h, &m)

  angle = calcAngle(h, m)
  ans = calcAns(float64(a), float64(b), angle)
  fmt.Println(ans)

  // fmt.Println(math.Sqrt(a*a + b*b - 2*a*b*math.Cos(diff(360*(h/12)+30*(m/60), 360*(m/60))*math.Pi/180)))
}

func diff(a, b float64) float64 {
	if a > b {
		return a - b
	}
	return b - a
}

func calcAngle(h, m float64) (ans float64) {
  hAngle := h * 30 + 30 * m / 60
  mAngle := m * 6
  // hAngle := 360*(h/12)+30*(m/60)
  // mAngle := 360*(m/60)
  if hAngle > mAngle {
    ans = float64(hAngle - mAngle)
  } else {
    ans = float64(mAngle - hAngle)
  }
  return ans
}

func calcAns(a float64, b float64, angle float64) (ans float64) {
  cos := math.Cos(angle*math.Pi/180)
  ans = math.Sqrt(a*a+b*b-2*a*b*cos)
  return ans
}


Measured memory_bytes: 1820
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans=0,i,n,k,a[100];
	cin>>n>>k;
	for(i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+1+n);
	for(i=n;i>n-k;i--)
		ans+=a[i];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
char c1, c2, c3;

int main()
{
    cin>>c1>>c2>>c3;

    if(c1=='S' && c2=='S' && c3=='S') cout<<0;
    else if(c1=='R' && c2=='S') cout<<1;
         else if(c2=='S' && c3=='R') cout<<1;
                else if(c1=='R' && c2=='R' && c3=='R') cout<<3;
                    else if(c1=='R' && c2=='R' && c3=='S') cout<<2;
                            else if(c3=='R' && c2=='R' && c1=='S') cout<<2;
                                 else if(c1=='S' && c2=='R' && c3=='S') cout<<1;
    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
 
int main(void){
  int a,b;
  int i;
  scanf("%d",&a);
  scanf("%d",&b);
  for(i=1;i<4;i++){
    if(i!=a && i != b){
      break;
    }
  }
  printf("%d\n",i);
 return 0; 
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N;
vector<ll> t(100010,0);
vector<ll> x(100010,0);
vector<ll> y(100010,0);


int main() {
    cin >> N;
    rep(i,N){
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }
    ll check = 0;
    rep(i,N){
        ll time = t[i+1]-t[i];
        ll d = abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
        if (time-d >= 0 && (time-d)%2 == 0){
            continue;
        }
        else check = 1;
    }
    if (check) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 2560
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, char, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll mod = 1000000007;

int main(void)
{
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = s.size();
	vector<ll> digits(n, 0);
	rep(i, n) {
		char c = s[i];
		digits[n-1-i] = c - '0';
	}
	vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(110, vector<ll>(2, 0)));
	dp[n - 1][1][1] = 1;
	dp[n - 1][1][0] = digits[n - 1]-1;
	dp[n - 1][0][0] = 1;
	for (int i = n - 2; i >= 0; i--) {
		if (digits[i] == 0) {
			rep(j, 109) {
				//0
				dp[i][j][1] += dp[i + 1][j][1];
				dp[i][j][0] += dp[i + 1][j][0];
				//1..9
				dp[i][j+1][0] += 9 * dp[i + 1][j][0];
			}
		}
		else {
			rep(j, 109) {
				//0
				dp[i][j][0] += dp[i + 1][j][1];
				dp[i][j][0] += dp[i + 1][j][0];
				//1..d-1				
				dp[i][j+1][0] += (digits[i]-1) * dp[i+1][j][1];
				dp[i][j+1][1] +=  dp[i+1][j][1];
				//1..9
				dp[i][j+1][0] += 9 * dp[i + 1][j][0];
			}
		}
	}
	cout << dp[0][k][0] + dp[0][k][1] << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

int main(void){
  ll l, r;
  ll ans = 2020;
  cin >> l >> r;
  for(ll i = l; i <=  min(l+2020, r); ++i){
    for(ll j = i+1; j <=  min(i+2020, r); ++j){
      ans = min(ans, (i*j)%2019);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
struct Node
{
	int x,y;
};
struct Edge
{
	int to,next;
}e[5000005];
vector<Node>a[1000005];
int f[100005],rt[100005],d[1100005],h[1100005],cnt;
inline void Addedge(int x,int y)
{
	e[++cnt]=(Edge){y,h[x]};h[x]=cnt;return;
}
inline int GetFather(int x)
{
	if(f[x]==x)return x;
	return f[x]=GetFather(f[x]);
}
inline void Merge(int x,int y)
{
	x=GetFather(x);
	y=GetFather(y);
	if(x!=y)f[x]=y;
	return;
}
queue<int>q;
int main(void)
{
	int i,j,x,y,n,m,c,id;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)
	{
		scanf("%d%d%d",&x,&y,&c);
		a[c].push_back((Node){x,y});
	}
	id=n;
	for(i=1;i<=1000000;++i)
	{
		for(j=0;j<a[i].size();++j)
		{
			x=a[i][j].x;y=a[i][j].y;
			f[x]=x;f[y]=y;
			rt[x]=rt[y]=0;
		}
		for(j=0;j<a[i].size();++j)Merge(a[i][j].x,a[i][j].y);
		for(j=0;j<a[i].size();++j)
		{
			x=a[i][j].x;y=a[i][j].y;
			if(!rt[GetFather(x)])rt[GetFather(x)]=++id;
			if(!rt[GetFather(y)])rt[GetFather(y)]=++id;
			Addedge(x,rt[GetFather(x)]);
			Addedge(rt[GetFather(x)],x);
			Addedge(y,rt[GetFather(y)]);
			Addedge(rt[GetFather(y)],y);
		}
	}
	q.push(1);
	while(!q.empty())
	{
		x=q.front();q.pop();
		for(i=h[x];i;i=e[i].next)
		{
			y=e[i].to;
			if(!d[y]){d[y]=d[x]+1;q.push(y);}
		}
	}
	if(d[n])printf("%d\n",d[n]/2);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 42368
N,M = map(int, input().split())
A = [int(input()) for i in range(M)]
dp = [0]*(N+1)
for k in A:
    dp[k]="E"
dp[0]=1
if dp[1]=="E":
    dp[1]= 0
else:
    dp[1]= 1
for i in range(2,N+1):
    if dp[i]=="E":
        dp[i] = 0
    else:
        dp[i] = (dp[i-1]+dp[i-2])%(10**9+7)
print(dp[-1])

Measured memory_bytes: 13620
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	ll n,m;
	ll ans=0LL;
	cin >>n>>m;
	if(n==1 or m==1){
		ans=max(n,m)-2;
	}
	else
	{
		ans = (n - 2) * (m - 2);
	}
	if(n*m==1){
		ans=1;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
vector<llong> AllDivisors(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
pair<llong, llong> Reduction(pair<llong, llong> A) {
	llong tmp = gcd(A.first, A.second);
	auto p = make_pair(A.first / tmp, A.second / tmp);
	return p;
}
//ここまで共通
int N;
int ANS = 0;
vector<int> L;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int l;
		cin >> l;
		L.push_back(l);
	}

	for (int i = 0; i < N - 2; i++) {
		for (int j = i + 1; j < N - 1; j++) {
			for (int k = j + 1; k < N; k++) {
				vector<int> P;
				P.push_back(L[i]);
				P.push_back(L[j]);
				P.push_back(L[k]);

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

				if (P[0] - P[1] < P[2] && P[0] != P[1] && P[1] != P[2] && P[2] != P[0]) {
					ANS++;
				}
			}
		}
	}
	cout << ANS << endl;
	return 0;
}

Measured memory_bytes: 3604
/* به نام یزدان */
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 100 + 5, MAX_K = 100 * 1000 + 5;
int n, k, a[MAX_N], dp[MAX_K];

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	for (int i = 1; i <= k; i++)
		for (int j = 0; j < n; j++)
			if (a[j] <= i)
				dp[i] |= !dp[i - a[j]];
}

void print_output() {
	if (dp[k])
		cout << "First";
	else
		cout << "Second";
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read_input();
	solve();
	print_output();
}


Measured memory_bytes: 640
# ＢＦＳ, グラフ, 全探索, 親の情報を自身に加算
 # ※ 要削除

from collections import deque

n, q = map(int,input().split())

pic = [[] for _ in range(n+1)] # ダミーのノード '0' を含む
for _ in range(n-1): # 絵の取り込み
    x, y = map(int, input().split())
    pic[x].append(y)
    pic[y].append(x)
    
cnts = [0] * (n+1) # カウンター初期化
for _ in range(q): # 初期情報取り込み
    x, y = map(int, input().split())
    cnts[x] += y

visited = [0] * (n+1) # 訪問の記録、初期化
visited[0], visited[1] = 1, 1 # 開始時情報取り込み

queue = deque([])
queue.append(1)

#print(n, q) # ※
#print(pic) # ※
#print(cnts)
#print(visited) # ※

while queue:
    tmp = queue.popleft() # 探索候補を popleft して...
    for i in pic[tmp]: # 次の探索候補を探索
        if visited[i] != 0: # 未訪問かどうかを確認...
            continue
        else: # 未訪問の場合...
            visited[i] = 1 # 現在地の訪問を記録
            cnts[i] += cnts[tmp] # 親の 'cnt' を自身の 'cnt' に加える
            queue.append(i) # 現在地を探索候補に積む

print(*cnts[1:])


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

int main(){
  string s,t;
  int n;
  cin >> s >> t;
  n=s.size();
  s=s+t.at(n);
  if(s==t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
import scala.io.StdIn

object Main {
  def main(args:Array[String]){
    val sc=new java.util.Scanner(System.in)
    val W,H,x,y,r=sc.nextInt()
    println(if(r<=x&&r<=y&&x+r<=W&&y+r<=H) "Yes" else "No")
  }
}

Measured memory_bytes: 45124
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
int n, m;

//使用する関数
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 (a > b) { a = b; return 1; }
	return 0;
}

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

	cin >> n >> m;
	cout << ((n == m) ? "Yes" : "No" )<< endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <bits/stdc++.h>
#include <string.h>
#include <algorithm>
#define ll long long int
#define test_case int t,i;cin>>t;for(i=0;i<t;i++)
using namespace std;

int main()
{
    int n,i,x,c=0;
    cin>>n;

    vector<int>a;
    vector<int>sorted;

    for (i=0; i<n; i++)
    {
        cin>>x;
        a.push_back(x);
        sorted.push_back(x);
    }

    sort(sorted.begin(),sorted.end());
    
    for(i=0; i<n; i++)
    {
        if(a[i]!=sorted[i])
            c++;
    }

    if (c==2 || c==0)
        cout<<"YES\n";
    else
        cout<<"NO\n";

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <cstdint>
#define pi 3.14159
#define ll long long
// #define int ll
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int h,w;
  cin>>h>>w;
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  vector<vector<int>> dp(h,vi(w,0));
  int idx=0;
  rep(i,0,h){
    if(i%2==0){
      rep(j,0,w){
        if(a[idx]) a[idx]-=1,dp[i][j]=idx+1;
        else {
          idx=idx+1;
          a[idx]-=1,dp[i][j]=idx+1;
        }
      }
    }
    else{
      rrep(j,w-1,0){
        if(a[idx]) a[idx]-=1,dp[i][j]=idx+1;
        else {
          idx=idx+1;
          a[idx]-=1,dp[i][j]=idx+1;
        }
      }
    }
  }
  rep(i,0,h){
    rep(j,0,w) cout<<dp[i][j]<<" ";
    cout<<endl;
  }
}
int main(){
    optimizeIO();
    solve();
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define mod 1000000007


int main(){
  ll n;
  ll h[110]={0};
  ll ma[110]={0};
  cin >>n;
  ll res=0;
  rep(i,n){
    cin >> h[i];
    res=max(res,h[i]);
    ma[i]=h[i];
  }
  ll ans=0;
  rep(i,n){
    bool flag=true;
    rep(j,i){
      if(h[i]<ma[j]){
        flag=false;
      }
    }
    if(flag)ans++;
  }
  cout << ans << endl;
}


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

int main(void)
{
    vector<int> v;

    for (int i = 0; i < 3; i++)
    {
        int n;
        cin >> n;
        v.push_back(n);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i];
        if (i != v.size()-1)
            cout << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,w,h) rep(j,h)rep(i,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int a,b;
    std::cin >> a>>b;
    if(a==b)std::cout << a*2 << std::endl;
    else std::cout << max(a,b)*2-1 << std::endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>

int list[105];

void qsort_v2(int d[], int s, int e)
{
    int i, j, p, temp;
    
    if(e - s <= 1) {
        return;
    }
    
    p = d[s];
    i = s;
    j = e - 1;
    
    while (1) {
        
        while (d[i] < p && i < e)
            i++;
        
        while (p < d[j] && j > s)
            j--;
        if (i >= j)
            break;
        
        temp = d[i];
        d[i] = d[j];
        d[j] = temp;
        
        i++;
        j--;
        
    }
    
    qsort_v2(d, s, i);
    qsort_v2(d, j + 1, e);
    
    for(i = 0; i <= e; i++) {
        list[i] = d[i];
    }
}

int main(void)
{
    int n, x;
    
    int i;
    
    scanf("%d %d\n", &n, &x);
    
    for(i = 0; i < n; i++) {
        if(i == n - 1) {
            scanf("%d", &list[i]);
        } else {
            scanf("%d ", &list[i]);
        }
    }
    
    qsort_v2(list, 0, n);
    
    for(i = 0; i < n; i++) {
        if(list[i] > x) {
            printf("%d\n", i);
            break;
        } else if(i == n - 1) {
            if(list[i] == x) {
                printf("%d\n", i + 1);
            } else {
                printf("%d\n", i);
            }
        } else {
            x -= list[i];
            //printf("%d人目に配った、残りは%dこだ\n", i + 1, x);
        }
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll N;
    string s;
    vector<string> S;
    
    map<string,vector<char>> M;
    set<ll> L;
    
    cin >> N;
    REP(i,N){
        cin >> s;
        L.insert(s.size());
        reverse(s.begin(),s.end());
        S.push_back(s);
        char t = s[(int)(s.size())-1];
        s.pop_back();
        M[s].push_back(t);
        
    }
    
    vector<ll> R;
    R.push_back(0);
    auto li = L.begin();
    while(li != L.end()){
        R.push_back(*li++);
    }
    
    ll Ans=0;
    
    REP(i,N){
        if(S[i].size() == R[1])continue;
        ll Al[26]={};
        REP(j,S[i].size()){Al[S[i][j]-'a']++;}
        
        string T="";
        REP(j,R.size()){
            if(R[j]>=S[i].size())break;
            if(j==0)continue;
            for(ll k=max(0LL,R[j-1]-1);k<R[j]-1;k++){
                Al[S[i][k]-'a']--;
                T.push_back(S[i][k]);
            }
            
            REP(k,M[T].size()){
                if(Al[M[T][k]-'a']>0){
                    Ans++;
                }
            }
            
        }
        
    }
    
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 257120
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;


int mx6[] = {1,0,-1,1,-1,0};
int my6[] = {1,1,1,0,0,-1};

int main(){
    int x,y;
    cin >> x >> y;
    rep(i,100) rep(j,100){
        if(2 * i + 4 * j == y && i + j == x){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<double, string> P;

int main(int argc, char const *argv[]) {
	int n;cin>>n;
	vector<P> a;
	double sum = 0.0;
	rep(i,n) {
		double x; string u;
		cin>>x>>u;
		if (u == "BTC") x*=380000.0;
		sum+=x;
	}
	cout<<fixed<<setprecision(8);
	cout << sum << endl;
	return 0;
}

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

int main()
{
    int n,k,x;
    while(cin>>n>>k){
        int mx=0,g=0;
        for(int i=0; i<n; i++){
            cin>>x;
            g=__gcd(g,x);
            mx=max(mx,x);
        }
        if(k<=mx && k%g==0) cout<<"POSSIBLE"<<endl;
        else cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys

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


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n,k=map(int,input().split())
	V=list(map(int,input().split()))
	V=[0]+V+[0]
	LL=list(accumulate(V))
	RR=list(accumulate(V[::-1]))[::-1]
	ans=0
	for l in range(n+1):
		for r in range(n-l+1):
			for x in range(l+r+1):
				if l+r+x<=k:
					xx=V[1:l+1]+V[n+1-r:n+1]
					xx.sort()
					xxx=list(accumulate(xx))
					xxx=[0]+xxx
					ans=max(ans,LL[l]+RR[n-r+1]-xxx[x])
	print(ans)

if __name__ == "__main__":
		main()


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

using namespace std;

int main(){
    string s;
    string p;
    bool check=false;
    getline(cin,s);
    getline(cin,p);
    for(int i=0;i<s.length();i++){
        if(s[i]==p[0]){
            for(int j=0;j<p.length();j++){
                int temp;
                if(i+j>=s.length()){
                    temp=i+j-s.length();
                }else{
                    temp=i+j;
                }
                if(s[temp]==p[j]){
                    check=true;
                }else{
                    check=false;
                    break;
                }
            }
        }
        if(check){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3200
W, H, N = map(int, input().split())

x = [0] * N
y = [0] * N
a = [0] * N

for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())

X1 = 0
X2 = W
Y1 = 0
Y2 = H

entire = W * H

for i in range(N):
    if a[i] == 1:
        X1 = max(X1, x[i])
    if a[i] == 2:
        X2 = min(X2, x[i])
    if a[i] == 3:
        Y1 = max(Y1, y[i])
    if a[i] == 4:
        Y2 = min(Y2, y[i])

if X1 >= X2 or Y1 >= Y2:
    print('0')
else:
    entire = (Y2-Y1) * (X2-X1)
    print(entire)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(N) for(int i = 0; i < N; i++)
using namespace std;
const int MOD = 2019;

int main(){
  int L, R; cin >>L >>R;
  if(R - L > MOD) cout <<0 <<endl;
  else {
    int ans = 1e9;
    for(int i = L; i <= R; i++){
      for(int j = i + 1; j <= R; j++){
	ans = min(ans, ((i % MOD) * (j % MOD)) % MOD);
      }
    }
    cout <<ans <<endl;
  }
  return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    string s,t;
    cin>>n>>s>>t;
    for (int i = 0; i < n; i++)
    {
        cout<<s[i]<<t[i];
    }
    cout<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int H, W; cin >> H >> W;
  vector<vector<int>> S(H+4, vector<int>(W+4));
  int sr, sc; cin >> sr >> sc; sr++, sc++;
  int gr, gc; cin >> gr >> gc; gr++, gc++;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c; cin >> c;
      S[i+2][j+2] = c == '.';
    }
  }
  vector<vector<int>> dist(H+4, vector<int>(W+4, 1e9));
  dist[sr][sc] = 0;
  deque<tuple<int, int, int>> d;
  d.push_back({sr, sc, 0});
  while (d.size()) {
    auto [r, c, x] = d.front(); d.pop_front();
    if (x != dist[r][c]) continue;
    int dr[] = {-1, 0, 1, 0};
    int dc[] = {0, -1, 0, 1};
    for (int i = 0; i < 4; i++) {
      int nr = dr[i] + r;
      int nc = dc[i] + c;
      if (!S[nr][nc]) continue;
      if (dist[nr][nc] > x) {
        dist[nr][nc] = x;
        d.push_front({nr, nc, x});
      }
    }
    for (int i = -2; i <= 2; i++) {
      for (int j = -2; j <= 2; j++) {
        int nr = i + r;
        int nc = j + c;
        if (!S[nr][nc]) continue;
        if (dist[nr][nc] > x + 1) {
          dist[nr][nc] = x + 1;
          d.push_back({nr, nc, x + 1});
        }
      }
    }
  }
  int res = dist[gr][gc];
  if (res == 1e9) res = -1;
  cout << res << endl;
}


Measured memory_bytes: 11660
#include<cstdio>
char s[100001];
int const p=1e9+7;
int num[4][100001]={};
// c^n mod p
long long power(long long n,long long c=2) {
    long long a[64];
    a[0]=c;
    for(int i=1;i<63;i++)a[i]=(a[i-1]*a[i-1])%p;

    long long ans=1;
    for(int i=0;i<63;i++)if((n&(1ll<<i))!=0)ans=(ans*a[i])%p;
    return ans;
}
int main(){
    scanf("%s",s);
    int len,ans=0;
    for(len=0;s[len]!='\0';len++){
        if(s[len]=='A')num[0][len]=1;
        else if(s[len]=='B')num[1][len]=1;
        else if(s[len]=='C')num[2][len]=1;
        else num[3][len]=1;
    }
    for(int i=1;i<len;i++){
        for(int j=0;j<4;j++)num[j][i]+=num[j][i-1];
    }
    for(int i=1;i<len-1;i++){
        if(s[i]=='B'||s[i]=='?'){
            int A_l=num[0][i-1], C_r=num[2][len-1]-num[2][i];
            int Q_l=num[3][i-1], Q_r=num[3][len-1]-num[3][i];
            int pattern_l=(1LL*A_l*power(Q_l,3)+1LL*Q_l*power(Q_l-1,3))%p;
            int pattern_r=(1LL*C_r*power(Q_r,3)+1LL*Q_r*power(Q_r-1,3))%p;
            ans=(ans+1LL*pattern_l*pattern_r)%p;
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(1000000)


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


n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = [int(i) - 1 for i in input().split()]
    c += 1
    e[a].append([b, c])
    e[b].append([a, c])

c = [0] * n


def dfs(i=0, r=-1, co=0):
    c[i] = co
    for j, k in e[i]:
        if j != r:
            dfs(j, i, (co+k) % 2)


dfs()
print("\n".join(map(str, c)))


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

int main()
{
    int n,a;
    while(cin>>n)
    {
        int x=0;
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<10;k++){
                    a=n-i-j-k;
                    if(a>=0&&a<=9)
                        x++;
                }
            }
        }
        cout<<x<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;

 

ll int power(ll int x, ll int y, ll int p)  
{  
    ll int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by 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;  
}  
 
int main()
{
  fastio();

 
ll int T;
T=1;
while(T--)
{
	string s;
	
	int k;
	cin>>k;cin>>s;
	if(s.size()<=k)
		cout<<s<<endl;
	else
		cout<<s.substr(0,k)+"..."<<endl;

}
    return 0;
}

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

int main(){

    int a,b;
    cin >> a >> b;

    if((a+b)%2==0){
        cout << (a+b)/2 << endl;
    }else{
        cout << (a+b)/2+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

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

void input(vec &a){
    cin>>N;
    a.resize(N * 3);
    rep(i, N * 3) {cin>>a[i]; --a[i];}
}

int solver(vec a){
    rep(i, N - 1) sort(a.begin() + i * 3 + 2, a.begin() + i * 3 + 5);
    mat dp(N, vec(N, 0));
    vec memo(N, 0);
    int base = N * 10;
    dp[a[0]][a[1]] = dp[a[1]][a[0]] = memo[a[0]] = memo[a[1]] = base;
    for(int i = 2; i + 2 < N * 3; i += 3){
        if(a[i] == a[i + 1] && a[i + 1] == a[i + 2]){
            --base;
            continue;
        }
        vec temp(0); // (score * N + x) * N + y
        // swap one
        rep(k, 3) rep(x, N) temp.push_back((memo[x] * N + x) * N + a[i + k]);
        // swap two
        ll m = *max_element(ALL(memo));
        rep(k, 3) temp.push_back((m * N + a[i + k]) * N + a[i + (k + 1) % 3]);
        // use one
        if(a[i + 1] == a[i + 2]) swap(a[i], a[i + 2]);
        if(a[i] == a[i + 1]){
            rep(x, N){
                temp.push_back(((dp[a[i]][x] + 1) * N + x) * N + a[i + 2]);
            }
        }
        //use two
        rep(k, 3) temp.push_back(((dp[a[i + k]][a[i + k]] + 1) * N + a[i + (k + 1) % 3]) * N + a[i + (k + 2) % 3]);
        int x, y;
        ll score;
        for(ll q : temp){
            y = q % N;
            q /= N;
            x = q % N; score = q / N;
            chmax(dp[x][y], score);
            chmax(dp[y][x], score);
            chmax(memo[x], score);
            chmax(memo[y], score);
        }
    }
    int ans = 0, ml = *a.rbegin();
    rep(i,N) chmax(ans, (int)*max_element(ALL(dp[i])));
    chmax(ans, (int)dp[ml][ml] + 1);
    return ans - base;
}

int greedy_solver(vec a){return 0;}

void rand_make(vec &a, uniform_int_distribution<> &rand10, uniform_int_distribution<> &randINF, mt19937 &mt){
    N = rand10(mt);
    a.resize(N * 3);
    rep(i, N * 3) {
        a[i] = randINF(mt) % N;
    }
}

void run_debug(vec &a, int max_n = 3){
    int ans(0), ans2(0);
    random_device seed;
    mt19937 mt(seed());
    uniform_int_distribution<> rand10(1, max_n), randINF(0, (int)1e+9);
    int num = (int)1e+5;
    while(ans == ans2 && (--num)){
        rand_make(a, rand10, randINF, mt);
        ans = solver(a);
        ans2 = greedy_solver(a);
    }
    cout<<N<<endl;
    rep(i, N * 3) cout<<a[i] + 1<<" \n"[i == N * 3 - 1];
    cout<<ans<<endl;
    cout<<ans2<<endl;
}

int main() {
    vec a;
    //run_debug(a, 4);
    input(a);
    cout<<solver(a)<<endl;
}

Measured memory_bytes: 35208
n=int(input())
l=[int(input()) for _ in range(n)]
ans=0
if l[0]!=0:
  print(-1)
  exit()
for i in range(n-1):
  if (l[i]+1==l[i+1]):
    ans+=1
  elif (l[i]>=l[i+1]):
    ans+=l[i+1]
  else:
    print(-1)
    exit()
print(ans)


Measured memory_bytes: 17016
#include<stdio.h>
#define M 100000
#define N 100

int p[N],m[N][N];
int n;


void Matrix(){
  int i,j,l,q,k;
 
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=M;
      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	if(q<m[i][j]){
	  m[i][j]=q;
	}
      }
    }
  }
  printf("%d\n",m[1][n]);
}

int main(){
  int i,r,c;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&r,&c);
    p[i]=r;
    p[i+1]=c;
  }
  Matrix();
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

int main() {
  string s;
  cin >> s;
  if (s.back() == 's') {
    cout << s << "es" << endl;
  } else {
    cout << s << "s" << endl;
  }

  return 0;
}


Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 白のコマ */
	private static final char WHITE = '.';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			scanner.nextLine();
			boolean[][] s = new boolean[h][w];
			IntStream.range(0, h).forEach(i -> Arrays.fill(s[i], false));
			int whiteCount = 0;
			for (int i = 0; i < h; i++) {
				char[] l = scanner.nextLine().toCharArray();
				for (int j = 0; j < w; j++) {
					s[i][j] = (l[j] == WHITE);
					if (s[i][j]) {
						whiteCount++;
					}
				}
			}
			int[][] v = new int[h][w];
			IntStream.range(0, h).forEach(i -> Arrays.fill(v[i], Integer.MAX_VALUE));
			v[0][0] = 1;
			calcResult(0, 0, s, v);
			System.out.println((v[h - 1][w - 1] < Integer.MAX_VALUE) ? whiteCount - v[h - 1][w - 1] : -1);
		}
	}

	/**
	 * @param x X座標
	 * @param y Y座標
	 * @param s マスの状態の配列
	 * @param v (0,0)からそれぞれのマスへ移動する場合の通過マスの数の最小値
	 */
	private static void calcResult(int x, int y, final boolean[][] s, final int[][] v) {
		int h = s.length, w = s[0].length;
		if (((h - 1) == x) && ((w - 1) == y)) {
			// 終点の場合、終了
			return;
		}
		if ((x > 0) && s[x - 1][y] && (v[x][y] + 1 < v[x - 1][y])) {
			v[x - 1][y] = v[x][y] + 1;
			calcResult(x - 1, y, s, v);
		}
		if ((y > 0) && s[x][y - 1] && (v[x][y] + 1 < v[x][y - 1])) {
			v[x][y - 1] = v[x][y] + 1;
			calcResult(x, y - 1, s, v);
		}
		if ((x < h - 1) && s[x + 1][y] && (v[x][y] + 1 < v[x + 1][y])) {
			v[x + 1][y] = v[x][y] + 1;
			calcResult(x + 1, y, s, v);
		}
		if ((y < w - 1) && s[x][y + 1] && (v[x][y] + 1 < v[x][y + 1])) {
			v[x][y + 1] = v[x][y] + 1;
			calcResult(x, y + 1, s, v);
		}
	}
}


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

int main(){
  int n,k;
  cin >> n >> k;
  long mod = INF;
  // int l[k],r[k];
  vector<pair<int,int>> lr(k);
  rep(i,k){
    int a,b;
    cin >> a >> b;
    lr[i].first = a;
    lr[i].second = b;
  }
  sort(lr.begin(), lr.end());
  long dp[n+1],rui[n+1];
  rep(i,n+1){
    dp[i] = 0;
    rui[i] = 0;
  }
  dp[1] = 1; rui[1] = 1;
  for(int i=2;i<=n;i++){
    long tmp = 0;
    rep(j,k){
      int left = lr[j].first, right = lr[j].second;
      if(right < i){
        long ss = rui[i-left] - rui[i-right-1];
        if(ss < 0)ss += mod;
        tmp += ss;
        tmp %= mod;
      }else if(right >= i && left < i){
        tmp += rui[i-left];
        tmp %= mod;
      }
    }
    dp[i] = tmp;
    rui[i] = rui[i-1] + tmp;
    rui[i] %= mod;
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 6716
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

int dp[3][105]={},a[3][105];

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

  for(int i=1;i<=N;i++) {
    cin >> a[1][i];
  }
  for(int i=1;i<=N;i++) {
    cin >> a[2][i];
  }
  dp[1][1]=a[1][1];
  dp[2][1]=dp[1][1]+a[2][1];
  for(int i=2;i<=N;i++) {
    dp[1][i]=dp[1][i-1]+a[1][i];
  }
  for(int i=2;i<=N;i++) {
    dp[2][i]=max(dp[2][i-1]+a[2][i],dp[1][i]+a[2][i]);
  }

  cout << dp[2][N] << endl;
}

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

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

    vector<int> h(n);
    rep(i,n) cin >> h[i];

    h[0]--;
    for (int i = 1; i < n; i++) {
        if (h[i] == h[i-1]) {
            continue;
        }

        if (h[i] > h[i-1]) {
            h[i]--;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
 
using namespace std;
 
int main(){
  int W, H, x, y, r;
 
  cin >> W >> H >> x >> y >> r;
  if(x-r < 0 || x+r > W || y-r < 0 || y+r > H){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
 
  return 0;
}
 

Measured memory_bytes: 3076
var
y,n,x,i,j,c,d,b:longint;
e:qword;
begin
read(n,x,y);
for i:=1 to n do
begin
d:=i;
c:=0;
while(d>0) do
begin
c:=c+d mod 10;
d:=d div 10;
end;
if (c>=x) and (c<=y) then e:=e+i;
end;
write(e);
end.

Measured memory_bytes: 128