akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(std::string S_A, std::string S_B, std::string S_C){
    char turn = 'a';
    do{
        switch(turn){
            case 'a':
            if(S_A.size()==0){cout<<"A"<<endl;return;}
                turn = S_A[0];
                S_A.erase(0,1);
                
                break;
            case 'b':
            if(S_B.size()==0){cout<<"B"<<endl;return;}
                turn = S_B[0];
                S_B.erase(0,1);
                
                break;
            case 'c':
            if(S_C.size()==0){cout<<"C"<<endl;return;}
                turn = S_C[0];
                S_C.erase(0,1);
                
                break;
        }
    }while(1);
}

int main(){
    std::string S_A;
    std::cin >> S_A;
    std::string S_B;
    std::cin >> S_B;
    std::string S_C;
    std::cin >> S_C;
    solve(S_A, S_B, S_C);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=n-1;i>=0;i--){
    cout<<a[i];
    if(i)cout<<" ";
  }
  cout<<endl;
}



Measured memory_bytes: 3108
from enum import IntEnum


class Attrs(IntEnum):
    LEFT = 0
    RIGHT = 1
    PARENT = 2
    SIBLING = 3
    DEPTH = 4
    HEIGHT = 5


def parents(nodes):
    for i, node in enumerate(nodes):
        if node[Attrs.LEFT] != -1:
            nodes[node[Attrs.LEFT]][Attrs.PARENT] = i
            nodes[node[Attrs.LEFT]][Attrs.SIBLING] = node[Attrs.RIGHT]
        if node[Attrs.RIGHT] != -1:
            nodes[node[Attrs.RIGHT]][Attrs.PARENT] = i
            nodes[node[Attrs.RIGHT]][Attrs.SIBLING] = node[Attrs.LEFT]


def depth_and_heights(nodes):
    def depth(n):
        if nodetype(n) != "root" and n[Attrs.DEPTH] == 0:
            n[Attrs.DEPTH] = depth(nodes[n[Attrs.PARENT]]) + 1
        return n[Attrs.DEPTH]

    def height(n):
        if nodetype(n) != "leaf" and n[Attrs.HEIGHT] == 0:
            if n[Attrs.LEFT] != -1:
                lh = height(nodes[n[Attrs.LEFT]])
            else:
                lh = -1

            if n[Attrs.RIGHT] != -1:
                rh = height(nodes[n[Attrs.RIGHT]])
            else:
                rh = -1
            n[Attrs.HEIGHT] = max(lh, rh) + 1
        return n[Attrs.HEIGHT]

    for node in nodes:
        node[Attrs.DEPTH] = depth(node)
        node[Attrs.HEIGHT] = height(node)


def degree(node):
    if node[Attrs.LEFT] != -1 and node[Attrs.RIGHT] != -1:
        return 2
    elif node[Attrs.LEFT] != -1:
        return 1
    elif node[Attrs.RIGHT] != -1:
        return 1
    else:
        return 0


def nodetype(node):
    if node[Attrs.PARENT] == -1:
        return "root"
    elif node[Attrs.LEFT] == -1 and node[Attrs.RIGHT] == -1:
        return "leaf"
    else:
        return "internal node"


def print_tree(ns):
    parents(ns)
    depth_and_heights(ns)

    for nid, n in enumerate(ns):
        print(("node {}: parent = {}, sibling = {}, degree = {}, " +
               "depth = {}, height = {}, {}").format(nid,
                                                     n[Attrs.PARENT],
                                                     n[Attrs.SIBLING],
                                                     degree(n),
                                                     n[Attrs.DEPTH],
                                                     n[Attrs.HEIGHT],
                                                     nodetype(n)))


def run():
    n = int(input())
    nodes = [None] * n

    for i in range(n):
        nodeid, *attrs = [int(i) for i in input().split()]
        attrs.extend([-1, -1, 0, 0])
        nodes[nodeid] = attrs

    print_tree(nodes)


if __name__ == '__main__':
    run()



Measured memory_bytes: 6352
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,x,ans=0;
  std::cin>>n>>x;

  ll temp=0;

  rep(i,0,n){
    ll a;
    std::cin>>a;
    if(temp+a>x){
      ans+=temp+a-x;
      temp=x-temp;
    }else{
      temp=a;
    }
  }

  std::cout<<ans;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int a, b; cin >> a >> b;
    for (int x = 1; ; x++) {
        if (x * 8 / 100 == a && x / 10 == b) {
            cout << x << endl;
            break;
        }
        if (x * 8 / 100 > a) {
            cout << -1 << endl;
            break;
        }
    }
}


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

#define ll long long
ll mod = 1e9+7;

ll answer(ll s){
    ll zero = 0;
    vector<ll> note(s+3);
    note[3] = 1;

    for (ll i = 1; i < s; i++)
    {
        note[i+3] = note[i+2] + note[i];
        note[i+3] %= mod;
    }

    return note[s]%mod;
}

