akhauriyash/Code-Regression huggingface dataset:
class _Node {
  constructor(key, left = null, right = null) {
    this.key = key;
    this.left = left;
    this.right = right;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    this.root = new BinaryTree.Node(key, null, null);
    this.insert = (key) => {
      let x = this.root, y;
      let newNode = new BinaryTree.Node(key, null, null);
      while (x !== null) {
        y = x;
        x = x[key < x.key ? 'left' : 'right'];
      }
      y[key < y.key ? 'left' : 'right'] = newNode;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



Measured memory_bytes: 198944
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct UnionFind {
  vector<ll> par; 
  vector<ll> siz; 

    
  UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
    for (ll i = 0; i < sz_; ++i) par[i] = i; 
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.resize(sz_, 1);
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }

  ll root(ll x) { 
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(ll x, ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return siz[root(x)];
  }
};

ll n, m;

void solve() {
  UnionFind uf(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--, b--;

    uf.merge(a, b);
  }
  ll ans = 1, ok = 0;
  vector<bool> visited(n, false);
  rep(i, n) {
    int v = uf.root(i);
    if (visited[v]) continue;
    visited[v] = true;
    ans = (ans * 2) % mod;
    if (uf.size(v) > 1) ok = 1;
  }
  ans = (ans + ok) % mod;
  cout << ans << '\n';
}

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

  while (cin >> n >> m, n || m) {
    solve();
  }

  




  
  return 0;
}


Measured memory_bytes: 4528
#include <iostream>

using namespace std;
int max(int a, int b, int c) {
  int ans = 0;
  ans = a > b ? (a > c ? a : c) : (b > c ? b : c);
  return ans;
}
int min(int a, int b, int c) {
  int ans = 0;
  ans = a > b ? (b > c ? c : b) : (a > c ? c : a);
  return ans;
}

int main(void) {
  int a, b, c;
  int ans = 0;
  cin >> a >> b >> c;
  int n1 = max(a, b, c);
  int n3 = min(a, b, c);
  int n2 = a+b+c - n1 - n3;
  
  int d1 = n1 - n2;
  int d2 = n1 - n3;
  
  if (d1 % 2 && d2 % 2) {
  	ans += d1;
    ans += (d2 - d1) / 2;
  } else if (d1 % 2 == 0 && d2 % 2 == 0) {
  	ans += d1 / 2;
    ans += d2 / 2;
  } else {
    ans++;
    ans += (d1+d2+1) / 2;
  }
     
      cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
//vector<vector<ll>> data(3, vector<ll>(4));
//vector<ll> data(N);
//str s = to_string(i);
//int i = c - '0'
//sort(data.begin(), data.end());
//reverse(data.begin(), data.end());
//data.erase(unique(data.begin(), data.end()), data.end());
//str.substr(n)//n番以降スライス
//str.substr(n,m)//n番以降m文字スライス
//str.erase(n)//n番以降削除
//str.erase(n,m)//n番以降m文字削除
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define FORD(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define PB push_back
#define MOD 1000000007
using namespace std;

int main() {
	ll N;
	ll s;
	cin >> N;

	vector<ll> data(N+1);
	data.at(0) = 1;
	FOR(i,1, N+1) {
		REP(j, i - 2) {
			data.at(i) += data.at(j);
			data.at(i) %= MOD;
		}
	}
	if (data.at(N) % MOD >= 0) data.at(N) = data.at(N) % MOD;
	else data.at(N) = data.at(N) % MOD + MOD;
	cout << data.at(N) << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	vector <double> dp(n + 1);
	dp[0] = 1;
	for(int i = 0; i < n; i ++) {
		double p;
		scanf("%lf", &p);
		for(int j = i + 1; j >= 0; j --) {
			dp[j] = p * dp[j - 1] + (1 - p) * dp[j];
		}
	}
	double ans = 0;
	for(int i = n / 2 + 1; i <= n; i ++) {
		ans += dp[i];
	}
	printf("%.10lf", ans);
	return 0;
}


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

int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        int ans = 0;
        for (int j = 0; j < m; j++)
        {
            ans += a[i][j] * b[j];
        }
        if ((ans + c) > 0)
        {
            count++;
        }
    }
    cout << count << endl;
}

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

int main(void) {
   int N;
   cin>>N;
   std::map<int,int> A;
   for (int i = 0 ; i < N;i++) {
      int a;
      cin>>a;
      A[a] = i+1;
   }
   for (auto el: A) {
      cout<<el.second<<" ";
   }
   cout<<endl;


   return 0;
}

Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N, d[100000],ans;
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> d[i];
	}
	
