akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 1;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	FOR(i, 1, 10) {
		if (i * 100 + i * 10 + i >= N) {
			cout << i * 100 + i * 10 + i << endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
//A
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;

int main(){
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int N, X, T;
	scanf("%d%d%d", &N, &X, &T);
	int cnt = N / X + (N % X > 0);
	printf("%d\n", T * cnt);
}

Measured memory_bytes: 3784
n = int(input())
s = [input() for i in range(n)]

ans = [0]*4

for i in range(n):
    if s[i] == 'AC':
        ans[0] += 1
    elif s[i] == 'WA':
        ans[1] += 1
    elif s[i] == 'TLE':
        ans[2] += 1
    else:
        ans[3] += 1

print('AC x', ans[0])
print('WA x', ans[1])
print('TLE x', ans[2])
print('RE x', ans[3])

Measured memory_bytes: 16324
def get_primes(n):
	primes = [True for i in range(n+1)]
	primes[0] = False
	primes[1] = False
	for i in range(2, n+1):
		if i*i > n:
			break
		if not primes[i]:
			continue
		for non_prime in range(2 * i, n+1, i):
			primes[non_prime] = False
	return [i for i, prime in enumerate(primes) if prime]


def main():
	N = int(input())
	ans = 1
	DIV = 10**9+7
	primes = get_primes(N)
	d = [1]*len(primes)

	for i, p in enumerate(primes):
		q = p
		while N >= q:
			d[i] += N//q
			q *= p

	for div_num in d:
		ans *= div_num
		ans %= DIV
	print(ans)


if __name__ == '__main__':
    main()

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<bool> b(8);
  int fc = 0;
  for(int i = 0; i < n; i ++) {
    cin >> a.at(i);
    if (a.at(i) <= 399) {
      b.at(0) = true;
    } else if (a.at(i) <= 799) {
      b.at(1) = true;
    } else if (a.at(i) <= 1199) {
      b.at(2) = true;
    } else if (a.at(i) <= 1599) {
      b.at(3) = true;
    } else if (a.at(i) <= 1999) {
      b.at(4) = true;
    } else if (a.at(i) <= 2399) {
      b.at(5) = true;
    } else if (a.at(i) <= 2799) {
      b.at(6) = true;
    } else if (a.at(i) <= 3199) {
      b.at(7) = true;
    } else {
      fc ++;
    }
  }

  int sum = 0;
  for (int i = 0; i < 8; i ++) {
    if (b.at(i)) {
      sum ++;
    }
  }

  if (sum == 0) {
    cout << 1 << " " << fc << endl;
  } else {
    cout << sum << " " << sum + fc << endl;
  }
}


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

vector<int> par(200010);
vector<set<int>> st(200010);
vector<ll> c(200010), ans(200010);

void dfs(int i) {
    for (auto s : st[i]) {
        if (par[s] != 0)
            continue;
        par[s] = i;
        ans[s] += ans[i] + c[s];
        dfs(s);
    }
}

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

    cout << fixed << setprecision(10);
    int n, q;
    cin >> n >> q;
    int a, b;

    par[1] = 1;
    rep(i, 0, n - 1) {
        cin >> a >> b;
        st[a].insert(b);
        st[b].insert(a);
    }
    rep(i, 0, q) {
        int p;
        ll x;
        cin >> p >> x;
        c[p] += x;
    }

    ans[1] = c[1];
    dfs(1);
    rep(i, 1, n + 1) {
        cout << ans[i] << endl;
    }

    return 0;
}


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

/*
最大値の最小化(今回の場合, 最長の最短化)は二分探索が使える典型問題.
全ての丸太を, 丸太の長さを表す数直線上のある点X以下の長さにするために必要な切る回数が
K以下であるかどうかを判定する問題.
今回は最大値を最小化するので, 数直線上において大きい側がok, 小さい側がngとなる.
(長さ0の丸太は切ることができない)
二分探索である長さXを取って, 全ての丸太について, それぞれ長さX以下にするためには
何回切る必要があるかを調べる((A[i]-1)/x). その合計がK以下かどうか判定.
基本的に, Xが大きい方が切る回数は減るので, 合計がK以上ならXを大きくするべき(left(ng)=X)だし,
Kかそれ以下ならもっと攻められるから小さくするべき(right(ok)=X)
そうやって探索範囲を半分にしていって, 最終的にleftとrightの差が1以下になったら終了.
最小の最大値を求めるので, rightの値を取る.
*/

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  
  // めぐる式二分探索法
  // ngは解が存在しない値, okは解が存在する値を設定すれば良いので, 今回の場合はそれぞれ0, 1e9でも良い
  int ng = 0, ok = 1e9;
  while (abs(ok - ng) > 1) {  // どちらが大きいか明白であればabsは要らない
    int mid = (ok + ng) / 2;
    
    ll count = 0;
    rep(i, N) count += ((A.at(i) + mid - 1) / mid) - 1;
    (count <= K ? ok : ng) = mid;
    
    /*
    // ラムダ式. [&]で既出の変数を関数内で使うことができる. }後の()は関数呼び出しの意
    auto check = [&] {
      ll count = 0;
      // 全ての丸太について, それぞれを長さmid以下にするために必要な切断回数を求め足し合わせる
      rep(i, N) count += (A[i] - 1) / mid;
      return count <= K;  // return true or false
    }() ? ok = mid : ng = mid;
    */
    
    /*
    上の処理は以下と同義
    auto check = [&] {処理};
    if (check(mid)) ok = mid;
    else ng = mid;
    */
  }
  
  // 最小の最大値ok(right)
  cout << ok << endl;
}

