akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

constexpr double kRate = 380000.0;

int main() {
  double sum = 0;
  int N; cin >> N;
  for (int i = 0; i < N; ++i) {
    double y; string S; cin >> y >> S;
    if (S == "JPY") sum += y;
    else            sum += y * kRate;
  }
  printf("%lf\n", sum);
}


Measured memory_bytes: 3756
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <cstdlib>
#define INF 998244353

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

const ll MOD = 1e9+7;

static long gcd(long a, long b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
/*
long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}*/

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された

    if(n%6 != 1 && n%6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false; // 6n-1
        if(n%(i+2) == 0) return false; // 6n+1
    }

    return true;
}

map< ll, ll > prime_factor(ll n) {//素因数分解
    map< ll, ll > ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

ll calcNumOfCombination(ll n, ll r){
    ll num = 1;
    for(ll i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}

int bubblesort(vector<int> array,int size){//バブルソート　転倒数
    int kaisu = 0;
    for(int i = 0; i < size; i++){
        for(int j = i + 1; j < size; j++){
            if(array[i] > array[j]){
                int number = array[i];
                array[i] = array[j];
                array[j] = number;
                kaisu++;
            }
        }
    }
    return kaisu;
}

ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum = (sum * i)%MOD;
    }
    return sum;
}

// nPnの順列に対して処理を実行する
void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}





int main() {
 int N;
 cin >> N;
 ll X[N],L[N];
 pair<ll,ll> a[N];
 for(int i=0;i<N;i++){
     cin >> X[i] >> L[i];
     a[i].second = X[i]-L[i];
     a[i].first=X[i]+L[i];
 }
 sort(a,a+N);



 ll ans = 0 , t = LONG_LONG_MIN;
 for(int i=0;i<N;i++){
     if(t <= a[i].second){
         ans++;
         t = a[i].first;
     }
 }





    cout << ans << endl;

}






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

int main(void)
{
    int n, m;
    int a[100][100], b[100], c[100] = {};
    
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> a[i][j];
    for (int j = 0; j < m; ++j)
        cin >> b[j];
    
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
           c[i] += a[i][j] * b[j] ;
    
    for (int i = 0; i < n; ++i)
        cout << c[i] << endl;
    
    return 0;
}


Measured memory_bytes: 3100
k,n=map(int,input().split())
a=[int(i) for i in input().split()]

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

distances.append(k-a[len(a)-1]+a[0])

m=max(distances)

print(k-m)

Measured memory_bytes: 25452
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a*n,b)<<endl;
}



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

int main() {
  int N, sum = 0, n;
  cin >> N;
  n = N;

  while(n){
    sum += n % 10;
    n = n / 10;
  }

  if (N % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	ini(n);
	out(n*n*n);
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

int main() {
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	

	cout << X * min(N, K) + Y * (N - K) * (N > K) << endl;
	return 0;
}

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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  
  L = A + B;
  R = C + D;
  if(L > R){
    cout << "Left" << endl;
   }else{
    if(L == R){
    cout << "Balanced" << endl;
    }else{
      cout << "Right" << endl;
    }
   }
}

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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld Pi = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 1e3 + 10;
const ll INF = (ll) 3e18;
const ld EPS = (ld) 1e-8;

ll a[3];

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

    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout << a[2] - a[0];

}

/*
*/


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

typedef long long ll;

const int maxn = 3e5 + 6;

ll a[maxn];
ll sm[maxn];
ll sma[maxn];

int n; int m;

void smc() {
	multiset<int> S = *new multiset<int>();
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		S.insert(a[i]);
		sum += a[i];
		if (S.size() > m) {
			sum -= *S.begin();
			S.erase(S.begin());
		}
		sm[i] = sum;
	}
}
	
		

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	
	cin>>n;  m = n; n = n*3;
	
	for (int i = 1; i <= n; i++) {
		cin>>a[i];
	}
	
	smc();
	for (int i = 1; i <= n; i++) { sma[i] = sm[i]; a[i] = -a[i];}
	
	reverse(a+1,a+n+1);
	smc();
	
	ll ans = -1e15;
	
	for (int i = m; i <= n-m; i++) { ans = max(ans, sma[i] + sm[n-i]); }
	
	cout<<ans<<endl;
}
		


Measured memory_bytes: 12032
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    string s;
    cin >> s;

    int v = s[0];

    bool isUpper = ('A' <= v && v <= 'Z');
    cout << (isUpper ? 'A' : 'a') << endl;

    return 0;
}


Measured memory_bytes: 3608
/* ex 7_1
   Rikuta */

#include <stdio.h>
//point型の構造体を定義
typedef struct point
{   
    //中身はint型が二つ,x座標,y座標
    int x_elem;
    int y_elem;
}point;

