akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
	char l[3][3],s[9],m;
	int i;
	while(scanf("%s",s)!=EOF){
		l[0][0]=s[0];
		l[0][1]=s[1];
		l[0][2]=s[2];
		l[1][0]=s[3];
		l[1][1]=s[4];
		l[1][2]=s[5];
		l[2][0]=s[6];
		l[2][1]=s[7];
		l[2][2]=s[8];
		m='d';
		for(i=0;i<3;i++){
			if(l[i][0]=='o'&&l[i][1]=='o'&&l[i][2]=='o'){
				m='o';
			}else if(l[i][0]=='x'&&l[i][1]=='x'&&l[i][2]=='x'){
				m='x';
			}
		}
		for(i=0;i<3;i++){
			if(l[0][i]=='o'&&l[1][i]=='o'&&l[2][i]=='o'){
				m='o';
			}else if(l[0][i]=='x'&&l[1][i]=='x'&&l[2][i]=='x'){
				m='x';
			}
		}
		if(l[0][0]=='o'&&l[1][1]=='o'&&l[2][2]=='o'){
			m='o';
		}
		if(l[0][0]=='x'&&l[1][1]=='x'&&l[2][2]=='x'){
			m='x';
		}
		if(l[2][0]=='o'&&l[1][1]=='o'&&l[0][2]=='o'){
			m='o';
		}
		if(l[2][0]=='x'&&l[1][1]=='x'&&l[0][2]=='x'){
			m='x';
		}
		printf("%c\n",m);
	}
	return 0;
}

Measured memory_bytes: 2580
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;
const double eps = 1e-10;

