akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int OFS = 2000;

int N, K;
int imos[6010][6010];
int sum[2010][2010];

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

	rep(i, N) {
		int x, y;
		char c;
		scanf("%d %d %c", &x, &y, &c);

		if (c == 'W') y += K;

		x %= 2*K, y %= 2*K;

		//imos[y][x]++;
		//printf("y = %lld, x = %lld\n", y, x);

		/*
		imos[y][x]++;
		imos[y][x - K]--;
		imos[y - K][x]--;
		imos[y - K][x - K]++;
		*/
		imos[y + OFS][x + OFS]++;
		imos[y + OFS][x - K + OFS]--;
		imos[y - K + OFS][x + OFS]--;
		imos[y - K + OFS][x - K + OFS]++;

		y -= K, x -= K;

		imos[y + OFS][x + OFS]++;
		imos[y + OFS][x - K + OFS]--;
		imos[y - K + OFS][x + OFS]--;
		imos[y - K + OFS][x - K + OFS]++;
	}

	rrange(y, 0, 6005) {
		rrange(x, 0, 6005) {
			imos[y][x] += imos[y][x + 1];
		}
	}

	rrange(y, 0, 6005) {
		rrange(x, 0, 6005) {
			imos[y][x] += imos[y + 1][x];
		}
	}

	rep(i, 6005) rep(j, 6005) sum[i%(2*K)][j%(2*K)] += imos[i][j];

	int mx = 1;

	rep(y, 2005) {
		rep(x, 2005) {
			chmax(mx, sum[y][x]);
		}
	}

	cout << mx << endl;
}




Measured memory_bytes: 157056
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int sum;

		if( A <= B -1) {
			sum = 2 * B - 1;
		}else if( A < B + 1 && A > B - 1) {
			sum = A + B;
		}else {
			sum = 2 * A - 1;
		}

		System.out.println(sum);
	}

}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll pre[100005];
int nod(int x)
{
    int cnt=0;
    while(x>0)
    {
        cnt++;
        x=x/10;
    }
    return cnt;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    pre[0]=0;
    int cnt=0;
    for(int i=1;i<=1e5;i++)
    {
        if(nod(i)%2==1)
            cnt++;
        pre[i]=cnt;
    }
    int n;
    while(cin>>n)
    {
        cout<<pre[n]<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fr first
#define sc second
#define close(x){cout<<x<<endl;return 0;}
#define pb push_back
#define mp make_pair
#define forr(i,a,b) for(ll i=a;i<b;i++)
void dfs(int v,int p,int d);
vector<vector<int> > vec;
int s=0;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,x,y;
cin>>x>>y;
cout<<x-y+1<<endl;
}


Measured memory_bytes: 256
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(i, j, k)
            
print(ans)

Measured memory_bytes: 69764
/* Dynamic Programming implementation of LCS problem */
#include<bits/stdc++.h>
using namespace std; 

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string &X, string &Y, int m, int n ) 
{ 
int L[m+1][n+1]; 

/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
	that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 

// Following code is used to print LCS 
int index = L[m][n]; 

// Create a character array to store the lcs string 
string lcs="";  // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	// If current character in X[] and Y are same, then 
	// current character is part of LCS 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs = lcs+X[i-1]; // Put current character in result 
		i--; j--; index--;	 // reduce values of i, j and index 
	} 

	// If not same, then find the larger of two and 
	// go in the direction of larger value 
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 

// Print the lcs
for(int i=lcs.size()-1;i>=0;i--)cout<<lcs[i];
} 

/* Driver program to test above function */
int main() 
{ 
string  X;
string  Y; 
cin>>X>>Y;
int m = X.size(); 
int n = Y.size(); 
lcs(X, Y, m, n); 
return 0; 
} 




Measured memory_bytes: 35456
N = int(input())
dum_list = list(map(int,input().split(' ')))

goukei = sum(dum_list)
dum_list = [2*x for x in dum_list]

ans_list = []
ans = ''

tmp = 0
for i in range(1,N-1,2):
  tmp += dum_list[i]
  
ans_list.append(goukei - tmp)
ans += str(ans_list[0])

for i in range(N-1):
  ans_list.append(dum_list[i] - ans_list[i])
  ans += ' ' + str(ans_list[i+1])
  
print(ans)

