akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,m;
char c[25][25];
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};
int vis[23][23];
int mx=0;
void bfs(int x,int y){
	queue<pair<pair<int,int>,int> > q;
	q.push(make_pair(make_pair(x,y),0));
	while(!q.empty()){
		pair<pair<int,int>,int> p;
		p=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int ax=p.first.first+dx[i];
			int ay=p.first.second+dy[i];
			if(ax==x&&ay==y)continue;
			if(ax>=0&&ax<n&&ay>=0&&ay<m&&c[ax][ay]=='.'&&!vis[ax][ay]){
				vis[ax][ay]=p.second+1;
				mx=max(mx,vis[ax][ay]);
				q.push(make_pair(make_pair(ax,ay),vis[ax][ay]));
			}
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>c[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(c[i][j]=='#')continue;
			bfs(i,j);
			memset(vis,0,sizeof(vis));
		}
	}
	cout<<mx<<endl;
	return 0;
}

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

int main() {
  vector<pair<int, int> > v;
  int p, s;
  while (scanf("%d,%d", &p, &s), p + s) {
    v.push_back(make_pair(s, p));
  }

  sort(v.begin(), v.end(), greater<pair<int, int> >());

  vector<int> rank(101, 1);
  int r = 1;
  for (int i = 1; i < v.size(); ++i) {
    if (v[i].first != v[i - 1].first) r++;
    rank[v[i].second] = r;
  }

  int q;
  while (cin >> q) {
    cout << rank[q] << endl;
  }
}

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

using namespace std;