int main() {
    int n; cin >> n;
    vll a(n);
    rep(i,n) {
        ll x; cin >> x;
        a[i] = x;
        if (x == 0) {cout << 0 << endl; return 0;}
    }
    ll sum = 1;
    rep(i,n) {
        // cout << sum << endl;
        // cout << (ll)1e18/a[i]+1 << endl;
        if (sum >= (ll)1e18/a[i]+1) {cout << -1 << endl; return 0;}
        else sum *= a[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3988
N=int(input())
a=list(map(int,input().split()))
sum=0
for i in a:
        sum+=i
sum/=N
mini=100000000
k=0
for i in a:
        if mini>abs(i-sum):
                mini=abs(i-sum)
                ans=k
        k+=1
print(ans)

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll K, A, B;
    cin >> K >> A >> B;
    if(B - A <= 2 || K < A - 1) {
        cout << K + 1 << endl;
    } else {
        ll temp;
        temp = max(0LL, (K - A + 1) / 2);
        cout << A + temp * (B - A) + ((K - A - 1) % 2 ? 1 : 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

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

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

	int x = 0;
	int ans = 0;
	while (x < n) {
		if (a[x] == x+1) {
			ans++;
			x += 2;
		}
		else {
			x++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  
  int n, x;
  cin >> n >> x;
  
  int m, sum = 0, l = 1001;
  REP(i,n) {
    cin >> m;
    sum += m;
    l = min(l,m);
  }
  
  n += (x - sum) / l;
  
  cout << n << endl;
  
}

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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

using namespace std;

int main(){
  int K,A,B;
  cin >> K >> A >>B;
  int flag=0;
  for(int i=A;i<=B;i++){
    if(i%K==0)flag=1;
  }
  if(flag)cout << "OK";
  else cout << "NG";
  
  return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		if(Character.isUpperCase( a.charAt(0))) {
			System.out.print("A");
		}
		else {
			System.out.print("a");
		}
	}

}

Measured memory_bytes: 35740
#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;
int main() {
    double n, k;
    int c=0;
    double ans=0;
    cin >> n >> k;
    double j;
    for (int i = 1; i <= n; ++i) {
        if(k > i) {
            j=i;
            while(k > j) {
                j = j * 2.0000000000;
                c++;
            }
            ans += 1.0000000000/n * pow(1.0000000000/2.0000000000, c);
            c=0;
        }
        else {
            ans += 1.0000000000/n;
        }
    }
    cout << fixed << setprecision(12) << ans << endl;
	return 0;
}


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

class Edge {
public:
	int v1, v2, d;
};

int s, t, V[10000];
Edge E[100000];

bool X(const Edge& a, const Edge& b) { return a.d < b.d; }

int Kruskal() {
	int m = 0;
	for (int i = 0; i < t; i++) {
		Edge e = E[i];
		if (V[e.v1] != V[e.v2]) {
			int v = V[e.v1], u = V[e.v2]; m += e.d;
			for (int j = 0; j < s; j++) {
				if (V[j] == u) V[j] = v;
			}
		}
	}
	return m;
}

int main() {
	cin >> s >> t;
	for (int i = 0; i < s; i++) V[i] = i;
	for (int i = 0; i < t; i++) {
		cin >> E[i].v1 >> E[i].v2 >> E[i].d;
	}

	sort(E, E+t, X);

	cout << Kruskal() << endl;
}


Measured memory_bytes: 4300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;

int main()
{
  ll h,a;cin>>h>>a;
  cout<<(h+a-1)/a<<endl;
  return 0;
}


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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: [u32; 3]
    }
    let mut a = a;
    a.sort();
    println!("{}", a[2] - a[1] + a[1] - a[0]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> P(N), A(N+10);
    rep(i,N){
        cin >> P[i];
    }
    //A[0] = 1;
    ll cur = -1;
    ll ans = 0;
    rep(i,N){
        A[P[i]-1] = i;
        /*
        if(P[i] == cur){
            cur++;
            continue;
        }else{
            //cur++;
            ans++;
        }*/
    }
    ll tmp = 0;
    rep(i,N){
        if(cur < A[i]){
            tmp++;
            cur = A[i];
        }else{
            cmax(ans, tmp);
            cur = A[i];
            tmp = 1;
        }
    }
    cmax(ans, tmp);
    cout << N - ans << endl;
}

Measured memory_bytes: 3328
package main

import (
	"fmt"
)

func main() {
	var a, b, v, w,t int
	var D int
	fmt.Scan(&a, &v)
	fmt.Scan(&b, &w)
	fmt.Scan(&t)

	if a > b {
		D = a-b
	} else {
		D= b-a
	}
	D2:=(v-w)*t
	if D2>=D {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  ll ans = 1;
  rep(i,3){
    ans *= n;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
    using namespace std;
    int main()
    {

        string S;
        cin >> S;
        int length = S.length();
        bool isEasy = true;
        for (int i = 0; i < length; i++){
            if ((i % 2) == 0) {
                //0スタートより割り切れが奇数
                if (S[i] == 'L'){
                    isEasy = false;
                    break;
                }
            } else {
                if (S[i] == 'R'){
                    isEasy = false;
                    break;
                }
            }
        }
        if (isEasy){
            cout << "Yes";
        }else {
            cout << "No";
        }
        
        return 0;
    }

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Main m = new Main(sc);
    m.show(m.solve());
    // m.debug();
  }

  int A;
  int B;
  int M;
  int[] a;
  int[] b;
  int[] x;
  int[] y;
  int[] c;
  Scanner sc;
  int[] ticket;

  // 標準入力用のコンストラクタ
  public Main(Scanner sc) {
    this.sc = sc;
    A = sc.nextInt();
    B = sc.nextInt();
    M = sc.nextInt();
    a = nextArray(A);
    b = nextArray(B);
    x = new int[M];
    y = new int[M];
    c = new int[M];
    for (int i = 0; i < M; i++) {
      x[i] = sc.nextInt() - 1;
      y[i] = sc.nextInt() - 1;
      c[i] = sc.nextInt();
    }
    ticket = new int[M];
    for (int i = 0; i < M; i++) {
      ticket[i] = a[x[i]] + b[y[i]] - c[i];
    }
  }

  // int配列の読み込み
  int[] nextArray(int n) {
    int[] ans = new int[n];
    for (int i = 0; i < n; i++) ans[i] = sc.nextInt();
    return ans;
  }

  // 判定処理：割引券で２台買う、１台ずつ買う、安いほう
  int solve() {
    int x = waribiki();
    int y = refrigerator() + microwave();
    return Math.min(x, y);
  }

  // int配列の最低値
  int min(int[] a) {
    int ans = a[0];
    for (int i = 1; i < a.length; i++) if (ans > a[i]) ans = a[i];
    return ans;
  }

  // 冷蔵庫単体の最低金額
  int refrigerator() {
    return min(a);
  }

  // 電子レンジ単体の最低価格
  int microwave() {
    return min(b);
  }

  // 割引券使ったペアの最低価格
  int waribiki() {
    return min(ticket);
  }

  // 回答の表示
  void show(int ans) {
    System.out.println(ans);
  }

  // デバッグ表示
  void debug() {
    System.out.printf("A = %d\n", A);
    System.out.printf("B = %d\n", B);
    System.out.printf("M = %d\n", M);
    System.out.printf("a = %s\n", Arrays.toString(a));
    System.out.printf("min(a) = %d\n", min(a));
    System.out.printf("b = %s\n", Arrays.toString(b));
    System.out.printf("min(b) = %d\n", min(b));
    System.out.printf("x = %s\n", Arrays.toString(x));
    System.out.printf("y = %s\n", Arrays.toString(y));
    System.out.printf("c = %s\n", Arrays.toString(c));
    System.out.printf("ticket = %s\n", Arrays.toString(ticket));
    System.out.printf("min(ticket) = %d\n", min(ticket));
  }
}


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

int main(){
  int n;cin>>n;
  vector<int> v(n);
  rep(i,n){
    cin>>v.at(i);
  }
  vector<int> color(8,0);
  int other=0;
  rep(i,n){
    if (0<=v.at(i) && v.at(i) <= 399){
      color.at(0)++;
    }
    else if (400<=v.at(i) && v.at(i)<=799){
      color.at(1)++;
    }
    else if (800<=v.at(i) && v.at(i)<=1199){
      color.at(2)++;
    }
    else if (1200<=v.at(i) && v.at(i)<=1599){
      color.at(3)++;
    }
    else if (1600<=v.at(i) && v.at(i)<=1999){
      color.at(4)++;
    }
    else if (2000<=v.at(i) && v.at(i)<=2399){
      color.at(5)++;
    }
    else if (2400<=v.at(i) && v.at(i)<=2799){
      color.at(6)++;
    }
    else if (2800<=v.at(i) && v.at(i)<=3199){
      color.at(7)++;
    }
    else if (3200<=v.at(i)){
      other++;
    }
  }
  int sum=0;
  rep(i,8){
    if (color.at(i) > 0){
      sum++;
    }
  }
  if (sum<=other){
    if (sum==0 || sum == 1){
      cout << 1 << " " << sum + other << endl;
    }
    else{
      cout << sum << " " << sum + other << endl;
    }
  }
  else {
    cout << sum << " " << sum + other << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#define _ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

map <long long, long long> f;
const int mod = 2019;

int main()
{_
    f[0] = 1;
    string s; cin >> s;
    int suf = 0;
    long long multi = 1;
    long long ans = 0;
    for (int i = s.size() - 1; i >= 0; --i)
    {
        int d = s[i] - '0';
        suf = (suf + d * multi) % mod;
        multi = (10 * multi) % mod;
        ans += f[suf];
        f[suf]++;
    }
    cout << ans;
}

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

using namespace std;
#define ff(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define rep(i, a, b) for(int i = (a), _b = (b); i < _b; ++i)
#define fd(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define SZ(x) ((int)(x).size())
#define db(x) cout << #x << " == " << x << endl
#define _ << ", " << 
#define X first
#define Y second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define endl '\n'
#define pc putchar
#define gc getchar 
#define bit(i) (1<<(i))

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

const int N=405,MD=1e9+7;
ll n,c,a[N],b[N],dp[N][N],val[N][N],pwr[N][N];

void enter(){
	cin>>n>>c;
	ff(i,1,n) cin>>a[i];
	ff(i,1,n) cin>>b[i];
}

void process(){
	ff(i,1,N-1){
		pwr[i][0]=1;
		ff(j,1,N-1) pwr[i][j]=pwr[i][j-1]*i%MD;
	}

	ff(i,1,n) ff(k,0,N-1){
		ff(j,a[i],b[i]){
 			val[i][k]+=pwr[j][k];
 			while (val[i][k]>=MD) val[i][k]-=MD;
		}
	}

	dp[0][0]=1;
	// dp[i][j]: da chia j vien keo

	ff(i,1,n) ff(j,0,c) ff(k,0,j){
		dp[i][j]=(dp[i][j]+dp[i-1][j-k]*val[i][k]%MD)%MD;
	}
	cout<<dp[n][c]<<endl;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	//freopen("test.inp","r",stdin);
	//freopen("test.out","w",stdout);

	enter();
	process();	

	return 0;
}


Measured memory_bytes: 4096
'use strict'
function main(input) {
  input = input.trim().split('\n')
  const HW = input.shift().split(' ').map(v => Number(v))
  input = input.map(r => r.split(''))
  let L = []
  let R = []
  let U = []
  let D = []
  let max = 0
  for (let h = 0; h < HW[0]; h++) {
    L[h] = []
    R[h] = []
    U[h] = []
    D[h] = []
    for (let w = 0; w < HW[1]; w++) {
      L[h][w] = 0
      U[h][w] = 0
      if (input[h][w] === '.') {
        L[h][w] = w === 0 ? 1 : L[h][w-1] + 1
        U[h][w] = h === 0 ? 1 : U[h-1][w] + 1
      }
    }
  }
  for (let h = HW[0] - 1; h >= 0; h--) {
    for (let w = HW[1] - 1; w >= 0; w--) {
      R[h][w] = 0
      D[h][w] = 0
      if (input[h][w] === '.') {
        R[h][w] = w === HW[1] - 1 ? 1 : R[h][w+1] + 1
        D[h][w] = h === HW[0] - 1 ? 1 : D[h+1][w] + 1

        const sum = L[h][w] + R[h][w]+ U[h][w] + D[h][w] - 3
        if (sum > max) max = sum
      }
    }
  }
  console.log(max)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 220420
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100];
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;
    return 0;
}

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

int main()
{
    int n,i,y=0,no=0;
    bool isPrime = true;
    cin>> n;
    if (n >= 1 && n <= 9) cout<< "Yes";
    if(n>9){
        for (i = 2; i <= n / 2; ++i) {
      if (n % i == 0) {
         isPrime = false;
         break;
      }
   }
   if (isPrime)
      cout << "No";
   else{
    for(i=2; i<=9; i++){
        if(n%i==0){
         int c= n/i;
        if(c<=9){
            //cout << "Yes";
            y++;

        }
        else {
                //cout << "No";
                no++;
        }
        }
   }
   if(y>=1) cout << "Yes";
   else cout << "No";
   }

   return 0;
    }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    int n,k; cin>>n>>k;
    vector<P> dt(n);
    rep(i,n)cin>>dt.at(i).S>>dt.at(i).F;
    sort(all(dt),greater<P>());
    int sum=0,type=0;
    vector<int> usedtype(n,0);
    vector<int> remove,add;
    rep(i,n){
        if(i<k){
            sum+=dt.at(i).F;
            if(usedtype.at(dt.at(i).S-1)++==0)type++;
            else remove.push_back(dt.at(i).F);
        }else{
            if(usedtype.at(dt.at(i).S-1)++==0)add.push_back(dt.at(i).F);
        }
    }
    reverse(all(add));
    int ans=sum+type*type; type++;
    for(;type<=n;type++){
        if(remove.size()==0 or add.size()==0)break;
        sum-=remove.back(); remove.pop_back();
        sum+=add.back(); add.pop_back();
        chmax(ans, sum+type*type);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3264
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    int A, B, C, D;
    int n;
    cin >> n;
    D = n % 10;
    n /= 10;
    C = n % 10;
    n /= 10;
    B = n % 10;
    n /= 10;
    A = n;

    auto l = (2 << 2);
    auto to_op = [](int b) {
        return b ? "+" : "-";
    };
    for (int i = 0; i < l; ++i)
    {
        bitset<8> bit(i);
        int ret = A;
        ret = ret + (bit[0] ? B : -B);
        ret = ret + (bit[1] ? C : -C);
        ret = ret + (bit[2] ? D : -D);
        if (ret == 7)
        {
            cout << A << to_op(bit[0]);
            cout << B << to_op(bit[1]);
            cout << C << to_op(bit[2]);
            cout << D << "=7" << endl;
            return 0;
        }
    }
    throw runtime_error("not found");
    return 0;
}

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

#include <atcoder/all>
using namespace atcoder;

int main() {
    int N, K;
    cin >> N >> K;
    mcf_graph<ll, ll> mcf(N*2+2);
    int s = N*2;
    int t = N*2+1;
    ll INF = pow(10,9);
    mcf.add_edge(s, t, N*K, INF);
    rep(i,N) {
        mcf.add_edge(s, i, K, 0);
        mcf.add_edge(N+i, t, K, 0);
    }
    rep(i,N) {
        rep(j, N) {
            ll v;
            cin >> v;
            mcf.add_edge(i, N+j, 1, INF-v);
        }
    }
    auto results = mcf.flow(s, t, K*N);
    cout << N*K*INF - results.second << endl;
    vector<string> grid(N, string(N, '.'));
    auto edges = mcf.edges();
    for (auto e: edges) {
        if (e.from == s || e.to == t || e.flow == 0) continue;
        grid[e.from][e.to-N] = 'X';
    }
    rep(i,N) {
        cout << grid[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3956
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
int n,a,b;
int main(){
	scanf("%d%d%d",&n,&a,&b);
	puts(((b-a-1)&1)?"Alice":"Borys");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 998244353;
ll a, b, c, n, m, x, y, z, w, h, ans1, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        ll v[n], sum1[n], sum2[n];
        rep(i, n){
            cin >> v[i];
        }
        ll ans1 = 0;
        sum1[0] = v[0];
        if(sum1[0] <= 0){
            ans1 += 1 - sum1[0];
            sum1[0] = 1;
        }
        rep(i, 1, n){
            sum1[i] = sum1[i - 1] + v[i];
            if(sum1[i] == 0){
                sum1[i] = (sum1[i - 1] > 0 ? -1 : 1);
                ans1++;
            }
            if(sum1[i] < 0 && sum1[i - 1] < 0){
                ans1 += 1 - sum1[i];
                sum1[i] = 1;
            }
            if(sum1[i] > 0 && sum1[i - 1] > 0){
                ans1 += sum1[i] + 1;
                sum1[i] = -1;
            }
        }
        ll ans2 = 0;
        sum2[0] = v[0];
        if(sum2[0] >= 0){
            ans2 += sum2[0] + 1;
            sum2[0] = -1;
        }
        rep(i, 1, n){
            sum2[i] = sum2[i - 1] + v[i];
            if(sum2[i] == 0){
                sum2[i] = (sum2[i - 1] > 0 ? -1 : 1);
                ans2++;
            }
            if(sum2[i] < 0 && sum2[i - 1] < 0){
                ans2 += 1 - sum2[i];
                sum2[i] = 1;
            }
            if(sum2[i] > 0 && sum2[i - 1] > 0){
                ans2 += sum2[i] + 1;
                sum2[i] = -1;
            }
        }
        print(min(ans1, ans2));
    }
}


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

char S[100009];

int main() {
    int N, K; scanf("%d%d",&N,&K);
    int a = 0, b = 0, ans = 0;
    for(int i=1; i<=N; i++) {
        scanf(" %c", &S[i]);
        if(i >= 2) {
            if(S[i] != S[i-1]) {
                if(S[i] == 'R') ++a;
                else ++b;
            }
            else ++ans;
        }
    }
    int c = min(a, b);
    a -= c; b -= c;
    if(K <= c) printf("%d", ans + 2*K);
    else if(K <= c + max(a, b))printf("%d", ans + 2*c + K - c);
    else printf("%d", N-1);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

// https://ei1333.github.io/algorithm/cumulative-sum2d.html
template <class T> struct CumulativeSum2D {
    vector<vector<T>> data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector<T>(H + 1, 0)) {}

    void add(int x, int y, T z) {
        ++x, ++y;
        if (x >= data.size() || y >= data[0].size())
            return;
        data[x][y] += z;
    }

    void build() {
        FOR(i, 1, data.size()) FOR(j, 1, data.size()) {
            data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
        }
    }

    T query(int sx, int sy, int gx, int gy) {
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }

    void print() {
        for (auto &x : data) {
            for (auto &y : x) {
                cout << y << " ";
            }
            cout << endl;
        }
    }
};

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    char c;
    int n, k, x, y;
    cin >> n >> k;
    CumulativeSum2D<int> s(k * 2, k * 2);
    REP(i, n) {
        cin >> x >> y >> c;
        if (c == 'W') {
            y += k;
        }
        y %= 2 * k;
        if (y >= k) {
            y -= k;
            x += k;
        }
        x %= 2 * k;
        s.add(x, y, 1);
        s.add((x + k) % (2 * k), y + k, 1);
    }
    // 二次元累積和
    s.build();
    // s.print();
    int maxv = 0;
    REP(x, k) REP(y, k) {
        int t = s.query(x, y, x + k, y + k);
        maxv = max({maxv, t, n - t});
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 16000
#include <iostream>

using namespace std;

main(){
  int dp[31];
  dp[0] = 0;
  for(int i=1;i<31;i++){
    if(i%2){
      dp[i] = dp[i-1] + dp[i-1] + 1;
    }else{
      dp[i] = dp[i-1] + dp[i-2] + 1;
    }
  }
  int n;
  while(cin >> n){
    cout << dp[n] << endl;
  }
}

Measured memory_bytes: 0
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[N];
		int sum = 0;
		int count = 0;

		for(int i=0; i<N; i++){
			a[i] = sc.nextInt();
		}
		//System.out.println(Arrays.toString(a));
		quick_sort(a, 0, N-1);
		//System.out.println(Arrays.toString(a));

		for(int i=0; i<N; i++){
			sum += a[i];
			count++;
			if(sum==x){
				System.out.println(count);
				return;
			}else if(sum>x){
				System.out.println(count-1);
				return;
			}
		}
		System.out.println(N-1);
	}

	static void quick_sort(int[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    }
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e14;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, W, w[200], v[200], dp[101010];


void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> W;
    FOR(N)
    cin >> w[i] >> v[i];
    FOR(101000)
    dp[i] = INF;
    dp[0] = 0;
    int ans = 0;
    FOR(N) {
        for (int bef = 100000; bef >= 0; bef--) {
            itn nxt = bef + v[i];
            if (nxt > 100000)
                continue;
            chmin(dp[nxt], dp[bef] + w[i]);
        }
    }
    FOR(100010) {
        if (dp[i] <= W)
            chmax(ans, i);
    }
    cout << ans << endl;
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define M 1000000007LL
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((ll)v.size())
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
#define mod 1000000007
#define MAXN 300002
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
ll arr[300002];
int main() {
       ios::sync_with_stdio(false);
       cin.tie(0);
       cout.tie(0);
        ll n;string s;
        cin>>n>>s;
        map<char,ll> my;
        for(auto it:s)
          my[it]++;
        ll ans=1;
        for(auto it:my)
        {
           ans=(ans*(it.S+1))%mod;
        }
        cout<<(ans-1+mod)%mod;
       return 0;
     
}

Measured memory_bytes: 512
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007



void solve()
{
     ll n;
     cin >> n;
     n--;
     ll f = 0;
     for(ll i = 1 ; i<=n ; ++i) {

     	 f += n/ i ;
     }

     cout << f;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);cin.tie(0);   
    //TEST
     solve();
}



Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int dp[100005];

vii v[100005];

void dfs(int at,int p=0)
{
	vii v1;
	tr(v[at],it)
	{
		int to=*it;
		if(to!=p)
		{
			dfs(to,at);
			v1.pb(dp[to]);
		}
	}
	sort(all(v1));
	int dd=0;
	tr(v1,it)
	{
		int x=*it;
		dd=max(dd+1,x+1);
	}
	dp[at]=dd;
}

int main()
{ios_base::sync_with_stdio(false);
int n;
gl(n);
rep(i,2,n)
{
	int x;
	cin>>x;
	v[x].pb(i);
}
dfs(1);
ol(dp[1]);
return 0;
}


Measured memory_bytes: 15488
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    int hari=0;
    cin>>a>>b;
    
    for(int i=a; i<=b;i++){
        bool harinezu=true;
        string str_a = to_string(i);
        
        for(int j=0; j<str_a.size()/2;j++){
        if(str_a[j] != str_a[str_a.size()-(1+j)]){
            
        
            harinezu=false;
            break;
        }
    }
    
    if(harinezu) hari++;
  }
  cout<<hari<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
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 unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll X, Y;
	cin >> X >> Y;

	bool ans = true;

	ll s = Y - 2 * X;
	if (s < 0) ans = false;
	if (s % 2 != 0) ans = false;

	ll y = s / 2;
	ll t = X - y;
	if (t < 0) ans = false;

	if (ans)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}


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

using ll = long long int;
const int MAX_N = 500 + 5;

int n;
int c[MAX_N], s[MAX_N], f[MAX_N];

int main(void){
  // Here your code !
  scanf("%d", &n);

  for (int i = 1; i <= n - 1; ++i) {
    scanf("%d %d %d", &c[i], &s[i], &f[i]);
  }

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

    if (i == n) {printf("%d\n", 0); break;}

    t += (s[i] + c[i]);

    for (int j = i + 1; j <= n - 1; ++j) {
      if (s[j] > t) {
        t += s[j] - t;
      }
      else {
        int popin = t % f[j];
        if (popin != 0) t += f[j] - popin;
      }
      t += c[j];
    }
    printf("%d\n", t);
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <string>
#include <bitset>
#include <stack>
#include <map>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	a[0]--;
	bool ans = true;
	for (int i = 1; i < n; i++) {
		if (a[i] < a[i - 1]) {
			ans = false;
			break;
		}
		if (a[i] != a[i - 1]) a[i]--;
	}
	cout << (ans ? "Yes" : "No");
}

Measured memory_bytes: 892
O = str(input())
E = str(input())

ans = ""
if len(O) == len(E):
    for i in range(len(E)):
        ans += O[i]
        ans += E[i]
else:
    for i in range(len(E)):
        ans += O[i]
        ans += E[i]
    ans += O[len(O)-1]
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

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

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

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };

int N, M;
vector<string> S;
inline void input(){
    fast_io();
    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        string s; cin >> s;
        S.push_back(s);
    }
}

#include <atcoder/maxflow>
#include <atcoder/mincostflow>

#define WALL '#'
#define PATH '.'
#define PIECE 'o'

void chmax(ll &a, ll b){if(a<b) a=b;}

inline int solve(){
    atcoder::mcf_graph<ll, ll> graph(N*M+10);
    int s = N*M+2, t = N*M+3;
    ll INF = 1e6;
    vector<pii> Ps;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M; j++)
        {
            if(S[i][j]==PIECE){
                int to = M*i+j;
                Ps.emplace_back(i, j);
                graph.add_edge(s, to, 1, 0);
            }
            else if(S[i][j]==PATH){
                int to = M*i+j;
                graph.add_edge(to, t, 1, 0);
            }
        }
    }

    ll K = Ps.size();
    for (int k = 0; k < K; k++)
    {
        int x = Ps[k].first;
        int y = Ps[k].second;
        vector<vector<ll>> dist(N,vector<ll>(M,-INF));
        dist[x][y] = 0;
        for (int i = x; i < N; i++)
        {
            for (int j = y; j < M; j++)
            {
                if(S[i][j]==WALL) continue;
                if(i>=1 && dist[i-1][j]>=0) chmax(dist[i][j], dist[i-1][j] + 1);
                if(j>=1 && dist[i][j-1]>=0) chmax(dist[i][j], dist[i][j-1] + 1);
            }
        }
        for (int i = x; i < N; i++)
        {
            for (int j = y; j < M; j++)
            {
                if(S[i][j]==WALL) continue;
                if(S[i][j]==PIECE) continue;
                if(dist[i][j]==-INF) continue;
                graph.add_edge(x*M+y, i*M+j, 1, INF - dist[i][j] );
            }
        }
    }
    graph.add_edge(s, t, K, INF);
    ll  cap,cost;
    tie(cap,cost) = graph.flow(s, t, K);
    cout << (K*INF - cost) << endl;    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


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

using namespace std;
typedef long long ll;

#define LOOP(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) LOOP(i, 0, n)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359

int main(void) {
  int cnt = 0;
  vector<int> ans;
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    vector<int> v;
    int temp;
    for (int i = 0; i < n; i++) {
      cin >> temp;
      v.push_back(temp);
    }
    sort(v.begin(), v.end());
    for(int i=1; i<n-1; i++) {
      cnt += v[i];
    }
    ans.push_back(cnt/(n-2));
    cnt = 0;
  }

  for(int i=0; i<ans.size(); i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

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

int main(){
  int hito,mono;
  int tmpMono;
  int tmpSuki;
  
  cin >> hito >> mono;
  vector<int> vec(mono,0);
  
  for(int i = 0; i < hito; i++){
    cin >> tmpMono;
    for(int j = 0; j < tmpMono; j++){
      cin >> tmpSuki;
      vec.at(tmpSuki - 1) += 1;
    }
  }
  
  int cnt = 0;
  for(int i = 0; i < mono; i++){
    if(vec.at(i) == hito) cnt++;
  }
  
  cout << cnt;
}


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

using namespace std;

int main(){
    char str[4];
    char a,b;
    int hoge=0;

    cin >> str;
    a = str[0];
    for (int i=0;i<4;i++){
        if (a == str[i]){
            hoge++;
        }
    }

    if (hoge == 2){
        for  (int i=1;i<4;i++){
            if (a != str[i]){
                b = str[i];
            }
        }
    }
    else{
        cout << "No" << endl;
        return 0;
    }
    hoge = 0;
    for (int i=0;i<4;i++){
        if (b == str[i]){
            hoge++;
        }
    }

    if (hoge == 2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }



    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string yomi[10] = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};
    cout << yomi[N % 10] << endl;
}

Measured memory_bytes: 3576
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Map<Integer, Set<Integer>> doukutsu = new HashMap<>();

        for (int i=0;i<m;i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            Set<Integer> mitch = new HashSet<>();
            if (doukutsu.containsKey(a)) {
                mitch = doukutsu.get(a);
            }
            mitch.add(b);
            doukutsu.put(a,mitch);

            Set<Integer> mitch2 = new HashSet<>();
            if (doukutsu.containsKey(b)) {
                mitch2 = doukutsu.get(b);
            }
            mitch2.add(a);
            doukutsu.put(b,mitch2);
        }
        Map<Integer, Integer> ans = new HashMap<>();
        Set<Integer> next = new HashSet<>();
        next.add(1);

        while (!next.isEmpty()) {
            Set<Integer> next2 = new HashSet<>();
            for (Integer nInt : next) {
                Set<Integer> root = doukutsu.get(nInt);
                for (Integer rInt : root) {
                    if (!ans.containsKey(rInt) && rInt != 1) {
                        ans.put(rInt, nInt);
                        next2.add(rInt);
                    }
                }
            }
            next = next2;
        }

        if (ans.size() < (n-1)) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
            for (int i = 2;i<=n;i++) {
                System.out.println(ans.get(i));
            }
        }

    }
}


Measured memory_bytes: 109828
S, Q = input(), int(input())
rev = False
st = []
ed = []
for _ in range(Q):
  a = input().split(' ')
  if a[0] == '1':
    rev = not rev
    continue
  if not rev:
    if a[1] == '1':
      st.append(a[2])
    else:
      ed.append(a[2])
  else:
    if a[1] == '1':
      ed.append(a[2])
    else:
      st.append(a[2])
if rev:
  print(''.join(reversed(ed)) + S[::-1] + ''.join(st))
else:
  print(''.join(reversed(st)) + S + ''.join(ed))

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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define endl '\n'

using ull = unsigned long int;
using ll = long long;

template <class Key, class Val>
using hmap = gp_hash_table<Key, Val>;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    const int precision = 13;
    cout.precision(precision);
    cout.setf(ios_base::fixed);

    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n, 0));
    for (auto& v : a) for (int& i : v) cin >> i;

    const int mod = 1e9 + 7;
    vector<vector<int>> dp(n, vector<int>(1<<n, -1));
    for (int i = 0; i < n; ++i) {
      dp[0][1<<i] = a[0][i];
    }

    function<int(int, int)> solve = [&](int man, int unpaired) -> int {
      if (dp[man][unpaired] != -1) return dp[man][unpaired];
      if (man == 0) return dp[man][unpaired];

      int& ans = dp[man][unpaired];

      ans = 0;
      for (int j = 0; j < n; ++j) {
        if (!(unpaired & (1<<j)) or a[man][j] == 0) continue;
        ans += solve(man-1, unpaired^(1<<j));
        if (ans >= mod) ans -= mod;
      }

      return ans;
    };

    cout << solve(n-1, (1<<n) -1) << endl;

    return 0;
}


