akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

c = 0
tmp = 0
m = []
for i in range(n):
    if a[i] < b[i]:
        c += 1
        tmp -= (b[i]-a[i])
    else:
        m.append(a[i]-b[i])

if tmp == 0:
    print(0)
    exit()

m.sort(reverse=True)
i = 0
while i < len(m):
    tmp += m[i]
    i += 1
    if tmp >= 0:
        print(c+i)
        exit()
        break
print(-1)    

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

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

ll N;
int main() {
  cin >> N;
  int OTEHON[10];
  int P[10];
  int Q[10];
  for(int i=0; i<N; i++) {
      cin >> P[i];
  }

  for(int i=0; i<N; i++) {
      cin >> Q[i];
  }

  for(int i=0; i<N; i++) {
      OTEHON[i] = i+1;
  }

  sort (OTEHON, OTEHON+N);

  ll count = 1;
  ll a = 0;
  ll b = 0;

  do {
    bool isP = true;
    bool isQ = true;
    for(int i=0; i<N; i++) {
        if (OTEHON[i] != P[i]) {
            isP = false;
        }
        if (OTEHON[i] != Q[i]) {
            isQ = false;
        }
    }

    if (isP) {
        a = count;
    }
    if (isQ) {
        b = count;
    }

    count++;
  } while ( std::next_permutation(OTEHON,OTEHON+N) );

  cout << abs(a-b) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
void say(string s){
	cout << s << endl;
	exit(0);
}
struct Edge{
	int to;
	int cost;
};

int RR;
vector<int> val;
vector<vector<Edge>> g;
vector<bool> done;

void dfs(int x,int v,bool first,int &rmi,int &cmi){
	if( done[x] ) return;
	else done[x] = true;
	
	if( first ) val[x] = 0;
	else val[x] = v;
	
	if( x >= RR ) cmi = min(cmi,val[x]);
	else rmi = min(rmi,val[x]);	
	
	for( auto e : g[x] ){
		dfs(e.to, e.cost - val[x], false, rmi, cmi );
	}
	
}
void solve(long long R, long long C, long long N, vector<long long> r, vector<long long> c, vector<long long> a){
	RR = R;
	auto row = [&](int x){ return x; };
	auto col = [&](int x){ return R+x; };
	g.resize(R+C);
	val.resize(R+C);
	done.resize(R+C);
	for(int i = 0 ; i < N ; i++){
		r[i]--;
		c[i]--;
		g[row(r[i])].push_back({col(c[i]),a[i]});
		g[col(c[i])].push_back({row(r[i]),a[i]});		
	}
	for(int i = 0 ; i < R + C ; i++){
		int rmi = 1e18;
		int cmi = 1e18;
		dfs(i,-1,true,rmi,cmi);
		
		if( rmi + cmi < 0 ) say("No");
		
	}
	for(int i = 0 ; i < N ; i++)
		if( val[row(r[i])] + val[col(c[i])] != a[i] ) say("No");

	say("Yes");
	
	
	
	
}
 
 
 
signed main(){	
	ios::sync_with_stdio(false);
	long long R;
	long long N;
	long long C;
	cin >> R;
	cin >> C;
	cin >> N;
	vector<long long> r(N-1+1);
	vector<long long> a(N-1+1);
	vector<long long> c(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		cin >> r[i];
		cin >> c[i];
		cin >> a[i];
	}
	solve(R, C, N, r, c, a);
	return 0;
}

Measured memory_bytes: 21248
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 998244353
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll v[12] = {0,2,0,1,0,1,0,0,1,0,1,0};
    ll x,y; cin >> x >> y; x--; y--;
    if(v[x]==v[y]) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 256
from itertools import accumulate

n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cost = 0
cnt = 0

a = [0] + list(accumulate(a))
b = [0] + list(accumulate(b))

ans = 0

b_cnt = m

for a_cnt in range(n+1):
    if a[a_cnt] > k:
        continue

    while b[b_cnt] > k - a[a_cnt]:
        b_cnt -= 1

    ans = max(ans, a_cnt + b_cnt)

print(ans)

Measured memory_bytes: 42228
#include <iostream>
#include <stack>
#define MAX 100
using namespace std;

enum Color {
  WHITE, GRAY, BLACK
};

int G[MAX][MAX];
int n;
int d[MAX];
int f[MAX];
Color color[MAX];
int cur_time;


void dfs_init() {
  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
  }
  cur_time = 0;
}

