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

int main(void){
    string s;
    cin >> s;
    deque<char> dq;
    
    for (int i = 0;i < s.size();i++) {
        dq.push_back(s[i]);
    }

    // query section
    int q;

    cin >> q;
    bool rev = false; //下でも使うので注意
    for (int i = 0;i < q;i++) {
        int t; //1 or 2
        cin >> t;

        if (t == 1) {
            //Ti == 1
            rev = !rev;
            continue;
        }

        //Ti == 2
        int f;
        char c;
        cin >> f >> c;

        if (rev) {
            if (f == 1) {
                f = 2;
            } else {
                f = 1;
            }
        }

        if (f == 1) {
            dq.push_front(c);
        } else {
            dq.push_back(c);
        }
        
    }

    // return section
    string ret = "";
    
    while (!dq.empty()){
        ret.push_back(dq.front());
        dq.pop_front();
    }

    if (rev) {
        reverse(ret.begin(), ret.end());
    }

    cout << ret <<endl;
    return 0;
}

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

using namespace std;

string s,t;

int main(){
	int n,m;
	cin >> s >> t;
	bool possible;
	n=s.size();
	m=t.size();
	if(m>n){
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	string meilleur="",actuel;
	
	for(int i=0;i<n-m+1;i++){
		possible=true;
		for(int j=0;j<m;j++){
			if(s[i+j]!='?' && s[i+j]!=t[j]) possible=false;
		}
		
		if(possible){
			actuel=s;
			for(int j=0;j<n;j++){
				if(actuel[j]=='?') actuel[j]='a';
			}
			for(int j=0;j<m;j++){
				 actuel[i+j]=t[j];
			}
			
			if(meilleur=="" || meilleur>actuel) meilleur=actuel;
		}
	}
	
	if(meilleur=="") cout << "UNRESTORABLE" << endl;
	else cout << meilleur << endl;
	
} 


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <list>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

void solve(){
	int a, n, b, X[100010];
	scanf("%d%d%d", &n, &a, &b);
	for(int i=1;i<=n;i++)scanf("%d", X+i);
	ll ans = 0;
	for(int i=2;i<=n;i++){
		ans += min((X[i] - X[i-1]) * (ll)a, (ll)b);
	}
	printf("%lld", ans);
}

int main(){
	int Tc = 1;// scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int n,a[45];

int main(){
	cin >> n;
	a[1] = a[0] = 1;
	for(int i = 2;i <= n;i++){
		a[i] = a[i-1] + a[i-2];
	}
	cout << a[n] <<endl;
	return 0;
}

Measured memory_bytes: 1164
def warshall_floyd(d):
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

h , w = map(int,input().split())
x = []
for i in range(10):
    p = list(map(int,input().split()))
    x.append(p)

    
x = warshall_floyd(x)
ans = 0
for i in range(h):
    s = list(map(int,input().split()))
    for j in range(w):
        if s[j] != -1:
            ans += x[s[j]][1]
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int a = sc.nextInt();
		sc.close();
		if (h % a == 0) {
			print(h / a);
			return;
		}
		print((h / a) + 1);
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

}


Measured memory_bytes: 22612
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  int n, k, s;
  cin >> n >> k >> s;

  for(int i = 0; i < k; i++){
    cout << s << ' ';
  }
  for(int i = k; i < n; i++){
    cout << s%(1000000000) + 1 << ' ';
  }
  cout << endl;
}


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

const int nex =  3010;
const int mod = 1e9 + 7;

char s[nex];
int dp[nex][nex];
// prefix sum array
int prefix_sum[nex][nex];
// dp[i][j] will store the numbers of ways we can arrange prefix of length i 
// whose last number is j

void add_self(int& a, int b)
{
  a += b;
  if(a > mod)
  {
    a -= mod;
  }
}

