akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

const int N = 1e6+7;
const int MOD = 1e9+7;
const int INF = (~(1<<31));

int fre(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}

inline int read(){
	int x=0,f=-1;char ch=getchar();
	for(;ch<'0'||'9'<ch;ch=getchar())if(ch=='-') f=-1;
	for(;'0'<=ch&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}

#define lal puts("****");
#define pb  push_back
#define mp  make_pair

/*****************************************************************/

int n,m;
char s[111];
int main(){
	scanf("%s",s);
	int l = strlen (s);

	sort(s,s+l);
	int flag= 0;
	for(int i=1;i<l;i++){
		if(s[i]==s[i-1]) {
			flag = 1;
			break;
		}
	}

	if(flag) puts("no");
	else     puts("yes");
	
	return 0;
}




Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;
typedef long long lol;
struct Node{
	int next,to,a,b;
}edge[202];
int head[101];
lol f[51][2505],ans[51];
struct Status{
	int x,c;
	lol dis;
	Status(int xx,int cc,lol diss){
		x=xx;c=cc;dis=diss;
	}
	bool operator<(const Status &b) const{
		return dis>b.dis;
	}
};
int num,c[51],d[51],S,n,m,maxcost;
priority_queue<Status>Q;
void add(int u,int v,int a,int b)
{
	num++;
	edge[num].next=head[u];
	head[u]=num;
	edge[num].to=v;
	edge[num].a=a;
	edge[num].b=b;
}
void SPFA(int x)
{
	Q.push(Status(x,min(n*50,S),0));
	while (!Q.empty())
	{
		Status x=Q.top();
		Q.pop();
		if (f[x.x][x.c]>x.dis) continue;
		//printf("\n%d %d %d:",x.x,x.dis,x.c);
		for (int i=head[x.x];i;i=edge[i].next)
		{
			int v=edge[i].to;
			//printf("%d ",v);
			lol s=0;
			int lc=x.c-edge[i].a;
			if (lc>=0) 
			{
				if (x.dis+s+edge[i].b<f[v][lc])
				{
					f[v][lc]=x.dis+s+edge[i].b;
					Q.push(Status(v,lc,f[v][lc]));
				}
			}
		}
		if (f[x.x][min(x.c+c[x.x],2500)]>x.dis+d[x.x])
		{
			f[x.x][min(x.c+c[x.x],2500)]=x.dis+d[x.x];
			Q.push(Status(x.x,min(x.c+c[x.x],2500),x.dis+d[x.x]));
		}
	}
}
int main()
{int i,j,u,v,a,b;
//freopen("E.out","w",stdout);
	scanf("%d%d%d",&n,&m,&S);
	for (i=1;i<=m;i++)
	{
		scanf("%d%d%d%d",&u,&v,&a,&b);
		add(u,v,a,b);
		add(v,u,a,b);
	}
	for (i=1;i<=n;i++)
	{
		scanf("%d%d",&c[i],&d[i]);
	}
	memset(f,127/2,sizeof(f));
	f[1][min(n*50,S)]=0;
	maxcost=n*50;
	SPFA(1);
	memset(ans,127/2,sizeof(ans));
	for (j=2;j<=n;j++)
	for (i=0;i<=n*50;i++)
	{
		ans[j]=min(ans[j],f[j][i]);
	}
	for (i=2;i<=n;i++)
	printf("%lld\n",ans[i]);
}

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

int main(){
    int r;
    cin >> r;
    cout << 3*r*r <<endl;
    return 0;
}

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

#define pb     push_back
#define mp     make_pair
#define all(v) v.begin() , v.end()
#define allr(v) v.rbegin(), v.rend()
const ll INF =  0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int MAX = 1e5+5;

int n, ev, d;
vector<int> a;

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);

	// #ifndef ONLINE_JUDGE
	// freopen("in","r",stdin);
	// freopen("out","w",stdout);
	// #endif

	scanf("%d" , &n);
	for(int i = 0 ; i < n ; i++){
		scanf("%d" , &d);
		if(d%2 == 0)
			ev++;
	}
	int ans = pow(3, n) - pow(2, ev);
	printf("%d", ans);
	return 0;
}  

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

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000010;
const int delta = 11353;

int n, X[N], V[N], a[N], DP[N << 2], L[N], R[N], ind[N], pre[N], suf[N];
vi vl[N];

void Set(int id, int lq, int rq, int x, int l, int r){
	if (rq <= l || r <= lq) return;
	if (lq <= l && r <= rq){
		DP[id] = (DP[id] + x) % MOD;
		return;
	}
	int md = (l + r) >> 1;
	Set(id << 1, lq, rq, x, l, md);
	Set(id << 1 | 1, lq, rq, x, md, r);
	DP[id] = (DP[id << 1] + DP[id << 1 | 1]) % MOD;
}

int get(int id, int lq, int rq, int l, int r){
	if (rq <= l || r <= lq) return 0;
	if (lq <=l && r <= rq){
		return DP[id];
	}
	int md = (l + r) >> 1;
	return ((get(id << 1, lq, rq, l, md) + get(id << 1 | 1, lq, rq, md, r)) % MOD);
}

