akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  int s; cin >> s;
  bool MMYY = false;
  bool YYMM = false;
  string ans;
  if(s/100 >= 1 && s/100 < 13){
    MMYY = true;
    if(s%100 >= 1 && s%100 < 13){
      YYMM = true;
    }
  }else{
    if(s%100 >= 1 && s%100 < 13){
      YYMM = true;
    }
  }
  
  if(MMYY == true){
    ans = "MMYY";
    if(YYMM == true){
      ans = "AMBIGUOUS";
    }
  }else{
    ans = "NA";
    if(YYMM == true){
      ans = "YYMM";
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double w,h,x,y;
    cin >> w >> h >>  x >> y;
    double s= w*h/2;
    cout << s << " "<< ((w==x*2 && h==y*2)?1:0)<<endl;

}

Measured memory_bytes: 256
n = int(input())
pt = 0
px = 0
py = 0
l = []
for i in range(n):
    t,x,y = map(int,input().split())
    l.append((t,x,y))

for i in range(n):
    t,x,y = l[i]
    d = abs(x - px) + abs(y - py)
    dt = t - pt
    if d % 2 != dt % 2 or dt < d:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 17372
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(){
  long X, A, B, A5, B5;
  scanf("%ld", &X);
  for (A = 0; 1; A++) {
    for (B = 0; B <= A; B++) {
      A5 = A * A * A * A * A;
      B5 = B * B * B * B * B;
      if (A5 - B5 == X) {
        printf("%d %d", A, B);
        return 0;
      }
      if (A5 + B5 == X) {
        printf("%d %d", A, -B);
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;

	int Ans = (n - 1)*(m - 1);

	cout << Ans;

	return 0;
}

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

int main(){
  int n, l;
  cin >> n >> l;
  int ans;
  if (l > 0) ans = (l+l+n) * (n-1) / 2; // l+1 + l+n-1
  else if (l + n <= 0) ans = (l+l+n-2) * (n-1) / 2; // l + l+n-1-1
  else ans = (l+l+n-1) * n / 2;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(x,val) memset(x,val,sizeof(x));

int v[105],w[105];
int n;
int weight;
ll dp[105][100005];
ll cal(int pos,int cap)
{
    if(pos>=n){
        return 0;
    }
    if(dp[pos][cap]!=-1)return dp[pos][cap];
    ll x=0,y=0;
    if(cap+w[pos]<=weight){
        x = cal(pos+1,cap+w[pos])+v[pos];
    }
    else x=0;
    y = cal(pos+1,cap);

    return dp[pos][cap]=max(x,y);
}
int main()
{
    mem(dp,-1);
    cin >>n;
    cin >>weight;

    for(int i=0;i<n;i++){
        cin >>w[i]>>v[i];
    }
    cout <<cal(0,0)<<endl;

    return 0;

}

Measured memory_bytes: 82304
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)

int main(void){
	int n,i,st,sh,cmp;
	char t[101],h[101];
	
	scanf("%d",&n);
	
	st=0;
	sh=0;
	rep(i,0,n){
		cmp=0;
		scanf("%s",t);
		getchar();
		scanf("%s",h);
		
		cmp=strcmp(t,h);
		if(cmp>0) st+=3;
		else if(cmp==0){
			st++; sh++;
		}else sh+=3;
		
	}
	printf("%d %d\n",st,sh);	
	
	return 0;
}



Measured memory_bytes: 2036
#include<iostream>
#include<vector>

int main(){
	//入力機構
	size_t N,K;
	std::cin>>N>>K;
	std::vector<int> x(N,0);//|x[i]|<10^8なのでintで表現できる
	for(size_t i=0;i<N;i++){
		std::cin>>x[i];
	}

	//処理機構
	//連続したK本を火をつけるのが最適解の条件である
	//全探索すればok。O(N-K)でいける。
	//i番目(i=0,1,...)から右にK本の火をつけるのは次の方法でいける。x[i]からx[i+K-1]に火をつければいいので、
	//(1-1)x[i]<x[i+K-1]<=0の時、time=-x[i]
	//(1-2)x[i]<=0<x[i+K-1]の時、time=-x[i]+x[i+K-1]+std::min(-x[i],x[i+K-1])
	//(1-3)0<x[i]<x[i+k-1]の時、time=x[i+K-1]
	int ans=-1;
	for(size_t i=0;i+K-1<N;i++){
		//x[i]~x[i+K-1]をつけるための計算
		int time;
		if(x[i+K-1]<=0){
			time=-x[i];
		} else if(x[i]<=0 && 0<x[i+K-1]){
			time=-x[i]+x[i+K-1];
			if(-x[i]<x[i+K-1]){
				time+=-x[i];
			} else{
				time+=x[i+K-1];
			}
		} else{
			time=x[i+K-1];
		}
		//これが最小なら、最小時間を更新。ansが負の時は、初期化されていない証拠
		if(ans<0 || time<ans){
			ans=time;
		}
	}

	//出力機構
	std::cout<<ans<<std::endl;

	return 0;
}


Measured memory_bytes: 640
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array.Unboxed

main :: IO ()
main = do
  [n,m] <- getl $ wrds toInt
  unless (n == 0 && m == 0) $ do
    solve n <$> replicateM m (getl $ wrds toInt) >>= print
    main
    
solve :: Int -> [[Int]] -> Int
solve n xs = mst am [0] [1..n-1] 0
  where
    ia = listArray ((0,0),(n-1,n-1)) $ repeat 10000 :: UArray (Int,Int) Int
    am = foldl (\ar [i,j,c] -> ar // [((i,j),c),((j,i),c)]) ia xs

mst :: UArray (Int,Int) Int -> [Int] -> [Int] -> Int -> Int
mst am us [] mnc = mnc
mst am us vs mnc = mst am (nu:us) (vs \\ [nu]) (mnc+tc)
  where
    (tc,nu) = minimum [(am ! (u,v), v)|u <- us, v <- vs]

toInt :: String -> Int
toInt s = read s

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

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

using namespace std;
	
int a[30];

int main()
{
	long long a,ans=0;
	cin >> a;
	long long ar1[a],ar2[a];
	for(int i=0;i<a;i++)
	{
		cin >> ar1[i] >> ar2[i];
	}
	for(int i=a-1;i>=0;i--)
	{
		ar1[i]+=ans;
		if(ar1[i]%ar2[i] != 0)
		ans+=ar2[i]-(ar1[i]%ar2[i]);
		
	}
	cout << ans;
}

 



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

// using
using namespace std;

// typedef
typedef long long ll;

// define
#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 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)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, 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() {
    const int MAX_H = 100, MAX_W = 100;
    int H, W;
    char a[MAX_H][MAX_W];
    bool row[MAX_H] = {}, col[MAX_W] = {};
    cin >> H >> W;
    REP(i, H) {
        REP(j, W) {
            cin >> a[i][j];
            if (a[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }
    REP(i, H) {
        if (!row[i]) {
            continue;
        }
        REP(j, W) {
            if (!col[j]) {
                continue;
            }
            cout << a[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std;
const unsigned ll l=1000000007;
const int MAX_=2000;

int main()
{
  ll a,b;
  cin >> a >> b;

  set<ll> s;

  ll c = a+b;
  a = min(a,b);
  b = c-a;

  // cout << a << b << endl;


  if(a%2 == 0)
  {
    s.insert(2);
    while(a%2 == 0)
      a /= 2;
  }

  for(ll i=3; i*i<=a; i+=2)
  {
    if(a%i == 0)
    {
      s.insert(i);
      while(a%i == 0)
        a/=i;
    }
  }

  if(a!=1)
    s.insert(a);

  ll n = s.size();

  // cout << n << endl;

  for(auto i: s)
  {
    if(b%i != 0)
      n--;
  }

  cout << n+1 << endl;

  return 0;
}


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

import static java.lang.Integer.parseInt;

/**
 * Ohgas' Fortune
 */
public class Main {

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

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

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

			int b = parseInt(br.readLine());
			int y = parseInt(br.readLine());
			int max = -1;

			int n = parseInt(br.readLine());
			for (int j = 0; j < n; j++) {
				StringTokenizer st = new StringTokenizer(br.readLine());

				int t = parseInt(st.nextToken());
				double r = Double.parseDouble(st.nextToken());
				int c = parseInt(st.nextToken());

				if (t == 0) {
					max = Math.max(max, simple(b, y, r, c));
				} else {
					max = Math.max(max, compound(b, y, r, c));
				}
			}

			System.out.println(max);
		}
	}

	static int simple(int b, int y, double r, int c) {
		int _i = 0;
		for (int i = 0; i < y; i++) {
			_i += b * r;
			b -= c;
		}
		return b + _i;
	}

	static int compound(int b, int y, double r, int c) {
		for (int i = 0; i < y; i++) {
			int _i = 0;
			_i += b * r;
			b += _i;
			b -= c;
		}
		return b;
	}
}

Measured memory_bytes: 31740
// C++ program to count the Minimum number of 
// increasing subsequences 
#include <bits/stdc++.h> 
using namespace std; 

long MinimumNumIncreasingSubsequences(long arr[], long n) 
{ 
	multiset<long> last; 

	// last element in each increasing subsequence 
	// found so far 
	for (long i = 0; i < n; i++) { 

		// here our current element is arr[i] 
		multiset<long>::iterator it = last.lower_bound(arr[i]); 

		// iterator to the first element larger 
		// than or equal to arr[i] 
		if (it == last.begin()) 

			// if all the elements in last larger 
			// than or to arr[i] then insert it into last 
			last.insert(arr[i]); 

		else { 
			it--; 

			// the largest element smaller than arr[i] is the number 
			// before *it which is it-- 
			last.erase(it); // erase the largest element smaller than arr[i] 
			last.insert(arr[i]); // and replace it with arr[i] 
		} 
	} 
	return last.size(); // our answer is the size of last 
} 


int main() 
{ 

	long n;
	cin>>n;
	long arr[n];
	for(long i=0;i<n;i++)
		cin>>arr[i];
	
		cout<< MinimumNumIncreasingSubsequences(arr, n); 
	return 0; 
} 


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

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int X,Y;cin >> X >> Y;
  if((2*X-Y)%3){
    cout << 0 << endl;
  }
  else{
    COMinit();
    int a=(2*X-Y)/3,b=X-2*a;
    cout << COM(a+b,b) << endl;
  }
}

Measured memory_bytes: 23680
<?php

[$N, $K] = fscanf(STDIN, "%d%d");

$A = fscanf(STDIN, str_repeat("%d", $N));
$score = 1;

for($i=$K;$i<$N;$i++){
    if($A[$i-$K] >= $A[$i]){
        echo "No".PHP_EOL;
    }else{
        echo "Yes".PHP_EOL;
    }
}



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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


signed main() {
    int T;
    cin >> T;

    vector<string> vcs = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

    for(int t=0; t<T; t++) {
        string s;
        cin >> s;

        int idx = -1;
        int num = 0;
        bool flag = false;
        for(int i=0; i<s.length(); i++){
            //cout << i <<" "<< s[i] <<" "<< idx << endl;
            if (s[i] == '0') {
                //cout << i <<" num:"<< num <<" idx:"<< idx <<" flag:"<< flag << endl;
                if (!flag) cout << "";
                else cout << vcs[num-1][idx];
                //cout << endl;
                idx = -1;
                flag = false;
            } else {
                flag = true;
                num = s[i] - '0';
                idx = (idx+1)%vcs[num-1].length();
                //cout << vcs[num-1][idx] << endl;
            }
            //cout << s[i] << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
ll power(ll x,ll n)
{
	ll res =1;
	while(n>0)
	{
		if(n%2==1)
	res=res*x;
	x=x*x;
	n=n/2;
	}
	return res;
	
}

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,k,i;
    cin>>n>>m>>k;
    ll a[n],b[m];
    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<m;i++)
    cin>>b[i];
    set<ll>s;
    while(k--)
    {
    	int x,y,c;
    	cin>>x>>y>>c;
    	s.insert(a[x-1]+b[y-1]-c);
    	
	}
    sort(a,a+n);
    sort(b,b+n);
    cout<<min(*s.begin(),a[0]+b[0]);
	
    
}


Measured memory_bytes: 5120
#include <stdio.h>
 
int n,S[500001];
int a=0;
 
void merge(int left, int mid, int right)
{
  int n1 = mid - left;
  int n2 = right - mid;
   
  int L[n1+1], R[n2+1];
   
  int i, j, k;
   
  for(i=0; i<n1; i++)
    L[i] = S[left+i];
   
  for(i=0; i<n2; i++)
    R[i] = S[mid+i];
     
  L[n1] = 1000000001;
  R[n2] = 1000000001;
   
  i = 0;
  j = 0;
   
  for(k=left; k<right; k++){
    a++;
    if(L[i] <= R[j])
      S[k] = L[i++];
    else
      S[k] = R[j++];
  }
}
 
void mergeSort(int left, int right)
{
  int mid;
   
  if(right -left <= 1)
    return;
     
  mid = (left+right)/2;
  mergeSort(left, mid);
  mergeSort(mid, right);
   
  merge(left, mid, right);
}

int main(){
int i,left,right;
scanf("%d", &n);
for(i=0; i<n; i++)
scanf("%d", &S[i]);
left = 0;
right = n;
mergeSort(left, right);
for(i=0; i<n; i++){
if(i>0)
printf(" ");
printf("%d", S[i]);
  }
printf("\n");
printf("%d\n", a);
return 0;
}

Measured memory_bytes: 5628
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve() {
	while (true) {
		int n, t, l, b;
		cin >> n >> t >> l >> b;
		if (n == 0) return;
		int inst[200] = {};
		REP(i, l) {
			int a;
			cin >> a;
			inst[a] = 1;
		}
		REP(i, b) {
			int a;
			cin >> a;
			inst[a] = 2;
		}
		long double ans[200][200] = {};
		ans[0][0] = 1.0;
		REP(i, t) {
			REP(q, n) {
				long double prob = ans[i][q] / (long double)6.0000L;
				for (int j = 1; j <= 6; ++j) {
					int next = q + j;
					if (next > n) {
						next = n - (next - n);
					}
					if (inst[next] == 1) {
						ans[i + 2][next] += prob;
					}
					else if (inst[next] == 2) {
						ans[i + 1][0] += prob;
					}
					else {
						ans[i + 1][next] += prob;
					}
				}
			}
			ans[i + 1][n] += ans[i][n];
		}
		cout << ans[t][n] << endl;
	}
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3892
import java.util.ArrayDeque;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}
	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}
	static IntStream INS(int n){
		return REPS(n).map(i->getInt());
	}
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	
	public static void main(String[] $){
		int n=getInt();
		
		ArrayDeque<Integer> d=new ArrayDeque<>();
		
		for(int i=0;i<n;i++) {
			int v=getInt();
			if(i%2==0) {
				d.addLast(v);
			}else {
				d.addFirst(v);
			}
		}
		
		StringJoiner j=new StringJoiner(" ");
		
		if(n%2==1) {
			while(!d.isEmpty())
				j.add(String.valueOf(d.pollLast()));
		}else {
			while(!d.isEmpty())
				j.add(String.valueOf(d.pollFirst()));
		}
		System.out.println(j.toString());
	}
}


Measured memory_bytes: 71620
# -*- coding:utf-8
while True:
    A = list(map(int,input().split()))
    H,W = A[0],A[1]

    if H == 0 and W == 0:
        break

    for i in range(H):
        for j in range(W):
            if i == H - 1 or j == W - 1:
                print("#",end='')
            elif i == 0 or j == 0:
                print("#",end='')
            else:
                print(".",end='')
        print()
    print()


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

static const int Max = 1000;

void show(int*A, int N) {
	for (int i = 0; i < N; ++i) {
		cout << A[i];
		if (i != N - 1) {
			cout << ' ';
		}
	}
	cout << endl;
}

void Insert(int* A, int N) {
	for (int i = 1; i < N; ++i) {
		int j = i - 1;
		int v = A[i];

		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			--j;
		}
		A[j+1] = v;
		
		show(A, N);
	}
}

int main() {
	int A[Max], N;
	
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	show(A, N);
	Insert(A, N);


}


Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int cal(int i,int a,int b,int c,int d){
    // if (i == 4 && sum == 7) return res;
    if(i==0) return a+b+c+d;
    else if(i==1) return a+b+c-d;
    else if(i==2) return a+b-c+d;
    else if(i==3) return a-b+c+d;
    else if(i==4) return a+b-c-d;
    else if(i==5) return a-b+c-d;
    else if(i==6) return a-b-c+d;
    else if(i==7) return a-b-c-d;
    else return 0;
}
int main(){
    int in;
    int a,b,c,d;
    cin >> in;
    // cout << in << endl;
    a = in / 1000;
    if ( a != 0) in = in % (a*1000);
    b = in / 100;
    if ( b != 0) in = in % (b*100);
    c = in / 10;
    if ( c != 0) in = in % (c*10);
    d = in / 1;

    // cout << a << b << c << d << endl;


    int res = 0;
    for (int i = 0; i < 8; i++){
        if(cal(i,a,b,c,d)==7) res = i;
    }

    if(res==0) cout<< a<<'+'<<b<<'+'<<c<<'+'<<d<<'='<<7<<endl;
    else if(res==1) cout<< a<<'+'<<b<<'+'<<c<<'-'<<d<<'='<<7<<endl;
    else if(res==2) cout<< a<<'+'<<b<<'-'<<c<<'+'<<d<<'='<<7<<endl;
    else if(res==3) cout<< a<<'-'<<b<<'+'<<c<<'+'<<d<<'='<<7<<endl;
    else if(res==4) cout<< a<<'+'<<b<<'-'<<c<<'-'<<d<<'='<<7<<endl;
    else if(res==5) cout<< a<<'-'<<b<<'+'<<c<<'-'<<d<<'='<<7<<endl;
    else if(res==6) cout<< a<<'-'<<b<<'-'<<c<<'+'<<d<<'='<<7<<endl;
    else if(res==7) cout<< a<<'-'<<b<<'-'<<c<<'-'<<d<<'='<<7<<endl;

    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
ts = [0] + gets.chomp.split.map(&:to_i)
vs = gets.chomp.split.map(&:to_i)
(1..n).each{ |i| ts[i] += ts[i - 1] }

times = (ts[-1] * 2 + 1).times.map{ [0] * (n+2) }
steps = 0.0.step(ts[-1], 0.5)
steps.each_with_index do |t, j|
  times[j][0] = t
  times[j][n+1] = ts[-1] - t
end
(0...n).each do |i|
  steps.each_with_index do |t, j|
    if ts[i] > t
      times[j][i+1] = vs[i] - (t - ts[i])
    elsif ts[i] <= t && t <= ts[i+1]
      times[j][i+1] = vs[i]
    else
      times[j][i+1] = vs[i] + (t - ts[i+1])
    end
  end
end

mins = times.map{ |ts| ts.min }

puts mins.each_cons(2).map{ |p, q| 0.5 * (p + q) / 2 }.reduce(:+)


Measured memory_bytes: 38964
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 200005
using namespace std;

int n,t,x,y,cnt,tot,fac[N],inv[N],ans,mn[N],a[N],b[N],c[N],sz[N],sum[N],m,mm;
int main(){
	scanf("%d%d%d",&n,&x,&y);
	int i;
	memset(mn,60,sizeof(mn));
	for (i=1,m=mm=1010000000; i<=n; i++){
		scanf("%d%d",&a[i],&b[i]);
		mn[a[i]]=min(mn[a[i]],b[i]);
		if (b[i]<m){
			m=b[i]; t=a[i];
		}
	}
	for (i=1; i<=n; i++) if (a[i]!=t && b[i]<mm) mm=b[i];
	for (i=1; i<=n; i++) if (b[i]+mn[a[i]]<=x) sz[a[i]]++;
	for (i=1; i<=n; i++) if (b[i]+m<=y && a[i]!=t || b[i]+mm<=y) sum[a[i]]++;
	for (i=1; i<=n; i++) if (sum[i] || i==t){
		c[++cnt]=max(sum[i],sz[i]);
		tot+=c[cnt];
	}
	fac[0]=inv[0]=inv[1]=1;
	for (i=1; i<=n; i++) fac[i]=(ll)fac[i-1]*i%mod;
	for (i=2; i<=n; i++) inv[i]=mod-(ll)inv[mod%i]*(mod/i)%mod;
	for (i=2; i<=n; i++) inv[i]=(ll)inv[i-1]*inv[i]%mod;
	for (i=ans=1; i<=cnt; i++){
		ans=(ll)ans*fac[tot]%mod*inv[c[i]]%mod*inv[tot-c[i]]%mod; tot-=c[i];
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<mint>> dp(110, vector<mint>(10,0));
  dp[0][0] = 1;
  rep(i,h)rep(j,w){
    rep(b,(1<<(w-1))){
      bool flag = false;
      rep(c,w-2)if(bit(b,c) && bit(b,(c+1))) flag=true;
      if(flag) continue;
      if(1<=j && bit(b,(j-1))){
        dp[i+1][j-1] += dp[i][j];
        continue;
      }
      if(j<=w-2 && bit(b,j)){
        dp[i+1][j+1] += dp[i][j];
        continue;
      }
      dp[i+1][j] += dp[i][j];
    }
  }
  ll ans = dp[h][k-1].x;
  cout << ans << endl;
  return 0;
}


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

int main(){
    
    int N;
    cin >> N;
    int P[N];
    for(int i = 0; i < N;i++)cin >> P[i];
    
    int a = P[0];
    int cont = 1;
    for(int i = 1; i < N;i++){
        if(a > P[i])a = P[i],cont++;
    }
    cout << cont << endl;
}


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

/*
詰めるのは最後で良い
左の個数、右の個数で総当たり
*/

ll n,k,v[60],ru[60],ans=0;

void init(){
	cin>>n>>k;
	reg(i,1,n)cin>>v[i];
}

int main(void){
	init();
	reg(i,0,k){
		reg(j,0,k-i){
			if(i>=n-j+1)continue;
			ll sum=0;
			vector<ll> a;
			reg(l,1,i){
				a.push_back(v[l]);
				sum+=v[l];
			}
			reg(l,n-j+1,n){
				a.push_back(v[l]);
				sum+=v[l];
			}
			sort(a.begin(),a.end());
			rep(l,k-i-j){
				if(l>=a.size())break;
				if(a[l]>=0)break;
				sum-=a[l];
			}
			ans=max(ans,sum);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#define ll long long
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ll n = 753,x,mn=1e9,dif;

    string s;
    cin>>s;

    for(int i=0;i<s.size()-2;i++)
    {
        ll p=1,num=0;
        for(int j=i+2;j>=i;j--)
        {
            x = (s[j]-'1')+1;
            num+=(p*x);
            p*=10;
        }
        dif = abs(num-n);
        mn=min(mn,dif);
    }

    cout<<mn<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,k;
	cin>>a>>b>>k;
	if(b-a+1<=2*k)
	{
		for(int i=a;i<=b;i++)
			cout<<i<<endl;
	}
	else
	{
		for(int i=a;i<=a+k-1;i++)
			cout<<i<<endl;
		for(int i=b-k+1;i<=b;i++)
			cout<<i<<endl;
	}
  	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 N = sc.nextInt();
        int M = sc.nextInt();
        int sum = 0;
        for(int i=0;i<M;i++){
            sum += sc.nextInt();
        }
        if(N-sum >= 0){
            System.out.println(N-sum);
        }else{
            System.out.println(-1);
        }

    }

}


Measured memory_bytes: 46324
/**
 * Doubly Linked List
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=ja
 */

#include<iostream>
#include<algorithm>
#include<list>
using namespace std;

void trace(list <int>lst) {
  for (auto itr = lst.begin(); itr != lst.end(); ++itr) {
    if (itr != lst.begin()) {
      cout << ' ';
    }

    cout << *itr;
  }

  cout << endl;

  /*
  // 現在の並び替え状態を出力する
  int size = A.size();
  for (int i = 0; i < size; i++) {
    cout << A.at(i);
    if (i < size - 1) {
      cout << ' ';
    } else {
      cout << endl;
    }
  }
  */
}

int main() {
  // 入出力の高速化
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  // プロセスの格納
  list <int>lst;
  for (int i = 0; i < N; i++) {
    string command;
    cin >> command;
    int number;

    if (command == "insert") {
      cin >> number;
      lst.push_front(number);
    } else if (command == "delete") {
      cin >> number;
      for (auto itr = lst.begin(); itr != lst.end(); ++itr) {
        if (*itr == number) {
          lst.erase(itr);
          break;
        }
      }
    } else if (command == "deleteFirst") {
      lst.pop_front();
    } else if (command == "deleteLast") {
      lst.pop_back();
    }
  }

  trace(lst);
}



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

int main(){
  string s;
  int n;
  map<string,vector<int>> list;
  while(cin>>s>>n){
    list[s].push_back(n);
  }
  for(auto &i: list){
    cout<<i.first<<endl;
    auto &list = i.second;
    sort(list.begin(),list.end());
    for(int j=0;j<list.size()-1;j++){
      cout<<list[j]<<" ";
    }cout<<list[list.size()-1]<<endl;
  }
}

Measured memory_bytes: 1240
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> v(n), c(n), z(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        z[i] = v[i] - c[i];
    }

    Int ans = 0;
    for (int i = ((1 << n) - 1); i >= 0; --i) {
        Int tem = 0;
        int k = i;
        for (int index = 0; index < n; index++) {
            if (k & 1) {
                tem += z[index];
            }
            k = k >> 1;
        }
        ans = max(ans, tem);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
var f:array[0..2000,0..2000] of int64;
    a:array[1..2000] of int64;
    n,i,j:longint;
    tot,minn,x:int64;
function left(k:longint):longint;
begin
  exit(((k-2+n) mod n)+1);
end;
function min(a,b:int64):int64;
begin
  if a<b then exit(a);
  exit(b);
end;
begin
  minn:=100000000000000000;
  readln(n,x);
  for i:=1 to n do read(a[i]);
  for i:=1 to n do f[i,0]:=a[i];
  for j:=1 to n-1 do
    for i:=1 to n do
      f[i,j]:=min(f[i,j-1],f[left(i),j-1]);
  for i:=0 to n-1 do
  begin
    tot:=x*i;
    for j:=1 to n do tot:=tot+f[j,i];
    if tot<minn then minn:=tot;
  end;
  writeln(minn);
end.

Measured memory_bytes: 31360
n, a = gets.to_s.split.map{|t|t.to_i}
x    = gets.to_s.split.map{|t|t.to_i - a}.sort.reverse

h = Hash.new(0)
h[0] = 1
x.each do |t|
  s = h.dup
  h.each do |(k,v)|
    next if k+t < 0
    s[k+t] += v
  end
  h = s.dup
end

puts h[0] - 1

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

const int MAX = 100;

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

    double revres = 0;
    rep(i,n){
        cin >> a;
        revres += 1.0 / a;
    }
    printf("%lf\n", 1.0 / revres);
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <map>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <string>
#include <limits.h>

#define MAXN 100001

using namespace std;


bool spe[MAXN];
int lng[MAXN];

int pare(int n){
    if (lng[n] == n) {
        return n;
    }else{
        return pare(lng[n]);
    }
}

int main(){
    
    int n;
    cin >> n;
    int m;
    cin >> m;
    
    for (int i = 1; i <= m; i++) {
        spe[i] = false;
        lng[i] = i;
    }
    
    int sp = 0;
    
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        int base;
        cin >> base;
        spe[base] = true;
        sp = base;
        for(int j = 1; j < k; j++){
            int l;
            cin >> l;
            lng[pare(l)] = lng[pare(base)];
            spe[l] = true;
        }
    }
    
    int root = pare(sp);
    
    for (int i = 1; i <= m; i++) {
        if (spe[i] && root != pare(i)) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" <<endl;
    
    return 0;
}


Measured memory_bytes: 768
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))


;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))
(defmacro aif (test-form then-form &optional else-form)
  `(let ((it ,test-form))
     (if it ,then-form ,else-form)))

;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

(defmacro defchangef (name op default-val)
  `(defmacro ,name (var &optional (val ,default-val))
     `(setq ,var (,',op ,val ,var))))
(defmacro read-str ()
  `(write-to-string (read)))

;;本体
(defconstant *mod* 1000000007)
(defvar n (read))
(defvar m (read))
(defvar fib
  (make-array (1+ n)))

(vref fib 0 1)
(vref fib 1 1)
(loop for i from 2 to n
   do (vref fib i (+ (vref fib (1- i))
                     (vref fib (- i 2)))))
(vref fib 1 1)


(defun main ()
  (let ((ans 1) (pos 0) next)
    (dotimes (i m)
      (setf next (1- (read)))
      (if (= (- next (- pos 2)) 1)
          (setf ans 0)
          (setf ans (mod (* ans (vref fib (- next pos))) *mod*)))
      (setf pos (+ 2 next)))
    (setf ans (mod (* ans (vref fib (- n pos))) *mod*))
    (println ans)))

#-swank(main)


Measured memory_bytes: 948808
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int main(){
    set<ll>set1;
	std::vector<ll> arr,arr1;
	ll freq[200001],freq1[200001];
	memset(freq,0,sizeof(freq));
	memset(freq1,0,sizeof(freq1));
	ll n,a,k=0,sum1=0,sum=0,h;
	cin>>n;
	f(i,0,n){
		cin>>a;arr.pb(a);
		set1.insert(a);
		freq[a]++;
	}
	for(auto it=set1.begin();it!=set1.end();it++){
	    h=(freq[*it])*(freq[*it]-1)/2;
	    sum1+=h;
	}
	for(int i=0;i<n;i++){
		if(i==k){
			if(freq[arr[i]]!=0){
				sum=sum1-(freq[arr[i]]-1);
				arr1.pb(sum);
			}
		}
		k++;
	}
	
	for(int i=0;i<arr1.size();i++){
		cout<<arr1[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 15344
from collections import defaultdict
import sys
sys.setrecursionlimit(10**5)
def solve():
    N = int(input())
    G = defaultdict(list)
    for i in range(N-1):
        u,v,w = map(int,input().split())
        u -= 1
        v -= 1
        G[u].append((v,w))
        G[v].append((u,w))

    res = [0] * N
    dfs(0,-1,1,G,res)

    print(*res,sep='\n')

def dfs(v,p,c,G,res):
    res[v] = c

    for e in G[v]:
        if e[0] == p:
            continue
        if e[1] % 2 == 0:
            dfs(e[0],v,c,G,res)
        else:
            dfs(e[0],v,1-c,G,res)
        
if __name__ == '__main__':
    solve()

Measured memory_bytes: 154840
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	vector<int> B(M);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}
	vector<vector<int> > dp(N + 1, vector<int>(M + 1, 0));
    //dp[i][j]表示由s的前i个组成的子序列和由t的前j个组成的子序列之间的公共子序列的个数

	for (int i = 0; i <= N; i++)
    {
		dp[i][0] = 1;//都包含空的一个
	}
	for (int i = 0; i <= M; i++)
    {
		dp[0][i] = 1;
	}

	for (int i = 1; i <= N; i++)
    {
		for (int j = 1; j <= M; j++)
        {
			dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			if (A[i - 1] != B[j - 1])
			{
				dp[i][j] -= dp[i - 1][j - 1];
			}
			dp[i][j] = (dp[i][j] + 10 * MOD) % MOD;
		}
	}
	cout << dp[N][M] << endl;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	int n=0;
	cin>>s>>t;
	rep(i,3)if(s[i]==t[i])n++;
	puta(n);
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int cnt;cnt=0;
    int val;
    REP(i,N){
        cin>>val;
        if(val!=i+1){
            cnt++;
        }
    }
    if(cnt==0||cnt==2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [str(input()) for _ in range(N)]

S.sort()

ans = []
most = 0
tmpstr = S[0]
tmpcnt = 0


for s in S:
    if tmpstr == s:
        tmpcnt += 1
    else:
        if tmpcnt > most:
            ans.clear()
            ans.append(tmpstr)
            most = tmpcnt

        elif tmpcnt == most:
            ans.append(tmpstr)

        tmpcnt = 1
        tmpstr = s

if tmpcnt > most:
    ans.clear()
    ans.append(tmpstr)
    most = tmpcnt
elif tmpcnt == most:
    ans.append(tmpstr)

for a in ans:
    print(a)


Measured memory_bytes: 20680
#include<stdio.h>
#include <stdlib.h>

int main()
{
    int h, w, sum=0, min=1000000;
    double p = 3.1415;
    int max = 1-1000001;

    
    while (1){
        scanf("%d%d", &h, &w);
        if(h==0 && w==0){
            break;
        }
        else {
            for (int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    if ( i==0 || i == h-1 ){
                    printf("#");
                    }else {
                        if(j==0 || j == w-1){
                            printf("#");
                        }else{
                            printf(".");
                        }        
                    }
                }
                printf("\n");
            }
            printf("\n");
        }
    }
        return 0;
}           


Measured memory_bytes: 1980
#pragma GCC target ("avx")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")

#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

const ll INF = 100'000'000'000'000'000LL;

int N, K;
ll H[300];
vector<ll> v;

ll dp[301][301][302];
ll rmq1[301][301][302], rmq2[301][301][302];

signed main(){
    cin >> N >> K;
    rep(i, N){
        cin >> H[i];
        v.pb(H[i]);
    }
    v.pb(0);
    sort(all(v));

    for(int n=N; n>=0; n--){
        for(int k=0; k<=K; k++){
            for(int i=0; i<v.size(); i++){
                if(n == N) dp[n][k][i] = v[i];
                else{
                    dp[n][k][i] = dp[n+1][k][lower_bound(all(v), H[n])-v.begin()] + abs(H[n]-v[i]);
                    if(k > 0){
                        dp[n][k][i] = min(dp[n][k][i], rmq1[n+1][k-1][i] + v[i]);
                        dp[n][k][i] = min(dp[n][k][i], rmq2[n+1][k-1][i] - v[i]);
                    }
                }
            }
            for(int i=0; i<v.size(); i++){
                rmq1[n][k][i] = min((i == 0 ? INF : rmq1[n][k][i-1]), dp[n][k][i]-v[i]);
            }
            for(int i=v.size()-1; i>=0; i--){
                rmq2[n][k][i] = min((i == v.size()-1 ? INF : rmq2[n][k][i+1]), dp[n][k][i]+v[i]);
            }
        }
    }

    cout << dp[0][K][0] / 2LL << endl;
}

Measured memory_bytes: 641536
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

void decitobinbitodeci()
{
    string binary = bitset<8>(128).to_string(); //to binary
    cout<<binary<<"\n";

    unsigned long decimal = bitset<8>(binary).to_ulong();
    cout<<decimal<<"\n";
}

int getnum(string a)
{
    int i,p=0;
    rep0(i,a.size())
    {
        p*=10;
        p+=a[i]-'0';
    }
    return p;
}

/*
1.always remember for ncr(n,2), you can calculate by
n*(n-1)/2
2.Power of 2 ->  (1ll<<i)
*/

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a;
    cin>>a;
    ll b=100, c=0;
    while(true)
    {
        ll sum=b/100;
        b+=sum;
        c++;
        if(a==100)
        {
            cout<<0<<endl;
            return 0;
        }
        if(b>=a)
        {
            cout<<c<<endl;
            return 0;
        }
    }
}


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

#define infi            5e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)

using namespace std;

inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}

// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//

// vector<pll>vec[30005];
// ll ans;

// ll DFS(int u, int v){
//     ll cur,prev=0;

//     loop(i,vec[v].size()){
//         if(vec[v][i].ff!=u){
//             cur = DFS(v, vec[v][i].ff)+vec[v][i].ss;
//             ans = max(ans, cur+prev);
//             prev = max(prev, cur);
//         }
//     }
//     return prev;
// }


ll solve(string str, ll n){
    if(str=="")return n;
    ll ans=0;
    loop1(i,str.length()){
        ans+=solve(str.substr(i), n+stoll(str.substr(0,i)));
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle//freopen("in.txt", "r", stdin);//#endif
    //freopen("in.txt", "r", stdin);

    // int tt=rr;
    // int x,y,n;
    // ll w;
    // loop1(t,tt){
    
    string str;
    cin >> str;
    cout << solve(str, 0) << endl;
    
    // }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define debug(x) cerr << #x << ": " << x << "\n"
#define debugv(x) cerr << #x << ": \n" << rep(i,)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for (int i=(a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
#define INF 1e9

#define mod 1000000007
int i, j, k, l, m;
int N, M, K,X;
int dp[100005][2];
int ans;
signed main()
{
    cin >> N>>X;
    vector<int> L(N);
    rep(i,N)cin>>L[i];

    vector<int> D(N*2);
    D[0] = 0;
    ans = 1;
    for(int i = 1; i <= N; i++){
        D[i] = D[i-1] + L[i-1];
        //debug(D[i]);
        if (D[i] <= X)
            ans ++;
        //debug(ans);
    }




    cout<<ans<<endl;
    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 PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 998244353;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin>>N;
    int D[N];
    map<int,int> m;
    int dm=0;
    rep(i,N) {
        cin>>D[i];
        D[i];
        m[D[i]]++;
        dm=max(dm,D[i]);
    }
    int ans=1;
    int x=1;
    if(D[0]!=0) ans=0;
    rep(i,dm+1){
        if(i==0) {
            if(m[i]!=1) ans=0;
        }else{
            int y=m[i];
            rep(j,y){
                ans=(ans*x)%MOD;
            }
        }
        x=m[i];

    }
    cout << ans << endl;
    




}


Measured memory_bytes: 7296
#include<stdio.h>
#include<utility>
#include<algorithm>
using namespace std;
pair<int, int> a[100005];
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i) scanf("%d %d", &a[i].first, &a[i].second);
	sort(a, a + m);
	int ans = 1, t = a[0].second;
	for (int i = 1; i < m; ++i){
		if (a[i].first < t) t = min(t, a[i].second);
		else ++ans, t = a[i].second;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024