int main() {

    int R; cin >> R;

    if (R < 1200) {
        cout << "ABC" << endl;
    } else if(R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


int calc(int a,int b){
  if(b == 0) return 1;
  if(b%2 == 0){
    int d = calc(a,b/2);
    return (d*d)%MOD;
  }
  return (a*calc(a,b-1))%MOD;
}

int comb(int n,int r){
  int tmp = 1,ttmp = 1;
  for(int i = n;i >= n-r+1;i--) tmp = (tmp*i)%MOD;
  for(int i = 1;i <= r;i++) ttmp = (ttmp*i)%MOD;
  return (tmp*calc(ttmp,MOD-2))%MOD;
}

int powMod(int n, int p) {
  int res = 1;
  while (p) {
    if (p & 1) (res *= n) %= MOD;
    (n *= n) %= MOD;
    p >>= 1;
  }
  return res;
}
int invMod(int n) {
  return powMod(n, MOD - 2);
}

signed main() {
  int N, A, B; 
  cin >> N >> A >> B;

  cout << ((powMod(2, N)-comb(N, A)-comb(N, B)-1)%MOD+MOD)%MOD << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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;
}
int main() {
    int N, K;
    cin >> N >> K;
    vi a(N);
    rep(i, 0, N) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    int res = 0;
    rep(i, 0, K) {
        res += a[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,m;
  cin >>n >> m;
  string s;
  cin >> s;
  int p = n;
  vi ans;
  while(p!=0){
    int np = -1,deme= -1;
    for(int j = m;j>=1;j--){
      deme=j;
      np = p-deme;
      //show(s[np]);
      if(np<0)continue;
      if(s[np] == '0'){
        //show(deme);
        ans.push_back(deme);
        j=0;
      }
    }
    if(s[np] == '1'){
      cout<<-1<<endl;
      return 0;
    }
    p=np;
    
  }
  reverse(ans.begin(),ans.end());
  for(auto e: ans){
    cout<< e << " ";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1144
//arc061_d.cpp
//Thu Jul  4 22:08:52 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll h,w,n;
	cin >> h >> w >> n;

	vector<P> pos;

	for (int i=0;i<n;i++){
		ll a,b;
		cin >> a >> b;
//		cout << a << " " << b << endl;
		for (int j=0;j<3;j++){
			for (int k=0;k<3;k++){
				if (a-j>0 && b-k>0 && a-j<=h-2 && b-k<=w-2){
					P temp = make_pair(a-j,b-k);
					pos.push_back(temp);
//					cout << " " << a-j << " " << b-k << endl;
				}
			}
		}
	}

	sort(pos.begin(),pos.end());

	ll ans[9];
	fill(ans,ans+9,0);
	ll prevfirst = -1;
	ll prevsecond = -1;
	ll plus = 0;
	int count = 0;
	for (int i=0;i<pos.size();i++){
//		cout << " " << pos[i].first << " " << pos[i].second << endl;
		if (pos[i].first == prevfirst &&
			pos[i].second == prevsecond){
			count++;
		}else {
			plus++;
			if (count > 0){
				ans[count-1]++;
			}
			count = 1;
		}
		prevfirst = pos[i].first;
		prevsecond = pos[i].second;
	}
	if (count>0){
		ans[count-1]++;
	}

	ll anszero = (h-2)*(w-2)-plus;
	cout << anszero << endl;

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

Measured memory_bytes: 9836
#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(){
  int x,y,z;
  int tmp;
  cin >> x >> y >> z;
  tmp = x;
  x = y;
  y = tmp;
  tmp = z;
  z = x;
  x = tmp;
  cout << x << " " << y << " " << z <<endl;
}


Measured memory_bytes: 256
<?php

$map = array(
	'a' => 0,
	'b' => 1,
	'c' => 2,
	'd' => 3,
	'e' => 4,
	'f' => 5,
	'g' => 6,
	'h' => 7,
	'i' => 8,
	'j' => 9,
	'k' =>10,
	'l' =>11,
	'm' =>12,
	'n' =>13,
	'o' =>14,
	'p' =>15,
	'q' =>16,
	'r' =>17,
	's' =>18,
	't' =>19,
	'u' =>20,
	'v' =>21,
	'w' =>22,
	'x' =>23,
	'y' =>24,
	'z' =>25,
);

$rev_map = array_flip($map);

$n = trim(fgets(STDIN));

for ($i = 0; $i < $n; $i++) {
	$line = trim(fgets(STDIN));
	echo solve($line) . "\n";
}


function solve($line) {
	$words = explode(' ', $line);
	foreach ($words as $w) {
		if (strlen($w) != 4) {
			continue;
		}
		for ($a = 1; $a < 26; $a++) {
			for ($b = 0; $b < 26; $b++) {
				if (encrypt($a, $b, 'that') == $w || encrypt($a, $b, 'this') == $w) {
					return decrypt($a, $b, $line);
				}
			}
		}
	}
}

function decrypt($a, $b, $line) {
	$decrypt_map = generate_decrypt_map($a, $b);
	$dec = '';
	for ($i = 0; $i < strlen($line); $i++) {
		$char = $line[$i];
		if (preg_match('/[a-z]/', $char)) {
			$dec .= $decrypt_map[$char];
		} else {
			$dec .= $char;
		}
	}
	return $dec;
}

function generate_decrypt_map($a, $b) {
	global $map;
	$result = array();
	foreach ($map as $k => $c) {
		$result[$k] = encrypt_char($a, $b, $k);
	}
	return array_flip($result);
}


function encrypt($a, $b, $w) {
	$result = '';
	for($i = 0; $i < strlen($w); $i++) {
		$result .= encrypt_char($a, $b, $w[$i]);
	}
	return $result;
}

function encrypt_char($a, $b, $char) {
	global $map, $rev_map;
	$g = $map[$char];
	$enc = ($a * $g + $b) % 26;
	return $rev_map[$enc];
}

Measured memory_bytes: 6792
#include <stdio.h>

int main(void){
    char Input;
    char Talone;
    int Tal;
    while(1){
        Talone = ' ';
        Tal =0;
        while (1) {
            scanf("%c",&Input);
            if(Input == '\n'){
                break;
            }
            Talone += Input - '0';
            if(Talone >= '*'){
                Tal+=10;
                Talone = Talone - 10;
            }
        }
        Talone = Talone + 16;
        if(Tal == 0 && Talone == '0'){
            break;
        }else{
            if(Tal/10==0){
                printf("%c\n",Talone);
            }else{
                printf("%d%c\n",Tal/10,Talone);
            }
        }
    }
}


Measured memory_bytes: 2036
N = int(input())
X = list(map(int,input().split()))

X.sort()
dist = float("inf")
for i in range(X[0],X[-1]+1):
  d = 0
  for j in range(N):
    d += (i - X[j]) ** 2
  dist = min(dist,d)
  
print(dist)

Measured memory_bytes: 9092
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

            @SuppressWarnings("unchecked")
            List<Edge>[] edges = new List[N];
            for (int i = 0; i < N; i++) {
                edges[i] = new ArrayList<>();
            }

            for (int i = 0; i < N - 1; i++) {
                int a = sc.nextInt() - 1;
                int b = sc.nextInt() - 1;

                edges[a].add(new Edge(i, b));
                edges[b].add(new Edge(i, a));
            }

            int[] colors = new int[N - 1];
            dfs(0, -1, -1, colors, edges);

            int K = Arrays.stream(colors).max().getAsInt();

            StringBuilder ans = new StringBuilder();
            ans.append(K).append("\n");
            for (int c : colors) {
                ans.append(c).append("\n");
            }

            System.out.print(ans.toString());
        }
    }

    public static void dfs(int v, int pv, int pc, int[] colors, List<Edge>[] edges) {
        int c = 1;
        for (Edge e : edges[v]) {
            if (e.to == pv) {
                continue;
            }

            if (c == pc) {
                c++;
            }

            colors[e.index] = c;

            dfs(e.to, v, c, colors, edges);

            c++;
        }
    }

    public static class Edge {

        int index;

        int to;

        public Edge(int index, int to) {
            this.index = index;
            this.to = to;
        }

    }

}


Measured memory_bytes: 106132
#C
import math

def gcd_great(l,m,n):
    p=math.gcd(l,m)
    q=math.gcd(p,n)
    return q

k=int(input())

#(n,n,m)のパターン
gcd_sum=0
for i in range(1,k+1):
    for j in range(1,k+1):
        if i!=j:
            g=math.gcd(i,j)
            gcd_sum=gcd_sum+g*3

#(l,m,n)のパターン
for a in range(1,k-1):
    for b in range(a+1,k):
            for c in range(b+1,k+1):
                gcd_sum+=gcd_great(a,b,c)*6
gcd_sum+=int((k+1)*k*(1/2))
#(n,n,n)のパターン
print(gcd_sum)

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n;
    cin >> n;
    int x[n],y[n];
    for(int i=0;i<n;i++){
        cin >> x[i]>>y[i];
    }
    double t =0.000001;
    double r[n];
    double rmax;
    int p[n]={};
    int maxi;
    for(double th=0;th < 2*M_PI;th+=t){
         rmax= -2000000;
        for(int i=0;i<n;i++){
            r[i]=x[i]*cos(th) + y[i]*sin(th);
            if(rmax<r[i]){
                rmax=r[i];
                maxi=i;
            }
        }
        p[maxi]++;
    }
    double w=0;
    for(int i=0;i<n;i++)w+=p[i];
    for(int i=0;i<n;i++)cout <<double(p[i])/w<<endl;;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int N;
	cin >> N;

	int max_len = 0;
	int total = 0;
	for (int i = 0; i < N; i++) {
		int l;
		cin >> l;
		max_len = max(max_len, l);
		total = total + l;
	}

	if ((total - max_len) > max_len) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

/////////////////////////////////////////////////////

ll N;
char S[40];

ll i, j, k;

int main(){
    scanf("%lld%lld%lld", &i, &j, &k);
    if(j*k>=i){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    vector<ll> a(3);
    ll k;
    cin>>a[0]>>a[1]>>a[2]>>k;
    sort(a.begin(), a.end());
    ll sum=a[0]+a[1]+a[2]*pow(2,k);
    cout<<sum<<endl;
}

Measured memory_bytes: 256
// PrintTestCases.c
// オンラインジャッジでは、提出されたプログラムが複数の入力データそれぞれに対して
// 正しい出力を行っているかを判定するために、１つの入力データファイルに
// 複数のデータセットが含まれているものがあります。
// この問題は、そのようなデータセットを処理するための練習問題です。
// 
// １つの整数 x を読み込み、それをそのまま出力するプログラムを作成して下さい。
// ただし、この問題は以下に示すようにいくつかのデータセットが与えられることに注意して下さい。
// 【入力】
// 入力は複数のデータセットから構成されています。
// 各データセットは１つの整数 x を含む１行から構成されています。
// x が 0 のとき入力の終わりを示し、このデータセットに対する出力を行ってはいけません。
// 【出力】
// 各データセットごとに、以下の形式で x を出力して下さい：
// Case i: x
// ここで、i は１から始まるデータセットの番号を示します。
// Caseと番号 iの間に１つの空白を入れて下さい。
// また、:（コロン）と整数 x の間に１つの空白を入れて下さい。
// サンプル入出力を参考にして下さい。
// 【制約】
// ・1 ≤ x ≤ 10,000
// ・データセットの数は 10,000 を超えない。
// 【例】
// 入力：
// 3
// 5
// 11
// 7
// 8
// 19
// 0
// 出力：
// Case 1: 3
// Case 2: 5
// Case 3: 11
// Case 4: 7
// Case 5: 8
// Case 6: 19
#include<stdio.h>

int main( void) {
  int i = 1, x;

  while ( 1) {
    scanf( "%d", &x);

    if ( x == 0) break;

    printf( "Case %d: %d\n", i++, x);
  }

  return 0;
}



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

int main(){
  int x;
  cin >> x;
  int i = 0, ans = 0;
  while(1){
    i += x;
    i %= 360;
    ++ans;
    if(i == 0) break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    if (n%2!=0) {
        puts("No");
        return 0;
    } else {
        string tmp1 = "";
        string tmp2 = "";
        rep(i, n) {
            if (i<=n/2-1) tmp1 += s[i];
            else tmp2 += s[i];
        }
        if (tmp1 == tmp2) {
            puts("Yes");
            return 0;
        }
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
from math import factorial as f
n, blue = map(int, input().split())
red = n - blue
mod = 10 ** 9 + 7


def p(n, r):
    return f(n) // f(n-r)


def c(n, r):
    return p(n, r) // f(r)


for i in range(1, blue + 1):
    if red < i - 1:
        print(0)
    else:
        space = c(red + 1, i)
        pattern = c(blue - 1, blue - i)
        print(space * pattern % mod)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
vector<pii>x,y;
int X,Y,n,boss[100005],ans,a,b,c;
priority_queue<pair<int,pii> >pq;
int F(int N)
{
    if(N==boss[N])return boss[N];
    else return boss[N]=F(boss[N]);
}
void un(int x,int y)
{
    boss[F(x)]=F(y);
    return;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        boss[i]=i;
        scanf("%d %d",&X,&Y);
        x.pb({X,i});
        y.pb({Y,i});
    }
    sort(all(x));
    sort(all(y));
    for(int i=1;i<n;i++)
    {
        pq.push({-abs(x[i].F-x[i-1].F),{x[i].S,x[i-1].S}});
        pq.push({-abs(y[i].F-y[i-1].F),{y[i].S,y[i-1].S}});
    }
    while(!pq.empty())
    {
        c=-pq.top().F;
        a=pq.top().S.F;
        b=pq.top().S.S;
        pq.pop();
        //printf("{%d %d %d}\n",a,b,c);
        if(F(a)!=F(b))
        {
            //printf("{%d %d %d}\n",a,b,c);
            un(a,b);
            ans+=c;
        }
    }
    printf("%d",ans);
}


Measured memory_bytes: 10916
N = int(input())
ans = []
b = list(map(int,input().split()))
while b:
    i = len(b)-1
    while b[i] != i+1 and i >= 1:
        i -= 1
    if b[i] == i+1:
        ans.append(b.pop(i))
    else:
        break
if b:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)

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

int main(){
  int K;
  cin >> K;
  
  int ans = 0;
  for(int i = 1; i <= K; i++){
    for(int j = 1; j <= K; j++){
      for(int k = 1; k <= K; k++){
        int m = min(i, min(j, k));
        while(true){
          if(i % m == 0 && j % m == 0 && k % m == 0){
            ans += m;
            break;
          }
          m--;
        }
      }
    }
  }
  
  cout << ans << endl;
}


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

int main() {
	int N; cin >> N;

	vector<set<int>> vset(N, set<int>());
	vector<int> vec(N);

	for (int i = 0; i < N - 1; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		vset[a].insert(b);
		vset[b].insert(a);
	}

	int start;
	{
		vector<int> vec(N, -1);
		deque<int> dq;
		dq.push_back(0);
		vec[0] = 0;

		while (dq.size() > 0) {
			int now = dq.front();
			for (int next : vset[now]) {
				if (vec[next] == -1) {
					vec[next] = vec[now] + 1;
					start = next;
					dq.push_back(next);
				}
			}
			
			dq.pop_front();
		}
	}

	int dim = 0;
	{
		vector<int> vec(N, -1);
		deque<int> dq;
		dq.push_back(start);
		vec[start] = 0;

		while (dq.size() > 0) {
			int now = dq.front();
			for (int next : vset[now]) {
				if (vec[next] == -1) {
					vec[next] = vec[now] + 1;
					dim = vec[next];
					dq.push_back(next);
				}
			}
			dq.pop_front();
		}
	}

	if ((dim + 1) % 3 == 2) cout << "Second" << endl;
	else cout << "First" << endl;
}

Measured memory_bytes: 30772
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

template<typename T>
T gcd(T x, T y)
{
	if (x > y)
	{
		swap(x, y);
	}
	return x ? gcd(x, y % x) : y;
}

template<typename T>
T lcm(vector<T> a)
{
	vector<int> b;
	for (int i = 1; i <= a.size(); i += 2)
	{
		if (i == a.size())
		{
			b.push_back(a.at(i - 1));
		}
		else
		{
			T g = gcd(a.at(i - 1), a.at(i));
			b.push_back((a.at(i - 1) / g) * a.at(i));
		}
	}

	return  (b.size() == 1) ? b.at(0) : lcm(b);
}

int main()
{
	int n;
	
	vector<int> a;
	for (cin >> n; n--; )
	{
		int x;
		cin >> x;

		a.push_back(x);
	}
	
	cout << lcm(a) << endl;
}


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

int main() {
	int a, b, c, num;

	cin >> num;

	int* bat = new int[ num * 3 ];

	for( int i = 0; i < num; ++i ) {
		cin >> bat[ i*3 + 0 ] >> bat[ i*3 + 1 ] >> bat[ i*3 + 2 ];
	}

	for( int i = 0; i < num; ++i ) {
		a = bat[ i*3 + 0 ];
		b = bat[ i*3 + 1 ];
		c = bat[ i*3 + 2 ];
		if ( a < b ) {
			int t = a;
			a = b;
			b = t;
		}
		if ( a < c ) {
			int t = a;
			a = c;
			c = t;
		}
		
		if ( !( a*a - ( b*b + c*c ) ) ) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}

	delete[] bat;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	map<int, int> mp;
	rep(i,n){
		int a;
		cin >> a;
		++mp[a];
	}
	int ans = 0;
	for(auto p : mp){
		if(p.second%2 == 1) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8152
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let a: usize = read().unwrap();
    let b: usize = read().unwrap();
    let c: usize = read().unwrap();

    if (a == b) | (a == c) | (b == c) {
        if (a == b) & (b == c) {
            println!("No");
        } else {
            println!("Yes");
        }
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
aaa = na()
bbb = na()
ccc = na()
ans = 0
pr = -100
for i in range(n):
    a = aaa[i] - 1
    ans += bbb[a]
    if a == pr + 1:
        ans += ccc[pr]
    pr = a

print(ans)

Measured memory_bytes: 3064
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]
n = rri()
if 400<=n<=599:
    print(8)
if 600<=n<=799:
    print(7)
if 800<=n<=999:
    print(6)
if 1000<=n<=1199:
    print(5)
if 1200<=n<=1399:
    print(4)
if 1400<= n<=1599:
    print(3)
if 1600<=n<=1799:
    print(2)
if 1800<=n<=1999:
    print(1)

Measured memory_bytes: 64824
I=lambda:map(int,input().split())
n,m,c=I()
b=list(I())
A=[list(I()) for _ in[0]*n]
e=0
for a in A:
  d=0
  for i,j in zip(b,a):
    d+=i*j
  e+=(d+c>0)
print(e)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;

int main(){
  ll n; cin >> n;
  vector<ll> v(n);
  rep(i,n){
    cin >> v[i];
  }
  ll ans=0;
  ll cnt=0;
  for(ll i=0; i<n-1; i++){
    ll cu = v[i], ne = v[i+1];
    if(cu >= ne){
      cnt++;
    }else{
      ans=max(cnt,ans);
      cnt=0;
    }
  }
  ans=max(cnt,ans);
  cout << ans;
  return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

const int MAX_N=2999;
int N;
double dp[MAX_N+1][MAX_N+1];
double p[MAX_N];

void solve(){
    double ans=0;
    dp[1][1]=p[0];dp[1][0]=1-p[0];
    for(int i=2;i<=N;i++){
        for(int j=0;j<=i;j++){
            if(j>=1) dp[i][j]=dp[i-1][j]*(1-p[i-1])+dp[i-1][j-1]*p[i-1];
            else dp[i][j]=dp[i-1][j]*(1-p[i-1]);
        }
    }
    for(int i=0;i<=N;i++){
        if(i>N-i) ans+=dp[N][i];
    }
    printf("%.10f\n",ans);
}


int main(){
    cin>>N;
    rep(i,N) cin>>p[i];
    solve();
}

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

// 解説より、8方向分の添字は差分のリストを作ると楽

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> field(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> field[i][j];
    }
  }
  
  const vector<int> dx = {1, 0, -1, 0, 1, -1, -1, 1};
  const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1};
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == '#') continue;

      int count = 0;
      for (int d = 0; d < 8; d++) {
        const int ni = i + dy.at(d);
        const int nj = j + dx.at(d);
        
        if (ni < 0 or H <= ni) continue;
        if (nj < 0 or W <= nj) continue;
        if (field[ni][nj] == '#') count++;
      }
      
      field[i][j] = '0' + count;
    }
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << field[i][j];
      if (j == W - 1) cout << endl;
    }
  }
}

