akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

int n;

int dfs(int parent, int node, vector<vector<int>>& line, vector<vector<int>>& v){
    int childsum = 0;

    if (parent != -1  && line[node].size() == 1) {
        v[node].push_back(n - childsum - 1);
        return 1;
    }
    for(auto next: line[node]){
        if (next == parent) continue;
        int score = dfs(node, next, line, v);
        childsum += score;
        v[node].push_back(score);
    }
    v[node].push_back(n - childsum - 1);
    return childsum + 1;
}


mint calprob(int e, int n){
    mint m1(2), m2(2), m3(2);
    return (m1.pow(e) - (mint)1) * (m1.pow(n-e) - (mint)1);  
}

int main()
{
    cin >> n;
    vector<vector<int>> line(n);
    rep(i, n-1){
        int tmpa, tmpb;
        cin >> tmpa >> tmpb;
        tmpa--; tmpb--;
        line[tmpa].push_back(tmpb);
        line[tmpb].push_back(tmpa);    
    }

    //各頂点の個数を格納
    vector<vector<int>> v(n);
    dfs(-1, 0, line, v);

    mint ans(0);
    mint two(2);
    rep(i, n){
      mint pat(0);
      pat += two.pow(n-1); //自分が白のパターン
      pat -= 1; //全て白のパターン
      for(auto e: v[i]){
        pat -= two.pow(e) - 1;
      }
      //cout << i << ":"<< pat.x << endl;
      ans += pat;
    }
    ans /= two.pow(n);
    cout << ans.x << endl;
}



Measured memory_bytes: 37760
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF=1e18;
int n;
ll a[5001];
vector<int> g[5001];
vector<ll> dp[2][5001];
int dp2[5001];
//int ans[5001];
bool used[5001];
int ct[5001];
ll sum[5001];
void dfs(int x){
	used[x]=1;
	vector<int> c;
	ct[x]=1;
	sum[x]=a[x];
	for(auto y:g[x]){
		if(used[y]){
			continue;
		}
		dfs(y);
		ct[x]+=ct[y];
		sum[x]+=sum[y];
		c.push_back(y);
	}
	for(int i=0; i<=ct[x]; i++) dp[0][x].push_back(INF), dp[1][x].push_back(INF);
	dp[0][x][1]=a[x];
	int ct0=1;
	for(auto y:c){
		//dp[1][x].clear();
		for(int i=0; i<=ct0+ct[y]; i++) dp[1][x][i]=INF;
		for(int i=ct0; i>=1; i--){
			for(int j=1; j<=ct[y]; j++){
				dp[1][x][i+j-1]=min(dp[1][x][i+j-1], dp[0][x][i]+dp[0][y][j]);
				if(dp[0][y][j]<0) dp[1][x][i+j]=min(dp[1][x][i+j], dp[0][x][i]);
			}
			if(a[y]>0) dp[1][x][i+dp2[y]]=min(dp[0][x][i], dp[1][x][i+dp2[y]]);
		}
		ct0+=ct[y];
		for(int i=0; i<=ct0; i++) dp[0][x][i]=dp[1][x][i];
	}
	if(a[x]>0){
		dp2[x]=1;
		for(auto y:c){
			if(a[y]<0){
				for(int j=1; j<=ct[y]; j++){
					if(dp[0][y][j]<0){
						dp2[x]+=j;
						break;
					}
				}
			}else{
				int j1=n+1;
				for(int j=1; j<=ct[y]; j++){
					if(dp[0][y][j]<0){
						j1=j;
						break;
					}
				}
				dp2[x]+=min(j1, dp2[y]-1);
			}
		}
	}
}

int main()
{
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=0; i<n-1; i++){
		int u, v; cin>>u>>v;
		u--; v--;
		g[u].push_back(v); g[v].push_back(u);
	}
	dfs(0);
	int ans=n;
	for(int i=1; i<=n; i++){
		if(dp[0][0][i]<0){
          //cout<<dp[0][0][i]<<endl;
          //cout<<i<<endl;
			ans=min(ans, i);
			break;
		}
	}
	if(a[0]>0) ans=min(ans, dp2[0]);
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 191616
#y,m,d=map(int,input().split())
#a,b=map(int,input().split())
n=int(input())
#a=int(input())
#b=int(input())
#s=list(input())
#T=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
#b=list(map(int,input().split()))
#b=list(map(int,input().split()))
#a=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#a=[list(input().split())for _ in range(n)]
a=[int(input())for _ in range(n)]
ans=0
total=0
judge=False
for i in range(n):
    total+=a[i]
    if a[i]==0:
        ans+=total//2
        total=0
        judge=True
