akhauriyash/Code-Regression huggingface dataset:
class MemoisdCombi
  @fac
  @finv
  @inv
  @modulo

  def initialize(max, mod)
    @modulo = mod
    @fac = Array.new(max)
    @finv = Array.new(max)
    @inv = Array.new(max)

    @fac[0] = @fac[1] = 1
    @finv[0] = @finv[1] = 1
    @inv[1] = 1
    for i in 2..max - 1
      @fac[i] = @fac[i - 1] * i % @modulo
      @inv[i] = @modulo - @inv[@modulo % i] * (@modulo / i) % @modulo
      @finv[i] = @finv[i - 1] * @inv[i] % @modulo
    end
  end

  def combination(n, k)
    return 0 if (n < k)
    return 0 if (n < 0 || k < 0)
    return @fac[n] * (@finv[k] * @finv[n - k] % @modulo) % @modulo
  end
end

# n: 部屋数 (3≤n≤2×10^5)
# k: 移動回数(2≤k≤10^9)

# res: 組み合わせ数
# 重複あり組み合わせ
# n人がn部屋にいるときの組み合わせ総数
modulo = 1000000007
max = 200001

str = gets
n, k = str.chomp.split(" ").map(&:to_i)
ary = Array.new(n)

mc = MemoisdCombi.new(max, modulo)

result = 0
roop_num = [n, k].min

(0..roop_num).each do |m|
  # m: 誰もいない部屋の数
  a = mc.combination(n, m) # nCm
  b = mc.combination(n - 1, m) # n-mHm
  result = (result + (a * b % modulo)) % modulo
end

p result


Measured memory_bytes: 10108
#include <bits/stdc++.h>
#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

typedef long long ll;

using namespace std;


//1,1,2,3, 8, 15, 48, 105   384,  945, 3840
//  1,2,6,24,120,720,5040,40320,

int main(){

    ll n;
    cin >> n;

    if(n % 2 == 1){
        cout << 0 << endl;
    }else{
        ll five_factor = 0;
        ll k = 5;

        while(k < n){
            five_factor += n / (k * 2);
            k *= 5;
        }

        cout << five_factor << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int V,E,R,S[500010],T[500010],D[500010];
int C[100000];
const int INF=10000*100000+100;
int i,t,j;

int main()
{

	for(i=0;i<100000;i++)
	{
		C[i]=INF;
	}

	scanf("%d",&V);
	scanf("%d",&E);
	scanf("%d",&R);

	C[R]=0;

	for(i=0;i<E;i++)
	{
		scanf("%d",&S[i]);
		scanf("%d",&T[i]);
		scanf("%d",&D[i]);
	}

	for(t=0;t<V;t++)
	{
		int update=-1;
		for(i=0;i<E;i++)
		{
			int s=S[i],t=T[i],d=D[i];
			if(C[s]<INF && C[t]>C[s]+d)
			{
				C[t]=C[s]+d;
				update=1;
			}
		}
		if(update==-1) break;
	}
	for(j=0;j<V;j++)
	{
		if(C[j]<INF)
			printf("%d\n",C[j]);
		else
			printf("INF\n");
	}
	return 0;
}

Measured memory_bytes: 7252
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pb push_back
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    vector < pii > s;
    int n;
    fi>>n;
    while (n --)
    {
        int x,y;
        fi>>x>>y;
        s.pb(mp(x,y));
    }
    reverse(s.begin(),s.end());
    ll ans = 0;
    ll offset = 0;
    for (auto it : s)
    {
        const ll need = it.y * ((it.y - 1 + offset + it.x) / it.y);
        ans += need - (it.x + offset);
        offset += need - (it.x + offset);
    }
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,p,q;
    cin>>n;
    std::deque<int> deq;
    for (int i=1;i<=n;i++) {
        deq.emplace_back(i);
    }
    string a="";
    for (int i=0;i<n;i++) {
        cin>>p;
        a+=to_string(p);
    }
    string b="";
    for (int i=0;i<n;i++) {
        cin>>q;
        b+=to_string(q);
    }
    if (a!=b) {
        int count=0,A,B;
        do {
            count++;
            string tmp="";
            for (int i=0;i<n;i++) {
                tmp+=to_string(deq[i]);
            }
            if (tmp==a) {
                A=count;
            } else if (tmp==b) {
                B=count;
            }
        } while (next_permutation(deq.begin(),deq.end()));
        cout<<abs(A-B)<<endl;
    } else {
        cout<<0<<endl;
    }
}

Measured memory_bytes: 3676
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new MyInputStream(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(MyInputStream cin)
        {
            var A = cin.ReadInt();
            var B = cin.ReadInt();
            var C = cin.ReadInt();
            var D = cin.ReadInt();
            var left = A + B;
            var right = C + D;
            if (left == right) WriteLine("Balanced");
            else if (left < right) WriteLine("Right");
            else WriteLine("Left");
        }
    }

    public class MyInputStream
    {
        private readonly System.IO.TextReader _stream;
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(System.IO.TextReader s, char separator = ' ')
        {
            this.separator = separator;
            this._stream = s;
            inputStream = new Queue<string>();
        }
        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
        public string ReadLine() { return _stream.ReadLine(); }
        public int ReadInt() { return int.Parse(Read()); }
        public long ReadLong() { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret;}
    }
}

