akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;

int main(){
    int N, M; 
    cin >> N >> M;
    vector<int> city(N);
    for (int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        city[a-1] += 1;
        city[b-1] += 1;
    }
    for (int i=0; i<N; i++){
        cout << city[i] << endl;
    }
}

Measured memory_bytes: 3608
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
product = 1
if A[0]==0:
  print(0)
else:
  for i in range(len(A)):
    product *= A[i]
    if product > 10**18:
      print(-1)
      break
if product <= 10**18 and A[0]!=0:
  print(product)

Measured memory_bytes: 21544
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;

int main(int argc, char const *argv[]) {
  int a;
  int b;
  cin >> a;
  cin >> b;

  string a_str = "";
  for (int i = 0; i < b; i++) {
    a_str += to_string(a);
  }
  string b_str = "";
  for (int i = 0; i < a; i++) {
    b_str += to_string(b);
  }

  if (a_str < b_str){
    cout << a_str;
  } else {
    cout << b_str;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int[] sa = new int[7];
		for(int i=0;i<7;i++){
		int a = sc.nextInt();
		int b = sc.nextInt();
		 sa[i] = a-b;
		}
		for(int i = 0;i<7;i++){
			System.out.println(sa[i]);
		}
	}

}

Measured memory_bytes: 17168
# import sys
import bisect

# sys.setrecursionlimit(4100000)


# def inputs(num_of_input):
#     ins = [input() for i in range(num_of_input)]
#     return ins


# def bis_insert(L, target, top=None, bottom=None):
#     if top is None:
#         top = len(L)
#     if bottom is None:
#         bottom = 0

#     while bottom < top:
#         half = (top + bottom) // 2
#         if target > L[half]:
#             bottom = half + 1
#         else:
#             top = half
#     return bottom


def solve(inputs):
    L = string_to_int(inputs)
    L.sort()
    total_count = 0
    for i in range(len(L) - 2):
        for j in range(i + 1, len(L)-1):
            a = L[i]
            b = L[j]
            target = a + b
            # r = bis_insert(L, target)
            r = bisect.bisect_left(L, target)
            total_count += r - j - 1
    return total_count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(input())
    print(ret)


Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 1005;
char sl[nax][nax];

const int mod = 1e9 + 7;

void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

int main() {
    int h, w;
    scanf("%d%d", &h, &w);
    for(int row = 0; row < h; ++row) {
        scanf("%s", sl[row]);
    }
    vector<vector<int>> dp(h, vector<int>(w));
    dp[0][0] = 1;
    for(int row = 0; row < h; ++row) {
        for(int col = 0; col < w; ++col) {
            for(int r2 : {row, row + 1}) {
                int c2 = col;
                if(r2 == row) {
                    c2 = col + 1;
                }
                if(r2 < h && c2 < w && sl[r2][c2] == '.') {
                    add_self(dp[r2][c2], dp[row][col]);
                }
            }
        }
    }
    printf("%d\n", dp[h-1][w-1]);
}

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

using namespace std;

typedef long long int lli;

lli employees[4001];
bool checked[4001];

signed main()
{
	lli n;
	while (cin >> n, n) {
		for (lli i = 1; i <= 4000; ++i) employees[i] = checked[i] = false;

		vector<lli> ans;

		for (lli i = 0; i < n; ++i) {
			lli num, a, b; cin >> num >> a >> b;

			if (checked[num]) continue;

			employees[num] += a * b;

			if (employees[num] >= 1000000) {
				ans.push_back(num);
				checked[num] = true;
			}
		}

		if (ans.empty()) cout << "NA" << endl;

        for (lli i = 0; i < ans.size(); ++i) {
            cout << ans[i] << endl;
        }
	}
}

Measured memory_bytes: 1268
#include<stdio.h>
int main(){
  int a,b;
  char op;
  scanf("%d %c %d",&a,&op,&b);

  while(1){
    if(op=='?'){
      break;
    }

  else if(op=='+'){

    printf("%d\n",a+b);

  }else if(op=='-'){

    printf("%d\n",a-b);

  }else if(op=='*'){

    printf("%d\n",a*b);

  }else if (op=='/' ){

    printf("%d\n",a/b);

    }

  else{
    printf("Erroe\n");

  }

    scanf("%d %c %d",&a,&op,&b);
    
  }
  
      return 0;
}

Measured memory_bytes: 600
// 2020-07-17 08:36:05
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  using P = pair<int, int>;
  int n;
  cin >> n;
  priority_queue<P> que;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    que.emplace(b, a);
  }
  int cur = que.top().first;
  while(!que.empty()) {
    int b, a;
    tie(b, a) = que.top(); que.pop();
    chmin(cur, b);
    cur -= a;
    if(cur < 0) {
      cout << "No" << '\n';
      return;
    }
  }
  cout << "Yes" << '\n';
  return;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