	sort(d, d + N);

	ans = d[N / 2] - d[N / 2-1];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
INF = 10**10+5
MOD =10**9+7

#入力
n = input()
for i in range(len(n)):
    if n[i] == "7":
        print("Yes")
        sys.exit()
print("No")

Measured memory_bytes: 27128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  string a, b;
  cin >> a >> b;
  int num = stoi(a+b);
  double r = floor(sqrt(num));
  if (r == num/r){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
//typedef pair<int,int> P;

//少数点表示
//cout << std::fixed << std::setprecision(14) <<double値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    string s;
    cin >> s;
    auto n = s.size();
    bool ok = true;
    rep(i,n){
        if(i%2 == 0){
            if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D') continue;
            else ok = false;
        }else if(i%2 != 0){
            if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') continue;
            else ok = false;
        }
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

int MAX = 100000;

vector<vector<int>> user(MAX, vector<int>(0));
vector<int> group(MAX, -1);

// 模範回答
// void dfs(int start, int group_i) {
//     stack<int> s;
//     group[start] = group_i;
//     s.push(start);
//     while (!s.empty()) {
//         int current = s.top();
//         s.pop();
//         for (int i = 0; i < user[current].size(); i++) {
//             int adj = user[current][i];
//             if (group[adj] == NIL) {
//                 s.push(adj);
//                 group[adj] = group_i;
//             }
//         }
//     }
// }

// 再帰によるdfs
void dfs(int start, int group_i) {
    group[start] = group_i;
    rep(i, user[start].size()) {
        int adj = user[start][i];
        if (group[adj] == -1) {
            dfs(adj, group_i);
        }
    }
}

// スタックによるdfsパターン1
// void dfs(int start, int group_i) {
//     stack<int> s;
//     group[start] = group_i;
//     s.push(start);
//     while (!s.empty()) {
//         int current = s.top();
//         group[current] = group_i;
//         bool stop = true;
//         for (int i = 0; i < user[current].size(); i++) {
//             int adj = user[current][i];
//             if (group[adj] == -1) {
//                 s.push(adj);
//                 stop = false;
//                 break;
//             }
//         }
//         if (stop) s.pop();
//     }
// }

int main() {
    int n, m, s, t, q;
    scanf("%d %d", &n, &m);
    rep(i, m) {
        scanf("%d %d", &s, &t);
        user[s].push_back(t);
        user[t].push_back(s);
    }

    int group_i = 0;
    rep(i, n) {
        if (group[i] == -1) {
            dfs(i, group_i++);
        }
    }

    scanf("%d", &q);
    rep(i, q) {
        scanf("%d %d", &s, &t);
        if (group[s] == group[t]) printf("yes\n");
        else printf("no\n");
    }
}


Measured memory_bytes: 11792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const int mxn=2e5+5;
int n,a[mxn*3],b[mxn],t[mxn],l,r=1;
int main(){
	cin>>n;
	rep(i,n)cin>>a[i+n+1];
	rep(i,n)cin>>a[i];
	a[n*2+1]=a[n+1];
	a[n]=a[0];
	rep(i,n)b[i]=a[0]^a[n+i+1];
	rep(i,n*2+1)a[i]^=a[i+1];
	rep(i,n)a[i+n*2+1]=a[i+n+1];
	a[n]=1e9;
	rep(i,n*2+1){
		bool f=(t[i-l]+i>=r);
		if(f)for(l=i,r=max(r,i);a[r-l]==a[r];++r);
		t[i]=(f?r-l:t[i-l]);
		if(t[i]==n)cout<<i-n-1<<' '<<b[i-n-1]<<endl;
	}
}



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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N, M; cin >> N >> M;
    i64 a;
    i64 s = 0;
    REP(i, M) {
        cin >> a;
        s += a;
    }

    i64 ans = N - s;
    if (ans < 0) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3652
import sys
import itertools

abset=set()
for _ in range(3):
  a,b=map(int,input().split())
  abset.add((a,b))
#print(abset)

for perm in itertools.permutations(range(1,5)):
  #print(perm)
  
  for i in range(1,4):
    if not (perm[i-1],perm[i]) in abset and not (perm[i],perm[i-1]) in abset:
      break
  else:
    #print(perm)
    print("YES")
    sys.exit(0)
else:
  print("NO")

Measured memory_bytes: 9188
open Batteries
let n, k = Scanf.sscanf (read_line()) "%d %d" (fun n k -> n, k)
let h = Array.init n (fun a -> Scanf.scanf " %d" @@ fun b -> b)

let dp = Array.init 100010 @@ fun a -> max_int
let _ = dp.(0) <- 0

let change i w =
  if dp.(i) > dp.(i-w) + (abs @@ h.(i) - h.(i-w)) then dp.(i) <- dp.(i-w) + (abs @@ h.(i) - h.(i-w))


let rec loop i =
  if i >= n then dp.(n-1) else (
    change i 1; 
    if i > 1 then 
    let rec loop2 i2 =
      if i2 > k || -1 >= (i - i2) then () else (change i i2; loop2 (i2+1))
    in loop2 2
     else ();
    loop (i+1)
    )


let _ = Printf.printf "%d\n" @@ loop 1


Measured memory_bytes: 6528
n = int(input())
balls = list(map(int, input().split()))
conbi = [0]*n
for i in balls:
    conbi[i-1] +=1
result = 0
for j in range(n):
    result += (conbi[j]*(conbi[j]-1))//2
for k in balls:
    print(result-conbi[k-1]+1, end=" ")


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

using namespace std;

int main(){

    int X, Y;
    cin >> X >> Y;

    int ans = 0;
    if(X == 1 && Y == 1){
        ans = 1000000;
        cout << ans << endl;
        return 0;
    }

    if(X == 1) ans += 300000;
    else if(X == 2) ans += 200000;
    else if(X == 3) ans += 100000;

    if(Y == 1) ans += 300000;
    else if(Y == 2) ans += 200000;
    else if(Y == 3) ans += 100000;

    cout << ans << endl;
    
    

    return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
 
int main() {

    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n)    cin>>a.at(i);

    vector<int> s(n+1);
    s[0]=0;
    rep(i,n) {
        s[i+1]=s[i]+a[i];
    }

    int ma=0;
    int memo;
    rep(i,(n-k+1)) {
        ma=max(ma,s[i+k]-s[i]);
    }
    double ans=(double)(ma+k)/2;

    printf("%.9f\n",ans);
    
 return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>

using namespace std;

int main()
{

	string s;
	cin >> s;
	bool flag=true;
	if(s[0]!='A')flag=false;
	int count=0;
	for(int i=2;i<s.size()-1;i++)
		if(s[i]=='C')count++;
	if(count!=1)flag=false;
	for(int i=0;i<s.size();i++)
		if(s[i]!='A' and s[i]!='C' and (s[i]<'a' or s[i]>'z'))flag=false;

	cout << (flag ? "AC" : "WA") << endl;



}

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

int a[100005],b[100005],c[100005];
vector<int>d[100006];
 
void dfs(int v,int s) {
	a[v]=a[s]+1;
	b[v]=1;
	c[v]=s;
	for(auto x:d[v]) {
		if(x==s) continue;
		dfs(x,v);
		b[v]=max(b[v],b[x]+1);
	}
	
}
int main(){
    int n,u,v;
    cin>>n>>u>>v;
	for(int i=1;i<n;i++) {
		int x,y;
		cin>>x>>y;
		d[x].push_back(y);
		d[y].push_back(x);
	}
	dfs(v,0);
	int ans=-1;
	int dis=a[u]-a[v];
	
	dis=(dis-1)/2;
//	cout<<dis<<endl;
	while(dis--){ 
	    u=c[u];
	}
	if(d[u].size()==1) 
	     ans=a[u]-2;
	else 
	    ans=b[u]+a[u]-3;
	    
	cout<<ans<<endl;
	

}


Measured memory_bytes: 16616
antena=[]
for i in range(0, 5):
    antena.append(int(input()))
k = int(input())
flag = 0
for i in range(0, 4):
    for j in range(i+1, 5):
        if antena[j]-antena[i]>k:
            flag = 1
if flag==0:
    print("Yay!")
else:
    print(":(")


Measured memory_bytes: 2940
h,w,*S = $<.read.split
H,W,Q,r = h.to_i,w.to_i,[]
D = [[0,1],[0,-1],[1,0],[-1,0]]
S.each {|s| s << "#" }
S << "#"*W
(T=H*W).times {|i| Q << i.divmod(W).push(Array.new(T)) }
T.times {|c|
  Q.pop(Q.size).each {|h,w,a|
    next  if a[i=h*W+w] || S[h][w]!=?.
    a[i] = r = c
    D.each {|y,x| Q << [h+y,w+x,a] }
  }
}
p r

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

Measured memory_bytes: 1736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _001_FindingMissingCards
{

    class Program
    {
        static void Main()
        {
            var tmpStrings = Console.ReadLine().Split(' ');
            var x = Convert.ToInt64(tmpStrings[0]);
            var y = Convert.ToInt64(tmpStrings[1]);

            if (x < y)
            {
                var tmp = x;
                x = y;
                y = tmp;
            }
            while (y > 0)
            {
                var r = x % y;
                x = y;
                y = r;
            }
            Console.WriteLine(x);

        }
    }
}

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> city(N,0);
  for(int i=0; i<M; i++){
    int a,b;
    cin >> a >> b;
    
    city.at(a-1)++;
    city.at(b-1)++;
    
  }
  
  for(int i=0; i<N; i++) cout << city.at(i) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,s;
int a[100010];
int b[100010];
int main(){
	cin>>n>>s;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		b[i]=999999999;
	}
	b[1]=0;
	for(int i=2;i<=n;++i){
		for(int j=i-1;j>max(0,i-1-s);--j){
			b[i]=min(b[j]+abs(a[i]-a[j]),b[i]);
		}
	}
	cout<<b[n]<<endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif
struct segtree{
	using D = int;
	D inf = 1e9;

	int N;
	vector<D> val;

	segtree(){}
	segtree(int n){
		N=1;
		while(N<n) N*=2;
		val.assign(N*2,-inf);
	}
	segtree(const vector<D>& ds){
		int n = ds.size();
		N=1;
		while(N<n) N*=2;
		val.assign(N*2,-inf);
		rep(i,n) val[i+N] = ds[i];
		for(int i=N-1;i>0;i--) val[i] = max(val[i*2],val[i*2+1]);
	}
	void changemax(int k,D d){
		k+=N;
		chmax(val[k],d);
		k/=2;
		while(k){
			val[k] = max(val[k*2],val[k*2+1]);
			k/=2;
		}
	}
	D getmax(int a,int b){
		D res = -inf;
		a+=N,b+=N;
		while(a<b){
			if(a&1) chmax(res,val[a++]);
			if(b&1) chmax(res,val[--b]);
			a/=2,b/=2;
		}
		return res;
	}
};
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	cin >> N;
	V<int> A(N);
	rep(i,N) cin >> A[i];
	{
		V<int> as = A;
		sort(all(as));
		as.erase(unique(all(as)),as.end());
		rep(i,N) A[i] = lower_bound(all(as),A[i]) - as.begin();
	}
	segtree seg(V<int>(N,0));
	int len = 0;
	rep(i,N){
		int v = seg.getmax(A[i],N) + 1;
		seg.changemax(A[i],v);
		chmax(len,v);
	}
	cout << len << endl;
}


Measured memory_bytes: 2072
#include <stdio.h>
#include <math.h>

int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    int h[n];
    int ma[n];
    for(int i=0; i<n; i++){
        scanf("%d",&h[i]);
        ma[i]=0;
    }
    int a[m];
    int b[m];
    for(int i=0; i<m; i++){
        scanf("%d %d",&a[i],&b[i]);
        ma[a[i]-1]=fmax(ma[a[i]-1],h[b[i]-1]);
        ma[b[i]-1]=fmax(ma[b[i]-1],h[a[i]-1]);
    }
    int ans=0;
    for(int i=0; i<n; i++){
        if(ma[i]<h[i]){
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3668
#include<stdio.h>
int main(void)
{
	int x1,x2,x3,x4,y1,y2,y3,y4,s,t;
	scanf("%d %d %d %d %d %d %d %d",&x1,&x2,&x3,&x4,&y1,&y2,&y3,&y4);
	s=x1+x2+x3+x4;
	t=y1+y2+y3+y4;
	if(s>t){
		printf("%d\n",s);
	}
	else if(s<t){
		printf("%d\n",t);
	}
	else if(s==t){
		printf("%d\n",t);
	}
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vll Graph(N);
  REP(i,N-1){
    ll A;
    IN(A);
    A--;
    Graph[A]++;
  }

  REP(i,N){
    OUT(Graph[i]);
  }

  return 0;
}

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

void _139() {
    string s, t;
    cin >> s;
    cin >> t;

    int count = 0;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == t[i])
            count++;
    }
    cout << count << endl;
}

void _138() {
    int a;
    string s;
    cin >> a;
    cin >> s;

    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;
}

void _137() {
    int a, b;
    cin >> a >> b;

    int add = a + b;
    int mult = a * b;
    int sub = a - b;

    cout << max(add, max(mult, sub)) << endl;
}

void _136() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) << endl;
}

void _135() {
    long long a, b;
    cin >> a >> b;

    if (abs(a - b) % 2 != 0)
        cout << "IMPOSSIBLE" << endl;
    else
        cout << (a + b) / 2 << endl;
}

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

int main()
{
    _134();
    return 0;
}



Measured memory_bytes: 256
//copied from https://atcoder.jp/contests/abc124/submissions/4957128
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var s = cin.ReadLine;
            
