akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  string s; cin >> s;
  int n = s.size();
  int ans = 0;
  rep(i, n-1) {
    if(s[i] != s[i+1]) ++ans;
  }
  cout << ans << endl;
}

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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int i = a;i < b;++i) cout << ary[i] << (b-1 == i ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

int n;
vector<vector<vector<double>>> dp(310,vector<vector<double>>(310,vector<double>(310,-1.0)));

double rec(int i,int j,int k) {
    if (dp[i][j][k] > -1) return dp[i][j][k];
    double res = 0.0;
    if (i) res += rec(i-1,j,k)*i;
    if (j) res += rec(i+1,j-1,k)*j;
    if (k) res += rec(i,j+1,k-1)*k;
    res += n;
    res /= i+j+k;
    return dp[i][j][k] = res;
}

int main() {
    cin >> n;
    int a[4] = {0,0,0,0};
    for (int i = 0;i < n;++i) {
        int b;
        cin >> b;
        a[b]++;
    }
    dp[0][0][0] = 0;
    cout << setprecision(12) << rec(a[1],a[2],a[3]) << endl;
    return 0;
}

Measured memory_bytes: 237568
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
string ans;
void dfs(int lft,string res)
{
	if(!lft)
	{
		if(ans=="")ans=res;
		else ans=min(ans,res);
		return;
	}
	string t=res;
	reverse(t.begin(),t.end());
	t=res+t;
	for(int i=0;i<=res.size();i++)
		dfs(lft-1,t.substr(i,res.size()));
}
int main()
{
	int n,k;
	string s;
	cin>>n>>k;
	cin>>s;
	while(k--)
	{
		string t=s;
		reverse(t.begin(),t.end());
		t=s+t;
		string s2=s;
		if(k==0)
		{
			for(int i=1;i<=s.length();i++)
				s2=min(s2,t.substr(i,s.length()));
			cout<<s2;
			return 0;
		}
		reverse(t.begin(),t.end());
		reverse(s2.begin(),s2.end());
		for(int i=0;i<=s.length();i++)
			s2=min(s2,t.substr(i,s.length()));
		reverse(s2.begin(),s2.end());
	//	cout<<t<<" "<<s2<<endl;
	//	system("pause");
		bool same=1;
		for(int i=1;i<s.length();i++)
			if(s[i]!=s[i-1])same=0;
		if(same)
		{
			cout<<s2;
			return 0;
		}
		s=s2;
	}
	return 0;
}

Measured memory_bytes: 256
import com.sun.source.util.Trees;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<Integer> list = new HashSet<>();
		Set<Integer> delList = new HashSet<>();
		for (int i = 0; i < n; i++) {
			int num = sc.nextInt();
			if (list.contains(num)) {
				delList.add(num);
			} else {
				list.add(num);
			}
		}
		int max = Collections.max(list);
		boolean[] array = new boolean[max * 2 + 100];
		for (int tmp : list) {
			for (int j = tmp * 2; j < max * 2 + 100; j += tmp) {
				array[j] = true;
			}
		}
		list.removeAll(delList);
		int count = 0;
		for (int num : list) {
			if (!array[num]) {
				++count;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 69780
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <numeric>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
    int a, b, c, k; cin >> a >> b >> c >> k;

    int sum = 0;
    if (k >= a) {
        sum += a;
    } else {
        sum += k;
        cout << sum << endl;
        return 0;
    }
    if (k - a >= b) {
        sum += 0;
    } else {
        sum += 0;
        cout << sum << endl;
        return 0;
    }
    if (k - a - b>= c) {
        sum -= c;
    } else {
        sum -= (k - a - b);
        cout << sum << endl;
        return 0;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3192
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n,cnt=0;
	bool flag = true;;
	cin >> n;
	vector<int>garden(n);
	rep(i, n)cin >> garden[i];
	while (flag) {
		flag = false;
		rep(i, n) {
			if (garden[i] != 0) {
				flag = true;
				garden[i]--;
				for (i = i + 1; i < n; i++) {
					if (garden[i] == 0)break;;
					garden[i]--;
				}
				cnt++;
			}
		}

	}

	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 3608
/********************************************************************
* @file stuck.cpp
* @brief stackライブラリを使用したサンプルソース
* @date 2020/06/09
* @version 1.0
* @note 入力された数式をスタックにより処理する
* @par サンプルソース作成
*********************************************************************/

#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
using namespace std;

int main(){

    queue<pair<string, int>> Q;
    int n, q, process_time, time=0;
    string process_name;

    cin >> n >> q;

    for(int i=0; i<n; i++){
        cin >> process_name >> process_time;
        Q.push(make_pair(process_name, process_time));
    }

    pair<string, int> process_pair;

    while(!Q.empty()){
        process_pair = Q.front();
        Q.pop();
        if(process_pair.second<=q){
            cout << process_pair.first << " " << process_pair.second+time << endl;
            time += process_pair.second;
        }else{
            process_pair.second -= q;
            Q.push(make_pair(process_pair.first, process_pair.second));
            time += q;
        }
    }

    return 0;
}


Measured memory_bytes: 6260
#include <bits/stdc++.h>
using namespace std;
#define mem(x,v) memset(x,v,sizeof(x))
#define low(x) (x & (-x))
#define ll long long
const int N = 300000;
int c[N],n,k;
ll b[N],d[N];
map<long long,int> mp;

void add(int x){
    while(x <= n + 1){
        c[x]++;
        x += low(x);
    }
    return;
}
ll sum(int x){
    ll m = 0;
    while(x > 0){
        m += c[x];
        x -= low(x);
    }
    return m;
}
int main() {
    ll ans = 0;
    int x;
    scanf("%d%d",&n,&k);
    for (int i = 1; i <= n; i++){
        scanf("%d",&x);
        d[i] = b[i] = b[i-1] + x - k; //计算 x 求和 除以 k*i； 然后就是求比当前数小的、
    }
    int tt = 1;
    sort(b,b + n + 1);
    for (int i = 0; i <= n; i++)
        if (!mp[b[i]]) mp[b[i]] = tt++;
    for (int  i= 0; i <= n; i++){
        ans += sum(mp[d[i]]); //处理 0 的情况。
        add(mp[d[i]]);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 17152
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,m;
    cin>>n>>m;
    vector<ll> a(n),b(n),c(m),d(m);
    rep(i,n) cin>>a[i]>>b[i];
    rep(i,m) cin>>c[i]>>d[i];
    int ans;
    rep(i,n){
        ll mini=1000000000;
        rep(j,m){
            ll dx=abs(a[i]-c[j]),dy=abs(b[i]-d[j]);
            if(mini>dx+dy){
                mini=dx+dy;
                ans=j+1;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H;
    cin >> H;
    ll num = 1;
    ll ans = 0;
    while (H > 0) {
        ans += num;
        H /= 2;
        num *= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
town = Array.new(4) { 0 }

3.times do
  a, b = gets.split.map(&:to_i)
  town[a - 1] += 1
  town[b - 1] += 1
end

one = 0
two = 0
town.each do |t|
  if t == 1
    one += 1
  elsif t == 2
    two+= 1
  end
end

if one == 2 && two == 2
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 1788
# include <bits/stdc++.h>
using namespace std;
# define pb push_back
const int N = 100005;
typedef long long i64;

int vis[N], k[N];

int main ()
{
    int n, m, p;
    char s[5];
    cin >> n >> m;
    int ans1 = 0, ans2 = 0;
    for (int i = 1; i <= m; ++i) {
        cin >> p >> s;
        if (s[0] == 'W') {
            if (vis[p] == 0) ++k[p];
        }
        else {
            if (vis[p] == 0) {++ans1; vis[p] = 1; ans2+=k[p];}
        }
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
x = int(raw_input())

count = 0
for i in range(a+1):
	if (500*i) > x:
		break
	for j in range(b+1):
		if (500*i + 100*j) > x:
			break
		for k in range(c+1):
			if (500*i + 100*j + 50*k) > x:
				break
			if (500*i + 100*j + 50*k) == x:
				count = count + 1

print str(count)

Measured memory_bytes: 2568
import itertools
import math

n = int(input())

location = [list(map(int, input().split())) for _ in range(n)]

pmt = list(itertools.permutations(range(0, n)))

dis_sum = 0

for i in pmt:
    dis = 0
    for j in range(n-1):
        x1, y1 = location[i[j]]
        x2, y2 = location[i[j+1]]
        dis += math.sqrt((x1-x2)**2 + (y1-y2)**2)
    dis_sum += dis

print(dis_sum/len(pmt))





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

const long long MOD = 1000000007;

long long n, m, p;

int main() {
	cin >> n >> m;
	if (n < m) swap(n, m);
	if (n - m > 1) cout << 0 << endl;
	else {
		if (n == m) p = 2;
		else p = 1;
		for (long long i = 2; i <= n; ++i)
			p = p * i % MOD;
		for (long long i = 2; i <= m; ++i)
			p = p * i % MOD;
		cout << p << endl;
	}
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    println!("{}{}", 2018, &s[4..]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;

const int N = 1000+5;
const int M = 20000+5;

LL dp[N][M];

struct data {
    int w, s, v;
    bool operator< (data b) {return w+s < b.w + b.s;}
};

data a[N];

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

    for (int i=1; i<=n; i++)
        cin>>a[i].w>>a[i].s>>a[i].v;

    sort(a+1, a+n+1);
    for (int i=1; i<=n; i++) {
        for (int j=0; j<M; j++)
            dp[i][j] = dp[i-1][j];

        for (int j=0; j<=a[i].s; j++)
            dp[i][j+a[i].w] = max(dp[i][j+a[i].w], dp[i-1][j] + a[i].v);
    }

    long long ans = 0;
    for (int i=0; i<M; i++)
        ans = max(ans, dp[n][i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 156672
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)

int maxlong(int a,int b){
  if(a>b) return a;
  else return b;
}

signed main(){
  int a,b;
  cin>>a>>b;
  if(a==1&&b==1){
    cout<<1<<endl;
    return 0;
  }
  if(a==1||b==1){
    cout<<maxlong(a+b-3,0)<<endl;
    return 0;
  }
  int ans=maxlong((a-2),0)*maxlong(b-2,0);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut buf: String = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n: i32 = buf.trim().parse::<i32>().unwrap();
    let mut mochi: Vec<i32> = Vec::new();
    for _ in 0..n {
        let mut buf: String = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let m: i32 = buf.trim().parse::<i32>().unwrap();
        mochi.push(m);
    }
    mochi.sort();
    mochi.dedup();
    println!("{}", mochi.len());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,X;
    ll m[110];
    cin >> N >> X;
    rep(i,0,N) cin >> m[i];
    sort(m, m+N);
    rep(i,0,N) X -= m[i];
    print(N + X / m[0]);

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, m, a;
   cin >> n >> m;
   vector<int> ctr_trans(n + 1, 0);
   vector<bool> is_hole(n + 1, false);
   for (int i = 0; i < m; i++)
   {
      cin >> a;
      is_hole[a] = true;
   }
   ctr_trans[0] = 1;
   ctr_trans[1] = (int)(!is_hole[1]);
   for (int i = 2; i <= n; i++)
   {
      if (is_hole[i])
         continue;
      else
         for (int j = i - 1; j >= max(0, i - 2); j--)
            ctr_trans[i] = (ctr_trans[i] + ctr_trans[j]) % INF;
   }
   cout << ctr_trans[n] << endl;
   return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int tc; cin>>tc; while(tc--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
long long MOD = 1e9 + 7;
double PI = 4*atan(1);


ll poow( ll n, ll e)
{
    ll ans= 1;

    for(int i=1; i<=e; i++)
    {
        ans*= n;
        ans%= MOD;
    }
    return ans%MOD;
}

int main()
{
    optimize();

    long long n;

    cin>> n;

    ll res= poow(10LL, n ) % MOD;
    res-= (2 * (poow( 9LL, n)- MOD) );
    res%= MOD;
    res+= ( poow (8LL, n));   ////subtracting the overlap to prevent double counting [minus* minus= plus]
    res%= MOD;
    cout << res;
    nl;

    return 0;
}



//∣AUB∣ = ∣A∣ + ∣B∣ − ∣A∩B∣ //subtracting the overlap to prevent double counting
//
//A = Set of sequences that does not contain 0
//
//B = Set of sequences that does not contain 9
//
//n(A) = n(B) = pow(9,n)
//
//n(A intersection B) = pow(8,n)




Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#include <cmath> 
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;   
int main()  
{ 
    int a,b,c;
    cin>>a>>b>>c;
    int d,e,f;
    int ans;
    d=max(max(a,b),c);
    e=min(min(a,b),c);
    f=a+b+c-d-e;
    if(e%2==f%2)ans=(d-f)+(f-e)/2;
    else ans=ans=(d-f)+(f-e)/2+2;
    cout<<ans<<endl;
//    system("pause");
    return 0;
}


Measured memory_bytes: 256
# B - String Rotation
# https://beta.atcoder.jp/contests/abc103/tasks/abc103_b

# B_String_Rotation_2.py

S = input()
T = input()

def judge(S,T):
    length = len(S)
    if length != len(T):
        return "No"
    else:
        for i in range(0, length):
            S_rotated = S[length-i:] + S[:length-i]
            if S_rotated == T:
                return "Yes"
        return "No"
print(judge(S,T))


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

using namespace std;

typedef long long LL;
typedef pair<int,int> pi;
typedef vector<int> vi;
#define ST first
#define ND second
#define PB push_back
#define DET(a,b,c) (LL(b.x-a.x)*LL((c.y-a.y))-LL((c.x-a.x))*LL((b.y-a.y)))

const int MOD = 1000*1000*1000+7;
string K;
int D,len;
int dp[101][2];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>K>>D;
    len = K.size();
    dp[0][0] = 1;
    for(int pos=0; pos<len; pos++) {
        int tmp[101][2];
        for(int sum=0; sum<D; sum++) {
            for(bool smaller:{0,1}) {
                tmp[sum][smaller] = 0;
            }
        }
        for(int sum=0; sum<D; sum++) {
            for(int smaller=0; smaller<2; smaller++) {
                for(int digit=0; digit<10; digit++) {
                    if(!smaller&&(digit>K[pos]-'0')) break;
                    tmp[(sum+digit)%D][smaller||(digit<K[pos]-'0')]+=dp[sum][smaller];
                    tmp[(sum+digit)%D][smaller||(digit<K[pos]-'0')]%=MOD;
                }
            }
        }
        for(int sum=0; sum<D;sum++) {
            for(bool smaller:{0,1}) {
                dp[sum][smaller] = tmp[sum][smaller];
                //cout<<pos<<" "<<sum<<" "<<smaller<<" "<<dp[sum][smaller]<<"\n";
            }
        }
    }
    int ans = (dp[0][0]+dp[0][1])%MOD;
    ans = (ans-1+MOD)%MOD;
    cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    string s; cin>>s;
    int ans=0;

    if(s[0]=='A') ans++;
    int cnt=0;
    rep(i,2,s.size()-1){
        if(s[i]=='C'){
            cnt++;
            s[i]='c';
        }
    }
    // cout<<s<<endl;
    if(cnt==1) ans++;
    // cout<<ans<<endl;
    bool ok=true;
    rep(i,1,s.size()){
        if(s[i]>'Z'){
            continue;
        }else ok=false;
    }
    // if('C'<'A') cout<<"Yes"<<endl;
    if(ok) ans++;

    if(ans==3) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
}

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

int main() {
  long n,k,x,y,ans,dataid;
  string c;
  cin >> n >> k;
  vector<vector<long>> data(n);
  vector<long> zougen(k);
  for(long i=0;i<n;i++) {
    cin >> x >> y >> c;
    if((x/k+y/k)%2==0) {
      if(c=="W") data[i]={x%k,y%k,1};
      else data[i]={x%k,y%k,0};
    } else {
      if(c=="W") data[i]={x%k,y%k,0};
      else data[i]={x%k,y%k,1};
    }
  }
  for(long i=0;i<n;i++) {
    if(data[i][2]==1) {
      zougen[0]++;
      if(data[i][1]!=0) zougen[k-data[i][1]]--;
    } else {
      if(data[i][1]!=0) zougen[k-data[i][1]]++;
    }
  }
  sort(data.begin(),data.end());
  dataid=n-1;
  for(long i=0;i<k;i++) {
    long aaa=0;
    if(dataid>=0) {
      while(data[dataid][0]==k-i) {
        if(data[dataid][2]==1) {
          zougen[0]--;
          if(data[dataid][1]!=0) zougen[k-data[dataid][1]]+=2;
        } else {
          zougen[0]++;
          if(data[dataid][1]!=0) zougen[k-data[dataid][1]]-=2;
        }
        dataid--;
        if(dataid<0) break;
      }
    }
    for(long j=0;j<k;j++) {
      aaa+=zougen[j];
      ans=max(ans,aaa);
      ans=max(ans,n-aaa);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>
#include <climits>

using namespace std;

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

int main() {
    int x, y, z, k;
    scanf("%d %d %d %d", &x, &y, &z, &k);
    vector<ll> a(x), b(y), c(z);
    for (int i = 0; i < x; ++i) {
        scanf("%lld", &a[i]);
    }
    for (int i = 0; i < y; ++i) {
        scanf("%lld", &b[i]);
    }
    for (int i = 0; i < z; ++i) {
        scanf("%lld", &c[i]);
    }

    priority_queue<ll, vector<ll>, greater<ll>> q;
    for (int i = 0; i < x; ++i) {
        for (int j = 0; j < y; ++j) {
            q.push(a[i] + b[j]);
            if (q.size() > 3000) {
                q.pop();
            }
        }
    }

    vector<ll> d;
    while (!q.empty()) {
        d.push_back(q.top());
        q.pop();
    }

    int t = d.size();
    for (int i = 0; i < z; ++i) {
        for (int j = 0; j < t; ++j) {
            q.push(c[i] + d[j]);
            if (q.size() > 3000) {
                q.pop();
            }
        }
    }

    vector<ll> e;
    while (!q.empty()) {
        e.push_back(q.top());
        q.pop();
    }

    int ez = e.size();
    for (int i = 0; i < k; ++i) {
        printf("%lld\n", e[ez - 1 - i]);
    }
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli A,B=0,C=0,D=0,F=0;
  string S,T;
  cin >> S >> T;
  A=S.size();
  B=T.size();
  if(A>B)Out("GREATER");
  else if(S==T)Out("EQUAL");
  else if(B>A)Out("LESS");
  else if(S>T)Out("GREATER");
  else Out("LESS");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int H,W;

int dist[22][22][22][22];
const int INF=1e8;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main(){
  cin>>H>>W;
  vector<string> S(H);
  rep(i,H) cin>>S[i];

  rep(i,H) rep(j,W) rep(k,H) rep(l,W) dist[i][j][k][l]=INF;
  rep(i,H) rep(j,W){
    if(S[i][j]=='#') continue;
    dist[i][j][i][j]=0;
    for(int k=0;k<4;k++){
      int nx=i+dx[k];
      int ny=j+dy[k];
      if(nx<0||ny<0||nx>=H||ny>=W) continue;
      if(S[nx][ny]=='.') dist[i][j][nx][ny]=1;
    }
  }

  rep(i,H) rep(j,W){
    rep(k,H) rep(l,W){
      rep(a,H) rep(b,W){
        dist[k][l][a][b]=min(dist[k][l][a][b],dist[k][l][i][j]+dist[i][j][a][b]);
      }
    }
  }

  int ans=0;
  rep(i,H) rep(j,W) rep(k,H) rep(l,W){
    if(dist[i][j][k][l]==INF) continue;
    ans=max(ans,dist[i][j][k][l]);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
using namespace std;
int main()
{
    double x, t;
    cin >> x >> t;
    cout << setprecision(4) << x / t << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,M;
int ax[20],ay[20];
int main(){
  while(1){
    cin>>N;
    if(N==0)break;
    for(int i=0;i<N;i++)cin>>ax[i]>>ay[i];
    cin>>M;
    int px=10,py=10,cnt=0;
    for(int i=0;i<M;i++){
      char ch;
      int num;
      cin>>ch>>num;
      for(int j=0;j<num;j++){
        if(ch=='N')py++;
        if(ch=='E')px++;
        if(ch=='S')py--;
        if(ch=='W')px--;
        for(int k=0;k<N;k++){
          if(ax[k]==px&&ay[k]==py){
            cnt++;
            ax[k]=-1;
            ay[k]=-1;
          }
        }
      }
    }
    if(cnt==N)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  int mn = 0;
  int now = 0;
  rep(i,S.size()){
    if(S[i] == ')') now--;
    else now++;
    mn = min(mn, now);
  }

  string ret = "";
  mn *= -1;
  rep(i,mn) ret += "(";
  rep(i,S.size()) ret += S[i];
  rep(i,abs(now+mn)) ret += ")";

  cout << ret << endl;
  
  return 0;
}

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

int main(void){
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    string t = "";
    rep(i, s.size()){
        t += s[i];
        if(t == "maerd") t = "";
        else if(t == "remaerd") t = "";
        else if(t == "esare") t = "";
        else if(t == "resare") t = "";
    }
    if(t == "") cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10000)
def resolve():
    A, B, C, X, Y = list(map(int, input().split(" ")))
    if A + B < 2 * C:
        print(A*X+B*Y)
        return
    if X < Y:
        m = min((Y-X)*B, 2*(Y-X)*C)
        print(2*X*C+m)
        return
    else:
        m = min((X-Y)*A, 2*(X-Y)*C)
        print(2*Y*C+m)
        return

    
    
if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38384
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

const p = 1000000007

func main() {
  N := NextInt()
  A := NextIntVec()
  B := make([][]int, N)
  for i, a := range A {
    B[i] = make([]int, 60)
    for j := range B[i] {
      B[i][j] = a % 2
      a /= 2
    }
  }
  ans := 0
  for j := 0; j < 60; j++ {
    b := make([]int, 2)
    for i := range B {
      b[B[i][j]]++
    }
    ans += (1 << uint(j)) % p * (b[0] * b[1] % p) % p
    ans %= p
  }
  Write(ans)
  Output()
}

Measured memory_bytes: 161640
#include <stdio.h>

int main(){
	int n;
	scanf("%d" ,&n);
	char str[n + 1];
	scanf("%s" ,str);
	if(n % 2 == 1){
		puts("No");
	}
	else if(n % 2 == 0){
		int flag = 1;
		for(int i = 0; i < n / 2; i++){
			if(str[i] != str[i + n / 2]){
			flag = 0;
			}
		}
		if(flag == 0){
			puts("No");
		}
		else if(flag == 1){
			puts("Yes");
		}
	}
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  for(double i=1;i<1251;i++){
    if( (int)(i*0.08) == a && (int)(i*(0.1)) == b ){
      cout << (int)i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int N; cin >> N;
  long long A, B;
  long long tempa, tempb;
  long long m;
  cin >> A >> B;
  for (int i = 1; i<N; i++){
    cin >> tempa >> tempb;
    m = max((B-1)/tempb+1, (A-1)/tempa+1);
    A = m*tempa;
    B = m*tempb;
  }
  cout << A + B << endl;
}


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

const int maxn = 1e5+5;
int n, u, v;
vector<int> adj[maxn];
int d1[maxn], d2[maxn];

pair<int,int> furthest = {-1,-1};
bool seen[maxn];
void dfs(int i, int d) {
    furthest = max(furthest,{d2[i],i});
    seen[i] = true;
    for (int j: adj[i]) {
        if (d1[j] < d2[j] && !seen[j]) {
            dfs(j,d+1);
        }
    }
}

int main() {
    cin >> n >> u >> v;
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        d1[i] = maxn;
        d2[i] = maxn;
    }
    d1[u] = 0;
    d2[v] = 0;
    q.push(u);
    while (!q.empty()) {
        int f = q.front(); q.pop();
        for (int j: adj[f]) {
            if (d1[j] > d1[f] + 1) {
                d1[j] = d1[f] + 1;
                q.push(j);
            }
        }
    }
    q.push(v);
    while (!q.empty()) {
        int f = q.front(); q.pop();
        for (int j: adj[f]) {
            if (d2[j] > d2[f] + 1) {
                d2[j] = d2[f] + 1;
                q.push(j);
            }
        }
    }
    dfs(u,0);
    int ans = d1[furthest.second];
    int d = d2[furthest.second] - d1[furthest.second];
    for (int i = 0; ; i++) {
        if (i % 2 == 0) {
            if (i % 4 == 0) d--;
            else d++;
        }
        else {
            d--;
            ans++;
        }
        if (d == 0) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, k;
    cin >> n >> k;
    vec v(n);
    rep(i, n) cin >> v[i];

    int res = 0;

    for (int a = 0; a <= min(n, k); a++) {
        for (int b = 0; a + b <= min(n, k); b++) {
            priority_queue<int, vec, greater<int>> que;
            int tres = 0;

            for (int i = 0; i < a; i++) que.push(v[i]);
            rep(i, b) que.push(v[n-1-i]);

            rep(i, k-a-b) if (!que.empty() && que.top() < 0) que.pop();

            while (!que.empty()) {
                tres += que.top();
                que.pop();
            }

            res = max(res, tres);
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
        int x,y;
        
        scanf("%d %d",&x,&y);
        
		//xとyが0ではない間
        while(!(x == 0 && y == 0)){
                //xがy以下のとき
                if(x <= y){
                	//そのまま
                        printf("%d %d\n",x,y);
                }
			//xがyより大きいとき
                else{
                	//入れ替え
                        printf("%d %d\n",y,x);
                }
                scanf("%d %d",&x,&y);
        }
        return 0;
}


Measured memory_bytes: 2068
#

import sys
input=sys.stdin.readline

def main():
    N = int(input())
    R = [tuple(map(int, input().split())) for i in range(N)]
    A = sorted(R, key = lambda x: x[0] + x[1])
    B = sorted(R, key = lambda x: x[0] - x[1])
    a = abs(A[-1][0] - A[0][0]) + abs(A[-1][1] - A[0][1])
    b = abs(B[-1][0] - B[0][0]) + abs(B[-1][1] - B[0][1])
    print(max(a, b))
    
    
    
if __name__=="__main__":
    main()


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

int main() {
  int N, n;
  cin >> N;
  n = N;
  for (int i = 0; i < 9; i++) {    
  int x;      
    x += n % 10;
    n /= 10;
    if (i == 8){
  if ( N % x == 0){
    cout << "Yes" << endl;}
  else{
    cout << "No" << endl;}
    }
  }
}

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

using namespace std;

bool isPrime( int n )
{
	if ( n < 2 )
	{
		return false;
	}

	for ( int i = 2; i <= sqrt( n ); i++ )
	{
		if ( !( n % i ) )
		{
			return false;
		}
	}

	return true;
}

int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( n == 0 )
		{
			break;
		}

		int sum = 0;

		for ( int i = 2, count = 0; count < n; i++ )
		{
			if ( isPrime( i ) )
			{
				sum += i;
				count++;
			}
		}

		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 868
module Main where

import           Control.Monad
import           Data.Array.IO
import           Data.List
import           Data.List.Split
import           Data.Ord
import qualified Data.Vector.Unboxed as V
import           Text.Printf

main :: IO ()
main = do
  [a,b] <- map read . words <$> getLine :: IO [Int]
  print $ a - b + 1




Measured memory_bytes: 508
def judge():
    H,W=map(int,input().split())

    field=[]
    field.append("."*(W+2))
    for i in range(H):
        field.append("." + input() + ".")
    field.append("."*(W+2))
    for i in range(1,H+1):
        for j in range(1,W+1):
            if(field[i][j]=="#"):
                if(field[i-1][j]=="#" or field[i+1][j]=="#" or field[i][j-1]=="#" or field[i][j+1]=="#"):
                    pass
                else:
                    print("No")
                    return 0
    print("Yes")


judge()

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

int main() {
  int H,W;
  cin>>H>>W;
  vector<string> S(H);
  for(int i=0;i<H;i++){
    cin>>S[i];
  }
  vector<vector<int>> G(H,vector<int>(W));
  
  int ans=0;
  int num,before;

  for(int h=0;h<H;h++){
    num=1;
    before=0;
    for(int w=1;w<W;w++){
      if(S[h][w-1]!=S[h][w]){
        if (S[h][w-1]=='#'){
          G[h][w-1]=-1;
          before+=1;
        }else{
          for(int n=before;n<num+before;n++){
            G[h][n]=num;
          }
          before+=num;
          num=1;
        }
      }else{
        if (S[h][w-1]=='#'){
          G[h][w-1]=-1;
          before+=1;
        }else{
          num+=1;
        }
      }
    }
    if (S[h][W-1]=='#'){
      G[h][W-1]=-1;
    }else{
      for(int n=before;n<num+before;n++){
        G[h][n]=num;
      }
    }
  }



  for(int w=0;w<W;w++){
    num=1;
    before=0;
    for(int h=1;h<H;h++){
      if(S[h-1][w]!=S[h][w]){
        if (S[h-1][w]=='#'){
          before+=1;
        }else{
          for(int n=before;n<num+before;n++){
            G[n][w]+=num;
            ans=max(ans,G[n][w]);
          }
          before+=num;
          num=1;
        }
      }else{
        if (S[h-1][w]=='#'){
          G[h-1][w]=-1;
          before+=1;
        }else{
          num+=1;
        }
      }
    }
    if (S[H-1][w]=='#'){
      continue;
    }else{
      for(int n=before;n<num+before;n++){
        G[n][w]+=num;
        ans=max(ans,G[n][w]);
      }
    }
  }
  cout<<ans-1<<endl;  
}

Measured memory_bytes: 20096
import java.util.Scanner;
public class Main{
 public static void main (String[] args){
  Scanner sc = new Scanner(System.in);
 int a = sc.nextInt();
 int b = sc.nextInt();

   int area = a*b;
   int length = 2*a + 2*b;

System.out.println(area + " " + length);
}
}


Measured memory_bytes: 26280
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cstring>
#include <algorithm>
#include <vector>
//#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <map>
#include <numeric>
using namespace std;
#define fin << '\n'
#define finl << '\n';
#define finn cout << '\n'
#define unless(flg) if(!(flg))
#define alles(obj) obj.begin(), obj.end()
// bashise
#define elif else if
#define echo cout <<
#define read cin >>
// javaise
#define bash push_back
#define makePair make_pair
#define isEmpty empty
// germanise
#define drucken(obj) cout << obj << '\n'
#define lesen(obj) cin >> obj
#define fur for
#define wenn if
#define sonst else
#define Zahl int
// type-define
#define String string
#define Stack stack
#define Queue queue
#define pQueue priority_queue
#define Vector vector
#define Pair pair
#define Map map
typedef long long llong;
typedef bool boolean;
typedef Pair<int,int> Pii;
typedef Vector<int> Vi;
// utils
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
boolean isMovable(int x,int y,int w,int h){return (x>=0&&y>=0&&x<w&&y<h);};
const int INF = 1 << 29;

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

    int a[3];
    for ( int i = 0; i < 3; i++ ) {
        read a[i];
    }
    sort(a, a+3);
    echo a[0] + a[1] + a[2]*10 fin;


    return 0;
}


Measured memory_bytes: 256
/**
*	created: 29.08.2020 21:18:40
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template<typename T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

// UnionFind
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n,-1) {}
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x,y);
        par[x] += par[y]; par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);}
    int size(int x) {return -par[root(x)];}
};

signed main() {
    int n, m; cin >> n >> m;
    UnionFind uf(n);
    rep(i,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    int ans = -1;
    rep(i,n) chmax(ans,uf.size(i));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4760
h,w=map(int,input().split())

m=0 if h%3==0 else w
n=0 if w%3==0 else h
m=min(m,n)
for i in range(1,w):
    s=sorted([h*i,(h//2)*(w-i),h*w-h*i-(h//2)*(w-i)])
    m=min(m,s[2]-s[0])
for i in range(1,h):
    s=sorted([w*i,(w//2)*(h-i),h*w-w*i-(w//2)*(h-i)])
    m=min(m,s[2]-s[0])
print(m)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _cin      ios_base::sync_with_stdio(0);  cin.tie(0);
#define READ      freopen("input.txt", "r", stdin);
#define WRITE     freopen("output.txt", "w", stdout);
#define endl "\n"
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<ll> >
#define vll vector<ll>
#define mll map<ll,ll>
#define sz(x) (ll)x.size()
#define sll set<ll>
#define pll pair<ll,ll>
#define F first
#define S second
const ll MAX = 1000004;
const ll INF = 1e18L + 5;


int main() {

	_cin
	// READ
	// WRITE
	ll n, k;
	cin >> n >> k;
	ll a[n + 1];
	rep(i, 1, n + 1) cin >> a[i];
	ll dp[n + 1][k + 1];
	dp[0][0] = 1;
	rep(i, 1, k + 1) dp[0][i] = 0;
	rep(i, 1, n + 1) {
		vll sum(k + 1, 0);

		sum[0] = dp[i - 1][0] ;
		rep(j, 1, k + 1) sum[j] = (sum[j - 1] + dp[i - 1][j]) % hell ;
		rep(j, 0, k + 1) {
			if (j <= a[i]) {
				dp[i][j] = sum[j];
			} else {
				ll s = (j - a[i] - 1);
				dp[i][j] = (sum[j] - sum[s] + hell) % hell  ;

			}
		}

		sum.clear();

	}

	cout << dp[n][k] % hell << endl;





}

Measured memory_bytes: 83320
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int N;
LL A[100000];

int main(void){
    cin>>N;
    REP(i,N)
        cin>>A[i];
    LL ans=0;
    REP(i,N){
        ans+=A[i]/2;
        if(i<N-1&&0<A[i+1]&&A[i]%2==1){
            ans++;
            A[i+1]--;
        }
    }
    cout<<ans<<endl;
     return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

string sub(int n) {
	string ret = "";
	string num = to_string(n);
	for (int i = 0; i < 6 - num.size(); i++) {
		ret += '0';
	}
	return ret + num;
}

int binarySearch(vector<int> vec, int key) {
	int L, R, M;
	L = 0;
	R = vec.size();
	M = (L + R) / 2;
	while (L <= R) {
		if (vec[M] == key) {
			return ++M;
		}
		else if (key < vec[M]) {
			R = M;
			M= (L + R) / 2;
		}
		else {
			L = M + 1;
			M = (L + R) / 2;
		}
	}
}

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

	struct Info {
		int p;
		int y;
	};

	vector<struct Info> v(M);
	vector<vector<int>> prf(N, vector<int>(0));

	for (int i = 0; i < M; i++) {
		int P, Y;
		cin >> P >> Y;
		v.at(i).p = P;
		v.at(i).y = Y;
		prf.at(P - 1).push_back(Y);
	}

	for (int i = 0; i < N; i++) {
		sort(prf.at(i).begin(), prf.at(i).end());
	}

	for (int i = 0; i < M; i++) {
		int P, Y;
		P = v.at(i).p;
		Y = v.at(i).y;
		//cout << P << ' ' << Y << endl;
		int n = binarySearch(prf.at(P - 1), Y);
		cout << sub(P) << sub(n) << endl;
	}
}

Measured memory_bytes: 9496
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

k = [0] * N
j = 0
for i in range(N):
    while j != N and B[i] >= C[j]:
        j += 1
    k[i] = N - j

z = list(accumulate(k[::-1]))[::-1] + [0]

ans = 0
j = 0
for i in range(N):
    while j != N and A[i] >= B[j]:
        j += 1
    ans += z[j]

print(ans)
        

Measured memory_bytes: 25420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var nkq = Input3();
            var res = new long[nkq[0]+1];

            for (long i = 0; i < nkq[2]; i++)
            {
                long a = long.Parse(Console.ReadLine());
                res[a]++;
            }

            for(long j = 1; j <= nkq[0]; j++)
            {
                if (nkq[1] + res[j] - nkq[2] > 0) Console.WriteLine("Yes");
                else Console.WriteLine("No");
            }

           // Console.WriteLine(ans);


        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  string foo = "";
  int qq;
  cin >> qq;
  bool ok = false;
  while (qq--) {
    int x;
    cin >> x;
    if (x == 1) {
      ok ^= 1;
    } else {
      int y;
      char z;
      cin >> y >> z;
      if (y == 1) {
        if (ok) {
          s += z; 
        } else {
          foo += z;
        }
      } else {
        if (ok) {
          foo += z;
        } else {
          s += z;
        }
      }
    } 
  }
  reverse(foo.begin(), foo.end());
  for (int i = 0; i < (int)s.size(); i++) {
    foo += s[i];
  }
  if (ok) reverse(foo.begin(), foo.end());
  cout << foo << '\n';
  return 0;
}

Measured memory_bytes: 1108
#include <stdio.h>

int main() {
	int a[4], b[4], i, j, hit, blow;
	while (scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]) != EOF) {
		scanf("%d %d %d %d", &b[0], &b[1], &b[2], &b[3]);
		hit = 0;
		blow = 0;
		for (i = 0; i < 4; i++) {
			if (a[i] == b[i]) hit++;
			for (j = 0; j < 4; j++) {
				if (a[i] == b[j] && a[i] != b[i]) blow++;
			}
		}
		printf("%d %d\n", hit, blow);
	}
	return 0;
}

Measured memory_bytes: 596