akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
import math
import itertools


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# これだと、O(n*n)
"""
temp_ans = []


def problem_a(input_string):
    S = int(input_string[0].rstrip())
    N = input_string[1].rstrip()
    N_l = len(N)
    global temp_ans
    for i in range(N_l)[::-1]:
        temp_ans += N[i]
        #print(temp_ans)
        for s in temp_ans:
            #print(s)
            if N[i] not in s:
                temp_ans.append(N[i]+s)
    #print(temp_ans)
    return len(temp_ans) % (10**9 + 7)
"""


def problem_a(input_string):
    S = int(input_string[0].rstrip())
    N = input_string[1].rstrip()
    #print(S)
    dic = {}
    c = 0
    for i in range(S)[::-1]:
        if N[i] not in dic:
            dic[N[i]] = 1
            #c += i+1
        else:
            dic[N[i]] += 1

    c = 1
    for key, value in dic.items():
        c *= (value+1)
    c -= 1
    """
    c += 2**len(dic.keys())-1
    #print(c)
    #c += S
    for key, value in dic.items():
        if value > 1:
            #c -= (value-1)
            c += 2**(len(dic.keys()))-1
            #print(c)
    #for key, value in dic.items():
    for key, value in dic.items():
        if value > 1:
            if len(dic.keys()) != S:
                c -= 2**(S-len(dic.keys())-1)
    """
            #print(c)
        #else:
    #c += (S-len(dic.keys()))
    """
    s_N = sorted(N)
    for i in range(S-1):
        if s_N[i] != s_N[i+1]:
            c += 2**(i+2)
    """
    """
    for key, value in dic.items():
        if value > 1:
            c += 2**(len(dic.items())-value)
        else:
            c += 2**(len(dic.items())-value)
    """
    #combinations_count(len(, r)

    return c % (10**9 + 7)


def main():
    input_line = stdin.readlines()
    answer = problem_a(input_line)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
# N個、重さW
N, W = map(int, input().split())

# 重さ, 価値
array = [list(map(int, input().split())) for _ in range(N)]

# 価値の最大値
sum = 1
for i in range(N):
    sum += array[i][1]

weights = [[float('inf')] * (sum + 1) for _ in range(N + 1)]
# 初期値
weights[0][0] = 0
# 価値ごとの重さの最小値を出す
for n in range(N):
    # 価値が0..1000までのそれぞれについて、価値を超えているうちの重さの最小値を算出する
    for v in range(sum + 1):
        # n回目の品物を持ち帰らない場合の重量
        weights[n + 1][v] = weights[n][v]
        weight = weights[n][v - array[n][1]] + array[n][0]
        if weight < weights[n + 1][v]:
            weights[n + 1][v] = weight

ans = 0
for i in range(sum):
    if weights[N][i] <= W:
        ans = i
print(f"{ans}")


Measured memory_bytes: 235540
#include <iostream>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  if(n%2==1) {
    cout << "No" << endl;
    return 0;
  }
  for(int i=0; i<n/2; i++) {
    if(s[i]!=s[i+n/2]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;

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

	cin >> N >> M >> K;
	vector<long long int>v(N + 1);
	for (int i = 1; i <= N; i++)cin >> v[i];
	vector<long long int>dp(N + 1);
	for (int i = 1; i <= K; i++) {
		deque<int>Q;
		for (int j = N - 1; j >= N - M; j--) {
			if (Q.empty())Q.push_back(j);
			else {
				while (!Q.empty() && dp[Q.back()] <= dp[j])Q.pop_back();
				Q.push_back(j);
			}
		}
		for (int j = N; j>=i; j--) {
			if (Q.front() == j)Q.pop_front();
			dp[j] = dp[Q.front()] + v[j] * i;
			if (j - M - 1 >= 0) {
				while (!Q.empty() && dp[Q.back()] <= dp[j - M - 1])Q.pop_back();
				Q.push_back(j - M - 1);
			}
		}
		//for (int j = 1; j <= N; j++)cout << i << " " << j << " " << dp[j] << endl;
	}
	cout << *max_element(dp.begin(), dp.end()) << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int x;
    cin >> x;
    cout << (2199 - x) / 200 << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int N, A;
long long DP[51][51][2501]; 
//DP[i][j][k] : i번째 카드 전까진 고려했으며 j개의 카드를 골랐고 고른 카드의 합이 k일때 남은 카드를 골라 A를 만드는 경우의수
vector<int> vec;

long long solve(int ind,int picked, int sum) {
	if (ind == N) {
		if (picked == 0) return 0;
		else if (sum == A * picked) return 1;
		else return 0;
	}
	if (DP[ind][picked][sum] != -1) return DP[ind][picked][sum];
	long long ret = 0;
	ret += solve(ind + 1, picked, sum);
	ret += solve(ind + 1, picked + 1, sum + vec[ind]);
	return DP[ind][picked][sum] = ret;
}

int main() {
	memset(DP, -1, sizeof(DP));
	cin >> N >> A;
	for (int i = 0; i < N; i++) {
		int temp;
		cin >> temp;
		vec.push_back(temp);
	}
	cout << solve(0, 0, 0) << "\n";
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    deque<int> b;
    rep(i,n){
        int tmp;cin>>tmp;
        if(i%2==0)b.push_front(tmp);
        else b.push_back(tmp);
    }
    if(n%2!=0)for(int i=0;i<n;i++)cout<<b[i]<<' ';
    else for(int i=n-1;i>=0;i--)cout<<b[i]<<' ';
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    double a,b,x;
    cin >> a >> b >> x;
    if((2.0 * x) / (a * b) <= a){
        printf("%.10lf\n", 90.0 - atan((2.0 * x) / (a * b * b)) * 180.0 / M_PI);
    }else{
        printf("%.10lf\n", atan((2.0 * b - (2.0 * x) / (a * a)) / a) * 180.0 / M_PI);
    }
    return 0;
}

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

int main()
{
	int N, K;
	cin >> N >> K ;
	vector<int> vec(N) ;
	
	int d = 0;
	int A = 0;
	
	for( int i=0; i<K; ++i)
	{
		cin >> d ;
		for( int j = 0; j<d; ++j)
		{
			cin >> A ;
			vec.at(A-1) = 1 ;
		}
	}
	
	int count = 0;
	for(int i = 0; i<N; ++i)
	{
		if(vec.at(i)==0)
			++count ;
	}
	
	cout << count <<endl ;
	
}	


Measured memory_bytes: 3628
N,K = map(int, input().split())
A = list(map(int, input().split()))

move = 1
l = [1]
flag = [False]*(N+1)
flag[1] = True

for i in range(K):
    move = A[move-1]
    if flag[move]:
        # ind = l.index(move)
        # l = l[ind:]
        break
    flag[move] = True
    l.append(move)

# print("ind:{}".format(ind))
# print("l:{}".format(l))
ind = l.index(move)
# l = l[ind:]
rest = (K-ind) % (len(l) - ind) + ind

# print(rest)
print(l[rest])


Measured memory_bytes: 32368
import itertools

n,k=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x:(x+1)/2,a))