bool cmp(int x, int y){
	return V[x] < V[y];
}

int minu(int a, int b){
	a -= b;
	if (a < 0) a += MOD;
	return a;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> X[i] >> V[i];
		ind[i] = i;
	}
	sort(ind + 1, ind + n + 1, cmp);
	for (int i = 1; i <= n; i++) a[i] = X[ind[i]];
	for (int i = 1; i <= n; i++) pre[i] = max(pre[i - 1], a[i]);
	suf[n + 1] = INF;
	for (int i = n; i >= 1; i--){
		suf[i] = min(suf[i + 1], a[i]);
	}
//	for (int i = 1; i <= n; i++) cout << a[i] << ' ';
//	cout << '\n';
	for (int i = 1; i <= n; i++){
		int l = 0, r = i;
		while (r - l > 1){
			int md = (l + r) >> 1;
			if (pre[md] >= a[i]) r = md;
			else l = md;
		}
		L[i] = r;
		l = i, r = n + 1;
		while (r - l > 1){
			int md = (l + r) >> 1;
			if (suf[md] <= a[i]) l = md;
			else r = md;
		}
		R[i] = l;
//		cout << i << ' ' << L[i] << ' ' << R[i] << '\n';
		vl[L[i]].pb(R[i]);
	}
	Set(1, 0, 1, 1, 0, n + 1);
	for (int i = 1; i <= n; i++){
		sort(all(vl[i]));
		for (auto u:vl[i]){
			int x = get(1, i - 1, u + 1, 0, n + 1);
			Set(1, u, u + 1, x, 0, n + 1);
			
		}
	}
	cout << get(1, n, n + 1, 0, n + 1);

	return 0;
}


Measured memory_bytes: 31120
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct UnionFind{
    vector<ll> par;
    vector<ll> siz;

    void init(ll n){
        for(ll i=0;i<n;i++){
            par.push_back(i);
            siz.push_back(1);
        }
    }
    ll root(ll x){
        //根を返す
        if(par[x]==x){
            return x;
        }
        else{
            return (par[x]=root(par[x]));
        }
    }
    bool sameParent(ll x,ll y){
        return(root(x)==root(y));
    }
    void unite(ll x, ll y){
        x=root(x);y=root(y);
        if(x==y)    return;
        //データ構造->小を大にくっつける
        if(siz[x]<siz[y]) swap(x,y);
        siz[x] += siz[y];
        par[y]=x;
    }

    ll size(ll x){
        return siz[root(x)];
    }
};
//どんだけ情報を与えても一個は教えてもらわないと当たらないんじゃないか？？
//逆に一個情報もらえればダーッと全部わかる→グループ化。UF??
int main(){
    ll n,m;
    cin>>n>>m;
    UnionFind uf;
    uf.init(n);
    rep(i,m){
        ll x,y,z;
        cin>>x>>y>>z;
        x--;y--;
        uf.unite(x,y);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(uf.root(i)==i) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2156
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

#define MAX_N 1000
#define MAX_B 10000
int dp[MAX_N + 1][MAX_B + 1];
int main() {
    int h, n;
    scanf("%d %d", &h, &n);
    int *a = malloc(sizeof(int) * n); // attack
    int *b = malloc(sizeof(int) * n); // cost
    int max = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        scanf("%d", &b[i]);
    }

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= h; j++) {
            dp[i][j] = 100000000;
        }
    }
    dp[0][0] = 0;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= h + max; j++) {
            if (j < a[i]) {
                dp[i+1][j] = MIN(dp[i][j], dp[i+1][0] + b[i]);
                //printf("1) %d, %d, %d\n", i, j, dp[i+1][j]);
            } else {
                dp[i+1][j] = MIN(dp[i][j], dp[i+1][j-a[i]] + b[i]);
                //printf("2) %d, %d, %d\n", i, j, dp[i+1][j]);
            }
        }
    }

    /*
        for (int i = 0; i < n + 1; i++) {
        for (int j = 0; j < h + 1; j++) {
            printf("%d ", dp[i][j]);
        }
        printf("\n");

    }
    */
    printf("%d\n", dp[n][h]);
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,clr;
    cin >> n >> clr;
    int d[clr][clr];
    for(int i = 0; i < clr; i++) {
        for(int j = 0; j < clr; j++) {
            cin >> d[i][j];
        }
    }
    int cnt[3][clr];
    fill(cnt[0],cnt[3],0);

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            int r=(i+j)%3;
            int c;
            cin >> c;
            c--;
            cnt[r][c]++;
        }
    }