void dfs_main(int v) {
  if (color[v] == BLACK) return;
  color[v] = GRAY;
  d[v] = ++cur_time;
  for (int i = 0; i < n; i++) {
    if (G[v][i] && color[i] == WHITE) {
      dfs_main(i);
    }
  }
  color[v] = BLACK;
  f[v] = ++cur_time;
}

void dfs() {
  dfs_init();
  for (int i = 0; i < n; i++) {
    dfs_main(i);
  }
}


int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      G[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int vi, out_v_num;
    cin >> vi;
    cin >> out_v_num;
    for (int j = 0; j < out_v_num; j++) {
      int out_vi;
      cin >> out_vi;
      G[vi-1][out_vi-1] = 1;
    }
  }

  dfs();

  for (int i = 0; i < n; i++) {
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
  return 0;
}



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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    string S;
    cin >> S;
    int ans = 0;
    char first = 'a' - 1;
    string current = "";
    current += first;
    int i = 0;
    bool finish = false;
    while (i < S.length()) {
        string target = "";
        target += S[i];
        if (current != target) {
            ans++;
            current = target;
            i++;
        } else {
            int j = 0;
            while (current == target) {
                j++;
                if (i+j == S.length()) {
                    finish = true;
                    break;
                }
                target += S[i+j];
            }
            if (finish) {
                break;
            }
            ans++;
            current = target;
            i += j+1;
        }
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 640
q, h, s, d = list(map(int, input().split()))
n = int(input()) * 4

p = sorted([(q, 8), (h, 4), (s, 2), (d, 1)], key=lambda x: x[0] * x[1])
ans = 0
for v, i in p:
    ans += n // (8 // i) * v
    n = n % (8 // i)
print(ans)

Measured memory_bytes: 3064
class UnionFind():
    # 負の値はルートで集合の個数
    # 正の値は次の要素を返す
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    # 集合の代表を求める
    def find(self, x):
        while self.table[x] >= 0:
            # 根に来た時,self.table[根のindex]は負の値なのでx = 根のindexで値が返される。
            x = self.table[x]
        return x

    # 併合
    def union(self, x, y):
        s1 = self.find(x)  # 根のindex,table[s1]がグラフの高さ
        s2 = self.find(y)
        if s1 != s2:  # 根が異なる場合
            if self.table[s1] != self.table[s2]:  # グラフの高さが異なる場合
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                # グラフの長さが同じ場合,どちらを根にしても変わらない
                # その際,グラフが1長くなることを考慮する
                self.table[s1] += -1
                self.table[s2] = s1
        return


n, m = [int(i) for i in input().split()]
a = [0 for i in range(m)]
b = [0 for i in range(m)]
for i in range(m):
    a[i], b[i] = [int(i) - 1 for i in input().split()]

count = 0
for i in range(m):
    # 辺iが橋であるかを判定
    union = UnionFind(n)
    for j in range(m):
        if j != i:
            union.union(a[j], b[j])
    root = union.find(0)
    for j in range(1, n):
        if union.find(j) != root:
            count += 1
            break
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*int h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a;*/


	/*int h, n;
	cin >> h >> n;
	int s = 0;
	int a;
	rep(i, n) {
		cin >> a;
		s += a;
	}
	if (s >= h)puts("Yes");
	else puts("No");*/


	int n, k;
	cin >> n >> k;
	vector<ll>h(n);
	rep(i, n)cin >> h[i];
	ll ans = 0;
	int mi = min(n, k);
	sort(all(h));
	rep(i, n - mi) {
		ans += h[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N,K=LI()

BUF=[0]*(K+1)
for i in reversed(range(1, K+1)):
    pat = POW(K//i, N)
    for j in range(2, K+1):
        if i*j <= K:
            pat -= BUF[i*j]
        else:
            break
    # print("pat:{} i:{}".format(pat, i))
    BUF[i] = pat

res = 0
for i, j in enumerate(BUF):
    res += (i*j) % DVSR
print(res%DVSR)


Measured memory_bytes: 69060
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<int>())
using namespace std;
int main()
{
  speed_up;
  ll a, b, x, c, d;
  cin>>a>>b>>x;
  a = a - 1;
  if(a>=0) c = a/x + 1;
  else c = 0;

   d = b/x + 1;
   cout<<d - c<<endl;

  return 0;
}



Measured memory_bytes: 3644
import math

def manhattan(xs, ys):
    return sum([abs(x-y) for x, y in zip(xs, ys)])

def euclid(xs, ys):
    return math.sqrt(sum([(x-y)**2 for x, y in zip(xs, ys)]))

def l3(xs, ys):
    return sum([abs(x-y)**3 for x, y in zip(xs, ys)])**(1/3)

def chev(xs, ys):
    return max([abs(x-y) for x, y in zip(xs, ys)])

def norm():
    n = int(input())
    xs = list(map(int, input().split()))
    ys = list(map(int, input().split()))
    print(manhattan(xs, ys))
    print(euclid(xs, ys))
    print(l3(xs, ys))
    print(chev(xs, ys))

norm()

Measured memory_bytes: 7788
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 2000005; // RE :()
const int M = 500005;
int p[N];
int nxt[M],ans[M],ok[M];
string s, t,tmp;
void KMP(){
	// bug :(
	int n = tmp.size();
	int t_size = t.size();
	int len = max(tmp.size(), t.size()) * 2;
	while (s.size() < len) s += tmp;
	s = t + "#" + s;
	len = s.size();
	for(int i=1;i<len;++i){
		int j = p[i-1];
		while (j && s[i] != s[j]) j = p[j-1];
		if (s[i] == s[j]) j++;
		p[i] = j;
	}
	memset(nxt, -1, sizeof(nxt));
	// create graph.
	for(int i= len - n;i<len;++i){
		if (p[i] == t_size) nxt[(i - t_size + 1) % n] = (i + 1) % n;	
	}
	int res = 0, cnt = 0;
	bool cycle = 0;
	for(int i=0;i<n;++i){
		if (!ok[i] && nxt[i] != -1){
			int j = i;
			ok[j] = ++cnt; // create new DAG component.
			ans[cnt] = 0;
			while (nxt[j] != -1){
				j = nxt[j];
				ans[cnt]++;
				if (ok[j]) { 
					if (ok[j] == cnt || ans[ok[j]] == -1) {
						ans[cnt] = -1; 
						cycle = 1;
					}
					else ans[cnt] += ans[ok[j]];
					break; 
				}
				ok[j] = cnt;
			}
			res = max(res, ans[cnt]);
		}
	}
	// for(int i=0;i<n;++i) cout << ok[i] << ' ';
	cout << (!cycle ? res : -1);
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> tmp >> t;
	KMP();
}


Measured memory_bytes: 19092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,j;
    cin >> n;
    vector<int> i(n);
    for(j=0;j<n;j++){
        cin >> i.at(j);
    }
    int max=0;
    for(j=0;j<n;j++){
        if(i.at(j)>=max){
            max=i.at(j);
        }
    }
    int min=10000;
    for(j=0;j<n;j++){
        if(i[j]<=min){
            min=i.at(j);
        }
    }
    cout << max-min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep0(i, n) for(int i=0; i<(int)(n);i++)
typedef int64_t lint;
using namespace std;

int main(){
    lint n, k;
    cin >> n >> k;
    vector<lint> a(n);
    rep0(i, n){
        cin >> a[i];
    }

    lint ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            lint left = 0; //中に
            lint right = 0; //中に
            if(a[i] > a[j]){
                if(i > j)left ++ ;
                if(i < j)right ++ ;
            }
            ans += (k * (k - 1) * (right + left))/2 + k * right; //中に
            ans %= 1000000007; //中に
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
n = int(input())
S = list(input())
ANS = []
a = 0
b = 0
for s in S:
    ANS.append(s)
    if s == '(':
        a += 1
        #print(ANS)
    else:
        b += 1
        if a<b:
            a += 1
            ANS.insert(0,'(')
        #print(ANS)
for i in range(a-b):
    ANS.append(')')
print("".join(ANS))


Measured memory_bytes: 3316
package main
import(
  "fmt"
)
  func main(){
    var n, i, x, a, temp int 
    ans:=1
    fmt.Scan(&n)
    c:=make([]int, 100000)
    for i=0;i<n;i++{
      fmt.Scan(&a)
      c[a]++
    }
    // c[b] = a[i] == b なる i の個数

    for x=1;x<99999;x++{
      temp=c[x-1]+c[x]+c[x+1]
      if temp>ans{
        ans=temp
      }
    }
  fmt.Println(ans)
}



Measured memory_bytes: 5504
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#define mp make_pair
#define pb push_back
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const ll INF=10000000000;
const int DMAX=100000+5;
const int MOD=6000000;
template<class T> inline void read(T &x){
    x=0; 
    T f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch<='9' && ch>='0'){
        x=x*10+(ch-'0');
        ch=getchar();
    }
    x*=f;
}
int d;
int a[DMAX];
int main(){
	cin>>d;
	int ans=0;
	for(int i=1;i<=d;i++){
		cin>>a[i];
		ans+=a[i];
	}
	sort(a+1,a+d+1);
	ans-=(a[d]/2);
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main(){
  
  double a,b,h,m;
  
  cin >> a >> b >> h >> m ;
  double co = 30*h-5.5*m;
 double pi = 3.1415926535897932384626;
  
 
   printf("%.20lf\n", sqrt(a*a+b*b - 2*a*b*cos((co*pi)/180)));
  
}
  

Measured memory_bytes: 4228
import itertools
from math import atan2, sqrt

N = int(input())
A = [t for _ in range(N) if (t := tuple(map(int, input().split()))) != (0, 0)]

A.sort(key=lambda x: atan2(x[1], x[0]))

# 向きが同じエンジンは１つにまとめる
Ax, Ay = [], []
for _, v in itertools.groupby(A, key=lambda x: atan2(x[1], x[0])):
    sx, sy = 0, 0
    for vx, vy in v:
        sx += vx
        sy += vy
    Ax.append(sx)
    Ay.append(sy)

Nu = len(Ax)

Ax = [0] + list(itertools.accumulate(Ax * 2))
Ay = [0] + list(itertools.accumulate(Ay * 2))

ans = 0
for i in range(Nu + 1):
    for j in range(i + 1, min(i + Nu + 1, 2 * Nu + 1)):
        ans = max(ans, (Ax[j] - Ax[i]) ** 2 + (Ay[j] - Ay[i]) ** 2)

print(sqrt(ans))


Measured memory_bytes: 9516
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k,q = na()

a = [0]*n

for i in range(q):
    j = ni()
    a[j-1] += 1

b = [k-q+i for i in a]

for i in b:
    if i > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 8636
def main():
    N = int(input())
    *A, = map(int, input().split())

    tot = 0
    x = 0
    for a in A:
        tot += abs(x - a)
        x = a
    else:
        tot += abs(x)

    A = [0] + A + [0]
    ans = []
    for i in range(1, N + 1):
        ans.append(
            tot - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i - 1] - A[i + 1])
        )
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 14544
//デバッグ文入れたまま提出するとか、アホなのか…
#include <iostream>
#include <string>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1};

int h, w, q;
string s[2000];
int cntV[2001][2001];	//頂点数, 2次元累積和
int cntD[2001][2001];	//Σ次数, 2次元累積和
int cntEy[2001][2001];	//次数(縦方向), 横方向に累積和
int cntEx[2001][2001];	//次数(横方向), 縦方向に累積和

void input() {
	int i, j, dir;
	cin >> h >> w >> q;
	for (i = 0; i < h; i++) cin >> s[i];
	
	rep(i, h) rep(j, w) cntV[i + 1][j + 1] = s[i][j] - '0';
	rep(i, h) rep(j, w) cntV[i + 1][j + 1] += cntV[i + 1][j];
	rep(j, w) rep(i, h) cntV[i + 1][j + 1] += cntV[i][j + 1];
	
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '0') continue;
			rep(dir, 4) {
				int y = i + dy[dir];
				int x = j + dx[dir];
				if (!(0 <= y && y < h && 0 <= x && x < w)) continue;
				if (s[y][x] == '1') cntD[i + 1][j + 1]++;
			}
		}
	}
	rep(i, h) rep(j, w) cntD[i + 1][j + 1] += cntD[i + 1][j];
	rep(j, w) rep(i, h) cntD[i + 1][j + 1] += cntD[i][j + 1];
	
	rep(i, h - 1) {
		rep(j, w) {
			if (s[i][j] == '1' && s[i + 1][j] == '1') cntEy[i][j + 1] = 1;
		}
	}
	rep(i, h) rep(j, w) cntEy[i][j + 1] += cntEy[i][j];
	
	rep(i, h) {
		rep(j, w - 1) {
			if (s[i][j] == '1' && s[i][j + 1] == '1') cntEx[i + 1][j] = 1;
		}
	}
	rep(j, w) rep(i, h) cntEx[i + 1][j] += cntEx[i][j];
}

