akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> S(100, vector<int>(100, 0));



void black(int startX, int finX, int startY, int finF){

//  vector<vector<int>> S(H, vector<int>(W,0));

  for(int i = startX; i < finX; i++){
    for(int j = startY; j < finF; j++){
      if(S.at(j).at(i)==0){
        S.at(j).at(i) = 1;
      }
    }
  }


/*  for(int j = 0; j < 4; j++){
    for(int i = 0; i < 5; i++){
   //   if(S.at(j).at(i)==1){
        cout << S.at(j).at(i);
     // }
    }
    cout << endl;

  }

  cout << endl;
*/
}


int main(){
  int W, H, N;
  cin >> W >> H >> N;

  vector<int> x(N);
  vector<int> y(N);
  vector<int> a(N);

  for(int i = 0; i < N; i++){
    cin >> x.at(i) >> y.at(i) >> a.at(i);
  }

//  vector<vector<int>> S(H, <int>(W, 0));



  for(int i = 0; i < N; i++){
    if(a.at(i)==1){
    black(0, x.at(i), 0, H);

    } else if(a.at(i)==2){
    black(x.at(i), W, 0, H);

    } else if(a.at(i)==3){
    black(0, W, 0, y.at(i));

    }else if(a.at(i)==4){


    black(0, W, y.at(i), H);

    }
  }


 int count = 0;
 for(int i = 0; i < W; i++){
   for(int j = 0; j < H; j++){
     if(S.at(j).at(i)==0){
       count++;
     }
   }
 }

 cout << count << endl;

}




Measured memory_bytes: 256
//File Name: arc073_C.cpp
  //Created Time: 2017年05月14日 星期日 14时54分17秒
                                   
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL solve(const int n,const int t){
	LL res(0);
	int pre,now;
	scanf("%d",&pre);
	for(int i(2);i<=n;++i){
		scanf("%d",&now);
		if(now >= pre + t){
			res += t;
			pre = now;
		}
		else{
			res += now - pre;
			pre = now;
		}
	}
	res += t;
	return res;
}
int main(){
	int n,t;
	scanf("%d %d",&n,&t);
	printf("%lld\n",solve(n,t));
	return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
int_list=[int(input()) for i in range(N)]
min = 10**9
int_list.sort()
for i in range (K - 1,len(int_list)):
    if int_list[i] - int_list[i - K + 1] < min:
        min = int_list[i] - int_list[i - K + 1]

print(min)

Measured memory_bytes: 7484
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  map<string,int> mp;
  rep(i,n){
    string s;
    cin >> s;
    mp[s]=0;
  }
  cout << mp.size() << endl;
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vikas.k
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = 0;

            for (int i = 0; i < 3; i++) {
                a = a * 10 + in.nextInt();
            }

            if (a % 4 == 0) {
                out.print("YES");
                return;
            }
            out.print("NO");
        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
#include <iostream>

using namespace std;

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


int main() {
    int n;
    cin>>n;
    
    long long int sum = 0;
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                int ans1 = gcd(i,j);
                int ans2 = gcd(ans1,k);
                
                sum+=ans2;
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String W = sc.nextLine();
        String[] T;
        T = new String[1000];
        int i = 0;
        int count = 0;
        while(true){
            T[i] = sc.next();
            if(T[i].equals("END_OF_TEXT")){
                break;
            }
            if(T[i].equalsIgnoreCase(W)){
                count++;
            }
            i++;
        }
        System.out.println(count);
    }    
}


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

using namespace std;

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

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

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

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

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

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

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

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

    lint dp1[20][1000];
    fill(dp1[0], dp1[20], -1LL);

    lint dp2[1000];
    fill(dp2, dp2 + t, -1LL);

    rep(i, n){
        lint a;
        cin >> a;
        chmax(dp1[0][a % t], a);
    }

    rep(i, 19){
        rep(j, t){
            chmax(dp1[i + 1][j], dp1[i][j]);
            rep(k, t){
                if(dp1[i][j] >= 0LL && dp1[i][k] >= 0LL){
                    chmax(dp1[i + 1][(j + k) % t], dp1[i][j] + dp1[i][k]);
                }
            }
        }
    }

    rep(i, 20){
        if(!(m >> i & 1)){
            continue;
        }
        lint dp3[1000];
        rep(j, t){
            dp3[j] = dp2[j];
        }
        rep(j, t){
            chmax(dp3[j], dp1[i][j]);
            rep(k, t){
                if(dp1[i][j] >= 0LL && dp2[k] >= 0LL){
                    chmax(dp3[(j + k) % t], dp1[i][j] + dp2[k]);
                }
            }
        }
        rep(j, t){
            dp2[j] = dp3[j];
        }
    }

    rrep(j, t - 1){
        chmax(dp2[j], dp2[j + 1]);
    }

    int q;
    cin >> q;

    while(q--){
        int a, b;
        cin >> a >> b;
        if(dp2[a] >= 0LL && dp2[a] / t >= b){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    cout << flush;

    return 0;
}


Measured memory_bytes: 3284
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
//to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {

	int n;
	string s;
	cin >> n >> s;
	rep(i, s.size()) {
		if (char(s[i] + n) > 'Z') {
			cout << char(s[i] + n - 26);
		}
		else {
			cout << char(s[i] + n);
		}
	}
	cout << rt;

	please AC;
}
//参考：---