int main()
{
  int n;
  scanf("%d%s", &n, s);
  
  // now of ways to put number in string of length 1 is 1
  dp[1][1] = 1;
  
  for(int len = 2; len <= n; len++)
  {
    for(int i = 1; i <= len - 1; i++)
    {
      prefix_sum[len - 1][i] = (prefix_sum[len - 1][i - 1] + dp[len - 1][i]) % mod;
    }
    for(int last_place = 1; last_place <= len; last_place++)
    {
      int L, R;
      if(s[len - 2] == '<')
      {
        L = 1; 
        R = last_place - 1;
      }
      else
      {
        L = last_place;
        R = len - 1;
      }
      if(L <= R)
      {
        add_self(dp[len][last_place], (prefix_sum[len - 1][R] - prefix_sum[len - 1][L - 1] + mod) % mod);
      }
      //  for(int i = L; i <= R; i++)
      //  {
        //  add_self(dp[len][last_place], dp[len - 1][i]);
      //  }
      //  for(int second_last_place = 1; second_last_place <= len - 1; second_last_place++)
      //  {
        //  int real_at_second_last = second_last_place;
        //  if(real_at_second_last >= last_place)
        //  {
          //  real_at_second_last++;
        //  }
        //  if((real_at_second_last < last_place) != (s[len - 2] == '<'))
        //  {
          //  continue;
        //  }
        //  add_self(dp[len][last_place], dp[len - 1][second_last_place]);
      //  }
    }
  }
  int sol = 0;
  for(int i = 1; i <= n; i++)
  {
    add_self(sol, dp[n][i]);
  }
  printf("%d", sol);
  
  return 0;
}


Measured memory_bytes: 69632
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	a++;
	YES(b * 2 <= a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ll n, d, x,ans=0;
  cin >> n >> d >> x;
  d--;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  ans += x;
  REP(i, n) { ans += 1+floor((double)d / a[i]); }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3612
N,K = list(map(int,input().split()))
mod = 10**9+7

lst = [0]*(N+2)
lst[1] = N+1
mi = [0]*(N+2)
ma = [0]*(N+2)
ma[1] = N
for i in range(2,N+2):
    mi[i] = mi[i-1]+i-1
    ma[i] = ma[i-1]+N+1-i
    lst[i] = (ma[i]-mi[i]+1)

print(sum(lst[K::])%mod)

Measured memory_bytes: 70784
#include<iostream>
#include<climits>
using namespace std;
int dp[1000001][4];
int  a[1000001];
int  b[1000001];
int  c[1000001];

int solve(int n)
{
    dp[1][0]=a[1];
    dp[1][1]=b[1];
    dp[1][2]=c[1];

    for(int i=2;i<=n;i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
    }
    int c=max(dp[n][0],max(dp[n][1],dp[n][2]));
    return c;

}
int main()
{
    int n; cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        cin>>b[i];
        cin>>c[i];
    }
    cout<<solve(n)<<endl;
}

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

int ctr[27] = {};

int getIndex(char c){
	if(c>='A' && c<='Z') return c-'A';
	if(c>='a' && c<='z') return c-'a';
	return 26;
}

int main(){
	string str;
	
	while(getline(cin, str)){
		for(int i=str.size()-1; i>=0; i--){
			ctr[ getIndex(str[i]) ] ++;
		}
	}
	for(int i=0; i<26; i++){
		cout << (char)('a'+i) << " : " << ctr[i] << "\n";
	}
	cout << flush;
	
	return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int main(void)
{
	int n,w;
	int v;
	int max;
	double sum;
	int count;
	int i1;

	while(1){
		cin>>n>>w;
		if(n+w==0) break;

		vector<int> bar(15,0);
		count=0;
		for(i1=0;i1<n;i1++){
			cin>>v;
			bar[v/w]++;	
		}

		max=0;
		for(i1=0;i1<15;i1++){
			if(max<bar[i1]) max=bar[i1];
			if(bar[i1]>0) count=i1;
		}

		sum=0.01;
		for(i1=0;i1<=count;i1++){
			sum+=(((double)(count-i1)/(double)count)*((double)bar[i1]/(double)max));
		}

		printf("%lf\n",sum);

	}
	return 0;
}

Measured memory_bytes: 1212
package main

import "fmt"

var N, M, K int

type Unionfind struct {
	par []int
	siz []int
}

func (u *Unionfind) Init(n int) {
	u.par = make([]int, n)
	u.siz = make([]int, n)
	for i := range u.par {
		u.par[i] = i
		u.siz[i] = 1
	}
}

func (u *Unionfind) Root(x int) int {
	if u.par[x] == x {
		return x
	}
	rx := u.Root(u.par[x])
	u.par[x] = rx
	return u.par[x]
}
func (u *Unionfind) Same(x, y int) bool {
	rx, ry := u.Root(x), u.Root(y)
	return rx == ry
}
func (u *Unionfind) Unite(x, y int) {
	rx, ry := u.Root(x), u.Root(y)
	if rx == ry {
		return
	}
	if u.siz[ry] < u.siz[rx] {
		rx, ry = ry, rx
	}
	u.siz[ry] += u.siz[rx]
	u.par[rx] = ry
}
func (u *Unionfind) Size(x int) int {
	return u.siz[u.Root(x)]
}

var fs [][]int
var funion Unionfind

func main() {
	fmt.Scan(&N, &M, &K)
	funion.Init(N)
	fs = make([][]int, N)

	for i := 0; i < M; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		a, b = a-1, b-1
		fs[a] = append(fs[a], b)
		fs[b] = append(fs[b], a)
		funion.Unite(a, b)
	}
	for i := 0; i < K; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		a, b = a-1, b-1
		fs[a] = append(fs[a], b)
		fs[b] = append(fs[b], a)
	}

	for a := 0; a < N; a++ {
		siz := funion.Size(a) - 1
		for _, b := range fs[a] {
			if funion.Same(a, b) {
				siz--
			}
		}
		if a == N-1 {
			fmt.Printf("%d\n", siz)
		} else {
			fmt.Printf("%d ", siz)
		}
	}
}