Measured memory_bytes: 3572
infa = 10**10
n = int(input())
a = list(map(int,input().split()))

for k in range(infa):
    mina = min(a)

    for i in range(len(a)):
       
        if a[i] == mina:
            a[i] = mina
        else:
            a[i] = a[i] % mina
    
    a = [j for j in a if not j == 0]

    if len(a) == a.count(mina):
        break

print(mina)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  if(A%2==0 || B%2==0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}
      
  

Measured memory_bytes: 256
S= input()
Q = int(input())
rev_cnt = 0

a = "0"
a_rev_cnt = 0
b = "0"
b_rev_cnt = 0

for _ in range(Q):
    query = input()
    if query[0]=="1":
        t = 1
        rev_cnt  = -1*rev_cnt+1
        a,b = b,a

    else:
        t,f,c = query.split()
        if f=="1":
            if rev_cnt ==0:
                a = c+a
            else:
                a = a+c

        elif f=="2":
            if rev_cnt ==0:
                b = b+c
            else:
                b = c+b
if a[0]=="0":
    a = a[::-1]
a = a[:-1]
if b[-1]=="0":
    b = b[::-1]
b = b[1:]


if rev_cnt%2==0:
    ans = a+S+b
else:
    ans = a+S[::-1]+b
print(ans)

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    string s,t;
    cin>>s>>t;
    int n=s.length();
    int res =0;
    for (int i=0; i<n; i++) {
	res+=s[i]!=t[i];
    }
    out(res);
    
    return 0;
}