int main(){
    ll s;
    cin >> s;
    // cout << mod << endl;

    if(s<3){
        cout << 0 << endl;
    } else{
        ll ans = answer(s);
        ans += ans < 0 ? mod : 0;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include <math.h>
#include<vector>
#include<algorithm>
#include <numeric>
using namespace std;

int main() {
	long long h;
	int n;
	vector<long long> a(100005);
	cin >> h >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	long long Sum = 0;
	
	for (int i = 0; i < n; i++) {
		Sum = Sum + a[i];
		if (Sum >= h)break;
	}
	if (Sum < h)cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int a=0,b=0,c=0;
  char s[3];
  scanf("%s",s);
  int i;
  for(i=0;i<3;i++){
    if(s[i]=='a') a=1;
    if(s[i]=='b') b=1;
    if(s[i]=='c') c=1;
  }
  if(a==1 && b==1 && c==1) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> l(2*n);
  for(int i=0;i<2*n;i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  int ans1=0,ans2=0;
  for(int i=0;i<2*n;i++){
    if(i%2==0){
      ans1+=l[i];
    }
    else{
      ans2+=l[i];
    }
  }
  cout << max(ans1,ans2+l[0]-l[2*n-1]) << endl;
}

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

using namespace std;

int n;
set<string> s;
string a;

int main(void)
{
	scanf("%d", &n);
	
	while(n--)
	{
		cin >> a;
		s.insert(a);
	}
	
	printf("%d", s.size());
	return 0;
}

Measured memory_bytes: 19368
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<int> score(n);
            REP(i, n) cin >> score[i];
            whole(sort, score);
            int ans = INF;
            REP(i, n - 1) ans = min(ans, score[i + 1] - score[i]);
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 3076
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#include<vector>
const int mod = 1e9 + 7;


vector<vector<int> >al(100001);
bool vis[100001];
ll dp[100001][2] = {};

void dfs(int root){

	vis[root] = true;

	bool leaf  = true;
	ll black =1;
	ll white = 1;
	for(int x:al[root]){
		if(!vis[x]){
			leaf = false;
			dfs(x);
			black = (black * dp[x][1]) % mod ;
			white = (white * (dp[x][0]+dp[x][1]))% mod;
		}
		
		
	}
	dp[root][0] = black % mod;
	dp[root][1] = white % mod;
}


int main(){
	IOS;
	int n;
	cin >> n;
	int x,y;

	for(int i=1;i<n ; ++i){
		cin >> x >> y;
		al[x].push_back(y);
		al[y].push_back(x);
	}
	dfs(1);
	
	cout << (dp[1][0] + dp[1][1] + mod) % mod << endl;
}

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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(tx, ty, w, h) (0 <= tx && tx <= w && 0 <= ty && ty <= h)

/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;

/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}

/* general_method */
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; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int s;
void in(){
    cin >> s;
}

int f(int t){
    if(t % 2 == 0) return t / 2;
    else return 3 * t + 1;
}

void solve(){

    set<int> t;
    t.insert(s);
    int nxt = s;
    while(not exist(t, f(nxt))){
        t.insert(f(nxt));
        nxt = f(nxt);
    }

    print(t.size() + 1);


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
const main = (input: string) => {
  const strList = input.split('');
  console.log((strList[2] === strList[3] && strList[4] === strList[5] ? 'Yes' : 'No'));
}

// *この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.S;
		Console.WriteLine("{0}",(s[2]==s[3]&&s[4]==s[5])?"Yes":"No");
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13140
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++) // for簡略表記
#define DUMP(ar) for(int loop=0; loop<(int)ar.size(); loop++) cout << "[" << loop << "]:" << ar[loop] << endl // 配列一覧表示
#define DUMPL(ar) for(int loop=0; loop<(int)ar.size(); loop++) { cout << ar[loop]; if(loop<(int)ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// cout << setw(5) << ... で表示形式を5桁に設定 5桁未満なら頭に空白がつく 5桁越なら先頭から5桁まで
// cout << setw(5) << setfill('0') << ... で空白部分の埋め文字に5を使う
// getline(cin, [変数]); で空白などを含む入力の受け取り(行ごとの受け取り)
// cin >> ws; でそこまでにストリームに残されたホワイトスペースを取り除く(=以降のgetlineの有効化)

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

    int n, a;
    cin >> n >> a;
    vector<int> c(n), t(n);
    FOR(i, n){
        cin >> c[i] >> t[i];
    }

    int mmin = numeric_limits<int>::max(), m_idx = -1;
    FOR(i, n){
        if(t[i] <= a && c[i] < mmin){
            mmin = c[i];
            m_idx = i;
        }
    }

    if(m_idx == -1){
        COUT("TLE");
    }else{
        COUT(mmin);
    }


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        Deque<Long> deque = new ArrayDeque<>();
        deque.add(3L);
        deque.add(5L);
        deque.add(7L);

        int count = 0;
        while (true) {
            long v = deque.pop();
            if (v > n) {
                break;
            }
            String s = String.valueOf(v);
            if (s.contains("3") && s.contains("5") && s.contains("7")) {
                count++;
            }
            deque.add(v * 10 + 3);
            deque.add(v * 10 + 5);
            deque.add(v * 10 + 7);
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 27604
#include <stdio.h>
int n, a, b;

int main() {
	scanf("%d %d %d", &n,&a,&b);
	int left = a; int right = b;

	while (a < b) {
		//Alice turn
		if (a + 1 < b)++a;
		else if (a - 1 > 0)--a;
		else { printf("Borys"); return 0; }

		//Borys turn
		if (b - 1 > a)--b;
		else if (b + 1 < n)++b;
		else { printf("Alice"); return 0; };
	}
}

Measured memory_bytes: 128
i=input()
m=list(map(int,input().split()))
c=0
for i in range(1,len(m)-1):
    if m[i - 1] > m[i] > m[i + 1]:
        c+=1
    elif m[i - 1] < m[i] < m[i + 1]:
        c+=1
print(c)




Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

vector<vector<ll> > g;
vector<ll> cnt;

void dfs(int x,ll k){
	ll num=2;
	for (int i = 0; i < g[x].size(); i++){
		int p = g[x][i];
		if(cnt[p]<0){
			cnt[p] = max(0LL,k-num);
			num++;
			dfs(p,k);
		}
	}
}

int main()
{
	ll n,k;
	cin>>n>>k;
	if(n==1){
		cout<<k<<endl;
		return 0;
	}
	g.resize(n,vector<ll>());
	cnt.resize(n,-1LL);
	for (int i = 0; i < n-1; i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int s = -1;
	for (int i = 0; i < n; i++){
		if(g[i].size()==1){
			s=i;
			break;
		}
	}
	cnt[s] = k;
	cnt[g[s][0]] = k-1;
	dfs(g[s][0],k);

	ll ans = 1;
	for (int i = 0; i < n; i++){
		ans *= cnt[i];
		ans %= mod;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 11136
#include<iostream>
using namespace std;
int main () {
    
    int n,m,x,c;
    
    cin >> n >> m;
    
    int amatrix[n][m] = {{0}};
    
    int bmatrix[m] = {0};
    
    
    
    for (int h1 = 0; h1 < n; h1 ++) {
        
        for (int h2 = 0; h2 < m; h2 ++) {
            
            cin >> x;
            
            amatrix[h1][h2] = x;
            
        }
        
    }
    
    for (int h3 = 0; h3 < m; h3 ++) {
        
        cin >> x;
            
        bmatrix[h3] = x;
        
    }
    
    for (int i = 0; i < n; i ++) {
        
        c = 0;
        
        for (int j = 0; j < m; j ++) {
            
            c += amatrix[i][j] * bmatrix[j];
            
        }
        
        cout << c << endl;
        
    }
    
    return 0;
    
}



Measured memory_bytes: 3120
module Main where
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  ss <- replicateM n getLine
  putStrLn $ toStr $ isShiritori ss []


isShiritori :: [String] -> [String] -> Bool
isShiritori [] _ = True
isShiritori (x:xs) [] = isShiritori xs [x] 
isShiritori (x:xs) (y:ys)
  | x `elem` y:ys = False
  | head x /= last y= False
  | otherwise = isShiritori xs $ x:y:ys
  
toStr :: Bool -> String
toStr b
  | b = "Yes"
  | not b = "No"


Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll path[300][300];
bool vis[300][300];
int main(){
    int N;
    cin>>N;
    for(int y=0;y<N;y++){
        for(int x=0;x<N;x++){
            cin>>path[y][x];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                if(path[j][k]>path[j][i]+path[i][k]){
                    cout<<-1<<endl;
                    return 0;
                }
                if(path[j][k]==path[j][i]+path[i][k] && !(i==k||i==j)){
                    vis[j][k]=true;
                }
                path[j][k]=min(path[j][k], path[j][i]+path[i][k]);
            }
        }
    }
    ll ans = 0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(j==i)continue;
            for(int k=0;k<N;k++){
                if(i==k || j==k)continue;
                if(path[i][j]+path[j][k]==path[i][k]){
                    path[i][k]=1145141919;
                    path[k][i]=1145141919;
                }
            }
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<i;j++){
            if(!vis[i][j])ans+=path[i][j];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int D = int.Parse(input[0]);
		int[] c = new int[26];
		input = Console.ReadLine().Split(' ');
		for(int i=0; i<26; i++) c[i] = int.Parse(input[i]);
		int[][] s = new int[D][];
		for(int i=0; i<D; i++)
		{
			input = Console.ReadLine().Split(' ');
			s[i] = new int[26];
			for(int j=0; j<26; j++) s[i][j] = int.Parse(input[j]);
		}
		int[] t = new int[D];
		int[][] last = new int[D][];	
		for(int i=0; i<D; i++)
		{
			last[i] = new int[26];
			for(int j=0; j<26; j++) last[i][j] = -1;
		}
		int satisfy = 0;
		for(int i=0; i<D; i++)
		{
			int maxS = s[i][0];
			int idx = 0;
			for(int j=1; j<26; j++)
			if(maxS < s[i][j])
			{
				maxS = s[i][j];
				idx = j;
			} 
			t[i] = idx;
			satisfy += s[i][t[i]];
			last[i][t[i]] = i;
			for(int j=0; j<26; j++)
			{
				if(j!=t[i] && i>0) last[i][j] = last[i-1][j];
				satisfy -= c[j] * (i - last[i][j]);
			}
		}
		Random rd = new Random();
		for(int i=0; i<1000000; i++)
		{
			int dTmp = rd.Next() % D;
			int qTmp = rd.Next() % 26;
			int qPre = t[dTmp];
			int iSatisfy = satisfy;
			iSatisfy += (s[dTmp][qTmp] - s[dTmp][qPre]);
			int lastTemp = last[dTmp][qPre];
			int nextD = dTmp;
			for(; nextD < D && dTmp == last[nextD][qPre]; nextD++) { }
			iSatisfy -= c[qPre] * (lastTemp - dTmp) * (nextD - dTmp);
			nextD = dTmp;
			for(; nextD < D && dTmp == last[nextD][qTmp]; nextD++) { }
			iSatisfy -= c[qTmp] * ((dTmp == 0 ? -1 : last[dTmp-1][qTmp]) - dTmp) * (nextD - dTmp);
			if(satisfy < iSatisfy) satisfy = iSatisfy;
			else t[dTmp] = qPre;
		}
		foreach(int ans in t) Console.WriteLine(ans + 1);
	}
}


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

#define int long long

using namespace std;



int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int D, T, S;
    cin >> D >> T >> S;

    if(D > T*S)
    {
    	cout << "No" << '\n';
    }
    else
    {
    	cout << "Yes" << '\n';
    }

    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<array>
#include<algorithm>
#include<deque>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<list>

int main(void) {
	using namespace std;
	/*int N, A,res;
	cin >> N >> A;
	res = N * N - A;
	cout << res << endl;*/

	/*int a, b,c;
	cin >> a >> b;
	c = a * b;
	c = c % 2;
	if (c == 0) {
		cout << "Even" << endl;
	}
	else if(c == 1){
		cout << "Odd" << endl;
	}*/

	/*int A, B, a, b, c;
	cin >> A >> B;
	a = A + B;
	b = A - B;
	c = A * B;
	if (a >= b && a >= c) {
		cout << a << endl;
	}
	else if (b >= a && b >= c) {
		cout << b << endl;
	}
	else if (c >= a && c >= b) {
		cout << c << endl;
	}*/

	/*int K, S,res = 0;
	cin >> K >> S;
	for (int X = 0; X <= K;X++) {
		for (int Y = 0; Y <= K; Y++) {
			for (int Z = 0; Z <= K; Z++) {
				if (X + Y + Z == S) {
					res += 1;
				}

			}
		}
	}
	cout << res << endl;*/

	/*int N,a;
	cin >> N;
	set<int>s;
	for (int i = 0; i < N;i++) {
		cin >> a;
		s.insert(a);
	}
	cout << s.size() << endl;*/

	/*int N, a, res;
	vector<int>vec;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		vec.push_back(a);
	}
	sort(vec.begin(), vec.end());
	res = vec[vec.size() - 1] - vec[0];
	cout << res << endl;*/

	int Alice = 0, Bob = 0,a,N;
	deque<int>dec;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		dec.push_back(a);
	}
	sort(dec.rbegin(), dec.rend());
	for (int i = 0; i < N;i++) {
		if (i % 2 == 0) {
			Alice += dec[0];
			dec.pop_front();
		}
		else if (i % 2 == 1) {
			Bob += dec[0];
			dec.pop_front();
		}
	}
	cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    vector<int> c1(26,0),c2(26,0);
    for(int i = 0; i < s.size(); i++){
        c1[s[i]-'a']++;
        c2[t[i]-'a']++;
    }
    sort(c1.begin(),c1.end());
    sort(c2.begin(),c2.end());
    if(c1==c2)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 776
#include <stdio.h>
#define N 100000
#define Q 50000

int main(){
  int n, q, i, count = 0, left, right, mid, S[N], T[Q];

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &S[i]);
  }

  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &T[i]);
  }

  for(i = 0; i < q; i++){
    left = 0;
    right = n;
    while(left < right){
      mid = (left + right) / 2;
      //printf("left = %d, right = %d, mid = %d, count = %d\n", left, right, mid, count);
      if(T[i] == S[mid]){
	count++;
	break;
      }
      else if(T[i] > S[mid]) left = mid + 1;
      else right = mid;
    }
  }

  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 1184
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()

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

    int nc = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int k = 2 * j - i;
            if (k >= n) break;

            if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) ++nc;
        }
    }

    auto ca = count(all(s), 'R');
    auto cb = count(all(s), 'G');
    auto cc = count(all(s), 'B');
    
    cout << ca * cb * cc - nc;
    
    return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
