akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll factorial(ll n){
    ll res=1;
    while(n--){
    if(n==0){
        return res;
    }
     res*=(n+1);
     res%=mod;
    }
    return 0;
}
int main(){
 ll n,m;
 cin>>n>>m;
 if(abs(n-m)>1){
     cout<<0<<endl;
     return 0;
 }
 ll ans=factorial(n)*factorial(m)%mod;
 if(n==m)ans=ans*2%mod;
 cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n, m;
  cin >> n >> m;
  
  vector<ll> h(n);
  for (int i = 0; i < n; i++){
    cin >> h[i];
  }
  vector<vector<ll>> edge(n, vector<ll>(0));
  for (int i = 0; i < m; i++){
    ll a, b;
    cin >> a >> b;
    
    a--; b--;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
  }

  ll ans = 0;
  for (int i = 0; i < n; i++){
    int ok = 1;
    for (int j = 0; j < edge[i].size(); j++){
      if (h[i] <= h[edge[i][j]])
        ok = 0;
    }
    ans += ok;
  }
  cout << ans << endl;
  
  
  

  return 0;
}


Measured memory_bytes: 9784
#include<stdio.h>
int main(){
  long a[200000],cnt=0;
  long i,n;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
  }
  if(a[n-1]>n-1){
    printf("-1\n");
    return 0;
  }
  else
    cnt=a[n-1];
  for(i=n-2;i>=0;i--){
    if(a[i+1]>a[i]+1||a[i]>i){
      printf("-1\n");
      return 0;
    }
    else if(a[i+1]!=a[i]+1)
      cnt+=a[i];
  }
  printf("%ld\n",cnt);
}

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

using namespace std;

int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(20);

    int n, k;
    cin >> n >> k;

    int ans = 1;
    n -= k;
    while(n>0){
        n -= k-1;
        ++ans;
    }
    cout << ans << '\n';

}

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

int main() {
    int list[16][16] = {0};
    int n;
    cin>>n;
    for(int i = 0; i < n; i += 1) {
        int m;
        for(int j = 0; j < n; j += 1) list[i][j] = -1;
        
        cin>>m;
      
        for(int j = 0; j < m; j += 1) {
            int x,y;
            cin>>x;
            cin>>y;
            list[i][x-1] = y;
        }
    }
  
    int max = 0;
    for(int t = 1; t < (1u<<n); t+= 1) {
        int l = 1;
        for(int i = 0; i < n; i += 1) {
            if((t&(1u<<i)) != (1u<<i)) continue;
          
            for(int j = 0; j < n; j += 1) {
                
                if (list[i][j] != -1 && (t&(1u<<j)) != (list[i][j]<<j)) {
                    l = 0;
                    break;
                }
            }
        }
        if (l && max < __builtin_popcount(t)) max = __builtin_popcount(t);
    }
    cout<<max;
  return 0;
}

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

int main() {
  int n;cin>>n;
  n = 10000-n;
  n%=1000;
  cout<<n;
  
}


Measured memory_bytes: 3636
import numpy as np
from sys import argv
import time
np.random.seed(1)


def input_from_file():
    with open(argv[1], "r") as f:
        D = int(f.readline())
        C = np.array(f.readline().split(), dtype=int)
        S = tuple(tuple(map(int, f.readline().split())) for _ in range(D))
    return D, C, S


def input_from_console():
    D = int(input())
    C = np.array(input().split(), dtype=int)
    S = tuple(tuple(map(int, input().split())) for _ in range(D))
    return D, C, S


def greed(D, C, S):
    last = np.ones(26, dtype=int)
    ans = []
    for s in S:
        s = np.array(s)
        tmp = s + C * last
        i = np.argmax(tmp)
        last[i] = 0
        last += 1
        ans.append(i + 1)
    return ans


def calc_score(D, C, S, T):
    res = 0
    last = np.ones(26, dtype=int)
    for d, t in enumerate(T):
        t -= 1
        last[t] = 0
        score = S[d][t]
        score -= (C * last).sum()
        res += score
        last += 1
    return res


def output_to_file(ans):
    with open("output.txt", "w", newline="") as f:
        for a in ans:
            f.write("{}\n".format(a))


def main():
    start = time.time()
    lim = 1.500
    D, C, S = input_from_console()
    #D, C, S = input_from_file()
    #初期解, 貪欲法
    sol = greed(D, C, S)
    score = calc_score(D, C, S, sol)
    while True:
        d = np.random.randint(0, D)
        q = np.random.randint(1, 27)
        old = sol[d]
        sol[d] = q
        new_score = calc_score(D, C, S, sol)
        if new_score > score:
            score = new_score
        else:
            sol[d] = old
        if time.time() - start >= lim:
            break
    print(*sol, sep="\n")
    # output_to_file(sol)


if __name__ == "__main__":
    main()

Measured memory_bytes: 27656
#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;
static const int INF (1<<30);
static const ll mod = 1e9+7;

