akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std ;
#define int unsigned long long
const int mxn = 8000005 ;
const int Mod = 1e9+7 ;
int frac[mxn], inv[mxn];
int f[2005][2005], n, k;
int power(int a, int b){
    int res=1, car=a; 
    while(b){
        if(b&1) (res*=car)%=Mod;
        (car*=car)%=Mod;
        b>>=1;
    }
    return res;
}
void init(){
    frac[0]=1 ;
    for(int i=1;i<mxn;++i) (frac[i]=frac[i-1]*i)%=Mod ;
    inv[mxn-1] = power(frac[mxn-1], Mod-2);
    for(int i=mxn-2;i>0;--i) inv[i]=(inv[i+1]*(i+1))%Mod ;
    inv[0] = 1 ;
}
int C(int n, int k){
    return ((frac[n]*inv[k]%Mod)*inv[n-k])%Mod ;
}
signed main(){
    init() ;
    cin>>n>>k;
    if(k==1) return puts("1"),0 ;
    f[0][0] = 1 ;
    for(int i=1;i<=n;++i)
        for(int j=0;j<=i;++j)
            (f[i][j] = f[i-1][j]+(j?((((f[i][j-1]*(n-j+1))%Mod)*C(n*k-i-(j-1)*(k-1)-1, k-2))%Mod):(0)))%=Mod ;
    cout<<f[n][n]<<endl ;
}

Measured memory_bytes: 155136
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#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>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    string S;
    cin >> S;

    map<char, int> m;
    m['a'] = m['b'] = m['c'] = 0;
    for (auto c : S) m[c]++;

    bool good = true;
    for (auto x : m) for (auto y : m) if (abs(x.second - y.second) >= 2) good = false;

    cout << (good ? "YES" : "NO") << endl;

}













































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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};


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

  ll h, w;
  cin >> h >> w;
  ll m[h][w];
  REP(i, h){
    REP(j, w)
      cin >> m[i][j];
  }

  ll b;
  REP(i, h){
    REP(j, w){
      cin >> b;
      m[i][j] = abs(m[i][j]-b);
      }
  }

  bool dp[h][w][13000];
  REP(i, h){
    REP(j, w){
      REP(k, 13000)
        dp[i][j][k] = false;
    }
  }


  dp[0][0][m[0][0]] = true;

  REP(i, h){
    REP(j, w){
      REP(k, 13000){
        if(dp[i][j][k] == false)
          continue;
        if(i+1<h){
          dp[i+1][j][k+m[i+1][j]] = true;
          dp[i+1][j][abs(k-m[i+1][j])] = true;
        }
        if(j+1<w){
          dp[i][j+1][k+m[i][j+1]] = true;
          dp[i][j+1][abs(k-m[i][j+1])] = true;
        }
      }
    }
  }

  ll ans = 13000;
  REP(i, 13000){
    if(dp[h-1][w-1][i] == true)
      ans = min(ans, ll(i));
  }

  cout << ans << endl;

}


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

struct FenwickTree {
    int n;
    vector<int> tree;

    void init(int _n) {
        n = _n;
        tree.resize(n + 1);
    }

    void update(int idx, int val) {
        for(; idx <= n; idx += idx & -idx) {
            tree[idx] += val;
        }
    }

    int sum(int idx) {
        int tot = 0;
        for(; idx > 0; idx -= idx & -idx) {
            tot += tree[idx];
        }

        return tot;
    }

    int sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }
} alpha[30];

int n, q;
string s;

int get(char c) {
    return c - 'a';
}

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

    cin >> n;

    cin >> s;

    s = ' ' + s;

    cin >> q;

    for(int i = 0; i < 30; i++){
        alpha[i].init(n);
    }

    for(int i = 1; i <= n; i++){
        alpha[get(s[i])].update(i, 1);
    }

    while(q--) {
        int tp; cin >> tp;

        if(tp == 1) {
            int i;  char c;   cin >> i >> c;

            alpha[get(s[i])].update(i, -1);
            alpha[get(c)].update(i, 1);

            s[i] = c;
        } else {
            int l, r;   cin >> l >> r;
            int ans = 0;
            for(int i = 0; i < 30; i++){
                ans += (alpha[i].sum(l, r) > 0);
            }

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

    return 0;
}


Measured memory_bytes: 59568
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){
    std::set<string> dic;

    int count;
    cin >> count;

    for(int i=0; i<count; i++){
        string buf1, buf2;
        cin >> buf1 >> buf2;
        if(buf1 == "insert"){
            dic.insert(buf2);
          }
        else{
          if(dic.count(buf2) > 0) printf("yes\n");
          else printf("no\n");
        }
    }
    return 0;
}

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

