akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10 ** 6)
k = int(input())

ansl = []

def dfs(s):
    if len(s) >= 11:
        return
    ansl.append(s)
    if s[-1] != "0":
        dfs(s+str(int(s[-1])-1))
    dfs(s + str(int(s[-1])))
    if s[-1] != "9":
        dfs(s + str(int(s[-1]) + 1))

for i in range(1,10):
    dfs(str(i))
ansl = [int(a) for a in ansl]
ansl = sorted(ansl)
print(ansl[k-1])

Measured memory_bytes: 86232
#include <iostream>
#include <vector>
#include <string>
#include <atcoder/mincostflow>

namespace ac = atcoder;

using lint = long long;
constexpr lint BUF = 1 << 30;

void solve() {
    int n, k;
    std::cin >> n >> k;

    int s = n * 2, g = s + 1;
    ac::mcf_graph<int, lint> graph(n * 2 + 2);

    graph.add_edge(s, g, n * k, BUF);
    for (int i = 0; i < n; ++i) {
        graph.add_edge(s, i, k, 0);
        graph.add_edge(n + i, g, k, 0);
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            lint x;
            std::cin >> x;
            graph.add_edge(i, n + j, 1, BUF - x);
        }
    }

    std::cout << BUF * n * k - graph.flow(s, g, n * k).second << "\n";

    std::vector<std::string> grid(n, std::string(n, '.'));
    for (auto e : graph.edges()) {
        if (e.flow == 0 || e.from == s || e.to == g) continue;
        int i = e.from, j = e.to - n;
        grid[i][j] = 'X';
    }

    for (const auto& v : grid) std::cout << v << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3872
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define ss cout << " ";
#define nn cout << "\n";
#define ct(x) cout << x;
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
const int maxn = 200200;
 
void solve(){

    return;
}
vector <int> A[200005];
vector <bool> V(200005, 0);
int nr = 0;
int rs = 0;

void dfs(int nod) {
    V[nod] = 1;
    nr++;
    for(int i = 0; i < (int)A[nod].size(); i++) {
        int next = A[nod][i];
        if(!V[next]) {
            dfs(next);
        }
    }
}
 
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int x,y;
        cin >> x >> y;
        A[x].push_back(y);
        A[y].push_back(x);
    }
    for (int i = 1; i <= n; i++){
        if (!V[i]){
            nr = 0;
            dfs(i);
            rs = max(nr, rs);
        }
    }
    ctn(rs);
    return 0;
}


Measured memory_bytes: 20720
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
        int h,m,s;
        cin >> h >> m >> s;
        while(h>=0){
                int pass = h*3600+m*60+s;
                int last = 120*60-pass;
                cout << setw(2) << setfill('0') << last/3600 << ':' << setw(2) << setfill('0') << last%3600/60 << ':' << setw(2) << setfill('0') << last%60 << endl;
                last *= 3;
                cout << setw(2) << setfill('0') << last/3600 << ':' << setw(2) << setfill('0') << last%3600/60 << ':' << setw(2) << setfill('0') << last%60 << endl;
                cin >> h >> m >> s;
        }   
}

Measured memory_bytes: 0
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(t, n) {
		int p, q;
		cin >> p >> q;
		if (p < q)swap(p, q);
		int k = sqrt(p*p + q*q);
		int cnt = 0;
		FOR(i, -k, k + 1) {
			FOR(j,-k, k + 1) {
				if (i == 0 && j == 0)continue;
				int c = i*i + j*j;
				if ((i*p + j*q) % c == 0 && (i*q - j*p) % c == 0)cnt++;
			}
		}

		if (cnt == 8)cout << 'P' << endl;
		else cout << 'C' << endl;

	}
	return 0;
}

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

