akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl


/*--------------------template--------------------*/


int main() {
    cin >> n;
    vi v(n);
    REP(i, n) cin >> v[i];
    REP(i, n) {
        if (v[i] == 0) {
            ans += sum / 2;
            sum = 0;
        } else {
            sum += v[i];
        }
    }
    cout << (ans += sum / 2) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <bitset>

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

using namespace std;

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  vector<vector<int>> dp(n, vector<int>(8));
  string c = "JOI";
  int idx = find(begin(c), end(c), s[0]) - begin(c);
  int bits = 1 << idx | 1;
  for (int i = 0; i < 8; ++i) {
    if ((i & bits) == bits) {
      dp[0][i] = 1;
    }
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < 8; ++j) {
      bitset<3> b(j);
      int idx = find(begin(c), end(c), s[i]) -begin(c);
      int bits = 1 << idx;
      for (int k = 0; k < 8; ++k) {
        if ((k & bits) == bits) {
          bitset<3> b2(k);
          auto is = b & b2;
          if (is.any()) {
            dp[i][k] += dp[i-1][j];
            dp[i][k] %= 10007;
          }
        }
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < 8; ++i) {
    sum += dp[n-1][i];
    sum %= 10007;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

//最小値問題
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    llong n,h[100002],dp[100002];
    cin >> n;
    rep(i,n){
        cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(llong i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    bool a = true;
    for(int i=1;i<4;i++){
        if(s[i] == s[i-1]) a = false;
    }
    if(a) cout << "Good" << endl;
    else cout << "Bad" << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;

int N, M;
long long int A[100005], C[100005];
int B[100005];

vector<long long int>V;
set<long long int >temp;
vector<long long int >W;

map<long long int, int> MAP;

int main(void) {

	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		V.push_back(A[i]);
	}

	for (int i = 1; i <= M; i++) {
		cin >> B[i] >> C[i];
		temp.insert(-C[i]);
		MAP[C[i]] += B[i];
	}

	sort(V.begin(), V.end());

	

	for (auto it = temp.begin(); it != temp.end(); it++) {

		long long int val;
		val = (*it);
		val = -val;

		for (int j = 1; j <= MAP[val]; j++) {
			W.push_back(val); if (W.size() > N) { break; }
		}

		if (W.size() > N) { break; }
	}
	
	W.push_back(-100004);


	vector<long long int>ans;

	int p = 0, q = 0;

	for (int i = 1; i <= N; i++) {
		//cout << "comp " << V[p] << " " << W[q] << endl;
		if (V[p] > W[q]) { ans.push_back(V[p]); p++; }
		else { ans.push_back(W[q]); q++; p++; }
	}

	long long int ANS = 0;

	for (int i = 0; i < N; i++) {
		ANS += ans[i];
	}

	cout << ANS << endl;

	/*for (int i = 0; i < N; i++) {
		cout << "V[" << i << "]= " << V[i] << endl;
	}
	for (int i = 0; i < N; i++) {
		cout << "W[" << i << "]= " << W[i] << endl;
	}

	for (int i = 0; i < N; i++) {
		cout << "ans[" << i << "]= " << ans[i] << endl;
	}*/


	return 0;
}

Measured memory_bytes: 16244
N = list(map(int, input().split()))
N.sort()
d = N[2] - N[1]
if (N[2] - (N[0] + d)) % 2 == 0:
    print(d +(N[2] - (N[0] + d)) // 2)
else:
    print(d + (N[2] - (N[0] + d)) // 2 + 2)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int H, W, N, x, y, a; vector<int> l[4];
int main() {
	cin >> W >> H >> N;
	for(int i = 0; i < N; i++) {
		cin >> x >> y >> a;
		if(a <= 2) l[a - 1].push_back(x);
		else l[a - 1].push_back(y);
	}
	int e1 = (l[0].size() ? *max_element(l[0].begin(), l[0].end()) : 0);
	int e2 = (l[1].size() ? *min_element(l[1].begin(), l[1].end()) : W);
	int e3 = (l[2].size() ? *max_element(l[2].begin(), l[2].end()) : 0);
	int e4 = (l[3].size() ? *min_element(l[3].begin(), l[3].end()) : H);
	cout << max(e2 - e1, 0) * max(e4 - e3, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <set>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
    int a,b;

    cin >> a >> b;

    if(a*b%2==0) cout << "Even" << "\n";
    else cout << "Odd" << "\n";

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=0
b=n*10**9
for i in range(m):
  x,y=map(int,input().split())  
  a=max(a,x)
  b=min(b,y)
if b>=a:
  ans=b-a+1
  print(ans)
else:
  print(0)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int sum;
int main()
{
	int x,a,b;
	cin>>a>>b;
	sum=a+a-1;
	if(sum<a+b)
		sum=a+b;
	if(sum<b+b-1)
		sum=b+b-1;
	cout<<sum;
	return 0; 
 } 

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
      	int t = sc.nextInt();
      	int s = sc.nextInt();
      	if( d <= t * s ){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
	}
}

Measured memory_bytes: 27080
#include <algorithm>
#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 ll long long
#define INF 1000000000000000000

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

    string s;
    cin >> s;
    int N = s.size();
    int ans = 1e9;
    for (int i = 0; i < N - 2; i++) {
        string ss = s.substr(i, 3);
        int num = abs(753 - stoi(ss));
        ans = min(ans, num);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3592
import collections
n,m = map(int, raw_input().split(' '))
matrix = [list(raw_input()) for _ in range(n)]
dpleft = [[0 for j in range(m)] for i in range(n)]
dpright = [[0 for j in range(m)] for i in range(n)]
dpup = [[0 for j in range(m)] for i in range(n)]
dpdown = [[0 for j in range(m)] for i in range(n)]

for i in range(n):
	cumul = 0
	for j in range(m):
		if matrix[i][j] == '#':
			cumul = 0
		else:
			dpleft[i][j] = cumul
			cumul +=1

	cumul = 0
	for j in range(m-1,-1,-1):
		if matrix[i][j] == '#':
			cumul = 0
		else:
			dpright[i][j] = cumul
			cumul +=1

for j in range(m):
	cumul = 0
	for i in range(n):
		if matrix[i][j] == '#':
			cumul = 0
		else:
			dpup[i][j] = cumul
			cumul +=1

	cumul = 0
	for i in range(n-1,-1,-1):
		if matrix[i][j] == '#':
			cumul = 0
		else:
			dpdown[i][j] = cumul
			cumul +=1
r = 0
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] != '#':
			r = max(r, 1 + dpleft[i][j] + dpright[i][j] + dpdown[i][j] + dpup[i][j])

print r

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


void solve(long long M, long long D){
    long long res = 0;
    for(long long d=22;d<=D;++d){
        int d1 = d%10;
        int d2 = (d/10)%10;
        if(d1>=2&&d2>=2&&d1*d2<=M)res++;
    }
    cout<<res<<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long M;
    scanf("%lld",&M);
    long long D;
    scanf("%lld",&D);
    solve(M, D);
    return 0;
}


Measured memory_bytes: 256
hoge = []
N = int(input())
for i in range(N):
    hoge.append(input().split())

btc = 380000
a = 0
for e in hoge:
    if e[1] == 'JPY':
        a += float(e[0])
    else:
        a += float(e[0]) * btc
print(a)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define maxn 200009
#define LL long long
using namespace std;
LL a[maxn];
map<LL,int>mp;
int main(){
  int n;LL ans=0;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
    scanf("%lld",a+i),a[i]+=a[i-1];
  mp[0]=1;
  for(int i=1;i<=n;i++){
    if(mp.count(a[i])) ans+=mp[a[i]];
    mp[a[i]]++;
  }
  printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
const ll inf = 1e18;
const int nax = 2e6 + 7;

using namespace std;
string s;
//int fl1 , fl2;
int main(int argc,char ** argv){
	dhoom;
	deque< char > dq;
	string s;
	cin >> s;
	for(int i = 0 ;i < (int)s.size() ; i++)
		dq.pb(s[i]);
	int q;
	cin >> q;
	int flag = 0;
	for(int i = 0 ; i < q ; i++){
			int f;
			cin >> f;
			if(f == 1){
				flag ^= 1;
			}
			if(f == 2){
				int x;
				char y;
				cin >>x >> y;
				if(flag == 0){
					if(x == 1)
						dq.push_front(y);
					else
						dq.push_back(y);
				}
				else{
					if(x == 1)
						dq.push_back(y);	
					else
						dq.push_front(y);
				}
			}
	}
	if(flag == 1)
	{
		while(!dq.empty()){
			char x = dq.back();
			cout << x ;
			dq.pop_back();
		}
	}
	else
	{
		while(!dq.empty()){
			char x = dq.front();
			cout << x;	
			dq.pop_front();
		}
	}
	return 0;
	
}


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

int main(void) {

    int h, w;
    while(cin >> h >> w){

      if( h == 0 && w == 0 ) break;

      for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
          if( i == 0 || j == 0 || i == h-1 || j == w-1 ) cout << "#";
          else cout << ".";
        }
        cout << endl;
      }
      cout << endl;
    }


    return 0;
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N, C, K, t[100100], ans;

int main () {
        scanf("%d %d %d", &N, &C, &K);
        fo(i, 0, N) scanf("%d", &t[i]);
        sort(t, t+N);
        fo(i, 0, N) {
                int rs = i;
                while (i+1 < N && t[i+1] == t[i]) i++;
                int re = i, nbus = (re-rs+C) / C;
                ans += nbus;
                ll extra = 1ll * nbus * C - ((ll) re-rs+1);
                while (i+1 < N && t[i+1] <= t[rs]+K && extra > 0) {
                        i++;
                        extra--;
                }
        }
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
    
    if(a==b){
        //a＝＝bの場合
        System.out.println("a == b");
       } 
    
    else{
        //a<bの場合
        if (a<b){
        System.out.println("a < b");    
        }
        
        //a＞bの場合
       else{
        System.out.println("a > b");  
         
        }        
    }
    //    System.out.println();
    }
}


Measured memory_bytes: 26240
// 速度改善版.
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
vector<vector<int>> A(MAX);
priority_queue<int> reward;

int main(){

    // 1. 入力情報取得.
    int N, M;
    scanf("%d %d", &N, &M);
    for(int i = 0; i < N; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        if(a <= M) A[a].push_back(b);
    }
    
    // 2. どの仕事を請けるか確定させる.
    //      (報酬支払日／仕事開始日)
    // No.1  M     日後 : 0日目
    // No.2  M - 1 日後 : 1日目まで.
    // No.3  M - 2 日後 : 2日目まで.
    // No.4  M - 3 日後 : 3日目まで.
    // ...
    // No.M      1 日後 : M - 1日目まで.
    // -> 仕事開始日が最も遅い, No.M から順に, 仕事出来るかどうかを決めていく.
    // -> 具体的には, 以下の流れで, 仕事を請けるか決定していくイメージ.
    // No.M       の 仕事 が, X(M)件     あれば, 一番報酬 の 大きい仕事 を 請ける.
    // No.(M - 1) の 仕事 が, X(M - 1)件 あれば, No.M の 残りの仕事 と 併せて, 一番報酬の大きい仕事を引き受ける.
    // 以下, 繰り返し.
    // ※N件の制約事項は, 4. で対応.
    priority_queue<int> pq;
    for(int d = M - 1; d >= 0; d--){
        // 2-1. d日目で, 可能な仕事の報酬を取得.
        for(auto &r : A[M - d]) pq.push(r);
        
        // 2-2. 仕事があれば, 報酬情報(1件)を, rewardテーブルに登録.
        if(pq.size() > 0){
            int r = pq.top();
            pq.pop();
            reward.push(r);;
        }
    }
    
    // 3. 最大 N件 まで請けた場合に, 報酬の最大値を計算.
    int ans = 0, counter = N;
    while(!reward.empty() && counter > 0){
        int r = reward.top();
        reward.pop();
        ans += r;
        counter--;
    }
    
    // 4. 出力 ～ 後処理.
    printf("%d\n", ans);
    return 0;

}

Measured memory_bytes: 6268
/*
 * atcoder/dp_3rd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const int MAX = 100100;
ll N;
ll A[MAX][4];
ll dp[MAX][4];

void input() {
  cin >> N;
  loop(n,0,N) {
    cin >> A[n][1] >> A[n][2] >> A[n][3];
  }
}

void solve() {
  memset(dp, 0, sizeof(dp));

  for (int n=0; n<N; n++) {
    for (int k=1; k<=3; k++) {
      if (n == 0) {
        dp[0][k] = A[0][k];
        continue;
      }

      for (int k_1=1; k_1<=3; k_1++) {
        if (k == k_1) continue;
        if (chmax(dp[n][k], dp[n-1][k_1] + A[n][k])) {
          // cout << n << " " << k << " " << dp[n][k] << endl;
        }
      }
    }
  }
  cout << max(max(dp[N-1][1], dp[N-1][2]), dp[N-1][3]) << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 6528
#B
ABCD = input().split(' ')
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
while A > 0 and C > 0:
    C -= B
    A -= D
if C <= 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9052
#include <iostream>
#include <set>
using namespace std;
int main(){
    int x,n;
    cin >> x >> n;
    set<int> st;
    for(int i = 0; i < n; i++){
        int p; cin >> p;
        st.insert(p);
    }
    int a = 0;
    while(1){
        if(st.count(x-a) == 0){
            cout << x-a << endl;
            break;
        }
        if(st.count(x+a) == 0){
            cout << x+a << endl;
            break;
        }
        a++;
    }
    return 0;
}

Measured memory_bytes: 3596
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	as := intSliceScanner(n)
	sort.Ints(as)
	cant := -1
	for i := 0; i < n-1; i++ {
		if as[i]*2 < as[i+1] {
			cant = i
		}
		as[i+1] += as[i]
	}
	fmt.Println(n - cant - 1)
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    int mx = 0;
    rep(i, 0, n) {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    int l = 0, r = inf;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        int cnt = 0;
        rep(i, 0, n) cnt += (a[i] - 1) / mid;
        if (cnt <= k) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << "\n";
}


Measured memory_bytes: 5176
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rep(i, n) cin >> a[i];
  ans = a[0];
  rrep(i, 1, n) ans = __gcd(ans, a[i]);
  Cout(ans);
  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

inline bool isMonth(const int d) { return 0 < d && d <= 12; }

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    string s;
    cin >> s;

    const int up = stoi(s.substr(0, 2));
    const int down = stoi(s.substr(2, 2));

    if (isMonth(up) && isMonth(down)) cout << "AMBIGUOUS\n";
    else if (isMonth(up) && !isMonth(down)) cout << "MMYY\n";
    else if (!isMonth(up) && isMonth(down)) cout << "YYMM\n";
    else cout << "NA\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
int main() {
    std::string n;
    std::cin >> n;
    for (auto& c : n) {
        if (c == '1') {
            c = '9';
        }
        else if (c == '9') {
            c = '1';
        }
    }
    std::cout << n << std::endl;
}


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

using ll = long long;
using P = pair<int, int>;

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

int cnt[4];

int main() {
  int a, b;
  for (int i = 0; i < 3; i++) {
    cin >> a >> b;
    cnt[a-1]++, cnt[b-1]++;
  }

  sort(cnt, cnt + 4);
  int ans[4] = {1, 1, 2, 2};
  for (int i = 0; i < 4; i++) if (cnt[i] != ans[i]) {
    cout << "NO" << endl;
    return 0;
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int n;
	cin >> n;
	getchar();
	while(n > 0){
	    char a[2000] = {0};
	    scanf("%[^\n]",a);
	    getchar();
	    int len = 0;
	    for(int i = 0; a[i] != 0; i++) len++;
	    for(int i = 0; i < len; i++){
            if(a[i] == 'H' && a[i+1] == 'o' && a[i+2] == 's' && a[i+3] == 'h' && a[i+4] == 'i' && a[i+5] == 'n' && a[i+6] == 'o') a[i+6] = 'a';
	    }
	    printf("%s\n",a);
        n--;
	}
	return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_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(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int a[10] = {3,8,5,2,6,9,1,2,6,10};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code

    int N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N);
    vector<vector<ll>> dp(K, vector<ll>(N, 0));
    rep(i, N) {
        cin >> A[i];
    }
    dp[0] = A;
    rep(i, 1, K) {
        deque<int> dq;
        rep(j, i) {
            while(!dq.empty() && dp[i - 1][dq.back()] < dp[i - 1][j]) {
                dq.pop_back();
            }
            dq.push_back(j);
        }
        rep(j, i, N) {
//            cout << i << "," << j << ":" << dq.front() << endl;
            dp[i][j] = dp[i - 1][dq.front()] + A[j] * (i + 1);
            while(!dq.empty() && dp[i - 1][dq.back()] < dp[i - 1][j]) {
                dq.pop_back();
            }
            dq.push_back(j);
            while(!dq.empty() && j - dq.front() >= M) dq.pop_front();
            
        }
    }
    
    ll ans = 0;
    rep(i, N) {
        ans = max(ans, dp[K - 1][i]);
    }
    output(ans);
    
    
    
    return 0;
}


Measured memory_bytes: 237056
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    long long a;
    cin >> a;
    int b = sqrt(a);
    int num = 1;
    for(int i=b+1;i>0;i--){
        if(a/i*i == a)
        {
            num = i;
            break;
        }
    }

    cout << num+a/num-2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100005
typedef long long ll;
ll ans[N];
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int start = 0;
    while(start < n){
    	int end = start;
    	while(s[end] == 'R') end++;
    	int r = end - 1;
    	int l = end;
    	while(s[end] == 'L') end++;
    	end--;

    	for(int i = start ; i <= end ; i++){
    		if(i % 2 == r % 2)	ans[r]++;
    		else ans[l]++;
    	}
    	start = end + 1;
    }
    for(int i = 0 ; i < n ; i++)
    	cout << ans[i] << " ";

}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;

int n,m,a,sum;

signed main() {
    cin >> n >> m;
    rep(i,m) cin >> a, sum += a;
    if (sum > n) cout << -1 << endl;
    else cout << n-sum << endl;
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    map<i64, i64> m;
    for (i32 i = 0; i < N; i++) {
        i64 a;
        cin >> a;
        m[a]++;
    }
    i64 sum = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
        if (it->first != it->second) {
            i64 sub = it->second - it->first;
            sum += sub > 0 ? sub : it->second;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 9528
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		if (arr.length % 2 == 1) {
		    System.out.println("No");
		    return;
		}
		for (int i = 0; i < arr.length; i++) {
		    if ((i % 2 == 0 && arr[i] == 'h') ||
		        (i % 2 == 1 && arr[i] == 'i')) {
		        } else {
		            System.out.println("No");
		            return;
		        }
		}
	    System.out.println("Yes");
	}
}


Measured memory_bytes: 22996
import java.util.Scanner;
class Point{
	public double x_;
	public double y_;
	
	Point(double x,double y){
		x_ = x;
		y_ = y;
	}
	
	double long_(Point a,Point b) {
		return Math.sqrt((b.x_-a.x_)*(b.x_-a.x_)+(b.y_-a.y_)*(b.y_-a.y_));
	}
	
}

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x = sc.nextDouble();
		double y = sc.nextDouble();
		Point p1 = new Point(x,y);
		 x = sc.nextDouble();
		 y = sc.nextDouble();
		Point p2 = new Point(x,y);
		
		System.out.println(p1.long_(p1,p2));
		
	}
}



Measured memory_bytes: 27876
#include <algorithm>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main(){
    int A, B, T;
    cin >> A >> B >> T;

    int sum = 0;
    for (int i=A; i<=T; i+=A) {
        sum += B;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
const int N = 1e6 + 9;
int vis[N], take[N];
int main() {
	//file();
	fast();
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		vis[x]++;
	}
	int ans = n;
	for (int i = 1; i < N; i++) {
		if (take[i] || !vis[i]) continue;
		if (vis[i] > 1) ans -= vis[i];
		for (int j = i + i; j < N; j += i) {
			if (take[j] || !vis[j]) continue;
			take[j] = 1;
			ans -= vis[j];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11456
import Data.List

cons a as = Just (a:as)

ans' _ [] = Nothing
ans' m (a:as) =
   if m < a
   then Nothing
   else if m == a
        then Just [a]
        else if a' /= Nothing
             then a' >>= (cons a)
             else b'
   where
        a' = ans' (m-a) as
        b' = ans' m as

ans m a =
   let o = ans' m a
   in
        case o of
            Nothing -> "no"
            Just _  -> "yes"

main = do
    _ <- getLine
    a <- getLine
    _ <- getLine
    m <- getLine
    let a' = sort $ map read $ words a :: [Int]
        m' = map read $ words m :: [Int]
        o  = map (\ m -> ans m a') m'
--    print o
    mapM_ putStrLn o


Measured memory_bytes: 4576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int K;
    cin >> K;
    vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << vec.at(K - 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
	int n,m,i,j;
	while(cin>>n &&n){
		string A,B;
		vector<string> a,b;
		for(i=0;i<n;i++){
			cin>>A;
			cin>>B;
			a.push_back(A);
			b.push_back(B);
		}
		cin>>m;
		string X;
		vector<string> x;
		for(i=0;i<m;i++){
			cin>>X;
			for(j=0;j<n;j++){
				if(X==a[j]){
				X=b[j];
				break;
			}
			}
			x.push_back(X);
		}
		for(i=0;i<m;i++){
		cout<<x[i];
		}
		cout << endl;
	}
return 0;
}

Measured memory_bytes: 2840
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

class State {
public:
	int id;
	string str;
	int deep;
	vector<State> rep;

	void draw()
	{
		rep(i, deep) {
			cout << '.';
		}

		cout << str << endl;

		for (auto& r : rep) {
			r.draw();
		}
	}

	void add(State s, int i)
	{
		if (i == id) {
			s.deep = deep + 1;
			rep.push_back(s);
		}
		else {
			for (auto& r : rep) {
				r.add(s, i);
			}
		}
	}
};

int main()
{
	int n;

	cin >> n;

	State s;
	s.id = 1;
	s.deep = 0;
	
	cin >> s.str >> s.str;

	rep(i, n - 1) {
		int r;
		State temp;
		temp.id = i + 2;

		cin >> r >> temp.str;

		s.add(temp, r);
	}

	s.draw();

	return 0;
}

Measured memory_bytes: 3408
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include  <vector>
using namespace std;
#define INF 0x3f3f3f3f
const int N = 1111;
int mod = 1e9 + 7;
typedef long long ll;


int main()  
{
   /// freopen("in.txt", "r", stdin); 
    int n;
    while (~scanf("%d", &n))
    {
        if (n < 1000)
            puts("ABC");
        else
            puts("ABD");
    }
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x"=" << x <<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3

#define MAX_N 1000000001

int main(){
	cin.sync_with_stdio(false);
	string str;
	cin >> str;
	int j = 0;
	string newStr = "          ";
	rep(i, str.size()){
		if(str[i] == '0' || str[i] == '1') {
			newStr[j++] = str[i];
		} else {
			j--;
			if (j < 0) j = 0;
		}
	}

	cout << newStr.substr(0, j) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long lld;
#define INF (1<<20)

int main(){
  int N; cin >> N;
  int ban[311][311];
  lld P[311][311];
  memset(P,0,sizeof(P));
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      cin >> ban[i][j];
      P[i][j] = P[i][j-1]+P[i-1][j]-P[i-1][j-1]+ban[i][j];
    }
  }
  lld ret = -INF;
  for(int i=1;i<=N;i++){
    for(int j=i;j<=N;j++){
      lld prev=0;
      for(int k=1;k<=N;k++){
	lld line = P[j][k]-P[i-1][k]-P[j][k-1]+P[i-1][k-1];
	ret = max(ret,line+prev);
	prev = max(line,prev+ban[i][k]+(i!=j?ban[j][k]:0));
      }
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 4196
from collections import deque
n,m = map(int,input().split())
G = [[[] for _ in range(3)] for _ in range(n)]
for _ in range(m):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    G[u][0].append((v,1))
    G[u][1].append((v,2))
    G[u][2].append((v,0))
s,t = map(int,input().split())
s -= 1
t -= 1

dist = [[-1]*3 for _ in range(n)]
dist[s][0] = 0
Q = deque([(s,0)])
while Q:
    now,r = Q.popleft()
    for nxt,nr in G[now][r]:
        if dist[nxt][nr] != -1: continue
        dist[nxt][nr] = dist[now][r]
        if r == 2: dist[nxt][nr] += 1
        Q.append((nxt,nr))
# print(dist)
print(dist[t][0])

Measured memory_bytes: 83904
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val goal = cin.nextInt()
    val a = cin.nextInt()
    val b = 2 * a - goal;
    println(b);
	/* print(cin.nextInt()+cin.nextInt()) */
	/* print(" ")                         */
	/* println(cin.next())                */
}


Measured memory_bytes: 29352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int N = rei();
	string S = res();
	int R = 0;
	int B = 0;
	for(int i=0;i<N;i++){
		if(S[i] == 'R'){
			R++;
		}
		else{
			B++;
		}
	}
	if(R > B){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[][] s = new String[h][w];
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				s[i][j] = sc.next();
			}
		}
		String sans = "snuke";
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if(s[i][j].equals(sans)){
					char c = (char)(j + 'A');
					String ans = c +  "" + (i+1);
					System.out.println(ans);
				}
			}
		}
		sc.close();

	}

}

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

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> c(H);
    for (int i = 0; i < H; i++)
    {
        cin >> c.at(i);
    }

    int res = 0;
    for (int ph = 0; ph < (1 << H); ph++)
    {
        for (int pw = 0; pw < (1 << W); pw++)
        {
            int cnt = 0;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (c.at(i).at(j) == '#' && ((ph >> i) & 1) == 0 && ((pw >> j) & 1) == 0)
                        cnt++;
                }
            }
            if (cnt == K)
                res++;
        }
    }
    cout << res << endl;
    return 0;
}


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