signed main() {
	input();
	
	for (int i = 0; i < q; i++) {
		int ly, lx, ry, rx;
		cin >> ly >> lx >> ry >> rx;
		ly--; lx--;
		
		int numOf1 = cntV[ry][rx] - cntV[ry][lx] - cntV[ly][rx] + cntV[ly][lx]; //いくつ1があるか？
		int numOfE = cntD[ry][rx] - cntD[ry][lx] - cntD[ly][rx] + cntD[ly][lx];
		
		if (ly - 1 >= 0) numOfE -= cntEy[ly - 1][rx] - cntEy[ly - 1][lx];
		if (ry - 1 >= 0) numOfE -= cntEy[ry - 1][rx] - cntEy[ry - 1][lx];
		if (lx - 1 >= 0) numOfE -= cntEx[ry][lx - 1] - cntEx[ly][lx - 1];
		if (rx - 1 >= 0) numOfE -= cntEx[ry][rx - 1] - cntEx[ly][rx - 1];
		numOfE /= 2;
		
		cout << numOf1 - numOfE << endl;
	}
	return 0;
}

Measured memory_bytes: 68480
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<string, set<int>> list;
    string s;
    int n;
    while(cin >> s >> n) list[s].insert(n);
    for(auto x : list)
    {
        cout << x.first << endl;
        bool flag = false;
        for(auto p : x.second)
        {
            if(flag) cout << " ";
            cout << p;
            flag = true;
        }
        cout << endl;
    }
    return 0;
}