int main() {
    int k, x; cin >> k >> x;
    for(int i = x - (k - 1); i <= x + (k - 1); i++){
        cout << i << ' ';
    }

    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<math.h>

using namespace std;
#define lli long long int

int main(){
    lli k;
    cin>>k;
    if(k==1){
        cout<<"1\n";
        return 0;
    }
    if(k%2==0 || k%5==0){
        cout<<"-1\n";
        return 0;
    }

    if(k%7==0) k/=7;
    k*=9;

    lli a=10;
    for(int i=0;i<=10*k;i++){
        if((a-1+k)%k==0){
            cout<<i+1<<"\n";
            return 0;
        }
        a=(a*10)%k;
    }

    return 0;

}

Measured memory_bytes: 3156
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanWords)

	count := map[int]int{}

	sizeA := nextInt()
	for i := 0; i < sizeA; i++ {
		count[nextInt()]++
	}
	sizeB := nextInt()
	for i := 0; i < sizeB; i++ {
		count[nextInt()]++
	}
	// fmt.Println(count)

	keys := []int{}
	for k := range count {
		keys = append(keys, k)
	}
	sort.Ints(keys)
	for _, k := range keys {
		if count[k] == 1 {
			fmt.Println(k)
		}
	}
}



Measured memory_bytes: 31284
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

