akhauriyash/Code-Regression huggingface dataset:
<?php
$q = str_replace("\r\n","",trim(fgets(STDIN)));
$len = strlen($q);
$next = $q;
if(strlen($q) == 1){
    printf("No");
    exit;
}
for($j=0; $j<$len-1; $j++){
    $buf = $next;
    if(substr($buf,0,2) != "hi"){
        printf("No");
        exit;
    }
    if (strlen($buf) == 2){
        printf("Yes");
        exit;
    }
    //printf($buf."]\n");
    if ($buf[2] != 'h'){
        printf("No");
        exit;
    }
    $next = substr($buf,2);
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long int li;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<float, float> ff;
typedef pair<double, double> dd;
typedef unsigned int ui;
typedef vector<ii> vii;
typedef vector<ff> vff;
typedef set<int> si;
typedef set<lli> slli;
typedef vector<lli> vlli;
typedef long long ll;
typedef long long ll;
typedef vector<ll> vll;
typedef unsigned long long int ulli;
#define MOD 1000000007
#define INF (unsigned)(~0)>>1
typedef pair<int, ii> iii;
void arr_int(int* given_arr, int n){
  for(int i=0;i<n;i++)
    scanf("%d", &given_arr[i]);
}
void solve();
int main(int argc, char const *argv[]){
  solve();
  return 0;
}
void solve(){
  int A,B;
  cin>>A>>B;
  for(int i= 1LL*A/0.08 ; i<=1LL*(A+1)/0.08;i++){
    if(int(i*0.1) == B && int(i*0.08) == A){
      printf("%d\n", i);
      return;
    }
  }
  printf("%d\n", -1);
}


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

int main(){
  int A,B,K;
  cin >> A >> B >> K;
  vector<int> v;
  for(int i=1;i<=min(A,B);i++){
    if((A%i==0)&&(B%i==0)){
      v.push_back(i);
    }
  }
  sort(v.begin(),v.end(),greater<int>());
  cout << v.at(K-1) << endl;
  return 0;
}


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

int main()
{
    long long x, k, d;

    cin >> x >> k >> d;

    x = abs(x);
    long long remind = x % d;
    long long quo = (x - remind) / d; //何回で行けるか

    long long ans = 0;
    if (k < quo)
    {
        ans = x - k * d;
    }
    else
    {
        if (quo % 2 == k % 2)
        {
            ans = remind;
        }
        else
        {
            ans = abs(remind - d);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3640
from collections import deque
import sys
input = sys.stdin.buffer.readline

N = int(input())

edges = [[] for _ in range(N)]
for _ in range(N - 1):
    fr, to, cost = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].append((to, cost))
    edges[to].append((fr, cost))

Q, K = map(int, input().split())
K -= 1
XY = [tuple(map(int, input().split())) for _ in range(Q)]

que = deque([(K, -1, 0)])
dist = [10**18] * N
while que:
    now, pr, d = que.popleft()
    dist[now] = d
    for to, c in edges[now]:
        if to == pr:
            continue
        que.append((to, now, d + c))

ans = [dist[x - 1] + dist[y - 1] for x, y in XY]
print(*ans, sep='\n')


Measured memory_bytes: 63484
S = int(input())

x1 = 0
y1 = 0
x2 = 10 ** 9
y2 = 1

y3_, x3_  =  divmod(S, x2)
if y3_ == 10 ** 9:
  y3 = y3_
  x3 = x3_
else:
  y3 = y3_ + 1
  x3 = 10 ** 9 - x3_

print(x1, y1, x2, y2, x3, y3)

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

int main() {
    ll N;
    scanf("%lld", &N);
    ll a;
    set<ll> s;
    while (N--) {
        scanf("%lld", &a);
        if (s.find(a) == s.end()) {
            s.insert(a);
        } else {
            s.erase(a);
        }
    }
    printf("%lu", s.size());
}

Measured memory_bytes: 4864
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n: Int = sc.nextInt
  val pointList: List[Int] = List.fill(n)(sc.nextInt)
  def go(sum: Int, curr: Int): Int = curr match {
    case 0 => go(sum, curr + 1)
    case x if x < pointList.min => go(sum, curr + 1)
    case x if x > pointList.max => sum
    case _ => go(Math.min(sum, pointList.map(x => Math.pow(x - curr, 2)).sum.toInt), curr + 1)
  }
  println(go(Int.MaxValue, 0))
}

Measured memory_bytes: 55732
#include<stdio.h> 
int main(){ 
    int r,n,cnt=0;
    scanf("%d",&n);
    while(n>0){
        r=n%10;
        if(r==7){
            printf("Yes");
            cnt++;
            break;
        }
        n=n/10;
         }
    if(cnt==0){
        printf("No");
    }
    
     return 0; 
    }

Measured memory_bytes: 1704
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a*b %2 == 0) cout << "No" << endl;
  else cout << "Yes" << endl;
  
}


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

