akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

int n;

void dfs(string s="a",char mx='a'){
    if(s.size()==n){
        cout<<s<<endl;
        return;
    }
    for(char c='a';c!=mx+2;c++){
        char nmx=max(c,mx);
        dfs(s+c,nmx);
    }
}

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







Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e5 + 10;
const ll INF = 1e18;

int N;
int a[MAX];
ll f[2][MAX][2];//选到第i个数, 已经选了j个, 当前选了1，没选0的最大值


int main() {
#ifdef ACM_LOCAL
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
    memset(f, -0x3f, sizeof(f));
    for (int i = 0; i <= N; i++) f[0][i][0] = 0;
    for (int i = 1; i <= N; i++) {
        int now = i % 2, pre = now ^ 1;
        for (int j = max(0, i / 2 - 10); j <= i / 2; j++) {
            f[now][j + 1][1] = -INF;
            f[now][j][0] = -INF;
        }
        for (int j = max(0, i / 2 - 10); j <= i / 2; j++) {
            f[now][j + 1][1] = max(f[now][j + 1][1], f[pre][j][0] + a[i]);
            f[now][j][0] = max(f[now][j][0], max(f[pre][j][0], f[pre][j][1]));
        }
    }
    printf("%lld\n", max(f[N % 2][N / 2][0], f[N % 2][N / 2][1]));


    return 0;
}


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

int main() {
	int K, N;
	cin >> K >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	int MAX = 0;
	for (int i = 0; i < N - 1; i++) MAX = max(MAX, A[i + 1] - A[i]);
	MAX = max(MAX, K - A[N - 1] + A[0]);
	cout << K - MAX << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int f[320][320][320];
char c[320];
int i,j,k,m,n;

int main()
{
	scanf("%s",c+1);
	n=strlen(c+1);
	scanf("%d",&m);
	for (i=n;i>0;i--)
		for (j=i;j<=n;j++)
			for (k=0;k<=m;k++)
			{
				f[i][j][k]=max(f[i][j][k],f[i+1][j][k]);
				f[i][j][k]=max(f[i][j][k],f[i][j-1][k]);
				if (c[i]==c[j])
					f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k]+1+(i!=j));
				if (k>0)
					f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k-1]+1+(i!=j));
			}
	printf("%d",f[1][n][m]);
	return 0;
}

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

int main(){
  int t,n,result;

  while(cin >> t >> n){
    switch (t) {
      case 1:
      result = 6000 * n;
      break;
      case 2:
      result = 4000 * n;
      break;
      case 3:
      result = 3000 * n;
      break;
      case 4:
      result = 2000 * n;
      break;
    }
    cout << result << endl;
  }
}

Measured memory_bytes: 1164
#include<stdio.h>

int main(){
    int N;
    int P[210000];
    int place[210000];
    int tmp, ans;

    scanf("%d", &N);
    for(int i=0; i<N; i++){
        scanf("%d", &P[i]);
        place[P[i]]=i;
    }

    ans = N;
    tmp=1;
    for(int i=2; i<=N; i++){
        if(place[i]>place[i-1]){
            tmp++;
        }else{
            tmp=1;
        }
        if(ans>N-tmp){
            ans = N-tmp;
        }
    }
    if(N==1){
        ans=0;
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  bool flag=false, ans=false;
  for(int i=0;i<s.size();i++){
    if(s[i]=='C') flag=true;
    if(flag){
      if(s[i]=='F') {
        ans=true;
        break;
      }
    }
  }
  cout<<((ans)? "Yes":"No");
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int xs = Integer.parseInt(sa[0]);
		int ys = Integer.parseInt(sa[1]);
		int xt = Integer.parseInt(sa[2]);
		int yt = Integer.parseInt(sa[3]);
		int n = Integer.parseInt(br.readLine());
		Node[] arr = new Node[n + 2];
		Node ns = new Node();
		ns.x = xs;
		ns.y = ys;
		arr[0] = ns;
		Node nt = new Node();
		nt.v = n + 1;
		nt.x = xt;
		nt.y = yt;
		nt.d = 1e18;
		arr[n + 1] = nt;
		for (int i = 1; i <= n; i++) {
			sa = br.readLine().split(" ");
			Node node = new Node();
			node.v = i;
			node.x = Integer.parseInt(sa[0]);
			node.y = Integer.parseInt(sa[1]);
			node.r = Integer.parseInt(sa[2]);
			node.d = 1e18;
			arr[i] = node;
		}
		br.close();

		Set<Integer> set = new HashSet<>();
		for (int i = 0; i <= n + 1; i++) {
			set.add(i);
		}
		double[] dist = new double[n + 2];
		Arrays.fill(dist, 1e18);
		dist[0] = 0;
		PriorityQueue<Node> que = new PriorityQueue<Node>();
		Node first = arr[0];
		que.add(first);
		while (!que.isEmpty()) {
			Node cur = que.poll();
			if (set.remove(cur.v)) {
				for (int i : set) {
					int j = cur.v;
					double c = Math.hypot(arr[i].x - arr[j].x, arr[i].y - arr[j].y) - arr[i].r - arr[j].r;
					c = Math.max(c, 0);
					double alt = cur.d + c;
					if (alt < dist[i]) {
						dist[i] = alt;
						Node next = new Node();
						next.v = i;
						next.d = alt;
						que.add(next);
					}
				}
			}
		}
		System.out.println(dist[n + 1]);
	}

	static class Hen {
		int v, c;

		public Hen(int v, int c) {
			this.v = v;
			this.c = c;
		}
	}

	static class Node implements Comparable<Node> {
		int v, x, y, r;
		double d;

		public int compareTo(Node o) {
			return Double.compare(d, o.d);
		}
	}
}