if judge:
    print(ans+total//2)
else:
    print(sum(a)//2)



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

namespace arc083_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (x[2] < x[3])
            {
                int a = x[2];
                x[2] = x[3]; x[3] = a;
            }
            double maxparcent = -1;
            double maxwater = 0;
            double maxsugar = 0;
            for (int i = 0; i <= 30 / x[0]; i++)
            {
                for (int j = 0; j <= 30 / x[1]; j++)
                {
                    for (int k = 0; k < x[3]; k++)
                    {
                        for (int l = 0; l < 1000 / x[3]; l++)
                        {
                            double nowwater = (x[0] * i + x[1] * j) * 100;
                            double nowsugar = x[2] * k + x[3] * l;
                            if (!(i == 0 && j == 0))
                            {
                                if (nowwater * x[4] / 100 >= nowsugar && nowsugar + nowwater <= x[5])
                                {
                                    if (maxparcent < nowsugar / (nowsugar + nowwater))
                                    {
                                        maxparcent = nowsugar / (nowsugar + nowwater);
                                        maxsugar = nowsugar;
                                        maxwater = nowwater + nowsugar;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Console.WriteLine(maxwater + " " + maxsugar);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(long long int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL << 60);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    fill((T*)array, (T*)(array + N), val);
}
int main() {
    ll a,b,c, k,sum = 0; cin >> a >> b >> c >> k;
    if (k <= a) cout << k << endl;
    else if (a + b >= k) cout << a << endl;
    else cout << a - (k - (a + b)) << endl;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 5005
#define MO 1000000007
#define LL long long
char s[MAXN];
LL dp[MAXN][MAXN];
LL qsm(LL a,LL b)
{
	LL ret=1;
	while(b)
	{
		if(b&1) ret=ret*a%MO;
		a=a*a%MO;
		b>>=1;
	}
	return ret;
}
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",s);
	int len=strlen(s);
	LL inv=qsm(2,MO-2);
	inv=qsm(inv,len);
	dp[0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<=i;j++)
			if(dp[i][j]!=0)
			{
				dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j]*2%MO)%MO;
				if(j==0) dp[i+1][0]=(dp[i+1][0]+dp[i][j])%MO;
				else dp[i+1][j-1]=(dp[i+1][j-1]+dp[i][j])%MO;
			}
	printf("%lld\n",dp[n][len]*inv%MO);
}

Measured memory_bytes: 193920
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		int count =　0;
		for(var i=0;i<3;i++){
			if(str.Substring(i,1) == "1"){
				count += 1;
			}
		}
		Console.WriteLine(count);
	}
}

Measured memory_bytes: 13140
#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 N;
  cin >> N;
  int d1, d2;
  int tmp = 0;
  int cnt = 0;
  rep(i, N) {
    cin >> d1 >> d2;
    if (d1 == d2) {
      tmp++;
    } else {
      cnt = max(cnt, tmp);
      tmp = 0;
    }
  }
  cnt = max(cnt, tmp);
  string ans = cnt < 3 ? "No" : "Yes";
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint1() {
	int A = 0;
	int pn = 1;
	if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
	A = ct - '0';
	while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
	return pn * A;
}
inline int getint2() {
	int A = 0;
	int pn = 1;
	if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
	A = ct - '0';
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
	return pn * A;
}

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


	int N = getint1();
	int RR = -1e9;
	int RL = -1e9;
	int RUD = -1e9;
	int LR = 1e9;
	int LL = 1e9;
	int LUD = 1e9;
	int UU = -1e9;
	int UD = -1e9;
	int URL = -1e9;
	int DU = 1e9;
	int DD = 1e9;
	int DRL = 1e9;

	rep(i, N) {
		int x, y;
		char d;

		if (ci - cn + 28 > cm) {
			x = getint1();
			y = getint1();
			d = getcha();
			getcha();
		}
		else {
			x = getint2();
			y = getint2();
			d = *ci++;
			ci++;
		}

		if (d == 'R') {
			RR = max(RR, x);
			LR = min(LR, x);
			URL = max(URL, y);
			DRL = min(DRL, y);
		}
		else if (d == 'L') {
			RL = max(RL, x);
			LL = min(LL, x);
			URL = max(URL, y);
			DRL = min(DRL, y);
		}
		else if (d == 'U') {
			RUD = max(RUD, x);
			LUD = min(LUD, x);
			UU = max(UU, y);
			DU = min(DU, y);
		}
		else {
			RUD = max(RUD, x);
			LUD = min(LUD, x);
			UD = max(UD, y);
			DD = min(DD, y);
		}
	}

	vector<double> kouho;
	kouho.pb(0);
	kouho.pb(0.5 * (RL - RR));
	kouho.pb(0.5 * (LL - LR));
	kouho.pb(RUD - RR);
	kouho.pb(LUD - LR);
	kouho.pb(RL - RUD);
	kouho.pb(LL - LUD);
	kouho.pb(0.5 * (UD - UU));
	kouho.pb(0.5 * (DD - DU));
	kouho.pb(URL - UU);
	kouho.pb(DRL - DU);
	kouho.pb(UD - URL);
	kouho.pb(DD - DRL);

	double saishou = 1e20;
	for (double D : kouho) {
		if (D >= 0) {
			double Xmax = max({ RR + D, RL - D, (double)RUD });
			double Xmin = min({ LR + D, LL - D, (double)LUD });

			double Ymax = max({ UU + D, UD - D, (double)URL });
			double Ymin = min({ DU + D, DD - D, (double)DRL });

			saishou = min(saishou, (Xmax - Xmin) * (Ymax - Ymin));
		}
	}
	
	cout << fixed << setprecision(12) << saishou << endl;

	Would you please return 0;
}

Measured memory_bytes: 384
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N;
    string S;
    scan(N);
    scan(S);

    auto rh = RollingHash(S);

    int ans;

    foreach (i ; 0 .. N) {
        foreach (j ; i .. N) {
            while (ans < j - i && j + ans < N && 
                rh.slice(i, i + ans + 1) == rh.slice(j, j + ans + 1)) ans++;
        }
    }

    writeln(ans);
}


struct RollingHash {
    enum MAX_LENGTH = 500000;
    enum ulong MASK30 = (1UL << 30) - 1;
    enum ulong MASK31 = (1UL << 31) - 1;
    enum ulong MOD = (1UL << 61) - 1;
    enum ulong POSITIVIZER = MOD * ((1UL << 3) - 1);
    uint base;
    ulong[] basePow = new ulong[](MAX_LENGTH + 1);
    ulong[] hash;

    this(string s) {
        auto rnd = Random(unpredictableSeed);
        base = uniform(129, int.max, rnd).to!uint;
        basePow[0] = 1;
        foreach (i ; 1 .. MAX_LENGTH + 1) {
            basePow[i] = calcMod(mul(basePow[i - 1], base));
        }

        hash = new ulong[](s.length + 1);
        foreach (i ; 0 .. s.length) {
            hash[i + 1] = calcMod(mul(hash[i], base) + s[i]);
        }
    }

    // hash(s[begin .. end])
    ulong slice(int begin, int end) {
        return calcMod(hash[end] + POSITIVIZER - mul(hash[begin], basePow[end - begin]));
    }

    ulong mul(ulong l, ulong r) {
        auto lu = l >> 31;
        auto ld = l & MASK31;
        auto ru = r >> 31;
        auto rd = r & MASK31;
        auto middleBit = ld * ru + lu * rd;
        return ((lu * ru) << 1) + ld * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30);
    }

    ulong mul(ulong l, uint r) {
        auto lu = l >> 31;
        auto rd = r & MASK31;
        auto middleBit = lu * rd;
        return (l & MASK31) * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30);
    }

    ulong calcMod(ulong val) {
        val = (val & MOD) + (val >> 61);
        if (val >= MOD) val -= MOD;
        return val;
    }
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 6268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e4 + 10;
const int maxv = 1e6 + 10;
const ll mod = 1e9 + 7;
int a[maxn], tot[maxv];
ll ans;
ll inv[maxv];
ll powMod(ll a, int k)
{
	ll ret = 1;
	while(k)
	{
		if(k & 1) ret = ret * a % mod;
		a = a * a % mod; k >>= 1;
	}
	return ret;
}
int main()
{
	inv[1] = 1;
	for(int i = 2; i < maxv; ++i)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d", &a[i]);
		int x = a[i];
		for(int j = 2; j * j <= x; ++j)
			if(x % j == 0)
			{
				int cnt = 0;
				while(x % j == 0)
					x /= j, ++cnt;
				tot[j] = max(tot[j], cnt);
			}
		if(x > 1)
			tot[x] = max(tot[x], 1);
	}
	ll lcm = 1;
	for(int i = 2; i < maxv; ++i)
		if(tot[i])
			lcm = lcm * powMod(i, tot[i]) % mod;
	for(int i = 1; i <= n; ++i)
	{
		ll tmp = lcm;
		int x = a[i];
		for(int j = 2; j * j <= x; ++j)
			if(x % j == 0)
			{
				int cnt = 0;
				while(x % j == 0)
					x /= j, ++cnt;
				tmp = tmp * powMod(inv[j], cnt) % mod;
			}
		if(x > 1)
			tmp = tmp * inv[x] % mod; 
		ans = (ans + tmp) % mod;
	}
	printf("%I64d\n", ans);
	return 0;
}
		