Measured memory_bytes: 11348
w,h,n = map(int,raw_input().split(" "))
lines = map(lambda x : map(int,x.split(" ")),[raw_input() for var in range(n)])

x_min,x_max,y_min,y_max = 0,w,0,h
for var in lines:
    x,y,a = var
    if a == 1:
        x_min = x_min if x_min > x else x
    elif a == 2:
        x_max = x_max if x_max < x else x
    elif a == 3:
        y_min = y_min if y_min > y else y
    elif a == 4:
        y_max = y_max if y_max < y else y

print (lambda x: x if x > 0 else 0  )(x_max-x_min)*(y_max - y_min) 


Measured memory_bytes: 2568
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int a[105];
bool check(int a, int b, int c){
    if(a != b and a != c and b != c){
        if(a + b > c and a + c > b and b + c > a){
            return true;
        }
        return  false;
    }
    return false;
}
int main() {
#ifdef LOCAL
    freopen("in1.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif


    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if(check(a[i],a[j],a[k])){
                    ans++;
                }
            }
        }
    }
    cout<< ans <<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <math.h>
int main(){
  int A,B,i,rA,sum=1,c=0;
  scanf("%d %d",&A,&B);
  rA=A-1;
    
  while(B>sum){
    sum += rA;
    c++;
  }
  printf("%d",c);
} 

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
// C - Forbidden List
class Main{
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int N = sc.nextInt();

		ArrayList<Integer> lstA;

		lstA = new ArrayList<Integer>();

		for (int i=0; i < N; i++) {
			int x = sc.nextInt();
			lstA.add(x);

//			if (x==X) {
//				System.out.println(x);
//				return;
//			}
		}

		Collections.sort(lstA);

		if (N==0 || !lstA.contains(X)) {
			System.out.println(X);
			return;
		}

		int idx=1;

		while (true) {

			int minus = X - idx;
			int plus = X + idx;

			if (lstA.contains(minus) && lstA.contains(plus)) {
				idx++;
				continue;
			}

			if (!lstA.contains(minus) && !lstA.contains(minus)) {
				System.out.println(minus);
				break;
			} else if (!lstA.contains(minus)) {
				System.out.println(minus);
				break;
			} else {
				System.out.println(plus);
				break;
			}
		}


	}
}

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

#define rep(i, x, n) for(int i=(x);i<(n);i++)
#define reps(i, x, n) for(int i=(x);i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){ return (y != 0 ? gcd(y, x % y) : x); }
//最小公倍数
lol lcm(lol x, lol y){ return ((x * y) / gcd(max(x, y), min(x, y))); }

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int l[n + 5];
  rep(i, 0, n){
    cin >> l[i];
  }
  sort(l, l + n, greater<int>());
  int sum = 0;
  rep(i, 0, k){
    sum += l[i];
  }
  cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 3616
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();

    println!(
        "{}",
        s.chars()
            .fold((0u64, 0u64), |(count_b, ans), c| if c == 'B' {
                (count_b + 1, ans)
            } else {
                (count_b, ans + count_b)
            })
            .1
    );
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}



Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;


int main(){

	double d,w,h,r,min_dist,dist1,dist2,dist3;
	int n;

	while(true){
		scanf("%lf %lf %lf",&d,&w,&h);
		if(d == 0.0 && w == 0.0 && h == 0.0)break;

		scanf("%d",&n);

		for(int i=0; i < n; i++){
			scanf("%lf",&r);
			dist1 = (sqrt(d*d+w*w))/2.0;
			dist2 = (sqrt(w*w+h*h))/2.0;
			dist3 = (sqrt(d*d+h*h))/2.0;
			min_dist = min(dist1,min(dist2,dist3));
			if(r > min_dist){
				printf("OK\n");
			}else{
				printf("NA\n");
			}
		}
	}

    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n;
  cin >> n;
  V<string> s(n);
  rep(i, n) cin >> s[i];

  int ans(0);
  rep(i, n) {
    int S = s[i].length();
    rep(j, S - 1) {
      if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++;
    }
  }
  int a(0), b(0), ab(0);
  rep(i, n) {
    if (s[i].back() == 'A' && s[i][0] == 'B')
      ab++;
    else if (s[i].back() == 'A')
      a++;
    else if (s[i][0] == 'B')
      b++;
  }
  if (ab > 1) ans += ab - 1;
  if (ab > 0) {
    if (a > 0) {
      a--;
      ans++;
    }
    if (b > 0) {
      b--;
      ans++;
    }
  }
  ans += min(a, b);
  cout << ans << endl;
}


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