a=[0]+list(itertools.accumulate(a))
ans=0

for i in range(n-k+1):
  ans=max(ans,a[i+k]-a[i])
  
print(ans)

Measured memory_bytes: 115724
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
#define a_macro(args...) sum(args)
#define mp make_pair
#define eb emplace_back
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

typedef long long ll;
const ll mod = 1e9+7;


int main(int argc, const char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,x,i,j,k;
    cin>>n>>m>>x;
    vector<int> C(n);
    vector<vector<int>> a(n,vector<int> (m));
    for(i=0;i<n;++i){
    	cin>>C[i];
    	for(j=0;j<m;++j)
    		cin>>a[i][j];
    }
    for(j=0;j<m;++j){
    	int sum = 0;
    	for(i=0;i<n;++i)
    		sum += a[i][j];
    	if(sum < x){
    		cout<<"-1\n";
    		return 0;
    	}
    }
    int ans = INT_MAX;
    for(i=0;i<(1<<n);++i){
    	int sum = 0;
    	vector<int> temp(n);
    	for(j=0;j<n;++j){
    		if((1<<j) & i){
    			sum += C[j];
    			for(k=0;k<m;++k)
    			temp[k] += a[j][k];
    		}
    	}
    	for(k=0;k<m;++k)
    		if(temp[k] < x)
    			break;
    	if(k == m)
    		ans = min(ans,sum);
    }
    cout<<ans<<"\n";
    
#ifndef LOCAL_DEFINE
    cerr << "Time elapsed: "<< 1e1 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif // LOCAL_DEFINE
    return 0;
}

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

using namespace std;

typedef long long ll;


bool field[20][20];
int cnt;

int dx[] = {1,0};
int dy[] = {0,1};
int h,w;

void dfs(int x,int y){
	for(int i = 0; i < 2; i++){
		int px = x + dx[i];
		int py = y + dy[i];
		if(px >= 0 && px < w && py >= 0 && py < h){
			if(py == h-1 && px == w - 1){
				cnt++;
				return;
			}
			if(field[py][px] == true){
				dfs(px,py);
			}
		}
	}
}


int main(){

	int n;

	while(cin >> w >> h && !(w == 0 && h == 0)){
		for(int i = 0; i < 20; i++)
			fill(field[i],field[i]+20,true);
		cin >> n;
		cnt =0;
		for(int i = 0; i < n; i++){
			int xx,yy;
			cin >> xx >> yy;
			xx--;
			yy--;
			field[yy][xx] = false;
		}
		dfs(0,0);
		cout << cnt << endl;
	}


	return 0;
}

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

int main(){
  int N;
  string S;
  int p=0,w=0,y=0,g=0;
  
  cin >> N;
  
  for(int i=0; i < N;i++){
    cin >> S;
    if(S=="P"){
      p=1;
    }else if(S=="W"){
      w=1;
    }else if(S=="Y"){
      y=1;
    }else if(S=="G"){
      g=1;
    }
  }
 
  if(p+w+y+g == 3){
	cout << "Three" << endl;
  }else{
    cout << "Four" << endl;
  }
}

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