int main() {
    string s1,s2;
    cin>>s1>>s2;
    int n1=s1.size(),n2=s2.size();
    if(n1!=n2){cout<<"No";return 0;}
    bool b=0,b2;
    for(int i=0;i<n1;i++){
        for(int j=0;j<n1;j++){
            if(s1[i]==s2[j]){
                b2=1;
                for(int k=0;k<n1;k++){
                    if(s1[(i+k)%n1]!=s2[(j+k)%n1])b2=0;
                }
                if(b2==1){cout<<"Yes";return 0;}
            }
        }
    }
    cout<<"No";
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static boolean find(Tree T, long k){
        Node x = T.root;
        while(true){
            if(x == null)
                break;
            if(x.key == k)
                return true;
            else if(k < x.key)
                x = x.left;
            else 
                x = x.right;
        }
        return false;
    }
    public static void inorder(Node root){
        if(root == null)
            return;
        if(root.left != null)
            inorder(root.left);
        System.out.print(" " + root.key);
        if(root.right != null)
            inorder(root.right);
    }
    public static void preorder(Node root){
        if(root == null)
            return;
        System.out.print(" " + root.key);
        if(root.left != null)
            preorder(root.left);
        if(root.right != null)
            preorder(root.right);
    }
    public static void insert(Tree T, Node k){
        Node y = new Node(0);
        Node x = T.root;
        while(x != null){
            y = x;
            if(k.key < x.key)
                x = x.left;
            else
                x = x.right;
        }
        k.parent = y;
        if(y == null)
            T.root = k;
        else if(k.key < y.key)
            y.left = k;
        else
            y.right = k;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        String nul = sc.next();
        Node first = new Node(sc.nextInt());
        Tree T = new Tree(first);
        for(int i = 1 ; i < m ; i++){
            String order = sc.next();
            if(order.equals("print")){
                inorder(T.root);
                System.out.println();
                preorder(T.root);
                System.out.println();
            }
            else if(order.equals("insert")){
                long v = sc.nextLong();
                insert(T,new Node(v));
            }
            else{
                long k = sc.nextLong();
                if(find(T,k))
                    System.out.println("yes");
                else
                    System.out.println("no");
            }
        }
    }
}
class Tree{
    Node root = null;
    Tree(Node root){
        this.root = root;
    }
}
class Node{
    long key;
    Node parent;
    Node left = null;
    Node right = null;
    Node(long key){
        this.key = key;
    }
}


Measured memory_bytes: 271848
from heapq import heappop, heappush
INF = 10 ** 9 + 7

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

Xx = sorted((x, i) for i, (x, _) in enumerate(X))
Xy = sorted((y, i) for i, (_, y) in enumerate(X))

graph = [[] for _ in range(N)]
for i in range(N - 1):
    graph[Xx[i][1]].append((Xx[i + 1][1], Xx[i + 1][0] - Xx[i][0]))
    graph[Xx[i + 1][1]].append((Xx[i][1], Xx[i + 1][0] - Xx[i][0]))
    
    graph[Xy[i][1]].append((Xy[i + 1][1], Xy[i + 1][0] - Xy[i][0]))
    graph[Xy[i + 1][1]].append((Xy[i][1], Xy[i + 1][0] - Xy[i][0]))

min_cost = [INF] * N
visited = [False] * N

pq = []
heappush(pq, (0, 0))
ret = 0

while pq:
    cost, u = heappop(pq)
    if visited[u]:
        continue
    visited[u] = True
    min_cost[u] = cost
    ret += cost
    for v, c in graph[u]:
        if min_cost[v] > c:
            heappush(pq, (c, v))
            
print(ret)


Measured memory_bytes: 124120
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.HashSet;
import java.util.Scanner;