Measured memory_bytes: 11136
local n = io.read("*n", "*l")
local s = io.read()
local t = {}
for i = 1, n do
  t[i] = s:sub(i, i) == "o"
end
local a = {}
for ia = 1, 4 do
  a[1] = ia % 2 == 1
  a[2] = 2 < ia
  for i = 2, n do
    if t[i] then
      if a[i] then
        a[i + 1] = a[i - 1]
      else
        a[i + 1] = not a[i - 1]
      end
    else
      if a[i] then
        a[i + 1] = not a[i - 1]
      else
        a[i + 1] = a[i - 1]
      end
    end
  end
  if a[1] == a[n + 1] then
    local v = true
    if t[1] then
      if a[1] then
        v = a[2] == a[n]
      else
        v = a[2] ~= a[n]
      end
    else
      if a[1] then
        v = a[2] ~= a[n]
      else
        v = a[2] == a[n]
      end
    end
    if v then
      for i = 1, n do
        io.write(a[i] and "S" or "W")
      end
      io.write("\n")
      os.exit()
    end
  end
end
print(-1)


Measured memory_bytes: 4896
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var w string
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &w)

	var b bool
	for i := 0; i < len(w); i++ {
		if strings.Count(w, string(w[i]))%2 == 1 {
			b = true
		}
	}
	if b {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}