            var count0 = 0;
            var count1 = 0;

            for (var i = 0; i < s.Length; i++) {
                var temps = s.Substring(i,1);
                if (i%2 == 0) {
                    if (temps == "0") {
                        count0++;
                    } else {
                        count1++;
                    }
                } else {
                    if (temps == "0") {
                        count1++;
                    } else {
                        count0++;
                    }
                }
            }
            var ans = count0 < count1 ? count0 : count1;
            WriteLine(ans);
        }

        private double MultipleCeil(double value, double multiple) {return Math.Ceiling(value / multiple) * multiple;}

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 13408
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <utility>
#include <bitset>
using namespace std;
typedef long long ll;
const ll inf = 4e18;
const ll mod = 1e9+7;
#define print(X) cout << X << endl
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (ll (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define repd(i, m, n) for (ll (i) = (m); (i) > (n); --(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

template <class T>
string join(const vector<T>& v, const char* delim = 0) {
  string s;
  if (!v.empty()) {
    s += v[0];
    for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
      if (delim) s += delim;
      s += v[i];
    }
  }
  return s;
}
//         100
// .........
// .........
// #########
// .########

int main(void)
{
    ll A,B;
    ll N=100;
    cin >> A >> B;
    vec<vec<char>> s(N, vec<char>(N, '#'));

    rep (y,N/2) {
        rep (x,N) {
            s[y][x] = '.';
        }
    }
    A -= 1;
    B -= 1;
    ll x, y;
    x = 0;
    y = 0;
    while (B--) {
        s[y][x] = '#';
        x+=2;
        if (x>=N) {
            x=0;
            y+=2;
        }
    }
    x = 0;
    y = N-1;
    while (A--) {
        s[y][x] = '.';
        x+=2;
        if (x>=N) {
            x=0;
            y-=2;
        }
    }
    print(N<<" "<<N);
    rep(y,N) {
        print(join(s[y]));
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   int H, W, K; cin >> H >> W >> K;

   vector<vector<char>> init(H, vector<char>(W));

   rep(i, 0, H) {
     rep(j, 0, W) {
       cin >> init.at(i).at(j);
     }
   }

   ll ans = 0;

   for (int i = 0; i < (1 << H); i++) {
     for (int j = 0; j < (1 << W); j++) {
       int cnt = 0;
       for (int k = 0; k < H; k++) {
         for (int l = 0; l < W; l++) {
           if ((i & (1 << k)) && (j & (1 << l)) && init.at(k).at(l) == '#') cnt++;
         }
       }
       if (cnt == K) ans++;
     }
   }

   cout << ans << endl;
 }


Measured memory_bytes: 3628
#include <cstdio>
#define N 505
int h, w;
char p[N][N], r[N][N], b[N][N];
int main() {
	int i, j, k;
	scanf("%d%d", &h, &w);
	for(i=1; i<=h; i++) {
		k = i%2 ? w-1 : 1;
		for(j=1; j<=k; j++) r[i][j] = '#', b[i][j] = '.';
		for(; j<=w; j++) r[i][j] = '.', b[i][j] = '#';
		scanf("%s", &p[i][1]);
		for(j=1; j<=w; j++) if(p[i][j]=='#') r[i][j] = b[i][j] = '#';
	}
	for(i=1; i<=h; i++, puts("")) for(j=1; j<=w; j++) putchar(r[i][j]);
	puts("");
	for(i=1; i<=h; i++, puts("")) for(j=1; j<=w; j++) putchar(b[i][j]);
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<algorithm>
using namespace std;
int p[20][20];
int q[210];
int dx[]={0,0,0,1,1,-1,-1};
int dy[]={0,1,-1,1,0,0,-1};
long long mat[210][210];
long long val[210][210];
long long tmp[210][210];
int main(){
	int T=0;
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		long long mod=b;
		for(int i=0;i<20;i++)for(int j=0;j<20;j++)
			p[i][j]=-1;
		int sz=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<a+i;j++){
				scanf("%d",q+sz);
				p[i][j]=sz++;
			}
		}
		for(int i=a;i<a*2-1;i++){
			for(int j=i-a+1;j<a*2-1;j++){
				scanf("%d",q+sz);
				p[i][j]=sz++;
			}
		}
		for(int i=0;i<sz;i++)for(int j=0;j<sz;j++){
			mat[i][j]=0;
			val[i][j]=0;
			if(i==j)val[i][j]=1;
		}
		for(int i=0;i<20;i++){
			for(int j=0;j<20;j++){
				if(!~p[i][j])continue;
				int at=p[i][j];
				for(int k=0;k<7;k++){
					int tx=i+dx[k];int ty=j+dy[k];
					if(tx<0||ty<0)continue;
					if(!~p[tx][ty])continue;
					mat[p[tx][ty]][at]++;
				}
			}
		}
		while(c){
			if(c%2){
				for(int i=0;i<sz;i++)for(int j=0;j<sz;j++)tmp[i][j]=0;
				for(int i=0;i<sz;i++)for(int j=0;j<sz;j++)for(int k=0;k<sz;k++)
					tmp[i][j]=(tmp[i][j]+mat[i][k]*val[k][j])%mod;
				for(int i=0;i<sz;i++)for(int j=0;j<sz;j++)val[i][j]=tmp[i][j];
			}
			c/=2;
			for(int i=0;i<sz;i++)for(int j=0;j<sz;j++)tmp[i][j]=0;
			for(int i=0;i<sz;i++)for(int j=0;j<sz;j++)for(int k=0;k<sz;k++)
				tmp[i][j]=(tmp[i][j]+mat[i][k]*mat[k][j])%mod;
			for(int i=0;i<sz;i++)for(int j=0;j<sz;j++)mat[i][j]=tmp[i][j];
		}
		
		long long ret=0;
		for(int i=0;i<sz;i++){
			long long v=0;
			for(int j=0;j<sz;j++){
				v=(v+val[i][j]*q[j])%mod;
			}
			ret+=v;
		}
		printf("Case %d: %lld\n",++T,ret);
	}
}

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

int main(){
  int n = 0;
  int i;
  string s;

  cin >> s;

  for (i = 0; i < 4; i++){
    if(s[i] == '+'){
      n++;
    }else{
      n--;
    }
  }

  cout << n;
}


Measured memory_bytes: 256
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
M=1
for a in A:
    M=((M * a) // gcd(M, a))
M%=mod

print(sum([M*pow(a,mod-2,mod)%mod for a in A])%mod)


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

bool isLeapYear(int n) {
    if ((n % 4 == 0 && n % 100 != 0) || n % 400 == 0) {
        return true;
    }
    return false;
}

int main() {
    bool spaceFlag = false;
    while (true) {
        int a, b;
        cin >> a >> b;
        if (a == 0 && b ==0) {
            break;
        }
        if (spaceFlag) {
            cout << endl;
        } else {
            spaceFlag = true;
        }
        bool NAFlag = true;
        for (int i = a; i <= b; i++) {
            if (isLeapYear(i)) {
                cout << i << endl;
                NAFlag = false;
            }
        }
        if (NAFlag) {
            cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 0
import Data.List
import Control.Monad

solve :: Int -> Int -> [[Int]] -> Int
solve n m xyz = maximum . map f $ replicateM 3 [-1,1] where
  f p = sum' . take m . sortBy (flip compare) $
        map (sum . zipWith (*) p) xyz

sum' = sum . (0:)

main = do
  [n, m] <- readWords
  xyz <- replicateM n readWords
  print $ solve n m xyz

readWords = map read . words <$> getLine


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

#define MAXINF 1000000005
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repc(it, x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rrepc(it, x) for(auto it = (x).rbegin(); it != (x).rend(); ++it)
#define all(x) (x).begin(), (x).end()

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, a;
    cin >> h >> a;
    int ans = h/a + (h%a==0?0:1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
H, W, K  = map(int, input().split())
HW = [list(input()) for i in range(H)]
ans = 0

for i in range(2**H):
  for j in range(2**W):
    tmp_i = format(i,"0"+str(H)+"b")
    tmp_j = format(j,"0"+str(W)+"b")
    tmp = 0
    for p in range(H):
      if tmp_i[p] == "0":
        continue
      for q in range(W):
        if tmp_j[q] == "0":
          continue
        if HW[p][q] == "#":
          tmp += 1
    #print(tmp)
    if tmp == K:
      ans += 1

print(ans) 

Measured memory_bytes: 9176
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let d,x = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let l = List.map (fun a -> 1+ (d-1) / a) a_lst in
  let sum = List.fold_left (+) 0 l in

  Printf.printf "%d\n" @@ sum + x


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

int main(){
  int max,min;
  string st;
  cin >> min >> max;

  int cnt = 0;
  for(int i = min; i <= max; i++){
    st = to_string(i);
    //cout << st << endl;
    if(st[0] == st[4] && st[1] == st[3]) cnt++;
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        h: usize,
        w: usize,
        ss: [String; h],
    };
    let s = ss.iter().map(|s| s.chars().collect::<Vec<_>>()).collect::<Vec<_>>();

    for i in 0..h{
        for j in 0..w{
            if s[i][j] == '.'{
                let sx = if j == 0{0}else{j-1};
                let ex = if j == w-1{w-1}else{j+1};
                let sy = if i == 0{0}else{i-1};
                let ey = if i == h-1{h-1}else{i+1};
                // println!("{},{},{},{},{},{}",i,j,sx,sy,ex,ey);
                let mut count = 0;
                for x in sx..ex+1{
                    for y in sy..ey+1{
                        if s[y][x] == '#'{
                            count += 1;
                        }
                    }
                }
                print!("{}", count);
            }
            else {
                print!("#" );
            }
        }
        println!("")
    }

}


Measured memory_bytes: 4352
#include<stdio.h>                                                 
#include<string.h>                                                
int main(void){                                                   
   int K,i;                                                       
   char S[100];                                                   
                                                                  
   scanf("%d",&K);                                                
   scanf("%s",S);                                                 
   int len = strlen(S);                                           
                                                                  
   if(len <= K){                                                  
      printf("%s",S);                                             
   }else{                                                         
   for(i = 0; i < K; i++){                                        
      printf("%c",S[i]);                                          
   }                                                              
      printf("...");                                              
    }                                                             
   return 0;                                                      
}    

Measured memory_bytes: 1708
N, M = map(int, input().split())
num = ['*' for _ in range(N)]


for _ in range(M):
    s, c = input().split()
    s = int(s)

    if num[s-1] != '*' and num[s-1] != c:
        print('-1')
        exit()
    else:
        num[s-1] = c

if len(num) == 1 and (num[0] == '0' or num[0] == '*'):
    print('0')
    exit()

if num[0] == '0':
    print('-1')
    exit()

for i in range(N):
    if num[i] == '*':
        if i == 0:
            print('1', end='')
        else:
            print('0', end='')
    else:
        print(num[i], end='')

print('')


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);
template<long long Mod = mod>
constexpr long long MOD(long long in) {
    return in % Mod;
}

int n;
int p[200005];
int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> n;

    for (int i = 0; i < n; ++i)
        std::cin >> p[i];

    std::set<std::pair<int, int>> s;
    for (int i = 0; i < n; ++i) {
        auto begin = s.lower_bound({ p[i] - 1,0 });

        if (begin != s.end() && begin->first == p[i] - 1)
            s.emplace(p[i], begin->second + 1);
        else
            s.emplace(p[i], 1);
    }

    int ans = 0;
    for (auto ss : s) {
        ans = std::max(ans, ss.second);
    }

    std::cout << n - ans << std::endl;

    return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  int m = 0;
  rep(i, S.size()) {
    if (S[i] == '1') m++;
  }

  cout << m << endl;

  return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

int main() {
    int L, R, d;
    int cnt = 0;
    cin >> L >> R >> d;
    for (int i = L; i <= R; i++) {
        if (i % d == 0) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;
	string s, t;cin>>s>>t;
	n = s.length();
	m = t.length();
	bool mf = true;
	for(int i = n-1 - (m-1);i >= 0;i--){
		bool flag = true;
		rep(j, m){
			if(s[i+j]=='?'||s[i+j] == t[j]){

			}else{
				flag = false;
			}
		}
		if(flag){
			mf = false;
			rep(j, m){
				s[i+j] = t[j];
			}
			break;
		}
	}
	if(mf){
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	rep(i, n){
		if(s[i] == '?')s[i] = 'a';
	}
	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc173/tasks/abc173_e

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define FORR(i,b,e) for(int i=(b); i>=(int)(e); i--)
#define ALL(v)     (v.begin()), (v.end())

#define DEBUG 1
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int N_MAX = 2*1e5;
const int A_I_MAX = 1e9;
const int MOD = 1e9+7;

int N, K;
vector<int> A;

vector<double> pacc;
vector<double> nacc;

int main() {
  cin >> N >> K;
  A = vector<int>(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A));

  int ni = lower_bound(ALL(A), 0) - A.begin();
  int nc = ni;
  nacc = vector<double>(nc + 1);
  nacc[0] = 0;
  for (int i = 0, j = 0; i < ni; i++, j++) {
    nacc[j + 1] = nacc[j] + log10(abs(A[i]));
  }

  int pi = upper_bound(ALL(A), 0) - A.begin();
  int pc = N - pi;
  pacc = vector<double>(pc + 1);
  pacc[0] = 0;
  for (int i = N - 1, j = 0; i >= pi; i--, j++) {
    pacc[j + 1] = pacc[j] + log10(abs(A[i]));
  }

  double xlog = 0;
  int xnk = -1;
  int xpk = -1;
  for (int nk = 0; nk <= K; nk += 2) {
    int pk = K - nk;
    if (pk > pc || nk > nc) continue;
    double tmp = pacc[pk] + nacc[nk];
    if (tmp > xlog) {
      xlog = tmp;
      xnk = nk;
      xpk = pk;
    }
  }

  ll ans = 1;
  if (xlog > 0) {
    for (int i = 0; i < xnk; i++) {
      ans = ans * (MOD + A[i]) % MOD;
    }
    for (int i = N - 1; i >= N - xpk; i--) {
      ans = ans * A[i] % MOD;
    }
  } else {
    sort(ALL(A), [](auto const& lhs, auto const& rhs) { return abs(lhs) < abs(rhs); });
    REP(i, K) ans = ans * (MOD + A[i]) % MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 5872
import sys

def f(a):
    A = [0] * 40
    for i in range(40):
        if a >= 2**i:
            b = a // 2**(i+1) * 2**i
            c = max(0, a % 2**(i+1) - 2**i + 1)

            if (b+c) % 2 == 1:
                A[i] = 1
        else:
            break
    return A



def main():
    input = sys.stdin.readline
    A, B = map(int, input().split())

    X = f(A-1)
    Y = f(B)
    ans = 0
    for i in range(40):
        if X[i] == 0 and Y[i] == 0:
            continue
        if X[i] * Y[i] == 0:
            ans += 2**i

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N = int(input())

def compare(lstA, lstB):
    lst_fail = [b - a for a, b in zip(lstA, lstB) if a<b]
    lst_pass = sorted([a - b for a, b in zip(lstA, lstB) if a>=b], reverse=True)
    return lst_fail, lst_pass

def change_count(lst_fail, lst_pass):
    sum_short = sum(lst_fail)
    cnt = 0
    scores = 0
    for score in lst_pass:
        if scores >= sum_short:
            break
        else:
            scores += score
            cnt += 1
    return cnt


lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))

lst_fail, lst_pass = compare(lst_A, lst_B)

cnt_f = len(lst_fail)
cnt_p_change = change_count(lst_fail, lst_pass)

if sum(lst_A) < sum(lst_B):
    print(-1)
else:
    print(cnt_f + cnt_p_change)

Measured memory_bytes: 18620