akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n, m;
	cin >> n >> m;
	vector<int>numberofBall(n, 1);
	vector<int>redBall(n, 0);
	redBall[0] = 1;
	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		if (redBall[x] == 1) {
			if (numberofBall[x] == 1) {
				redBall[x] = 0;
				redBall[y] = 1;
			}
			else redBall[y] = 1;
		}
		numberofBall[x]--;
		numberofBall[y]++;
	}
	int ans = 0;
	rep(i,n){
		if (redBall[i] == 1)ans++;
	}
	print(ans);
}

Measured memory_bytes: 4848
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d[] = new int[n];
		for(int i = 0; i < n; ++i)
			d[i] = sc.nextInt();
		sc.close();
		Arrays.sort(d);
		int mid = (n - 1) / 2;
		int ans = 0;
		if(d[mid] != d[mid + 1])
		ans = d[mid + 1] - d[mid];
		System.out.println(ans);
	}
}


Measured memory_bytes: 52116
<?php
fscanf(STDIN, "%d", $n);

$prev = $n - 1;
for ($i = 1; $i < $n; $i++) {
  if ($n % $i === 0) {
    $count = $i + $n / $i - 2;
    if ($count > $prev) {
      echo $prev;
      exit;
    }
    $prev = $count;
  }
  if ($i > 10000000) {
    echo $prev;
    exit;
  }
}
echo $count;


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	int h, w, n;
	cin >> h >> w >> n;
	int minv = min(h, w);
	int maxv = max(h, w);
	int masu = 0;
	for (int i = 1; i <= minv; i++) {
		masu += maxv;
		if (n <= masu) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin>>x;
    int ans1,ans2;
    ans1=x/500;
    ans1*=1000;
    x=x%500;
    ans2=x/5;
    ans2*=5;
    cout<<ans1+ans2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int a;
  int b;
  int c;
  int min;
  int max;
  int mid;
  
  cin >> a >> b >> c;
  
  min=a;
  if(b<=min)
    min=b;
  if(c<=min)
    min=c;
  
  max=a;
  if(b>=max)
    max=b;
  if(c>=max)
    max=c;
  
  if(a!=max && a!=min)
    mid=a;
  if(b!=max && b!=min)
    mid=b;
  if(c!=max && c!=min)
    mid=c;
    else if(a==b)
      mid=a;
    else if(b==c)
      mid=b;
    else if(c==a)
      mid=c;
      
  cout << min <<" "<< mid <<" "<< max <<"\n";
} 

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef long long ll;

const int MOD = 1000000007;