int main() {
  
  int N; cin >> N;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) cin >> vec[i];
  
  if (N == 1) { cout << vec[0] << endl; return 0; }
  
  int tmp = __gcd(vec[0], vec[1]);
  
  for (int i = 2; i < N; i++) tmp = __gcd(tmp, vec[i]);
  
  cout << tmp << endl;
  
}

Measured memory_bytes: 3760
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    vector<int> w(n);
    for (int i = 0; i < n; i++) {
        cin >> w.at(i);
    }
    
    int ans = 1e+5;
    for (int i = 0; i < n - 1; i++) {
        int a = 0, b = 0;
        for (int j = 0; j <= i; j++) a += w.at(j);
        for (int j = i + 1; j < n; j++) b += w.at(j);
        ans = min(ans, abs(a - b));
    }
    
    cout << ans << endl;
    
    return 0;
}


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

#define dbg if(0)
using namespace std;
#define ll long long

int main(){
    int n,m;
    ll ans=0;
    cin >> n>>m;
    ll a[n+1];
    a[0]=0;
    for(int i=1;i<=n;i++){
        int tmp;
        cin >> tmp;
        a[i]=(a[i-1]+tmp % m)%m;
    }
    sort(a,a+n+1);
    ll bef=a[0];
    ll cnt=0;
    for(int i=1;i<=n;i++){
        cnt++;
        dbg cout <<a[i]<<endl;
        if(a[i]==0)ans++;
        if (bef!=a[i]){
            dbg cout <<cnt<<endl;
            cnt--;
            ans+=(cnt-1)*(cnt)/2;
            cnt=1;
        }
        bef=a[i];
    }
    ans+=(cnt-1)*(cnt)/2;


    cout <<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vvl G(n);
    vector<pair<ll, ll>> vp;  // vp[i] = (a, b) : 辺iは頂点aとbを結ぶ
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
        vp.emplace_back(a, b);
    } 
    
    vl cs(n);  // cs[i] : 頂点iと親を結ぶ辺の色
    vl used(n);  // used[i] : 頂点iを訪れたら1
    map<pair<ll, ll>, ll> mp;  // mp[(i, j)] : 頂点iと頂点jを結ぶ辺の色
    queue<ll> Q;

    Q.push(0);
    used[0] = 1;
    while(!Q.empty()) {
        ll v = Q.front();
        Q.pop();
        ll color = 1;
        for(auto u : G[v]) {
            if(used[u]) {
                continue;
            }
            if(color == cs[v]) {
                color++;
            }
            cs[u] = mp[make_pair(u, v)] = mp[make_pair(v, u)] = color;
            color++;
            used[u] = 1;
            Q.push(u);
        }
    }

    ll K = 0;
    rep(i, n) {
        chmax(K, (ll)G[i].size());
    }
    out(K);

    for(auto p : vp) {
        out(mp[p]);
    }

    re0;
}