using namespace std;

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

    int multiple_of_4 = 0;
    int multiple_of_2 = 0;
    int other = 0;
    for (int i = 0; i < N; i++) {
        unsigned long long a;
        cin >> a;
        if (a % 4ULL == 0ULL) {
            multiple_of_4++;
        } else if (a % 2ULL == 0ULL) {
            multiple_of_2++;
        } else {
            other++;
        }
    }

    if (multiple_of_2 > 0) {
        other++;
    }
    if (multiple_of_4 >= other - 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
};


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String str1 = scan.nextLine();
		int[] str1Array = parseIntArrayFromString(str1);

		int count = str1Array[0];
		int maxJump = str1Array[1];

		String str2 = scan.nextLine();
		int[] heightArray = parseIntArrayFromString(str2);

		int[] minCostArray = new int[count];

		Arrays.fill(minCostArray, Integer.MAX_VALUE);
		minCostArray[0] = 0;

		for (int i = 1; i < count; i++) {

			int checkCount = Math.min(i, maxJump);

			for (int j = 1; j <= checkCount; j++) {

				minCostArray[i] = Math.min(
						minCostArray[i],
						minCostArray[i - j] + Math.abs(heightArray[i] - heightArray[i - j]));
			}
		}

		System.out.println(minCostArray[count - 1]);
	}

	private static int[] parseIntArrayFromString(String stringBeforeSplit) {

		String[] stringArray = stringBeforeSplit.split(" ");

		return Arrays.stream(stringArray)
				.mapToInt(Integer::parseInt)
				.toArray();
	}
}


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


int main()
{
    ll k, n = 50;
    cin >> k;
    ll p = k/n, q = k%n;
    vector<ll> a(n);
    rep(i,n) a[i] = i + p - q;
    rep(i,q) a[i] += n + 1;

    cout << n << endl;
    rep(i,n) cout << a[i] << (i!=n-1?" ":"\n") << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int l,a,b,c,d;
  int day;
  cin>>l>>a>>b>>c>>d;
  if(a%c==0&&b%d==0) day=l-max(a/c,b/d);
  else if(a%c==0&&b%d!=0) day=l-max(a/c,b/d+1);
  else if(a%c!=0&&b%d==0) day=l-max(a/c+1,b/d);
  else day=l-max(a/c+1,b/d+1);
  cout<<day<<endl;
  return 0;
}


Measured memory_bytes: 3088
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n, m;
    cin >> n >> m;

    vector<int> a(m);
    rep(i, m){
        cin >> a[i];
        --a[i];
    }

    vector<int> ans(n);
    rep(i, m){
        int cnt = n;
        rep(j, n){
            int b;
            cin >> b;
            --b;
            if(b == a[i]){
                ++ans[j];
                --cnt;
            }
        }
        ans[a[i]] += cnt;
    }

    rep(i, n){
        cout << ans[i] << endl;
    }

    cout << flush;

    return 0;
}


Measured memory_bytes: 3168
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        String[] s = new String[n];
        for(int i=0;i<s.length;i++)
        {
            s[i] = scan.next();
        }
        
        int m = scan.nextInt();
        String[] t = new String[m];
        for(int i=0;i<t.length;i++)
        {
            t[i] = scan.next();
        }
        
        int max = 0;
        for(int i=0;i<s.length;i++)
        {
            int tmp = 0;
            for(int j=0;j<s.length;j++)
            {
                if(s[i].equals(s[j]))
                {
                    tmp++;
                }
            }
            for(int j=0;j<t.length;j++)
            {
                if(s[i].equals(t[j]))
                {
                    tmp--;
                }
            }
            if(tmp>max)
            {
                max = tmp;
            }
        }
        
        System.out.println(max);
    }
}

Measured memory_bytes: 23380
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
//***********//
int main() {
	cin >> N >> K;
	vl A(N);
	for (i = 0; i < N; i++) cin >> A[i];
	vl S(N + 1);
	S[0] = 0;
	for (i = 0; i < N; i++) S[i + 1] = S[i] + A[i];
	vl P(N+1);
	for (i = 0; i < N+1; i++) P[i] = (S[i] - i) % K;
	map<ll,ll> M;
	for (j = 1; j <= N; j++) {
		//追加&削除作業
		if (j - K >= 0) {
			M[P[j - K]]--;
		}
		M[P[j - 1]]++;
		//ans追加作業
		ans += M[P[j]];
	}
	cout << ans;
}

