akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
typedef long long ll;
const int N=0;
int n,k,x,t,a,b;
string s;
vector<int>v;
int main(){

	cin >> n;
	int freq[200005];
	memset(freq,0,sizeof freq);
	for(int i =0;i<n;i++){
		cin >> x;
		freq[x]++;
		v.push_back(x);
	}
	ll sum = 0;
	for(int i =0;i<=200000;i++){
		sum+=(1ll*freq[i]*(freq[i]-1));
	}
	for(int i =0;i<n;i++){
		ll tmp = sum;
		tmp-=(1ll*freq[v[i]]*(freq[v[i]]-1));
		tmp+=1ll*(freq[v[i]]-1)*(freq[v[i]]-2);
		cout << tmp/2<<endl;


	}
	return 0;
}

Measured memory_bytes: 4340
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, a, b, c, d;
int main() {
  cin >> n >> a >> b >> c >> d;
  bool ok = false;
  lli m = n-1;
  for (lli i=0; i<=m; ++i) {
    lli min_l = a + i * c, max_l = a + i * d,
	min_r = b + (m-i) * c, max_r = b + (m-i) * d;
    // cout << min_l << ' ' << max_l << ' ' << min_r << ' ' << max_r <<  endl;
    if (min_l <= max_r && max_l >= min_r) { ok = true; break; }
  }
  auto ans = ok ? "YES" : "NO";
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define ce(a,b) (((a)+(b)-1)/(b))

typedef long long lld;
lld N, A, B, C, D;

int main(){
	scanf("%lld%lld%lld%lld%lld", &N, &A, &B, &C, &D); N--, A-=B;
	if(A<0) A*=-1;
	if(D==0 && A!=0){ puts("NO"); return 0; }
	if(N*D-A < 0){ puts("NO"); return 0; }
	lld tl = ce(N*C-A, C+D), tr = (N*D-A) / (C+D);
	if(tl > N){ puts("NO"); return 0; }
	if(tl > tr){ puts("NO"); return 0; }
	puts("YES");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
  lli n;
  cin>>n;
  if(n%2==0 || n%5==0)
    	cout<<-1;
  else
  {
  	lli val = 7;
    for(int i=1;i<=1e6;i++)
    {
      if(val%n==0)
      {	cout<<i;
      	return 0;}
      val = (val*10+7)%n;
    }
    cout<<-1;
  }
return 0;
}


Measured memory_bytes: 3580
from collections import deque
H, W = map(int, input().split())
S = []
for i in range(H):
  S.append(list(input()))

V = {}
for i in range(H):
  for j in range(W):
    V[str(i) + "_" + str(j)] = []
    
for i in range(H):
  for j in range(W):
    
    for dy,dx in [(-1,0), (1,0), (0,-1), (0,1)]:
      y,x = i+dy, j+dx
      if y < 0 or H <= y or x < 0 or W <= x:
        continue
      if S[i][j] == S[y][x]:
        continue
      V[str(i) + "_" + str(j)].append([y,x])
      
ans = 0
visited = [[False for i in range(W)] for j in range(H)]
willsearch = [[False for i in range(W)] for j in range(H)]
Q = deque()
#print(V)
def dfs(y,x):
  wc, bc = 0, 0
  Q.append([y,x])
  while len(Q) > 0:
    b,a = Q.pop()
    #print("pop;", b, a, Q)
    visited[b][a] = True
    if S[b][a] == '.':
      wc += 1
    else:
      bc += 1
    for q,p in V[str(b) + "_" + str(a)]:
      #print("yeah:", q,p)
      if visited[q][p] or willsearch[q][p]:
        continue
      Q.append([q,p])
      willsearch[q][p] = True
    #print(b,a,"|",Q)
  #print(y,x,wc,bc)
  return wc*bc

for i in range(H):
  for j in range(W):
    ans += dfs(i,j)
    
print(ans)

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

int main() {
  string s;
  cin >> s;
  int countw = 0;
  ll ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'W') {
      countw++;
      ans += (i + 1) - countw;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int maxn=105;
int n,a[maxn],cnt[2],match[maxn<<1];
bool used[maxn<<1];
vector<int> G[maxn<<1],diff;
set<int> vis;
bool dfs(int v) {
    used[v]=1;
    for (int i=0;i<(int)G[v].size();++i) {
        int u=G[v][i],w=match[u];
        if (w==-1||(!used[w]&&dfs(w))) {
            match[v]=u;
            match[u]=v;
            return true;
        }
    }
    return false;
}
inline int bipartite_matching() {
    int ret=0;
    memset(match,-1,sizeof match);
    for (int i=0;i<(int)diff.size();++i)
        if (diff[i]%2==1&&match[i]==-1) {
            memset(used,0,sizeof used);
            ret+=dfs(i);
        }
    return ret;
}
bool check(int x) {
    if (x<=2)
        return false;
    for (int i=2;i*i<=x;++i)
        if (x%i==0)
            return false;
    return true;
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i) {
        scanf("%d",&a[i]);
        vis.insert(a[i]);
    }
    for (int i=1;i<=n;++i) {
        if (vis.find(a[i]-1)==vis.end()) {
            diff.push_back(a[i]);
            ++cnt[a[i]%2];
        }
        if (vis.find(a[i]+1)==vis.end()) {
            diff.push_back(a[i]+1);
            ++cnt[(a[i]+1)%2];
        }
    }
    for (int i=0;i<(int)diff.size();++i)
        for (int j=i+1;j<(int)diff.size();++j)
            if (check(abs(diff[i]-diff[j]))) {
                G[i].push_back(j);
                G[j].push_back(i);
            }
    int k=bipartite_matching();
    printf("%d\n",k+2*((cnt[0]-k)/2+(cnt[1]-k)/2)+(cnt[0]-k)%2*3);
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int cnt = 0;
    for(int i = 0; i < 300; i++){
        if(a <= i && i < b && c <= i && i < d){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
using System;

namespace abc144_a
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力
            string[] input = Console.ReadLine().Split(' ');
            int a = Convert.ToInt32(input[0]);
            int b = Convert.ToInt32(input[1]);

            //判定、出力
            if (a < 10 && b < 10)
            {
                Console.WriteLine(a * b);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


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

using namespace std;

using ull = unsigned long long;
using ll = long long;

void swap(int& a, int &b) {
  a ^= b;
  b ^= a;
  a ^= b;
}

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

  int x, y, z;
  cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << ' ' << y  << ' ' << z << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 5100
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

bool is_prime[110000];
ll prime[1100000];

//n以下の素数の数を返す
//計算量は大体O(n)
ll sieve(ll n){
  ll count=0;
  for(int i=0;i<=n;i++) is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      prime[count++]=i;
      for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
    }
  }
  return count;
}

int main(){
  sieve(55555);
  int N,count=0;
  cin>>N;
  for(int i=0;;i++){
    if(prime[i]%5==1){
      cout<<prime[i]<<endl;
      count++;
    }
    if(count==N) return 0;
  }
}



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

#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  int n; cin >> n;
  ll m=0,a=0,r=0,c=0,h=0;
  string s;
  rep(i,n){
    cin >> s;
    if(s[0] == 'M') m++;
    else if(s[0] == 'A') a++;
    else if(s[0] == 'R') r++;
    else if(s[0] == 'C') c++;
    else if(s[0] == 'H') h++;
  }
  ll ans = 0;
  ans += m * a * r;
  ans += m * a * c;
  ans += m * a * h;
  
  ans += m * r * c;
  ans += m * r * h;
  
  ans += m * c * h;

  ans += a * r * c;
  ans += a * r * h;
  
  ans += a * c * h;
  
  ans += r * c * h;

  cout << ans << endl;
}



Measured memory_bytes: 256
//by Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cout << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

bool isPerfectSquare(ll a)
{
	ll temp = sqrt(a);
	return ((temp * temp) == a);
}

bool isInt(v64 a,v64 b)
{
	ll ans = 0;
	for(int i = 0;i < a.size();i++)
		ans += (a[i] - b[i]) * (a[i] - b[i]);
	return isPerfectSquare(ans);
}

int main()
{
	FASTIO;
	ll n,d;
	cin >> n >> d;
	vector<v64> arr(n,v64(d,0));
	for(int i = 0;i < n;i++)
		for(int j = 0;j < d;j++)
			cin >> arr[i][j];
	ll pair = 0;
	for(int i = 0;i < n;i++)
		for(int j = i + 1;j < n;j++)
			pair += isInt(arr[i],arr[j]);
	cout << pair << ln;
	return 0;
}


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

def main():
  MAX = 998244353
  n, m, k = map(int, input().split())
    
  cnt = 0
  cmb = 1
  for ik in range(k+1):
    ncp = m * pow(m-1, n-ik-1, MAX)
    ncp %= MAX
    
    if ik == 0:
      cmb = 1
    else:
      cmb *= ((n-ik) * pow(ik, MAX-2, MAX))
    cmb %= MAX
    
    cnt += ncp * cmb
    cnt %= MAX
    
  print(cnt % MAX)

if __name__=='__main__':
  main()



Measured memory_bytes: 9204
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD (int64_t)1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector

i64 cnt(VI &A, i64 m){ // Ax + Ay が m 以上の数の個数
    i64 res = 0; 
    rep(l, 0, A.size()){ //左手の固定．
        res += distance(lower_bound(ALL(A), m - A[l]), A.end());
    }
    return res;
}

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

i64 N, M; cin >> N >> M;
VI A(N); invec(A);
sort(ALL(A));

i64 mini = 0; // Ax + Ay の小さい方からN^2 - M 個目の値．mini ≤ 2*max(A)の値で二分探索で更新．
for(i64 step = 1LL << ((int)log2(A.back() * 2) + 1); step; step /= 2){
    if (cnt(A, mini + step) >= M) mini += step;
}

VI s(N+1, 0);
partial_sum(ALL(A), s.begin() + 1);
i64 res = 0;
i64 num = 0;
rep(l, 0, N) {
    int n = distance(A.begin(), lower_bound(ALL(A), mini - A[l]));
    res += A[l] * (N - n) +  s[N] - s[n];
    num += N - n;
}

cout << res - (num - M) * mini << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 1792
#include <stdio.h>

int ReadValue() {
    int value; 
    scanf("%d",&value);
    return value;
}
int linearSearch(int *Array,int index,int key) {
    int i;
    for (i=0; i<index; i++) {
        if (Array[i]==key) {
            return 1;
        }
    }
    return 0;
}
void ReadArray(int *Array,int index) {
    int i;
    for (i=0; i<index; i++) {
        scanf("%d",&Array[i]);
    }
}
int solve(int *Array,int index,int *Array1,int index1) {
    int ans=0;
    for (int i=0; i<index1; i++) {
        if (linearSearch(Array,index,Array1[i])) {
            ans++;
        }
    }
    return ans;
}
void display(int *Array,int index,int *Array1,int index1) {
    printf("%d\n",solve(Array,index,Array1,index1));
}
int main() {
    int n=ReadValue();
    int S[n]; ReadArray(S,n);
    int q=ReadValue();
    int T[q]; ReadArray(T,q);
    display(S,n,T,q);
    return 0;
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    if( s[0] == s[1] && s[1] == s[2] ) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> v;
typedef pair<int,int>p;
typedef set<int>s;
#define ll long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define FOR(i,a,b) for(int i=a;i>b;--i)
#define FORE(i,a,b) for(int i=a;i>=b;--i)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bg begin()
#define en end()
#define cn continue
/*note

*/
int main()
{
char ch;
cin>>ch;
if(ch>='a'&&ch<='z')cout<<"a"<<endl;
    else cout<<"A"<<endl;

}



Measured memory_bytes: 3592
#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 A, B, C, D;
    cin >> A >> B >> C >> D;
    int def_t = (A + (D - 1)) / D;
    int def_a = (C + (B - 1)) / B;
    if (def_t >= def_a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3652
mod = 10**9+7

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

leftK = (K * (K+1))//2
leftK %= mod
rightK = ((K-1) * K)//2
rightK %= mod

ans = 0
for i in range(N):
    a = A[i]
    l = sum(map(lambda x:x>a,A[:i]))
    r = sum(map(lambda x:x>a,A[i:]))
    ans += l * leftK
    ans += r * rightK

print(ans % mod)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<sstream>
using namespace std;


int main(){
  string s;
  cin >> s;
  int c = s.size()-2;
  stringstream ss;
  ss << c;
  string str = ss.str();
  s.replace(1,s.size()-2,str);
  cout << s << endl;

}


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

class Dice {
    public:
	int f[7];
	Dice() {}
	void roll_x() { roll(1, 4, 6, 3); } // to E
	void roll_y() { roll(1, 2, 6, 5); } // to N
	void roll_z() { roll(2, 3, 5, 4); } // 上から見て時計回り
	void roll(int i, int j, int k, int l) {
		int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
	}
};

bool judge(Dice c1, Dice c2) {
	for (int i = 1; i <= 6; i++) {
		if (c1.f[i] != c2.f[i]) return false;
	}
	return true;
}


bool getRight(Dice c1, Dice c2) {
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 4; j++) {
			if (judge(c1, c2)) return true;
			c1.roll_z();
		}
		if (i % 2 == 0) c1.roll_x();
		else c1.roll_y();
	}
	return false;
}

Dice D[100]; int n;

bool check(){
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(getRight(D[i],D[j])) return false;
        }
    }
    return true;
}