Measured memory_bytes: 22128
#include <stdio.h>

int main(void)
{
	char S[4];
	int i = 0;
	int j;
	
	scanf("%s",S);
	
	for (j = 0;j < 4;j++){
		if(S[j] == '+'){
			i++;
		}
		
		else if(S[j] == '-'){
			i--;
		}
	}
	
	printf("%d\n",i);
	
	return(0);
}

Measured memory_bytes: 128
def decode(str)
  res = []
  if str.count('_') > 0
    res = str.split('_')
  else
    if /[a-z]/.match(str[0])
      str[0] = str[0].upcase
    end
    str.chars.each do |c|
      if /[A-Z]/.match(c)
        res << c.downcase
      else
        res[-1] << c.downcase
      end
    end
  end
  return res
end

def encode(vs, t)
  res = ""
  if t == 'D'
    res = vs * '_'
  else
    vs.each do |str|
      str[0] = str[0].upcase
      res << str
    end
    if t == 'L'
      res[0] = res[0].downcase
    end
  end
  return res
end

while true
  str, t = gets.split
  break if t == 'X'
  puts(encode(decode(str), t))
end


Measured memory_bytes: 6932
// Aizu Vol-10 1008: What Color Is The Universe?
// 2017.8.19 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 299993
typedef struct { int n, c; } HASH;
HASH hash[HASHSIZ + 5], *hashend = hash + HASHSIZ;

