akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int c1, c2, c3;
		int count;
		
		while (sc.hasNext()) {
			c1 = sc.nextInt();
			c2 = sc.nextInt();
			c3 = sc.nextInt();
			count = 0;
			
			for (int i = 1; i <= 10 && i + c1 + c2 <= 20; i++) {
				if (i != c1 && i != c2 && i != c3) {
					count++;
				}
			}
			if (4 <= count) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 12000
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // get a integer
        int n = sc.nextInt();
        int[] as = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            as[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 1; i <= n; i++) {
            int as_i = as[i];
            if (as_i > i && as[as_i] == i) {
                count++;
            }
        }
        // output
        System.out.println(count);
    }

}

Measured memory_bytes: 31560
// BROWNIE TK
 
#include <bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
 
#define forz(i, n) for (int i = 0; i < n; i++)
#define bui(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define mui(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
 
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define osetlli tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

using namespace std;
 
/*STD fucntions*/
lli power(lli x,lli y,lli p)
{
    lli res=1;
    x=x%p;
    while(y>0)
    {
        if(y&1)
            res=(res*x)%p;
        //y must be even now
        y=y>>1; //y=y/2
        x=(x*x)%p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{ return a * b / gcd(a, b); }
lli modi(lli a,lli m)
{
// fermat little thm where m is prime
return power(a,m-2,m);
}
/*CODE BEGINS*/
int main()
{
 kira;
 lli h,w;
 cin>>h>>w;
 char a[h][w];
 lli dp[h][w];
 forz(i,h)
 {
   forz(j,w)
   {
     cin>>a[i][j];
     if(a[i][j]=='#')dp[i][j]=0;
    // cout<<a[i][j]<<" ";
   }
   //cout<<endl;
 }
 dp[0][0]=1;
 for(int i=1;i<h;i++)
 {
   if(a[i][0]=='.')
   dp[i][0]=dp[i-1][0];
 }
 for(int i=1;i<w;i++)
 {
   if(a[0][i]=='.')
   dp[0][i]=dp[0][i-1];
 }
 for(int i=1;i<h;i++)
 {
   for(int j=1;j<w;j++)
   {
     if(a[i][j]=='.')
     dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
   }
 }
 cout<<dp[h-1][w-1];
 return 0;
}


Measured memory_bytes: 9088
def GCD(a, b):
    if b == 0:
        return a
    else:
        return GCD(b, a % b)

def LCM(a, b):
    return a // GCD(a, b) * b

def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    for a in A:
        ans = GCD(ans, a)
    print(ans)

    return 0


if __name__ == '__main__':
    main()

Measured memory_bytes: 14224
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
n = II()
print((1000-(n%1000))%1000)

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

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

const ll INF = 1LL << 60;
const int MOD = 1000000007;

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    string s; cin >> s;
    int n = s.size() - 1;

    const char op_c[] = {'-', ' ', '+'};

    for(ll bit = 0; bit < (1 << n); ++bit){
        vector<int> op(n);
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                op[i] = 1;
            }else{
                op[i] = -1;
            }
        }
        int ans = (int)(s[0] - '0');
        for(int i = 1; i < s.size(); ++i){
            ans += (int)(s[i] - '0') * op[i - 1];
        }
        if(ans == 7){
            cout << s[0] << op_c[op[0] + 1] << s[1] << op_c[op[1] + 1] << s[2] << op_c[op[2] + 1] << s[3] << "=7" << endl;
            return 0;
        }
    }
    cout << "false" << endl;
    return 0;
}



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

using namespace std;

typedef long long int ll;
#define REP(i, I, N) for (int i = I; i < N; ++i)
#define rep(i, N) REP(i, 0, N)

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

    vector<vector<int>> vec(M);
    cout << endl;
    rep(i, M) {
        int k;
        cin >> k;
        vec[i].resize(k);
        rep(j, k) {
            cin >> vec[i][j];
            --vec[i][j];
        }
    }

    vector<int> p(M);
    rep(i, M) cin >> p[i];
    int ans = 0;
    rep (i, 1 << N) {
        bool ok = true;
        rep(j, M) {
            int c = 0;
            for (int id: vec[j]) {
                if ((i >> id) & 1) ++c;
            }
            c %= 2;
            if (c != p[j]) ok = false;
        }
        if (ok) ++ans;
    }

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

    int h;
    cin >> h;

    int cnt = 1;
    int ans = 0;
    while(h > 0){
        ans += cnt;
        cnt *= 2;
        h /= 2;
    }
    cout << ans << endl;

    
    
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc153.contest.atcoder.jp/tasks/abc153_b

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

int main() {
  int D,x;
  cin >> D;
  vector<int> c(26);
  vector<int> last(26);
  for (int i=0;i<26;i++) {
    cin >> c.at(i);
  }
  vector<vector<int>> s(D,vector<int>(26));
  for (int i=0;i<D;i++) {
    for (int j=0;j<26;j++) {
      cin >> s.at(i).at(j);
    }
  }
  for (int i=0;i<D;i++) {
    x=rand();
    cout << x%26+1 << endl;
  }
}