int main() {
  int A;
  cin >> A  ;
  
  if(A<105){
    cout<<"0"<<endl;
  }
  
  else if(105<=A&&A<135){
    cout<<"1"<<endl;
  }
  
  else if(135<=A&&A<165){
    cout<<"2"<<endl;
  }
  
   else if(165<=A&&A<189){
    cout<<"3"<<endl;
  }
  
  else if(189<=A&&A<195){
    cout<<"4"<<endl;
  }
  
  else {
    cout<<"5"<<endl;
  }
 
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] a = new int[3];
    for(int  i = 0;i<3;i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    int count = 0;
    while(a[0]!=a[2]){
      count++;
      if(a[2]-a[0]>=2){
        a[0]+=2;
      }else{
        a[0]++;
        a[1]++;
      }
      Arrays.sort(a);
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 35548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i = k; i <= n + 1; ++i) {
    ll mi = i * (i - 1) / 2;
    ll ma = i * (n + (n - i + 1)) / 2;
    // cout << i << " " << ma << " " << mi << endl;
    ll l = ma - mi + 1;
    add(ans, l % mod);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
using System;

namespace _047_CupGame
{
	class Program
	{
		static void Main ( string[] args )
		{
			string cap = "A";

			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				string[] split = inputStr.Split (',');

				if (cap == split[0])
				{
					cap = split[1];
				}
				else if (cap == split[1])
				{
					cap = split[0];
				}
			}

			Console.WriteLine (cap);
		}
	}
}

Measured memory_bytes: 8804
#include<stdio.h>
#include<math.h>
int main(){
    int N,i,j,num=0,y;
	scanf("%d",&N);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	/*prime number check*/
	for(i=0;i<N;i++){
		y=0;
		if(A[i]==2){
			num++;
			continue;
		}
		if((A[i]%2)==0)continue;
		for(j=3;j<=sqrt(A[i]);j+=2){
			if((A[i]%j)==0){
				y=1;
				break;
			}
		}
		if(y==0)num++;
	}
	printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b&&a>c){
		cout<<"A"<<endl;
	}else if(b>c){
		cout<<"B"<<endl;
	}else{
		cout<<'C'<<endl;
	}
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>

long long cost[50][50];
long long minutes[50][50];
long long ans[50][50 * 100 + 2];
long long exchange[50];
long long minutes_exchange[50];

int main() {
    int n, m; long long s; std::cin >> n >> m >> s;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cost[i][j] = -1;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) minutes[i][j] = -1;
    long long sum = 0;
    for (int i = 0; i < m; i++) {
        long long a, b, c, d; std::cin >> a >> b >> c >> d;
        a--; b--;
        cost[a][b] = cost[b][a] = c;
        minutes[a][b] = minutes[b][a] = d;
        sum += c;
    }
    if (sum <= s) s = sum;

    constexpr long long INIT = 1e18;
    for (int i = 0; i < n; i++) {
        std::cin >> exchange[i] >> minutes_exchange[i];
    }
    using Node = std::pair<long long, std::pair<long long, long long>>;
    std::priority_queue<Node, std::vector<Node>, std::greater<Node>> que;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < sum + 2; j++) {
            ans[i][j] = INIT;
        }
    }
    que.push({ 0,{ 0, s } });
    bool vis[50] = {};
    int cnt = 0;
    while (!que.empty()) {
        auto node = move(que.top());
        que.pop();
        long long dist = node.first;
        long long pos = node.second.first;
        long long coin = node.second.second;
        if (ans[pos][coin] != INIT) continue;
        ans[pos][coin] = dist;
        if (!vis[pos]) {
            vis[pos] = true;
            cnt++;
            if (cnt >= n) {
                break;
            }
        }

        for (int i = 0; i < n; i++) {
            if (cost[pos][i] == -1) continue;
            long long nxtcoin = coin - cost[pos][i];
            if (nxtcoin < 0) continue;
            if (ans[i][nxtcoin] != INIT) continue;
            que.push({ dist + minutes[pos][i],{ i, nxtcoin } });
        }

        if (coin < sum) {
            long long nxtcoin = std::min(sum, coin + exchange[pos]);
            long long nxtdist = dist + minutes_exchange[pos];
            if (ans[pos][nxtcoin] != INIT) continue;
            que.push({ nxtdist,{ pos, nxtcoin } });
        }
    }
    for (int i = 1; i < n; i++) {
        std::cout << *std::min_element(ans[i], ans[i] + sum + 1) << std::endl;
    }
    return 0;
}


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