//    cout << "\n";
//    for(int i = 0; i < 3; i++) {
//        for(int j = 0; j < clr; j++) {
//            cout << cnt[i][j] << " ";
//        }
//        cout << "\n";
//    }
    if(n==1){
        cout << "0" << "\n";
        return 0;
    }
    int ans=1e9;
    int t[3];
    for(t[0] = 0; t[0] < clr; t[0]++) {
        for(t[1] = 0; t[1] < clr; t[1]++) {
            for(t[2] = 0; t[2] < clr; t[2]++) {
                if(t[0]==t[1]||t[1]==t[2]||t[2]==t[0]) continue;
                int tans=0;
                for(int l = 0; l < 3; l++) {
                    int to=t[l];
                    for(int m = 0; m < clr; m++) {
                        int fr=m;
                        int cost = d[fr][to]*cnt[l][fr];
                        tans+=cost;
                    }
                }
                ans=min(ans,tans);
            }
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3560
n = int(input())
F = [0]
for i in range(1, n+1):
    A = [F[i-1]+1]
    j = 1
    while i-6**j >= 0:
        A.append(F[i-6**j]+1)
        j += 1
    j = 1
    while i-9**j >= 0:
        A.append(F[i-9**j]+1)
        j += 1
    F.append(min(A))
print(F[n])


Measured memory_bytes: 3864
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	int n;
	cin >> n;
vector<int>s(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		sum += s[i];
	}
	if (sum % 10 == 0) {
		sort(s.begin(),s.end());
		for (int i = 0; i < n; i++) {
			if (s[i] % 10 != 0) {
				cout << sum - s[i] << endl;
				return 0;
			}
		}
	}
	else {
		cout << sum << endl;
		return 0;
	}
	cout << "0" << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define M 998244353
using namespace std;
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
// Function to find gcd of array of 
// numbers  
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
int k;
cin>>k;
int s=0;
for(int i=1;i<=k;i++)
{
for(int j=1;j<=k;j++)
{
for(int l=1;l<=k;l++)
{
	s+=gcd(gcd(i,j),l);
}	
}	
}
cout<<s<<"\n";
return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
using namespace std;
const ll MAXN = 1e6+7;
int main(){
    ll a,b; cin>>a>>b;
    for(ll x=10*b; x<=10*b+9; x++){
        ll aux = (x*8LL)/100LL;
        if(aux==a){cout<<x<<endl; return 0;}
    }
    cout<<"-1"<<endl;
}

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

int main(){
  int n, color[9], x, mini=0;
    cin >> n;
    for(int i=0; i<9; i++) color[i] = 0;
    for(int i=0; i<n; i++){
      cin >> x;
      if(3200<=x) color[8]++;
      else if(color[x/400]==0){
          color[x/400]++;
          mini += 1;
      }
    }

    cout << max(1, mini) << ' ' << mini+color[8] << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 A, B, C;
  std::cin >> A >> B >> C;
  if (A % 2 == 0 && B % 2 == 0 && C % 2 == 0 && A == B && B == C) {
    std::cout << -1 << std::endl;
  } else {
    i64 i;
    for (i = 0; A % 2 == 0 && B % 2 == 0 && C % 2 == 0; ++i) {
      i64 old_A = A, old_B = B, old_C = C;
      A = (old_B + old_C) / 2;
      B = (old_C + old_A) / 2;
      C = (old_A + old_B) / 2;
    }
    std::cout << i << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll H, W, N, posH, posW, Sr, Sc;
string S, T;

void solve() {
	cin >> H;

	int sub = H / 100;

	bool a = false, b = false;

	if (sub >= 1 && sub <= 12) {
		a = true;
	}

	sub = H % 100;

	if (sub >= 1 && sub <= 12) {
		b = true;
	}

	if (a && b) {
		cout << "AMBIGUOUS";
	}
	if (!a && b) {
		cout << "YYMM";
	}
	if (a && !b) {
		cout << "MMYY";
	}
	if (!a && !b) {
		cout << "NA";
	}

}

int main() {
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	// your code goes here
	int i,N,cnt;
	float kakuritu;
	scanf("%d",&N);
	for(i=1;i<=N;i++){
		if(i%2==1) cnt++;
	}
	kakuritu = (float)cnt / N;
	printf("%f\n",kakuritu);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
    int n, tmp;
    int max = 1;
    int min = 1e9;
    scanf("%d", &n);
    for (int i= 0; i < n; i++){
        scanf("%d", &tmp);
        max = (max < tmp) ? tmp : max;
        min = (min > tmp) ? tmp : min;
    }
    printf("%d\n", max - min);
    return 0; 
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
map <long long int,int> m;
pair <int,int> p[90010];
int abs(int a){
	return a>0 ? a : (-1)*a;
}
int main(){
	int i,j,h,w,d,a;
	scanf("%d%d%d",&h,&w,&d);
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			scanf("%d",&a);
			p[a].first=i; p[a].second=j;
		}
	}
	int n,l,r; long long int x,y,z;
	for(i=0;i<=d-1;i++){
		l=p[i+1].first; r=p[i+1].second;
		for(j=i+d;j<h*w;j+=d){
			x=100000*(i+1) +j+1;
			m[x]= abs(p[j+1].first-l) + abs(p[j+1].second-r) + ( j!=i+d ? m[x-d] : 0 ) ;
			l=p[j+1].first; r=p[j+1].second;
			
			
		}
		
	}
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d%d",&l,&r);
		int sum=0;
		int ki= (l%d==0 ? d : l%d);
		y=ki*100000+r;
		z=ki*100000+l;
		printf("%d\n",m[y]-m[z]);
	}
	
	
}

Measured memory_bytes: 7424
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

h, w, k = map(int, input().split())
s = [list(input()) for _ in range(h)]

ans = 0
for b1 in range(2**h):
    for b2 in range(2**w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (b1 & (1 << i) == 0) and (b2 & (1 << j) == 0):
                    if s[i][j] == '#':
                        cnt += 1
        if cnt == k:
            ans += 1

print(ans)


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 1e5+5;
string s;
ll n,k,result;
ll a[N];
ll fac[N], finv[N], inv[N];

void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < N; 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 COMB(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;
}

ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

// a*b/m
ll mul(ll a, ll b, ll m) {
    a = mod(a, m); b = mod(b, m);
    if (b == 0) return 0;
    ll res = mul(mod(a + a, m), b>>1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}


int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  rep(i,n) cin >> a[i];
  SORT(a,n);
  COMBinit();
  for(int x = 0; x <= n-k; x++) {
    ll temp = COMB(n-x-1, k-1);
    result += mul(temp, a[n-1-x] -a[x], MOD);
    result %= MOD;
    // cout << x << " : " << result << endl;
  }
  std::cout << result << endl;
}


Measured memory_bytes: 3328
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,k=n1()
X=n1()

ans=float("inf")
for i in range(n-k+1):
    a=X[i]
    b=X[i+k-1]
    if a*b<0:
        tmp=min(abs(a)*2+abs(b),abs(a)+abs(b)*2)
    else:
        tmp=max(abs(a),abs(b))
    ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 14252
#include <cstdio>

int R[200000 + 10], n;

inline int max(int a, int b) {
  return (a > b) ? a : b;
}

inline int min(int a, int b) {
  return (a < b) ? a : b;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) { scanf("%d", &R[i]); }

  int vmin = R[0];
  int vmax = -1000000000;

  for (int i = 1; i < n; ++i) {
    vmax = max(vmax, R[i] - vmin);
    vmin = min(vmin, R[i]);
  }

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

  return 0;
}

Measured memory_bytes: 1804
#include<stdio.h>

int main(){
  int n;
  char p, dummy;
  int input;
  int arr[4][13];
  int i, j;

  // array initialization
  for(i = 0; i < 4; i++){
    for(j = 0; j < 13; j++){
      arr[i][j] = 0;
    }
  }

  // array input
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%c", &dummy);
    scanf("%c %d", &p, &input);
    switch(p){
      case 'S':
	arr[0][input - 1] = 1;
	break;
      case 'H':
	arr[1][input - 1] = 1;
	break;
      case 'C':
	arr[2][input - 1] = 1;
	break;
      case 'D':
	arr[3][input - 1] = 1;
	break;
    }
  }

  // output
  for(i = 0; i < 4; i++){
    for(j = 0; j < 13; j++){
      if(arr[i][j] == 0){
        switch(i){
          case 0:
            printf("S %d\n", j + 1);
            break;
          case 1:
            printf("H %d\n", j + 1);
            break;
          case 2:
            printf("C %d\n", j + 1);
            break;
          case 3:
            printf("D %d\n", j + 1);
            break;
        }
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 2064
#57
import decimal
a,b = map(int,input().split())

for i in range(1,10001):
    num1 = int(i*decimal.Decimal("0.08"))
    num2 = int(i*decimal.Decimal("0.1"))
    if num1 == a and num2 == b:
        print(i)
        break
    if int(i*decimal.Decimal("0.08")) > a:
        print("-1")
        break

Measured memory_bytes: 10036
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
//const ll MOD=100000;
const ll MAX=1e7;
const ll INF=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll 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;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r];
}
signed main(){
    ll N; cin>>N;
    if(N==1){
        cout<<1<<endl;
        return 0;
    }
    vi dp(N+1);
    vi sum(N+1);
    dp[1]=sum[1]=1;
    ll ans=(dp[1]*(N-1)%MOD*(N-1)%MOD+dp[1]*std::min(2ll,N-1))%MOD;
    rep(i,2,N){
        dp[i]=sum[i-1]-dp[i-2];
        dp[i]=(dp[i]+MOD)%MOD;
        ans+=dp[i]*(N-1)%MOD*(N-1)%MOD;
        ans+=dp[i]*std::min(N-1,i+1)%MOD;
        ans%=MOD;
        sum[i]=(sum[i-1]+dp[i])%MOD;
    }
    dp[N]=sum[N-1]-dp[N-2];
    dp[N]=(dp[N]+MOD)%MOD;
    ans+=dp[N]*N%MOD;
    ans%=MOD;
    cout<<ans<<endl;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define re register int
using namespace std;
typedef pair<int,int> pir;
const int N=1e5+10;
int n;
int fa[N];
set<int> e[N];
map<pir,int> cnt;
queue<pir>q;
inline int read(){
	int x=0,f=0,ch=getchar();
    while(!isdigit(ch)){f|=ch=='-';ch=getchar();};
    while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48),ch=getchar();}
    return f?-x:x;
}
inline int find(int x){
	return x==fa[x]?x:fa[x]=find(fa[x]);	
}
inline void add_edge(int u,int v){
	e[u].insert(v);e[v].insert(u);
	cnt[pir(u,v)]++;cnt[pir(v,u)]++;
	if(cnt[pir(u,v)]==2) q.push(pir(u,v));
}
void init(){
	scanf("%d",&n);
	for(re i=1;i<=n;i++) fa[i]=i;
	for(re i=1,u,v;i<=(n-1)<<1;i++) add_edge(u=read(),v=read());
}
void solve(){
	while(!q.empty()){
		int x=q.front().first,y=q.front().second;
		q.pop();
		x=find(x),y=find(y);
		e[x].erase(y),e[y].erase(x);
		if(e[x].size()<e[y].size()) swap(x,y);
		fa[y]=x;
		for(set<int>::iterator i=e[y].begin();i!=e[y].end();i++){
			e[*i].erase(y),e[*i].insert(x),e[x].insert(*i);
			cnt[pir(y,*i)]=cnt[pir(*i,y)]=0;
			cnt[pir(x,*i)]++;cnt[pir(*i,x)]++;
			if(cnt[pir(x,*i)]==2) q.push(pir(x,*i));
		}
		e[y].clear();
	}
}
void print(){
	int ans=0;
	for(re i=1;i<=n;i++)
		if(i==find(i))
			ans++;
	puts(ans==1?"YES":"NO");
}
int main(){
	init();
	solve();
	print();
}

Measured memory_bytes: 56320
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N,a[100000];
bool Awin(){
	cin>>N;
	rep(i,N) cin>>a[i];
	sort(a,a+N);
	int x=0,y=0;
	int c=0;
	rep(step,N-1){
		if(a[x]>y+1) y++,c=0;
		else x++,c++;
	}
	if(c>0){
		if(a[x]>y+1){
			if((a[x]-y)%2==0) return 1;
		}
		return c%2;
	}
	return 1-(a[x]-y)%2;
}
int main(){
	if(Awin()) puts("First");
	else puts("Second");
}


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

int check(vector<int> array, vector<int> time){
  int ans = 0;
  for(int i = 0; i < array.size(); i++){
    ans += time[array[i]];
    if( i < array.size()-1){
      if(ans % 10 != 0){
      	ans += 10 - ans%10;
      }
    }
  }
  return ans;
}

int main(){
  vector<int> array = {0,1,2,3,4};
  vector<int> time(array.size());
  for(int i = 0; i < array.size(); i++){
    cin >> time.at(i);
  }
  
  int tmpans = 100000;
  int tmp;
  do{
    tmp = check(array, time);
    if(tmp < tmpans){
      tmpans = tmp;
    }
  }while(next_permutation(array.begin(), array.end()));
    
  cout << tmpans << endl;

}


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

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

	if ((c + b - 1) / b <= (a + d - 1) / d) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	
	return 0;
}
	

Measured memory_bytes: 3620
def argsort(arr, reverse=False, shift=20):
    N = len(arr)
    tmp=[0]*N
    for i in range(N):
        tmp[i] = (arr[i] << shift) | i
    tmp = sorted(tmp,reverse=reverse)
    out=[0]*N
    mask = (1<<shift) - 1
    for j in range(N):
        i = tmp[j] & mask
        out[j] = i
    return out

def dfs(G1,a0,seen,postorder,order):
    todo = [~a0, a0]
    while todo:
        a = todo.pop()
        if a >= 0:
            seen[a] = 1
            for b in G1[a]:
                if seen[b]: continue
                todo.append(~b)
                todo.append(b)
        else:
          if postorder[~a] == -1:
            postorder[~a] = order
            order += 1
    return seen,postorder,order
  
def dfs2(G2,v,seen):
    todo = [v]
    seen[v] = 1
    cc = [v]
    while todo:
        v = todo.pop()
        for next_v in G2[v]:
            if seen[next_v]: continue
            seen[next_v] = 1
            todo.append(next_v)
            cc.append(next_v)
    return cc,seen
  
def scc(G1,G2):
  N = len(G1)
  seen = [0]*N
  postorder=[-1]*N
  order = 0
  for i in range(N):
    if seen[i]:continue
    seen,postorder,order = dfs(G1,i,seen,postorder,order)

  seen = [0]*N
  scclist = []
  for i in argsort(postorder,reverse=True):
    if seen[i]:continue
    cc,seen = dfs2(G2,i,seen)
    scclist.append(cc)
  return scclist

def main():
  N,M = map(int,input().split())
  G1 = [[] for _ in range(N)]
  G2 = [[] for _ in range(N)]
  for i in range(M):
    a,b=map(int,input().split())
    G1[a].append(b)
    G2[b].append(a)
  scclist = scc(G1,G2)
  print(len(scclist))
  for cc in scclist:
    print(len(cc),*cc)
    
if __name__=="__main__":
  main()

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

using namespace std;

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define DOW(i,b,a) for (int i = (b); i >= (a); i--)
#define pb(a) push_back(a)
#define ALL(a) (a).begin(),(a).end()
#define fi first
#define se second

template<typename T>
void print_array(T* arr, int num) {
   FOR(i, 0, num) cout << arr[i] << ' ';
   cout << endl;
}

template<typename T> 
void print_vector(vector<T> vec) {
   FOR(i,0,vec.size()) cout << vec[i] << ' ';
   cout << endl;
}

int a,b,c;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("test.txt", "r", stdin);
    cin >> a >> b >> c;
    bitset<110> chk;
    chk.reset();
    int ans = 1, cur = a;
    while (ans) {
        int k = cur % b;
        if (k == c) {
            cout << "YES";
            return 0;
        }
        if (chk[k]) ans = 0;
        chk[k] = 1;
        cur += a;
    }
    cout << "NO";
}