Measured memory_bytes: 56784
import sys
        
def getpar(Edge, p):
    N = len(Edge)
    par = [0]*N
    par[0] = -1
    par[p]  -1
    stack = [p]
    visited = set([p])
    while stack:
        vn = stack.pop()
        for vf in Edge[vn]:
            if vf in visited:
                continue
            visited.add(vf)
            par[vf] = vn
            stack.append(vf)
    return par

def topological_sort_tree(E, r):
    Q = [r]
    L = []
    visited = set([r])
    while Q:
        vn = Q.pop()
        L.append(vn)
        for vf in E[vn]:
            if vf not in visited:
                visited.add(vf)
                Q.append(vf)
    return L

N = int(input())
Edge = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, sys.stdin.readline().split())
    a -= 1
    b -= 1
    Edge[a].append(b)
    Edge[b].append(a)

P = getpar(Edge, 0)
L = topological_sort_tree(Edge, 0)

dp = [0]*N
for l in L[1:][::-1]:
    p = P[l]
    dp[p] ^= (dp[l] + 1)


print('Alice' if dp[0] else 'Bob')


Measured memory_bytes: 77100
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		
		System.out.println((H-h)*(W-w));
	}
}

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

using namespace std;

const int MAX = 105;
long long a[MAX];

int main(int argc, char* argv[])
{
    if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
    if(argc == 3) freopen(argv[2], "w", stdout);
    ios::sync_with_stdio(false);
    int n;
    long long m = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m = max(a[i], m);
    }
    bool flag = true;
    long long x, y = 1;
    while (flag) {
        x = (m / __gcd(m, y)) * y;
        flag = false;
        for (int i = 0; i < n; i++) {
            if (x % a[i]) {
                y = a[i];
                flag = true;
                break;
            }
        }
        m = x;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 左の子(left child), r:右の子(right child)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];
int calcHeight(int u){
int l=0,r=0;
if(T[u].l==-1 && T[u].r==-1)return 0;
else if(T[u].l==-1 && T[u].r!=-1)r=calcHeight(T[u].r);
else if(T[u].l!=-1 && T[u].r==-1)r=calcHeight(T[u].l);
else {
  l=calcHeight(T[u].l);
  r=calcHeight(T[u].r);
}
	if(l>r)return ++l;
	else return ++r;
}
void print(int u){
 int i, c, h;
 printf("node %d: parent = %d, sibling = ", u, T[u].p);
 if(T[u].p==-1)printf("-1");
 else if(T[T[u].p].l==u)printf("%d",T[T[u].p].r);
 else printf("%d",T[T[u].p].l);
 printf(", degree = ");
 if(T[u].l!=-1 && T[u].r!=-1)printf("2");
 else if(T[u].l==-1 && T[u].r==-1)printf("0");
 else printf("1");
 printf(", depth = %d, ", D[u]);
 h=calcHeight(u);
 printf("height = %d, ",h);
 if(T[u].p==-1) printf("root");
 else if(T[u].l==NIL && T[u].r==NIL) printf("leaf");
 else printf("internal node");
 printf("\n");
}
void calcDepth(int u, int p){
 D[u] = p;
 if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
 if(T[u].r!=NIL) calcDepth(T[u].r,p+1);
}
int main(){
 int i, j, k;
 int n;
 int id, sib, child;
 int root = NIL;
 scanf("%d", &n);
 for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
 for(i=0; i<n; i++){
   scanf("%d", &id);
   scanf("%d %d", &T[id].l,&T[id].r);
   T[T[id].l].p = T[T[id].r].p = id;
   }
 
 //根を求める (find the root)
 for(i=0; i<n; i++){
   if(T[i].p == -1) root = i;
 }
 //それぞれのノードの深さを求める (find depth of each node)
 calcDepth(root, 0);
 //calcHeight
 //出力 (output)
 /*s
 for(i=0; i<n; i++)
 printf("lc:%d, r:%d\n",T[i].l,T[i].r);
 e*/
 for(i=0; i<n; i++) print(i);
 return 0;
}



