akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rush() int T;scanf("%d",&T);int kase=1;while(T--)
#define all(x) (x).begin(),(x).End()
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define pb(x) push_back(x)
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
using std::bitset;
typedef long long ll;
const ll maxn=1e6+5;
const ll mod=998244353;
const ll INF=0x3f3f3f3f3f3f3f3f;
const long double PI=acos(-1.0);
const long double eps=1e-5;
inline ll read(){ll ans=0,flag=1;char c;c=getchar();while(c<'0' || c>'9'){if(c=='-')flag=-1;c=getchar();}while(c>='0' && c<='9'){ans=ans*10+(ll)(c-'0');c=getchar();}return ans*flag;}
ll quickpow(ll x,ll y,ll mod){ll ans=1;while(y){if(y&1)ans=ans*x%mod;x=x*x%mod;y>>=1;}return ans;}

int a[15][15];

int f(int x)
{
    int t=x;
    while(t>=10)
    {
        t/=10;
    }
    return t;
}

int main()
{
    int n;
    cin>>n;
    mem(a);
    for(int i=1;i<=n;i++)
    {
        int x=i%10;
        int y=f(i);
        if(!x||!y)
            continue;
        else
            a[y][x]++;
    }
    ll ans=0;
    for(int i=1;i<=9;i++)
        for(int j=1;j<10;j++)
    {
        ans+=a[i][j]*a[j][i];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        aa: [usize; n]
    }
    
    for i in 0..n {
        if i < k {
            continue;
        }

        if aa[i] <= aa[i-k] {
            println!("No");
        } else {
            println!("Yes");
        }
    }
}


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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

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