Measured memory_bytes: 1848
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int a[100010], b[100010], c[100010];
int dp[3][100010];
int main()
{
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < N; j++) {
			dp[i][j] = -1;
		}
	}
	dp[0][0] = a[0];
	dp[1][0] = b[0];
	dp[2][0] = c[0];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			if (j == 0) {
				dp[j][i + 1] = max(dp[1][i] + a[i + 1], dp[2][i] + a[i + 1]);
			}
			else if (j == 1) {
				dp[j][i + 1] = max(dp[0][i] + b[i + 1], dp[2][i] + b[i + 1]);
			}
			else {
				dp[j][i + 1] = max(dp[0][i] + c[i + 1], dp[1][i] + c[i + 1]);
			}
		}
	}
	cout << max({ dp[0][N],dp[1][N],dp[2][N] }) << endl;
}

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

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var abc = "abcdefghijklmnopqrstuvwxyz";

            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            // 文字列の入力
            string s = Console.ReadLine();

            var max = 0;

            for(int i = 1; i < s.Length; i++) {
                var s1 = s.Substring(0, i);
                var s2 = s.Substring(i);

                var count = 0;

                foreach(var c in abc) {
                    if(s1.Contains(c) && s2.Contains(c)) {
                        count++;
                    }
                }

                if(count > max) {
                    max = count;
                }
            }

            Console.WriteLine(max);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int compare(const void *a, const void *b){
  return *(int *)a-*(int *)b;
}

int main(void){
  int n,i,j,w=0,k=0,number;
  int num[10000];
  int ans[100];
  scanf("%d",&n);

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

  qsort(num,n,sizeof(int),compare);

  if(n==3){
    printf("%d",num[1]);
    printf("%d\n",num[0]);
  }
  else{
    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
        if(i!=j){
          int bas=1;
          number = num[j];
          while(number!=0){
            number = number / 10;
            ++k;
          }
          while(k!=0){
            bas *=10 ;
            --k;
          }
          ans[w]=num[i]*bas+num[j];
          w++;
        }
      }
    }
    qsort(ans,w-1,sizeof(int),compare);
    printf("%d\n",ans[2]);
  }

  return 0;
}



Measured memory_bytes: 2052
icase=0
if icase==0:
    n,a,b=map(int,input().split())
    nsum=0
    for i in range(1,n+1):
        nn=sum([int(ii) for ii in list(str(i))])
#        print(i,nn)
        if a<=nn and nn<=b:
            nsum=nsum+i
    print(nsum)
    

Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//A
	int a, b;
	cin >> a >> b;
	if (b % a == 0) cout << a + b << endl;
	else cout << b - a << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int n,k;