Measured memory_bytes: 17408
#include <iostream>
#include <algorithm>
#include <vector>
 
typedef long long ll;
 
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
    ll n;
    std::cin >> n;
    std::vector<ll> a(n);
    ll min = 10000000, max = -10000000, sum = 0;
    for(auto& i : a){
        std::cin >> i;
        sum += i;
        min = std::min(min, i);
        max = std::max(max, i);
    }
    std::cout << min << " " << max << " " << sum << "\n";
    return 0;
}

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

namespace B042
{
	class Program
	{
		static void Main(string[] args)
		{
				List<int> tmp = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
			List<string> list = new List<string>();
			for (int i = 0; i < tmp[0]; i++)
				list.Add(Console.ReadLine());

			list.Sort();

			string ans = string.Empty;
			foreach (var value in list)
			{
				ans += value;
			}
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 4440
# coding=utf-8


class Dice(object):

    def __init__(self, list_):
        self.label = list_

    def getLabel(self, i):
        return self.label[i - 1]

    def _rotateS(self):
        self.label = [self.getLabel(i) for i in [5, 1, 3, 4, 6, 2]]

    def _rotateN(self):
        self.label = [self.getLabel(i) for i in [2, 6, 3, 4, 1, 5]]

    def _rotateE(self):
        self.label = [self.getLabel(i) for i in [4, 2, 1, 6, 5, 3]]

    def _rotateW(self):
        self.label = [self.getLabel(i) for i in [3, 2, 6, 1, 5, 4]]

    def _spinPos(self):
        self.label = [self.getLabel(i) for i in [1, 4, 2, 5, 3, 6]]

    def _spinNeg(self):
        self.label = [self.getLabel(i) for i in [1, 3, 5, 2, 4, 6]]

    def rotate(self, rotates):
        for r in rotates:
            if r == 'S':
                self._rotateS()
            elif r == 'N':
                self._rotateN()
            elif r == 'E':
                self._rotateE()
            elif r == 'W':
                self._rotateW()
            elif r == 'T':
                self._spinPos()
            elif r == 'B':
                self._spinNeg()

    def matchTopFront(self, top, front):
        iTop = self.label.index(top) + 1
        topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: 'SS'}
        self.rotate(topRot[iTop])

        iFront = self.label.index(front) + 1
        frontRot = {2: '', 3: 'B', 4: 'T', 5: 'TT'}
        self.rotate(frontRot[iFront])

    def copy(self):
        return Dice(self.label[:])

