akhauriyash/Code-Regression huggingface dataset:
from collections import deque
import heapq

n,k = map(int,input().split())
v = list(map(int,input().split()))

ans = 0
for i in range(1,min(n,k)+1):
    for j in range(i+1):
        s = []
        heapq.heapify(s)
        res = 0
        num = 0
        for _ in range(j):
            heapq.heappush(s,v[num])
            res += v[num]
            num += 1
        num = 1
        for _ in range(j,i):
            heapq.heappush(s,v[-num])
            res += v[-num]
            num += 1

        for j in range(k-i):
            if len(s) == 0:
                break
            if s[0] < 0:
                res -= heapq.heappop(s)
            else:
                break
        if ans < res:
            ans = res
print(ans)


Measured memory_bytes: 3436
n_switch, n_lamp = map(int,input().split())
lamp_switch_count = [0] * n_lamp
lamp_switch = [0] * n_lamp

for i in range(n_lamp):
    ls = list(map(int, input().split()))
    lamp_switch_count[i] = ls[0]
    ls_switch = ls[1:]
    for j in range(len(ls_switch)):
        ls_switch[j] -= 1
    lamp_switch[i] = ls_switch

mod_ls = list(map(int, input().split()))

ans = 0
for pattern in range(2**n_switch):
    all_on = True
    switch_on_ls = [0] * n_switch 
    for i_switch in range(n_switch):
        if (pattern >> i_switch) & 1:
            switch_on_ls[i_switch] = 1
    for i_lamp in range(n_lamp):
        num_target = lamp_switch_count[i_lamp]
        onswitch_num = 0
        for i in range(num_target):
            ind_of_target_switch = lamp_switch[i_lamp][i]
            if switch_on_ls[ind_of_target_switch]:
                onswitch_num += 1
        if onswitch_num % 2 != mod_ls[i_lamp]:
            all_on = False
    if all_on:
        ans += 1
print(ans)




Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define dump(x)  cout << #x << " = " << (x) << endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;

    string s;
    cin >> s;
    rp(i,sz(s)) {
        if(i < sz(s) - 1)
            if(s[i] == s[i+1])
            {
                cout << i+1 << " "<<i+2<<endl;
                return 0;
            }
        if(i < sz(s)-2)
            if(s[i] == s[i+2]){
                cout << i+1 << " "<<i+3 <<endl;
                return 0;
            }
    }
    cout << "-1 -1\n";
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

using namespace std;


int main(){
    int N;cin >> N;
    vector<int> vec;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec.push_back(b);
    }
    int ma = 0;
    int ans = 0;
    for(int a = 0;a < N;a++){
        if(ma  <= vec.at(a)){
            ans++;
        }
        ma = max(ma,vec.at(a));
    }
    cout<<ans<<endl;
}


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

int main() {
  
  string S;
  cin >> S;
  
  for ( int i=0; i < S.size(); i++) {
  
  if ( S.at(i) == 'L' && i % 2 ==0) {
    cout << "No" << endl;
    break;
  }
  if ( S.at(i) == 'R' && i % 2 ==1) {
    cout << "No" << endl;
    break;
  }
  else if ( i==S.size()-1 ) {
      cout << "Yes" << endl;
  }
  }
}

Measured memory_bytes: 256
using System;
 
public class Hello{
	public static void Main(){
      string s = Console.ReadLine();
      char x,y;
      int N = s.Length;
      int C_1,C_2;
      int flag;
      flag=0;
      C_1=(N-1)/2;
      C_2=(N+3)/2;
      for(int i=0;i<C_1;i++){
        x = s[i];
        y = s[C_1-1-i];
        if(x!=y){
          flag=1;
          break;
        }
      }
      for(int i = C_2;i<N;i++){
        x=s[i];
        y=s[N-1-i];
        if(x!=y){
          flag=1;
          break;
        }
      }
      if(flag==1){
        Console.Write("No");
      }
      else Console.WriteLine("Yes");
	}
} 


Measured memory_bytes: 13140
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int map[101][101];
int main()
{
	int h, w;
	char c[201];
	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; i++)
	{
		scanf("%s",c);
		for (int j = 0; j < w; j++)
		{
			if (c[j] == 'c')
				map[i][j] = 0;
			else
				map[i][j] = -1;
		}
	}
	for (int i = 0; i < h; i++)
	{
		for (int j = 1; j < w; j++)
		{
			if (map[i][j] < 0)
			{
				if (map[i][j-1] >= 0)
					map[i][j] = map[i][j-1] + 1;
			}
		}
	}
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (j != w - 1)
				cout << map[i][j] << ' ';
			else
				cout << map[i][j] << endl;
		}
	}
	return 0;
}

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

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

    int cnt = 0;
    rep(y, h) rep(x, w) {
        char a;
        cin >> a;
        if (a == '#') cnt++;
    }

    if (cnt == h + w - 1)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 100100100
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    
    ll lsum = 0, rsum = 0;
    
    rep(i,n) rsum += a[i];
    ll ans = INF;
    lsum += a[0];
    rsum -= a[0];
    for(int i = 1; i<n-1; i++){
        lsum += a[i];
        rsum -= a[i];
        ans = min(ans, abs(lsum-rsum));
    }
    if(n == 2) ans = abs(lsum-rsum);

    cout << ans << endl;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define imprime(v) for(int X=0;X<v.size();X++) printf("%d ", v[X]); printf("\n");