Measured memory_bytes: 4176
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a;
    lli d, t, s;
    cin >> d >> t >> s;
    lli reqd = t * s;
    if (reqd >= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

Measured memory_bytes: 3640
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
int n, a[200], ans;
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+1+n);
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			for (int k=j+1;k<=n;k++)
				ans+=(a[i]+a[j])>a[k] && a[i]!=a[j] && a[j]!=a[k];
	cout<<ans<<endl;
    return 0;
}

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

struct X{
    int zero;
    int one;
};

const int INF=1e9;
X or_expr(int &p,string& s);
X and_expr(int &p,string& s);
X term(int &p,string& s);

X term(int& p,string& s){
    if(s[p]=='('){
        p++;
        X ret=or_expr(p,s);
        assert(s[p++]==')');
        return ret;
    }
    else{
        assert(s[p]=='?');
        p++;
        return X{1,1};
    }
}
X and_expr(int &p,string& s){
    vector<X> vec;
    while(p<s.size() && s[p]!=')' && s[p]!='|'){
        vec.push_back(term(p,s));
        if(s[p]=='&') p++;
    }
    int zero=INF;
    int sum=0;
    for(int i=0;i<vec.size();i++){
        zero=min(zero,sum+vec[i].zero);
        sum+=vec[i].one;
    }
    int one=0;
    for(int i=0;i<vec.size();i++){
        one+=vec[i].one;
    }
    return X{zero,one};
}