Measured memory_bytes: 2108
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
Main();
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var X = one[1];
  var list = nextIntArray();
  list.push(X);
  list.sort(function(a,b){
  	return a - b;
  });
  var output = 0;
  for(var i = 1; i < N + 1; i++){
    if(i == 0){
       output = list[i] - list[i - 1];
    }else{
       output = gcd(list[i] - list[i - 1],output);
    }
  }
  myout(output);
}
function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

Measured memory_bytes: 30288
import java.util.*;
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        double a =sc.nextInt();

        double two=Math.sqrt(a);
        double three=Math.cbrt(a);
        double four=Math.pow(a,0.25);
        double five=Math.pow(a,0.2);

        double unti[];
        unti=new double[4];
        unti[0]=Math.floor(two);
        unti[1]=Math.floor(three);
        unti[2]=Math.floor(four);
        unti[3]=Math.floor(five);
        double max=0;
        for(int i=0;i<4;i++){
             double jo=Math.pow(unti[i],i+2);
            max=Math.max(max,jo);
        }
        int ans=(int)max;
        System.out.println(ans);


        
    }
}

Measured memory_bytes: 21844
from functools import reduce
import fractions

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

N, M = map(int, input().split())
a_list = list(set(list(map(int, input().split()))))

lcm = 1

for a in a_list:
  lcm = lcm_base(lcm, a)