Measured memory_bytes: 14704
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  t,i,j,k,l,r,alp[26]={0};
    string s;
    cin>>s;
    for(i=0;s[i];i++)
    {
        ll x=s[i]-'a';
        alp[x]++;
    }
    ll matchLen=0;
    for(i=0;i<26;i++)
     {
        if(alp[i]) matchLen++;
     }
     if(matchLen==s.length())

        cout<<"yes"<<endl;
    else
        cout<<"no"<<endl;

    return 0;
}





Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=3e5+100;
const ll mod=998244353;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll row[maxn],col[maxn];
map<pair<ll,ll>,ll> mp;
int main(){
   // freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll n,m,s;
    cin>>n>>m>>s;
    for(int i=1;i<=s;i++){
        int x,y;
        cin>>x>>y;
        mp[make_pair(x,y)]++;
        row[x]++,col[y]++;
    }
    ll maxh=*max_element(row+1,row+1+n);
    ll maxw=*max_element(col+1,col+1+m);
    vector<ll> h,w;
    for(int i=1;i<=n;i++){
        if(row[i]==maxh)
            h.emplace_back(i);
    }
    for(int i=1;i<=m;i++){
        if(col[i]==maxw)
            w.emplace_back(i);
    }
    for(int i=0;i<(int)h.size();i++){
        for(int j=0;j<(int)w.size();j++){
            if(mp[make_pair(h[i],w[j])]==0){
                cout<<maxh+maxw<<endl;
                return 0;
            }
        }
    }cout<<maxh+maxw-1<<endl;
	return 0;
}

Measured memory_bytes: 35008
#include <stdio.h>
//#include <string.h>

int main(void){
  /*
  char a1[2] = "A";
  char a2[2] = "T";
  char a3[2] = "G";
  char a4[2] = "C";
*/
  char a;
  scanf("%c", &a);
  
  if(a=='A') printf("T");
  else if(a=='T') printf("A");
  else if(a=='G') printf("C");
  else if(a=='C') printf("G");




  return 0;
}

  


Measured memory_bytes: 1544
#include<bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define endl "\n"
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
 
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pp;
typedef pair<ll,pair<ll,ll> > ppp;
 
const ll N    = 5e5+5;
const ll INF  = 1e9;
const ll mod  = 1e9+7;

ll a[N];

void solve()
{
    ll n;
    string s;

    cin>>n;
    cout<<3*n*n<<endl;


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
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; }
typedef long long ll;
int main(void){
    int h,w;cin>>h>>w;
    int c[10][10];
    rep(i,10)rep(j,10) cin>>c[i][j];
    vector<int> t(10,1e+4);
    t[1]=0;
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > que;
    que.push({0,1});
    while(que.size()){
        int k=que.top().first,x=que.top().second;que.pop();
        rep(i,10){
            int nk=k+c[i][x];
            if(chmin(t[i],nk))que.push({nk,i});
        }
    }
    ll res=0;
    rep(i,h)rep(j,w){
        int a;cin>>a;
        if(a==-1)continue;
        res+=t[a];
    }
    cout<<res<<endl;
}

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

#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
template<typename T>
T gcd(T a, T b) { return b ? gcd(b,a%b) : a;}
template<typename T>
T lcm(T a, T b) { return a / gcd(a,  b) * b;}

class Drink{
public:
    ll a;
    ll b;
    bool operator<(const Drink &another) const
    {
        return a < another.a;//年齢を比較
    };
    //2つのconstを付けないとコンパイルエラーになるので注意!!
};

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

    vector<Drink> v(n);

    rep(i, n){
        cin >> v[i].a;
        cin >> v[i].b;
    }

    sort(all(v));

    ll money=0;
    ll count=0;
    ll i=0;
    while(1){
        //cout << v[i].a << "-----" << v[i].b << endl;
        if(count+v[i].b>=m){
            money+=v[i].a*(m-count);
            break;
        }
        money+=v[i].a*v[i].b;
        count+=v[i].b;
        i++;
    }

    cout << money << endl;


    return 0;
    
}






Measured memory_bytes: 1792
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    T=list(input())
    
    N=len(T)
    for i in range(N):
        if T[i]=="?":
            T[i]="D"
            
    print(''.join(map(str, T)))

main()


Measured memory_bytes: 98524
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-8;
int INF = 1e9;
int dp[200][200];
int main(){
	int n,t[200],a[200],b[200],c[200],d;
	cin>>d>>n;
	REP(i,d)cin>>t[i];
	REP(i,n)cin>>a[i]>>b[i]>>c[i];
	REP(i,n)REP(j,n){
		if(a[i]<=t[0]&&t[0]<=b[i]&&a[j]<=t[1]&&t[1]<=b[j]){
			dp[1][j]=max(dp[1][j],abs(c[i]-c[j]));
		}
	}
	for(int i=2;i<d;i++)
		REP(j,n)
			if(a[j]<=t[i]&&t[i]<=b[j])
				REP(k,n)dp[i][j]=max(dp[i][j],dp[i-1][k]+abs(c[j]-c[k]));
	int ans=0;
	REP(i,n)ans=max(ans,dp[d-1][i]);
	cout<<ans<<endl;
}

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

const int MAX = 50;
const int64_t INF = 4611686018427387903; // 10^62-1、使わない辺とかに用いる

