akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//↓✟MLE魔、TLE魔✟
#define int long long
//↑✟MLE魔、TLE魔✟
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
class Union_Find{
private:
    vector<int> t,s;
public:
    Union_Find(int max_length){
        rep(i,max_length+1){
            t.push_back(i);
            s.push_back(1);
        }
    }
    void Union(int x,int y){
        if(same(x,y))return;
        int tx=Find(x),ty=Find(y);
        if(s[tx]<s[ty]){
            s[ty]+=s[tx];
            t[tx]=ty;
        }
        else if(s[tx]>s[ty]){
            s[tx]+=s[ty];
            t[ty]=tx;
        }
        else if(tx>ty){
            t[tx]=ty;
            s[ty]+=s[tx];
        }
        else{
            t[ty]=tx;
            s[tx]+=s[ty];
        }
    }
    int Find(int n){
        if(t[n]==n)return n;
        else return t[n]=Find(t[n]);
    }
    bool same(int x,int y){
        return Find(x)==Find(y);
    }
    int gets(int a){
        return s[a];
    }
};
signed main(){
    int n,m,ans=0;
    pair<int,int> p[100000];
    cin>>n>>m;
    rep(i,n)cin>>p[i].first>>p[i].second;
    sort(p,p+n);
    rep(i,n){
        if(m<=p[i].second){
            cout<<ans+m*p[i].first<<endl;
            return 0;
        }
        m-=p[i].second;
        ans+=p[i].first*p[i].second;
    }
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#define MAX_i 70000

typedef struct process{
    char name[11];
    int time;
}pr;
void enqueue(pr x);
pr dequeue();
pr p[MAX_i];
int head,tail;

int main(void){
    int n,q,i,sum=0;
    pr x;
    
    scanf("%d %d",&n,&q);
    for(i=0;i<n;i++){
        scanf("%s %d",p[i].name,&p[i].time);
    }
    head=0;
    tail=n;
    while(head!=tail){
        x=dequeue();
        if(x.time<=q){
            sum+=x.time;
            printf("%s %d\n",x.name,sum);
        }else{
            sum+=q;
            x.time-=q;
            enqueue(x);
        }
    }
    return 0;
}

void enqueue(pr x){
    p[tail]=x;
    if(tail+1==MAX_i){
        tail=0;
    }else{
        tail++;
    }
}

pr dequeue(){
    if(head+1==MAX_i){
        head=0;
        return p[MAX_i-1];
    }else{
        head++;
        return p[head-1];
    }
}



Measured memory_bytes: 2816
// Aizu Vol-0 0067: The Number of Island
// 2017.8.4

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *gets(char *);
char buf[100];

typedef struct { char r, c; } T;
char a[14][14];
char f[14][14];
T s[14 * 14];
int top;

void see(int r, int c, int n)
{
//	printf("See [%d,%d], n=%d\n", r, c, n);
	f[r][c] = n, s[0].r = r, s[0].c = c;
	for (top = 1; top; ) {
		r = s[--top].r, c = s[top].c;
		if (a[r - 1][c] == '1' && !f[r - 1][c]) f[r - 1][c] = n, s[top].r = r - 1, s[top++].c = c;
		if (a[r + 1][c] == '1' && !f[r + 1][c]) f[r + 1][c] = n, s[top].r = r + 1, s[top++].c = c;
		if (a[r][c - 1] == '1' && !f[r][c - 1]) f[r][c - 1] = n, s[top].r = r, s[top++].c = c - 1;
		if (a[r][c + 1] == '1' && !f[r][c + 1]) f[r][c + 1] = n, s[top].r = r, s[top++].c = c + 1;
	}
}

int main()
{
	int r, c, k = 1, cnt;
	
	while (1) {
		if (k) k = 0;
		else if (gets(buf) == NULL) break;
		for (r = 1; r <= 12; r++) gets(&a[r][1]);
		memset(f, 0, sizeof(f));
		for (cnt = 0, r = 1; r <= 12; r++) for (c = 1; c <= 12; c++) {
			if (a[r][c] == '1' && !f[r][c]) see(r, c, ++cnt);
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 520
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed
int main()
{
     ios;
     ll a, b, c, d;
     cin >> a >> b >> c >> d;
     cout << max({a * c, a * d, b * c, b * d});
     return 0;
}    

Measured memory_bytes: 3596
from itertools import permutations
n = int(input())
p_nums = tuple([int(i) for i in input().split()])
q_nums = tuple([int(i) for i in input().split()])

tmp = permutations(range(1, n+1))
d = {tuple(permu): i for i, permu in enumerate(tmp, 1)}

print(abs(d[p_nums] - d[q_nums]))


Measured memory_bytes: 10344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cfenv>
#include <cmath>

using namespace std;

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


  cout<<a*b<<endl;


  return 0;
}

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //n+1個 町 n 勇者
		
		int []a = new int[n+1]; //モンスターの数
		
		int [] b = new int[n]; //倒せる
		
		for(int i = 0; i < n+1; i++) {
			a[i] = stdIn.nextInt();
		}
		for(int i = 0; i < n; i++) {
			b[i] = stdIn.nextInt();
		}
		
		long cnt = 0;
		
		for(int i = 0; i < n; i++) {
			if(a[i] >= b[i]) {
				cnt += b[i];
			}else {
				cnt += a[i];
				int space = b[i] - a[i];
				
				if(space<= a[i+1]) {
					a[i+1] = a[i+1] - space;
					cnt += space;
					
				}else {
					cnt += a[i+1];
					a[i+1] = 0;
				}
			}
		}
		System.out.println(cnt);
		
	}

}


Measured memory_bytes: 64716
#include<stdio.h>
int main(){
int i,j,k,x,y,z,flag=0;
char s[100];
scanf("%s",s);
for(i=1;s[i]!='\0';i++)
if(s[i]!='9')
{
flag=1;
break;
}
x=0;
y=strlen(s);
if(flag==1)
x=s[0]-48+9*(y-1)-1;
else
x=s[0]-48+9*(y-1);
printf("%d",x);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int ma = 0, mb = 0;
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        if(chmax(ma, a)) mb = b;
    }
    cout << ma + mb << endl;
}

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