int main() {
    int x,y;
    cin >> x >> y;
    cout << x+y/2 << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int N,A,B,C,m,n,a,b,c,x,y,z,i,j,k;
int main()
{
	cin>>m>>n;
	A=1;
	for(i=1;A<n;i++)
	{
		A+=(m-1);
	}
	cout<<i-1;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  if(a < b && b < c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3184
#include<stdio.h>
int main()
{
	int A,B,C;
	int sum=0;
	scanf("%d%d%d",&A,&B,&C);
	sum=A+B+C;
	if(sum==17)
	printf("YES\n");
	else
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int min(int a,int b){
    if(a>b){
        return b;
    }
    else{
        return a;
    }
}

int main(void){
    int N,M,X;
    scanf("%d %d %d",&N,&M,&X);
    int i,a[M];
    for(i=0;i<M;i++){
        scanf("%d",&a[i]);
    }
    int counter = 0;
    for(i=0;i<M;i++){
        if(a[i]<X){
            counter ++;
        }
        else{
            break;
        }

    }
    int val = min(counter,M-counter);
    printf("%d\n",val);
    
    return 0;
}

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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e16;
const int MOD = 1000000007;

using namespace std;

ll gcd(ll a, ll b) {
    while (a > 0) {
        ll t = a;
        a = b % a;
        b = t;
    }
    return b;
}

int main() {
    ios::sync_with_stdio(false);

    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll lcm = C / gcd(C, D) * D;

    cout << B - (B/C + B/D - B/lcm) - ((A-1) - ((A-1)/C + (A-1)/D - (A-1)/lcm) ) << endl;

    return 0;
}


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

int main()
{
	string n;
  	cin >> n;
  	int flag = 0;
  	if(n.size() < 3)
    {
      flag = 0;
    }
  	else
      for(int i = 0; i < n.size() - 2; ++i)
    {
      	if(n[i] == n[i+1] && n[i] == n[i+2])
        {
          flag = 1;
          break;
        }
    }
  
  if(flag )
    cout <<"Yes\n";
  else
    cout << "No\n";
}

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

using namespace std;

int n;
long long sol, tmp;

int st[100001], dr[100001];

int main() {
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> st[i] >> dr[i];
    st[i] *= 2;
    dr[i] *= -2;
  }
  sort(st + 1, st + n + 1);
  sort(dr + 1, dr + n + 1);
  reverse(st + 1, st + n + 1);
  reverse(dr + 1, dr + n + 1);
  for(int i = 1; i <= n; i++) {
    sol = max(sol, tmp + st[i]);
    sol = max(sol, tmp + dr[i]);
    sol = max(sol, tmp + st[i] + dr[i]);
    tmp += st[i] + dr[i];
  }
  cout << sol;
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sorting_Three_Numbers
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            List<int> nums = new List<int>();

            for (int i = 0; i < input.Length; i++)
            {
                nums.Add(int.Parse(input[i]));
            }

            nums.Sort();
            Console.WriteLine(nums[0]+ " " + nums[1]+ " "+nums[2]);
        }
    }
}



Measured memory_bytes: 18016
#include<stdio.h>
#include<queue>
using namespace std;
int h[1000001];
int main(){
	h[1]=1;
	for(int i=2;i<=1000000;i*=2)h[i]=1;
	for(int i=1;i<=1000000;i++){
		if(h[i]){
			for(int j=i*3;j<=1000000;j*=3)if(h[j]==0)h[j]=2;
		}
	}
	for(int i=1;i<=1000000;i++){
		if(h[i]){
			for(int j=i*5;j<=1000000;j*=5)if(h[j]==0)h[j]=3;
		}
	}
	int a,b;
	while(scanf("%d",&a),a){
		scanf("%d",&b);
		int ret=0;
		for(int i=a;i<=b;i++)if(h[i])ret++;
		printf("%d\n",ret);
	}
}

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

int main() {
  int N,M,i,A,B;
  ll c=0;
  cin >> N >> M;
  vector<pair<ll,int>> D(N);
  
  for(i=0; i<N; i++) {
    cin >> A >> B;
    D.at(i).first = A;
    D.at(i).second = B;
  }
  sort(D.begin(), D.end());
  
  for(i=0; i<N; i++) {
    if(M>=D.at(i).second) {
      c+= D.at(i).first * D.at(i).second;
      M-=D.at(i).second;
    }
    else {
      c+= D.at(i).first * M;
      break;
    }
  }
  
  cout << c << endl;
}

Measured memory_bytes: 1792
/*
ALDS1_3_B
*/

#include <iostream>

using namespace std;

static const int NMAX = 100000;


typedef struct proc {
    char name[10];
    int time;
} proc;

proc Q[NMAX];
int head = 0;
int tail = 0;

void enqueue(proc x) {
    Q[tail] = x;
    tail = (tail+1) % NMAX;
}

proc dequeue() {
    proc x = Q[head];
    head = (head+1) % NMAX;
    return x;
}

int main() {
    int n, q, t;
    proc p;

    cin >> n >> q;
    t = q;

    for(int i = 0; i < n; i++) {
        cin >> p.name >> p.time;
        enqueue(p);
    }

    //cout << "-----" << endl;//

    while(head != tail) {

        p = dequeue();
        p.time -= q;

        //cout << p.name << " " << p.time << endl;//

        if(p.time > 0) {
            enqueue(p);
            t += q;
        }
        else {
            int tmp = p.time;
            p.time += t;
            cout << p.name << " " << p.time << endl;
            t += (q+tmp);
        }

        //cout << t << endl;//
    }
    
    return 0;

}


Measured memory_bytes: 4628
package main

import (
	"bufio"
	"fmt"
	"math"
	"math/rand"
	"os"
	"time"
)

var D int
var cs []int
var ss [][]int

func main() {
	D = ReadInt()
	cs = ReadInts(26)
	ss = make([][]int, D)
	for i := 0; i < D; i++ {
		ss[i] = ReadInts(26)
	}

	// naives
	answers := []int{}
	last := make([]int, 26)
	for d := 1; d <= D; d++ {
		maxT, maxScore := -1, math.MinInt32
		for i := 0; i < 26; i++ {
			s := ss[d-1][i] - cs[i]*(d-last[i])
			if s > maxScore {
				maxT, maxScore = i, s
			}
		}
		last[maxT] = d
		answers = append(answers, maxT+1)
	}

	rand.Seed(123456777)

	score := scores(answers)
	bestAnswers, bestScore := Dup(answers), score

	start := time.Now()
	timeout := 1950 * time.Millisecond

	for {
		elapsed := time.Now().Sub(start)
		if elapsed >= timeout {
			break
		}

		d, q := rand.Intn(D)+1, rand.Intn(26)+1
		orig := answers[d-1]
		answers[d-1] = q
		score := scores(answers)

		best := false
		if score > bestScore {
			best = true
			bestAnswers, bestScore = Dup(answers), score
		}

		if elapsed < time.Second {
			// 最初はベストのときだけ更新する
			if best {
				// none
			} else {
				answers[d-1] = orig // revert
			}
		} else {
			answers[d-1] = orig // revert
		}
	}

	for _, v := range bestAnswers {
		fmt.Println(v)
	}
}

func Dup(xs []int) []int {
	return append([]int{}, xs...)
}

func scores(answers []int) int {
	last := make([]int, 26)
	score := 0
	for d := 1; d <= D; d++ {
		t := answers[d-1] - 1
		score += ss[d-1][t]
		last[t] = d
		for i := 0; i < 26; i++ {
			score -= cs[i] * (d - last[i])
		}
	}
	return score
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll mod = 1000000007;

int inv(int n){
	if(n == 1)return 1;
	return (mod - mod/n)*1LL*inv(mod%n)%mod;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int x, y;
	cin>>x>>y;
	if((x + y)%3){
		cout<<0<<endl;
		exit(0);
	}
	int a = x - (x + y)/3;
	int b = y - (x + y)/3;
	if(a < 0 || b < 0){
		cout<<0<<endl;
		exit(0);
	}
	ll num = 1, den = 1;
	for(int i = 1; i <= a; i++){
		(num *= (b + i)) %= mod;
		(den *= i) %= mod;
	}
	ll ans = num*inv(den)%mod;
	cout<<ans<<endl;

	return 0;
}

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

#define endl '\n'
using namespace std;
using ll = long long;

const int N = 102, K = 100005;

int n, k;
ll arr[N];
bool dp[K];  // dp[i] = true : First hand will win if there are i stones initially

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin  >> arr[i];
}

void process()
{
    dp[0] = false;
    for(int i = 1; i <= k; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(i >= arr[j])
            {
                dp[i] |= !dp[i-arr[j]];
            }
        }
    }
    if(dp[k] == true) cout << "First" << endl;
    else cout << "Second" << endl;
}



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