int main()
{
  int a,b,c,d,e,f,i;
  for(int i=1; i>0;){
    cin >> a >> b;
    if(a == 0 && b == 0){
      break;
    }
    for(int ii=0; ii<a; ii++){
      if(ii == 0 || ii == a-1){
      for(int iii=0; iii<b; iii++){
	cout << "#" ;
      }
      }
      else{
	for(int iiii=0; iiii<b; iiii++){
	  if(iiii == 0 || iiii == b-1){
	    cout << "#" ;
	  }
	  else
	    {
	      cout <<".";
	    }
	}
      }
    cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main(){
    LL n;
    LL money=1000;
    LL stock=0;
    cin >> n;
    vector<LL> a(n);
    for(LL i=0; i<n; i++){
        cin >> a[i];
    }

    for(LL i=0; i<n; i++){
        if(i==n-1){
            money=money+stock*a[i];
            stock=0;
        }else{
            if(a[i+1]>a[i]){
                stock=stock+money/a[i];
                money=money%a[i];
            }else if(a[i+1]<a[i]){
                money=money+stock*a[i];
                stock=0;
            }
        }
    }

    cout << money << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#define ll long long
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>QUE;//きゅー
int length(char* str) {
	int len = strlen(str);
	return len;
}
ll GCD(ll a,ll b)
{

    ll r, tmp;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }


    return b;
}
ll LCM(ll a,ll b)
{

    ll r, x, tmp;
    ll i, j;
    ll lcm;
    i = a;
    j = b;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    lcm = (i / b) * j;

    return lcm;
}

int main()
{
    int A, B;
    cin >> A >> B;
    cout << LCM(A, B);
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	char s[5];
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++)
	{
		if(s[i]=='7')
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int X;
cin >> X;

ll now = 0;

rrep(i,1000000) {
    now+= i;
    if(now >= X) {
        cout << i << endl;
        break;
    }
}

return 0;
}

Measured memory_bytes: 256
from itertools import groupby as gb
n=int(input())
s=set(list("qazwsxedcrfvtgbyhnujmiklop"))
l=[500 for i in range(26)]
for i in  range(n):
  strd=sorted(input())
  vs=set(strd)
  sstr=sorted(list(vs))
  gr=[(a,len(list(b))) for a,b in gb(strd)]
  for t in s-vs:
    l[ord(t)-97]=0
  if sum(l)==0:print();exit()
  for v in vs:
    fg=ord(v)-97
    l[fg]=min(l[fg],gr[sstr.index(v)][1])
  s&=vs
ans=""
for i,c in enumerate(l):
  if c:
    f=chr(i+97)
    ans+=f*c
print(ans)

Measured memory_bytes: 3064
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import defaultdict

def main():
  n, t = map(int, input().split())
  la = list(map(int, input().split()))
  min_a = 10**9 + 7
  max_a = -1
  
  cnts = defaultdict(int)
  for a in la:
    min_a = min(min_a, a)
    cnts[a - min_a] += 1
  print(cnts[max(cnts.keys())])

if __name__=='__main__':
  main()



Measured memory_bytes: 20960
#include<bits/stdc++.h>
using namespace std ;
typedef unsigned long long ll ;
const ll N = 3033 ; 
ll dp[N], s[N], n, mod = 1e9+7;
string S ;
int main ()
{
	ios::sync_with_stdio(false) ; cout.tie() ; cin.tie() ;
	cin >> n >> S ;
	for(int i = 1 ; i < N ; i ++) s[i] = 1 ;
	for(int i = 2 ; i <= n ; i ++){
		for(int j = 1 ; j <= i ; j ++)
			if(S[i-2] == '>') dp[j] = (s[i-1]-s[j-1]+mod)%mod ;
			else dp[j] = s[j-1] ;
		for(int j = 1 ; j < N ; j ++) s[j] = (s[j-1]+dp[j])%mod;
	}
	cout << s[N-1] ;
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

bool cmp(pii d1, pii d2){
	return d1.second < d2.second;
}

void Main()
{
	int n, k;
	cin >> n >> k;
	vi a(n);  
	vi cnt(n+1,0);
	rep(i,n) {
		cin >> a[i];
		cnt[a[i]]++; 
	}
	vector<pii> data;
	int i = 0;
	while(i <= n){
		if(cnt[i]!=0) data.push_back(pii(i, cnt[i]));
		i++;
	}
	// rep(i,data.size()) cout << data[i].first << ": " << data[i].second << endl;
	stable_sort(all(data), cmp);
	int ans = 0;
	i = 0;
	while(data.size()>k){
		ans += data[i].second;
		i++;
		k++;
    }
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 5104
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < n; i++) {
			set.add(sc.nextInt());
		}
		sc.close();

		if (set.size() == n) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 100756
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int n,h,a[100010],b[100010];
int main(){
	cin>>n>>h;
	int maxi=-1;
	lol(i,n){
		cin>>a[i]>>b[i];
		maxi=max(maxi,a[i]);
	}
	sort(b,b+n);
	int k=0;
	for(int i=n-1;i>=0;i--){
		if(b[i]<maxi)break;
		h-=b[i];
		k++;
		if(h<=0)break;
	}
	if(h>0){
		k+=(h+maxi-1)/maxi;
	}
	cout<<k<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    ll H,W;
    cin >> H >> W;
    ll N;
    cin >> N;
    vector<vector<ll>> col(H,vector<ll>(W));
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    ll ct=0;
    ll index=1;
    for(int i=0;i<H;i++){
        if(ct%2==0){
            for(int j=0;j<W;j++){
                col[i][j]=index;
                A[index-1]--;
                if(A[index-1]==0) index++;
            }
        }
        else{
            for(int j=W-1;j>=0;j--){
                col[i][j]=index;
                A[index-1]--;
                if(A[index-1]==0) index++;
            }
        }
        ct++;
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout << col[i][j];
            if(j!=W-1) cout << " ";
        }
        cout << endl;
    }
    
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

void solve(int a, int b)
{
    int ans, count = 0;

    for (int n = 1; n <= 3; n++)
    {
        ans = a * b * n;
        
        if(ans%2 != 0)
        {
            count++;
        }
    }
    
    if(count > 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

int main()
{
    int a, b;

    cin >> a >> b;

    solve(a, b);

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigDecimal;
import java.util.*;


public class Main {
	static int[] vy = {1,0,-1,0};
	static int[] vx = {0,1,0,-1};
	public static void main(String[] args) {	
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		while(true) {
			int W = sc.nextInt();
			int H = sc.nextInt();
			int D = 0;
			if(W == 0 && H == 0) break;
			int w = 1;
			int h = 1;
			while(true) {
				String in = sc.next();
				if(in.equals("FORWARD")) {
					int idx = sc.nextInt();
					w = Math.max(Math.min((w + vx[D]*idx),W),1);
					h = Math.max(Math.min((h + vy[D]*idx),H),1);
				}
				if(in.equals("BACKWARD")) {
					int idx = sc.nextInt();
					w = Math.max(Math.min((w - vx[D]*idx),W),1);
					h = Math.max(Math.min((h - vy[D]*idx),H),1);
				}
				if(in.equals("RIGHT")) {
					D = (D+1) % 4;
				}
				if(in.equals("LEFT")) {
					D = (D+3) % 4;
				}
				if(in.equals("STOP")) {
					break;
				}
			}
			System.out.println(w + " " + h);
			
			
		}
	}
}

Measured memory_bytes: 34408
S = input()
A = int(S[:2])
B = int(S[2:])
if 1 <= A <= 12:
    if 1 <= B <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= B <= 12:
        print('YYMM')
    else:
        print('NA')


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int count=0;
    if(a!=b) count++;
    if(b!=c) count++;
    if(c!=a) count++;
    if(!count) count=1;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Q; cin >> N >> Q;
  vector<stack<int> > S(N, stack<int>());
  vector<int> ans;
  REP(i, Q){
    int q, t, x; cin >> q >> t;
    if(q == 0){
      cin >> x;
      S[t].push(x);
    }else if(q == 1){
      if(!S[t].empty()) ans.push_back(S[t].top());
    }else{
      if(!S[t].empty()) S[t].pop();
    }
  }
  for(auto &i : ans) cout << i << endl;
}



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

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,i,count=0;
    cin>>n;
    string s;
    cin>>s;
    for(i=0;i<n-2;i++)
    {
    	if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
    	count++;
	}
	cout<<count<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i++)

using namespace std;

int main(){
  string s; cin >> s;

  string ans = "";
  string key = "";
  for(int i=0;i < s.size();i++) {
    key = s.substr(i,1);
    if( (i+1) % 2 == 0) {
      if( key == "L" || key == "U" || key == "D") {
        ans = "Yes";
      }else{
        ans = "No";
        break;
      }
    }else{
      if( key == "R" || key == "U" || key == "D") {
        ans = "Yes";
      }else{
        ans = "No";
        break;
      }
    }
  }

  cout << ans << endl;
}

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

int main(void) {
    int N;cin>>N;
    int A[N];
    for (int i = 0; i < N; i++) cin>>A[i];
        for (int i = 0; i < N; i++) {
            cout << A[i];
            if (i < N - 1) cout << " ";
        }
        cout << endl;
    for (int i = 1; i < N; i++) {
        int val = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > val) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = val;
        for (int i = 0; i < N; i++) {
            cout << A[i];
            if (i < N - 1) cout << " ";
        }
        cout << endl;
    }    
    return 0;
}


Measured memory_bytes: 3060
import sys
import bisect

A, B, Q = map(int, sys.stdin.readline().split())
INF = 10 ** 18
S = [-INF] + [int(sys.stdin.readline()) for _ in range(A)] + [INF]
T = [-INF] + [int(sys.stdin.readline()) for _ in range(B)] + [INF]
X = [int(sys.stdin.readline()) for _ in range(Q)]


# def binary_search(q, A):
#     l, r = 0, len(A)
#     while r - l > 1:
#         mid = (l + r) // 2
#         if q > A[mid]:
#             l = mid
#         else:
#             r = mid
#     return A[l], A[r]


def main():
    for x in X:
        ids, idt = bisect.bisect_right(S, x), bisect.bisect_right(T, x)
        print(min(abs(s-t) + min(abs(s-x), abs(t-x)) for s in S[ids-1:ids+1] for t in T[idt-1:idt+1]))
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 76380
from collections import deque

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

graph = [[] for _ in range(N + 1)]

for x in range(M):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

prev = [-1] * (N + 1)
prev[0] = 0
prev[1] = 1


d = deque()
d.append(1)

while d:
    v = d.popleft()
    for i in graph[v]:
        if prev[i] == -1:
            prev[i] = v
            d.append(i)

prev.pop(0)
prev.pop(0)
if len(prev) > 0:
    print("Yes")
    for y in prev:
        print(y)
else:
    print("No")


Measured memory_bytes: 94444
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
//Nodeクラス
class Node{
    int number;
    Node left;
    Node right;
    Node parent;
    //Nodeコンストラクタ
    Node(int number){
        this.number = number;
        left = null;
        right = null;
        parent = null;
    }

    void preorder(){
        System.out.print(" " + this.number);
        if(this.left != null)   this.left.preorder();
        if(this.right != null)  this.right.preorder();
    }
    
    void inorder(){
        if(this.left != null)   this.left.inorder();
        System.out.print(" " + this.number);
        if(this.right != null)  this.right.inorder();
    }
    
    void postorder(){
        if(this.left != null)   this.left.postorder();
        if(this.right != null)  this.right.postorder();
        System.out.print(" " + this.number);
    }
}

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
        int n = Integer.parseInt(br.readLine());
	
        Node[] tree = new Node[n];
        for(int i = 0; i < n; i++){
            tree[i] = new Node(i);
        }
	
        for(int i = 0; i < n; i++){
            String[] input = br.readLine().split(" ");
            int num = Integer.parseInt(input[0]);
            int left = Integer.parseInt(input[1]);
            int right = Integer.parseInt(input[2]);
            
            if(left+right != -2){
                if(left == -1){
                    tree[num].right = tree[right];
                    tree[right].parent = tree[num];
                }else if(right == -1){
                    tree[num].left = tree[left];
                    tree[left].parent = tree[num];
                }else{
                    tree[num].right = tree[right];
                    tree[num].left = tree[left];
                    tree[right].parent = tree[num];
                    tree[left].parent = tree[num];
                }
            }
        }
	
        Node root = tree[0];
        while(root.parent != null){
            root = root.parent;
        }
	
        System.out.println("Preorder");
        root.preorder();
        System.out.println("\nInorder");
        root.inorder();
        System.out.println("\nPostorder");
        root.postorder(); 
        System.out.println();     
    }
}


Measured memory_bytes: 24396
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
 
const int N = 100100;
const int MOD = 1000000007;
int n, a[N];
 
ll sheel[N], fact[N], freq[N], tillNow;
 
map<int, int> there;
 
int cnt(int pos)
{
    return lower_bound(a, a + n, pos) - a;
}
int main()
{
   // freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    fact[0] = 1;
    for (int i = 1; i < N; ++i) {
        fact[i] = (1ll * i * fact[i - 1]) % MOD;
    }
    for (int i = 0; i < n; ++i) {
        sheel[i] = tillNow;
        if(2 * (i+1-tillNow) - 1 > a[i])
            tillNow++;
        freq[sheel[i]]++;
    }
/*    for (int i = 0; i < n; ++i){
        cout << sheel[i] << " ";
    }
    cout << endl;*/
    ll fn = 1;
    ll counter = 0;
    for (int i = 0; i < n; ++i) {
        counter += freq[i];
        fn = (fn * counter) %MOD;
        counter--;
    }
    printf("%lld\n",fn );
    return 0;
}

Measured memory_bytes: 2560
# AOJ 1124: When Can We Meet?
# Python3 2018.7.14 bal4u

while True:
	n, q = map(int, input().split())
	if n == 0: break
	f, ma = [0]*120, 0
	for i in range(n):
		ds = list(map(int, input().split()))
		for d in ds[1:]:
			f[d] += 1
			ma = max(ma, d)
	ans = 0
	for i in range(1, ma+1):
		if f[i] >= q and f[i] > f[ans]: ans = i
	print(ans)


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

int main(){
    string s; cin >> s;
    ll sum=0;
    int n = s.size()-1;
    reverse(s.begin(),s.end());
    for(int bit=0;bit<(1<<n);++bit){
        ll res=s[0]-'0';
        ll digit=10;
        rep(i,n){
            if(bit & (1<<i)){//i番目のフラグが立っている
                sum += res;
                res=0;
                digit=1;
            }
            res+=(s[i+1]-'0')*digit;
            digit*=10;
        }
        sum += res;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdio.h>      /* printf */
#include <math.h> 
#include<iostream>
using namespace std;

int main () {
	int t,h,a;
	//scanf("%d", &t);
	scanf("%d %d", &h,&a);

	int tot=0;
	for(int i = 0;i<a;i++){
		int arr;

		cin>>arr;
		tot += arr;
	}

	if (tot>= h){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}

	return 0;
}

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

int main() {
	int N, x[100], y[100], h[100], outX, outY, outH;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}
	for (int X = 0; X <= 100; X++) {
		for (int Y = 0; Y <= 100; Y++) {
			bool check = true;
			int H;
			for (int i = 0; i < N; i++) {
				if (h[i] > 0) {
					H = h[i] + abs(X - x[i]) + abs(Y - y[i]);
				}
			}
			for (int i = 0; i < N; i++) {
				if (h[i] != max(H - abs(X - x[i]) - abs(Y - y[i]), 0)) check = false;
			}
			if (check) {
				outX = X;
				outY = Y;
				outH = H;
			}
		}
	}
	cout << outX << " " << outY << " " << outH;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long int
#define ff first
#define ss second
#define S size()
#define mod (ll)(1e9+7)
#define mset(a,k) memset(a,k,sizeof(a))
#define fr(i, x, y) for ( ll i = x; i < y;i++)
#define dr(i, x, y) for ( ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define pqueue priority_queue<ll>
#define piqueue priority_queue<ll,vll ,greater<ll>>
#define mapcl map<char,ll>
#define mapll map<ll,ll>
#define mapsl map<string,ll>
#define vi vector<ll>
#define vs vector<string>
#define vb vector<bool>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define piii pair<ll,pii>
#define vii vector<pii>
#define vvi vector<vi>
#define vvii vector<vii>
using namespace std;
void fast() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
//----------------------------------------FUNCTIONS-------------------------------------
ll gcd(ll x, ll y )						{if (y == 0) return x; return gcd(y, x % y);}
ll lcm(ll a, ll b)						{return (a * b) / gcd(a, b);}
ll logx(ll base, ll num)				{int cnt = 0; while (num != 1) {num /= base; ++cnt;} return cnt;}
vi vin(ll n)							{vi a(n); fr(i, 0, n) cin >> a[i]; return a;}
void out(vi a)							{for (int i = 0; i < (ll)a.S; i++) { cout << a[i] << " "; } cout << endl;}
void in(ll *a, ll n)        			{for (ll i = 0; i < n; i++)cin >> a[i];}
void out(ll *a, ll n)					{fr(i, 0, n) {cout << a[i] << " ";} cout << '\n';}
void out1(vi v)							{fr(i, 0, (ll)v.S) {cout << v[i] << " ";} cout << endl;}
const ll MAXN = (ll)(1 * 1e6 + 5 ), level = 22;

void solve()
{
	string s;
	cin >> s;
	ll ans = 0;
	fr(i, 0, s.S)
	{
		ans += (s[i] - '0');
	}
	if (ans % 9 == 0)cout << "Yes\n";
	else cout << "No\n";
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen ("inp4.txt", "r", stdin);
	freopen ("out4.txt", "w", stdout);
#endif
	fast();
	ll t = 1;
	//cin >> t;
	fr(i, 0, t)
	{
		solve();
	}
}

Measured memory_bytes: 3728
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	int N;
	String S;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		N = nextInt();
		S = next();
		byte[] asciiCodes;
		try {
			asciiCodes = S.getBytes("US-ASCII");
		} catch (Exception e) {
		e.printStackTrace();
		return;
		}
		for (int i = 0; i < asciiCodes.length; i++) {
			asciiCodes[i] += N;
			if(asciiCodes[i] > 90)asciiCodes[i] -= 26;
		}

        String resultString;
        try {
            resultString = new String(asciiCodes, "US-ASCII");
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        out.println(resultString);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}

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


#define int long long 


const int N = 5e5 + 7;

int a[N], mx[N], mn[N];

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for(int i = 1; i <= 3 * n; i++) {
		cin >> a[i];
	}
	multiset <int> st; int sum = 0;

	for(int i = 1; i <= 3 * n; i++) {
		sum += a[i];
		st.insert(a[i]);
		if(st.size() > n) {
			sum -= *st.begin();
			st.erase(st.begin());
		}
		mx[i] = sum;
	}

	st.clear(); sum = 0;

	for(int i = 3 * n; i >= 1; i--) {
		sum += a[i];
		st.insert(a[i]);
		if(st.size() > n) {
			sum -= *st.rbegin();
			st.erase(st.lower_bound(*st.rbegin()));
		}
		mn[i] = sum;
	}

	int ans = -1e18;

	for(int i = 1; i <= 3 * n; i++) {
		if(i >= n && 3 * n - i >= n) { 
			ans = max(ans, mx[i] - mn[i + 1]);
		}	
	}
	cout << ans << endl;
}

Measured memory_bytes: 15360
import Foundation

var line: String

line = readLine()!

var nums: [Int] = Array<Int>()
for num in line.componentsSeparatedByString(" ") {
	nums.append(Int(num)!)
}

if nums[0] + nums[1] < nums[2] + nums[3] {
	print("Right")
}else if nums[0] + nums[1] > nums[2] + nums[3] {
	print("Left")
}else{
	print("Balanced")
}




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

int main(){
    const int MAX_N = 1e5+10;
    int N;
    string S[MAX_N];
    cin >> N;
    for (int i = 0; i < N; ++i){
        string s;
        cin >> s;
        int a[10];
        for (int j = 0; j < 10; ++j){
            a[j] = s[j]-0;
        }
        sort(a, a+10);
        for (int j = 0; j < 10; ++j){
            s[j] = a[j];
        }
        S[i] = s;
    }
    sort(S, S+N);

    long long ans = 0;
    long long sum = 1;
    string n, p = S[0];
    for (int i = 1; i < N; ++i){
        n = S[i];
        if(p == n){
            sum += 1;
        }else{
            ans += sum * (sum-1) / 2;
            sum = 1;
        }
        p = n;
    }
    ans += sum * (sum-1) / 2;


    cout << ans << endl;


}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb emplace_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};
vector<edge> g[100010];
int dist[100010];

void dfs1(int now,int p){
    for(edge e:g[now]){
        if(e.to==p)continue;
        dfs1(e.to,now);
        chmax(dist[now],dist[e.to]+e.cost);
    }
}

int dfs2(int idx,int d_par,int par){
    vpint d_child;
    d_child.pb(0,-1);
    for(edge e:g[idx]){
        if(e.to==par)d_child.pb(d_par+e.cost,e.to);
        else d_child.pb(e.cost+dist[e.to],e.to);
    }
    sort(d_child.rbegin(),d_child.rend());
    int ret=d_child[0].fi+d_child[1].fi;
    //cout<<ret<<endl;
    for(edge e:g[idx]){
        if(e.to==par)continue;
        ret=max(ret,dfs2(e.to,d_child[d_child[0].se==e.to].fi,idx));
    }
    return (ret);
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    int N;
    cin>>N;
    rep(i,0,N-1){
        int a,b,c;
        cin>>a>>b>>c;
        g[a].pb(edge(b,c));
        g[b].pb(edge(a,c));
    }
    dfs1(N/2,-1);
    cout<<dfs2(N/2,0,-1)<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


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


void solve(std::string X){
  stack<char> s;
  for(auto c : X) {
    if(!s.empty() and s.top() == 'S' and c == 'T') {
      s.pop();
    } else {
      s.push(c);
    }
  }
  std::cout << s.size() << std::endl;
}

int main(){
    std::string X;
    std::cin >> X;
    solve(X);
    return 0;
}


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

int main(void)
{   ios::sync_with_stdio(false);
    int n, count=0, i, j;
    string s;
    cin>>n>>s;
    i = 0;
    j = s.length()-1;
    while(i<j){
        while(s[j]=='W'&&i<j)
            j--;
        while(s[i]=='R'&&i<j)
            i++;
        if(i<j){
            i++;
            j--;
            count++;
        }
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3776
#include <iostream>
#include <vector>
#include <climits>
using namespace  std;

void fnInput(vector<int> &rvnSort)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvnSort.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
    cin >> rvnSort[i];
}

void fnMerge(vector<int> &rvnSort, int &rnSortCnt, int nLeft, int nMid, int nRight)
{
  vector<int> vnLeft, vnRight;
  int nLeftSiz = nMid - nLeft;
  int nRightSiz = nRight - nMid;

  vnLeft.resize(nLeftSiz + 1);
  vnRight.resize(nRightSiz + 1);

  for (int i = 0; i < nLeftSiz; i++)
    vnLeft[i] = rvnSort[nLeft + i];
  for (int i = 0; i < nRightSiz; i++)
    vnRight[i] = rvnSort[nMid + i];

  vnLeft[nLeftSiz] = INT_MAX;
  vnRight[nRightSiz] = INT_MAX;
  int i = 0, j = 0;

  for (int n = nLeft; n < nRight; n++)
  {
    if (vnLeft[i] <= vnRight[j])
      rvnSort[n] = vnLeft[i++];
    else
      rvnSort[n] = vnRight[j++];
    rnSortCnt++;
  }
}

void fnMergeSort(vector<int> &rvnSort, int &rnSortCnt, int nLeft, int nRight)
{
  if (nLeft + 1 < nRight)
  {
    int nMid = (nLeft + nRight) / 2;
    fnMergeSort(rvnSort, rnSortCnt, nLeft, nMid);
    fnMergeSort(rvnSort, rnSortCnt, nMid, nRight);
    fnMerge(rvnSort, rnSortCnt, nLeft, nMid, nRight);
  }
}

void fnResult(const vector<int> &cnrvnSort, int nSortCnt)
{
  for (int i = 0; i < cnrvnSort.size(); i++)
  {
    if (i != 0)  cout << " ";
    cout << cnrvnSort[i];
  }
  cout << endl;
  cout << nSortCnt << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnSort;

  fnInput(vnSort);

  int nLeft = 0;
  int nRight = vnSort.size();
  int nSortCnt = 0;
  fnMergeSort(vnSort, nSortCnt, nLeft, nRight);

  fnResult(vnSort, nSortCnt);

  return 0;
}

Measured memory_bytes: 6808
k, n = map(int, input().split())

a = list(map(int, input().split()))

x = 10 ** 6

for i in range(n-1):
    if x > k - (a[i+1] - a[i]):
        x = k - (a[i+1] - a[i])
    
if x > a[n-1] - a[0]:
    x = a[n-1] - a[0]

print(x)

Measured memory_bytes: 26420
import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] arguments = br.readLine().split(" ");
		double x1 = Double.parseDouble(arguments[0]);
		double y1 = Double.parseDouble(arguments[1]);
		double x2 = Double.parseDouble(arguments[2]);
		double y2 = Double.parseDouble(arguments[3]);
		
		double dx = abs(x2 - x1);
		double dy = abs(y2 - y1);
		
		double distance = sqrt(pow(dx, 2) + pow(dy, 2));
		
		System.out.println(distance);
	}

}

Measured memory_bytes: 17124
// C - Good Sequence
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int C[100001];

int main(){
	int N; cin>>N;
	int ans = 0;
	rp(i, 0, N){
		int a; scanf("%d",&a);
		if(a<=N) C[a]++; else ans++;
	}
	rp(a, 1, N+1) ans += C[a] - (C[a]<a? 0: a);
	cout<< ans <<endl;
}

Measured memory_bytes: 256
import Data.List (tails)

main = do
  li <- getLine
  let [n,d] = map read $ words li
  vs <- getVecs n
  let answer = compute vs
  print answer

getVecs :: Int -> IO [[Int]]
getVecs 0 = return []
getVecs n = do
  li <- getLine
  let v = map read $ words li
  vs <- getVecs (pred n)
  return (v:vs)

squares = [ k*k | k <- [1..] ]
isSquare x = inner squares where
  inner (kk:kks) = case compare x kk of
    LT -> False
    EQ -> True
    GT -> inner kks

compute vs = length
  [ ()
  | v1:vs1 <- tails vs
  , v2 <- vs1
  , isSquare $ sum $ map (^ 2) $ zipWith (-) v1 v2
  ]


Measured memory_bytes: 1020
count = 0
$s = $t = []
STDIN.each_line {|line|
  if count == 0
  elsif count == 1
    $s = line.split " "
  elsif count == 2
  elsif count == 3
    $t = line.split " "
  end

  count += 1
}

$s.map! {|item| item.to_i }
$t.map! {|item| item.to_i }

def search s, value
  l = 0
  r = s.length
  while (l  + 1 < r)
    i = (r + l) / 2
    if s[i] <= value
      l = i
    else
      r = i
    end
  end

  return s[l] == value
end


result = 0
$t.each do |value|
  if search $s, value
    result += 1
  end
end

puts result



Measured memory_bytes: 14180
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();

		if (k % 2 == 1) {
			long wa =0;
			for (int i = 1; i <= n; i++) {
				if (i % k == 0) {
					wa++;
				}}
			System.out.println(wa * wa * wa);

		} else {
			long wa = 0;
			long wa2 = 0;
			for (int i = 1; i <= n; i++) {
				if (i % k == 0) {
					wa++;
				}
				if ((i % k) == (k / 2)) {
					wa2++;
				}
			}

			System.out.println((wa * wa * wa) + (wa2 * wa2 * wa2));

		}

	}
}

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

