akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

const ll MAX = 5000001;//10^7が限界
const ll MOD = Mod;
//const ll MOD = INT64_MAX;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

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


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>k;
    ll bl = k;
    ll re = n-k;
    COMinit();
    repi(i,1,k+1){
        ll tmp = COM(bl-1,i-1);
        ll tmp2 = COM(re+1,i);
        tmp %= Mod;
        tmp2 %= Mod;
        ll ans = tmp*tmp2;
        ans %= Mod;
        print(ans);
    }
    return 0;
}

Measured memory_bytes: 117504
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f(i,a,b) for(ll i=a; i<b; i++)
ll gcd(ll ina, ll inb) 
{     
    if (ina == 0) 
       return inb; 
    if (inb == 0) 
       return ina; 
   
    
    if (ina == inb) 
        return ina; 
   
    if (ina > inb) 
        return gcd(ina-inb, inb); 
    return gcd(ina, inb-ina); 
} 
ll lcm(ll in1, ll in2)
{ ll ans=1; ans=(in1*in2)/gcd(in1,in2); 
return ans;
}
int main()
{ ll n; cin>>n;  ll a[n][3]={}; ll b,c,d; cin>>b>>c>>d; a[0][0]=b; a[0][1]=c; a[0][2]=d;
f(i,1,n)  {  cin>>b>>c>>d;  a[i][0]=b+max(a[i-1][1],a[i-1][2]); a[i][1]=c+max(a[i-1][0],a[i-1][2]); a[i][2]=d+max(a[i-1][0],a[i-1][1]);  }
ll ans=0; ans=max(ans,a[n-1][0]); ans=max(ans,a[n-1][1]); ans=max(ans,a[n-1][2]);  cout<<ans;}   






Measured memory_bytes: 5916
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

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

    if(a>b)ans+=b;
    else ans+=a;
    if(c>d)ans+=d;
    else ans+=c;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vll vector<ll>
#define pb push_back
#define x first
#define y second

struct data
{
	int len,i_,j_;
	char c;
};

data max_of(data a, data b)
{
	return a.len>b.len ? a : b;
}

int main()
{
	IOS
  	string s,t;
	cin>>s;
	cin>>t;
	vector<vector<data> > dp(s.length()+1,vector<data> (t.length()+1,{0,-1,-1,'\0'}));int i,j;
	for(i=1;i<=s.length();i++)
	{
		for(j=1;j<=t.length();j++)
		{
			if(s[i-1] == t[j-1])
				{
					dp[i][j].len=dp[i-1][j-1].len+1;
					dp[i][j].i_ = i-1;
					dp[i][j].j_ = j-1;
					dp[i][j].c = s[i-1];
				}
			else
				dp[i][j]=max_of(dp[i-1][j],dp[i][j-1]);

			//cout<<i<<' '<<j<<' '<<dp[i][j].c<<' '<<dp[i][j].i_<<' '<<dp[i][j].j_<<'\n';
		}
	}
	data ans =dp[s.length()][t.length()];
	string r;
	while(ans.i_>=0 && ans.j_>=0)
	{
		r += ans.c;
		ans=dp[ans.i_][ans.j_];
	}
	reverse(r.begin(),r.end());
	cout<<r;
}

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

using namespace std;

int n;
long long k, a[200010], b[200010];

bool cmp(const long long &l, const long long &r)
{
    return l > r;
}

void Input()
{
    ios_base::sync_with_stdio(0);       cin.tie(0);

    cin >> n >> k;
    for (int i=1; i<=n; i++)
        cin >> a[i];
    for (int i=1; i<=n; i++)
        cin >> b[i];

    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1, cmp);
}

long long Divide(long long u, long long v)
{
    if (u % v != 0) return u / v + 1;
    return u / v;
}

bool check(long long t, long long e)
{
    for (int i=1; i<=n; i++)
        if (a[i]*b[i] > t)
        {
            if ((long long) a[i]*b[i] <= (long long) t) continue;

            long long o = Divide((a[i]*b[i] - t), b[i]);
            if (o > e) return false;
            e -= o;
        }

    return true;
}

void Process()
{
    long long l = -1, r = 1e15+1;

    while (r - l > 1)
    {
        long long mid = (l + r) >> 1;
        if (check(mid, k)) r = mid;
            else l = mid;
    }

    cout << r;
}

int main()
{
    Input();
    Process();
    return 0;
}


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

#define ll long long

#define MAX_N 200001


/*
 * - 入力を期待値に変える
 * - 累積和を求める
 */
ll N, K;
vector<double> S(MAX_N, 0);