using namespace std;

long long int dp[3005][3005];
int points[3000];
long long int pre[30001];

long long int solve(int i, int j){

    if(i == j - 1)
        return max(points[i], points[j]);

    if(dp[i][j] != -1)
        return dp[i][j];

    dp[i][j] = max(points[i] + pre[j] - pre[i] - solve(i+1, j), points[j] + pre[j-1] - pre[i-1] - solve(i, j-1));

    return dp[i][j];

}

int main(){

    int N;
    cin >> N;

    for(int i = 0; i < 3001; i++)
        for (int j = 0; j < 3001; j++)
            dp[i][j] = -1;

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

        cin >> points[i];
        pre[i] = pre[i-1] + points[i];
    }

    solve(1, N);

    cout << 2*dp[1][N] - pre[N] << endl;
    return 0;
}


Measured memory_bytes: 70912
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 28 21:42:33 2016

@author: you
"""

n = list(map(int, input().split()))
l = n[0] * 100 + n[1] * 10 + n[2]
m = l % 4
if m == 0:
    ans = "YES"
else:
    ans = "NO"
print(ans)    


Measured memory_bytes: 3060
n, m = map(int, input().split())
ab_array = [[int(x) for x in input().split()] for y in range(m)]
graph = [[] for x in range(n + 1)]


def dfs(graph, now, a, b):
    visited[now] = True
    for next in graph[now]:
        if (now == a and next == b) or (now == b and next == a):
            continue
        if not visited[next]:
            dfs(graph, next, a, b)
    return visited.count(False) == 1


for a, b in ab_array:
    graph[a].append(b)
    graph[b].append(a)
ans = 0
for a, b in ab_array:
    start = a
    end = b
    visited = [False for x in range(n + 1)]
    now = 1
    next_array = [now]
    while len(next_array) != 0:
        visited[now] = True
        for next in graph[now]:
            if (now == a and next == b) or (now == b and next == a):
                continue
            if not visited[next]:
                next_array.append(next)
        now = next_array.pop()
    if visited.count(False) == 1:
        ans += 1

    # if dfs(graph, 1, a, b):
    #     ans += 1
print(m - ans)


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



int main() 
{
  ll N; cin>>N;
  ll sum=1;
  vector<ll> A(N);
  rep(i,N)
  {
    cin>>A.at(i);
    if(A.at(i)==0) {cout<<0<<endl; return 0;}
  }
  rep(i,N)
  {
    if(sum>1000000000000000000/A.at(i)+1) {cout<<-1<<endl; return 0;}
    sum*=A.at(i);
    if(sum>1000000000000000000) {cout<<-1<<endl; return 0;}
  }  
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 4048
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String str = sc.next();
		int[] right = new int[N];
		int[] left = new int[N];
		for (int i = 0; i < N; ++i) {
			right[i] = (i > 0 ? right[i - 1] : 0) + (str.charAt(i) == 'W' ? 1 : 0);
		}
		for (int i = N - 1; i >= 0; --i) {
			left[i] = (i + 1 < N ? left[i + 1] : 0) + (str.charAt(i) == 'E' ? 1 : 0);
		}
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < N; ++i) {
			ans = Math.min(ans, right[i] + left[i] - 1);
		}
		System.out.println(ans);
	}

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

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 32848
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int N, M;
    cin >> N >> M;
    int A[N], B[N];
    REP(i, N) cin >> A[i] >> B[i];

    map<int, priority_queue<int>> m;
    REP(i, N) {
        if (A[i] <= M)
            m[A[i]].push(B[i]);
    }
    ll reward = 0;
    int recvJobs = 0;
    priority_queue<int> possible;
    int prev = 0;
    for (auto itr = m.begin(); itr != m.end(); ++itr) {
        int a = itr->first;
        priority_queue<int> q = itr->second;
        // prev ~ a - 1
        FOR(i, prev, a - 1) {
            if (possible.size() > 0) {
                reward += possible.top();
                possible.pop();
                recvJobs++;
            }
            if (recvJobs == N) break;
        }
        // update possible queue
        while (q.size() > 0) {
            possible.push(q.top());
            q.pop();
        }
        // a
        if (possible.size() > 0) {
            reward += possible.top();
            possible.pop();
            recvJobs++;
        }
        prev = a;
        if (recvJobs == N) break;
    }
    FOR(i, prev, M) {
        if (possible.size() > 0) {
            reward += possible.top();
            possible.pop();
            recvJobs++;
        }
        if (recvJobs == N) break;
    }
    cout << reward << endl;
    return 0;
}


Measured memory_bytes: 11648
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    mod = 10**9+7
    K = int(input())
    S = input()
    Nk = len(S)
    ret = 0
    nCk = 1
    pw25 = 1
    pw26 = pow(26,K,mod)
    inv26 = pow(26,mod-2,mod)
    for i in range(K+1):
        ret += nCk * pw25 * pw26
        ret %= mod
        nCk *= (i+Nk) * pow(i+1,mod-2,mod)
        nCk %= mod
        pw25 = (pw25*25)%mod
        pw26 = (pw26*inv26)%mod

    print(ret)

if __name__ == '__main__':
    main()


Measured memory_bytes: 75124
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import ceil

def main():
  s = 0
  xs = []
  for x in [int(input()) for _ in range(5)]:
    if x % 10 == 0:
      s += x
    else:
      xs.append(x)
  if len(xs) < 2:
    print(s + sum(xs))
  else:
    xs = sorted(xs, key=lambda x: x%10, reverse=True)
    print(s + sum(map(lambda x: ceil(x/10)*10, xs[:-1])) + xs[-1])

if __name__=='__main__':
  main()



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const long long mod = 1e9 + 7;

int main()
{
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		String str=input.readLine();
		String str2=input.readLine();
		String[] atr=str2.split(" ");
		int n=Integer.parseInt(str);
		int[] number =new int[n];
		for(int i=0;i<atr.length;i++){
		number[i]=Integer.parseInt(atr[i]);
		}
		int min=number[0];
		int max=number[0];
		long sum=0;
		for(int i=0;i<number.length;i++){
			if(min>number[i]){
				min=number[i];
			}
		}
		for(int i=0;i<number.length;i++){
			if(max<number[i]){
				max=number[i];
			}
		}
		for(int i=0;i<number.length;i++){
			sum+=number[i];
		}
		System.out.println(min+" "+max+" "+sum);	
		
	}
}

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

int main(){
    int D, G, p[11], c[11];
    cin>>D>>G;
    for(int i=0; i<D; i++){
        cin>>p[i]>>c[i];}

    int ans=1e9;
    for(int mask=0; mask < (1 << D); mask++){ // ビットシフト(A<<B)はAを2*B倍する処理
        int sum=0, num=0, rest_max=-1;
        for(int i=0; i<D; i++){
            if(mask >> i & 1){ // (A>>B)はAを(1/2*B)倍する処理。論理積(i&1)は2進数でiと1で両方1の桁のみ1、それ以外は0と表示する処理
              sum+=100*(i+1)*p[i]+c[i];  // p[i]におけるボーナス含む全ての得点の合計
              num+=p[i]; } // 問題数p[i]の合計
            else{rest_max=i;}  // rest_maxはそのループにおけるボーナス未取得状態でのiを指す
        }
      
        if(sum<G){ // p[i]におけるボーナス含む全ての得点の合計がGより小さい場合
            int s1=100*(rest_max+1);  // p[i]の得点が最小の問題をいくつ足せばsum>=Gになるか
            int need=(G-sum+s1-1)/s1;  // 足りないx*100の数はneed*s1=G-sum+s1-1より算出し、
            if(need>=p[rest_max]){continue;} // それがp[rest_max]以上の場合はループして高いp[i]の和を足し、
            num+=need; // それがp[rest_max]未満なら、p[rest_max]の個数内を足す。
        }
      ans=min(ans, num);  // 各問題の点数の合計の最小値
    }
  cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod ((int)1e9+7)
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;

const int N = (int)2e5+5;

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

    string s;
    cin>>s;
    if(s[5]=='1' || s[6]>'4') {
        cout<<"TBD";
    }
    else cout<<"Heisei";
}


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

int main(){
    vector<int> in(3);
    vector<bool> odd(3);
    int oddnum=0,op=0,max_index=-1,max_num=-1;;

    for(int i=0; i<3; i++){
        cin >> in[i];
        if(in[i]%2 == 0){
            odd[i] = true;
            oddnum++;
        }else{
            odd[i] = false;
        }
    }
    if(oddnum==2){
        for(int i=0; i<3; i++){
            if(odd[i]){
                in[i]++;
            }
        }
        op++;
    }else if(oddnum == 1){
        for(int i=0; i<3; i++){
            if(!odd[i]){
                in[i]++;
            }
        }
        op++;
    }
    for(int i=0; i<3; i++){
        if(max_num < in[i]){
            max_num = in[i];
        }
    }
    for(int i=0; i<3; i++){
        op += (max_num - in[i])/2;
    }
    cout << op << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

struct mint {
	ll x;
	ll m;
	mint(ll x=0, ll m=1e9+7): x(x%m), m(m) {}
	mint operator-() const { return mint(m-x, m); }
	mint operator+(const mint o) const { return mint(x+o.x, m); }
	mint operator-(const mint o) const { return mint(x-o.x+m, m); }
	mint operator*(const mint o) const { return mint(x*o.x, m); }
	mint& operator+=(const mint o) { x = (x+o.x)%m; return *this; }
	mint& operator-=(const mint o) { x = (x-o.x+m)%m; return *this; }
	mint& operator*=(const mint o) { x = x*o.x%m; return *this; }
	template<typename T> mint operator+(const T o) const { return mint(x+o, m); }
	template<typename T> mint operator-(const T o) const { return mint(x-((ll)o)%m+m, m); }
	template<typename T> mint operator*(const T o) const { return mint(x*o, m); }
	template<typename T> mint& operator+=(const T o) { x = (x+(ll)o%m)%m; return *this; }
	template<typename T> mint& operator-=(const T o) { x = (x-((ll)o)%m+m)%m; return *this; }
	template<typename T> mint& operator*=(const T o) { x = x*((ll)o%m)%m; return *this; }
	template<typename T> mint& operator=(const T o) { x = o%m; return *this; }
};

mint dp[55][55][1300];
int main(){
	int N, K;
	cin >> N >> K;

	dp[0][0][0] = 1;
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			for(int k=0; k<=N*N/2; k++){
				debug(any{i, j, k, dp[i][j][k].x});
				dp[i+1][j][k+j] += dp[i][j][k];
				dp[i+1][j+1][k+j] += dp[i][j][k];
				dp[i+1][j][k+j] += dp[i][j][k]*2*j;
				if(j>0) dp[i+1][j-1][k+j] += dp[i][j][k]*j*j;
			}
		}
	}

	ll ans;
	if(K%2) ans = 0;
	else ans = dp[N][0][K/2].x;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 61696
n,m=map(int,input().split())

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

a.sort()

bc=[]
for i in range(m):
    bc.append(list(map(int,input().split())))

bc.sort(key=lambda x:x[1],reverse=True)

lis=[]
for i in range(m):
    if len(lis)>=n:
        break
    for _ in range(bc[i][0]):
        lis.append(bc[i][1])

while len(lis)<n:
    lis.append(0)

s=0
for i in range(n):
    s+=max(a[i],lis[i])

print(s)

Measured memory_bytes: 32700
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[100000];
        for(int i = 0; i < n; i++){
            x[sc.nextInt() - 1]++;
        }
        int all = 0, cnt = 0;
        for(int i = 0; i < 100000; i++){
            if(x[i] > 0){
                all++;
                if(x[i] % 2 == 0){
                    cnt++;
                    cnt %= 2;
                }
            }
        }
        System.out.println(all - cnt);
    }
}

Measured memory_bytes: 51152
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(abs(a-b)%2==1){
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	cout<<min(a,b)+abs(a-b)/2<<endl;
	return 0;
}


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

int main(){
  int w,h,x,y;
  cin>>w>>h>>x>>y;
  double f=(double)w*h/2;
  int cnt=1;
  if(w%2!=0 ||h%2!=0){
    cnt=0;
    
  }else{
    if(x!=w/2 || y!=h/2)cnt=0;
  }
  printf("%.9f %d",f,cnt);
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;

const ll MAX = 510000;
const ll MOD = 1000000007;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 順列計算
ll ARR(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n-k] % MOD;
}
//重複組合せ計算
ll MULTICOM(ll n, ll k){
    return COM(n+k-1,k);
}
//べき乗計算
ll modpow(ll a,ll n,ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

void Main(){
    COMinit();
    ll n;cin>>n;
    ll k;cin>>k;
    vector<ll> a(n);
    For(i,0,n) cin>>a[i];
    sort(ALL(a));
    vector<ll> sum(n,0);
    For(i,0,n){
        sum[i]+=COM(i,k-1);
        sum[i]-=COM(n-1-i,k-1);
    }
    For(i,0,n){
        //cout<<sum[i]<<" ";
        ans+=a[i]*sum[i]%MOD;
        ans%=MOD;
    }
    //cout<<endl;
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 13824
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

INF = 10*10

H,W = map(int, input().split())
C = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]

N = 100

# mp[i][j]..i→1にj回でする時の最小魔力
mp = [[INF]*N for _ in range(11)]
mp[0][1] = 0
for i in range(10):
    mp[i][1] = C[i][1]

for j in range(2,N):
    for i in range(10):
        mp[i][j] = min((C[i][k] + mp[k][j-1]) for k in range(10))

cnt = [0]*10
for a in A:
    for i in range(10):
        cnt[i] += a.count(i)

ans = 0
for i in range(10):
    ans += cnt[i] * mp[i][N-1]

print(ans)

Measured memory_bytes: 12448
#include<iostream>

using namespace std;

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

  int a[100];

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

  for (int i = 0; i < n; i++)
    {
      if (i) cout << " ";
      cout << a[n-1-i];
    }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1164
import sys
from collections import defaultdict
from typing import Dict


def find_shortest_distance(start_vertex: int, n: int,  relations: Dict[int, Dict]) -> Dict[int, int]:
    unreached_vertices = [x for x in range(1, n)]
    distance = {x: sys.maxsize for x in range(n)}
    distance[start_vertex] = 0
    vtx = None
    tmp_distance = [sys.maxsize for x in range(n)]
    for k, v in relations[start_vertex].items():
        tmp_distance[k] = v

    while True:
        min_dist = sys.maxsize
        for i in unreached_vertices:
            dist = tmp_distance[i]
            if dist < min_dist:
                min_dist = dist
                vtx = i
        if min_dist == sys.maxsize:
            break
        unreached_vertices.remove(vtx)
        distance[vtx] = min_dist
        neighbor_vertices = relations[vtx]
        for n_vtx, n_dist in neighbor_vertices.items():
            n_dist_from_start = distance[vtx] + n_dist
            tmp_dist = tmp_distance[n_vtx]
            if tmp_dist == sys.maxsize:
                tmp_distance[n_vtx] = n_dist_from_start
            else:
                if n_dist_from_start < tmp_dist:
                    tmp_distance[n_vtx] = n_dist_from_start
    return distance


def main():
    n = int(input())
    relations = defaultdict(dict)

    lines = sys.stdin.readlines()
    for i in range(n):
        u, k, *vtx_wght = map(int, lines[i].split())
        for v_i in range(k):
            relations[u][vtx_wght[2*v_i]] = vtx_wght[2*v_i+1]

    dist_from_0 = find_shortest_distance(0, n, relations)

    answers = [None] * n
    sorted_dist = sorted(dist_from_0.items(), key=lambda x: x[0])
    for i in range(n):
        answers[i] = f"{sorted_dist[i][0]} {sorted_dist[i][1]}"
    [print(ans) for ans in answers]
    return


main()


Measured memory_bytes: 55908
#include <stdio.h>

#define INF 2001

int graph[100][100], n, d[100], p[100], c[100];

int mst() {
    int i, v, min, result = 0;
    for (i = 0; i < n; i++) {
        d[i] = INF;
        p[i] = -1;
        c[i] = 1;
    }
    
    d[0] = 0;
    
    while (1) {
        min = INF;
        v = -1;
        for (i = 0; i < n; i++) {
            if (min > d[i] && c[i] != -1) {
                v = i;
                min = d[i];
            }
        }
        if (v == -1) break;
        c[v] = -1;
        for (i = 0; i < n; i++) {
            if (graph[v][i] != INF && c[i] != -1) {
                if (d[i] > graph[v][i]) {
                    d[i] = graph[v][i];
                    p[i] = v;
                    c[i] = 0;
                }
            }
        }
    }
    
    for (i = 0; i < n; i++) {
        if (p[i] != -1) result += graph[i][p[i]];
    }
    
    return result;
}

int main(void){
    int i, j;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            scanf("%d", &graph[i][j]);
            if (graph[i][j] == -1) graph[i][j] = INF;
        }
    }
    
    printf("%d\n", mst());
    
    return 0;
}




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

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

    string s;
    cin >> s;

    if(n % 2 != 0){
        cout << "No" << endl;
    }else{

        for(int i = 0;i < n/2;i++){
            if(s[i] != s[i+n/2]){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

ll cnt(ll N) {
    ll ans = 0;
    while(N%2 == 0) {
        N /= 2;
        ans++;
    }
    return ans;
}

int main() {
    int N;
    cin >> N;
    vecl even;
    ll ans = 0;
    REP(i,N) {
        ll a;
        cin >> a;
        if(a%2 == 0) even.push_back(a);
    }
    if(even.size() == 0) ans = 0;
    else if(even.size() == 1) ans = cnt(even[0]);
    else {
        for(auto a : even) ans += cnt(a); 
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  unordered_map<string, int> mp;
  mp["AC"] = 0;
  mp["WA"] = 0;
  mp["TLE"] = 0;
  mp["RE"] = 0;
  int n;
  cin >> n;
  while (n--){
    string x;
    cin >> x;
    mp[x]++;
  }
  for (auto it : mp){
    if (it.first == "AC")
      cout << it.first << " x " << it.second << "\n";
  }
  for (auto it : mp){
    if (it.first == "WA")
      cout << it.first << " x " << it.second << "\n";
  }
  for (auto it : mp){
    if (it.first == "TLE")
      cout << it.first << " x " << it.second << "\n";
  }
  for (auto it : mp){
    if (it.first == "RE")
      cout << it.first << " x " << it.second << "\n";
  }
  return 0;
}

Measured memory_bytes: 3668
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();

	}
	static class Task{
		int M = (int) (1e9 + 7);
		public void solve(int testNumber, InputReader in, PrintWriter out) {
				long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
				long l = b/c -(a-1)/c, r = b/d - (a-1)/d;
				out.print(b-a +1 - (l+r -(b/lcm(c,d) -(a-1)/lcm(c,d))));
		}//Solve
		private long lcm(long c, long d) {
			return c*d/gcd(c,d);
		}
		private long gcd(long c, long d) {
			if(d == 0) return c;
			return gcd(d, c%d);
		}
		

			
	}//task

	static class InputReader{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		public String next() {
			while(tokenizer == null || ! tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for(int i = -1; ++i < n;) arr[i] = Integer.parseInt(next());
			return arr;
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		
	}
}

Measured memory_bytes: 24788
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n;
  string s;
  cin >> n >>s;
 
  vector<ll> p(26);
  
  rep(i,n){
  p[s[i]-'a']++;
  }
  
  ll ans=1;
  rep(i,26){
  ans*=p[i]+1;
  ans%=mod;
  }
  
  cout << (ans+mod-1)%mod << endl;
}

Measured memory_bytes: 512
A,B,H,M=map(int,input().split())

import numpy as np
pi=np.pi

def clock(A,B,H,M):
    angleA=(H+M/60)/12*2*pi
    angleB=M/60*2*pi
    delta=angleA-angleB
    X_squared=A**2+B**2-2*A*B*np.cos(delta)
    X=np.sqrt( X_squared)
    print(X)
    
clock(A,B,H,M)

Measured memory_bytes: 27220
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define LLIandI pair<long long int , int>
#define ll long long

//第9回課題
//Curling
//問題:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1144&lang=jp
// 中央＊前

int W,H;
int memox[4] = {1, -1, 0, 0};
int memoy[4] = {0, 0, 1, -1};
int map[50][50];
int ans=11;


void dfs(int x,int y,int count){
	if(count+1>=ans)return;
	
	rep(dir,4){
	    int nx=x+memox[dir];
	    int ny=y+memoy[dir];
	    if(map[ny][nx]==1)continue;
	    while(1){
	        if(nx < 0 || ny < 0 || nx >= W || ny >= H)break;
	        if(map[ny][nx]==3){
	            ans=count+1;
	            return;
	        }
	        if(map[ny][nx]==1){
	            map[ny][nx]=0;
	            dfs(nx-memox[dir],ny-memoy[dir],count+1);
	            //printf("%d %d %d!\n",nx-memox[dir],ny-memoy[dir],count+1);
	            map[ny][nx]=1;
	            break;
	        }
	        nx+=memox[dir];
	        ny+=memoy[dir];
	    }
	}
	
	return;
}

int main(){
	while(1){
	    scanf("%d %d",&W,&H);
	    if(W==0)break;
		int sx,sy;
		rep(y,H){
			rep(x,W){
				scanf("%d",&map[y][x]);
				if(map[y][x] == 2){sx=x;sy=y;map[y][x]=0;}
			}
		}
		ans = 11;
		dfs(sx,sy,0);	
		if(ans<=10)printf("%d\n",ans);
		else printf("-1\n");
	}
	return 0;
}



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

int main(void){

    int n ;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int k=0;k<n;k++){
            cout<<a[k];
            if(k!=n-1)cout<<' ';
            if(k==n-1)cout<<endl;
        }
    for(int i=1;i<n;i++){
        for(int j=i;j>=0&&a[j]<a[j-1];j--){
            int tmp = a[j];
            a[j]=a[j-1];
            a[j-1]=tmp;
        }
        for(int k=0;k<n;k++){
            cout<<a[k];
            if(k!=n-1)cout<<' ';
            if(k==n-1)cout<<endl;
        }
    }

    return 0;
}


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

int main(void){
    vector<int> v;
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int num, x;
        cin >> num;
        if(num==0){
            cin >> x;
            v.push_back(x);
        }
        else if(num==1){
            cin >> x;
            cout << v.at(x) << "\n";
        }
        else{
            v.pop_back();
        }
    }
    
    
    return 0;
}



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

using namespace std;

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

  if(n % 10 == 7){
    cout << "Yes" << endl;
    return 0;
  }

  n /= 10;
  if(n % 10 == 7){
    cout << "Yes" << endl;
    return 0;


  }

  n /= 10;
  if(n % 10 == 7){
    cout << "Yes" << endl;
    return 0;
  }

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


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long A, B, C, K;
    cin >> A >> B >> C >> K;

    long long t = 0;
    if (K <= A)
    {
        cout << K << endl;
    }
    else
    {
        t = A;
        K -= A;
        if (K <= B)
        {
            cout << t << endl;
        }
        else
        {
            K -= B;
            cout << t - K << endl;
        }
    }
}

Measured memory_bytes: 3652