akhauriyash/Code-Regression huggingface dataset:
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn f(u: usize, p: usize, c: u64, edges: &Vec<Vec<(usize, u64)>>, depth: &mut Vec<u64>) {
    depth[u as usize] = c;
    for v in &edges[u] {
        if v.0 == p {
            continue;
        }
        f(v.0, u, c + v.1, edges, depth);
    }
}

fn dist(a: u32, b: u32) -> u32 {
    if a > b {
        a - b
    } else {
        b - a
    }
}

use std::collections::BTreeSet;

fn fun(
    u: usize,
    pvec: &Vec<usize>,
    edges: &Vec<Vec<usize>>,
    vals: &mut BTreeSet<usize>,
    nodes: &mut BTreeSet<usize>,
    checked: &mut BTreeSet<usize>,
) {
    if checked.contains(&u) {
        return;
    }
    checked.insert(u);
    nodes.insert(u);
    vals.insert(pvec[u]);
    for v in &edges[u] {
        fun(*v, pvec, edges, vals, nodes, checked);
    }
}

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];
    let ptmp: Vec<usize> = read_vec();
    let mut pvec: Vec<usize> = vec![1000000];
    for p in ptmp {
        pvec.push(p);
    }

    let mut edges: Vec<Vec<usize>> = vec![vec![]; n + 1];

    for _ in 0..m {
        let xy: Vec<usize> = read_vec();
        let x = xy[0];
        let y = xy[1];
        edges[x].push(y);
        edges[y].push(x);
    }

    let mut checked: BTreeSet<usize> = BTreeSet::new();

    let mut ans: u32 = 0;
    for i in 0..n {
        if checked.contains(&i) {
            continue;
        }
        let mut vals: BTreeSet<usize> = BTreeSet::new();
        let mut nodes: BTreeSet<usize> = BTreeSet::new();
        fun(i, &pvec, &edges, &mut vals, &mut nodes, &mut checked);
        for v in vals {
            if nodes.contains(&v) {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 22652
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	res := 0
	min := a[0]
	for i := 0; i < n; i++ {
		if a[i] <= min {
			res++
		}
		if a[i] < min {
			min = a[i]
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 3584
def solve():
    N,K=map(int,input().split())
    X=[0]*N
    Y=[0]*N
    for i in range(N):
        X[i],Y[i]=map(int,input().split())
    inf=1<<62
    ans=inf
    for x1 in X:
        for x2 in X:
            if x1 <= x2:
                for y1 in Y:
                    for y2 in Y:
                        if y1 <= y2:
                            cnt = 0
                            for i in range(N):
                                if x1 <= X[i] <= x2 and y1 <= Y[i] <= y2:
                                    cnt += 1
                            if cnt >= K:
                                ans = min(ans, (x2-x1)*(y2-y1))
    return ans

print(solve())


Measured memory_bytes: 46504
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;
import std.typecons;
 
alias Tuple!(int, "x", int, "y") Point;
 
auto move = [[-1, 0], [0, 1], [1, 0], [0, -1]];

void main(){
    string input;
    Point[200] points;
    while((input = readln.chomp) != "0"){
        int n = input.to!int;
        if(n == 1){
            "1 1".writeln;
            continue;
        }
        points[1..n] = Point.init;
        points[0] = Point(0, 0);
        foreach(i; 1..n){
            auto line = readln.split;
            int base = line[0].to!int;
            int dir = line[1].to!int;
            points[i] = Point(points[base].x + move[dir][0], points[base].y + move[dir][1]);
        }
        auto result = reduce!(q{max(a, b.x)}, q{min(a, b.x)}, q{max(a, b.y)}, q{min(a, b.y)})(tuple(0, 0, 0, 0), points[0..n]);
        writeln(result[0] - result[1] + 1, " ", result[2] - result[3] + 1);
    }
}

Measured memory_bytes: 1548
package main
import . "fmt"
import . "os"
func main() {
  var s,t string
  var n int
  Scan(&s)
  Scan(&t)
  n = len(s)
  for i:=0;i<n;i++ {
    s = s[n-1:n]+s[0:n-1]
    if s == t {
      Println("Yes")
      Exit(0)
    }
  }
  Println("No")
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int MAX = 6000;

int dp[MAX + 1];  // dp[i] : i分で得られる美味しさの最大値

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

    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> C(N);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        C[i] = make_pair(a, b);
    }
    sort(C.begin(), C.end());
    int ret = 0;
    for (int i = 0; i < N; i++) {
        int a = C[i].first, b = C[i].second;
        for (int j = min(MAX - a, T - 1); j >= 0; j--) {
            dp[j + a] = max(dp[j + a], dp[j] + b);
            ret = max(ret, dp[j + a]);
        }
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include    <iostream>
#include    <string>

using namespace std;

int main() {
    while(1) {
        int H, W;

        cin >> H >> W;
        if(H == 0 && W == 0) break;
        
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++)
                cout << (((i+j) % 2 == 0) ? '#' : '.');
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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

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

int main() {

  int n;
  cin >> n;
  vector<int> p(4);
  rep(i, 4) cin >> p[i];
  vector<int> t(4);
  rep(i, 4) cin >> t[i];

  int ans = 1000000000;
  for (int a = 0; a <= n; a++) {
    for (int b = 0; a + b <= n; b++) {
      for (int c = 0; a + b + c <= n; c++) {
        for (int d = 0; a + b + c + d <= n; d++) {
          if (a * t[0] + b * t[1] + c * t[2] + d * t[3] >= n) {
            ans = min(ans, a * p[0] + b * p[1] + c * p[2] + d * p[3]);
          }
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3104
from collections import Counter
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
v=[[] for i in range(m)]
for i in x:v[i%m].append(i)
a=0
for i in range(1,m//2+m%2):
  x,y=v[i],v[m-i]
  d=len(x)-len(y)
  if d<0:
    d=-d
    x,y=y,x
  c=sorted([p[1] for p in Counter(x).items()])
  p=0
  for t in c:
    p+=(t//2)
  a+=len(y)+min(p,(d//2))
a+=len(v[0])//2+(len(v[m//2])//2 if m%2==0 else 0)
print(a)

Measured memory_bytes: 76780
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < (n); ++i)
using namespace std;
using int64 = long long;

const string YES = "Yes";
const string NO = "No";

bool solve(int N, std::vector<std::string> S) {
  vector<int> lonly, ronly, lboth, rboth;
  vector<pair<int, int>> lr(N);

  REP(i, N) {
    int l = 0, r = 0;
    for (char c : S[i]) {
      if (c == '(') {
        l++;
      } else if (l > 0) {
        l--;
      } else {
        r++;
      }
    }
    lr[i] = make_pair(l, r);
    if (l == 0 && r == 0) {
      continue;
    } else if (r == 0) {
      lonly.push_back(i);
    } else if (l == 0) {
      ronly.push_back(i);
    } else if (l > r) {
      lboth.push_back(i);
    } else {
      rboth.push_back(i);
    }
  }
  sort(lboth.begin(), lboth.end(),
       [&](int i, int j) -> bool { return lr[i].second < lr[j].second; });
  sort(rboth.begin(), rboth.end(),
       [&](int i, int j) -> bool { return lr[i].first < lr[j].first; });

  int64 lstack = 0;
  for (int i : lonly) {
    assert(lr[i].second == 0);
    lstack += lr[i].first;
  }
  REP(i, lboth.size()) {
    int j = lboth[i];
    auto [l, r] = lr[j];
    if (r > lstack) {
      return false;
    }
    lstack += l - r;
  }

  int64 rstack = 0;
  for (int i : ronly) {
    assert(lr[i].first == 0);
    rstack += lr[i].second;
  }
  REP(i, rboth.size()) {
    int j = rboth[i];
    auto [l, r] = lr[j];
    if (l > rstack) {
      return false;
    }
    rstack += r - l;
  }

  return lstack == rstack;
}

int main() {
  int N;
  cin >> N;
  cin.ignore();
  std::vector<std::string> S(N);
  for (int i = 0; i < N; i++) {
    getline(cin, S[i]);
  }
  if (solve(N, std::move(S))) {
    cout << YES << endl;
  } else {
    cout << NO << endl;
  }
}


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

int main(){
  string  s,ans ="Good";
    cin >> s;
  rep(i,3){  
  if(s[i] == s[i+1]) ans ="Bad"; }
  
  cout << ans;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;

ll dp[100000 +10], w[100000 +10];
ll v[100000 +10];
int main()
{
	int n,m; cin>>n>>m;
	int i,j;
	for(i=1;i<=n;i++) cin>>w[i]>>v[i];
	
	for(i=1;i<=n;i++)
	{
		for(j=m;j>=w[i];j--)
		{
			dp[j] = max(dp[j] , dp[j-w[i]] + v[i]);
		}
	}
	printf("%lld\n",dp[m]);
	return 0;
}

Measured memory_bytes: 1152
def solve(s):
  turn = 'a'
  while True:
    if len(s[turn]) == 0:
      return turn.upper()
    nxt, s[turn] = s[turn][0], s[turn][1:]
    turn = nxt

s = {}
s['a']=raw_input()
s['b']=raw_input()
s['c']=raw_input()
print solve(s)

Measured memory_bytes: 2568
N = int(input())
A = list(map(int, input().split()))
A.append(0)

kabu = 0
en = 1000

for i in range(N):
    a, b = divmod(en, A[i])
    kabu += a
    en = b
    if A[i+1] < A[i]:
        en += kabu*A[i]
        kabu = 0

print(en)

Measured memory_bytes: 9176
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
vll B;
ll C;
ll N;
ll M;
vll ans;
bool is_prime[base10_6];

ll ltmp;
string stmp;
double dtmp;

/*
max 448,000,000
map<string,ll> count_map;
count_map['0']=0;
for(auto x : count_map) {
    string key = x.first;
    ll value = x.second;
}
*/



int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    map<ll,ll> count_map;
    map<ll,ll> pos_map;


    cin >> N;
    rep(ni,N){
        cin >> ltmp;
        A.push_back(ltmp);
        count_map[ltmp]++;
    }

    if(N==1){
        cout << 1 << endl;        
    }else if(count_map.count(1)>0){
        if(count_map[1]==1){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        sort(A.begin(),A.end());
        ll bef = -1;
        ll index = 0;
        rep(ai,A.size()){
            ll target = A[ai];
            if(bef!=target){
                bef = target;

                B.push_back(target);
                pos_map[target]=index;
                is_prime[index]=true;
                index++;
            }
        }
        ll cntB = index;

        for( ll number = 0 ; number < cntB ; number++ ){
            if(is_prime[number]){
                ll target = B[number];
                for( ll ni = target*2 ; ni <=B[cntB-1] ; ni+=target ){
                    if(count_map.count(ni)>0){
                        //cout << ni << endl;
                        index = pos_map[ni];
                        is_prime[index]=false;
                    }
                }
            }
        }

        ll cntans=0;
        rep(bi,cntB){
            ll target = B[bi];
            if(is_prime[bi] && count_map[target]==1){
                cntans++;
                //cout << target << endl;

            }
        }
        cout << cntans << endl;


    }



}

Measured memory_bytes: 31548
N = gets.to_i
a = gets.split.map &:to_i
money = 1000
stock = 0

for n in 1..N-1
  if a[n-1] < a[n]
    stock = money / a[n-1]
    money = money + (a[n] - a[n-1]) * stock
  end
end

puts money


Measured memory_bytes: 14352
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> cnt1;
    rep(i, N) {
        cin >> A[i];
        ll num1 = A[i] + i;
        cnt1[num1]++;
    }

    ll res = 0;
    rep(j, N) {
        if (cnt1[j - A[j]] > 0)
            res += cnt1[j - A[j]];
    }

    cout << res << endl;
}

Measured memory_bytes: 27456
N=int(input())
abc=[[] for _ in range(N)]

for i in range(N):
    abc[i]=list(map(int,input().split()))

dp=[[0,0,0] for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(3):#新しく選ぶもの
        for k in range(3):#選ぶもの
            if k!=j:
                dp[i][j]=max(dp[i][j] , dp[i-1][k]+abc[i-1][k])
                

print(max(dp[-1]))

Measured memory_bytes: 73248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for(auto& i:mp)

int main() {
  int k;
  cin >> k;
  ll ans = 0;
  repr(a,1,k+1){
    repr(b,1,k+1){
      repr(c,1,k+1){
        ans += gcd(gcd(a,b),c);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


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

// flagを用いたバブルソート
int bubbleSort(int A[], int N)
{
  int sw = 0;
  bool flag = true;

  for (int i = 0; flag; i++)
  {
    flag = false;
    for (int j = N - 1; j >= i + 1; j--)
    {
      if (A[j] < A[j - 1])
      {
        // 隣接要素を交換する
        swap(A[j], A[j - 1]);
        flag = true;
        sw++;
      }
    }
  }
  return sw;
}

int main()
{
  int A[100], N, sw;

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

  for (int i = 0; i < N; i++)
  {
    if (i)
    {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}


Measured memory_bytes: 3112
S = int(input())
# この四角形をつくる
sqrtS = int(S**0.5)
if sqrtS**2 < S:
    sqrtS+=1
# 約数
# def make_divisors(n):
#     divisors = []
#     for i in range(1, int(n**0.5)+1):
#         if n % i == 0:
#             divisors.append(i)
#             if i != n // i:
#                 divisors.append(n//i)
#     return divisors

# こいつの約分で、選ぶ
diff = sqrtS**2-S
# divs = sorted(make_divisors(diff))
# n = len(divs)

x0,y0 = (0,0)
if diff == 0:
    x1,y1 = (0,sqrtS)
    x2,y2 = (sqrtS,0)
else:
    x1,y1 = (diff,sqrtS)
    x2,y2 = (sqrtS, 1)

print(x0,y0,x1,y1,x2,y2)

# S = sqrtS**2-x1*y2
# print(S)

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

int h, w;
long long bl = 0, wh = 0;
const int MAXI = 410;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

vector<string> S;

bool seen[MAXI][MAXI];

void dfs(int x, int y){
    
    // 到達済みにする
    seen[x][y] = true;
    
    // カウント(*)
    if(S[x][y] == '#') bl++;
    else wh++;
    
    // いけるとこまでいく
    for(int i = 0; i < 4; i++){
        int nx, ny;
        nx = x + dx[i];
        ny = y + dy[i];

        // ありえんところ
        if(nx < 0 or ny < 0 or nx >= h or ny >= w){
            continue;
        }
        
        // 移動前と同じ色 or 到達済み
        if(S[x][y] == S[nx][ny] or seen[nx][ny]){
            continue;
        }

        // (*)を[nx][ny]としてここに書いていたが，
        // 黒白のみのときにカウントされない(2ペア以降からのカウントになる)
        dfs(nx, ny);
    }
}

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

    cin >> h >> w;
    S.resize(h);
    for(int i = 0; i < h; i++){
        cin >> S[i];
    }

    long long ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(S[i][j] == '.'){
                continue;
            }
            bl = 0, wh = 0;
            dfs(i, j);
            ans += bl * wh;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 18048
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            WriteLine(tmp[1] / tmp[0] > tmp[2] ? tmp[2] : tmp[1] / tmp[0]);
        }
    }
}

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

int main(){
    string s;
    int k, one = 0;
    cin >> s >> k;

    for(auto a:s){
        if(a == '1'){ one++; }
        else{ break; }
    }

    cout << (k <= one ? '1' : s[one]) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll n; string s;
    cin>>n>>s;
    ll sum=0;
    ll r=0,g=0,b=0;
    rep(i,n){
        if(s[i]=='R')r++;
        if(s[i]=='G')g++;
        if(s[i]=='B')b++;
    }
    sum=r*g*b;
    for(int i=0; i<n; ++i){
        for(int j=i+1; j<n; ++j){
            ll k=j*2-i;
            if(k>=n||i==j)continue;
            if(s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i])sum--;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3612
#include <stdio.h>

int main(){
  char s[4];
  int ans[3] = {};
  int i;
  scanf("%s",s);
  for(i = 0;i < 3;i++){
    switch(s[i]){
      case 'a':
        ans[0] = 1;
        break;
      case 'b':
        ans[1] = 1;
        break;
      case 'c':
        ans[2] = 1;
    }
  }
  if(ans[0] == 1 && ans[1] == 1 && ans[2] == 1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return(0);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
map<char,int> p;
int d[30005][4];
int main(){
	int n,ans=0;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<=999;i++){
		int a=i/100;
		int b=(i%100)/10;
		int c=i%10;
		int num[3]={a,b,c};
		int pos=0;
		for(int j=0;j<n;j++){
			if(s[j]=='0'+num[pos]){
				pos++;
			}
			if(pos==3) break;
		}
		if(pos==3) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   int a,l,k=0,i,s;
   cin>>a>>l;
   if(l%2!=0 ) {
        k=1;cout<<"No"<<endl;
   }
   else
   {
       for(i=a;i>=1;i--)
       {
           s=l-i*2;
           if(s%4==0)
           {
               if((s/4)+i==a){
                    k=1;
                cout<<"Yes"<<endl;
               return 0;
               }
           }

       }
       s=l;
       for(i=a;i>=1;i--)
       {
           s=l-i*4;
           if(l%2==0)
           {
               if((s/2)+i==a){
                    k=1;
                cout<<"Yes"<<endl;
             return 0;
               }
           }

       }
   }
  if(k==0)  cout<<"No"<<endl;

}


Measured memory_bytes: 3604
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, K):
    r = set([0])
    for i in range(1, math.floor(math.sqrt(N))+1):
        r.add(N//i)
        r.add(i)
    r = list(r)
    r.sort()
    # print(r)

    m = {}
    for i in range(len(r)-1):
        m[i+1] = r[i+1]-r[i]
    DP1 = {k: v for k, v in m.items()}
    DP2 = {}
    M = Mod(10**9+7)
    for _ in range(K):
        S = [0]
        for k in range(1, len(DP1)+1):
            S.append(M.add(S[-1], DP1[k]))
        for k in DP1:
            DP2[k] = M.mul(S[len(DP1)-k+1], m[k])
        DP1, DP2 = DP2, DP1
        # print(DP1)

    ans = 0
    for v in DP2.values():
        ans = M.add(ans, v)
    return ans


def main():
    N, K = read_int_n()
    print(slv(N, K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 123360
#include <bits/stdc++.h>
#define int   long long
#define vi   vector<int>
#define pii  pair<int,int>
#define pss  pair<string,string>
#define psi  pair<string,int>
#define vpii  vector<pair<int,int> >
#define vpss  vector<pair<string,string> >
#define vpsi  vector<pair<string,int> >
#define pb   push_back
#define mp   make_pair
#define ff   first
#define ss   second
#define fast  ios::sync_with_stdio(false); cin.tie(NULL);
#define f(i,a,b)  for(int i=a;i<=b;i++)
#define rf(i,a,b)  for(int i=a;i>=b;i--)
#define out(v,n)   f(i,0,n-1)cout<<v[i]<<" ";cout<<endl;
#define in(v,n)   f(i,0,n-1)cin>>v[i];
#define endl  "\n"
using namespace std;
signed main()
{
    fast
    int n,x; cin>>n>>x;
    if(500*n>=x) cout<<"Yes";
    else cout<<"No";
}


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

bool chkmax(int &x,int y){return x<y?x=y,true:false;}
bool chkmin(int &x,int y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,maxa,mina=1<<30;
int a[105],cnt[105];

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i]=readint(),chkmax(maxa,a[i]),chkmin(mina,a[i]);
	if(maxa>n) return printf("Impossible\n"),0;
	for(int i=1;i<=n;i++) cnt[a[i]]++;
	for(int i=maxa;i>=mina+1;i--) if(cnt[i]<2) return printf("Impossible\n"),0;
	if(maxa%2==1&&cnt[mina]!=2) return printf("Impossible\n"),0;
	else if(maxa%2==0&&cnt[mina]>1) return printf("Impossible\n"),0;
	printf("Possible\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define eb emplace_back
 
using namespace std;
 
typedef pair<int, int> ii;
typedef long long ll;
const int N = 1000007, inf = 0x3f3f3f3f;
 
int main() {
  int a, b;
	ios::sync_with_stdio(0); cin.tie(0);
  	cin >> a >> b;
  cout << a * b << endl;
}

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


int main(){
    int H, N;
    std::cin >> H >> N;
    std::vector< int > A(N);
    std::vector< int > B(N);
    for(int i=0; i<N; i++){
        std::cin >> A[i] >> B[i];
    }
    
    std::vector< int > HM(H+1);
    HM[0] = 0;
    for(int i=1; i<=H; i++){
        int min = 1e9;
        for(int j=0; j<N; j++){
            int tmp = i - A[j];
            int M;
            if(tmp < 0){
                M = B[j];
            }else{
                M = HM[tmp] + B[j];
            }
            if(min > M){
                min = M;
            }
        }
        HM[i] = min;
    }
    
    
    std::cout << HM[H] << std::endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x3,y3,x4,y4;
    int x,y;
    x=x2-x1;
    y=y2-y1;

    x3=x2-y;
    y3=y2+x;
    x4=x1-y;
    y4=y1+x;

    cout << x3 << " " << y3 << " " << x4 << " " << y4;

    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void){
    char S[101];
    int K;

    scanf("%s%d", S, &K);


    char tmp_c = S[0];
    int i;

    for(i = 0; S[i] == tmp_c; i ++);

    int start = i;
    int mid_count = 0;
    int end = 0;

    if(S[i] != '\0'){
        while(1){
            int j = i;
            tmp_c = S[j];

            for(; S[i] == tmp_c; i ++);
            
            if(S[i] == '\0'){
                end = i - j;
                break;
            }else{
                mid_count += (i - j) / 2;
            }
        }
    }
    long long int sum_count = (long long int) K * mid_count;

    if(S[0] == S[i - 1]){
        if(end > 0){
            sum_count += start / 2 + end / 2 + (long long int) (K - 1) * ((start + end) / 2);
        }else{
            sum_count += ((long long int) K * start) / 2;
        }
    }else{
        sum_count += (long long int) K * (start / 2) + (long long int) K * (end / 2);
    }
    printf("%lld\n", sum_count);
}

Measured memory_bytes: 128
#include<cstdio>

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

using namespace std;

const int INF=1<<29;

// a を base 進数で書いたものを 10 進数だと解釈したときの値
int f(int a,int base){
	int res=0;
	for(int ten=1;a>0;ten*=10){
		if(a%base>=10) return INF;
		res+=a%base*ten;
		a/=base;
	}
	return res;
}

int main(){
	for(int a,b,c;scanf("%d%d%d",&a,&b,&c),a!=-1;){
		bool ok=false;
		for(int base=2;base<=16;base++) if(f(a,base)==b) ok=true;
		if(!ok){
			puts("-1");
			continue;
		}

		for(a++;a<=c;a++){
			int b_next=INF;
			for(int base=2;base<=16;base++) if(b<=f(a,base) && f(a,base)<b_next) b_next=f(a,base);
			b=b_next;
		}
		printf("%d\n",b);
	}

	return 0;
}

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

int main()
{
	double x[3], y[3];
	double a, b, c, z, S;
	int i, j;

	cout<<setprecision(6);
	cout<<setiosflags(ios::fixed);
	S = 0;
	scanf("%lf,%lf", &x[0], &y[0]);
	scanf("%lf,%lf", &x[1], &y[1]);
	while (scanf("%lf,%lf", &x[2], &y[2]) != EOF) {
		a = sqrt( (x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]) );
		b = sqrt( (x[2]-x[1])*(x[2]-x[1]) + (y[2]-y[1])*(y[2]-y[1]) );
		c = sqrt( (x[0]-x[2])*(x[0]-x[2]) + (y[0]-y[2])*(y[0]-y[2]) );
		z = (a+b+c)/2.0;
		S += sqrt( z*(z-a)*(z-b)*(z-c) );
		x[1] = x[2];
		y[1] = y[2];
	}
	cout<<S<<endl;

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int count=0;
void merge(int A[],int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    int L[n1+1],R[n2+1];
    for(int i=0;i<n1;i++){
        L[i]=A[left+i];
    }
    for(int i=0;i<n2;i++){
        R[i]=A[mid+i];
    }
    L[n1]=10000000000;
    R[n2]=10000000000;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(L[i]<=R[j]){
            A[k]=L[i];
            i++;
            count++;
        }
        else{
            A[k]=R[j];
            j++;
            count++;
        }
    }
}

void mergesort(int A[],int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergesort(A,left,mid);
        mergesort(A,mid,right);
        merge(A,left,mid,right);
    }
}
int main(){
    int n;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    mergesort(A,0,n);
    for(int i=0;i<n-1;i++){
        cout<<A[i]<<" ";
    }
    cout<<A[n-1]<<endl;
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 6996
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl;}
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

int main(void){
    LL N, M;
    cin >> N >> M;

    vector<LL> A(N);
    rep(i, N) cin >> A[i];

    priority_queue<LL> pq;
    rep(i, N) pq.push(A[i]);

    rep(i, M){
        LL tmp = pq.top()/2;
        pq.pop();
        pq.push(tmp);
    }

    LL ans = 0;
    while(!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
from collections import defaultdict
n = int(input())
a_ls = list(map(int, input().split()))
L_dict = defaultdict(int)
for i in range(n):
    Li = a_ls[i] + i + 1
    L_dict[Li] += 1

ans = 0
for j in range(n):
    Rj = j + 1 - a_ls[j]
    ans += L_dict[Rj]
print(ans)


Measured memory_bytes: 61552
a, b = map(int, input().split())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n = gcd(a, b)

if n == 1:
    print(1)
    exit()

m = 2
ans = 1
while m <= (n ** 0.5):
    if n % m == 0:
        ans += 1
        while n % m == 0:
            n //= m
    if n == 1:
        break
    m += 1

if n > 1:
    ans += 1

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#define N 8
int main(void){
  int n,t,i,j,a[8],max,min;
  scanf("%d",&n);
  while(n--){
    max=min=0;
    scanf("%1d%1d%1d%1d%1d%1d%1d%1d",
	  &a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7]);
    for(i=0;i<N-1;i++){
      for(j=N-1;j>i;j--){
	if(a[j-1]<a[j]){
	  t=a[j-1];
	  a[j-1]=a[j];
	  a[j]=t;
	}
      }
    }
    for(i=0;i<N;i++){
      max*=10;
      max+=a[i];
    }
    for(i=0;i<N-1;i++){
      for(j=N-1;j>i;j--){
	if(a[j-1]>a[j]){
	  t=a[j-1];
	  a[j-1]=a[j];
	  a[j]=t;
	}
      }
    }
    for(i=0;i<N;i++){
      min*=10;
      min+=a[i];
    }
    printf("%d\n",max-min);
  }
  return 0;
}

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

int main(){
  int A,B,X;cin>>A>>B>>X;
  
  if(X-A>=0 && X-A<=B) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 3632
N = int(input())
S = input()
a = set(S[:1])
b = set(S[1:])
M = len(a & b)

for i in range(2,N):
  a = set(S[:i])
  b = set(S[i:])
  if len(a & b) > M:
    M = len(a & b)

print(M)

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

long long arr[300010],N,totalkiri=0,totalkanan=0,tmp,prefixkiri[300010],prefixkanan[300010];

priority_queue<long long,vector<long long>,greater<long long>> kiri;
priority_queue<long long> kanan;


void Input(){
	cin>>N;
	for(long long i=1; i<=3*N; i++){
		cin>>arr[i];
	}
}

void Teliti(){
	for(long long i=1; i<=N; i++){
		kiri.push(arr[i]); totalkiri+=arr[i];
	}
	prefixkiri[N]=totalkiri;
	for(long long i=N+1; i<=2*N; i++){
		if(arr[i]>kiri.top()){
			totalkiri-=kiri.top(); totalkiri+=arr[i]; kiri.pop(); kiri.push(arr[i]);
		}
		prefixkiri[i]=totalkiri;
	}
	for(long long i=3*N; i>2*N; i--){
		kanan.push(arr[i]); totalkanan+=arr[i];
	}
	prefixkanan[2*N+1]=totalkanan;
	for(long long i=2*N; i>N; i--){
		if(arr[i]<kanan.top()){
			totalkanan-=kanan.top(); totalkanan+=arr[i]; kanan.pop(); kanan.push(arr[i]);
		}
		prefixkanan[i]=totalkanan;
	}
}

void Solve(){
	Teliti();
	long long maxim=-1e15;
	for(long long i=N; i<=2*N; i++){
		maxim=max(prefixkiri[i]-prefixkanan[i+1],maxim);
	}
	cout<<maxim<<'\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Input();
	Solve();
}

Measured memory_bytes: 8892
#include <stdio.h>

int main(int argc, char *argv[])
{
    char line[256];
    int a, b;

    if (!fgets(line, sizeof(line), stdin)) {
        fprintf(stderr, "error input val\n");
        return -1;
    }

    if (sscanf(line, "%d %d", &a, &b) != 2) {
        fprintf(stderr, "error input format\n");
        return -1;
    }

    if (!(1<=a)) {
        fprintf(stderr, "error val range\n");
        return -1;
    }
    if (!(b<=1000000000)) {
        fprintf(stderr, "error val range\n");
        return -1;
    }

    printf("%d %d %f\n", a/b, a%b, (double)a/(double)b);

    return 0;
}

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

int main(){
 while(1){
 int x, y;
 cin>>x>>y;
 if(x == 0 && y == 0) break;

 if(x > y) swap(x, y);
 cout<<x<<" "<<y<<endl;
}
return 0;
}


Measured memory_bytes: 3056
#include<stdio.h>

int main(){
    int a, b, valuePlus, valueMinus, valueProduct, zero = 0;
    scanf("%d", &a);
    scanf("%d", &b);

    valuePlus = a + b;
    valueMinus = a - b;
    valueProduct = a * b;

    if(a == 0 && b == 0){
        printf("%d\n", zero);
    }else{
        if(valuePlus >= valueMinus && valuePlus >= valueProduct){
            printf("%d\n", valuePlus);
        }else if(valueMinus >= valuePlus && valueMinus >= valueProduct){
            printf("%d\n", valueMinus);
        }else if(valueProduct >= valuePlus && valueProduct >= valueMinus){
            printf("%d\n", valueProduct);
        }else{
        printf("%d\n", zero);
        }
    }

    return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int dp[11][156];

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    for (;;) {
        int N, K, S; cin >> N >> K >> S;
        if (!N) break;

        rep(i, 0, 11) rep(j, 0, 156) dp[i][j] = 0;
        dp[0][0] = 1;
        rep(i, 1, N + 1) {
            for (int j = K - 1; j >= 0; j--) {
                for (int k = S - 1; k >= 0; k--) {
                    if (k + i <= S)
                        dp[j + 1][k + i] += dp[j][k];
                }
            }
        } 
        cout << dp[K][S] << endl;
    }
}


Measured memory_bytes: 3032
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
//#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e8;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=100005;

int dp[22][1<<21];vi adj[22];

int solve(int i,int mask)
{
 if(i==0)
 {
     if(!mask)
     return dp[0][mask]=1;
     else
     {
         return dp[0][mask]=0;
     }
     
 }
 if(dp[i][mask]!= -1)
 return dp[i][mask];
 dp[i][mask]=0;
 for(int j:adj[i-1])
 if(mask&(1<<j))
 dp[i][mask]=(dp[i][mask]+solve(i-1,mask^(1<<j)))%hell;
 return dp[i][mask];

}

void solve()
{
int n;
cin>>n;
memset(dp,-1,sizeof(dp));
int a[n][n];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{cin>>a[i][j];
if(a[i][j])
adj[i].pb(j);
}
cout<<solve(n,(1<<n)-1);
}




int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}

Measured memory_bytes: 183880
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    st = []
    for _ in range(N):
        s, t = [x for x in input().split()]
        st.append([s, int(t)])

    X = input().strip()

    is_start = False
    ans = 0
    for s, t in st:
        if is_start:
            ans += t
        if s == X:
            is_start = True

    print(ans)
    

    



if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  int K,X;
  cin >> K >> X;

  int x = X - K + 1;
  int y = X + K - 1;
  for(int i = x;i <= y;i++){
    cout << i <<" ";
  }
  cout << endl;
}


Measured memory_bytes: 3672
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define x first
#define y second
 
typedef long long ll;
 
const ll INF = 1e9+5;
const ll MOD = 1e9+7;
 
int main() {
	int n;
  	cin >>n;
  	ll sol = 0;
  	int maxx = 0;
  	for (int i=0  ; i<n ; i++) {
     	int x;
      	cin >>x;
      	if (x > maxx) maxx = x;
      	else sol += maxx-x;
    }
  	cout <<sol<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++) cin >> d[i];

    int ans = 0;
    for(int i = 0; i < n - 1; i++) {
        for(int j = i + 1; j < n; j++) {
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <cmath>
#include <iterator>
#include <complex>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <string>
#include <cassert>
#include <iomanip>
#include <cstdlib>
#include <numeric>

using namespace std;
typedef long long ll;
const int N = 200005;
int par1[N], par2[N];
int comp1[N], comp2[N];
int getparent1(int x)
{
	if(par1[x]==x)
		return x;
	int p1 = getparent1(par1[x]);
	return par1[x]=p1;
}
int getparent2(int x)
{
	if(par2[x]==x)
		return x;
	int p2 = getparent2(par2[x]);
	return par2[x]=p2;
}
inline void unite1(int p1, int p2)
{
	if(p1==p2)
		return;
	if(comp1[p1]<comp1[p2])
		unite1(p2,p1);
	else
	{
		comp1[p1]+=comp1[p2];
		par1[p2] = p1;
	}
}
inline void unite2(int p1, int p2)
{
	if(p1==p2)
		return;
	if(comp2[p1]<comp2[p2])
		unite2(p2,p1);
	else
	{
		comp2[p1]+=comp2[p2];
		par2[p2] = p1;
	}
}
vector<int> els[N];
int ans[N], cnt[N], vis[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k,l, x, y;
	cin>>n>>k>>l;
	for(int i=1; i<=n; i++)
	{
		par1[i] = i;
		comp1[i] = 1;
		par2[i] = i;
		comp2[i] = 1;
	}
	for(int i=0; i<k; i++)
	{
		cin>>x>>y;
		unite1(getparent1(x),getparent1(y));
	}
	for(int i=0; i<l; i++)
	{
		cin>>x>>y;
		unite2(getparent2(x),getparent2(y));
	}
	for(int i=1; i<=n; i++)
	{
		int p = getparent1(i);
		els[p].push_back(i);
	}
	// for(int i=1; i<=n; i++)
	// {
	// 	if(els[i].empty())
	// 		continue;
	// 	cout<<i<<":";
	// 	for(auto x: els[i])
	// 		cout<<x<<",";
	// 	cout<<endl;
	// }
	for(int i=1; i<=n; i++)
	{
		if(els[i].empty())
			continue;
		for(auto x: els[i])
		{
			int p = getparent2(x);
			if(vis[p]!=i)
			{
				vis[p] = i;
				cnt[p] = 0;
			}
			cnt[p]++;
		}
		for(auto x: els[i])
			ans[x] = cnt[getparent2(x)];
	}
	for(int i=1; i<=n; i++)
		cout<<ans[i]<<" ";
}

Measured memory_bytes: 16256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

void dfs(vector<set<int>> &edges, vector<bool> &f, int n) {
    f[n] = true;
    for (int m : edges[n]) {
        if (!f[m])
            dfs(edges, f, m);
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<set<int>> edges(N + 1);
    for (int i = 0; i < M; i++) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        edges[X].insert(Y);
        edges[Y].insert(X);
    }
    vector<bool> f(N + 1, false);
    f[0] = true;
    int ans = 0;
    for (int i = 1; i < N + 1; i++) {
        if (!f[i] && edges[i].size() != 0) {
            dfs(edges, f, i);
            ans++;
        }
    }
    for (bool b : f) {
        if (!b)
            ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

int n, k, s;

int main() {
	scanf("%d%d%d", &n, &k, &s);
	for (int i = 1; i <= k; i++) cout << s << " ";
	if (k != n) {
		int cnt = s-1==0?s + 1: s-1;
		for (int i = 1; i < n - k; i++) {
			cout << cnt << " ";
		}
//		cout << "1000000000" << " ";
		cout << cnt << endl;
	}
	else cout << endl;
	return 0;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n;

	f(i,0,n-1) cin>>ara[i];

	sort(ara,ara+n,greater<int>());

	int a=0,b=0;

	f(i,0,n-1) {
        if(i & 1) b+=ara[i];
        else a+=ara[i];
	}

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

}


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

int main(void){
    string s;
    cin >> s;
    //int flag = 1;
    int place;
    if(s.front() != 'A'){
        cout << "WA" << endl;
        return 0;
    }
    string t = s.substr(2,s.size()-3);
    int count=0;
    for(int i=0; i<t.size(); i++){
        if(t[i] == 'C'){
            count++;
            place = i+1;
        }
    }
    if(count != 1){
        cout << "WA" << endl;
        return 0;
    }
    s.erase(s.begin());
    s.erase(s.begin() + place);
    for(int i=0; i<s.size(); i++){
        if(!(s[i] >= 'a' && s[i] <= 'z')){
            cout << "WA" << endl;
            return 0;
        }
    }
    cout << "AC" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
    public static void main(String arg[])
    {
        Scanner sc=new Scanner(System.in);
        boolean a[] =new boolean[10001];
        Arrays.fill(a, true);
        for(int i=2; i*i<=10000; i++)
        {
            if(!a[i])
                continue;
            for(int j=i*2; j<=10000; j+=i)
                a[j]=false;
        }
        while(sc.hasNext())
        {
            int n=sc.nextInt();
            if(n==0)
                return;
            int sum=0;
            int ans=0;
            for(int i=2; i<=n; i++)
            {
                sum =0;
                if(a[i])
                    for(int j=i; j<=n; j++)
                    {
                        if(a[j])
                        {
                            sum+=j;
                            if(n==sum)
                                ans++;
                        }
                        if(sum>=n)
                            break;
                    }
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 12000
#include<stdio.h>

int main(void)
{
	for (;;)
	{
		int a, b;
		char op;

		scanf("%d %c %d", &a, &op, &b);

		if (op == '+')
		{
			printf("%d\n", a + b);
		}
		else if (op == '-')
		{
			printf("%d\n", a - b);
		}
		else if (op == '*')
		{
			printf("%d\n", a * b);
		}
		else if (op == '/')
		{
			printf("%d\n", a / b);
		}
		else
		{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 600