Measured memory_bytes: 2976
import itertools
import math
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls = rils(n)
ds = [
    math.sqrt((x0 - x1)**2 + (y0 - y1)**2)
    for (x0, y0), (x1, y1) in itertools.combinations(ls, 2)
]
print((n - 1) * sum(ds) / len(ds))

Measured memory_bytes: 3064
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-05-14 17:01:02
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

#include <unordered_map>

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

  int n; cin >> n;
  vector<int64> a(n);
  cin >> a;

  for (int i = 1; i < n; ++i) a[i] += a[i - 1];

  int64 ans = 0;

  unordered_map<int64, int> mp;
  ++mp[0];

  for (int64 e : a) {
    ans += mp[e];
    ++mp[e];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 10056
from sys import stdin
input = stdin.readline
from collections import deque

N,M = [int(x) for x in input().split()]
next =[set() for _ in range(N+1)]

for i in range(M):
    A,B = [int(x) for x in input().split()]
    next[A].add(B)
    next[B].add(A)

opened = deque()
opened.append(1)

prev = [-1] * (N+1)
prev[1] = 1

while len(opened) != 0:
    target = opened.popleft()
    for n in next[target]:
        if prev[n] == -1:
            opened.append(n)
            prev[n] = target


print('Yes')
# for i in range(2,N+1):
#     print(prev[i])
print(" ".join([str(x) for x in prev[2:]]))

Measured memory_bytes: 120624
package main

import (
	"fmt"
	//"strconv"
)

func main() {
	var A,B,C int
	fmt.Scanf("%d %d %d",&A,&B,&C)
  if A==B || A==C || B==C{
    if A==B&&B==C{
      fmt.Print("No")
    }else{
     fmt.Print("Yes")
    }
  }else{
    fmt.Print("No")
  }
}

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

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

	int num,count;
	if(a < b){
		num=a;
		count=b;
	}else{
		num=b;
		count=a;
	}

	for(int i=0;i < count;i++){
		cout << num;
	}

	cout << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i)-1 = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main()
{	
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    REP(i, n) cin >> v[i];

    REP(i, n-k){
        bool ok = false;
        if(v[i+k] > v[i]) ok = true;
        if(ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

}


Measured memory_bytes: 4764
#include <cstdint>
#include <iostream>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

} // namespace null_null

#include <vector>
#include <math.h>

namespace null_null {

void main_() {
  usize N;
  std::cin>>N;
  std::vector<i32>B(N-1);
  for(usize i=0;i<N-1;i++){
    std::cin>>B[i];
  }

  i32 ans=B[0]+B[N-2];
  for(usize i=1;i<N-1;i++){
    ans+=std::min((int)B[i-1],(int)B[i]);
  }

  std::cout<<ans<<std::endl;
}

} // namespace null_null

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  null_null::main_();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 +5;
long long a[N];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	long long ans=0;
	for(int i=0;i<n-k;i++) ans+=a[i];
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int cnt = 0;

        for (int i = a; i <= b; i++) {
            if((c % i) == 0) {
                cnt++;
            }
        }
        System.out.println(cnt);
        sc.close();
    }
}