int main(){
   int N,Q;
   cin >> N >> Q;
   string s;
   cin >> s;
   vector< pair<char,char> > query;
   vector<int> pos[26];
   for(int i=0;i<N;i++){
      pos[s[i]-'A'].push_back(i+1);
   }
   for(int i=0;i<Q;i++){
      char t,d;
      cin >> t >> d;
      query.push_back(make_pair(t,d));
   }
   // search left
   int tmpl = 0;
   for(int i = Q-1; i>=0; i--){
      int t = query[i].first;
      int d = query[i].second;
      if( t==s[tmpl]&&d=='L'){
         tmpl++;
         if(tmpl==N){
            break;
         }
      }
      else if(tmpl!=0&&t==s[tmpl-1]&&d=='R'){
         tmpl--;
      }
   }
   int tmpr = 0;
   for(int i = Q-1; i>=0; i--){
      int t = query[i].first;
      int d = query[i].second;
      if( t==s[N-1-tmpr]&&d=='R'){
         tmpr++;
         if(tmpr==N){
            break;
         }
      }
      else if(tmpr!=0&&t==s[N-tmpr]&&d=='L'){
         tmpr--;
      }
   }
   int drop = min(tmpr+tmpl,N);
   cout << N-drop << endl;
   return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  int n = s.size() - 1;
  long long ans = 0;
  for (int bit = 0; bit < (1<<n); bit++) {
    vector<long long> a;
    int m = 0;
    for (int i = 1; i <= n+1; i++) {
      if(bit&(1<<(n-i)) || i==n+1) {
        long long b = stoll(s.substr(m, i-m));
        a.push_back(b);
        m = i;
      }
    }
    for (long long x : a) ans += x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define UM unordered_map
#define eps 1e-8
typedef unsigned long ul;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ul> VUL;
typedef pair<int, int> PII;
typedef double db;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//const ul MOD = 1e9 + 7;
//head


int main()
{
	int n;
	ul k;
	UM<int, int> idx;
	cin>>n>>k;
	VI tele(n+1);
	VI dest;
	rep(i,1,n+1)
		cin>>tele[i];
	int t=1,s=1;
	dest.pb(1);
	idx[1]=0;
	while(idx.find(tele[t]) == idx.end()) {
		t = tele[t];
		dest.pb(t);
		idx[t]=s++;
	}
	t=tele[t];
	int cstart = idx[t];
	if(k <= cstart)
		cout<<dest[k]<<endl;
	else {
		k -= cstart;
		cout<<dest[cstart + (k%(s-idx[t]))]<<endl;
	}
	return 0;
}


Measured memory_bytes: 12740
#include <stdio.h>
int main(void){
    int n,i,j,o,s=2000;
    long a[200];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%ld",&a[i]);
    }
    for(i=0;i<n;i++){
        o=0;
        while(a[i]%2==0){
            a[i]/=2;
            o++;
        }
        if(s>o){
            s=o;
        }
    }
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 128
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long k = Long.parseLong(sc.next());
		Map<Integer, Long> m = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			long b = Integer.parseInt(sc.next());
			if (m.get(a) != null) {
				b += m.get(a);
			}
			m.put(a, b);
		}
		long c = 0;
		for (Integer i:m.keySet()) {
			c += m.get(i);
			if (c >= k) {
				System.out.println(i);
				return;
			}
		}
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Measured memory_bytes: 108208
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,k,l,x,c=0,n;
    cin>>n;
    long long int ar[n+5];
    long long int br[n+5];
    ar[0]=0;
    br[0]=0;
    for(i=1;i<=n;i++)
    {
        cin>>ar[i];
    }
    for(i=1;i<=n;i++)
    {
        l=ar[i];
        l=l;
//        cout<<l-1<<endl;
//        cout<<l<<endl;
        br[l]=i;

    }
    for(i=1;i<=n;i++)
        cout<<br[i]<<" ";

}