Measured memory_bytes: 256
S = input()
T = input()

ans = "UNRESTORABLE"
for i in range(len(S)-len(T)+1):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break

        if cnt == len(T):
            # Sのi~i+jまでがTと一致させられる
            ans = S[:i] + T + S[i+len(T):]
            ans = ans.replace("?", "a")
            # 複数箇所でTを入れられる場合、後ろに入れたいのでSの最後まで見ていく
            
        
print(ans)



Measured memory_bytes: 3060
#include<cstdio>
#include<queue>
using namespace std;

const int INF = -1;

int G[110][110] = {};
int d[110] = {};

void bfs(int s, int n)
{
  int v;
  queue<int> que;

  for(int i = 1;i <= n;i++) d[i] = INF; //init

  que.push(s);
  d[s] = 0;
  
  while(que.size()){
    v = que.front();
    que.pop();

    for(int i = 1;i <= n;i++){
      if(G[v][i] != 1) continue;
      if(d[i] != INF) continue;

      que.push(i);
      d[i] = d[v]+1;
    }
  }
}

int main()
{
  int n;
  int i,j;
  int u,k,v;

  scanf("%d", &n);

  for(i = 0;i < n;i++){
    scanf("%d%d", &u, &k);

    for(j = 0;j < k;j++){
      scanf("%d", &v);
      G[u][v] = 1;
    }
  }

  /*for(i = 1;i <= n;i++)
    if(d[i] == 0) bfs(i, n);
  */
  bfs(1, n);
  
  for(i = 1;i <= n;i++)
    printf("%d %d\n", i, d[i]);

  return 0;
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())