Measured memory_bytes: 26408
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  int N;
  cin >> N;
  vector<int> difficulty(N);
  rep(i, N) cin >> difficulty[i];
  std::sort(difficulty.begin(), difficulty.end());
  int answer = difficulty[N/2] - difficulty[N/2 - 1];
  cout << answer << '\n';
}


Measured memory_bytes: 640
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    S = [0] * N
    for _ in range(K):
        d = int(input())
        A = [int(a) for a in input().split()]
        for a in A: S[a-1] += 1
    print(S.count(0))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9192
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int w, h, n;
    cin >> w >> h >> n;
    int x[n], y[n], a[n];
    int b[4] = {0, w, 0, h};
    rep(i, n){
        cin >> x[i] >> y[i] >> a[i];
        a[i]--;
        if(a[i] == 0){
            b[a[i]] = max(b[a[i]], x[i]);
        }else if(a[i] == 1){
            b[a[i]] = min(b[a[i]], x[i]);
        }else if (a[i] == 2){
            b[a[i]] = max(b[a[i]], y[i]);
        }else{
            b[a[i]] = min(b[a[i]], y[i]);
        }
    }
    cout << (max(0, b[1] - b[0]) * max(0, b[3] - b[2])) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using l1 = long long;
int conv(int a,int b){
    int s=1;int t=1;int u=1;
    rep(i,a){
        s*=i+1;
    }
    rep(i,a-b){
        t*=i+1;
    }
    rep(i,b){
        u*=i+1;
    }

    return s/t/u;
}

