akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
    long n;
    cin >> n;
    long a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
  
    // a[0]が正の場合
    long sum = 0;
    long plus = 0;
    for (int i = 0; i < n; ++i){
    	if (i%2==0){
    	    if (sum+a[i]<1){
    	        plus += 1 - (sum + a[i]);  //sum+a[i]+k = 1
    	        //cout << "i:" << i << " a[i]:" << a[i] << " + " 
    	        //    << 1 - (sum + a[i]) << " sum " << sum << " -> " << 1 << endl;
    	        sum = 1;
    	        
    	    }
    	    else sum += a[i];
    	}
    	else{
    	    if (sum+a[i]>-1){
    	        plus += 1 + (sum + a[i]);  //sum+a[i]-k = -1
    	        sum = -1;
    	    }
    	    else sum += a[i];
    	}
    	// cout << "i:" << i << " " << a[i]  << " " << plus<< " " << sum << endl;
    }

    // a[0]が負の場合
    sum = 0;
    long minus = 0;
    for (int i = 0; i < n; ++i){
    	if (i%2==1){
    	    if (sum+a[i]<1){
    	        minus += 1 - (sum + a[i]);  //sum+a[i]+k = 1
    	        sum = 1;
    	    }
    	    else sum += a[i];
    	}
    	else{
    	    if (sum+a[i]>-1){
    	        minus += 1 + (sum + a[i]);  //sum+a[i]-k = -1
    	        sum = -1;
    	    }
    	    else sum += a[i];
    	}
    	// cout << "i:" << i << " " << a[i]  << " " << minus<< " " << sum << endl;
    }
    cout << min(plus, minus) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w, ans = 0, count = 0;
  string t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> h >> w;
  vs s(h);
  rep(i, 0, h)
  {
    cin >> s[i];
  }
  const lli dx[] = {1, 0, -1, 1, -1, 0, -1, 1};
  const lli dy[] = {1, 1, 1, 0, 0, -1, -1, -1};

  rep(i, 0, h)
  {
    rep(j, 0, w)
    {
      if (s[i][j] == '#')
      {
        continue;
      }
      rep(k, 0, 8)
      {
        a = i + dy[k];
        b = j + dx[k];
        if (a < 0 || a >= h)
          continue;
        if (b < 0 || b >= w)
          continue;
        if (s[a][b] == '#')
          count++;
      }
      s[i][j] = count + '0';
      count = 0;
    }
  }
  rep(i, 0, h)
  {
    cout << s[i] << endl;
  }
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
const int N = 301;
int n, m, l, q;
vector<pair<int,int> > g[N];
int res[N][N], vis[N];
int s[N*N], t[N*N];
struct data{
	int filled, rem, host;
	bool operator < (const data &rhs) const{
		return (filled > rhs.filled) || (filled == rhs.filled && rem < rhs.rem);
	}
};
data rec[N];
priority_queue<data> wl;
signed main(){
	cin >> n >> m >> l;
	for(int i = 1 ; i <= m ; i ++){
		int u, v, w;
		cin >> u >> v >> w;
		if(w <= l){
			g[u].push_back({v, w});
			g[v].push_back({u, w});
		}
	}
	cin >> q;
	for(int i = 1 ; i <= n ; i ++){
		//cout << "examining i = " << i << endl;
		for(int j = 1 ; j <= n ; j ++){
			rec[j] = {LONG_MAX, LONG_MAX, 0};
		}
		rec[i] = {0, l, i};
		wl.push({0, l, i});
		while(wl.size()){
			data u = wl.top(); wl.pop();
			//cout << u.filled << " " << u.rem << " " << u.host << endl;
			if(u.filled != rec[u.host].filled && u.rem != rec[u.host].rem) continue;
			int filled = u.filled;
			int rem = u.rem;
			for(pair<int,int> v: g[u.host]){
				if(!vis[v.fi]){
					data next;
					if(rem < v.se) next = {filled + 1, l - v.se, v.fi};
					else next = {filled, rem - v.se, v.fi};
					if(rec[v.fi] < next){
						next.host = v.fi;
						rec[v.fi] = next;
						wl.push(next);
					}
				}
			}
		}
		for(int j = 1 ; j <= n ; j ++){
			res[i][j] = (rec[j].filled != LONG_MAX ? rec[j].filled : -1);
			//cout << res[i][j] << " ";
		}
		//cout << endl;
	}
	for(int i = 1 ; i <= q ; i ++){
		cin >> s[i] >> t[i];
	}
	for(int i = 1 ; i <= q ; i ++)
		cout << res[s[i]][t[i]] << endl;
}

Measured memory_bytes: 4992
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int N,K;
    int[] A;

    private void solve() {
        N = nextInt();
        K = nextInt();
        A = new int[N];
        for(int i = 0;i < N;i++) {
            A[i] = nextInt();
        }

        int ans = 1;
        int k = K;
        while(k < N) {
            k += K - 1;
            ans++;
        }
        out.println(ans);
    }
    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

using namespace std;