int main(){
	ll a,b,c; cin >> a >> b >> c;
	if(a == b && a != c)cout << "Yes" << endl;
	else if(c == b && a != b)cout << "Yes" << endl;
	else if(a == c && a != b)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

signed main(){
    int S;string T;
    while(cin>>S>>T,S!=0||T!="0"){
        map<int,vint>M;
        int n=T.size()-1;
        rep(b,1<<n){
            int sum=0,tmp=T[0]-'0';
            rep(i,n){
                if(b>>i&1){
                    sum+=tmp;
                    tmp=0;
                }
                tmp=tmp*10+T[i+1]-'0';
            }
            sum+=tmp;
            if(sum<=S)M[sum].pb(b);
        }
        if(M.size()==0){
            cout<<"error"<<endl;
            continue;
        }
        vint &v=M.rbegin()->se;
        if(v.size()>=2){
            cout<<"rejected"<<endl;
            continue;
        }
        int b=v[0];
        cout<<M.rbegin()->fi<<" ";
        cout<<T[0];
        rep(i,n){
            if(b>>i&1)cout<<" ";
            cout<<T[i+1];
        }cout<<endl;
    }
    return 0;
}

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define ll  long long
#define ull unsigned long long

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

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 1005;

// gcd
ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}
ll lucas(ll n)
{
	if ( n == 0)
		return 2;
	if ( n == 1)
		return 1;
	ll a = 2;
	ll b = 1;
	for ( int i = 2; i <= n; i++)
	{
		ll c = a + b;
		a = b;
		b = c;
	}
	return b;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ll ans = 0;
	ll a = 1;
	ll b = 2;
	ll n;
	cin >> n;
	cout << lucas(n) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <cstring> 
using namespace std;
const int N=1000+5;

int main()
{
	char s[N];
	int w;
	cin>>s>>w;
	int n=strlen(s);
	for(int i=0;i<n;){
		cout<<s[i];
		i+=w;
	}
	
	return 0;
}

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

int main(){
  int a, b, c, x, y;
  int min, nmin;
  int i, j;

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

  min = a*x + b*y;

  if(x>=y){
    for(i=0; i<y; i++){
      nmin = a*(x-i) + b*(y-i) + c*2*i;
      if(min>nmin) min = nmin;
    }
    for(j=i; j<=x; j++){
      nmin = a*(x-j) + c*2*j;
      if(min>nmin) min = nmin;
    }
  }else{
    for(i=0; i<x; i++){
      nmin = a*(x-i) + b*(y-i) + c*2*i;
      if(min>nmin) min = nmin;
    }
    for(j=i; j<=y; j++){
      nmin = b*(y-j) + c*2*j;
      if(min>nmin) min = nmin;
    }
  }

  cout << min << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX_N = 100010;
static const int NIL = -1;

vector<int> G[MAX_N];
int color[MAX_N];

void bfs(int u, int id) {
  stack<int> s;
  s.push(u);
  color[u] = id;
  while (!s.empty()) {
    int f = s.top(); s.pop();
    for (int i = 0; i < G[f].size(); ++i) {
      int v = G[f][i];
      if (color[v] == NIL) {
        color[v] = id;
        s.push(v);
      }
    }
  }
}

int main() {
  int n, m, s, t, q;

  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  for (int i = 0; i < n; ++i) {
    color[i] = NIL;
  }

  int id = 1;
  for (int u = 0; u < n; ++u) {
    if (color[u] == NIL) {
      bfs(u, id++);
    }
  }

  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> s >> t;
    if (color[s] == color[t]) {
      cout << "yes\n";
    } else {
      cout << "no\n";
    }
  }
  
  return 0;
}


Measured memory_bytes: 9028
#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ar array
const int MOD = (int)1e9 + 7;

void solve() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < (int) n; i++) {
        cin >> arr[i];
    }
    vector<int> dp(n,0);
    for (int i = (int) n - 1; i >= 0; --i) {
        if(i==(n-1)) dp[i]=arr[i];
        else dp[i] = dp[i+1]+arr[i];
    }
    int ans = 0;
    for (int i = (int) n - 2; i >= 0; --i) {
        ans += (dp[i+1]%MOD*arr[i]%MOD)%MOD;
    }
    cout << ((ans%MOD)+MOD)%MOD << "\n";
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int TC = 1;
    while (TC--)
        solve();

    return 0;
}