int main(){
    int x,y;
    cin>>x>>y;
    if(y>x*4){
        cout<<"No\n";
        return 0;
    }
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            if(i*2+j*4==y && i+j==x){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3632
N = input()
K = int(input())


def f(n, d, k):
    if k == 0:
        return 1
    if d == 1:
        return int(n) if k == 1 else 0
    msb = int(n[0])
    if msb == 0:
        return f(n[1:], d - 1, k)
    return f(n[1:], d - 1, k - 1) + (msb - 1) * f('9' * (d - 1), d - 1, k - 1) + f('9' * (d - 1), d - 1, k)


print(f(N, len(N), K))


Measured memory_bytes: 3188
H,W,D=gets.split.map(&:to_i)
A=[]
H.times{
    A << gets.split.map{|i|i.to_i-1}
}
cs=Array.new(D){Array.new}
H.times{|y|
    W.times{|x|
        a=A[y][x]
        cs[a%D][a/D]=[x,y]
    }
}
#warn cs.inspect
D.times{|d|
    (cs[d].size-1).downto(1){|i|
        dx=(cs[d][i][0] - cs[d][i-1][0]).abs
        dy=(cs[d][i][1] - cs[d][i-1][1]).abs
        cs[d][i] = dx+dy
    }
    cs[d][0]=0
    1.upto(cs[d].size-1){|i|
        cs[d][i]+=cs[d][i-1]
    }
}
#warn cs.inspect
Q=gets.to_i
Q.times{
    l,r=gets.split.map{|i|i.to_i-1}
    warn [cs[l%D][l/D], cs[r%D][r/D]].inspect
    puts cs[r%D][r/D] - cs[l%D][l/D]
}


Measured memory_bytes: 25848
n,m=gets.split.map(&:to_i)
l=Array.new(n).map{[]}
m.times do |k|
  p,y=gets.split.map(&:to_i)
  l[p-1] << [y,k]
end
a=[]
n.times do |i|
  j=1
  l[i].sort.each do |y,k|
    a[k]=format("%06d%06d",i+1,j)
    j+=1
  end
end
puts a


Measured memory_bytes: 29212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int N, M;
  cin >> N >> M;
  int ans;
  ans = N * (N - 1) / 2 + M * (M - 1) / 2;
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define N 200020
const ll mod=1e9+7;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,k;
ll fac[N],inv[N],ans;
ll qpow(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;i++){
		fac[i]=fac[i-1]*i%mod;
	}
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
ll C(int n,int m){
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	n=read(),k=read();
	init(n);
	for(int i=0;i<=min(n-1,k);i++){
		ans=(ans+C(n-1,n-i-1)*C(n,i)%mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
total = 0
for i in a:
    d[i] += 1
    total += i
Q = int(input())

for i in range(Q):
    b, c = map(int, input().split())
    cnt = d[b]
    total -= cnt * b
    d[b] = 0
    d[c] += cnt
    total += c * cnt
    print(total)

Measured memory_bytes: 24128
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    for i in range(1,n+1):
        u = 108*i//100
        if u == n:
            print(i)
            break
        elif u > n:
            print(':(')
            break


if __name__ == '__main__':
    main()

Measured memory_bytes: 8984
"use strict";

main(require("fs").readFileSync("/dev/stdin", "utf8"));

function main(input) {
  const [[n, k], sticks] = input.split("\n").map(s => s.split(" ").map(Number));

  // 降順にソート
  sticks.sort((a, b) => b - a);

  const ans = sticks.slice(0, k).reduce((p, c) => p + c);
  console.log(ans);
}

Measured memory_bytes: 11468
#include<iostream>
#include<string>
using namespace std;
int main(){
	int count=0;
	string a;
	while(cin>>a){
		int i=a.size()-1;
		int e=1;
		while(true){
			if(a[i]>='0'&&a[i]<='9'){
				count+=e*(a[i]-'0');
				e*=10;
			}
			else
				e=1;
			if(i==0)
				break;
			i--;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
int main(void) {
  long long int a, b, c;
  cin >> a >> b >> c;
  long long int rhs = c - a - b;
  if(rhs < 0) {
    cout<<"No\n";
    return 0;
  }
  rhs = rhs * rhs;
  long long int lhs = 4*a*b;
  if(lhs < rhs) {
    cout<<"Yes\n";
  } else {
	cout<<"No\n";
  }
}

Measured memory_bytes: 3612
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n + 2];
		long d = 0;
		for (int i = 1; i <= n; i++) {
			a[i] = Integer.parseInt(sc.next());
			d += Math.abs(a[i] - a[i - 1]);
		}
		d += Math.abs(a[n]);
		for (int i = 1; i <= n; i++)
			System.out.println(d - (Math.abs(a[i] - a[i - 1]) + Math.abs(a[i + 1] - a[i])) + Math.abs(a[i + 1] - a[i - 1]));
	}
}

Measured memory_bytes: 54396
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int MAXN = 10 + 1e5;
const long long oo = 1 + 1e18;
typedef long long LL;
typedef pair < int, int > II;
typedef pair < int, II > III;

int n, d[MAXN], top = 0, L[MAXN], R[MAXN], id[MAXN];
long long a[MAXN];

int main()
{
    #define TASK "ABC"
  //  freopen(TASK".inp","r",stdin);
 //   freopen(TASK".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        id[a[i]] = i;
    }
    long long ans = 0;
    a[0] = a[n+1] = oo;
    multiset < int > s;
    s.insert(0);
    s.insert(0);
    s.insert(n+1);
    s.insert(n+1);
    for (int i = n - 1; i >= 1; i--){
        s.insert(id[i+1]);
        auto it1 = s.lower_bound(id[i]);
        auto it2 = it1;
        it1--;
        int l1 = *it1--, l2 = *it1;
        int r1 = *it2++, r2 = *it2;
        ans += LL(i) * LL( (l1 - l2) * (r1 - id[i]) + (r2 - r1) * (id[i] - l1) );
      //  cout << ans << endl;
    }
    cout << ans;



    return 0;
}




Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}

int main(){
  int a,b;
  cin>>a>>b;
  int c = a-2*b;
  cout<<max(0,c)<<endl;
  
}




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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
typedef unsigned long long ull;
typedef long long ll;

const int INF=INT_MAX/2;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    int N,A,B;
    cin >> N >> A >> B;

	vector<vector<int>> dp(401,vector<int>(401,INF));    
	dp[0][0]=0;

    while (N--) {
		int a, b, c;
		cin >> a >> b >> c;
		for (int x = 400; x >= a; x--){
			for (int y = 400; y >= b; y--)
				dp[x][y] = min(dp[x][y], dp[x - a][y - b] + c);
		}
	}
	int ans = INF;
	for (int x = 1; x <= 400; x++){
		for (int y = 1; y <= 400; y++){
			if (x * B == y * A)
				ans = min(ans, dp[x][y]);
		}
	}
	if (ans == INF) 
		ans = -1;
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 896
S = input()
mm = len(S)

ans = True


i = 0
j = mm-1
while(1):
    if i==j or j<i:
        break

    if S[i]!=S[j]:
        ans = False
        break
    i += 1
    j -= 1


i = 0
j = (mm-1)//2-1
while(1):
    if i==j or j<i:
        break
    if S[i]!=S[j]:
        ans = False
        break
    i += 1
    j -= 1


i = (mm+3)//2-1
j = mm-1
while(1):
    # print(S[i],S[j])
    if i==j or j<i:
        break
    if S[i]!=S[j]:
        ans = False
        break
    i += 1
    j -= 1

if ans:
    print("Yes")
else:
    print("No")








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

signed main() {
    string s;
    cin >> s;

    bool flag = false;
    for(int i = 0; i < 3; i++){
        if(s[i] == '7') flag = true;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()
G = [[] for _ in range(n)]
for _ in range(n-1):
    a,b=LI()
    G[a-1]+=[b-1]
    G[b - 1] += [a - 1]


def dfs(v, visited):
    """
    :param v: X側の未マッチングの頂点の1つ
    :param visited: 空のsetを渡す（外部からの呼び出し時）
    :return: 増大路が見つかればTrue
    """
    for u in G[v]:
        if memo[u]:
            continue
        if u in visited:
            continue
        visited.add(u)
        if matched[u] == -1:
            matched[u] = v
            return True
        elif dfs(matched[u], visited) == 1:
            matched[u] = v
            return True
        else:
            memo[u] = 1
    return False

cnt = 0
matched = [-1] * n
visited = set()
memo = [0] * n
for i in range(n):
    cnt += int(dfs(i, set()))

if cnt == n:
    print("Second")
else:
    print("First")





Measured memory_bytes: 100396
#include <bits/stdc++.h>
using namespace std;
int64_t INF = (1 << 20);
int64_t N, MAXN = 10010;
vector< vector < pair<int64_t, int64_t> > > Edges(MAXN);

void dijkstra()
{
  priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t> >, greater<pair<int64_t, int64_t > > > PQ;
  vector<int64_t> Color(MAXN, 0), D(MAXN, INF); // 各点を無限大にする。

  D.at(0) = 0; // 始点を0とする。
  PQ.push(make_pair(0, 0));
  Color.at(0) = 1; // グレーの状態に

  while (!PQ.empty())
  {
    pair<int64_t, int64_t> f = PQ.top();
    PQ.pop();
    int64_t u = f.second; // 未決定の中で、最短経路の頂点
    Color.at(u) = 2;      // 決定済とする
    if (D.at(u) < f.first)
      continue;
    for (int i = 0; i < Edges.at(u).size(); i++)
    {
      int64_t v = Edges.at(u).at(i).first; // uからの辺の終点
      if (Color.at(v) == 2)
        continue;
      if (D.at(v) > D.at(u) + Edges.at(u).at(i).second) // uを経由した場合の距離
      {
        D.at(v) = D.at(u) + Edges.at(u).at(i).second;
        PQ.push(make_pair(D.at(v), v)); // 頂点vの暫定での距離、頂点vをペアにする
        Color.at(v) = 1;                // グレーにする
      }
    }
  }
  for (int i = 0; i < N; i++)
    cout << i << ' ' << (D.at(i) == INF ? -1 : D.at(i)) << endl;
}

int main()
{
  cin >> N;
  int k, u, v, c;
  for (int i = 0; i < N; i++)
  {
    cin >> u >> k;
    for (int j = 0; j < k; j++)
    {
      cin >> v >> c;
      Edges.at(u).push_back(make_pair(v, c));
    }
  }

  dijkstra();
}



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

int main(){
  int N,k=0;
  cin>>N;
  priority_queue<int,vector<int>,greater<int>> P;
  for(int i=0;i<N;i++){
    int p,j=0;
    cin>>p;
    P.push(p);
    if(P.top()>=p)
      k++;
  }
  cout<<k<<endl;
}

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

int mod_pow2(int n, int mod) {
  int res = 1;
  for (int i = 0; i < n; ++i) {
    res = res * 2 % mod;
  }
  return res;
}

int main(int argc, char *argv[]) {
  const int mod = 1e9 + 7;
  int N;
  cin >> N;

  int cnts[N];
  fill(cnts, cnts + N, 0);
  for (int i = 0; i < N; ++i) {
    int A;
    cin >> A;
    ++cnts[A];
  }

  bool possible = true;
  for (int i = N; 1 < i; i -= 2) {
    if (cnts[i - 1] != 2) {
      possible = false;
      break;
    }
  }

  if (cnts[0] != (N & 1))
    possible = false;

  cout << (possible ? mod_pow2(N / 2, mod) : 0) << endl;

  return 0;
}



Measured memory_bytes: 640
A=int(input()) 
B=int(input()) 
C=int(input())
X=int(input())
cnt=0
for i in range(0,A+1):
    for j in range(0,B+1):
        for k in range(0, C+1):
            if 500*i+100*j+50*k==X:
                cnt+=1
            else:
                continue
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
    int n, m, i, j;
	ll answer;
    int tmpa, tmpb, tmpc;
	vector<int> d;
	int endmark;
	cin >> n >> m;
	vector<int> a(n);
	vector< pair<int, int> > ope(m);
	bool end = false;
	
	for (i = 0; i < n; i++) 
		cin >> a[i];	
	sort(a.begin(), a.end());
	
	for (i = 0; i < m; i++) 
		cin >> ope[i].second >> ope[i].first;
	sort(ope.begin(), ope.end());

	endmark = 0;
	for (i = ope.size() - 1; i >= 0; i--) {
		int c = ope[i].first;
		int b = ope[i].second;
		for (j = 0; j < b; j++) {
			d.push_back(c);
			endmark++;
			if (endmark == n) {
				end = true;
				break;
			}
		}
		if (end)
			break;
	}

	for (i = 0; i < n; i++) {
		if (a[i] >= d[i])
			break;
		else
			a[i] = d[i];
	}

	answer = 0;
	for (i = 0; i < a.size(); i++)
		answer += a[i];

	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const ll INF = (1LL << 31) - 1;
const double pi=acos(-1);


int main(){
  int h,w;
  cin >> h >> w;
  vector<string>a(h);
  rep(i,h)cin>>a[i];
  vector<int>vec;
  rep(i,h){
    rep(j,w){
      if(a[i][j]=='#')vec.push_back(j);
    }
  }
  int sum=0;
  rep(i,vec.size()-1){
    if(vec[i]+1==vec[i+1]||vec[i]==vec[i+1]){
      sum++;
      continue;
    }
    cout << "Impossible" << endl;
    return 0;
  }
  
  if(w+h-2==sum)cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
  
    
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1000+10;
int main()
{
    string str;
    while(cin>>str){
        printf("2018/01/%c%c\n",str[8],str[9]);
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){

	int H, W;
	
	while (1){
		cin >> H >> W;
		if (H == 0 && W == 0)break;


		for (int i = 0; i < H ; i++)
		{
			for (int j = 0; j < W ; j++)
			{
				if ((i+j)%2==0)
				{
					cout << "#";
				}
				else
				{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}






	return 0;
}

Measured memory_bytes: 3060
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,m,k = map(int,readline().split())
mod = 998244353
 
if m == 1:
    if k < n-1:
        print(0)
    else:
        print(1)
    exit()

def pow(n,p,mod=mod): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod

def factrial_memo(n=2*10**5,mod=mod):
    fact = [1, 1]
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % mod)
    return fact
fact = factrial_memo()

def fermat_cmb(n, r, mod=mod): #needs pow,factrial_memo(only fact). return nCk
    return fact[n] * pow(fact[r],mod-2) * pow(fact[n-r],mod-2) %mod
ans = 0
for i in range(k+1):
    res = m*pow(m-1,n-1-i) #塊を含めて分けられるもの達
    ans += res*fermat_cmb(n-1,i)%mod
print(ans%mod)

Measured memory_bytes: 81584
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
    
    int N;
    cin>>N;
    
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    
    
    int ans=0;
    
    for(int i=0;i<N;i++){
        for(int j=N-1;j>=i;j--){
            if(A[j]<A[j-1]){
                swap(A[j],A[j-1]);
                ans++;
            }
        }
    }
    
    for(int k=0;k<N-1;k++){
        cout<<A[k]<<" ";
    }
    
    cout<<A[N-1]<<endl;
    cout<<ans<<endl;
}


Measured memory_bytes: 3088
n = int(raw_input())

def update(i,l,n,ms,dp):
    min_val = 10000000000000
    for k in range(1,l):
        val = dp[i][k]+dp[i+k][l-k]+ms[i][0]*ms[i+k-1][1]*ms[i+l-1][1]
        if min_val > val:
            min_val = val
    return min_val

dp = {}
for i in range(n+1):
    dp[i] = {}
    for j in range(n+1):
        dp[i][j] = 0

ms = []
for i in range(n):
    r,c = map(int, raw_input().split(' '))
    ms.append((r,c))

for l in range(2,n+1):
    for i in range(n):
        if i + l > n: break
        dp[i][l] = update(i,l,n,ms,dp)

print dp[0][n]

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

int main(){
    ll n,d;
    cin >> n >> d;
    vector<ll> x(n,0);
    vector<ll> y(n,0);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    int ans = 0;
    for(int i = 0;i < n;i++){
        ll d1 = (x[i]*x[i])+(y[i]*y[i]);
        
        if(d1 <= d*d){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6420
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
E = [A[i] for i in range(n) if i%2 == 1]
O = [A[i] for i in range(n) if i%2 == 0]
e = Counter(E).most_common(2)
o = Counter(O).most_common(2)
if e[0][0] != o[0][0]: ##Eの最頻値とOの最頻値が違う
    ans = (n//2-e[0][1])+(n//2-o[0][1])
    print(ans)
    ##以下、EとOの最頻値が同じ時の処理を書く
elif len(e)>=2 and len(o)>=2:
    ans = min((n//2-e[0][1])+(n//2-o[1][1]), (n//2-e[1][1])+(n//2-o[0][1]))
    print(ans)
else:
    print(n//2)

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

int main()
{
	int h, w;
	while (cin >> h >> w, h || w)
	{
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++) cout << ((i + j) % 2 == 0 ? '#' : '.');
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

ll D[5];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int A[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
  int B[] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
  int C[] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
  int n;
  cin >> n;
  REP(i,n){
    string s;
    cin >> s;
    if(s[0]=='M') D[0]++;
    else if(s[0]=='A') D[1]++;
    else if(s[0]=='R') D[2]++;
    else if(s[0]=='C') D[3]++;
    else if(s[0]=='H') D[4]++;
  }
  ll ans = 0;
  REP(i,10){
    ans += D[A[i]]*D[B[i]]*D[C[i]];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main(){
	int a,b,c;
		for(a=1;a<10;++a){
			for(b=1;b<10;++b){
				c=a*b;
				std::cout<<a<<"x"<<b<<"="<<c<<std::endl;
				}
		}
	 return 0;
	}

Measured memory_bytes: 1116
A, B, C, X, Y = map(int, input().split())

cost_1 = A*X + B*Y
cost_2 = C * max(X, Y) * 2

cost_3 = C * min(X, Y) * 2 + (X - min(X, Y))*A + (Y - min(X, Y))*B


print(min(cost_1, cost_2, cost_3))

Measured memory_bytes: 61716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if(H==0 && W==0) {
				break;
			}
			for(int i=0;i<H;i++) {
				for(int j=0;j<W;j++) {
					System.out.printf("#");
				}System.out.printf("\n");
			
			}System.out.println();
		}
		sc.close();
	
}

}


Measured memory_bytes: 60952
def compress_array_to_hash(array)
  hash = {}
  array.map { |e|
    if hash[e].nil?
      hash[e] = 1
    else
      hash[e] += 1
    end
  }
  hash
end
_n = gets
hash = compress_array_to_hash(gets.split.map(&:to_i))

max = 0
hash.each do |key, value|
  count = value + (hash[key+1] || 0) + (hash[key+2] || 0)
  max = [max, count].max
end
puts max


Measured memory_bytes: 15492
#include <stdio.h>
    #include <stdlib.h>
    int compare(const void *a,const void *b){
    	return *(int*)b-*(int*)a;
    }
    int main(){
    	int n,i,r=0,t=1;
    	int arr[999];
    	scanf("%d",&n);
    	for(i=0;i<n;i++)scanf("%d",&arr[i]);
    	qsort(arr,n,4,compare);
    	for(i=0;i<n;i++){
    		r+=t*arr[i];
    		t=-t;
    	}
    	printf("%d\n",r);
    	return 0;
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"Yes"<<endl
#define cno cout<<"No"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
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; }
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int h,w; cin >> h >> w;
    int H,W;
    H = h/2; W = w/2;
    map<char,int> mp;
    for(char c = 'a'; c <= 'z'; c++){
        mp[c] = 0;
    }
    for(char c = 'A'; c <= 'Z'; c++){
        mp[c] = 0;
    }
    rep(i,h)rep(j,w){
        char c; cin >> c;
        ++mp.at(c);
    }
    bool ok = true;
    int cnt_odd = 0;
    int cnt_four = 0;
    for(char c = 'a'; c <= 'z'; c++){
        if(mp.at(c)%2 == 1) ++cnt_odd;
        cnt_four += mp.at(c)/4;
    }
    for(char c = 'A'; c <= 'Z'; c++){
        if(mp.at(c)%2 == 1) ++cnt_odd;
        cnt_four += mp.at(c)/4;
    }
    if(h%2 == 0 && w%2 == 0){
        if(cnt_four != H*W) ok = false;
    }
    else if(h%2 == 1 && w%2 == 1){
        if(cnt_odd > 1) ok = false;
        if(cnt_four < H*W) ok = false;
    }
    else{
        if(cnt_odd > 0) ok = false;
        if(cnt_four < H*W) ok = false;
    }
    ok? cyes : cno;
    return 0;
}


Measured memory_bytes: 256
//<editor-fold desc="Headers & Macros">
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define o(x) cout << x << '\n'
#define o2(x, y) cout << x << ' ' << y << '\n'
#define on() cout << '\n'
#define os(x) cout << x << ' '

#define i(x) cin >> x
#define i2(x, y) cin >> x >> y

#define DBG = 1

using ll = long long;
//</editor-fold>

struct Item {
    int weight;
    int value;
};

int main() {
    //<editor-fold desc="Init">
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //</editor-fold>

    int n, total_weight;
    i2(n, total_weight);

    vector<ll> best_value(total_weight + 1, 0);

    for (int i = 0; i < n; ++i) {
        Item item{};

        i2(item.weight, item.value);

        for (int remaining_weight = total_weight - item.weight; remaining_weight >= 0; --remaining_weight) {
            // Is it a good idea to take item i-th?
            ll take_item_value = best_value[remaining_weight] + item.value;
            int used_weight = remaining_weight + item.weight;

            if (take_item_value > best_value[used_weight]) {
                // Yes! Let's do it
                best_value[used_weight] = take_item_value;
            }
        }
    }

    o(best_value[total_weight]);

    return 0;
}

Measured memory_bytes: 1024
n,x = map(int,input().split())
ans = 0
if 2*x == n:
    ans = 3*x
else:
    ans += n
    a = x
    b = n - x
    while True:
        ans += (a//b)*2*b
        c = b
        b = a%b
        a = c
        if b == 0:
            ans -= a
            break
    
print(ans)


Measured memory_bytes: 3060
n,m=map(int,input().split())
l=[[] for i in range(n)]
for i in range(m):
  p,y=map(int,input().split())
  l[p-1].append((y,i))

ids=["" for i in range(m)]
for i in range(n):
  l[i].sort()
  for j in range(len(l[i])):
    ids[l[i][j][1]]="{:0>6d}".format(i+1)+"{:0>6d}".format(j+1)
print("\n".join(ids))

Measured memory_bytes: 95888
import * as fs from 'fs';

namespace AtCoder.abc095 {
    class ProgramA {
        args: string[];

        // oxo
        // 900
        constructor(args: string[]) {
            this.args = args;
        }

        main(): void {
            const cnt: number = this.args[0].split('').reduce((prev: number, curr: string) => {
                if (curr === 'o') prev++;
                return prev;
            }, 0);

            console.log(700 + 100 * cnt);
        }
    }

    const args: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    const func = new ProgramA(args);
    func.main();
}

Measured memory_bytes: 7820
import java.util.Scanner;

public class Main {


	 public static void main(String[] args)
	 {
		 int a,b;
         Scanner sc = new Scanner(System.in);
    
        
          a = sc.nextInt();
          b = sc.nextInt();
         if(a<b)
        	 System.out.println("a < b");
         else if(a>b)
        	 System.out.println("a > b");
         else
        	 System.out.println("a == b");
         
         sc.close();
	 }
	 
}



Measured memory_bytes: 26168
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char a = sc.next().charAt(0);
		char b = sc.next().charAt(0);
		
		if(a==b) {
			System.out.println('H');
		}else {
			System.out.println('D');
		}

	}

}


Measured memory_bytes: 21972
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n,l[205],ans;
vector<int> v;
int main(){
	cin>>n;
	for(int i=1;i<=n*2;i++)
		cin>>l[i];
	sort(l+1,l+1+n+n);
	for(int i=1;i<=n;i++)
		ans+=l[i*2-1];
	cout<<ans;
	return 0;
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.1415926535
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define MAX 200005

vector<int> v[MAX];
int t=0;
vector<pair<int,int>> inout(MAX);
int vis[MAX]={};
ll a[2*MAX]={};

void dfs(int r)
{
    int p=t;
    vis[r]=1;
    ffor(i,0,sz(v[r]))
    {
        if(!vis[v[r][i]])
        {
            t++;
            dfs(v[r][i]);
        }
    }
    t++;
    inout[r]=mp(p,t);
}

int main()
{
    int n,q;
    cin>>n>>q;
    ffor(i,0,n-1)
    {
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1);
    while(q--)
    {
        int index,val;
        cin>>index>>val;
        a[inout[index].ff]+=val;
        a[inout[index].ss+1]-=val;
    }
    ffor(i,1,2*MAX) a[i]+=a[i-1];
    ffor(i,1,n+1) cout<<a[inout[i].ff]<<" ";
    return 0;
}


Measured memory_bytes: 31232
#include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int a[500], b, c, d, e,f, g, i, j;
	for(i=0;i<6;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<4;i++){
		for(j=1;j<4;j++){
			if(a[i]>a[j]){
				swap(a[i], a[j]);
			}}}
		if(a[4]>a[5]){
			swap(a[4], a[5]);
		}
		b=a[1]+a[2]+a[3]+a[5];
		printf("%d\n",b);
	return 0;
}

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

template <typename T>
T _min(
  const T & lhs
  , const T & rhs
)
{
  return ((lhs < rhs) ? lhs : rhs);
}

int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 0; i < 5; ++i)
  {
    int begin = 1;
    int end = 10;
    for (int j = 0; j < i; ++j)
    {
      begin *= 10;
      end *= 10;
    }
    int j = begin;
    for (; j < end; ++j)
    {
      if (N < j)
        break;
      auto m = j;
      int sum = m%10;
      for (int k = 0; k < i; ++k)
      {
        m /= 10;
        sum += m%10;
      }
      if ((A <= sum) && (sum <= B))
        total += j;
    }
    if (j < end)
      break;
  }
  cout << total;
  return 0;
}


Measured memory_bytes: 256
n, y = map(int, input().split())
for m10 in range(n+1):
    for m5 in range(n-m10 +1):
        m1 = n - m10 - m5
        if m10 *10000 + m5 * 5000 + m1 * 1000 == y:
            print(m10, m5, m1)
            exit(0)
print("-1 -1 -1")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include <math.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;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  int M;
  int X;
  cin >>N>>M>>X;
  vector<int> vec(M);
  rep(i,M) {
cin >>vec.at(i);
  }
  if(X>vec.at(M-1)) {
cout<< 0<< endl;
  }
else if (X<vec.at(0)) {
cout<< 0<< endl;
}
  
     else {
  //戦略決定
  int left=0;
  int right=0;
  
  rep(i,M) {
    if(X>vec.at(i)) {
      left++;
    }
    else {
      right++;
    }
  }
 int count=0;
       int counting=0;
  if(left>=right) {
    rep(i,M) {
      
      if(X<vec.at(i)) {
        count++;
      }
    }
      cout<< count<< endl;
    
  }
       else if (left<right) {
         rep(i,M) {

           if(X>vec.at(i)) {
             counting++;
           }
         }
           cout<<counting<< endl;
         
       }
       
       
     }
     
     
     
     
     
     
     }
    

    
    


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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	if(n % 2 == 0){
		cout << n / 2 - 1 << endl;
	}else{
		cout << n / 2 << endl;
	}

}


Measured memory_bytes: 256
import sys
from math import gcd
stdin = sys.stdin

n = int(input())
an = list(map(int, stdin.readline().split()))
bn = []

m = max(an)
ls = [i for i in range(m+1)]
for i in range(2, m+1):
    if ls[i] == i:
        for j in range(2, m//i+1):
            ls[i*j] = i
#print(ls)

def primeset(t):
    ls2 = set()
    while t != 1:
        ls2.add(ls[t])
        t = t//ls[t]
    return ls2
#print(primeset(6))


primes= set()
for i in an:
    for j in primeset(i):
        if j in primes:
            break
    else:
        primes |= primeset(i)
        continue
    break
else:
    print("pairwise coprime")
    exit(0)

GCD = an[0]
for i in range(1, n):
    GCD = gcd(GCD, an[i])
if GCD == 1:
    print("setwise coprime")
else:
    print('not coprime')

Measured memory_bytes: 127512
#include <cstdio>
#include <cmath>

const long double pi=asin(1.)*2;

int main()
{
  int n;
  long long L;
  scanf("%d%lld",&n,&L);
  long double T[3010];
  for(int i=0;i<n;i++){
    long long t;
    scanf("%lld",&t);
    T[i]=2.*pi*t/L;
  }
  long double ansx=0,ansy=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      long double m0=(T[i]+T[j])/2,m1=m0+pi;
      ansx+=cos(m0)*(n-(j-i)-1)+cos(m1)*(j-i-1);
      ansy+=sin(m0)*(n-(j-i)-1)+sin(m1)*(j-i-1);
    }
  }
  ansx/=(long long)n*(n-1)*(n-2)/6;
  ansy/=(long long)n*(n-1)*(n-2)/6;
  printf("%.15Lf %.15Lf\n",ansx,ansy);
  return 0;
}


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

using namespace std;
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define pll pair<ll,ll>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

bool pallan(string s){
    ll i=0,j=s.size()-1;
    while(i<j){
        if(s[i]!=s[j])
            return false;
        i++;
        j--;
    }
    return true;
}
unordered_map<ll,ll> dp,vis;
ll find(ll n,vector<pll> &v,ll k,ll i){
    if(k<=0)
        return 0;
        
    if(vis[k]==1)
        return dp[k];
        
    ll ans = INT_MAX;
    for(ll j=0;j<n;j++){
        ans = min(ans,v[j].ss+find(n,v,k-v[j].ff,j+1));
    }
    vis[k] = 1;
    dp[k] = ans;
    return dp[k];
    
}

int main() {
    fio;
    
    ll k,n;cin>>k>>n;
    
    std::vector<pair<ll,ll>> v ;
    for(ll i=0;i<n;i++){
        ll a,b;cin>>a>>b;
        v.push_back({a,b});
    }
    
    
    cout<<find(n,v,k,0);
	return 0;
}

Measured memory_bytes: 1792