Measured memory_bytes: 3680
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	string s, t;
	cin >> s;
	cin >> t;

	vector<int> ch1(100, 0), ch2(100, 0);
	vector<vector<int>> iti(100,vector<int>());
	for (int i = 0; i < t.size(); i++)
	{
		ch2[t[i] - 'a']++;
	}
	for (int i = 0; i < s.size(); i++)
	{
		ch1[s[i] - 'a']++;
		iti[s[i] - 'a'].push_back(i + 1);
	}

	for (int i = 0; i < 100; i++)
	{
		iti[i].push_back(-1);
	}

	for (int i = 0; i < 100; i++)
	{
		if (ch2[i] != 0 && ch1[i] == 0)
		{
			cout << -1 << endl;
			return 0;
		}
	}

	long long ans = 0;
	long long poi;
	ans += iti[t[0]-'a'][0];
	poi = iti[t[0] - 'a'][0];
	vector<int> imadoko(100, 0);
	if (iti[t[0] - 'a'][1] != -1)
		imadoko[t[0] - 'a']++;
	for (int i = 1; i < t.size(); i++)
	{
		for (int j = imadoko[t[i]-'a']; j < iti[t[i] - 'a'].size(); j++)
		{
			if (poi < iti[t[i] - 'a'][j])
			{
				ans += iti[t[i] - 'a'][j] - poi;
				poi = iti[t[i] - 'a'][j];
				if (iti[t[0] - 'a'][j + 1] != -1)
					imadoko[t[i] - 'a']++;
				else
					imadoko[t[i] - 'a'] = 0;
				break;
			}
			if (j == iti[t[i] - 'a'].size() - 1)
			{
				ans += s.size() - poi + iti[t[i] - 'a'][0];
				poi = iti[t[i] - 'a'][0];
				for (int k = 0; k < 100; k++)
				{
					imadoko[k] = 0;
				}
			}

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


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

const int MAX = 100100;

vector<int> memo(MAX, -1);

int solve(int n) {
    if(n == 0) return 0;
    if(memo[n] != -1) return memo[n];

    int res = n;
    for(int i=1;i<=n;i*=6) res = min(res, solve(n-i)+1);

    for(int i=9;i<=n;i*=9) res = min(res, solve(n-i)+1);

    return memo[n]=res;
}
int main() {
    int N;
    cin >> N;
    cout << solve(N) << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int 
int c=0;

 int main()
 {
     int n;
     cin>>n;
     int arr[n];
     arr[0]=0;
     for(int i=1;i<=n;i++)
     {
        int x;
        cin>>x;
        arr[i]=x;
     }
     int k=1;
     int f=0;
    for(int i=1;i<=n;i++)
    {
        if(arr[i] ==k)
        {
           f=1;
            k++;
        }
        else 
        c++;
            
    }
    if(f==0)
    {
        cout<<"-1";
    }
    else 
    cout<<c;
     
     
     
     
 }

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

using namespace std;

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

    vector<int> sv(0);
    for (int i = 1, l = 0; i <= static_cast<int>(s.size()); i++) {
        if (i == static_cast<int>(s.size()) || s[l] != s[i]) {
            sv.push_back(i - l);
            l = i;
        }
    }

    int cnt = 0;
    while (static_cast<int>(sv.size()) >= 2) {
        if (sv[0] < sv[1]) {
            cnt += 2 * sv[0];
            sv[1] -= sv[0];
            sv.erase(sv.begin());
        } else if (sv[0] == sv[1]) {
            cnt += 2 * sv[0];
            sv.erase(sv.begin());
            sv.erase(sv.begin());
        } else {
            cnt += 2 * sv[1];
            sv[0] -= sv[1];
            sv.erase(sv.begin() + 1);

            if (sv.size() >= 2) {
                sv[0] += sv[1];
                sv.erase(sv.begin() + 1);
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define For(i,x,y) for(int i=x; i<y; ++i)
#define mem(x,y) memset(x,y,sizeof(x))
#define ALL(a) a.begin(),a.end()
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define DOF 0x7f7f7f7f
#define se second
#define fi first
#define endl '\n'
 
template <typename T>
inline void read(T &r){
    static char c; r=0; int f=1;
    for(c=getchar(); c<'0'||c>'9'; c=getchar()) if(c=='-')f=-1;
    for(; c>='0'&&c<='9'; r=(r<<1)+(r<<3)+(c^48),c=getchar());
    r*=f;
} // -_- 
 
const int N = 10;
int a[N],b[N],c[N];
int main(){
    int n; cin>>n;
    for(int i = 0; i < n; ++i) c[i] = i+1;
    for(int i = 0; i < n; ++i) cin>>a[i];
    for(int i = 0; i < n; ++i) cin>>b[i];
    int l = -1, r = -1, idx = 1;
    do{
        int f1 = 1, f2 = 1;
        for(int i = 0; i < n; ++i){
            if(c[i]!=a[i]) f1 = 0;
            if(c[i]!=b[i]) f2 = 0;
        }
        if(f1) l = idx;
        if(f2) r = idx;
        if(l != -1 && r != -1) break;
        ++idx;
    }while(next_permutation(c, c + n));
    cout<<abs(l - r)<<endl;
    // system("pause");
}

Measured memory_bytes: 256
<?php

fscanf(STDIN,"%d",$n);
$line = explode(" ", trim(fgets(STDIN)));

$cnt = 1;
$min = $line[0];
for($i=1; $i<$n; $i++){
    if($line[$i] < $min){
        $cnt++;
        $min = $line[$i];
    }
}

echo $cnt;

Measured memory_bytes: 18932
package main

import (
        "fmt"
)

func solution(a, b, c int) string {
        for i := 1; i < b+1; i++ {
                if i*a%b == c {
                        return "YES"
                }
        }
        return "NO"
}

func main() {
        var a, b, c int
        fmt.Scan(&a, &b, &c)
        fmt.Println(solution(a, b, c))
}

Measured memory_bytes: 512
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    n4 = 0
    n2 = 0
    for a in A:
        if a % 4 == 0:
            n4 += 1
        elif a % 2 == 0:
            n2 += 1

    if n4 >= N//2:
        return 'Yes'
    elif n2 >= 2 and n4 >= (N - n2 + 1) // 2:
        return 'Yes'
    else:
        return 'No'


if __name__ == '__main__':
    print(main())


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


int main() {
  int n; cin >> n;
  vector<int> pos(n);
  for (int i = 0; i < n; ++i) cin >> pos[i];
  sort(pos.begin(), pos.end());
  cout << pos[n - 1] - pos[0] << endl;
	return 0;
}


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

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

  int ans = 0;
  for (int i = 0; i < 8; i++) {
    int power = pow(2, i);
    if (power <= N) {
      ans = power;
    }
  }

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

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N + 1];
        int[] B = new int[N];

        for (int i = 0; i < N + 1; i++) {
            A[i] = sc.nextInt();
        }
        for (int i = 0; i < N; i++) {
            B[i] = sc.nextInt();
        }

        long sum = 0;
        int carry = 0;
        for (int i = 0; i < N + 1; i++) {
            if (A[i] >= carry) {
                A[i] -= carry;
                sum += carry;
            } else {
                sum += A[i];
                A[i] = 0;
            }

            if (i == N) {
                break;
            }

            if (B[i] > A[i]) {
                int diff = B[i] - A[i];
                sum += A[i];
                carry = diff;
            } else {
                sum += B[i];
                carry = 0;
            }
        }

        System.out.println(sum);
        return;
    }

}

Measured memory_bytes: 64716
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	int n = s.length(),m=t.length();
	vector<vector<int> > dp(n,vector<int>(m,0));
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(i==0&&j==0){
				dp[i][j] = ((s[i]==t[j])?1:0);
			}
			else if(i==0){
				dp[i][j] = ((s[i]==t[j])?1:dp[i][j-1]);
			}
			else if(j==0){
				dp[i][j] = ((s[i]==t[j])?1:dp[i-1][j]);
			}
			else{
				dp[i][j] = ((s[i]==t[j])?1+dp[i-1][j-1]:max(dp[i][j-1],dp[i-1][j]));
			}
		}
	}
	string ans = "";
	int i=n-1,j=m-1;
	while(i>=0&&j>=0){
		if(s[i]==t[j]){
			ans += s[i];
			i--;j--;
		}
		else{
			if(i==0){
				j--;
			}
			else if(j==0){
				i--;
			}
			else if(dp[i-1][j]>dp[i][j-1]){
				i--;
			}
			else{
				j--;
			}
		}
	}
	reverse(ans.begin(),ans.end());
//	cout<<dp[n-1][m-1]<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 35584
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    if (A + B > N + 1) {
        write(-1);
        return 0;
    }
    else if (B < (N + A - 1) / A || A < (N + B - 1) / B) {
        write(-1);
        return 0;
    }

    bool reverse = A < B;
    if (reverse) swap(A, B);

    // A >= B
    vector<int> a(A);
    rep(i, A) a[i] = i + 1;

    vv<int> b(A);
    int n = A + 1;
    for (int i = 0; i < A; ++i) {
        for (int j = 0; j < B - 1 && n <= N; ++j) {
            b[i].push_back(n++);
        }
    }

    vector<int> ans(N);
    int index = 0;
    for (int i = 0; i < A; ++i) {
        for (int j = b[i].size() - 1; j >= 0; --j) {
            ans[index++] = b[i][j];
        }
        ans[index++] = a[i];
    }

    if (reverse) {
        for (int& n : ans) n = N - n + 1;
    }

    for (int i = 0; i < N; ++i) {
        cout << ans[i] << (i == N - 1 ? '\n' : ' ');
    }
}

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

