akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	string s;
	cin >> s;
	if(cin.eof()) break;
	int ans = 0;
	int ans1 = 0;
	REP(i,s.size()-2){
	    string temp = s.substr(i,3);
	    if(temp == "JOI") ans++; 
	    if(temp == "IOI") ans1++; 
	}
	cout << ans << endl;
	cout << ans1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3164
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  ll unit = 0; // In each step, sum is decreased by unit. sum of [1, N]
  rep(i, N) {
    unit += i + 1;
  }
  ll s = 0;
  rep(i, N) {
    s += A[i];
  }
  if ((s % unit) != 0) {
    cout << "NO" << endl;
    return 0;
  }

  // Now, s is dividable by unit.
  ll cnt = s / unit;

  vector<ll> diff(N); // diff[i] = A[i] - A[i-1].
  rep(i, N) {
    diff[i] = A[i]-A[(i-1+N)%N];
  }
  // For Debug
  // cout << "diff:" << endl;
  // rep(i, N) {
  //   cout << diff[i] << " ";
  // }
  // cout << endl;

  // Now, diff[i] must be cnt + (-N)*k (k=0, 1, 2, ...)
  rep(i, N) {
    diff[i] -= cnt;
  }
  // cout << "diff:" << endl;
  // rep(i, N) {
  //   cout << diff[i] << " ";
  // }
  // cout << endl;

  // Now, diff[i] must be (-N)*k (k=0, 1, 2, ...)

  // Check if diff[i] is dividable by N.
  // Check if diff[i] <= 0.
  // Check if the summention of diff[i]/N is same with cnt.
  ll n_cnt = 0;
  rep(i, N) {
    if ((diff[i] % N) != 0) {
      cout << "NO" << endl;
      return 0;
    }
    if (diff[i] > 0) {
      cout << "NO" << endl;
      return 0;
    }
    n_cnt -= diff[i] / N; // diff[i] <= 0, so we use -=.
  }
  if (n_cnt != cnt) {
    cout << "NO" << endl;
    return 0;
  }

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


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

char S[123456];