for a in a_list:
  if (lcm // a) % 2 == 0:
    lcm = 0
    break
if lcm == 0:
  print(0)
elif M == 1 and lcm == 2:
  print(1)
else:
  print(int(-(-M//(lcm//2))/2))

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

int main(){
  int n,m;
  cin >> n >> m;
  
  vector<int> light(m);
  
  rep(i,m){
    int k;
    cin >> k;
    int sum = 0;  
    rep(j,k){
      int s;
      cin >> s;
      s--;
      sum |= 1<<s;
    }
    light[i] = sum;
  }
/*
  rep(i,m){
    rep(j,n){
      cout << (light[i]>>j&1);
    }
    cout << endl;
  }
  cout << endl;
*/
  vector<int> p(n);
  rep(i,m) cin >> p[i];
  
  int ans = 0;
  rep(i,1<<n){
    bool ok = true;
    rep(j,m){
      int k = __builtin_popcount( light[j]&i );
      //rep(l,n){cout <<( (light[j]&i)>>l&1 );} cout << endl;
      if(k%2 != p[j]) ok = false;
    }
    //cout << endl;
    if(ok) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(){
    ll n;
    cin>>n;
    
    auto pf=prime_factorize(n);
    ll ans=0;
    for(auto p : pf){
        ll x=p.second;
        ll y=1,tmp=0;
        while(y<=x){
            tmp++;
            x-=y;
            y++;
        }
        ans+=tmp;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3620
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = str(input())
    t = str(input())
    
    for i in range(N):
        if s[i] == t[0]:
            if s[i:] == t[:(N-i)]:
                print(len(s[:i]+s[i:]+t[(N-i):]))
                exit()
                
    print(len(s+t))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
s = input()
n = len(s)

cnt = 1
before = s[0]
ind = 1
while ind < n:
    if before != s[ind]:
        cnt += 1
        before = s[ind]
        ind += 1
    elif before == s[ind]:
        if ind < n-1:
            before = s[ind:ind+2]
            ind += 2
            cnt += 1
        else:
            ind += 1

print(cnt)

Measured memory_bytes: 3500
used = [[False for i in range(13) ]for i in range(4)]
mark = "SHCD"
dic = {"S":0, "H":1, "C":2, "D":3}

n = int(input())
for i in range(n):
    li = input().split()
    m = li[0]
    k = int(li[1])
    
    used[dic[m]][k - 1] =True

for i in range(4):
    for j in range(13):
        if (not used[i][j]):
            print("{0} {1}".format(mark[i], j+1))


Measured memory_bytes: 5600
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) {
                OUT("Yes");
                return 0;
            }
        }
    }
    OUT("No");
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 21 22:53:14 2020

@author: liang
"""

S = input()

ans = S[0]

for i in range(8):
    tmp = int(S[0])
    lis = list()
    for j in range(3):
        lis.append(i>>j&1)
    for i in range(3):
        if lis[i] == 1:
            tmp += int(S[i+1])
        else:
            tmp -= int(S[i+1])
    #print(tmp)
    if tmp == 7:
        for i in range(3):
            if lis[i] == 1:
                ans += "+" + S[i+1]
            else:
                ans += "-" + S[i+1]
        ans += "=7"
        break
    #print(lis)
else:
    print("err")
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
//using ll = long long;
#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll z = *x;
  *x = *y;
  *y = z;
}
void print(vector<ll> vec){
  ll length = (ll)vec.size();
  rep(i,length){
    if(i != 0){cout << " ";}
    cout << vec[i];
  }
  cout << endl;
}
ll gcd(ll x,ll y){
  if(y == 0){
    return x;
  }
  return gcd(y,x%y);
}
int main() {
  ll a,b;
  cin >> a >>b;
  if(a < b){
    swap(a,b);
  }
  tmp1 = gcd(a,b);
  bool flag = false;
  ll ans = 1;
  REP(i,2,1e7){
    flag = false;
    while(tmp1 % i == 0){
      if(!flag){
        ans++;
        flag = true;
      }
      tmp1 /= i;
    }
  }
  if(tmp1 != 1){
    ans++;
  }
  cout << ans;
}


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

bool dic_order( const string &lhs, const string &rhs )
{
	string temp1 = lhs + rhs;
	string temp2 = rhs + lhs;

	return temp1.compare( temp2 ) < 0;
}

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

	string strs[100];
	for ( int i = 0; i < N; ++i ) {
		cin >> strs[i];
	}

	sort( strs, strs + N, dic_order );

	string res;
	for ( int i = 0; i < N; ++i ) {
		res += strs[i];
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 1000011
#define LOG 20
#define inf	100000007
using namespace std;
char a[MAX];
int w[MAX],e[MAX];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	int n;
	cin>>n;
	memset(w,0,sizeof w);
	memset(e,0,sizeof e);
	for(int i = 1; i <= n ;i++)cin>>a[i];

	for(int i = 1; i <= n ; i++){
		w[i] = w[i-1];
		e[i] = e[i-1];
		if(a[i] == 'W')w[i]++;
		else e[i]++;
	}

	int ans = inf;
	for(int i = 1; i <= n ;i ++){
		// cout<<w[i-1] <<" " <<e[n] - e[i]<<endl;
		ans = min(ans ,w[i-1] + e[n] - e[i]);
	}
	cout<<ans;
	return 0;
}


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

#define LOOP(val,times) for(val = 0;val < (times);++val)

int main(){
    int dp[400];
    int n,W;
    int i,j;
    int weight,value;
    int inf,sup,score;
    scanf("%d",&n);
    LOOP(i,400) dp[i] = 0;
    LOOP(i,n){
        scanf("%d %d %d",&inf,&sup,&score);
        for(weight = inf;weight <= sup;weight++){
            bool flag = 1;
            while(flag){
                flag = 0;
                LOOP(j,400){
                    if(j >= weight && dp[j-weight] != 0 && dp[j] < dp[j-weight] + score){
                        flag = 1;
                        dp[j] = dp[j-weight] + score;
                    }
                    if(j == weight){
                        dp[j] = max(score,dp[j]);
                    }
                }
            }
        }
    }
    int ans[400];
    int m;
    scanf("%d",&m);
    LOOP(i,m){
        scanf("%d",&W);
        if(dp[W] == 0){
            printf("%d\n",-1);
            return 0;
        }
        ans[i] = dp[W];
    }
    LOOP(i,m){
        printf("%d\n",ans[i]);
    }
    int k;cin >> k;
}


Measured memory_bytes: 3236
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    return 0;
}



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

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

    int H, W; cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    int count = 0;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            cin >> a[i][j];

    vector<vector<int>> ans;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W-1; j++) {
            if (a[i][j] & 1) {
                a[i][j+1]++;
                ans.push_back({i+1, j+1, i+1, j+2});
            }
        }
    }
    for (int i = 0; i < H-1; i++) {
        if (a[i][W-1] & 1) {
            a[i+1][W-1]++;
            ans.push_back({i+1, W, i+2, W});
        }
    }

    cout << ans.size() << "\n";
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i].front();
        for (int j = 1; j < 4; j++)
            cout << " " << ans[i][j];
        cout << "\n";
    }
}

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

using namespace std;

const int NN = 2e5 + 5;
int n , a[NN];
long long comfort;

deque <int> posibil;

int main()
{
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    for(int i = 1, j = n ; i <= j ; i ++, j --)
        swap(a[i], a[j]);
    if(n == 2)
    {
        cout << a[1] << '\n';
    }
    else if(n == 3)
    {
        cout << a[1] + a[2] << '\n';
    }
    else
    {
        comfort += a[1];
        comfort += a[2];
        comfort += a[2];
        int sansa = 2;
        posibil.push_back(a[3]);
        posibil.push_back(a[4]);
        for(int i = 5 ; i <= n ; i ++)
        {
            if(sansa == 1)
            {
                sansa --;
                comfort += posibil.front();
                posibil.pop_front();
                sansa = 2;
            }
            else
            {
                sansa --;
                comfort += posibil.front();
            }
            posibil.push_back(a[i]);
        }
        cout << comfort << '\n';
    }
    return 0;
}


Measured memory_bytes: 4672
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

typedef long long ll;
using namespace std;

int main(){

    int N; cin >> N;

    int A[N];
    int B[N];
    int C[N];

    for(int i=0; i<N; i++) scanf("%d", &A[i]);
    for(int i=0; i<N; i++) scanf("%d", &B[i]);
    for(int i=0; i<N; i++) scanf("%d", &C[i]);

    sort(A, A+N);
    sort(C, C+N);
    long long int cnt=0;

    for(int i=0; i<N; i++){
        ll I = lower_bound(A, A+N, B[i]) - A;
        ll J = upper_bound(C, C+N, B[i]) - C;
        cnt += I * (N-J);
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h> 
using namespace std;
bool comp(long long a, long long b) 
{ 
    return (a < b); 
} 
int main()
{
    long long q,h,s,d,n,m;
    cin>>q>>h>>s>>d>>n;
    if(n==1)
    {
        cout<<std::min({s,2*h,4*q}, comp)<<endl;
    }
 else
    {
        m=std::min({d/2,s,2*h,4*q}, comp);
        if(m==d/2)
        {
            if(n%2==1)
            {long long t=((n-1)*d)/2 +(std::min({s,2*h,4*q}, comp));
            cout<<t<<endl;}
            else
           { long long t=(n*d)/2;
            cout<<t<<endl;}
        }
        else if(m==s)
        {long long t=n*m;
        cout<<t<<endl;}
        else if(m==2*h)
        {long long t=n*m;
        cout<<t<<endl;}
        else
        {long long t=n*m;
        cout<<t<<endl;}
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a = 0;
  int b = 0;
  
  cin >> a >> b;
  
  if (a > b) {
    for (int i = 0; i < a; i++) {
      cout << b;
    }
    cout << endl;
  } else {
    for (int i = 0; i < b; i++) {
      cout << a;
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  long long d = c - a - b;
  if (d > 0 && d * d > 4 * a * b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def b():
    N = int(input())
    count = 0
    res = "No"
    for i in range(N):
        d = set(map(int, input().split()))
        if len(d) == 1:
            count +=1
        else:
            count = 0
        if count == 3:
            res = "Yes"
            break
    print(res)
    
b()

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
int n,fa[N];
ll ans,d,a[N],l[N],r[N];
int main()
{
	cin>>n>>d;
	ans=(n-1)*d;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),ans+=a[i],l[i]=r[i]=1e18;
	l[1]=a[1];
	for(int i=2;i<=n;i++)l[i]=min(l[i-1],a[i]-(i-1)*d);
	r[n]=a[n]+(n-1)*d;
	for(int i=n-1;i;i--)r[i]=min(r[i+1],a[i]+(i-1)*d);
	for(int i=2;i<n;i++)ans+=min((i-1)*d+l[i],r[i]-(i-1)*d);
	cout<<ans<<endl;
}

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

int main() {
  int a = 0;
  int b = 0;
  cin >> a >> b;
  if(a <= 8 && b <= 8){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;

int N;
string S;
map<char, int> mp;

void Input() {
    cin >> N >> S;
    for(char a = 'a'; a <= 'z'; a++) mp[a] = 0;
    return;
}

int main() {
    Input();
    for (char c : S) { mp[c]++; }
    long long ans = 1;
    for (char a = 'a'; a <= 'z'; a++) {
        ans *= (mp[a]+1);
        ans %= MOD;
    }
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 512
let n = stdin.ReadLine() |> int
let s = stdin.ReadLine()
if 
    s.Length % 2 = 0 && 
    (s |> Seq.take(n / 2)) |> Seq.forall2 (fun a b -> a = b) (s |> Seq.skip(n / 2)) 
then "Yes" else "No"
|> stdout.WriteLine

Measured memory_bytes: 13396
n,d=map(int,input().split())
x=[]
ans=0
for i in range(n):
  y=list(map(int,input().split()))
  x.append(y)
for i in range(n):
  for j in range(i,n):
    l=0
    for k in range(d):
      l+=(x[i][k]-x[j][k])**2
    for z in range(1,int(1+40*(d**0.5))):
      if z*z==l:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include <cstddef>
#include <limits>
#include <climits>
#include <cfloat>
#include <cstdint>
#include <cstdlib>
#include <new>
#include <typeinfo>
#include <exception>
#include <initializer_list>
// #include <cstdalign>
#include <stdexcept>
#include <cassert>
#include <cerrno>
#include <system_error>
#include <string>
 
#if __has_include(<string_view>)
#include <string_view>
#endif
 
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>

using namespace std;
 
int main() {
  int a, b;
  scanf("%d", &a);
  scanf("%d", &b);
  
  cout << a * b << endl;
  
  return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////
struct edge { ll to, cost; };
int main() {
	ll n, m, s, t;
	cin >> n >> m >> s >> t;
	s--, t--;
	ll u[100100], v[100100], a[100100], b[100100];
	vector<vector<pair<ll, ll>>>ypath(n), spath(n);
	for (int i = 0; i < m; ++i) {
		cin >> u[i] >> v[i] >> a[i] >> b[i];
		u[i]--, v[i]--;
		ypath[u[i]].push_back({ v[i],a[i] });
		ypath[v[i]].push_back({ u[i],a[i] });
		spath[u[i]].push_back({ v[i],b[i] });
		spath[v[i]].push_back({ u[i],b[i] });
	}
	vector<ll>ydis(n + 1, 1LL << 50), sdis(n + 1, 1LL << 50);
	ydis[s] = 0;
	sdis[t] = 0;
	priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>>yen, snuuk;
	yen.push({ 0,s });
	snuuk.push({ 0,s });
	while (!yen.empty()) {
		pair<ll, ll> p = yen.top();
		yen.pop();
		ll v = p.second;
		if (ydis[v] < p.first)continue;
		for (int i = 0; i < ypath[v].size(); ++i) {
			edge e = { ypath[v][i].first,ypath[v][i].second };
			if (ydis[e.to] > ydis[v] + e.cost) {
				ydis[e.to] = ydis[v] + e.cost;
				yen.push({ ydis[e.to],e.to });
			}
		}
	}
	snuuk.push({ 0,t });
	while (!snuuk.empty()) {
		pair<ll, ll>p = snuuk.top();
		snuuk.pop();
		ll v = p.second;
		if (sdis[v] < p.first)continue;
		for (int i = 0; i < spath[v].size(); ++i) {
			edge e = { spath[v][i].first,spath[v][i].second };
			if (sdis[e.to] > sdis[v] + e.cost) {
				sdis[e.to] = sdis[v] + e.cost;
				snuuk.push({ sdis[e.to],e.to });
			}
		}
	}
	vector<ll>ans(n + 1, 1e15);
	for (int i = n-1; i >=0; --i) {
		ans[i] = min(ans[i + 1], ydis[i] + sdis[i]);
	}
	ll tmp = 1e15;
	for (int i = 0; i < n; ++i) {
		cout << tmp-ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 23288
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

check = [True] * (N + 1)
count = 0

now = 1
while check[A[now]] and K:
    now = A[now]
    check[now] = False
    K -= 1

if K == 0:
    print (now)
    exit()


check = [True] * (N + 1)
count = 0

while check[A[now]] and K:
    now = A[now]
    check[now] = False
    count += 1
    K -= 1

if K == 0:
    print (now)
    exit()

K %= count

while K:
    K -= 1
    now = A[now]

print (now)



Measured memory_bytes: 31116
c=[]
for i in range(3):
    c1=list(map(int,input().split()))
    c.append(c1)
ans='No'
if c[0][0]-c[0][1]==c[1][0]-c[1][1]==c[2][0]-c[2][1]:
    if c[0][1]-c[0][2]==c[1][1]-c[1][2]==c[2][1]-c[2][2]:
        if c[0][0]-c[1][0]==c[0][1]-c[1][1]==c[0][2]-c[1][2]:
            if c[1][0]-c[2][0]==c[1][1]-c[2][1]==c[1][2]-c[2][2]:
                ans='Yes'
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split())) # 横入力

x = [0]
aaa = 0
aa = sum(a)
y = [aa]
for i in range(n):
    aaa += a[i]
    x.append(aaa)
    aa -= a[i]
    y.append(aa)

ans = 202020202020
for i in range(n+1):
    ans = min(ans, abs(x[i] - y[i]))

print(ans)

Measured memory_bytes: 30572
import java.util.*;
public class Main {

    public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
        Double d, v, y;
        int a;
        while (sc.hasNext()){
            d = sc.nextDouble();
            v = d/9.8;
            y = (v*v)*4.9;
            a = (int)Math.ceil((y+5)/5);
            System.out.println(a);
        }
    }
}

Measured memory_bytes: 18776
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define RB rbegin()
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define MD 1000000007
#define PPF pop_front()
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;u.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>u,uc;
LL ar[120005];
LL br[500005];
LL cr[500][500];
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c,str;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    while(tt--)
    {
//        UOSMOY;
cin>>n;
cout<<n+(n*n)+(n*n*n)<<endl;

    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 3616
n=gets.chomp.to_i
array= gets.chomp.split.map(&:to_i)

n.times do |i|
    if array[i] % 2==0
        unless array[i]%3==0 || array[i]%5==0
            puts "DENIED"
            exit
        end
    end
end

puts "APPROVED"

Measured memory_bytes: 1788
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
    string s;
    vector<char> fs;

	cin >> s;
	
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'B') {
			if (!fs.empty()) {
				fs.pop_back();	
			}
		}
		else {
			fs.push_back(s[i]);
		}
	}

	for (vector<char>::iterator it = fs.begin(); it != fs.end(); ++it) {
		cout << *it;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define f first
#define s second
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string h="" ,s;
	cin>>s;
	for(char it:s)
	{
		if(it=='B')
		{
			if(h.length()!=0)
				h = h.substr(0,h.length()-1);
		}
		else
			h+= it;
	}
	cout<<h<<endl;
	return 0;
}

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

using namespace std;

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

  auto d = div(S, 60);
  auto s = d.rem;
  d = div(d.quot, 60);
  auto m = d.rem;
  auto h = d.quot;

  cout << h << ':' << m << ':' << s << endl;
  return 0;
} 



Measured memory_bytes: 3100
#include <cstdio>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;
typedef long long LL;


int main(void) {

	LL A, B, C, X, Y, m1, m2, m3;

	cin >> A >> B >> C >> X >> Y;

	m1 = A * X + B * Y;

	m2 = 2 * C * max(X, Y);

	if (X < Y)
		m3 = 2 * C * X + (Y - X) * B;
	else
		m3 = 2 * C * Y + (X - Y) * A;


	cout << min({ m1,m2,m3 }) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 300000;
int sum[MAXN + 5];
int cnt[MAXN + 5], ans[MAXN + 5];
int N, x;
int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++)
		scanf("%d", &x), cnt[x]++;
	sort(cnt + 1, cnt + N + 1);
	int p = 1;
	for(int i=1;i<=N;i++)
		sum[i] = cnt[i] + sum[i-1];
	for(int i=1;i<=N;i++) {
		while( p < N && cnt[p + 1] <= i ) p++;
		int k = sum[p] + (N - p)*i;
		ans[k / i] = i;
	}
	for(int i=N;i>=1;i--)
		ans[i] = max(ans[i], ans[i + 1]);
	for(int i=1;i<=N;i++)
		printf("%d\n", ans[i]);
}

Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <bitset>

using namespace std;
typedef long long ll;

int main(){
    int n;
    int a[2020];
    cin >> n;
    int sm=0;
    for(int i=0;i<n;i++){ cin >> a[i]; sm+=a[i];}
    sm = (sm + 1) / 2;

    bitset<4000001> dp;
    dp.set(0);
    for(int i=0;i<n;i++){
        bitset<4000001> pd;
        pd = dp;
        dp |= pd << a[i];
    }
    
    while(dp[sm]==0) sm++;
    printf("%d\n", sm);

   return 0;
}

Measured memory_bytes: 2304
import math
X, K, D = map(int, input().split())

kyori = abs(X)
kaisu = math.ceil(kyori / D)

if(K < kaisu):
    ans = kyori - (K * D)
    #if(X < 0):
    #    print(-ans)
    #else:
    #    print(ans)
else:
    if((K - kaisu) % 2 == 0):
        ans = kyori - (kaisu * D)
    else:
        ans = kyori - (kaisu * D) + D

    #if(X < 0):
    #    print(-ans)
    #else:
    #    print(ans)

print(abs(ans))

Measured memory_bytes: 9140
def N():
    return int(input())
def L():
    return list(map(int,input().split()))
def NL(n):
    return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7
#import numpy
k = N()
a,b = L()
for i in range(a,b+1):
    if i%k == 0:
        print("OK")
        exit()
print("NG")

Measured memory_bytes: 9180
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

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

long long N;
long long dp[100010][3];
long long happy[100010][3];
long long inf = 1<<30;

int main() {
    scanf("%Ld", &N);
    for (int i = 0; i < N; i++) for(int j = 0; j < 3; j++) scanf("%Ld", & happy[i][j]);

    for (int i = 1; i < N+1; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++){
                if (j != k) chmax(dp[i][j], dp[i-1][k] + happy[i-1][k]);
            }
        }
    }

    long long maxelement = 0;
    for (int i = 0; i < 3; i++) maxelement = max(maxelement, dp[N][i]);
    printf("%Ld\n", maxelement);

}

Measured memory_bytes: 4992
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,m,n,ans;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(a<=b && a<=c){
		m=a-25;
	}
	else if(b<=a && b<=c){
		m=b-25;
	}
	else if(c<=a && c<=b){
		m=c-25;
	}
	if(d<=e){
		n=d-25;
	}
	else if(e<=d){
		n=e-25;
	}
	ans=m+n;
	printf("%d\n",ans);
	return 0;
}


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

int mx;
int nm[11],ans;

void dfs(int a,int b,int brw,int k,int x){
  int ai,bi;
  if(a==0){
      int pnt=0;
    for(int i=x-1;i>=0;i--) pnt=pnt*10+nm[i];
    ans=max(ans,pnt);
    return;
  }
    ai=a%10,bi=b%10; 
  a/=10,b/=10;
  if(brw==0){
    if(ai-brw>=bi) nm[x]=ai-brw-bi,brw=0;
    else nm[x]=ai-brw-bi+10,brw=1;
   dfs(a,b,brw,k,x+1);
  }else{
    if(k>0){
      brw=0;
      if(ai-brw>=bi)nm[x]=ai-brw-bi,brw=0;
      else nm[x]=ai-brw-bi+10,brw=1;
      dfs(a,b,brw,k-1,x+1);
    }
    brw=1;
    if(ai-brw>=bi) nm[x]=ai-brw-bi,brw=0;
    else nm[x]=ai-brw-bi+10,brw=1;
    dfs(a,b,brw,k,x+1);
  }
}

int main(){
  int k,brw=0,a,b;
  cin>>a>>b>>k;
  dfs(a,b,brw,k,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <set>
#include <vector>

int main()
{
  int N, M;
  std::set<int> a;
  
  std::cin >> N >> M;
  for(int i=0; i<M; i++){
    int temp;
    std::cin >> temp;
    a.insert(temp);
  }
  
  std::vector<long long int> pattern(N+1);
  pattern[0] = 1;
  pattern[1] = a.find(1) != a.end() ? 0 : 1;
  
  for(int i=2; i<N+1; i++){
    if(a.find(i) != a.end()){
      pattern[i] = 0;
    } else {
      pattern[i] = (pattern[i-1] + pattern[i-2]) % 1000000007;
    }
  }
  
  std::cout << pattern[N] % 1000000007;
  
  return 0; 
}

Measured memory_bytes: 5760
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;



void Show(vector<bool> Ps) {
	for (int i = 0; i < Ps.size(); i++) {
		if (Ps[i]) {
			cout << "T" << endl;
		} else {
			cout << "F" << endl;
		}
	}
}

void Show(vector<int> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		cout << Ns[i] << endl;
	}
}



int main() {
	int N, X;
	cin >> N >> X;
	vector<int> Keys;
	Keys.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> Keys[i];
		Keys[i] = abs(Keys[i] - X);
	}
	int Min = Keys[0];
	int Answer = 1;
	for (int i = 0; i < N; i++) {
		bool OK = true;
		Min = min(Min, Keys[i]);
		for (int j = 0; j < N; j++) {
			if (Keys[j] % Keys[i] != 0) {
				OK = false;
				break;
			}
		}
		if (OK) {
			Answer = max(Answer, abs(Keys[i]));
		}
	}
	if (Answer == 1) {
		int A = 1;
		for (int i = 1; i < Min; i++) {
			bool OK = true;
			for (int j = 0; j < N; j++) {
				if (Keys[j] % i != 0) {
					OK = false;
					break;
				}
			}
			if (OK) {
				A = i;
			}
		}
		Answer = A;
	}
	cout << Answer << endl;
}

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

template <typename T>
void print(const T &v);

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, m)
    {
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
    }
    int ans = 0;
    for (int i = 0; i < m; i++) // 各辺を除外したケースを計算する
    {
        vector<vector<int>> G(n);
        rep(j, m)
        {
            if (j == i)
            {
                continue;
            }
            G[a[j]].push_back(b[j]);
            G[b[j]].push_back(a[j]);
        }
        queue<int> qe;
        qe.push(0);
        vector<bool> seen(n, false);
        while (!qe.empty())
        {
            int now = qe.front();
            qe.pop();
            if (seen[now])
            {
                continue;
            }
            for (int next : G[now])
            {
                if (!seen[next])
                {
                    qe.push(next);
                }
            }
            seen[now] = true;
        }
        for (bool s : seen)
        {
            if (!s)
            {
                ++ans;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (IntStream.rangeClosed(1, 9).anyMatch(num -> (n % num == 0) && (n / num < 10))) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 27472
import math
def ccw(p1,p2,p3):
    return (p2[0]-p1[0])*(p3[1]-p2[1])-(p2[1]-p1[1])*(p3[0]-p2[0])
while True:
    n=input()
    if n==0:
        break
    p=[0]*n
    for i in xrange(n):
        p[i]=map(float,raw_input().strip().split(","))
    P=min(p,key=lambda a:(a[1],a[0]))
    p.sort(key=lambda x:math.atan2(x[1]-P[1],x[0]-P[0]))
    M=0
    ans=0
    for i in xrange(1,n-1):
        if all([ccw(p[M],p[i],p[j])>=0 for j in xrange(i+1,n)]):
            M=i
        else:
            ans+=1
    print ans

Measured memory_bytes: 4488
import qualified Data.ByteString.Char8 as B
import Data.List
main=do
    n<-readLn::IO Int
    as<-map read.words<$>getLine::IO[Int]
    print $ sol n as

sol n as = snd $ minimum $ zip (map (\a->abs(a*n-sm)) as) [0..]
    where
        sm = sum as


Measured memory_bytes: 1020
// from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("[line({})] {}: {:?}", line!(), stringify!($x), $x) };}
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};
#[allow(unused_imports)]
use std::mem::swap;

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    #[allow(unused_macros)]
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    #[allow(unused_macros)]
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut map = HashMap::new();
    map.insert(0, 1_usize);
    let mut sum = 0;
    for &e in &a {
        sum += e;
        let r = map.entry(sum).or_insert(0);
        // ans += *r;
        *r += 1;
    }
    let ans: usize = map.iter().map(|(_, x)| x * (x - 1) / 2).sum();
    println!("{}", ans);
}


Measured memory_bytes: 20632