ll dp[110][100010];
ll dp_sum[110][100010];
int a[110];
  

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  cin >> n >> k;
  for(int i=1;i<=n;i++)cin >> a[i];
  dp[0][0]=1;
  for(int j=0;j<=k;j++)dp_sum[0][j]=1;
  for(int i=1;i<=n;i++){
    for(int j=0;j<=k;j++){
      dp[i][j]=dp_sum[i-1][j];
      if(j-a[i]-1>=0)dp[i][j]-=dp_sum[i-1][j-a[i]-1];
      
      if(j-1>=0)dp_sum[i][j]=dp_sum[i][j-1]+dp[i][j];
      else dp_sum[i][j]=dp[i][j];
      dp[i][j]%=MOD;
      dp_sum[i][j]%=MOD;
    }
  }
  cout<<(dp[n][k]+MOD)%MOD<< endl;
}


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

int main(){

    ll a,b,c,n;

    cin >> a >> b >> c >>n;

    if(abs((ll)a-b)>1e+18){
        cout << "Unfair" << endl;
    }

    if(n%2){
        cout << b-a << endl;
    }else{
        cout << a-b << endl;
    }

    return 0;
}

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


int main(void){
  int N;
  cin >> N;
  for(int k = 0; k < N; k++){
    int maxint = 0, minint = 0;
    string num1, num2, maxnum, minnum;
    cin >> num1;
    num2 = num1;
    /*Maximum Combination*/
    while(maxnum.size() < num1.size()){
      int index;
      char nowmaxnum = '0';
      for(int i = 0; i < num1.size(); i++){
        if(num1[i] > nowmaxnum){
          nowmaxnum = num1[i];
          index = i;
        }
      }
      num1[index] = '0';
      maxnum.insert(maxnum.end(), nowmaxnum);
    }

    /*Minimum Combination*/
    while(minnum.size() < num2.size()){
      int index;
      char nowminnum = '9';
      for(int i = 0; i < num2.size(); i++){
        if(num2[i] < nowminnum){
          nowminnum = num2[i];
          index = i;
        }
      }
      num2[index] = '9';
      minnum.insert(minnum.end(), nowminnum);
    }

    /*String to int*/
    for(int i = 0; i < maxnum.size(); i++){
      maxint += (maxnum[i] - '0') * (int)pow(10, maxnum.size() - i - 1);
    }
    
    for(int i = 0; i < minnum.size(); i++){
      minint += (minnum[i] - '0') * (int)pow(10, minnum.size() - i - 1);
    }
    cout << maxint - minint << endl;
  }
  return 0;
}

Measured memory_bytes: 1260
import sys
input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, input().split()))