/**
 * Created by Harry on 5/3/20.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        HashSet set = new HashSet();
        for(int s=0; s<k; s++){
            int d = scanner.nextInt();
            for(int i=0; i<d; i++){
                set.add(scanner.nextInt());
            }
        }
        System.out.println(n-set.size());
    }

}


Measured memory_bytes: 46416
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
typedef long long ll;
const int maxn = 100005;
const int maxm = 105;
const int mod = 998244353;
const int inf = 1e9 + 7;
//head
vector<int> G[maxn];
int main() {
    string s;
    cin >> s;
    bool ok = true;
    if(s.back() == '1') ok = false;
    if(sz(s) > 1 && s[0] == '0') ok = false;
    for(int i = 0; i < sz(s)/2; ++i) {
        if(s[i] != s[sz(s)-2-i]) ok = false;
    }
    if(ok) {
        int cur = 1;
        for(int i = 1; i < sz(s); ++i) {
            G[cur].pb(i+1);
            if(s[i-1] == '1') {
                cur = i+1;
            }
        }
        for(int i = 1; i <= sz(s); ++i) {
            for(auto v : G[i]) {
                printf("%d %d\n", i, v);
            }
        }
    }
    else cout << -1 << endl;
    return 0;
}


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

int main() {
  long int k, a, b;
  long int out;
  cin >> k >> a >> b;
  if(b - a < 2){
    out = k + 1;
  }else if(k - 1 < a){
    out = k + 1;
  }else if((k - a + 1) % 2 == 0){
    out = a + ((k - a + 1) / 2) * (b - a);
  }else{
    out = a + 1 + ((k - a + 1) / 2) * (b - a);
  }
  cout << out;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
using namespace std;

int
main(int argc, char *argv[])
{
  int k, x;
  cin >> k >> x;
  int m = max(x - k + 1, -1000000);
  int M = min(x + k - 1, 1000000);
  for (int i = m; i <= M; i++) cout << i << " ";
  cout << endl;
  return 0;
}


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

using namespace std;

int N, A[100100], K;
int memo[100100];
int dp(int n) {
	if (n == 1) return 0;
	if (n < 1) return 1e9 + 7;
	int &ans = memo[n];
	if (ans != -1) return ans;
	ans = 1e9 + 7;
	for (int i = 1; i <= K; i++) {
		ans = min(ans, dp(n - i) + abs(A[n] - A[n - i]));
	}

	return ans;
}
int main() {
	memset(memo, -1, sizeof(memo));
	cin >> N >> K;
	A[0] = -(1e9 + 7);
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	cout << dp(N) << endl;
	return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)

int main(){
    int n,z,w;
    cin >> n >> z >> w;
 	vector<int> a(n);
    rep(i,n) cin >> a[i];
    if(n == 1){
		cout << abs(a[n-1] - w) << endl;
    }else{
    	cout << max(abs(a[n-1] - w), abs(a[n-1] - a[n-2])) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 100005
int a[N],mx,n,mn,pm,pn;
int siz;pair<int ,int >ans[N];
int main()
{
	scanf("%d",&n);mx=-0x3f3f3f3f,mn=0x3f3f3f3f;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),(mx<a[i]?(mx=a[i],pm=i):0),(mn>a[i]?(mn=a[i],pn=i):0);
	if(pm==pn)
	{
		if(n==1)return printf("%d\n",mx),0;
		pn++;
	}
	for(int i=1;i<=n;i++)
		if(i!=pm&&i!=pn)
			if(a[i]<0)ans[++siz]=make_pair(mx,a[i]),mx-=a[i];
			else ans[++siz]=make_pair(mn,a[i]),mn-=a[i];
	ans[++siz]=make_pair(mx,mn);
	printf("%d\n",mx-mn);
	for(int i=1;i<=siz;i++)printf("%d %d\n",ans[i].first,ans[i].second);
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vstr=vector<string>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    int n;
    cin>>n;
    vin d(n);
    rep(i,n)cin>>d[i];
    int sum=0;
    rep(i,n-1){
        rep2(j,i+1,n){
            sum+=d[i]*d[j];
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{

    public static void solve(String s , String t){
      if(s.length() == 0){
        System.out.println("Yes");
        return;
      }
      for(int i = 0 ; i < s.length() ; i++){
            if(s.charAt(i) != t.charAt(i)){
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
    }

    public static void gora(){
        Scanner scn = new Scanner(System.in);

        // long test = scn.nextLong();

        String s = scn.nextLine();

        String t = scn.nextLine();

        // long arr[] = new long[n];

        // for(int i = 0 ; i < arr.length ; i++){
        //     arr[i] = scn.nextLong();
        // }

        solve(s, t);
    }

    public static void main(String args[]){
        gora();
    }
}




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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}


void dfs(int v, set<int> &visit, deque<int> &visit2, vector<vector<int>> &G, bool flag) {

    for(int i = 0; i < G[v].size(); i++) {
        if (visit.find(G[v][i]) == visit.end()) {
            visit.insert(G[v][i]);
            //visit2.push_back(G[v][i]);
            
            if (!flag) visit2.push_front(G[v][i]);
            else visit2.push_back(G[v][i]);
            
            dfs(G[v][i], visit, visit2, G, flag);
            return;
        }
    }
    return;
}

void solve() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    set<int> visit;
    deque<int> visit2;
    visit.insert(0);
    visit.insert(G[0][0]);
    visit2.push_back(0);
    visit2.push_back(G[0][0]);

    dfs(G[0][0], visit, visit2, G, true);
    dfs(0, visit, visit2, G, false);

    cout << visit2.size() << endl;
    for (int i = 0; i < visit2.size(); i++) {
        cout << visit2[i] + 1 << " ";
    }
    cout << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

const int mod=1e9+7;
int n,k;
long long a[100010];
long long jc[100010]={1},inv[100010]={1};

long long pow(long long a,int b)
{
	long long ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}

long long c(int n,int m)
{
	return jc[n]*inv[m]%mod*inv[n-m]%mod;
}

int main()
{
	// freopen("test.in","r",stdin);
	scanf("%d%d",&n,&k);
	if(k==1)
	{
		puts("0");
		return 0;
	}
	for(int i=1;i<=n;i++)
		scanf("%lld",a+i),jc[i]=jc[i-1]*i%mod,inv[i]=pow(jc[i],mod-2);
	std::sort(a+1,a+1+n);
	for(int i=1;i<=n;i++) a[i]+=a[i-1],a[i]=(a[i]%mod+mod)%mod;
	long long ans=0;
	for(int i=k;i<=n;i++)
	{
		ans+=((a[n]-a[i-1]-a[n-i+1])%mod+mod)%mod*c(i-2,k-2)%mod;
		ans%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
ll mod = 1e9+ 7;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    ll res = 0;
    for(int i=0;i<n;i++){
	ll r = 0,s = 0;
	for(int j=0;j<n;j++)if(a[i] > a[j])s++;
	for(int j=i+1;j<n;j++)if(a[i]> a[j])r++;
	res += ((k*k)%mod*s)%mod - (((k*(k+1))/2)%mod*s)%mod + (r*k)%mod + mod;
	res %= mod;
    }
    cout<<res<<endl;
 
    return 0;
}


Measured memory_bytes: 256
K = input()
N = len(K)
D = int(input())
mod = 10**9+7

dp = [[[0]*D for _ in range(2)] for _ in range(N+1)]
dp[0][0][0] = 1

for i, s in enumerate(K):
    a = ord(s)-48
    for j in range(D):
        for k in range(10):
            b = (j+k)%D
            dp[i+1][1][b] += dp[i][1][j]
            if k<a:
                dp[i+1][1][b] += dp[i][0][j]
            dp[i+1][1][b] %= mod
    
    for j in range(D):
        b = (j+a)%D
        dp[i+1][0][b] += dp[i][0][j]
        dp[i+1][0][b] %= mod

print((dp[N][1][0]+dp[N][0][0]-1)%mod)

Measured memory_bytes: 61532
#[test]
fn test_solve() {
   assert_eq!(solve("5 2\n1 4\n2 5\n"), "1\n");
   assert_eq!(solve("9 5\n1 8\n2 7\n3 5\n4 6\n7 9\n"), "2\n");
   assert_eq!(solve("5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n"), "4\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut div = vec![-1; n];
    use std::cmp::max;
    for _ in 0..m {
        let a: isize = sc.read();
        let b: usize = sc.read();
        div[b-1] = max(div[b-1], a-1);
    }
    let mut x = 0;
    let mut ans = 0;
    for i in 0..n {
        if x <= div[i] {
            x = i as isize;
            ans += 1;
        }
    }

    format!("{}\n", ans)
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}

Measured memory_bytes: 6396
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int partition(int a[],int s,int g){
	int x=a[g];
	int gto=s-1;
	for(int j=s;j<g;j++){
		if(a[j]<=x){
			gto++;
			int alt=a[j];
			a[j]=a[gto];
			a[gto]=alt;
		}
	}
	gto++;
	int alt=a[g];
	a[g]=a[gto];
	a[gto]=alt;
	return gto;
}

int main(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	int m=partition(a,0,n-1);
	rep(i,n){
		if(i==m)cout<<"["<<a[i]<<"]";
		else cout<<a[i];
		if(i!=n-1)cout<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1548
const MOD: u64 = 1e9 as u64 + 7;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let s: Vec<char> = sc.chars();
    let m = s.len();

    let mut dp = vec![0; n + 1];
    dp[0] = 1;
    for _ in 0..n {
        let mut next = vec![0; n + 1];
        for i in 0..(n + 1) {
            if i == 0 {
                next[0] += dp[i];
                next[0] %= MOD;
            } else {
                next[i - 1] += dp[i];
                next[i - 1] %= MOD;
            }
            if i < n {
                next[i + 1] += dp[i] * 2;
                next[i + 1] %= MOD;
            }
        }
        dp = next;
    }

    let inv2 = mod_pow(2, MOD - 2);
    let inv_pow = mod_pow(inv2, m as u64);
    println!("{}", (dp[m] * inv_pow) % MOD);
}

fn mod_pow(x: u64, mut e: u64) -> u64 {
    let mut result = 1;
    let mut cur = x;
    while e > 0 {
        if e & 1 == 1 {
            result *= cur;
            result %= MOD;
        }
        cur = (cur * cur) % MOD;
        e >>= 1;
    }
    result
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main() {
    string s;
    cin>>s;
    int ans[26]={0};
    for(int i=0;i<s.length();i++){
        ans[s[i]-'a']++;
    }
    int f=0;
    for(int i=0;i<26;i++){
        if(ans[i]%2!=0){
            f=1;break;
        }
    }
    if(f==1)cout<<"No"<<endl;
    else cout<<"Yes"<<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;
using ll = long long;
using p = pair<int,int>;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> ac(n),pena(n);
  rep(i,m){
    int a;
    string b;
    cin >> a >> b;
    a--;
    if( ac[a] == 1 )continue;
    if( b == "AC") ac[a] = 1;
    else if( b == "WA") pena[a] ++;
  }
  int ok = 0, ng = 0;
  rep(i,n){
    ok += ac[i];
    if( ac[i] == 1 ) ng += pena[i];
  }
  cout << ok << " " << ng << endl;
  return 0;
} 


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

int main() {
  string s;
  cin >> s;
  if (s == "RRR")
    cout << 3 << endl;
  else if (s == "RRS" || s == "SRR")
    cout << 2 << endl;
  else if (s == "SRS" || s == "RSR" || s == "SSR" || s == "RSS")
    cout << 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

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

int main() {
	char str[10001];

	while (cin >> str != NULL) {
		int joi = 0, ioi = 0;
		REP(i,strlen(str) - 2) {
			if (strncmp(&str[i], "IOI", 3) == 0) ioi++;
			else if (strncmp(&str[i], "JOI", 3) == 0) joi++;
		}

		printf("%d\n%d\n", joi, ioi);
	}
	return 0;
}

Measured memory_bytes: 1132
S = input()
T = input()

d = len(S)-len(T)

cntlist = []
for i in range(d+1):
    cnt = 0
    s = S[i:i+len(T)]
    for j in range(len(T)):
        cnt += T[j] == s[j]
    cntlist.append(cnt)

print(len(T)-max(cntlist))

Measured memory_bytes: 9052
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int 			long long int
#define pll 			pair<ll , ll>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b) {
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) {
	return mod_pow(a , mod-2);
}

void solve() {
    
    int n , k;
    
    cin >> n >> k;
    
    int ans = 0;
    
    int a[n];
    
    for(int i = 0; i < n; ++i) {
    	cin >> a[i];
    }
    
    sort(a , a+n);
    
    for(int i = 0; i < n-k; ++i) {
    	ans += a[i];
    }
    
    cout << ans;
}       

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


Measured memory_bytes: 5208
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;cin>>x;
  bool flag;
  for(int i=x;i<x*2;i++){
    flag = true;
    for(int j=2;j<i;j++) if(i%j==0){flag=false;break;}
    if(flag){cout<<i;return 0;}
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

#include<iostream>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

static const int N = 1005;

int n;
ll K;
int dp[N][N];

int main()
{
	scanf("%d",&n);
	string s1,s2;
	for(int k=0;k<n;k++){
		//scanf("%s",&s1);
		//scanf("%s",&s2);
		cin >> s1 >> s2;
		s1 = ' ' + s1;
		s2 = ' ' + s2;
		for(int i=0;i<s1.size();i++)dp[i][0]=0;
		for(int i=0;i<s2.size();i++)dp[0][i]=0;
		for(int i=1;i<s1.size();i++){
			for(int j=1;j<s2.size();j++){
				if(s1[i]==s2[j]){
					dp[i][j] = dp[i-1][j-1]+1;
				}else{
					dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
				}
				//printf("%d\n",dp[i][j]);
			}
		}
		printf("%d\n",dp[s1.size()-1][s2.size()-1]);
	}

	return 0;
}



Measured memory_bytes: 7080
N = int(input())
a1 = [0]
a = a1+list(map(int,input().split()))
count=0
for i in range(1,N+1):
    if(i%2==1):
        if(a[i]%2==1):
            #print(i,a[i])
            count+=1
#print(a)
print(count)

Measured memory_bytes: 9180
for e in iter(input,'0'):
 a=[list(map(int,input().split()))for _ in[0]*int(e)]
 b=[list(map(int,input().split()))for _ in[0]*int(input())]
 for s,t in b:
  u,v=a[0]
  x,y=s-u,t-v
  for u,v in a:
   if[u+x,v+y]not in b:break
  else:print(x,y)


Measured memory_bytes: 5980
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input()) - 1
print(arr[k])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define MAXN 300
#define INF 1000000000
   
using namespace std;
queue<int>q[MAXN+6];
int vis[MAXN+6];
bool vvis[MAXN+80];
void get(int &v)
{
	char c;
	while((c=getchar())!=EOF&&isdigit(c)==0);
	v=c-'0';
	while((c=getchar())!=EOF&&isdigit(c))
		v=(v<<1)+(v<<3)+c-'0';
	return ;
}
int get()
{
	int v;
	char c;
	while((c=getchar())!=EOF&&isdigit(c)==0);
	v=c-'0';
	while((c=getchar())!=EOF&&isdigit(c))
		v=(v<<1)+(v<<3)+c-'0';
	return v;
}
int chk(int n,int m)
{
	int i,pos=1;
	memset(vis,0,sizeof(vis));
	for(i=1;i<=n;i++)
		vis[q[i].front()]++;
	for(i=2;i<=m;i++)
		if(vis[pos]<vis[i])
			pos=i;
	return pos;
}
int main()
{
	int n,m,i,j,ans,tmp;
	get(n);
	get(m);
	ans=n;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			q[i].push(get());
	do{
		ans=min(ans,vis[tmp=chk(n,m)]);
		vvis[tmp]=1;
		for(i=1;i<=n;i++)
			while(q[i].size()&&vvis[q[i].front()])
				q[i].pop();
	}while(q[1].size());
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
const int mod=1000000007;
const int INF=1e18;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int ans=(n/500) * 500;
    n-=ans;
    ans*=2;
    ans=ans+(n/5)*5;
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(float,input().split()))
dp=[[0] *(n+1) for _ in range(n+1)]
#print(dp)
dp[0][0]=1.0
for i in range(n):
  for j in range(n):
    dp[i+1][j+1]+=dp[i][j]*p[i]
    dp[i+1][j]+=dp[i][j]*(1-p[i])
#print(dp)

ans=0
for i in range((n+1)//2,n+1):
  ans+=dp[n][i]
  #print("dp[n][i]",dp[n][i],"ans",ans)
print(ans)

Measured memory_bytes: 202852
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

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

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

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

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())

#sum = 0

# for i in range(N-1):
#     sum += (i + 1)

#sum = int((N * (N+1)) / 2 - N)
#sum = (N * (N+1)) / 2 - N

#print(sum)

print((N-1) * N // 2)


Measured memory_bytes: 5372
#include <bits/stdc++.h>
using namespace std;
 
int main()
{ 
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
 
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++)
		cin >> a[i];
	int ans = 0;
	int cnt = 1;
	for(int i=0; i<n; i++){
		if (a[i] != cnt) {
			++ans;
			continue;
		}
		++cnt;
	}
 
	if (cnt == 1) cout << "-1\n";
	else cout << ans << "\n";
 
	return 0;
	return 0; 
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		long n = s.nextLong();
		
		int ctr = 0;
		long num = 0;
		
		while(n>num*26+26) {
			num = num*26+26;
			ctr++;
		}
		n = n-num-1;
		while(ctr>=0) {
			long ans = (long)(Math.pow(26, ctr));
			long r = (n/ans);
			System.out.print((char)(r+97));
			n = n%ans;
			ctr--;
		}
		
		
	}

}


Measured memory_bytes: 35816
import sys
a=int(input())
i=a
if a==2:
  print(2)
  sys.exit()
while True:
  b=int(i**0.5)
  judge=False
  for j in range(2,b+2):
    if i%j==0:
      i+=1
      judge=True
      break
    else:
      continue
  if judge==False:
    print(i)
    sys.exit()

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main() {
	int x;
	
	cin >> x;

	if (1<=x && x<1200) {
		cout << "ABC" << endl;
	}
	if (1200 <= x && x<= 3000) {
		cout << "ARC" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
// C - /\/\/\/
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<int> E(100000),O(100000);//[value]<count>
	int maxE=0,maxO=0,e1=0,e2=0,o1=0,o2=0;
	rp(i, 0, N/2){
		int e,o; scanf("%d%d",&e,&o); e--,o--;
		E[e]++;
		if(E[e] > e1){ e1 = E[e]; maxE = e+1; }
		else if(E[e] > e2) e2 = E[e];
		O[o]++;
		if(O[o] > o1){ o1 = O[o]; maxO = o+1; }
		else if(O[o] > o2) o2 = O[o];
	}
	cout<< N - (maxE!=maxO? e1+o1: max(e1+o2, e2+o1)) <<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main(){
    int k, n; cin >> k >> n;
    vector<int> a(n);
    ll sum = 0;
    int maxDistance = 0;

    rep(i,n) cin >> a[i];
    
    rep(i, n-1) {
        sum += a[i];
        int distance = a[i+1]-a[i];
        if(distance > maxDistance) maxDistance = distance;
    }
    
    int distance = (k-a[n-1]) + (a[0]);
    if(distance > maxDistance) maxDistance = distance;
    
    cout << k-maxDistance << endl;
        
    


}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        String inputNameA;
        String inputNameB;
        int numberOfA;
        int numberOfB;
        String choiceName;

        Scanner scanner = new Scanner(System.in);
        String inputName = scanner.nextLine();
        String inputNum = scanner.nextLine();
        choiceName = scanner.nextLine();
        scanner.close();

        String[] editInputName = inputName.split(" ");
        inputNameA = editInputName[0];
        inputNameB = editInputName[1];
        String[] editInputNum = inputNum.split(" ");
        numberOfA = Integer.parseInt(editInputNum[0]);
        numberOfB = Integer.parseInt(editInputNum[1]);

        if (inputNameA.equals(choiceName)) {
            numberOfA--;
        } else if (inputNameB.equals(choiceName)) {
            numberOfB--;
        }

        System.out.println(numberOfA + " " + numberOfB);

    }
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// DON'T USE THESE MACROS DURING ICPC PRACTICE
#define For(i,n) for (int i=0; i<n; i++)
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define Down(i,n) for (int i=n-1; i>=0; i--)
#define DOWN(i,a,b) for (int i=b; i>=a; i--)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<int> vi;

const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ld EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());



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

	int n, k;
	cin >> n >> k;
	cout << (k==1 ? 0 : n-k) << nl;

	return 0;
}


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

using namespace std;

int  main(){
 
  int dis[ 10];
  fill( dis,dis+10 , 0);
  
  for(int i=0 ; i <3;i++)
  {
    int a,b;
    cin>>a>>b;
    dis[a]++;
    dis[b]++;
    
    
  }
  
  int flag = 0 ;
  for( int i=1 ;i <5;i++)
    if( dis[i] > 2)
      flag =1;
  
  if( flag ==1  )
    cout<<"NO";
  else
    cout<<"YES";
  
  
  
  
}

Measured memory_bytes: 3596
main :: IO ()
main = getLine >>= print . solve . toBools

solve :: [Bool] -> Int
solve ss = go 0 ss
  where 
    go _ [] = 0
    go i (s:ss)
      | s == False = go (i+1) ss
      | otherwise = i + go i ss

toBools [] = []
toBools (s:ss) = (if s == 'W'
                 then True
                 else False):toBools ss


Measured memory_bytes: 11388
A = int(input())
B = int(input())
C = int(input())
X = int(input())
flg= 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            tmp = i * 500 + j * 100 + k * 50
            if tmp == X:
                flg += 1

print(flg)

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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;

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

int a[105];

int main()
{
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        sum+=a[i];
    }
    int m;
    cin>>m;
    while(m--){
        int p,x;
        cin>>p>>x;
        cout<<sum-a[p]+x<<endl;
    }
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

int N, Q;
int S[100010];

int main() {
  int ans = 0;

  scanf("%d", &N);
  REP(i, N) scanf("%d", S+i);

  scanf("%d", &Q);
  REP(i, Q) {
    int t;
    scanf("%d", &t);
    auto it = lower_bound(S, S+N, t);
    ans += (it != S+N && t == *it);
  }

  printf("%d\n", ans);
  return 0;
}

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

using namespace std;


using ll = long long;


template<long long M>
class modint {
    public:
        long long a;
        modint(const long long x = 0LL) : a((x % M + M) % M) {}
        long long &value() { return a; }
        modint operator+(const modint rhs) const {
            return modint(*this) += rhs;
        }
        modint operator-(const modint rhs) const {
            return modint(*this) -= rhs;
        }
        modint operator*(const modint rhs) const {
            return modint(*this) *= rhs;
        }
        modint operator/(const modint rhs) const {
            return modint(*this) /= rhs;
        }
        modint &operator+=(const modint rhs) {
            a += rhs.a;
            if (a >= M) {
                a -= M;
            }
            return *this;
        }
        modint &operator-=(const modint rhs) {
            if (a < rhs.a) {
                a += M;
            }
            a -= rhs.a;
            return *this;
        }
        modint &operator*=(const modint rhs) {
            a = a * rhs.a % M;
            return *this;
        }
        modint pow(long long n) const {
            modint ret(1);
            modint x = *this;
            while (n) {
                if ((n & 1) == 1) {
                    ret *= x;
                }
                n >>= 1;
                x *= x;
            }
            return ret;
        }
        modint inv() const {
            return pow(M - 2);
        }
        modint &operator/=(const modint rhs) {
            return *this *= rhs.inv();
        }
};


using mint = modint<1000000007>;


const ll MAX = 100000;
mint fact[MAX + 1];
mint inv[MAX + 1];


void init(ll N) {
    fact[0] = mint(1);

    for (ll i = 1; i <= N; i++) {
        fact[i] = fact[i - 1] * mint(i);
    }
    inv[N] = fact[N].inv();
    for (ll i = N; i >= 1; --i) {
        inv[i - 1] = inv[i] * mint(i);
    }
}


mint comb(ll n, ll k) {
    if (n - k < 0 || k < 0) {
        return 0;
    }
    return fact[n] * inv[k] * inv[n - k];
}



int main() {
    int N, K;

    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    init(N);

    mint ans;
   for (ll i = 0; i < N; i++) {
       ans += (comb(i, K - 1) - comb(N - i - 1, K - 1)) * mint(A[i]);
   }
   cout << ans.a % 1000000007 << endl;

    return 0;
}

/*
int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    init(N);

    mint sigma_max, sigma_min;
    mint ans;
    for (ll i = 0; i < N; i++) {
        ans += (comb(i, K - 1) - comb(N - i - 1, K - 1)) * mint(A[i]);
        // sigma_max += mint(A[i]) * comb(i, K - 1);
        // sigma_min += mint(A[i]) * comb(N - i - 1, K - 1);
    }
    // mint ans = sigma_max - sigma_min;
    cout << ans.a << endl;
}
*/