#define int long long
#define hell 1000000007

int32_t main()
{
    int h,w;
    cin >> h >> w;
    int dp[h+1][w+1];
    for(int i=0;i<=w;++i) dp[0][i]=0;
    for(int i=0;i<=h;++i) dp[i][0]=0;
    dp[1][1]=1;
    char temp;
    for(int i=1;i<=h;++i)
    {
        for(int j=1;j<=w;++j)
        {
            cin >> temp;
            if(i==1 && j==1) continue;
            if(temp=='#') dp[i][j]=0;
            else{
                dp[i][j] = (dp[i-1][j] % hell) + (dp[i][j-1]%hell);
                dp[i][j] %=hell;
            }
        }
    }
    cout << dp[h][w] << endl;
}

Measured memory_bytes: 11324
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,s;
  cin>>k>>s;
  int ans=0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      int z=s-(x+y);
      if(0<=z && z<=k){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}
  

Measured memory_bytes: 256
def point(m):
    if m=="r":
        return p
    elif m=="s":
        return r
    else:
        return s

n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = str(input())
q = [ [i] for i in range(k)]
for i in range(k,n):
    q[i%k].append(i)
ans = 0
for i in range(k):
    j = 0
    while j<len(q[i]):
        if j==len(q[i])-1:
            ans += point(t[q[i][j]])
            j+=1
        else:
            if t[q[i][j]] == t[q[i][j+1]]:
                ans += point(t[q[i][j]])
                j +=2
            else:
                ans += point(t[q[i][j]])
                j +=1
