akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define SKILLER ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N=1e4, MOD = 1e9 + 7;
string s, t;
int n, m, totW;
//int w[105], v[105];
int cache[N][N];
char a[N][N];
int dp(int i, int j)
{
  if(i == n && j == m)return 1;
  if( i == n && a[i][j + 1] != '.') return 0;
  if( j == m && a[i + 1][j] != '.') return 0;
  if(a[i][j] != '.') return 0;
  if(cache[i][j] != -1)return cache[i][j];
  cache[i][j] = 0;
  cache[i][j] = dp(i + 1,j)%MOD + dp(i, j + 1)%MOD;
  return cache[i][j]%MOD;
}

int32_t main()
{
    SKILLER

    memset(cache, -1, sizeof(cache));
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    int ans = dp(1,1);
   // cout<<ans<<"\n";
    cout<< ans;
    return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int w,h,n;
    cin>>w>>h>>n;

    int rect[h][w]={};

    rep(i,n){
        int x,y,a;
        cin>>x>>y>>a;

        if(a==1){
            rep(i,h)for(int j=0;j<x;++j){
                rect[i][j]=1;
            }
        }
        else if (a==2)
        {
            rep(i,h)for(int j=x;j<w;++j){
                rect[i][j]=1;
            }
        }
        else if (a==3)
        {
            rep(j,w)for(int i=0;i<y;++i){
                rect[i][j]=1;
            }
        }
        else
        {
            rep(j,w)for(int i=y;i<h;++i){
                rect[i][j]=1;
            }
        }
    }


    for(int i=h-1;i>=0;--i){
        rep(j,w){
            if(rect[i][j]==0)ans++;
            //cout<<rect[i][j]<<" ";
        }
        //ln;
    }


    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a[] = new int[9];

        for (int i = 0; i < a.length; i++) {
            a[i] = scan.nextInt();
        }

        int n = scan.nextInt();

        for (int i = 0; i < n; i++) {
            int b = scan.nextInt();
            for (int j = 0; j < a.length; j++) {
                if (b == a[j]) {
                    a[j] = 0;
                }
            }
        }

        for (int i = 0; i < 3; i++) {
            if (a[i] == 0 && a[i + 3] == 0 && a[i + 6] == 0) {
                System.out.println("Yes");
                return;
            }
        }

        for (int i = 0; i < 3; i++) {
            if (a[3 * i] == 0 && a[3 * i + 1] == 0 && a[3 * i + 2] == 0) {
                System.out.println("Yes");
                return;
            }
        }

        if (a[0] == 0 && a[4] == 0 && a[8] == 0) {
            System.out.println("Yes");
            return;
        }

        if (a[2] == 0 && a[4] == 0 && a[6] == 0) {
            System.out.println("Yes");
            return;
        }

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


Measured memory_bytes: 23380
n,k = map(int,input().split())
p = list(map(int,input().split()))

ls_mu = []
for i in range(n):
    mu = (p[i]+1)/2
    ls_mu.append(mu)
# print(ls_mu)
m = 0
M = 0
for i in range(n-k+1):
    if i==0:
        for j in range(k):
            m += ls_mu[j]
        M += m
    else:
        l = ls_mu[i-1]
        r = ls_mu[i+k-1]
        m = m - l + r
        M = max(m,M)

print(M)

Measured memory_bytes: 25060
#include <iostream>
#include <functional>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
const ll INF = 1e18;

ll dp[200005][4];

// cp temp.cpp abc160_e.cpp

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


Measured memory_bytes: 3132
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main(){
	int A,B,K;
	cin>>A>>B>>K;
	
	int ans;
	int j=0;
	for(int i=min(A,B);i>0;i--){
		if(A%i==0&&B%i==0){
			j++;
			if(j==K){
				ans=i;
			}
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    set<string> s;
    string T = "";
    bool ok = true;
    for(int i=0;i<N;i++){
        string S;
        cin >> S;
        ok &= !s.count(S);
        if(!s.empty()){
            ok &= T.back()==S[0];
        }
        T = S;
        s.insert(S);
    }
    cout << (ok? "Yes\n":"No\n");
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int x=0;
  int ans=0;
  for (int i=0; i<N; i++) {
    if (S[i]=='I') {
      x++;
    } else {
      x--;
    }
    ans=max(x,ans);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	int n;
	std::cin >> n;

	std::vector<int> d(n);
	for(int i = 0; i < n; ++i){
		std::cin >> d.at(i);
	}

	std::vector<int> bucket(100, 0); //max number of kind is n
	for(int i = 0; i < n; ++i){
		++bucket.at(d.at(i) - 1);
	}
	//std::cout << "point1" << std::endl;

	int sum = 0;
	for(int i : bucket){
		if(i > 0){
			++sum;
		}
	}

	std::cout << sum << std::endl;

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ll h; cin>>h;
	map<ll, ll> mp;
	ll ans = 0;
	mp[h] = 1;
	while(!mp.empty()){
		map<ll, ll> nmp;
		for(auto x : mp){
			ans += x.second;
			if(x.first == 1)continue;
			nmp[x.first/2] += x.second*2;
		}
		mp = nmp;
	}
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}


int main() {
    LL X, A;
    cin >> X >> A;

    if (X < A) {
        cout << "0" << endl;
    } else {
        cout << "10" << endl;
    }
	
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

const int MAX = 4000003;

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

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

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

int main(){ 
  COMinit();
  ll N,M,K,ANS=0;
  cin >> N >> M >> K;
  ll com = COM(N*M-2,K-2);
  Rep(i,1,N){
    ll Z=1;
    Z*=M*M*(N-i);
    Z%=MOD;
    Z=(Z*com)%MOD;
    Z=(Z*i)%MOD;
    ANS=(ANS+Z)%MOD;
  }
  Rep(i,1,M){
    ll Z=1;
    Z*=N*N*(M-i);
    Z%=MOD;
    Z=(Z*com)%MOD;
    Z=(Z*i)%MOD;
    ANS=(ANS+Z)%MOD;
  }
  cout << ANS << endl;
}

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

int main() {
    long long int n;
    cin >> n;
    string ans = "";
    while (n)
    {
        ans += (char)('a' + (--n % 26));
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

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

#define reg register
typedef long long ll;
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)

char IO;
int rd(){
	int s=0,f=0;
	while(!isdigit(IO=getchar())) if(IO=='-') f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(isdigit(IO=getchar()));
	return f?-s:s;
}

const int N=1e5+10;
const int z[5][4]={{0,1},{0,-1},{1,0},{-1,0}};

int n,m;
char s[N],p[N];
int c[N];
int nxt[N][26];

int main(){
	scanf("%s%s",s+1,p+1);
	n=strlen(s+1),m=strlen(p+1);
	rep(i,1,n) c[s[i]-'a']++;
	rep(i,1,m) if(!c[p[i]-'a']) return puts("-1"),0;
	memset(nxt,10,sizeof nxt);
	drep(i,n,1) {
		int x=s[i]-'a';
		rep(j,0,25) {
			if(x==j) nxt[i][j]=i;
			else nxt[i][j]=nxt[i+1][j];
		}
	}
	ll now=0;
	rep(i,1,m) {
		ll x=p[i]-'a';
		ll t;
		if(now%n==0) t=n+1;
		else t=now%n+1;
		if(nxt[t][x]<=n) {
			now=now/n*n+nxt[t][x];
		} else {
			now=(now+n-1)/n*n+nxt[1][x];
		}
		//cout<<now<<endl;
	}
	printf("%lld\n",now);
}








Measured memory_bytes: 10624
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int manx=233;
int n;
int ans[27];
string s[manx]; 
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
	{
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
	{
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int main()
{
//	freopen("input.in","r",stdin);
//	freopen("output.out","w",stdout);
	n=read();
	memset(ans,10,sizeof(ans));
	for(int i=1;i<=n;i++) cin>>s[i];
	for(int i=1;i<=n;i++)
	{
		int temp[manx];
		memset(temp,0,sizeof(temp));
		for(int j=0;j<s[i].size();j++) temp[int(s[i][j])-96]++;
		for(int j=1;j<=26;j++) ans[j]=min(ans[j],temp[j]);
	}
	for(int i=1;i<=26;i++)
	{
		if(ans[i]>1e6) continue;
		for(int j=1;j<=ans[i];j++) printf("%c",'a'+i-1);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[101][101]={};
  int n,u,k,v;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      a[u][v]=1;
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<n;j++)
      cout<<a[i][j]<<' ';
    cout<<a[i][n]<<endl;
  }
  return 0;
}

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

int main() {
  int N;
  scanf("%d", &N);

  int h[110] = {0};
  for (int i = 0; i < N; i++) {
    scanf("%d", &h[i]);
  }

  int ans = 0;
  while (1) {
    int begin = -1;
    int end = 0;
    int height = 101;

    for (int i = 0; i < N; i++) {
      if (h[i] > 0) {
        begin = i;
        height = min(height, h[i]);
        break;
      }
    }

    if (begin == -1) break;
    
    for (int j = begin; j < N; j++) {
      if (h[j] == 0) {
        end = j;
        break;
      }
      height = min(height, h[j]);
      end = j + 1;
    }

    for (int i = begin; i < end; i++) {
      h[i] -= height;
    }
    
    ans += height;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[110][20];
struct ss{
	char first;
	char last;
}a[110];

int main(){
	int n,i,j;
	scanf("%d\n",&n);
	for(i=1;i<=n;i++){
		scanf("%s",s[i]);
		a[i].first=s[i][0];
		a[i].last=s[i][strlen(s[i])-1];
	}
	for(i=1;i<=n-1;i++)
	  for(j=i+1;j<=n;j++)
	    if(strcmp(s[i],s[j])==0){
	    		cout<<"No";return 0;
	    }
	for(i=2;i<=n;i++)
	  if(a[i].first!=a[i-1].last){
	  	cout<<"No";return 0;
	  }
	cout<<"Yes";
	return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  set<int> s;
  string ans = "YES";
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (s.count(a)) {
      ans = "NO";
    }
    s.insert(a);
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 9600
#include<stdio.h>
int main(){

  int a[10000],b[10000],i,j,x,y,count=0;

  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&a[i]);
    }

  scanf("%d",&y);
  for(i=0;i<y;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<y;i++){
    for(j=0;j<x;j++){
      if(a[j]==b[i]){
	count++;
	break;
      }
    }
  }

  printf("%d\n",count);
	
      
      
      


    return 0;
    }
    
      



Measured memory_bytes: 2088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

            //int[] T = new int[N];
            ulong[] T = new ulong[N];

            for (int i = 0; i < N; i++) T[i] = ulong.Parse(Console.ReadLine());

            ulong out01 = 1;

            for (int i = 0; i < N; i++)
            {
                out01 = Lcm(out01, T[i]);
            }
            Console.WriteLine(out01);
        }

        // 最小公倍数
        public static ulong Lcm(ulong a, ulong b)
        {
            return a / Gcd(a, b) * b;
        }
        // ユークリッドの互除法 
        public static ulong Gcd(ulong a, ulong b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}

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

bool check(const vector<ll>& a, const vector<ll>& b){
    if(a.size() != b.size()){ return false; }
    REP(i, a.size()){
        if(a.at(i) != b.at(i)){
            return false;
        }
    }
    return true;
}

void solve(long long N, std::vector<long long> P, std::vector<long long> Q){
    vector<ll> v(N);
    REP(i, N){ v.at(i) = i + 1; }
    ll ppos = -1, qpos = -1;
    ll i = 0;
    do{
        if(check(v, P)){ ppos = i; }
        if(check(v, Q)){ qpos = i; }
        i++;
    }while(next_permutation(v.begin(), v.end()));
    cout << abs(qpos - ppos) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    std::vector<long long> Q(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&Q[i]);
    }
    solve(N, std::move(P), std::move(Q));
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadLineInt();
            var str = ReadLineStringSplit();

            var s = "";


            
            for (int i = 0; i < n; i++) {
                s += str[0][i].ToString() + str[1][i].ToString();
            }

            Console.WriteLine($"{s}");
            ReadLine();
        }

        //メモ

        //配列
            //降順
            //var sort = array.OrderBy(x => -x).ToArray();

            //合計値
            //array.Sum();

        //kのn乗
        //(int) Math.Pow(k, n);


        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static long ReadLineLongInt() => long.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e11;
const long double PI = (acos(-1));


signed main() {
	int H, W;
	cin >> H >> W;
	vector<vector<int>>a(H, vector<int>(W));
	rep(i, H)rep(j, W) {
		int A;
		cin >> A;
		a[i][j] = A % 2;
	}
	vector<P>ans;
	int f = 0;
	rep(i, H) {
		rep(j, W) {
			if (a[i][j] && j + 1 < W) {
				a[i][j]--;
				a[i][j + 1]++;
				a[i][j + 1] %= 2;
				ans.push_back({ i + 1,j + 1 });
				f++;
			}
		}
	}
	int s = 0;
	rep(i, H) {
		if (a[i][W - 1] && i + 1 < H) {
			a[i][W - 1]--;
			a[i + 1][W - 1]++;
			a[i + 1][W - 1] %= 2;
			ans.push_back({ i + 1,W });
			s++;
		}
	}
	cout << f + s << endl;
	rep(i, f)cout << ans[i].first << " " << ans[i].second << " " << ans[i].first << " " << ans[i].second + 1 << endl;
	rep(i, s)cout << ans[f + i].first << " " << ans[f + i].second << " " << ans[f + i].first + 1 << " " << ans[f + i].second << endl;
}

Measured memory_bytes: 6128
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt
    val array = StdIn.readLine.split(" ").map(_.toInt)
    val arr = array.sortWith(_ > _)
    var bob = 0
    var alice = 0
    for(a <- 0 to arr.length -1) if(a % 2 == 0) alice += arr(a) else bob += arr(a)
    println(alice - bob)
    
  }
  
}

Measured memory_bytes: 25528
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define faster ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define ld long double
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define REP(i,a,b) for(ll i = a; i < b; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define bins(v, x) binary_search(v.begin(), v.end(), x)
#define pi 2*acos(0.0)
const int INF = 1e9+1;
const int mod = 1e9+7;
const int mod1 = 998244353;
 
ll modExp(ll base, ll exp, ll mod) {
   ll res = 1;
   while (exp > 0) {
    	if (exp % 2 == 1) {
        	res= (res * base) % mod;
		}
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}

ll inverse(ll base, ll exp, ll mod) {
   return modExp(base, exp - 2, mod);
}
 
ll nCr(ll n, ll k) { 
   ll C[n + 1][k + 1]; 
   
   REP(i,0,n+1){ 
      REP(j,0,min(i,k)+1) {
         if(j==0 || j==i) {
            C[i][j] = 1;  
         } else {
            C[i][j] = C[i-1][j-1] + C[i-1][j]; 
         }
      } 
   }
   return C[n][k]; 
}

bool compare(pair<int, int>&i, pair<int, int>&j) {
    return (i.S > j.S || (i.S == j.S && i.F > j.F));
}

void readtxt() {
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
}

void test() {
   int x, y;
   cin >> x >> y;
   for(int i = 0; i <= x; i++) {
      if(i*2 + (x-i)*4 == y) {
       	cout << "Yes" << endl;
  		   return;
      }
   }
  
   cout << "No" << endl;
}

int main() {
   //readtxt();
   faster;

   int t = 1;
   //cin >> t;
   while(t--)
      test();
}


Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n);
ll lcm(ll m, ll n);

int main(void) {

	int a, b;
	cin >> a >> b;

	for (int i = b - a + 1; i <= b + a - 1; i++) {
		if (i == b + a - 1) {
			cout << i << endl;
			break;
		}
		cout << i << " ";
	}

	return 0;

}

// 2番目から3要素だけ抜き出した部分文字列を取得する
//std::string result = s.substr(2, 3);  
#if 1
//最大公倍数
ll gcd(ll m, ll n)
{
	ll temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
#endif

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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    string s,t;
    cin >> s >> t;
    ll sn,tn;
    sn = s.length();
    tn = t.length();

    ll max = 0;
    rep(i,sn-tn+1){
        ll cnt = 0;
        rep(j,tn){
            if(s[i+j]==t[j]) cnt++;
        }
        chmax(max, cnt);
    }

    cout << tn - max << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

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

    if (a.length() > b.length()) cout << "GREATER" << endl;
    else if (a.length() < b.length()) cout << "LESS" << endl;
    else if (a == b) cout << "EQUAL" << endl;
    else {

        rep(i, a.length()) {
            if (a[i] > b[i]) {
                cout << "GREATER" << endl;
                break;
            } else if (a[i] < b[i]) {
                cout << "LESS" << endl;
                break;
            }
        }
    }

    return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 21;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 62;

ll n,q;
string s;
ll c[e5];
ll l[e5],r[e5];

int main(){
  cin >> n >> q;
  cin >> s;
  for(ll i = 1;i < n;i++){
    if(s[i-1] == 'A' && s[i] == 'C') c[i]++;
  }
  for(ll i = 1;i < n;i++){
    c[i] += c[i-1];
  }
  for(ll i = 0;i < q;i++){
    cin >> l[i] >> r[i];
  }
  for(ll i = 0;i < q;i++){
    cout << c[r[i]-1]-c[l[i]-1] << endl;
  }


}


Measured memory_bytes: 5888
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
    // insert code here...
    char p[202], s[101], cpy[101];
    scanf("%s %s", p, s);
    strcpy(cpy, p);
    strcat(p, cpy);
    if (strstr(p, s)==NULL) {
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}



Measured memory_bytes: 2136
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
int main(int argc, char const *argv[]) {
    int a,b;
    cin>>a>>b;
    cout<<a+b/2<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    from collections import deque
    from functools import reduce
    import sys
    input = sys.stdin.readline

    MOD = 10 ** 9 + 7

    def mod_mul(a, b):
        return a * b % MOD

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

    Graph = tuple(set() for _ in range(N))
    for _ in range(N - 1):
        a, b = (int(x) - 1 for x in input().split())
        Graph[a].add(b)
        Graph[b].add(a)

    dq = deque()
    color = [-1] * N
    color[0] = K
    used = 0
    for u in Graph[0]:
        color[u] = K - 1 - used
        used += 1
        dq.append(u)

    while dq:
        v = dq.popleft()
        used = 0
        for u in Graph[v]:
            if ~color[u]:
                continue
            color[u] = K - 2 - used
            used += 1
            dq.append(u)

    ans = reduce(mod_mul, color)

    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong H, W, K;
  vector<string> area;

  cin >> H >> W >> K;
  area.resize(H);
  for (auto &in: area) {
    cin >> in;
  }

  int ans = 0;
  for (int h = 0; h < (1<<H); ++h) {
    for (int w = 0; w < (1<<W); ++w) {
      int cnt = 0;
      for (int hh = 0; hh < H; ++hh) {
        for (int ww = 0; ww < W; ++ww) {
          if (((h >> hh) & 1) == 0 && ((w >> ww) & 1) == 0 && area[hh][ww] == '#') {
            cnt++;
          }
        }
      }
      ans += cnt == K;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
#define sort(a) sort(a.begin(),a.end());
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
#define TC cin>>t;while(t--)
const int MOD = 1e9+7;
const ld PI = 3.1415926535898;
const ll LLMAX = LLONG_MAX;

int main()
{
	int r;
	cin>>r;
	ld a=PI*2*r;
	cout<<a;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)998244353;
const ll INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

template<long long mod>
class modint{
	public:
		long long x;
		modint(long long a){x=a%mod;if(x<0)x+=mod;}
		modint(){x=0;}

		modint pow(long long a){
			modint res(1), b(x);
			while(a){
				if(a&1)res*=b;
				b*=b;
				a>>=1;
			}
			return res;
		}

		modint inv(){return pow(mod-2);}

		modint& operator+=(modint a){x=(x+a.x)%mod;return *this;}
		modint& operator-=(modint a){x=x-a.x;if(x<0)x+=mod;return *this;}
		modint& operator*=(modint a){x=x*a.x%mod;return *this;}
		modint& operator/=(modint a){x=x*a.inv().x%mod;return *this;}

		modint operator+(modint a){return modint(x)+=a;}
		modint operator-(modint a){return modint(x)-=a;}
		modint operator*(modint a){return modint(x)*=a;}
		modint operator/(modint a){return modint(x)/=a;}

		modint operator-(){return modint(x);}

		bool operator==(const modint a){return x == a.x;}
		bool operator<(const modint a){return x < a.x;}
		bool operator>(const modint a){return x > a.x;}
};

template<long long mod>
ostream& operator<<(ostream& os, const modint<mod>& a){
	os << a.x;
	return os;
}

using mint = modint<MOD>;


ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

ll lcm(ll a, ll b){
	ll res = a*b;
	while(b){
		a%=b;
		swap(a, b);
	}
	return res / a;
}

const ll MAX = 1000000;

int main(){

	vector<mint> rev(MAX+1);
	repa(i, MAX+1)rev[i] = mint(i).inv();
	repa(i, MAX+1){
		for(int j=i*2;j<=MAX;j+=i)rev[j] -= rev[i]; 
	}

	vector<int> pop(MAX+1, 0);

	int n;
	cin >> n;
	vector<ll> line(n);
	foreach(i, line){
		cin >> i;
		++pop[i];
	}

	mint ans;

	repa(i, MAX+1){
		mint sum;
		for(int j=i;j<=MAX;j+=i){
			sum += mint(j) * mint(pop[j]);
		}
		for(int j=i;j<=MAX;j+=i){
			if(!pop[j])continue;
			ans += rev[i] * (sum - mint(j)) * mint(j) * mint(pop[j]);
		}
	}

	cout << ans / mint(2) << endl;

	return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int a=N/100,b=N%100;
  if (1<=a&&a<=12&&1<=b&&b<=12){
    cout << "AMBIGUOUS" << endl;
  }
  else if (1<=a&&a<=12&&(b>12||b==0)){
    cout << "MMYY" << endl;
  }
  else if ((a>12||a==0)&&1<=b&&b<=12){
    cout << "YYMM" << endl;
  }
  else {
    cout << "NA" << endl;
  }
}

Measured memory_bytes: 256
a,b=gets.split(" ").map &:to_i
tmp_a = a%2==1 ? a+1 : a
tmp_b = b%2==1 ? b   : b-1
parity = ((tmp_b-tmp_a+1)/2)%2
ans = (a%2==1 ? a : 0) ^ (b%2==1 ? 0 : b) ^ parity
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b;
  cin >> n >> a >>b;
  int A,B,C;
  A=0;
  B=0;
  C=0;
  for(int i=0;i<n;i++){
    int m;
    cin >>m;
    if( m>=b+1){
      C++;
    }
    else if (m>=a+1){
      B++;
    }
    else{
      A++;
    }
  }
  cout << min({A,B,C});
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k,x,y;cin >> n >> k >> x >> y;
	ll ans = min(n,k) * x;
	n -= min(n,k);
	ans += n * y;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;cin >> x;
  vector<bool> p(x+1001,true);
  for(int i=2;i<=x+1000;i++){
    if(p[i]){
    for(int j=2;i*j<=x+1000;j++){
      p[i*j]=false;
    }
    }
  }
  for(int i=x;;i++){
    if(p[i]){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int ans = -1, l = 0;
        for (char c : scanner.next().toCharArray()) if (l != (l = c)) ans++;
        System.out.println(ans);
    }
}

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

int main() {
  int n,k=0;
  string s;
  cin >>n>>s;
  vector<int> sum(n+1,0);
  int ss=0,ans=300000;
  rep(i,n){
    if(s.at(i)=='#') ss++;
    sum[i+1]=ss;
  }
  rep(i,n+1){
    int kl=0,kr=0;
    kl=min(i-sum[i],sum[i]);
    kr=(n-i)-(sum[n]-sum[i]);
    ans=min(ans,(kl+kr));
    if((kl+kr)==ans) k=i;
  }
  cout<<ans<<endl;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n;

    cin >> n;
    
    ll a, b, c;
    REP(i, n){
        vector<ll> v;
        cin >> a >> b >> c;
        v.PB(a);
        v.PB(b);
        v.PB(c);
        SORTDESC(v, ll);
        if (v[0]*v[0] == v[1]*v[1] + v[2]*v[2]){
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3040
# coding: utf-8
# Your code here!

class Node:
    def __init__(self):
        self.parentId=-1
        self.left=-1
        self.right=-1

def preorder(id):
    global node
    print(" "+str(id),end="")
    if node[id].left != -1:
        preorder(node[id].left)
    if node[id].right != -1:
        preorder(node[id].right)
    
def inorder(id):
    global node
    if node[id].left != -1:
        inorder(node[id].left)
    print(" "+str(id),end="")
    if node[id].right != -1:
        inorder(node[id].right)

def postorder(id):
    global node
    if node[id].left !=-1:
        postorder(node[id].left)
    if node[id].right!=-1:
        postorder(node[id].right)
    print(" "+str(id),end="")

n=int(input())
a=[[int(i)for i in input().split()]for j in range(n)]
node=[Node()for i in range(n)]

for i in a:
    id=i[0]
    left=i[1]
    right=i[2]
    node[id].left=left
    node[id].right=right
    if left != -1:node[left].parentId=id
    if right != -1:node[right].parentId =id

root=-1
for i in range(n):
    if node[i].parentId==-1:
        root=i
        break
print("Preorder")
preorder(root)
print("\nInorder")
inorder(root)
print("\nPostorder")
postorder(root)
print("")


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

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

    int N, M; cin >> N >> M;
    map<int, int, greater<int>> m;
    for (int i = 0; i < N; i++) {
        int A; cin >> A;
        m[A]++;
    }
    for (int i = 0; i < M; i++) {
        int B, C; cin >> B >> C;
        m[C] += B;
    }
    long long ans = 0;
    for (pair<int, int> p : m) {
        if (p.second < N) {
            ans += 1LL * p.first * p.second;
            N -= p.second;
        }
        else {
            ans += 1LL * p.first * N;
            break;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 9600
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
t = Is()
od,ev = [t[i] for i in range(0,n,2)], [t[i] for i in range(1,n,2)]
odm = collections.Counter(od).most_common()[:2]
evm = collections.Counter(ev).most_common()[:2]
if odm[0][0] != evm[0][0]:
    ans = n - odm[0][1] - evm[0][1]
elif len(odm) == len(evm) == 1:
    ans = n//2
elif len(odm) == 1:
    ans = n - odm[0][1] - evm[1][1]
elif len(evm) == 1:
    ans = n - odm[1][1] - evm[0][1]
else:
    ans = n - max(odm[0][1]+evm[1][1], odm[1][1]+evm[0][1])
print(ans)
    

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

int main()
{
    int n;
    int a[105];
    int ans = 0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int flag = 1;
    for(int i=0;flag;i++)
    {
        flag = 0;
        for(int j=n-1;j>=i+1;j--)
        {
            if(a[j]<a[j-1])
            {
                int m = a[j-1];
                a[j-1] = a[j];
                a[j] = m;
                flag = 1;
                ans++;
            }
        }
    }
    for(int i=0;i<n-1;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<a[n-1]<<endl;
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a[90];
	int n;
	for (int i = 0; i < 90; i++) {
		if (i == 0)
			a[i] = 2;
		if (i == 1)
			a[i] = 1;
		if (i >= 2)
			a[i] = a[i - 1] + a[i - 2];
		//cout << a[i] << endl;
	}
	while (cin >> n) {
		cout << a[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
s_list = list(s)
t_list = list(t)
compare = []
score = []

if s == t:
    print(0)
else:
    for i in range(len(s) - len(t) + 1):
        compare.append(s[i : i + len(t)])
    
    for v in compare:
        count = 0
        for v1, v2 in zip(list(v), t_list):
            #print(v1, v2)
            if v1 == v2:
                count += 1
        score.append(count)
    print(len(t) - max(score))


Measured memory_bytes: 9224
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		Queue<Integer> que = new PriorityQueue<>(new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				return -1 * Integer.compare(o1, o2);
			}
		});
		for (int i = 0; i < N; ++i) {
			que.add(Integer.parseInt(tokens[i]));
		}

		int alice = 0;
		int bob = 0;
		boolean isAlice = true;
		while (!que.isEmpty()) {
			if (isAlice) {
				alice += que.poll();
			} else {
				bob += que.poll();
			}
			isAlice = !isAlice;
		}
		System.out.println((alice - bob));
	}

	void calc() {
	}

	void showResult() {
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X, x;
  cin >> N >> X >> x;
  int ans=abs(X-x);
  for(int i=1; i<N; i++){
    int x, a, b;
    cin >> x;
    a=abs(X-x);
    b=a%ans;
    while(b!=0){
      a=ans, ans=b, b=a%ans;
    }    
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int n = input[0];
        int m = input[1];
        bool[] flag = new bool[n];
        int[] waCount = new int[n];
        int ac = 0,
            wa = 0;
        string[] tmp;
        for (int i = 0; i < m; i++)
        {
            tmp = Console.ReadLine().Split(' ');
            int index = int.Parse(tmp[0]) - 1;
            if (tmp[1].Equals("WA"))
            {
                waCount[index]++;
            }
            else
            {
                if (!flag[index])
                {
                    ac++;
                    wa += waCount[index];
                    flag[index] = true;
                }
            }
        }
        Console.WriteLine($"{ac} {wa}");
    }
}

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

using namespace std;

int main()
{
    string s;

    cin >> s;

    int n = s.length();

    for (int i = 0; i < n; i++)
    {
        if (s[i] == '?')
            s[i] = 'D';
    }

    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 3752
from collections import defaultdict
from bisect import bisect_left, bisect, insort_left, insort
INF = 10000
def lcs(s1, s2):
    c = defaultdict(list)
    for i, s in enumerate(s1):
        c[s].append(i)
    for s in set(s2):
        c[s].append(INF)
    def g(li, a):
        for i in li:
            if i >= a:
                return i
        return -1
    dp = []
    for s2_k in s2:
        bgn_idx = 0
        for i, cur_idx in enumerate(dp):
            chr_idx = c[s2_k][bisect_left(c[s2_k], bgn_idx)]
            if chr_idx == INF:
                break
            dp[i] = min(cur_idx, chr_idx + 1)
            bgn_idx = cur_idx
        else:
            chr_idx = c[s2_k][bisect_left(c[s2_k], bgn_idx)]
            if chr_idx != INF:
                dp.append(chr_idx + 1)
    return len(dp)
def solve():
    N = int(input())
    for _ in range(N):
        x = input()
        y = input()
        print(lcs(x, y))
solve()



Measured memory_bytes: 6028
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define p 1000000007
#define inv2 500000004
#define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
using namespace std;
inline ll read(){
    ll x=0;char zf=1;char ch=getchar();
    while(ch!='-'&&!isdigit(ch))ch=getchar();
    if(ch=='-')zf=-1,ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int k,m,n,x,y,z,cnt,ans[505][505];
int main(){
	k=r;
	if(k<=500){
		writeln(k);
		for(rt i=1;i<=k;i++)for(rt j=1;j<=k;j++)cout<<i<<" \n"[j==k];
		return 0;
	}
	writeln(n=500);
	for(rt i=1;i<=n;i++){
		ans[1][i]=i;
		for(rt x=n,y=i%n+1;x!=1;x--,y=y%n+1)ans[x][y]=i;
	}
	for(rt i=n+1;i<=k;i++){
		if(i+i&1)ans[1][i]=i;
		for(rt x=n,y=i%n+1;x!=1;x--,y=y%n+1)if(i+y&1)ans[x][y]=i;
	}
	for(rt i=1;i<=n;i++)for(rt j=1;j<=n;j++)cout<<ans[i][j]<<" \n"[j==n];
	return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double d;
    cin >> d;
    cout << fixed << setprecision(10);
    cout << max(d * sqrt(2), floor(d) + 1.0) << endl;
    return 0;
}


Measured memory_bytes: 3308