l1 sum(l1 l,l1 r){
    return (l+r)*(r-l+1)/2;
}

int main(){
    int n,k;
    cin>>n>>k;
    cin>>n>>k;
    int a[n+1];
    rep(i,n+1)a[i]=i;
    
    l1 ans;

    for(int i=k;i<=n+1;++i){
        l1 l = sum(0,i-1), r = sum(n-i+1,n);
        ans+=r-l+1;
    }

    cout<<ans%1000000007<<endl;

    return 0;
}

Measured memory_bytes: 4320
S=list(input())

total=0
if len(S)%2==0:
    for i in range(int(len(S)/2)):
        if S[i]!=S[len(S)-1-i]:
            total+=1
    print(total)
else:
    for i in range(int((len(S)-1)/2)):
        if S[i]!=S[len(S)-1-i]:
            total+=1
    print(total)

Measured memory_bytes: 38384
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n; cin >> n;
	rep(i, n) {

		int Point = 0, Out = 0;
		VI rui(3);

		while (Out != 3) {
			string s; cin >> s;

			if (s == "HIT") {
				Point += rui[2];
				rui[2] = rui[1];
				rui[1] = rui[0];
				rui[0] = 1;
			}
			else if (s == "HOMERUN") {
				Point += rui[0] + rui[1] + rui[2] + 1;
				rui[0] = 0; rui[1] = 0; rui[2] = 0;
			}
			else if (s == "OUT") {
				Out++;
			}
		}

		Cout(Point);
	}
}


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

ll solve() {
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> A(N, vector<ll>(M));
    for ( int n = 0; n < N; n++ ) {
        for ( int m = 0; m < M; m++ ) {
            cin >> A[n][m];
        }
    }

    auto check = [&](ll k) {
        vector<int> ix(N);
        vector<int> num(M+1);
        vector<int> ng(M+1);
        for ( int n = 0; n < N; n++ ) {
            num[A[n][0]]++;
        }
        for(;;) {
            bool ok = true;
            for ( int m = 1; m <= M; m++ ) {
                if ( num[m] > k ) {
                    ng[m]++;
                    ok = false;
                }
            }
            if ( ok ) return true;
            for ( int n = 0; n < N; n++ ) {
                while ( ng[A[n][ix[n]]] > 0 ) {
                    num[A[n][ix[n]]]--;
                    ix[n]++;
                    if ( ix[n] >= M ) return false;
                    num[A[n][ix[n]]]++;
                }
            }
        }
        return false;
    };

    ll l = 0, r = N+1;
    while ( r - l > 1 ) {
        ll m = (l+r)/2;
        if ( check(m) ) r = m;
        else l = m;
    }
    return r;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int A, B; cin >> A >> B;
  cout << max((LL)0, A - 2*B) << endl;
  return 0;
}


