akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
public class Main {

	public static void main(String[] args) throws IOException{
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		
		double x=0.0, y = 0.0, kaku = 90.0/180*Math.PI; 			
		
		while(true){
			int n = 2;
			String c = br.readLine();
			if(c.equals("0,0"))
				break;
			double[] arr = new double[n];
			for(int i = 0; i < n; i++){
				if(c.indexOf(",") !=  -1){
					String str = c.substring(0, c.indexOf(","));
					arr[i] = Double.parseDouble(str);
					c = c.substring(c.indexOf(",") + 1);
				}
				else{
					arr[i] = Double.parseDouble(c);
				}
			}
			
			x += Math.cos(kaku)*arr[0];
			y += Math.sin(kaku)*arr[0];
			kaku -= arr[1]/180.0*Math.PI;
			
			

		}
		System.out.println((int)x);
		System.out.println((int)y);
		
	}

}

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

int main() {
	int x, n;
	cin >> x >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	int mn = 1001001;
	int ans = 0;
	if(n == 0) {
		cout << x << endl;
		return 0;
	}
	for(int i = -1; i < 102; i++) {
		bool ok = true;
		rep(j, n) {
			if (p[j] == i) {
				ok = false;
				break;
			}
		}
		if (ok) {
			if (mn > abs(x-i)) {
				mn = abs(x-i);
				ans = i;
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

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

int main(){
  string A, B, C;
  cin >> A >> B >> C;
  queue<char> qa, qb, qc;
  rep(i,sz(A)) qa.push(A[i]);
  rep(i,sz(B)) qb.push(B[i]);
  rep(i,sz(C)) qc.push(C[i]);
  char now = 'a';

  while (1){
    
    if (now == 'a') {
      if (qa.empty()) break;
      now = qa.front(), qa.pop();
    } else if (now == 'b') {
      if (qb.empty()) break;
      now = qb.front(), qb.pop();
    } else {
      if (qc.empty()) break;
      now = qc.front(), qc.pop();
    }
  }
  now = now - 0x20;
  cout << now << endl;
  return 0;
} 

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
 
/*
--------------------------------------------
 
	type
 
--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;
 
/*
--------------------------------------------
 
	container
 
--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
 
/*
--------------------------------------------
 
	repetition
 
--------------------------------------------
*/
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)
 
//algorithm
//#define SORT(c) sort((c).begin(),(c).end())
 
/*
--------------------------------------------
 
	constant
 
--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
/*
 
	Optimizer
 
*/
//#pragma GCC optimize("Ofast")


/*
 
	Utility Algorithm
 
*/
template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}

LL euclideanAlgorithm(LL a, LL b) {
    LL a_tmp = a;
    LL b_tmp = b;

    if (a_tmp > b_tmp) {
        swapAlgorithm<LL>(a_tmp, b_tmp);
    }

    LL r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

LL getLCM(LL a, LL b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

/*
  Code
*/

int main(int argc, char const *argv[])
{
  int N;
  cin >> N;

  string S;
  cin >> S;

  if(N % 2 == 1) {
    cout << "No" << endl;
  }
  else {
    if (S.substr(0, N/2) == S.substr(N/2, N/2)) {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
class MyBinaryNode
  attr_accessor :parent, :left, :right

  def initialize
    @parent = -1
    @left = -1
    @right = -1
  end

  def sibling(self_id, nodes)
    if @parent == -1
      return -1
    else
      parent = nodes[@parent]
      if parent.right == self_id
        return parent.left
      else
        return parent.right
      end
    end
  end

  def depth(nodes)
    if @parent == -1
      return 0
    else
      return nodes[@parent].depth(nodes) + 1
    end
  end

  def height(nodes)
    if @right == -1 && @left == -1
      return 0
    elsif @right == -1 && @left != -1
      return nodes[@left].height(nodes) + 1
    elsif @right != -1 && @left == -1
      return nodes[@right].height(nodes) + 1
    else
      return [nodes[@right].height(nodes),nodes[@left].height(nodes)].max + 1
    end
  end

  def degree
    degree = 0
    if @right != -1
      degree += 1
    end
    if @left != -1
      degree += 1
    end
    return degree
  end

  def type
    if @parent == -1
      "root"
    elsif @left != -1 || @right != -1
      "internal node"
    else
      "leaf"
    end
  end
end


n = gets.to_i
nodes = []
n.times do
  nodes << MyBinaryNode.new
end


n.times do
  inputs = gets.split.map(&:to_i)
  node_id = inputs.shift
  node = nodes[node_id]
  left = inputs.shift
  if left != -1
    node.left = left
    left_node = nodes[left]
    left_node.parent = node_id
  end
  right = inputs.shift
  if right != -1
    node.right = right
    right_node = nodes[right]
    right_node.parent = node_id
  end
end

root_id = nil
nodes.each_with_index do |node, i|
  if node.parent.nil?
    node.parent = -1
    root_id = i
  end
end

# set_depth(nodes, root_id, 0)

nodes.each_with_index do |node, i|
  puts "node #{i}: parent = #{node.parent}, sibling = #{node.sibling(i, nodes)}, degree = #{node.degree}, depth = #{node.depth(nodes)}, height = #{node.height(nodes)}, #{node.type}"
end


Measured memory_bytes: 6880
#include<bits/stdc++.h>
#define Mx 1000000000005 
#define ll long long  
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll,ll>
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define vii vector<pair<ll,ll> > 
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a,x) memset(a,x,sizeof(a))
using namespace std;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
  return a.second<b.second;
}
/*vi b=v;
   sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  ll t; cin>>t; fr(f,0,t){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 */

int main()
{
  ll n,W; cin>>n>>W;
  ll wt[n],v[n],ans;
  fr(i,0,n)
    cin>>wt[i]>>v[i];

  vector<vector<ll>> dp(n+1, vector<ll>(1e5 + 1, 0));

  fr(i,0,n+1)
    dp[i][0]=0;
  fr(j,0,1e5 + 1)
    dp[0][j]=Mx;

  dp[0][0]=0;

  fr(i,1,n+1)
  {
    fr(j,1,1e5+1)
    {
      dp[i][j]=dp[i-1][j];
      if(j>=v[i-1])
        dp[i][j]=min(dp[i][j], wt[i-1]+dp[i-1][j-v[i-1]]);
    }
  }

  for(ll i=1e5;i>=0;i--)
    if(dp[n][i]<=W)
    {
      ans=i;
      break;
    }

  cout<<ans;

}

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

long long N, A, B;

int main() {
    cin >> N >> A >> B;
    if (B < A || (N == 1 && A != B)) {
        cout << 0 << endl;
        return 0;
    }
    cout << (N - 2) * (B - A) + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    ll a,b,m;
    cin >> a >> b >> m;

    ll aa[a],bb[b];
    inrep(a,aa);
    inrep(b,bb);

    ll ans  = linf;

    rep(i,0,m){
	ll x,y,c;
	cin >> x>> y >> c;
	ans = min(ans,aa[x-1]+bb[y-1]-c);
    }

    
    sort(aa,aa+a);
    sort(bb,bb+b);
    ans = min(ans,aa[0]+bb[0]);
    
    P(ans);
    return  0;
}


Measured memory_bytes: 1792
import sys

input = sys.stdin.readline


def main():
    n, t = map(int, input().split())
    routes = list(
        filter(lambda x: x[1] <= t, [list(map(int, input().split())) for _ in range(n)])
    )
    if routes:
        print(min(routes)[0])
    else:
        print("TLE")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
s = [input() for i in range(2)]
n = int(s[0])
l = s[1].split()
n1 = int(l[0])
n2 = int(l[1])
m="NG"
i=n1
while i <= n2:
    if i % n==0:
        m = "OK"
        break
    i +=1
print(m)

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

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

}


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

int main(void){
  int N;
  vector<int> nums;
  
  while(cin >> N){
    int times=0;
    if(N==0){
      break;
    }
    if(N%1111==0){
      cout << "NA" << endl;
    }
    else{
      while(N!=6174){
	for(int i=1;i<=4;i++)
	  nums.push_back( (N% (int)pow(10,i) )/(int)pow(10,i-1) );
	N=0;
	sort(nums.begin(),nums.end(),greater<int>());
	for(int i=0;i<4;i++)
	  N+=nums[i]*pow(10,4-i-1)-nums[i]*pow(10,i);
	times++;
	nums.clear();
      } 
      cout << times << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1260
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int H,W;
vector<string> vs;

bool dfs(int y, int x, int nokori)
{
  if(nokori==0) return true;
  bool ret = false;
  if(x+1 < W && vs[y][x+1] == '#') ret |= dfs(y,x+1,nokori-1);
  if(y+1 < H && vs[y+1][x] == '#') ret |= dfs(y+1,x,nokori-1);
  return ret;
}

int main(){
  cin>>H>>W;
  int cnt = 0;
  FOR(y,0,H){
    string s;
    cin>>s;
    vs.push_back(s);
    FOR(x,0,s.length())
    {
      if(s[x]=='#') cnt++;
    }
  }
  if(cnt!=H+W-1)
  {
    cout << "Impossible" << endl;
    return 0;
  }
  if(dfs(0,0,H+W-2))
  {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
function Main(input) {
   input = input.split('\n');
   n = parseInt(input[0]);
   a = parseInt(input[1]);
   wattaamari = n % 500;
   if (wattaamari <= a) {
       console.log('Yes');
   } else {
       console.log('No');
   }
}
 Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;

typedef long long ll;
typedef vector<int> vi;

ll mod = 1e9+7;

ll solve() {
    int n; cin >> n;

    ll sum = 0;
    rep(x, n + 1) {
        if (x % 3 != 0 && x % 5 != 0) 
            sum += x;
    }

    return sum;
}

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

	cout << solve() << endl;
}


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

// @@ !! LIM()

ll solve() {
  ll N, M; cin >> N >> M;
  if (M == 1) {
    if (N == 1) return 0;
    return N * (N-1) / 2;
  }
  if (N == 1) {
    return M * (M-1) / 2;
  }
  return N * (N-1) / 2 + M * (M-1) / 2;
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);
  cout << solve() << endl;

  return 0;
}



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

int main(){
  ll n;
  cin >> n;
  ll c = n, ans = n;
  ll a[3], b[3];
  rep(i,3) cin >> a[i];
  rep(i,3) cin >> b[i];
  vector<ll> dp1(n+1,-INF);
  dp1[0] = 0;
  rep(i,n+1) {
    rep(j,3) {
      if(i-a[j] >= 0) dp1[i] = max(dp1[i],dp1[i-a[j]]+b[j]);
    }
  }
  rep(i,n+1) c = max(c,dp1[i]+n-i);
  vector<ll> dp2(c+1,-INF);
  dp2[0] = 0;
  rep(i,c+1) {
    rep(j,3) {
      if(i-b[j] >= 0) dp2[i] = max(dp2[i],dp2[i-b[j]]+a[j]);
    }
  }
  rep(i,c+1) ans = max(ans,dp2[i]+c-i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 195584
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = 1;
        Map<String, Integer> map = new HashMap<>();
        for (int i=0; i<n; i++) {
            String s = sc.next();
            if (map.containsKey(s)) {
                max = Math.max(max, map.get(s) +1);
                map.put(s, map.get(s) +1);
            } else {
                map.put(s, 1);
            }
        }
//        String[] array = new String[map.size()];
        List<String> array = new ArrayList<>();
        int i = 0;
        for (String key : map.keySet()) {
            if (map.get(key) == max) {
//                array[i] = key;
                array.add(key);
                i++;
            }
        }
//        Arrays.sort(array);
        Collections.sort(array);
        for (String s : array) {
            System.out.println(s);
        }
    }
}

Measured memory_bytes: 83236
/// hi_im_manh :D
#include <bits/stdc++.h>
#define reset(a,n) memset(a,0,(n+1)*sizeof(int))
#define endl "\n"
#define llmin LLONG_MIN
#define llmax LLONG_MAX
#define intmax INT_MAX
#define intmin INT_MIN
#define ll long long
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define duckman "TASK"

#define input freopen(duckman".inp", "r", stdin);
#define output freopen(duckman".out", "w", stdout);

#define nmax 22000
using namespace std;


int main()
{
    fast;
//    input;
//    output;
    int a, b;
    cin >> a >> b;
    for (int i = 1; i <= 1e4; ++i) {
        int a2 = i*0.08;
        int b2 = i*0.1;
        if (a2 == a && b2 == b) {
            cout << i;
            return 0;
        }
    }
    cout << -1;
}
/*


*/


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        String S = scanner.next();
        scanner.close();


        String[] splitStr = S.split("");

        String current = splitStr[0];
        int count = 1;
        for (int i = 1; i < N; i++) {
            if (current.equals(splitStr[i])) {
                continue;
            }
            current = splitStr[i];
            count++;
        }

        System.out.println(count);

    }

}


Measured memory_bytes: 32488
n = int(input())
INFTY = 10**8

p = [0]*(n+1)
for i in range(n):
    roww = input().split()
    p[i] = int(roww[0])
    p[i+1] = int(roww[1])

M = [[0]*n for i in range(n)]

def matricChainMultiplication(n, p, M):
#     2つの行列積のmin, 次は3という風に増やしていく
    for l in range(2, n+1):
        for i in range(0, n - l + 1):
            j = i + l - 1 #積を見る最大のIndex
            M[i][j] = INFTY
            for k in range(i, j):
                M[i][j] = min(M[i][j],
                              M[i][k] + M[k+1][j] +
                              p[i] * p[k+1] * p[j+1] )
#                 print(l, i, j, k, M[i][j])
    return M[0][n-1]

print(matricChainMultiplication(n, p, M))



Measured memory_bytes: 5672
Q = gets.to_i
plist = []
2.upto(100000) do |n|
  isprime = true
  2.upto(n - 2) do |k|
    break if k ** 2 > n
    if n % k == 0 
      isprime = false
      break
    end
  end
  plist.push(n) if isprime
end

llist = plist.select{|n| plist.include?((n + 1) / 2)}
llist.unshift(-1)
llist.push(10 ** 6)

Q.times do
  l, r = gets.split(' ').map(&:to_i)
  l = llist.bsearch_index{|n| n >= l}
  r = llist.bsearch_index{|n| n > r}
  puts r - l
end

Measured memory_bytes: 2300
h,w = map(int,input().split())

n = int(input())

arr = list(map(int,input().split()))
ans = [[0 for i in range(w)] for j in range(h)]

right = True
temp = 0
ind = 1
for i in range(h):
    for j in range(w):
        if right:
            ans[i][j] = ind
            temp += 1
        else:
            ans[i][-j-1] = ind
            temp += 1
        if temp>=arr[ind-1]:
            ind += 1
            temp = 0
    right = not right

for i in range(h):
    for j in range(w-1):
        print(ans[i][j],end=" ")
    print(ans[i][-1])

Measured memory_bytes: 3916
n=int(input())
l=[[] for i in range(n+1)]
l[0]=[0,0,0]
for i in range(1,n+1):
    l[i]=list(map(int,input().split()))
for i in range(n):
    flag=False
    t=l[i+1][0]-l[i][0]
    x=l[i+1][1]-l[i][1]
    y=l[i+1][2]-l[i][2]
    for a in range(t+1):
        for b in range(t+1-a):
            c=a-x
            d=b-y
            if a+b+c+d==t:
                flag=True
                break
        if flag: break
    if not flag:
        print("No")
        break
if flag: print("Yes")

Measured memory_bytes: 58656
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

/**
 * @brief Union-Find
 * @docs ./docs/union_find.md
 */

#include <algorithm>
#include <vector>

struct UnionFind {
private:
    const int n;
    int size_;
    vector<int> uf;
public:
    // 初期化 UnionFind uni(n) のように宣言すれば良い
    UnionFind(int _n) : n(_n), size_(_n), uf(_n, -1) {}
    // find (木の根を求める)
    int find(int x) {return (uf[x] < 0) ? x : uf[x] = find(uf[x]);}
    // x と y が同じ集合に属するかどうか
    bool same(int x, int y) {return find(x) == find(y);}
    // x が属する集合の要素数
    int size(int x) {return -uf[find(x)];}
    // 集合はいくつあるか
    int size()      {return size_;}
    // x と y の属する集合を併合
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        size_--;
        if(-uf[x] < -uf[y]) swap(x, y);
        uf[x] += uf[y]; uf[y] = x;
        return true;
    }
};

int solve_testcase() {
    int N; cin >> N;
    if(N == 0) return 1;

    vector< vector<int> > D(35);
    vector< vector<bool> > T(N, vector<bool>(N));
    for(int i=0; i<N; i++) {
        T[i][i] = true;
        int K; scanf("%d", &K);
        for(int j=0; j<K; j++) {
            int d; scanf("%d", &d);
            D[d].emplace_back(i);
        }
    }

    int ans = -1;
    for(int d=1; d<=30; d++) {
        for(size_t i=0; i<D[d].size(); i++) {
            for(size_t j=0; j<D[d].size(); j++) {
                if(i == j) continue;
                int u = D[d][i], v = D[d][j];
                for(int x=0; x<N; x++) {
                    if(T[x][u]) T[x][v] = true;
                    if(T[x][v]) T[x][u] = true;
                }
            }
        }

        for(int i=0; i<N; i++) {
            bool ok = true;
            for(int j=0; j<N; j++) {
                ok &= (T[j][i]);
            }
            if(ok) {
                ans = d;
                break;
            }
        }
        if(ans >= 0) break;
    }
    
    cout << ans << endl;
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 3124
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static void calc_ans (int *n_ac, int *n_penalty, int n_ques, int n_subm) {
    int     i, n;
    char    result[3];
    int8_t  is_ac[n_ques];  /* if AC then 1, else 0 */
    int     n_wa[n_ques];

    memset(is_ac, 0, n_ques*sizeof(int8_t));
    memset(n_wa, 0, n_ques*sizeof(int));

    for ( i=0; i<n_subm; i++ ) {
        scanf("%d%s", &n, result);
        if ( !strncmp("AC", result, 2) )
            is_ac[n-1] = 1;
        else if ( is_ac[n-1] != 1 )
            n_wa[n-1]++;
    }

    for ( i=0; i<n_ques; i++ ) {
        if ( is_ac[i] == 1 ) {
            (*n_ac)++;
            *n_penalty += n_wa[i];
        }
    }
}

int main (void) {
    int n, m;
    int n_ac=0, n_penalty=0;

    scanf("%d%d", &n, &m);
    calc_ans(&n_ac, &n_penalty, n, m);
    printf("%d %d\n", n_ac, n_penalty);

    return EXIT_SUCCESS;
}


Measured memory_bytes: 640
import sys
def input(): return sys.stdin.readline().strip()

def pow_two(n):
    ret = 0
    while n % 2 == 0:
        n //= 2
        ret += 1
    return ret

def main():
    n = int(input())
    A = list(map(int, input().split()))
    ans = 10**10
    for a in A: ans = min(ans, pow_two(a))
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 62948
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cast static_cast
#define ll long long int
#define v vector
#define vi vector< int >
#define vpi vector< pair< int,int > >
using namespace std;
ll modF=1e7;

void solve(){
	int n,k;
	cin>>n>>k;
	int h[n+1];
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	int dp[n+1];
	dp[1]=0;
	for(int i=2;i<=n;i++){
		int min=INT_MAX;
		for(int j=i-1;j>=1 && j>=i-k;j--){
			if(dp[j]+abs(h[i]-h[j])<min)
				min=dp[j]+abs(h[i]-h[j]);
		}
		dp[i]=min;
	}
	cout<<dp[n]<<"\n";
}

int main(){
	boost_io;
	solve();
	return 0;
}

Measured memory_bytes: 4392
import collections

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

# k番目の数字の総数がkey、そのときの答えがvalue
removes = {}

c = collections.Counter(A)
c2 = {}
for key in c:
    if c[key] > 1:
        c2[key] = c[key]

def comb(n):
    return (n * (n - 1)) // 2

# print(c2)
for k in range(N):
    # k番目の数字
    i = A[k]
    # k番目の数字の総数
    count = c[i]
    if count not in removes:
        answer = 0
        for key in c2:
            if i == key:
                answer += comb(c2[key] - 1)
            else:
                answer += comb(c2[key])
        removes[count] = answer
    print(removes[count])


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

double f(int i,int n,int k){
  int count=0,m=2;
  while(i<k){
  	i=i*2;
    count++;
  }
  if(count==0)
    return (double)1/n;
  else if(count==1)
    return (double)1/(n*2);
  else{
  for(int j=1;j<count;j++)
    m=m*2;
  return (double)1/(n*m);
  }
}

int main(){
  int n,k;
  double p=0.0;
  cin >> n >> k;
  for(int i=0;i<n;i++){
  	p+=f(i+1,n,k);
  }
 cout << std::setprecision(15) << p;
}

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

int main() {
    vector<ll> x(5);

    ll ans = 0;

    for (ll i = 0; i < x.size(); i++) {
        cin >> x.at(i);

        if(x.at(i) == 0) ans = i + 1;
    }
    

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

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

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

long long MOD = 1000000000 + 7;
// 約数列挙 O(√n)
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main(){
  cout << setprecision(10);
  ll N;
  cin >> N;
  ll ans = 0;
  for(ll i = 1; i <= N; i++){
    auto ret = divisor(i);
    if(i%2==1 && ret.size()==8) ans++;
  }
  cout << ans << endl;
}


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

// --- DEBUG begin --- cut here ---
template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

template <class Head>
void dbgLog(Head&& head) {
  cerr << head << endl;
}

template <class Head, class... Tail>
void dbgLog(Head&& head, Tail&&... tail)
{
  cerr << head << " ";
  dbgLog(forward<Tail>(tail)...);
}

#if DEBUG
  #define DLOG(...)        dbgLog(__VA_ARGS__)
  #define DFMT(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFMT(...)
  #define DCALL(func, ...)
#endif

// operator<< definitions for some classes

template <typename T1, typename T2>
ostream& operator<< (ostream& os, const pair<T1,T2>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

template <typename T>
ostream& operator<< (ostream& os, const vector<T>& v) {
  os << '[';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << ']';

  return os;
}

template <typename T, typename T2, typename T3>
ostream& operator<< (ostream& os, const priority_queue<T, T2, T3>& orig) {
  priority_queue<T, T2, T3> pq(orig);
  bool first = true;
  os << '[';
  while (!pq.empty()) {
    T x = pq.top(); pq.pop();
    if (!first) os << ", ";
    os << x;
    first = false;
  }
  return os << ']';
}
// --- DEBUG end --- cut here ---



using Tuple = tuple<ll, int, int>;
using Pair = pair<int, int>;

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, M; cin >> N >> M;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());

  vector<ll> sum(N+1);
  for (int i = 0; i < N; i++) {
    sum.at(i+1) = sum.at(i) + A.at(i);
  }
  if (M == N*N) {
    cout << 2 * N * sum.at(N) << endl;
    return 0;
  }
  
  auto chk = [&](ll bnd, ll& count) -> bool {
    DLOG("chk called", bnd);
    count = 0;
    for (int i = 0; i < N; i++) {
      auto it = lower_bound(A.begin(), A.end(), bnd - A.at(i));
      int idx = it - A.begin();
      DLOG("i, idx", i, idx);
      count += N - idx;
    }
    DLOG("chk count", count);
    return count <= M;
  };

  ll count;
  ll ok = A.at(N-1) + A.at(N-1) + 1;
  ll ng = A.at(0) + A.at(0);
  while (ng+1 < ok) {
    ll mid = (ok + ng) / 2;
    if (chk(mid, count)) ok = mid;
    else                 ng = mid;
  }
  ll sat = 0;
  for (int i = 0; i < N; i++) {
    auto it = lower_bound(A.begin(), A.end(), ok - A.at(i));
    int idx = it - A.begin();
    sat += (N - idx) * A.at(i) + sum.at(N) - sum.at(idx);
  }
  chk(ok, count);
  cout << sat + (M - count) * (ok - 1) << endl;

  return 0;
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int A, B, C, D;
      cin >> A >> B >> C >> D;
      if (A + B > C + D) {
        cout << "Left" << endl;
      }
      else if (A + B == C + D) {
        cout << "Balanced" << endl;
      }
      else {
        cout << "Right" << endl;
      }
    }

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x % y)); }
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int T;
  cin >> T;
  rep(cnt, 0, T) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    string ans = "Yes";

    if (a < b) {
      ans = "No";
    } else {
      if (b > d) {
        ans = "No";
      } else {
        if (b <= c) {
          ans = "Yes";
        } else if ((b - gcd(b, d) + a % gcd(b, d)) > c) {
          ans = "No";
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)

#define vll    vector<ll>
#define vvll   vector<vector<ll>>
#define all(x) (x).begin(),(x).end()

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

	//組(a, b, c)の各数字をKで割ったあまりをi, j, kとすると、
	//
	//i + j = 0 (mod K)   (1)
	//j + k = 0 (mod K)   (2)
	//k + i = 0 (mod K)   (3)
	//
	//が成り立てば良い。特に(1) - (2) + (3)より
	//
	//2 * i = 0 (mod K)   (4)
	//
	//が成り立つ。
	//
	//Kが奇数の場合は(4)が必要十分、Kが偶数の場合は(4)かつ
	//
	//i = 0 (mod K/2)   (4)
	//
	//が必要十分。

	ll ans = 0;

	ll cnt1 = 0;
	reple(i, 1, N)
	{
		if (i % K == 0) cnt1++;
	}

	ans += cnt1 * cnt1 * cnt1;

	if (K % 2 == 0)
	{
		ll cnt2 = 0;
		reple(i, 1, N)
		{
			if (i % K == K / 2) cnt2++;
		}

		ans += cnt2 * cnt2 * cnt2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int data[200][3],sum[200]={0},i,j,k,n,flag=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&data[i][0],&data[i][1],&data[i][2]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<3;j++){
		flag=0;
			for(k=0;k<n;k++){
				if(i!=k && data[i][j] == data[k][j]){
					flag=1;
				}
			}
			if(flag!=1){
				sum[i]+=data[i][j];
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%d\n",sum[i]);
	}
	return 0;
}

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

int main()
{
    int N, K;
    int L;
    priority_queue < int > pq;

    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        cin >> L;
        pq.push(L);
    }
    int sum = 0;
    for(int i = 0; i < K; i++) {
        sum += pq.top(); pq.pop();
    }

    cout << sum << endl;
    return (0);
}


Measured memory_bytes: 256
N = int(input())
d = dict()
for _ in range(N):
    s = list(input())
    s.sort()
    s = "".join(s)
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

print(sum(v*(v-1)//2 for v in d.values()))

Measured memory_bytes: 17924
n = io.read('*n')
a = {}
for i = 1, n do
  local u = io.read('*n')
  if not a[u] then a[u] = 0 end
  a[u] = a[u] + 1
end

m = io.read('*n')
ans = true
for i = 1, m do
  local u = io.read('*n')
  if not a[u] or a[u] == 0 then
    ans = false
    break
  end
  a[u] = a[u] - 1
end
if ans then print('YES') else print('NO') end

Measured memory_bytes: 12648
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

using ull = unsigned long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vull = vector<ull>;
using vpii = vector<pii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {
    
    string hai;
    cin >>hai;
    hai[5]=' ';
    hai[13]=' ';
    cout <<hai;

    return 0;
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef pair<int, string> pis;
int main(){
  int n;
  while(cin >> n, n){
    vector<string> alpha(n), beta(n);
    for(int i = 0; i < n; i++){
      cin >> alpha[i] >> beta[i];
    }
    string s, t;
    cin >> s >> t;
    queue<pis> que;
    que.push(mp(0, s));
    bool flag = false;
    while(que.size()){
      int cnt = que.front().first;
      s = que.front().second;
      que.pop();
      if(s == t){
	cout << cnt << endl;
	flag = true;
	break;
      }
      if(cnt > 10){
      	cout << -1 << endl;
      	flag = true;
      	break;	
      }

      for(int i = 0; i < alpha.size(); i++){
	vector<int> pos;
	string tmp = s;
	for(int j = 0; j <= (int)s.length() - (int)alpha[i].length(); j++){
	  if(s.substr(j, alpha[i].length()) == alpha[i])
	    pos.push_back(j), j += alpha[i].length() - 1;
	}
	for(int j = pos.size() - 1; j >= 0; j--){
	  tmp = tmp.substr(0, pos[j]) +
	    beta[i] + tmp.substr(pos[j] + alpha[i].length());
	}
	if(s != tmp && tmp.length() <= t.length()){
	  que.push(mp(cnt + 1, tmp));
	}
      }
    }
    if(flag == false){
      cout << -1 << endl;
    }
  }
}

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

main(){
	int n;
	while(cin >> n, n){
		int Max=0, Min=500;
		while(n--){
			int a[5];
			cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
			int x = a[0]+a[1]+a[2]+a[3]+a[4];
			Max = max(Max, x);
			Min = min(Min, x);
		}
		cout << Max << " " << Min << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	int h, w;
	cin >> h >> w;

	vector<vector<int>> v(h, vector<int>(w));
	rep(i,h){
		rep(j,w){
			cin >> v[i][j];
		}
	}

	vector<tuple<int,int,int,int>> ans;
	int y, x;
	bool p = false;

	auto f = [&](int i, int j){
		if(p){
			ans.emplace_back(y, x, i, j);
			p = false;
		}else{
			y = i;
			x = j;
			p = true;
		}
	};
	auto g = [&](int i, int j){
		ans.emplace_back(y, x, i, j);
		y = i;
		x = j;
	};

	rep(i,h){
		if(i % 2){
			for (int j = w - 1; j >= 0; j--) {
				if(v[i][j] % 2) f(i,j);
				else if(p) g(i,j);
			}
		}else{
			rep(j,w){
				if(v[i][j] % 2) f(i,j);
				else if(p) g(i,j);
			}
		}
	}

	cout << ans.size() << endl;
	for(auto pp : ans){
		int a, b, c, d;
		tie(a,b,c,d) = pp;
		a++; b++; c++; d++;
		cout << a << ' ' << b << ' ' << c << ' ' << d << endl;
	}
}


Measured memory_bytes: 5232
// Aizu Vol-10 1052: Old Bridges
// 2017.8.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

typedef struct { int v, w; } T; T tbl[30];

int cmp(T *a, T *b)
{
	int d;
	if ((d = a->w - b->w) != 0) return d;
	return a->v - b->v;
}

int main()
{
	int n;
	int i, s;

	while (scanf("%d", &n) && n) {
		for (i = 0; i < n; i++) scanf("%d%d", &(tbl[i].v), &(tbl[i].w));
		qsort(tbl, n, sizeof(T), cmp);
		for (s = i = 0; i < n; i++)
			if ((s = s + tbl[i].v) > tbl[i].w) break;
		puts(i >= n ? "Yes" : "No");
	}
	return 0;
}

Measured memory_bytes: 588
//#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define M_PI 3.14159265358979323846
typedef long long ll;



int main() {
	//fios;

	
	ll n;
	cin >> n;
	vector<ll> factors(n+1, 0);
	for(ll i = 1; i <= n; i++) factors[i] = i;

	for(ll i = 2; i <= n; i+=2) {
		factors[i] = 2;
	}

	for(ll i = 3; i * i <= n; i++) {
		if(factors[i] == i) {
			for(ll j = i*i; j <= n; j += i) {
				if(factors[j] == j) factors[j] = i;
			}
		}
	}

	ll num, cnt = 0;
	for(ll c1 = 1; c1 < n; c1++) {
		num = n - c1;
		if(num == 1) {
			cnt += 1;
		} else {
			ll ans = 1, dup = factors[num], c = 1;
			ll j = num / factors[num];

			while(j != 1) {
				if(factors[j] == dup) c+= 1;
				else {
					dup = factors[j];
					ans *= (c + 1);
					c = 1;
				}
				j /= factors[j];
			}
			ans *= (c+1);
			cnt += ans;
		}
	}
	cout << cnt << endl;
}

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

int N, K;
vector<int> dp;
vector<int> a;

int rec(int i, int turn)
{
    if(dp.at(i) >= 0)
    {
        if(turn == 0 ) return dp.at(i);
        else return 1-dp.at(i);
    }

    for(int j = 0; j < N; ++j)
    {
        if((i - a.at(j)) < 0) continue;

        int res = rec(i - a.at(j), 1-turn);
        if(turn == 0)
        {
            if(res == 0)
            {
                dp.at(i) = 0;
                return 0;
            } 
        }
        else
        {
            if(res == 1)
            {
                dp.at(i) = 0;
                return 1;
            } 
        }
    }
    dp.at(i) = 1;
    return 1 - turn;

}

int main(void)
{

    cin >> N >> K;

    dp.assign(K+1, -1);
    a.assign(N,0);

    for (int i = 0; i < N; ++i)
    {
        int tmp;
        cin >> tmp;
        a.at(i) = tmp;
    }


    double ans = rec(K, 0);

    if(ans == 0) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}



Measured memory_bytes: 6912
#!/usr/bin/env ruby
# opt(i) = min{ opt(i-2)+|c(i, i-2)|, opt(i-1)+|c(i, i-1)|, ..., opt(i-k)+|c(i, i-k| }

n, k = STDIN.readline.strip.split(' ').map(&:to_i)
h = STDIN.readline.strip.split(' ').map(&:to_i)

def opt(k, h)
  m = []
  m[0] = 0
  for i in 1..h.size-1 do
    c_min = 10**10
    for j in 1..k do
      break if i-j < 0
      c = m[i-j] + (h[i] - h[i-j]).abs
      c_min = c if c < c_min
    end
    m[i] = c_min
  end
  m[-1]
end

puts opt(k, h)


Measured memory_bytes: 13708
#include <iostream>
#include <cmath>
#include <math.h>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
	double a, b, x;

	cin >> a >> b >> x;

	double m = 4 * (b - (x / (a * a))) * (b - (x / (a * a))) + a * a;
	double s2 = (a * a) / m;
	double s = sqrt(s2);
	double t = asin(s);
	double d = 180.0 / M_PI * t;

	if (x / (a * a) >= b / 2) {
		printf("%.9lf\n", 90 - d);
	} else {
		double ta = 2 * x / (a * b * b);
		double alp = atan(ta);
		d = 180.0 / M_PI * alp;
		printf("%.9lf\n", 90 - d);
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

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

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

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

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int n;
    cin >> n;
    ll ans = 0;
    ll now = 0;
    rep(i, n) {
        ll a;
        cin >> a;
        ll d = max(0ll, now - a);
        ans += d;
        now = max(now, a + d);
    }
    cout << ans << endl;
}

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

int main (){
    int n, p, all = 0, max = 0;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> p;
        if (max < p){
            max = p;
        }
        all += p;
    }
    cout << all - max/2 << endl;
    return 0;
}


Measured memory_bytes: 384
from collections import Counter
from itertools import product

H, W, N, *AB = map(int, open(0).read().split())

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in product((-1, 0, 1), repeat=2)
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
    )

D = Counter(v for _, v in C.items())

print((H - 2) * (W - 2) - sum(D.values()))
for i in range(1, 10):
    print(D[i])


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

int main() {
  	long a, b, k;
    cin >> a >> b >> k;
    if (a >= k) {
        a -= k;
    } else {
        k -= a;
        a = 0;
        if (b >= k) b -= k;
        else b = 0;
    }
    cout << a << ' ' <<  b << '\n';
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<assert.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;//角度转弧度 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 2e5+10, M = 1e6+10;
int h, w;
int a[N], b[N];
struct SegTree {
struct node {
	int l, r;
	ll mn, add;
}tr[N * 4];
void build(int u, int l, int r) {
	if(l == r) {
		tr[u] = {l, r, 0, 0};
	} else {
		int mid = l + r >> 1;
		tr[u] = {l, r};
		build(u << 1, l, mid);
		build(u << 1 | 1, mid + 1, r);
	}
}
void pushup(int u) {
	tr[u].mn = min(tr[u << 1].mn, tr[u << 1 | 1].mn);
}
void pushdown(int u) {
	if(tr[u].add) {
		tr[u << 1].mn += tr[u].add;
		tr[u << 1 | 1].mn += tr[u].add;
		tr[u << 1].add += tr[u].add;
		tr[u << 1 | 1].add += tr[u].add;
		tr[u].add = 0;
	}
}
void modify(int u, int l, int r, ll d) {
	if(tr[u].l >= l&&tr[u].r <= r) {
		tr[u].mn += d;
		tr[u].add += d;
	} else {
		int mid = tr[u].l + tr[u].r >> 1;
		pushdown(u);
		if(l <= mid) modify(u << 1, l, r, d);
		if(r > mid) modify(u << 1 | 1, l, r, d);
		pushup(u);
	}
}
ll query(int u, int l, int r) {
	if(tr[u].l >= l&&tr[u].r <= r) {
		return tr[u].mn;
	} else {
		int mid = tr[u].l + tr[u].r >> 1;
		pushdown(u);
		ll ans = INF;
		if(l <= mid) ans = min(ans, query(u << 1, l, r));
		if(r > mid) ans = min(ans, query(u << 1 | 1, l, r));
		return ans;
	}
}
}x, y;
int main() {
	cin>>h>>w;
	for(int i = 1;i <= h;i++) {
		scanf("%d %d", &a[i], &b[i]);
	}
	x.build(1, 1, w), y.build(1, 1, w);
	for(int i = 1;i <= w;i++) {
		y.modify(1, i, i, -i);
	}
	int f1 = 0;
	for(int i = 1;i <= h;i++) {
		if(f1) {
			cout<<"-1\n";
			continue;
		}
		if(b[i] + 1 <= w)
		x.modify(1, b[i] + 1, b[i] + 1, min(1ll * (b[i] + 1 + y.query(1, 1, b[i])) - x.query(1, b[i] + 1, b[i] + 1), 0ll));
		if(b[i] + 1 <= w)
		y.modify(1, b[i] + 1, b[i] + 1, min(y.query(1, 1, b[i]) - y.query(1, b[i] + 1, b[i] + 1), 0ll));
		x.modify(1, a[i], b[i], 1e9);
		y.modify(1, a[i], b[i], 1e9);
		x.modify(1, 1, w, 1);
		y.modify(1, 1, w, 1);
		int ans = x.query(1, 1, w);
		//cout<<y.query(1, 1, w)<<"\n";
		if(ans >= 1e9) {
			f1 = 1;
			cout<<"-1\n";
		} else {
			cout<<ans<<"\n";
		}
	}
	return 0;
}


Measured memory_bytes: 29816
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  string s, t;
  readf("%s %s\n", &s, &t);
  foreach (i; 0..n) {
    writef("%s%s", s[i], t[i]);
  }
  writeln();
}


Measured memory_bytes: 256