bool check(int64_t x, int64_t *a, int N) {
	for (int i = 0;i < N;i ++) {
		int64_t operate = 0;
		for (int j = 0;j < N;j ++) {
			operate += (a[j] + x - i + 1) / (N + 1);
		}
		if (operate <= x - i) return false;
	}
	return true;
}

int64_t binarySearch(int64_t l, int64_t r, int64_t *a, int N) {
	int64_t mid;
	for (mid = r >> 1;r - l > 1;mid = l + (r - l >> 1)) {
		if (check(mid, a, N)) l = mid;
		else r = mid;
	}
	return mid;
}
int main() {
	int N;
	int64_t a[MAX];
	cin >> N;
	for (int i = 0;i < N;i ++) cin >> a[i];
	
	int64_t ans = binarySearch(0, INF, a, N);
	if (check(ans, a, N)) ans ++;
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

操作回数をX回と決め打ちます
この時、ある数aに対して行わなければならない操作回数は(a+X-N+1)/(N+1)の端数切り上げです
ということは、O(N^2)でX回以内にできるか分かります
よって後はXを二分探索すれば良いです、O(N^2log(max(a)))
*/

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      s: chars,
    }
    let n = s.len();
    for i in 0..n {
        if (i+1)%2 == 0 {
            if !(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
                return puts!("{}\n", "No");
            }
        } else {
            if !(s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
                return puts!("{}\n", "No");
            }
        }
    }
    puts!("{}\n", "Yes");
}


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

typedef long long ll;
typedef unsigned long long ull;

int partition(int *A, int p, int r){
    int x=A[r];
    int i=p-1;
    for(int j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            int tmp=A[i];
            A[i]=A[j];
            A[j]=tmp;
        }
    }
    int tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;

    return i+1;
}

int main(){
    int n, A[100000];
    cin >> n;    
    for(int i=0;i<n;i++) cin >> A[i];

    int q = partition(A, 0, n-1);
    for(int i=0;i<q;i++){
        if(i>0) cout << ' ';
        cout << A[i];
    }
    cout << " [" << A[q] << ']';
    for(int i=q+1;i<n;i++) cout << ' ' << A[i];
    cout << endl;

    return 0;
}


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

int main(){
  int N, M;
  cin>>N>>M;
  int sum=0;
  for(int i=0; i<M; i++){
    int a;
    cin>>a;
    sum+=a;
  }
  if(sum>N) cout<<-1<<endl;
  else cout<<N-sum<<endl;
}


Measured memory_bytes: 3676
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
public class Main {
 
    private static final int BIG_NUM  = 2000000000;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int H,W;
 
        String work[] = new String[2];
 