Measured memory_bytes: 256
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let mut v:Vec<usize> = Vec::new();
    for i in 0..9 {
        let va:usize = read!();
        v.push(va);
    }
    let mut n:usize = read!();
    for i in 0..n {
        let c:usize = read!();
        for j in 0..9 {
            if c==v[j] {
                v[j] = 0;
            }
        }
    }
    for i in 0..3 {
        if v[i] == v[i+3] && v[i] == v[i+6] {
            println!("Yes");
            exit(0);
        }
    }
    for i in 0..3 {
        if v[i*3] == v[i*3+1] && v[i*3] == v[i*3+2] {
            println!("Yes");
            exit(0);
        }
    }
    if v[0] == v[4] && v[0] == v[8] {
        println!("Yes");
        exit(0);
    }
    if v[2] == v[4] && v[2] == v[6] {
        println!("Yes");
        exit(0);
    }
    println!("No");
}

Measured memory_bytes: 2144
#created by  nit1n
N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
for i in  range(N) :
    for j in range (S+1) :
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] = dp[i+1][j]%mod
        if j +A[i] <= S :
            dp[i+1][j+A[i]] += dp[i][j] 
            dp[i+1][j+A[i]] %= mod


print(dp[N][S])

            
            


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

int main() {
    int a, b; cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0) {
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }
}


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