ans = 0
for d in range(1, N//2):
    tmp = 0
    checked = set()
    for t in range(N//d):
        ind = d*t
        if ind + d >= N-1 or ind in checked or ind == N - 1 - ind: break
        tmp += A[ind] + A[-ind-1]
        checked.add(N-1-ind)
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 108020
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
using namespace std;

int main(){
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    long long n;
    cin >> n;

    for (long i = -100;i<100;i++){
        for (long j = -100;j<100;j++){
            if (i*i*i*i*i-j*j*j*j*j==n){
                cout << i << " " << j <<endl;
                exit(0);
            }
        }
    }

    for (long i = 64;i<300;i++){
        for (long j = 64;j<300;j++){
            if (i*i*i*i*i-j*j*j*j*j==n){
                cout << i << " " << j <<endl;
                exit(0);
            }
        }
    }

    //long long i =63;
    //long long j =62;
    //for (long long ii = 0;ii<100000;ii++){
    //    long long ans=i*i*i*i*i-j*j*j*j*j;
    //    if (ans==n){
    //        cout << i << " " << j <<endl;
    //        exit(0);
    //    }else if(ans>n){
    //        j=j+1;
    //    }
    //    else{
    //        i=i+1;
    //    }
    //}
}



Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main(void) {
	// n+1本目の直線は最大n個の直線と交差し、交差数＋1個の領域を分割する
	// An+1 = An + n + 1, A1 = 2
	// An = 2 + Σ(k+1)
	// An = (n^2 + n + 2) / 2

	int n;

	while (cin >> n) {
		cout << (n * n + n + 2) / 2 << endl;
	}
}

Measured memory_bytes: 1160
import scala.io.StdIn
object Main extends App {
  // def calcPows(n:Int) = 
  val x = StdIn.readLine.toInt
  val r = math.sqrt(x).toInt
  val ans = (1 to r).map { i =>
    val e: Seq[Int] = for {
      j <- (1 to r)
      e = math.pow(i,j).toInt if(e <= x)
    } yield e
    e.max
  }
  println(ans.max)
}

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

int myabs(int x) {
  if ( x < 0 ) {
    return -x;
  }
  else {
    return x;
  }
}

int main() {
  //input
  int N;
  cin >> N;
  vector<int> A(N+2);
  A.at(0) = 0;
  rep(i,N) {
    cin >> A.at(i+1);
  }
  A.at(N+1) = 0;
  //calc & output
  int base = 0;
  rep(i,N+1) {
    base += myabs(A.at(i+1)-A.at(i));
  }
//  cout << base << endl;
  rep(i,N) {
    int S = base
      			- myabs(A.at(i+1) - A.at(i))
      			- myabs(A.at(i+2) - A.at(i+1))
      			+ myabs(A.at(i+2) - A.at(i));
    cout << S << endl;
  }
}

Measured memory_bytes: 1664
#include<stdio.h>
int main() {
    int a, b, c, x, y;
    scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
    c = c * 2;
    int ans;
    if (c <= a && c <= b) {
        if (x > y)
            ans = x * c;
        else
            ans = y * c;
    }
    else if (c <= a && c > b) {
        if (x > y)
            ans = x * c;
        else
            ans = x * c + (y - x)*b;
    }
    else if (c > a && c <= b) {
        if (x < y)
            ans = y * c;
        else
            ans = y * c + (x - y)*a;
    }
    else if (c < a + b) {
        if (x > y)
            ans = y * c + (x - y)*a;
        else
            ans = x * c + (y - x)*b;
    }
    else
        ans = a * x + b * y;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
minans = inf ;ans = 0 ;count = 0 ;pro = 1
sys.setrecursionlimit(10**7)

n,u,v=map(int,input().split())
u-=1;v-=1
G=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)
D=[-1]*n
maxD=[-1]*n

def make_tree_dfs(n,d):
    D[n]=d
    tmp=0
    f=True
    for gi in G[n]:
        if D[gi]==-1:
            f=False
            tmp=max(tmp,make_tree_dfs(gi,d+1))
    if f: tmp=d
    maxD[n]=tmp
    return tmp

make_tree_dfs(v,0)
sdis=D[u]

def good_dfs(v,d,sdis):
    f=True
    for gi in G[v]:
        if D[gi]==d-1 and d-1>sdis-(d-1):
            return good_dfs(gi,d-1,sdis)
    return (maxD[v],d)

gd,orid=good_dfs(u,D[u],sdis)
k=orid-(sdis-orid)
print(gd-orid+(sdis-orid)+k-1)
# print(D)
# print(maxD)
# print(sdis,orid,gd,k)
        







Measured memory_bytes: 98664
#include <iostream>

using namespace std;

int a[10001];
int b[10001];

int main(){
    int n;
    cin>>n;
    long long sumA = 0;
    long long sumB = 0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        sumA+=a[i];
    } 
    for(int i=0; i<n; i++){
        cin>>b[i];
        sumB+=b[i];
    }
    
    long long tot_ops = sumB - sumA;
    long long op_A = 0, op_B = 0;
    for(int i=0; i<n; i++){
        if(b[i] > a[i]) {
            op_A += (b[i] - a[i])/2;
            if(a[i]%2 != b[i]%2){
                op_A++;
                op_B++;
            }
        }
        if(a[i] > b[i]) op_B += a[i] - b[i];
    }
    if(op_A > tot_ops || op_B > tot_ops || (tot_ops - op_A)*2 != tot_ops - op_B) cout<<"No";
    else cout<<"Yes";
    return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> L(N);
  for(int i=0; i<N; i++){
    cin>>L.at(i);
  }
  sort(L.begin(),L.end());
  reverse(L.begin(),L.end());
  int sum = 0;
  for(int i=1; i<N; i++){
    sum += L.at(i);
  }
  if(L.at(0)<sum){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
#include<unordered_set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

string s[100010], t;
signed main(void)
{
	int n;
	cin >> n;
	REP(i, n) cin >> s[i];
	cin >> t;

	int left = 0, right = 0;
	REP(i, n) {
		string a = s[i], b = s[i];
		REP(j, s[i].size()) {
			if(s[i][j] == '?') {
				a[j] = 'a';
				b[j] = 'z';
			}
		}
		if(a > t) right++;
		else if(b < t) left++;
	}

	FOR(i, left+1, n-right+2) {
		cout << i;
		if(i != n-right+1) cout << " ";
	}
	cout << endl;
	return 0;
}


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

int main() {
    long long n; cin >> n; long long s = 0;
    long long arr[n]; for (long long i = 0; i < n; i ++) cin >> arr[i]; long long curr = arr[0];
    for (long long i = 1; i < n; i ++) {
        if (arr[i] == curr) continue;
        if (arr[i] < curr) {s += (curr-arr[i]); continue;}
        if (arr[i] > curr) curr = arr[i];
    } cout << s << endl;
}

Measured memory_bytes: 5152
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def dfs(N, nodes, src):
    """ DFS(木、スタック、重みあり) """

    stack = [(src, -1, 0)]
    dist = [INF] * N
    while stack:
        u, prev, c1 = stack.pop()
        dist[u] = c1
        for v, c2 in nodes[u]:
            if v != prev:
                stack.append((v, u, c1+c2))
    return dist

N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b, c = MAP()
    a -= 1; b -= 1
    nodes[a].append((b, c))
    nodes[b].append((a, c))

Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
ans = []
for i in range(Q):
    x, y = MAP()
    x -= 1; y -= 1
    ans.append(str(res[x] + res[y]))
print('\n'.join(ans))


Measured memory_bytes: 94804
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

namespace ndifix{

}

int main(){
    int h,w;cin>>h>>w;
    string s,t;
    t="snuke";
    for(int i=0;i<h*w;i++){
        cin>>s;
        if(s==t){cout<<(i%w==w-1?char('A'+w-1):char('A'+i%w))<<i/w+1<<endl;return 0;}
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n;
int a[17][17];
int cost[(1 << 16) + 2];
int dp[(1 << 16) + 2];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    cin>>n;
    f(i, n) {
        f(j, n) cin>>a[i][j];
    }
    f(i, (1 << n)) {
        f(j, n) {
            rep(k, j + 1, n - 1){
                if((i >> j) & 1 && (i >> k) & 1) cost[i] += a[j][k];
            }
        }
    }
    for(int i = 0; i < (1 << n); i++) {
        dp[i] = cost[i];
        for(int j = i; j > 0; j = (j - 1) & i) {
            dp[i] = max(dp[i], dp[j] + cost[(i ^ j)]);
        }
    }  
    cout<<dp[(1 << n) - 1];
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        200005
#define mod         1000000007
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,i;
    cin>>a>>b;
    for(i=1;i<=100000;i++){
        double x,y,p,q;
        x=double(i)*(0.08);
        y=double(i)*(0.1);
        p=int(x);
        q=int(y);
        if(p==a&&q==b){
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
}

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

#define M_MAX   (100000)

int main()
{
    // 整数の入力
    int N ,M;
    int result = 0;
    cin >> N >> M;
    int x[M_MAX];

    for (int i = 0; i < M; i++) cin >> x[i];

    sort(x, x + M);

    vector<int> diff;
    for(int i = 0; i < M-1; i++) diff.push_back(x[i+1] - x[i]);
    sort(diff.begin(), diff.end());
 
    for(int i = 0; i < M-N; i++) result += diff[i];
    cout << result << endl;
    return 0;

}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    int N;cin>>N;
    map<string,int> info;
    rep(i,N){
        string S;cin>>S;
        info[S]++;
    }
    int maxc=0;
    for(auto p:info)maxc=max(maxc,p.se);
    vector<string> ans;
    for(auto p:info){
        if(p.se==maxc)ans.push_back(p.fi);
    }
    sort(all(ans));
    for(auto p:ans)cout<<p<<endl;
    return 0;
}

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

int main() {
  int n,m;
  cin>>n>>m;
  int c,tt;
  c=0;
  std::vector<string> a(n),b(m);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<m;i++)cin>>b[i];
  for(int i=0;i<n-m+1&&c==0;i++){
    for(int j=0;j<n-m+1&&c==0;j++){
      tt=0;
      for(int k=0;k<m&&c==0;k++){
        for(int l=0;l<m&&c==0;l++){
          if(b[k][l]==a[i+k][j+l])tt++;
          if(tt==m*m)c=1;
        }
      }
    }
  }
  if(c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int num[3];
    cin >> num[0] >> num[1] >> num[2];
    sort(num, num + 3);

    P(num[2] * 10 + num[1] + num[0]);

    return 0;
}


Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define M_PI			3.1415926535897932384626433832795		// 円周率

// 内部構造体 - 座標情報
typedef struct Point {
	double mdX, mdY;											// 座標
} Point;

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// ２点間の距離 - 取得
double
fGetLen(
	Point *pzpPoint1			// <I> 座標１
	, Point *pzpPoint2			// <I> 座標２
)
{
	double ldX = pzpPoint1->mdX - pzpPoint2->mdX;
	double ldY = pzpPoint1->mdY - pzpPoint2->mdY;
	return sqrt(ldX * ldX + ldY * ldY);
}

// 座標 - 取得
int
fGetPoint(
	double pdAngle				// <I> 角度
	, double pdLen				// <I> 長さ
	, Point *pzpPoint			// <O> 座標
)
{
	pdAngle *= 2.0 * M_PI / 360.0;
	pzpPoint->mdX = pdLen * cos(pdAngle);
	pzpPoint->mdY = pdLen * sin(pdAngle);

	return 0;
}

// 実行メイン
int
fMain(
)
{
	char lc1Buf[1024];

	// 値 - 取得
	double ldA, ldB;
	int liH, liM;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lf%lf%d%d", &ldA, &ldB, &liH, &liM);

	// 時
	Point lzH;
	fGetPoint((double)((15 - liH) % 12) * 30.0 - (double)liM / 2.0, ldA, &lzH);

	// 分
	Point lzM;
	fGetPoint((double)((75 - liM) % 60) * 6.0, ldB, &lzM);

	// ２点間の距離 - 取得
	double ldLen = fGetLen(&lzH, &lzM);

	// 出力
	sprintf(lc1Buf, "%.10lf\n", ldLen);
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

constexpr long MOD = 1000000007;
// constexpr long MOD = 998244353;

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

  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);

  long cnt = 0;
  for (long i = 0; i < N; i++) {
    for (long j = 0; j < i; j++) {
      if (A.at(j) > A.at(i)) cnt++;
    }
  }

  long cnt2 = 0;
  for (long i = 0; i < N; i++) {
    for (long j = 0; j < N; j++) {
      if (A.at(i) > A.at(j)) cnt2++;
    }
  }

  long tmp = K * (K - 1) / 2 % MOD;

  long ans = cnt * K;
  ans %= MOD;
  ans += cnt2 * tmp;
  ans %= MOD;

  cout << ans << "\n";
}

Measured memory_bytes: 3628
answers = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
k = int(input())
print(answers[k-1])

Measured memory_bytes: 9320
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vi v;
int ans = 0, q;
vi a, b, c, d;

void get(int id, int n, int mx)
{
	if (id == n)
	{
		int cur = 0;
		for (int i = 0; i < q; ++i)
		{
			if (v[b[i]] - v[a[i]] == c[i])
				cur += d[i];
		}

		ans = max(ans, cur);

		return;
	}

	int cur = 1;
	if (v.size())
		cur = v.back();

	for (int num = cur; num <= mx; ++num)
	{
		v.pb(num);
		get(id + 1, n, mx);
		v.pop_back();
	}
}

int32_t main()
{
	FIO;
	int n, m; cin >> n >> m >> q;

	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);

	for (int i = 0; i < q; ++i)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--, b[i]--;
	}

	get(0, n, m);

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; FOR(cnt, 0, getline(stream,res,sp_word))
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;

int main(){
  str S; cin >> S;
  printf("%d",S.rfind('Z') - distance(S.begin(),find(all(S),'A')) + 1);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<vector<int>> pos(200005);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        pos[a].push_back(i);
    }
    
    // 1 が存在しないとき
    if(pos[1].size() == 0){
        cout << -1 << endl;
        return 0;
    }
    
    // 現在地 : 1 の中で一番左側の位置
    int now_pos = pos[1][0];
    for(int i = 2; i < 200005; ++i){
        if(pos[i].size() == 0){
	    	cout << n - i + 1 << endl;
         	return 0;
        }
        
        auto it = upper_bound(pos[i].begin(), pos[i].end(), now_pos);
        
        if(it == pos[i].end()){     // 条件を満たすものがない場合
            cout << n - i + 1 << endl;
            return 0;
        }
        
        now_pos = *it;      // 現在地の更新
    }
}

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

using namespace std;

using ll = long long;

constexpr ll mod = 1e9 + 7;

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

  ll n, k;
  cin >> n >> k;

  vector<vector<ll>> a(n, vector<ll>(n));
  vector<vector<ll>> res(n, vector<ll>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
    res[i][i] = 1;
  }

  vector<vector<ll>> tmp(n, vector<ll>(n));
  while (k) {
    if (k & 1) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          tmp[i][j] = 0;
          for (int m = 0; m < n; ++m) {
            tmp[i][j] = (tmp[i][j] + res[i][m] * a[m][j]) % mod;
          }
        }
      }
      swap(res, tmp);
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        tmp[i][j] = 0;
        for (int m = 0; m < n; ++m) {
          tmp[i][j] = (tmp[i][j] + a[i][m] * a[m][j]) % mod;
        }
      }
    }
    swap(a, tmp);
    k /= 2;
  }

  ll total = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      total = (total + res[i][j]) % mod;
    }
  }

  cout << total << '\n';

  return 0;
}


Measured memory_bytes: 384