Measured memory_bytes: 3952
N,K = map(int,input().split())

R,S,P = map(int,input().split())

T = input()

ans = 0
t = ""

for i in range(N):

    if T[i] == "r":

        if len(t) < K or (len(t) >= K and t[-K] != "P"):
            ans += P
            t += "P"
        else:
            t += "N"

    if T[i] == "s":

        if len(t) < K or (len(t) >= K and t[-K] != "R"):
            ans += R
            t += "R"
        else:
            t += "N"


    if T[i] == "p":

        if len(t) < K or (len(t) >= K and t[-K] != "S"):
            ans += S
            t += "S"
        else:
            t += "N"

print (ans)


Measured memory_bytes: 3444
# Atcoder Problem Solving
H,W=map(int,input().split())
c=[list(map(int,input().split())) for i in range(H)]
b=[list(map(int,input().split())) for i in range(H)]
a=[[0 for i  in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        a[i][j]=abs(c[i][j]-b[i][j])
        
dp=[[0 for i in range(W)] for j in range(H)]

# Bitset演算
# 答えは絶対値が絶対-80から80以内に収まる

X=3200

dp[0][0]= (1<<(X+a[0][0]))  | (1<<(X-a[0][0]))
# 初期化の条件

for i in range(H):
    for j in range(W):
        if 0<=i<H and 0<=j+1<W:
            dp[i][j+1]|=(dp[i][j]<<a[i][j+1])
            dp[i][j+1]|=(dp[i][j]>>a[i][j+1]) 
            
        if 0<=i+1<H and 0<=j<W:
            dp[i+1][j]|=(dp[i][j]<<a[i+1][j])
            dp[i+1][j]|=(dp[i][j]>>a[i+1][j])
            
A=str(bin(dp[H-1][W-1]))[::-1]
L=len(A)
ans=3200
for i in range(L):
    if A[i]=="1":
        ans=min(ans,abs(i-X))
print(ans)

Measured memory_bytes: 53468
#include<iostream>
#include<cmath>
using namespace std;
int before,after,sum;

int calc(int x){
  double a;
  a=x*100.0/(100+before);
  int b;
  b=ceil(a);
  if((int)(b*(100.0+before)/100) != x)return -1;
     double c=b*(100.0+after)/100;
     return (int)c;
}

int main(){
  while(cin>>before>>after>>sum,sum){
    int max=0;
    int a;
    for(int i=1;i<sum;i++){
      int tmp1,tmp2;
	tmp1=calc(i);
	tmp2=calc(sum-i);
	if(tmp1+tmp2>max)max=tmp1+tmp2;
    }
    cout << max << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
 
typedef struct
{
  int num;
  char mark;
} card;
 
int length;
int i, j;
card orig_n[36];
card sort_n[36];
card tmp;

void ScanCards();
void BubbleSort();
void PrintSortedCards();
void JudgeStable();
void SelectionSort();
void PrintSortedCards();
void JudgeStable();
 
void ScanCards(){
  char c;
 
  scanf("%d", &length);
  for(i=0;i<length;i++){
      while(1){
      c = getchar();
      if(c != ' ' && c != '\n') break;
      }
      orig_n[i].mark=c;
      scanf("%d",&orig_n[i].num);
      orig_n[i]=orig_n[i];
    }
}

void BubbleSort(){
  int flag;
 
  for(i=0;i<length;i++) sort_n[i]=orig_n[i];
 
  for(i=0;i<length;i++){
      flag=0;
      for(j=length-1;j>i;j--){
      if(sort_n[j-1].num>sort_n[j].num){
          tmp=sort_n[j];
          sort_n[j]=sort_n[j-1];
          sort_n[j-1]=tmp;
          flag=1;
        }
    }
      if(flag==0) break;
    }
}

void SelectionSort(){
  int min_i;
 
  for(i=0;i<length;i++) sort_n[i]=orig_n[i];
 
  for(i=0;i<length;i++){
      min_i=i;
      for(j=i;j<length;j++){
      if(sort_n[j].num<sort_n[min_i].num) min_i=j;
    }
      tmp=sort_n[i];
      sort_n[i]=sort_n[min_i];
      sort_n[min_i]=tmp;
    }

}

void PrintSortedCards(){
  for(i=0;i<length-1;i++){
      printf("%c%d ", sort_n[i].mark, sort_n[i].num);
    }
  printf("%c%d\n", sort_n[length-1].mark, sort_n[length-1].num);
}

void JudgeStable(){
  int s1,s2;
  int flag=0;
 
  for(i=0;i<length;i++){
      if(sort_n[i].num == sort_n[i+1].num){
      for(j=0;j<length;j++){
	if((sort_n[i].num==orig_n[j].num) && (sort_n[i].mark==orig_n[j].mark)) s1=j;
	if((sort_n[i + 1].num == orig_n[j].num) && (sort_n[i + 1].mark==orig_n[j].mark)) s2=j;
        }
      if(s1>s2) flag=1;
    }
      if(flag==1) break;
    }
  if(flag==0) printf("Stable\n");
  else printf("Not stable\n");
 
}

int main()
{
  ScanCards();
 
  BubbleSort();
 
  PrintSortedCards();
 
  JudgeStable();
 
  SelectionSort();
 
  PrintSortedCards();
 
  JudgeStable();
 
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
using pi = pair<lint, lint>;
const int MAXN = 100005;
const int mod = 998244353;
const int MAXC = 1005;

int main(){
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;

public class Main{

    public static void main(String[] args){
        //START

        Scanner sc=new Scanner(System.in);
        String A=sc.nextLine();
        String B=sc.nextLine();

        String[] strArray1=A.split("");
        String[] strArray2=B.split("");

        int i=0;
        for(i=0;i<strArray1.length;i++){
            if(!(strArray1[i].equals(strArray2[i]))){
                System.out.println("No");
                break;
            }
            if(i==strArray1.length-1){
                if(strArray2.length==strArray1.length+1){
                    System.out.println("Yes");
                    break;
                }

            }
        }
        //END
    }
}


Measured memory_bytes: 35788
# -*- coding: utf-8 -*-
 
import sys
import subprocess
import json
import time
import math
import re
import sqlite3
 
N = int(input())
s = input()
x = 0
max_x = 0
 
for c in s:
    if c == 'I': x += 1
    else: x -= 1
    max_x = max(max_x, x)
 
print(max_x)

Measured memory_bytes: 5320
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n;
ll v[1001],w[1001],s[1001];
ll dp[1001][20022];
int ord[1001];
bool cmp(const int& l,const int& r){
    return min(s[l],s[r]-w[l])>min(s[r],s[l]-w[r]);
}
int main(){
    cin>>n;
    rep(i,n) cin>>w[i]>>s[i]>>v[i];
    rep(i,n) ord[i]=i;
    sort(ord,ord+n,cmp);
    rep(i,n)rep(j,20002){
        int id=ord[i];
        dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
        if(j<=s[id]) dp[i+1][j+w[id]]=max(dp[i+1][j+w[id]],dp[i][j]+v[id]);
    }
    ll ans=0;
    rep(i,20002) ans=max(ans,dp[n][i]);
    cout<<ans<<endl;
    return 0;
}


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

const int maxn = 105;
int H, W;
char grid[maxn][maxn];
int dp[maxn][maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> grid[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i == 0 && j == 0) dp[i][j] = (grid[i][j]=='#');
            else if (i == 0) dp[i][j] = dp[i][j-1] + (grid[i][j] == '#' && grid[i][j] != grid[i][j-1]);
            else if (j == 0) dp[i][j] = dp[i-1][j] + (grid[i][j] == '#' && grid[i][j] != grid[i-1][j]);
            else dp[i][j] = min(dp[i][j-1]+(grid[i][j] == '#' && grid[i][j]!=grid[i][j-1]),dp[i-1][j]+(grid[i][j] == '#' && grid[i][j]!=grid[i-1][j]));
        }
    }
    int ans = dp[H-1][W-1];
    cout << ans << '\n';
}



Measured memory_bytes: 256
from collections import deque
import sys

sys.setrecursionlimit(1000000)

H, W = map(int, input().split())
G = [list(input()) for _ in range(H)]
que = deque()
# 始点を追加
for i in range(H):
    for j in range(W):
        if G[i][j] == '#':
            que.append([i, j])
cnt = -1
while que:
    cnt += 1
    next_que = deque()
    while que:
        h, w = que.popleft()  # BFSで探索
        dh = [1, 0, -1, 0]
        dw = [0, 1, 0, -1]
        for j in range(4):
            nh = h + dh[j]
            nw = w + dw[j]
            if 0 <= nh < H and 0 <= nw < W and G[nh][nw] == '.':
                G[nh][nw] = '#'
                next_que.append([nh, nw])
    que = next_que
print(cnt)

Measured memory_bytes: 168668
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r=0
p=[0,0,0,0,0]
for i in range(0,3):
  a,b = map(int, input().split())
  p[a]=p[a]+1
  r=max(r,p[a])
  p[b]=p[b]+1
  r=max(r,p[b])


if r >= 3:
  print('NO')
else:
  print('YES')


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
    double x1 = 0.0;
    double y1 = 0.0;
    double x2 = 0.0;
    double y2 = 0.0;
    
    cin >> x1 >> y1 >> x2 >> y2;
    cout << setprecision(20) << sqrt(((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))) << endl;
    
    return 0;
}


Measured memory_bytes: 3260
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

typedef vector<long long> vi;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,i,j,k,a[200],c=0,x,si;
    set<int> s;
    cin>>n;
    si=0;
    for(i=0;i<n;i++){
        cin>>a[i];
    }

    for(i=0;i<n-2;i++){
        for(j=i+1;j<n-1;j++){
            if(a[i]==a[j]) continue;
            for(k=j+1;k<n;k++){
                if(a[k]==a[i] || a[k]==a[j]) continue;
                if((a[i]+a[j])>a[k] && (a[i]+a[k])>a[j] && (a[j]+a[k])>a[i]) {
                    c++;
                    //cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
                }
            }
        }
    }
    cout<<c;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (min(A, B) <= C && max(A, B) >= C) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

		//??\??????????????????????????????Scanner???????????§???????????????
		Scanner scan = new Scanner(System.in);

		//????´¢??????????????????????????????
		String w = scan.next();

		//??????????????£????????¨????????????????????????????????¨?????°????????????
		int count = 0;

		while(true){
			//????????????1?????????????????????
			String t = scan.next();

			//???????????¶
			if( t.equals("END_OF_TEXT")){
				break;
			}
			//??§???????°????????????????????????????
			if(t.equalsIgnoreCase(w)){
				//true??????????????????
				count++;
			}
		}
		//???????????¨???
		System.out.println(count);

	}

}

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

using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;


int32_t main() {
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    
    ini(n);
    ini(n1);
    vi V(n);
    int pref[n];
    fill(pref,pref+n,0);
    int ato[n];
    fill(ato,ato+n,0);
    FOR(i,0,n){
        in(V[i]);
    }
    FOR(i,0,n){
        FOR(i1,0,i){
            if(V[i1]<V[i])pref[i]++;
        }
        FOR(i1,i+1,n){
            if(V[i1]<V[i])ato[i]++;
        }
    }
    int tmp = 0;
    int mo = 1000000007;
    FOR(i,0,n){
        tmp+=(pref[i]*((((n1-1)*n1)/2)%mo))%mo;
        tmp+=(ato[i]*((n1*(n1+1)/2)%mo))%mo;
    }
    tmp = tmp%mo;
    out(tmp);
    
    
    
    
    
    
    return 0;
}


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

using namespace std;

string solve(string a, string b){
  string res="";
  for(int i=0;i<a.size();i++){
    if(a[i]==b[i])res+='0';
    else res+='1';
  }
  return res;
}

int main(void){

  int n,x;
  string s[10]={
    "0111111",
    "0000110",
    "1011011",
    "1001111",
    "1100110",
    "1101101",
    "1111101",
    "0100111",
    "1111111",
    "1101111"
  };


  string a,b;
  while(cin >> n,~n){

    cin >> x;
    cout << s[x] << endl;
    a = s[x];
    n--; 

    while(n--){
      cin >> x;
      b=s[x];
      string ans=solve(a,b);
      cout << ans << endl;
      a=b;
    }
  }

  return 0;
}

Measured memory_bytes: 1204
x, y = map(int, input().split())
sub = 0
if x == 1:
    sub+=300000
elif x == 2:
    sub+=200000
elif x == 3:
    sub+=100000

if y == 1:
    sub+=300000
elif y == 2:
    sub+=200000
elif y == 3:
    sub+=100000

if x == 1 and y == 1:
    sub+=400000
print(sub)


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    
    vector<string> ans_r(H), ans_b(H);
    string r1 = "", r2 = "", b1 = "", b2 = "";
    for (int i = 0; i < W; i++) {
        if (i < W-1) r1 += "#";
        else r1 += ".";
        if (i > 0) r2 += ".";
        else r2 += "#";
        
        if (i < W-1) b1 += ".";
        else b1 += "#";
        if (i > 0) b2 += "#";
        else b2 += ".";
    }
    
    for (int i = 0; i < H; i++) {
        if (i%2 == 0) {
            ans_r[i] = r1;
            ans_b[i] = b1;
        }else {
            ans_r[i] = r2;
            ans_b[i] = b2;
        }
    }
    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '#') {
                ans_r[i][j] = '#';
                ans_b[i][j] = '#';
            }
        }
    }
    
    for (int i = 0; i < H; i++) {
        cout << ans_r[i] << endl;
    }
    cout << endl;
    
    
    for (int i = 0; i < H; i++) {
        cout << ans_b[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
import math
def firstdigit(i):
    r = int(round((float(i)/10-math.floor(float(i)/10))*10))
    return 9 if r==0 else r
food = []
for s in range(5):
    food.append(int(input()))
food=sorted(food,key=firstdigit)
sum=food.pop(0)
for s in food:
    sum+=int(round(math.ceil(float(s)/10)*10))
print(sum)

Measured memory_bytes: 3060
# https://atcoder.jp/contests/abc112/tasks/abc112_c

N = int(input())

p_l = [list(map(int, input().split())) for _ in range(N)]
p_l.sort(key=lambda x: -x[2])

temp_p = p_l[0]

for x in range(101):  # X
    for y in range(101):  # Y
        # 仮の中心
        h = temp_p[2] + abs(temp_p[1] - y) + abs(temp_p[0] - x)

        if all(max(h - abs(p[1] - y) - abs(p[0] - x), 0) == p[2] for p in p_l[1:]):
            print("{} {} {}".format(x, y, h))
            exit()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main(){
	string str;
	while(cin>>str){
		int j=0,i=0;
		for(size_t p=0;(p=str.find("JOI",p))!=-1;j++,p++);
		for(size_t p=0;(p=str.find("IOI",p))!=-1;i++,p++);
		cout<<j<<endl<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
table = list(map(int, input().split()))

for i in range(2, 0, -1):
    k = 0
    while k < i:
        if table[k] > table[k+1]:
            table[k], table[k+1] = table[k+1], table[k]
        k += 1;


print(table[0], table[1], table[2])


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  rep(i, n){
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(a.begin(), a.end(), greater<int>());
  double h = sum / (4 * (double) m);
  cerr << h << endl;
  string b = "Yes";
  rep(i, m){
    if(a.at(i) < h) b = "No";
  }
  cout << b << endl; 
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var n, h int
	fmt.Scan(&n, &h)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sort.Sort(sort.Reverse(sort.IntSlice(b)))
	aMax := a[0]
	ans := 0
	for i := 0; i < n; i++ {
		if aMax > b[i] || h <= 0 {
			break
		}
		h -= b[i]
		ans++
	}
	if h <= 0 {
		fmt.Println(ans)
	} else {
		fmt.Println(ans + int(math.Ceil(float64(h)/float64(aMax))))
	}
}


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

#define NMAX 101

using namespace std;

int W, H;
int x, y;

int main()
{
    cin >> W >> H >> x >> y;
    double midX = (double)W / 2;
    double midY = (double)H / 2;

    if((double)x == midX && (double)y == midY)
        printf("%.9lf %d\n", 2 * midX * midY, 1);
    else if((double)x == midX || (double)y == midY)
        printf("%.9lf %d\n", 2 * midX * midY, 0);
    else
    {
        printf("%.9lf %d\n", (double)W * (double)H / 2, 0);
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int r, g; cin >> r >> g;
  outl(2 * g - r);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ss[100005];
void ini()
{
    for(int i=0;i<100005;i++)
    {
        ss[i]=i;
    }
}
int main() {
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    int count=0;
    for(int i=1;i<n-1;i++)
    {
        if(arr[i-1]>arr[i]&&arr[i]>arr[i+1])count++;
        if(arr[i-1]<arr[i]&&arr[i]<arr[i+1])count++;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long LL;
int main()
{
    int x,y,ans=0,a[300]={0,300000,200000,100000,0};
    scanf("%d%d",&x,&y);
    if(x==1&&y==1)
        printf("1000000");
    else
        printf("%d",a[x]+a[y]);
    return 0;
}


Measured memory_bytes: 256
manipulation_times, num = tuple(int(i) for i in input().split(" "))
num_list = []
for i in range(manipulation_times):
    num_list.append(tuple(int(i) for i in input().split(" ")))


def num_0(tup):
    return tup[0]


num_list.sort(key=num_0)
count = 0
for i in num_list:
    count += i[1]
    if count >= num:
        print(i[0])
        break


Measured memory_bytes: 18192
#include <bits/stdc++.h>
using namespace std;
int main(void){
    double n;
    std::deque<double> deq;
    while (cin>>n) {
        deq.emplace_back(n);
    }
    sort(deq.begin(),deq.end());
    cout << deq.back()-deq.front() << endl;
}



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

int main() {
    stack<int> S1;
    stack<pair<int,int> > S2;
    char ch;
    int A=0;
    for (int i=0; cin >> ch; i++) {
        if (ch=='\\') {
            S1.push(i);
        } else if (ch=='/' && !S1.empty()) {
            int j=S1.top();
            S1.pop();
            A+=i-j;
            int a=i-j;
            while (!S2.empty() && S2.top().first>j) {
                a+=S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j,a));
        }
    }
    vector<int> L;
    while (!S2.empty()) {
        L.push_back(S2.top().second);
        S2.pop();
    }
    reverse(L.begin(),L.end());
    printf("%d\n",A);
    printf("%d",L.size());
    for (int k=0; k<L.size(); k++) {
        printf(" %d",L[k]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 3248
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> X(5);
    int idx = 0, mi = 10;
    REP(i, 5) {
        cin >> X[i];
        int Y = X[i] % 10;
        if (Y == 0) {
            continue;
        } else if (amin(mi, Y)) {
            idx = i;
        }
    }
    int res = 0;
    REP(i, 5) {
        if (i != idx) {
            res += ceil(X[i], 10) * 10;
        }
    }
    res += X[idx];
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
int cnt = 0;
int keta(ll x){
    if(x == 0) return cnt;
    else{
        x /= 10;
        cnt++;
        return keta(x);
    }
}



int main(void){
    // Your code here!
   ll S;
   cin >> S;
   int b = keta(S);
   ll ans = 0;
   vector<bool> vec(b-1);
   for(int i = 0; i < pow(2, b - 1); i++){
       ll I = i;
       for(int j = 0; j < b - 1; j++){
           vec.at(j) = I % 2;
           I /= 2;
       }
    
        vector<int> tennis(0);
        for(int j = 0; j < b-1; j++){
            if(vec.at(j) == 1) tennis.push_back(j);
        }
        int x = tennis.size();
    
        ll S_now = S;
        for(int j = 0; j < x; j++){
            ans += S_now / ll(pow(10, b-1-tennis.at(j)));
            S_now -= ll(S_now / int(pow(10, b-1-tennis.at(j)))) * pow(10, b-1-tennis.at(j));
        }
        ans += ll(S_now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <stdlib.h>
#include <numeric>
#include <cmath>
#define mod 1000000007
typedef unsigned long long int ll;
using namespace std;



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int sum1=0;int sum2=0;int md=INT32_MAX;
    for(int i=1;i<n-1;i++)
    {
        sum1=0;sum2=0;
        for(int j=0;j<=i;j++)
        sum1+=a[j];
        for(int j=i+1;j<n;j++)
        sum2+=a[j];
        if(abs(sum2-sum1)<md)
        md=abs(sum2-sum1);

    }
    cout<<md<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int LCM(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >> n;
    vector<tuple<string,int,int>> tau(n);
    rep(i,n){
        string s; cin >> s;
        int p; cin >> p;
        tau[i] = make_tuple(s,100 - p,i + 1);
    }
    SORT(tau);
    rep(i,n) cout << get<2>(tau[i]) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;
struct side{
    int to;
    int cost;
};
struct tree{
    vector<side>sons;
    int pos;
    int p;
};
tree map[100000];
int top;
void build(int now){
    if(map[now].pos>map[top].pos)top=now;
    for(int i=0;i<map[now].sons.size();i++)if(map[now].sons[i].to!=map[now].p){
        map[map[now].sons[i].to].p=now;
        map[map[now].sons[i].to].pos=map[now].pos+map[now].sons[i].cost;
        build(map[now].sons[i].to);
    }
}
int main(){
    int n,l,r,c;
    scanf("%d",&n);
    top=0;
    for(int i=1;i<n;i++){
        scanf("%d%d%d",&l,&r,&c);
        map[l].sons.push_back((side){r,c});
        map[r].sons.push_back((side){l,c});
    }
    map[0].pos=0;
    map[0].p=-1;
    build(0);
    map[top].pos=0;
    map[top].p=-1;
    build(top);
    printf("%d\n",map[top].pos);
}

Measured memory_bytes: 13684
from collections import Counter
N = int(input())
P = [tuple(map(int, input().split())) for _ in range(N)]
P.sort()
if N == 1:
  print(1)
  exit()

ct = Counter()
for i in range(len(P)):
  x1, y1 = P[i]
  for j in range(i+1, len(P)):
    x2, y2 = P[j]
    dx, dy = x2-x1, y2-y1
    if dx < 0:
      dx, dy = -dx, -dy
    ct[(dx, dy)] += 1

print(N - ct.most_common(1)[0][1])

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[101],b[101];
 cin>>n;
 for(int i=0;i<n;i++) cin>>a[i];
 for(int i=0;i<n;i++) cin>>b[i];
 int t=n,ans,chek=0,maxx=0;
	while(t--){
		ans=0;
	 for(int i=0;i<=chek;i++) ans+=a[i];
		for(int i=chek;i<n;i++) ans+=b[i];
		maxx=max(maxx,ans);
  chek++;
	}
 cout<<maxx;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll res = 0;
    for (int i = 0; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        res += i;
    }
    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
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; }
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    string S;
    cin >> S;
    ll N = len(S);
    vector<ll> R(N), L(N);
    ll ct = 1;
    rep(i, N - 1){
        if(S[i + 1] == 'R') ++ct;
        else R[i] = ct, ct = 0;
    }
    ct = 1;
    for (ll i = N - 1; i >= 1; --i){
        if(S[i - 1] == 'L') ++ct;
        else L[i] = ct, ct = 0;
    }

    rep(i, N - 1){
        if(S[i] == 'R' and S[i + 1] == 'L'){
            cout << devc(R[i], 2) + L[i + 1] / 2 << " ";
            cout << devc(L[i + 1], 2) + R[i] / 2 << " ";
            ++i;
        }
        else cout << 0 << " ";
    }
    if(S[N - 2] == 'L') cout << 0 << " ";
    print("");

    return 0;
}

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

int main(){
    long long n = 3; 
    
    cin >> n;
    
    // map<string, long long> m;

    // long n = 3;
    // map<string, long long> m = {{"acornistnt", 1}, {"peanutbomb", 2} ,{"constraint", 3}};
    map<string, long long> m;
    
    // vector<string> ss = {"acornistnt", "peanutbomb","constraint"};

    // for(long long i=0; i<n; i++){
    //     string s = ss.at(i);
    //     sort(s.begin(), s.end());
    //     m.insert(make_pair(s, i));
    // }

    for(long long i=0; i<n; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        m[s]++;
    }

    long long ans=0;

    for(auto p : m){
        long long x = p.second;
        // cout << "x = " << x <<endl;
        ans += x * (x-1)/2;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
s=int(input())
list=[s]
num=2
while num<=1000000:
  if list[num-2]%2==0:
    list.append(list[num-2]/2)
  else:
    list.append(list[num-2]*3+1)
  if list[num-1] in list[:num-1]:
    break
  num+=1
print(num)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }

int main(){
    int n,m; cin >> n >> m;
    vector<vector<int>> g(n), h(n);
    vector<int> s(m), t(m);
    vector<D> pr(m);
    map<P, int> index;
    rep(i,m){
        cin >> s[i] >> t[i]; s[i]--; t[i]--;
        g[s[i]].pb(t[i]);
        h[t[i]].pb(s[i]);
        index[{s[i], t[i]}] = i;
    }

    rep(i,m) pr[i] = 1.0 / (D)g[s[i]].size();

    vector<D> p(n);
    p[0] = 1;
    rep(i,n){
        for(int j : g[i]){
            p[j] += p[i] * pr[index[{i,j}]];
        }
    }

    vector<D> e(n);
    e[n-1] = 0;
    rrep(i,n){
        for(int j : h[i]){
            e[j] += (e[i]+1.0) * pr[index[{j,i}]];
        }
    }

    D ans = e[0];

    rep(i,m){
        int x = s[i], y = t[i];
        if(g[x].size() == 1) continue;

        D newex = (e[x] * (D)g[x].size() - 1.0 - e[y]) / (D)(g[x].size() - 1);
        
        chmin(ans, e[0] - p[x] * (e[x] - newex));
    }

    printf("%.10f\n", ans);
}


Measured memory_bytes: 19452
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
#include<ctime>

using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0)
#define ll long long
#define ull unsigned ll 
#define pb push_back

#define endl '\n'
#define mod 1000000007

#define FOR(i,k,n) for(int i=k; i<n; i++)
#define ROF(i,k,n) for(int i=k; i>=n; i--)
#define MEMSET(t) memset(t,0,sizeof(t));
#define time clock_t tStart
#define Start clock()
#define Time printf("Time taken: %.3fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC)



ll minC(int ar[], int n, ll dp[]) 
{
  if(n==1) return 0;
  if(dp[n]!=-1) return dp[n];
  if(n==2) return dp[n]=abs(ar[n-1]-ar[n-2]); 
  return dp[n]=min(
                    abs(ar[n-1]-ar[n-2])+minC(ar,n-1,dp),
                    abs(ar[n-1]-ar[n-3])+minC(ar,n-2,dp)  ); 
}

int main()
{
  fastio; 
  int t=1;
  while(t--)
  {
    int n;
    cin>>n;

    int ar[n];
    ll dp[n+1];
    FOR(i,0,n) cin>>ar[i];

   memset(dp,-1,sizeof(dp));
    cout<< minC(ar,n,dp)<<endl;
  

  }
  return 0;
}   


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

int main(){
  string str;
  cin >> str;
  string checkStr = "";
  rep(i, str.length()){
    if(str[i] != 'x') checkStr = checkStr + str[i];
  }
  bool kaibun = true;
  rep(i, checkStr.length()/2){
    if(checkStr[i] != checkStr[checkStr.length()-1-i]){
      kaibun = false;
      break;
    }
  }
  if(!kaibun){
    cout << -1 << endl;
    return 0;
  }
  int vecLength;
  if(checkStr.length() % 2 == 0) vecLength = checkStr.length() / 2;
  else vecLength = checkStr.length() / 2 + 1; 
  vector<int> front(vecLength, 0);
  vector<int> back(vecLength, 0);
  deque<char> que;
  rep(i, str.length()) que.push_back(str[i]);
  rep(i, vecLength){
    while(!que.empty() && que.front() == 'x'){
      que.pop_front();
      front[i]++;
    }
    if(!que.empty()) que.pop_front();
    while(!que.empty() && que.back() == 'x'){
      que.pop_back();
      back[i]++;
    }
    if(!que.empty()) que.pop_back();
  }
  int count = 0;
  rep(i, vecLength){
    count += abs(front[i]-back[i]);
  }
  cout << count << endl;
  return 0;
}
    

Measured memory_bytes: 1080
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n, start, end, ls, le;
    String s;
    int[] words;
    boolean[][] w;
    boolean[] use;

    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    if(n==0) break;

	    words = new int[26]; // start-end テ」ツ?ョテァツ崢クテ・ツッツセテヲツャツ。テヲツ閉ー
	    w = new boolean[26][26]; // start-end テ」ツ?ョティツセツコテ」ツ?古」ツ?づ」ツつ凝」ツ??
	    use = new boolean[26];

	    for(int i=0; i<n; i++){
		s = sc.next();
		char[] c = s.toCharArray();
		
		// テ」ツつづ」ツ?ョテ」ツ?凖」ツ?氾」ツ?湘ゥツ鳴禿ヲツ??」ツ?」テ」ツ?禿」ツ?療」ツ??」ツ?禿」ツ?ィテ」ツつ津」ツ?療」ツ?ヲテ」ツ??」ツ?淌」ツ?づ、ツスツ陛ヲツ閉?0'ティツカツウテ」ツ?療」ツ?淌」ツ?療」ツ??
		start = c[0]-'a';
		end = c[c.length-1]-'a';

		words[start]++;
		words[end]--;
		w[start][end] = true;
		use[start] = use[end] = true;		
	    }
	 

	    //showW();
	    System.out.println(solve() ? "OK" : "NG");
	}
    }

    boolean solve(){
	/*
	  テァツ崢クテ・ツッツセテヲツャツ。テヲツ閉ーテ」ツ?ョテ・ツ?ヲテァツ青?」ツ?ッテ」ツつウテ」ツつウテ」ツ??
	*/
	for(int i=0; i<26; i++){
	    if(!use[i]) continue;
	    if(words[i]!=0) return false; 
	}

	/*
	  hテ」ツ?ァテ・ツァツ凝」ツ?セテ」ツつ格テ」ツ?ァテァツオツづ」ツつ湘」ツつ凝・ツ債佚ィツェツ榲」ツ?古」ツ?づ」ツつ凝」ツ?凝ッツシツ湘・ツ按・テ」ツ?ョテヲツ鳴?・ツュツ楊テ」ツつ津、ツサツ凝」ツ?療」ツ?ヲhテ・ツァツ凝」ツ?セテ」ツつ格テァツオツづ」ツつ湘」ツつ甘」ツ?ョテ・ツ債佚ィツェツ榲」ツ?ィテ」ツ?ァテ」ツ?催」ツつ凝」ツ??
	  (iテ」ツ?ィjテ」ツ?ッティツ?ェテ・ツ按?」ツ?ァテ」ツつ暗」ツ?湘ゥツ鳴禿ゥツ?陛」ツ?暗」ツつ凝」ツ?ョテ」ツ?ァテ」ツ?）テ」ツ?ッテ、ツスツソテ」ツつ湘」ツ?ェテ」ツ??ヲツ鳴ケテ・ツ青妥」ツ?ァティツ。ツ古」ツ?催」ツ?セテ」ツ??
	*/
	for(int k=0; k<26; k++)
	    for(int h=0; h<26; h++)
		for(int i=0; i<26; i++)
		    w[h][i] = w[h][i] || (w[h][k]&&w[k][i]);
	
	/*
	  テヲツ慊?・ツセツ古」ツ?ォテ・ツ?・テ・ツ環崚」ツ?療」ツ?淌・ツ債佚ィツェツ榲」ツ?ョテヲツ慊?・ツ按敕」ツ?ョテヲツ鳴?・ツュツ耀tartテ」ツ?凝」ツつ嘉、ツスツソテァツ板ィテ」ツ?療」ツ?ヲテ」ツ??」ツつ?
	  テ・ツ?ィテ」ツ?ヲテ」ツ?ョテ」ツつ「テ」ツδォテ」ツδ陛」ツつ。テ」ツδ凖」ツδε」ツδ暗」ツ?ォテ」ツ?淌」ツ?ゥテ」ツつ甘ァツ敖?」ツ?妥」ツつ凝」ツ?凝」ツ??
	  テ、ツスツソテァツ板ィテ」ツ?療」ツ?淌・ツ?ィテ」ツ?ヲテ」ツ?ョテヲツ鳴?・ツュツ療」ツ?凝」ツつ嘉ヲツ慊?・ツセツ古」ツ?ョテヲツ鳴?・ツュツ容ndテ」ツ?クテ」ツ?淌」ツ?ゥテ」ツつ甘ァツ敖?」ツ?妥」ツつ凝」ツ??
	 */
	for(int i=0; i<26; i++)
	    if(use[i]){
		if(!w[start][i]) return false;
		if(!w[i][end]) return false;
	    }
	return true;
    }

    void showWords(){
	for(int i=0; i<26; i++)
	    System.out.print(words[i]+" ");
	System.out.println();
	System.out.println("----------");
    } 

    void showW(){
	for(int i=0; i<26; i++){
	    for(int k=0; k<26; k++)
		System.out.print(w[i][k]+" ");
	    System.out.println();
	}
	System.out.println("----------");
    }
}

Measured memory_bytes: 47464
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

void print_ans(bool flag){
    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }   
}

int main(){
    int n;
    cin >> n;
    ll a;
    int x = 0;
    int y = 0;
    int z = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a % 4 == 0){
            x++;
        } else if(a % 2 == 0){
            y++;
        } else {
            z++;
        }
    }
    print_ans((x >= z) || ((x == z - 1) && (y == 0)));
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K, A, B;
    cin >> K >> A >> B;

    ll ans = K + 1;
    if (A + 2 >= B) {
        cout << ans << endl;
        return 0;
    }

    ll cnt = 0;
    cnt += A - 1;
    if (cnt >= K) {
        cout << ans << endl;
        return 0;
    }

    ll cur = A;
    ll rest = K - cnt;
    cur += (B - A) * (rest / 2) + (rest % 2);
    cout << max(ans, cur) << endl;
    return 0;
}

Measured memory_bytes: 256
def com(n,r):
    re=fct[n]*pow(fct[r],md-2,md)*pow(fct[n-r],md-2,md)
    re%=md
    return re

n,m,k=map(int,input().split())
md=10**9+7
ans=0
fct=[1]*(n*m-1)
f=1
for i in range(1,n*m-1):
    f=f*i%md
    fct[i]=f
for d in range(1,m):
    ans=(ans+d*(m-d)*n*n)%md
for d in range(1,n):
    ans=(ans+d*(n-d)*m*m)%md
ans=(ans*com(n*m-2,k-2))%md
print(ans)


Measured memory_bytes: 10868
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int map[][];
	int w, h;
	void run() {
		Scanner sc = new Scanner(System.in);
		w = sc.nextInt();
		h = sc.nextInt();
		map = new int[h+2][w+2];
		for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) {
			map[i][j] = sc.nextInt();
		}
		bfs(0, 0);
//		for(int[] a: map) debug(a);
		int cnt = 0;
		for(int i=0;i<h+2;i++) for(int j=0;j<w+2;j++) {
			for(int k=2;k<5;k++) if( allow(j+dx[i%2][k], i+dy[i%2][k]) && map[i][j] + map[i+dy[i%2][k]][j+dx[i%2][k]] == 3 ) 
				cnt++;
		}
		System.out.println(cnt);
	}
	int dx[][] = {{-1,0,1,0,-1,-1}, {0,1,1,1,0,-1}};
	int dy[][] = {{-1,-1,0,1,1,0},{-1,-1,0,1,1,0}};
	void bfs(int sx, int sy) {
		LinkedList<P> que = new LinkedList<P>();
		que.add(new P(sx, sy));
		for(;!que.isEmpty();) {
			P p = que.removeFirst();
			int x = p.x;
			int y = p.y;
			for(int i=0;i<6;i++) {
				if( allow(x+dx[y%2][i], y+dy[y%2][i]) && map[y+dy[y%2][i]][x+dx[y%2][i]] == 0 ) {
					map[y+dy[y%2][i]][x+dx[y%2][i]] = 2;
					que.add(new P(x+dx[y%2][i], y+dy[y%2][i]));
				}
			}
		}
	}
	
	class P {
		int x, y;
		P(int x, int y) {
			this.x = x;this.y =y;
		}
	}
	
	boolean allow(int x, int y) {
		return !(x < 0 || y < 0 || x >= w+2 || y >= h+2 );
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
using ll = long long;
 
ll euclid(ll a, ll b ){
    ll temp;
    if( a < b ) { temp = a; a = b; b = temp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return euclid( b, a % b );
}

int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll E = (C*D)/euclid(C, D);
    ll q = B - A + 1;
    ll f;
    f = B/C - A/C;
    if(A%C == 0){
        f++;
    }
    ll g;
    g = B/D - A/D;
    if(A%D == 0){
        g++;
    }
    ll h;
    h = B/E - A/E;
    if(A%E == 0){
        h++;
    }
    cout << q-f-g+h;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,i,j,tmp,sum;
  int a[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    for(j=i;j<n;j++){
      if(a[i]<a[j]){
        tmp=0;
        tmp=a[i];
        a[i]=a[j];
        a[j]=tmp;
      }
    }
  }
  for(i=0;i<n;i++){
    if(i%2==0){
      sum+=a[i];
    }else{
      sum-=a[i];
    }
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128