akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

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

S = ((N+1)*N)//2
sA = sum(A)
if sA%S!=0:
    print("NO")
else:
    C = sA//S
    count = 0    
    flag = False
    for i in range(N):
        if i == N-1:
            sub=A[0]-A[i]
        else:
            sub=A[i+1]-A[i]

        if (sub + C*(N-1))%N != 0:
            flag = True
            break
        cnt = C-(sub + C*(N-1))//N
        if cnt>C or cnt<0:
            flag = True
            break
        count += cnt
    if flag:
        print("NO")
    else:
        if C == count:
            print("YES")
        else:
            print("NO")

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

int main(){
    int s,w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe" <<endl;
    else cout << "safe" <<endl;

    return 0;
}

Measured memory_bytes: 3636
n=int(input())

def ketacul(x):
    keta=1
    while(x/10>=1):
        x=x/10
        keta+=1
    return keta
count=0
for i in range(1,n+1):
    a=ketacul(i)
    if a%2==1:
        count+=1
print(count)

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {

        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            int N = Integer.parseInt(in.readLine());
            char[] A = String.valueOf(in.readLine()).toCharArray();;
            char[] B = String.valueOf(in.readLine()).toCharArray();;
            char[] C = String.valueOf(in.readLine()).toCharArray();;
            
            int changeCnt = 0;
            int sameCnt;
            for (int i = 0; i < N; i++) {
                sameCnt = 0;
                if (A[i] == B[i]) {
                    sameCnt++;
                }
                if (A[i] == C[i]) {
                    sameCnt++;
                }
                if (B[i] == C[i]) {
                    sameCnt++;
                }
                
                if (sameCnt < 2) {
                   changeCnt += (2 - sameCnt); 
                }
            }
             
            System.out.println(changeCnt);
        } catch(Exception e) {
            System.out.println(e);
            System.exit(0);
        }
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n,k;
  cin>>n>>k;
  vector<Int> a(n),b(n);
  for(Int i=0;i<n;i++) cin>>a[i]>>b[i];
  Int ans=0;
  for(int i=0;i<n;i++) if((k|a[i])==k) ans+=b[i];
  //cout<<ans<<endl;
  for(Int i=0;i<=40;i++){
    if(((k>>(40-i))&1)==0) continue;
    Int x=0;
    for(Int j=0;j<=i;j++) x+=(1LL<<(40-j));
    Int res=0;
    Int y=((k-(1LL<<(40-i)))&x);
    for(int j=0;j<n;j++)
      if((y|(a[j]&x))==y) res+=b[j];
    //for(int j=0;j<n;j++) cout<<(40-i)<<":"<<(a[j]&x)<<" "<<y<<" "<<b[j]<<endl;
    //cout<<res<<endl;
    ans=max(ans,res);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
n,m = map(int,input().split())
stair = []
mod = int(1e9+7)
for i in range(m):
    stair.append(int(input()))
dp = [0] * (n+1)
dp[0] = 1
stair.append(int(1e10))
k = 0
for i in range(1, n+1):
    if i == stair[k]:
        dp[i] = 0
        k += 1
    elif i == 1:
        dp[1] = 1
    else:
        dp[i] = (dp[i-1] + dp[i-2])%mod
print(dp[-1])





Measured memory_bytes: 7824
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    int A[N];
    for(int i=0;i<N;i++) cin >> A[i];
    int B[N+1];
    for(int i=0;i<N;i++) B[i] =0;
    for(int i=0;i<N;i++) B[A[i]-1]++;
    sort(B, B+N);
    int cnt=0;
    for(int i=0;i<N;i++){
        if(B[i] != 0) cnt++;
    }
    int C[cnt+1];
    for(int i=0;i<cnt+1;i++) C[i] = 0;
    int k = cnt;
    cnt =0;
    for(int i=0;i<N;i++){
        if(B[i] != 0)
        {C[cnt] = B[i];
        cnt++;}
    }
    int j = k-K, ans = 0;
    for(int i=0;i<j;i++) ans += C[i];
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main()
{
	int a,b;
	char op;
	
	while(scanf("%d %c %d", &a, &op, &b))
	{
		if(op == '?')
		{
			break;
		}
		switch(op)
		{	
			case '+':
				printf("%d\n", a+b);
				break;
			case '-':
				printf("%d\n", a-b);
				break;
			case '*':
				printf("%d\n", a*b);
				break;
			case '/':
				printf("%d\n", a/b);
				break;			
		}
	}
	return 0;
 } 


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

int n, m, cnt[2], ans = 0;

int main() {
  int i, j, x;
  cin >> m >> n;
  for(i = 0; i < m; ++i) {
    cnt[0] = cnt[1] = 0;
    for(j = 0; j < n; ++j) {
      cin >> x;
      if(i != 0) x = 1 - x;
      if(j == 0 || j == n - 1)
        ++cnt[x];
      else
        ++cnt[1 - x];
    }
    if(n == 1)
      ans += cnt[1];
    else if(cnt[0] == 0)
      ans += cnt[1] - 1;
    else
      ans += cnt[1] + 1;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int n,l;
    cin >> n >> l;
    vector<string> s(110);
    for(int i=0;i<n;i++){
        cin >> s.at(i);
    }
    sort(s.begin(),s.end());
    for(int i=0;i<s.size();i++){
        cout << s.at(i);
    }
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
num,A,B = 0,sum(a),sum(b)
for i in range(n): num+=max(0,((b[i]-a[i])+(b[i]-a[i])%2)//2)
if num>B-A: print("No")
else: print("Yes")

Measured memory_bytes: 4596
def makefac(n):
    global faclist
    faclist = [1, 1]
    for i in range(2, n + 1):
        faclist.append(faclist[-1] * i % MOD)
    return None
def mcomb(n, r):#nCr % MOD
    return faclist[n] * pow(faclist[r],MOD - 2, MOD) * pow(faclist[n-r], MOD - 2, MOD)
def mperm(n, r):#nPr % MOD
    return faclist[n] * pow(faclist[n-r],MOD - 2, MOD)

N, M = map(int, input().split())
MOD = 10 ** 9 + 7
makefac(M)
ans = mperm(M, N)
for k in range(1, N + 1):
    ans += ((-1)**k * mcomb(N, k) * mperm(M - k, N - k)) % MOD
ans = ans * mperm(M, N) % MOD
print(ans)


Measured memory_bytes: 104464
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<map>

using namespace std;

int main() {
	const int SIZE = 2001;
	bool dp[SIZE] = { false };
	
	int n;
	int m;
	int ary[20];
	vector<int> vec;

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

	vec.push_back(0);
	dp[0] = true;
	for (int i = 0; i < n; i++) {
		int s = vec.size();
		for (int j = 0; j < s; j++) {
			if (dp[vec[j] + ary[i]] == false) {
				dp[vec[j] + ary[i]] = true;
				vec.push_back(vec[j] + ary[i]);
			}
		}
	}
	
	cin >> m;
	for (int i = 0; i < m; i++) {
		int v;
		cin >> v;
		if (dp[v]) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3140
/*
██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗
██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗
█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║
██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║
██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝
Believe in yourself ,( try and try and then try ), You can do it
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define clr(arr, x) memset(arr, x, sizeof arr)
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define OO 0x3f3f3f3f3f3f3f3fLL
const int oo = 0x3f3f3f3f, Mod = 1e9 + 7;
using namespace std;
typedef long long ll;
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K(){ 
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
	K_K();
	string s;
	cin >> s;
	for (int i = 0; i < sz(s); i++){
		if (s[i] == '?')
			cout << 'D';
		else
			cout << s[i];
	}
}

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

string d = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
string e[40] = {"100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000","101","010001","000011","10010001","000000","000001"};

string tb(int n){
    string res = "";
    int c = 5;
    char cc;
    while(c--){
        cc = n%2+'0';
        res = string(1, n%2+'0') + res;
        n /= 2;
    }
    return res;
}

bool isPrefix(string sc, string sp){
    int i;
    for(i = 0; sp[i] && i < sc.size(); i++){
        if( sc[i] != sp[i] ) return false;
    }
    return i == sc.size();
}

int main(){
    string s;
    int i, j;
    while( getline(cin, s) ){
        string c = string("");
        for(i = 0; i < s.size(); i++){
            int ind = d.find_first_of(s[i]);
            c += tb( ind );
        }
        i = 0;
        int len = c.size();
        while(i < len){
            string t = "";
            int can,rem, f = 0;
            while(i+f < len){
                can = 0;
                t += c[i+f];
                for(j = 0; j < 36; j++){
                    if( isPrefix(t, e[j]) ){
                        can++;
                        rem = j;
                    }
                }
                if( can == 1 ){
                    if( i+e[rem].size() <= len){
                        cout << d[rem];
                    }
                    i += e[rem].size()-1;
                    break;
                }
                f++;
            }
            i++;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1184
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

signed main(){
    ll n;
    cin>>n;
    if(n%2==0) cout<<n<<endl;
    else cout<<n*2<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); List <Integer> H = new ArrayList <Integer> (); List <Integer> W = new ArrayList <Integer> (); int lastH = 0; int lastW = 0; do { lastH = stdIn.nextInt(); lastW = stdIn.nextInt(); H.add(lastH); W.add(lastW); } while (lastH != 0 || lastW != 0); for(int i = 0; i < H.size()-1; i++) { for(int j = 0; j < H.get(i); j++) { if(j == 0 || j == H.get(i) - 1) { for(int k = 0; k < W.get(i); k++) { System.out.print("#"); } } else { System.out.print("#"); for(int k = 0; k < W.get(i) - 2; k++) { System.out.print("."); } System.out.print("#"); } System.out.println(); } System.out.println(); } } } 


Measured memory_bytes: 36492
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#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, k) for(int i = 0; i < n; i += k)

int main()
{
    ll x, y;

    cin >> x >> y;

    if(x == 0){
        if(y > 0){
            cout << y << endl;
        }
        else{
            cout << abs(y) + 1 << endl;
        }
    }
    else if(y == 0){
        if(x > 0){
            cout << x + 1 << endl;
        }
        else{
            cout << abs(x) << endl;
        }
    }
    else if(x >= 0 && y >= 0){
        if(x < y){
            cout << y - x << endl;
        }
        else{
            cout << x - y + 2 << endl;
        }
    }
    else if(x < 0 && y >= 0){
        if(abs(x) <= y){
            cout << y - abs(x) + 1 << endl;
        }
        else{
            cout << abs(x) - y + 1 << endl;
        }
    }
    else if(x >= 0 && y < 0){
        if(x <= abs(y)){
            cout << abs(y) - x + 1 << endl;
        }
        else{
            cout << x - abs(y) + 1 << endl;
        }
    }
    else{
        if(abs(x) < abs(y)){
            cout << abs(y) - abs(x) + 2 << endl;
        }
        else{
            cout << abs(x) - abs(y) << endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define boost ios_base::sync_with_stdio(false)
#define forloop(i,a,b) for(int i=a;i<b;i++)
#define forloopp(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
signed main()
{
    boost;
    int n; cin>>n;
    int arr[n];
    forloop(i,0,n)cin>>arr[i];
    int dp[n];
    dp[0]=0; dp[1]=abs(arr[1]-arr[0]);
    forloop(i,2,n)
    {
        dp[i]=min((dp[i-1]+abs(arr[i-1]-arr[i])),((dp[i-2]+abs(arr[i-2]-arr[i]))));
    }
    cout<<dp[n-1];
}    


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

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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  s1 = toupper(s1[0]);
  s2 = toupper(s2[0]);
  s3 = toupper(s3[0]);
  string sum = s1+s2+s3;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

vector<vector<int>> g;
vector<bool> visited;
vector<int> ordered;

int dp[100100];

void dfs(int v) {
    if (visited[v]) return;
    visited[v] = true;
    for (auto u: g[v]) {
        if (visited[u]) continue;
        dfs(u);
    }
    ordered.push_back(v);
};

int main() {
    int n, m; cin >> n >> m;
    g.resize(n);
    visited.resize(n);
    rep(i,m) {
        int xi, yi; cin >> xi >> yi;
        --xi, --yi;
        g[xi].push_back(yi);
    }
    rep(i,n) {
        if (visited[i]) continue;
        dfs(i);
    }
    reverse(all(ordered));
    //rep(i,n) cout << ordered[i] << endl;
    
    rep(i,n) {
        for (auto v: g[ordered[i]]) {
            dp[v] = max(dp[ordered[i]]+1, dp[v]);
        }
    }
    int ans = 0;
    rep(i,n) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11676
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S;
    cin >> S;
    string ans ="Good";
    for(int i=0;i+1<S.size();i++){
        if(S[i] == S[i+1]){
            ans = "Bad";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3112
//#pragma GCC target ("avx2,sse2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree <pair <ll, int>, null_type, less <pair <ll, int> >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define db double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"

#define left fsdsdfoisf
#define sum dpsdfioppsf
#define assign xcvjlkdjfio
#define trie fksdfkjkfnjuiv
#define next sidlfjsfkl
#define merge sdfksdkfsldf

#define int long long

using namespace std;

void dout() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 3007, inf = 1e15;
int n, a[N], dp[N][N];

int calc(int l, int r) {
    if (l > r) {
        return 0;
    }
    int & res = dp[l][r];
    if (res != -1) {
        return res;
    }
    res = -inf;
    res = max(res, a[l] - calc(l + 1, r));
    res = max(res, a[r] - calc(l, r - 1));
    return res;
}

void solve(int tc) {
    // check for (int i = 0; i < n; j++)
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    cout << calc(1, n);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}


Measured memory_bytes: 71040
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int n;
cin >> n;
using ll = long long;
ll a[2][500] = {};
for(int i = 0; i < 2; ++i){
for(int j = 0; j < n; ++j){
cin >> a[i][j];
}
}
ll best = 0;
 
for(int poz = 0; poz < n; ++poz){
best = max(best, accumulate(a[0], a[0] + poz + 1, 0ll) + accumulate(a[1]+poz, a[1]+n, 0ll));
}
cout << best << endl;
return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        String str = sc.next();
        int n = sc.nextInt();
        
        System.out.print(str.charAt(0));
        for(int i=n; i<str.length(); i++){
            if(i%n==0)
            System.out.print(str.charAt(i));
        }
	}
}


Measured memory_bytes: 36160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
//unionfind
struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};
int main(){
  string s;
  int w;
  cin >> s >> w;
  string ans;
  rep(i,(s.size()-1)/w+1)
    ans+=s.at(w*i);
  cout << ans << endl;
}

Measured memory_bytes: 3604
/*input
1
0.50
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
double dp[3000][3000];
double arr[3000];
int min1;
void solve(int n)
{   

	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{	if(i==0 && j==0)
			{
				dp[i][j]=1;
			}
			else if(i==0&&j!=0)
			{
				dp[i][j]=0;
			}
			else if(i!=0 && j==0)
			{
				dp[i][j]=dp[i-1][j]*(1-arr[i-1]);
			}
			else 
			{
				dp[i][j]=dp[i-1][j]*(1-arr[i-1])+dp[i-1][j-1]*arr[i-1];
			}
		}
	}
}
int main()
{
   int n ;
   cin>>n;
   for(int i=0;i<n;i++)
   {
   	cin>>arr[i];
   	//cout<<arr[i]<<' ';
   }

   solve(n);
   
   int x=n/2;
   x=n-n/2;
   double ans=0;
   for(int i=x;i<=n;i++)
   {
   	ans+=dp[n][i];
   }
   cout<<fixed<<setprecision(9)<<ans;
  
 }


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

struct guide{
	string s;
	int p, num;
};


int main(){
	int n;
	guide sp[100];
	
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> sp[i].s >> sp[i].p;
		sp[i].num = i + 1;
	}
	
	for(int i = 0; i < n - 1; i++){
		for(int j = i; j < n; j++){
			if(sp[i].s == sp[j].s){
				if(sp[i].p < sp[j].p){
					guide tmp = {sp[j].s, sp[j].p, sp[j].num};
					sp[j].s = sp[i].s;
					sp[j].p = sp[i].p;
					sp[j].num = sp[i].num;
					sp[i].s = tmp.s;
					sp[i].p = tmp.p;
					sp[i].num = tmp.num;
				}
			}
			else if(sp[i].s > sp[j].s){
				guide tmp = {sp[j].s, sp[j].p, sp[j].num};
				sp[j].s = sp[i].s;
				sp[j].p = sp[i].p;
				sp[j].num = sp[i].num;
				sp[i].s = tmp.s;
				sp[i].p = tmp.p;
				sp[i].num = tmp.num;
			}
		}
	}
	
	for(int i = 0; i < n; i++) cout << sp[i].num << endl;
	return 0;
}

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

ll beki(ll a, ll b) {
  if (b == 0) return 1;
  ll ret = beki(a, b / 2);
  ret = ret * ret % MOD;
  if (b & 1) ret = ret * a % MOD;
  return ret;
}

int main() {
  int N;
  cin >> N;
  map<P, int> mp;
  int abzero = 0;
  rep(i, N) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      abzero++;
      continue;
    }
    if (b < 0) {
      b = -b;
      a = -a;
    } else if (b == 0) {
      mp[make_pair(1, 0)]++;
      continue;
    }
    ll g = gcd(a, b);
    mp[make_pair(a / g, b / g)]++;
  }
  ll ans = 1;
  set<P> visited;
  for (const auto& [k, _] : mp) {
    if (visited.count(k)) continue;
    ll tmp = 1;
    P chokkou;
    if (k.first > 0) {
      chokkou = make_pair(-k.second, k.first);
    } else {
      chokkou = make_pair(k.second, -k.first);
    }
    tmp = (tmp + beki(2, mp[k]) - 1) % MOD;
    tmp = (tmp + beki(2, mp[chokkou]) - 1) % MOD;
    visited.insert(chokkou);
    ans = (ans * tmp) % MOD;
  }
  ans = (ans + abzero + MOD - 1) % MOD;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 40988
import heapq
import sys
input=sys.stdin.readline
N,Q=map(int,input().split())

event_list=[]
for i in range(N):
  S,T,X=map(int,input().split())
  event_list.append((S-X-0.5,1,X))
  event_list.append((T-X-0.5,-1,X))
  
dlist=[]
for i in range(Q):
  D=int(input())
  event_list.append((D,0,X))  
  dlist.append(D)
event_list.sort()
#print(event_list)

answer_dic={}
stop_set=set()
min_set=float("inf")
for t,f,x in event_list:
  if f==1:
    stop_set.add(x)
    if x<min_set:
      min_set=x
  elif f==-1:
    stop_set.remove(x)
    if x==min_set:
      if len(stop_set)>0:
        min_set=min(stop_set)
      else:
        min_set=float("inf")
  else:
    if len(stop_set)>0:
      answer_dic[t]=min_set
    else:
      answer_dic[t]=-1
#print(answer_dic)

for d in dlist:
  print(answer_dic[d])

Measured memory_bytes: 107188
#include<cstdio>
#include<cstdlib>


using namespace std;
using ll=long long;

#define MOD 1000000007


ll fact(int n)
{
	ll ret=1;

	for(;n;n--) ret=(ret*n)%MOD;
	return ret;
}


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		ll ans;

		if(abs(n-m)>1)
		{
			ans=0;
		}
		else
		{
			ans=(fact(n)*fact(m))%MOD;
			if(n==m) ans=(ans*2)%MOD;
		}
		printf("%d\n", (int)ans);
	}

	return 0;
}



Measured memory_bytes: 128
main = do
    s <- getLine
    let alphabet = "abcdefghijklmnopqrstuvwxyz"
        n = length s
        ans | n < 26 = s ++ g s alphabet
            | null s' = "-1"
            | otherwise = init s' ++ g s' (dropWhile (<= last s') alphabet)
            where s' = take (n - f (reverse s)) s
    putStrLn ans

f [] = 0
f (a:[]) = 1
f (a:b:as) | a < b = 1 + f (b:as)
           | otherwise = 1

g s a = head (dropWhile (`elem` s) a) : []

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

typedef long long ll;

int main() {	
	int n;
	cin >> n;
	map<pair<int,int>,ll> m;
	for (int i = 1; i <= n; ++i) {
		vector<int> val;
		int x = i;
		while (x) {
			val.push_back(x % 10);
			x /= 10;
		}
		if (val[0] != 0 && val[(int)val.size() - 1] != 0) {
			///cout << val[0] << " " << val[(int)val.size() - 1] << endl;
			m[{val[(int)val.size() - 1],val[0]}]++;
		}
	}
	ll ans = 0;
	//map<pair<int,int>,bool> ch;
	for (auto &x : m) {
		//if (!ch[{x.first.first,x.first.second}]) {
			//ll p1 = 
			//if (x.first.first == x.first.second) {
			//	ans += x.second;
			//}else {
				ans += x.second * m[{x.first.second,x.first.first}];
			//}
			//cout << x.first.first << " " << x.first.second << " " << x.first.second << " " << x.first.first << " " <<x.second << " " <<  p1 << endl;
		///}
		//ch[{x.first.second,x.first.first}] = 1;
	}
	cout << ans;
}










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

int main() {
int A,B,C;
  cin >>A>>B>>C;
  if((A==7&&B==5&&C==5) || (A==5&&B==7&&C==5) ||(A==5&&B==5&&C==7)){
    cout <<"YES";
  }
  else{
    cout <<"NO";
  }

}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  ll cnt = 0;
  ll m = 0;
  for (ll i = 0; i < N; ++i) {
    ll d1, d2;
    cin >> d1 >> d2;
    if (d1 == d2) {
      cnt += 1;
    }
    else {
      cnt = 0;
    }
    m = max(cnt, m);
  }
  if (m >= 3) {
    cout << "Yes" << "\n";
  }
  else {
    cout << "No" << "\n";
  }
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>

int compare( const void *, const void * );

int main( void ) {
	int i, j, score[ 2 ][ 10 ], sum[ 2 ] = {};

	for ( i = 2; i--;  ) {
		for ( j = 10; j--; scanf( "%d", score[ i ] + j ) ) ;

		qsort( score[ i ], 10, sizeof(int), &compare );

		for ( j = 3; j--; sum[ i ] += score[ i ][ j ] ) ;
	}

	printf( "%d %d\n", sum[ 1 ], sum[ 0 ] );

	return 0;
}

int compare( const void *a, const void *b ) {
	return *(int *)b - *(int *)a;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void)
{
	int n,k;
	
	scanf("%d %d",&n,&k);
	
	
	
	double sum = 0;
	
	
	
	for(int i = 1; i <= n; i++){
		int temp = i;
		double ans = 1/(double)n;
		if(temp < k){
			while(temp < k){				
				ans = ans*0.5;
				temp= temp * 2;
			}
			sum = sum + ans;
		}else{
			sum = sum + 1/(double)n;
		}
	}
		
				
	
	printf("%.10lf\n",sum);
	
	return 0;
	
}
		
		
			
			
			
			
			
		
	
	
	

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30
typedef pair<int,int> pii;
int main() {
  int n;
  while(cin>>n,n) {
    vector<pii> v;
    while(n--) {
      int c;
      cin >> c;
      int time = 0;
      REP(i,4) {
        int m,s;
        cin >> m >> s;
        time += m*60+s;
      }
      v.push_back(pii(time,c));
    }
    sort(ALL(v));
    cout << v[0].second << endl;
    cout << v[1].second << endl;
    cout << v[v.size()-2].second << endl;
  }
}

Measured memory_bytes: 0
l=[]
n=int(input())
for i in range(n):
  a,b=map(int,input().split())
  l.append((a,b,a+b))
l=sorted(l,key=lambda t: t[2],reverse=True)
x=y=0
for i in range(n):
  if i%2==0:
    x+=l[i][0]
  else:
    y+=l[i][1]
print(x-y)

Measured memory_bytes: 22904
/* A Naive recursive implementation of LCS problem */
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 3123;

char X[MAXN];
char Y[MAXN];
string resp;

int pd[MAXN][MAXN];

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
int lcs(int m, int n)
{
	if(pd[m][n] != -1)
		return pd[m][n];

	if (m == 0 || n == 0)
		return pd[m][n] = 0;
	if (X[m-1] == Y[n-1])
		return pd[m][n] = ( 1 + lcs(m-1, n-1) );
	else
		return pd[m][n] = max(lcs(m, n-1), lcs(m-1, n));
}

/* Driver code */
int main()
{
	scanf("%s\n%s", X, Y);

	int m = strlen(X);
	int n = strlen(Y);

	memset(pd, -1, sizeof(pd));
	lcs(m, n);

	int i=m;
	int j=n;
	while((i>0) && (j>0)){
		// cout << pd[i][j] << ' ';

		if(X[i-1] == Y[j-1]){
			resp += Y[j-1];
			i-=1;
			j-=1;
		}
		else if(pd[i-1][j] > pd[i][j-1])
			i-=1;
		else
			j-=1;
	}

	reverse(resp.begin(), resp.end());
	cout << resp << endl;

	return 0;
}

// This code is contributed by rathbhupendra 


Measured memory_bytes: 38656
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	int min_score = 100;
	int sum = 0;
	
	int tmp_score = 1;
	
	for(int i=0; i<n; i++){
		cin >> tmp_score;
		sum += tmp_score;
		if (tmp_score%10!=0 && tmp_score<min_score){
			min_score = tmp_score;
		}
	}
	
	if (min_score==100){
		cout << "0\n";
	}else{
		if (sum%10==0){
			cout << (sum - min_score) << "\n";
		}else{
			cout << sum << "\n";
		}
	}
		
	return 0;
	
}

Measured memory_bytes: 888
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

a = []
for i in range(n - 1):
    a.append(x[i+1] - x[i])

b = []
for i in range(m - 1):
    b.append(y[i+1] - y[i])

s = 0
for i in range(1, n):
    s += i * (n - i) * a[i-1]
    s = s % (10 ** 9 + 7)

t = 0
for i in range(1, m):
    t += i * (m - i) * b[i-1]
    t = t % (10 ** 9 + 7)

print((s * t) % (10 ** 9 + 7))


Measured memory_bytes: 87268
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define fr first
#define sc second
#define INFTY 100000000
typedef pair<int,int > iiP;
typedef pair<double,iiP> P;
struct Edge{
  int to,Distance;
  Edge(){}
  Edge(int to,int Distance):to(to),Distance(Distance){};
};
int n,City,p,Start,Goal;
double Time[31][1<<8];
bool used[31][1<<8];
vector< int > ticket;
vector< vector< Edge > > info;
double Dijkstra();
int main(){

  while(cin >> n >> City >> p >> Start >> Goal && n){
  info.resize(City+1);
  for(int i=0,t;i<n;i++){
    cin >> t;
    ticket.push_back(t);
  }
  for(int i=0,x,y,z;i<p;i++){
    cin >> x >> y >> z;
    info[x].push_back(Edge(y,z));
    info[y].push_back(Edge(x,z));
  }
  double ans = Dijkstra();
  if(ans == -1) cout << "Impossible" << endl;
  else cout << fixed << setprecision(7) << ans << endl;
  info.clear();
  ticket.clear();
  }
}
double Dijkstra(){
  double min = INFTY;
  for(int i=0;i<31;i++){
    for(int j=0;j<(1<<8);j++){
      Time[i][j] = INFTY;
      used[i][j] = false;
    }
  }
  Time[Start][(1<<n)-1] = 0.0;
  priority_queue< P,vector<P>,greater<P> > que;
  que.push(P(0.0,iiP(Start,(1<<n)-1)));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int now = p.sc.fr,TIC = p.sc.sc;
    double cost = p.fr;
    if(now == Goal)return cost;
    if(used[now][TIC]) continue;
    used[now][TIC] = true;
    for(int i=0;i<info[now].size();i++){
      Edge e = info[now][i];
      for(int j=0;j<n;j++){
        if(!(1 & TIC>>j)) continue;
        double t = cost + (double)e.Distance/(double)ticket[j];
        if(t < Time[e.to][TIC & ~(1<<j)]){
          Time[e.to][TIC & ~(1<<j)] = t;
          que.push(P(t,iiP(e.to,TIC & ~(1<<j))));
        }
      }
    }
  }
  return -1;
}

Measured memory_bytes: 2732
N = int(input())
P = list(map(int, input().split()))

ans = 0
mins = [10**6]
for i in P:
    v = min(mins[-1], i)
    mins.append(v)
mins.pop(0)

ans = 0
for i, j in zip(P, mins):
    if i <= j:
        ans += 1
print(ans)


Measured memory_bytes: 24744
n, m, q = list(map(int, input().split(' ')))

aq = [None] * q
bq = [None] * q
cq = [None] * q
dq = [None] * q
for i in range(q):
    aq[i], bq[i], cq[i], dq[i] = list(map(int, input().split(' ')))

result = 0

def dfs(i, ary):
    global result
    if i == n:
        val = 0
        for j in range(q):
            if ary[bq[j] - 1] - ary[aq[j] - 1] == cq[j]:
                val += dq[j]
        if result < val:
            result = val
    else:
        if ary == []:
            for c in range(1, m + 1):
                dfs(i + 1, [c])
        else:
            l = ary[-1]
            for c in range(l, m + 1):
                dfs(i + 1, ary + [c])

dfs(0, [])

print(result)



Measured memory_bytes: 71980
#include<bits/stdc++.h>
using namespace std;
int n,k;
long long dp[2010][2010],a[1010];
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;++i)scanf("%lld",a+i);
    for(int i=1;i<=n;++i){
    	dp[i][0]=a[i];
        for(int j=1;j<n;++j){
            int y=i-j;if(y<1)y+=n;
            dp[i][j]=min(dp[i][j-1],a[y]);
		}
	}
	long long mn=1e18;
	for(int i=0;i<n;++i){
	    long long ans=0;
	    for(int j=1;j<=n;++j)ans+=dp[j][i];
	    mn=min(mn,(long long)i*k+ans);
	}
	cout<<mn<<endl;
}


Measured memory_bytes: 31616
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

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

int main() {
    string S;
    cin >> S;

    // 97
    // cout << 'a' - 0 << endl;

    int C[26];
    REP(0, i, 26) {
        C[i] = 0;
    }

    REP(0, i, S.length()) {
        C[S[i] - 97]++;

        if(C[S[i] - 97] > 1) {
            cout << "no" << endl;
            return 0;
        }
    }

    cout << "yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,ans;
	scanf("%lld",&n);
	for(int i=sqrt(n);i>0;i--)
	{
		if(n%i==0)
        {
            ans=n/i;
            break;	
        }  		
	}
	int w=0;
	while(ans>0)
	{
		w++;
		ans/=10;
	}
	printf("%d\n",w);
	return 0;
}

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

typedef long long ll;
const int N = 1e5 + 10;
int cnt[N];

int main()
{
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; i ++)
        cin >> x, sum += x, cnt[x] ++;
    ll q, b, c;
    cin >> q;
    while (q--)
    {
        cin >> b >> c;
        sum += (c - b) * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }
    

}


Measured memory_bytes: 3972
#include<iostream>
using namespace std;
typedef long long int ll;

int main(){
	ll W, H, x, y;
	cin >> W >> H >> x >> y;
	cout << (double)W * (double)H / 2.0 << " " << ((W == 2 * x && H == 2 * y) ? 1 : 0) << 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,K;
int A[222222];

vint pos[222222];
int nex[222222];
int dist[222222];
signed main(){
	cin>>N>>K;
	rep(i,N)cin>>A[i];
	rep(i,N)pos[A[i]].pb(i);
	rep(i,222222){
		if(pos[i].size()==0)continue;
		rep(j,pos[i].size()){
			int x;
			if(j+1<pos[i].size()){
				x=pos[i][j+1];
			}
			else{
				x=pos[i][0];
			}
			nex[pos[i][j]]=x;
		}
	}


	memset(dist,-1,sizeof(dist));
	int v=0;
	int d=1;
	while(true){
		int u=nex[v];
		int nd=d;
		if(u<=v)nd++;
		if(nd>K)break;
		u++;
		if(u==N){
			u=0;
			nd++;
		}
		if(nd>K)break;
		v=u;
		d=nd;
		if(dist[v]!=-1){
			int m=d-dist[v];
			int tmp=(K-d)/m;
			d+=tmp*m;
			break;
		}
		dist[u]=nd;
	}


	vint ans;
	while(d<=K){
		int u=nex[v];
		int nd=d;
		if(u<=v)nd++;
		if(nd>K){
			ans.pb(A[v]);
			v++;
			if(v==N){
				v=0;
				d++;
			}
			continue;
		}

		v=u+1;
		d=nd;
		if(v==N){
			v=0;
			d++;
		}
	}
	if(ans.size()){
		rep(i,ans.size()){
			if(i)printf(" ");
			printf("%lld",ans[i]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 19700
import java.util.*;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int a, b;

	String[] line = sc.nextLine().split(" ");
	a = Integer.parseInt(line[0]);
	b = Integer.parseInt(line[1]);

	int menseki = a * b;
	int shu = 2 * a + 2 * b;
	System.out.println(menseki + " " + shu);
    }
}

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    a = ii()
    for _ in range(3):
        ii()
    e = ii()
    k = ii()
    print('Yay!') if e - a <= k else print(':(')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
'use strict'
function main(input) {
  input = input.trim().split(' ')
  const r = Number(input[0])
  const D = Number(input[1])
  let ans = [Number(input[2])]

  for (let i = 1; i <= 10; i++) {
    ans[i] = r * ans[i - 1] - D
  }

  ans.shift()
  console.log(ans.join('\n'))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7628
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+5;
char s[N];
int fa[N];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    if(s[1]=='0'||s[n-1]=='0'||s[n]=='1'){
        puts("-1");
        return 0;
    }
    for(int i=1;i<n;i++){
        if(s[i]!=s[n-i]){
            puts("-1");
            return 0;
        }
    }
    int p=1;
    for(int i=2;i<=n/2+1;i++){
        fa[i]=p;
        if(s[n/2-(i-1)+1]=='1')
            p=i;
    }
    for(int i=n/2+2;i<=n;i++)
        fa[i]=1;
    for(int i=2;i<=n;i++)
        printf("%d %d\n",i,fa[i]);
}


Measured memory_bytes: 1664
from collections import Counter

# https://atcoder.jp/contests/abc152/submissions/15835670


def fast_prime_factorization_many(lst):
    # 素因数分解（ロー法、複数）
    from subprocess import Popen, PIPE
    res = Popen(["factor"] + list(map(str, lst)), stdout=PIPE).communicate()[0].split(b"\n")[:-1]
    return [Counter(list(map(int, r.split()[1:]))) for r in res]


def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    if N == 1:
        print(1)
        exit(0)

    mod = int(1e9+7)
    Factors = fast_prime_factorization_many(A)
    # print(Factors)
    # lcmを求める
    lcm = 1
    max_factor = [0] * (1000010)
    for f in Factors:
        for k, v in f.items():
            v_prev = max_factor[k]
            if v_prev < v:
                for i in range(v-v_prev):
                    lcm = lcm * k % mod
                max_factor[k] = v

    ans = 0
    for a in A:
        wk = lcm * pow(a, mod-2, mod)
        # print(wk)
        ans += wk
        ans %= mod
    print(ans)
    exit(0)


main()


Measured memory_bytes: 90116
#include <iostream>

using namespace std;

int main(){
    int a, b, c;
    int n = 0, r;
    cin >> a >> b >> c;
    for (int i = a; i <= b; i ++){
        r = c % i;
        if (r == 0) {
            n++;
        } else {
            continue;
        }
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3112
while line = gets
    next if line.to_s.strip == ""
    line_array = line.split(" ")
    start_time = (line_array[0].to_i * 60) + line_array[1].to_i
    end_time = (line_array[2].to_i * 60) + line_array[3].to_i
    time = end_time - start_time - line_array[4].to_i
    puts time
end

Measured memory_bytes: 14324
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,k;
vector<pair<int,int> >v;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		v.push_back(make_pair(x,i));
	}
	vector<int>ans;int pre1=-1,pre2;
	for(int i=1;i<=k+1;i++){
		sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		for(int i=0;i<v.size();i++){
			if(v[i].second!=pre1){
				pre2=v[i].second;
				ans.push_back(v[i].second);
				if(--v[i].first<0){
					puts("-1");return 0;
				}
			}
		}
		pre1=pre2;
	}
	cout<<ans.size()<<endl;
	for(int x:ans)cout<<x<<" ";
	return 0;
}

Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
ll a[100009];
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                n = i*i+j*j+k*k+i*j+j*k+k*i;
                if(n<=10000)
                    a[n]++;
            }
        }
    }
    cin>>n;
    for(i=1;i<=n;i++)
        cout<<a[i]<<endl;
    return 0;
}