print(ans)

Measured memory_bytes: 15464
#include <bits/stdc++.h>
using namespace std;
 
int n,m,a,b,ans;
set<int> AL[100005];
int h[100005];
int visited[100005];
 
void dfs(int u){
	if(visited[u] == 1) return;
  	visited[u] = 1;
  	bool good = true;
  	for(int v: AL[u]){
    	if(h[u] <= h[v]) good = false;
      dfs(v);
    }
  	if(good) ++ans;
}
 
int main(){
	cin >> n >> m;
  	for(int i=0;i<n;++i) cin >> h[i];
  	for(int i=0;i<m;++i){
    	cin >> a >> b;
     	--a; --b;
     	AL[a].insert(b);
      AL[b].insert(a);
    }
  	for(int i=0;i<n;++i){
    	if(visited[i] == 0) dfs(i);
    }
  	cout << ans;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int a, b, c; std::cin >> a >> b >> c;
    std::cout << min(b / a, c) << "\n";
}


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


int main(){
    int m, n;
    cin >> n >> m;
    vector<pair<long long, long long> > p(n);
    long long a, b;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        p[i] = make_pair(a, b);
    } 
    sort(p.begin(), p.end());
    long long cost=0;
    long long count=0;
    for (int i = 0; i < n; i++) {
        if(count+p[i].second > m){
            cost += p[i].first * (m - count);
            break;
        }else{
            cost += p[i].first * p[i].second;
            count += p[i].second;
        }
    } 
    cout << cost << endl;


    return 0;
}

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