void input() {
  ll a;
  double total = 0;
  cin >> N >> K;
  S.at(0) = 0;
  for (ll i=1; i<=N; i++) {
    cin >> a;
    total = 0.0;
    for (int j=1; j<=a; j++) {
      total += (double)j;
    }
    total /= (double)a;
    S.at(i) = total + S.at(i-1);
  }
}

void solve() {
  double max_ = 0;
  for (ll i = 0; i<=N-K; i++) {
    if (max_ < S.at(i+K) - S.at(i)) {
      max_ = S.at(i+K) - S.at(i);
    }
  }
  cout << max_ << endl;
}

int main() {
  cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x1 = sc.nextInt();
    int y1 = sc.nextInt();
    int x2 = sc.nextInt();
    int y2 = sc.nextInt();
    int x3 = x2+y1-y2;
    int y3 = y2+x2-x1;
    int x4 = x1+y1-y2;
    int y4 = y1+x2-x1;
    System.out.print(x3);
    System.out.print(" " + y3);
    System.out.print(" " +x4);
    System.out.println(" " +y4);
  }
}
    

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

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

int main(){
	string str;
	cin >> str;
	if(str[0] == str[1]) { cout << "1 2" << endl; return 0; }
	REP(c, 26){
		char target = char('a' + c);
		REP(i, str.size()-2){
			int cnt = 0;
			REP(j, 3) if(str[i+j] == target) cnt++;
			if(cnt > 1) { cout << i+1 << " " << i+3 << endl; return 0; }
		}
	}
	cout << "-1 -1" << endl;
}


Measured memory_bytes: 512
#include <iostream>
#define endl '\n'