int main() {
  ll N, K; cin >> N >> K;
  vector<int> A(N), B(N);
  rep(i, N) cin >> A[i];
  B = A;

  ll sw = 0LL;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N-1; j >= i+1; j--) {
      if (B[j] < B[j-1]) {
        swap(B[j], B[j-1]);
        flag = 1;
        sw++;
        sw %= mod;
      }
    }
  }


  vector<ll> dp(2005, 0LL);
  for (auto x : A) dp[x+1]++;

  for (int i = 1; i < 2001; i++) {
    dp[i] += dp[i-1];
  }
  /*for (auto x : A) dp[x-1]++;
  for (int i = 2000; i >= 0; i--) {
    dp[i] += dp[i+1];
  }*/

  ll ans = 0LL;
  for (auto x : A) {
    ans += dp[x] * (((K-1) * K / 2LL)%mod);
    //ans += dp[x] * (K-1) * K / 2LL;
    ans %= mod;
  }

  ans += sw * K;
  ans %= mod;


  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// I think of what the world could be, A vision of the one I see, A million dreams is all it's gonna take

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn = 2e5 + 10, mod = 998244353;

int h[maxn], par[maxn];
vector<int> v[maxn];

pii far(int u, int pr = -1){
    par[u] = pr;
    h[u] = pr == -1 ? 0 : (h[pr] + 1);
    pii ans = {0, u};
    for(int y : v[u]){
	if(y != pr){
	    pii p = far(y, u);
	    p.F++;
	    ans = max(ans, p);
	}	    
    }
    return ans;
}

int total[maxn], dp1[maxn], dp2[maxn], under[maxn];

void dfs(int u, int par = -1){
    total[u] = 1, dp2[u] = 1;
    if(sz(v[u]) == (par != -1))
	dp2[u] = 0, dp1[u] = 1;
    for(int y : v[u]){
	if(y != par){
	    dfs(y, u);
	    under[u] = max(under[u], under[y] + 1);
	    total[u] = 3ll * total[u] * total[y] % mod;
	}
    }
    for(int y : v[u]){
	if(y != par){
	    int no = 0, yes = 0;
	    if(under[u] == under[y] + 1){
		no = (2ll * total[y] + 1ll * dp2[y]) % mod;
		yes = dp1[y];
	    }
	    else{
		no = 3ll * total[y] % mod;
		yes = 0;
	    }
	    dp1[u] = (1ll * dp1[u] * no + 1ll * dp2[u] * yes) % mod;
	    dp2[u] = (1ll * dp2[u] * no) % mod;
	}
    }
}

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

    int n;
    cin >> n;
    for(int i = 0; i < n-1; i++){
	int a, b;
	cin >> a >> b;
	v[a].PB(b);
	v[b].PB(a);
    }
    int A = far(1).S;
    pii p = far(A);
    int diam = p.F, B = p.S;

    int ans = 0;

    if(diam & 1){
	for(int i = 0; i < (diam/2); i++)
	    B = par[B];
	A = par[B];
	dfs(A, B);
	dfs(B, A);
	ans = 1ll * dp1[A] * dp1[B] % mod;
    }
    else{
	for(int i = 0; i < (diam/2); i++)
	    B = par[B];
	dfs(B);
	int zer = 1, one = 0, two = 0; 
	for(int y : v[B]){
	    int yes = 0, no = 0;
	    if(under[B] == under[y] + 1){
		no = (1ll * total[y] + 2ll * dp2[y]) % mod;
		yes = dp1[y];
	    }
	    else{
		no = 3ll * total[y] % mod;
	    }
	    two = (1ll * two * no + 1ll * one * yes) % mod;
	    one = (1ll * one * no + 1ll * zer * yes) % mod;
	    zer = (1ll * zer * no) % mod;
	}
	ans = two;
    }
    return cout << ans << endl, 0;
}


Measured memory_bytes: 23808
import math
N,D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

cnt = 0

for i in range(N):
    for j in range(i + 1, N):
        diff = 0
        for k in range(D):
            diff += (X[i][k] - X[j][k]) ** 2
        if math.sqrt(diff).is_integer():
            cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a)  a.begin(),a.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;

void a(){
    ll x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x<< ' ' << y<< ' ' << z;
}