Measured memory_bytes: 2560
import java.util.Scanner;

/*
ベルトラン・チェビシェフの定理
「任意の自然数 n に対して、n < p ≤ 2n を満たす素数 p が存在する」
*/
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());

        for (int i = x; i < x * 2; i++) {
            if (IsPrime(i)) {
                System.out.println(i);
                break;
            }
        }
    }

    static boolean IsPrime(int n) {
        if (n < 2) return false;
        else if (n == 2) return true;
        else if (n%2 == 0) return false;
        double sqrtNum = Math.sqrt(n);
        for (int i=3; i<=sqrtNum; i+=2) {
            if (n%i == 0) {return false;}
        }
        return true;
    }
}

Measured memory_bytes: 23892
n = gets.to_i
vs = gets.split

oc = Hash.new(0)
ec = Hash.new(0)
(0..n-1).each do |i|
  if i.odd?
    oc[vs[i]] += 1
  else
    ec[vs[i]] += 1
  end
end
ans = 0
oc = oc.sort { |(k1, v1),(k2,v2)| v2<=>v1 }
ec = ec.sort { |(k1, v1),(k2,v2)| v2<=>v1 }
ocmax = oc[0]
ecmax = ec[0]
if ocmax[0] == ecmax[0]
  if ocmax[1] == ecmax[1]
    if ec.dig(1,1).to_i > oc.dig(1,1).to_i
      ans += n - ocmax[1] - ec.dig(1,1).to_i
    else
      ans += n - ecmax[1] - oc.dig(1,1).to_i
    end
  elsif ocmax[1] > ecmax[1]
    ans += n - ocmax[1] - ec.dig(1,1).to_i
  else
    ans += n - ecmax[1] - oc.dig(1,1).to_i
  end