typedef long long ll;

using namespace std;
int main(){
    int N;
    cin >> N;
    int A[N+1] = {};
    ll sum = 0;
    for (int i = 1; i <= N; i++) {
    	cin >> A[i];
    	sum += A[i];
    }
    int M[N+1] = {};
    // M[1] を求める
    M[1] = sum;
    for (int i = 2; i < N; i += 2) {
    	M[1] -= 2 * A[i];
    }

    // M[i+1] = 2*A[i] - M[i] の漸化式が成り立つので、前から求める
    for (int i = 1; i <= N; i++) {
    	M[i+1] = 2 * A[i] - M[i];
    }

    for (int i = 1; i <= N; i++) {
	    cout << M[i] << " ";	
    }

}


Measured memory_bytes: 2048
until (n = gets.to_i).zero?
  arr = Array.new(n + 1, Array.new(n + 1, 0))
  
  n.times do |i|
    arr[i] = gets.split.map(&:to_i).push(0)
    
    n.times do |j|
      arr[i][n] += arr[i][j]
    end
  end
  
  (n + 1).times do |i|
    str = ""
    
    (n + 1).times do |j|
      arr[n][i] += arr[j][i] unless j == n
      str += sprintf("%5d", arr[i][j])
    end
    
    puts str
  end
end

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