        while(true){
 
            try {
                work = br.readLine().split("[\\s]+");
                if(work[0].equals("0") && work[1].equals("0"))break;
 
                H = Integer.parseInt(work[0]);
                W = Integer.parseInt(work[1]);
 
                for(int row = 0; row < H; row++){
                    for(int col = 0; col < W; col++){
                        System.out.printf("#");
                    }
                    System.out.printf("\n");
                }
 
                System.out.printf("\n");
 
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


Measured memory_bytes: 60012
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())

ans = False
for i in str(N):
    if i == "7":
        ans = True
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 10936
import itertools

n, m, q = map(int, input().split())
abcds = [tuple(map(int, input().split())) for _ in range(q)]
x = [(i + 1) for i in range(m)]
ans = 0
for elem in itertools.combinations_with_replacement(x, n):
    rep = 0
    for i in range(q):
        if elem[abcds[i][1] - 1] - elem[abcds[i][0] - 1] == abcds[i][2]:
            rep += abcds[i][3]
    ans = max(ans, rep)
print(ans)


Measured memory_bytes: 68108
def main():
    A, B = map(int, input().split())

    ans = f(A, B)
    print(ans)


def TLE(A, B):
    ans = A
    for y in range(A+1, B+1):
        ans ^= y

    return ans


def f(A, B):
    """
    2^0: 0001
    2^1: 0010
         0011
    2^2: 0100
         0101
         0110
         0111
    2^3: 1000

    連番のdiff:
        1増えるので,2進数では下1桁は必ず異なる
        桁上りを考慮するとすべて変わる可能性もある
        1/2個,下二桁以外は同じになるので0になる
        偶数ベースに奇数との比較をする場合は 000...01
            0^1: 000 001, 001
            2^3: 010 010, 001
            4^5: 100 101, 001
            6^7: 110 111, 001

            この 01 になる偶数奇数のペア数が
            偶数個なら xor=0
            奇数個なら xor=1
    その次
         1- 2: 001- 010 -> 011
         2- 3: 010- 011 -> 001
         3- 4: 011- 100 -> 111
        11-12:1011-1100 -> 111

      a=0^1^2^3^4^5
      b=0^1^2^3^4^5^6^7^8
    a^b=            6^7^8
    """
    def xor_from_zero(x):
        if x == 0:
            return 0
        if x % 2 == 1:
            # 0含めたペアなので+1
            return (x + 1) // 2 % 2
        else:
            # e.g. :01234 0123までペア
            return x ^ (x // 2 % 2)

    a = xor_from_zero(A - 1)
    b = xor_from_zero(B)
    ans = a ^ b
    return ans


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define MAXN 2005 
#define P int(1e9+7)
using namespace std;
typedef long long ll;
const int NN = 4e6;

ll qpow(ll x, int n){
	ll res = 1;
	while(n){
		if(n&1) res = res * x % P;
		x = x * x % P;
		n /= 2;
	}
	return res;
}

int N,K;

ll fac[NN+5], ifac[NN+5];
ll dp[MAXN][MAXN];
/*
dp[i][j] = dp[i-1][j] + dp[i][j-1] * (n-j+1) * comb(i+j*(k-1)-1,k-2)
*/

void init(){
	fac[0] = 1;
	for(int i=1;i<=NN;i++){
		fac[i] = fac[i-1] * i % P;
	}
	
	ifac[NN] = qpow(fac[NN], P-2);
	for(int i=NN-1;i>=0;i--){
		ifac[i] = ifac[i+1] * (i+1) % P;
	}
}

ll comb(int n, int k){
	if(k > n) return 0;
	return fac[n] * ifac[k] % P * ifac[n-k] % P;
}

int main(){
	
	cin>>N>>K;
	if(K==1){
		cout<<"1"<<endl;
		return 0;
	}
	init();
	dp[0][0] = 1;
	
	for(int i=1;i<=N;i++){
		for(int j=0;j<=i;j++){
			dp[i][j] = dp[i-1][j];
			if(j>0) dp[i][j] = (dp[i][j] + dp[i][j-1] * (N-j+1) % P * comb((N-i)+(N-j+1)*(K-1)-1, K-2)) % P;
		}
	}
	
	cout<<dp[N][N]<<endl;
	return 0;
}


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

int main(){
  int n;
  vector<int>::iterator position;
  
  cin >> n;
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin >> l.at(i);
  }
  int64_t cnt = 0;
  
  sort(l.begin(),l.end());
  
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      position = upper_bound(l.begin(),l.end(),l.at(j)-l.at(i));
      //cout << l.at(j)-l.at(i) << "(" << i << "," << j << ")"<< distance(l.begin(),position)<<endl;
      if(distance(l.begin(),position) < i){
        if(i-distance(l.begin(),position) >= 1){
          cnt += i-distance(l.begin(),position);
        }
      }
    }
  }
  cout << cnt << endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	ll n;
	cin >> n;
	int a[100100], s[100100], t[100100] = { 0 };
	ll sum = 0;
	a[0] = 0;
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
		s[i - 1] = abs(a[i] - a[i - 1]);
		sum += s[i - 1];
		if (i > 1)t[i - 1] = abs(a[i] - a[i - 2]);
	}
	s[n] = abs(0 - a[n]);
	sum += s[n];
	t[n] = abs(0 - a[n - 1]);
	for (int i = 0;i < n;i++) {
		cout << sum - (s[i] + s[i + 1]) + t[i + 1] << endl;
	}
}

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



int main() {
    int n, d;
    cin >> n >> d;
    
    int r = d * 2 + 1;
    
    cout << (n+r-1) / r << endl;
    
    
    return 0;
}




Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//    fl();
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<max(a,b);i++)
		printf("%c",min(a,b)+'0');
	puts("");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sp ' '
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007, mod998 = 998244353;

int N, M, K;
ll DP[100000][301], A[100000], res;

int main() {
	cin >> N >> M >> K;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	for (int i = 1; i <= K; ++i) {
		deque<pair<int, ll>>q;
		q.push_back(mkp(i - 2, i == 1 ? 0 : DP[i - 2][i - 1]));
		for (int j = i - 1; j < N; ++j) {
			while (q.back().first + M < j)q.pop_back();
			DP[j][i] = q.back().second + A[j] * i;
			while (!q.empty() && q.front().second < DP[j][i - 1])q.pop_front();
			q.push_front(mkp(j, DP[j][i - 1]));
		}
	}
	for (int i = 0; i < N; ++i) {
		res = max(res, DP[i][K]);
	}
	cout << res << endl;
}

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