#define endl "\n"
const int INF= 0x3f3f3f3f;
const long double pi= acos(-1);
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
const int MOD=1e9+7;
const ll LINF=0x3f3f3f3f3f3f3f3f;
int k;
int n, m;
int grid[105][105];
int a[100005];
int mh[] = {1, -1, 0, 0};
int mv[] = {0, 0, 1, -1};

bool ok(int x, int y) {
  return !(x < 0 or y < 0 or x >= n or y >= m);
}

void solve() {
  int dir = 1;
  int pt = 0;
  for(int i = 0; i < n; i++) {
    if(dir == 1) {
      for(int j = 0; j < m; j++) {
        if(a[pt] == 0) pt++;
        grid[i][j] = pt + 1;
        a[pt]--;
      }
    }
    else {
      for(int j = m - 1; j >= 0; j--) {
        if(a[pt] == 0) pt++;
        grid[i][j] = pt + 1;
        a[pt]--;
      }
    }
    
    dir = -dir;
  }
}

int main() {
  sc2(n, m);
  sc(k);
  for(int i = 0; i < k; i++) {
    sc(a[i]);
  }
  solve();
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      if(j != 0) printf(" ");
      printf("%d", grid[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	map<int,int> mpn;
	rep(i,n){
		int a;cin>>a;
		mpn[a]++;
	}
	int m;cin>>m;
	rep(i,m){
		int a;cin>>a;
		mpn[a]--;
		if(mpn[a]<0){
			cout<<"NO"<<"\n";
			return 0;
		}
	}
	cout<<"YES"<<"\n";
}

Measured memory_bytes: 9600
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();

            foreach (var v in n)
            {
                if (v == '9')
                {
                    Console.Write('1');
                } else if (v == '1')
                {
                    Console.Write('9');
                } else
                {
                    Console.Write(v);
                }
            }

            Console.WriteLine();
        }
    }
}


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

using namespace std;

#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define ll long long int

//Zavrsi vise: https://atcoder.jp/contests/dp/tasks/dp_a

int INF = 1e9+5;

int main() {
int N,K;
cin>>N>>K;
vector<int> v(N);
vector<int> dp(N,INF);
for(auto& x: v)
    cin>>x;
dp[0] = 0;
for(int i=0;i<N;i++) {
    for(int j=i+1;j<=i+K;j++) {
        if(j<N) {
            dp[j] = min(dp[j],dp[i]+abs(v[i]-v[j]));
        }
    }
}
cout<<dp[N-1]<<endl;
return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}




int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	string a, b;
	cin >> a >> b;

	int ans = 0;
	for(int i = 0; i < a.size(); i++)
		if(a[i] != b[i])
			ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3772
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 0;
        boolean isContinue = true;
        int n = Integer.parseInt(sc.nextLine());
        String[] list = sc.nextLine().split(" ");
        sc.close();
        while (isContinue) {
            for (int i = 0; i < n; i++) {
                Integer val = Integer.parseInt(list[i]);
                if (val % 2 == 0) {
                    list[i] = String.valueOf(val / 2);
                } else {
                    isContinue = false;
                    break;
                }
            }
            if (isContinue) {
                count++;
            }
        }
        System.out.println(count);
    }
}

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

typedef long long ll;
using namespace std;
//using namespace atcoder;

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define _reps(i, s, n) for(ll i = (ll)(s); i < (ll)n; i++)
#define REP(...) _overload(__VA_ARGS__, _reps, _rep,)(__VA_ARGS__)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