X or_expr(int &p,string& s){
    vector<X> vec;
    while(p<s.size() && s[p]!=')'){
        vec.push_back(and_expr(p,s));
        if(s[p]=='|') p++;
    }
    int one=INF;
    int sum=0;
    for(int i=0;i<vec.size();i++){
        one=min(one,sum+vec[i].one);
        sum+=vec[i].zero;
    }
    int zero=0;
    for(int i=0;i<vec.size();i++){
        zero+=vec[i].zero;
    }
    return X{zero,one};
}
int main(){
    string s;
    cin>>s;
    int p=0;
    auto ret=or_expr(p,s);
    cout<<ret.zero<<" "<<ret.one<<endl;
    return 0;
}


Measured memory_bytes: 3336
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <iomanip>
using namespace std;

typedef long long ll;

#define INF 10e17
#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>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  double d;
  cin >> d;
  cout << fixed;
  cout << setprecision(12);

  double d2 = d * d;
  double ans = d * sqrt(2);

  for (int x = 1; x <= 10; ++x) {
    if (d * d - x * x >= 0) {
      double y = sqrt(max(0.0, d * d - x * x));
      ans = max(ans, x + (y < 1.0 ? 1.0 : y));
    }
  }

  cout << ans << endl;
}



Measured memory_bytes: 3260
N, M = map(int, input().split())