int main() {
    vector<vector<int>> c(3,vector<int>(3));
    REP(i,3) {
        cin >> c[i][0] >> c[i][1] >> c[i][2];
    }
    
    
    bool flg = true;
    REP(i,2) {
        int gap0,gap1,gap2;
        gap0 = c[i+1][0] - c[i][0];
        gap1 = c[i+1][1] - c[i][1];
        gap2 = c[i+1][2] - c[i][2];
        if ( gap0 != gap1 or gap1 != gap2 ) flg = false;
    }
    REP(i,2) {
        int gap0,gap1,gap2;
        gap0 = c[0][i+1] - c[0][i];
        gap1 = c[1][i+1] - c[1][i];
        gap2 = c[2][i+1] - c[2][i];
        if ( gap0 != gap1 or gap1 != gap2 ) flg = false;
    }
    
    if ( flg ) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3608
n;m;a[100];b[100];i;c(int*x,int*y){return a[*y]-a[*x]?:*x-*y;}main(x){for(;~scanf("%d%d",&n,&m)&&n;puts("")){bzero(a,4*m);for(i=0;i<n*m;a[i++%m]+=x,b[i%m]=i%m)scanf("%d",&x);qsort(b,m,4,c);for(i=0;i<m;i++)printf("%s%d",i?" ":"",b[i]+1);}}

Measured memory_bytes: 428
//组合数=杨辉三角 
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int N=55;
int n,a,b;
ll v[N],c[N][N];
bool cmp(ll x,ll y)
{
	return x>y;
}

void pre()//杨辉三角求组合数 Cn^m=n!/(m!(n-m)!) =杨辉三角第n-1层第m-1个数 即从n中取m个的方案数 Cn^0+Cn^1+.....+Cn^n=2^n<2^64 50!>ll
{

	for(int i=0;i<=50;i++)
	{
		c[i][0]=1;c[i][i]=1;
	}
	for(int i=1;i<=50;i++)
	{
		for(int j=1;j<i;j++)
		{
			c[i][j]=c[i-1][j]+c[i-1][j-1];
		}
	}
}

int main()
{
	double ave=0;
	ll m=0,sum=0;
	scanf("%d%d%d",&n,&a,&b);
	
	pre();
	
/*	for(int i=0;i<=50;i++)
	{
		for(int j=0;j<=i;j++)
		{
			printf("%lld ",c[i][j]);
		}
		printf("\n");
	}
*/	
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&v[i]);
	}
	
	sort(v+1,v+1+n,cmp);
	for(int i=1;i<=a;i++)
	{
		sum+=v[i];
	}
	ave=(double)sum/a;

	int num1=0,num2=0;
	for(int i=1;i<=n;i++)
	{
		if(v[i]==v[a])
		{
			num1++;
			if(i>=a)
			{
				num2++;
			}
		}
	}
	if(v[1]==v[a])
	{
		for(int i=a;i<=min(num1,b);i++)
		{
			m+=c[num1][i];
		}
	}
	else
	{
		num2--;
		m=c[num1][num2];//cout<<num1<<" "<<num2<<" "<<endl;
	}
	printf("%lf\n%lld",ave,m);
	return 0;

}
/*
8 2 5
1 1 2 2 3 3 3 3

11
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n,k;cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    ll dp[100002];
    for(int i=0;i<100002;i++)dp[i]=10000000000;
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if((i-j)<0)break;
            else
            {
                dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
return 0;
}

Measured memory_bytes: 5192
package main

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

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Scan()
  O := sc.Text()
  sc.Scan()
  E := sc.Text()
  result := make([]byte, len(O)+len(E))
  for i, _ := range result {
    if i % 2 == 0 {
      result[i] = O[i/2]
    } else {
      result[i] = E[i/2]
    }
  }
  fmt.Println(string(result))
}


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

#define ll long long



using namespace std;

const ll MOD = 1000000007;

ll n, m;

ll pwr (ll a, ll b)
{
    if(b == 0)
        return 1;
    if(b & 1)
        return a * pwr(a, (b ^ 1)) % MOD;
    ll p = pwr(a, (b >> 1));
    return p * p % MOD;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    if((n + m) % 3 != 0)
    {
        cout << "0\n";
        return 0;
    }
    ll diag = (n + m) / 3;
    ll pos = 2 * diag - n;
    if(pos < 0 || pos > diag)
    {
        cout << "0\n";
        return 0;
    }
    ll ans = 1;
    for(ll i = (diag - pos + 1); i <= diag; i++)
        ans = ans * i % MOD;
    ll fact = 1;
    for(ll i = 1; i <= pos; i++)
        fact = fact * i % MOD;
    ans = ans * pwr(fact, MOD - 2) % MOD;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int used[10];
string s;
int ans=0;

void rec(int n){
  if(n==s.size()){
    int k=1;
    for(int i=n-1;i>=0;i--){
      ans+=k*(s[i]-'0');
      k*=10;
      if(used[i])k=1;
    }
    return;
  }
  used[n]=1;
  rec(n+1);
  used[n]=0;
  rec(n+1);
}

signed main(){
  cin>>s;
  rec(1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int S,A,B,C;

  scanf("%d",&S);

  A=S/3600;
  B=(S-3600*A)/60;
  C=(S-3600*A-60*B);

  printf("%d:""%d:""%d\n",A,B,C);

  return 0;
}

Measured memory_bytes: 592
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, m := iScan(), iScan()
	a := iSScan(m)
	sort.Ints(a)
	match := map[int]int{1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
	use := make(map[int]int)
	for _, v := range a {
		use[match[v]] = v
	}
	value := make([]int, 0, len(use))
	for k, _ := range use {
		value = append(value, k)
	}
	dp := make([][]int, len(value)+1)
	num := make([][][]int, len(value)+1)
	dp[0] = make([]int, n+1)
	num[0] = make([][]int, n+1)
	for i := 0; i <= n; i++ {
		num[0][i] = make([]int, 9)
	}
	for i := 1; i <= n; i++ {
		dp[0][i] = -mod
	}
	for i := 1; i <= len(value); i++ {
		idx := i - 1
		dp[i] = make([]int, n+1)
		num[i] = make([][]int, n+1)
		for j := 0; j <= n; j++ {
			num[i][j] = make([]int, 9)
		}
		for j := 1; j <= n; j++ {
			dp[i][j] = -mod
		}
		for j := 1; j <= n; j++ {
			if j < value[idx] {
				dp[i][j] = dp[i-1][j]
				copy(num[i][j], num[i-1][j])
			} else {
				p, q := dp[i-1][j], dp[i][j-value[idx]]+1
				if p > q {
					dp[i][j] = p
					copy(num[i][j], num[i-1][j])
				} else if p < q {
					dp[i][j] = q
					copy(num[i][j], num[i][j-value[idx]])
					num[i][j][use[value[idx]]-1]++
				} else {
					f := true
					dp[i][j] = q
					copy(num[i][j], num[i][j-value[idx]])
					num[i][j][use[value[idx]]-1]++
					for z := 8; z >= 0; z-- {
						if num[i-1][j][z] < num[i][j][z] {
							f = false
							break
						} else if num[i-1][j][z] > num[i][j-value[idx]][z] {
							break
						}
					}
					if f {
						dp[i][j] = p
						copy(num[i][j], num[i-1][j])
					}
				}
			}
		}
	}
	for i := 9; i > 0; i-- {
		fmt.Print(strings.Repeat(strconv.Itoa(i), num[len(value)][n][i-1]))
	}
	fmt.Println("")
}


Measured memory_bytes: 9140
n = int(input())
p = [int(x) for x in input().split(' ')]
count = 0
for i in range(1, n-1):
    if p[i] > p[i-1] and p[i] < p[i+1]:
        count += 1
    elif p[i] > p[i+1] and p[i] < p[i-1]:
        count += 1
    else:
        count += 0
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

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

    if (N[0] == N[1] && N[1] == N[2]) {
        cout << "Yes" << endl;
    } else if (N[1] == N[2] && N[2] == N[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

ll n, m;

ll fact(ll x) {
  ll ret = 1;
  for (ll i=1;i<=x;i++) {
    ret = ret * i % MOD;
  }
  return ret;
}

void solve() {
  if (abs(n - m) > 1) {
    cout << 0 << endl;
    return;
  }
  ll factn = fact(n);
  ll factm = fact(m);
  ll ans;
  if (n == m) {
    ans = ((2 * factn) % MOD) * factm % MOD;
  } else {
    ans = factn * factm % MOD;
  }
  cout << ans << endl;
}

int main() {
  cin >> n >> m;
  solve();
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=1;i<n;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) REP(i,v.size())cout<<#v<<"["<<i<<"]: "<<v[i]<<endl
#define ALL(a) (a).begin(),(a).end()

const int INF = 1e9;

const int MAX_R = 30;
const int MAX_C = 30;
const int MAX_V = 900;

int R,C;
int V;

// dijkstra
int cost[MAX_V][MAX_V];
int dist[MAX_V];
bool used[MAX_V];
void dijkstra(int s){
  fill(dist,dist+V,INF);
  fill(used,used+V,false);
  dist[s]=0;
  while(true){
    int v=-1;
    REP(u,V) if(!used[u]&&(v==-1||dist[u]<dist[v])) v=u;
    if(v==-1) break;
    used[v] = true;
    REP(u,V) dist[u] = min(dist[u],dist[v]+cost[v][u]);
  }
}

int mp[MAX_R][MAX_C];
int NONE=0,WALL=1,ALLY=2,ENEMY=3;
int SX,SY,GX,GY;

int main(){
  cin >> R >> C;
  V = R*C;
  REP(i,R){
    string s;
    cin>>s;
    REP(j,C){
      char c = s[j];
      if(c=='.')mp[i][j]=NONE;
      if(c=='#')mp[i][j]=WALL;
      if(c=='o')mp[i][j]=ALLY;
      if(c=='x')mp[i][j]=ENEMY;
      if(c=='S'){
        mp[i][j]=NONE;
        SX=j;SY=i;
      }
      if(c=='G'){
        mp[i][j]=NONE;
        GX=j;GY=i;
      }
    }
  }

  // fill(cost,cost+MAX_V*MAX_V,INF);
  REP(i,MAX_V)REP(j,MAX_V)cost[i][j]=INF;
  int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
  REP(y,R)REP(x,C){
    int now = mp[y][x];
    if(now==WALL)continue;
    if(GY==y&&GX==x)continue;
    REP(d,4){
      int ny=y+dy[d],nx=x+dx[d];
      if(nx<0||ny<0||nx>=C||ny>=R)continue;
      int next = mp[ny][nx];
      if(next==WALL)continue;
      if(next==NONE)cost[y*C+x][ny*C+nx]=2;
      if(next==ALLY)cost[y*C+x][ny*C+nx]=1;
      REP(i,3){
        if(nx<0||ny<0||nx>=C||ny>=R)break;
        next = mp[ny][nx];
        if(next==WALL)break;
        cost[y*C+x][ny*C+nx] = min(cost[y*C+x][ny*C+nx],3+i);
        ny+=dy[d]; nx+=dx[d];
      }
    }
  }
  dijkstra(SY*C+SX);
  cout << dist[GY*C+GX] << endl;
  return 0;
}

Measured memory_bytes: 4380
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;

alias FactorizeResult = ulong[101];

void main() {
    const N = readln.chomp.to!int;

    FactorizeResult table;
    foreach (i; 1..N+1) {
        table[] += primeFactorize(i)[];
    }

    ulong func(ulong i, int r) {
        if (r > 75) return 0;
        if (i == 101) {
            return r == 75 ? 1 : 0;
        }
        ulong result = 0;
        foreach (x; [0,2,4,14,24,74].filter!(y => y <= table[i])) {
            result += memoize!func(i+1,r * (x+1));
        }
        return result;
    }
    writeln(func(0,1));
}

FactorizeResult primeFactorize(int x) {
    if (x == 1) {
        FactorizeResult result;
        return result;
    }
    int y = 2;
    while (true) {
        if (x % y == 0) {
            auto po = memoize!primeFactorize(x/y);
            po[y]++;
            return po;
        } else {
            y++;
        }
    }
}


Measured memory_bytes: 508
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
const ll init = pow(10, 15);
struct edge {int to; ll yen, snuke; };
typedef pair<int, int> P; //firstは最短距離、secondは頂点の番号
typedef pair<ll, int> P2; //firstは最短コスト、secondは頂点の番号(index)
int n; //頂点数
vector<edge> G[100005];
ll d_yen[100005], d_snuke[100005];

//始点sから各頂点への最短経路を求める(yen)
void dijkstra_yen(int s) {
  // greater<P>を指定することでfirstが小さい順に取り出せるようにする
  priority_queue<P, vector<P>, greater<P> >  que;
  fill(d_yen, d_yen + n, init);
  d_yen[s] = 0;
  que.push(P(0, s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if (d_yen[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d_yen[e.to] > d_yen[v] + e.yen) {
        d_yen[e.to] = d_yen[v] + e.yen;
        que.push(P(d_yen[e.to], e.to));
      }
    }
  }
}

//始点sから各頂点への最短経路を求める(snuke)
void dijkstra_snuke(int s) {
  // greater<P>を指定することでfirstが小さい順に取り出せるようにする
  priority_queue<P, vector<P>, greater<P> >  que;
  fill(d_snuke, d_snuke + n, init);
  d_snuke[s] = 0;
  que.push(P(0, s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if (d_snuke[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d_snuke[e.to] > d_snuke[v] + e.snuke) {
        d_snuke[e.to] = d_snuke[v] + e.snuke;
        que.push(P(d_snuke[e.to], e.to));
      }
    }
  }
}

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

  int m,s,t,u,v;
  cin >> n >> m >> s >> t;
  s--, t--;
  ll a,b;
  rep(i, m){
    cin >> u >> v >> a >> b;
    u--,v--;
    edge edge1 = {v, a, b};
    edge edge2 = {u, a, b};
    G[u].push_back(edge1);
    G[v].push_back(edge2); 
  }
  dijkstra_yen(s);
  dijkstra_snuke(t);

  priority_queue<P2, vector<P2>, greater<P2> > que2;
  rep(i, n) que2.push(P2(d_yen[i]+d_snuke[i], i));
  
  rep(i,n){
    P2 ans = que2.top();
    while(i > ans.second){
      que2.pop();
      ans = que2.top();
    }
    cout << init - ans.first << endl;
  }

  return 0;
}

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

using namespace std;

int n;
int a[100];

long long ans = 1000;
long long stock = 0;

int main() {
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);

	for (int i = 1; i < n; i++) {
		long long del = ans / a[i];
		stock += del;
		ans -= del * a[i];
		if (a[i] > a[i + 1]) {
			ans += stock * a[i];
			stock = 0;
		}
	}

	ans += stock * a[n];
	cout <<ans << endl;
	return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int main(){
    map<char,int>count;
    string str;
    while(cin>>str){
        for(int i=0;i<(int)str.size();i++){
            if(isupper(str[i])){
                str[i]=tolower(str[i]);
            }
        }
        for(int i=0;i<(int)str.size();i++){
            count[str[i]]++;
        }
    }
    for(char ch='a';ch<='z';ch++){
        cout<<ch<<" : "<<count[ch]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3128
b,e = map(int, input().split())

r = [0] * 1000
for _ in range(int(input())):
    b1, e2 = map(int, input().split())
    for x in range(b1, e2):
        r[x] = 1

def check():
    for x in range(b, e):
        if r[x] == 1:
            return 1
    return 0

print(check())



Measured memory_bytes: 5600
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) :x((x% mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

mint comb(ll n, ll a) {
  mint x = 1, y = 1;
  for (ll i = 0; i < a; i++) {
    x *= (i + 1);
    y *= (n - i);
  }
  return y / x;
}

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

  if (m == 1) {
    ll ans = k >= n - 1 ? 1 : 0;
    cout << ans << endl;
  }
  else {
    mint nn(n), mm(m), kk(k);
    mint el1(1);
    mint el2(m);
    mint el3 = mint(m - 1).pow(n - 1);
    mint ans = el1 * el2 * el3;
    for (ll i = 1; i <= k; i++) {
      el1 *= (n - i);
      el1 /= i;
      el3 /= (m - 1);
      ans += el1 * el2 * el3;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3632
// 2016-12-08
#include <iostream>
using namespace std;

int main() {
	int n, m, p, k, l;
	bool a[100], b[100][100];
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				b[i][j] = false;
			}
			a[i] = true;
		}
		for (int i = 0; i < n; i++) {
			cin >> m;
			for (int j = 0; j < m; j++) {
				cin >> p;
				b[i][p - 1] = true;
			}
		}
		cin >> k;
		for (int i = 0; i < k; i ++) {
			cin >> l;
			for (int j = 0; j < n; j++) {
				a[j] &= b[j][l - 1];
			}
		}
		int r, c = 0;
		for (int i = 0; i < n; i++) {
			if (a[i]) {
				r = i + 1;
				c++;
			}
		}
		if (c != 1) {
			r = -1;
		}
		cout << r << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		while(true){
			int sum=0;
			int ave=0;
			int n=scan.nextInt();
			if(n==0){
				break;
			}
			int[] s = new int[n];
			for(int i = 0;i < n;i++){
				s[i]=scan.nextInt();
			}
			Arrays.sort(s);
			for(int i=1;i<n-1;i++){
				sum+=s[i];
			}
			ave=sum/(n-2);
			System.out.println(ave);
		}
	}
}



Measured memory_bytes: 29340
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
using namespace std;
typedef long long LL;

int main() {
    LL a, b, c, ans = 0;
    cin >> a >> b;
    c = b - a;
    for (int i = 0; i < c; i++) {
        ans += i;
    }
    cout << ans - a << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
  int a1,a2,a3,a4,b1,b2,b3,b4;
  while(scanf("%d %d %d %d",&a1,&a2,&a3,&a4)>0){
    scanf("%d %d %d %d",&b1,&b2,&b3,&b4);
    int h=0,b=0;
    if(b1==a1) h++;
    if(b1==a2||b1==a3||b1==a4) b++;
    if(b2==a2) h++;
    if(b2==a1||b2==a3||b2==a4) b++;
    if(b3==a3) h++;
    if(b3==a1||b3==a2||b3==a4) b++;
    if(b4==a4) h++;
    if(b4==a1||b4==a2||b4==a3) b++;
    printf("%d %d\n",h,b);
  }
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define sd(x) scanf("%d",&x)
#define sdl(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define pdl(x) printf("%lld\n",x)
#define MAXN 200009
using namespace std;
int main()
{
	ll a,b,c,x,y;
	sdl(a);
	sdl(b);
	sdl(c);
	sdl(x);
	sdl(y);
	if(2*c<a+b)
	{
		ll ans=min(x,y)*c*2ll;
		ll temp=min(x,y);
		x=x-temp;
		y=y-temp;
		if(x)
		{
			if(2*c<a)
			{
				ans=ans+(x*c*2ll);
			}
			else
			{
				ans=ans+(x*a);
			}
		}
		if(y)
		{
			if(2*c<b)
			{
				ans=ans+(y*2ll*c);
			}
			else
			{
				ans=ans+(y*b);
			}
		}
		pdl(ans);
	}
	else
	{
		ll ans=x*a+y*b;
		pdl(ans);
	}
	return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
ok = False
if x == 4 or x == 6 or x == 9 or x == 11:
    if y == 4 or y == 6 or y == 9 or y == 11: ok = True
elif x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10 or x == 12:
    if y == 1 or y == 3 or y == 5 or y == 7 or y == 8 or y == 10 or y == 12: ok = True
if ok: print('Yes')
else: print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;



int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
    rep(i,n) cin>>a[i];
	vector<ll> b = a;
	sort(b.begin(), b.end());
	ll l = b[n / 2 - 1], r = b[n / 2];
	rep(i, n) {
		if (a[i] <= l) cout << r << endl;
		else cout << l << endl;
	}
}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int d[251];

int main(){
    int h;
    cin >> h;
    for(int i = 0; i < h; i++){
        cin >> d[i];
    }
    for(int i = 0; i < h; i++){
        printf("node %d: key = %d, ", i + 1, d[i]);
        if(i > 0) printf("parent key = %d, ", d[(i - 1) / 2]);
        if(2 * i + 1 < h) printf("left key = %d, ", d[(2 * i + 1)]);
        if(2 * i + 2 < h) printf("right key = %d, ", d[(2 * i + 2)]);
        printf("\n");
    }
}

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

int main(){
  int n,d,x;
  int count=0;
  cin >> n >> d >> x;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    for(int j=1;j<d;j++){
      if(a[i]*j+1<=d){
        count++;
      }
    }
  }
  cout << count+n+x << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

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

typedef long long ll;
typedef vector<vector<int>> Graph;

int main() {
	//入力;
	int N;
	cin >> N;
	vector<int> P(N), Q(N),R(N);
	REP(i, N) { cin >> P[i]; }
	REP(i, N) { cin >> Q[i]; }
	REP(i, N) { R[i] = i + 1; }

	int counter = 1;
	int pcount, qcount;
	do {
		if (R == P) {
			pcount = counter;
		}
		if (R == Q) {
			qcount = counter;
		}
		counter++;
	} while (next_permutation(R.begin(), R.end()));

	cout << abs(pcount - qcount) << endl;
	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

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

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

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

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

const ll INF = 1LL << 60;

int N, W;

string s, t;
int dp[3010][3010];

int main() {
  cin >> s >> t;
  memset(dp, 0, sizeof(dp));

  for (int i = 0; i < s.size(); ++i) {
    for (int j = 0; j < t.size(); ++j) {
      if (s[i] == t[j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
    }
  }
  //  cout << dp[s.size()][t.size()] << endl;

  // 復元
  string res = "";
  int i = (int)s.size(), j = (int)t.size();
  while (i > 0 && j > 0) {
    // (i-1, j) -> (i, j) と更新されていた場合
    if (dp[i][j] == dp[i - 1][j]) {
      --i;  // DP の遷移を遡る
    }

    // (i, j-1) -> (i, j) と更新されていた場合
    else if (dp[i][j] == dp[i][j - 1]) {
      --j;  // DP の遷移を遡る
    }

    // (i-1, j-1) -> (i, j) と更新されていた場合
    else {
      res = s[i - 1] + res;  // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
      --i, --j;  // DP の遷移を遡る
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 35712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
   public static void main(String[] args)  {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            br.readLine();
            String[] split = br.readLine().split(" ");
            int n = split.length;
            double[] prob = new double[n];
            for (int i = 0; i < n; i++) {
               prob[i] = Double.parseDouble(split[i]); 
            }
            double[] dp = new double[n + 1];
            dp[0] = 1.0;
            for (int i = 1; i <= n; i++) {
                for (int j = n; j >= 0; j--) {
                    double p = 0.0;
                    if (j == 0) {
                        p += dp[j]*(1 - prob[i - 1]);
                    } else {
                        p += dp[j - 1]*prob[i - 1] + dp[j]*(1 - prob[i - 1]);
                    }
                    dp[j] = p;
                }
            }
            double result = 0.0;
            for (int i = (n + 1) / 2 ; i <= n; i++) {
                result += dp[i];
            }
            /*for(double[] row: dp) {
                for (Double d: row) {
                    System.out.print(String.format("%.2f ", d == null ? 0.0 : d));
                }
                System.out.println();
            }*/
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 24788
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    int x[27];
    int y[27];
    int ans=0;
    for(int i=1;i<n;i++){
        int tmp=0;
        memset(x,0,sizeof x);
        memset(y,0,sizeof y);
        for(int j=0;j<i;j++)x[(s[j]-'a')]++;
        for(int j=i;j<n;j++)y[(s[j]-'a')]++;
        for(int j=0;j<26;j++)if(x[j]>0 && y[j]>0)tmp++;
        ans=max(ans,tmp);
    }
    cout << ans << endl;
}

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