Measured memory_bytes: 15616
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B; cin >> A >> B;
  A--; B--;
  vector<vector<char>> S(100,vector<char>(100,'U'));
  //'U'は未確定を表す
  
  for(int i = 1; i <= A; i++){ 
    int a = i/50; int b = i%50;
    S[2*a+1][2*b] = '.';}
  
  for(int j = 1; j <= B; j++){
    int a = j/50; int b = j%50;
    S[2*a+1+50][2*b] = '#';}
  
  for(int i = 0; i < 100; i++){
    for(int j = 0; j < 100; j++){
      if( i < 50 && S[i][j] == 'U'){ S[i][j] = '#';}
      if( i >= 50 && S[i][j] == 'U'){ S[i][j] = '.';}
    }}
  
  cout << 100 << " " << 100 << endl;
  for(int i = 0; i < 100; i++){
    for(int j = 0; j < 100; j++){
      cout << S[i][j];}
    cout << endl;}
  
  return 0;}
     

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

/*
 * .#.#.#.#.#.#
 * ############
 *
 *
 *
 */

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;

    cout << "100 100" << endl;
    a--, b--;
    REP(i, 100) REP(j, 100){
        if(i < 50){
            if(i % 2 == 0 && j % 2 == 0 && a > 0){
                cout << '.';
                a--;
            }else{
                cout << '#';
            }
        }else{
            if(i % 2 == 1 && j % 2 == 0 && b > 0){
                cout << '#';
                b--;
            }else{
                cout << '.';
            }
        }
        if(j == 99) cout << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

int main(){
	ll K;
	cin >> K;
	ll A = K/50;
	ll B = K%50;
	cout << 50 <<endl;
	rep(i,B){
		cout << 50+A << " ";
	}
	rep(i,50-B){
		if(A>0){
			cout << 49+A-B << " ";
		}else{
			cout << 0 << " ";
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");

  K = parseInt(input[0]);
  [A, B] = input[1].split(" ").map((str) => parseInt(str, 10));

  for (let i = A; i <= B; i++) {
    if (i % K === 0) {
      console.log("OK");
      return;
    }
  }
  console.log("NG");
}

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


Measured memory_bytes: 29468
#include <iostream>
#include <vector>
using namespace std;
int main() {
    while (true) {
        int n, p; cin >> n >> p;
        if (n == 0 and p == 0) break;
        vector<int> a(n);
        int b = p;
        int i = 0;
        while (true) {
            if (b) {
                -- b;
                ++ a[i];
                if (a[i] == p) break;
            } else {
                b = a[i];
                a[i] = 0;
            }
            i = (i + 1) % n;
        }
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
A = int(input())

B = int(input())

if A == 1 and B == 2:
  print(3)
elif A == 2 and B == 1:
  print(3)
elif A == 2 and B == 3:
  print(1)
elif A == 3 and B == 2:
  print(1)
elif A == 1 and B == 3:
  print(2)
elif A == 3 and B == 1:
  print(2)
  
  

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int N = 1e5+10;
int a[N];
int main(){
    int a,b;
    cin >> a >> b;
    if(a >=10 || b>=10) cout <<"-1\n";
    else cout << a*b<<'\n';





    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n;
long long ans, a[10][10];
int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++) if(i%10){
		int t = i;
		for(;t/10; t/=10);
		a[t][i%10]++;
	}
	rep(i,10) rep(j,10) ans += a[i][j]*a[j][i];
	printf("%lld\n", ans);
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt(),k=nxt();
    vector <double> v(n);
    for(int i=0;i<n;i++)
    {
        double x;
        cin>>x;
        v[i]=(x+1)/2;
    }
    double max=0;
    for(int i=0;i<k;i++)
        max+=v[i];
    double cur=max;
    for(int i=k;i<n;i++)
    {
        cur+=v[i];
        cur-=v[i-k];
        if(cur>max)
            max=cur;
    }
    cout<<setprecision(10)<<max<<endl;
  

    return 0;   
}


 
 


Measured memory_bytes: 1792
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const int big=1e9+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
class dinic{
public:
	int n,sta,gol;
	vector<vector<llint>> hen;
	vector<int>dis;//bfsの距離
	//隣接行列(O(VVE)なので)
	dinic(int in,int s,int g){
		n=in;
		sta=s;
		gol=g;
		hen.res(in);
		dis.res(in);
		for(int i=0;i<n;i++){hen[i].res(in);}
	}
	void add(int u,int v,llint wei){hen[u][v]+=wei;}
	//隣接なので逆編情報が不要!!
	//増加のbfsする
	//それが増加する向きだけに流す
	//流れないなら、終了!
	void bfs(void){
		int i;
		for(i=0;i<n;i++){dis[i]=-1;}//初期化
		queue<pair<int,int>>que;
		que.push(mp(0,sta));
		dis[sta]=0;
		while(!que.empty()){
			
			int kyo=que.front().fir;
			int town=que.front().sec;
			que.pop();
			for(i=0;i<n;i++){
				if(hen[town][i]!=0&&dis[i]==-1){dis[i]=kyo+1;que.push(mp(kyo+1,i));}
			}
		}
	}
	llint dfs(int ter,llint lim){
		//それまでの上限がlim
		//流した量を返す
		if(ter==gol){return lim;}
		llint ans=0;
		int i;
		for(i=0;i<n;i++){
			if(dis[ter]>=dis[i]||hen[ter][i]==0){continue;}//dinic
			if(lim==ans){break;}
			llint nga=dfs(i,min(lim-ans,hen[ter][i]));
			ans+=nga;
			hen[ter][i]-=nga;
			hen[i][ter]+=nga;
		}
		return ans;
	}
	llint solve(void){
		llint ans=0;
		while(-1){
			bfs();
			llint nga=dfs(sta,big);
			ans+=nga;
			if(nga==0){break;}
		}
		return ans;
	}
};
int main(void){
	int h,w,i,j;cin>>h>>w;
	dinic gra(h+w,-1,-1);//ダミー
	vector<string> mat(h);
	for(i=0;i<h;i++){
		cin>>mat[i];
		for(j=0;j<w;j++){
			if(mat[i][j]=='o'){gra.add(h+j,i,1);gra.add(i,h+j,1);}
			if(mat[i][j]=='S'){
				gra.sta=i;
				gra.add(h+j,i,999999);gra.add(i,h+j,999999);
			}
			if(mat[i][j]=='T'){
				gra.gol=i;
				gra.add(h+j,i,999999);gra.add(i,h+j,999999);
			}
		}
	}
	if(gra.sta==gra.gol){cout<<-1<<endl;RE;}
	int ans=gra.solve();
	if(ans<999876){cout<<ans<<endl;}else{cout<<-1<<endl;}
	RE;
}

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

int main() {
    int K, N;
    cin >> K >> N;
    
    vector<int> A(N);

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

    int md = A[0] + (K-A[N-1]);
    rep(i, N-1) md = max(md, A[i+1]-A[i]);
    cout << K-md << endl;
}

Measured memory_bytes: 1024
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    S = input()
    T = "ACGT"

    print(T[3-T.index(S)])


main()


Measured memory_bytes: 5172
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <cctype>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    string S; cin >> S;
    int N = S.size();
    bool ok = S[0] == 'A';
    int countC = 0;
    for (int i = 2; i < N-1; ++i) {
        if (S[i] == 'C') countC += 1;
        else ok &= islower(S[i]) > 0;
    }

    ok &= countC == 1;

    ok &= islower(S[1]) > 0;
    ok &= islower(S[N-1]) > 0;

    if (ok) cout << "AC" << endl;
    else cout << "WA" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int ans = 0;
		
		for (int i = 1; i <= N; i++) {
			
			int keta = String.valueOf(i).length();
			if(keta % 2 ==1){
				ans++;
			}
			
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 27732
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pii> v(n);
    REP(i,n) {
        cin >> v[i].first >> v[i].second;
    }
    
    sort(ALL(v));
    ll ans = 0;
    ll idx = 0;
    ll dam = 0;
    priority_queue<pll,vector<pll>, greater<pll>> pq;
    while(v.size() > idx) {
        //cerr << v.size() << endl;
        while(!pq.empty() && pq.top().first < v[idx].first) {
            dam -= pq.top().second;
            pq.pop();
        }
        ll bomb = max(0LL,(v[idx].second + a - dam -1) / a);
        ll dm = a * bomb;
        dam += dm;
        ans += bomb;
        pq.emplace(v[idx].first + d * 2,dm);
        idx++;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 6768
var data = [
	[500*3,850*3*0.88,4],
	[300*4,550*4*0.85,5],
	[200*5,380*5*0.8,6],
	[500,850,11],
	[300,550,17],
	[200,380,26]
];

var f = function(input){
	var min = 100000000;
	var index = [0,0,0,0,0,0];
	for(index[0] = 0; index[0]<data[0][2]; index[0]++){
	for(index[1] = 0; index[1]<data[1][2]; index[1]++){
	for(index[2] = 0; index[2]<data[2][2]; index[2]++){
	for(index[3] = 0; index[3]<data[3][2]; index[3]++){
	for(index[4] = 0; index[4]<data[4][2]; index[4]++){
	for(index[5] = 0; index[5]<data[5][2]; index[5]++){
		var g = 0;
		var price = 0;
		for(var i=0; i<6; i++){
			g += index[i]*data[i][0];
			price += index[i]*data[i][1];
		}
		if(g==input) min = Math.min(price, min);
	}
	}
	}
	}
	}
	}
	return min;
};

var lines = [];

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{
	chunk.trim().split('\n').forEach(function(line) {
		lines.push(line);
	});
});

process.stdin.on('end', function(){
	for(var i=0; i<lines.length; i++) {
		var e = parseInt(lines[i].trim());
		if(e==0) return;
		console.log(f(e));
	}
});

Measured memory_bytes: 9456
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define rev(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;






int main() {

    int N, D, X;
    cin >> N >> D >> X;
    int a[N];
    rep(i,N) cin >> a[i];

    int ans = X;
    for (int d = 1; d <= D; ++d) {
        rep(i,N) {
            if ((d - 1) % a[i] == 0) ++ans;
        }
    }

    out(ans);

    return 0;
}




//              g++ -std=c++1z






Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include<string.h>
#include <math.h>
#include <stack>
#define ll long long
using namespace std;

int main() {

	int a, b;
	scanf("%d %d", &a, &b);
	if (a >= 13)
		printf("%d\n", b);
	else if (a >= 6)
		printf("%d\n", b / 2);
	else {
		printf("0\n");
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[1020];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	int f=0;
	for(int i=1;i<=n;i++){
		if(a[i]%2==0){
			if(a[i]%3!=0&&a[i]%5!=0) f=1;
		}
	}
	if(f) cout<<"DENIED"<<endl;
	else cout<<"APPROVED"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
  ll n,k,r,s,p;
  string t;
  cin5(n,k,r,s,p);
  cin>>t;
  loop(i,n){
    if(t[i]=='r'){
      t[i]='p';
      continue;
    }
    if(t[i]=='s'){
      t[i]='r';
      continue;
    }
    if(t[i]=='p')t[i]='s';
  }
  vec ans(n,-1);
  Pool(i,k,n-1){
    if(t[i]!=t[i-k]){
      if(ans[i]!=0)ans[i]=1;
      ans[i-k]=1;
    }
    if(t[i]==t[i-k]&&ans[i]==0){
      ans[i-k]=1;
    }
    if(t[i]==t[i-k]&&ans[i]!=0){
      ans[i-k]=0;
    }
  }
  ll ANS=0;
  loop(i,n){
    if(ans[i]){
      if(t[i]=='p')ANS+=p;
      if(t[i]=='r')ANS+=r;
      if(t[i]=='s')ANS+=s;
    }
  }
  putout(ANS);
  
}


Measured memory_bytes: 1280
#include<stdio.h>
 
int main(void){
 int a;
 scanf("%d",&a);
 int h,m,s;
 h=a/3600;
 m=(a-h*3600)/60;
 s=a-h*3600-m*60;
 printf("%d:%d:%d\n",h,m,s);
 return 0;
}

Measured memory_bytes: 1856
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re

def rdp_connect() -> bool:
    global s1, s2
    s1 = input()
    if s1 == '.':
        return False
    s2 = input()
    return True

def rdp_token(s: str):
    res = []
    while s:
        match = re.match(r'[a-zA-Z0-9;]+', s)
        if match:
            res.append(s[:match.end()])
            s = s[match.end():]
            continue
        match = re.match(r'"[^"]*"', s)
        if match:
            res.append(s[:match.end()-1])
            s = s[match.end():]
            continue
        break
    return res

def rdp_check() -> bool:
    l1 = rdp_token(s1)
    l2 = rdp_token(s2)
    if len(l1) != len(l2):
        return False
    flag = True
    for t1, t2 in zip(l1, l2):
        if t1 == t2:
            continue
        if t1[0] == t2[0] == '"' and flag:
            flag = False
        else:
            return False
    return True

if __name__ == '__main__':
    while rdp_connect():
        if s1 == s2:
            print('IDENTICAL')
        elif rdp_check():
            print('CLOSE')
        else:
            print('DIFFERENT')

Measured memory_bytes: 7668
import heapq


heap = []
heapq.heapify(heap)

orders = []
order = input()
while order != "end":
    orders.append(order)
    order = input()

for order in orders:
    if order.startswith("insert"):
        o, x = order.split()
        x = int(x)
        heapq.heappush(heap, -x)
    else:
        print(-heapq.heappop(heap))



Measured memory_bytes: 184588
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define ABSS(a, b) (a > b ? a - b : b - a)

int main(void) {
	uint32_t N;

	scanf("%"PRIu32, &N);

	printf("%"PRIu32, N%2 == 0 ? N : N*2);

	return 0;
}


Measured memory_bytes: 128
#B
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

dp = [float('inf')]*n
for i in range(n):
    if i == 0:
        dp[i] = 0
        continue    
    for j in range(1,k+1):
        if i-j>=0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])

Measured memory_bytes: 55392
///#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
///#define double long double
#define all(x) (x).begin(), (x).end()
#define finout(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
#define X first
#define Y second

using namespace std;
const int MOD = 1e9 + 7;

typedef pair <int, int> pii;
typedef vector <int> vi;
inline int ni() {int x; cin >> x; return x;}
template <class T>
inline T nt() {T x; cin >> x; return x;}
inline void print(){}
template<typename T, typename ...TAIL>
inline void print(const T &t, TAIL... tail) {cout << t; print(tail...);}
inline void input() {return;}
template<typename T, typename ...TAIL>
inline void input(T &t, TAIL&... tail) {cin >> t; input(tail...);}

const int N = 3001;
const int inf = 1e9 + 7;
const double PI = 3.14159265359;

signed main () {
    ios_base::sync_with_stdio(NULL);  cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector <pair <int, int> > v;
    for (int i = 0; i < n; i++) {
        v.push_back({ni() - 1, i});
    }
    sort(all(v));
    multiset <int> st;
    st.insert(-1);
    st.insert(n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (v[i].second - *prev(st.lower_bound(v[i].second))) * (*st.lower_bound(v[i].second) - v[i].second) * (i + 1);
        st.insert(v[i].second);
    }
    cout << ans << '\n';
    return 0;
}




















Measured memory_bytes: 15756
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
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;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
int main(void) {
    int N;
    cin >> N;
    vi a(N);
    rep(i,N)  cin >> a[i];
    
    int breakCount = 0;
    int okCount = 0;
    int index=1;
    rep(i,N){
        if(index == a[i]){
           okCount++;
           index++;
        } 
        else{
            breakCount++;
        }
    }

    if(breakCount > 0 && okCount == 0) fin(-1);
    else if(breakCount == 0 && okCount > 0)fin(0);
    else fin(breakCount);
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int x;
  x = a;
  a = b;
  b = x;
  x = a;
  a = c;
  c = x;
  cout << a << " " << b << " " << c << " " << endl;

}


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxm = 100100;

const int maxn = 410;

int n, m;

vector<pair<int, int> > all[maxn + 5];

pair<int, int> ed[maxm + 5];

bool now[maxn + 5][maxn + 5][maxn + 5];

bool ok[maxn + 5][maxn + 5];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d", &n, &m);
	memset(ok, 1, sizeof ok);
	REP(i, 0, m)
	{
		int x, y;
		scanf("%d%d", &x, &y), --x, --y;
		ed[i] = mp(x, y);
	}
	REP(i, 0, n) REP(j, 0, i)
	{
		now[i][j][i] = 1;
		now[i][j][j] = 1;
		all[i].pb(mp(i, j));
		all[j].pb(mp(i, j));
	}
	for (int i = m - 1; i >= 0; --i)
	{
		vector<pair<int, int> > tmp;
		for (auto u : all[ed[i].x]) if (ok[u.x][u.y])
		{
			if (now[u.x][u.y][ed[i].y])
			{
				ok[u.x][u.y] = 0;
				continue;
			}
			tmp.pb(u);
		}
		for (auto u : all[ed[i].y]) if (ok[u.x][u.y])
		{
			if (now[u.x][u.y][ed[i].x])
			{
				ok[u.x][u.y] = 0;
				continue;
			}
			tmp.pb(u);
		}
		for (auto u : tmp) now[u.x][u.y][ed[i].x] = now[u.x][u.y][ed[i].y] = 1;
		all[ed[i].x] = all[ed[i].y] = tmp;
	}
	int ans = 0;
	REP(i, 0, n) REP(j, 0, i) if (ok[i][j]) ++ans;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 84028
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in(0).split(' ').map(_.toLong)
  val A = ls(0)
  val B = ls(1)
  val K = ls(2)
  if(K <= A){
    print((A-K) + " " + B)
  }else if(A < K && K<=A+B){
    print("0 " + (A+B-K))  
  }else{
    print("0 0")
  }
}


Measured memory_bytes: 25672
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w, h;
		for(;;) {
			h = sc.nextInt();
			w = sc.nextInt();
			
			if(h == 0 && w == 0) {
				break;
			}
			for(int i = 0; i < h; i++) {
				if(i == 0 || i == h-1) {
					for(int j = 0; j < w; j++) {
						System.out.print("#");
					}
					System.out.print("\n");
				} else {
					for(int j = 0; j < w; j++) {
						if(j == 0 || j == w-1) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					}
					System.out.print("\n");
				}
			}
			System.out.print("\n");
		}
		sc.close();
	}
}


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

//Compiler version g++ 6.3.0

int main()
{
   int n,k,x=0;
   cin>>n>>k;
   int p[n];
   for(int i=0;i<n;i++)
   cin>>p[i];
   sort(p,p+n);
   for(int i=0;i<k;i++)
   x+=p[i];
   cout<<x<<endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

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

	double x1, x2, y1, y2, x3, y3;
	cin >> x1 >> y1 >> x2 >> y2;

	x3 = (x2 - x1);
	y3 = (y2 - y1);

	int q;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		double px, py, px2, py2;
		cin >> px >> py;

		px2 = (px - x1);
		py2 = (py - y1);

		if ((px2*px2 + py2*py2) <= 0.0000001 || (abs(px2 - x3) <= 0.000000001&&abs(py2 - y3) <= 0.000000001))
		{
			cout << "ON_SEGMENT" << endl;
			continue;
		}

		double cross = (py2*x3 - px2*y3);
		if (abs(cross) <= 0.00000000001)
		{
			if ((px2*x3 + py2*y3)>0)
			{
				if ((x3*x3 + y3*y3) < (px2*px2 + py2*py2))
				{
					cout << "ONLINE_FRONT" << endl;
				}
				else
				{
					cout << "ON_SEGMENT" << endl;
				}
			}
			else
			{
				cout << "ONLINE_BACK" << endl;
			}
		}
		else
		{
			if (cross > 0)
			{
				cout << "COUNTER_CLOCKWISE" << endl;
			}
			else
			{
				cout << "CLOCKWISE" << endl;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3272
#include <stdio.h>

int main(){
int n, ac=0, wa=0, tle=0, re=0;
char stat[100];
scanf("%d", &n);
for(int i=0;i<n;i++){
    scanf("%s", stat);
    if(stat[1]=='C')
        ac++;
    else if(stat[1]=='A')
        wa++;
    else if(stat[1]=='L')
        tle++;
    else if(stat[1]=='E')
        re++;
}
printf("AC x %d\n", ac);
printf("WA x %d\n", wa);
printf("TLE x %d\n", tle);
printf("RE x %d\n", re);

return 0;
}

Measured memory_bytes: 1732
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let (n, k, c): (usize, usize, usize) = (sc.read(), sc.read(), sc.read());
    let s = sc.chars();

    let mut pos: usize = 0;
    let l: Vec<usize> = (0..k)
        .map(|_| {
            while s[pos] == 'x' {
                pos += 1;
            }
            pos += c + 1;
            pos - c - 1
        })
        .collect();

    let mut pos: usize = n - 1;
    let r: Vec<usize> = (0..k)
        .map(|i| {
            while s[pos] == 'x' {
                pos -= 1;
            }
            if i + 1 < k {
                pos -= c + 1;
                pos + c + 1
            } else {
                pos
            }
        })
        .collect();

    for (x, y) in l.iter().zip(r.iter().rev()) {
        if x == y {
            print!("{}\n", x + 1);
        }
    }
}


Measured memory_bytes: 5960
import heapq


class Edge:
    def __init__(self, dst, weight):
        self.dst, self.weight = dst, weight

    def __lt__(self, e):
        return self.weight > e.weight


class Graph:
    def __init__(self, V):
        self.V = V
        self.E = [[] for _ in range(V)]

    def add_edge(self, src, dst, weight):
        self.E[src].append(Edge(dst, weight))


class ShortestPath:
    """Dijkstra's algorithm : find the shortest path from a vertex
       Complexity: O(E + log(V))
       used in GRL1A(AOJ)
    """

    def __init__(self, G, INF=10**9):
        """ V: the number of vertexes
            E: adjacency list (all edge in E must be 0 or positive)
            start: start vertex
            INF: Infinity distance
        """
        self.G, self.INF = G, INF

    class Node:
        def __init__(self, v, cost):
            self.v, self.cost = v, cost

        def __lt__(self, n):
            return self.cost < n.cost

    def dijkstra(self, start, goal=None):
        que = list()
        self.dist = [self.INF] * self.G.V  # distance from start
        self.prev = [-1] * self.G.V  # prev vertex of shortest path
        self.dist[start] = 0
        heapq.heappush(que, self.Node(start, 0))

        while len(que) > 0:
            n = heapq.heappop(que)
            if self.dist[n.v] < n.cost:
                continue
            if goal is not None and n.v == goal:
                return
            for e in self.G.E[n.v]:
                if self.dist[n.v] + e.weight < self.dist[e.dst]:
                    self.dist[e.dst] = self.dist[n.v] + e.weight
                    heapq.heappush(que, self.Node(e.dst, self.dist[e.dst]))
                    self.prev[e.dst] = n.v

    def getPath(self, end):
        path = [end]
        while self.prev[end] != -1:
            end = self.prev[end]
        return path[::-1]

V, E, start = map(int, input().split())
G = Graph(V)
for _ in range(E):
    s, t, d = map(int, input().split())
    G.add_edge(s, t, d)
INF = 10**9
sp = ShortestPath(G, INF)
sp.dijkstra(start)
for i in range(G.V):
    print("INF" if sp.dist[i] == INF else sp.dist[i])

Measured memory_bytes: 150632