int main(){

    int n,a,b;
    cin >> n >> a >> b;
    
    int ans1,ans2,ans3;
    ans1 = a*n;
    ans2 = b;
    if(ans1>ans2)ans3 = ans2;
    else ans3 = ans1;

    cout <<ans3 <<endl;
  
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
#include<map>
#include<string>
using namespace std;

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

struct Data{
	int y, x;
	Data(){}
	Data(int _y, int _x){
		y = _y; x = _x;
	}
};

int fld[100][100];

void PaintFld(int c, int y, int x, int h, int w){
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			fld[y+i][x+j] = c;
		}
	}
}

int main(){
	int W, H;
	while(cin >> W >> H, W || H){
		fill_n( (int*)fld, 100*100, 0 );
		int Xs, Ys, Xg, Yg, N, C, D, X, Y;
		cin >> Xs >> Ys >> Xg >> Yg >> N;
		Xs--; Ys--; Xg--; Yg--;
		for(int i = 0; i < N; i++){
			cin >> C >> D >> X >> Y;
			X--; Y--;
			if(D == 0) PaintFld(C, Y, X, 2, 4);
			else PaintFld(C, Y, X, 4, 2);
		}

		queue<Data> q;
		Data q_front;
		bool memo[100][100] = {}, ans = false;
		q.push( Data(Ys, Xs) );
		while( !q.empty() ){
			q_front = q.front(); q.pop();

			if( fld[q_front.y][q_front.x] == 0 ||
				fld[q_front.y][q_front.x] != fld[Ys][Xs] )
				continue;

			if(q_front.y == Yg && q_front.x == Xg){
				ans = true; break;
			}

			if(memo[q_front.y][q_front.x]) continue;
			memo[q_front.y][q_front.x] = true;

			for(int i = 0; i < 4; i++){
				int ny = q_front.y + dy[i];
				int nx = q_front.x + dx[i];
				if(ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
				q.push( Data(ny, nx) );
			}
		}
		
		if(ans) puts("OK");
		else puts("NG");
	}
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

signed main(){
  int X, K, D;
  cin >> X >> K >> D;
  X = abs(X);
  if( X/D > K ){
    cout << abs(X - D*K) << endl;
  }else{
    int now = X - (X/D)*D;
    K -= X/D;
    if( K%2 == 1 ) cout << min(abs(now-D), now+D) << endl;
    else cout << now << endl;
  }
}


Measured memory_bytes: 3632
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
n = int(input())
b=[]
for i in range(n):
    c = int(input())
    b.append(c)
ref = [[0]*3 for i in range(3)]
for i in b:
    if i in a1:
        j = a1.index(i)
        ref[0][j] = 1
    elif i in a2:
        j = a2.index(i)
        ref[1][j] = 1
    elif i in a3:
        j = a3.index(i)
        ref[2][j] = 1
    else: pass

if sum(ref[0])==3 or sum(ref[1])==3 or sum(ref[2])==3:
    print("Yes")
elif ref[0][0]+ref[1][0]+ref[2][0]==3:
    print("Yes")
elif ref[0][1]+ref[1][1]+ref[2][1]==3:
    print("Yes")
elif ref[0][2]+ref[1][2]+ref[2][2]==3:
    print("Yes")
elif ref[0][0]+ref[1][1]+ref[2][2]==3:
    print("Yes")
elif ref[0][2]+ref[1][1]+ref[2][0]==3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
def main():
    n = int(input())
    arr = list(map(int, input().split()))
    if 0 in arr:
        print(0)
        return
    prod = 1
    for x in arr:
        prod *= x
        if prod > int(1e18):
            print(-1)
            return
    print(prod)

if __name__ == "__main__":
    main()

Measured memory_bytes: 21676
//79B
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    long L[2], tmp=0, n;
    cin >> n;
    L[0] =2;
    L[1] =1;
    rep(i, n-1){
        //cout << L[0] + L[1] << endl;
        tmp = L[0] + L[1];
        L[0] =L[1];
        L[1] = tmp;
        
        
    }
    if(n==1){
        cout << 1 << endl;
    }else{
        cout << tmp << endl;
    }
    
}

Measured memory_bytes: 256
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*; 
import java.util.*;
import java.util.regex.*;

/*
		  br = new BufferedReader(new FileReader("input.txt"));
		  pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
		  br = new BufferedReader(new InputStreamReader(System.in));
		  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int qq = 1;
		//int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++)	{
			String s = nextToken();
			int k = readInt();
			TreeSet<String> all = new TreeSet<>();
			for(int i = 0; i < s.length(); i++) {
				for(int j = i+1; j <= i+k && j <= s.length(); j++) {
					all.add(s.substring(i, j));
				}
			}
			while(k-- > 1) {
				all.remove(all.first());
			}
			pw.println(all.first());
		}
		exitImmediately();
	}

	private static void exitImmediately() {
		pw.close();
		System.exit(0);
	}

	private static long readLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private static double readDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private static String nextLine() throws IOException  {
		String s = br.readLine();
		if(s == null) {
			exitImmediately();
		}
		st = null;
		return s;
	}

	private static String nextToken() throws IOException  {
		while(st == null || !st.hasMoreTokens())  {
			st = new StringTokenizer(nextLine().trim());
		}
		return st.nextToken();
	}
}

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

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

int main(void) {
	int n; cin >> n;
	string s; cin >> s;
	vector<int> sum(n + 2, 0);

	rep(i, n) sum[i + 1] = (s[i] == 'E') ? 1 : 0;
	rep(i, n + 1) sum[i + 1] += sum[i];
	// rep(i, n + 1) printf("%d ", sum[i]);
	// printf("\n");

	int ans = 1e9;
	rep(i, n) {
		int leftE = sum[i] - sum[0];
		int leftW = i - leftE;
		int rightE = sum[n] - sum[i + 1];
		int rightW = (n - i - 1) - rightE;
		// printf("i%d %d %d %d %d\n", i, leftE, leftW, rightE, rightW);
		ans = min(ans, leftW + rightE);
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

const int nMax = 200005;

int n, a[nMax];
long long difMax = 0, k;

int main(){
//    freopen("date.in", "r", stdin);
//    freopen("date.out", "w", stdout);
    cin >> k >> n;

    long long sum = 0;
    for (int i=1; i<=n; i++){
        cin >> a[i];
    }
    for (int i=1; i<=n; i++){
        long long dif = 0;
        if (i>1) dif = a[i]-a[i-1];
        else dif = k-a[n]+a[1];

        sum += dif;
        if (dif>difMax){
            difMax = dif;
        }
    }
    cout << sum-difMax;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>

#define INF (1<<29)

using namespace std;

int main(void){

  int n,m,p,a,b,x,y,z,in;
  double dp[(1<<8)][31],graph[31][31];
  vector<int>t;

  while(cin >> n >> m >> p >> a >> b){
    if(!(n|m|p|a|b))break;
    
    t.clear();

    for(int i=0;i<31;i++){
      for(int j=0;j<31;j++)graph[i][j]=-1;
      graph[i][i]=0;
    }
    
    for(int i=0;i<(1<<8);i++)
      for(int j=0;j<31;j++)dp[i][j]=INF;
    
    for(int i=0;i<n;i++){
      cin >> in;
      t.push_back(in);
    }

    for(int i=0;i<p;i++){
      cin >> x >> y >> z;
      graph[x][y]=graph[y][x]=z;
    }

    dp[0][a]=0;
    double res=INF;
    for(int S=0;S<(1<<8);S++){
      res=min(res,dp[S][b]);
      for(int v=1;v<=m;v++){
	for(int i=0;i<n;i++){
	  if(!(S>>i & 1)){
	    for(int u=1;u<=m;u++){
	      if(graph[v][u]>=0){
		dp[S|(1<<i)][u]=min(dp[S|(1<<i)][u],dp[S][v]+graph[v][u]/t[i]);
	      }
	    }
	  }
	}
      }
    }
    if(res==INF)printf("Impossible");
    else printf("%.3f",res);
    cout << endl;
  }

  return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    ll ans = 0;
    REP(i, S.length()) {
        if (S[i] != T[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3748
N,K,S = map(int, input().split())

sa = N-K+1
a = [1 for i in range(N)]
if S-sa+1 >0:
        
    a[0] = S - sa + 1

    for i in range(1,sa):
        if i < N:
    
            a[i] = 1
    j = 0
    for i in range(sa,N):
        a[i] = a[j]

        j +=1
        j %= sa

    for x in a:
        print(x, end = " ")


else:
    for i in range(K):
        a[i] = S
    if S != 10**9:    
        for i in range(K,N):
            a[i] = 10**9
    else:
        for i in range(K,N):
            a[i] == 10**9 -1
    for x in a:
        print(x, end = " ")

Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int64_t N, x, ans = 0;
    cin >> N >> x;
    vector<int64_t> A(N), B(N - 1);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < N - 1; i++) {
        B.at(i) = A.at(i) + A.at(i + 1);
    }
    for (int i = 0; i < N - 2; i++) {
        if (B.at(i) >= x) {
            ans += B.at(i) - x;
            B.at(i + 1) -= min(B.at(i) - x, A.at(i + 1));
        }
    }
    if (B.at(N - 2) >= x) {
        ans += B.at(N - 2) - x;
    }
    cout << ans << endl;
}


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


int main()
{
	int i, j, k, l, m;
	long long int K;
	cin >> K;
	long long int ans[50];
	cout << "50" << endl;
	for (i = 0; i < K%50; i++) {
		cout << 99 - K % 50 + K / 50 << " ";
	}
	for (i = K % 50; i < 50; i++) {
		cout << 49 - K % 50 + K / 50 << " ";
	}
    return 0;
}



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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == t[i])
			continue;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

//!

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

class sol{
    public:
    long b,w;
};
#define MOD 1000000007
#define N 100005
vector<int> v[N];
sol dp[N];

void dfs(int i, int p){
    dp[i].b=1;
    dp[i].w=1;
    for(auto x: v[i]){
        if(x==p) continue;
        dfs(x,i);
        dp[i].w*= (dp[x].w+dp[x].b)%MOD;
        dp[i].b*= dp[x].w;
        dp[i].w%= MOD;
        dp[i].b%=MOD;
    }
}
int main(){
    int n;
    cin >> n;
    int x, y;
    for(int i=0;i<n-1;i++){
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1,1);
    long ans= dp[1].b+dp[1].w;
    ans%=MOD;
    cout << ans << endl;
}

Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin>>n;
   int a[3];
   int x,y,z;
   a[0]=0;
   a[1]=0;
   a[2]=0;
long long ans=0;
    for(int i=0;i<n;i++){
        cin>>x>>y>>z;
       x+=max(a[1],a[2]);
       y+=max(a[0],a[2]);
       z+=max(a[0],a[1]);
       a[0]=x;
       a[1]=y;
       a[2]=z;
    }


ans=max(x,max(y,z));
cout<<ans;

    return 0;
}

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

int main() {

  int i, j, len, count = 0, m, n;
  char s[201], h[101], t[201];

  while(1) {
    scanf("%s",s);
    len = strlen(s);
    if(s[0] == '-') break;
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
      scanf("%d", &n);
      //printf("%s -> ", s);
      for(j = 0; j < len - n; j++) {
	t[j] = s[n+j];
	//printf("(%d, %d) ", j, n+j);
      }
      //printf("\n");
      for(j = 0; j < n; j++) {
	t[len - n + j] = s[j];
	//printf("(%d, %d) ", len-n+j, j);
      }
      //printf("\n");
      for(j = 0; j < len; j++) {
	s[j] = t[j];
      }
    }

    for(i = 0; i < len; i++) {
      printf("%c",t[i]);
    }
    printf("\n");
  }      

  return 0;
}

Measured memory_bytes: 568
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        long W = sc.nextLong();

        if (W == 1 || H == 1) {
            System.out.println(1);
            return;
        }


        long first = W % 2 == 1 ? W / 2 + 1 : W / 2;
        long second = (W - 1) % 2 == 1 ? (W - 1) / 2 + 1 : (W - 1) / 2;

        long fr = H % 2 == 1 ? H / 2 + 1 : H / 2;
        long sr = (H - 1) % 2 == 1 ? (H - 1) / 2 + 1 : (H - 1) / 2;

        System.out.println(fr * first + sr * second);
    }
}

Measured memory_bytes: 21716
import math
import sys

input = sys.stdin.readline


def main():
    bingo = [list(map(int, input().split())) for _ in range(3)]
    for _ in range(int(input())):
        n = int(input())
        for i in range(3):
            for j in range(3):
                if bingo[i][j] == n:
                    bingo[i][j] = True

    ret = False
    for i in range(3):
        is_break = False
        for j in range(3):
            if bingo[i][j] is not True:
                is_break = True
                break
        if not is_break:
            ret = True
            break

    if ret is True:
        print('Yes')
        return

    for i in range(3):
        is_break = False
        for j in range(3):
            if bingo[j][i] is not True:
                is_break = True
                break
        if not is_break:
            ret = True
            break

    if ret is True:
        print('Yes')
        return

    if bingo[0][0] is True and bingo[1][1] is True and bingo[2][2] is True:
        print('Yes')
        return

    if bingo[0][2] is True and bingo[1][1] is True and bingo[2][0] is True:
        print('Yes')
        return

    print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

h1,m1,h2,m2,k = NextInts()

x1 = h1*60 + m1
x2 = h2 * 60 + m2

print(x2-x1-k)


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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k;
    string s;
    cin >> k >> s;
    if ((int)s.size() > k) {
        s = s.substr(0, k);
        s += "...";
    }
    cout << s << '\n';
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
using namespace std;
void change(string);
int timecal(int,int);
int h,m;
int main(){
  int n,MM,lrate,ldsum,lok,drate,ddsum,dok,mrate,mdsum,mok,ljudge,djudge,mjudge,i;
  string str;
  while(1){
    cin >> n;
    if(n==0) break;
    lrate=ldsum=lok=drate=ddsum=dok=mrate=mdsum=mok=0;
    for(i=0;i<n;i++){
      cin >> str >> MM;
      change(str);
      if(h==0) h=24;
      if(h==1) h=25;
      if(11<=h&&h<=14){
	ldsum++;
	ljudge=timecal(m,MM);
	if(ljudge<=8) lok++;
      }
      else if(18<=h&&h<=20){
	ddsum++;
	djudge=timecal(m,MM);
	if(djudge<=8) dok++;
      }
      else if(21<=h&&h<=25){
	mdsum++;
	mjudge=timecal(m,MM);
	if(mjudge<=8) mok++;
      }
    }
    if(ldsum!=0) lrate=1.0*lok/ldsum*100;
    if(ddsum!=0) drate=1.0*dok/ddsum*100;
    if(mdsum!=0) mrate=1.0*mok/mdsum*100;
    if(ldsum!=0) cout << "lunch " << lrate << endl;
    else cout << "lunch no guest" << endl;
    if(ddsum!=0) cout << "dinner " << drate << endl;
    else cout << "dinner no guest" << endl;
    if(mdsum!=0) cout << "midnight " << mrate << endl;
    else cout << "midniget no guest" << endl;
  }
  return 0;
}
void change(string s){
  int i,x=1;
  h=0;
  m=0;
  for(i=0;i<5;i++){
    if(0<=i&&i<=1){
      h=x*h+(s[i]-'0');
      x*=10;
      if(i==1) x=1;
    }
    else if(3<=i&&i<=4){
      m=x*m+(s[i]-'0');
      x*=10;
    }
  }
}
int timecal(int m,int MM){
  int ret;
  if(m<=MM) ret=MM-m;
  else{
    MM+=60;
    ret=MM-m;
  }
  return ret;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	ll cnt[2]={0,0};
	rep(i, s.size()){
		cnt[s[i]-'0']++;
	}
	cout << 2*min(cnt[0], cnt[1]) << endl;
	return 0;
}

Measured memory_bytes: 640
from collections import deque

def solve():
    ret = 0
    A.sort(reverse=True)
    stack = deque()
    for a in A:
        if not stack:
            stack.append(a)
            continue
        ret += stack.popleft()
        stack.extend([a, a])
    print(ret)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    solve()

Measured memory_bytes: 32512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

ll C[51][51];

void comb_table(int N) {
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0 || j == i) {
                C[i][j] = 1LL;
            } else {
                C[i][j] = C[i-1][j-1] + C[i-1][j];
            }
        }
    }
}

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

    int n, a, b;
    cin >> n >> a >> b;
    ll v[n];
    for (int i = 0; i < n; i++) cin >> v[i];

    sort(v, v+n, greater<ll>());

    ll sm = 0LL;
    for (int i = 0; i < a; i++) sm += v[i];
    cout.precision(20);
    cout << fixed << (double)sm / (double)a << "\n";

    int candidate=0, needed=0;
    for (int i = a; i < n; i++) {
        if (v[i] != v[a-1]) break;
        candidate++;
    }
    for (int i = a-1; i >= 0; i--) {
        if (v[i] != v[a-1]) break;
        candidate++;
        needed++;
    }

    comb_table(n);

    if (v[0] != v[a-1]) {
        cout << C[candidate][needed];
    } else {
        ll ans = 0LL;
        for (int i = a; i <= min(b, candidate); i++) {
            ans += C[candidate][i];
        }
        cout << ans;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

const double pi = acos(-1);
int n;
vector<pair<double, double>> ans;

void koch(pair<double, double> s, pair<double, double> t, int k) {
    using P = pair<double, double>;
    if (k == n) {
        ans.pb(s);
        return;
    }
    double sx = s.fi, sy = s.se, tx = t.fi, ty = t.se;
    double lx = (2*sx + tx)/3, ly = (2*sy + ty)/3, rx = (sx + 2*tx)/3, ry = (sy + 2*ty)/3;
    double mx = (rx - lx) * cos(pi/3) - (ry - ly) * sin(pi/3) + lx;
    double my = (rx - lx) * sin(pi/3) + (ry - ly) * cos(pi/3) + ly;
    koch(s, P(lx, ly), k+1);
    koch(P(lx, ly), P(mx, my), k+1);
    koch(P(mx, my), P(rx, ry), k+1);
    koch(P(rx, ry), t, k+1);
}

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

    cin >> n;
    pair<double, double> s(0, 0), t(100, 0);
    koch(s, t, 0);
    ans.pb(t);
    cout << fixed << setprecision(15);
    rep(i, sz(ans)) {
        cout << ans[i].fi << " " << ans[i].se << endl;
    }
}



Measured memory_bytes: 3384
//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define int long long
#define ll long long
#define str string
#define db double
#define ac() cout<<"Yes"<<endl;
#define wa() cout<<"No"<<endl;
#define ddd cout<<"---debug---"<<endl;
#define ff(a,b) for(signed long long (a)=1;(a)<=(b);(a)++)
#define fff(a,b) for(signed long long (a)=0;(a)<(b);(a)++)
#define re readdd()
#define pr(a) printtt(a)
#define pee puts("");
#define eee putchar(' ');
#define pss(a) push_back(a)
#define ps(a) push(a)
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}//
int ppow(int a,int b,int mod){a%=mod;//
int ans=1%mod;while(b){if(b&1)ans=(long long)ans*a%mod;
a=(long long)a*a%mod;b>>=1;}return ans;}
int readdd(){int x=0,f=1;char c=getchar();//
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return f*x;}
void printtt(int x){if(x<0)putchar('-'),x=-x;
if(x>=10)printtt(x/10);putchar(x%10+'0');}
bool addd(int a,int b){return a>b;};
//
int l[15],r[15],c[15],cc[15],tot;
char s[15][1005];
int n,m,k;
int cal(int st,int ed,int j){//st-ed行第j列
    int ans=0;
    for(int i=st;i<=ed;i++){
        if(s[i][j]=='1')ans++;
    }
    return ans;
}
int check(){
    for(int i=1;i<=tot;i++)c[i]=cc[i]=0;
    int ans=0;
    for(int j=1;j<=m;j++){//列
        int ok=1;
        for(int e=1;e<=tot;e++){
            cc[e]=cal(l[e],r[e],j);
            if(cc[e]>k)return -1;//无解
            if(c[e]+cc[e]>k){
                ok=0;
            }
        }
        if(ok){
            for(int e=1;e<=tot;e++)c[e]+=cc[e];
        }else{
            ans++;
            for(int e=1;e<=tot;e++)c[e]=cc[e];
        }
    }
    return ans;
}
signed main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        scanf("%s",s[i]+1);
    }
    int ans=1e9;
    for(int i=0;i<(1<<(n-1));i++){
        int temp=0;
        for(int j=0;j<(n-1);j++)if(i>>j&1)temp++;
        tot=0;
        int last=1;
        for(int j=0;j<(n-1);j++){
            if(i>>j&1)tot++,l[tot]=last,r[tot]=j+1,last=j+2;
        }
        if(last<=n)tot++,l[tot]=last,r[tot]=n;
        int t=check();
        if(t==-1)continue;
        else temp+=t;
        ans=min(ans,temp);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

char str[200001];
int s,t,i;
int main() {
	scanf("%s",str);
	i=0;
	while(str[i]!='\0'){
		if(s==0) {
			if(str[i]=='T') t++;
			else if(str[i]=='S') s++;
		}
		else {
			if(str[i]=='T') s--;
			else if(str[i]=='S') s++;
		}
		i++;
	}
	printf("%d\n",t*2);	
	return 0;
}

Measured memory_bytes: 384
N,M = [int(i) for i in input().split()] #Nがスイッチの数、Mは電球の数
sss = []
for i in range(M):
    buff = [int(i) for i in input().split()][1:]
    onoff = 0
    for b in buff:
        onoff += 1<<(b-1)
    sss.append(onoff)

ppp = [int(i) for i in input().split()]

ct=0
for i in range(1<<N):
    for s,p in zip(sss,ppp):
        if bin(i&s).count("1")%2!=p:
            break
    else:
        ct+=1

print(ct)

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

int main(){
    int n,m; cin >> n >> m; 
    ll dp[n+1];
    bool a[n+1];
    for(int i = 0; i <= n; i++) a[i] = true;
    for(int i = 0; i < m; i++){
        int st; cin >> st;
        a[st] = false;
    }

    dp[0] = 1;
    if(!a[1]) dp[1] = 0;
    else dp[1] = 1;

    for(int i = 2; i <= n; i++){
        if(!a[i]){
            dp[i] = 0;
        }else{
            dp[i] = (dp[i-1] + dp[i-2]) % MAX;
        }
    }

    cout << dp[n] %MAX << endl;

    return 0;
}

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

int main() {
  int w, h, n, ans = 0;
  int x, y, a, pos;
  cin >> w >> h >> n;
  vector<int> M(w*h, 1);
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> a;
    for (int j = 0; j < h; j++) {
      for (int k = 0; k < w; k++) {
        pos = k + j*w;
        switch (a) {
          case 1:
            if (k < x) M.at(pos) = 0;
            break;
          case 2:
            if (k >= x) M.at(pos) = 0;
            break;
          case 3:
            if (j < y) M.at(pos) = 0;
            break;
          case 4:
            if (j >= y) M.at(pos) = 0;
            break;
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (M.at(j + i*w)) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

while True:
    str = input().split()
    n, x = int(str[0]), int(str[1])
    if n == 0 and x == 0:
        break
    
    numbers_comb = itertools.combinations(range(1, n + 1), 3)
    answers = [comb for comb in numbers_comb if comb[0] + comb[1] + comb[2] == x]
    print(len(answers))


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

int main() {
  int num;
  double n, a[2525], ans, plas, ave, i = 10, min = 100, sa;

  scanf("%lf", &n);

  for(num = 0;num < n;num++) {
    scanf("%lf", &a[num]);
    plas = plas + a[num];
  }

  ave = plas / num;

  for(num = n - 1;num >= 0;num--) {
    sa = a[num] - ave;
    if(sa < 0) {
        sa = sa * -1;
    }
    if(sa <= min) {
      min = sa;
      i = num;
    }
  }

  printf("%d", (int)i);

  return 0;

}


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

int smaller(int k, int m) {
    if (k<m) return k;
    else if(k==m) return k;
    else if(k>m) return m;
}

int main() {
    scanf("%d %d %d", &n, &a, &b);
    c=a*n;
    s=smaller(c,b);
    printf("%d\n", s);
}


Measured memory_bytes: 128
import sys

def main():
  s = list(input())
  t = list(input())
  
  s.sort()
  t.sort()
  t.reverse()
  m = min(len(s), len(t))
  for i in range(m):
    if s[i] > t[i]:
      print('No')
      sys.exit()
    elif s[i] < t[i]:
      print('Yes')
      sys.exit()

  if len(s) < len(t):
    print('Yes')
    sys.exit()
  else:
    print('No')
    sys.exit()
    
main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
int p[n];
REP(i,n) cin >> p[i];
int ans=0;
REP(i,n-2){
  if(p[i]<p[i+1]&&p[i+1]<p[i+2]) {
    ans++;
  } else if(p[i]>p[i+1]&&p[i+1]>p[i+2]) {
    ans++;
  }
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int nyu;
  int a, b, c;
  cin>>nyu;
  a=nyu/100;
  b=(nyu-100*a)/10;
  c=nyu-100*a-10*b;
  cout<<a+b+c<<endl;
}

Measured memory_bytes: 256
///
// File:  c.cpp
// Author: ymiyamoto
//
// Created on Sun Oct  1 21:09:59 2017
//

#include <cstdint>
#include <iostream>
#include <map>
#include <string>

using namespace std;
#define SIZE 10

static bool sep[SIZE];
static string str;

static uint64_t calc_count()
{
  uint64_t count = 0;
  uint64_t val = 0;
  for (uint32_t i = 0; i < str.size(); i++) {
    val *= 10;
    val += str[i] - '0';
    if (sep[i]) {
      count += val;
      val = 0;
    }
  }
  count += val;
  return count;
}

static uint64_t perm(uint32_t i, uint32_t N)
{
  uint64_t count = 0;

  if (i < N) {
    sep[i] = true;
    count += perm(i + 1, N);
    sep[i] = false;
    count += perm(i + 1, N);
  } else {
    count += calc_count();
  }

  return count;
}

int32_t main()
{
  cin >> str;

  cout << perm(0, str.size() - 1) << endl;

  return 0;
}


Measured memory_bytes: 256