int main(){
    long a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    long ah;
    long long ak;
    if(d>e){
        ah=d;
        ak=((2*e)*c)+((d-e)*a);
    }
    else{
        ah=e;
        ak=((2*d)*c)+((e-d)*b);
    }
    long val=(c)*(2*ah);
    long long val1=(d*a)+(b*e);
    if(ak<=val&&ak<=val1) cout<<ak<<endl;
    else if(val<=val1&&val<=ak) cout<<val<<endl;
    else cout<<val1<<endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use proconio::{input, fastout};
use proconio::marker::{Chars, Bytes, Usize1};

#[fastout]
fn main() {
    input!{
        n:String
    }
    let res = n.chars().fold(0, |res, x| (res + x.to_digit(10).unwrap()) % 9);
    println!("{}", if res > 0 { "No" } else { "Yes" });
}


Measured memory_bytes: 2344
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int s;
    cin >> s;
    vector<int> a;
    for (int i = 0; i < 1000000; i++)
    {
        if (i == 0)
        {
            a.push_back(s);
        }
        else
        {
            if (a[i-1] % 2 == 0)
            {
                a.push_back(a[i - 1] / 2);
            }
            else
            {
                a.push_back(3 * a[i - 1] + 1);
            }
            for (int j = 0; j < i; j++)
            {
                if (a[j] == a[i])
                {
                    cout << i+1 << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int r;

  cin >> r;

  cout << r * r << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, r;
  cin >> a >> b >> c >> d;

  r = a + b - (c + d);
  if (r > 0) {
    cout << "Left" << endl;
  } else if (r == 0) {
    cout << "Balanced" << endl;
  } else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner f = new Scanner(System.in);
        // fill in the dictionary with the initial value
        String base = f.nextLine();
        int mods = Integer.parseInt(f.nextLine());
        for(int mod = 0; mod < mods; mod++){
            String[] parts = f.nextLine().split(" ");
            String command = parts[0];
            if(command.equals("replace")){
                base = base.substring(0,Integer.parseInt(parts[1])) + parts[3] +  base.substring(Integer.parseInt(parts[2])+1);
            } else if(command.equals("reverse")) {
                String temp = base.substring(Integer.parseInt(parts[1]),Integer.parseInt(parts[2])+1);
                base = base.substring(0,Integer.parseInt(parts[1])) + reverse(temp) +  base.substring(Integer.parseInt(parts[2])+1);
            } else if(command.equals("print")) {
                System.out.println(base.substring(Integer.parseInt(parts[1]),Integer.parseInt(parts[2])+1));
            }
        }
    }
    public static String reverse(String part){
        StringBuilder newStr = new StringBuilder();
        for(int i = part.length()-1; i >= 0; i--){
            newStr.append(String.valueOf(part.charAt(i)));
        }
        return newStr.toString();
    }
}


Measured memory_bytes: 30000
#include <iostream>

using namespace std;

int main(void) {
  int i, j, min, tmp, L, R;
  int _i, _j;
  cin >> L;
  cin >> R;
  min = 2018;
  for(i = L; i < R; i++) {
    _i = i % 2019;
    for(j = i + 1; j <= R; j++) {
      _j = j % 2019;
      tmp = _i*_j % 2019;
      if(min > tmp) {
        min = tmp;
        if(min == 0) break;
      }
    }
    if(min == 0) break;
  }
  cout << min << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 100010
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}
struct Edge{
	int u, v, Next;
} G[M * 2];
int head[M], tot;
inline void add(int u, int v) {
	G[++ tot] = (Edge){u, v, head[u]};
	head[u] = tot;
}
int n;
int Fa[M], d[M];
inline int dfs(int x, int fa) {
	Fa[x] = fa; d[x] = d[fa] + 1;
	int ret = x;
	for(int i = head[x]; i != -1; i = G[i].Next) {
		if(G[i].v == fa) continue;
		int v = dfs(G[i].v, x);
		if(d[v] > d[ret]) ret = v;
	}
	return ret;
}
bool is_[M]; 
int a[M], tt;
int cnt[M];
inline vector<int> Solve() {
	int now = 0;
	vector<int> ret;
	ret.resize(n);
	for(int i = 1; i <= tt; ++ i) {
		for(int j = 1; j < a[i]; ++ j) {
			ret[now + j - 1] = now + j + 1;
		}
		ret[now + a[i] - 1] = now + 1;
		now += a[i];
	} 
	return ret;
}
int main() {
//	freopen("a.in", "r", stdin);
	memset(head, -1, sizeof(head));
	n = read();
	for(int i = 1; i < n; ++ i) {
		int u = read(), v = read();
		add(u, v); add(v, u);
	}
	int s = dfs(1, 0);
	int t = dfs(s, 0);
//	cerr << s << " " << t << endl;
	for(int i = t; i != 0; i = Fa[i]) {
		is_[i] = 1;
	}
	for(int i = 1; i <= n; ++ i) {
		if(!is_[i] && !is_[Fa[i]]) {
			return puts("-1"), 0;
		}
		if(!is_[i]) cnt[Fa[i]] ++;
	}
	for(int i = t; i != 0; i = Fa[i]) {
		a[++ tt] = cnt[i] + 1;
	}
	vector<int> A1 = Solve();
	for(int i = 1; i <= tt / 2; ++ i) {
		swap(a[i], a[tt - i + 1]);
	}
	vector<int> A2 = Solve();
	for(int i = 0; i < A1.size(); ++ i) {
		if(A1[i] < A2[i]) {
			for(int j = 0; j < A1.size(); ++ j) {
				printf("%d ", A1[j]);
			}
			return 0;
		}
		if(A1[i] > A2[i]) {
			for(int j = 0; j < A2.size(); ++ j) {
				printf("%d ", A2[j]);
			}
			return 0;
		}
	}
	for(int j = 0; j < A1.size(); ++ j) {
		printf("%d ", A1[j]);
	}
}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	int n;
	LL T;
	cin >> n >> T;
	LL t[n];
	LL ans = 0;
	cin >> t[0];
	for (int i = 1; i < n; i++) {
		cin >> t[i];
		if (t[i] - t[i-1] >= T) {
			ans += T;
		}
		else {
			ans += t[i] - t[i-1];
		}
	}

	ans += T;


	cout << ans << endl;

	return 0;
}



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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{

    lint n, p;
    cin >> n >> p;
    lint p2 = p;

    lint ans=1, tmp;
    vector <lint > v(1000000);
    
    if(n==1){
        cout << p << "\n";
        return 0;
    }

    for (lint i = 2; i * i < p2;)
    {
        if(p%i==0){
            p =p/i;
            v[i] += 1;
            //cout << i << v[i] << "\n";
        }else{
            i++;
        }
    }
    
    for (lint i = 2; i * i < p2;i++){
        //cout << v[i] << "\n";
        lint c = v[i] / n;
        if(c>0){
            REP(j,c)ans *= i;
        }
    }


    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

vector<ll> enum_div(int n){
	vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i){
			if(n%i == 0){
				ret.push_back(i);
				ret.push_back(n/i);
			}
	}
	return ret;
}


int main(){
	ll N,ans=0;
	cin >> N;
	vector<ll> a(N);
	FOR(i,0,N)cin>>a[i];
	SORT(a);
	FOR(i,0,2){
		for(auto y:enum_div(a[i])){
			ll k = 0;
			FOR(j,0,N){
				if(a[j]%y==0)k++;
			}
			if(k>=N-1){
				ans = max(ans,y);
			}
		}
	}
	cout << ans << endl;
}

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

int n;
int d[100], a[100];

map<vector<int>, int> conv;
int state(vector<int> v){
	int t = *min_element(begin(v), end(v));
	for (int i = 0; i < 7; i++){
		v[i] -= t;
	}
	return conv[v];
}

int dp[100][5040];
int calc(int p, vector<int> v){
	if (p == n) return 0;
	if (p >= 7 && ~dp[p][state(v)]) return dp[p][state(v)];
	int res = 0;
	for (int i = 0; i <= v.size(); i++){
		int add = 0;
		for (int j = 0; j < v.size(); j++){
			if (j < i && p - v[j] <= d[v[j]]) add += a[v[j]];
			if (j >= i && p - v[j] <= d[p]) add += a[p];
		}
		vector<int> v2 = v;
		v2.insert(begin(v2) + i, p);
		if (v2.size() > 7) v2.erase(find(begin(v2), end(v2), p - 7));
		res = max(res, add + calc(p + 1, v2));
	}
	if (p >= 7) dp[p][state(v)] = res;
	return res;
}

int main()
{
	vector<int> v(7);
	iota(begin(v), end(v), 0);
	int t = 0;
	do {
		conv[v] = t++;
	} while (next_permutation(begin(v), end(v)));

	cin >> n;
	for (int i = 0; i < n; i++) cin >> d[i];
	for (int i = 0; i < n; i++) cin >> a[i];

	memset(dp, -1, sizeof(dp));
	cout << calc(0, vector<int>()) << endl;
}

Measured memory_bytes: 5744
C = [list(map(int, input().split())) for _ in range(3)]

A = [0] * (3)
B = [0] * (3)

for i in range(3):
  B[i] = C[0][i] - A[0]
A[1] = C[1][0] - B[0]
A[2] = C[2][0] - B[0]

for i in range(3):
  for j in range(3):
    if C[i][j] != A[i] + B[j]:
      print('No')
      exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N = 0;
  cin >> N;

  int sum = 0;
  for (int i = 0; i < N; i++) {
    int l=0,r=0;
    cin >> l >> r;
    sum += r - l + 1;
  }

  cout << sum << endl;
}

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

long long a[2 * 100000 + 100];
long long b[2 * 100000 + 100];
long n;

long calcIndex(long ind, long n){
  if(n%2 == 0){
    long center = n/2;
    if(ind == center){
      return 0;
    }else if(ind > center){
      return (ind-center)*2;
    }else{
      return (center-ind)*2-1;
    }
  }else{
    long center = n/2;
    if(ind == center){
      return 0;
    }else if(ind > center){
      return (ind-center)*2-1;
    }else{
      return (center-ind)*2;
    }
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }

  for(long i=0;i<n;i++){
    b[i] = a[calcIndex(i,n)];
  }

  for(long i=0;i<n;i++){
    cout << b[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 5248
N=int(input())
X=list(map(int,input().split()))

# Xをソート(Xsort)
# 除く数字が中央より左の場合、答えは中央右(r)の数字
# 逆も然り
Xsort=sorted(X)
l=(N-1)//2
r=l+1
th=Xsort[l]
for i in range(N):
    if X[i]<=th:
        ans=Xsort[r]
    else:
        ans=Xsort[l]
    print(ans)

Measured memory_bytes: 26772
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int x; cin>>x;
    cout<<(!x)<<"\n"; 
    return 0;
}

Measured memory_bytes: 3668
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

int C, R;

int solve(int idx, vector<vector<int> > a)
{
  if (idx >= C) {
    int ret = 0;
    for (int i = 0; i < R; ++i) {
      int cnt = 0;
      for (int j = 0; j < C; ++j) {
	if (a[j][i])
	  ++cnt;
      }
      ret += max(cnt, C-cnt);
    }
    return ret;
  }

  int ret = solve(idx+1, a);
  for (int i = 0; i < R; ++i)
    a[idx][i] ^= 1;
  return max(ret, solve(idx+1, a));
}

int main()
{
  while (~scanf("%d %d", &C, &R)) {
    if ((C|R) == 0)
      break;

    vector<vector<int> > a(C, vector<int>(R));
    for (int i = 0; i < C; ++i) {
      for (int j = 0; j < R; ++j)
	scanf("%d", &a[i][j]);
    }

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

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

int main() {
	int m;
	cin >> m;
	ll k = 0, s = 0;
	rep(i, m) {
		ll d, c;
		cin >> d >> c;
		k += c;
		s += d * c;
	}
	cout << (k - 1) + (s - 1) / 9 << endl;
	return 0;
}

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

int main() {
	int n, x;
	while(1){
		cin >> n >> x;
		if(n==0 && x==0) break;
		int count = 0;
		for(int i=1; i<=n; i++){
			for(int j=i; j<=n; j++){
				for(int k=j; k<=n; k++){
					if(i+j+k==x && i!=j && j!=k && k!=i)
					count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}


Measured memory_bytes: 3096