int main(void){
    int n;
    cin>>n;
    vector <int> a(n), b(n+1), c(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    for(int i=1;i<=n-1;i++){
        cin>>c[i];
    }
    int res=0;
    for(int i=0;i<n;i++){
        res+=b[a[i]];
        //cout<<b[a[i]]<<endl;
        if(i!=0&&a[i]-a[i-1]==1){
            res+=c[a[i]-1];
            //cout<<c[a[i]-1]<<endl;
        }
    }
    cout<<res<<endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll N, A;
    cin >> N >> A;
    ll rem = N % 500;
    if(rem <= A) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using li = unsigned long long int;
using namespace std;

int main() {
    fastIO;
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    sort(a.begin(), a.end());
    cout << a.back() - a.front() << endl;
}

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

using namespace std;

int main() {
    int H, W;
    
    for (;;) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for (int h = 1; h <= H; h++) {
            for (int w = 1; w <= W; w++) {
                char c = '.';
                if (h == 1 || h == H || w == 1 || w == W) {
                    c = '#';
                }
                cout << c;
            }
            cout << endl;
        }
        cout << endl;
    }
    
}



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

using namespace std;

 long long int knapSack(long long int W[],long long int V[],long long int n,long long int w){
    long long int res[n+1][w+1];

    for(long long int i=0;i<=w;i++){
        res[0][i]=0;
    }

    for(long long int j=0;j<=n;j++){
        res[j][0]=0;
    }

    for(long long int i=1;i<=n;i++){
        for(long long int j=1;j<=w;j++){
            if(W[i-1]<=j){
                res[i][j]=max(res[i-1][j],V[i-1]+res[i-1][j-W[i-1]]);
            }
            else{
                res[i][j]=res[i-1][j];
            }
        }
    }
    return res[n][w];
}

 int main(){
    long long int n,w;
    cin>>n>>w;
    long long int W[n],V[n];
    for(long long int i=0;i<n;i++){
        cin>>W[i]>>V[i];
    }
    cout<<knapSack(W,V,n,w)<<endl;
    return 0;
}


Measured memory_bytes: 79104
import java.io.*

val pw = PrintWriter(System.out)
const val MOD = 1000000007L
const val INF = 2147483647
const val LINF = 9223372036854775807L

fun main(args: Array<String>) {
    solve()
    pw.flush()
}

fun solve() {
    val n = nextLong()
    println(n * (n - 1) / 2)
}

fun println(v: String) {
    pw.println(v)
}

fun print(v: String) {
    pw.print(v)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ").toMutableList()
fun nextIntList(index: Int = 0) = next().split(" ").map { it.toInt() + index }.toMutableList()
fun nextLongList(index: Long = 0L) = next().split(" ").map { it.toLong() + index }.toMutableList()
fun nextDoubleList() = next().split(" ").map { it.toDouble() }.toMutableList()

fun ary(n: Int, init: String = "") = Array(n) { init }
fun intAry(n: Int, init: Int = 0) = IntArray(n) { init }
fun longAry(n: Int, init: Long = 0L) = LongArray(n) { init }
fun doubleAry(n: Int, init: Double = 0.0) = DoubleArray(n) { init }
fun ary2(n: Int, m: Int, init: String = "") = Array(n) { Array(m) { init } }
fun intAry2(n: Int, m: Int, init: Int = 0) = Array(n) { IntArray(m) { init } }
fun longAry2(n: Int, m: Int, init: Long = 0) = Array(n) { LongArray(m) { init } }
fun doubleAry2(n: Int, m: Int, init: Double = 0.0) = Array(n) { DoubleArray(m) { init } }
fun ary3(n: Int, m: Int, k: Int, init: String = "") = Array(n) { Array(m) { Array(k) { init } } }
fun intAry3(n: Int, m: Int, k: Int, init: Int = 0) = Array(n) { Array(m) { IntArray(k) { init } } }
fun longAry3(n: Int, m: Int, k: Int, init: Long = 0L) = Array(n) { Array(m) { LongArray(k) { init } } }
fun doubleAry3(n: Int, m: Int, k: Int, init: Double = 0.0) = Array(n) { Array(m) { DoubleArray(k) { init } } }

fun abs(n: Int): Int = Math.abs(n)
fun abs(n: Long): Long = Math.abs(n)
fun abs(n: Double): Double = Math.abs(n)
fun max(vararg values: Int) = if (values.isEmpty()) -INF else values.max()!!
fun max(vararg values: Long) = if (values.isEmpty()) -LINF else values.max()!!
fun min(vararg values: Int) = if (values.isEmpty()) INF else values.min()!!
fun min(vararg values: Long) = if (values.isEmpty()) LINF else values.min()!!
fun swap(a: String, b: String) = Pair<String, String>(b, a)
fun swap(a: Int, b: Int) = Pair<Int, Int>(b, a)
fun swap(a: Long, b: Long) = Pair<Long, Long>(b, a)
fun swap(a: Double, b: Double) = Pair<Double, Double>(b, a)

fun gcd(a: Int, b: Int): Int = if (a % b == 0) b else gcd(b, (a % b))

Measured memory_bytes: 31732
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn=100111;
int n;
ll fac[maxn],inv[maxn],si[maxn];
ll a[maxn],dp[maxn];
ll get_coef(int a,int b)
{
	return fac[n]*(si[a]+si[b]-1+mod)%mod;
}
int main()
{
	fac[0]=1;
	for(int i=1;i<maxn;i++)fac[i]=fac[i-1]*i%mod;
	for(int i=1;i<maxn;i++)inv[i]=qpow(i,mod-2);
	for(int i=1;i<maxn;i++)si[i]=(si[i-1]+inv[i])%mod;
	geti(n);
	for(int i=1;i<=n;i++)geti(a[i]);
	ll ans=0;
	for(int i=1;i<=n;i++)ans=(ans+a[i]*get_coef(i,n-i+1))%mod;
	cout<<(ans%mod+mod)%mod<<endl;
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;

struct UnionFind {
  // 要素に対応する値は自分の根。根は要素数の-1倍したものを代入する。
  // 根ならそのグループの要素数(負)が、子であれば親の番号が入る。初期値-1。
  vector<int> uni;
  UnionFind(){
    uni = vector<int>(100100, -1);
  }

  // 頂点aの所属するグループを調べる。
  int root(int a)
  {
    // uni[a]が負の値なら親はa自身
    if (uni[a] < 0) return a;
    // 正の値であれば、親ルートを調べ戻り値で根に直接つなぐ。
    else {
      uni[a] = root(uni[a]);
      return uni[a];
      // return uni[a] = root(uni[a]);
    }
  }

  // 頂点aとbをつなぐ、もともと同じグループの場合falseを返す。
  bool connect(int a, int b)
  {
    a = root(a);
    b = root(b);
    if (a == b) return false;

    // aを大きなグループにしたいので、逆であれば入れ替える。
    if (uni[a] > uni[b])
    {
      int hoge = a;
      a = b;
      b = hoge;
    }

    //aとbを結合し、bをaの親とする。
    uni[a] += uni[b];
    uni[b] = a;
    return true;
  }

  //  頂点a, bが同じグループか
  bool isConnect(int a, int b)
  {
    return root(a) == root(b);
  }

  // 頂点aを含むグループの頂点数を調べる
  int size(int a)
  {
    return -uni[root(a)];
  }

};


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> l(m), r(m), d(m);
  // vector<pair<p, int>> v(m);
  // rep(i, n) cin >> v[i].first.second >> v[i].first.first >> v[i].second;
  vector<vector<p>> v(n);
  UnionFind uni;
  rep(i, m){
    int l, r, d;
    cin >> l >> r >> d;
    l--;r--;
    v[l].push_back({r, d});
    v[r].push_back({l, -d});
    uni.connect(l, r);
  }

  set<int> roots;
  for (int i = 0; i < n; ++i) {
    roots.insert(uni.root(i));
  }

  vector<bool> visited(n);
  vector<int> dist(n, -1);
  for(auto r : roots){
    visited[r] = true;
    queue<int> q;
    q.push(r);
    dist[r] = 0;
    while(!q.empty()){
      int from = q.front();
      q.pop();
      visited[from] = true;
      for(auto a : v[from]){
        int to = a.first;
        int d = a.second;
        if(visited[to]) continue;
        visited[to] = true;
        dist[to] = dist[from] + d;
        q.push(to);
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    for(auto a : v[i]){
      int to = a.first;
      int d = a.second;
      if(dist[i] + d != dist[to]){
        cout << "No" << endl;
        exit(0);
      }
    }
  }
  cout << "Yes" << endl;

}


Measured memory_bytes: 16384
var cc,so: ansistring ;
    a,b,c,d,e,f,g,gg,yo : longint ;
begin
 readln(cc);
 a:=length(cc);
 while (gg=0)and(yo=0) do
  begin
   so:='';
   for b:=a-4 to a do
    so:=so+cc[b];
//   writeln(so);
   a:=a-5;
   if so='dream' then
    a:=a
   else if so='erase' then
    a:=a
   else if so='raser' then
    begin
     if a>=1 then
      begin
       if (cc[a]='e')then
        a:=a-1
       else
        gg:=1;
      end
     else
      gg:=1;
    end
   else if so='eamer'then
    begin
     if a>=2 then
      begin
       if (cc[a]='r')and(cc[a-1]='d') then
        a:=a-2
       else
        gg:=1;
      end
     else
      gg:=1;
    end
   else
    gg:=1;
   if a=0 then
    yo:=1
   else if a<5 then
    gg:=1

//   writeln(cc[a-1],a:2);
  end;
 if yo=1 then
 writeln('YES')
 else if gg=1 then
  writeln('NO');

end.


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

int main() 
{
    string s;
    cin>>s;
    int n = 0;
    for(int i = 0; i<s.size(); i++) {
        if(s[i] == '-') n--;
        else n++;
    }
    cout<<n<<endl;
    return 0;
}


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

struct Card{char suit, value;};

void bubble(struct Card A[], int N){
    for(int i = 0; i < N; i++){
        for(int j = N-1; j >= i + 1; j--){
            if(A[j].value < A[j - 1].value){
                Card t = A[j];
                A[j] = A[j - 1];
                A[j - 1] = t;
            }
        }
    }
}

void slection(struct Card A[], int N){
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i; j < N; j++){
            if(A[j].value < A[minj].value)minj = j;
        }
        Card t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
}

void print(struct Card A[], int N){
    for(int i = 0; i < N; i++){
        if(i > 0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N){
    for(int i = 0; i < N; i++){
        if(C1[i].suit != C2[i].suit)return false;
    }
    return true;
}

int main(){
    Card C1[100], C2[100];
    int N;
    char ch;

    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> C1[i].suit >> C1[i].value;
    }

    for(int i = 0; i < N; i++) C2[i] = C1[i];

    bubble(C1, N);
    slection(C2, N);

    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);
    if(isStable(C1, C2, N)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }

    return 0;

}


Measured memory_bytes: 3100
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    int m;
    cin >> m;
    vector<int> p(m);
    vector<int> x(m);
    for (int i = 0; i < m; ++i) {
        cin >> p[i] >> x[i];
    }
    for (int i = 0; i < m; ++i) {
        ll sum = 0;
        for (int j = 0; j < n; ++j) {
            if(p[i] == j+1) sum += x[i];
            else sum += t[j];
        }
        cout << sum << std::endl;
    }
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


struct BIT {
  int n;
  vector<ll> tree;
  BIT(int n):n(n),tree(n+1) {} 
  void fill(ll val) {
    REP(i, n+1) tree[i] = (i&-i) * val;
  }
  void add(int idx, ll val) {
    for (int x=idx+1; x<=n; x+=x&-x) tree[x] += val;
  }
  // sum[0, idx]
  ll range(int idx) {
    ll sum=0;
    for (int x=idx+1; x>0; x-=x&-x) sum += tree[x];
    return sum;
  }
  // sum[a, b]
  ll range(int a, int b) {
    return range(b) - range(a - 1);
  }
};

// 反転数
// a[i] > a[j] かつ  i < j である組 (i,j) の個数
// バブルソートの交換回数でもある
// 蟻本 p.162
ll inversion_number(int *A, int N) {
  ll ans = 0;
  // normalize(A); // 座標圧縮
  BIT bit(N + 5);
  REP(i, N) {
    ans += bit.range(N - A[i]);
    bit.add(N - A[i], 1);
  }
  return ans;
}

const int MAX_N = 212345;
int idx[MAX_N];

int main2() {
  string s; cin >> s;
  int N = (int)s.size();

  vector<int> count(26);
  REP(i, N) count[s[i]-'a']++;
  if (count_if(ALL(count), [](int x){ return x % 2 == 1; } ) >= 2) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> done(26);
  string A,B;
  REP(i, N) {
    int c = s[i]-'a';
    if (count[c] % 2 == 1 && count[c] - done[c] == 1) {
      B += s[i];
    } else if (done[c] < count[c] / 2) {
      A += s[i];
    }
    done[c]++;
  }
  string C = A;
  reverse(ALL(C));
  // cout << s << endl;
  string T = A+B+C;
  // cout << T << endl;

  vector<int> nxt(26);

  int n = 0;
  REP(i, N) {
    int x = nxt[s[i]-'a'];
    while (T[x] != s[i]) x++;
    idx[n++] = x;
    nxt[s[i]-'a'] = x+1;
  }
  // pv(idx, idx + N);

  ll ans = inversion_number(idx, N);
  cout << ans << endl;

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
long long n,z,x,c;
string ss;
int main()
{
    cin>>ss;
    for(int i=0;i<ss.length();i++){
        if(ss[i]=='1')ss[i]='9';
        else if(ss[i]=='9')ss[i]='1';
    }
    cout<<ss<<endl;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)
N, Q = map(int, input().split())

neighbor = defaultdict(list)
counter = [0] * N

for i in range(N-1):
    a, b = map(int, input().split())
    neighbor[a-1].append(b-1)
    neighbor[b-1].append(a-1)

for i in range(Q):
    p, x = map(int, input().split())
    counter[p-1] += x

def solve():
    stack = [(0, None)]
    while stack:
        (node, parent) = stack.pop()
        if parent is not None:
            counter[node] += counter[parent]
        for c in neighbor[node]:
            if c != parent:
                stack.append((c, node))

solve()
print(*counter)


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

#define pb push_back
const int N = 1e6L + 11;
char s[N];
bool vis[N];

bool chk(int n, int m) {
	fill(vis, vis + n + 1, 0);
	vector <int> l, r;
	for(int i = n; i >= 1; i --)
		if(s[i] == 'I' && r.size() < m) {
			r.pb(i);
			vis[i] = 1;
		}
	reverse(r.begin(), r.end());
	for(int i = 1; i <= n; i ++)
		if((s[i] == 'I' || s[i] == 'J') && !vis[i] && l.size() < m)
			l.pb(i);

	if(l.size() < m || r.size() < m) return 0;
	int p = 0;
	for(int i = 1; i <= n; i ++)
		if(s[i] == 'O' && p < m && l[p] <= i && r[p] >= i)
			p ++;
	return p == m;
}

int main() {
	int n; cin >> n;
	scanf("%s", s + 1);
	int l = 0, r = n / 3 + 1;
	while(l + 1 < r) {
		int m = (l + r) / 2;
		if(chk(n, m)) l = m;
		else r = m;
	}
	cout << l << '\n';
}

Measured memory_bytes: 9608
#include <bits/stdc++.h>
#define ld          double
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i = a; i < b; i++)
#define mat         vector<vi>
using namespace std;
const int maxn = 307;
int n, k;
mat dotmod(mat& mx, mat& my){
    int n = mx.size();
    mat ret(n, vi(n, 0));
    rep(i, 0, n){
        rep(j, 0, n){
            rep(k, 0, n)
            ret[i][j] = (ret[i][j] + (mx[k][j] * my[i][k])%hell)%hell;
        }
    }
    return ret;
}
mat dotpow(int p, mat a)
{
    int n = a.size(); p--;
    mat x(a);
    while(p!=0){
        if(p%2==1){
            x = dotmod(x, a);
            p-=1;
        }
        else{
            a = dotmod(a, a);
            p/=2;
        }
    }
    return x;
}

void solve()
{
    cin>>n>>k;
    mat a(n, vi(n, 0));
    rep(i, 0, n){
        rep(j, 0, n)
        cin>>a[i][j];
    }
    a = dotpow(k, a);
    int ans = 0;
    rep(i, 0, n)
    {
        rep(j, 0, n)ans = (ans + a[i][j])%hell;
    }
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
S = input()
K = int(input())
def calculate(S,K):
    normalStart = 1
    firstOneArr = []
    for s in S:
        if s != "1":
            normalStart = int(s)
            break
        else:
            firstOneArr.append(1)
    if K > len(firstOneArr):
        print(normalStart)
    else:
        print(1)
calculate(S,K)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long INF = 1e12;
int main(){
    int a,b,q;
    cin >> a >> b >> q;
    vector<long long> shrine;
    vector<long long> temple;
    shrine.push_back(-INF);
    temple.push_back(-INF);
    long long tmp;
    for(int i = 0;i<a;i++){
        cin >> tmp;
        shrine.push_back(tmp);
    }
    for(int i = 0;i<b;i++){
        cin >> tmp;
        temple.push_back(tmp);
    }
    shrine.push_back(INF);
    temple.push_back(INF);
    vector<long long> ans;
    long long temans,tem;
    long long ls,rs,lt,rt;
    for(int i = 0;i<q;i++){
        cin >> tmp;
        temans = INF;
        auto itrt = upper_bound(temple.begin(),temple.end(),tmp);
        rt = *itrt;
        itrt--;
        lt = *itrt;
        auto itrs = upper_bound(shrine.begin(),shrine.end(),tmp);
        rs = *itrs;
        itrs--;
        ls = *itrs;
        temans = min(temans,abs(rt-tmp)+abs(rs-rt));
        temans = min(temans,abs(rt-tmp)+abs(ls-rt));
        temans = min(temans,abs(lt-tmp)+abs(rs-lt));
        temans = min(temans,abs(lt-tmp)+abs(ls-lt));
        temans = min(temans,abs(rs-tmp)+abs(rt-rs));
        temans = min(temans,abs(rs-tmp)+abs(lt-rs));
        temans = min(temans,abs(ls-tmp)+abs(rt-ls));
        temans = min(temans,abs(ls-tmp)+abs(lt-ls));
        ans.push_back(temans);
    }
    for(int i = 0;i<ans.size();i++){
        cout << ans[i] << endl;
    }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\stdout", "w", stdout);
    }
    int n, d;
    cin >> n >> d;
    vector<vector<int>> v(n);
    FOR(i, n) {
        int vi;
        FOR(k, d){
            cin >> vi;
            v[i].push_back(vi);
        }
    }

    int cnt = 0;
    FOR(i, n){
        for(int j=i+1; j<n; j++){
            ll dist = 0;
            FOR(k, d)
                dist += (v[i][k] - v[j][k]) *(v[i][k] - v[j][k]);

            ll r = round(sqrt(dist));
            if (r*r == dist)
                cnt++;
        }
    }
    cout << cnt << endl;

    //if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

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

bool isPrime[1000010];
void set_prime() {
	for (int i = 1; i <= 1000000; i++) {
		isPrime[i] = true;
	}
	isPrime[0] = false; isPrime[1] = false;
	for (int i = 2; i * i <= 1000000; i++) {
		int j = 2;
		while (i * j <= 1000000) {
			isPrime[i * j] = false;
			j++;
		}
	}
}

int main()
{
	set_prime();
	ll N;
	cin >> N;
	vector<ll> V;
	for (ll i = 2; i * i <= N; i++) {
		if (isPrime[i]) {
			ll sum = i;
			while (sum <= 1000000) {
				V.push_back(sum);
				sum *= i;
			}
		}
	}
	sort(V.begin(), V.end());
	int ans = 0;
	for (ll num : V) {
		if (N % num == 0) {
			N /= num;
			ans++;
		}
		//cout << N << endl;
	}
	if (N > 1000000)  ans++;
	cout << ans << endl;
}


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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
// 解き直し.
// ABC 131解説.
// https://img.atcoder.jp/abc131/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
const int MAX_V = 1e5 + 1;
// const int MAX_V = 8;
using LL = long long;
int cX[MAX_V], cY[MAX_V];  // 各頂点X, Y ごとに, 連結成分番号を保存.
LL cVX[MAX_V], cVY[MAX_V]; // 各連結成分 の X, Y の 頂点数を保存.
vector<int> X[MAX_V], Y[MAX_V];

// 深さ優先探索(depth-first search).
// https://ja.wikipedia.org/wiki/深さ優先探索
// @param x: 探索開始の頂点X番号.
// @param l: 連結成分番号(※1以上).
// @return : 特に無し.
void dfs(int x, int l){

    // 1. 終了条件設定.
    // -> 連結成分番号が設定済みであれば, 終了.
    if(cX[x] > 0) return;
    
    // 2. 頂点 X について, 連結成分情報 を 設定.
    cX[x] = l, cVX[l]++;
    
    // 3. 頂点 X に, 隣接する 頂点 Y を 探索.
    for(auto &y : X[x]){
        
        if(cY[y] > 0) continue;
        // 3-1. 頂点 Y に, 連結成分 l を設定し, 連結成分のカウンターを +1 更新.
        cY[y] = l, cVY[l]++;
        
        // 3-2. 頂点 Y に, 隣接する 頂点 X を 探索(再帰処理).
        for(auto &nx : Y[y]){
            if(cX[nx] > 0) continue;
            dfs(nx, l);
        }
    }
}

int main() {

    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);

    // 以下, 解説通り.
    // 2. グラフ作成.
    for(int i = 0; i < N; i++){
        int u, v;
        scanf("%d %d", &u, &v);
        // u -> v
        X[u].push_back(v);
        // v -> u
        Y[v].push_back(u);
    }
    
    // グラフ情報確認.
    // for(int i = 1; i < MAX_V; i++){
    //     if(X[i].size() > 0) for(auto &p : X[i]) printf("%d %d\n", i, p);
    // }
    
    // 3. 連結成分に分解.
    int c = 0;
    for(int i = 1; i < MAX_V; i++) if(X[i].size() > 0 && cX[i] == 0) c++, dfs(i, c);
    
    // グラフ連結情報確認.
    // for(int i = 1; i < MAX_V; i++){
    //     printf("cX[%d], cY[%d] = [%d, %d]\n", i, i, cX[i], cY[i]);
    //     printf("cVX[%d], cVY[%d] = [%lld, %lld]\n", i, i, cVX[i], cVY[i]);
    // }
    
    // 5. 後処理.
    // ※各連結成分 の X, Y の 頂点数(cVX, cVY) について, long long で 計算しないと, 
    // テストケース(09.txt, 10.txt, 11.txt, 15.txt) で, WA となるので要注意.
    LL ans = 0;
    for(int i = 1; i < MAX_V; i++) ans += cVX[i] * cVY[i];
    ans -= N; // 連結済 の 辺数 を 減算.
    printf("%lld\n", ans);
    return 0;

}

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

int main() {
	// your code goes here
	int i, j, k;
	string s;
	cin>>s;
	for(i=0; i<12; ++i) {
		if(i==4)
			cout<<" ";
		cout<<s[i];
	}
	cout<<endl;
	return 0;
}

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


int main() {
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif
	
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;

	int one = a*60 + b;
	int two = c*60 + d;
	cout << (two-one-e);	

}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl "\n"
#define sz(u) (int)(u.size())
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void solve(){
int a,b,k;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK";
            return ;
        }
    }
    cout<<"NG";
    }
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    }