Measured memory_bytes: 6320
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

//[i文字目][alphabet]
int nex[201010][26];
int main()
{
	string s,t;
	cin >> s;
	cin >> t;

    int A = s.size();

    string s2 = s + s;

    for(int j = 0; j < 26; ++j)
    {
        nex[2*A][j] = s2.size();
    }

    for(int i = s2.size() - 1; i >= 0; --i)
    {
        for(int j = 0; j < 26; ++j)
        {
            //1文字前の(後ろからだから後)の情報をもらう
            nex[i][j] = nex[i+1][j];
        }
        //今回の分(位置なので+1)
        nex[i][s2[i] - 'a'] = i + 1;
    }

    //nex[0] - nex[s*2 -1]までのoffsetが完成

    ll res = 0;
    for(auto c: t)
    {
        //数値に変換
        c -= 'a';
        //xはsのあまり
        int x = res % A;
        //s中にないアルファベットなら
        if(nex[x][c] == s2.size())
        {
            cout << -1 << endl;
            return 0;
        }
        res += nex[x][c] - x;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 21120
/*-- ILSH --*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define viii vector < vii >
#define vlll vector < vll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=200000+6;
const ll inf=1e18+1e17;
void solve(){
	int n;
	cin>>n;
	int min =1e9;
	int count=0;
	for ( int i=0;i<n;i++){
		int aa;
		cin>>aa;
		if ( aa<min){
			min=aa;
			count++;
		}
	}
	cout<<count<<'\n';
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //    freopen ("INPUT.txt" , "r" , stdin);
    //    freopen ("OUTPUT.txt", "w" , stdout);
    // #endif	
    int t=1;
    //cin>>t;
    while ( t-- ){
    	solve();
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
int const MAXN=1001;
int const INF=2<<29;
typedef pair<int,int> P;
int h,w;
int sx,sy;
int res=0;
char maze[MAXN][MAXN]={0};
int d[MAXN][MAXN]={0};
int next[4][2]={{0,1},{0,-1},{1,0},{-1,0}};

void bfs(int n)
{
	queue<P> q;
	q.push(P(sx,sy));
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			d[i][j]=INF;
	d[sx][sy]=0;
	while(q.size())
	{
		P p=q.front();
		q.pop();
		if(maze[p.first][p.second]=='0'+n)
		{
			res+=d[p.first][p.second];
			sx=p.first;
			sy=p.second;
			return;
		}
		for(int i=0;i<4;i++)
		{
			int tx=p.first+next[i][0];
			int ty=p.second+next[i][1];
			if(maze[tx][ty]&&maze[tx][ty]!='X'&&d[tx][ty]==INF)
			{
				d[tx][ty]=d[p.first][p.second]+1;
				q.push(P(tx,ty));
			}
		}
	}		
}

int main()
{
	int n;
	cin>>h>>w>>n;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
		{
			cin>>maze[i][j];
			if(maze[i][j]=='S')
				sx=i,sy=j;
		}
	for(int i=1;i<=n;i++)
		bfs(i);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 7968
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i++)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 100000000

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;


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

	rep(i, s.length()) {
		if (i % 2 == 0)
		{
			ans = ans + s[i];
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
ll ans=0,n;
 
void backtrack(ll x,ll a,ll b,ll c){
	if(x>n)
		return;
	if(a&&b&&c)
		ans++;
	backtrack(x*10+3,a+1,b,c);
	backtrack(x*10+5,a,b+1,c);
	backtrack(x*10+7,a,b,c+1);
}
 
int main()
{
	cin>>n;
	backtrack(0,0,0,0);
	cout<<ans;
	return 0;
}

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

int main() {
    int H,W;
    cin >> H >> W;
    vector<vector<char>> a(H,vector<char>(W));
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            cin >> a[i][j];
        }
    }

    vector<bool> row(H,false);
    vector<bool> col(W,false);
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            if(a[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }

    for(int i=0;i<H;i++) {
        if(row[i]) {
            for(int j=0;j<W;j++) {
                if(col[j]) {
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    ll r, g, b, n;
    cin >> r >> g >> b >> n;

    ll ans = 0;
    for(ll i = 0; i * r <= n; i++) {
        for(ll j = 0; i * r + j * g <= n; j++)
            if((n - i * r - j * g) % b == 0) ans++;
    }
    cout << ans << endl;

    return 0;
}

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

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

	vector<int> d(N);
	REP(i, N){
		cin >> d[i];
	}

	bitset<100> s;
	REP(i, N){
		s.set(d[i] - 1, 1);
	}
	cout << s.count() << endl;
}


Measured memory_bytes: 3632
n = int(input())
nums = list(map(int, input().split()))
if n == 0:
  if nums[0] == 1:
    print(1)
  else:
    print(-1)
  exit()
if n > 0 and nums[0] != 0:
  print(-1)
  exit()
n_nods = 1
ans = 1
ret = sum(nums)
for i in range(1,n+1):
  n_nods = min(n_nods*2,ret)
  ans += n_nods
  ret -= nums[i]
  n_nods -= nums[i]
  if n_nods < 0:
    print(-1)
    exit()
  if n_nods == 0 and i < n:
    print(-1)
    exit()
print(ans)

Measured memory_bytes: 19984
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>

using namespace std;

int main(void)
{
    string S;
    int N, i, a=0, b=0;

    cin >> S;

    N = S.size();

    for(i=0; i<N; i++){
        if(S[i] == '0'){
            a++;
        }
        else{
            b++;
        }
    }

    cout << min(a, b) * 2 << endl;

    return 0;
}

Measured memory_bytes: 512
using System;

class Program
{
    static void Main()
    {
            int i, j,sum=0,all=0;
            
            string inp = Console.ReadLine();
            string[] data = inp.Split(' ');
            int tate = int.Parse(data[0]);
            int yoko = int.Parse(data[1]);
            int[] total = new int[yoko];
            int[,] men = new int[tate, yoko];
            for (i = 0; i < tate; i++)
            {
                string inn = Console.ReadLine();
                string[] din = inn.Split(' ');
                for (j = 0; j < yoko; j++)
                {
                    men[i,j] = int.Parse(din[j]);
                }
            }

            for (i = 0; i < tate; i++)
            {
                for (j = 0; j < yoko; j++)
                {
                    total[j] += men[i,j];
                    sum += men[i, j];
                    Console.Write("{0} ",men[i,j]);
                }
                Console.Write("{0}\n", sum);
                all += sum;
                sum = 0;
            }
            int x;
            for (x = 0; x < yoko; x++)
            {
                Console.Write("{0} ", total[x]);
            }
            Console.Write("{0}\n", all);
    }
}


Measured memory_bytes: 9220
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n;
  while(cin >> n, n) {
    int a = 0, b = 0;
    REP(i,n) {
      int c, d;
      cin >> c >> d;
      if (c>d) {
        a += c+d;
      } else if (c < d)
        b += c+d;
      else {
        a += c;
        b += c;
      }
    }
    cout << a << " " << b << endl;
  }
}

Measured memory_bytes: 0
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll k,a,b,tmp;

int main()
{Tie
	cin>>k>>a>>b,k++;
	if(b-a>2&&k>a)
		cout << a+(k-a)/2*(b-a)+(k-a)%2<<'\n';
	else
		cout << k<<'\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,k;
  	cin>>n>>k;
  	vector<int> a(n);
  	for(int i=0;i<n;i++){
		cin>>a[i];
    }
  
  	sort(a.begin(),a.end());
  	reverse(a.begin(),a.end());
  
  	int ans=0;
  
  	for(int i=0;i<k;i++){
		ans+=a[i];
    }
  
  
  	cout<<ans<<endl;
  	
}
  	

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

#define MAX 100000
#define NIL -1

struct Node{
int parent, left, right;
};

struct Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int,int);
int setHeight(int);
int getSibling(int);
void print(int);

int main(){
  int i,v,l,r,root=0;
  cin >> n;
  for(i=0;i<n;i++) T[i].parent=NIL;

  for(i=0;i<n;i++){
    cin >> v >> l >> r;
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL) T[l].parent=v;
    if(r!=NIL) T[r].parent=v;
  }
  for(i=0;i<n;i++){
    if(T[i].parent==NIL) root=i;
  }

  setDepth(root,0);
  setHeight(root);
  for(i=0;i<n;i++) print(i);
  return 0;
}

void setDepth(int u,int d){
  if(u==NIL) return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0, h2=0;
  if(T[u].left!=NIL) h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL) h2=setHeight(T[u].right)+1;
  return H[u]=(h1>h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].parent==NIL) return NIL;
  if(T[T[u].parent].left!=u && T[T[u].parent].left!=NIL) return T[T[u].parent].\
                                                           left;
  if(T[T[u].parent].right!=u && T[T[u].parent].right!=NIL) return T[T[u].parent\
                                                                    ].right;
  return NIL;
}
void print(int u){
  int deg=0;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "sibling = " << getSibling(u) << ", ";
  if(T[u].left!=NIL) deg++;
  if(T[u].right!=NIL) deg++;
  cout << "degree = " << deg << ", ";
  cout << "depth = " << D[u] << ", ";
  cout << "height = " << H[u] << ", ";
  if(T[u].parent==NIL) cout << "root" << endl;
  else if(T[u].left==NIL && T[u].right==NIL) cout << "leaf" << endl;
  else cout << "internal node" << endl;
}


Measured memory_bytes: 3140
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 998244353;
const ll INF = (1ll << 60);

int main(void)
{
    int n, k;
    cin >> n >> k;

    vector<ll> l(k), r(k), dp(n , 0), s(n +1, 0);

    for (int i = 0; i < k; i++)
    {
        cin >> l[i] >> r[i];
    }

    dp[0] = 1;
    s[1] = 1;

    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < k; j++)
        {
            ll x, y;

            if (i - l[j] < 0)
            {
                continue;
            }

            x = i - l[j] + 1; //big
            y = max(i - r[j], 0ll);     //small

            dp[i] += s[x] - s[y] + MOD;
            dp[i] %= MOD;
        }

        s[i + 1] = s[i] + dp[i] + MOD;
        s[i + 1] %= MOD;
    }

    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

void answer(bool ok) {
  cout << (ok ? "Possible" : "Impossible") << endl;
  exit(0);
}
#define NO() answer(false)
#define YES() answer(true)

const int N = 105;
int a[N];
int f[N];

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    f[a[i]]++;
  }
  sort(a, a + n);
  if (a[n - 1] != a[n - 2]) NO();

  int d = a[n - 1];
  int r = (d + 1) / 2;
  for (int x = r; x <= d; x++) {
    int cur = 2;
    if (x == r && d % 2 == 0) cur = 1;
    if (f[x] < cur) NO();
    f[x] -= cur;
  }

  for (int x = 1; x <= r; x++) {
    if (f[x]) NO();
  }

  YES();

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  for(int i = k; i < n; i++) {
    if(a.at(i-k) < a.at(i)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 4848
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <bits/stdc++.h>


using namespace std;
using ll = long long ;

vector<int> to[100005];
const int INF = 1001001001;

int main() {

    int n,m ; 
    cin >> n  >> m  ;

    for(int i=0;i<m;++i){
      int a,b ;
      cin >> a >> b ;
      --a; --b;
      to[a].push_back(b);
      to[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n,INF);
    vector<int> pre(n,-1);
    dist[0] = 0;
    q.push(0);
    while (!q.empty())
    {
      int v = q.front();q.pop();
      for(int u : to[v]){
        if(dist[u]!=INF) continue ;
        dist[u] = dist[v]+1;
        pre[u] = v;
        q.push(u);
      }
    }
    
    cout << "Yes" << endl;
    for(int i=0;i<n;i++){
      if(i==0) continue;
      int ans = pre[i] ;
      ++ans ;
      cout << ans << endl ;
    }
    return 0 ;
}

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



int main() {
  int n; cin>>n;
  string s; cin>>s;
  
  int allR=0;
  for(int i=0; i<n; i++){
    allR += (s.at(i)=='R');
  }
  if(allR==n || allR==0){cout<<"0\n"; return 0;}
  
  int cw, cr;
  cw=0; cr=allR;
  for(int i=0; i<n; i++){
    bool isr=(s.at(i)=='R');
    cw+=1-isr; cr-=isr;
    if(cw==cr){
      cout<<cw<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
using namespace std;
 
const int p=1e9+7;
const int maxn=1e5+2;
int DP[3000][3000], choice[3000][3000];  // choice[i][j] = 0, 1, 2   if(0) => i-- if(1) => j-- if(2) => i-- && j--

void solve() {
    // int N; cin >> N;
    string s, t; cin >> s >> t;
    DP[0][0] = 0;
    if(s[0] == t[0]) {
        DP[0][0] = 1;
        choice[0][0] = 2;
    }
    int n = s.length();
    int m = t.length();
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            // not picking 
            if(i > 0) {
                DP[i][j] = DP[i-1][j];
                choice[i][j] = 0;
            }
            if(j > 0) {
                if(DP[i][j-1] > DP[i][j]) { // if DP[i][j] is not initialised above it contains zero due to global declaration
                    DP[i][j] = DP[i][j-1];
                    choice[i][j] = 1;
                }
            }

            // picking only when they characters are equal
            if(s[i] == t[j]) {
                int ans = 1;
                if(i > 0 && j > 0) {
                    ans = 1 + DP[i-1][j-1];
                }
                if(ans > DP[i][j]) {
                    DP[i][j] = ans;
                    choice[i][j] = 2;
                }
            }
        }
    }

    // cout << DP[n-1][m-1] <<"\n";       // optimal max length of common subsequence

    // choice 1 & 2  correspond to not getting picked
    int i = n-1, j = m-1;
    string ans = "";
    while(i >= 0 && j >= 0) {
        if(choice[i][j] == 0) {
            i--;
        }
        else if(choice[i][j] == 1) {
            j--;
        }
        else {
            ans = s[i] + ans;
            i--; j--;
        }
    }
    cout << ans <<"\n";
}

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

Measured memory_bytes: 74016
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int64_t n,m,c;
  cin >> n >> m >> c;
  vector<int64_t> b(m);
  rep(i,m){
    cin >> b[i];
  } 
  int64_t solved = 0;
  rep(i,n){
    int64_t total = c;
    rep(i,m){
      int64_t hoge;
      cin >> hoge;
      total += b[i]*hoge;
    }
    if(total > 0) solved++;
  }
  cout << solved << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  lol n;
  cin >> n;
  lol a[n + 5];
  rep(i, n){
    cin >> a[i];
  }
  sort(a, a +n, greater<lol>());
  priority_queue<lol> nasu;
  int sum = 0;
  a[n] = INF;
  rep(i, n){
    sum ++;
    if(sum == 2){
      nasu.push(a[i]);
      sum = 0;
    }
    if(a[i] != a[i + 1]){
      sum = 0;
    }
  }
  if(nasu.size() < 2){
    cout << 0 << '\n';
  } else {
    lol na = nasu.top();
    nasu.pop();
    cout << na * nasu.top() << '\n';
  }
  return 0;
}


Measured memory_bytes: 1660
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        ArrayList<ArrayList<Integer>> edges = new ArrayList<>(N+1);
        ArrayList<ArrayList<Integer>> parents = new ArrayList<>(N+1);
        for(int i = 0; i < N+1; i++) {
            edges.add(new ArrayList<Integer>());
            parents.add(new ArrayList<Integer>());
        }

        int[] incounts = new int[N+1];
        for(int i = 0; i < N - 1 + M; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();

            edges.get(A).add(B);
            incounts[B]++;

            parents.get(B).add(A);
        }

        LinkedList<Integer> queue = new LinkedList<>();
        for(int i = 1; i < N+1; i++) {
            if (incounts[i] == 0) {
                queue.add(i);
            }
        }

        int[] vertexes = new int[N+1];
        int n = 0;
        while(!queue.isEmpty()) {
            int v = queue.removeFirst();
            vertexes[v] = n;
            n++;
            for(int w: edges.get(v)) {
                incounts[w]--;
                if (incounts[w] == 0) {
                    queue.add(w);
                }
            }
        }

        for(int i = 1; i < N+1; i++) {
            if (vertexes[i] == 0) {
                System.out.println(0);
            } else {
                int parent = -1;
                for(int w: parents.get(i)) {
                    if(parent < 0 || vertexes[w] > vertexes[parent]) {
                        parent = w;
                    }
                }
                System.out.println(parent);
            }
        }
    }
}


Measured memory_bytes: 133744
#include<iostream>
#include<cstring>
//#include<bits/stdc++.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#define  si(a)       scanf("%d",&a)
#define  sl(a)       scanf("%lld",&a)
#define  sii(a,b)    scanf("%d%d",&a,&b)
#define  sll(a,b)    scanf("%lld%lld",&a,&b)
#define  queues      priority_queue
#define mod 1000000007
#define mem(a)  memset(a,0,sizeof(a));
#define def(a) ((a)&(-a))
#define fi  first
#define se  second
#define mp  make_pair
#define  pb push_back
#define mem(a,b) memset(a,b,sizeof(a));
typedef long long ll;
//priority_queue<ll,vector<ll >,greater<ll > >q;
const int INF=0x3f3f3f3f;
//const double E=exp(1);
//const double PI=acos(-1);
using namespace std;
//__builtin_popcount
//priority_queue
const ll MAX=100000;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll kc(ll a,ll b)
{
    ll c=1;
    while(b)
    {
        if(b&1)c=(c*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return c;
}
bool cmp(double x,double y)
{
    return x>y;
}
ll F[50003*3];
ll Find(ll a)
{
    return F[a]<0?a:F[a]=Find(F[a]);
}
ll same(ll a,ll b)
{
    if(Find(a)==Find(b))return 1;
    return 0;
}
ll up1(ll a,ll b)
{
    ll x,y;
    x=Find(a);
    y=Find(b);
    if(x!=y)
        F[x]=y;
    return 0;
}
int read() {
    int x=0,f=1;char s=getchar();
    for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
    for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
    return x*f;
}
ll dp[100003][14];
int main()
{
   // ios::sync_with_stdio(false);
   string s;
   cin>>s;
   int a=s.size();
   dp[0][0]=1;
   for(int i=0;i<a;i++)
   {
       if(s[i]!='?')
       {
           int x=s[i]-'0';
           for(int j=0;j<=12;j++)
            dp[i+1][(j*10+x)%13]=dp[i][j];
       }
       else {
        for(int j=0;j<=9;j++)
        {
            for(int k=0;k<=12;k++)
                dp[i+1][(k*10+j)%13]=(dp[i+1][(k*10+j)%13]+dp[i][k])%mod;

        }

       }
   }
   cout<<dp[a][5]%mod<<endl;
}




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

int main() {
    int a,b;
    cin>>a>>b;
    
    cout<<(a+b+2-1)/2<<endl;
    
    return 0;
    }

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(x,n) for(auto& (x) : n)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define inf 1000000000
#define llinf 1000000000000000
#define MAX 1000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;
typedef pair<int,pint> P;

int main(){
    int n,k;
    cin>>n>>k;
    vint v(n);
    int ans=0;
    rep(i,n)cin>>v[i];
    reps(i,0,min(k,n)+1){
        rep(j,i+1){
            vint v2;
            rep(r,j){
                //cout<<r<<" "<<v[r]<<endl;
                v2.pb(v[r]);
            }
            rep(r,i-j){
                //cout<<n-r<<" "<<v[n-r]<<endl;
                v2.pb(v[n-r-1]);
            }
            //rep(r,v2.size())cout<<v2[r]<<endl;
            sort(all(v2));
            int sum=0;
            rep(r,i){
                if(r<k-i && v2[r]<0)continue;
                //cout<<v2[r]<<endl;
                sum+=v2[r];
            }
            //cout<<i<<" "<<j<<" "<<sum<<endl;
            ans=max(sum,ans);
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {

    static long MOD = 1000000007;

    public static long gcd(long a, long b) {
        if(b == 0) return a;
        return gcd(b, a%b);
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a,b);
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long ans = (b - a + 1) - ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d)));
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<functional>
using  namespace std;
typedef long long ll;
#define pd(x) printf("%d\n",x)
const double eps=1e-6;
const double PI=acos(-1.0);
const int INF=1e9+10;
const int MOD=1e9+7;
const int N=2e5+15;
int a[N],b[N];
vector<int>g[N];
void dfs1(int u,int fa)
{
   for(int i=0;i<g[u].size();i++)
   {
       int v=g[u][i];
        if(v==fa) continue;
       a[v]=a[u]+1;
       dfs1(v,u);
   }
}
void dfs2(int u,int fa)
{
   for(int i=0;i<g[u].size();i++)
   {
       int v=g[u][i];
       if(v==fa) continue;
       b[v]=b[u]+1;
       dfs2(v,u);
   }
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int u,v;
        for(int i=1; i<=n; i++)
        {
            g[i].clear();
            a[i]=b[i]=INF;
        }
        for(int i=1; i<n; i++)
        {
            scanf("%d%d",&u,&v);
            g[u].push_back(v);
            g[v].push_back(u);
        }
       dfs1(1,1);
       dfs2(n,n);
       int num1=0,num2=0;
       for(int i=2;i<n;i++)
       {
           if(a[i]<=b[i]) num1++;
           else num2++;
       }
        if(num1>num2) puts("Fennec");
        else puts("Snuke");
    }
    return 0;
}

Measured memory_bytes: 15744
N=int(input())
N-=1
A=[]
for i in range(N):
    B = list(map(int, input().split()))
    A.append(B)

for i in range(N):
    total=0
    for k in range(i,N):
        if k==i:
            total+=A[k][0]+A[k][1]
        else:
            if A[k][1]>total:
                total=A[k][1]
            if total%A[k][2]!=0:
                total=total+A[k][2]-total%A[k][2] 
            total+=A[k][0]
    print(total)
print(0)



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 1e9+7;
#define PI 3.1415926535
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
const int siz = 2*(1e6 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int prime[siz];
vector<int> vt;
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}


void sieve()
{
	int cnt = 0;
	prime[1] = prime[0] = 1;

	for(int i = 2 ; i < siz ; i++)
	{
		if(prime[i] != 1)
		{
			cnt++;
			for(int j = 2*i ; j < siz ; j+= i)
			{
				prime[j] = 1;
			}
		}
	}

	cout<<cnt<<"\n";
	
	


}



signed main()
{
	
	speedrap
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		int a[n];
		int sum = 0;
		for(int i = 0 ; i <n ; i++ )
		{
			cin>>a[i];
			sum += a[i];
		}

		int val = sum/(4*m);

		int cnt = 0;
		for(int i = 0 ; i < n ; i++)
		{
			if((4*m*a[i]) >= sum)
			{
				cnt++;
			}
		}

		if(cnt>=m)
		{
			cout<<"Yes\n";
		}
		else
		{
			cout<<"No\n";
		}
	}
}

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

using namespace std;

int main() {
  string S, T;
  cin >> S;
  cin >> T;
  int result = T.length();
  for (int i = 0; i < S.length()-T.length()+1; i++) {
    int tmp = 0;
    for (int j = 0; j < T.length(); j++) {
      if (T[j] != S[i+j]) tmp++;
    }
    result = result > tmp ? tmp : result;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<ctime>
#include<iostream>
#define INF 1e9
using namespace std;
const int maxn=201010;
int n,maxx;
string s;
map<string,int> q;
map<string,int>::iterator it;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		q[s]++;
		maxx=max(maxx,q[s]);
	}
	for(it=q.begin();it!=q.end();it++)
		if(it->second==maxx)
			cout<<it->first<<endl;
	return 0;
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    int ans=0;
    for(int i=1;i<n;i++)
    {
        ans+=i;
    }
    for(int i=0;i<m;i++)
    {
        ans+=i;
    }
    cout<<ans;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        // 主処理
        int result = a <= b ? a : a - 1;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#define Map_ map<string, int>
#define Map map<int, Map_ >
#define F first
#define S second

using namespace std;

Map data;

void insert(const string& s, const int& x){
  Map::iterator it=data.find(s.size());
  if(it==data.end()){
    Map_ tmp;
    tmp.insert(make_pair(s,x));
    data.insert(make_pair(s.size(),tmp));
    return;
  }
  Map_::iterator jt=it->S.find(s);
  if(jt==it->S.end()) it->S.insert(make_pair(s,x));
  else jt->S+=x;
}

void print(){
  for(Map::iterator it=data.begin(); it!=data.end(); ++it){
    for(Map_::iterator jt=it->S.begin(); jt!=it->S.end(); ++jt){
      cout << jt->F << " " << jt->S << endl;
    }
  }
}

int main(){
  int n, x;
  string s;
  data.clear();
  cin >> n;
  for(int i=0; i<n; ++i){
    cin >> s >> x; insert(s,x);
  }
  print();
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    if(n>=1800)
    cout<<1;
    else if(n>=1600)
    cout<<2;
    else if(n>=1400)
    cout<<3;
    else if(n>=1200)
    cout<<4;
    else if(n>=1000)
    cout<<5;
    else if(n>=800)
    cout<<6;
    else if(n>=600)
    cout<<7;
    else if(n>=400)
    cout<<8;
    return 0;
}


Measured memory_bytes: 3644
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
P=list(map(int,input().split()))
for i in range(n):
    if P[i]!=i+1:
        count+=1
if count in (2,0):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>

using namespace std;

class UnionFind{
private:
    vector<int> Parent;
public:
    UnionFind(int N){
        vector<int> Parent(N,-1);
    }

    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A]=root(Parent[A]);
    }

    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A,int B){
        A=root(A);
        B=root(B);
        if(A==B) return false;
        if(size(A)<size(B)) swap(A,B);
        Parent[A]-=Parent[B];
        Parent[B]=A;
    }
};

int main(){
    int r,D,x;
    cin >> r >> D >> x;
    for(int i=0;i<10;i++){
        x = r*x-D;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> p[m];
  rep(i, m) cin >> p[i].second >> p[i].first;

  sort(p, p + m);
  int ans = 0;
  int break_index = -1;
  rep(i, m) {
    if (p[i].second <= break_index && break_index < p[i].first) continue;
    else {
      ans ++;
      break_index = p[i].first - 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+100;
#define ll long long

void solve(){
    ll n;
    cin>>n;
    int m=n/500;
    int t=(n-m*500)/5;
    cout<<m*1000+t*5<<endl;
}

int main(){
    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
map<int,int> mp,v;
int main(){
    int num;
    cin>>num;
    int sqt_num=(int)sqrt((double)num);
    vector<bool> prime(num,true);
    prime.at(0)=false;
    for(int i=0;i<sqt_num;i++){
        if(prime.at(i)){
            for(int j=2;(i+1)*j<=num;j++){
                prime.at((i+1)*j-1)=false;
            }
        }
    }
    for(int i=num;i>=1;i--){
   int  n=i;
    for(int j=0;j<=i-1;j++){
        if(n==1)break;
        if(prime.at(j)){
            while(n%(j+1)==0){
                n/=(j+1);
                mp[(j+1)]++;
            }
        }
    }
    }
    ll ans=0;
    vector<ll> tmp;
    for(auto p:mp){
        ll res=p.second+1;
       tmp.push_back(res);
       //cout<<res<<endl;
    }
    for(int i=0;i<tmp.size();i++){
        if(tmp.at(i)>=75)ans++;
    }
    for(int i=0;i<tmp.size();i++){
        for(int j=0;j<tmp.size();j++){
            if(i==j)continue;
            if(tmp.at(i)>=5&&tmp.at(j)>=15)ans++;
            if(tmp.at(i)>=3&&tmp.at(j)>=25)ans++;
        }
    }
    for(int i=0;i<tmp.size();i++){
        for(int j=0;j<tmp.size();j++){
            for(int k=j+1;k<tmp.size();k++){
            if(i==j||i==k)continue;
            if(tmp.at(i)>=3&&tmp.at(j)>=5&&tmp.at(k)>=5)ans++;
            }
        }
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

lld f(lld y,lld x)
{
	if (y == -1 )
	{
		return 0;
	}else
	{
		return y / x + 1;
	}
}

int main()
{
	lld a,b,x;
	cin >> a >> b >> x;

	cout << f(b,x) - f(a-1,x) << endl;

	return 0;
}

Measured memory_bytes: 256