void solve() {
  int N;
  cin >> N;
  vi P(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  int ans = 0;
  int vmin = P[0];
  for (int i = 0; i < N; i++) {
    if (P[i] <= vmin) {
      ans++;
      vmin = P[i];
    }
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <array>
using namespace std;

int main()
{
    int numa, numb;
    cin >> numa >> numb;

    array<pair<int,int>,51> A;
    array<pair<int,pair<int,int> >,51> B;

    for(int i=0;i<numa;i++){
        cin >> A[i].first >> A[i].second;
    }
    for(int i=0;i<numb;i++){
        cin >> B[i].second.first >> B[i].second.second;
        B[i].first = i+1;
    }

    for(int i=0;i<numa;i++){
        int x = A[i].first;
        int y = A[i].second;
        int way = 1e9;
        int current;
        for(int j=0;j<numb;j++){
            if(way>abs(x-B[j].second.first)+abs(y-B[j].second.second)){
                way = abs(x-B[j].second.first)+abs(y-B[j].second.second);
                current = B[j].first;
            }
        }
        cout << current << endl;
    }

    return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vector<P> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(all(p));
  vl ml(n + 1, 1e18), mr(n + 1, 1e18);
  rep(i, n) ml[i + 1] = min(ml[i], p[i].second);
  for(ll i = n - 1; i >= 0; i--) mr[i] = min(mr[i + 1], p[i].second);
  ll ans = 0;
  // cout << endl;
  // rep(i, n) cout << p[i].first << ' ' << p[i].second << endl;
  // cout << endl;
  rep(i, n - 1) {
    ll l1 = p[i].first;
    ll r1 = p[i].second;
    ll l2 = p[n - 1].first;
    ll r2 = mr[i + 1];
    ll tr = ml[i];
    ll now = max(0LL, min(r1, tr) - l1 + 1) + max(0LL, r2 - l2 + 1);
    ans = max(ans, now);
    now = max(0LL, r1 - l1 + 1) + max(0LL, min(r2, tr) - l2 + 1);
    ans = max(ans, now);
    // printf("(%d,%d),(%d,%d),%ld\n", l1, r1, l2, r2, tr);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6432
#include <stdio.h>
int main (void){
  int A,B;
  int S,T,U;
  int max;
  scanf("%d %d",&A,&B);
  S=A+B;
  T=A-B;
  U=A*B;
  max=S;
  if(max<T){
    max=T;
  }
  if(max<U){
    max=U;
  }
  
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>

using namespace std;

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

int main() {
    int N, D;
    cin >> N >> D;
    cout << N / (2 * D + 1) + (N % (2 * D + 1) > 0 ? 1 : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
/*	* In the name of GOD
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define int long long

int32_t main(){
	int n, k;
	cin >> n >> k;
	int a[n];
	bool f[n + 1] = {};
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	vector <int> v;
	int x = 1;
	while (!f[x]){
		v.push_back(x);
		f[x] = true;
		x = a[x - 1];
	}
//	for (int i = 0; i < v.size(); i++){
//		cout << v[i] << ' ';
//	}
//	cout << endl;
	int y = a[v[v.size() - 1] - 1];
	int an = 0;
	for (int i = 0; i < v.size(); i++){
		if (v[i] == y)
			an = i;
	}
	if (k < an){
		cout << v[k];
		return 0;
	}
	k -= an;
//	cout << an << endl;
	int z = v.size() - an;
//	cout << z << endl;
	cout << v[(k % z) + an];
}


Measured memory_bytes: 7124
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;
    int cnt = 0;
    int glo = 1;
    rep(i, n) {
        if (s[i] == 'a' && cnt < a + b) {
            cout << "Yes" << endl;
            cnt++;
        }
        else if (s[i] == 'b' && cnt < a + b && glo <= b) {
            cout << "Yes" << endl;
            cnt++;
            glo++;
        }
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 896
/**
*    created: 23.06.2020 23:22:38
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;
    if (s[0] == '1') s[0] = '9';
    else s[0] = '1';
    if (s[1] == '1') s[1] = '9';
    else s[1] = '1';
    if (s[2] == '1') s[2] = '9';
    else s[2] = '1';
    cout << s << endl;
    return 0;
}

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

int main()
{
        string s;
        cin >>s;
        int ans =0;
        int a = 0;
                
        
        for(int i = 0;i< s.size();i++)
        {
                if(s[i] == 'A' || s[i] =='C'|| s[i] == 'G' || s[i] == 'T')
                        a++;
                else{
                        ans = max(ans, a);
                        a= 0;
                }
        }
         ans = max(ans, a);
        cout << ans << endl;
}



Measured memory_bytes: 256
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-09-15 19:45
# @url:

import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
## 注意嵌套括号!!!!!!
## 先有思路,再写代码,别着急!!!
## 先有朴素解法,不要有思维定式,试着换思路解决
def main():
    x=int(input())
    dp=[0]*(x+1)
    mod=10**9+7
    for i in range(x+1):
        if i<3:
            dp[i]=0
            continue
        dp[i]=1
        for j in range(3,i-3+1):
            if i-j>5:
                dp[i]+=(1+dp[i-j]%mod-1)
            else:
                dp[i]+=dp[i-j]%mod
    print (dp[-1]%mod)
if __name__ == "__main__":
    main()

Measured memory_bytes: 77520
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    vector<ll> bits(64, 0);
    rep(i, n){
        for(ll j = 0; j <= 60; j++){
            if(a[i] & (1LL << j)){
                bits[j]++;
            }
        }
    }

    ll x = 0;
    for(ll i = 60; i >= 0; i--){
        //cout << i << " " << bits[i] << endl;
        if((x | (1LL << i)) > k){
            continue;
        }
        if(bits[i] <= n / 2){
            x |= (1LL << i);
        }
    }
    ll ans = 0;
    rep(i, n){
        ans += (a[i] ^ x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  int n,k;
  scanf("%d %d", &n, &k);
  long v[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &v[i]);
  }
  long get[n];
  int operation;
  long value;
  long max = 0;
  for (int left = 0; left <= n; left++) {
    for (int right = 0; left+right <= n; right++) {
      operation = left+right;
      if (operation > k) {
        break;
      }
      for (int i = 0; i < n; i++) {
        get[i] = 0;
      }
      value = 0;
      for (int i = 0; i < left; i++) {
        get[i] = v[i];
        value += v[i];
      }
      for (int i = 0; i < right; i++) {
        get[left+i] = v[n-1-i];
        value += v[n-1-i];
      }
      qsort(get, n, sizeof(long), cmpnum);
      for (int i = 0; i < n; i++) {
        if (operation == k || get[i] >= 0) {
          break;
        }
        operation++;
        value -= get[i];
      }
      if (value > max) {
        max = value;
      }
    }
  }
  printf("%ld\n", max);

  return 0;
}

Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
double dist(ll i, ll j)
{
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}

int main()
{
    ll i,j,cc=0;
    ll n;cin>>n;
    map<string,ll>q;
    string str;for(i=0;i<n;i++){
    cin>>str;
    sort(str.begin(),str.end());
    q[str]++;
    }
    for(auto it =q.begin(); it != q.end();it++){
            ll x=(it->second);
        cc+=(x*(x-1))/2;
    }
    cout<<cc<<endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1E9 + 7;
const int INF = 1 << 29;

int main() {
  int N;
  string S;
  cin >> N >> S;
  int CountR = 0;
  int CountG = 0;
  int CountB = 0;
  rep(i, N) {
    if (S[i] == 'R') CountR++;
    if (S[i] == 'G') CountG++;
    if (S[i] == 'B') CountB++;
  };
  //   ll ans = CountR * CountG * CountB;
  //   rep(i, N) {
  //     rep(d, N) {
  //       int j = i + d;
  //       int k = j + d;
  //       if (k >= N) break;
  //       if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) ans--;
  //     }
  //   }
  //   cout << ans << endl;
  long long ans = 0;
  int rgb = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int k = i + 2 * j;
      if (k >= N) break;
      if (S[i] != S[i + j] && S[i] != S[k] && S[i + j] != S[k]) rgb++;
    }
  }
  ans = (long long)CountR * CountG * CountB - rgb;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int n,m,c;
  cin >> n >> m >> c;
  vector<int> b(m);
  rep(i,m) cin >> b[i];

  ll res = 0;

  rep(i,n) {
    vector<int> a(m);
    ll ans = 0;
    rep(j,m) {
      ll tmp;
      cin >> tmp;
      ans += tmp * b[j];
    }

    if (ans + c > 0) {
      res += 1;
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n+1],b[m+1];
	rep(i,n)cin>>a[i+1];
	rep(i,m)cin>>b[i+1];
	a[0]=b[0]=0;
	for(int i=1;i<=n;i++)a[i]+=a[i-1];
	for(int i=1;i<=m;i++)b[i]+=b[i-1];
	int l=0,r=n+m+1;
	while(l+1<r){
		int x=mid(l,r);
		int ok=0;
		for(int i=0;i<=n;i++){
			int j=x-i;
			if(j<0||j>m)continue;
			if(a[i]+b[j]<=k){ok=1;break;}
		}
		if(ok)l=x;
		else r=x;
	}
	cout<<l;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

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

char a[60][60];

int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			cin>>a[i][j];
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			int res=0;
			if(a[i-1][j-1]=='#')
				++res;
			if(a[i-1][j]=='#')
				++res;
			if(a[i-1][j+1]=='#')
				++res;
			if(a[i][j-1]=='#')
				++res;
			if(a[i][j+1]=='#')
				++res;
			if(a[i+1][j-1]=='#')
				++res;
			if(a[i+1][j]=='#')
				++res;
			if(a[i+1][j+1]=='#')
				++res;
			if(a[i][j]=='#')
				cout<<'#';
			else
				cout<<res;
		}
		cout<<endl;
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

vector<int> p_tree(201012,0);

void make_child(vector<vector<int> > adja,int now,int parent,int left, vector<int> counter){
  int num = left + counter[now];
  p_tree[now] = num;
  for(child : adja[now]){
    if(child == parent) continue;
    make_child(adja, child, now, num, counter);
  }
  return;
}

int main(){
  int n,q;
  cin >> n >> q;
  vector<vector<int> > adja(n);
  vector<int> counter(n,0);
  vector<int> a(n,0);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    adja[a-1].push_back(b-1);
    adja[b-1].push_back(a-1);
  }
  rep(i,q){
    int p, x;
    cin >> p >> x;
    counter[p-1] += x;
  }
  //make_child(adja,0,-1,0,counter);
  queue<tuple<int,int,int> > que;
  que.push(make_tuple(0,-1,0));
  while(!que.empty()){
    tuple<int,int,int> buf = que.front();
    que.pop();
    int now = get<0>(buf);
    int parent = get<1>(buf);
    int left = get<2>(buf);
    int num = left + counter[now];
    a[now] = num;
    for(c : adja[now])
      if(c != parent)
        que.push(make_tuple(c,now,num));
  }
  
  rep(i,n-1) cout << a[i] << ' ';
  cout << a[n-1] << endl;
}




Measured memory_bytes: 18676
#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>;

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

	int n, m, x;
	cin >> n >> m >> x;
	int	count;
	count = 0;
	rep(i, m)
	{
		int a;
		cin >> a;
		if (a < x)
			count++;
		else
			break;
	}
	cout << min(count, m - count) << endl;
}


Measured memory_bytes: 256
# 2019/04/06

from numpy import array, argmax, ones

InRange = 5

# 入力受け取り
a_e = array([int(input()) for i in range(InRange)])

# 1桁目が0以外で最小
a_e10 = 10 - a_e % 10
a_e10[a_e10 == 10] = 0

sum_index = ones(InRange, dtype=bool)
sum_index[argmax(a_e10)] = False

sum_time = a_e.sum() + a_e10[sum_index].sum()

print(sum_time)

Measured memory_bytes: 12492
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1700

struct Info{
	int a,b;
};

int V; //頂点数
int N;
vector<int> G[NUM]; //グラフの隣接リスト表現
int match[NUM]; //マッチングのペア
bool used[NUM]; //DFSですでに調べたかのフラグ
//bool have_pair[NUM]; //ペアを既に作ったかのフラグ
Info info[800];

//fromとtoを結ぶ辺をグラフに追加する
void add_edge(int from,int to){
	G[from].push_back(to);
	G[to].push_back(from);
}

//増加パスをDFSで探す(node_idのペアを探す)
int dfs(int node_id){
	used[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		int adj_node_id = G[node_id][i],pair_id = match[adj_node_id];
		if((pair_id < 0)|| //隣接するノードに、まだペアが存在しない
				(used[pair_id] == false && dfs(pair_id) == true)){

			match[node_id] = adj_node_id;
			match[adj_node_id] = node_id;

			return true;
		}
	}
	return false;
}


int bipartie_matching(){
	int ret = 0;
	for(int i = 0; i < V; i++)match[i] = -1; //ペアなしにしておく
	for(int node_id = 0; node_id < V; node_id++){
		if(match[node_id] < 0){ //node_idにペアがいない場合
			for(int i = 0; i < V; i++)used[i] = false;
			if(dfs(node_id)){ //増加パスが存在する場合
				ret++;
			}
		}
	}
	return ret;
}


int main(){

	int A,B;
	scanf("%d %d %d",&N,&A,&B);

	bool check[N];
	int tmp,ans = 0;

	//N件のデータを読み込む
	for(int i = 0; i < N; i++){
		check[i] = false;

		scanf("%d %d",&info[i].a,&info[i].b);
		tmp = abs(info[i].a-info[i].b);
		if(tmp <= A || (tmp >= B && tmp <= 2*A)){
			ans++;
			check[i] = true;
		}
	}

	for(int i = 0; i < N; i++){
		if(check[i])continue;

		for(int k = i+1; k < N; k++){ //2重計上を防ぐため、自分よりインデックスが大きいもののみ走査
			if(k == i || check[k] == true)continue;
			tmp = abs((info[i].a+info[k].a)-(info[i].b+info[k].b));
			if(tmp <= A || (tmp >= B && tmp <= 2*A)){
				add_edge(i,k);
			}
		}
	}

	V = N;

	printf("%d\n", ans+bipartie_matching());

	return 0;
}



Measured memory_bytes: 3552
#include <bits/stdc++.h>
#include <math.h>
 
#define rep(i, n) for(int i = 0; (int)(i) < n; i++)
 
using namespace std;
 
int main() {
  int k;
  int ans = 0;
  cin >> k;
  for(int i = 1; i <= k; i++){
    for(int j = 1; j <= k; j++){
      for(int l = 1; l <= k; l++){
        ans += gcd(gcd(i, j), l);
      }
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String ans = "";
		while(n >= k) {
			int mod = n % k;
			ans = mod + ans;
			n = n/k;
		}
		ans = n + ans;
		System.out.println(ans.length());

		sc.close();
	}
}

Measured memory_bytes: 39276
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000;
const int MOD = (int)1e9 + 7;
template <class T>
inline T in()
{
    T x;
    cin >> x;
    return x;
}

bool comp(const pair<string, int> &a, const pair<string, int> &b)
{
    return (a.first > b.first) && (a.second > b.second);
}

signed main()
{
    int n = in<int>();
    vector<pair<string, int>> v;
    map<pair<string, int>, int> m;
    for (int i = 0; i < n; i++)
    {
        string s = in<string>();
        int p = in<int>();
        auto shop = make_pair(s, INF - p);
        v.push_back(shop);
        m[shop] = i + 1;
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
    {
        cout << m[v[i]] << "\n";
    }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	static int z = 0;
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		Long X = sc.nextLong();
		Long sum = 100L;
		for(int i = 1; i <= 3760; i++){
			sum = sum + sum / 100L;
			if(sum >= X){
				System.out.println(i);
				System.exit(0);
			}
		}
	}


	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {return br.readLine();}

		public boolean ready() throws IOException {return br.ready();}

		public double nextDouble(String x)
		{

			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}


	}
}

Measured memory_bytes: 32644
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <deque>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <sstream>
#include <type_traits>
#define SET(x,y) x |= (1 << y)
#define CLEAR(x,y) x &= ~(1<< y)
#define READ(x,y) ((0u == (x & (1<<y)))?0u:1u)
#define TOGGLE(x,y) (x ^= (1<<y))
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define si(n) scanf("%d",&n)
#define sf(n) scanf("%f",&n)
#define sl(n) scanf("%lld",&n)
#define slu(n) scanf("%llu",&n)
#define sd(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
#define pnl printf("\n")
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pF first
#define pS second
#define CL(a,b) memset(a,b,sizeof(a))
#define sqr(x) ((x)*(x))
#define intLIMIT numeric_limits<int>
#define longLIMIT numeric_limits<long long>
#define GCD(a,b) __gcd((a),(b))
#define dbl(x) (double)(x)
#define vi vector <int>
#define vii vector < pair <int, int> >
#define vll vector <long long>
#define allof(x) (x).begin(), (x).end()
#define fastCin cin.sync_with_stdio(0);cin.tie(0)
#define scanUnsigned(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#define printArr(a,l) cout<<#a<<": ";for(int i=0;i<(l);i++){cout<<a[i]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(int i=0;i<(r);i++){for(int j=0;j<(c);j++){cout<<a[i][j]<<" ";}cout<<endl;}
char _;
using namespace std;
void PRINT (int x, int y) { for (int i = y-1; i >= 0; i--) { cout << READ(x,i); } cout << endl; }

vector<string>vec_splitter(string s){s+=',';vector<string>res;while(!s.empty()){res.push_back(s.substr(0,s.find(',')));s=s.substr(s.find(',')+1);}
return res;}
void debug_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM){cerr<<endl;}
template<typename Head,typename...Tail>void debug_out(vector<string>args,int idx,int LINE_NUM,Head H,Tail...T){if(idx>0)cerr<<", ";else cerr<<"Line("<<LINE_NUM<<") ";stringstream ss;ss<<H;cerr<<args[idx]<<" = "<<ss.str();debug_out(args,idx+1,LINE_NUM,T...);}
#ifdef LOCAL_DBG
#define dbg(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define dbg(...) 42
#endif

int main () {
	fastCin;
	int X, Y;
	cin >> X >> Y;
	for (int x = 0; x <= X; x++) {
		if (2*x + (X-x)*4 == Y) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
int main(){
	int counter=0;
	string a;
	cin>>a;
    for(int i=0;i<6;i++){
		if(a.at(i)=='1'){
			counter=counter+1;
		}
	}
	cout<<counter<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,p;
long x[1<<17];
long S;
main()
{
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		long w,b;cin>>w>>b;
		S-=b*p;
		x[i]=w*(100-p)+b*p;
	}
	sort(x,x+n,greater<long>());
	for(int i=0;i<n;i++)
	{
		S+=x[i];
		if(S>=0)
		{
			cout<<i+1<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n*2);
    int i;
    for(i=0; i<n*2; i++) {
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());

    ll sum=0;
    for(i=0; i<n; i++) {
        sum+=MIN(a[2*i], a[2*i+1]);
    }
    printf("%lld\n", sum);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

vector<bool> m1, m2;
vector<bool> reached;
vector< vector<int> > G;
bool dp(int v) {
	bool res = false;
	if (m1[v]) return m2[v];
	if (reached[v]) res = true;
	else {
		reached[v] = true;
		EACH(to, G[v]) {
			res |= dp(to);
		}
		reached[v] = false;
	}
	return m1[v] = true, m2[v] = res;
}
bool check(const vector<string>& s) {
	map<char, int> tbl;
	for (char c = 'a'; c <= 'z'; ++c) tbl[c] = (int)(c-'a');
	int N = 26;
	G = vector< vector<int> >(N);
	REP(i, s.size()) FOR(j, i+1, s.size()) {
		if (s[i] == s[j]) continue;
		if (s[i].size() > s[j].size() && s[i].substr(0, s[j].size()) == s[j]) return false;
		REP(k, min(s[i].size(), s[j].size())) {
			if (s[i][k] != s[j][k]) {
				G[tbl[s[i][k]]].pb(tbl[s[j][k]]);
				break;
			}
		}
	}
	m1 = vector<bool>(N, false);
	m2 = vector<bool>(N, false);
	reached = vector<bool>(N, false);
	REP(i, N) if ( dp(i) ) return false;
	return true;
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N;
	while (cin >> N, N) {
		vector<string> s(N); cin >> s;
		vector<string> ss = s; reverse(ALL(ss));
		if ( check(s) ) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

Measured memory_bytes: 3948
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<int,int>
#define ti3 tuple<ll,ll,ll>

struct UnionFind {
    vector<int> data;
    
    UnionFind(int size) : data(size, -1) { }
    
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y)
        {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

int main()
{
    ll x;
    cin >> x;
    ll c = x / 11;
    ll m = x % 11;
    ll count = c * 2;
    if(m == 0)
    {
        cout << count << endl;
        return 0;
    }
    if(m <= 6)
    {
        cout << count + 1 << endl;
        return 0;
    }
    cout << count + 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int main()
{
	long long n,a=0,b=0,c=0,d=0;
	string s;
	cin >> n;
	for (long long i = 0; i < n; i++) {
		cin >> s;
		if (s == "AC")a++;
		else if (s == "WA")b++;
		else if (s == "TLE")c++;
		else if (s == "RE")d++;
	}
	cout << "AC" << " " << "x" << " " << a << endl;
	cout << "WA" << " " << "x" << " " << b << endl;
	cout << "TLE" << " " << "x" << " " << c << endl;
	cout << "RE" << " " << "x" << " " << d;
	return 0;
}

Measured memory_bytes: 3640
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int h = Integer.parseInt(sc.next());
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
		
		System.out.println(h <= Arrays.stream(a).sum() ? "Yes" : "No");
	}
}


Measured memory_bytes: 59228
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
#define MAX_N 25
const int MAX = 2000010;
const int MOD = 1e9+7;
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
int main() {
    
    int n; cin >> n;

    map<int,int> mp;int t;
    vector<int> a(n+1);
    int idx = -1;
    for(int i=0; i<n+1; i++){
        cin >> a[i];
        mp[a[i]]++;
        if(mp[a[i]] == 2){
            t = a[i];
        }
    }
    vector<long long> ans;
    COMinit();
    int l = -1, r = -1;
    for(int i=0; i<=n; i++){
        if(a[i] == t){
            if(l == -1){
                l = i;
            }else{
                r = i;
            }
        }
    }


    int mxlen = l + n+1-r;
    //cout << mxlen << endl;
    for(int i=0; i<=n; i++){
        int len2 = i+1;

        
        if(mxlen>=len2){
            ans.push_back((COM(n+1, i+1) - COM(mxlen-1, len2-1)+MOD)%MOD);
        }else{
            ans.push_back(COM(n+1, i+1));
        }

    }

    for(auto e: ans){
        cout << e << endl;
    }
    return 0;
}



Measured memory_bytes: 54132
n,y=map(int,input().split())
for i in range(n+1):
  for j in range(n-i+1):
    if n-i-j>=0 and 10000*i+5000*j+1000*(n-i-j)==y:
      print(i,j,n-i-j)
      exit()
print(-1,-1,-1)

Measured memory_bytes: 40684
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
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; }
 
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; }
 
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

char G[55][55];
int cost[55][55];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int h,w; cin>>h>>w;
  int wnum=0;
  rep(i,h) rep(j,w){
    cin>>G[i][j];
    if(G[i][j]=='.') wnum++;
  }
  memset(cost, -1, sizeof(cost));
  cost[0][0]=0;
  
  queue<pii> q;
  q.emplace(0,0);
  while(!q.empty()){
    int y=q.front().first;
    int x=q.front().second;
    q.pop();
    rep(i,4){
      int ny=dy[i]+y;
      int nx=dx[i]+x;
      if(inside(ny,nx,h,w)&&G[ny][nx]=='.'){
        if(cost[ny][nx]!=-1) continue;
        cost[ny][nx]=cost[y][x]+1;
        q.emplace(ny,nx);
      }
    }
  }
  
  int gcost=cost[h-1][w-1];
  if(gcost==-1) cout<<-1<<endl;
  else cout<<wnum-gcost-1<<endl;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pi> vpi;
typedef vector<bool> vbool;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define forall(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define F0(i,n) for(ll i = 0; i < n; i++)
#define F1(i,n) for(ll i = 1; i <= n; i++)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define per(i,a,b) for(int i = b-1; i >= a; i--)
#define FIN ios::sync_with_stdio(false);cin.tie(0);
#define db(x) cout<<#x<<" = "<<x<<"\n"
#define all(v) v.begin(),v.end()
#define modulo(a,b) ((a%b)+b)%b
#define F first
#define S second
#define INF 1000000010
#define eps 0.000000000001
#define mod 1000000007
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//=======================//
int n,W;
vector<vector<ll> > dp;
vi w,v;

int main () {
	//FIN
	cin >> n >> W;
	dp = vector<vector<ll> >(n, vector<ll>(W+1, 0));
	w = v = vi(n);
	F0(i,n) cin >> w[i] >> v[i];
	dp[0][0] = 0;
	dp[0][w[0]] = v[0];
	F0(i,n-1) F0(j,W+1) {
		dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
		if (j+w[i+1] <=  W) dp[i+1][j+w[i+1]] = max(dp[i+1][j+w[i+1]], dp[i][j] + v[i+1]);
	}
	ll res = 0;
	F0(i,W+1) {
		res = max(res, dp[n-1][i]);
	}
	cout << res << "\n";
	return 0;
}










Measured memory_bytes: 82328
#include <iostream>
#include <vector>
#include <string.h>
#include <climits>
#include <algorithm>
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;

int N;
int Ma, Mb;
int a[45], b[45], c[45];

int dp[45][410][410];

signed main()
{
	cin >> N >> Ma >> Mb;
	for (size_t i = 0; i < N; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}

	for (size_t i = 0; i < 45; i++)
	{
		for (size_t j = 0; j < 410; j++)
		{
			for (size_t k = 0; k < 410; k++)
			{
				dp[i][j][k] = INF;
			}
		}
	}

	dp[0][0][0] = 0;
	dp[0][a[0]][b[0]] = c[0];
	for (size_t i = 0; i < N - 1; i++)
	{
		for (size_t j = 0; j < 410; j++)
		{
			for (size_t k = 0; k < 410; k++)
			{
				if (dp[i][j][k] != INF) {
					dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
					dp[i + 1][j + a[i + 1]][k + b[i + 1]] = min(dp[i + 1][j + a[i + 1]][k + b[i + 1]], dp[i][j][k] + c[i + 1]);
				}
			}
		}
	}

	int ans = INF;
	for (size_t i = 0; i < 410; i++)
	{
		for (size_t j = 0; j < 410; j++)
		{
			if (i != 0 && j != 0 && j * Ma == i * Mb) {
				if (dp[N - 1][i][j] < ans) {
 					ans = dp[N - 1][i][j];
				}
			}
		}
	}

	cout << (ans == INF ? -1 : ans) << endl;
}

Measured memory_bytes: 59392
main = do
  x <- getLine

  let solve (c:ss) ns nst len | c == 'S' = solve ss (ns+1) nst (len+1)
                              | c == 'T' = if ns > 0
                                           then solve ss (ns-1) (nst+1) (len+1)
                                           else solve ss ns nst (len+1)
      solve [] _ nst len = len - 2 * nst

  print $ solve x 0 0 0

Measured memory_bytes: 9596
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
int V, E;
// ???????????????????????????????????????
const int MAX_V = 110;
struct edge {int to, cap, rev; }; // ???????????????????????????
vector<edge> G[MAX_V];
bool used[MAX_V];
// from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from, int to, int cap) {
  G[from].push_back((edge){to, cap, G[to].size()});
  G[to].push_back((edge){from, 0, G[from].size()-1});
}
// ?¢?????????????dfs??§??¢???
int dfs(int v, int t, int f) {
  if(v == t) return f;
  used[v] = true;
  FOR(i,0,G[v].size()) {
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s, int t) {
  int flow = 0;
  for(;;) {
    FOR(i,0,MAX_V) used[i] = 0;
    int f = dfs(s, t, 1e9);
    if(f == 0) return flow;
    flow += f;
  }
}

int main()
{
  cin >> V >> E;
  FOR(i,0,E) {
    int a,b,c;
    cin >> a >> b >> c;
    add_edge(a,b,c);
  }
  cout << max_flow(0,V-1) << endl;
  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    vector<ll> a(n);
    ll s = 0;
    rep(i,m) cin>>a[i], s+=a[i];
    if (n-s >= 0) cout << n-s << '\n';
    else cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 11172
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define debug(x) cout << "> x:" << x << endl;
#define len(x) int(x.size())
#define all(x) x.begin(), x.end()
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(){
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vi vs(n);
	for(int i=0; i<n; ++i) cin >> vs[i];
	int err=0;
	for(int i=0; i<n; ++i) if(vs[i]!=i+1) ++err;
	if(err==2 or err==0) cout << "YES\n";
	else cout << "NO\n";
}


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

#define F first
#define S second
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl

using namespace std;

typedef long long ll;
typedef double dbl;
const int INF = 1.01e9;



int main() {
#define TASK "A"
#ifdef HOME 
    assert(freopen(TASK".in", "r", stdin));
#endif
    int n;
    scanf("%d", &n);
    for (int tt = 0; tt < n; tt++) {
        ll a, b;
        cin >> a >> b;
        if (abs(a - b) <= 1) {
            cout << (min(a, b) - 1) * 2 << endl;
            continue;
        }
        if (a > b) swap(a, b);
        ll answer = a - 1;
        ll val = a * b;
        ll d = sqrt(val);
        //db2(answer, d);
        assert(a <= d);
        answer += (d - a);
        ll f = (val - 1) / d;
        f--;
        answer += f;
        cout << answer << endl;
    }





    return 0;
}



Measured memory_bytes: 256