Measured memory_bytes: 3688
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <unordered_set>
# include <unordered_map>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define STR(x) string x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }



int main()
{
	while (true)
	{
		INT(L); if (L == 0)break;
		vi a;
		FOR(i, 12)
		{
			INT(x); INT(y);
			a.push_back(x-y);
		}
		FOR(i, 12)
		{
			L -= a[i];
			if (L <= 0){
				cout << i + 1 << endl; break;
			}
			if (i == 12 - 1)cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 3056
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        int y = sc.nextInt();
        Long menseki = (long) (t * y);
        long nagasa = (t * 2) + (y * 2);
        System.out.println(menseki + " " + nagasa);

    }

}


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

long attack_time(long hp){
    if(hp == 1){
        return 1;
    }
    return 2 * attack_time(hp / 2) + 1;
}

int main(void){
    long h;
    cin >> h;

    cout << attack_time(h) << "\n";
    return 0;
}


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

int A, B;
long long C, D;
int ans;

int main() {
  cin >> A >> B;
  C = max(A, B);
  D = min(A, B);
  
  if (C % D == 0) cout << C << endl;
  else {
  for (int i = 2; i < 10000000000; i++){
  if ((C * i) % D == 0){
  cout << C * i << endl;
    break;
  } 
  }
  }
  
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
 
long long f(int sign, const vector<long long>& a)
{
  long long cnt = 0;
	long long sum = 0;
 
	for(int i=0; i<a.size(); i++)
	{
		sum += a[i];
		if(sign*sum <= 0)
		{
			long long d = sign - sum;
			sum += d;
			cnt += abs(d);
		}
		
		sign *= -1;
	}
 
	return cnt;
}
 
int main(void)
{
	int n;
	cin >> n;
 
	vector<long long> a(n);
	for(int i=0; i<n; i++)
		cin >> a[i];
 
	long long sum[2];
	sum[0] = f(1, a);
	sum[1] = f(-1, a);
	
	cout << min(sum[0], sum[1]) << endl;
 
	return 0;
}

Measured memory_bytes: 1024
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

#include <vector>
#include <iostream>
#include <functional>
using namespace std;
using modulo = modint<1000000007>;
int main() {
	int N;
	cin >> N;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; ++i) {
		int x, y;
		cin >> x >> y; --x, --y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	vector<modulo> pcomb(N / 2 + 1);
	pcomb[0] = 1;
	for (int i = 1; i <= N / 2; ++i) {
		pcomb[i] = pcomb[i - 1] * (2 * i - 1);
	}
	vector<int> subc(N);
	function<void(int, int)> dfs = [&](int pos, int pre) {
		subc[pos] = 1;
		for (int i : G[pos]) {
			if (i != pre) {
				dfs(i, pos);
				subc[pos] += subc[i];
			}
		}
	};
	dfs(0, -1);
	function<vector<modulo>(int, int)> calc = [&](int pos, int pre) {
		vector<modulo> dp(subc[pos] / 2 + 1);
		dp[0] = 1;
		int sum = 0;
		for (int i : G[pos]) {
			if (i == pre) continue;
			vector<modulo> res = calc(i, pos);
			for (int j = sum; j >= 0; --j) {
				for (int k = res.size() - 1; k >= 1; --k) {
					dp[j + k] += dp[j] * res[k];
				}
				dp[j] *= res[0];
			}
			sum += res.size() - 1;
		}
		if (subc[pos] % 2 == 0) {
			for (int i = 0; i < subc[pos] / 2; ++i) {
				dp[subc[pos] / 2] -= dp[i] * pcomb[subc[pos] / 2 - i];
			}
		}
		return dp;
	};
	vector<modulo> ans = calc(0, -1);
	cout << (modulo(0) - ans[N / 2]).get() << endl;
	return 0;
}

Measured memory_bytes: 17408
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
#define ll int64_t
#define REP(i, n) for (int i=0; i<n; i++)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> p(3, vector<ll>(N));
    REP(i, N) cin >> p[0][i] >> p[1][i] >> p[2][i];
    vector<vector<ll>> p2 = p;

    ll ans = 0;
    REP(i, (1<<3)){
        p = p2;
        REP(j, 3){
            if (i & 1<<j){
                REP(k, N) p[j][k] *= -1;
            }
        }

        vector<ll> s(N);
        REP(j, N) s[j] = p[0][j] + p[1][j] + p[2][j];
        sort(s.begin(), s.end(), greater<ll>());
        ll temp = 0;
        REP(j, M) temp += s[j];

        ans = max(ans, temp);
    }

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 10*9+7

int main(){
  long long x; cin >> x;
  long long money = 100;
  long long cnt = 0;
  while(money<x){
    money = money *(1.01);
    cnt++;
  }
  cout<< cnt <<endl;
}


Measured memory_bytes: 3632
def cardGameForTwo():
	N = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	diffPoint = 0 
	for index in range(0, N):
		if index % 2 == 0:
			diffPoint += a[index]
		else:
			diffPoint -= a[index]
	print(diffPoint)

cardGameForTwo()

Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  long N,K;
  cin>>N>>K;
  long H[200010];
  for (int i=0;i<N;i++) cin>>H[i];
  sort(H,H+N);
  long sum=0;
  for (int i=0; i<N-K; i++) sum+=H[i];
  cout<<sum<<endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.IO;

namespace ABC
{
    class ABC168D
    {
        const string FILE = "/tmp/data.txt";

        static int[] result;
        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            string line;
            string[] sa;
            line = Console.ReadLine();
            sa = line.Split(' ');
            int n = int.Parse(sa[0]);
            int m = int.Parse(sa[1]);

            List<int>[] path = new List<int>[n + 1];
            for (int i = 0; i < n + 1; ++i)
            {
                path[i] = new List<int>();
            }

            for (int j = 1; j < m + 1; ++j)
            {
                line = Console.ReadLine();
                sa = line.Split(' ');
                int a = int.Parse(sa[0]);
                int b = int.Parse(sa[1]);
                path[a].Add(b);
                path[b].Add(a);
            }


            result = new int[n + 1];
            HashSet<int> nextRoom = new HashSet<int>();
            List<int> p = path[1];
            for (int i = 0; i < p.Count; ++i)
            {
                int room = p[i];

                result[room] = 1;
                nextRoom.Add(room);
            }

            HashSet<int> nextNextRoom = new HashSet<int>();
            while (nextRoom.Count > 0)
            {
                foreach (var next in nextRoom)
                {
                    p = path[next];
                    for (int i = 0; i < p.Count; ++i)
                    {
                        int room = p[i];

                        if (result[room] == 0)
                        {
                            result[room] = next;
                            nextNextRoom.Add(room);
                        }
                    }
                }

                var t = nextRoom;
                nextRoom = nextNextRoom;
                nextNextRoom = t;
                nextNextRoom.Clear();
            }

            bool succeed = true;
            for (int i = 2; i < n + 1; ++i)
            {
                if (result[i] == 0)
                {
                    succeed = false;
                    break;
                }
            }
            if (succeed == false)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
                for (int i = 2; i < n + 1; ++i)
                {
                    Console.WriteLine(result[i]);
                }
            }

#if DEBUG
            Console.WriteLine();
#endif
        }
    }
}


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