Measured memory_bytes: 2432
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

class P
{
    static void Main()
    {
        int[] nkl = Console.ReadLine().Split().Select(int.Parse).ToArray();
        UnionFind road = new UnionFind(nkl[0]);
        UnionFind train = new UnionFind(nkl[0]);
        for (int i = 0; i < nkl[1]; i++)
        {
            int[] ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            road.Unite(ab[0], ab[1]);
        }
        for (int i = 0; i < nkl[2]; i++)
        {
            int[] ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            train.Unite(ab[0], ab[1]);
        }

        int[] roadd = Enumerable.Range(0, road.Size).Select(x => road.Find(x)).ToArray();
        int[] traind = Enumerable.Range(0, train.Size).Select(x => train.Find(x)).ToArray();
        //<道路グループindex,<電車グループインデックス,属してるインデックス>>
        Dictionary<int, Dictionary<int, int>> dict = new Dictionary<int, Dictionary<int, int>>();
        for (int i = 0; i < roadd.Length; i++)
        {
            if (!dict.ContainsKey(roadd[i])) dict.Add(roadd[i], new Dictionary<int, int>());
            if (!dict[roadd[i]].ContainsKey(traind[i])) dict[roadd[i]].Add(traind[i], 0);
            dict[roadd[i]][traind[i]]++;
        }
        Console.WriteLine(string.Join(" ", Enumerable.Range(0, nkl[0]).Select(x => dict[roadd[x]][traind[x]]).ToArray()));
    }
}