PY = []
cnt = [0]*N

for i in range(M):
    p, y = map(int, input().split())
    PY.append([i, p, y])
    cnt[p-1] += 1
    
PY = sorted(PY, key=lambda x: x[1])

ans = []

for i in range(N):
    temp_shi = []
    for j in range(cnt[i]):
        temp_shi.append(PY[len(ans)+len(temp_shi)])
    
    temp_shi = sorted(temp_shi, key=lambda x: x[2])
    
    for j in range(cnt[i]):
        ans.append([temp_shi[j][0], str(i+1).zfill(6) + str(j+1).zfill(6)])

ans = sorted(ans, key=lambda x: x[0])

for i in range(M):
    print(ans[i][1])

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

using namespace std;
int main() {
  int d, n;
  cin >> d >> n;
  vector<int> v;

  int base = 0;
  int inc = 0;
  switch (d) {
    case 0:
      base = 1;
      inc = 1;
      break;
    case 1:
      base = 100;
      inc = 100;
      break;
    case 2:
      base = 10000;
      inc = 10000;
      break;
  }

  for (int i = 0; i < 101; i++) {
    int work = base + inc * i;
    if (d == 0 && work % 100 == 0) continue;
    if (d == 1 && work % 10000 == 0) continue;
    if (d == 2 && work % 1000000 == 0) continue;
    v.push_back(base + inc * i);
  }

  cout << v.at(n - 1) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll a,b,q;cin >> a >> b >> q;
    vector<ll> s(a);//神社
    rep(i,a) cin >> s[i];
    vector<ll> t(b);//寺
    rep(i,b) cin >> t[i];
    vector<ll> x(q);
    rep(i,q) cin >> x[i];
    vector<ll> near_temple(a);
    rep(i,a){
        auto itr = upper_bound(t.begin(), t.end(),s[i]);
        if(itr == t.begin())near_temple[i] = abs(*itr - s[i]);
        else if(itr == t.end()){
            itr--;near_temple[i] = abs(*itr - s[i]);
        }
        else{
            ll temp = *itr;itr--;
            ll temp2 = *itr;
            assert(temp2 <= s[i] && s[i] <= temp);
            near_temple[i] = min(abs(s[i] - temp2), abs(s[i] - temp));
        }
    }
    vector<ll> near_shrine(b);
    rep(i,b){
        auto itr = upper_bound(s.begin(), s.end(),t[i]);
        if(itr == s.begin())near_shrine[i] = abs(*itr - t[i]);
        else if(itr == s.end()){
            itr--;near_shrine[i] = abs(*itr - t[i]);
        }
        else{
            ll temp = *itr;itr--;
            ll temp2 = *itr;
            assert(temp2 <= t[i] && t[i] <= temp);
            near_shrine[i] = min(abs(t[i] - temp2), abs(t[i] - temp));
        }
    }

    rep(i,q){
        auto itr_sh = upper_bound(s.begin(), s.end(), x[i]);
        auto itr_te = upper_bound(t.begin(), t.end(), x[i]); 
        ll temp_s1, temp_s2, temp_t1, temp_t2;
        ll sh1,sh2,te1,te2;
        if(itr_sh == s.begin()){
            sh1 = itr_sh - s.begin();
            temp_s1 = abs(s[sh1] - x[i]) + near_temple[sh1];
            temp_s2 = LONG_MAX;
        }
        else if(itr_sh == s.end()){
            sh1 = itr_sh - s.begin() - 1;
            temp_s1 = abs(s[sh1] - x[i]) + near_temple[sh1];
            temp_s2 = LONG_MAX;
        }
        else{
            sh1 = itr_sh - s.begin();
            sh2 = sh1 - 1;
            temp_s1 = abs(s[sh1] - x[i]) + near_temple[sh1];
            temp_s2 = abs(s[sh2] - x[i]) + near_temple[sh2];
        }

        if(itr_te == t.begin()){
            te1 = itr_te - t.begin();
            temp_t1 = abs(t[te1] - x[i]) + near_shrine[te1];
            temp_t2 = LONG_MAX;
        }
        else if(itr_te == t.end()){
            te1 = itr_te - t.begin() - 1;
            temp_t1 = abs(t[te1] - x[i]) + near_shrine[te1];
            temp_t2 = LONG_MAX;
        }
        else{
            te1 = itr_te - t.begin();
            te2 = te1 - 1;
            temp_t1 = abs(t[te1] - x[i]) + near_shrine[te1];
            temp_t2 = abs(t[te2] - x[i]) + near_shrine[te2];
        }

        ll ans = min(min(temp_s1, temp_s2), min(temp_t1, temp_t2));
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 5248
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] s = scanner.next().toCharArray();
        scanner.close();

        int count = 0;
        for (char c : s) {
            if (c == '1') count++;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define PI 3.14159265358979l
int main() {
    int n;
    cin >> n;
    vector<int> h(n + 1);
    for (int i = 1; i <= n; i++)cin >> h[i];
    int dp[100000];
    dp[2] = abs(h[2] - h[1]);
    dp[1] = 0;
    for (int i = 3; i <= n; i++) {
        int a = abs(h[i] - h[i - 2]);
        int b = abs(h[i] - h[i - 1]);
        dp[i] = min(dp[i - 2] + a, dp[i - 1] + b);
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1024
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

/* ford fulkerson algorithm (verified in AOJ/GRL_6_A) */
const int INF = 1LL << 29;
struct edge {
    int to, cap, rev;
    edge(int to, int cap, int rev): to(to), cap(cap), rev(rev) {}
};

struct ford_fulkerson {
    int N;  vector<vector<edge>> graph;  vector<char> visited;

    ford_fulkerson() {}
    ford_fulkerson(int _N) { init(_N); }

    void init(int _N) {
        N = _N; graph.resize(N); visited.resize(N);
    }

    void add_edge(int u, int v, int cap) {
        graph[u].push_back(edge(v, cap, graph[v].size()));
        graph[v].push_back(edge(u, 0, (int)graph[u].size()-1));
    }

    int max_flow(int s, int t) {
        int flow = 0;
        for (;;) {
            fill(visited.begin(), visited.end(), 0);
            int acc = dfs(s, t, INF);
            if (acc == 0) break;
            flow += acc;
        }
        return flow;
    }

    int dfs(int v, int t, int f) {
        if (v == t) return f;
        visited[v] = 1;
        for (int i = 0; i < graph[v].size(); ++i) {
            edge& e = graph[v][i];
            if (!visited[e.to] && e.cap > 0) {
                int ff = dfs(e.to, t, min(f, e.cap));
                if (ff > 0) {
                    e.cap -= ff;
                    graph[e.to][e.rev].cap += ff;
                    return ff;
                }
            }
        }
        return 0;
    }
};

int N, M, S, T;

int G[205][205], H[205][205];
int C[205][205];

int main() {
    cin >> N >> M >> S >> T;
    --S; --T;

    ford_fulkerson ff(N);

    for (int j = 0; j < N; ++j) {
        for (int k = 0; k < N; ++k) {
            H[j][k] = G[j][k] = INF;
        }
        H[j][j] = G[j][j] = 0;
    }

    for (int j = 0; j < M; ++j) {
        int u, v, d, c;
        cin >> u >> v >> d >> c;
        --u; --v;
        H[u][v] = G[u][v] = d;  C[u][v] = c;
    }

    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }


    int visited[101010];
    fill(visited, visited+N, false);

    queue<int> que;
    que.push(T); visited[T] = 1;

    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (int j = 0; j < N; ++j) {
            if (j == v) continue;
            if (G[S][j] + H[j][v] == G[S][v]) {
                ff.add_edge(j, v, C[j][v]);
                if (!visited[j]) {
                    visited[j] = true;
                    que.push(j);
                }
            }
        }
    }

    cout << ff.max_flow(S, T) << endl;

    return 0;
}



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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
    for (int i = 0; i < H; i++){
      cin >> a.at(i);
    }
  
  for (int i = 0; i < W+2; i++){
    cout << "#";
  }
  cout << endl;
  
  for (int i = 0; i < H; i++){
    cout << "#" << a.at(i) << "#" << endl;
  }
  
    for (int i = 0; i < W+2; i++){
    cout << "#";
  }
  cout << endl;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc054/tasks/abc054_b
# これも緑diffのB問題
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


from itertools import product
N, M = read_ints()
A = []
for a in read_map(N):
    for aa in a:
        A.append(1 if aa == '#' else 0)
B = []
for b in read_map(M):
    for bb in b:
        B.append(1 if bb == '#' else 0)


# 面倒なのでnumpy芸していっすか？
import numpy as np
A = np.array(A).reshape((N, N))
B = np.array(B).reshape((M, M))

for i, j in product(range(N - M + 1), range(N - M + 1)):
    ii, jj = i + M, j + M
    A_sub = A[i:ii, j:jj]
    if np.logical_xor(A_sub, B).sum() == 0:
        print('Yes')
        exit()

print('No')


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

int main() {
	int n, m, x, a[110], left = 0, right = 0;
	cin >> n >> m >> x;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		if (a[i] < x) left++;
		else right++;
	}
	cout << min(left, right) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main() {
    ll S; cin >> S;
    ll L = 1000000000;
    ll high = 1000000000;
    ll low = 0;
    ll mid;
    while(high-low>1) {
        mid = (high+low) / 2;
        if(mid*L>=S) high = mid;
        else low = mid;
    }
    ll H = high;
    ll x = L - S + (H-1) * L;
    cout << "0 0 " << L << " " << 1 << " " << x << " " << H << endl;
    /*
    cout << abs(L*H-x) << endl;
    */ 
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    vector<int64> c(100000001, 0);
    for (int i=1; i<=10000000; i++) {
        for (int j=i; j<=10000000; j+=i)  c[j]++;
    }

    int64 ans = 0;
    for (int64 i=1; i<=n; i++) {
        ans += i * c[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 784068
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a%500<=b){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
using System;
 
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[,,] h = new int[4,3,10];
 
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Split(' ');
            int b = int.Parse(s[0]);
            int f = int.Parse(s[1]);
            int r = int.Parse(s[2]);
            int v = int.Parse(s[3]);
            h[b - 1, f - 1, r - 1] += v;
        }
 
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    Console.Write(" {0}", h[i, j, k]);
                }
                Console.Write("\n");
            }
            if(i < 3) Console.WriteLine("####################");
        }
    }
}