void b(){
    ll n,m; cin >> n >> m;
    auto a = v<>(n,0);
    rep(i,n) cin >> a[i];
    ll sum = accumulate(all(a),0);
    sort(all(a));
    ll check = ceil((double)sum/(4*m));
    ll ans = n - (lower_bound(all(a),check)-a.begin());
    if(ans>=m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

void c(){
    ll n,k; cin >> n >> k;
    ll d = n%k;
    cout << min(d,abs(d-k)) << endl;
}

void d(){

}

int main(){
    c();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n;cin>>n;
  vector<ll> a(n);rep(i,n)cin>>a[i];
  vector<ll> b(n);
  b[0] = a[0];
  rep(i,n-1)b[i+1] = (b[i] + a[i+1]);
  
  ll ans = 0;

  rep(i,n){
    ll tmp = b[n-1] - b[i];
    tmp %= INF;
    ans += a[i] * tmp;
    ans %= INF;
  }

  print(ans);
  return 0;
}

Measured memory_bytes: 6412
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include<stack>
#include<queue>
using namespace std;

 
int main(){
    string s;
    cin >> s;

    // stack<int> st;
    queue<int> que;
    char f = s[0]; int zure;
    if(f == '<') zure = 0;
    else zure = 1;
    // cout << zure;
    int renzoku = 1;
    for(int i=1; i<s.size(); i++){
        if(f == s[i]){
            renzoku++;
        }
        else{
            que.push(renzoku);
            // cout << renzoku;
            renzoku = 1;
            f = s[i];
        }
    }
    que.push(renzoku);

    long long int ans = 0;
    if(zure == 1){
        long long int c = que.front(); que.pop();
        ans += (0+c-1)*c/2 + c;
    }
    while(!que.empty()){
        long long int a = que.front(); que.pop();
        long long int b;
        if(!que.empty()) {b = que.front(); que.pop();}
        else {b = 0;}
        ans += (0+a-1)*a/2 + (0+b-1)*b/2 + max(a,b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1796
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        List<Long> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            long temp = Long.parseLong(sc.next());
            if (temp % 2 == 0) {
                a.add(temp);
            }
        }
        if (a.size() == 0) {
            System.out.println(0);
            return;
        }
        Collections.sort(a);
        int ans = 0;
        for (int i = 0; i < a.size(); i++) {
            while (a.get(i) % 2 == 0) {
                ans++;
                a.set(i, a.get(i) / 2);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 36684
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;

// Extended Print Func
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& input){
    os << "[ ";
    REP(i, input.size()){
        os << input[i];
        if (i < input.size()-1) { os << " "; }
    }
    os << " ]";
    return os;
}
void print() { std::cout << "\n"; }
template<class T, class... A> void print(const T& first, const A&... rest) { std::cout << first << " "; print(rest...); }
template<class... A> void print(const A&... rest) { print(rest...); }



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i,N){ cin >> A[i]; }

  // 積がX以下になるものの数を(bnsで)求めてbns (1/2する)
  sort(A.begin(), A.end());
  ll x_left = -1e18-1;
  ll x_right = 1e18+1;
  while (x_left+1 < x_right){
    ll x = (x_right + x_left) / 2;
    ll cnt = 0;
    REP(i,N){
      if (A[i]>0){
        ll ok = i, ng = N;
        while (ok+1 < ng){
          ll mid = (ng+ok)/2;
          if (A[i]*A[mid] <= x){
            ok = mid;
          } else {
            ng = mid;
          }
        }
        cnt += ok - i;
      } else {
        ll ok = N, ng = i;
        while (ng+1 < ok){
          ll mid = (ok+ng)/2;
          if (A[i]*A[mid] <= x){
            ok = mid;
          } else {
            ng = mid;
          }
        }
        cnt += N - ok;
      }
    }
    if (cnt >= K) {
      x_right = x;
    } else {
      x_left = x;
    }
  }

  cout << x_right << "\n";
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
typedef long long ll;
ll x[100010],y[100010];
int n;
int C(ll n,ll k){return(n&k)==k;}
bool light(ll a,ll b){
	int i,f;
	f=0;
	for(i=1;i<=n;i++){
		if(x[i]<=a&&y[i]<=b)f^=C(a+b-x[i]-y[i],a-x[i]);
	}
	return f;
}
int main(){
	int i;
	ll x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%lld%lld",::x+i,::y+i);
	x=2e17;
	y=0;
	for(i=60;i>=0;i--){
		if(light(x-(1ll<<i),y+(1ll<<i))){
			x-=1ll<<i;
			y+=1ll<<i;
		}
	}
	printf("%lld",x);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

using namespace std;


int main(){
   ll n;
   cin>>n;
   string ans;

   do{
      n--;
      int x=n%26;
      ans+=97+x;
      n/=26;
      if(n==0) break;

   }while(1);

   

   
   
   reverse(ans.begin(),ans.end());
   cout<<ans;

   
   
return 0;
}



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

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

int main(){
	int N;
	cin >> N;
	vector<long long> A(N);
	for(int i=0;i<N;i++)	cin >> A.at(i);

	long long ans=0;
	long long mi=1e9;
	int count=0;
	int count0=0;
	for(int i=0;i<N;i++){
		ans+=abs(A.at(i));
		mi=min(mi,abs(A.at(i)));
		if(A.at(i)<0)	count++;
		else if(A.at(i)==0)	count0++;
	}
	if(count0>0)	cout << ans << endl;
	else if(count%2==0)	cout << ans << endl;
	else	cout << ans-2*mi << endl;

	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      int count = 0;
      int x = scn.nextInt();
		int[] a = new int[n];
		for(int i=0; i<a.length; ++i){
			a[i] = scn.nextInt();
		}
      long sum = 0;
      for (int i=0; i<a.length; ++i){
        sum = sum + a[i];
      }
      if(sum < x){
       System.out.println(n-1);
      }else if(sum == x){
        System.out.println(n);
      }else{
      Arrays.sort(a);
      for(int i=0; i<a.length; ++i){
        if(x>=a[i]){
          x = x - a[i];
          count = count + 1;
        }
      }
      System.out.println(count);
		}
    }
}


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

int main(){
    
    int n, m;
    cin >> n >> m;
    
    vector<int> nomal(n+1,1);
    
    for (int i = 0; i < m; i++){
        int a;
        cin >> a;
        nomal[a] = 0;
    }
    
    vector<int> dp(n+2);
    const int mod = 1e9+7;
    
    dp[0] = 1; // 0段目までの移動方法は,移動しないという0通り
    
    for (int now= 0; now < n; now++){
        for (int next = now+1; next <= min(n,now+2);next++){
            
            if (nomal[next]){
                dp[next] += dp[now];
                dp[next] %= mod;
            }
        }
    }
    
    cout << dp[n] << endl;
    return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct UF {
  vint data;
  UF(int n):data(n, -1){}
  int find(int x) {
    return data[x] < 0 ? x : find(data[x]);
  }
  int size(int x) {
    return -data[find(x)];
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return false;
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;
  vint A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];
  vector<vint> graph(N);
  rep(i, M) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  vint id(N);
  iota(all(id), 0);
  sort(all(id), [&](int i, int j) {
      return A[i]-B[i] < A[j]-B[j];
    });
  vint dp(N, -1);
  UF uf(N);
  vint bsum(N);
  for(int i : id) {
    int res = max(0ll, A[i]-B[i]);
    int sum = B[i];
    for(int j : graph[i]) {
      int v = uf.find(j);
      if(uf.same(i, v) || dp[v] == -1) continue;
      chmin(res, max(dp[v], A[i]-(B[i]+bsum[v])));
      sum += bsum[v];
      uf.unite(i, v);
    }
    int u = uf.find(i);
    dp[u] = res;
    bsum[u] = sum;
  }
  //cout<<accumulate(all(B), 0ll)<<" "<<bsum[uf.find(id.back())]<<endl;
  cout << bsum[uf.find(id.back())] + dp[uf.find(id.back())] << endl;

  return 0;
}


Measured memory_bytes: 11008
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
//使い方　インスタンス化(頂点数)　uniteつなぐ(双方向注意) same判定
int main()
{
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    for (int i = 0; i < h;i++){
        for (int j = 0; j < w;j++){
            if((i<b&&j<a)||(i>=b&&j>=a))
                cout << 1;
            else
            {
                cout << 0;
            }
            
        }
        cout << endl;
    }
}


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

using namespace std;

int dp[3001][7001];

int res(0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int n, range;
    cin >> n >> range;
    
    vector<pair<int, int>> menu(n);
    
    for (int i = 0; i < n; ++i)
    {
        int duration, delicious;
        cin >> duration >> delicious;
        menu[i] = make_pair(duration, delicious);
    }
    
    sort(menu.begin(), menu.end());
    
    for (int j = 0; j < n; ++j)
        for (int k = 0; k < range; ++k)
            if (k - menu[j].first >= 0)
                dp[j + 1][k] = max(dp[j][k], dp[j][k - menu[j].first] + menu[j].second);
            else
                dp[j + 1][k] = dp[j][k];

    for (int s = 0; s < n; ++s)
        res = max(res, dp[s][range - 1] + menu[s].second);

    cout << res;
}

Measured memory_bytes: 81408
package main

import "fmt"
import "strconv"

func main() {
	var n string
	var m int
	fmt.Scanf("%s", &n)
	in := []byte(n)
	for _, i := range in {
		tmp, _ := strconv.Atoi(string(i))
		m = (m + tmp) % 9
	}
	if m%9 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main() {
  string S;
  char a,b,c,d;
  
  cin >> S;
  
  a = S.at(2);
  b = S.at(3);
  c = S.at(4);
  d = S.at(5);
  
  if(a == b && c == d) cout << "Yes" << endl;
  
  else cout << "No" << endl;
}


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

int main(int argc, char const *argv[]) {
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    int U=y+r; int D=y-r;
    int R=x+r; int L=x-r;
    if (U>H||D<0||R>H||L<0) cout<<"No\n";
    else cout<<"Yes\n"; 
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int s[27];
int main()
{
	char ch;
	for (int i=1; i<=3; ++i)
	{
		cin >> ch;
		s[int(ch-96)]++;
	}
	if (s[1]==1&&s[2]==1&&s[3]==1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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


Measured memory_bytes: 2940
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val r = sc.nextInt()
    println(problem156a(n, r))
}

fun problem156a(n: Int, r: Int): Int {
    return if (10 <= n) r else r + (100 * (10 - n))
}

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

using ll = long long;

int main(){
  char C;
  cin >> C;
  C++;
  cout << C << endl;
}

Measured memory_bytes: 256
// BEGINNING WITH NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
// ATCODER BEGINNERS PROBLEMS 
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.flush();
  	int a,b,c;
    cin >> a >> b >> c;
  	(c>=a && c<=b) ? cout<<"Yes": cout<<"No";
	return 0;
	// Bye Bye 2019
}

Measured memory_bytes: 256
N=int(input())
S1=input()
S2=input()

T=[]
i=0
while i<N:
  if S1[i]==S2[i]:
    T.append("T")
    i+=1
  else:
    T.append("Y")
    i+=2
#print(T)

u=[0]*len(T)
u[0]=3 if T[0]=="T" else 6
for i in range(1,len(T)):
  if T[i]=="T" and T[i-1]=="T":
    u[i]=2
  elif T[i]=="T" and T[i-1]=="Y":
    u[i]=1
  elif T[i]=="Y" and T[i-1]=="T":
    u[i]=2
  else:
    u[i]=3
#print(u)

md=10**9+7
ans=1
for i in u:
  ans*=i
  ans%=md
print(ans)

Measured memory_bytes: 3064
n=int(input())
a=input().split(" ")
a=list(map(int,a))

b=input().split(" ")
b=list(map(int,b))
counta=0
countb=0
for i in range(n):
    if a[i]<b[i]: #a<b
        temp=b[i]-a[i] 
        if temp%2==0:
            counta+=int(temp/2)
            #countb-=int(temp/2)
        else:
            counta+=int((temp+1)/2)
            countb+=1
            
    if a[i]>b[i]:#a>b
        temp=a[i]-b[i]
        countb+=temp
       # counta-=temp
# print(counta)
# print(countb)
if counta>=countb:
    print("Yes")
else:
    print("No")
    

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int a, b, k;
  cin >> a >> b >> k;
  int cnt = 0;
  vi32 l;
  reps(i, 100) {
    if (a % i == 0 && b % i == 0) l.push_back(i);
  }
  sort(all(l), greater<i32>());
  cout << l[k - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
def yoko():
    for h, line in enumerate(L):
        if line[q-1:q-1+p] != [' ']*p:
            h = h-1
            for w in range(q-1, q-1+p):
                L[h][w] = '#'
            break
    else:
        for w in range(q-1, (q-1+p-1)+1):
            L[h][w] = '#'
    
    check(h, 1)
    
def tate():
    for h, line in enumerate(L):
        if line[q-1] != ' ':
            h = h-1
            for i in range(h-p+1, h-p+1+p):
                L[i][q-1] = '#'
            break
    else:
        for i in range(h-p+1, h-p+1+p):
            L[i][q-1] = '#'
    
    check(h-p+1, p)

def check(h, _h):
    c = 0
    while c < _h:
        if L[h] == ['#']*5:
            del L[h]
        else:
            h += 1
        c += 1
     
def add():
    c = 0
    for line in L:
        if line == [' ']*5:
            c += 1
        else:
            break
    for i in range(5-c):
        L.insert(0, [' ']*5)
        
def result():
    ans = 0
    for line in L:
        for v in line:
            if v == '#':
                ans += 1
    else:
        print ans

while True:
    n = input()
    if n == 0: break
    L = [[' ']*5 for i in range(5)]
    for i in range(n):
        d, p, q = map(int, raw_input().split())
        if d == 1:
            yoko()
        else:
            tate()
        add()
    else:
        result()

Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
/*cout <<"Debug"
cout <<x-30<<' '<<y-30<<endl;*/
typedef pair<pair<int ,int>, int> P;
vector<pair<pair<int ,int>, int> > v_ans;
vector<int>v_taro;
vector<int>v_hana;
/*taro tenn,hanako_ten,sum*/

bool cmp(P h, P r){
  return h.second < r.second;
}
int main(){
  string s;
  int ans = 0;

  cin >>s;
  for(int i = 0;i<4;i++){
    if(s[i] == '+')ans++;
    if(s[i] == '-')ans--;
  }
  cout <<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    
    int m,f,r;
    for(int i=0;;i++){
        scanf("%d%d%d",&m,&f,&r);
        if(m==-1 && f==-1 && r==-1){
            break;
        }else{
        if(m==-1 || f==-1){
            printf("F\n");
        }else if(m+f>=80){
            printf("A\n");
        }else if(m+f>=65 && m+f<80){
            printf("B\n");
        }else if(m+f>=50 && m+f<65){
            printf("C\n");
        }else if(m+f>=30 && m+f<50){
            if(r>=50){
                printf("C\n");
            }else{
                printf("D\n");}
        }else if(m+f<30){
            printf("F\n");
        }
        }}
    return 0;
}



Measured memory_bytes: 2076
#include <iostream>

using namespace std;

static const long MOD = 1000000007;

int main(int argc, char *argv[]) {
	int n, m;
	cin >> n >> m;

	long xs = 0;
	for (int i = 1; i <= n; i++) {
		long x;
		cin >> x;
		xs = (xs + (-n + 2L * i - 1) * x + MOD) % MOD;
	}

	long ys = 0;
	for (int i = 1; i <= m; i++) {
		long y;
		cin >> y;
		ys = (ys + (-m + 2L * i - 1) * y + MOD) % MOD;
	}

	cout << (xs * ys) % MOD << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;
bool us[100100]={false};
int p[100100]={0};
int main(){
	/*Eratosthenes*/
	p[2] = 2;
	for(int i = 0; i < 100101 ; i+=2)us[i] = true;
	for(int i = 3; i < 100101; i+=2){
		if(us[i] == true)continue;
		else if(us[i] == false){
			p[i] = i;
			for(int j = i+i; j < 100101; j += i)us[j] = true;
		}
	}

	int n;

	while(scanf("%d",&n),n){
		for(int i = n; i >= 0; i--){
			if(!us[i] && !us[i-2]){
				printf("%d %d\n",p[i-2],p[i]);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1676
#include <iostream>

using namespace std;

int main() {
  int d; 

  while (cin >> d) {
    int s = 0;
    for (int x_i = 0; x_i <= 600-d; x_i += d)
      s += x_i*x_i*d;

    cout << s << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 

#define PI 3.14159265

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)5e5 + 7;
const int inf = (int)1e9 + 7;
//const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
 
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

const int mod = 998244353;

struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};



int v[206];
int main(){
	clr(v,0);
	v[1] = 300000;
	v[2] = 200000;
	v[3] = 100000;
	v[0] = 400000;
	int x, y; cin>> x>>y;
	if(x == 1 && y == 1)
		cout<<v[1]+v[1]+v[0];
	else{
		cout<<v[x]+v[y];
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
ll ans=0;
int N;
ll A[100005];
bool used[100005];
vector<string> ope;
int main(int argc,char const* argv[])
{
  memset(used,false,sizeof(used));
  cin >> N;
  for (int i = 0; i < N; ++i)
    {
      cin >> A[i]; 
    }
  sort(A,A+N);
  ll minnum=A[0];
  ll maxnum=A[N-1];
  for (int i = 1; i < N-1; ++i)
    {
      if(A[i]>0)
	{
	  string tmp="";
	  tmp=to_string(minnum);
	  tmp=tmp+" ";
	  tmp=tmp+to_string(A[i]);
	  ope.push_back(tmp);
	  minnum-=A[i];
	  used[i]=true;
	}
    }
  for (int i = N-2; i >= 1; i--)
    {
      if(used[i]==false)
	{
	  ope.push_back(to_string(maxnum)+' '+to_string(A[i]));
	  maxnum-=A[i];
	}
    }
  ope.push_back(to_string(maxnum)+' '+to_string(minnum));
  cout << maxnum-minnum << endl;
  for (int i = 0; i < ope.size(); ++i)
    {
      cout << ope[i] << endl;
    }
  return 0;
}


Measured memory_bytes: 9844
def main():
    n=int(input())
    a=[]
    for i in range(n):
        a.append(int(input()))
    ans = 1
    tmp = a[0]
    while ans <=n:
        if tmp == 2:
            print(ans)
            exit()
        else:
            tmp = a[tmp-1]
            ans += 1
    print(-1)
if __name__ == '__main__':
    main()

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

int main() {
	int N,cnt;
	cin >> N;
	vector<int> std(N,0);
	for(int i = 0;i < N ;i++)
	{
		cin >> std.at(i);
  }
  int sv = 1;
  for(int j = 0;j < N;j++)
  {
  	cnt++;
  	sv = std.at(sv-1);
		if(sv == 2)
		{
			cout << cnt << endl;
			break;
		}
		else if(j == N - 1){
			cout << -1 << endl;
		}
	}
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,e,f,t,m,i;
	char s[10];
	while(1)
	{
		scanf("%d", &n);
		if(n==0)
		break;
		a=1;
		b=2;
		c=3;
		d=4;
		e=5;
		f=6;
		m=1;
		for(i=0; i<n; i++)
		{
			scanf("%s", s);
			if(s[0]=='N')
			{
				t=a;
				a=b;
				b=f;
				f=e;
				e=t;
			}
			if(s[0]=='E')
			{
				t=a;
				a=d;
				d=f;
				f=c;
				c=t;
			}
			if(s[0]=='W')
			{
				t=a;
				a=c;
				c=f;
				f=d;
				d=t;
			}
			if(s[0]=='S')
			{
				t=a;
				a=e;
				e=f;
				f=b;
				b=t;
			}
			if(s[0]=='R')
			{
				t=b;
				b=c;
				c=e;
				e=d;
				d=t;
			}
			if(s[0]=='L')
			{
				t=b;
				b=d;
				d=e;
				e=c;
				c=t;
			}
			m+=a;
		}
		printf("%d\n", m);
	}
	
	return 0;
}


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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    //0.25,0.5,1,2
    int q,h,s,d;
    cin>>q>>h>>s>>d;
    int n;
    cin>>n;
    int m=min(8*q,min(4*h,min(2*s,d)));
    int ans=(n/2)*m;
    ans+=(n%2)*(min(4*q,min(2*h,s)));
    cout<<ans<<endl;

    return 0;
}

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

#include <vector>

using namespace std;

int main()
{
	long long N;

	cin >> N;

	vector<long long> ans(4);

	string s;

	for (int i = 0; i < N; i++)
	{
		cin >> s;

		if (s == "AC")
			ans[0]++;
		else if (s == "WA")
			ans[1]++;
		else if (s == "TLE")
			ans[2]++;
		else if (s == "RE")
			ans[3]++;
	}

	cout << "AC x " << ans[0] << endl;
	cout << "WA x " << ans[1] << endl;
	cout << "TLE x " << ans[2] << endl;
	cout << "RE x " << ans[3] << endl;

}


Measured memory_bytes: 3624
N = int(input())

ans = [0] * (N+1)

for i in range(N+1):
    if i % 3 != 0 and i % 5 != 0 and i % 15 != 0:
        ans[i] = ans[i-1] + i
    else:
        ans[i] = ans[i-1]
print(ans[-1])


Measured memory_bytes: 41504
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def check(s):
    if (s[len(s) // 2:] == s[:len(s) // 2]):
        print(len(s))
        exit()


S = S()
n = len(S)
if (n % 2 == 0):
    while S:
        S = S[:-2]
        check(S)
else:
    S = S[:-1]
    check(S)
    while S:
        S = S[:-2]
        check(S)


Measured memory_bytes: 42440
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c==17&&a*b*c==175)
  {
    cout<<"YES"<<endl;
  }
   else
  {
    cout<<"NO"<<endl;
   }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s=="SRR")
		cout<<"2";
	else if(s=="SRS")
		cout<<"1";
	else if(s=="RRR")
		cout<<"3";
	else if(s=="SSS")
		cout<<"0";
	else if(s=="RSR")
		cout<<"1";
	else if(s=="RRS")
		cout<<"2";
	else if(s=="SSR")
		cout<<"1";
	else
		cout<<"1";
}


Measured memory_bytes: 3624
<?php

  while(true) {

    $line = explode(" ",trim(fgets(STDIN)));
    $H =$line[0];
    $W = $line[1];
    if($H ==0 && $W == 0) {
      break;
    }

    for($i=0;$i<$H;$i++) {
      if(($i%2)===0) {
        for($j=0;$j<$W;$j++) {
          if(($j%2)===0) {
            print("#");
          }else{
            print(".");
          }
        }
      }else{
        for($j=0;$j<$W;$j++) {
          if(($j%2)===0) {
            print(".");
          }else{
            print("#");
          }
        }
      }
      echo PHP_EOL;
    }
    echo PHP_EOL;
    }



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

int main(){
    int N;cin>>N;
    int info[N][3];
    rep(i,N)cin>>info[i][0]>>info[i][1]>>info[i][2];
    rep(i,101)rep(j,101){
        int x,y,c;
        rep(k,N){
            if(info[k][2]){
                x=info[k][0];
                y=info[k][1];
                c=info[k][2];
                break;
            }
        }
        int H=c+abs(x-j)+abs(y-i);
        int flag=0;
        rep(k,N){
            if(max(H-abs(info[k][0]-j)-abs(info[k][1]-i),0)!=info[k][2]){
                flag++;
                break;
            }
        }
        if(!flag){
            cout<<j<<" "<<i<<" "<<H<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
s = input()
a, b = 0, 0
for i in range(len(s)):
  if i % 2 == 1:
    if s[i] == "0":
      b += 1
    else:
      a += 1
  else:
    if s[i] == "0":
      a += 1
    else:
      b += 1
if a > b:
  print(b)
else:
  print(a)
  

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

int N;
int Q[25][25] = {};
int P[4] = {13,17,19,23};

int main(){
    while(cin >> N && N>0){
        int d,t,q;
        for(int i=1;i<=24;i++) for(int j=0;j<24;j++) Q[i][j] = 0;
        for(int i=1;i<=N;i++){
            cin >> d >> t;
            for(int j=0;j<d;j++){
                cin >> q;
                Q[d][(j-t+d)%d] += q;
            }
        }
        int ans = 0;
        for(int i=0;i<=55440;i++){
            int now = 0;
            for(int j=1;j<=24;j++){
                if(j==13 || j==17 || j==19 || j==23) continue;
                now += Q[j][i%j];
            }
            ans = max(ans,now);
        }
        for(int i=0;i<4;i++){
            int ma = 0;
            for(int j=0;j<P[i];j++) ma = max(ma,Q[P[i]][j]);
            ans += ma;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2988
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

LL C[55][55];

void pre() {
  C[0][0] = 1;
  rep(i,1,55) {
    C[i][0] = C[i][i] = 1;
    rep(j,1,i) {
      C[i][j] = C[i-1][j-1] + C[i-1][j];
    }
  }
}

int main() {
  pre();
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  vector<LL > v;
  rep(i,0,n) {
    LL x;
    cin >> x;
    v.push_back(x);
  }
  sort(all(v));
  double sm = 0;
  rep(i,0,a) sm += v[n-1-i];
  sm /= a;
  printf("%0.6lf\n",sm);
  int big, eq;
  big = eq = 0;
  rep(i,0,n) {
    big += v[i] > v[n-a];
    eq += v[i] == v[n-a];
  }
  LL ans = 0;
  if(big) {
    a -= big;
    b -= big;
    ans = C[eq][a];
  } else {
    ans = 0;
    rep(i,a,b+1) {
      ans += C[eq][i];
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main(){
	var n int
	var x, num, sum int
	m := []int{}

	fmt.Scan(&n, &x)

	for i:=0; i<n; i++ {
		fmt.Scan(&num)
		m = append(m, num)
		x -= num
	}

	min := m[0]
	for v := range m {
		if min > m[v] {
			min = m[v]
		}
	}
	
	sum = n + x/min

	fmt.Print(sum)
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18

int main() {
    int N, K;
    long long S;
    while (cin >> N >> K >> S, N) {
        vector<int> x(N), y(N), z(N);
        for (int i = 0; i < N; i++) cin >> x[i] >> y[i] >> z[i];
        #define dif(arr, i, j) abs(arr[i] - arr[j])
        auto is_connected = [&](int i, int j) {
            long long dx = dif(x, i, j), dy = dif(y, i, j), dz = dif(z, i, j);
            return dx <= S && dy <= S && dz <= S;
        };
        auto isec_area = [&](int i, int j) {
            long long dx = S - dif(x, i, j),
                      dy = S - dif(y, i, j),
                      dz = S - dif(z, i, j);
            return (dx * dy + dy * dz + dz * dx) * 2;
        };
        vector<vector<int>> g(N);
        for (int i = 0; i < N; i++) for (int j = 0; j < i; j++) {
            if (is_connected(i, j)) g[i].emplace_back(j), g[j].emplace_back(i);
        }
        long long cube = 6 * S * S;
        long long mi = INF;
        auto dfs = [&](auto dfs, int u, int p, int s, int d, long long res) -> void {
            if (d == K) {
                if (K > 2 && is_connected(u, s)) res -= isec_area(u, s);
                mi = min(mi, res);
                return ;
            }
            for (int v: g[u]) if (v != p) {
                dfs(dfs, v, u, s, d + 1, res - isec_area(v, u) + cube);
            }
        };
        for (int s = 0; s < N; s++) dfs(dfs, s, -1, s, 1, cube);
        if (mi == INF) mi = -1;
        cout << mi << endl;
    }
	return 0;
}



Measured memory_bytes: 3208
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]


    H,W,N = LI()

    d = collections.Counter()
    for _ in range(N):
        x,y = LI()
        for dx in range(-1,2):
            for dy in range(-1,2):
                nx = x+dx
                ny = y+dy
                if 1 < nx < H and 1 < ny < W:
                    d[(nx,ny)] += 1
    ans = [0] * 10
    for x,c in collections.Counter(d.values()).items():
        ans[x] += c
    ans[0] = (H-2) * (W-2) - sum(ans[1:])

    print(*ans,sep='\n')

if __name__ == '__main__':
    main()

Measured memory_bytes: 193208
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans  = 0
for i in range(n-1):
    s = a[i] + a[i+1]
    if s > x:
        a[i+1] -= s - x
        a[i+1] = max(0, a[i+1])
        ans += s-x
print(ans)

Measured memory_bytes: 85700
#?????????http://ja.wikipedia.org/wiki/??¬??????????????\??????????????¢
def levenshtein_distance(str1, str2):
    d = [[0] * (len(str2) + 1) for _ in range(len(str1) + 1)]

    for i1 in range(len(str1) + 1):
       d[i1][0] = i1
    for i2 in range(len(str2) + 1):
       d[0][i2] = i2

    for i1 in range(len(str1)):
        for i2 in range(len(str2)):
            cost = 0 if str1[i1] == str2[i2] else 1
            d[i1 + 1][i2 + 1] = min(d[i1    ][i2 + 1] + 1,     # ??????????????\
                                    d[i1 + 1][i2    ] + 1,     # ???????????????
                                    d[i1    ][i2    ] + cost)  # ???????????????
#    for di in d:
#        print(*di)
    return d[-1][-1]

from sys import stdin
readline = stdin.readline

s1, s2 = [readline().strip() for _ in range(2)]
print(levenshtein_distance(s1, s2))

Measured memory_bytes: 44464
import org.w3c.dom.ls.LSInput;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        String n1 = sc.next();

        int count = 0;
        String s = null;
        for (int i = 0; i < 3; i++) {
            if (n1.substring(i, i + 1).equals(s) || count == 0) {
               if(n1.substring(i, i + 1).equals("R")) {
                   count++;
               }
            }
            s = n1.substring(i, i + 1);
        }

        p(String.valueOf(count));
    }

    static void p(String s) { System.out.println(s); }
}


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


int main(){
  string s;
  cin >> s;
  rep(i,sz(s)) {
    if (s[i] == '9') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	m1 += h1 * 60;
	m2 += h2 * 60;
	m2 -= k;
	cout << m2 - m1 << endl;

	return 0;
}

Measured memory_bytes: 3640