int main()
{
    string S;
    cin >> S;
    
    char op[3];
    rep(i,3)op[i]='+';//0->+,1->-
    int count;
    rep(i,8){
        for(int n=i,j=0;n>=1;n/=2,++j){
            op[j]=(n%2==0?'+':'-');
        }
        count=S[0]-'0';
        rep(j,3){
            if(op[j]=='+'){
                count+=(S[j+1]-'0');
            }else{
                count-=(S[j+1]-'0');
            }
        }

        if(count==7){
            cout << S[0]<<op[0]<<S[1]<<op[1] << S[2]<<op[2]<< S[3]<<"=7"<< endl;
            return 0;
        }
        rep(j,3)op[j]='+';
        
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll     = long long;
using prefix = __attribute__((constructor))void;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807LL;

#define elif           else if
#define def            inline auto
#define func           inline constexpr ll
#define up(i,a,n)      for(ll i=(a),i##_1=(n);i<=i##_1;++i)
#define down(i,a,n)    for(ll i=(a),i##_1=(n);i>=i##_1;--i)
#define rep(i,n)       up(i,0,n-1)
#define append(a)      push_back(a)

func    gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
func    lcm(ll a,ll b) {return a*b/gcd(a,b);}
def     dig(ll a)      {return to_string(a).length();}
prefix  init()         {cin.tie(0),ios::sync_with_stdio(0);}

ll H,W,N,X;
ll M[500000][4];
ll A[500][500];

signed main(){
    cin>>H>>W;

    rep(i,H)rep(j,W){
        cin>>X;
        A[i][j]+=X;
        if(A[i][j]&1&&j<W-1){
            A[i][j]--;
            A[i][j+1]++;
            M[N][0]=i,M[N][1]=j,M[N][2]=i,M[N][3]=j+1;
            N++;
        }
    }
    rep(i,H-1){
        if(A[i][W-1]&1){
            A[i][W-1]--;
            A[i+1][W-1]++;
            M[N][0]=i,M[N][1]=W-1,M[N][2]=i+1,M[N][3]=W-1;
            N++;
        }
    }
    cout<<N<<endl;
    rep(i,N){
        cout<<M[i][0]+1<<" "<<M[i][1]+1<<" "<<M[i][2]+1<<" "<<M[i][3]+1<<"\n";
    }

}
//for compilation: g++ -o _ _.cpp -std=c++14 (or 17)
//
//for fastening: g++ -O2 -o _ _.cpp -std=c++14 (or 17)
//for fastening: g++ -O3 -mtune=native -march=native -o _ _.cpp -std=c++14 (or 17)


Measured memory_bytes: 8192
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	vector<int>k(N);
	vector<int>sum(N);
	int cnt = 1;
	int cnt2 = 0;
	for (int i = 1; i < N; i++) {
		if (A[i - 1] == A[i])cnt++;
		else {
			k[cnt2] = cnt;
			cnt2++;
			cnt = 1;
		}
	}
	k[N - 1] = cnt;
	/*for (int i = 0; i < N; i++) {
		cout << k[i] << ' ';
	}*/
	sort(k.rbegin(), k.rend());
	int cnt3 = 0;
	for (int i = 0; i < N; i++) {
		if (k[i] != 0)cnt3++;
	}
	vector<int>KK(cnt3);
	for (int i = 0; i < cnt3; i++) {
		KK[i] = k[i];
	}
	/*for (int i = 0; i < cnt3; i++) {
		cout << KK[i] << ' ';
	}*/
	sort(KK.begin(), KK.end());
	int aans = 0;
	if (cnt3 - K <= 0) {
		cout << 0 << endl;
	}
	else if (cnt3 - K > 0) {
		for (int i = 0; i < cnt3 - K; i++) {
			aans += KK[i];
		}
		cout << aans << endl;
	}

}


Measured memory_bytes: 3328
S = list(raw_input())

i = 0
cnt = 0
while len(S) > 0:
    if i+1 == len(S):
        break
    if S[i] != S[i+1]:
        del S[i]
        del S[i]
        if i <= 0:
            i = -1
        else:
            i -= 2
        cnt += 2
    i += 1

print cnt

Measured memory_bytes: 3460
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    unordered_map<ll, int> mp;
    int cnt = 0;
    for (auto ai : a) {
        mp[ai]++;
    }
    for (auto itr = a.rbegin(); itr != a.rend(); itr++) {
        ll ai = *itr;
        if (mp[ai] == 0) continue;
        ll pow2 = 1;
        while (pow2 <= ai) pow2 *= 2;
        ll bi = pow2 - ai;

        if ((ai == bi && mp[ai] >= 2) || (ai != bi && mp[bi] >= 1)) {
            cnt++;
            mp[ai]--, mp[bi]--;
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 18420
def main():
	import sys
	from math import sqrt

	MAX = 1000000

	table = [True]*1000000
	table[0] = table[1] = False

	primes = []
	counted = 0

	for i in range(MAX):
		if table[i]:
			primes.append(i)
			for j in range(2*i, MAX, i):
				table[j] = False

	for line in sys.stdin:
		n = int(line)

		cnt = 0
		for prime in primes:
			if prime > n:
				break
			else:
				cnt += 1
		print(cnt)


if __name__ == '__main__':
	main()

Measured memory_bytes: 18396
local N, M = io.read("n", "n")
local r = {}
for i=1,M do
  local a, b = io.read("n", "n")
  r[a] = (r[a] or 0) + 1
  r[b] = (r[b] or 0) + 1
end
for i=1,N do
  print(r[i] or 0)
end

Measured memory_bytes: 508
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	ll n,ans=0;
	bool b=false;
	cin >> n;
	for(int i=1;i<=5;i++){
		if(pow(10,i)==n) b=true; 
	}
	if(b){
		cout << 10 << endl;
		return 0;
	}
	else{
		while(n>0){
			ans+=n%10;
			n/=10;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int cost(int* a, int n, int x)
{
    int i;
    int c = 0;

    for (i = 0; i < n; ++i){
        c += abs(x - a[i]) * abs(x - a[i]);
    }

    return (c);
}

int main(void)
{
    int n;
    int a[128];
    int i;
    int ave;
    int c1, c2;

    scanf("%d", &n);
    ave = 0;
    for (i = 0; i < n; ++i){
        scanf("%d", a + i);
        ave += a[i];
    }
    ave /= n;
    c1 = cost(a, n, ave);
    c2 = cost(a, n, ave + 1);

    printf("%d\n", c1 < c2 ? c1 : c2);

    return (0);
}


Measured memory_bytes: 128
#include<iostream>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー

using namespace std;


int main()
{
	string str;
	
	map<char, bool> check;

	cin >> str;

	for (int i = 0; i < str.length(); ++i)
	{
		auto itr = check.find(str.at(i));        // "xyz" が設定されているか？
		if (itr != check.end()) {
			cout << "no" << endl;
			return 0;
		}
		else {
			check[str.at(i)] == true;
		}

	}
	cout << "yes" << endl;

	return 0;
}

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

const lli INF=1e16;
struct seg_tr{
	static const int MAX=1<<18;
	lli tr[MAX<<1];
	void init() { for(int i=0;i<MAX+MAX;i++) tr[i] = INF; }
	void upd(int cur,lli val) {
		tr[cur+=MAX] = val;
		cur>>=1;
		while(cur) {
			tr[cur] = min(tr[cur<<1],tr[cur<<1|1]);
			cur>>=1;
		}
	}
	lli get(int l,int r) {
		l+=MAX; r+=MAX;

		lli res = INF;
		while(l<=r) {
			res = min({res,tr[l],tr[r]});
			if(l&1) l++;
			if(!(r&1)) r--;
			l>>=1; r>>=1;
		}
		return res;
	}
}lt,rt;

int n,q,A,B;
inline lli _abs(lli cur) {return cur<0 ? -cur : cur;}
int main() {
	scanf("%d%d%d%d",&n,&q,&A,&B);
	lt.init(); rt.init();
	
	int pr = A, cur;
	lli sum = 0;
	lt.upd(B, -B); rt.upd(B, B);
	while(q--) {
		scanf("%d",&cur);
		sum += _abs(cur - pr);
		
		lli v = min(lt.get(1,cur)+cur, rt.get(cur,n)-cur);
		lt.upd(pr, v-_abs(cur-pr)-pr);
		rt.upd(pr, v-_abs(cur-pr)+pr);
		pr=cur;
	}

	lli ad = INF;
	for(int i=1;i<=n;i++)
		ad = min({ad,lt.get(i,i)+i, rt.get(i,i)-i});
	printf("%lld\n",sum+ad);

	return 0;
}


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

int main(){
  int n;
  ll yen;
  cin >> n >> yen;
  int check = 0;
  int x = -1, y = -1, z = -1;
  rep(i, n+1){
    rep(j, n+1){
      int senen = n-i-j;
      if(senen >= 0){
        ll money = 10000 * i + 5000 * j + 1000 * senen;
        if(money == yen) {
          x = i;
          y = j;
          z = senen;
          check = 1;
        }
        if(check) break;
      }
      if(check) break;
    }
    if(check) break;
    
  }
  
  cout << x <<" "<<y <<" "<< z<< endl;
  
}


Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Prac
{
    class Prog
    {
        public static void Main()
        {
            Stack<long> rpn = new Stack<long>();
            var inputs = Console.ReadLine().Split(' ');

            var operant = 0L;
            foreach (var i in inputs)
            {
                if (long.TryParse(i, out operant))
                {
                    rpn.Push(operant);
                }
                else
                {
                    switch (i)
                    {
                        case "+":
                            rpn.Push(rpn.Pop() + rpn.Pop());
                            break;
                        case "*":
                            rpn.Push(rpn.Pop() * rpn.Pop());
                            break;
                        case "-":
                            rpn.Push(-(rpn.Pop() - rpn.Pop()));
                            break;
                    }

                }
            }
            Console.WriteLine(rpn.Pop()); 

        }
    }
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  int res = 0;
  if (( A <= C && C < B ) || ( C <= A && A < D )) res = min(B,D) - max(A,C);
  
  cout << res << endl;
  
}

Measured memory_bytes: 256
import numpy as N
n,k=map(int,input().split())
A=N.array(list(map(int,input().split())))
A.sort()
p=A[A>0]
z=N.count_nonzero(A==0)
m=A[A<0]
r=10**19
l=-r
while r-l>1:
    b=(l+r)//2
    c=0
    if b>=0:
        c+=z*n
    c+=A.searchsorted(b//p,side='right').sum()
    c+=n*len(m)-A.searchsorted(-(-b//m),side='left').sum()
    c-=N.count_nonzero(A*A<=b)
    if c//2>=k:
        r=b
    else:
        l=b
print(r)

Measured memory_bytes: 32328
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	char s[8001];
	int ox, oy;
	scanf("%s", s);
	scanf("%d %d", &ox, &oy);

	vector<int> x, y;
	{
		bool direction = false;
		int count = 0;
		for (int i = 0; s[i] != 0; i++) {
			if (s[i] == 'T') {
				if (!direction) {
					x.push_back(count);
				} else {
					y.push_back(count);
				}
				count = 0;
				direction = !direction;
			}
			else {
				count++;
			}
		}
		if (!direction) {
			x.push_back(count);
		}
		else {
			y.push_back(count);
		}
	}

	vector<bool> dp(8001, false), cur(8001, false);
	dp[0] = true;
	for (int i = 1; i < x.size(); i++) {
		if (!x[i])
			continue;
		for (int j = 0; j <= 8000; j++) {
			if (!dp[j])
				continue;
			dp[j] = false;
			cur[abs(j + x[i])] = true;
			cur[abs(j - x[i])] = true;
		}
		swap(dp, cur);
	}
	if (!dp[abs(x[0] - ox)]) {
		printf("No\n");
		return 0;
	}
	for (int i = 0; i <= 8000; i++)
		dp[i] = false;
	dp[0] = true;
	for (int i = 0; i < y.size(); i++) {
		if (!y[i])
			continue;
		for (int j = 0; j <= 8000; j++) {
			if (!dp[j])
				continue;
			dp[j] = false;
			cur[abs(j + y[i])] = true;
			cur[abs(j - y[i])] = true;
		}
		swap(dp, cur);
	}
	if (!dp[abs(oy)]) {
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
 
def main():
    N = int(readline())
    A = [0] *(10**5+1)
    total = 0
    for a in map(int, readline().split()):
        total += a
        A[a] += 1
 
 
    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().split())
        total += A[b]*(c-b)
        print(total)
        A[c] += A[b]
        A[b] = 0
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 15920
#include<iostream>
using namespace std;
int A, B;
void solve()
{
    int sum;
    sum = max(A, B);
  	if(A == sum)
      A--;
    else if(B == sum)
      B--;
    sum += max(A, B);
    
    cout << sum << endl;
}
int main()
{
   cin >> A >> B;
   solve();
   return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
P = [list(map(int, input().split())) for i in range(N)]
left = 0; right = 2*10**18+1
while left+1 < right:
    mid = (left + right) // 2
    cnt = 0
    for w, d in P:
        if w <= mid:
            cnt += 1 + (mid - w) // d
    if cnt < K:
        left = mid
    else:
        right = mid
print(right)

Measured memory_bytes: 62860
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<30)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N,M;
  cin >> N >> M;
  ll ans=0;
  vector<pair<ll,ll>> v;
  ll A,B;
  for(int i=0;i<N;i++){
    cin  >>  A >> B;
    v.push_back({A,B});
  }
  sort(v.begin(),v.end());
  for(int i=0;i<N;i++){
    ll yen=v[i].first;
    ll count=v[i].second;
    if(M>count){
      ans+=yen*count;
      M-=count;
    }else{
      ans+=yen*M;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, m, i, j, k, a, b;
	cin >> n >> m;
	vector<bool> v1(n + 1, false), v2(n + 1, false);
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		if (a == 1) v1[b] = true;
		if (b == n) v2[a] = true;
	}

	bool ans = false;
	for (i = 1; i <= n; i++) {
		if (v1[i] && v2[i]) ans = true;
	}

	if (ans) cout << "POSSIBLE\n";
	else cout << "IMPOSSIBLE\n";

	return 0;
}


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

ll getf(ll z, ll x) {

	if (z < 0) {
		return 0;
	}
	else {
		return z / x + 1;
	}
}

int main() {
	
	ll a, b, x; cin >> a >> b >> x;		
	cout << getf(b, x) - getf(a - 1,x) << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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; }
const long long INF = 1LL << 60;

int main(){
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for(int i = 0; i < N; i++){
    cin >> S.at(i);
  }
  sort(ALL(S));
  for(int i = 0; i < N; i++){
    cout<< S.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
 
enu=max(a)
a.remove(enu)

k=(enu)/2
sa=float("inf")
 
for i in range(n-1):
    if abs(k-a[i])<sa:
        sa=abs(k-a[i])
        aru=a[i]
 
print(enu,aru)

Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,m,a[100010];
int main(){
	LL i,j,k,l,ans;
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==1)l=i;
	}
	k=n-l;
	j=k/(m-1);
	ans=j;
	for(i=n-ans*(m-1)-1;i>0;i-=(m-1))
		ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
n = gets.to_i
hs = gets.chomp.split.map(&:to_i).reverse
ans = []
cnt = 0
current = hs.shift
hs.each do |h|
  if h >= current
    cnt += 1
  else
    ans << cnt
    cnt = 0
  end
  current = h
end
ans << cnt
puts ans.max

Measured memory_bytes: 10756
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		for(int i=1; i<=100000; i++) {
			if( i*2/25 == A && i*1/10 == B) {
				pl(i);
				System.exit(0);
			}
		}
		pl(-1);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}

}

Measured memory_bytes: 23892
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;
#define M 2200
#define N 100010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
ll a[N];
map<ll,ll>sum,Vis;
ll p[N],q[N];
ll n;
ll prime[N],vis[N],tot;
inline void prepare(ll Maxn)
{
	for(register ll i=2;i<=Maxn;i++)
	{
		if(!vis[i]){prime[++tot]=i;}
		for(register ll j=1;j<=tot&&prime[j]*i<=Maxn;j++)
		{
			vis[i*prime[j]]=1;
			if(i%prime[j]==0)break;
		}
	}
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	prepare(M);
	n=read();
	for(register ll i=1;i<=n;i++)a[i]=read();
	for(register ll i=1;i<=n;i++)
	{
		ll v=a[i];p[i]=q[i]=1;
		for(register ll j=1;j<=tot;j++)
		{
			ll tmp=prime[j]*prime[j]*prime[j];
			while(v%tmp==0)v/=tmp;
			tmp=prime[j]*prime[j];
			if(v%tmp==0)
			{
				v/=tmp;
				p[i]*=tmp;
				q[i]*=prime[j];
			}
			tmp=prime[j];
			if(v%tmp==0)
			{
				v/=tmp;
				p[i]*=tmp;
				q[i]*=prime[j]*prime[j];
			}
		}
		if(v>1)
		{
			ll tmp=sqrt(v);
			if(tmp*tmp==v)
			{
				p[i]*=v;
				q[i]*=tmp;
			}
			else
			{
				p[i]*=v;
				q[i]*=v*v;
			}
		}
		sum[p[i]]++;
	}
	ll ans=0;
	for(register ll i=1;i<=n;i++)
	{
//		cout<<"WTF:"<<i<<" "<<a[i]<<" "<<p[i]<<" "<<q[i]<<" "<<sum[p[i]]<<" "<<sum[q[i]]<<endl;
		if(Vis[p[i]])continue;
		if(p[i]==q[i]){Vis[p[i]]=1;ans++;continue;}
		ans+=max(sum[p[i]],sum[q[i]]);
		Vis[p[i]]=1,Vis[q[i]]=1;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 31076
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    vl A(N); F0R(i, N) cin >> A[i];

    ll ans = 0;
    sort(all(A)); reverse(all(A));
    F0R(i, N-1) {
        ans += A[(i+1)/2];
    }
    cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 4820
#include <stdio.h>
#include <math.h>

int main(void)
{
	int value,value_2;
	double x=0.0,y=0.0,angle=90;

	while(1)
	{
		scanf("%d,%d",&value,&value_2);
		if(value == 0 && value_2 == 0) break;

		x += cos(angle*M_PI/180)*value;
		y += sin(angle*M_PI/180)*value;
		angle -= value_2;
	}

	printf("%d\n%d\n",(int)x,(int)y);
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <cstdint>

constexpr int MAX = 310000;
constexpr int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int64_t COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();

    int h, w, a, b;
    std::cin >> h >> w >> a >> b;

    // 全体
    const int64_t total = COM(h - 1 + w - 1, h - 1);
    // 進入禁止エリアを通るパターン
    int64_t n = 0;
    // 進入禁止エリアの一つ手前までに下に降りる回数
    const int v = h - a - 1;
    for (int i = 0; i < b; ++i)
    {
        const int64_t tmp0 = COM(v + i, v);
        const int64_t tmp1 = COM(a - 1 + w - 1 - i, a - 1);

        n += tmp0 * tmp1 % MOD;
        n %= MOD;
    }
    int result = (total - n) % MOD;
    if (result < 0)
    {
        result += MOD;
    }

    std::cout << result << std::endl;

    return 0;
}


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

int main()
{
long long  N,M;
cin >> N >> M;
if(N >= 2 && M >= 2) cout << (N-2) * (M-2) << endl;
else if(N == 1 && M == 1) cout << 1 << endl;
else cout << N*M - 2 << endl;
}

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int a, b;
	cin >> a >> b;
	if (a <= 9 && b <= 9) {
		cout << a * b << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256