Measured memory_bytes: 180608
#include <iostream>
#include <sstream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<n;i++)
vector<double> data;
pair<double,double> lc;
vector<bool> done;

double memo[1<<12][11];

int boxSize;
bool flag;

double solve(double x,double a,double b){
	return (2.0*x+sqrt(4*x*x-4*(x*x-4*a*b)) ) / 2.0;
}

void memo_view()
{
	for(int i=0;i < ( 1<<done.size() );i++){
		for(int j=0; j < done.size() ;j++){
			if(i & (1<<j) )cout << j+1 << " ";
		}
		cout << endl;
		cout << "=" << memo[i] << endl << endl;
	}
}
void bt(){
	if( count(done.begin(),done.end(),true) == done.size() ){
		if( lc.X + lc.Y <= boxSize){
			flag = true;
		}
	}
	if(flag || lc.X + lc.Y > boxSize - 1.0e-07)return;
	
	int msk = 0;
	for(int i=0;i<done.size();i++){
		if(done[i])msk += 1<<i;
	}
	if( lc.X + lc.Y >= memo[msk][(int)lc.first])return;
	memo[msk][(int)lc.first] = lc.X + lc.Y;
	for(int i=0;i<data.size();i++){
		if(done[i])continue;
		
		if(solve(lc.X,lc.Y,data[i]) > boxSize)continue;
		done[i] = true;
		pair<double,double> tmp = lc;
		lc = make_pair(solve(lc.X,lc.Y,data[i]),data[i]);
		bt();
		lc = tmp;
		done[i] = false;
	}
}


int main(){
	int t;
	string s;
	while(getline(cin,s) && s != ""){
		vector<int> input;
		flag = false;
		data.clear();
		
		stringstream ss(s);
		while(ss >> t)input.push_back(t);
		
		boxSize = input[0];
		for(int i=1;i<input.size();i++){
			data.push_back(input[i]);
		}
		sort( data.begin(),data.end(),greater<int>() );
		done.resize(data.size());
		fill(done.begin(),done.end(),false);
		rep(i,1<<12)rep(j,11)memo[i][j] = (1<<12);
		
		for(int i=0;i<data.size();i++){
			done[i] = true;
			lc = make_pair(data[i],data[i]);
			bt();
			done[i] = false;
		}

		cout << (flag?"OK":"NA") << endl;
	}
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
int main(){
  bool flag = true;
  while(flag){
    int a, b;
    cin >> a >> b;
if( a == 0 && b ==0) break;
    for(int i = 0; i<a;i++){
       for(int j = 0; j<b; j++){
        if(i==0 || i == a-1)
           cout << '#';
        else if(j == 0 || j == b-1)
           cout << '#';
        else
           cout << '.';
}
cout << endl;
}
cout << endl;
}
}


Measured memory_bytes: 3076