int main() {
    string s,ans;
    long long n,k=0;
    cin>>s;
    n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            ans[k]='1';
            k++;
        }else if(s[i]=='0'){
            ans[k]='0';
            k++;
        }else{
            k--;
            if(k<0)k=0;
        }
    }
    for(int i=0;i<k;i++){
        cout<<ans[i];
    }
    cout<<endl;
    return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double
 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define MX LLONG_MAX
#define MN LLONG_MIN
 
const int N=1e5+5;
const ll mod=1e9+7;
 
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}          
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

int32_t main()                  
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll r,d,x;
    cin>>r>>d>>x;
    ll c=10;
    while(c--)
    {
        x = r*x- d;
        cout<<x<<endl;
    }
    return 0;
}  

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int isPrime(int n){
  for(int i=2;i*i<=n;i++) if(n%i==0) return 0;
  return 1;
}
int main(){
  int i,j,dp[1500000]={},c;
  i=2;
  
  while(i<1500000){
    c=1;
    dp[i]=0;
    while(isPrime(i+c)==0){
      c++;
    }
    if(i+c<1500000){
      for(j=i+1;j<i+c;j++) dp[j]=c;
      dp[i+c]=0;
    }
    i+=c;
  }
  int n;
  cin >> n;
  while(n!=0){
    cout << dp[n] << endl;
    cin >> n;
  }
  return 0;
}