using namespace std;

int main(){

    int n;
    vector<pair<int,int>> red;
    vector<pair<int,int>> blue;

    cin >> n;

    rep(i,n){
        int tmpx,tmpy;
        cin >> tmpx >> tmpy;

        red.push_back(make_pair(tmpy,tmpx));
    }
    
    rep(i,n){
        int tmpx,tmpy;
        cin >> tmpx >> tmpy;

        blue.push_back(make_pair(tmpy,tmpx));
    }

    sorta(red);
    sorta(blue);

    vector<int> bluecheck(100,0);

    int ans = 0;

    for(int i = red.size() - 1; i >= 0; i--){
        int redy = red[i].first;
        int redx = red[i].second;

        int tmpi = n - 1;

        while(blue[tmpi].first > redy){
            tmpi--;
        }

        tmpi++;

        int obji = n;
        int minx = INT_MAX;

        for(int j = tmpi; j < n; j++){
            if(blue[j].second > redx && blue[j].second < minx && bluecheck[j] == 0){
                minx = blue[j].second;
                obji = j;
            }
        }

        if(obji != n){
            //cerr << redx  << " " << redy << "  " << blue[obji].second << " " << blue[obji].first << endl;
            ans++;
            bluecheck[obji]++;
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (int argc, const char * argv [])
{
    int x,y,menseki,nagasa;
    scanf("%d %d",&x,&y);
    menseki=x*y;
    nagasa=x*2+y*2;
    printf("%d %d\n",menseki,nagasa);
    return 0;
}

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

using namespace std;

int main(void)
{
    string S;
    cin >> S;
    int sum = 0;
    int num = stoi(S);
    for(int i=0; i<S.size(); i++){
        sum += S[i]-'0';
    }
    if(num%sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int N;
  cin >> N;
    vector<int> P(N);
    rep(i,N) cin >> P.at(i);

    int curMin = N+1;

    int count = 0;

    rep(i,N){
        curMin = min(curMin, P.at(i));
        if(curMin == P.at(i)) count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 

#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)

void ayush(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

ll gcd(ll a, ll b) 
{ 
    if (a == 0) return b; 
    return gcd(b % a, a); 
} 

ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1) res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}
ll mulmod(ll a, ll b, ll mod) 
{ 
    ll res = 0; 
    a = a % mod; 
    while (b > 0) 
    { 
        if (b % 2 == 1) res = (res + a) % mod; 
        a = (a * 2) % mod; 
        b /= 2; 
    }  
    return res % mod; 
} 

int main(){
    ayush();
    fastio;

    ll t; t=1;
    while(t<=5){
        ll x; cin>>x;
        if(x==0) {cout<<t; break;}
        t++;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define lli long long int

lli solve(lli n)
{
    lli sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            
            sum+=i;
        }
    }
    return  sum;

}
int main()
{
    lli n;
	cin>>n;
	cout<<solve(n)<<"\n";

	return 0;
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int i, j;
  i=(A-1)/D;
  j=(C-1)/B;
  if(i<j)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

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


def solve(N: int):
    x = N // 1000
    N -= x * 1000
    if N == 0:
        print(0)
    else:
        print(1000 - N)
    return

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61724
#include <cstdio>
#include <cctype>
int main(){

char ch;
while(1){
scanf("%c",&ch);
if(isalpha(ch)){
if(islower(ch)) printf("%c",toupper(ch));
else printf("%c",tolower(ch));
}
else printf("%c",ch);

if(ch=='\n') break;
}
return 0;
}



Measured memory_bytes: 2604
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = []
for i in range(M):
    temp = list(map(int,input().split()))
    AB.append(temp)


hills = [[] for i in range(N)]
for ab in AB:
    a = ab[0]
    b = ab[1]
    hills[a-1].append(H[b-1])
    hills[b-1].append(H[a-1])

for hill in hills:
    hill = set(hill)
    
counter = 0
for i in range(N):
    hill = hills[i]
    if not hill :
        counter += 1
    elif H[i] > max(hill):
        counter += 1
    else :
        counter += 0

print(counter)



Measured memory_bytes: 43776
#include <bits/stdc++.h>
using namespace std;
int mcxi_to_int(string s) {
    int num=1,sum=0;
    for(int i=0;i<s.size();i++) {
        if(isdigit(s[i])) {
            num=s[i]-'0';
        }else if(s[i]=='m') {
            sum+=1000*num;
            num=1;
        }else if(s[i]=='c') {
            sum+=100*num;
            num=1;
        }else if(s[i]=='x') {
            sum+=10*num;
            num=1;
        }else {
            sum+=num;
            num=1;
        }
    }
    return sum;
}
string int_to_mcxi(int n) {
    string ret="";
    int num[4];
    for(int i=0;i<4;i++) {
        num[i]=n%10;
        n/=10;
    }
    if(num[3]>1) ret+=string(1,num[3]+'0')+"m";
    else if(num[3]==1) ret+="m";
    if(num[2]>1) ret+=string(1,num[2]+'0')+"c";
    else if(num[2]==1) ret+="c";
    if(num[1]>1) ret+=string(1,num[1]+'0')+"x";
    else if(num[1]==1) ret+="x";
    if(num[0]>1) ret+=string(1,num[0]+'0')+"i";
    else if(num[0]==1) ret+="i";
    return ret;
}
int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++) {
        string s1,s2;
        cin>>s1>>s2;
        cout<<int_to_mcxi(mcxi_to_int(s1)+mcxi_to_int(s2))<<endl;
    }
}

Measured memory_bytes: 3172
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<iomanip>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

int main(){
	
	while(true){
		int max,count=0;
		cin >> max;

		if(max==0){
			break;
		}

		for(int i=1;i<max;i++){
			int sum=0;
			for(int k=i;k<max;k++){
				sum+=k;
				if(sum==max){
					count++;
					break;
				}
			}
		}
		cout << count << endl;
	}


}

Measured memory_bytes: 1160
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, M, R;
    scan(N, M, R);
    auto r = aryread();
    auto G = new long[][](N, N);
    foreach (i; 0 .. N)
    {
        G[i][] = long.max >> 2;
        G[i][i] = 0;
    }
    foreach (i; 0 .. M)
    {
        long a, b, c;
        scan(a, b, c);
        a--, b--;
        G[a][b] = G[b][a] = c;
    }
    WF(G);
    r[] -= 1;
    r.sort();
    long ans = long.max;
    do
    {
        long tmp;
        foreach (i; 0 .. R - 1)
            tmp += G[r[i]][r[i + 1]];
        ans = ans.min(tmp);
    }
    while (nextPermutation(r));
    writeln(ans);
}

void WF(T)(ref T[][] G)
{
    foreach (k; 0 .. G.length)
        foreach (i; 0 .. G.length)
            foreach (j; 0 .. G.length)
                if (G[i][k] + G[k][j] < G[i][j])
                    G[i][j] = G[i][k] + G[k][j];
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
long long n,m,x,c,ans=10000000000000LL,money,b;
int main(){
   cin>>n>>m>>x;
   long long a[n][m],c[n];
   for(int i=0;i<n;i++){
      cin>>c[i];
      for(int j=0;j<m;j++){
         cin>>a[i][j];
      }
   }
   for(int i=0;i<m;i++){
      long long sum=0LL;
      for(int j=0;j<n;j++){
         sum+=a[j][i];
      }
      if(sum<x){cout<<-1<<endl;return 0;}
   }


   for(int bit=0;bit<1<<n;bit++){
      

      for(int i=0;i<m;i++){
         b=bit;
         long long sum=0LL;
         for(int j=0;j<n;j++){
            if(b&1LL)sum+=a[j][i];
            b>>=1;
         }
         if(sum<x)goto E;

      }
      money=0LL;
      b=bit;
      for(int i=0;i<n;i++){
         if(b&1LL)money+=c[i];
         b>>=1;
      }
      ans=min(ans,money);
      E:;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

int main(){
	int hako[10];
	REP(i,10)cin >> hako[i];
	sort(hako,hako+10);
	reverse(hako,hako+10);
	REP(i,3)cout << hako[i] << endl;
	return 0;
}

Measured memory_bytes: 3076
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

var ans int

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	w, _ := strconv.Atoi(stringLineScan())
	wv := make([][]int, n)
	for i := 0; i < n; i++ {
		t := make([]int, 2)
		t[0], _ = strconv.Atoi(stringLineScan())
		t[1], _ = strconv.Atoi(stringLineScan())
		wv[i] = t
	}
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		t := make([]int, w+1)
		dp[i] = t
	}
	mv := 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= w; j++ {
			weight, value := wv[i-1][0], wv[i-1][1]
			if j-weight >= 0 {
				v := dp[i-1][j-weight] + value
				if v >= dp[i-1][j] {
					dp[i][j] = v
					if v > mv {
						mv = v
					}
				} else {
					dp[i][j] = dp[i-1][j]
				}
			} else {
				dp[i][j] = dp[i-1][j]
			}
		}
	}
	fmt.Println(mv)
}

Measured memory_bytes: 81792
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;

using Real = double;
using Point = complex< Real >;
const Real EPS = 1e-8, PI = acos(-1);
using Polygon = vector< Point >;

namespace std {
  bool operator<(const Point &a, const Point &b) {
    return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
  }
}

inline bool eq(Real a, Real b) { return fabs(b - a) < EPS; }
Real cross(const Point &a, const Point &b) {
  return real(a) * imag(b) - imag(a) * real(b);
}

Real dot(const Point &a, const Point &b) {
  return real(a) * real(b) + imag(a) * imag(b);
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C
// 点の回転方向
int ccw(const Point &a, Point b, Point c) {
  b = b - a, c = c - a;
  if(cross(b, c) > EPS) return +1;  // "COUNTER_CLOCKWISE"
  if(cross(b, c) < -EPS) return -1; // "CLOCKWISE"
  if(dot(b, c) < 0) return +2;      // "ONLINE_BACK"
  if(norm(b) < norm(c)) return -2;  // "ONLINE_FRONT"
  return 0;                         // "ON_SEGMENT"
}

Point operator*(const Point &p, const Real &d) {
  return Point(real(p) * d, imag(p) * d);
}

istream &operator>>(istream &is, Point &p) {
  Real a, b;
  is >> a >> b;
  p = Point(a, b);
  return is;
}

ostream &operator<<(ostream &os, Point &p) {
  os << fixed << setprecision(10) << p.real() << " " << p.imag();
}

Polygon convex_hull(Polygon &p) {
  int n = (int) p.size(), k = 0;
  if(n <= 2) return p;
  sort(p.begin(), p.end());
  vector< Point > ch(2 * n);
  for(int i = 0; i < n; ch[k++] = p[i++]) {
    while(k >= 2 && cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < EPS) --k;
  }
  for(int i = n - 2, t = k + 1; i >= 0; ch[k++] = p[i--]) {
    while(k >= t && cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < EPS) --k;
  }
  ch.resize(k - 1);
  return ch;
}

int main(){
    int n;
    cin >> n;
    Polygon v(n);
    map<Point,int> ma;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        ma[v[i]] = i;
    }
    auto p = convex_hull(v);
    vector<double> ans(n,0.0);
    if(p.size()==2){
        for (int i = 0; i < p.size(); i++) {
            ans[ma[p[i]]] = 1./2;
        }
    }
    else{
        for (int i = 0; i < p.size(); i++) {
            Point a = p[(i+1)%p.size()] - p[i];
            Point b = p[(i-1+p.size())%p.size()] - p[i];
            double theta = acos(dot(a,b) / abs(a) / abs(b));
            ans[ma[p[i]]] = (PI - theta) / 2 / PI;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << setprecision(30) << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b;
    if(a>b){
        c = a;
        a--;
    }else{
        c = b;
        b--;
    }
    if(a>b){
        c += a;
    }else{
        c += b;
    }
    cout <<c <<endl;
    
}

Measured memory_bytes: 256