akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){

    int N;
    cin >> N;
    
    int C0 = 0;
    int C1 = 0;
    int C2 = 0;
    int C3 = 0;
    
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        if(S == "AC"){
            C0++;
        }
        if(S == "WA"){
            C1++;
        }
        if(S == "TLE"){
            C2++;
        }
        if(S == "RE"){
            C3++;
        }
    }

    cout << "AC x " << C0 << endl;
    cout << "WA x " << C1 << endl;
    cout << "TLE x " << C2 << endl;
    cout << "RE x " << C3 << endl;
}



Measured memory_bytes: 3548
#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++)
using ll = long long;

using namespace std;
int main(){
	vector<int>Term;
	int num;
	cin >> num;
	rep(i, 4) {
		Term.push_back(num % 10);
		num /= 10;
	}
	string ans = to_string(Term[3]);
	for (int tmp = 0; tmp < (1 << 3); tmp++) {	//演算子が入りうるすべての場所をbitで表現
		bitset<3>bit(tmp);	//取りうる最大のbit数　<>内は定数不可
		num = Term[3];
		rep(i, 3) {
			if (bit.test(2-i)) {
				num += Term[2-i] * (-1);
			}
			else {
				num += Term[2 - i];
			}
		}
		if (num == 7) {
			rep(i, 3) {
				if (bit.test(2 - i)) {
					ans += "-" + to_string(Term[2 - i]);
				}
				else {
					ans += "+" + to_string(Term[2 - i]);
				}
			}
			break;
		}
	}
	cout << ans << "=7" << endl;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)

n,q = list(map(int, input().split()))

graph = defaultdict(list)
for _ in range(n-1):
    p,c = list(map(int, input().split()))
    graph[p].append(c)
    graph[c].append(p)

counter = defaultdict(int)
for _ in range(q):
    i,c = list(map(int, input().split()))
    counter[i] += c

ans = [0] * (n + 1)
visit = [False] * (n + 1)
def dfs(node, total_counter):
    visit[node] = True
    total_counter += counter.get(node, 0)
    
    for child in graph[node]:
        if not visit[child]:
            dfs(child, total_counter)
    ans[node] = total_counter

dfs(1, 0)

print(*ans[1:])

Measured memory_bytes: 257588
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

#define int LL

const int MAX_V = 202;
int d[MAX_V][MAX_V];
int V;