int main(){
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    for(int i=0; i*r<=n; i++){
        for(int j=0; j*g<=n; j++){
            if((-r*i - g*j + n) % b == 0 && (-r*i - g*j + n) >= 0) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long num = sc.nextLong();
        long sum = 0;
        long min = 1000000000000l;
        double num2 = Math.sqrt(num);
        long num3 = (long)num2+1;
        for(long i=1;i<=num3;i++)
        {
            if(num%i==0)
            {
                sum = num/i-1 + i-1;
            }
            if(sum<min)
            {
                min = sum ;
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 23764
import java.util.*;

import javax.xml.crypto.Data;
public class Main{

	public static void main(String[] args) {
		for(int i = 1; i <= 9; ++i)
			for(int n = 1; n <= 9; ++n)
				System.out.println(i+"x"+n+"="+i*n);
	}

}

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

using namespace std;
using i64 = long long;
using vi64 = vector<i64>;

i64 n;
vi64 a;
vi64 c;

void add(int x) {
  while (x <= n * 3) {
    c[x]++;
    x += x & -x;
  }
}

i64 sum(int x) {
  i64 s = 0;
  while (x) {
    s += c[x];
    x -= x & -x;
  }
  return s;
}

bool check(i64 md) {
  vi64 s(n + 1);
  rep(i, n) {
    if (a[i] >= md) {
      s[i + 1] = s[i] + 1;
    } else {
      s[i + 1] = s[i] - 1;
    }
  }
  i64 cnt = 0;
  c = vi64(n * 5);
  rep(i, n + 1) {
    cnt += sum(s[i] + n + 1);
    add(s[i] + n + 1);
  }
  return cnt >= ((i64) n * (n + 1) / 2 + 1) / 2;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  cin >> n;
  a = vi64(n);
  rep(i, n) cin >> a[i];
  i64 ok = 0, ng = 1e9 + 1;
  while (ng - ok > 1) {
    i64 md = (ok + ng) / 2;
    if (check(md)) {
      ok = md;
    } else {
      ng = md;
    }
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 9704
using System;
using System.Linq;
using System.Collections.Generic;
namespace abc083b
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] str = Console.ReadLine().Split(' ');
            int n = int.Parse(str[0]);
            int a = int.Parse(str[1]);
            int b = int.Parse(str[2]);

            int sum = 0;
            for (int i = 1; i <= n; i++)
            {
                int num = 0;

                var strN = i.ToString();
                foreach (var item in strN)
                {
                    num += Convert.ToInt32(item.ToString());
                }

                if (num >= a && num <=  b)
                {
                    sum += i;
                }
            }
            Console.WriteLine(sum);

        }
    }
}


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

int e[4];

int main() {
  cin >> e[0] >> e[1] >> e[2] >> e[3];
  sort(e,e+4);
  if(e[0] == e[1] && e[2] == e[3]) {
    cout << "yes" << endl;
  }else {
    cout << "no" << endl;
  }
}

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

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define _shv(v) for (auto _t1 : v) cerr << _t1 << " "; cerr << endl;
#define dg(x) cerr << #x << ": " << (x) << endl;
#define dgv(v) cerr << #v << ": "; _shv(v);
#define dgm(m) cerr << #m << ":" << endl; for (auto _t2 : m) { _shv(_t2); }

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

template<typename T> inline void pt(T x) { cout << x << endl; }
template<typename T> inline void inv(T& v) { for (auto& t : v) cin >> t; }
template<typename T> inline int siz(T& x) { return x.size(); }
template<typename T> inline ll pow2(T n) { return 1ll << n; }
template<typename T, typename U> inline int bit(T x, U n) { return x >> n & 1; }
template<typename T, typename U>
inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }


int main() {
    int n; cin >> n;
    vi r(n), c(n);
    rep(i, n) cin >> r[i] >> c[i];
    vvl dp(n, vl(n, 0));
    rep(i, 1, n) {
        rep(j, n - i) {
            dp[j][j + i] = INF;
            rep(k, i) {
                umin(dp[j][j + i],
                    dp[j][j + k] + dp[j + k + 1][j + i] +
                    r[j] * c[j + i] * c[j + k]
                );
            }
        }
    }
    pt(dp[0][n - 1]);

    return 0;
}



Measured memory_bytes: 3220
def pow(a,b):
    ans=1
    if b==0:
        return 1
    for i in range(b):
        ans=ans*a
        if ans > mod:
            ans=ans%mod
    return ans%mod
        
        
mod=1000000007

n=int(input())

if n==1:
    print(0)
else:
    ans=pow(10,n)+pow(8,n)-(pow(9,n)*2)
    print(ans%mod)


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s[3] = {"Sunny", "Cloudy","Rainy"};
    string i;
    cin >> i;
    if(i == s[0]) cout << s[1];
    else if(i==s[1]) cout << s[2];
    else if(i== s[2]) cout << s[0];
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<cstring>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;



#define MAX_V 1000
#define INF 10000000000

struct edge{int to;long long cap,rev;};

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,long long cap)
{
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}

void bfs(int s)
{
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty())
	{
		int v = que.front();que.pop();
		for(int i = 0;i < G[v].size();++i)
		{
			edge &e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0)
			{
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v ,int t,long long f)
{
	if(v == t)return f;
	for(int &i = iter[v];i < G[v].size() ;++i)
	{
		edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to])
		{
			long long d = dfs(e.to,t,min(f,e.cap));
			if(d > 0)
			{
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

long long Dinic(int s,int t)
{
	long long flow = 0;
	while(1)
	{
		bfs(s);
		if(level[t] < 0)return flow;
		memset(iter,0,sizeof(iter));
		long long f;while((f = dfs(s,t,INF)) > 0)flow += f;
	}
}

char mp[111][111];

int main()
{
	int h,w;cin >> h >> w;
	int sx,sy,tx,ty;
	
	REP(i,h)
	{
		REP(j,w)
		{
			cin >> mp[i][j];
			if(mp[i][j] == 'S')
			{
				add_edge(252,i,100000);
				add_edge(i,252,100000);
				add_edge(252,j+111,100000);
				add_edge(j+111,252,100000);
			}
			else if(mp[i][j] == 'T')
			{
				add_edge(i,256,100000);
				add_edge(256,i,100000);
				add_edge(j+111,256,100000);
				add_edge(256,j+111,100000);
			}
			else if(mp[i][j] == 'o')
			{
				add_edge(i,j+111,1);
				add_edge(j+111,i,1);
			}
		}
	}
	
		
	//cout << sy << ' ' << sx << ' ' << ty << ' ' << tx << endl;
	int ans = Dinic(252,256);
	if(ans >= 100000)
	{
		cout << -1 << endl;
		
	}
	else
	{
		cout << ans << endl;
	}

	return 0;
}

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

typedef long long ll;
const int N = 200054;

int n;
ll I, a[N], b[N];

void merge_sort(int L, int R) {
	if (L + 1 == R) return;
	int M = (L + R) / 2, i = L, j = M, c = L;
	merge_sort(L, M), merge_sort(M, R), memcpy(b + L, a + L, (R - L) << 3);
	for (; i < M && j < R; a[c++] = (b[i] <= b[j] ? b[i++] : (I += M - i, b[j++])));
	i < M ? memcpy(a + c, b + i, (M - i) << 3) : memcpy(a + c, b + j, (R - j) << 3);
}

int main() {
	int i, k;
	scanf("%d%d", &n, &k);
	for (i = 1; i <= n; ++i) scanf("%lld", a + i), a[i] += a[i - 1] - k;
	merge_sort(0, ++n), printf("%lld\n", n * (n - 1ll) / 2 - I);
	return 0;
}

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

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

int N;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N;

    int ans = N % 2 == 0 ? N : N * 2;
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n,m,l,i,j,k;
    int a[100][100]={{}},b[100][100]={{}};
    long c[100][100]={{}};

    cin >> n >> m >> l;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin >> a[i][j];
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            cin >> b[i][j];
        }

    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            cout << c[i][j];
            if(j!=l-1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3248