class UnionFind
{
    public int Size { get; private set; }
    List<int> parent;
    List<int> sizes;
    public UnionFind()
    {
        Size = 0;
        parent = new List<int>(65536);
        sizes = new List<int>(65536);
    }
    public UnionFind(int count)
    {
        Size = 0;
        parent = new List<int>(count);
        sizes = new List<int>(count);
        ExtendSize(count);
    }
    public bool Unite(int x, int y)
    {
        int xp = Find(x);
        int yp = Find(y);
        if (yp == xp) return false;
        if (sizes[xp] < sizes[yp])
        {
            var tmp = xp;
            xp = yp;
            yp = tmp;
        }
        parent[yp] = xp;
        sizes[xp] += sizes[yp];
        return true;
    }
    public IEnumerable<int> AllParents => parent.Where(x => x == parent[x]);
    public int GetSize(int x)
    {
        ExtendSize(x + 1);
        return sizes[x];
    }
    public bool IsSameGroup(int x, int y) => Find(x) == Find(y);
    public int Find(int x)
    {
        ExtendSize(x + 1);
        return parent[x] == parent[parent[x]] ? parent[x] : parent[x] = Find(parent[x]);
    }
    public void ExtendSize(int treeSize)
    {
        while (Size < treeSize)
        {
            parent.Add(Size);
            sizes.Add(1);
            Size++;
        }
    }
}

Measured memory_bytes: 72916
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

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

// to container
template <class C>
void input(C &c)
{
    for_each(c.begin(), c.end(), [](auto &i) { cin >> i; });
}

// to number, string
template <class T>
T input()
{
    T data;
    cin >> data;
    return data;
}