//point型を返す，引数としてpointを二つもつ関数の定義
point shift_point(point p_past,point p_now){
    //次の点の宣言
    point nextpoint;

    //次の点のx,y座標の計算
    nextpoint.x_elem = p_now.x_elem - (p_now.y_elem - p_past.y_elem);
    nextpoint.y_elem = p_now.y_elem + (p_now.x_elem - p_past.x_elem);
    
    //次の点を返す
    return nextpoint;
}


int main(void)
{
    //point型の座標配列を準備
    point coordinates[4];

    //入力
    scanf("%d%d%d%d", &coordinates[0].x_elem, &coordinates[0].y_elem, &coordinates[1].x_elem, &coordinates[1].y_elem);
    
    for (int i = 2; i <= 3; i++)
    {   
        //shift_point関数を用いて，3,4番目の座標を計算
        coordinates[i] = shift_point(coordinates[i - 2], coordinates[i - 1]);
        
        //計算した座標を出力
        printf("%d %d ", coordinates[i].x_elem, coordinates[i].y_elem);
    }

    //改行
    printf("\n");
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;using int32=int_fast32_t;using uint32=uint_fast32_t;using int64=int_fast64_t;using uint64=uint_fast64_t;using pi=pair<int32,int32>;using pll=pair<int64,int64>;using vi=vector<int32>;using vvi=vector<vector<int32>>;using vll=vector<int64>;using ll=int64;using ull=uint64;
#define all(x) x.begin(),x.end()
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
struct A{
    ll t,d;
    int s=0;
};
void Main(){
    int N = read();
    int K = read();
    vector<struct A> a(N);
    for(int i=0;i<N;i++){
        a[i].t = read();
        a[i].d = read();
    }
    sort(all(a), [](const auto& lhs, const auto& rhs) {return lhs.d > rhs.d;});
    vi U(N+1,0);
    ll D=0;
    for(int i=0;i<N;i++) if(U[a[i].t] == 0){
        if(i<K) D++;
        U[a[i].t]++;
        a[i].s++;
    }
    vi C1(N,0), C2(N,0);
    int j=0;
    for(int i=K-1;i>0;i--) if(a[i].s==0) C1[j++]=i;
    j=0;
    for(int i=K;i<N;i++) if(a[i].s==1) C2[j++]=i;
    ll Ans, T = 0;
    for (int h = 0; h < K; h++) T += a[h].d;
    Ans = T + D * D;
    for(int i=0;i<=K;i++) if((C1[i]==0)||(C2[i]==0)) break;
    else{
        swap(a[C1[i]], a[C2[i]]);
        D++;
        ll ans;
        T = 0;
        for (int h = 0; h < K; h++) T += a[h].d;
        ans = T + D * D;
        Ans = max(Ans, ans);
    }
    printf("%lld\n", Ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}


Measured memory_bytes: 4992
N = int(input())
A = []
B = []
for i in range(N):
  temp = list(map(int, input().split()))
  A.append(temp[0])
  B.append(temp[1])
As = sorted(A)
Bs = sorted(B)

if(N%2==1):
  print(Bs[N//2] - As[N//2] + 1)
else:
  ans = ( (Bs[N//2-1]+Bs[N//2])/2 - (As[N//2-1]+As[N//2])/2 ) * 2 + 1
  print(int(ans))

Measured memory_bytes: 28700
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int main(){
	string s;
	cin >> s;
	int i,n,a = 0,b = 0, c = 0;
	n = s.size();
	for(i=0;i<n;i++){
		if(s[i]=='a'){
			a++;
		}
		if(s[i]=='b'){
			b++;
		}
		if(s[i]=='c'){
			c++;
		}
	}
	int u = max({a,b,c}),v = min({a,b,c});
	if(u-v<=1){
		cout << "YES" << endl;
		return 0;
	}
	cout  << "NO" << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define _GLIBCXX_DEBUG
 
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
 
 
 
int main(){
	ll n;
	cin>>n;
	vector<string> s(n);
	map<string,ll> mp;
 
	for (size_t i = 0; i < n; i++)
	{
		cin>>s.at(i);
	}
 
	for (size_t i = 0; i < n; i++)
	{
		mp[s.at(i)]++;
		
	}
	
	ll mx = 0;
 
	for (auto p : mp)
	{
		mx = max(mx,p.second);
	}
 
	for (auto p : mp)
	{
		if (p.second != mx)
		{
			continue;
		}
		cout<<p.first<<endl;
		
	}
	
	
	
}

Measured memory_bytes: 26752
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int strcmp_custom(char* s1, char* s2);


int main(int argc, const char * argv[]) {
    // insert code here...
    
    char w[11];
    char s[1000];
    
    scanf("%s",w);
    
    int count = 0;
    while(1){
        scanf("%s",s);
        
        if(strcmp(s, "END_OF_TEXT") == 0){
            break;
        }
        else if(strcmp_custom(s, w)){
            count++;
        }
        
    }

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

int strcmp_custom(char* s1, char* s2){
    
    int i=0;
    while(1){
        
        if(s1[i] == '\0' && s2[i] == '\0'){
            return 1;
        }
        if(s1[i] == '\0' || s2[i] == '\0'){
            return 0;
        }
        else if(toupper(s1[i]) == toupper(s2[i])){
            i++;
        }
        else{
            return 0;
        }
        
    }

}

Measured memory_bytes: 540
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
typedef pair<int,int> P;
string s;
vector<P> ans;

int main(){
	cin>>s;
	int n=(int)s.size();
	bool flg=true;
	if (s[n-1]!='0'){
		flg=false;
	}
	if (s[0]=='0'){
		flg=false;
	}
	REP(i,n/2){
		if (s[i]!=s[n-i-2]){
			flg=false;
		}
	}
	if (flg){
		ans.push_back(P(1,2));
		int v=2;
		if (n==2){
			goto COR;
		}
		FOR(i,1,(n-1)/2){
			if (s[i]=='0'){
				ans.push_back(P(v,i+2));
			}else{
				ans.push_back(P(v,i+2));
				v=i+2;
			}
		}
		if (n&1){
			for(auto &ite:ans){
				int &f=ite.first,&s=ite.second;
				if (f==v){
					f=n;
				}else if (f>v){
					f--;
				}
				if (s==v){
					s=n;
				}else if (s>v){
					s--;
				}
			}
			REP(i,n/2){
				P p=ans[i];
				int f=p.first,s=p.second;
				if (f<n){
					f=n-f;
				}
				if (s<n){
					s=n-s;
				}
				ans.push_back(P(f,s));
			}
		}else{
			if (s[n/2-1]=='1'){
				REP(i,n/2-1){
					P p=ans[i];
					ans.push_back(P(n+1-p.first,n+1-p.second));
				}
				ans.push_back(P(v,n+1-v));
			}else{
				for(auto &ite:ans){
					int &f=ite.first,&s=ite.second;
					if (f==v){
						f=n/2;
					}else if (f>v){
						f--;
					}
					if (s==v){
						s=n/2;
					}else if (s>v){
						s--;
					}
				}
				REP(i,n/2-1){
					P p=ans[i];
					int f=p.first,s=p.second;
					if (f<n/2){
						f=n-f;
					}
					if (s<n/2){
						s=n-s;
					}
					ans.push_back(P(f,s));
				}
				ans.push_back(P(n/2,n));
			}
		}
		COR:
		for(auto ite:ans){
			cout<<ite.first<<" "<<ite.second<<endl;
		}
	}else{
		cout<<-1<<endl;
	}
	return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c && a == c){
        cout << 1 << endl;
    }else if(a == b || b == c || a == c){
        cout << 2 << endl;
    }else{
        cout << 3 << endl;
    }
}

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

int main()
{
	ll k, x;
	cin >> k >> x;

	for(ll i = x-k+1; i <= x+k-1; ++i) cout << i << " ";
	cout << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll gcd (ll x, ll y){
    if (y == 0)return x;
    else return gcd(y, x%y);
}


int main() {
    int N, X;
    cin >> N >> X;
    vector<int>Xs(N);
    for(int i=0; i<N; i++){
        int xi;
        cin >> xi;
        Xs[i] = abs(xi-X);
    }

    ll g = 0;
    for (int i=0; i<N; i++){
        g = gcd(g,Xs[i]);
    }
    cout << g << endl;


}

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



int main(){
    string s;
    cin >>s;
    set<char> st;
    for(int i=0;i<s.size();i++){
        if(st.count(s[i])){
            cout<<"no"<<endl;
            break;
        }else{
            st.insert(s[i]);
            if(i==s.size()-1){
                cout<<"yes"<<endl;
            }
        }
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <string>
#include <sstream>
#include <iostream>
#include <math.h>
#include <random>
#include <cstdio>
using namespace std;

const int LOOP = 1000; //??????????????°
const double EPS = 1e-6; //??????????????¨(?°??????????????????????)
int L;
int N; //???????????±???????????°

//???????????±????????????????????????????????¨?????¨???????¨????????¨??????????
double Evaluate(int r[12]) {
	double val = r[0] + r[N-1];
	for (int i = 0; i < N - 1; i++)
	{
		int a = abs(r[i] - r[i+1]), c = r[i] + r[i+1];
		val += sqrt(c*c - a*a);
	}
	return val;
}

//?????¨?????????????????°???????????¨??????????????????????§???????????±???????
//(????§?????????????true)
bool Changes(int cnt) {
	return cnt < rand()%LOOP;
}

//?????????????????????????????¢??°
//?????????????°??????????????¨?????????????
//int r[12] : ???????????±?????????0??????N-1???????????????????????????????????????????????????????´???????
double Solve(int r[12]) {
	double score = Evaluate(r); //?????¨?????¶???r[]????¨???????????´????????????°
	double mi = score; //???????????§?????¶???????¨???????????°???????????´????????????°
	for (int cnt = 0; cnt < LOOP; cnt++)
	{
		//===============================================

		///random
        int i=rand()%N;
        int j=rand()%N;
        int t=r[i];
        r[i]=r[j];
		r[j]=t;
        score = Evaluate(r);
		if(score<mi){
            mi=score;
		}else{
            if(Changes(cnt)){
                mi=score;
            }else{
                int a=r[i];
                r[i]=r[j];
                r[j]=a;
            }
		}
		//===============================================
	}
	return mi; //????°?????????????
}

//??\?????¢????????????????????¢????????£????????§???????????????
int main() {
    srand(time(NULL));
	while (cin >> L)
	{
		N = 0;
		int r[12];
		string S;
		getline(cin, S);
		stringstream SS(S);
		while (!SS.eof()) SS >> r[N++];

		double ans;
		if (N == 1) ans = r[0]*2;
		else ans = Solve(r);

		if (L - ans + EPS > 0) puts("OK");
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 3076
#include <stdio.h>

int memo[2][5001][10000];

int N;
int map[10000-1];

int tansaku(int pos,int rest,int status) {
	int result=0x3fffffff;
	int now_result;
	if(pos>=N-1)return (rest-status==0)?0:0x3fffffff;
	if(rest<0)return 0x3fffffff;
	if(memo[status][rest][pos]>0)return memo[status][rest][pos]-1;
	if(status) {
		now_result=tansaku(pos+1,rest-1,1);
		if(now_result<result)result=now_result;
		now_result=tansaku(pos+1,rest-1,0)+map[pos];
		if(now_result<result)result=now_result;
	} else {
		now_result=tansaku(pos+1,rest,0);
		if(now_result<result)result=now_result;
		now_result=tansaku(pos+1,rest,1)+map[pos];
		if(now_result<result)result=now_result;
	}
	memo[status][rest][pos]=result+1;
	return result;
}

int main(void) {
	int i;
	int result;
	scanf("%d",&N);
	for(i=0;i<N-1;i++)scanf("%d",&map[i]);
	result=tansaku(0,N/2,0);
	printf("%d\n",result);
	return 0;
}

Measured memory_bytes: 0
// 2011/02/06 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

class Team{
	public:
		char name;
		int  win;
		int  defeat;
		int  draw;

		bool operator < (const Team& t) const
		{
			if(win==t.win)
				return defeat<t.defeat;
			else
				return win>t.win;
		}
};

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		Team T[10];
		for(int i=0; i<n; i++){
			cin >> T[i].name;
			T[i].win = T[i].defeat = T[i].draw = 0;
			for(int j=0; j<n-1; j++){
				int r;
				cin >> r;
				if(r==0)
					T[i].win++;
				else if(r==1)
					T[i].defeat++;
				else if(r==2)
					T[i].draw++;
			}
		}

		stable_sort(T, T+n);

		for(int i=0; i<n; i++)
			cout << T[i].name << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, K, Q = map(int, readline().split())
    As = map(int, readlines())
    Ps = [0] * N
    for A in As:
        Ps[A-1] += 1
    for P in Ps:
        if Q - P < K:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 8612
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll N;
    cin >> N;
    vector<ll> As(N);
    rep(i,0,N) {
        cin >> As[i];
    }
    unordered_map<ll, ll> diffmap;
    ll ans = 0;
    rrep(i,N,0) {
        ans += diffmap[As[i] + i];
        diffmap[i-As[i]]++;
    }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
    long long n, m;
    cin >> n >> m;
    long long ans = 0;
    long long kS = m / 2;
    if(n <= kS){
        ans += n;
        kS -= n;
        if(kS != 0){
            ans += kS / 2;
        }
    }
    else{
        ans = min(kS, n);
    }

    cout << ans;
    return 0;
}


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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int a, b;
  cin >> a >> b;
  int mid = a + b >> 1;
  if (abs(a - mid) == abs(b - mid)) {
    cout << mid << "\n";
  } else {
    cout << "IMPOSSIBLE\n";
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 256
<?php
// Your code here!
// $s = trim(fgets(STDIN));
$right = trim(fgets(STDIN));
$left = "";
$num = trim(fgets(STDIN));
$rev_flg = false;
for($i=0; $i<$num; $i++){
    $q = trim(fgets(STDIN));
    if($q == 1){
        $rev_flg = !$rev_flg;
    }else{
        list($a, $f, $st) = explode(" ", $q);
        
        if($rev_flg == false){
            if($f == 1){
                $left = $left . $st;
            }else{
                $right = $right . $st;
            }
        }else{
            if($f == 1){
                $right = $right . $st;
            }else{
                $left = $left . $st;
            }
        }
    }
}

$str = strrev($left) . $right;
$str = $rev_flg == false ? $str : strrev($str);

echo $str;



?>

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

int n;
char s[1234567];
int mod = 998244353;
int p2[1234567];
int ans;
int dlaD[1234567];

bool dzialaPref(int d) {
	int m = n/d;
	
	for (int i=0; i < d; i++) {
		for (int j = 0; j < m; j++) {
			int dig = s[j]-'0';
			dig = (dig + (i%2))%2;
			if (dig < (s[i*m+j]-'0')) return true;
			if (dig > (s[i*m+j]-'0')) return false;
		}
	}
	return true;
}

int prefMod(int d) {
	int m = n/d;
	int lans = 0;
	FOR(i,0,m) {
		lans = (2*lans+s[i]-'0') % mod;
	}
	return lans;
}

int main() {
	read(n);
	scanf("%s", s);
	p2[0] = 1;
	FOR(i,1,2*n+5) p2[i] = (p2[i-1]+p2[i-1]) % mod;
	ans = 2*n;
	FOR(i,0,n) ans = (ans + p2[n-1-i]*(s[i]-'0')*2LL*n) % mod;
	// ans = (2n)*(x+1)
	for (int d = 3; d <= n; d+=2) {
		if (n%d != 0) continue;
		int m = n/d;
		dlaD[d] = (dlaD[d] + prefMod(d)) % mod;
		if (dzialaPref(d)) {
			dlaD[d]++;
		}
		dlaD[d]%=mod;
	}
	for (int d = n; d >= 1; d--) {
		if (n%d != 0) continue;
		if (d%2!=1) continue;
		for (int j = 1; j<d; j+=2) {
			if (d%j==0) {
				dlaD[j] = (dlaD[j] + mod- dlaD[d]) %mod;
			}
		}
	}
	for (int d = 3; d <=n; d+=2) {
		if (n%d != 0) continue;
		int m = n/d;
		ans +=(((2LL*(m-n+mod))%mod)*1LL*dlaD[d])%mod;
		ans %= mod;
	}
	printf("%d\n", ans);
}





Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=508,p=998244353,inf=0x3f3f3f3f;
int read(){
    int f=1,g=0;char ch=getchar();
    for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
    for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
    return f*g;
}
int n,m;
ll a[N][N],b[N][N],f[N][N];
ll getsum(ll a[][N],int lx,int ly,int rx,int ry)
{return a[rx][ry]-a[rx][ly-1]-a[lx-1][ry]+a[lx-1][ly-1];}
void chkmin(ll &x,ll y){if (x>y) x=y;}
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		for (int j=1;j<i;j++) b[i][j]=read();
		for (int j=i+1;j<=n;j++) a[i][j]=read();
		for (int j=1;j<=n;j++)
		a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1],
		b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1];
	}
	memset(f,0x3f,sizeof(f));
	f[0][0]=0;
	for (int i=0;i<n;i++)
	for (int j=0;j<=max(i-1,0);j++)
	for (int k=i+1;k<=n;k++)
	chkmin(f[k][i],f[i][j]+getsum(a,i+1,i+1,k,k)+getsum(b,k+1,j+1,n,i));
	ll ans=f[n][0];
	for (int i=1;i<n;i++) chkmin(ans,f[n][i]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <functional>
 
using namespace std;
 
int main() {
  int N, M;
  
  cin >> N >> M;
  
  vector<int> A(N);
  for (auto i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<int>());
  auto sum = accumulate(A.begin(), A.end(), 0);
  if (A[M-1] >= sum / (4.0 * M)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

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

int main(){
    int a;
    cin >>a ;
    cout << a + a*a + a*a*a << endl;

    return 0;
}

Measured memory_bytes: 3576
s=input()
t=input()

slen=len(s)
tlen = len(t)
min = tlen

for i in range(slen - tlen + 1):
    count = 0
    for j in range(tlen):
        if s[i + j] != t[j]:
            count += 1
    if count < min:
        min = count

print(min)

Measured memory_bytes: 67392
package main

import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)

const MaxBuf = 200100
var buf []byte
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf,MaxBuf)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt64() int64 {
	sc.Scan()
	r,_ := strconv.ParseInt(sc.Text(),10,64)
	return r
}

func readInt() int {
   sc.Scan()
   r,_ := strconv.Atoi(sc.Text())
   return r
}

func readFloat64() float64 {
	sc.Scan()
	r,_ := strconv.ParseFloat(sc.Text(),64)
	return r
}

func main() {
	n := readInt()
	k := readInt()
	ans := 0
	for i := 0; i < n; i++ {
		if readInt() >= k {
			ans++
		}
	}
	fmt.Println(ans)

}

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

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

  int near = 999999;
  int num;
  string str;
  for (int i = 0; i < S.size() - 2; i++)
  {
    str = S.substr(i, 3);
    num = stoi(str);
    if (abs(753 - num) < near){
      near = abs(753 - num);
    }  
  }
  
  cout << near << endl;
}

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

int main(){
  int k;
  string s;
  cin >> k >> s;
  if(s.size() > k) s=s.substr(0,k)+"...";
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3632
from itertools import accumulate

MOD = 10 ** 9 + 7
table_len = 2 * 10 ** 5 + 10

fac = [1, 1]
for i in range(2, table_len):
    fac.append(fac[-1] * i % MOD)
    
finv = [0] * table_len
finv[-1] = pow(fac[-1], MOD - 2, MOD)
for i in range(table_len-1, -1, -1):
    finv[i-1] = finv[i] * i % MOD


N = int(input())

adj = [[] for _ in range(N+1)]

for _ in range(N-1):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)


dfs_order = []
parent = [0] * (N+1)
root = 1
stack = [root]
while stack:
    node = stack.pop()
    dfs_order.append(node)
    for child in adj[node]:
        if child != parent[node]:
            parent[child] = node
            stack.append(child)


dp1_size = [1] * (N+1)
for node in reversed(dfs_order):
    for child in adj[node]:
        if child != parent[node]:
            dp1_size[node] += dp1_size[child]

dp2_size = [0] * (N+1)
for node in dfs_order:
    around = [dp1_size[next_node] if next_node != parent[node] else dp2_size[node] for next_node in adj[node]]
    from_left = [0] + list(accumulate(around))[:-1]
    from_right = list(accumulate(reversed(around)))[-2::-1] + [0]
    without = [l + r for l, r in zip(from_left, from_right)]
    for next_node, value in zip(adj[node], without):
        if next_node != parent[node]:
            dp2_size[next_node] += value + 1

dp1 = [1] * (N+1)
for node in reversed(dfs_order):
    s = 0
    for child in adj[node]:
        if child != parent[node]:
            s += dp1_size[child]
            dp1[node] *= dp1[child]
            dp1[node] %= MOD
            dp1[node] *= finv[dp1_size[child]]
            dp1[node] %= MOD
    dp1[node] *= fac[s]
    dp1[node] %= MOD

def func(t1, t2):
    size1, value1 = t1
    size2, value2 = t2
    size = size1 + size2
    comb = fac[size] * finv[size1] * finv[size2] % MOD
    value = comb * value1 * value2 % MOD
    return (size, value)
        
dp2 = [1] * (N+1)
for node in dfs_order:
    around_size = [dp1_size[next_node] if next_node != parent[node] else dp2_size[node] for next_node in adj[node]]
    around = [dp1[next_node] if next_node != parent[node] else dp2[node] for next_node in adj[node]]
    
    from_left = [(0, 1)] + list(accumulate(zip(around_size, around), func))[:-1]
    from_right = list(accumulate(reversed(list(zip(around_size, around))), func))[-2::-1] + [(0, 1)]
    without = [func(l, r) for l, r in zip(from_left, from_right)]
    for next_node, (_, value) in zip(adj[node], without):
        if next_node != parent[node]:
            dp2[next_node] = value

for size1, val1, size2, val2 in zip(dp1_size[1:], dp1[1:], dp2_size[1:], dp2[1:]):
    print(func((size1 - 1, val1), (size2, val2))[1])

Measured memory_bytes: 196180
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final long MOD = 1000000007;
	public static void main(String[] args) {
		int i=0,j=0,k=0;
		Scanner sc = new Scanner(in);
		char[] s = sc.next().toCharArray();
		sc.close();
		long[] n = new long[s.length];
		for (i = 0; i < s.length; i++) {
			n[i] = s[i]-'0';
		}
		long sum = ston(n, 0, s.length);
		int mx = (int) pow(2,s.length-1);
		for (i = 1; i < mx; i++) {
			int sp=0;
			int ep=1;
			j=i;
			while(j>0) {
				if((j & 1) == 1) {
					sum += ston(n, sp, ep);
					sp=ep;
				}
				ep++;
				j >>>= 1;
			}
			sum += ston(n, sp, s.length);
		}
		out.println(sum);
	}
	public static long ston(long[] n, int s, int e) {
		long m = 0;
		for (int i = s; i < e; i++) {
			m*=10;
			m+= n[i];
		}
		return m;
	}
}


Measured memory_bytes: 21844
from collections import deque
h, w = map(int, input().split())
s_list = []
for _ in range(h):
    s = input()
    s_list.append(s)
d = deque()
count = 0
if s_list[0][0] == '#':
    count += 1
d.append([0, 0, count])

vis = [[101 for i in range(w)] for j in range(h)]
if s_list[0][0] == '.':
    vis[0][0] = 0
else:
    vis[0][0] = 1
for x in range(h):
    for y in range(w):
        for xx, yy in [[1, 0], [0, 1]]:
            if (0 <= x + xx < h) & (0 <= y + yy < w):
                if (s_list[x][y] == '.') & (s_list[x + xx][y + yy] == '#'):
                    vis[x + xx][y + yy] = min(vis[x][y] + 1, vis[x + xx][y + yy])
                else:
                    vis[x + xx][y + yy] = min(vis[x][y], vis[x + xx][y + yy])          
print(vis[-1][-1])

Measured memory_bytes: 3444
#include <iostream>
#include <cmath>

int main() {
  int A, B;
  std::cin >> A >> B;

  int AL = std::ceil(12.5 * A);
  int AH = std::ceil(12.5 * (A + 1));
  int BL = std::ceil(10.0 * B);
  int BH = std::ceil(10.0 * (B + 1));

  int ans = -1;

  if (AL < BH && BL < AH) ans = std::max(AL, BL);

  std::cout << ans << std::endl;

  return 0;
}


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

int main() {
    int N; 
    cin >> N;
    int H[N];
    for (int i=0; i<N; i++) scanf("%d", &H[i]);

    int ans=0, move_num=0;
    for (int i=0; i<N-1; i++) {
        if (H[i] >= H[i+1]) move_num++;
        else move_num = 0;
        
        ans = max(ans, move_num);
    }

    cout << ans << endl;

    return 0;
}



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

ll n;

void dfs(string s,char mx){
    if(s.size()==n){
        cout << s << endl;
    }
    else{
        for(char c='a';c<=mx;c++){
            if(c==mx){
                dfs(s+c,mx+1);
            }
            else{
                dfs(s+c,mx);
            }
        }
    }
}

int main(){
    cin >> n;
    dfs("",'a');
    return 0;
}  


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    int money = 0;
    if (a >= 13){
        money = b;
    }
    else if (a >= 6){
        money = b / 2;
    }
    else{
        money = 0;
    }
    cout << money << endl;
}

Measured memory_bytes: 256
def dfs(to, history)
  if history.include?(to)
    target = history.slice(history.index(to), history.count - history.index(to))
    flag = true
    target.each do |i|
      unless (target - $ways[i]).count == target.count - 1
        flag = false
        break
      end
    end

    if flag
      puts target.count
      target.each do |i|
        puts i
      end
      exit
    else
      return
    end
  end

  $already << to
  next_history = history + [to]
  return if $ways[to].nil?
  $ways[to].each do |t|
    dfs(t, next_history)
  end
end

N, M = gets.split.map(&:to_i)
arrs = M.times.map { gets.split.map(&:to_i) }
$ways = arrs.group_by { |arr| arr[0] }.map { |k, v| [k, v.map { |vv| vv[1]}] }.to_h

$already = []

$ways.each do |from, to|
  $already = $already.uniq
  unless $already.include?(from)
    to.each do |t|
      $already << from
      dfs(t, [from])
    end
  end
end

puts '-1'

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

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    if (a-k>=0)cout << a-k << " " << b << endl;
    else if (a+b-k>=0) cout << 0 << " " << a+b-k << endl;
    else cout << 0 << " " << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <limits>
const int mod = 1e9 + 7;
#define INF 1000000000000000
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
long long gcd(long long a, long long b) {
    if (a < b)
        swap(a, b);
    long long r = a % b;
    if (r == 0)
        return b;
    else
        return gcd(b, r);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n; cin >> n;
    string s, t; cin >> s >> t;
    rep(i, n) cout << s.at(i) << t.at(i);
}

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

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

int main( void )
{
	ll n;
	cin >> n;

	vector<P> time(n);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		time[i] = make_pair(b, a);
	}
	sort(time.begin(), time.end());

	ll now = 0;
	rep(i, n) {
		now += time[i].second;
		if ( now > time[i].first ) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


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

using namespace std;

using i64 = long long;

const i64 MOD = 998244353;
const i64 INF = i64(1e18) + 7;


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

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


template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


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

    auto mpow = [](auto x, i64 y){
        auto z = x;
        decltype(x) val = y & 1 ? x : decltype(x)(1);
        while(z *= z, y >>= 1)
            if(y & 1)
                val *= z;
        return val;
    };

    auto calc_fact = [mpow]{
     constexpr int N = 5e6;
     vector<mint> fact(N + 1, 1);
     vector<mint> inv(N + 1, 1);
     for(int i = 1; i < N; ++i){
      fact[i + 1] = fact[i] * (i + 1);
      inv[i + 1] = mpow(fact[i + 1], MOD - 2);
     }
     return make_pair(fact, inv);
    };
    vector<mint> fact, inv;
    tie(fact, inv) = calc_fact();

    auto ncr = [&fact, &inv](int n, int r){
     if(n < 0 || r < 0 || n < r)
      return mint(0);
     return fact[n] * inv[r] * inv[n - r];
    };

    // 総和3Mになる通り数
    // N-1個のしきりを入れる
    mint ans = ncr(3 * m + n - 1, n - 1);
    for(int ma = 2 * m + 1; ma <= 3 * m; ++ma){
        ans -= ncr(3 * m - ma + n - 2, n - 2) * n;
    }

    for(int cnt = m + 1; cnt <= n; ++cnt){
        mint val = 1;
        val *= ncr(n, cnt);
        int diff = 3 * m - cnt;
        if(diff % 2 == 0){
            val *= ncr(diff / 2 + n - 1, n - 1);
            ans -= val;
        }
    }

    cout << ans << endl;
}





Measured memory_bytes: 156544
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

separate as (b : bs) asum bsum
  | abs (bsum - asum) > abs (bsum - asum - 2 * b) = separate (b : as) bs (asum + b) (bsum - b)
  | otherwise = [asum, bsum]

main = do
  n <- getInt
  as <- getIntList
  let [asum, bsum] = separate [] as 0 (sum as)
  print $ abs (asum - bsum)


Measured memory_bytes: 16156
N = int(input())
A = list(map(int, input().split()))
 
ans = [0]*N
for i in range(N):
  ans[A[i]-1] = str(i+1)

# 答えを出力する。print(end=...)は便利！
for i in range(N):
  print(ans[i], end=' ')

Measured memory_bytes: 20436
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(abs(a[i]-a[j])%(n-1)==0){
				cout<<a[i]<<' '<<a[j]<<endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;

int main ()
{
  int H, W;
  cin >> H >> W;
  char s[50][50];

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s[i][j];
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s[i][j] == '#') {
        if ((j > 0 && s[i][j-1] == '#') ||
            (i > 0 && s[i-1][j] == '#') ||
            (j < W-1 && s[i][j+1] == '#') ||
            (i < H-1 && s[i+1][j] == '#')) {
        } else {
          printf ("No\n");
          return 0;
        }
      }
    }
  }
  printf("Yes\n");

}



Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s, t, u;
  int a, b;

  cin >> s >> t;
  cin >> a >> b;
  cin >> u;

  if (s == u)
    cout << a - 1 << " " << b << endl;
  else
    cout << a << " " << b - 1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>;
int main(void){
  int A,B,ans;
  int sum,mult,sub;
  char s[10];
  scanf("%d %d",&A,&B);
  if(A+B<=A-B)ans=A-B;
  else ans=A+B;
  if(ans<=A*B)ans=A*B;
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define LL long long
LL myabs(LL a){
	return a>=0?a:-a;
}
int main(){
	LL x,k,d,ans;
	scanf("%lld%lld%lld",&x,&k,&d);
	x=myabs(x);
	if(x/d>=k)ans=x-k*d;
	else{//x/d<k
		k-=x/d;
		if(k%2==0)ans=x%d;
		else ans=d-x%d;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1696
from collections import defaultdict,deque
import sys, bisect, math, itertools
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

n, m = inpl()
h = inpl()
v=[True for i in range(n)]
for i in range(m):
    a, b = inpl()  # h[a-1]>h[b-1]
    if h[a - 1] == h[b - 1]:
        v[a - 1] = False
        v[b - 1] = False
    elif h[a - 1] < h[b - 1]:
        v[a - 1] = False
    else:
        v[b - 1] = False
print(v.count(True))

Measured memory_bytes: 86496
N, Q = map(int, input().split())
S = list(input())

encount_func = {}
count = 0
encount_func[0] = 0
for i in range(1,N):
    check_str = S[i-1] + S[i]
    #print(check_str)
    if check_str == "AC":
        count += 1
        encount_func[i] = count
    else:
        encount_func[i] = count

#print(encount_func)
#for key in encount_func:
#    print(encount_func[key])

ans = []
for _ in range(Q):
    L, R = map(int, input().split())
    ans.append(encount_func[R-1] - encount_func[L-1])

for i in range(Q):
    print(ans[i])

Measured memory_bytes: 19488
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, C, K = map(int, input().split())
T = [0]*N
for i in range(N):
    T[i] = int(input())
T.sort()
count = 1
tmp = 0
_tmp = 0  # 乗せた人数、直前のバスまでに乗せた人数
while tmp < N-1:
    tmp += 1
    if (tmp - _tmp == C or T[tmp] - T[_tmp] > K):
        _tmp = tmp
        count += 1
print(str(count))


Measured memory_bytes: 7472