int main(){
	ll n;	cin >> n;
	ll ans = 0;

	REP(i, 1, n){
		ans += n / i;
		if( n % i == 0 )	ans--;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3620
while True:
    a,b = [int(i) for i in input().split()]

    if a == 0 and b == 0:
        break

    if a < b:
        a,b = b,a

    cnt = 0
    while b > 0:
        a, b = b, a % b
        cnt += 1

    print(a, cnt)



Measured memory_bytes: 5608
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<cassert>
using namespace std;
#define N 4
#define N2 16
#define LIMIT 100
 
static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = { 'r', 'u', 'l', 'd'};
int MDT[N2][N2];
 
struct Puzzle{int f[N2], space, MD;};
 
Puzzle state;
int limit;
int path[LIMIT];
 
int getAllMD(Puzzle pz){
  int sum = 0;
  for(int i = 0 ; i < N2 ; i++){
    if(pz.f[i] == N2) continue;
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}
 
bool isSolved(){
  for(int i = 0 ; i < N2 ; i++) if(state.f[i] != i + 1) return false;
  return true;
}
 
bool dfs(int depth, int prev){
  if(state.MD == 0) return true;
  if(depth + state.MD > limit) return false;
 
  int sx = state.space / N;
  int sy = state.space % N;
  Puzzle tmp;
 
  for(int r = 0 ; r < 4 ; r++){
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
    if(max(prev, r)-min(prev, r) == 2) continue;
    tmp = state;
    state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
    state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
    swap(state.f[tx * N + ty], state.f[sx * N + sy]);
    state.space = tx * N + ty;
    if(dfs(depth + 1, r)) {path[depth] = r; return true;}
    state = tmp;
  }
 
  return false;
}
 
string iterative_deepening(Puzzle in){
  in.MD = getAllMD(in);
 
  for(limit = in.MD ; limit <= LIMIT ; limit++){
    state = in;
    if(dfs(0, -100)){
      string ans = "";
      for(int i = 0 ; i < limit ; i++) ans += dir[path[i]];
      return ans;
    }
  }
 
  return "ubsolvable";
}
 
int main(){
  for(int i = 0 ; i < N2 ; i++)
    for(int j = 0 ; j < N2 ; j++)
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
 
  Puzzle in;
 
  for(int i = 0 ; i < N2 ; i++){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = iterative_deepening(in);
  cout << ans.size() << endl;
 
  return 0;
}

Measured memory_bytes: 3232
N = int(input())
l = list(map(int, input().split()))

l[0] -= 0

ans = 'Yes'
for i in range(1,N):
    if l[i-1] < l[i]:
        l[i] -= 1
    elif l[i-1] == l[i]:
        pass
    else:
        ans = 'No'
        break
print(ans)



Measured memory_bytes: 14252
#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 pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int n,k;
    cin >> n >> k;

    vector<pair<ll,ll>> v;

    rep(i,n){
        int x,y;
        cin >> x >> y;

        v.pback(mpair(x,y));

    }
    
    ll ans = LLONG_MAX;

    for(int a = 0; a <= n - 2; a++){
        for(int b = 0; b <= n - 1; b++){
            for(int c = 0; c <= n - 2; c++){
                for(int d = 0; d <= n - 1; d++){

                    ll left = min(v[a].first, v[b].first);
                    ll right = max(v[a].first, v[b].first);
                    ll bottom = min(v[c].second, v[d].second);
                    ll top = max(v[c].second, v[d].second);

                    int count = 0;

                    rep(i,n){
                        ll x = v[i].first;
                        ll y = v[i].second;
                        if(left <= x && x <= right && bottom <= y && y <= top){
                            count++;
                        }
                    }

                    if(count >= k){
                        ans = min(ans, (right - left) * (top - bottom));
                    }
                }
            }
        }
    }





    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
<?php
while (fscanf(STDIN, "%d %d %d", $T, $P, $R) && ($T | $P | $R)) {
  $correct = array(array());
  $wrong = array(array());
  
  for ($i = 0; $i < $T; $i++) {
    for ($j = 0; $j < $P; $j++) {
      $correct[$i + 1][$j + 1] = 0;
      $wrong[$i + 1][$j + 1] = 0;
    }
  }

  for ($i = 0; $i < $R; $i++) {
    $in = explode(" ", trim(fgets(STDIN)));
    
    if ($in[3] == 'WRONG') {
      $wrong[$in[0]][$in[1]]++;
    } else {
      if ($correct[$in[0]][$in[1]]) continue;
      $correct[$in[0]][$in[1]] = 1200 * $wrong[$in[0]][$in[1]] + $in[2];
    }
  }

  $id = array();
  $solved = array();
  $total = array();
  for ($i = 0; $i < $T; $i++) {
    $s = $t = 0;
    for ($j = 0; $j < $P; $j++) {
      $s += ($correct[$i + 1][$j + 1] > 0) ? 1 : 0;
      $t += $correct[$i + 1][$j + 1];
    }
    $id[] = $i + 1;
    $solved[] = $s;
    $total[] = $t;
  }
  $state = array($solved, $total, $id);
      
  array_multisort($state[0], SORT_DESC, $state[1], SORT_ASC, $state[2], SORT_ASC);
  
  for ($i = 0; $i < $T; $i++) {
    print $state[2][$i] . " " . $state[0][$i] . " " . $state[1][$i] . "\n";
  }
}

Measured memory_bytes: 6932
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;

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


vector<P>G[100010];
int color[100010];

void dfs(int v, int p, int c) {
	color[v] = c;
	for (int i = 0; i < G[v].size(); i++) {
		int q = G[v][i].first;
		int d = G[v][i].second;
		//if (color[v] >= 0)continue;
		if (q == p) continue;
		//cout << v << ' ' << q << endl;
		if (d % 2 == 0) dfs(q, v, color[v]);
		else dfs(q, v, 1 - color[v]);
	}
	return;
}

int main(void) {
	int N; cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int p, q, d; cin >> p >> q >> d;
		p--; q--;
		G[p].push_back({ q, d });
		G[q].push_back({ p, d });
		color[i] = -1;
	}

	dfs(0, -1, 0);

	for (int i = 0; i < N; i++) cout << color[i] << endl;

}


Measured memory_bytes: 9088
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
    long X,N;
    set<long> list;
    cin >> X >> N;
    list.insert(114514);
    for(int i = 0; i < N; i++){
        long tmp;
        cin >> tmp;
        list.insert(tmp);
    }

    for (int i = 0; i < 100; i++)
    { 
        long p,n;
        n = X - i;
        p = X + i;
        auto ni = list.find(n);
        auto pi = list.find(p);
        if(ni == list.end()){
            cout << n << endl;
            return 0;
        }else if(pi == list.end()){
            cout <<  p << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3652
//ProblemB

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <memory>
#include <cstdio>
#include <cstring>

using namespace std;

//ProblemB

#define MAXN 10000

class Solve {
private:
	int n;
	int a[MAXN];

	void solve() {
		cin >> n;
		for (int i = 0; i < n; i++) cin >> a[i];

		long long plus = 0, minus = 0;
		int b;
		for (int i = 0; i < n; i++) {
			cin >> b;
			a[i] -= b;

			if (a[i] > 0) plus += a[i];
			else minus += (-a[i]) / 2 * 2;
		}

		if (plus * 2 <= minus) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

public:
	Solve() { solve(); }
};

int main(int argc, char* argv[]) {
	unique_ptr<Solve> solve = make_unique<Solve>();
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    final double EPS = 1.0e-10;

    void run() {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0)
                break;
            P[] ps = new P[n];
            for (int i = 0; i < n; i++) {
                ps[i] = new P(sc.nextDouble(), sc.nextDouble());
            }
            int ans = 1;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    if (ps[i].sub(ps[j]).abs() > 2)
                        continue;
                    P[] cs = makeCircle(ps[i], ps[j], 1.0);
                    for (int l = 0; l < 2; l++) {
                        double cx = cs[l].x;
                        double cy = cs[l].y;
                        int c = 2;
                        for (int k = 0; k < n; k++) {
                            if (k == i || k == j)
                                continue;
                            if ((ps[k].x - cx) * (ps[k].x - cx)
                                    + (ps[k].y - cy) * (ps[k].y - cy) <= 1.0 + EPS) {
                                c++;
                            }
                        }
                        ans = Math.max(c, ans);
                    }
                }
            }
            System.out.println(ans);
        }

    }

    P[] makeCircle(P a, P b, double r) {
        double th = Math.atan(-(b.x - a.x) / (b.y - a.y));
        P m = a.add(b).mul(0.5);
        double dis = Math.sqrt(r * r - b.sub(m).abs2());
        return new P[] {
                new P(m.x - dis * Math.cos(th), m.y - dis * Math.sin(th)),
                new P(m.x + dis * Math.cos(th), m.y + dis * Math.sin(th)) };
    }

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

class P {
    double x;
    double y;

    P(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public String toString() {
        return "(" + x + " , " + y + ")";
    }

    public P add(P p) {
        return new P(p.x + x, p.y + y);
    }

    public P sub(P p) {
        return new P(x - p.x, y - p.y);
    }

    public P mul(double k) {
        return new P(k * x, k * y);
    }

    public double abs() {
        return Math.sqrt(x * x + y * y);
    }

    public double abs2() {
        return x * x + y * y;
    }

    public double det(P p) {
        return x * p.y - y * p.x;
    }

    public P rot90() {
        return new P(-y, x);
    }
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int n,m;
  n=s.size();
  m=t.size();
  if(n<m){cout<<"LESS";}
  else if(n>m){cout<<"GREATER";}
  else if (s<t){cout<<"LESS";}
  else if(s>t){cout<<"GREATER";}
  else{cout<<"EQUAL";}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

struct UnionFind {
  vector<int> parent;
  vector<ll> sum;
  UnionFind (int n) : parent(n, -1), sum(n, 0) {}
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (parent[y] < parent[x]) swap(x, y);
    if (parent[x] == parent[y]) --parent[x];
    parent[y] = x;
    sum[x] += sum[y];
    return true;
  }
};

void dfs(const vector<vector<tuple<int,ll,int>>>& g, vector<bool>& save, vector<bool>& vis, int v, ll y) {
  vis[v] = true;
  for (auto&& e : g[v]) {
    int to,i;
    ll w;
    tie(to, w, i) = e;
    if (w > y) continue;
    save[i] = true;
    if (vis[to]) continue;
    dfs(g, save, vis, to, y);
  }
}

int main()
{
  int n,m;
  cin>>n>>m;
  vecll x(n);
  for(auto&& e:x) cin>>e;
  vector<tuple<ll,int,int,int>> ve;
  vector<vector<tuple<int,ll,int>>> g(n);
  for(int i:irange(0,m)) {
    int a,b;
    ll y;
    cin>>a>>b>>y;
    --a;--b;
    g[a].emplace_back(b, y, i);
    g[b].emplace_back(a, y, i);
    ve.emplace_back(y,a,b,i);
  }
  boost::sort(ve);
  vector<bool> candi(m);
  UnionFind uf(n);
  uf.sum = x;
  for(auto&& p:index(ve)) {
    ll y;
    int a,b,i;
    tie(y,a,b,i) = p.value();
    uf.merge(a, b);
    if (uf.sum[uf.root(a)] >= y) {
      candi[p.index()] = true;
    }
  }
  vector<bool> save(m);
  vector<bool> vis(n);
  for(int i:irange(0,m)) {
    int j=m-i-1;
    if (!candi[j]) continue;
    ll y;
    int a,b,k;
    tie(y,a,b,k) = ve[j];
    if (save[k]) continue;
    save[k] = true;
    dfs(g, save, vis, a, y);
  }
  cout<<boost::count(save, false)<<endl;
  return 0;
}


Measured memory_bytes: 21680
#include<bits/stdc++.h>
using namespace std;
int s1,s2,a;
char c[100010],c1,c2;
int main(){
	scanf("%s",c+1);
	a=strlen(c+1);
	c1=c[1],c2=c[a];
	if((c1==c2&&a%2==0)||c1!=c2&&a%2!=0) cout<<"First";
	else cout<<"Second"; 
	return 0;
}

Measured memory_bytes: 384
from functools import reduce

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def div_ceil(x, y): return (x + y - 1) // y

N, M = map(int, input().split())
*A, = map(int, input().split())
A = list(set([a // 2 for a in A]))
L = reduce(lcm, A)
for a in A:
    if (L // a) % 2 == 0:
        ans = 0
        break
else:
    ans = div_ceil(M // L, 2)
print(ans)

Measured memory_bytes: 14748
#include <stdio.h>
int main(void){
	int a,b,c,i;
	scanf("%d %d %d",&a,&b,&c);
	for(i=1;i<b;i++){
		int x=a*i,r=x%b;
		if(r==c){printf("YES");return 0;}
	}
	printf("NO");
}

Measured memory_bytes: 128
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a, b = (int(_) for _ in input().split())
    if (a*b) % 2 == 1:
        print('Yes')
    else:
        print('No')
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
std::string s;
int main()
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	std::cout.tie(0);
	std::cin>>s;
	int c=1e9,f=-1;
	for(int i=0;i<(int)s.size();i++)
	{
		if(s[i]=='C')
		{
			c=i;
			break;
		}
	}
	for(int i=(int)s.size()-1;i>=0;i--)
	{
		if(s[i]=='F')
		{
			f=i;
			break;
		}
	}
	if(c<f)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 256
//
//  main.c
//  ITP1_7_B
//
//  Created by k16031kk on 2018/05/26.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int n,x;
    while(1) {
        scanf("%d %d", &n, &x);
        if(n==0 && x==0) break;
        int count=0;
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {
                if(i==j) break;
                for(int k=1; k<=n; k++) {
                    if(j==k || i==k) break;
                    if(i+j+k==x) count++;
                }
            }
        }
        printf("%d\n",count);
    }
    
    return 0;
}



Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int main() {
  int has[4][13] = {0};
  int n, r;
  char s;
  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> s >> r;
    has[(s == 'H') + (s == 'C') * 2 + (s == 'D') * 3][r - 1] = 1;
  }

  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 13; ++j) {
      if (!has[i][j]) {
        cout << "SHCD"[i] << ' ' << (j + 1) << endl;
      }
    }
  }
  return 0;
} 



Measured memory_bytes: 3080
#include <stdio.h>
#define MAX 100000
  
void Preorder(int);
void Inorder(int);
void Postorder(int);
  
struct Node{
  int p,s,l,r;
};
  
struct Node T[MAX];
 
int n,i;
 
int main(){
  int j,lf,ri,c[MAX],id[MAX],p,s,deg[MAX],dep,h;
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++){
    T[i].p = -1;
    T[i].s = -1;
    T[i].l = -1;
    T[i].r = -1;
  }
    
  for(i = 0 ; i < n ; i++){
    scanf("%d",&id[i]);
    for(j = 0 ; j < 2 ; j++){
      scanf("%d",&c[j]);
      if(j == 0){
        lf = c[j];
        T[id[i]].l = c[j];
        T[c[j]].p = id[i];
      }
      else {
        ri = c[j];
        T[id[i]].r = c[j];
        T[c[j]].p = id[i];
      }
    }
  }
  for(i = 0 ; i < n ; i++){
    if(T[i].p == -1) break;
  }  
  printf("Preorder\n");
  Preorder(i); 
  printf("\nInorder\n");
  Inorder(i); 
  printf("\nPostorder\n");
  Postorder(i);
  printf("\n");  
  return 0;
}
void Preorder(int u){
  printf(" %d",u);
   if(T[u].l != -1){
    Preorder(T[u].l);
  }
  if(T[u].r != -1){
    Preorder(T[u].r);
  }
}
void Inorder(int u){
  if(T[u].l != -1){
    Inorder(T[u].l);
  }
  printf(" %d",u);
  if(T[u].r != -1){
    Inorder(T[u].r);
  }
}
void Postorder(int u){
     if(T[u].l != -1){
    Postorder(T[u].l);
  }
  if(T[u].r != -1){
    Postorder(T[u].r);
  }
  printf(" %d",u);  
}

Measured memory_bytes: 632
H,W=gets.split.map(&:to_i)
as=H.times.map{gets.split.map(&:to_i)}
i=-1
j=0
lastw=0
lasth=0
ans=Array.new
cnt=0
while i<H-1 do
	i+=1
	if i.even?
		0.upto(W-1) do |j|
			next if i==0 && j==0
			if as[lasth][lastw].odd?
				as[lasth][lastw]-=1
				as[i][j]+=1
				cnt+=1
				ans << "#{lasth+1} #{lastw+1} #{i+1} #{j+1}"
			end
			lastw,lasth=j,i
		end
	else	
		(W-1).downto(0) do |j|
			if as[lasth][lastw].odd?
				as[lasth][lastw]-=1
				as[i][j]+=1
				ans << "#{lasth+1} #{lastw+1} #{i+1} #{j+1}"
				cnt+=1
			end
			lastw,lasth=j,i	
		end
	end

end
puts cnt
puts ans

Measured memory_bytes: 17916
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=INF; cin>>n;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            string l=to_string(i);
            string r=to_string(n/i);
            ans=min(ans,(ll)max(l.size(),r.size()));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
const string YES = "Yes";
const string NO = "No";

string N;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    solve();
}

// 0 <= N < 10^{200000}
// N は整数

// string N
// N が 9 の倍数ならば Yes、そうでないなら No を出力せよ。
void solve(){
    ll sum=0;
    rep(i,N.size())sum+=N[i]-'0';
    cout<<(sum%9?NO:YES)<<endl;
}


Measured memory_bytes: 3736
program train;
var 
    i, temp : integer;
    a : array[1..3] of integer;

begin
    for i := 1 to 3 do 
        read(a[i]);

    temp := a[1];
    a[1] := a[2];
    a[2] := temp;

    temp := a[1];
    a[1] := a[3];
    a[3] := temp;

    for i := 1 to 3 do
        write(a[i],' ');

end.

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;


signed main() {
    int N;
    cin >> N;
    for (int a = 1; a <= 9; ++a) {
        for (int b = 1; b <= 9; ++b) {
            if (a * b == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

int main () {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector <int> participant(N+1, K-Q);

    int A;
    for (int i = 0; i < Q; i++) {
        cin >> A;
        participant[A] += 1;
    }

    for (int i = 1; i < participant.size(); i++) {
      	cout << (participant[i] > 0 ? "Yes" : "No" ) << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
// ABC001C.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>

using namespace std;




int main()
{
	int a,b;
	cin>>a>>b;
	if( b % a == 0){
		cout<< a + b<<endl;
	}else{
		cout<< b - a<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
import numpy as np

H, N = map(int, input().split())
AB = np.array([list(map(int, input().split())) for i in range(N)])
A = AB[:, 0]
B = AB[:, 1]

# インデックスはライフ 値はそれを以下にする最小MP
# dp = np.array([0 for i in range(H+1)])
# dp = np.array([10**10 for i in range(H+1)])
dp = np.array([np.inf for i in range(H+1)])
dp[0] = 0

for i in range(1, H+1):
    dp[i] = min(dp[np.maximum(i-A, 0)] + B)

print(int(dp[-1]))

Measured memory_bytes: 14696
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#define ll long long
#define ull long long unsigned
using namespace std;
#define foru(i,a,n) for (int i=(a); i<=(n); i++)
#define ford(i,n,a) for (int i=(n); i>=(a); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define bit1cnt(x) (__builtin_popcountll(x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define Pi 3.14159265358979
#define ii pair<int,int>
#define LL pair<ll,ll>
const int N = 2e5;
map <int,int> f;
map <int,int>::iterator it;
int n, x, y, ans = 0;
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin >>n;
    foru(i, 1, n){
        cin >>x;
        f[x]++;
    }
    for(it=f.begin(); it!=f.end(); it++){
        x = it->first;
        y = it->second;
        if(y<x) ans += y; else ans += y-x;
    }
    cout <<ans;
    return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

struct node{
  int pr;
  int ed;
  int size;
  node(int pr=-1,int ed=0,int size=1):pr(pr),ed(ed),size(size){}
};

int parent(vector<node> &m,int u){return m[u].pr==-1?u:parent(m,m[u].pr);}

int add_edge(vector<node> &m,int u,int v){
  int ret=0;
  u=parent(m,u);
  v=parent(m,v);
  if(u==v){m[u].ed++; return m[u].ed<=m[u].size?1:0;}
  if(m[u].size<m[v].size){swap(u,v);}
  auto &U=m[u];
  auto &V=m[v];
  ret-=min(U.size,U.ed)+min(V.size,V.ed);
  U.size+=V.size;
  U.ed+=V.ed+1;
  V.pr=u;
  ret+=min(U.size,U.ed);
  return ret;
}

int main(){
  typedef pair<ll,pll> card;

  ll N,H,W;
  cin>>N>>H>>W;
  vector<card> A(N);
  for(auto &I:A){cin>>I.S>>I.F; I.S.F--; I.S.S--;}
  vector<node> uft(H+W,node());
  sort(A.begin(),A.end(),greater<card>());
  ll ans=0;
  for(ll i=0;i<N;i++){
    ans+=A[i].F*add_edge(uft,A[i].S.F,A[i].S.S+H);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 4992
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, M = getNM()
# l ~ rのどれかを持っていれば通過できる
L = 0
R = float('inf')

for i in range(M):
    l, r = getNM()
    L = max(L, l)
    R = min(R, r)

if R >= L:
    print(R - L + 1)
else:
    print(0)

Measured memory_bytes: 83944
import itertools
h, w = map(int, input().split())
cells = [[c for c in input()] for i in range(h)]

for y in range(h):
    for x in range(w):
        cnt = 0
        if cells[y][x] == '#':
            continue
        for dy, dx in itertools.product((-1, 0, 1), repeat=2):
            if not (0 <= y + dy < h and 0 <= x + dx < w):
                continue
            if cells[y + dy][x + dx] == '#':
                cnt += 1
        cells[y][x] = str(cnt)

for line in cells:
    print(''.join(line))


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

int g[10][10];

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> G(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a][b]=1;
        g[b][a]=1;
    }

    vector<int> ord(n);
    rep(i,n) ord[i]=i;

    int ans=0;
    do{
        
        if(ord[0]!=0) continue;
        bool ok=true;
        rep(i,n-1){
            if(!g[ord[i]][ord[i+1]]){
                ok=false;
                break;
            }
        }
        if(ok) ans++;
    }while(next_permutation(all(ord)));
    
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;


bool solve(char p2, char p1, auto& S)
{
    char initP2 = p2; // 最後の仮定
    char initP1 = p1; // 先頭の仮定

    std::string ans;
    for (size_t i = 0; i < S.size(); ++i) {
        auto c = S[i];
        char next;
        if (p2 == 'W' && p1 == 'W') {
            if (c == 'o') {
                next = 'S';
            }
            else {
                next = 'W';
            }
        }
        else if (p2 == 'S' && p1 == 'W') {
            if (c == 'o') {
                next = 'W';
            }
            else {
                next = 'S';
            }
        }
        else if (p2 == 'W' && p1 == 'S') {
            if (c == 'o') {
                next = 'W';
            }
            else {
                next = 'S';
            }
        }
        else {
            // p2 == 'S' && p1 == 'S'
            if (c == 'o') {
                next = 'S';
            }
            else {
                next = 'W';
            }
        }
        ans += p1;

        p2 = p1;
        p1 = next;
    }

    if (initP2 == ans[ans.size()-1] &&
        initP1 == p1)
    {
        std::cout << ans << std::endl;
        return true;
    }
    return false;
}



int main()
{
    int64_t N;
    std::cin >> N;

    std::string S;
    std::cin >> S;

    if (solve('W', 'S', S)) {
        return 0;
    }
    if (solve('S', 'S', S)) {
        return 0;
    }
    if (solve('W', 'W', S)) {
        return 0;
    }
    if (solve('S', 'W', S)) {
        return 0;
    }

    std::cout << "-1" << std::endl;

    return 0;
}


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

int main(){
    string s; cin >> s;
    sort(s.begin(), s.end());

    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin >>a>>b;
  int n=0;
  if (b==100)
    {
    n=a*1000+b;
  }
  else if(b>=10)
    {
    n = a*100+b;
  }
  else
    {
    n=a*10+b;
  }
  int s=sqrt(n);
  if (s*s==n) {
    cout<< "Yes" <<endl;
  } else
   {
    cout<< "No" <<endl;
  }

}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;

int main()
{
    fastio;
  	int n;
  	cin>>n;
  	LL a[n],sum=0;
  	int count[100000+7];
    
  memset(count,0,sizeof(count));
  for(int i=0;i<n;i++){
    cin>>a[i];
    count[a[i]]++;
    sum+=a[i];
  }
  

  int q;
  cin>>q;
  while(q--){
   
   LL b,c;
   cin>>b>>c;
   if(count[b]>0){
     sum = sum-(b*count[b])+(c*count[b]);
     count[c]+= count[b];
     count[b]=0;

   }
     cout<<sum<<"\n";
  }
   
}

Measured memory_bytes: 4812
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
s_xy = set(xy)

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        ix, iy = xy[i]
        jx, jy = xy[j]
        p = jx - ix
        q = jy - iy
        tc = sum((x-p,y-q) in xy for x, y in s_xy)

        count = max(count, tc)

print(n-count)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main(void){
    int n,x[100],y[100];
    cin>>n;
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<n;i++)cin>>y[i];
    double d[4]={};
    for(int p=1;p<=3;p++){
        for(int i=0;i<n;i++){
            d[p]+=pow(fabs(x[i]-y[i]),p);
        }
        d[p]=pow(d[p],1.0/p);
    }
    
    for(int i=0;i<n;i++){
        d[0]=(d[0]<fabs(x[i]-y[i]))?fabs(x[i]-y[i]):d[0];
    }
    printf("%f\n",d[1]);
    printf("%f\n",d[2]);
    printf("%f\n",d[3]);
    printf("%f\n",d[0]);
    return 0;
}

Measured memory_bytes: 3352
void main() {
  problem();
}

void problem() {
  const MAX = 1_000_000_000_000_001;
  auto N = scan!long - 1;

  string solve() {
    char[] ans;

    foreach(i; 0..1000) {
      auto mod = N % 26;
      N /= 26;
      N -= 1;

      ans ~= 'a' + cast(char)mod;
      
      if (N < 0) {
        break;
      }
    }

    return cast(string)ans.reverse();
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 2764
a,b,c,x,y=map(int,input().split())
c*=2
d=a*x+b*y
f=max(x,y)*c
if x<y:
  
  e=x*c+(y-x)*b
else:
  z=x-y
  e=y*c+(x-y)*a
print(min(d,min(e,f)))


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

int main(){
  int N; cin >> N;
  vector<int> h(N);
  for (int i=0; i<N; i++) cin >> h[i];
  int ans = 0;
  while(true){
    bool flag = true;
    for (int i=0; i<N; i++){
      if (h[i]==0) continue;
      flag = false;
      int minh = 1000;
      int lft = N;
      for (int j=i; j<N; j++){
        if (h[j]==0){
          lft = j;
          break;
        }
        minh = min(minh, h[j]);
      }
      for (int j=i; j<lft; j++){
        h[j] -= minh;
      }
      ans += minh;
      break;
    }
    if (flag) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import itertools
s = input()
K = int(input())
dp = []

def substr(x):
    table = {}
    for i, j in itertools.combinations(range(len(x) + 1), 2):
        table[x[i:j]] = 1
    return sorted(table.keys())[:5]

dp = []

if len(s) < 6:
    dp = substr(s)
else:
    dp = substr(s[-5:])
    for i in range(-6, -len(s) -1, -1):
        for j in range(1, 6):
            if not s[i : i + j] in dp:
                dp = sorted(dp + [s[i : i + j]])[:5]
print(dp[K - 1])

Measured memory_bytes: 3064
if __name__ == '__main__':
    N, K = map(int, input().split())

    sunuke = [False for _ in range(N)]
    for i in range(K):
        d = int(input())
        A = list(map(int, input().split()))
        for a in A:
            sunuke[a-1] = True

    print(sunuke.count(False))




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

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

long long MOD = 1000000000 + 7;
const int MAX = 510000;

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

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

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

int main() {
    // 前処理
    COMinit();
    int N,K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i = 0; i < N; i++){
      cin >> A.at(i);
    }
    sort(A.begin(), A.end());

    ll ans = 0;
    for(int i = 0; i < N; i++){
      if(A[i] >= 0){
        ans += COM(i, K-1) * A[i];
        ans %= MOD;
        ans += COM(N-i-1, K-1) * (MOD - A[i]);
        ans %= MOD;
      } else{
        A[i] = MOD + A[i];
        ans += COM(i, K-1) * A[i];
        ans %= MOD;
        ans += COM(N-i-1, K-1) * (MOD - A[i]);
        ans %= MOD;
      }
    }

    cout << ans << endl;
}


Measured memory_bytes: 12928