Measured memory_bytes: 15848
#include <stdio.h>
int n, q;
char s[200005];
char t[200005];
char d[200005];
int lx, rx, ly, ry, e;
int check(int a) {
	for (int i = 0; i < q; i++) {
		if (s[a] == t[i]) {
			if (d[i] == 'L')a--;
			if (d[i] == 'R')a++;
		}
		if (a == -1)return -1;
		if (a == n)return n;
	}
	return a;
}
int main() {
	scanf("%d%d", &n, &q);
	scanf("%s", s);
	for (int i = 0; i < q; i++) {
		scanf(" %c %c", &t[i], &d[i]);
	}
	if (check(n - 1) == -1) {
		printf("0\n");
		return 0;
	}
	if (check(0) == n) {
		printf("0\n");
		return 0;
	}
	lx = -1;
	rx = n - 1;
	while (rx - lx > 1) {
		e = (rx + lx) / 2;
		if (check(e) == -1) {
			lx = e;
		}
		else {
			rx = e;
		}
	}
	ly = 0;
	ry = n;
	while (ry - ly > 1) {
		e = (ry + ly) / 2;
		if (check(e) == n) {
			ry = e;
		}
		else {
			ly = e;
		}
	}
	printf("%d\n", ly - rx + 1);
}

Measured memory_bytes: 768
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, K: int, h: "List[int]"):
    DP = [INF]*N
    DP[0] = 0
    for i in range(1, N):
        for j in range(1, K+1):
            if i-j >= 0:
                DP[i] = min(DP[i], DP[i-j]+abs(h[i]-h[i-j]))
    print(DP[N-1])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)


if __name__ == '__main__':
    main()


Measured memory_bytes: 55716