using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N, Y; cin >> N >> Y; Y /= 1000;
    
    for(int i = 0; i <= N; i++)
    {
        for(int j = 0; j <= N; j++)
        {
            if(9 * i + 4 * j != Y - N) continue;
            int k = Y - (10 * i) - (5 * j);
            if(k < 0) continue;
            cout << i << " " << j << " " << k << endl;
            return 0;
        }
    }
    
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String w = sc.nextLine();
        sc.close();

        int count = 0;
        String ans = "Yes";

        for(int i = 0; i < w.length(); i++){
            for(int j = 0; j < w.length(); j++){
                if(w.charAt(i) == w.charAt(j)){
                    count++;
                }
            }
            if(count % 2 == 1) {
                ans = "No";
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25172
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <utility>
 
using namespace std;


int bi(int n, int k){
if(k==1 && n%2==0){return 0;}
if(k==1 && n%2==1){return 1;}
if(k>=2){return bi(n/2,k-1);}
}

int power(int n){
if(n==0){return 1;}
else{ return 2*power(n-1);}
}

int main() {

int H;
int W;
int K;

cin >>H>>W>>K;

long int val[200][10]={};//高さn、棒mへ行く経路の数

int sen[10];

int nom;//線の引き方が正しいか

val[0][1]=1;

for(int h=1; h<=H; h++){

for(int i=0; i<power(W-1); i++){//線を引く箇所の決定

for(int j=1; j<=W; j++){
sen[j]=bi(i,j);}

nom=0;

for(int j=1; j<=W-1; j++){//線の引き方が正しいか判定
if(sen[j]==1&&sen[j+1]==1){nom=1;}
}

for(int j=1; j<=W; j++){

if(nom==1){break;}

if(j<W&&sen[j]==1){
val[h][j]=val[h][j]+val[h-1][j+1];}

else if(j>1&&sen[j-1]==1){
val[h][j]=val[h][j]+val[h-1][j-1];}

else {val[h][j]=val[h][j]+val[h-1][j];}

if(val[h][j]>=1000000007){val[h][j]=val[h][j]%1000000007;}

}

}

}

cout <<val[H][K];

}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>
 
#define out(t) cout << (t) << "\n"
 
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int uint;
 
int popcount(uint x) {
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}
 
int tzcnt(uint x) {
    return popcount(~x & x - 1);
}
 
struct Point {
    int x, y;
 
    Point(int p, int q) : x(p), y(q) {}
};
 
ll ans[100];
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int N, D, X;
    cin >> N >> D >> X;
 
    int ans = X;
 
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
 
        ans += D / a + (D % a > 0 ? 1 : 0) ;
    }
 
    out(ans);
 
    int aaa;
    cin >> aaa;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+100;
const int mod = 998244353;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll llINF = 0x3f3f3f3f3f3f3f3f;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
inline bool read(ll &num) {
    char in;bool IsN=false;
    in=getchar();
    if(in==EOF) return false;
    while(in!='-'&&(in<'0'||in>'9')) in=getchar();
    if(in=='-'){ IsN=true;num=0;}
    else num=in-'0';
    while(in=getchar(),in>='0'&&in<='9'){
            num*=10,num+=in-'0';
    } 
    if(IsN) num=-num;
    return true;
}
long long a[N];
int main(){
    int n;
    scanf("%d",&n);
    set<ll> st;
    map<ll,ll> nums;
    rep(i,1,n){
        read(a[i]);
        nums[a[i]]++;
    }
    if(a[1]){
        puts("0");
        return 0;
    }
    ll ans=1;
    for(int i=2;i<=n;i++){
        ans*=(nums[a[i]-1]);
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N, T; cin >> N >> T;
  if(N==1){ cout << 1 << endl; return 0;}
  vector<ll> A(N); rep(i,N) cin >> A[i];
  vector<ll> minis(N);
  vector<ll> nows(N);
  ll mini;
  ll now;
  mini = now = A[0];
  rep(i,N){
    if(i==0) { minis[i] = A[0]; nows[i] = A[0]; continue;}
    mini = min(mini, A[i]);
    now = A[i];
    minis[i] = mini;
    nows[i] = now;
  }
  map<ll,int> mp;
  int ans = 0;
  rep(i,N){
    mp[nows[i]-minis[i]]++;
  }
  for(auto i:mp){
    ans = i.second;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
 
#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;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
// vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep (i, s.size()) {
        ans += s[i] != t[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3824
N = int(input())
ans = ['AC', 'WA', 'TLE', 'RE']
d = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}

for i in range(N):
    s = input()
    d[s] += 1

for a in ans:
    print(a, 'x', d[a])

Measured memory_bytes: 9196
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  int P[10]={0,0,0,0,0,0,1,1,1,2};
  int Q[10]={1,1,1,2,2,3,2,2,3,3};
  int R[10]={2,3,4,3,4,4,3,4,4,4};
  int N;
  cin>>N;
  ll m=0,a=0,r=0,c=0,h=0;
  for (int i=0; i<N; i++) {
    string s;
    cin>>s;
    if (s[0]=='M') {
      m++;
    }
    if (s[0]=='A') {
      a++;
    }
    if (s[0]=='R') {
      r++;
    }
    if (s[0]=='C') {
      c++;
    }
    if (s[0]=='H') {
      h++;
    }
  }
  ll D[5];
  D [0]=m,D[1]=a,D[2]=r,D[3]=c,D[4]=h;
  ll ans=0;
  for (int d=0; d<10; d++) {
    ans+=D[P[d]]*D[Q[d]]*D[R[d]];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
S = input()

count = [0] * len(S)

max_i = len(S)
#print(max_i)

i = 0
while i < max_i:
    p0 = S[i]

    j = 0
    if 'R' == p0:
        while True:
            j += 1
            if p0 != S[i + j]:
                break

        k = j
        k2 = int(k / 2)
        k1 = k - k2
#        print("i1: %d, j: %d, k2: %d, k1: %d" % (i, j, k2, k1))

        if (j % 2) == 0:
            count[i + j] += k1
            count[i + j - 1] += k2
        else:
            count[i + j] += k2
            count[i + j - 1] += k1
        i += j
    else:
        while i + 1 < max_i and S[i + 1] == 'L':
            i += 1

        while True:
            j += 1
            if p0 != S[i - j]:
                break

        k = j
        k2 = int(k / 2)
        k1 = k - k2

#        print("i2: %d, j: %d, k2: %d, k1: %d" % (i, j, k2, k1))

        if (j % 2) == 0:
            count[i - j] += k1
            count[i - j + 1] += k2
        else:
            count[i - j] += k2
            count[i - j + 1] += k1

        i += 1

print(' '.join([str(v) for v in count]))


Measured memory_bytes: 10492
#include <stdio.h>
int main(void)
{
          int fmat[9] ;
          int i , j;
          for( i = 0 ; i < 9 ; i ++ ) scanf("%d", &fmat[i]) ;
          int n ;
          scanf("%d" , &n) ;
          int numbers[n] ;
          for( i = 0 ; i < n ; i++) scanf("%d" , &numbers[i]) ;
          int flag[9] = {0,0,0,0,0,0,0,0,0} ;

          for(i = 0 ; i < 9; i++)
          {
                    if(flag[i] == 0)
                    {
                    for( j = 0 ; j < n ; j++)
                    {
                              if(fmat[i] == numbers[j]) flag[i] = 1 ;
                    }
                    }

          }
          if (flag[0] == 1 && flag[1] == 1 && flag[2] == 1 ||
                flag[3] == 1 && flag[4] == 1 && flag[5] == 1 ||
                flag[6] == 1 && flag[7] == 1 && flag[8] == 1 ||
               flag[0] == 1 && flag[3] == 1 && flag[6] == 1 ||
               flag[1  ] == 1 && flag[4] == 1 && flag[7] == 1 ||
               flag[2] == 1 && flag[5] == 1 && flag[8] == 1 ||
               flag[0] == 1 && flag[4] == 1 && flag[8] == 1 ||
               flag[2] == 1 && flag[4] == 1 && flag[6] == 1 )
          {
                    printf("Yes") ;
          }
          else printf("No") ;


}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int N = 2e5;

int n;
string s;
bool uA[N], uB[N];

void dfs(int x, bool* u)
{
    for (int i = x; i < n; ++i)
    {
        if (s[i] == '#' && i < n - 1 && s[i + 1] == '#')
            break;
        if (s[i] != '#')
            u[i] = true;
    }
}

int main()
{
    int a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    --a; --b; --c; --d;
    cin >> s;
    for (int i = 0; i < n; ++i)
        uA[i] = uB[i] = false;

    dfs(a, uA);
    dfs(b, uB);

    if (!uA[c] || !uB[d])
    {
        cout << "No";
        return 0;
    }
    if (c < d)
    {
        cout << "Yes";
        return 0;
    }
    for (int i = b; i <= d; ++i)
    {
        if (s[i] == '.' && s[i] == s[i - 1] && s[i] == s[i + 1])
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ta = 0, aa = 0;
  while (A > 0) {
    A -= D;
    aa++;
  }
  while (C > 0) {
    C -= B;
    ta++;
  }
  if (ta <= aa)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3624
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

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

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

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

int N, M;
int a[100001];

LL dp[100001];

int main() {
    cin >> N >> M;
    REP (i, N + 1) {
        dp[i] = 0;
    }
    dp[0] = 1;
    REP (i, M) {
        cin >> a[i];
        dp[a[i]] = -1;
    }
    REP (i, N + 1) {
        if (dp[i] == -1) {
            continue;
        }
        if (i > 0 && dp[i - 1] != -1) {
            dp[i] += dp[i - 1];
        }
        if (i > 1 && dp[i - 2] != -1) {
            dp[i] += dp[i - 2];
        }
        if (dp[i] > MOD) {
            dp[i] %= MOD;
        }
    }
    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        long n = in.longNext();
        int k = in.intNext();

        long total = k;
        int i = 1;
        while (total <= n) {
            total *= k;
            i++;
        }
        out.println(i);

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


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


int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  map<string, int> ans = {
    {"AC", 0},
    {"WA", 0},
    {"TLE", 0},
    {"RE", 0},
  };
  rep(i, n) cin >> S.at(i);

  rep(i, n) {
    // switch(S.at(i)) {
    //   case "AC":
    //     ans["AC"]++;
    //     break;
    //   case "WA":
    //     ans["WA"]++;
    //     break;
    //   case "TLE":
    //     ans["TLE"]++;
    //     break;
    //   case "RE":
    //     ans["RE"]++;
    //     break;
    // }
    if(S[i] == "AC") ans["AC"]++;
    if(S[i] == "WA") ans["WA"]++;
    if(S[i] == "TLE") ans["TLE"]++;
    if(S[i] == "RE") ans["RE"]++;
  }

  cout << "AC x " << ans["AC"] << endl;
  cout << "WA x " << ans["WA"] << endl;
  cout << "TLE x " << ans["TLE"] << endl;
  cout << "RE x " << ans["RE"] << endl;

  return 0;
}

Measured memory_bytes: 6364
package main

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

func cubic(x int) int {
	return x * x * x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(1)
	}
	fmt.Println(cubic(num))
}



Measured memory_bytes: 1076
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N := getInt()
	a := getInts(N)
	pre := a[0]
	ans := 0
	for i := 1; i < N; i++ {
		if a[i] < pre {
			ans += pre - a[i]
		} else {
			pre = a[i]
		}
	}
	out(ans)
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* 
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

// keyが降順ソートされるmap
// map<int, int, std::greater<int>> edges;

signed main() {
  int h,w;
  cin >> h >> w;
  int n;
  cin >> n;
  int a;
  queue<int> col;
  for(int i=0;i<n;i++){
    cin >> a;
    while(a>0){
      col.push(i+1);
      a--;
    }
  }

  vector<int> line(w);
  int i=0;
  int j=0;
  while(!col.empty()){
    line[i] = col.front();col.pop();
    i++;
    if(i==w){
      if(j%2==1){
        reverse(line.begin(),line.end());
      }
      for(auto c:line){
        cout << c << " ";
      }
      cout << endl;
      i=0;
      j++;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3732
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << 48 - n;
}


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

using namespace std;

class LuckySeven
{
private:
  struct TestCase
  {
    string N ="";
  };

  TestCase T = {};

public:
  void run()
  {
    Input();

    Output();
  }


private:
  void Input()
  {
    cin >> T.N;
  }

  void Output()
  {
    bool is_yes = false;
    for (auto it = T.N.begin(); it != T.N.end(); ++it)
    {
      auto c = *it;
      if (c == '7')
      {
        is_yes = true;
        break;
      }
    }

    cout << (is_yes ? "Yes" : "No") << "\n" << flush;
  }

};

int main()
{
  LuckySeven prob = {};
  prob.run();

  return 0;
}



Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<array>
#include<algorithm>
using namespace std;

int main() {
	int a = 10000;
	string s;
	cin >> s;

	for (int i = 0; i < s.size() - 2; i++) {
		int MIN = min(a,abs(753-stoi(s.substr(i,3))));
		a = abs(MIN);
	}
	cout << a << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

using namespace std;

typedef long long ll;

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

  long long x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vector<long long> p(a);
  vector<long long> q(b);
  vector<long long> r(c);

  for (int i = 0; i < a; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> q[i];
  }
  for (int i = 0; i < c; i++) {
    cin >> r[i];
  }
  sort(p.begin(), p.end(), greater<long long>());
  sort(q.begin(), q.end(), greater<long long>());
  sort(r.begin(), r.end(), greater<long long>());

  priority_queue<long long> que;
  for (int i = 0; i < x; i++) {
    que.push(p[i]);
  }
  for (int i = 0; i < y; i++) {
    que.push(q[i]);
  }
  for (int i = 0; i < c; i++) {
    que.push(r[i]);
  }
  long long ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
	int n;
	string s, t;
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++)
	{
		bool ok = true;
		for (int j = 0; j + i < n; j++)
			if (s[i + j] != t[j])
				ok = false;
		if (ok)
		{
			cout << i + n << endl;
			return 0;
		}
	}
	cout << n * 2 << endl;
	return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*N
B[0]=1
if B[0] in A:c=B[0]
for i in range(1,N):
  B[i]=A[B[i-1]-1]

d=B.index(B[-1])+1
if K<=N:print(B[K]);exit()
print(B[d-1+(K+1-d)%(N-d)])


Measured memory_bytes: 32296
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0);
const int M = 1e9+7;
using namespace std;
const int N = 200000;
int arr[N+5];
int longest_log = 0;
int n, k;

bool do_cut(int len){
    int cuts = 0;
    for(int i=0; i<n; i++){
        cuts+=(arr[i]-1)/len;
    }
    return cuts<=k;
}

int main(){
    AC
    cin>>n>>k;
    for(int i=0; i<n; i++){
        cin>>arr[i];
        longest_log = max(longest_log, arr[i]);
    }

    int l=1, r=longest_log;
    while(l<r){
        int m = l+(r-l)/2;
        if(do_cut(m))
            r=m;
        else
            l=m+1;
    }
    cout<<l<<endl;

}

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

int my_abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
    int N,T,A;
    cin >> N >> T >> A;
    vector<double> tem(N);
    vector<int> high(N);

    for(int i = 0;i<N;i++){
        cin >> high.at(i);
        tem.at(i) = T - high.at(i)*0.006;
    }
    int smallsa = 9999999;
    int ans = 1;
    for(int j = 0;j<N;j++){
        int sa = A*1000 - tem.at(j)*1000;
        sa = my_abs(sa);
      	//cout << sa << endl;
        if(smallsa >= sa){
            smallsa = sa;
            ans = j+1;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int n, i, T, ca = 9999, cb, time;
	cin >> n >> T;
	for (i = 0;i < n;i++) {
		cin >> cb >> time;
		if (time <= T && ca > cb) {
			ca = cb;
		}
	}
	if (ca == 9999) {
		cout << "TLE" << endl;
	}
	else {
		cout << ca << endl;
	}
}

Measured memory_bytes: 256
n=gets.to_i
n.times{
	runner=Array.new(4,0)
	outcount=0
	while outcount < 3
		event=gets.chomp
			case event
			when "HIT"
				runner[3] += runner[2]
				runner[2] = runner[1]
				runner[1] = runner[0]
				runner[0] = 1
			when "HOMERUN"
				runner[3]+=runner[2]+runner[1]+runner[0]+1
				runner[2] = 0
				runner[1] = 0
				runner[0] = 0
			when "OUT"
				outcount+=1
			end
	end
	puts runner[3]
}

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

int main() {
	int r;
	cin >> r;
	string ans;
	if (r < 1200) {
		ans = "ABC";
	} else if (r < 2800) {
		ans = "ARC";
	} else {
		ans = "AGC";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// 5/13 過去問ガリガリ
#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>;
using Graph = vector<vector<int>>;

const int MAX_N = 1010;
const int MAX_H = 10010;
const int INF = 1000000009;

int dp[MAX_N][MAX_H];

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

    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    // dp初期条件。i = 0の時は全てINF。
    rep(j, H + 1) dp[0][j] = INF;

    // dp
    rep(i, N) {
        rep(j, H + 1) {
            if (j <= A[i]) {
                dp[i + 1][j] = min(dp[i][j], B[i]);
            } else {
                dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - A[i]] + B[i]);
            }
        }
    }

    cout << dp[N][H] << endl;
}


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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  ll n, x; cin >> n >> x;
  vector<ll> ans(2*n-1);
  if (x == 1 || x == 2*n-1) {
    cout << "No" << endl;
    return 0;
  }
  if (n == 2) {
    cout << "Yes" << endl;
    cout << 1 << endl << 2 << endl << 3 << endl;
    return 0;
  }
  if (x == 2) {
    ans[n-2] = 3, ans[n-1] = 2, ans[n] = 1, ans[n+1] = 4;
    FOR(i,5,2*n) {
      if (i-1 <= n+1) ans[i-5] = i;
      else ans[i-1] = i;
    }
  } else {
    ans[n-2] = x-1, ans[n-1] = x, ans[n] = x+1, ans[n+1] = x-2;
    FOR(i,1,2*n) {
      if (x-2 <= i && i <= x+1) continue;
      if (i < x-2 && i-1 < n-2) ans[i-1] = i;
      else if (i < x-2) ans[i+3] = i;
      else if (i-1 <= n+1) ans[i-5] = i;
      else ans[i-1] = i;
    }
  }
  cout << "Yes" << endl;
  REP(i,ans.size()) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

const int INF = 0x3f3f3f3f;
const int MAXN = 2e5+10;
map<string, int>ans;

int main()
{
	int n; cin>>n;
	for(int i = 0; i < n; ++i) {
		string tmp; cin>>tmp;
		ans[tmp]++;
	}
	int max_key = 0;
	map<string, int>::iterator it = ans.begin();
	for(;it != ans.end(); ++it) {
		if(max_key < it->second) {
			max_key = it->second;
		}
	}
	for(it = ans.begin();it != ans.end(); ++it) {
		if(max_key == it->second) {
			cout<<it->first<<endl;
		}
	}
	return 0; 
}

Measured memory_bytes: 26624
#include <iostream>
using namespace std;
int lol[300] = {};
long long dp[300][300] = {};

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

    int n, k;
    cin >> n >> k;
    if (n == k) cout << 0 << '\n';
    else{
        for (int i = 0; i < n; i++) cin >> lol[i];
        for (int r = 0; r < n; r++) dp[0][r] = lol[r];
        for (int s = 1; s < n-k; s++){
            for (int r = s; r < n; r++){
                long long m = 1ll<<56;
                for (int t = s-1; t < r; t++) m = min(m, dp[s-1][t] + max(0, lol[r] - lol[t]));
                dp[s][r] = m;
            }
        }
        long long ans = 1ll<<56;
        for (int r = n-k-1; r < n; r++) ans = min(ans, dp[n-k-1][r]);
        cout << ans << '\n';
    }
}


Measured memory_bytes: 1024
while True:
 h,w=map(int,input().split())
 if h==0:break
 for i in range(h):
  if i%2==0:print("".join(['#' if i%2==0 else '.' for i in range(w)]))
  else:print("".join(['.' if i%2==0 else '#' for i in range(w)]))
 print()

Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define inf 1e18
#define err(x) cout<<x<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);



using namespace std;
set <ll> ve[2000];
int main()
{


    FASTIO
    ll n,k;
    cin >> n>>k;
    vector <pair<ll,ll> > ed;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            ve[i].insert(j);

        }
    }
    ll maxx = n*(n-1)/2 - (n-1);

    ll minn = 0;
    if(k>maxx)
    cout<<-1;
    else
    {
        ll idx  = 0;
        for(ll i=0;i<k;i++)
        {
            if(ve[idx].size() > 1)
            {
                ll w = *ve[idx].begin();
                ve[idx].erase(w);


            }
            else
            idx ++,i--;


        }
        vector <pair<ll,ll> > ans;
        for(ll i=0;i<n;i++)
        {
            for(auto it:ve[i])
            ans.pb({i,it});
        }

        cout<<ans.size()<<endl;
        for(auto id:ans)
        cout<<id.F+1ll<<" "<<id.S+1ll<<endl;

    }





cout << endl ;
return 0;
}


Measured memory_bytes: 768
import sys
readline = sys.stdin.readline

MOD = 10**9+7
def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci
frac, fraci = frac(1341398)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD


N, M = map(int, readline().split())

ans = 0

for i in range(N+1):
    sign = -1 if i&1 else 1
    ans = (ans + sign*comb(M, i)*comb(N, i)*frac[i]*comb(M-i, N-i)**2*frac[N-i]**2)%MOD

print(ans)

Measured memory_bytes: 127704
A, B = map(int, input().split())
if A!=1 and B!=1:
  if A > B:
    print("Alice")
  elif B > A:
    print("Bob")
  else:
    print("Draw")

else:
  if A==1 and B==1:
    print("Draw")
  elif A==1:
    print("Alice")
  else:
    print("Bob")

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int a, b; cin >> a >> b;
    if(a - b * 2 > 0)cout << a - b * 2 << endl;
    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 3644
/*
	不互质的数两两连边
	先手的操作就是对边重定向
	后受到操作是找到最大的 topo 序
*/
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <queue>
#define N 2005

using namespace std;

int n;
int a[N], deg[N];
bool gra[N][N], vis[N];

inline int gcd(int u, int v) { return v ? gcd(v, u % v) : u; }

void dfs(int u) {
	vis[u] = true;
	for(int v = 1; v <= n; ++v) {
		if(vis[v] || !gra[u][v]) continue;
		gra[v][u] = false, ++deg[v];
	}
	for(int v = 1; v <= n; ++v) {
		if(vis[v] || !gra[u][v]) continue;
		dfs(v);
	}
	return;
}
void topo() {
	priority_queue<int> hp;
	for(int i = 1; i <= n; ++i)
		if(!deg[i]) hp.push(i);
	while(!hp.empty()) {
		int u = hp.top(); hp.pop();
		printf("%d ", a[u]);
		for(int v = 1; v <= n; ++v)
			if(gra[u][v] && !--deg[v])
				hp.push(v);
	}
	putchar('\n');
	return;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n);
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			gra[i][j] = gra[j][i] = (gcd(a[i], a[j]) != 1);
	for(int i = 1; i <= n; ++i)
		if(!vis[i])	dfs(i);
	topo();
	return 0;
}

Measured memory_bytes: 4224
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ruisekiwa = [0] * (N + 1)
for i in range(0, N):
    ruisekiwa[i + 1] = ruisekiwa[i] + A[i]
# print(ruisekiwa)
ans = 0
for i in range(N):
    ans += A[i] * (ruisekiwa[N] - ruisekiwa[i + 1]) % MOD
print(ans % MOD)


Measured memory_bytes: 31552
n = int(input())
a = list(map(int, input().split()))
slime = 101
count = 1
ans = 0

for i, s in enumerate(a):
    if s == slime:
        #print("same_slime")
        count += 1
    else:
        ans += count // 2
        count = 1
    slime = s
    if i == n - 1:
        ans += count // 2

print(ans)


Measured memory_bytes: 3060
fun main(args: Array<String>) {
    fun pow(a: Long, b: Long, mod: Int): Long {
        var bt = b
        var ret: Long = 1
        var tmp = a
        while (bt > 0) {
            if (bt and 1 == 1L) ret = ret * tmp % mod
            tmp = tmp * tmp % mod
            bt = bt shr 1
        }
        return ret
    }

    fun nCk(n: Int, k: Int, M: Int): Int {
        var ret: Long = 1
        val min = Math.min(k, n - k)
        for (i in 1..min) {
            ret = ret * pow(i.toLong(), (M - 2).toLong(), M) % M
        }
        for (i in n - min + 1..n) {
            ret = ret * i % M
        }
        return ret.toInt()
    }


    val mod = 1000000007L
    val (x, y) = readLine()!!.split(' ').map(String::toLong)

    val totalMove = (x + y) / 3
    val countU = y - totalMove
    val countR = x - totalMove
    if ((x + y) % 3 != 0L || countU < 0 || countR < 0) {
        println(0)
        return
    }
    println(nCk(totalMove.toInt(), countR.toInt(), mod.toInt()) % mod)
}

Measured memory_bytes: 38324
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i = 0;i < n;i++)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()

template<class T> bool chmax(T& a,T b){ if(a < b){ a = b; return true; }else return false; }
template<class T> bool chmin(T& a,T b){ if(a > b){ a = b; return true; }else return false; }
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
using vpi = vector<Pi>;
using vpl = vector<Pl>;
 
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout << "[" << #a << "," << #b << "] = " << "[" << a << "," << b << "]" << '\n'
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
	cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
	return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
	cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
	return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
  cout << "{" << p.first << "," << p.second << "}" << '\n';
  return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
	for (auto& i : arr)cin >> i; return in;
}

/////////////////////////////////////////////////////////////////////////
int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(20);
  string s;cin >> s;
  if(s.back() == 's') s += "es";
  else s += 's';
  cout << s << '\n';
  return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int n;
long long dist[2][100000];
long long ans[100001];
vector <pair<int, long long>> v[2][100000];

void calc(int s, int p) {
    int i;
    priority_queue <pair<long long, int>> q;
    
    for (i = 0; i < n; i++) dist[p][i] = 1e18;
    
    dist[p][s] = 0;
    q.push(make_pair(0, s));
    
    while (!q.empty()) {
        int x = q.top().second;
        long long d = -q.top().first;
        
        q.pop();
        
        if (dist[p][x] != d) continue;
        
        for (i = 0; i < v[p][x].size(); i++) {
            int y = v[p][x][i].first;
            long long nd = d + v[p][x][i].second;
            
            if (dist[p][y] > nd) {
                dist[p][y] = nd;
                q.push(make_pair(-nd, y));
            }
        }
    }
}

int main() {
    int m, s, t, i;
    
    scanf("%d %d %d %d", &n, &m, &s, &t);
    
    s--;
    t--;
    
    for (i = 0; i < m; i++) {
        int x, y, a, b;
        
        scanf("%d %d %d %d", &x, &y, &a, &b);
        
        x--;
        y--;
        
        v[0][x].push_back(make_pair(y, a));
        v[0][y].push_back(make_pair(x, a));
        v[1][x].push_back(make_pair(y, b));
        v[1][y].push_back(make_pair(x, b));
    }
    
    calc(s, 0);
    calc(t, 1);
    
    for (i = 0; i < n; i++) ans[i] = dist[0][i] + dist[1][i];
    for (i = n - 2; i >= 0; i--) ans[i] = min(ans[i], ans[i + 1]);
    
    for (i = 0; i < n; i++) printf("%lld\n", (long long)1e15 - ans[i]);
    
    return 0;
}


Measured memory_bytes: 19140
S = input()

ans = sum(map(int, list(S)))
for i in range(len(S)):
    if S[i] == "0":
        continue
    first_half = sum(map(int, list(S[0:i])))
    middle = (int(S[i]) - 1)
    last_half = 9 * (len(S) - i - 1)
    ans = max(ans, first_half + middle + last_half)
    
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
inline long long read()
{
	long long x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return x;
}
main()
{
	long long n = read(), ans = n;
	for (int i = 1; i < n; ++i)
	{
        long long u = read(), v = read();
		if (u > v) swap(u, v);
        ans += i * (n - i + 1);
        ans -= u * (n - v + 1);
	}
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 3760
arr = [0 for i in range(10001)]
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            if i*i + j*j + k*k +i*j + j*k + k*i <=10**4:
                arr[i*i + j*j + k*k +i*j + j*k + k*i]+=1

n = int(input())
for i in range(1,n+1):
    print(arr[i],end= " ")

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

using namespace std;

typedef struct {
    char suit, no;
} Card;

void bubble(Card A[],int N){
    for(int i = 0;i < N;i++){
        for(int j = N-1; i < j;j--){
            if(A[j].no < A[j-1].no){
                swap(A[j], A[j-1]);
            }
        }
    }
}

void selection_sort(Card A[],int N){
    for(int i = 0;i<N;i++){
        int minj = i;
        for(int j = i;j < N;j++){
            if(A[minj].no > A[j].no){
                minj = j;
            }
        }
        swap(A[i],A[minj]);
    }
}

void trace(Card c[],int N){
    for(int i = 0;i < N;i++){
        if(i)cout << " ";
        cout << c[i].suit << c[i].no;
    }
    cout << endl;
}

int main(){
    int N;
    bool flag = true;
    Card C1[100], C2[100];

    cin >> N;
    for(int i = 0;i<N;i++){
        cin >> C1[i].suit >> C1[i].no;
        C2[i] = C1[i];
    }

    bubble(C1, N);
    selection_sort(C2,N);

    trace(C1, N);
    cout << "Stable" << endl;

    trace(C2,N);
    for(int i = 0;i< N;i++){
        if(C1[i].suit != C2[i].suit){
            cout << "Not stable" << endl;
            flag =false;
            break;
        }
    }
    if(flag)cout << "Stable" << endl;
    
    return 0;
}


Measured memory_bytes: 3104