Measured memory_bytes: 8952
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  string s;cin>>s;
  

  vector<int> a(3);
  REP(i,1000){
    a[0]=i%10;
    a[1]=(i%100)/10;
    a[2]=i/100;

    int idx=0;
    REP(j,n){
      if ((s[j]-48)==a[idx])
      {
        idx++;
        if (idx==3){
          ans++;
          break;
          }
      }
    }
  }

  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
X = list(map(int, input().split()))


ans = float("inf")
for i in range(N-K+1):
  f = X[i]
  t = X[i+K-1]
  if f <= 0 <= t:
    ans = min(ans, min(abs(f), abs(t)) + abs(f)+abs(t))
  else:
    ans = min(ans, max(abs(f), abs(t)))

print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   printf("%d:", n);
   for (int i = 2; i * i <= n; i++) {
      while (n % i == 0) {
         n /= i;
         printf(" %d", i);
      }
   }
   if (n != 1)
      printf(" %d\n", n);
   else
      printf("\n");
   return 0;
}


Measured memory_bytes: 3232
import java.util.Scanner;


class Main {
	public static void main(String args[]) {
		int i[] = new int[3];
	    Scanner sc = new Scanner(System.in);
	    String  s1 = sc.next();
	    i[0] = Integer.parseInt(s1);
	    String  s2 = sc.next();
	    i[1] = Integer.parseInt(s2);
	    String  s3 = sc.next();
	    i[2] = Integer.parseInt(s3);
	    int w = 0;
	    for( int j = 0; j < i.length; j++ ){
	        for( int k = 0; k < i.length - 1; k++ ){
	            if( i[k] > i[(k + 1)] ){
	        	    w = i[k];
	        	    i[k] = i[(k + 1)];
	        	    i[(k + 1)] = w;
	            }
    	    }
	    }
	    System.out.println( i[0] + " " + i[1] + " " + i[2] );
	}

}