int main(void){
	int X;
	cin >> X;
	int kyu = 8 - (X-400)/200;
	cout << kyu << endl;
	return 0;
}


Measured memory_bytes: 3648
# def i():
#     yield "100000"
#     a = 0
#     b = 0
#     c = 0
#     l = []
#     for i in range(100000):
#         import random
#         r = random.randint(0, 2)
#         if r == 0:
#             l.append(str(a))
#             a += 1
#         elif r == 1:
#             l.append(str(b))
#             b += 1
#         else:
#             l.append(str(c))
#             c += 1
#     yield " ".join(l)
# input = i().__next__
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    cur = 1
    nums = []
    for i in range(N):
        if A[i] == 0:
            cur *= 1
            nums.append(0)
            continue
        #A[i] != 0
        cnt = 0
        for j, n in enumerate(nums):
            if n == A[i] - 1:
                if cnt == 0:
                    if len(nums) <= j:
                        print(0)
                        return
                    nums[j] += 1
                cnt += 1
        cur *= cnt
        cur %= 10**9+7
        # print(nums)
    m = [0, 3, 6, 6]
    if len(nums) >= 4:
        print(0)
        return
    
    print((cur * m[len(nums)]) % (10**9+7))
main()

Measured memory_bytes: 14396
while True:
    try:
        a, b, c, d, e, f = map(float, input().split())
        y = (a*f - c*d) / (a*e - b*d)
        x = (c - b*y) / a
        print ("%0.3f %0.3f" % (x, y))
    except:
        break