int color, cnt;

int lookup(int n)
{
	HASH *p = hash + n % HASHSIZ;
	while (p->n) {
		if (p->n == n) return ++(p->c);
		if (++p == hashend) p = hash;
	}
	p->n = n, p->c = 1;
	return 1;
}

int main()
{
	int n, i, k;

	while (scanf("%d", &n) && n) {
		memset(hash, 0, sizeof(hash)), cnt = 1;
		for (i = 0; i < n; i++) {
			scanf("%d", &k);
			if (lookup(k) == cnt) cnt++, color = k;
		}
		if (--cnt > n / 2) printf("%d\n", color);
		else puts("NO COLOR");
	}
	return 0;
}

Measured memory_bytes: 2964
chomp( my $n = <> );
chomp( my $s = <> );
chomp( my $t = <> );

while ( $s ) {
    $s eq $t and print 2*$n - length $s and exit;
    substr $s, 0, 1, '';
    substr $t, -1, 1, '';
}
print 2*$n;

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

// vector print(debug or stdout)
template <class Iit>
void vout(const Iit &begin,const Iit &end,ostream &out) {
    for(auto it = begin; it != end; it++) {
        auto tmp = it;
        if (++tmp == end) out << *it << '\n';
        else out << *it << " ";
    }
}

int main(void)
{
    IOS
    const ll N = 50;
    ll K; cin >> K;
    vector<ll> ans(N);
    int m = K % N;
    ll d = K / N;
    ll x = N-1 - m + d;
    ll y = N + d;
    REP(i,N) {
        if (i < m) ans[i] = y;
        else ans[i] = x;
    }
    OUT(50)
    vout(ALL(ans),cout);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	ll n,ans;
	cin>>n;
	for(int i=0;i*i<=n;i++){
		ans=i*i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, K = MAP()
A = LIST()
INF = 10**20


def calc_cost(A, bit):
    cost = 0
    observed = 1
    prev_height = A[0]
    bit = bit | 1

    for n in range(1, N):
        if prev_height < A[n]:
            prev_height = A[n]
            observed += 1
        elif bit >> n & 1:
            costi = prev_height - A[n] + 1
            prev_height = A[n] + costi
            observed += 1
            cost += costi
    return observed, cost


ans = INF
for i in range(1 << N):
    observed, cost = calc_cost(A, i)
    if observed >= K:
        ans = min(ans, cost)

print(ans)


# for i in range(1 << N):
#     use = [i>>j & 1 for j in range(N)]
#     if sum(use) < K:
#         continue

#     res = 0
#     now = 

Measured memory_bytes: 42860
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<pair<int, int> > A(N);
  for(int i=0; i<N; i++){
    A[i].second = i+1;
    cin >> A[i].first;
  }

  sort(A.begin(), A.end());

  for(int i=0; i<N; i++){
    cout << A[i].second << " ";
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    int A, B;
    rep(i, M) {
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    vector<int> check(N, -1);
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    while(!q.empty()) {
        pair<int, int> tmp = q.front(); q.pop();
        if (check[tmp.first] != -1) continue;
        check[tmp.first] = tmp.second;
        rep(i, G[tmp.first].size()) {
            q.push(make_pair(G[tmp.first][i], tmp.first));
        }
    }
    rep(i, N) {
        if (check[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    rep2(i, 1, N) {
        cout << check[i]+1 << endl;
    }
}


Measured memory_bytes: 12220
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

int main(){
	string x; cin >> x;
	stack<char> s;
	Rep(i, x.size()){
		if(x[i] - 'S' == 0){
			s.push(x[i]);
		}else if(s.empty() || (!s.empty() && x[i] - 'T' == 0 && s.top() - 'T' == 0)){
			s.push(x[i]);
		}else if(x[i] - 'T' == 0 && s.top() - 'S' == 0){
			s.pop();
		}
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 644
/**
 * @Author:      G_bg
 * @DateTime:    2019-09-28 20:13:36
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn = 1e5+10;
int a[maxn];
int main(int argc, const char *argv[]) {
    ios::sync_with_stdio(0);cin.tie(0);
    int n,x;cin >> n;
    for(int i = 0;i < n;++i){
        cin >> x;
        a[x] = i+1;
    }
    for(int i = 1;i < n;++i)
        cout << a[i] << " ";
    cout << a[n] << endl;
    return 0;
}

Measured memory_bytes: 1280
n, c = map(int, input().split())

x = [0] * n
v = [0] * n
for i in range(n):
    x[i], v[i] = map(int, input().split())

x = [0] + x + [c]
v = [0] + v + [0]

left = [0] * (n + 2)
right = [0] * (n + 2)

for i in range(n + 1):
    left[i + 1] = left[i] + v[i + 1] - (x[i + 1] - x[i])
for i in range(n + 1, 0, -1):
    right[i - 1] = right[i] + v[i - 1] - (x[i] - x[i - 1])


for i in range(n + 1):
    left[i + 1] = max(left[i + 1], left[i])
for i in range(n + 1, 0, -1):
    right[i - 1] = max(right[i - 1], right[i])

# 引き返さない最大
ans = max(left[-1], right[0])
right = list(reversed(right))
for i in range(n):
    tmp = left[i] - x[i]
    rem = n - i
    ans = max(ans, tmp + right[n - i])

for i in range(n):
    tmp = right[i] - (c - x[-(i + 1)])
    rem = n - i
    ans = max(ans, tmp + left[n - i])

print(ans)


Measured memory_bytes: 27472