Measured memory_bytes: 3668
// Coordinate compression

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)




int solve(){     
 
  int mx=1e14;
  int n,w;
  cin>>n>>w;
 int dp[100100];
 rep(i,0,100010)dp[i]=mx;
 
 rep(j,0,n)
 {
  int x,y;
  cin>>x>>y;
    for(int i=100010-y;i>=0;i--)
    {
      if(dp[i]!=mx)
      {
        dp[i+y]=min(dp[i+y],dp[i]+x);
      }
    }
     dp[y]=min(dp[y],x);
 }
 int ans=0;
 rep(i,0,100010)if(dp[i]<=w)ans=i;
 cout<<ans;

return 0;
}

 
signed main()
{    

 

   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);  

 
 int t=1;                                                                                                                  
 //cin>>t;
    while(t--)
     {
      solve();
     }
    return 0;
}

Measured memory_bytes: 1024
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	bool ok = true;
	if (s[0] != 'A') ok = false;
	if (s.substr(2, s.size() - 3).find('C') == string::npos) ok = false;
	int caps = 0;
	for (int i = 1; i < s.size(); ++i) {
		if ('A' <= s[i] && s[i] <= 'Z') ++caps;
	}
	if (caps != 1) ok = false;
	cout << (ok ? "AC" : "WA") << endl;
	return 0;
}

Measured memory_bytes: 256