Measured memory_bytes: 256
import sys
read_=sys.stdin.buffer.readline
N=int(read_())
A=input().split()
if len(A)==1:
    print(A[0])
    exit()
if N%2==0:
    ans=A[1::2][::-1]
    ans.extend(A[::2])
else:
    ans=A[::2][::-1]
    ans.extend(A[1::2])
print(' '.join(ans))

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

int main(){
    long long N, T;
    cin >> N >> T;
    long long ti[N];

    for(long i=0; i<N; i++){
        cin >> ti[i];
    }

    long long ttotal, tprev;
    long long shower;
    ttotal=0;
    shower=0;
    tprev=-T;
    for(long i=0; i<N; i++){
        ttotal = ti[i];
        if( tprev + T <= ttotal ){
            shower += T;
        }else{
            shower += (ttotal + T) - (tprev + T);
        }
        tprev = ttotal;        
    }

    cout << shower << endl;

    return 0;
}

Measured memory_bytes: 1792
x, y = map(int, input().split())

G = [(1, 3, 5, 7, 8, 10, 12),
     (4, 6, 9, 11),
     (2,)]
for g in G:
    if x in g and y in g:
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int N,Y;
    cin>>N>>Y;
    Y/=1000;
    //cout<<Y<<endl;
    int i=0,j=0,k=0;
    bool flag=false;
    for( i=0;i<=Y/10+1;++i){
        for( j=0;j<=Y/5+1;++j){
            k=N-i-j;
            if(10*i+5*j+k==Y&&k>=0){
                flag=true;
                break;
            }
            
        }
        if(flag)break;
    }
    
    if(flag){
        cout<<i<<" "<<j<<" "<<k<<endl;
    }else{
        cout<<-1<<" "<<-1<<" "<<-1<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>
#include <cstring>
using namespace std;

#define REPEAT(i, n) for(int i=0;i<(n);i++)

#define INF 1<<28

#define SIZE 200
#define OFFSET 100

typedef pair<int, int> point;

int field[SIZE][SIZE];

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

void init() {
    memset(field, -1, sizeof(field));
}

int main() {
    int t, n;
    while (cin >> t >> n) {
        if (t == 0 && n == 0) break;
        init();
        REPEAT(i, n) {
            int x, y;
            cin >> x >> y;
            field[x+OFFSET][y+OFFSET] = INF;
        }
        int sx, sy; cin >> sx >> sy;
        field[sx+OFFSET][sy+OFFSET] = 0;
        queue<point> Q; Q.push(point(sx, sy));
        while (!Q.empty()) {
            point cur = Q.front(); Q.pop();
            if (field[cur.first+OFFSET][cur.second+OFFSET] == t) {
                continue;
            }
            REPEAT(i, 6) {
                int cx = cur.first;
                int cy = cur.second;
                int nx = cx+dx[i];
                int ny = cy+dy[i];
                if (field[nx+OFFSET][ny+OFFSET] == -1) {
                    Q.push(point(nx, ny));
                    field[nx+OFFSET][ny+OFFSET] = field[cx+OFFSET][cy+OFFSET]+1;
                }
            }
        }
        int count = 0;
        REPEAT(i, SIZE) {
            REPEAT(j, SIZE) {
                if (field[i][j] != -1 && field[i][j] != INF) count++;
            }
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 1080
def f(L):
    X=0
    for k in L:
        X+=2**(k-1)
    return X

N,M=map(int,input().split())
H=2**N
inf=float("inf")

DP=[inf for _ in range(H)]
DP[0]=0

for _ in range(M):
    A,B=map(int,input().split())
    C=f(list(map(int,input().split())))

    for k in range(H):
        DP[k|C]=min(DP[k|C],DP[k]+A)

if DP[-1]==inf:
    print(-1)
else:
    print(DP[-1])

Measured memory_bytes: 75988
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
#define MAX(a, b) ((ll)(a) > (ll)(b)) ? (ll)(a) : (ll)(b)
#define MIN(a, b) ((ll)(a) > (ll)(b)) ? (ll)(b) : (ll)(a)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}};

ll min(ll a, ll b){
	if (a < b)
		return a;


		return b;
}


ll N, K;
vector<ll> A, B;



vector<ll> a;
ll b[30];



ll is_zero(ll a, ll k) {

	return ((a & (ll)pow(2, k)) == 0);
}

bool check(ll a, ll k) {


	



	if (k != -1) {
		for (int i = k; i < 30; i++) {

			if ((b[i] == 0 || i == k) && !is_zero(a, i))
				return false;

			
		}

	}

	else {
		for (int i = 0; i < 30; i++) {
			if (b[i] == 0 && !is_zero(a, i))
				return false;
		}
	}

	return true;
}


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

	ll u, v;

	rep(i, N) {
		cin >> v >> u;

		A.push_back(v);
		B.push_back(u);

	}

	rep(i, 30) {
		if ((K & (ll)pow(2.0, i)) != 0) {
			a.push_back(i);
			b[i] = 1;
		}
		

	}
	ll ans = 0;
	ll finalans = 0;
	reverse(a.begin(), a.end());


	rep(i, a.size()+1) {
		rep(j, N) {

			if (i != a.size()) {
				if (check(A[j], a[i]) == true) {

					ans += B[j];

				}

			}


			else {
				if (check(A[j], -1) == true)
					ans += B[j];

			}



		}


		finalans = MAX(ans, finalans);
		ans = 0;
	}


	
	cout << finalans << endl;
	

	return 0;
}

Measured memory_bytes: 2036
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    while True:
        n = I()
        if n == 0:
            break
        a = LS()
        r = None
        for i in range(n):
            if a[i] == 'x':
                if i > 0 and a[i-1] == 'x':
                    r = 'none'
                    break
            else:
                a[i] = int(a[i])
                if i > 0 and a[i-1] != 'x':
                    if i % 2 == 0:
                        if a[i-1] <= a[i]:
                            r = 'none'
                            break
                    elif a[i-1] >= a[i]:
                        r = 'none'
                        break
        if r:
            rr.append(r)
            continue
        ma = -inf
        mi = inf
        for i in range(n):
            if a[i] != 'x':
                continue
            if i % 2 == 0:
                if i > 0:
                    mi = min(mi, a[i-1]-1)
                if i < n-1:
                    mi = min(mi, a[i+1]-1)
            else:
                ma = max(ma, a[i-1]+1)
                if i < n-1:
                    ma = max(ma, a[i+1]+1)
        if ma == mi:
            rr.append(ma)
        elif ma == -1 or mi == inf:
            rr.append('ambiguous')
        elif ma > mi:
            rr.append('none')
        else:
            rr.append('ambiguous')



    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9136
import os
import sys

import numpy as np


def solve(inp):
    def dfs(links, s, checked, postorder):
        stack = [0, s]
        while stack:
            i, v = stack[-2:]
            if i == 0 and checked[v]:
                stack.pop()
                stack.pop()
                continue
            checked[v] = 1
            if i == len(links[v]):
                postorder.append(v)
                stack.pop()
                stack.pop()
                continue
            stack[-2] += 1
            stack.append(0)
            stack.append(links[v][i])

    def dfs2(rev_links, s, checked):
        q = [s]
        checked[s] = 1
        scc = [s]
        while q:
            v = q.pop()
            for u in rev_links[v]:
                if checked[u] == 0:
                    q.append(u)
                    checked[u] = 1
                    scc.append(u)
        return scc

    n = inp[0]
    m = inp[1]
    aaa = inp[2::2]
    bbb = inp[3::2]

    int_list = [0]
    int_list.clear()
    links = [int_list.copy() for _ in range(n)]
    rev_links = [int_list.copy() for _ in range(n)]

    for i in range(m):
        a = aaa[i]
        b = bbb[i]
        if a != b:
            links[a].append(b)
            rev_links[b].append(a)
    links = [list(set(link)) for link in links]
    rev_links = [list(set(link)) for link in rev_links]

    checked = np.zeros(n, np.int8)
    postorder = []

    for v in range(n):
        if checked[v]:
            continue
        dfs(links, v, checked, postorder)

    postorder.reverse()
    checked = np.zeros(n, np.int8)
    sccs = []

    for v in postorder:
        if checked[v]:
            continue
        sccs.append(dfs2(rev_links, v, checked))

    return sccs


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(len(ans))
for scc in ans:
    print(len(scc), *scc)


Measured memory_bytes: 310160
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const ll N=100005;
ll p[N],pp[N],bb[N];
ll power(ll x,ll y){
	ll re=1;
	while(y>0){
		if(y%2)re=re*x%hell;
		y=y/2;
		x=x*x%hell;
	}
	return re;
}
ll fun(ll n,ll k){
	ll re=p[n]*power(p[k],hell-2)%hell;
    re=re*power(p[n-k],hell-2)%hell;
	return re;
}
int main(){
	ll n,k;
	cin>>n>>k;
	ll a[n+1],sum1=0,sum2=0;
	for(ll i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(ll i=1;i<=n;i++){
		pp[i]=a[i];
		bb[i]=a[n-i+1];
	}
	for(ll i=n-1;i>=1;i--)pp[i]=(pp[i]+pp[i+1])%hell;
	for(ll i=n-1;i>=1;i--)bb[i]=(bb[i]+bb[i+1])%hell;
	p[0]=1;
	for(ll i=1;i<N;i++)p[i]=p[i-1]*i%hell;
	for(ll i=k;i<=n;i++){
		sum1=(sum1+fun(i-2,k-2)*pp[i]%hell)%hell;
		sum2=(sum2+fun(i-2,k-2)*bb[i]%hell)%hell;
		//cout<<sum1<<" "<<sum2<<endl;
	}
	cout<<(sum1-sum2+hell)%hell;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a, b;
	int s;
	int length;
	int o[1001];
	cin >> s;
	cin >> length;
	for (int i = 0; i < length; i++){
		cin >> a >> b;
		if (s % 2 == 0){
			if (a > s / 2){
				a = s + 1 - a;
			}
			if (b > s / 2) {
				b = s + 1 - b;
			}
		}else{
			if (a > s / 2 + 1) {
				a = s + 1 - a;
			}
			if (b > s / 2 + 1) {
				b = s + 1 - b;
			}	
		}
		o[i] = min(a, b) % 3;
		if (o[i] == 0){
			o[i] = 3;
		}
	}
	for (int i = 0; i < length; i++){
		cout << o[i] << endl;
	}
	char c;
	cin >> c;
}

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

#define sq(x) ((x)*(x))
const long long M = 1e9+7;

long long gcdExtended(long long a, long long b, long long *x, long long *y) 
{ 
    if (a == 0) { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    long long x1, y1;
    long long gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 

long long modInverse(long long b, long long m) 
{ 
    long long x, y;
    long long g = gcdExtended(b, m, &x, &y); 
  
    // Return -1 if b and m are not co-prime 
    if (g != 1) 
        return -1; 
    return (x%m + m) % m; 
} 
  
// Function to compute a/b under modlo m 
long long modDivide(long long a, long long b) 
{ 
    long long inv = modInverse(b, M); 
    assert(inv !=-1);
    return (inv * a) % M; 
} 

long long perm(long long x, long long y){
    if(y==0){
        return 1;
    }
    return (x* perm(x-1, y-1))%M;
}

long long pow2(long long x, long long y){
    if(y==0)
        return 1;
    if(y==1)
        return x;
    return y&1 ? (x*pow2(sq(x)%M, y>>1))%M : (pow2(sq(x)%M, y>>1))%M;
}

long long comb(long long x, long long y){
    return y<x-y ? modDivide(perm(x, y),perm(y, y)) : modDivide(perm(x, x-y),perm(x-y, x-y));
}
    
int main(){
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    printf("%lld", (pow2(2, n)-comb(n, a)-comb(n, b)-1+M*5)%M);
    return 0;
}

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

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		n = 1000 - n;
		int ans = 0;
		while (n >= 500) {
			n -= 500;
			ans++;
		}
		while (n >= 100) {
			n -= 100;
			ans++;
		}
		while (n >= 50) {
			n -= 50;
			ans++;
		}
		while (n >= 10) {
			n -= 10;
			ans++;
		}
		while (n >= 5) {
			n -= 5;
			ans++;
		}
		while (n >= 1) {
			n -= 1;
			ans++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};


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

    int n;
    cin >> n;
    n = n%1000;
    if(n) n = 1000-n;
    cout << n << endl;

    return 0;
}


Measured memory_bytes: 3648
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BPath {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int a, b;
	    map<int, int> mp;
	    for(int i=0; i<3; i++){
	        in >> a >> b;
	        mp[a]++;
	        mp[b]++;
	    }

	    int one=0, two=0;
	    for(auto const& e : mp){
	        if(e.second == 1) one++;
	        if(e.second == 2) two++;
	    }

	    ans2(one==two, out);
	}
};


int main() {
	BPath solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

using mint = atcoder::modint998244353;
const mint inv9 = mint(1) / 9;

struct S { // when 23
    mint num; // num = 23
    mint multiplier; // multiplier = 10^2
    unsigned int value () const { return num.val(); }
};

struct F {
    mint num;
};

S op(S l, S r) { return S{l.num * r.multiplier + r.num, l.multiplier * r.multiplier}; }

S e() { return S{0, 1}; }

S mapping(F l, S r) { return S{l.num == 0 ? r.num : ((r.multiplier-1) * inv9 * l.num) , r.multiplier}; }

F composition(F l, F r) { return F{l.num == 0 ? r.num : l.num}; }

F id() { return F{0}; }

void solve(long long N, long long Q, std::vector<long long> L, std::vector<long long> R, std::vector<long long> D){
    vector<S> a(N+1);
    rep(i,1,N+1) {
        a[i] = S{1, 10};
    }
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    rep(qi,0,Q) {
        seg.apply(L[qi], R[qi]+1, F{D[qi]});
        cout << seg.prod(1, N+1).value() << endl;
    }
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> L(Q);
    std::vector<long long> R(Q);
    std::vector<long long> D(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
        scanf("%lld",&D[i]);
    }
    solve(N, Q, std::move(L), std::move(R), std::move(D));
    return 0;
}


Measured memory_bytes: 14596
#include<iostream>
using namespace std;
int a,b;
int main(){
	while(cin>>a>>b){
		int c=a+b;
		if(c/1000000>=1){
			cout<<7<<endl;
		}
		else if(c/100000>=1){
			cout<<6<<endl;
		}
		else if(c/10000>=1){
			cout<<5<<endl;
		}
		else if(c/1000>=1){
			cout<<4<<endl;
		}
		else if(c/100>=1){
			cout<<3<<endl;
		}
		else if(c/10>=1){
			cout<<2<<endl;
		}
		else{
			cout<<1<<endl;
		}
	}
	return 0;
}			


Measured memory_bytes: 2992
#include<iostream>
#include<cstring>
using namespace std;
void print(      pair<long long int,long long int> *tree,int i)
{
  int br=1;
  int cnt=1;
  for(int x=0;x<i;x++)
    {
      cout<<"<"<<(*(tree+x)).first<<","<<(*(tree+x)).second<<"> ";
      if(cnt==br)
	{
	  cout<<endl;
	  br*=2;
	  cnt=1;
	}
      else
	cnt++;


    }
}

int main()
{
  int n,r,l;
  for(;cin>>n>>r>>l;)
    {
      // id,score;
      pair<long long int,long long int> tree[n*2-1];
      for(int i=0;i<n*2-1;i++)
	tree[i]=make_pair(0,-1);
      long long int time[n+1];
      memset(time,0,sizeof(time));
      //初期化
      for(int i=1;i<=n;i++)
	{
	  int num=(i-1)+(n-1);
	  tree[num].first=i;
	  tree[num].second=0;
	  pair<long long int ,long long int>base;
	  while(true)
	    {
	      num=(num-1)/2;

	      if(num*2+2<n*2-1 &&
		 (
		  tree[num*2+1].second < tree[num*2+2].second ||
		  (tree[num*2+1].second ==  tree[num*2+2].second && tree[num*2+1].first > tree[num*2+2].first)
		  )
		 )
		base=tree[num*2+2];
	      else
		base=tree[num*2+1];
	      tree[num]=base;
	      if(num==0)break;
	    }
	}
      int oldtime=0;
      //print(tree,n*2-1);
      for(int i=0;i<r;i++)
	{
	  int d,t,x;
	  cin>>d>>t>>x;
	  time[tree[0].first]+=(t-oldtime);
	  oldtime=t;

	  //木の更新
	  d--;
	  int num=d+(n-1);
	  //	  tree[num].first=i;
	  tree[num].second+=x;
	  pair<long long int ,long long int>base;
	  while(true)
	    {
	      num=(num-1)/2;
	      if(num*2+2<n*2-1 &&
		 (
		 tree[num*2+1].second < tree[num*2+2].second ||
		 (tree[num*2+1].second ==  tree[num*2+2].second && tree[num*2+1].first > tree[num*2+2].first)

		  )
		 )
		base=tree[num*2+2];
	      else
		base=tree[num*2+1];
	      tree[num]=base;
	      if(num==0)break;
	    }

	}
      time[tree[0].first]+=(l-oldtime);
      long long int max_time=0;
      long long int max_id;
      for(int i=n;i>0;i--)
	{
	  if(max_time<=time[i])
	    {
	      max_time=time[i];
	      max_id=i;
	    }
	}
      cout<<max_id<<endl;
    }

}

Measured memory_bytes: 5072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> c(n - 1), s(n - 1), f(n - 1);
	rep(i,n - 1) cin >> c.at(i) >> s.at(i) >> f.at(i);
	rep(i,n - 1){
		int t = 0;
		for(int j = i; j < n - 1; j++){
			if(t <= s.at(j)) t = s.at(j);
			else if((t - s.at(j)) % f.at(j) != 0) t += f.at(j) - (t - s.at(j)) % f.at(j);
			t += c.at(j);
		}
		cout << t << endl;
	}
	cout << 0 << endl;
}


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

int main(){
    ll n,k;
    cin >> n >> k;
    ll x = n;
    ll ans;
    x = x % k;
    if(abs(x) >= abs(x-k)){
        ans = abs(x-k);
    }else{
        ans = abs(x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

r =I()

print(r * r)


Measured memory_bytes: 43636
#include <stdio.h>
int main(){
    int n,i,j,ok=0;
    scanf("%d",&n);
    for(i=0;4*i<=n;i++){
        for(j=0;7*j<=n-4*i;j++)if(4*i+7*j==n)ok=1;
    }
    if(ok)printf("Yes");
    else printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int main(){
	int H, W;
	cin >> H >> W;
	const int sx = 0, sy = 0, gx = W-1, gy = H-1;
	int mazemap[H][W];
	int blockcount = 0;
	for( int i=0; i<H; i++){
		string temp;
		cin >> temp;
		for( int j=0; j<W; j++ ){
			if( temp[j] == '#' ){
				mazemap[i][j] = -1;
				blockcount++;
			}
			else{
				mazemap[i][j] = 0;
			}
		}
	}
	queue<pair<int, int>> Q;
	vector<pair<int, int>> BW = {pii(0, 1), pii(0, -1), pii(1, 0), pii(-1, 0)};
	pair<int, int> pos;
	Q.emplace(sx, sy);
	
	while( !Q.empty() ){
		pos = Q.front(); Q.pop();
		int posx = pos.first;
		int posy = pos.second;
		for( auto d : BW ){
			int xins = posx + d.first;
			int yins = posy + d.second;
			if(
				mazemap[yins][xins] == 0
				&&
				( xins != 0 || yins != 0 ) 
				&&
				0 <= xins && xins < W
				&&
				0 <= yins && yins < H
			){
				mazemap[yins][xins] = mazemap[posy][posx] + 1;  
				Q.emplace(xins, yins);
			}
		}
	}
	if( mazemap[gy][gx] ){
		cout << H*W - blockcount - mazemap[gy][gx] - 1 << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}

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

using namespace std;

int n, k;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> k;
    if ((n + 1) / 2 >= k) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

typedef long long LL;

int main(void){
    LL n, k;
    cin >> n >> k;
    bool f = true;
    LL tmp;
    LL x = k;
    int cnt = 0;
    if(n / k > 1){
        n = n % k + k;
    }
    while(f){
        tmp = llabs(n - k);
        if (tmp >= n)f = false;
        else if (tmp == 0){
            n = 0;
            f = false;
        }
        else n = tmp;
    }
    cout << n << endl;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
mi = L[0]
co = 1
for i in range(1, N):
  mi = min(L[i], mi)
  if L[i] == 1:
    co += 1
    break
  elif mi == L[i]:
    co += 1
print(co)

Measured memory_bytes: 32208
N = int(input())
A_INPUT = list(map(int, input().split()))

A = A_INPUT[:]

import bisect
for i in range(N):
    sorted_list = A[:i]
    v = A[i]
    unsorted_list = A[i+1:]
    bisect.insort(sorted_list, v)
    
    
        
    A = sorted_list + unsorted_list
    print(' '.join(map(str,A)))
    


Measured memory_bytes: 5632
N = int(input())
H = list( map(int, input().split(" ")) )

count = 0
count_max = 0

for i in range(0, len(H)-1):
    if H[i] >= H[i+1]:
        count += 1
    else:
        if count_max < count:
            count_max = count
        count = 0
if count_max < count:
    count_max = count
print(count_max)

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

using namespace std;

const int INF = 1 << 29;

struct Bipartite_Matching
{
  vector< vector< int > > graph;
  vector< int > match;
  vector< bool > used;

  Bipartite_Matching(int n)
  {
    graph.resize(n);
  }

  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  bool dfs(int v)
  {
    used[v] = true;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(w == -1 || (!used[w] && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return (true);
      }
    }
    return (false);
  }

  int bipartite_matching()
  {
    int ret = 0;
    match.assign(graph.size(), -1);
    for(int i = 0; i < graph.size(); i++) {
      if(match[i] == -1) {
        used.assign(graph.size(), false);
        ret += dfs(i);
      }
    }
    return (ret);
  }
};

int main()
{
  int N, M, L;
  int cost[100][100];
  int p[1000], t[1000];

  while(scanf("%d %d %d", &N, &M, &L), L) {
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) cost[i][j] = INF;
      cost[i][i] = 0;
    }

    for(int i = 0; i < M; i++) {
      int u, v, d;
      scanf("%d %d %d", &u, &v, &d);
      cost[u][v] = cost[v][u] = d;
    }
    for(int i = 0; i < L; i++) {
      scanf("%d %d", &p[i], &t[i]);
    }

    for(int k = 0; k < N; k++) {
      for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
          cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
        }
      }
    }

    Bipartite_Matching flow(L + L);
    for(int i = 0; i < L; i++) {
      for(int j = 0; j < L; j++) {
        if(i == j) continue;
        if(t[j] - t[i] >= cost[p[i]][p[j]]) {
          flow.add_edge(i, j + L);
        }
      }
    }
    printf("%d\n", L - flow.bipartite_matching());
  }
}

Measured memory_bytes: 8404
# -*- coding: utf-8 -*-
class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return

        if x<y:
            self.par[y] = x
        else:
            self.par[x] = y

    def same(self, x, y):
        return self.find(x) == self.find(y)


n,m = map(int, input().split())
uf = UnionFind(n+m)

for u in range(n):
    line = list(map(int, input().split()))
    k = line[0]
    for l in line[1:]:
        lng = n+l-1
        uf.unite(u, lng)

flag = True
for u in range(1,n):
    if not uf.same(0,u):
        flag = False
        break
if flag:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 12180
#include<stdio.h>

int main(void)
{
  int tate,yoko;
  int x,y;

  while(1){
    scanf("%d %d",&x,&y);
    if(x == 0 && y == 0)
    break;
  else 
    for(tate = 0; tate < x; tate++){
      for(yoko = 0; yoko < y; yoko++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

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

signed main(void)
{
	int a, b, c;
	set<int> s;
	cin >> a >> b >> c;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	cout << s.size() << endl;
	return 0;
}


Measured memory_bytes: 256
X = int(input())

def is_prime(n):
  if n == 2:
  	return True
  if n % 2 == 0:
    return False
  f = 3
  while f * f <= n:
    if n % f == 0:
      return False
    else:
      f += 2
  return True

for i in range(X, 10**6):
  if is_prime(i):
    print(i)
    break

Measured memory_bytes: 3060
H,W=map(int, input().split())
N=int(input())
A=[0]+list(map(int, input().split()))

M=[[0 for _ in range(W)] for __ in range(H)]
i=1
for y in range(H):
    if y&1:
        for x in range(W):
            if A[i]==0: i+=1
            M[y][x]=i
            A[i]-=1
    else:
        for x in range(W-1,-1,-1):
            if A[i]==0: i+=1
            M[y][x]=i
            A[i]-=1

for line in M: print(' '.join(map(str,line)))


Measured memory_bytes: 40560
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <algorithm>

using namespace std;

int main() {
	long long int K;
	cin >> K;
	long long int Q = K / 50 - 1;
	int amari = K % 50;
	int zero = 50 - amari - 1;
	vector<long long int> v;
	for (int i = 0; i < 50; i++) {
		v.push_back(i + 1);
	}
	if (amari != 0) {
		v[zero] = 0;
		Q += 1;
	}
	for (int i = 0; i < 50; i++) {
		v[i] += Q;
	}
	cout << 50 << endl;
	cout << v[0];
	for (int i = 1; i < 50; i++) {
		cout << " " << v[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

int main()
{
	vector<int> num(5);
	for (int i = 0; i < 5; i++)
	{
		cin >> num[i];
		if (num[i] == 0) {
			cout << i + 1 << endl;
			break;
		}
	}
}


Measured memory_bytes: 3600
# https://atcoder.jp/contests/abc070/tasks/abc070_c

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def gcd(x: int, y: int) -> int:
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x, y = y, r
    return x


def main():
    n = input_int()
    T = list(set([input_int() for _ in range(n)]))
    ans = T[0]
    for t in T[1:]:
        ans = ans * t // gcd(ans, t)
    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 62256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e7 + 10;
const ll INF = 9e18;

int T;
ll N, A, B, C, D;
map<ll, ll> mp;

ll dp(ll x) {
    if (x == 0) return 0;
    if (x == 1) return D;
    if (mp.count(x)) return mp[x];
    ll res = INF;
    if (res / D > x) res = x * D;

    ll l2 = (x/2)*2;
    ll r2 = ((x+1)/2)*2;
    ll l3 = (x/3)*3;
    ll r3 = ((x+2)/3)*3;
    ll l5 = (x/5)*5;
    ll r5 = ((x+4)/5)*5;

    res = min(res, llabs(l2-x)*D + A + dp(l2/2));
    res = min(res, llabs(r2-x)*D + A + dp(r2/2));

    res = min(res, llabs(l3-x)*D + B + dp(l3/3));
    res = min(res, llabs(r3-x)*D + B + dp(r3/3));

    res = min(res, llabs(l5-x)*D + C + dp(l5/5));
    res = min(res, llabs(r5-x)*D + C + dp(r5/5));


    return mp[x] = res;
}

int main() {
#ifdef ACM_LOCAL
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif
    cin >> T;
    while (T--) {
        mp.clear();
        cin >> N >> A >> B >> C >> D;
        cout << dp(N) << endl;
    }

    return 0;
}

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

/*
同じ色なら単調増加
色の数を決め打つ
a[i]未満の一番大きいところに入れるのが最適

6
1 2 3 3 4 5
*/

ll n,a[100010],cnt=0,lis[100010];

void init(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)lis[i]=-1e18;
}

int main(void){
	init();
	lis[0]=a[0];
	cnt=1;
	reg(i,1,n-1){
		// cerr<<i<<": ";
		// rep(j,cnt)cerr<<lis[j]<<" ";
		// cerr<<endl;
		ll l=cnt-1,r=0;
		if(lis[l]>=a[i]){
			lis[cnt]=a[i];
			cnt++;
			continue;
		}
		if(lis[r]<a[i]){  // これいる？
			lis[r]=a[i];
			continue;
		}
		while(l-r>1){
			ll mid=(l+r)/2;
			if(lis[mid]>=a[i]){
				r=mid;
			}else{
				l=mid;
			}
		}
		lis[l]=a[i];
	}
	// cerr<<n<<": ";
	// rep(i,cnt)cerr<<lis[i]<<" ";
	// cerr<<endl;
	cout<<cnt<<endl;
	return 0;
}

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

using namespace std;

void solve(int K, int A, int B) {
  cout << ((B / K - (A - 1) / K) > 0 ? "OK" : "NG") << endl;
}

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

  int K, A, B;
  cin >> K >> A >> B;

  solve(K, A, B);

  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
double pi =3.14159265358979322846264338327950288;
int main(){
    std::cout<<std::fixed<<std::setprecision(10);
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    //cout<<c<<endl;
    double dig = abs(abs((1.0/2.0)*(60*c+d))-6.0*d);
    if(d==0)dig=abs(360-(1.0/2.0)*(60*c+d));
    double co =cos(dig*(pi/180.0));
    //cout<<co<<endl;
    double ans = (a*a)+(b*b)-(a*b*2*co);
    cout<<sqrt(ans)<<endl;
   
}

Measured memory_bytes: 4136
using System;

namespace AtCoder.ABC._123
{
    class b
    {
        static void Main(string[] args)
        {
            int[] menu = new int[5];
            var line = "";
            for (var i = 0; i < 5; i++)
            {
                line = Console.ReadLine().Trim();
                menu[i] = int.Parse(line);
            }
            var cnt = 0;
            var min = 10;
            for(var i = 0; i < 5; ++i)
            {
                var m = menu[i] % 10;
                if(min > m && m != 0)
                {
                    min = m;
                }
                if(m == 0)
                {
                    cnt += menu[i];
                }
                else
                {
                    cnt += menu[i] - m + 10;
                }
            }
            if(min == 10)
            {
                min = 0;
            }
            else
            {
                cnt -= 10;
            }
            Console.WriteLine(cnt + min);
        }
    }
}


Measured memory_bytes: 11092