bool isPrime(ll n)
{
    if (n == 2)
    {
        return true;
    }
    bool res = true;
    for (int i = 2; i <= (ll)sqrt(n); i++)
    {
        if (n % i == 0)
        {
            res = false;
            break;
        }
    }

    return res;
}

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

    if (isPrime(N))
    {
        cout << N - 1 << endl;
    }
    else
    {
        ll m = (ll)pow(10, 12);
        for (ll i = 2; i <= (ll)sqrt(N); i++)
        {
            if (N % i == 0)
            {
                m = min(m, (N / i - 1) + (i - 1));
            }
        }

        cout << m << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define H 251

int main(){
  int i, id;
  int a[H];

  scanf("%d", &id);

  for(i = 1; i <= id; i++){
    scanf("%d", &a[i]);
  }

  for(i = 1; i <= id; i++){
    printf("node %d: key = %d, ", i, a[i]);
    if(i != 1){
      printf("parent key = %d, ", a[i/2]);
    }
    if(i*2+1 <= id){
      printf("left key = %d, right key = %d, ", a[i*2], a[i*2+1]);
    }else if(i*2 <= id){
      printf("left key = %d, ", a[i*2]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2056
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	static boolean prime[];
	void doIt() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		System.out.println(getGcd(n, m));
	}

	int getGcd(int n, int m) {
		int num = 1;
		for(int i = m / n; i >= 1; i--) {
			if(m % i == 0) {
				if(m / i >= n) {
					return i;
				}
			}
		}
		return num;
	}
	Main(){doIt();}
	public static void main(String[] args) {
		new Main();
	}

}


Measured memory_bytes: 23252
antenna = []
for i in range(5):
   antenna.append(int(input()))
k = int(input())
ifd = 0
for i in range(5): 
   for j in range(5):
      if((antenna[i] - antenna[j]) > k):ifd = 1
if(ifd == 0): print("Yay!")
else: print(":(")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n,sum=0,i;
cin>>n;
long long int arr[n];
for(i=0;i<n;i++){
    cin>>arr[i];
}long long int m=arr[0];
for(i=0;i<n;i++){
   if(arr[i]<m)
   sum+=(m-arr[i]);
   else
    m=arr[i];
}cout<<sum<<endl;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll a;
bool x;
int main(void){
    string s; cin>>s;
    string t; t=s;
    ll n=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='g') n++;
    }
    ll l=0,r=n,m=(l+r)/2;
    while(r-l>1){
        ll M=m;
        s=t;
        for(int i=s.size()-1;i>=0;i--){
            if(s[i]=='g'&&M>0){
                M--;
                s[i]='p';
            }
        }
        a=0;
        x=true;
        for(int i=0;i<s.size();i++){
            if(s[i]=='g'){
                a++;
            }else{
                a--;
            }
            if(a<0){
                x=false;
            }
        }
        if(x){
            l=m;
            m=(l+r)/2;
        }else{
            r=m;
            m=(l+r)/2;
        }
        //cout<<s<<" "<<x<<" "<<l<<" "<<r<<" "<<m<<endl;
    }
    cout<<l<<endl;
    
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int h, a;
    cin >> h >> a;
    
    int ans = 0;
    while (h >= 1) {
        ans++;
        h -= a;
    }
    

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

Measured memory_bytes: 256
// AOJ 2009: Area Separation
// 2017.10.30 bal4u@uu

#include <stdio.h>
#include <math.h>

#define EPS 1e-10

typedef struct { int x, y; } PP;
typedef struct { double x, y; } FPP;
typedef struct { PP p1, p2; } SEG;
SEG sg[102]; int n;
FPP pp[102]; int sz;

double dis(FPP p1, FPP p2)
{
	double dx = p1.x - p2.x;
	double dy = p1.y - p2.y;

//	return sqrt(dx*dx + dy*dy);
	return dx*dx + dy*dy;

}

int intersection(FPP *p, PP p1, PP p2, PP p3, PP p4)
{
	int t1, t2, t3, t4;
	double bo, ua;

	t1 = (p1.y-p3.y)*(p3.x-p4.x)-(p1.x-p3.x)*(p3.y-p4.y);
	t2 = (p2.y-p3.y)*(p3.x-p4.x)-(p2.x-p3.x)*(p3.y-p4.y);
	t3 = (p3.y-p1.y)*(p1.x-p2.x)-(p3.x-p1.x)*(p1.y-p2.y);
	t4 = (p4.y-p1.y)*(p1.x-p2.x)-(p4.x-p1.x)*(p1.y-p2.y);
	if ((t1 < 0 && t2 > 0 || t1 > 0 && t2 < 0) && (t3 < 0 && t4 > 0 || t3 > 0 && t4 < 0)) {
		bo = (p4.y-p3.y)*(p2.x-p1.x)-(p4.x-p3.x)*(p2.y-p1.y);
		ua = (p4.x-p3.x)*(p1.y-p3.y)-(p4.y-p3.y)*(p1.x-p3.x);
		p->x = p1.x + ua/bo * (p2.x-p1.x);
		p->y = p1.y + ua/bo * (p2.y-p1.y);
		return 1;
	} else return 0;
}

int main()
{
	int i, j, k, f, ans;
	FPP p;

	while(scanf("%d", &n) && n > 0) {
		for (i = 0; i < n; i++)
			scanf("%d%d%d%d", &sg[i].p1.x, &sg[i].p1.y, &sg[i].p2.x, &sg[i].p2.y);
		ans = 1;
		for (i = 0; i < n; i++) {
			sz = 0;
			for (j = 0; j < i; j++) {
				if (!intersection(&p, sg[i].p1, sg[i].p2, sg[j].p1, sg[j].p2)) continue;
				
				for (f = 1, k = 0; k < sz; k++) {
					if (dis(p, pp[k]) < EPS) { f = 0; break; }
				}
				if (f) pp[sz++] = p;
			}
			ans += sz + 1;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1736
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

//#define DEBUG
#ifdef DEBUG
    #define IFD(...) __VA_ARGS__
    #define IFN(...)
    #define L cout<<__LINE__<<"\n";
    #define PRINT(...) __VA_ARGS__ cout<<__LINE__<<" : "<<#__VA_ARGS__<<"\n"
    #define PRT(x) cout<<__LINE__<<" : "<<#x<<" = "<<x<<"\n"
#else // DEBUG
    #define IFD(...)
    #define IFN(...) __VA_ARGS__
    #define L
    #define PRINT(...) __VA_ARGS__
    #define PRT(x)
#endif // DEBUG

#define it iterator
#define rit reverse_iterator
#define mp make_pair
#define mems(a,b) memset(a,b,sizeof(a))
#define mem0(a) mems(a,0)
#define mem1(a) mems(a,1)
#define mem255(a) mems(a,255)
#define halt(s) cout<<s,exit(0)IFD(,cout<<"\n\nTIME: "<<runtime<<" sec\n\n")
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front
#define fort0(i,a,b) for(ll i=a,i##_TO=b;i<i##_TO;i++)
#define for0(i,n) fort0(i,0,n)
#define fort1(i,a,b) for(ll i=a,i##_TO=b;i<=i##_TO;i++)
#define for1(i,n) fort1(i,1,n)
#define ford(i,a,b) for(ll i=a,i##_TO=b;i>=i##_TO;i--)
#define loop(n) for0(LOOP_COUNTER,n)
#define runtime (clock()*1.0/CLOCKS_PER_SEC)
#define x first
#define y second

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define int ll

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

template
<
    class key,
    class val=null_type, /// null_mapped_type
    class comp=less<key>
>
using ord_set=tree /// find_by_order(), order_of_key()
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

typedef trie
<
    string,
    null_type,
    trie_string_access_traits<>,
    pat_trie_tag,
    trie_prefix_search_node_update
>
pref_trie; /// insert(), prefix_range()

template<class T,class U>
ostream&operator<<(ostream&out,pair<T,U> p)
{
    return out<<"("<<p.x<<","<<p.y<<")";
}

template<class Iter>
struct rng
{
    Iter from,to;
    rng(Iter from,Iter to):from(from),to(to){}
};

template<class Iter>
rng<Iter> range(Iter from,Iter to)
{
    return rng<Iter>(from,to);
}

template<class Iter>
ostream&operator<<(ostream&out,rng<Iter> r)
{
    out<<distance(r.from,r.to)<<":";
    for(Iter i=r.from;i!=r.to;i++)
        out<<" "<<*i;
    return out;
}

ll ppow(ll x,ll y,ll mod)
{
    ll res=1;
    while(y)
    {
        if(y&1)
            res=res*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return res;
}

signed main()
{
    IFN
    (
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    )

    int a,b,c;
    cin>>a>>b>>c;
    cout<<(max({a,b,c})-min({a,b,c}))<<"\n";

    IFD(cout<<"\n\nTIME: "<<runtime<<" sec\n\n";)
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int mod=inf;

il void inc(int &x,const int &y){if((x+=y)>=mod) x-=mod;}

int f[2][20][1<<20];
int cons[21][21];
int n,m,k;

il int lowbit(const int &x){
	return x&-x;
}

il int newsta(const int &comb,const int &i){
	return comb^(1<<i)^lowbit((comb>>i)<<i);
}

int main(){
//	fileio("test");
	scanf("%d%d%d",&n,&m,&k),--n;
	memset(cons,-1,sizeof(cons));
	while(k--){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c),--b;
		cons[a][b]=c;
	}
	f[1][0][0]=1;
	rep(i,1,m){
		int c=i&1;
		memset(f[c^1],0,sizeof(f[c^1]));
		rep0(j,n) rep0(comb,1<<n){
			int &cur=f[c][j][comb];
			if(!cur) continue;
			if(comb>>j&1){
				if(cons[i][j]==0) continue;
				inc((j==n-1?f[c^1][0]:f[c][j+1])[comb],cur);
			}else{
				if(cons[i][j]!=1){
					inc((j==n-1?f[c^1][0]:f[c][j+1])[comb],cur);
				}
				if(cons[i][j]!=0){
					inc((j==n-1?f[c^1][0]:f[c][j+1])[newsta(comb,j)],cur);
				}
			}
		}
	}
	int c=m&1^1,ans=0;
	rep0(comb,1<<n) inc(ans,f[c][0][comb]);
	printf("%d\n",ans);
//	cerr<<(dbl)clock()/CLOCKS_PER_SEC<<endl;
	return 0;
} 

Measured memory_bytes: 164224
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#define MAX 100000007
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

ll ans=0;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  ll K;
  cin >> S >> K;
  for(int i=0;i<K-1;i++){
    if(S[i] != '1'){
      cout << S[i] << endl;
      return 0;
    }
  }
  cout << S[K-1] << endl;
  return 0;
}


Measured memory_bytes: 256