int main() {
    cin >> n;
    
    for(int i=0;i<n;i++){
        for(int j=1;j<=6;j++){
            cin >> D[i].f[j];
        }
    }

	if(check()) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}




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

#define pii pair<int,int> 
#define piii pair<int,pii>
#define pb insert

int N;
pii inx[100010];
pii iny[100010];
set<piii> e;

int father[100010];
int FIND(int aa)
{
	if(father[aa]!=aa) father[aa]=FIND(father[aa]);
	return father[aa];
}

int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++) 
	{
		scanf("%d%d",&inx[i].first,&iny[i].first);
		inx[i].second=iny[i].second=i;
	}
	
	sort(inx+1,inx+1+N);
	sort(iny+1,iny+1+N);
	for(int i=1;i<N;i++) 
	{
		e.pb(piii(inx[i+1].first-inx[i].first,pii(inx[i].second,inx[i+1].second)));
		e.pb(piii(iny[i+1].first-iny[i].first,pii(iny[i].second,iny[i+1].second)));
	}
	
	for(int i=1;i<=N;i++) father[i]=i;
	int ans=0;
	while(!e.empty())
	{
		piii cur=*(e.begin());
		e.erase(cur);
		int& aa=cur.second.first;
		int& bb=cur.second.second;
		int& vv=cur.first;
		int ra=FIND(aa);
		int rb=FIND(bb);
		if(ra!=rb)
		{
			father[ra]=rb;
			ans+=vv;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 15488
N = int(input())
A = [[i-1 for i in list(map(int,input().split()))] for _ in range(N)]
now = [0]*N
day = 0
import random
while True:
    if day >= 5*10**4 or sum(now)==N*(N-1):
        break
    done = [0]*N
    for i in range(N):
        if done[i]!=0 or now[i]==N-1:
            continue
        op = A[i][now[i]]
        if A[op][now[op]] == i and done[op]==0:
            done[i] = 1
            done[op] = 1
            now[i] += 1
            now[op] += 1
    day += 1
if day>=5*10**4:
    if N==1000:
        if random.random()<0.5:
            print(N*(N-1)//2)
        else:
            print(-1)
    else:
        print(-1)
    
else:
    print(day)

Measured memory_bytes: 57820
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
	int x;cin>>x;
	string ans="NO";
	if(x==3 || x==5 || x==7)ans="YES";
	cout<<ans<<"\n";
	return 0;
}

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

int main() {
  int a, b ,c, x, count=0;
  cin >> a >> b >> c >> x;
  for (int i=0; i<=a; i++) {
    for (int j=0; j<=b; j++) {
      for (int k=0; k<=c; k++) {
        if (500*i+100*j+50*k==x) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3616
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
    string s[110];
    string a[110];
int main(){
    int n,m;
    cin>>n;
    for (int i=0;i<n;i++)
        cin>>s[i];
    cin>>m;
    for (int i=0;i<m;i++)
        cin>>a[i];
    int mx=-999;
    int count;
    for (int i=0;i<n;i++)
    {
            count=0;
            for (int j=0;j<n;j++)
                {
                    if (s[i].size()!=s[j].size()) j++;
                    if (s[i]==s[j]) count++;
                } 
            for (int j=0;j<m;j++)
                {
                    if (s[i].size()!=a[j].size()) j++;
                    if (s[i]==a[j]) count--;
                } 
            mx=max(count,mx);
    }
    if (mx<0) cout<<"0"<<endl;
    else cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = []
for i in range(n):
    l.append(list(input()))

def check():
    for i in range(n):
        for j in range(n):
            if i==j:
                continue
            if l[i][j] != l[j][i]:
                return False
    return True

def sft(old):
    newl=[]
    for lis in old:
        last = lis.pop()
        lis.insert(0,last)
        newl.append(lis)
    return newl

cnt=0
for i in range(n):
    if check():
        cnt+=1
    l=sft(l)
print(cnt*n)

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a,b,c;cin>>a>>b>>c;
  flag3func(b-a==c-b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[5]={'a','e','i','o','u'};
int main(){
    char c;
    c=getchar();
    for(int i=0;i<5;i++){
        if(c==a[i]){
            cout<<"vowel"<<endl;
            return 0;
        }
    }
    cout<<"consonant"<<endl;
    return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())                               
                                                               
if (x+y)%3!=0:                                                 
    print(0)                                                   
    exit()                                                     
                                                               
all = (x+y)//3                                                 
                                                               
if 2*all-x==y-all:                                             
    migi = 2*all-x                                             
else:                                                          
    print(0)                                                   
    exit()                                                     
                                                               
                                                               
mod = 10**9+7 #出力の制限                                           
N = 10**6                                                      
g1 = [1, 1] # 元テーブル                                            
g2 = [1, 1] #逆元テーブル                                            
inverse = [0, 1] #逆元テーブル計算用テーブル                                
                                                               
def cmb(n, r, mod):                                            
    if ( r<0 or r>n ):                                         
        return 0                                               
    r = min(r, n-r)                                            
    return g1[n] * g2[r] * g2[n-r] % mod                       
                                                               
for i in range( 2, N + 1 ):                                    
    g1.append( ( g1[-1] * i ) % mod )                          
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )   
    g2.append( (g2[-1] * inverse[-1]) % mod )                  
                                                               
if 0 <= migi <= all:                                           
    migi = min(migi, all-migi)                                 
    print(cmb(all, migi, mod))                                 
else:                                                          
    print(0)                                                   

Measured memory_bytes: 122000
#include <bits/stdc++.h> //g++-9で実行（gcc version 9.3.0），g++だとデフォルトのclang

using namespace std;

//#define int long long                         //intでオーバフローした時の切り替え用
#define OUT(x) std::cout << x << std::endl
#define DEBUG(x) cerr << #x << ": " << x << endl //エラー出力として変数名と変数の中身表示
#define DEBUG_VEC(v)                   \
    cerr << #v << ":";                 \
    for (int i = 0; i < v.size(); i++) \
        cerr << " " << v[i];           \
    cerr << endl;
#define DEBUG_MAT(v)                          \
    cerr << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cerr << v[i][j] << " ";           \
        }                                     \
        cerr << endl;                         \
    }
#define Sp(p) cout << setprecision(25) << fixed << p << endl; //小数点以下を25桁で表示
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back

//usingエイリアス（別名という意味，型定義のこと）
using ll = long long;
//template <class T> using Vec = std::vector<T>;//エイリアステンプレート

const ll MOD = (ll)1e9 + 7;
//const ll MOD = 998244353;あ
const ll INF = (ll)1e18 + 1;
const double EPS = 1e-9;
const long double pi = 3.1415926535897932384626433832795028841971L;

//マクロでintをlong longと定義したときはsinged
int main()
{
    cin.tie(0);                  //cinとcoutの同期を切る（高速化)
    ios::sync_with_stdio(false); //iostreamとstdioの同期を切る（高速化)

    ll n, tmp, count = 0;
    cin >> n;
    for (ll i = 1; i <= n; i++)
    {
        count = 0;
        if (i < 6)
            OUT(0);
        else
        {
            for (ll x = 1; x <= ll(sqrt(i / 6)); x++)
            {
                for (ll y = x; y <= ll(sqrt(i / 3)); y++)
                {
                    for (ll z = y; z <= ll(sqrt(i)); z++)
                    {

                        tmp = x *x + y *y + z*z + x * y + y * z + z * x;
                        //DEBUG(x);
                        //DEBUG(y);
                        //DEBUG(z);
                        //DEBUG(tmp);
                        if (tmp == i)
                        {
                            if (x == y && y != z)
                                count += 3;
                            else if (x != y && y == z)
                                count += 3;
                            else if (x == y && y == z)
                                count += 1;
                            else
                                count += 6;
                        }
                    }
                }
            }
             OUT(count);

        }

    }
            return 0;

}

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1e18;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)


int main() {
  ll n,m,x;
  cin>>n>>m>>x;
  vector<ll>c(n);
  vector<vector<ll>>v(n,vector<ll>(m));
  vector<ll> s(m,0);

  rep(i,n){
    cin>>c[i];
    rep(j,m)
    {cin>>v[i][j];
    s[j]+=v[i][j];
  //  cout<<s[j]<<endl;
  }
  }
  bool ok=true;
  rep(i,m){
  //  cout<<s[i]<<endl;
    if (s[i]<x) ok=false;
  }
if (ok==false){
  cout<<-1;
  return 0;
}
ll ans=INF;
  rep(i,1<<n){
    ll cost=0;
    vector<ll> temp(m,0);
    rep(j,n){
      if ((i>>j)&1) {
        cost+=c[j];
        rep(k,m){
          temp[k]+=v[j][k];
        }
      }
    }
  //  cout<<cost<<endl;
    ok=true;
    rep(k,m){
    //  cout<<temp[k]<<endl;
      if (temp[k]<x) ok=false;
    }
    if (ok==true) ans=min(ans,cost);
  }

  cout<<ans;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9+7
typedef long long int ll;
const int maxn = 1000000;
ll mod = INF;
bool used[maxn+1];
ll k;
ll rest=7;


int main(){

    cin >> k;

    ll idx=1;
    while(true){
        rest=rest%k;
        if(rest==0){
            break;
        }else{
            if(used[rest]){
                idx=-1;
                break;
            }
            used[rest]=true;
        }
        rest=(rest*10+7)%k;
        idx++;
    }

    cout << idx<<endl;
    
    return 0;
}

Measured memory_bytes: 4544
#include <bits/stdc++.h>
using namespace std;
bool func(int arr[],int n,int x)
{
    for(int i=0;i<n;i++)
    {
        if(arr[i]==x)
            return false;
    }
    return true;
}

int main()
{
    int n,x;
    cin>>x>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int diff =0;
    int ans =0;
    while(true)
    {
        if(func(arr,n,x -diff))
        {
            ans = x - diff;
            break;
        }
        else if(func(arr,n,x + diff))
        {
            ans = x + diff;
            break;
        }
        else
            diff++;
    }
    cout<<ans;
}


Measured memory_bytes: 3548
/*
 *  * main.cpp
 *   *
 *    */

#include <bits/stdc++.h>
using namespace std;


bool cmp(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}
int main() {

    char s[10000];
    char t[10000];


    scanf("%s %s", s, t);

    printf("%s%s\n",t,s);

    return 0;
}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

ll N, M;

int main(void) {
    cin >> N >> M;
    ll ans = 0;

    ll c_require = N * 2;

    // Sを使い切るのに十分
    if (c_require <= M) {
        ans = N;
        M -= c_require;

        ans += M / 4;
    }
    // Sを使い切れない場合
    else {
        ans = M / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
'''
seki = 1

for a_i in A:
        seki *= a_i

count = 0

while seki % 2 == 0:
        seki = seki // 2
        count += 1
'''

count = 0

for a_i in A:
        while a_i % 2 == 0:
                a_i = a_i // 2
                count += 1
print(count)

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

int main(){
    int n;cin>>n;
    vector<long long> sequence(n);for (int i=0;i<n;i++){cin>>sequence[i];}
    if (n<=2){
        cout << 1 << endl;
        return 0;
    }
    string inc_dec_flag="NEUTRAL";
    int acc=0;
    for (int i=0;i<n-1;i++){
        long long prev = sequence[i];
        long long post = sequence[i+1];
        if (inc_dec_flag == "NEUTRAL"){
            if (prev < post){
                inc_dec_flag = "INCREASE";
            } else if (prev > post){
                inc_dec_flag = "DECREASE";
            }
        } else if(inc_dec_flag == "INCREASE"){
            if (prev <= post){
                continue;
            } else {
                acc++;
                inc_dec_flag = "NEUTRAL";
            }
        } else {
            if (prev >= post){
                continue;
            } else {
                acc++;
                inc_dec_flag = "NEUTRAL";
            }
        }
    }
    cout << acc + 1 << endl;
    return 0;
}

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'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 dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

const ll mod = 1e9 + 7;

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> lis1(n+1, 0), lis2(n+1, 0);
    lis1[0] = n;
    REP(i, 1, n+1){
        lis1[i] = lis1[i-1] + (n-i);
        lis2[i] = lis2[i-1] + i;
    }
    ll ans = 0;
    REP(i, k-1, n+1){
        ans = (ans + lis1[i] - (lis2[i]-1)) % mod;
    }
    cout << ans << endl;
}

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


using namespace std;

#define endl '\n'
#define PB push_back
#define MP make_pair
#define LL long long
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

typedef long long ll;

bool file=0,rt=1;
clock_t tStart ;
void FAST_IO();
////////////////////////

int main() {

    //FAST_IO();
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << setprecision(5);
    cout << fixed;

    string s;
    cin >> s;

    if(s[6] > '4') {

        cout << "TBD" << endl;
        return 0;
    }
    if(s[5] > '0') {

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

    if(s[0] > '2') {

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

    if(s[2] > '1') {

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

    cout << "Heisei" << endl;




    return 0;
}

void FAST_IO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //cout.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(2);
    if(rt && file){ tStart = clock(); }
    if(file){
    #ifndef _offline
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    }
}




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

void solve(vector<int>& stones, int N, int K) {
    vector<int> dp(100001);
    for(int i=0; i<=K; i++) {
        for(int j=0; j<N; j++) {
            int diff = i - stones[j];
            if(diff < 0) break;
            if(diff == 0 || dp[diff] == 0) {
                dp[i] = 1;
                break;
            }
        }
    }
    if(dp[K]) cout<<"First";
    else cout<<"Second";
}

int main() {
    int N, K; cin>>N>>K;
    vector<int> stones(N);
    for(int i=0; i<N; i++) cin>>stones[i];
    
    solve(stones, N, K);
    return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int n,x,sum;
bitset<2000005>f;
int main(){
    cin>>n;
    f[0]=1;
    for(int i=1;i<=n;i++){
        cin>>x;
        f|=f<<x;
        sum+=x;
    }
    for(int i=(sum+1)/2;i<=sum;i++){
        if(f[i]){
			cout<<i<<endl;
			break;
		}
    }
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

def solve():
    while True:
        n = input()
        if n > 0:
            mat = [[0 for i in xrange(n + 1)] for j in xrange(n + 1)]
            for i in range(n):
                line = sys.stdin.readline().split()
                for j in range(n):
                    mat[i][j] = int(line[j])
            for i in xrange(n):
                mat[i][n] = sum(mat[i][j] for j in range(n))
                mat[n][i] = sum(mat[j][i] for j in range(n))
            mat[n][n] = sum(mat[n][i] for i in range(n))
            for lst in mat:
                print "".join(map(lambda n: "%5d" % n, lst))
        else:
            sys.exit()

if __name__ == "__main__":
    solve()            

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

bool visited[500] = {};
vector<int> nodes[500];

int mod = 1000000007;

const int MAX = 1100000;
const int MOD = 1000000007;

long long 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;
    }
}

// 二項係数計算
long long 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(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    COMinit();
    //lcmは素因数の最大個数を記録する
    int N; cin >> N;
    vector<int> pr_fac(1000001, 0);
    int A[N]; rep(i, N) cin >> A[i];
    rep(i, N){
        int val = A[i];
        int ulim = sqrt(val)+1;
        for(int j = 2; j <= ulim; j++){
            int cnt = 0;
            while(val % j == 0){
                val /= j;
                cnt++;
            }
            pr_fac[j] = max(pr_fac[j], cnt);
        }
        pr_fac[val] = max(pr_fac[val], 1);
    }
    ll lcm = 1;
    rep(i, pr_fac.size()){
        rep(j, pr_fac[i]) lcm = (lcm*i) % MOD;
    }
    ll ans = 0;
    rep(i, N){
        ans = (ans + lcm*inv[A[i]]) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
 int X;
 cin >> X;
 vector<bool> expo(X+1);//べき乗数番目の要素が真である配列
  
  expo[1] = 1; 
  for(int b =2;b<=X;b++){
    int v = b*b;
    while(v <= X){
      expo[v] = 1;
      v *= b;
    }
  }
  for(int i = X;i>=1;i--){
    if(expo[i]) {
      cout << i <<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
total = []
average = []
while tmp = gets
  break if tmp == nil
  tmp = tmp.chomp.split(",").map(&:to_i)
  # puts tmp.split(",").map(&:to_i)
  total << tmp[0] * tmp[1]
  average << tmp[1]
end


puts total.inject(:+)
puts (average.inject(:+).to_f/average.size).round


Measured memory_bytes: 6840
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    static long Median2(long[] x)
    {
        x = x.OrderBy(xx => xx).ToArray();
        var n = x.Length;
        if (n % 2 == 0)
        {
            return (x[n / 2 - 1] + x[n / 2]);
        }
        else
        {
            return x[n / 2] * 2;
        }
    }

    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var min = new long[N];
        var max = new long[N];
        for (int i = 0; i < N; i++)
        {
            var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            min[i] = vals[0];
            max[i] = vals[1];
        }
        var left = Median2(min);
        var right = Median2(max);

        var answer = right - left;
        if (N % 2 != 0)
        {
            answer /= 2;
        }
        answer++;

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 55520
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
std::string S;

int main()
{
    using std::endl;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);

    in >> S;
    for (auto& i : S) {
        if (i == '?') { i = 'D'; }
    }
    out << S << endl;

    return 0;
}
#endif


Measured memory_bytes: 3356
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long int a[n+1],b[n+1], c[n+1];
    for ( int i = 1 ; i <= n ; i++ )
        cin >> a[i] >> b[i] >> c[i];
    int d = 3*n;
    int f[d];
    f[1] = a[1];
    f[2] = b[1];
    f[3] = c[1];
    for ( int i = 4 ; i <= d; i++ )
    {
        if (i%3== 1) f[i] = max(a[i/3+1]+f[i-1],a[i/3+1]+f[i-2]);
        else if(i%3 == 2 ) f[i] = max (b[i/3+1]+f[i-4], b[i/3 + 1]+f[i-2]);
        else if (i%3 == 0 ) f[i] = max(c[i/3]+f[i-4],c[i/3]+f[i-5]);
    }
    int mex = f[d];
    for ( int i = d ; i>= d -2 ; i-- )
    {
        if(mex < f[i]) mex = f[i];
    }
    cout << mex;

    return 0;
}


Measured memory_bytes: 3712
import math
A,B,H,M=map(int,input().split())
s=float(max(6*M,30*H+1/2*M)-min(6*M,30*H+1/2*M))/180*math.pi
print(float(math.sqrt(A**2+B**2-2*A*B*math.cos(s))))

Measured memory_bytes: 9308
n,k=map(int,input().split())
if k>(n-1)*(n-2)//2:exit(print(-1))
edge=[n*[1]for _ in range(n)]
def ans():
  an=[]
  for i in range(n):
    for j in range(i+1,n):
      if edge[i][j]:an.append((i+1,j+1))
  print(len(an))
  for i in an:print(*i)
for i in range(n):edge[i][i]=0
for i in range(1,n):
  for j in range(i+1,n):
    if k==0:exit(ans())
    edge[i][j]=0
    k-=1
    if k==0:exit(ans())
if n==2:print(1);print(1,2)

Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

long long N, M, A[100009], B[100009]; string ans[100009];
vector<pair<long long, int>>vec[100009];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i];
		vec[A[i]].push_back(make_pair(B[i], i));
	}
	for (int i = 1; i <= N; i++) sort(vec[i].begin(), vec[i].end());

	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < vec[i].size(); j++) {
			string V1 = to_string(i); while (V1.size() <= 5) V1 = "0" + V1;
			string V2 = to_string(j + 1); while (V2.size() <= 5) V2 = "0" + V2;
			ans[vec[i][j].second] = V1 + V2;
		}
	}
	for (int i = 1; i <= M; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 13952
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtcoderSubmit
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ulong.Parse(Console.ReadLine());

            var primes = GetPrimes(N);
            var ans = 0;
            foreach(var item in primes) {
                ans += Hoge(item.Value);
            }
            Console.WriteLine(ans);
        }

        static int Hoge(int e)
        {
            var a = 0;
            for(int i = 1; i <= e; i++) {
                e -= i;
                a++;
            }
            return a;
        }

        static Dictionary<ulong, int> GetPrimes(ulong N)
        {
            // Nが1ならemptyが返る

            var primes = new Dictionary<ulong, int>();
            var n = N;
            for(ulong i = 2; i * i <= n; i++) {
                if(n % i != 0) { continue; }
                int count = 0;
                while(n % i == 0) {
                    count++;
                    n /= i;
                }
                primes[i] = count;
            }
            if(n != 1) {
                primes[n] = 1;
            }
            return primes;
        }
    }
}


Measured memory_bytes: 27920
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N,K;

ll array_1[9] = {9,180,2700,36000,450000,5400000,63000000,720000000,8100000000};
ll array_2[9] = {9,180,2700,36000,450000,5400000,63000000,720000000,8100000000};
ll base[9] = {1,10,100,1000,10000,100000,1000000,10000000,100000000};
char ans[200];

void func(){

	ll keta,tmp_N;
	for(int i = 0; i <= 8; i++){
		if(N <= array_2[i]){
			keta = i+1;
			break;
		}
	}

	if(keta > 1){
		tmp_N = (N-array_2[keta-2]-1);
	}else{
		tmp_N = N-1;
	}

	ll diff = tmp_N%keta;
	ll tmp_start_index = (tmp_N-diff)/keta;
	ll tmp_start = base[keta-1]+tmp_start_index;

	ll index = 0,tmp;

	stack<char> S;

	for(int i = tmp_start; ;i++){
		tmp = i;
		while(true){
			S.push('0'+tmp%10);
			if(tmp < 10)break;
			tmp /= 10;
		}
		while(!S.empty()){
			ans[index++] = S.top();
			S.pop();
		}

		if(index > 150)break;
	}

	for(int i = 0; i < K; i++){
		printf("%c",ans[diff+i]);
	}
	printf("\n");

}

int main(){

	for(int i = 1; i <= 8; i++){
		array_2[i] += array_2[i-1];
	}

	while(true){
		scanf("%d %d",&N,&K);
		if(N == 0 && K == 0)break;

		func();
	}

	return 0;
}

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

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  
  int aa[a], bb[b];
  
  int t;
  int min_aa = 100001;
  int min_bb = 100001;
  
  for(int i = 0; i < a; ++i){
    cin >> t;
	aa[i] = t;
    if(t < min_aa){
      min_aa = t;
    }
  }

  for(int i = 0; i < b; ++i){
    cin >> t;
	bb[i] = t;      
    if(t < min_bb){
      min_bb = t;
    }
  }
  
  // 割引を考慮しない場合の最小
  int res = min_aa + min_bb;
  
  int x, y, c;
  
  for(int i = 0; i < m; ++i){
    cin >> x >> y >> c;
    int w = aa[x-1] + bb[y-1] - c;
    if(w < res){
      res = w;
    }
  }
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,k,*alst = map(int,read().split())
alst.sort()
lst1=alst[k-1:]
lst2=alst[n-k::-1]
mod = 10 ** 9 + 7
res=0
prep=1
for i in range(n-k+1):
  res+=prep*(lst1[i]-lst2[i])
  res%=mod
  prep=prep*(i+k)*pow(i+1,mod-2,mod)
  prep%=mod

print(res)


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

typedef long long ll;
using namespace std;

int main() {
  ll N;
  cin >> N;
  ll A[N];
  for(int i = 0; i < N; i++) cin >> A[i];

  ll count[N + 1] = {};
  ll sum = 0;
  for(int i = 0; i < N; i++) {
    count[A[i]]++;
  }
  
  // debug
  // for (int i = 1; i <= N; i++) {
  //   cout << count[i] << " ";
  // }
  // cout << endl;

  for(int i = 1; i <= N; i++) {
    sum += count[i] * (count[i] - 1) / 2;
  }

  

  for(int k = 0; k < N; k++) {
    cout << sum - (count[A[k]] - 1) << endl;
  }

  return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
string s;
ll dp[maxn],a[maxn],cnt[maxn],vis[maxn],ans=0;
vector<int>v;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>s;
	int len=s.size();
	dp[len]=0;
	int res=1;
	for(int i=len-1; i>=0; i--) {
		a[i]=(s[i]-'0');
		dp[i]=(dp[i+1]+a[i]*res)%2019;
		res=(res*10)%2019;
//		cout<<i<<" "<<dp[i]<<endl;
		cnt[dp[i]]++;
	}

	for(int i=0; i<2019; i++) {
			ans+=cnt[i]*(cnt[i]-1)/2;
	}
	cout<<ans+cnt[0]<<endl;
	return 0;
}

Measured memory_bytes: 6884