akhauriyash/Code-Regression huggingface dataset:
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
Max = sys.maxsize
from math import factorial

def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


n,k = m()

s = [[] for i in range(n)]

for i in range(n-1):
	a,z = m()
	s[a-1].append(z-1)
	s[z-1].append(a-1)

co = k * cmb(k-1,len(s[0]),mod)
co %= mod

def dfs(tree,now,be):
	global co,d
	if len(tree[now]) != 1:
		ma = k - 2
		mm = len(tree[now]) - 1
		co *= cmb(ma,mm,mod)
		co %= mod
		for i in range(mm+1):
			if s[now][i] != be:
				dfs(tree,s[now][i],now)


for i in range(len(s[0])):
	dfs(s,s[0][i],0)


print(co)


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

int main(){
  int n,k;
  cin >> n >> k;
  set<int> d;
  for(int i=0;i<k;i++){
     int dinput;
     cin >> dinput;
     d.insert(dinput);
    }

 for(int i=n;i<100000;i++){
     int m=i;
     bool flag = 0;
     set<int> nn;
     while(m > 0){
         nn.insert(m % 10);
         m /= 10; 
      }
     for(auto it=nn.begin();it!=nn.end();it++){
              if(d.count(*it)){
              flag = 1;
              break;
            }
        }
        if(flag == 0){
            cout << i << endl;
            return 0;
        }
    }
 return 0;
}

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

using namespace std;

int main() {
    int N, x;
    cin >> N >> x;
    int a[N];
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    sort(a, a + N);
    int ans = 0;

    // 少ない子から順に飴を配る
    for (int i = 0; i < N; ++i) {
        if (x >= a[i]) {
            ++ans;
            x -= a[i];
        }
    }

    // 飴が余っていたら1人を犠牲にする
    if (ans == N && x > 0) --ans;

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e5+1;
string s,t;
int dp[3001][3010];
int rec (int i, int j){
    if (i == s.size() && j == t.size())return 0;
    if (i == s.size() || j == t.size())return -1e9;
    int &ret = dp[i][j];
    if (ret + 1)return ret;
    if (s[i] == t[j]){
        return ret = 1 + rec(i+1,j+1);
    }
    return ret = max(rec(i+1,j), rec(i, j+1));
}
void build (int i,int j){
    if (i == s.size() || j == t.size() )return;
    if (s[i] == t[j]) {
        cout <<s[i];
        build(i+1,j+1);
        return;
    }
    if (rec(i+1,j) > rec(i, j+1)) build(i+1,j);
    else build(i, j+1);
}
int main () {
    cin >> s >> t;
    memset(dp, -1, sizeof dp);
    int x = rec(0,0);
    build(0,0);
}


Measured memory_bytes: 35840
def get_minkowski_distance(a, b, p):
    """
    get Minkowski's distance
    a : int list
    b : int list
    p : int
    """
    s = 0
    res = 0.0

    if p == 0:
        l = []
        for x, y in zip(a, b):
            l.append(abs(x - y))
        res = max(l) 

    else:
        for x, y in zip(a, b):
            s += abs(x - y) ** p

        res = round((s ** (1/p)), 6)

    return res

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    print(get_minkowski_distance(a, b, 1))
    print(get_minkowski_distance(a, b, 2))
    print(get_minkowski_distance(a, b, 3))
    print(get_minkowski_distance(a, b, 0))



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

int N;
vector<string> w(110);
map<string, int> W;

string solve () {

    for (int i = 1; i < N; i++) {
        if (!(w[i-1][w[i-1].size()-1] == w[i][0] && W[w[i-1]] == 1)) {
            return "No";
        }
    }

    return "Yes";
}

int main () {

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> w[i];
        W[w[i]]++;
    }

    cout << solve() << endl;

    return 0;
}