int main() {

	scanf("%s", S);

	for (int i = 0; S[i]; ++i) {
		if (i % 2) {
			if (S[i] == 'R') {
				printf("No\n");
				return 0;
			}
		}
		else {
			if (S[i] == 'L') {
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");


	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	max := 0
	for i := 0; i < n; i++ {
		var p int
		fmt.Scan(&p)
		ans += p
		if p > max {
			max = p
		}
	}
	ans -= max / 2
	fmt.Println(ans)
}


Measured memory_bytes: 512
n, k = map(int,input().split())
a = list(map(int,input().split()))

ar = [-1 for i in range(n+1)]
ar[1] == 0
ni = 1
t = 0
while k > t:
    t += 1
    if t == k:
        print(a[ni-1])
        exit()
    elif ar[a[ni-1]] > -1:
        break
    else:
        ar[a[ni-1]] = t
        ni = a[ni-1]

mod = t-ar[a[ni-1]]
idx = ar[a[ni-1]]+((k-ar[a[ni-1]])%mod)
print(ar.index(idx))


Measured memory_bytes: 32384
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int ans=0,kell;
	kell=min(k,a);
	ans+=kell;
	k-=kell;
	kell=min(k,b);
	k-=kell;
	kell=min(k,c);
	k-=kell;
	ans-=kell;
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3660
N,k=gets.chomp.split(" ")
N_i = N.to_i
K = k.to_i
d_array=gets.chomp.split(" ").map(&:to_i)
E_array= (0..9).to_a - d_array

if 10-K == 1
    ret = E_array[0]
    while ret < N_i
        ret = ret*10 + E_array[0]
    end
    puts ret
    exit
end

# 使える数字を元にn進数を10進数にする
def to_i10(n)
    n_s = n.to_s(10-K)
    ret = 0

    start = 0
    diff = 0
    if E_array[0]!=0 && n_s.length>1
        if n_s[0]=="1" && n_s[1]=="0"
	        diff = E_array[-1] - E_array[0]
        else
            ret = E_array[n_s[0].to_i-1]
            diff = -1 if n_s.length==2 
        end
        start=1
    end

    (start..(n_s.length-1)).each do |i|
        ret = ret*10 + E_array[n_s[i].to_i] + diff
        diff = 0
    end
    ret
end

sup = (10**N.length).to_s(10-K).to_i
inf = 0
loop do
    mid = (sup + inf)/2
    if inf == mid
        puts to_i10(sup)
        break
    end

    mid_i10 = to_i10(mid)
    if mid_i10 < N_i
        inf = mid
    else
        sup = mid
    end
end


Measured memory_bytes: 14376
def get_input():
    A,B = [int(_) for _ in input().split(" ")]
    return A,B

def solve(A,B):
    return max([2*A-1,2*B-1,A+B])



if __name__ == "__main__":
    A,B = get_input()
    ans = solve(A,B)
    print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int k[];
        k = new int[6];

        for (int i = 0; i < 6; i++) {
            k[i] = scan.nextInt();
        }
        int min = 101;
        int total = 0;
        for (int i = 0; i < 4; i++) {
            if (k[i] < min) {
                min = k[i];
            }
            total += k[i];
            if (i == 3) {
                total = total - min;
            }
        }
        if (k[4] < k[5]) {
            System.out.println(total + k[5]);
        } else {
            System.out.println(total + k[4]);
        }

    }
}



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

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
/*
int main(){
  int w,h,n,x,y,a;
  cin>>w>>h>>n;
  int ans_x=w;
  int ans_y=h;
  rep(i,n){
    cin>>x>>y>>a;
    if(a==1){
      if(x>=ans_x){
        ans_x=0;
      }
      else{ans_x-=x;}
    }
    else if(a==2){
      ans_x=min(x,ans_x);
    }
    else if(a==3){
      if(y>=ans_y){
        ans_y=0;
      }
      else{ans_y-=y;}
    }
    else{
      ans_y=min(y,ans_y);
    }
  }
  int ans=ans_x*ans_y;
  cout<<max(0,ans)<<endl;
}*/
//(二次元)配列を使う方法がある。塗りつぶしなら1入れる

bool b_x[110]={},b_y[110]={};
int w,h,n;

void draw_b(int x,int y,int a){
  if(a==1){//x左塗る
    x--;
    for(int i=0;i<=x;i++){
      b_x[i]=true;
    }
  }
  if(a==2){//x右塗る
    for(int i=x;i<=w;i++){
      b_x[i]=true;
    }
  }
  if(a==3){//y下塗る
    y--;
    for(int i=0;i<=y;i++){
      b_y[i]=true;
    }
  }
  if(a==4){//y上塗る
    for(int i=y;i<=h;i++){
      b_y[i]=true;
    }
  }
}

int main(){
  int x,y,a,ans=0;
  cin>>w>>h>>n;
  int cnt=0;
  while(cnt<n){
    cin>>x>>y>>a;
    draw_b(x,y,a);
    cnt++;
  }
  int ans_x=0,ans_y=0;
  rep(i,w){
    if(b_x[i]==0){
      ans_x++;
    }
  }
  rep(i,h){
    if(b_y[i]==0){
      ans_y++;
    }
  }
  ans=ans_x*ans_y;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int INF2 = 1e15;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<int>a(N);
    int ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        if(i%2 == 0 && a[i]%2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
int main(void) {
   int A, B, C;
   scanf("%d%d%d", &A, &B, &C);
   if((A == B && B == C) || (A != B && B != C && C != A)) {
      printf("No\n");
   } else {
      printf("Yes\n");
   }
   return 0;
}


Measured memory_bytes: 1624
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	s := getString()

	ans := 0
	switch s {
	case "SUN":
		ans = 7
	case "MON":
		ans = 6
	case "TUE":
		ans = 5
	case "WED":
		ans = 4
	case "THU":
		ans = 3
	case "FRI":
		ans = 2
	case "SAT":
		ans = 1
	}
	out(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
const int N = 16;
const int M = 1e3 + 5;
const int Mod = 998244353;

struct Base
{
    int m;
    vector <ll> A;

    Base(int m = 0) : m(m)
    {
        A.assign(max(m, 1), 0);
    }

    void insert(ll x)
    {
        for (ll i = m - 1; ~i; --i)
        {
            if (x & (1LL << i))
            {
                if (A[i])
                {
                    x ^= A[i];
                }

                else
                {
                    A[i] = x;
                    break;
                }
            }
        }
    }

    vector <ll> Get()
    {
        vector <ll> Res;

        for (int i = 0; i < m; i++)
            if (A[i])
                Res.push_back(A[i]);

        return Res;
    }
};

int main()
{
    GO;
    int n;
    cin >> n;
    ll XOR = 0;
    vec a(n);
    for (auto& i : a)
        cin >> i, XOR ^= i;
    ll sum = XOR;
    for (auto& i : a)
        i &= ~XOR;
    Base b(60);
    for (auto i : a)
        b.insert(i);
    XOR = (1LL << 60) - 1 - XOR;
    ll temp = XOR;
    for(int i=59;i>=0;i--)
        if (XOR & 1LL << i)
        {
            if (temp & 1LL << i)
                temp ^= b.A[i];
            if (~temp & 1LL << i)
                sum += 2LL << i;
        }
    cout << sum<< endl;
    return 0;
}

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

typedef long long LL;
const LL mod = 1e9+7;
const int maxn = 2e5+3;

LL fac[maxn], inv[maxn];
int cnt, n, x, y, co[maxn], va[maxn], vis[maxn]={0}, ge[maxn]={0};
vector<int>v[maxn], tmp;
vector<pair<int, int> >r[maxn];
vector<pair<int, int> >p;

void dfs(int u)
{
    vis[u] = 1;
    ++cnt, ++ge[co[u]], tmp.push_back(co[u]);
    for(int i=0; i<v[u].size(); ++i)
    {
        int e = v[u][i];
        if(vis[e]) continue;
        dfs(e);
    }
}
int main()
{
    int c, w;
    scanf("%d%d%d",&n,&x,&y);
    cnt = 0;
    fac[0] = fac[1] = inv[0] = inv[1] = 1;
    for(LL i=2; i<=n; ++i)
    {
        fac[i] = fac[i-1]*i%mod;
        inv[i] = (mod-mod/i)*inv[mod%i]%mod;
    }
    for(int i=2; i<=n; ++i)
        inv[i] = inv[i-1]*inv[i]%mod;
    for(int i=1; i<=n; ++i)
    {
        scanf("%d%d",&c,&w);
        co[i] = c, va[i] = w;
        r[c].push_back(make_pair(w, i));
    }
    for(int i=1; i<=n; ++i)
    {
        if(r[i].size())
        {
            sort(r[i].begin(), r[i].end());
            p.push_back(r[i][0]);
            for(int j=1; j<r[i].size(); ++j)
                if(r[i][j].first+r[i][0].first <= x)
                    v[r[i][0].second].push_back(r[i][j].second),
                    v[r[i][j].second].push_back(r[i][0].second);
        }
    }
    sort(p.begin(), p.end());
    if(p.size())
    {
        int id = p[0].second;
        for(int i=1; i<=n; ++i)
        {
            if(co[i]==co[id] || va[i]+va[id]>y) continue;
            v[id].push_back(i), v[i].push_back(id);
        }
    }
    if(p.size()>1)
    {
        int id = p[1].second, imin = co[p[0].second];
        for(auto it = r[imin].begin(); it!=r[imin].end(); ++it)
            if(it->first + va[id]<=y)
                v[it->second].push_back(id), v[id].push_back(it->second);
    }
    dfs(p[0].second);
    LL ans = fac[cnt];
    for(int i=0; i<tmp.size(); ++i)
    {
        int num = ge[tmp[i]];
        ans = (ans*inv[num])%mod;
        ge[tmp[i]] = 0;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 29300
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
long counter = 1;

long monster(long H) {
	if (H == 1) {
		++counter;
		cout << "終わり" << endl;
		return 0;
	}
	else if(H>1) {
		if (H % 2 == 0) {//偶数
			++counter;
			cout << "偶数" << endl;
			cout << H << endl;

			return monster(H / 2);
		}
		else {//奇数
			counter += 2;
			cout << "奇数" << endl;
			cout << (H - 1)<<endl;
			return monster((H - 1) / 2);
		}

	}
}

int main() {
	long long H;
	long long ans;
	int i, j;
	int power=0;
	cin >> H;
	while (H > 1) {
		++power;
		H /= 2;
	}
	ans=pow(2, power+1);
	cout <<ans-1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 11
using namespace std;
int  n,m,x,y,ans,a[N],f[N][N],v[N];
int pd()
{
	for(int i=1;i<n;i++)if(!f[a[i]][a[i+1]])return 0;
	return 1;
}
void so(int x)
{
	if(x>n)ans+=pd();
	for(int i=2;i<=n;i++)if(!v[i]){
		a[x]=i;v[i]=1;
		so(x+1);v[i]=0;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d%d",&x,&y),f[x][y]=f[y][x]=1;
	a[1]=1;so(2);printf("%d",ans);
}

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

int main(void){
  string a,b;
  cin >> a>> b;
  string c = a+b;
  
  int p = stoi(c);

  for(int i = 0;i < 100100;i++){
    if(i*i == p){
      cout << "Yes" <<endl;
      return 0;
    }
  }
  cout << "No" <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

void swap(int *x, int *y){
    int c;
    c=*x;
    *x=*y;
    *y=c;
}

void Newton(int data[10][5], int H, int c)
{
    int i,j;
    for(i=0;i<H-1;i++)
    {
        for(j=0;j<H-1;j++)
        {
            if(data[j+1][c] == 0)
            {   // small -> large
                swap(&data[j][c], &data[j+1][c]);
            }
        }
    }
}

void print(int data[10][5], int H)
{
    int i, j;

    for(i = 0;i < H;++i)
    {
        for(j = 0;j < 5;++j)
        {
            printf("%d", data[i][j]);
        }
        printf("\n");
    }
    printf("\n");
}

int main()
{
    int H;
    int i, j, k;
    int disk[10][5], pt;
    int flag, flag1, l, r;

    while(scanf("%d", &H) == 1 && H)
    {
        memset(disk, -1, sizeof(disk));
        pt = 0;

        for(i = 0;i < H;++i)
        {
            for(j = 0;j < 5;++j)
            {
                scanf("%d", &disk[i][j]);
            }
        }

        while(1)
        {
            flag = 1;

            for(i = 0;i < H;++i) // 行ごとに連続の検出
            {
                l = 0;
                r = 0;
                flag1 = 0;

                for(j = 0;j < 4;++j)
                {
                    if(disk[i][j] == 0)
                    {
                        l = j + 1;
                        r = j + 1;
                    }
                    else if(disk[i][j] == disk[i][j+1] && !flag1)
                    {
                        r = j + 1;
                    }
                    else if(disk[i][j] != disk[i][j+1])
                    {
                        if(r - l > 1)
                        {
                            flag1 = 1;
                        }
                        else{
                            l = j + 1;
                            r = j + 1;
                        }
                    }
                }

                if(r - l > 1)
                {
                    for(k = l;k <= r;++k)
                    {
                        pt += disk[i][k];
                        disk[i][k] = 0;
                    }

                    flag = 0;
                }

//                print(disk, H);

            }

            for(j = 0;j < 5;++j) // ニュートンを呼んで盤面を整理する
            {
                Newton(disk, H, j);
            }

//            print(disk, H);

            if(flag)
            {
                printf("%d\n", pt);
                break;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using P = pair<string, string>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  map<P, int> mp1, mp2;
  for (int i = 0; i < 1 << n; i++) {
    string t1, t2;
    for (int j = 0; j < n; j++) {
      if (i & 1 << j) t1 += s[j];
      else t2 += s[j];
    }
    mp1[P(t1, t2)]++;
  }
  for (int i = 0; i < 1 << n; i++) {
    string t1, t2;
    for (int j = 0; j < n; j++) {
      if (i & 1 << j) t1 += s[2 * n - 1 - j];
      else t2 += s[2 * n - 1 - j];
    }
    mp2[P(t1, t2)]++;
  }
  
  auto itr1 = mp1.begin(), itr2 = mp2.begin();
  lint res = 0;
  while (itr1 != mp1.end() and itr2 != mp2.end()) {
    if (itr1->first == itr2->first) {
      res += (lint) itr1->second * itr2->second;
      itr1++, itr2++;
    } else if (itr1->first < itr2->first) {
      itr1++;
    } else {
      itr2++;
    }
  }
  cout << res << '\n';
  return 0;
}

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

int main(){
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	ll ans = A*X + B*Y;
	rep(i,2*max(X,Y)+1) {
		int na = max(X-i/2, 0);
		int nb = max(Y-i/2, 0);
		ll comb = C*i + A*na + B*nb;
		ans = min(ans,comb);
	}
	cout << ans << endl;

	return 0;
}


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

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

    int l = to_string(N).length();
    int a = 0, b = 0, x = 0;

    for (int i = 0; i < l; i++)
    {
        a = (N - b) / pow(10, (l - i - 1));
        b += a * pow(10, (l - i - 1));
        x += a;
    }

    if (N % x == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{int F;
cin>>F;
int a=F/100;
int b=F-(a*100);
if(a>=1 && a<=12 && (b>12 || b==0))
  {cout<<"MMYY";
  }
if(b>=1 && b<=12 && (a>12 || a==0))
  {cout<<"YYMM";
  }
if(a>=1 && a<=12 && b>=1 && b<=12)
  {cout<<"AMBIGUOUS";
  }
if((a>12 || a==0) && (b>12 || b==0))
  cout<<"NA";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h> 
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,m;
	cin>>n>>m;
	if(n==m){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	// your code goes here
	return 0;
}

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

int main()
{
    int i=0, j, k,a,b,c=1;
    char s[4],t[4];
    scanf("%d %d", &a,&b);
    while (c<b)
    {
        c += a - 1;
        i++;
    }
    printf("%d",i);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Arrays;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++)
		{
			char num[] = sc.next().toCharArray();
			Arrays.sort(num);
			String str = new String(num);
			Scanner minNumSc = new Scanner(str);
			int min = minNumSc.nextInt();
			Scanner maxNumSc = new Scanner((new StringBuffer(str).reverse()).toString());
			int max = maxNumSc.nextInt();
			System.out.println(max - min);
		}
	}
}

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll n;
  string s;
  cin >> n >> s;
  vector<pair<char, int>> vec;
  vec.emplace_back(s[0], 0);
  rep(i, s.size()) {
    if (vec.back().first == s[i]) {
      vec.back().second++;
    } else {
      vec.emplace_back(s[i], 1);
    }
  }
  cout << vec.size() << endl;
  return 0;
}


Measured memory_bytes: 4412
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	let x = parseInt(args[0][0], 10)
	const a = parseInt(args[1][0], 10)
	const b = parseInt(args[2][0], 10)
	x -= a
	x -= b * Math.floor(x / b)
	console.log(x)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
def main():
    import math

    H = int(input())
    if H == 1:
        print(1)
    else:
        count = int(math.log(H, 2))
        ans = 0
        for i in range(count+1):
            ans += 2 ** (i)
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
def htemp(t, x):
    return float(t - 0.006 * x)
    
input()
lt, la = [int(x) for x in input().split()]
h_ary = [int(x) for x in input().split()]
    
maxdiff = float('inf')
goodpoint = 0
for i, h in enumerate(h_ary):
    diff = abs(la - htemp(lt, h))
    if diff < maxdiff:
        maxdiff = diff
        goodpoint = i
print(goodpoint+1)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var a = Read();
            var b = Read();
            var c = Read();
            Println($"{a[0]}{b[1]}{c[2]}");
        }


        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 11092
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

using namespace std;


int main(void) {
	int n;
	cin >> n;
	cout << n * n << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int max(int x,int y);
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	printf("%d",max(a,b));
}
int max(int x,int y)
{
	if(2*x-1>x+y){
		if(2*x-1>2*y-1){
			return(2*x-1);
		}else{
			return(2*y-1);
		}
	}else{
		if(x+y>2*y-1){
			return(x+y);
		}else{
			return(2*y-1);
		}
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll N;
	cin >> N;
	vector<ll> C(N + 1), S(N + 1), F(N + 1);
	repn(i, N - 1) cin >> C[i] >> S[i] >> F[i];

	repn(i, N - 1) {
		ll t = 0;

		for (int j = i; j < N; j++) {
			t = max(t, S[j]);
			if (t%F[j] != 0) { t += (F[j] - t % F[j]); }
			t += C[j];
			//cout << t << " ";
		}

		cout << t << endl;
	}

	cout << 0 << endl;

	system("PAUSE");

	

}


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

int main() {
  string S;
  cin >> S;
  int size;
  size=S.size();
  if(S.at(size-1)=='s') {
    cout << S << "es" << endl;
  } else {
    cout << S << "s" << endl;
  }
}

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

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N;
    cin>>N;
    string s = to_string(N);
    int M=0;
    for(auto &it:s)M+=(it-'0');
    if(N%M==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
	ll k,n;
    cin >>k >> n;
    vector<ll> v(n);
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        if(i==n-1)
        {
            if(ans<k-v[i]+v[0])
            ans=k-v[i]+v[0];
        }
        else
        {
            if(ans<v[i+1]-v[i])
            ans=v[i+1]-v[i];
        }
    }
	cout << k-ans << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

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

using namespace std;

const int N = 200100;
vector <int> g[N];
vector <int> a;

void compress(vector <int> &a) {
	vector <int> b = a;
	sort(b.begin(), b.end());
	b.resize(unique(b.begin(), b.end()) - b.begin());
	map <int, int> match;
	for (int i = 0; i < (int)b.size(); i++) {
		match[b[i]] = i;
	}
	for (int i = 0; i < (int)a.size(); i++) {
		a[i] = match[a[i]];
	}
}

vector <vector <pair <int, int>>> mem;
int inc[N];

void update(int p, int x) {
	mem.push_back({});
	for (; p < N; p = (p | (p + 1))) {
		mem.back().emplace_back(p, inc[p]);
		inc[p] = max(inc[p], x);
	}
}

int get(int p) {
	int res = 0;
	for (;p >= 0; p = (p & (p + 1)) - 1) {
		res = max(res, inc[p]);
	}
	return res;
}

void back() { 
	for (auto t : mem.back()) {
		int p = t.first;
		int val = t.second;
		inc[p] = val;
	}
	mem.pop_back();
}

int ans[N];

void dfs(int v, int p) {
	ans[v] = get(a[v] - 1) + 1;
	update(a[v], ans[v]);
	ans[v] = max(ans[v], get(N - 1));
	for (auto u : g[v]) {
		if (u == p) {
			continue;
		}
		dfs(u, v);
	}
	back();
}

int main() {
	int n;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	compress(a);
	
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	dfs(0, -1);
	
	for (int v = 0; v < n; v++) {
		cout << ans[v] << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 54584
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
    int N,M;
    cin>>N>>M;
    
    ll H[N],ma[N];
    int A,B;
    int count=0;

    for(int i=0;i!=N;++i){
        cin>>H[i];
        ma[i]=0;
    }
    for(int i=0;i!=M;++i){
        cin>>A>>B;
        
        ma[A-1]=max(ma[A-1],H[B-1]);
       
        ma[B-1]=max(H[A-1],ma[B-1]);
        //cout<<"ma["<<A-1<<"]:"<<ma[A-1]<<endl;
        //cout<<"ma["<<B-1<<"]:"<<ma[B-1]<<endl;
        /*for(int j=0;j!=N;++j){
            cout<<"H["<<j<<"]:"<<H[j];
            if(j!=N-1){
                cout<<" ";
            }else{
                cout<<endl;
            }
        }*/
        /*for(int j=0;j!=N;++j){
            cout<<"ma["<<j<<"]:"<<ma[j];
            if(j!=N-1){
                cout<<" ";
            }else{
                cout<<endl;
            }
        }*/
    }
    
    
    
    for(int i=0;i!=N;++i){
         //cout<<"H["<<i<<"]:"<<H[i]<<" ma["<<i<<"]:"<<ma[i]<<endl;
        if(H[i]>ma[i]){
           
            ++count;
        }
    }
    cout<<count<<endl;
}


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

int main() {
  int n, k, i, num;
  cin >> n;
  cin >> k;
  i = 0;
  num = 1;
  for (i = 0; i < n; ++i) {
    if (num < k) {
      num *= 2;
    } else {
      break;
    }
  }
  cout << num + k*(n-i) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(void)
{
    while (1){
        int n, m;
        pair < int , int > data[100];
        scanf("%d %d", &n, &m);
        if ((n == 0) && (m == 0)) break;
        
        for (int i = 0; i < 100; i++){
            data[i].first = 0;
            data[i].second = i + 1;
        }
        
        int tmp;
        for (int i = 0; i < n; i++){
            for (int j = 0; j < m; j++){
                scanf(" %d", &tmp);
                if (tmp == 1) data[j].first++;
            }
        }
        
        /*
        for (int i = 0; i < m; i++){
            printf("%d >> %d\n", data[i].second, data[i].first);
        }
        */
        
        for (int i = 0; i < m; i++){
            for (int j = (m - 1); i < j; j--){
                if (data[j - 1].first < data[j].first){
                    swap(data[j], data[j - 1]);
                }
            }
        }
        
        /*
        printf("\n");
        for (int i = 0; i < m; i++){
            printf("%d >> %d\n", data[i].second, data[i].first);
        }
        */
        
        for (int i = 0; i < m; i++){
            printf("%d", data[i].second);
            if ((i + 1) != m) printf(" ");
        }
        printf("\n");
    }
    
    
    
    return (0);
}

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

using namespace std;

const double PI = 3.141592653589793238463;

struct point
{
    double x;
    double y;
};

double dist(point p, point q)
{
    return sqrt((p.x - q.x)*(p.x - q.x) + (p.y - q.y)*(p.y - q.y));
}

int main()
{
    int a, b, h, m;

    cin >> a >> b >> h >> m;

    point hour;
    point minute;

    hour.x = 0.0;
    hour.y = (double)a;

    minute.x = 0.0;
    minute.y = (double)b;

    double w;

    w = PI / 30.0;
    minute.x = b*sin(w*m);
    minute.y = b*cos(w*m);
    
    w = PI / 360.0;
    hour.x = a*sin(w*(60.0*h+m));
    hour.y = a*cos(w*(60.0*h+m));

    cout << fixed << setprecision(12) << dist(hour, minute) << "\n";

    return 0;
}

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

typedef long long LL;

int main(void){
	int n;
	scanf("%d", &n);
	int *p = malloc(sizeof(int) * (n + 1));
	for(int i = 0; i <= n; ++i){
		p[i] = 1;
	}
	for(int i = 2; i <= n; ++i){
		if(p[i] == 1){
			int t = 1;
			for(LL j = i; j <= n; j *= i){
				for(int k = j; k <= n; k += j){
					p[k] = p[k] / t * (t + 1);
				}
				++t;
			}
		}
	}
	LL ans = 0;
	for(int i = 1; i <= n; ++i){
		ans += (LL)p[i] * i;
	}
	printf("%lld\n", ans);
	free(p);
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    string ans = "No";
    if(a == b && b != c)ans = "Yes";
    else if(a == c && b != c)ans = "Yes";
    else if(c == b && a != c)ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	cin >> N;
	cout << (N + 1) / 2 << endl;
}


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

int main()
{
    int a,b, c,d;
    cin >> a >>b >> c >>d;
    int aa = (d+a-1)/d;
    int bb = (b+c-1)/b;

    if(bb> aa)cout <<"No\n";
    else cout <<"Yes\n";
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)
#define repit(it, t) for(__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define lb lower_bound
#define int long long
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second
#define DBG0(x) { cout << #x << ": " << x << "\t"; }
#define DBG(x) {DBG0(x); cout << endl;}
#define DBG2(x, y) {DBG0(x); DBG(y);}
#define DBG3(x, y, z) {DBG0(x); DBG2(y, z);}
#define DBG4(w, x, y, z) {DBG0(w); DBG3(x, y, z);}

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;

signed main(void){
    ios::sync_with_stdio(false);
    int a;
    cin >> a;
    set<int> s = set<int>();
    int i = 1;
    while (true) {
        if (s.find(a) != s.end()) {
            break;
        }

        i++;
        s.insert(a);
        if (a % 2) {
            a = a * 3 + 1;
        } else {
            a = a / 2;
        }
    }
    cout << i << endl;

    return 0;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
grid = []
for i in range(H):
    grid.append(input())

cnt = 0
ans = [[-1 for _ in range(W)] for _ in range(H)]
for i in range(H):

    f = -1
    for j in range(W):
        if grid[i][j] == "#":
            f = j
    if f == -1:
        continue

    first = False
    for j in range(W):
        if grid[i][j] == "#":
            if not first:
                first = True
            cnt += 1
            ans[i][j] = cnt
        else:
            if not first:
                ans[i][j] = cnt + 1
            else:
                ans[i][j] = cnt

for i in range(H):
    if ans[i][0] == -1:
        for j in range(i, H):
            if ans[j][0] != -1:
                ans[i] = ans[j]
                break

        if ans[i][0] == -1:
            for j in range(i, -1, -1):
                if ans[j][0] != -1:
                    ans[i] = ans[j]
                    break


for i in range(H):
    for j in range(W):
        print(ans[i][j], end=" ")
    print()


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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  if(A+B+C>21) cout<<"bust"<<endl;
  else cout<<"win"<<endl;
}

Measured memory_bytes: 3636
import sys

n = int(sys.stdin.readline().strip())
numbers = tuple(map(int, sys.stdin.readline().strip().split()))
kinds = set(numbers)


def answer(ans):
    print(ans)
    sys.exit()


if kinds == {0}:
    answer("Yes")

elif len(kinds) == 2:
    a, b = sorted(kinds)
    if a == 0:
        if numbers.count(a) * 3 == n:
            answer("Yes")
        else:
            answer("No")
    else:
        answer("No")

elif len(kinds) == 3:
    a, b, c = tuple(kinds)
    if (numbers.count(a) == numbers.count(b)) and (numbers.count(b) == numbers.count(c)):
        if a ^ b == c:
            answer("Yes")
        else:
            answer("No")
    else:
        answer("No")
else:
    answer("No")


Measured memory_bytes: 60784
x,k,d=map(int,input().split())
xa=abs(x)
kz=xa//d
xz=xa-kz*d

if xz*2>d:
  xzz=d-xz
  kz+=1
else:
  xzz=xz
rest=k-kz
if rest<0:
  print(xa-k*d)
elif rest%2==0:
  print(xzz)
else:
  print(d-xzz)
  

Measured memory_bytes: 8928
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define POWT(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODI 10000
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

signed main() {
	int w, h;
	while (scanf("%d %d", &w, &h)) {
		if (!w && !h)
			break;
		vector<vector<char>> mp(w, vector<char>(h, -1));
		pii cha;
		vector<pair<char, char>> homp;
		int homc = 0;
		REP(i, h) {
			REP(j, w) {
				int a = 0;
				scanf("%d", &a);
				if (a == 2) {
					cha = { j,i };
				}
				if (a == 1) {
					homp.push_back({ j,i });
					mp[j][i] = homc;
					homc++;
				}
			}
		}
		homp.push_back(cha);
		map<pair<int, char>, int> dp[2];//?±\??´????????¨??°
		dp[0][{0, homc}] = 1;
		bool t = 0;
		REP(i, homc) {
			for (auto cur : dp[t]) {
				pii curpos = homp[cur.first.second];
				int cnum;
				for (int j = curpos.second + 1; h > j; j++) {//???
					cnum = mp[curpos.first][j];
					if (cnum == -1)
						continue;
					if (!bitcheck(cur.first.first, cnum)) {
						int buf = cur.first.first; bitset(buf, cnum);
						dp[1 - t][{buf, cnum}] += cur.second;
					break;
					}
				}
				for (int j = curpos.second - 1; 0 <= j; j--) {//???
					cnum = mp[curpos.first][j];
					if (cnum == -1)
						continue;
					if (!bitcheck(cur.first.first, cnum)) {
						int buf = cur.first.first; bitset(buf, cnum);
						dp[1 - t][{buf, cnum}] += cur.second;
						break;
					}
					
				}
				for (int j = curpos.first + 1; w > j; j++) {//???
					cnum = mp[j][curpos.second];
					if (cnum == -1)
						continue;
					if (!bitcheck(cur.first.first, cnum)) {
						int buf = cur.first.first; bitset(buf, cnum);
						dp[1 - t][{buf, cnum}] += cur.second;
						break;
					}
				}
				for (int j = curpos.first - 1; 0 <= j; j--) {//???
					cnum = mp[j][curpos.second];
					if (cnum == -1)
						continue;
					if (!bitcheck(cur.first.first, cnum)) {
						int buf = cur.first.first; bitset(buf, cnum);
						dp[1 - t][{buf, cnum}] += cur.second;
					break;
					}
				}
			}
			dp[t].clear();
			t = 1 - t;
		}
		int ans = 0;

		for (auto cur : dp[t]) {
			if (homp[cur.first.second].first == cha.first || homp[cur.first.second].second == cha.second)
				ans += cur.second;
		}

		dp[1 - t].clear();
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 25768
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

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

    vector<int> ps(n);

    for (int i = 0; i < n; i++)
    {
        cin >> ps[i];
    }

    int count = 1;
    int prev_value_OK = ps[0];
    for (int i = 1; i < n; i++)
    {
        if (ps[i] == 1)
        {
            count++;
            break;
        }
        else if (ps[i] == 2 & prev_value_OK > 2)
        {
            count += 2;
            break;
        }
        if (ps[i] < prev_value_OK)
        {
            count++;
            prev_value_OK = ps[i];
            continue;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    val a = (0 until n).map { sc.next().toLong() }
    println(problem138b(n, a))
}

fun problem138b(n: Long, a: List<Long>): Double {
    var ans = 0.0
    a.forEach {
        ans += 1.0 / it
    }
    return 1.0 / ans
}

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define INF (1<<30)
#define INFLL (1L<<63)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define MAX_A 100000

int cnt[MAX_A+1];

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N; cin >> N;

  for (int i = 0; i < N; i++) {
    int A; cin >> A; cnt[A]++;
  }

  for (int i = 1; i <= MAX_A; i++) {
    if (cnt[i] == 0)
      continue;
    cnt[i] = (cnt[i] % 2 == 0) ? 2 : 1;
  }

  int one = 0, two = 0;
  for (int i = 1; i <= MAX_A; i++) {
    two += (cnt[i] == 2);
    one += (cnt[i] == 1);
  }

  while (two >= 2) {
    one += 2;
    two -= 2;
  }
  cout << one << endl;
  return 0;
}


Measured memory_bytes: 640
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():

    n = int(input())
    k = int(input())

    @lru_cache(None)
    def F(n, k):

        if n < 10:
            if 1 < k:
                return 0
            elif k == 1:
                return n
            elif k == 0:
                return 1

        m, r = divmod(n, 10)
        ret = 0
        # rに応じて場合分け
        if k >= 1:
            ret += F(m, k-1)*r  # r<=k
            ret += F(m-1, k-1)*(9-r)  # r>k
        ret += F(m, k)*1  # r==0
        return ret
    print(F(n, k))


resolve()

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

typedef long long ll;

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

    multiset<int> available;
    vector<vector<int> > v(100004);

    for (int i=0;i<n;++i){
        cin>>a>>b;
        v[a].push_back(b);
    }

    int ans = 0;
    int left = 0;
    for (int i=m-1;i>=0;i--){
        left++;
        for (auto e : v[m-i])
            available.insert(e);

        if (!available.empty()){
            ans += *prev(available.end());
            available.erase(prev(available.end()));
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

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

int main() {
    int n, m, k;
    cin >> n >> m >> k;

    vector<vector<int>> f(n, vector<int>(0));
    for (int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b; 
        f[a-1].push_back(b-1);
        f[b-1].push_back(a-1);
    }

    vector<vector<int>> b(n, vector<int>(0));
    for (int i=0; i<k; i++) {
        int c, d;
        cin >> c >> d;
        b[c-1].push_back(d-1);
        b[d-1].push_back(c-1);
    }
    
    map<int, int> gn;
    vector<int> g(n, 0);
    int num = 1;
    for (int i=0; i<n; i++) {
        if (!g[i]) {
            g[i] = num;
            int count = 1;
            queue<int> q;
            q.push(i);
            while (!q.empty()) {
                int target = q.front();
                q.pop();
                for (int j=0; j<f[target].size(); j++) {
                    if (g[f[target][j]]) continue;
                    g[f[target][j]] = num;
                    count++;
                    q.push(f[target][j]);
                }
            }
            gn[num] = count;
            num++;
        }
    }
    
    for (int i=0; i<n-1; i++) {
        int bn = 0;
        for (int j=0; j<b[i].size(); j++) {
            if (g[i] == g[b[i][j]]) bn++;
        }
        cout << gn[g[i]] - f[i].size() - bn - 1 << " ";
    }
    int bn = 0;
    for (int j=0; j<b[n-1].size(); j++) {
        if (g[n-1] == g[b[n-1][j]]) bn++;
    }
    cout << gn[g[n-1]] -f[n-1].size() - bn - 1 << endl;

    return 0;
}



Measured memory_bytes: 12800