Measured memory_bytes: 7428
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main(){
  int n;cin>>n;
  long long souwa = 0;
  priority_queue<long long,vector<long long>,greater<long long> > nw;
  for(int i = 0; n > i; i++){
    int s;cin>>s;
    for(int j = 0; s > j; j++){
      int tmp;cin>>tmp;
      if(nw.size() < i+1){
        nw.push(tmp);
        souwa += tmp;
      }else{
        if(nw.top() < tmp){
          souwa = souwa-nw.top()+tmp;
          nw.pop();
          nw.push(tmp);
        }
      }
      //cout << nw.size() << " " << souwa << endl;
    }

  }
  cout << souwa << endl;
}


Measured memory_bytes: 6884
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	static int acnt = 0, bcnt = 0;
	static boolean memo[][];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		HashMap<Integer, Integer> hm = new HashMap<>();
		int a, b = 0, c = 0;
		for (int i = 0; i < n; i++) {
			a = sc.nextInt();
			if (hm.containsKey(a)) {
				hm.put(a, hm.get(a) + 1);
			} else {
				hm.put(a, 1);
			}
		}

		for (int i : hm.keySet()) {
			if (hm.get(i) >= 2) {
				b = Math.max(b, i);
			}
		}
		if (hm.containsKey(b)) {
			hm.put(b, hm.get(b) - 2);
		}
		for (int i : hm.keySet()) {
			if (hm.get(i) >= 2) {
				c = Math.max(c, i);
			}
		}
		if (hm.containsKey(c)) {
			hm.put(c, hm.get(c) - 2);
		}
		System.out.println((long) b * c);
	}
}


Measured memory_bytes: 63800
k = gets.to_i

@memo = Array.new(201).map{Array.new(201, 0)}
def gcdmemo(i, j)
  return @memo[i][j] if @memo[i][j] > 0
  u, v = i, j
  while (j > 0) do
    r =  i % j
    i = j
    j = r
  end
  @memo[u][v] = i
end
1.upto(200) do |i|
  1.upto(200) do |j|
    gcdmemo(i, j)
  end
end
ans = 0
1.upto(k) do |i|
  1.upto(k) do |j|
    c = @memo[i][j]
    1.upto(k) do |l|
      ans += @memo[c][l]
    end
  end
end
puts ans

Measured memory_bytes: 14552
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		sum += A[i];
	}
	cout << sum - *max_element(A.begin(), A.end()) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256