Measured memory_bytes: 256
///
// File:  2746.cpp
// Author: ymiyamoto
//
// Created on Sun Dec 24 03:44:12 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main()
{
  while (true) {
    string jfen;
    cin >> jfen;
    if (jfen[0] == '#') break;

    uint32_t height = 1;
    uint32_t width = 0;
    for (uint32_t i = 0; i < jfen.size(); i++) {
      if (jfen[i] == '/') {
        height++;
      } else {
        if (height == 1) {
          if (jfen[i] == 'b') {
            width++;
          } else {
            width += jfen[i] - '0';
          }
        }
      }
    }

    vector<vector<char>> board(height, vector<char>(width, '.'));
    uint32_t x = 0;
    uint32_t y = 0;
    for (uint32_t i = 0; i < jfen.size(); i++) {
      if (jfen[i] == '/') {
        x = 0;
        y++;
      } else {
        if (jfen[i] == 'b') {
          board[y][x] = 'b';
          x++;
        } else {
          x += jfen[i] - '0';
        }
      }
    }

    uint32_t a, b, c, d;
    cin >> a >> b >> c >> d;
    board[a - 1][b - 1] = '.';
    board[c - 1][d - 1] = 'b';

    for (uint32_t i = 0; i < height; i++) {
      if (i != 0) cout << "/";
      uint32_t cnt = 0;
      string line = "";
      for (uint32_t j = 0; j < width; j++) {
        if (board[i][j] == 'b') {
          if (cnt > 0) {
            line += to_string(cnt);
            cnt = 0;
          }
          line += 'b';
        } else {
          cnt++;
        }
      }
      if (cnt > 0) {
        line += to_string(cnt);
      }
      cout << line;
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3176
#!/usr/bin/env python

n = int(input().rstrip())

line = input().rstrip()

max_count = 0
for i in range(n):
    a = set(line[0:i])
    b = set(line[i:])
    count = len(a.intersection(b))
    if max_count < count:
        max_count = count

print(max_count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair

using namespace std;

int main(){

    //累積和を用いて部分和Aとカード総和からAを引いた差が一番小さくなる値を求めればよい
    //O(N)のはず

    int n;
    cin >> n;

    vector<ll> v;
    vector<ll> accv;

    accv.pback(0);

    rep(i,n){
        ll tmp;
        cin >> tmp;
        v.pback(tmp);
        accv.pback(accv[i] + tmp);
    }

    ll sum = accv[n];

    ll ans = LLONG_MAX;

    rep(i,n - 1){
        ll tmpsum = sum - accv[i + 1];
        ll tmp = abs(accv[i + 1] - tmpsum); 

        ans = min(ans,tmp);
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#include <cmath>
#include <string>

#define INF 1000000

using namespace std;

int dp[100001] = {INF};

int main(void) {
    for(int i = 0;i < 100001;i++)
        dp[i] = INF;
    int n;
    cin >> n;
    dp[0] = 0;
    for(int i = 1;i <= 100000;i++) {
        for(int ii = 9;i - ii >= 0;ii=ii*9) {
            dp[i] = min(dp[i],dp[i - ii] + 1);
        }
        for(int ii = 6;i - ii >= 0;ii=ii*6) {
            dp[i] = min(dp[i],dp[i - ii] + 1);
        }
        dp[i] = min(dp[i],dp[i-1]+1);
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    uint64_t i=0,num=1,ans;
    while(i<N){
        if(D==0 && num%100!=0){
            ans=num;
            i++;
        }
        if(D==1 && num%100==0 && (num/100)%100!=0){
            ans=num;
            i++;
        }
        if(D==2 && num%100==0 && (num/100)%100==0 && (num/10000)%100!=0){
            ans=num;
            i++;
        }
        num++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<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; }
//#define int long long

void chmax(LP &a, LP b) {
	if(a.fr < b.fr) a.sc = max(a.fr, b.sc), a.fr = b.fr;
	else a.sc = max(a.sc, b.fr);
}

void solve() {
	int n; cin >> n;
	vector<ll> a(1<<n); vector<LP> dp(1<<n);
	for(int bit = 0; bit < (1<<n); ++bit) {
		cin >> a[bit];
		dp[bit] = {a[bit], -INF};
	}
	rep(i, n) {
		for(int bit = 0; bit < (1<<n); ++bit) {
			if(bit & (1<<i)) {
				chmax(dp[bit], dp[bit ^ (1<<i)]);
			}
		}
	}
	ll res = -INF;
	for(int bit = 0; bit < (1<<n); ++bit) {
		ll tmp = dp[bit].fr + dp[bit].sc;
		res = max(res, tmp);
		if(bit) cout << res << endl;
 	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
} 

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

const int MOD = 1000000007;

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

    vector<vector<long long>> dp(N + 1, vector<long long>(N + 1));

    for (int i = 0; i <= N; i++) {
        dp[i][0] = 1;
        dp[i][i] = 1;

        for (int j = 1; j < i; j++) {
            dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
        }
    }

    for (int i = 1; i <= K; i++) {
        if (N - K + 1 < i) {
            cout << 0 << endl;
            continue;
        }

        cout << (dp[N - K + 1][i] * dp[K - 1][i - 1]) % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 31616
x, y, a, b, c = gets.split.map(&:to_i)

p = gets.split.map(&:to_i)
q = gets.split.map(&:to_i)
r = gets.split.map(&:to_i)

red = p.max(x)
green = q.max(y)
result = (red + green + r.max(x+y))

puts result.max(x+y).inject(&:+)


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


int main() {
int N;
cin >> N;
long long ans = 1;
int c = 0;
for (int i = 0;i < N;i++) {
    string a;
    cin >> a;
    c += a.size();
    if (a == "0") {
        cout << 0 << endl;
        return 0;
    } 
    long long b = stol(a);
    if (c > 19 && ans == 0) continue;
    ans *= b;
}
if (c >= 19 && ans == 0 || ans > 1000000000000000000) cout << -1 << endl;
else cout << ans << endl;

return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int main(void){
    // Your code here!
    vector<int> V;
    
    int num_query;
    scanf("%d",&num_query);
    
    int command,tmp;
    
    for(int i=0; i<num_query; i++){
        scanf("%d" ,&command);
        
        switch(command){
            case 0:
                scanf("%d",&tmp);
                V.push_back(tmp);
                break;
            case 1:
                scanf("%d",&tmp);
                printf("%d\n",V[tmp]);
                break;
            case 2:
                V.pop_back();
                break;
                
        }
    }
    return 0;
}



Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0;i<N;i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  cout << A[A.size()-1]-A[0] << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

class Geometry:

    EPS = 10 ** -9

    def add(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return (x1+x2, y1+y2)

    def sub(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return (x1-x2, y1-y2)

    def mul(self, a, b):
        x1, y1 = a
        if not isinstance(b, tuple):
            return (x1*b, y1*b)
        x2, y2 = b 
        return (x1*x2, y1*y2)

    def norm(self, a):
        x, y = a
        return x**2 + y**2

    def dot(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return x1*x2 + y1*y2

    def cross(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return x1*y2 - y1*x2

    def project(self, seg, p):
        """ 線分segに対する点pの射影 """
        p1, p2 = seg
        base = self.sub(p2, p1)
        r = self.dot(self.sub(p, p1), base) / self.norm(base)
        return self.add(p1, self.mul(base, r))

    def reflect(self, seg, p):
        """ 線分segを対称軸とした点pの線対称の点 """
        return self.add(p, self.mul(self.sub(self.project(seg, p), p), 2))

    def ccw(self, p0, p1, p2):
        """ 線分p0,p1から線分p0,p2への回転方向 """
        a = self.sub(p1, p0)
        b = self.sub(p2, p0)
        # 反時計回り
        if self.cross(a, b) > self.EPS: return 1
        # 時計回り
        if self.cross(a, b) < -self.EPS: return -1
        # 直線上(p2 => p0 => p1)
        if self.dot(a, b) < -self.EPS: return 2
        # 直線上(p0 => p1 => p2)
        if self.norm(a) < self.norm(b): return -2
        # 直線上(p0 => p2 => p1)
        return 0

gm = Geometry()
x1, y1, x2, y2 = MAP()
a, b = (x1, y1), (x2, y2)
Q = INT()
for i in range(Q):
    x3, y3  = MAP()
    res = gm.ccw(a, b, (x3, y3))
    if res == 1:
        print('COUNTER_CLOCKWISE')
    elif res == -1:
        print('CLOCKWISE')
    elif res == 2:
        print('ONLINE_BACK')
    elif res == -2:
        print('ONLINE_FRONT')
    elif res == 0:
        print('ON_SEGMENT')



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

int f[110000];

int main() {
    // freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
    int n;
    scanf("%d",&n);
    int x=sqrt(n);
    for(int i=1;i<=x;i++)
        for(int j=1;j<=x;j++)
            for(int k=1;k<=x;k++)
                f[i*i+j*j+k*k+i*j+i*k+j*k]++;
    for(int i=1;i<=n;i++) printf("%d\n",f[i]);
    return 0;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	map<char,lli> d;

	cin>>n;
	REP(i,0,n){
		string s;
		cin>>s;
		d[s.at(0)]++;
	}

	lli ans = 0;

	string c="MARCH";

	for(lli i=0;i<5;i++){
		lli iCnt = d[c.at(i)];
		for(lli j=i+1;j<5;j++){
			lli jCnt = d[c.at(j)];
			for(lli k=j+1;k<5;k++){
				lli kCnt = d[c.at(k)];
				ans += (iCnt*jCnt*kCnt);
			}
		}
	}

	cout<<ans<<endl;

	return 0;
}

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

int main(){
    int n,m;cin>>n>>m;
    map<int, vector<int>> graph;
    int l, r;
    for (int i=0;i<m;i++){
        cin >> l >> r;
        graph[l].push_back(r);
        graph[r].push_back(l);
    }

    vector<int> nodes;
    for (int i=2;i<=n;i++){
        nodes.push_back(i);
    }

    int acc = 0;
    do {
        auto temp = nodes;
        temp.insert(temp.begin(), 1);
        bool flag = true;
        for (int i=0;i<n-1;i++){
            if (find(graph[temp[i]].begin(), graph[temp[i]].end(), temp[i+1]) == graph[temp[i]].end()){
                flag = false;
                break;
            }
        }
        if (flag){
            acc++;
        }
    }while(next_permutation(nodes.begin(), nodes.end()));
    cout << acc << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ma=-1, mv=0;
		for(int i=0;i<n;i++) {
			int a = sc.nextInt(), v = sc.nextInt();
			if(ma<0 || mv<v || (mv==v && ma>a)) {ma = a; mv = v;}
		}
		System.out.println(ma + " " + mv);
	}
}

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

std::vector<int> s(100000);
int cnt = 0;

int search(int value, int begin, int end){
    int left = begin;
    int right = end;
        
    while(left < right){
        int mid = (left + right) / 2;
        if(value < s[mid]){
            right = mid;
        }else if(value > s[mid]){
            left = mid+1;
        }else{
            cnt++;
            break; 
            
            //return 1;
        }
        //
    }
    return 0;
    
}

int main(void){
    int n, q, d;
    std::vector<int> t;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &d);
        s[i] = d;
    }
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%d", &d);
        t.push_back(d);
    } 

    for(int i = 0; i < q; i++){
        search(t[i], 0, n);
    }
    
    std::cout << cnt << std::endl;
    
    return 0;
}


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

#define int long long
const int INF = LLONG_MAX/10;
const int MAX_N = 100;
const int MAX_M = 21000;

int N, M, A[MAX_M], B[MAX_M], C[MAX_M];
int d[MAX_N][MAX_N];

signed main()
{
	fill((int*)d, (int*)d + MAX_N*MAX_N, INF);
	cin >> N >> M;
	for (int i = 0; i < N; i++) d[i][i] = 0;
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i] >> C[i]; A[i]--, B[i]--;
		d[A[i]][B[i]] = d[B[i]][A[i]] = C[i];
	}
	for (int k = 0; k < N; k++)
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	int ans = 0;
	for (int k = 0; k < M; k++)
	{
		bool flg = false;
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				flg = flg || (d[i][j] - d[i][A[k]] - d[B[k]][j] == C[k]);
		ans += !flg;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main()
{
	const long long DEF = 1000000007;
	long long N, fac = 1;
	cin >> N;

	vector<int> arr(N + 1, 0);
	vector<int> primes;
	for (int i = 2; i <= N; i++) {
		int val = i;
		for (int k : primes) {
			while (val % k == 0) {
				arr[k]++;
				val /= k;
			}
		}
		if (val == i) {
			primes.push_back(val);
			arr[val]++;
		}
	}

	long long  cnt = 1;
	for (int i = 2; i <= N; i++) {
		cnt = (cnt * (arr[i] + 1)) % DEF;
	}

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
arr = Array.new(w + 1){[0, 0]}
ans = 0

h.times do |i|
    s = gets
    k = 0
    (w + 1).times do |j|
        if s[j] != "."
            k.upto(j-1) {|l| arr[l][1] = j - k if arr[l][1] < j - k}
            k = j + 1
            ans < (sum = arr[j][0] + arr[j][1]) and ans = sum
            arr[j] = [0, 0]
        else
            arr[j][0] += 1
        end
    end
end

arr.each {|a, b| ans = a + b if ans < a + b}
puts ans - 1

Measured memory_bytes: 5244
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  int a[n+1];
  map <int,int> mp;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    if(mp.count(a[i])!=0){
      cout<<"NO";
      return 0;
    }
    mp[a[i]]++;
  }
  cout<<"YES";
}

Measured memory_bytes: 10368
#include<iostream>
using namespace std;
int main()
{

int n;
const long long big=1000000007;
cin>>n;
long long ans=n;
for(int i=1;i<n;i++)
{ans*=i;
 if(ans>big)
 ans%=big;}
 cout<<ans;
system("pause"); 
return 0;
}


Measured memory_bytes: 504
#!/usr/bin/env python3

def requiredMagic(nChain: int) -> int:
    return nChain // 2

N = int(input())
A = [int(x) for x in input().split(" ")]

lastColor = -1
nMagic = 0
nChain = 0
for i in range(0, N):
    if(lastColor == A[i]):
        nChain += 1
    else:
        lastColor = A[i]
        nMagic += requiredMagic(nChain)
        nChain = 1
nMagic += requiredMagic(nChain)

print(nMagic)


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
int main() {
	ll n, m;
	cin >> n >> m;
	if (n == 1 && m == 1)cout << 1 << endl;
	else if (n == 1 || m == 1)cout << max(n, m) - 2 << endl;
	else if (n == 2 || m == 2)cout << 0 << endl;
	else cout << n * m - 2 * (n + m) + 4 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define PI 3.141592653589793
int main(void){
    double r, s, l;
    
    scanf("%lf", &r);
    
    0 < r < 10000;
    
    s = r*r*PI;
    l = 2*r*PI;
    
    printf("%f %f\n", s, l);
    
    return (0);
    
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
typedef long long ll;
int n,m;
char s[maxn];
bool judge(int l,int r) {
	for (int i = l; i <= r; i++) {
		if (s[i] != s[r - i + l]) return false;
	}
	return true;
}
int main() {
	scanf("%s",s + 1);
	n = strlen(s + 1);
	int mid = (n + 1) / 2;
	//printf("%d %d %d\n",judge(1,mid - 1),judge(1,n),judge(mid + 1,n));
	if (judge(1,mid - 1) && judge(mid + 1,n) && judge(1,n)) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, x; cin >> n >> x;
	int now = 0;
	int cnt = 1;
	rep(i, n)
	{
		int l; cin >> l;
		now += l;
		if (now <= x)++cnt;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#define MAXN 101

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

int x,n,a[MAXN];
bool appear[201];

int main() {
	read(x),read(n);
	for(int i=1;i<=n;++i) {
		read(a[i]);
		appear[a[i]]=1;
	}
	std::sort(a+1,a+n+1);
	int minn=2147483647,ans;
	for(int i=101;i>=0;--i) {
		if(!appear[i]) {
			if(abs(x-i)<=minn) {
				minn=abs(x-i);
				ans=i;
			}
		}
	}
	std::cout<<ans<<'\n';
	return 0;
}

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

int main() {
    int N,X,L,count=1,D=0;
    cin>>N>>X;
    for(int i=1;i<=N;i++){
        cin >> L;
        D = D + L;
        if(D<=X) count++;
    }
    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


a,b = map(int,input().split())

g = gcd(a,b)


arr = []
temp = g
for i in range(2, int(-(-g**0.5//1))+1):
    if temp%i==0:
        cnt=0
        while temp%i==0:
            cnt+=1
            temp //= i
        arr.append([i, cnt])

if temp!=1:
    arr.append([temp, 1])

print(len(arr)+1)

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

int main() {
  string a, b;
  int s;
  float ss;
  cin >> a >> b;
  
  s = stoi(a + b);
  ss = (int)sqrt(s);
  
  if (s == ss*ss) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[101],b[101];
int main()
{
     while(scanf("%s%s",&a,&b)!=EOF){
         int la=strlen(a);
         int lb=strlen(b);
         sort(a,a+la);
         sort(b,b+lb);
         if(a[0]<b[lb-1]) cout<<"Yes"<<endl;
         else if(a[0]>b[lb-1]) cout<<"No"<<endl;
         else{
            if(a[0]==a[la-1]&&b[0]==b[lb-1]&&a[0]==b[0]){
                 if(lb>la) cout<<"Yes"<<endl;
                 else cout<<"No"<<endl;
                 continue;
             }
             int k=0;
             for(int i=0;i<la;i++){
                 for(int j=0;j<lb;j++){
                     if(b[j]>a[i]){
                         k++;
                         break;
                     }
                 }
             }
             if(k==la) cout<<"Yes"<<endl;
             else cout<<"No"<<endl;
         }
     }
     return 0;
 }

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

using namespace std; 
 
#define int long long
#define M 1000000007 
 
signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
	
//	int t;
//	cin >> t;
//	while(t--){
		int n,k;
		cin >> n >> k;
		string s;
		cin >> s;
		string s1=s;
		int ans=0;
		vector<pair<int,int> > arr;
		for(int i=0;i<n;i++){
			if(s[i]=='L'){
				int cnt=0,ind=i;
				while(i<n&&s[i]=='L'){
					i++;
					cnt++;
				}
				int temp=cnt;
				if(ind-1>=0){
					cnt++;
				}
				if(i==n){
					cnt--;
				}
				arr.push_back(make_pair(cnt-temp-1,ind));
			}
		}
		sort(arr.begin(),arr.end(),greater<pair<int,int> >());
		for(int i=0;i<min(k,(int)arr.size());i++){
			int j=arr[i].second;
//			cout << "j " << j << " cnt " << arr[i].first << endl;
			while(j<n&&s[j]=='L'){
				s[j]='R';
				j++;
			}
		}
		for(int i=0;i<n-1;i++){
			if(s[i+1]==s[i]){
				ans++;
			}
		}
		s=s1;
		int tans=ans;
		ans=0;
		arr.clear();
		for(int i=0;i<n;i++){
			if(s[i]=='R'){
				int cnt=0,ind=i;
				while(i<n&&s[i]=='R'){
					i++;
					cnt++;
				}
				int temp=cnt;
				if(ind-1>=0){
					cnt++;
				}
				if(i==n){
					cnt--;
				}
				arr.push_back(make_pair(cnt-temp-1,ind));
			}
		}
		sort(arr.begin(),arr.end(),greater<pair<int,int> >());
		for(int i=0;i<min(k,(int)arr.size());i++){
			int j=arr[i].second;
//			cout << "j " << j << " cnt " << arr[i].first << endl;
			while(j<n&&s[j]=='R'){
				s[j]='L';
				j++;
			}
		}
		for(int i=0;i<n-1;i++){
			if(s[i+1]==s[i]){
				ans++;
			}
		}
		cout << max(tans,ans) << endl;
//	}
}
 

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int cnt[n+1];
memset(cnt,0,sizeof cnt);
for(int i = 1;i<n;i++){
    int x;
    cin>>x;
    cnt[x]++;
}
for(int i = 1;i<=n;i++)
    cout<<cnt[i]<<endl;

}


Measured memory_bytes: 4376
(defun solve (n ps)
  (loop with tmp = most-positive-fixnum
        with count = 0
        for p in ps
        if (<= p tmp)
        do (setf tmp p)
           (incf count)
        finally (return count)))

(let* ((n (read))
       (ps (loop repeat n collect (read))))
  (format t "~A~%" (solve n ps)))


Measured memory_bytes: 61928
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    map <char,int> set;
    char tmp;
    rep(i,4){
        cin >> tmp;
        if(set.count(tmp) == 0)set[tmp] = 1;
        else set[tmp]++;
    }
    if(set.size() == 2 && set[tmp] == 2)cout<<"Yes" << endl;
    else cout <<"No"<<endl; return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] H = new int[N];
        int [] DP = new int[N];
        for(int i=0;i<N;i++)H[i] = sc.nextInt();
        DP[0]=0;
        DP[1]=Math.abs(H[1]-H[0]);
        for(int i=2;i<N;i++){
            int n1 = Math.abs(H[i]-H[i-2]);
            int n2 = Math.abs(H[i]-H[i-1]);
            if(DP[i-2]+n1<DP[i-1]+n2) DP[i] = DP[i-2]+n1;
            else DP[i]=DP[i-1]+n2;
        }
        System.out.println(DP[N-1]);
    }
}

Measured memory_bytes: 50840
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
static Scanner in = new Scanner(System.in);

public static void main(String[] args) {
  in.nextInt();
  while (in.hasNext()) {
	BigDecimal ax, ay, bx, by;
	{
	  BigDecimal x = in.nextBigDecimal();
	  BigDecimal y = in.nextBigDecimal();
	  ax = in.nextBigDecimal().subtract(x);
	  ay = in.nextBigDecimal().subtract(y);
	}
	{
	  BigDecimal x = in.nextBigDecimal();
	  BigDecimal y = in.nextBigDecimal();
	  bx = in.nextBigDecimal().subtract(x);
	  by = in.nextBigDecimal().subtract(y);
	}
	boolean is;
	{
	  is = ax.multiply(by).compareTo(ay.multiply(bx)) == 0;
	  System.out.println(is ? "YES" : "NO");
	}
  }
}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            
            int d = a / b;
            int r = a % b;
            double f = (double)a / b;
            
            System.out.println(d +" "+ r +" "+String.format("%.5f", f));
    }
}


Measured memory_bytes: 26548
import sys
n=int(input())
a=[[[0 for i in range(10)] for i in range(3)] for i in range(4)]
for i in range(n):
    w=input().split()
    b=(int(w[0]))
    f=(int(w[1]))
    r=(int(w[2]))
    v=(int(w[3]))
    a[b-1][f-1][r-1]+=v
for i in range(4):
    for j in range(3):
        for k in range(10):
            sys.stdout.write(" {0}".format(a[i][j][k]))
        sys.stdout.write("\n")
    if (i!=3):
        for x in range(20):
            sys.stdout.write("#")
        sys.stdout.write("\n")



Measured memory_bytes: 5628
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> numeros;
    if(1<=n<=100){
        while(n--){
            int numero;
            cin>>numero;
            numeros.push_back(numero);
        }
        bool denegado = false;
        for(int i=0;i<numeros.size();i++){
            int absoluto = numeros[i];
            if(absoluto>0 && absoluto <=1000){
                if(absoluto%2==0){
                    if(absoluto%3==0){
                        continue;
                    }else if(absoluto%5==0){
                        continue;
                    }else{
                        denegado =true;
                        break;
                    }
                    
                }
            }
        }
        if(!denegado)
            cout<<"APPROVED";
        else
            cout<<"DENIED";
        
        
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	while (scan.hasNext()) {
	    String input = scan.nextLine();
	    String[] inputs = input.split(" ");
	    int height = Integer.parseInt(inputs[0]);
	    int width = Integer.parseInt(inputs[1]);
	    if (height == 0 && width == 0) {
		break;
	    }
	    int line = 0;
	    while(line < height) {
		if (line % 2 == 0) {
		    printcheck1(width);
		} else {
		    printcheck2(width);
		}
		line++;
	    }
	    System.out.println();
	}
    }
    public static void printcheck1(int width) {
	for (int i = 0; i < width; i++) {
	    if (i % 2 == 0) {
		System.out.print("#");
	    } else {
		System.out.print(".");
	    }
	}
	System.out.println();
    }
    public static void printcheck2(int width) {
	for (int i = 0; i < width; i++) {
	    if (i % 2 == 0) {
		System.out.print(".");
	    } else {
		System.out.print("#");
	    }
	}
	System.out.println();
    }
}

Measured memory_bytes: 33008
import numpy as np
N = int(input())
l = list()
for n in range(N):
    l.append([int(x) for x in input().split()])
d = list()
for n in range(N):
    for m in range(n,N):
        d.append(np.sqrt((l[n][0]-l[m][0])**2+(l[n][1]-l[m][1])**2))
print(np.average(d)*(N+1))


Measured memory_bytes: 21288
#include<stdio.h>
#include<algorithm>
using namespace std;
long long mod=924844033;
int M=110000;
long long fact[110000];
long long inv[110000];
long long factinv[110000];
long long dp[2100][2100][4];
long long dp2[2100][2100];
pair<int,int> p[2100];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)p[i]=make_pair(i%b,i);
	std::sort(p,p+a);
	inv[1]=fact[0]=factinv[0]=1;
	for(int i=2;i<M;i++)inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	for(int i=1;i<M;i++)fact[i]=fact[i-1]*i%mod;
	for(int i=1;i<M;i++)factinv[i]=factinv[i-1]*inv[i]%mod;
	dp[0][0][0]=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<=i;j++){
			for(int k=0;k<4;k++){
				if(!dp[i][j][k])continue;
		//		printf("%d %d %d: %lld\n",i,j,k,dp[i][j][k]);
				dp[i+1][j][0]=(dp[i+1][j][0]+dp[i][j][k])%mod;
				for(int l=0;l<4;l++){
					if(j==0&&l!=3)continue;
					int tj=j;
					int tk=0;
					long long ks=1;
					if(l==0)tj--;
					if(l==3)tj++;
					
					if(!(l&1)){
						if((k&2)&&(p[i-1].first==p[i].first))ks*=j-1;
						else ks*=j;
						
					}else tk+=1;
					if(!(l&2)){
						if((k&1)&&(p[i-1].first==p[i].first))ks*=j-1;
						else ks*=j;
						
					}else tk+=2;
					dp[i+1][tj][tk]=(dp[i+1][tj][tk]+dp[i][j][k]*ks)%mod;
				}
			}
		}
	}
	printf("%lld\n",dp[a][0][0]);
}

Measured memory_bytes: 73216
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.11 18:48:48
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;


bool nibu_judge(const std::vector< std::vector< int > > &G, int &one, int &zero) {
    int n = G.size();
    std::vector< int > mark(n,-1); 
    struct vertex { int v; int p; int m; };
    for (int i = 0; i < n; i++) {
        if (mark[i] != -1) continue;
        std::stack<vertex> sta;
        sta.push({i,-1,0}); 
        while (!sta.empty()) {
            vertex q = sta.top(); sta.pop();
            int v = q.v, p = q.p, m = q.m;
            if (mark[v] != -1) {
                if (mark[v] != m) return false;
                continue;
            }
            mark[v] = m;
            for (int u : G[v]) {
                if (u == p) continue;
                sta.push({u,v,1 - m});
            }
        }
    }
    one = 0;
    zero = 0;
    for (int i = 0; i < n; i++) {
        if (mark[i] == 0) zero++;
        else one++;
    }
    return true;
}
int main() {
    int n,m;cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int one,zero;
    if (nibu_judge(g,one,zero)) {
        cout << (ll)one * zero - m << endl;
    }
    else {
        cout << (ll)n * (n - 1) / 2 - m << endl;
    }
    return 0;
}


Measured memory_bytes: 9504
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
const string target="01234567";
struct puzzle {
    string stat;
    int zero;
    puzzle(string _s,int _x) {
        stat=_s;
        zero=_x;
    }
};
int d[4]={-1,1,-4,4};
int n;
int main() {
    queue<puzzle> que;
    map<string, int> done;
    que.push(puzzle(target,0));
    done[target]=0;
    while (!que.empty()) {
        puzzle now = que.front(); que.pop();
        int pos=now.zero;
        for (int i=0; i<4; i++) {
            int nx=pos+d[i];
            if ((nx>=0&&nx<4&&pos>=0&&pos<4)||
                (nx>=4&&nx<8&&pos>=4&&pos<8)||
                (nx>=0&&nx<4&&pos>=4&&pos<8&&abs(nx-pos)==4)||
                (nx>=4&&nx<8&&pos>=0&&pos<4&&abs(nx-pos)==4)) {
                string temp=now.stat;
                swap(temp[pos],temp[nx]);
                if (done.count(temp)==0) {
                    que.push(puzzle(temp,nx));
                    done[temp]=done[now.stat]+1;
                }
            }
        }
    }
    while (scanf("%d",&n)!=EOF) {
        string stats="";
        stats+=(n+'0');
        for (int i=1; i<8; i++) {
            scanf("%d",&n);
            stats+=(n+'0');
        }
        printf("%d\n",done[stats]);
    }
}

Measured memory_bytes: 2084
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
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); }
const int MAXN = 1e6+5;
#ifndef LOCAL
#define cerr if(0)cout
#endif
int A[MAXN];
int cnt[MAXN];

bool done[MAXN];
int32_t main() 
{
	IAMSPEED

	int n; cin >> n;
	FOR(i,1,n) {
		cin >> A[i];
		cnt[A[i]]++;
	}
	vector<int>ans;
	for(int i = 1; i < MAXN; ++i) {
		if(done[i])continue;
		if(cnt[i]==0)continue;
		if(cnt[i]==1)ans.pb(i);
		for(int j = i*2; j<MAXN; j+=i) {
			done[j] = 1;
		}
	}
	cout << ans.size();
}


Measured memory_bytes: 9388
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin)
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
int digsum(int n){
	if(n==0)return 0;
	return n%10+digsum(n/10);
}
bool find(int n){
	return (n%digsum(n)==0);
}
void solve(){
     int n;
     cin>>n;
     cout<<(find(n)?"Yes":"No")<<endl;
 }
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
//#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k;
int a[N], b[N], c[N];
string ss;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++){
		int x, y, z;
		cin >> x >> y >> z;
		if (!i){
			a[i] = x; b[i] = y; c[i] = z;
		}
		else{
			a[i] = max(b[i - 1], c[i - 1]) + x;
			b[i] = max(a[i - 1], c[i - 1]) + y;
			c[i] = max(a[i - 1], b[i - 1]) + z;
		}
	}
	cout << max({a[n - 1], c[n - 1], b[n - 1]});
	return 0;
}












Measured memory_bytes: 1408
S = input()
len_S = len(S)
ans = [0]*len_S
ct_R, ct_L = 0, 0

for i in range(len_S-1):
    if S[i] == 'R' and S[i+1] == 'L':
        ct_R += 1
        ans[i] += ct_R//2
        ans[i+1] += ct_R//2
        ans[i] += 1 if ct_R % 2 else 0
        ct_R = 0
    elif S[i] == 'R':
        ct_R += 1
    if S[len_S-i-1] == 'L' and S[len_S-i-2] == 'R':
        ct_L += 1
        ans[len_S-i-1] += ct_L//2
        ans[len_S-i-2] += ct_L//2
        ans[len_S-i-1] += 1 if ct_L % 2 else 0
        ct_L = 0
    elif S[len_S-i-1] == 'L':
        ct_L += 1

print(*ans)


Measured memory_bytes: 6400
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

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

vector<int> divisors(int n) {
  vector<int> res;
  for(int i = 1; i*i <= n; ++i) {
    if(n % i != 0) continue;
    res.push_back(i);
    if(n/i == i) continue;
    res.push_back(n/i);
  }
  return res;
}

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> vec = divisors(gcd(a, b));
  sort(vec.rbegin(), vec.rend());
  cout << vec[k - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

ll n,m;
ll a[100010],b[100010],c[100010];
ll dp[100010];
ll w[]={0,300000,200000,100000};
ll ans=0;

int main(void){
	cin>>n>>m;
	if(n<=3)ans+=w[n];
	if(m<=3)ans+=w[m];
	if(n==1 && m==1)ans+=400000;
	cout<<ans<<endl;
	return 0;
}

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

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

    vector<pair<int, int>> bot(n), bot_arm(n);
    for (int i = 0; i < n; i++)
    {
        int x, l;
        cin >> x >> l;
        bot[i] = make_pair(x, l);

        int left = x - l, right = x + l;
        bot_arm[i] = make_pair(right, left);
    }

    sort(bot_arm.begin(), bot_arm.end());
    int ans = 0,arm_left = bot_arm[0].second - 10;
    for (int i = 0; i < n; i++)
    {
        if(arm_left <= bot_arm[i].second)
        {
            arm_left = bot_arm[i].first;
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4760
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

long long dp[1000003][2];
string S;
int len;

long long dp_(int i, int j) {
	
	if (dp[i][j] >= 0) {
		return dp[i][j];
	}
	if (i >= len) {
		dp[i][j] = j;
		return dp[i][j];
	}
	int a = S[len - i - 1] - '0';
	long long m,n;
	m = dp_(i + 1, 0) + a + j;
	n = dp_(i + 1, 1) + 10 - a - j;
	if (m > n) { m = n; }
	dp[i][j] = m;
	return dp[i][j];
}


int main() {
	cin >> S;
	len = S.length();

	for (int i = 0; i <= len; i++) {
		dp[i][0] = -1;
		dp[i][1] = -1;
	}
	
	cout << dp_(0, 0);
}

Measured memory_bytes: 63876
#include <cstdio>

const long long MAX = 100000;
long long x[MAX+1], y[MAX+1];
long long xd[MAX], yd[MAX];
const long long MOD = 1e9+7;

int main() {
        long long m, n;
        scanf("%lld%lld", &n, &m);

        for (int i=1; i<=n; ++i) {
                scanf("%lld", &x[i]);
        }
        for (int i=1; i<=m; ++i) {
                scanf("%lld", &y[i]);
        }

        for (int i=1; i<n; ++i) {
                xd[i] = x[i+1]-x[i];
        }
        for (int i=1; i<m; ++i) {
                yd[i] = y[i+1]-y[i];
        }

        long long mod_x = 0;
        for (int i=1; i<=n-1; ++i) {
                long long cur_total;
                mod_x += xd[i]*(i*(n-i));
                mod_x %= MOD;
        }
        long long mod_y = 0;
        for (int i=1; i<=m-1; ++i) {
                long long cur_total;
                mod_y += yd[i]*(i*(m-i));
                mod_y %= MOD;
        }
        printf("%lld\n", (mod_x * mod_y) % MOD);
        return 0;
}

Measured memory_bytes: 3328
from sys import stdin

N, M, X, Y = [int(x) for x in stdin.readline().rstrip().split()]
x = sorted([int(x) for x in stdin.readline().rstrip().split()], reverse=True)
y = sorted([int(x) for x in stdin.readline().rstrip().split()])
if y[0] > x[0] and Y > x[0] and X < y[0]:
    print('No War')
else:
    print('War')


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
int n,S;
int a[4];

while(cin>>n)
{
S=0;
a[0]=0;
a[1]=0;
a[2]=0;
a[3]=0;
for(int i=0;i<10;i++)
{
	a[0]=i;
	for(int j=0;j<10;j++)
{
	a[1]=j;
	for(int k=0;k<10;k++)
{
	a[2]=k;
		for(int l=0;l<10;l++)
{
	a[3]=l;
	if(a[0]+a[1]+a[2]+a[3]==n)
	{
		S++;
	}
}
}	
}
}
cout<<S<<endl;	
}
return 0;
}

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


def solve(N: int, A: "List[int]"):
    for i in range(N):
        A[i] -= i + 1
    A.sort()
    tmp = A[0]
    for i in range(N):
        A[i] -= tmp
    l = -1
    r = N
    cur = sum(A)
    #print(A)
    while r - l > 1:
        m = (l + r) // 2
        val = A[m]
        tmp = 0
        for a in A:
            tmp += abs(a - val)
        if tmp <= cur:
            l = m
            cur = tmp
        else:
            r = m
    val = A[l]
    ret = 0
    for a in A:
        ret += abs(a - val)

    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 29276
import java.util.Scanner;

class Main {
    public static void main (String[] arg) {
        int N, K;

        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();// 個数
        K = scanner.nextInt(); // 人
        scanner.close();

        int devide = N - (K -1);
         devide = devide - 1;
         
         if (K == 1) System.out.println("0"); 
         else System.out.println(devide);

    } 
}

Measured memory_bytes: 23252