using namespace std;

typedef vector< vector< pair<int, pair<int, int> > > > graph;

class Node{
public:
	int pos, dist, cost;
	Node(int pos, int dist, int cost) : pos(pos), dist(dist), cost(cost) {}
	bool operator < (const Node &nd) const { 
		return make_pair(dist, cost) > make_pair(nd.dist, nd.cost); 
	}
};

int main(){
	int N, M;
	static int dist[10000];
	static bool visit[10000];
	while(cin >> N >> M, N){
		graph g(N);
		for(int i=0;i<M;i++){
			int u, v, d, c; cin >> u >> v >> d >> c;
			g[u-1].push_back(make_pair(v-1, make_pair(d, c)));
			g[v-1].push_back(make_pair(u-1, make_pair(d, c)));
		}
		int ans = 0;
		memset(dist, -1, sizeof(dist));
		memset(visit, false, sizeof(visit));
		dist[0] = 0;
		priority_queue<Node> qu; qu.push(Node(0, 0, 0));
		while(!qu.empty()){
			Node nd = qu.top(); qu.pop();
			int pos = nd.pos, d = nd.dist;
			if(dist[pos]!=-1 && dist[pos] < d) continue;
			if(visit[pos]) continue;
			visit[pos] = true;
			ans += nd.cost;
			for(int i=0;i<g[pos].size();i++){
				int next = g[pos][i].first;
				if(dist[next]==-1 || dist[next] >= dist[pos] + g[pos][i].second.first){
					dist[next] = dist[pos] + g[pos][i].second.first;
					qu.push(Node(next, dist[next], g[pos][i].second.second));
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1760
using System;

class Program {
  static void Main() {
    var s = Console.ReadLine();
    var ans = 999;
    for (int i = 0; i <= s.Length - 3; i++) {
      int n = int.Parse(s.Substring(i, 3));
      ans = Math.Min(ans, Math.Abs(753 - n));
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13140
#!/usr/bin/env python3
import sys
import math


def solve(N: int):
    ans = 0

    r = math.ceil(math.sqrt(N))
    for i in range(1, r+2):
        for j in range(i, (N//i)+2):
            #print(i,j)
            if i*j<N:
                if i==j:
#                    print(i,j,(N-i*j), "*")
                    ans += 1
                else:
#                    print(i,j,(N-i*j))
                    ans += 2

    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9124
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
using namespace std;
map<int,int> p;
int a[100010];
int main()
{
    int n,i,j,k;
    long long s;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        p[a[i]]++;
    }
    j=0;
    for(i=0;i<n;i++)
        if(p[a[i]]>=2)
        j=max(j,a[i]);
    for(i=0;i<n;i++)
    if(a[i]==j)
    {
        p[a[i]]=p[a[i]]-2;
        break;
    }
    k=0;
    for(i=0;i<n;i++)
        if(p[a[i]]>=2)
        k=max(k,a[i]);
    s=(long long)j*k;
    printf("%lld\n",s);
    return 0;
}


Measured memory_bytes: 5248
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,x=0,res=0;
    cin>>n>>x;
    int a[n];
    int pre[n+1];
    pre[0]=0;
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
        pre[i+1]=pre[i]+a[i];
    }
    for(int i=0;i<=n;++i)
    {
        if(pre[i]<=x)
            ++res;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;


int main()
{
	fast;
	cin>>n>>m;
	cout<<(n+m-1)/m;
}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		long k = sc.nextLong();
		//
		//	
		//		for(int i = 1000;i <= 2000;i++){
		//			int S = 0;
		//			if(i <= 9){
		//				S = i;
		//			}else if(i > 9 && i < 100){
		//				S = i/10;
		//				S = S + (i - S*10 );
		//			}else{
		//				S = i/100;
		//				int SS = 0;
		//				SS = i - S*100;
		//				S = S + (SS/10) + (SS - SS/10*10);
		//			}
		//				System.out.println("i " + i+" S "+ S+" sunuke "+ (double)((double)i / S));
		//			
		//		}
		long count = 0;
		long sunukenum = 1l;
		

		while(true){
			if(count == k){
				return;
			}
			System.out.println(sunukenum);
		
			int keta = String.valueOf(sunukenum).length();
			long sunuke = Long.MAX_VALUE;
		//	System.out.println(sunuke);8
			long karinext = 0l;
			for(int i = 0;i <= keta;i++){
				long karin = sunukenum + (long)Math.pow(10, keta-i);
		//		System.out.println("karin "+karin);
//				System.out.println("sum "+sum(karin));

				long karisunuke = karin / sum(karin);
				if(sunuke > karisunuke){
					sunuke = karisunuke;
					karinext = karin;
				}	
			}
			sunukenum = karinext;	
			count++;
			
		}



	}
	static long sum(long n){
		long l =  String.valueOf(n).length();
		long s = 0l;
		for(int i = 0;i < l;i++){
			s +=  (long)(n/Math.pow(10, l-1-i));
			n -= (long)Math.pow(10, l-1-i) *(long)(n/Math.pow(10, l-1-i));
		}
		
		return s;
		
		
	}

}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}



Measured memory_bytes: 21120
n,k=gets.split.map(&:to_i)
d=gets.split.map(&:to_i)
y = (0..9).to_a - d
if (n.to_s.split('').map { |e| e.to_i } - y).empty?
  puts n
  exit
end
head = y.select { |e| e > 0 }.sort.first
min = y.sort.first
digits = n.to_s.size
if n.to_s[0].to_i < head
  puts head.to_s + min.to_s * (digits - 1)
else
  x = (head.to_s + min.to_s * (digits - 1)).to_i
  loop do
    if x > n && (x.to_s.split('').map { |e| e.to_i } - y).empty?
      puts x
      exit
    end
    x += 1
  end
end


Measured memory_bytes: 2044
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <utility>
#include <tuple>

using namespace std;

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


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
#define MOD (ll)1000000007
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

ll memo[100100] = {0};
int num = 1;

ll kaizyou(ll a){
	if(a <= num) return memo[a];
	
	rep(i,num,a+1){
		memo[i] = memo[i-1] * i % MOD;
		memo[i] %= MOD;
		num = max(num,i);
	}
	
	return memo[a];
}

int main(){
	ll n,m,a,b;
	cin >> n >> m;
	memo[0] = 1;
	memo[1] = 1;
	
	if(abs(n-m) > 1){
		cout << 0 << endl;
	}
	else if(n == m){
		cout << 2*kaizyou(n)*kaizyou(m) % MOD << endl;
	}
	else{
		cout << kaizyou(n)*kaizyou(m) % MOD << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    int k;
    cin >> n >> k;
    set<int> d;
    rep(i, k) {
        int x;
        cin >> x;
        d.insert(x);
    }

    for (int i = n; i < 100000; i++) {
        string s = to_string(i);
        int di = s.size();
        bool f = true;
        rep(j, di) {
            int nd = s[j] - '0';
            if (d.find(nd) != d.end()) f = false;
        }
        if (f) {
            cout << i << endl;
            exit(0);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long ll;
const ll INF = 2e9;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<ll>a(n);
	vector<ll>ans(n);
	ll sum = 0,sum2=0,minv=INF;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	for (int i = 0; i < n-1; ++i) {
		sum -= a[i];
		sum2 += a[i];
		ans[i] = abs(sum - sum2);
		minv = min(minv, ans[i]);
	}
	cout << minv << endl;
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = (ll)1e9;
constexpr ll mod = (ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	ll s; cin >> s;
	ll a = 1e9;
	ll x = (a - s % a) % a;
	ll y = (s + x) / a;
	cout << "0 0 1000000000 1 " << x << ' ' << y << "\n";

	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
	int h, w;
	cin >> h >> w;
	char s[h][w];
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++)cin >> s[i][j];
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '.')continue;
			if(i && s[i-1][j]=='#')continue;
			if(i != h-1 && s[i+1][j]=='#')continue;
			if(j && s[i][j-1]=='#')continue;
			if(j != w-1 && s[i][j+1]=='#')continue;
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;		
    return 0;
}

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

int main() {
  string A, B;
  cin >> A  >> B;
  
  if ( A.length() > B.length() ){
    cout << "GREATER";
  }
  if ( A.length() < B.length() ){
    cout << "LESS";
  }
  if ( A.length() == B.length() ){
    char X = 'E';
    for (int i = 0 ; i < A.length() ; i++ ){
      if (A.at(i) > B.at(i)){
        X = 'G';
        break;
      }
      else if (A.at(i) < B.at(i)){
        X = 'L';
        break;
      }
    }
    if ( X == 'G' ){
      cout << "GREATER";
    }
    else if ( X == 'L' ){
      cout << "LESS";
    }
    else if ( X == 'E' ){
      cout << "EQUAL";
    }
  }
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())

F=[]
for _ in range(N):
    F.append(list(map(int,input().split())))
P=[]
for _ in range(N):
    P.append(list(map(int,input().split())))

ans=-10**18
for i in range(1,2**10):
    l=list(map(int,bin(i)[2:]))
    l=[0]*(10-len(l))+l
    shop=[0]*N
    for time,flag in enumerate(l):
        for i in range(N):
            if F[i][time]==1 and flag:
                shop[i]+=1
    temp=0
    for i in range(N):
        temp+=P[i][shop[i]]
    ans=max(ans,temp)
        
print(ans)


Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 100005;



int main() {
 // freopen("in.cpp","r",stdin);
  int x;
  cin>>x;
  ll ret=0,sum=0;
  for(int i=1;;i++){
    sum+=i;
    ret++;
    if(sum>=x)break;
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    X = []
    for _ in range(N):
        x, l = (int(_) for _ in input().split())
        X.append([x-l, x+l])
    X.sort(key=lambda x:x[1])
    output = 0
    last = -10 ** 12
    for i in range(N):
        if last <= X[i][0]:
            output += 1
            last = X[i][1]
    print(output)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 21360
// 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  int n, k;
  int a[200005];
  int b[200005] = {0};
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    b[a[i]]++;
  }
  sort(b, b + n + 1);
  reverse(b, b + n + 1);
  int ans = 0;
  for(int i = k; i < n; i++){
    ans += b[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
n,m,x = gets.chomp.split(' ').map(&:to_i)
books = []
n.times do |i|
  books << gets.chomp.split(' ').map(&:to_i)
end

def fuga(array, bits)
  bits.map.with_index do |bit, i|
    array[i] if (bit == 1)
  end.compact
end

def hoge(books, bits)
  tmp = Array.new(books[0].size, 0)
  fuga(books, bits).each do |book|
    for i in 0...(tmp.size) do
      tmp[i] += book[i]
    end
  end
  tmp
end

def hantei(array, k)
  array.min >= k
end

min = 9999999

[0, 1].repeated_permutation(n) do |bits|
  foo = hoge(books, bits)
  next unless (hantei foo[1..-1], x)
  min = foo[0] if (min > foo[0])
end
puts min == 9999999 ? -1 : min

Measured memory_bytes: 14356
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [a,b] <- map (read::String->Int) . words <$> getLine
  print $ length [x|x<-[a..b], (take 2 .show) x==(reverse .drop 3 .show) x]

Measured memory_bytes: 4888
n,x,y=map(int,input().split())
x-=1
y-=1
k=[0]*n
for i in range(n-1):
  for j in range(i+1,n):
    m=min(j-i,abs(i-x)+1+abs(y-j))
    k[m]+=1
for i in range(1,n):print(k[i])



Measured memory_bytes: 3444
# coding: utf-8

n, k = map(int, input().split())
ans = 0
l = list(range(n))
s = n*(n+1)//2
m = 10**9+7

for i in range(n-k+2): # i+k個選ぶ
    #0,1,2 ..., n から i+k個選んだときの和の種類
    ans += ((s - (n-(i+k))*(n-(i+k)+1)//2) - (i+k-1)*(i+k)//2 +1)
    if ans > m:
        ans = ans % m
print(ans)

Measured memory_bytes: 16908
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll a[3][n],dp[3][n];
    memset(dp,0,3*n*sizeof(ll));
    for(ll i = 0;i < n;i++){
    	cin >> a[0][i] >> a[1][i] >> a[2][i];
    	dp[0][i] = a[0][i];
    	dp[1][i] = a[1][i];
    	dp[2][i] = a[2][i];
    }
    for(ll i = 1;i < n;i++){
    	dp[0][i] += max(dp[1][i-1],dp[2][i-1]);
    	dp[1][i] += max(dp[0][i-1],dp[2][i-1]);
    	dp[2][i] += max(dp[0][i-1],dp[1][i-1]);
    }
    cout << max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1])) << endl;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int64_t ans; cin>>ans;
	for(int i=1;i<n;++i){
		int64_t t; cin>>t;
		ans=lcm(ans,t);
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3620
#include<stdio.h>

static  int MAX = 500;
static  int INFTY = (1<<21);

int main(){
  int n, i, j;
  int M[MAX][MAX];
  int  h, g, f, v;
  int minv;
  int d[MAX];
  int vis[MAX];
  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &f, &h);
    for ( j = 0; j < h; j++ ){
      scanf("%d %d", &v, &g);
      M[f][v] = g;
    }
  }
  for ( i = 0; i < n; i++ ) {
    d[i] = INFTY;
    vis[i] = 0;
  }
  d[0] = 0;
  while(1){
    minv = INFTY;
    f = -1;
    for ( i = 0; i < n; i++ ){
      if ( minv > d[i] && !vis[i] ){
	f = i;
	minv = d[i];
      }
    }
    if ( f == -1 ) break;
    vis[f] = 1;
    for ( v = 0; v < n; v++ ){
      if ( !vis[v] && M[f][v] != INFTY ){
	if ( d[v] > d[f] + M[f][v] ){
	  d[v] = d[f] + M[f][v];
	}
      }
    }
  }
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i, (d[i]==INFTY?-1:d[i]));
  }
  return 0;
}



Measured memory_bytes: 2048
a,b=map(int, input().split())
if a==1:
  a=14
if b==1:
  b=14
if a==b:
  if a==14 and b==14:
    a=1
    b=1
  print("Draw")
elif a>b:
  if a==14:
    a=1
  print("Alice")
elif a<b:
  if b==14:
    b=1
  print("Bob")
    

Measured memory_bytes: 3060
#N,Wを入力
H,W = map(int, input().split())

trout = []

for i in range(H):
    trout.append(list(input()))

# 配列の比較用の変数
h = H-1
w = W-1

reslut = "Yes"
for i in range(H):
    for j in range(W):
        
        c = -1
        # "."だったらスルー
        if trout[i][j] == ".":
            pass
        
        else:
             # 真上
            if i>=1 and trout[i-1][j] == "#":
                c = 1
             # 左
            if j>=1 and trout[i][j-1] == "#":
                c = 1
            # 右
            if j<w and trout[i][j+1] == "#":
                c = 1
            # 真下
            if i<h and trout[i+1][j] == "#":
                c = 1
            
            if c == -1:
                reslut = "No"
                break
    else:
        continue
    break
    
print(reslut)

Measured memory_bytes: 3064
x,y,z,k=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
B=sorted(list(map(int,input().split())),reverse=True)
C=sorted(list(map(int,input().split())),reverse=True)
ans=[]
for i in range(x):
  j=0
  while (i+1)*(j+1)<=3000 and j<y:
    l=0
    while (i+1)*(j+1)*(l+1)<=3000 and l<z:
      a=A[i]+B[j]+C[l]
      ans.append(a)
      l=l+1
    j=j+1
ans=sorted(ans,reverse=True)
for i in range(k):
  print(ans[i])


Measured memory_bytes: 9544
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, 0, n) cin >> a[i] >> b[i];

  ll num = 1, x = a[0], y = b[0];
  rep(i, 1, n) {
    num = max((a[i - 1] * num + a[i] - 1) / a[i],
              (b[i - 1] * num + b[i] - 1) / b[i]);
    x = a[i] * num;
    y = b[i] * num;
  }

  cout << x + y << endl;

  return 0;
}


Measured memory_bytes: 3612
Q, H, S, D = input().split()
Q, H, S, D = int(Q), int(H), int(S), int(D)
N = int(input())

needtobuy_l = N
needtobuy_m = 0
per_2l_price = [D,
                S*2, S+H*2, S+H+Q*2,
                H*4, H*3+Q*2, H*2+Q*4, H+Q*6,
                Q*8]
per_1l_price = [S,
                H*2, H+Q*2,
                Q*4]

if needtobuy_l % 2 == 0:
    mincost = min(per_2l_price)
    needtobuy_m = mincost * (needtobuy_l // 2)
else:
    mincost = min(per_2l_price)
    needtobuy_m = mincost * (needtobuy_l // 2)
    mincost = min(per_1l_price)
    needtobuy_m += mincost * 1

print(needtobuy_m)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,m;
vector<P> G[100010];
vector<P> bombs;
int a[100010];
bool visited[100010];
int edge[100010];
bool muri=false;
vector<int> ans={};

void dfs(int s,int par,int e_idx){
  if(visited[s]) return;
  visited[s]=true;
  for(auto p:G[s]){
    int t=p.first,e=p.second;
    if(t==par) continue;
    dfs(t,s,e);
  }
  //cout << s << " " << edge[s] << " " << a[s] << endl;
  if(edge[s]!=a[s] && a[s]!=-1){
    if(par==-1){
      muri=true;
      return;
    }
    //cout << s << " " << par  << " " << e_idx+1 << endl;
    edge[par]^=1;
    ans.push_back(e_idx);
  }
}


void solve(){
  cin >> n >> m;
  bombs.resize(n);
  rep(i,n){
    cin >> bombs[i].first >> bombs[i].second;
  }
  sort(bombs.begin(),bombs.end());
  rep(i,m){
    int a,b;cin >> a >> b;
    int r=lower_bound(bombs.begin(),bombs.end(),P(b,2))-bombs.begin();
    int l=lower_bound(bombs.begin(),bombs.end(),P(a,0))-bombs.begin();
    if(l<r){
      G[l].emplace_back(r,i);
      G[r].emplace_back(l,i);
    }
    //cout << l << " " << r << endl;
  }
  // rep(i,n+1){
  //   cout << i << endl;
  //   for(auto t:G[i]){
  //     cout << t.first << " ";
  //   }
  //   cout << "" << endl;
  // }
  int s=0;
  per(i,n){
    if(bombs[i].second!=s){
      a[i+1]=1;
      s^=1;
    }
  }
  a[0]=-1;
  // rep(i,n+1){
  //   cout << a[i] << " ";
  // }
  //cout << "" << endl;
  rep(i,n+1){
    dfs(i,-1,-1);
  }
  if(muri) cout << -1 << endl;
  else{
    cout << ans.size() << endl;
    sort(ans.begin(),ans.end());
    for(int e:ans){
      cout << e+1 << " ";
    }
    cout << "" << endl;
  }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 15612
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int main(void){
    char matrix[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> matrix[i][j];
        }
    }
    cout << matrix[0][0] << matrix[1][1] << matrix[2][2] << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
num = ['3','5','7']
for i in range(len(str(N))-1):
    num2 = []
    for n in num:
        num2.append(n+'3')
        num2.append(n+'5')
        num2.append(n+'7')
        num2.append(n)
    num = num2
cnt = 0
num = set(num)
for n in num:
    if '3' in n and '5' in n and '7' in n:
        if int(n) <= N:
            cnt += 1
print(cnt)

Measured memory_bytes: 18716
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int x,k;
    cin>>x>>k;
    k=k*2-x;
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define N 1000000007

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int gcd_a = a[0];
    for (int i = 1; i < n; i++) {
        gcd_a = gcd(gcd_a, a[i]);
    }
    if (gcd_a > 1) {
        cout << "not coprime" << endl;
        return 0;
    }
    int a_max = 0;
    for (int i = 0; i < n; i++) {
        a_max = max(a[i], a_max);
    }

    vector<bool> s(a_max + 1, true);
    vector<int> d(a_max + 1, 0);
    s[1] = false;
    for (int n = 2; n <= a_max; n++) {
        if (not s[n]) continue;
        for (int i = 1; n * i <= a_max; i++) {
            s[n * i] = false;
            d[n * i] = n;
        }
    }

    vector<int> taken(a_max + 1, -1);
    for (int i = 0; i < n; i++) {
        while (a[i] > 1) {
            int p = d[a[i]];
            if (taken[p] == -1) {
                taken[p] = i;
            } else if (taken[p] != i) {
                cout << "setwise coprime" << endl;
                return 0;
            }
            a[i] /= p;
        }
    }
    cout << "pairwise coprime" << endl;
    return 0;
}

Measured memory_bytes: 15132
#include<stdio.h>
#include<string.h>
int main(void){
  char alf[28]="abcdefghijklmnopqrstuvwxyz",str[100000];
  int i,j;
  scanf("%s",str);
  for(i=0;i<strlen(str);i++){
    for(j=0;j<strlen(alf);j++){
      if(alf[j]==str[i]){
        alf[j]='0';
      }
    }
  }
  for(i=0;i<strlen(alf);i++){
    if(alf[i]!='0'){
      printf("%c",alf[i]);
      return 0;
    }
  }
  printf("None");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(void){
    int n,m,p;
    while(1){
        cin>>n>>m>>p;
        if(n==0)break;
        vector<int> x(n);
        int sum=0;
        for(int i=0;i<n;i++){
cin>>x[i];
sum+=x[i];
        }
        sum=sum*(100-p);
if(x[m-1]==0){
    cout<<"0"<<endl;
}else{       sum=sum / x[m-1];
        cout<<sum<<endl;
}
    }
    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T,class U>
ostream& operator << (ostream& os,pair<T,U>& p){
  os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
  is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
  for(int i=0;i<vec.size();i++){
    os << vec[i];
    if(i+1<vec.size())os << ' ';
  }
  return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
  for(int i=0;i<vec.size();i++)is >> vec[i];
  return is;
}
void fastio(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(20);
}
int a[10];
int main(){
  int x,y,z;
  cin >> x >> y >> z;
  a[x]++;
  a[y]++;
  a[z]++;
  if(a[5]==2&&a[7]==1)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

const int mn=1e5+8;
vector<int> to[mn],nto[mn],be(mn),siz(mn),vis(mn);
int cnt;

void dfs(int x,int fa)
{
	if(vis[x]) return ;
	vis[x]=1;
	siz[cnt]++;
	be[x]=cnt;
	for(int i=0;i<to[x].size();++i) {
		int t=to[x][i];
		if(t==fa) continue ;
		dfs(t,x);
	}
}

int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	int u,v;
	for(int i=1;i<=m;++i) {scanf("%d%d",&u,&v);to[u].pb(v),to[v].pb(u);}
	for(int i=1;i<=k;++i) {scanf("%d%d",&u,&v);nto[u].pb(v),nto[v].pb(u);}
	for(int i=1;i<=n;++i) {
		if(vis[i]) continue;
		cnt++;
		dfs(i,0);
	}
	int ans;
	for(int i=1;i<=n;++i) {
		ans=siz[be[i]]-1;
		ans-=to[i].size();
		for(int j=0;j<nto[i].size();++j) {
			if(be[i]==be[nto[i][j]]) ans--;
		}
		printf("%d ",ans);
	}
}

Measured memory_bytes: 13440
import java.io.*;
import java.util.*;

public class Main {
    Scanner sc;
    int[][] field;
    int gx, gy;
    int p;
    boolean[][][][] matatabi;

    int dataset;

    Main() {
        sc = new Scanner(System.in);
        dataset = sc.nextInt();
    }

    void init() {
        gx = sc.nextInt();
        gy = sc.nextInt();
        field = new int[gy+1][gx+1];
        matatabi = new boolean[gy+1][gx+1][gy+1][gx+1];

        p = sc.nextInt();
        for (int i = 0; i < p; i++) {
            int x1 = sc.nextInt();
            int y1 = sc.nextInt();
            int x2 = sc.nextInt();
            int y2 = sc.nextInt();
            matatabi[y1][x1][y2][x2] = true;
            matatabi[y2][x2][y1][x1] = true;
        }
    }

    void run() {
        for (int _i = 0; _i < dataset; _i++) {
            init();
            field[0][0] = 1;
            for (int i = 1; i <= gx; i++) {
                if (matatabi[0][i-1][0][i]) break;
                field[0][i] = 1;
            }
            for (int i = 1; i <= gy; i++) {
                if (matatabi[i-1][0][i][0]) break;
                field[i][0] = 1;
            }

            for (int i = 1; i <= gy; i++) {
                for (int j = 1; j <= gx; j++) {
                    if (matatabi[i][j-1][i][j] && matatabi[i-1][j][i][j]) {
                        field[i][j] = 0;
                    } else if (matatabi[i][j-1][i][j]) {
                        field[i][j] = field[i-1][j];
                    } else if (matatabi[i-1][j][i][j]) {
                        field[i][j] = field[i][j-1];
                    } else {
                        field[i][j] = field[i-1][j] + field[i][j-1];
                    }
                }
            }

            if (field[gy][gx] == 0) {
                System.out.println("Miserable Hokusai!");
            } else {
                System.out.println(field[gy][gx]);
            }
        }
    }

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

Measured memory_bytes: 13000
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define eps 1e-8
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");


signed main(){
    FASTER;
    int n;cin>>n;
    n--;
    cout<<n*(n+1)/2;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  ll ans = 0;
  int cnt = 0;
  for(int i=0; i<S.size(); i++){
    if(S[i] == 'A'){
      cnt++;
    }else{
      if(S.substr(i,2) == "BC"){
        ans += cnt;
        i++;
      }else{
        cnt = 0;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3784
from collections import Counter
N=input()
s=[ raw_input() for i in range(N) ]
M=input()
t=[ raw_input() for i in range(M) ]

cs=Counter(s)
ct=Counter(t)

ans=0
for i in cs.keys():
	ans=max(ans, cs[i]-ct[i])

print ans

Measured memory_bytes: 2812
#include <stdint.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long a) {
  cout << a + a * a + a * a * a << endl;
}

int main() {
  long long a;
  scanf("%lld", &a);
  solve(a);
  return 0;
}


Measured memory_bytes: 3756
def n_shichigo(N, M):
    if (not M == '') and (int(M) > int(N)):
        return 0

    if '7' in M and '5' in M and '3' in M:
        x = 1
    else:
        x = 0
    return n_shichigo(N, M+'7') + n_shichigo(N, M+'5') + n_shichigo(N, M+'3') + x

N = input()
print(n_shichigo(N, ''))

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

int main()
{
    vector<int> bell(3);
    for (int i = 0; i < bell.size(); i++)
    {
        cin >> bell[i];
    }
    sort(bell.begin(), bell.end());
    cout << bell[0] + bell[1] << endl;
}

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

using namespace std;

const int N = 4;
const int MAX_E = 72;
const char ope[] = {'+', '-', '*'};

bool is_end(vector<int> a) {
    REP(i, a.size()) if(a[i] != 0) return false;
    return true;
}

int calc(int type, int val, int x) {
    if(type == 0) return val - x;
    if(type == 1) return x - val;
    if(type == 2) return val / x;
}

bool used[5][5][300];
string memo[5][5][300];
string rec(const vector<int>& nums, int l, int r, int val) {
    if(used[l][r][val + MAX_E]) return memo[l][r][val + MAX_E];
    used[l][r][val + MAX_E] = true;
    string& res = memo[l][r][val + MAX_E];

    if(r - l == 1) {
        if(nums[l] == val) {
            return res = to_string(val);
        } else {
            return res = "";
        }
    }

    for(int k = 1; l + k < r; k++) {
        for(int x = -MAX_E; x <= MAX_E; x++) {
            for(int type = 0; type < 3; type++) {
                if(type == 2 && (x == 0 || val % x != 0)) continue;
                int y = calc(type, val, x);
                string ls = rec(nums, l, l + k, x);
                string rs = rec(nums, l + k, r, y);
                if(ls == "") continue;
                if(rs == "") continue;
                if(nums.size() == 4)
                return res = "(" + ls + ope[type] + rs + ")";
            }
        }
    }

    return res = "";
}

int main(){
    while(true) {
        vector<int> nums(N);
        REP(i, N) cin >> nums[i];
        if(is_end(nums)) break;

        bool exist = false;
        sort(nums.begin(), nums.end());
        do{
            memset(used, 0, sizeof(used));
            string s = rec(nums, 0, nums.size(), 10);
            if(s != "") {
                cout << s << endl;
                exist = true;
                break;
            }
        }while(next_permutation(nums.begin(), nums.end()));

        if(!exist) {
            cout << "0" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1332
fun main(args: Array<String>) {
    abc087b()
}

fun abc087b() {
    val (a, b, c, x) = (1..4).map { readLine()!!.toInt() }

    val answer = (0..a).map { y500 ->
        (0..b).map { y100 ->
            (0..c).map { y50 ->
                y500 * 500 + y100 * 100 + y50 * 50 == x
            }
        }.flatten()
    }.flatten().count { it }

    println(answer)
}


Measured memory_bytes: 38432
#include<iostream>

using namespace std;

int main(){

  int ninzu,i,j;
  double height;
  int gragh[6]={};


  cin >> ninzu;
  
  for(i=0;i<ninzu;i++){
    cin >> height;
    if(height<165.0)
      gragh[0]++;
    else{
      for(j=0;j<4;j++){
	if(165.0+j*5.0 <= height  &&  height < 170.0+j*5.0){
	  gragh[j+1]++;
	}
      }
    }
    if(height>=185.0)
      gragh[5]++;
  }

  for(i=0;i<6;i++){
    cout << i+1 << ":";
    for(j=0;j<gragh[i];j++){
      cout << "*";
    }
    cout << endl;
  }
}
	
    

Measured memory_bytes: 1232
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++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>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b = a, c = a;
    if (prev_permutation(all(b))) rep(i, n) cout << b[i] << (i == n-1 ? '\n' : ' ');
    rep(i, n) cout << a[i] << (i == n-1 ? '\n' : ' ');
    if (next_permutation(all(c))) rep(i, n) cout << c[i] << (i == n-1 ? '\n' : ' ');
}



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double a1 = double(60*h+m)/720 * 2*PI;
  double a2 = double(m)/60 * 2*PI;
  double dx = a*cos(a1) - b*cos(a2);
  double dy = a*sin(a1) - b*sin(a2);
  double ans = sqrt(dx*dx + dy*dy);
  printf("%.10f\n", ans);
}

Measured memory_bytes: 4084
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        set<int> si;
        for(int i=1; i<n; ++i)
            si.insert(i*i%n);

        vector<int> ret((n-1)/2+1, 0);
        set<int>::iterator it1, it2;
        for(it1=si.begin(); it1!=si.end(); ++it1){
            for(it2=it1, ++it2; it2!=si.end(); ++it2){
                int a = (*it1) - (*it2);
                if(a < 0)
                    a += n;
                if(a > (n-1)/2)
                    a = n - a;
                ret[a] += 2;
            }
        }

        for(int i=1; i<=(n-1)/2; ++i)
            cout << ret[i] << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll a,b,c;cin>>a>>b>>c;
    if(a+b<c-1){
        ll res=b*2+1+a;
        cout<<res<<endl;
        return 0;
    }
    cout<<b+c<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#include<string.h>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
const int maxn=100+6;
#define mod 1000000007
#define INF 0x3f3f3f3f
int main()
{
    string a,b,c;
    cin>>a;
    int l=a.size();
    rep(i,1,l)cout<<"x";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    N,A,B,C = map(int, input().split())
    l = [int(input()) for _ in range(N)]
    
    INF = 1<<20
    f = None
    
    def perm(n, a, b, c):
        if n == N:
            if all([a, b, c]):
                return abs(A-a)+abs(B-b)+abs(C-c)-30
            else:
                return INF
        return min(
            f(n+1,a,b,c),
            f(n+1,a+l[n],b,c)+10,
            f(n+1,a,b+l[n],c)+10,
            f(n+1,a,b,c+l[n])+10
            )
    
    f = perm
    print(f(0,0,0,0))

main()

Measured memory_bytes: 3064
X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);else for(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);else puts("NA");}exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
     string s;
     cin >> s;
     s.at(5)=' ';
     s.at(13)=' ';
     cout << s << endl;
     
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(){

  int a[3],b,i,j;

  scanf("%d %d %d", &a[0], &a[1], &a[2]);

  for(i=0;i<2;i++){

    for(j=i+1;j<3;j++){

      if(a[i] > a[j]){

        b = a[i];

        a[i] = a[j];

        a[j] = b;

      }

    }

  }

  printf("%d %d %d\n",a[0],a[1],a[2]);

  return 0;

}

Measured memory_bytes: 596