else
  ans += n - ocmax[1] - ecmax[1]
end
puts ans

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    if ( b < a * n ) {
        cout << b << endl;
    }
    else {
        cout << a * n << endl;
    }

    return 0;
}


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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dp[100010];

int main() {

    int  n;
    cin >> n;

    for (int i = 0; i < 100010; i++) {
        dp[i] = INF;
    }

    dp[0] = 0;

    for (int i = 1; i <= n; i++) {
        for (int pow6 = 1; pow6 <= n; pow6 *= 6) {
            if (i-pow6 >= 0)
                chmin(dp[i], dp[i-pow6] + 1);
        }
        for (int pow9 = 1; pow9 <= n; pow9 *= 9) {
            if (i-pow9 >= 0)
                chmin(dp[i], dp[i-pow9] + 1);
        }
    }
    
    cout << dp[n] << endl;

    return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
int main(void){
    int r;cin>>r;co(r*r);
}




Measured memory_bytes: 256
#include<cstdio>
int A,B,sta[4333],n,top,x;
char s[7],t[4333];
int main(){
	scanf("%d%d",&A,&B),n=A+B;
	if(A<=B)return puts("Impossible"),0;
	for(int i=0;i<n;++i)if(!top)sta[++top]=i;else{
		printf("? %d %d\n",sta[top],i),fflush(stdout),scanf("%s",s);
		if(*s=='Y')sta[++top]=i;else--top;
	}
	x=sta[top],t[x]='1';
	for(int i=0;i<n;++i)if(i!=x){
		printf("? %d %d\n",x,i),fflush(stdout),scanf("%s",s);
		t[i]=(*s=='Y')+48;
	}
	printf("! %s\n",t);
	return 0;
}

Measured memory_bytes: 632
#include<iostream>
#include<algorithm>
using namespace std;
 
 
int main(void)
{
    const int N = 5;
    while(1)
    {
        int hand[N];
        char dummy;
        int i, j;
        for(i = 0; i < N; i++)
        {
            if(i)
                cin >> dummy;
            cin >> hand[i];
        }
        if(!cin)
            break;
 
        sort(hand, hand+N);
 
        if(hand[0] == hand[3] ||
            hand[1] == hand[4])
            cout << "four card" << endl;
        else if( (hand[0] == hand[1] && hand[2] == hand[4]) ||
                (hand[0] == hand[2] && hand[3] == hand[4]) )
            cout << "full house" << endl;
        else if( (hand[0] == 1 && hand[1] == 10 && hand[2] == 11 && hand[3] == 12 && hand[4] == 13) ||
            (hand[0]+1==hand[1] && hand[1]+1==hand[2] && hand[2]+1==hand[3] && hand[3]+1==hand[4]) )
            cout << "straight" << endl;
        else if( (hand[0] == hand[2] || hand[1] == hand[3] || hand[2] == hand[4]) )
            cout << "three card" << endl;
        else if( (hand[0]==hand[1] && hand[2]==hand[3]) ||
                (hand[0]==hand[1] && hand[3]==hand[4]) ||
                (hand[1]==hand[2] && hand[3]==hand[4]) )
            cout << "two pair" << endl;
        else if( hand[0]==hand[1] || hand[1]==hand[2] || hand[2]==hand[3] || hand[3]==hand[4] )
            cout << "one pair" << endl;
        else
            cout << "null" << endl;
    }
    return 0;
}

Measured memory_bytes: 0