    def __eq__(self, other):
        if set(self.label) != set(other.label):
            return False
        for rs in ['', 'S', 'N', 'W', 'SS']:
            for r in rs:
                tmp = self.copy()
                tmp.rotate(r)
                top = tmp.getLabel(1) == other.getLabel(1)
                bottom = tmp.getLabel(6) == other.getLabel(6)
                side, n = False, 3
                while not side and n > 0:
                    if tmp.label[1:6] == other.label[1:6]:
                        side = True
                    else:
                        tmp.rotate('T')
                        n -= 1
                if top and bottom and side:
                    return True
        else:
            return False


def main():
    face1 = map(int, raw_input().split())
    face2 = map(int, raw_input().split())
    # ????????????????????????????????´?????????????????´???
    if set(face1) != set(face2):
        print 'No'
    # ???????????????????????´???
    elif len(face1) == len(set(face1)):
        d1 = Dice(face1)
        d2 = Dice(face2)
        d2.matchTopFront(d1.getLabel(1), d1.getLabel(2))
        print 'Yes' if d1.label == d2.label else 'No'
    # ???????????????????????´???
    else:
        d1 = Dice(face1)
        d2 = Dice(face2)
        print 'Yes' if d1 == d2 else 'No'

if __name__ == '__main__':
    main()

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

int main(){
	int N, M;
	cin >> N >> M;
	vector<long long> A(N);//円
	vector<long long> B(N);//本
	vector<pair<long long, long long>> pairs(N);
	long long ans = 0;//答え(円)
	int count = 0;//現在の本数

	for (int i = 0; i < N; i++) {
		cin >> A.at(i) >> B.at(i);
		pairs[i] = make_pair(A.at(i), B.at(i));
	}

	sort(pairs.begin(), pairs.end());

	for (int i = 0; i < N; i++) {
		if (count + pairs[i].second < M) {
			ans += pairs[i].second * pairs[i].first;
			count += pairs[i].second;
		}
		else {
			ans += (M - count) * pairs[i].first;
			break;
		}

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




Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;


int main(){
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if(n<=k) cout << n*x << endl;
    else cout << k*x + (n-k) * y << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque 
MOD = 10**9 +7
INF = 10**9
def main():
    n,m = map(int,input().split())
    V0 = [[] for _ in range(n)]
    V1 = [[] for _ in range(n)]
    V2 = [[] for _ in range(n)]
    for _ in range(m):
        u,v = map(int,input().split())
        u -= 1
        v -= 1
        V0[u].append(v)
        V1[u].append(v)
        V2[u].append(v)
    
    s,t = map(int,input().split())
    s -= 1
    t -= 1
    
    d0 = [-1]*n
    d1 = [-1]*n
    d2 = [-1]*n
    d0[s] = 0

    q = deque()
    q.append((s,0))
    while len(q):
        v,mod = q.popleft()
        if mod == 0:
            for e in V0[v]:
                if d1[e] == -1:
                    d1[e] = d0[v] + 1
                    q.append([e,1])

        elif mod == 1:
            for e in V1[v]:
                if d2[e] == -1:
                    d2[e] = d1[v] + 1
                    q.append([e,2])
        
        else:
            for e in V2[v]:
                if e == t:
                    print((d2[v] + 1)//3)
                    exit()           
                if d0[e] == -1:
                    d0[e] = d2[v] + 1
                    q.append([e,0])
    
    if d0[t] == -1:
        print(-1)
   
if __name__=='__main__':
    main()


Measured memory_bytes: 53796
a=input().split(' ')
n=int(a[0]);k=int(a[1]);q=int(a[2])
x=[]
for i in range(q):
    x.append(int(input()))
y=[k-q]*n
for i in x:
    y[i-1]=y[i-1]+1
for i in y:
    if i>0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 10528
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
a = LIST()
a.sort(reverse=True)
ans = a[0]
cnt = 0
idx = 1
for i in range(n - 2):
    ans += a[idx]
    cnt += 1
    if cnt == 2:
        cnt = 0
        idx += 1
print(ans)

Measured memory_bytes: 98128
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100010;
vector<int> ver[MAXN];
long long Fdp[MAXN],Sdp[MAXN],m;
int n,fa[MAXN];
 
void Fdfs(int x){
	vector<int>::iterator it;
	for(it=ver[x].begin();it!=ver[x].end();++it)
		if(*it!=fa[x]) fa[*it]=x,Fdfs(*it),Fdp[x]=Fdp[x]*(Fdp[*it]+1)%m;
	return;
}
 
void Sdfs(int x){
	int len=ver[x].size();
	long long suf[len+10],pre[len+10];
	pre[0]=1,suf[len+1]=1;
	for(int i=1;i<=len;++i)
		pre[i]=pre[i-1]*(Fdp[ver[x][i-1]]+1)%m,suf[len-i+1]=suf[len-i+2]*(Fdp[ver[x][len-i]]+1)%m;
	for(int i=0;i!=len;++i){
		if(Sdp[ver[x][i]]!=-1) continue;
		int tmp1=Fdp[x],tmp2=Fdp[ver[x][i]];
		fa[ver[x][i]]=-1,fa[x]=ver[x][i];
		Fdp[x]=pre[i]*suf[i+2]%m,Fdp[ver[x][i]]=(Fdp[x]+1)*tmp2%m;
		Sdp[ver[x][i]]=Fdp[ver[x][i]],Sdfs(ver[x][i]);
		fa[x]=-1,fa[ver[x][i]]=x;
		Fdp[x]=tmp1,Fdp[ver[x][i]]=tmp2;
	}
	return;
}
 
int main(){
	memset(Sdp,-1,sizeof(Sdp));
	cin>>n>>m;
	fill(Fdp+1,Fdp+n+1,1);
	for(int i=1,a,b;i<n;cin>>a>>b,ver[a].push_back(b),ver[b].push_back(a),++i);
	fa[1]=-1,Fdfs(1),Sdp[1]=Fdp[1],Sdfs(1);
	for(int i=1;i<=n;++i) cout<<Sdp[i]<<endl;
	return 0;
}

Measured memory_bytes: 33880
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  out(8-(a-400)/200);
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
#define MAXN 100005
using namespace std;
int n;
bool f=false;
vector<int> G[MAXN];
int fa[MAXN],deg[MAXN];
void dfs(int v,int p)
{
	fa[v]=p;
	for(int i=0;i<G[v].size();i++)
	{
		if(G[v][i]==p) continue;
		dfs(G[v][i],v);
	}
	return;
}
int find_ans(int v)
{
	int cnt=0,res=0;
	for(int i=0;i<G[v].size();i++)
	{
		if(G[v][i]==fa[v]) continue;
		int val=find_ans(G[v][i]);
		if(val==0) cnt++;
		res+=val;
	}
	if(cnt>0) return res+cnt-1; else return res;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
		deg[x]++;deg[y]++;
	}
	bool f=false;
	int ans;
	for(int i=0;i<n;i++)
	{
		if(deg[i]>=3)
		{
			f=true;
			dfs(i,-1);
			ans=find_ans(i);
			break;
		}
	}
	if(!f)
	{
		printf("1\n");
		return 0;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9856
n, k = map(int, input().split())
a = list(map(int, input().split()))
if k >= sum(a)-n:
	print(1)
else:
	ok, ng = 10**9, 1
	while ok-ng > 1:
		mid = (ok+ng)//2
		if sum((x-1)//mid for x in a) <= k:
			ok = mid
		else:
			ng = mid
	print(ok)

Measured memory_bytes: 93900
#include<stdio.h>

int main(){
  int n;
  long long int k=0;
  scanf("%d",&n);
  
  for(int i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0){
      k+=i;
    }
  }
  printf("%lld",k);
  return 0;
}
      
  

Measured memory_bytes: 1692
until(n,m=gets.split.map(&:to_i))==[0,0]do
r,p,a=[],[],[]
n.times{r.unshift(gets.gsub("?",".").split)}
m.times{p<<gets.split}
p.each{|p|r.each{|r|if p[0]=~/#{r[1]}/&&p[1]=~/#{r[2]}/
a<<p*" "if r[0]=~/p/
break
end}}
puts a.size,a
end

Measured memory_bytes: 9452
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
ll K;
int P[5000];
ll C[5000];

signed main(){
    cin >> N >> K;
    rep(i, N){
        cin >> P[i];
        P[i]--;
    }
    rep(i, N) cin >> C[i];

    ll ans = LLONG_MIN;
    rep(i, N){
        int k = i;
        ll sum = 0;
        vector<ll> tmp;
        do{
            k = P[k];
            sum += C[k];
            tmp.pb(sum);
        } while(k != i);

        rep(j, min(K, (ll)tmp.size())){
            ans = max(ans, tmp[j]);
            ans = max(ans, (K-1-j)/(ll)tmp.size()*sum + tmp[j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}

#define NUM_MAX 52
#define BUF_SIZE (NUM_MAX+10)
#define DIVISOR 1000000007

enum type {
    TYPE_EMPTY,
    TYPE_VERTICAL,
    TYPE_HORIZONTAL,
};

int main(void) {
    int num = get_int();
    static char str[2][NUM_MAX];
    get_str(str[0], num);
    get_str(str[1], num);

    int i;
    int64_t res = 1;
    int prev = TYPE_EMPTY;
    int cur;
    for(i = 0; i < num; i++) {
        // set domino vertically
        if(str[0][i] == str[1][i]) {
            cur = TYPE_VERTICAL;
            if(prev == TYPE_EMPTY) {
                res = (res * 3)%DIVISOR;
            } else if(cur == prev) {
                res = (res * 2)%DIVISOR;
            }
        // set domino horizontally
        } else {
            cur = TYPE_HORIZONTAL;
            if(prev == TYPE_EMPTY) {
                res = (res * 6)%DIVISOR;
            } else if (prev == TYPE_VERTICAL) {
                res = (res * 2)%DIVISOR;
            } else {
                res = (res * 3)%DIVISOR;
            }
            // skip
            i++;
        }
#ifdef DEBUG
        printf("%d[cur: %d]: %lld\n", i, cur, res);
#endif
        prev = cur;
    }
    printf("%d\n", (int)res);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0;
    if (a[0] != 0) {
        puts("-1");
        return 0;
    }

    srep(i, 1, n) {
        // cout << "i = " << i << " a[i] = " << a[i] << endl;
        if (a[i] - a[i-1] > 1) {
            puts("-1");
            return 0;
        }
        if (a[i] == a[i-1]+1) ans++;
        else ans += a[i];
    }

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

Measured memory_bytes: 1920
#include <stdio.h>
#define max(a,b) (a>b?a:b)
int main(){
	int n,ans=0;
	scanf("%d",&n);
	int s[n];
	for(int i=0;i<n;i++){
		scanf("%d",&s[i]);
	}

	static int dp[101][10010];

	for(int i=0;i<101;i++)
		for(int j=0;j<10010;j++){
			dp[i][j]=0;
		}

	dp[0][0]=1;
	dp[0][s[0]]=1;
	for(int i=1;i<n;i++)
		for(int j=0;j<10000;j++){
			if(j>=s[i])dp[i][j]=max(dp[i-1][j],dp[i-1][j-s[i]]);
			if(j<s[i]) dp[i][j]=dp[i-1][j];
		}
	/*for(int i=1;i<=n;i++){
		for(int j=0;j<101;j++){
			printf("%d\t",dp[i][j]);
		}
		printf("\n");

	}
*/
	for(int i =10000;i>0;i--){
		if(dp[n-1][i]!=0 && i%10!=0){
			ans=i;
			break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    
  int A,B,C,D;
  cin >> A >> B >> C >>D;
  
  if((A+B)>(C+D)){
   
      cout<< "Left" <<endl;
      
  }
  else if((A+B)<(C+D)){
   
      cout<< "Right" <<endl;
      
  }
  else{
    
      cout <<"Balanced" << endl;
      
  }
    
  
}


Measured memory_bytes: 256
<?php

//N M
list($n,$m) = explode(' ', trim(fgets(STDIN)));


//k s...s
for($i=1; $i<=$m; $i++){
  $t = explode(' ', trim(fgets(STDIN)));
  for($j=1;$j<=$t[0]; $j++){
    $l[$i][$j] = $t[$j];
  }
}


//p...p
$p = explode(' ', trim(fgets(STDIN)));
array_unshift($p,"");


//bit全検索 電球の状態の数だけループ
$ans = 0;
for($i=0; $i<2**$n; $i++){
  
  //電球の状態 (ex.00 01 10 11)
  $ls = str_pad(decbin($i), $n, 0, STR_PAD_LEFT);
  
  //それぞれの電球の状態で電球の数だけループ
  $c = 0;
  for($j=1; $j<=$m; $j++){
    
    //電球に繋がったスイッチの数だけループ
    $on = 0;
    foreach($l[$j] as $s){
      //繋がったスイッチがオンになっている場合にカウント
      if ($ls[$s-1] == 1) $on++;
    }
    //オンのスイッチの総数を２で割った余りが 対応するpと一致する電球の数をカウント
    if ($on%2==$p[$j]) $c++;    
  }
  //余りがpと一致した電球の数が 電球の総数と一致したらカウント
  if ($c == $m) $ans++;
  
}

echo $ans;


  
?>

Measured memory_bytes: 4604
N,M = map(int,input().split())

mod = 10**9 + 7
def kaijou(N):
	x = 1
	for i in range(N):
		x*=i+1
		x%=mod
	return x

kn = kaijou(N)
km = kaijou(M)
if abs(N-M) >=2:
	ans = 0

else:
	if abs(N-M) == 0:
		
		ans = kn*kn*2 % mod

	if abs(N-M) == 1:

		ans = kn * km % mod

print(ans)

Measured memory_bytes: 3064
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define Debug printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define debug(x) cerr<<#x<<'='<<x<<endl
#define mem(x,val) memset(x,val,sizeof x)
namespace mine
{
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
    template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
    bool IN(ll x,ll l,ll r){return l<=x and x<=r;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    int a[N];
    void main()
	{
        char c=getchar();putchar(c+1);
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 256
import numpy as np
N =int(input())
AB = []
for i in range(N):
    a,b = map(np.int64,input().split())
    AB.append((b,a))

AB.sort()
time = np.int64(0)

for b,a in AB:
    if time +a >b:
        print("No")
        exit()
    time +=a
    
print("Yes")
        

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

int main(){
  int N, W, H;
  cin >> N >> W >> H;
  vector<int> X(W+1,0), Y(H+1,0);
  for(int i = 0; i < N; ++i){
    int x, y, w;
    cin >> x >> y >> w;
    ++X[max(0,x-w)];
    --X[min(W,x+w)];
    ++Y[max(0,y-w)];
    --Y[min(H,y+w)];
  }
  for(int i = 1; i < W; ++i) X[i] += X[i-1];
  for(int i = 1; i < H; ++i) Y[i] += Y[i-1];
  bool x = true, y = true;
  for(int i = 0; i < W; ++i){
    if(not X[i]){
      x = false;
      break;
    }
  }
  for(int i = 0; i < H; ++i){
    if(not Y[i]){
      y = false;
      break;
    }
  }
  if(x or y) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int n,K;
char s[10100];
char ans[10100];
int cmp(int a,int b)
{
    int l=0;
    for(;l<n&&s[a+l]==s[b+l];++l);
    return s[a+l]<s[b+l]?a:b;
}
int main()
{
    scanf("%d%d",&n,&K);
    scanf("%s",s+1);
    for(int i=n+1;i<=n*2;++i)s[i]=s[n*2+1-i];
    int mp=1;
    for(int i=2;i<=n;++i)mp=cmp(mp,i);
//    cout<<"mp: "<<mp<<endl;
    char mc=s[mp];
    if(K==1)
    {
        for(int i=mp;i<=mp+n-1;++i)putchar(s[i]);puts("");
        return 0;
    }

    int cm=0;
    while(s[mp+cm]==mc)cm++;
    mp=n*2-mp+1;
    for(int i=1;i<=n;++i)ans[n-i+1]=s[mp-i+1];
//    for(int j=1;j<=n;++j)putchar(ans[j]);puts("");
    K-=2;
    while(K--)
    {
        cm*=2;
        if(cm>=n)
        {
            for(int i=1;i<=n;++i)putchar(mc);puts("");
            return 0;
        }
        mp=n-cm;
        for(int i=1;i<=mp;++i)ans[i]=ans[i+cm/2];
        for(int i=mp+1;i<=n;++i)ans[i]=mc;
//        for(int j=1;j<=n;++j)putchar(ans[j]);puts("");
    }
    cm*=2;
    if(cm>=n)
    {
        for(int i=1;i<=n;++i)putchar(mc);puts("");
        return 0;
    }
    for(int i=n+1;i<=n*2;++i)ans[i]=ans[n*2+1-i];
//    for(int i=1;i<=n*2;++i)putchar(ans[i]);puts("");
//    cout<<"cm: "<<cm<<endl;
    mp=n-cm/2;
    for(int i=1;i<=n;++i)putchar(ans[i+mp]);puts("");
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
step = [1]*(N+1)
for _ in range(M):
	A = int(input())
	step[A] = 0

for i in range(2,N+1):
	if step[i] == 0:
		continue
	step[i] = (step[i-1] + step[i-2])%(10**9+7)

print(step[-1]%(10**9+7))

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

int main() {
	// your code goes here
	int p,q,r;
	cin>>p>>q>>r;
	if(p<=q && q<=r){
		cout<<p<<" "<<q<<" "<<r<<endl;
	}
	else if(p<=r && r<=q){
		cout<<p<<" "<<r<<" "<<q<<endl;
	}
	else if(q<=p && p<=r){
		cout<<q<<" "<<p<<" "<<r<<endl;
	}
    else if(q<=r && r<=p){
		cout<<q<<" "<<r<<" "<<p<<endl;
	}
	else if(r<=p && p<=q){
		cout<<r<<" "<<p<<" "<<q<<endl;
	}
	else if(r<=q && q<=p){
		cout<<r<<" "<<q<<" "<<p<<endl;
	}
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  char n[4]; for (int i = 0; i < 4; i++) cin >> n[i];
  bool lol = true;
  for (int i = 0; i < 3; i++)
  {
    if (n[i] == n[i+1])
    {
      cout << "Bad" << endl;
      lol = false;
      break;
    }
  }
  if (lol == true) cout << "Good" << endl;
  return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

int N,X,D;

signed main(){
	cin>>N>>X>>D;
	if(D==0){
		if(X==0){
			cout<<1<<endl;
		}
		else{
			cout<<N+1<<endl;
		}
		return 0;
	}
	if(D<0){
		D*=-1;
		X*=-1;
	}

	map<int,vpint>bucket;
	for(int i=0;i<=N;i++){
		int l=i*(i-1)/2;
		int r=i*(N-1+N-1-i+1)/2;

		int con=X*i;
		int rem=(con%D+D)%D;
		int quo=(con-rem)/D;
		l+=quo;
		r+=quo;
		r++;
		bucket[rem].eb(l,r);
	}

	int ans=0;
	for(auto &p:bucket){
		vpint v=p.se;
		sort(all(v));
		vpint u;
		for(auto &q:v){
			if(u.size()==0||u.back().se<q.fi)u.pb(q);
			else chmax(u.back().se,q.se);
		}
		for(auto &q:u)ans+=q.se-q.fi;
	}	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 22144
S = input()
n = len(S)
n = n - 2 if n % 2 == 0 else n - 1
ans = -1
for i in range(n - 1, -1, -2):
    T = S[: i + 1]
    l = (i + 1) // 2
    if T[: l] == T[l:]:
        ans = i + 1
        break
print(ans)

Measured memory_bytes: 8992
N = int(input())
S = input()
a = [0 for i in range(N)]
for i in S[1:]:
    if i == "E":
        a[0] += 1
for i,s in enumerate(S[:-1]):
    if S[i] == "E" and S[i+1] == "E":
        a[i+1] = a[i] - 1
    if S[i] == "E" and S[i+1] == "W":
        a[i+1] = a[i]
    if S[i] == "W" and S[i+1] == "E":
        a[i+1] = a[i]
    if S[i] == "W" and S[i+1] == "W":
        a[i+1] = a[i] + 1

print(min(a))



Measured memory_bytes: 15500