Measured memory_bytes: 17128
s = input()

frommap = []
for d in range(10):
    frommap.append([0] * 13)
    for m in range(13):
        m2 = (m * 10 + d) % 13
        frommap[d][m2] = m

dp = [1] + [0] * 12
for c in s:
    if c == '?':
        dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in zip(*frommap)]
    else:
        dp = [dp[f] for f in frommap[int(c)]]

print(dp[5])

Measured memory_bytes: 3188
def check_adjacents(S, i, j):
    return i > 0 and S[i-1][j] == '#' or \
           i < H - 1 and S[i+1][j] == '#' or \
           j > 0 and S[i][j-1] == '#' or \
           j < W - 1 and S[i][j+1] == '#'

def solution(H, W, S):
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                adjacents_sharp = check_adjacents(S, i, j)
                if not adjacents_sharp:
                    return 'No'
    return 'Yes'

H, W = map(int, input().split())
S = [input() for _ in range(H)]
print(solution(H, W, S))

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<cstring>
using namespace std;

int main()
{
	int i,j,n,s[100000][2],sum;
	while(~scanf("%d",&n))
	{
		for(j = 0; j < n; j++)
		{
			for(i = 0; i < 2; i++)
			{
				scanf("%d",&s[j][i]);
			}
		}
		for(j = 0,sum = 0; j < n; j++)
		{
			sum = sum + s[j][1] - s[j][0] + 1;
		}
		printf("%d\n",sum);
	}
	return 0;
}

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

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

int main()
{
    ll i,j;
    double r;
    cin >> r;
    double PI = 3.1415926535;
    cout << 2.0*r*PI << endl;

    return 0;
}

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

int main() {
    int n, q;
    cin >> n >> q;
    fenwick_tree<long long> ft(n);

    for (int i = 0; i < n; i++) {
        int r;
        cin >> r;
        ft.add(i, r);
    }

    for (int i = 0; i < q; i++) {
        int w, a, b;
        cin >> w >> a >> b;
        if (w == 0) {
            ft.add(a, b);
        } else {
            long long out = ft.sum(a, b);
            cout << out << '\n';
        }
    }
}


Measured memory_bytes: 8216
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(void) {
    int H, W;
    
    cin >> H >> W;
    
    while( !(H == 0 && W == 0) ) {
        for(int h=1; h<=H; h++) {
            for(int w=1; w<=W; w++) {
                
                cout << ((h==1 || w==1 || h==H || w==W) ? '#' : '.');
            }
            cout << endl;
        }
        cout << endl;
        
        cin >> H >> W;
    }
    
    return 0;
}

Measured memory_bytes: 3100