void warshall_floyd() {
	for (int k = 0; k<V; k++) {
		for (int i = 0; i<V; i++) {
			for (int j = 0; j<V; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}
void first() {
	for (int i = 0; i < MAX_V; i++) {
		for (int j = 0; j < MAX_V; j++) {
			if (i == j)d[i][j] = 0;
			else d[i][j] = INF;
		}
	}
}
signed main() {
	first();
	int N, M, R;
	cin >> N >> M >> R;
	int a, b, c;
	vector<int> v;
	V = N;
	int r;
	for (int i = 0; i < R; i++) {
		cin >> r;
		v.emplace_back(r - 1);
	}
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		a--, b--;
		if (d[a][b] < c) continue;
		d[a][b] = c;
		d[b][a] = c;
	}
	warshall_floyd();
	sort(v.begin(), v.end());
	LL ans = INF;
	do {
		LL sum = 0;
		for (int i = 0; i < R - 1; i++) {
			sum += d[v[i]][v[i + 1]];
		}
		ans = min(sum, ans);
	} while (next_permutation(v.begin(), v.end()));
	cout << ans << endl;
}

Measured memory_bytes: 512
import math
list = [input() for i in range(5)]
one_min = 10
for i in range(5):
    if one_min >= int(list[i][-1]) > 0:
        one_min = int(list[i][-1])
sum = 0
for i in range(5):
    sum += math.ceil(int(list[i])/10)*10
print(sum - 10 + one_min)

Measured memory_bytes: 3064
N,K=map(int,input().split())
A=list(map(int,input().split()))

H=(K*(K-1))//2

X=0
M=10**9+7
I=(M+1)//2

for i in range(N):
    P,Q,S,V=0,0,0,0
    for j in range(N):
        if A[i]<A[j]:
            P+=1
            if j<i:
                S+=1
        if A[i]>A[j]:
            Q+=1
            if i<j:
                V+=1
    X+=K*(S+V)+H*(P+Q)
    X%=M
print((X*I)%M)

Measured memory_bytes: 73700
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>
#include<memory>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7




//メイン関数
int main()
{
	ll N, K;
	cin >> N >> K;
	vector<ll> a(N), b(N), l(N), c, r(N);
	REP(i, N)cin >> a[i];
	b = a;
	reverse(b.begin(), b.end());

	REP(i, N - 1)
	{
		l[i + 1] = l[i] + max(0ll, a[i]);
		r[i + 1] = r[i] + max(0ll, b[i]);
	}
	reverse(r.begin(), r.end());
	REP(i, N - 1)a[i + 1] += a[i];
	REP(i, N - K + 1)b[i] = a[i + K - 1] - (i == 0 ? 0 : a[i - 1]);

	ll res = -INFL;
	REP(i, N - K + 1)
	{
		ll score = l[i] + max(0ll,b[i]) + r[i + K - 1];
		//cerr << score << endl;
		res = max(res, score);
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;

int H, W;
vector<long> v;
int main(){

	while (true){
		cin >> H >> W;
		if (H + W == 0)break;

		for (int y = 0; y < H; ++y){
			for (int x = 0; x < W; ++x){
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	
	return 0;
}

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

int main(){
  int n,c;
  int sum1=0,sum2=0;
  cin >> n;
  vector<vector<int>> aij(2,vector<int>(n));
  for(int i=0;i<n;i++){ cin >> aij.at(0).at(i); sum1+=aij.at(0).at(i);}
  for(int i=0;i<n;i++){ cin >> aij.at(1).at(i); sum2+=aij.at(1).at(i);}
  vector<int> candies1(n),candies2(n);
  candies1.at(0) = aij.at(0).at(0);
  candies2.at(0) = sum2;
  for(int i=1;i<n;i++){
    candies1.at(i) = candies1.at(i-1)+aij.at(0).at(i);
    candies2.at(i) = candies2.at(i-1)-aij.at(1).at(i-1);
  }
  for(int i=0;i<n;i++) candies2.at(i) += candies1.at(i);
  int tmp = candies2.at(0);
  for(int i=0;i<n;i++){
    if(tmp < candies2.at(i)) tmp = candies2.at(i);
  }
  if(tmp>=(sum1+aij.at(1).at(n-1))) cout << tmp << endl;
  else cout << (sum1+aij.at(1).at(n-1)) << endl;
  
/*  c=aij.at(0).at(0);
  for(int i=0;i<n;i++){
    sum1 -= aij.at(0).at(i);
    if((sum1+aij.at(1).at(n-1))<sum2){
      c+=sum2; break;
    }
    else if((sum1+aij.at(1).at(n-1))>sum2){
      c+=aij.at(0).at(i+1);
      sum2-=aij.at(1).at(i);
    }
    else if(sum1 == 0){
      c+=sum2; break;
    }
    else{
      c+=aij.at(0).at(i+1);
      sum2-=aij.at(1).at(i);
    }
    }*/
  
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long int
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 1e5 + 7;
const int M = 11;
const ll mod = 1e9 + 7;

void solve1()
{
	double n, k, x, y, s = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> x >> y;
		if(sqrt(x * x + y * y) <= k)
			s++;
	}
	cout << s;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );
	//freopen( "moobuzz.in" , "r" , stdin );
    //freopen( "moobuzz.out" , "w" , stdout );
    
    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


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


int main() {
  int N;
  cin>>N;
  vector<int>price(N);
  
  int count=0;  int maxP=0;
   for(int i=0;i<N;i++){
     cin>>price.at(i);
     count+=price.at(i);
     maxP=max(maxP,price.at(i));
   }
  cout<<count-maxP/2;
}

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

int main(){
    ll n;
    cin >> n;
    ll ans = LLONG_MAX;
    for(ll i=1;i*i<=n;i++){
        if(n%i == 0){
            ans = min(ans , i+(n/i) - 2);
        }
    }
    cout<<ans;
    return 0;
}

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

int main () {
  string S;
  long K;
  cin >> S >> K;
  long s = S.size();
  vector<int> X(s);
  for (int i = 0; i < s; i++) {
    X.at(i) = S.at(i)-'0';
  }
  int a = min(s, K);
  for (int i = 0; i < a; i++) {
    if (X.at(i) != 1) {
      cout << X.at(i) << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,f,e) for(int (i)=(f); (i)<(e); (i)++)
#define repr(i,e,f) for(int (i)=(e-1); (i)>=(f); (i)--)

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int main(){
    ll X;
    cin >> X;
    ll ans = 0;
    ans = (X / 500) * 1000;
    X = X - (X / 500) * 500;
    ans += (X / 5) * 5;
    cout << ans;
    return 0;
}

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

int main(){
  int k, a, b ;
  cin >> k ;
  cin >> a >> b ;
  if(a%k == 0 || b%k == 0){
    cout << "OK" ;
    return 0 ;
  }
  if(a/k == b/k){
    cout << "NG" ;
    return 0 ;
  }
  cout << "OK" ;
  return 0 ;
}

Measured memory_bytes: 3560
#include <stdio.h>
int main(){
	
	int A1 , A2 , A3;

	scanf("%d %d %d", &A1 , &A2 , &A3);
	
	if(A1+A2+A3>=22)
	{
		printf("bust\n");
	}
	
	else if(A1+A2+A3<22)
	{
		printf("win\n");
	}
	
	return 0;
}

Measured memory_bytes: 2076
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
 
import java.util.*;
import java.lang.*;
import java.io.*;

@SuppressWarnings("unchecked")
public class Main implements Runnable {

  static BufferedReader in;
  static PrintWriter out;
 
  public static void main(String[] args) {
      new Thread(null, new Main(), "whatever", 1<<29).start();
  }
 
  public void run() {
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out, false);
 
    try
    {
      // in = new BufferedReader(new FileReader("class_treasurer.txt"));
      // out = new PrintWriter("output.txt");

      int t,x1,n,i,j,MOD=1000000007;
      long k;
      String str;
      String[] token;

      str=in.readLine().trim();
      token=str.split(" ");
      n=Integer.parseInt(token[0]);
      k=Long.parseLong(token[1]);

      str=in.readLine().trim();
      token=str.split(" ");

      int[] a=new int[n];
      int[] full=new int[n];
      int[] nextOnly=new int[n];

      for(i=0;i<n;i++) {
        a[i]=Integer.parseInt(token[i]);
      }

      for(i=0;i<n;i++) {
        for(j=i+1;j<n;j++) {
          if(a[i]>a[j]) {
            nextOnly[i]++;
          }
        }

        for(j=0;j<n;j++) {
          if(a[i]>a[j]) {
            full[i]++;
          }
        }
      }

      long total=0L;
      long nc2=((k-1L)*k)/2;
      nc2%=MOD;
      for(i=0;i<n;i++) {
        total+=((k*nextOnly[i])%MOD);
        total%=MOD;
        total+=((nc2*full[i])%MOD);
        total%=MOD;
      }

      out.println(total);

      out.flush();
      out.close();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 24404
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scan=new Scanner(System.in);
    int a=scan.nextInt();
    int b=scan.nextInt();
    if((a==1 && b==2) || (a==2 && b==1)){
      System.out.println(3);
    }else if((a==1 && b==3) || (a==3 && b==1)){
      System.out.println(2);
    }else if((a==2 && b==3) || (a==3 && b==2)){
      System.out.println(1);
    }
  }
}

Measured memory_bytes: 23764
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		if(n>=30) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}

}

Measured memory_bytes: 35876
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {
    ll n,m; cin >> n >> m;
    vector<ll> c(n,1),r(n,0);
    ll x,y;
    ll ans = 0;
    r[0] = 1;

    rep(i,m){
        cin >> x >> y;
        x --; y --;
        c[x] --;
        c[y] ++;

        if(r[y] > 0) r[y] ++;

        if(r[x] > 0) {
            r[x] --;
            r[y] = c[y];
        }
    }

    rep(i,n){
        if(r[i] > 0) ans ++;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1e9+7;

ll dp[10002][2][100];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string N;
    cin>>N;
  	int D;
    cin>>D;
    int n=N.length();
    dp[0][0][0]=1;
    rep(i,0,n){
        rep(j,0,2){
            rep(k,0,D){
                int lim=(j?9:N[i]-'0');
                rep(d,0,lim+1){
                    dp[i+1][j||d<lim][(k+d)%D]+=dp[i][j][k];
                    dp[i+1][j||d<lim][(k+d)%D]%=MOD;
                }
            }
        }
    }
    ll ans=-1; //正の整数
    rep(j,0,2){
        ans+=dp[n][j][0];
        ans=(ans%MOD+MOD)%MOD;
    }
    cout << ans<<"\n";
}


Measured memory_bytes: 15872
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;

int gcd(int a, int b) {
	if (a%b == 0) return b;
	return gcd(b, a%b);
}

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int w = a[0];
	for (int i = 1; i < n; i++) w = gcd(w, a[i]);
	cout << w << endl;
	return 0;
}


Measured memory_bytes: 640
def enum_divisors(n):
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.append(i)
    return res


N = int(input())
divs = enum_divisors(N)
ans = float("inf")
for div in divs:
    ans = min(ans, div + N // div - 2)
print(ans)


Measured memory_bytes: 9432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
  bool operator==(const mint rhs) const { return x == rhs.x; }
  bool operator!=(const mint rhs) const { return x != rhs.x; }
  bool operator<(const mint &a) const{ return x<a.x;};
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

template<typename ModInt> struct Combination {
  vector<ModInt> fact, ifact;
  Combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  ModInt C(int n, int k) {
    if (k < 0 || n < k) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  ModInt P(int n, int r) {
    if (r < 0 || n < r) return 0;
    return fact[n]*ifact[n-r];
  }
  ModInt H(int n, int r) {
    if (r < 0 || n < 0) return 0;
    return r == 0 ? 1 : C(n+r-1, r);
  }
  ModInt operator()(int n, int k) { return C(n, k);}
};

int main() {
  int n, m;
  cin >> n >> m;
  Combination<mint> comb(m);
  mint sub = 0;
  for (int k = 1; k <= n; ++k) { //Bのうちk個がAと被る
    sub += ((k&1) ? mint(1) : mint(-1)) * comb(n, k) * comb.P(m-k, n-k);
  }
  mint ans = comb.P(m, n) * (comb.P(m, n) - sub);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

constexpr int ms = 313;
int seen[ms][ms][ms], n;
double dp[ms][ms][ms];


double solve(int a, int b, int c) {
    if(seen[a][b][c] == 1 || (a + b + c == 0) ) return dp[a][b][c]; 
    double expected_for_progress = n / (1.0 * (a + b + c)); 
    double total = (a + b + c);
    double ret = expected_for_progress; 
    if(a > 0) ret += (a / total) * solve(a - 1, b, c);
    if(b > 0) ret += (b / total) * solve(a + 1, b - 1, c);
    if(c > 0) ret += (c / total) * solve(a, b + 1, c - 1);

    seen[a][b][c] = 1;
    dp[a][b][c] = ret;
    return dp[a][b][c];
}


int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    vector<int> f(3, 0); 
    memset(seen, 0, sizeof seen);

    for(int i = 0; i < n; ++i) {
        int x; cin >> x; 
        --x;
        f[x]++;
    }
    
    seen[0][0][0] = 1;
    dp[0][0][0] = 0.0;
    
    cout << fixed << setprecision(15);
    cout << solve(f[0], f[1], f[2]) << '\n';
    
    return 0;

}


Measured memory_bytes: 235224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define double long double
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define rsort(a) sort(all(a),greater<>())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T> inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<int,int> P;
const long long MOD=1000000007;
clock_t time_ini = clock();
double time_diff(){
  ll time_tmp = clock();
  const double time = static_cast<double>(time_tmp - time_ini) / CLOCKS_PER_SEC * 1000.0;
  return time;
}
#define saiaku if(time_diff() > 1990)

vector <ll> dp_a;
vector <ll> dp_b;
vector <ll> dp_c;
vector <ll> A;
vector <ll> B;
vector <ll> C;
bool used_a;
bool used_b;
bool used_c;

ll dfs(ll i){
  if (i==0) {
    if (used_a){
      used_a = false;
      return max(B[0], C[0]);
    } else if (used_b) {
      used_b = false;
      return max(C[0], A[0]);
    } else if (used_c) {
      used_c = false;
      return max(A[0], B[0]);
    }
  }

  if (used_a) {
    used_a = false;
    if (dp_a[i]>=0) {return dp_a[i];}
    ll ans_b = 0;
    ll ans_c = 0;
    used_b = true;
    ans_b = dfs(i-1) + B[i];
    used_c = true;
    ans_c = dfs(i-1) + C[i];
    return dp_a[i] = max(ans_b, ans_c);
  } else if (used_b) {
    used_b = false;
    if (dp_b[i]>=0) {return dp_b[i];}
    ll ans_c = 0;
    ll ans_a = 0;
    used_c = true;
    ans_c = dfs(i-1) + C[i];
    used_a = true;
    ans_a = dfs(i-1) + A[i];
    return dp_b[i] = max(ans_c, ans_a);
  } else if (used_c) {
    used_c = false;
    if (dp_c[i]>=0) {return dp_c[i];}
    ll ans_a = 0;
    ll ans_b = 0;
    used_a = true;
    ans_a = dfs(i-1) + A[i];
    used_b = true;
    ans_b = dfs(i-1) + B[i];
    return dp_c[i] = max(ans_a, ans_b);
  }
}

void solve(long long N, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c){
  dp_a = vector<ll> (N+1, -1);
  dp_b = vector<ll> (N+1, -1);
  dp_c = vector<ll> (N+1, -1);
  A = a;
  B = b;
  C = c;
  ll ans_a = 0;
  ll ans_b = 0;
  ll ans_c = 0;
  used_a = true;
  // ans_a = dfs(N-1) + a[N-1];
  ans_a = dfs(N-1);
  used_b = true;
  ans_b = dfs(N-1);
  used_c = true;
  ans_c = dfs(N-1);
  cout << max({ans_a, ans_b, ans_c}) << endl;
}

int main(){
    long long N;
    bool test = scanf("%lld",&N);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    std::vector<long long> c(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        scanf("%lld",&c[i]);
    }
    solve(N, std::move(a), std::move(b), std::move(c));
    return 0;
}


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

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;}

int main(){
	int n;
	cin >> n;
	
	int even = n / 2;
	double ans = (double)(n - even) / n;
	
	cout << fixed << setprecision(10) << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let S = rl().chars().collect::<Vec<_>>();
    let _Q = read!(usize);
    let K = read![[usize]];

    for k in K {
        debug!(k);

        let mut total = 0_i64;

        // いまの区間に含まれる D の個数
        let mut d_count = 0_i64;

        // いまの区間に含まれる M の個数
        let mut m_count = 0_i64;

        // いまの区間に含まれる DM ペアの個数
        let mut dm_count = 0_i64;

        let mut l = 0;
        for r in 0..N {
            if r - l >= k {
                // 次の区間幅を k に抑えるため、区間先頭を除外する。
                if S[l] == 'D' {
                    d_count -= 1;
                    dm_count -= m_count;
                }
                if S[l] == 'M' {
                    m_count -= 1;
                }
                l += 1;
            }

            if S[r] == 'D' {
                d_count += 1;
            }
            if S[r] == 'M' {
                // 区間の末尾に M が出現することで、区間内の DM ペアの個数は D の個数だけ増える。
                m_count += 1;
                dm_count += d_count;
                debug!((r, S[r], d_count, m_count, dm_count));
            }
            if S[r] == 'C' {
                // 区間内の DM ペアの個数だけ DMC が見つかったので数える。
                total += dm_count;
                debug!((r, S[r], dm_count, total));
            }
        }

        println!("{}", total);
    }
}


Measured memory_bytes: 12532
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, t;
    cin >> n >> t;
    vi a(n, 0);
    map<ll, ll> cnt;
    rep(i, n) cin >> a[i];

    // 逆順に見ていき、そこまでの最大値を売り箇所として最大利益を算出していく。
    ll num = t/2, maxPrise = -1, maxProfit = -1;
    for(ll i=n-1; i>=0; i--){
        if(maxPrise < a[i]){
            maxPrise = a[i];
            cnt[0]++;
        }
        else{
            ll profit = (maxPrise - a[i])*num;
            cnt[profit]++;
            if(maxProfit < profit) maxProfit = profit;
        }
    }
    cout << cnt[maxProfit] << endl;
}

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

#define lugan "ks1"
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define endl '\n'
#define _io ios_base::sync_with_stdio(0);   cin.tie(NULL); cout.tie(NULL);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5+7;
const int oo = 1e9+7;

inline void initf()
{
    freopen(lugan".inp", "r", stdin);
    freopen(lugan".out", "w", stdout);
}

int n, s, w, v;
ll dp[N];

int main()
{
    _io
    cin >> n >> s;
    for (int i=1; i<=n; i++)
    {
        cin >> w >> v;
        for (int t = s; t>=w; t--)
        {
            dp[t] = max(dp[t - w] + v, dp[t]);
            dp[s+1] = max(dp[s+1], dp[t]);
        }
    }
    cout << dp[s+1];
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n;
bool arr[23][23];
int M = 1e9+7;
int memo[(1 << 21) + 1] = {};
int dp(int man, int r_wmn){
  if(r_wmn==0)
    return 1;
  if(memo[r_wmn]!=-1)
    return memo[r_wmn];
  int num=0;
  for(int i=0;i<n;i++){
    if(!arr[man][n-i-1] || !(r_wmn&(1<<i)))
      continue;
      num+=dp(man+1,r_wmn^(1<<i));
    num=num%M;
  }
  memo[r_wmn]=num;
  return num;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>arr[i][j];
  memset(memo,-1,sizeof(memo));
  int res=dp(0,(1<<n)-1);
  cout<<res<<"\n";
}

Measured memory_bytes: 11792
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private List<List<Integer>> list = new ArrayList<>();

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        for (int i = 0; i < N; ++i) {
            list.add(new ArrayList<>());
        }
        for (int i = 0; i < N - 1; ++i) {
            int a = sc.nextInt();
            list.get(a - 1).add(i + 1);
        }
        _out.println(calc(0));
    }
    private int calc(int v) {
        List<Integer> child = list.get(v);
        if (child.size() == 0) {
            return 0;
        }

        List<Integer> tmp = new ArrayList<>();
        for (int u : child) {
            tmp.add(calc(u));
        }
        Collections.sort(tmp);
        int res = 0;
        for (int i = 0; i < tmp.size(); ++i) {
            int u = tmp.get(i);
            res = Math.max(res, u + child.size() - i);
        }
        return res;
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 97584
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;

    scanf("%d%d%d%d",&a,&b,&c,&d);
    int l=a+b;
    int r=c+d;
    if( l>r)
        cout<<"Left"<<endl;
    else if(l<r)
        cout<<"Right"<<endl;
    else
        cout<<"Balanced"<<endl;

    return 0;
}


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

signed main() {
  char c[111111];
  int ops;
  scanf("%s %d", c, &ops);
  int n = strlen(c);
  
#define next(c) (c=='z' ? 'a' : c+1)
#define minimize(c) do { \
    if (ops > 30) {\
      if (c=='a')\
        break;\
      ops -= 'z'-c + 1;\
      c = 'a';\
      break;\
    }\
    \
    int ops_orig=ops;\
    char c_orig = c;\
    while (c != 'a' && ops > 0) {\
      c = next(c);\
      --ops;\
    }\
    if (c != 'a') {\
      ops = ops_orig;\
      c = c_orig;\
    }\
} while(0);

  for (int i=0; i<n; ++i)
    minimize(c[i]);
  while (ops>0) {
    c[n-1] = next(c[n-1]);
    --ops;
  }
  puts(c);
}

/*
 * Local variables:
 * compile-command:"g++ -D_GLIBCXX_DEBUG -g3 -ggdb3 -O0 -Wall -Wextra -std=c++14 c.cc -o c && for f in *.in; do echo \"--- $f -------------\"; ./c <$f; done"
 * end:
 */



Measured memory_bytes: 512
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!{
        n: usize,
        a: [i32; n],
    }
    let ma = a.iter().max();
    let mi = a.iter().min();
    if ma != None && mi != None {
        println!("{}", ma.unwrap()-mi.unwrap());
    }
}


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

const int INF=100;
char maze[22][22];
int n,m;
int d[22][22];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};

int bfs(int sx, int sy, int gx, int gy) {
  queue<P> que;
  rep(i, n) rep(j, m) d[i][j]=INF;
  que.push(P(sx, sy));
  d[sx][sy]=0;
  while (que.size()) {
    P p=que.front();
    que.pop();
    if (p.first==gx&&p.second==gy) break;
    rep(i, 4) {
      int nx=p.first+dx[i];
      int ny=p.second+dy[i];
      if (0<=nx&&nx<n&&0<=ny&&ny<m&&maze[nx][ny]!='#'&&d[nx][ny]==INF) {
        que.push(P(nx, ny));
        d[nx][ny]=d[p.first][p.second]+1;
      }
    }
  }
  return d[gx][gy];
}

int main() {
  cin>>n>>m;
  rep(i, n) rep(j, m) cin>>maze[i][j];

  int res=0;
  rep(sx, n){
     rep(sy, m) {
       rep(gx, n) {
         rep(gy, m) {
           if (maze[sx][sy]=='#') continue;
           if (maze[gx][gy]=='#') continue;
           int tmp=bfs(sx, sy, gx, gy);
           res=max(res, tmp);
         }
       }
     }
  }
  cout<<res<<endl;
}

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

using namespace std;

int r, c;
bool check (int x, int y) {
    return ((x == 0 && y <= c) || (y == 0 && x <= r) || (x == r && y <= c) || (y == c && x <= r));
}

bool cmp (pair <pair <int, int>, pair <int, int> > p1, pair <pair <int, int>, pair <int, int> > p2) {
    return p1.second.second < p2.second.second;
}

int change (int x, int y) {
    if (x == 0 && y <= c) return y;
    if (y == c && x <= r) return y + x;
    if (x == r && y <= c) return r + c + c - y;
    if (x <= r && y == 0) return r + c + c + r - x;
}

int main(){
    int n;
    scanf("%d %d %d", &r, &c, &n);

    pair <pair <int, int>, pair <int, int> > a[2 * n + 1];
    bool used[n + 1];
    memset(used, 0, sizeof(used));

    int cur = 1;
    for (int i = 1; i<=2*n; i = i + 2) {
        scanf("%d %d %d %d", &a[i].first.first, &a[i].first.second, &a[i + 1].first.first, &a[i + 1].first.second);
        a[i].second.first = cur;
        a[i + 1].second.first = cur;

        a[i].second.second = change(a[i].first.first, a[i].first.second);
        a[i + 1].second.second = change(a[i + 1].first.first, a[i + 1].first.second);
        cur++;
    }
    for (int i = 1; i<=2*n; i = i + 2) {
        if (check(a[i].first.first, a[i].first.second) && check(a[i + 1].first.first, a[i + 1].first.second)) {
            used[a[i].second.first] = true;
        }
    }

    sort(a + 1, a + n * 2 + 1, cmp);
    stack <int> st;

    bool f = true;
    int cnt[2 * n + 1];
    memset(cnt, 0, sizeof(cnt));

    /*for (int i = 1; i<=2*n; i++) {
        if (used[a[i].second.first]) cout << a[i].first.first << " " << a[i].first.second << "\n";
    }*/

    for (int i = 1; i<=n*2; i++) {
        if (!used[a[i].second.first]) continue;

        if (st.empty()) {
            st.push(a[i].second.first);
            cnt[a[i].second.first]++;
        }
        else {
            if (cnt[a[i].second.first] == 0) {
                cnt[a[i].second.first]++;
                st.push(a[i].second.first);
            }
            else {
                int u = st.top(); st.pop();
                if (u != a[i].second.first) {
                    f = false;
                    break;
                }
            }
        }
    }

    if (f) printf("YES");
    else printf("NO");
    return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

typedef long long int ll;

int main () {
    string s; cin >> s;
    int n = s.size();

    ll mod = 0;
    ll next = 1;
    vector<ll> memo(2019, 0);
    memo[0] = 1;
    for (int i = n-1; i >= 0; i--) {
        mod = (((s[i] - '0') * next) + mod) % 2019;
        next = (next * 10) % 2019;
        memo[mod]++;
    }
    ll ans = 0;
    for (int i = 0; i < (int)memo.size(); i++) {
        if (memo[i] <= 1) { continue; }
        ans += ((memo[i] - 1)* (memo[i] -1 + 1)) / 2;
    }
    cout << ans << endl;
    
 
    return 0;
}

Measured memory_bytes: 3372
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main(){
 int n,l,i,temp;
 int max=0;

 cin>>n>>l;

 vector<int> apple(n);

 apple.at(0)=l;

 for(i=1;i<n;i++){
     apple.at(i)=l+i;

    if(apple.at(0)>=0){
        if(apple.at(i)<0){
            if(apple.at(i)*-1<apple.at(0)){
                temp=apple.at(0);
                apple.at(0)=apple.at(i);
                apple.at(i)=temp;
            }
        }
        else{
            if(apple.at(i)<apple.at(0)){
                temp=apple.at(0);
                apple.at(0)=apple.at(i);
                apple.at(i)=temp;
            }
        }
    }
    else{
        if(apple.at(i)<0){
            if(apple.at(i)*-1<apple.at(0)*-1){
                temp=apple.at(0);
                apple.at(0)=apple.at(i);
                apple.at(i)=temp;
            }
        }
        else{
            if(apple.at(i)<apple.at(0)*-1){
                temp=apple.at(0);
                apple.at(0)=apple.at(i);
                apple.at(i)=temp;
            }
        }
    }
 }

 for(i=1;i<n;i++){
     max+=apple.at(i);
 }

    cout<<max;
    
}




Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
C = [C[A[i]-1] for i, _ in enumerate(C) if A[i+1]-A[i]==1] 



U = sum(B) + sum(C)

print(U)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

vector<string> s(1000);
int visited[1010][1010];
int h, w, ch, cw, dh, dw;
vector<P> moves = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

bool is_range(int y, int x) {
  return 0 <= y && 0 <= x && y < h && x < w;
}
bool is_wall(int y, int x) {
  return s[y][x] == '#';
}
bool already_visited(int y, int x, int dist) {
  return visited[y][x] <= dist;
}
bool is_goal(int y, int x) {
  return y == dh && x == dw;
}

void bfs() {
  deque<P> d;
  d.push_back({ ch, cw });

  while(!d.empty()) {
    auto v = d.front(); d.pop_front();
    int y = v.first, x = v.second;
    int nd = visited[y][x];
    int ndd = nd+1;
    for(auto move:  moves) {
      int ny = y + move.first;
      int nx = x + move.second;

      if (!is_range(ny, nx)) continue;
      if (already_visited(ny,nx,nd)) continue;

      if (!is_wall(ny,nx)) {
        visited[ny][nx] = nd; // visit
        d.push_front({ ny, nx });
      } else {
        for (int i = -2; i <= 2; i++) {
          for (int j = -2; j <= 2; j++) {
            if (i==0 && j==0) continue;
            int ni = i+y;
            int nj = j+x;
            if (!is_range(ni,nj)) continue;
            if (is_wall(ni,nj)) continue;
            if (already_visited(ni,nj,ndd)) continue;

            if (ndd < visited[ni][nj]) visited[ni][nj] = ndd;
            d.push_back({ ni, nj });
          }
        }
      }
    }
  }
}

int main() {
  IOS;
  cin >> h >> w;
  cin >> ch >> cw;
  cin >> dh >> dw;
  REP(i,h) cin >> s[i];
  ch--; cw--; dh--; dw--;
  REP(i,1010) REP(j,1010) visited[i][j] = INF;
  visited[ch][cw] = 0;

  bfs();
  /*
  REP(i,h) {
    REP(j, w) {
      cout << visited[i][j] << " ";
    }
    cout << endl;
  }
  */

  if (visited[dh][dw] != INF) {
    COUT(visited[dh][dw]);
  } else {
    COUT(-1);
  }

  return 0;
}

Measured memory_bytes: 8784
package main

import (
    "fmt"
)

func main() {
    var a, b int
    fmt.Scanf("%d %d", &a, &b)
    s := a + b
    if (a % 2) != (b % 2) {
        fmt.Println("IMPOSSIBLE")
    } else if s % 2 == 0 {
        fmt.Println(s / 2)
    }
}


Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    cout << max(0,a-b*2) << endl;;

    return 0;
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    vector<ll> v(3);
    rep(i, 3) cin >> v[i];
    sort(all(v));
    ll ans = 0;
    while(v[1] < v[2]) {
        v[0]++;
        v[1]++;
        ans++;
    }
    ll tmp = v[2] - v[0];
    if (tmp % 2 == 0) {
        ans += tmp / 2;
    } else {
        ans += (tmp+1) / 2 + 1;
    }
    print(ans);
    return 0;
}

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

int main()
{
    int c;
    scanf("%c",&c);
        if(c=='A')
            printf("T\n");
        if(c=='T')
            printf("A\n");
        if(c=='C')
            printf("G\n");
        if(c=='G')
            printf("C\n");
    return 0;
}


Measured memory_bytes: 256
/*
*	User: Isanchez_Aguilar
*	Problem: AtCoder ABC134B - Golden Apple
*/
#include <bits/stdc++.h>

using namespace std;
using Long = long long;
using ii = pair<int, int>;

inline int countDigits(Long n)
{
	int ans = 0;

	while (n > 0)
		++ans, n /= 10ll;

	return ans;
}

int main(void)
{
	Long n;
	cin >> n;

	int ans = INT_MAX;

	for (Long i = 1; i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			Long a = i;
			Long b = n / i;
			int curr = max(countDigits(a), countDigits(b));
		
			ans = min(ans, curr);
		}
	}

	cout << ans;


	return 0;
}


Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
lis = lambda x : int(x.replace('.',''))
li2 = lambda : list(map(lis,input().split()))

# かぶっているか判定
# 最短判定

import math

class UnionFind:
    def __init__(self,n):
        self.n = n
        self.d = [-1] * n

    def find(self, x):
        if(self.d[x] < 0):
            return x
        self.d[x] = self.find(self.d[x])
        return self.d[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return False
        if(self.d[x] > self.d[y]):
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self,x):
        return -self.d[self.find(x)]

def judgeContact(a,b):
    # k = (a[0]-b[0])**2 + (a[1]-b[1])**2 + (a[2]-b[2])**2 - (a[3] + b[3]) ** 2
    k = math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2 + (a[2]-b[2])**2) - (a[3] + b[3]) 
    if k <= 0:
        return -1
    else:
        return k

def calc(n):
    ps = []
    uf = UnionFind(n)
    d = []
    cnt = 0
    ans = 0

    for i in range(n):
        p = li2()
        
        # かぶり判定
        for k,j in enumerate(ps):
            v = judgeContact(p,j) 
            if v == -1:
                # d.append([0,i,k])
                if uf.same(i,k) == False:
                    uf.union(i,k)
                    cnt += 1
            else:
                d.append([v,i,k])
        ps.append(p)

    d.sort()
    for i in d:
        if cnt == n-1:
            break

        if uf.same(i[1],i[2]):
            continue
        
        uf.union(i[1],i[2])
        # print('union',i[1],i[2],cnt,i[0])
        cnt += 1
        ans += i[0]

    
    print("{:.3f}".format(ans/1000))


while 1:
    n = ii()
    if n == 0:
        break
    
    calc(n)


Measured memory_bytes: 6328
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>

#include <cmath>

#define int long long

using namespace std;

signed main() {
  int n, m;
  cin >> n >> m;

  priority_queue<int> que;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    que.push(a);
  }

  for (int i = 0; i < m; i++) {
    int a = que.top();
    que.pop();

    a /= 2;
    que.push(a);
  }

  int ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }

  cout << ans << endl;

  return 0;
}


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

int A[20], n, q, k;

bool Comb(int sum, int i){
  if(sum == k) return true;
  if(i == n) return false;

  return Comb(sum + A[i], i + 1) || Comb(sum, i + 1);
}

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

  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> k;
    if(Comb(0, 0)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n;
    cin >> n;
    int ans = -1;
    for (int i = 0; i < 50000; i++)
    {
        if(n==i*108/100)
        {
            ans = i;
        }
    }
    if (ans==-1)
    {
        cout << ":(" << endl;
        return 0;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3596
l = []
c = int(input())
for i in range(c):
    a,b = map(int, input().split())
    l.append([a,b,abs(a+b)])
l.sort(key=lambda x:x[2])
k = l[::-1]
s = 0
for i in range(c):
    if i%2==0:
        s +=k[i][0]
    else:s-=k[i][1]
print(s)

Measured memory_bytes: 24480
#include <bits/stdc++.h>
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 int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

string s;

void input(){
    cin >> s;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int cntg = 0;
    int cntp = 0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'p') cntp++;
        else cntg++;
    }
    cout << s.size() / 2 - cntp << endl;
    return 0;
}

Measured memory_bytes: 512