akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define eb emplace_back
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define P 3000  //check the limits, man
#define N 100005
const ll INF = 1e18;
int ar[N][20];
int main()
{
    int n,i,k,a,b,x,q;
    in(n);
    vi v(n);
    read(v,i,n);
    in(x);
    for(i=n-1;i>=0;i--)
    {
        ar[i][0]=upper(v,v[i]+x);
        if(ar[i][0]<n)
            ar[i][0]--;
        lp(k,1,20)
        {
            if(ar[i][k-1]<n)
                ar[i][k]=ar[ar[i][k-1]][k-1];
            else
                ar[i][k]=n;
        }
    }
    in(q);
    while(q--)
    {
        in2(a,b);
        if(a>b)
            swap(a,b);
        a--,b--;
        x=0;
        for(k=19;k>=0;k--)
        {
            if(ar[a][k]<=b)
                a=ar[a][k],x+=(1<<k);
        }
        if(a<b)
            x++;
        out(x);
    }
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> ans(n,0);
  for(int i = 1; i < n; ++i){
    for(int j = i + 1; j <= n; ++j){
      ans[min(j - i, abs(x - i) + abs(y - j) + 1)]++;
     // cout << ans[1] << " " << ans[2] << " " << ans[3] << " " << ans[4] << endl;
    }
  }
  for(int i = 1; i < n; ++i) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 	string s;
  	cin>>s;
  	int n=s.size();
  	vector<vector<long long int>> dp(n,vector<long long int>(13));
  	
    if(s[0]=='?')
    {
        for(int i=0;i<10;i++)
        {
            dp[0][i]=1; 
        }
    }
    else
    {
        dp[0][s[0]-'0']=1;
    }
    
  	for(int i=1;i<n;i++)
    {
        for(int j=0;j<13;j++)
        {
            for(int l=0;l<13;l++)
            {
                if(s[i]=='?')
                {
                    for(int k=0;k<10;k++)
                    {
                        if((l*10+k)%13==j)
                        {
                            dp[i][j]+=dp[i-1][l];
                            dp[i][j]=dp[i][j]%1000000007;
                        }
                    }
                }
                else
                {
                    if((l*10+(s[i]-'0'))%13==j)
                    {
                        dp[i][j]+=dp[i-1][l];
                        dp[i][j]=dp[i][j]%1000000007;
                    }
                }
            }    
        }
    }
    cout<<dp[n-1][5]<<endl;
    return 0;
}

Measured memory_bytes: 13696
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	string S;
  
  cin>>S;
  vector<int> al(26);
  
  for(int i=0;i<S.size();++i){
   
    al[S[i]-'a']++;
    
    
  }
  
  if(*max_element(al.begin(),al.end())<=1){
  cout<<"yes"<<endl;
  }else{
    cout<<"no"<<endl;
  }
  
  
}


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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define MOD 1000000007

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

    map<char, int> ms, mt;
    for(int i = 0; i < s.size(); i++) {
        ms[s[i]]++;
        mt[t[i]]++;
    }

    vector<int> vs, vt;
    for(auto p : ms) {
        vs.push_back(p.second);
    }
    for(auto p : mt) {
        vt.push_back(p.second);
    }

    sort(vs.begin(), vs.end());
    sort(vt.begin(), vt.end());

    bool result = true;
    if(vs.size() == vt.size()) {
        REP(i, vs.size()) {
            if(vs[i] != vt[i]) {
                result = false;
                break;
            }
        }
    } else {
        result = false;
    }

    if(result) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int last = S.size();
  char las = S.at(last - 1);
  char str1 = 's';
  string str2 = "es";
  
  if (las == str1) {
    cout << S << "es" << endl;
  }
  else {
    cout << S << "s" << endl;
  }
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		
		long sum = 0;
		for (int i = 1; i <= n; i++) {
			if (i % 3 != 0 && i % 5 != 0) {
				sum += i;
			}
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 27196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/


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

    int n, m, t; cin >> n >> m >> t;
    vector <ll> dpR(n, 0), dpC(m, 0);
    set <pair<int,int>> s;
    for (int i = 0, a, b; i < t; ++i) {
        cin >> a >> b; a--, b--;
        dpR[a]++;
        dpC[b]++;
        s.insert({a, b});
    }
    
    ll maxr = *max_element(all(dpR));
    ll maxc = *max_element(all(dpC));
    ll ans = maxr + maxc;
    set <int> r, c;
    for (int i = 0; i < n; ++i) {
        if (dpR[i] == maxr) r.insert(i); 
    }
    for (int i = 0; i < m; ++i) {
        if (dpC[i] == maxc) c.insert(i); 
    }
    
    bool ok = true;
    for (int i : r) {
        for (int j: c) {
            if (!s.count({i, j})) {
                ok = false;
                break;
            }
        }
    }
    cout << (ans - ok);

    return 0;
}



Measured memory_bytes: 50164
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let q: usize = read!();
    let mut h: usize = read!();
    let mut s: usize = read!();
    let mut d: usize = read!();
    let n: usize = read!();
    let n = n * 100;

    if q + q < h {
        h = q + q;
    }

    if h + h < s {
        s = h + h;
    }

    if s + s < d {
        d = s + s;
    }

    println!("{}", solve(n, q, h, s, d, 0));
}

fn solve(n: usize, q: usize, h: usize, s: usize, d: usize, acc: usize) -> usize {
    if n >= 200 {
        solve(n - 200, q, h, s, d, acc + d)
    } else if n >= 100 {
        solve(n - 100, q, h, s, d, acc + s)
    } else if n >= 50 {
        solve(n - 50, q, h, s, d, acc + h)
    } else if n >= 25 {
        solve(n - 25, q, h, s, d, acc + q)
    } else if n == 0 {
        acc
    } else {
        panic!("HEYHEYHEY");
    }
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())

using namespace std;

int main(){

    int c[3][3] = {};

    rep(i,3){
        int tmp1,tmp2,tmp3;

        cin >> tmp1 >> tmp2 >> tmp3;

        c[i][0] = tmp1;
        c[i][1] = tmp2;
        c[i][2] = tmp3;
    }

    bool ans = true;

    rep(j,2){
        int basediff = c[0][0 + j] - c[0][1 + j];

        rep(i,2){
            if(c[i + 1][0 + j] - c[i + 1][1 + j] != basediff){
                ans = false;
            }
        }

        if(!ans) break;
    }

    if(ans){

     rep(i,2){
        int basediff = c[0 + i][0] - c[1 + i][0];

        rep(j,2){
            if(c[0 + i][1 + j] - c[1 + i][1 + j] != basediff){
                ans = false;
            }
        }

        if(!ans) break;
    }   

    }

    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

ll dp[11234][2][10]; // i:keta, j:leading-zero, k:num
int K;
string ans;


ll dfs(int k, int zero, int num) {
	if (k == -1) {
		return !zero;
	}
	
	
	ll & res = dp[k][zero][num];
	if (~res) return res;
	res = 0;
	
	REP(i, 10) {
		if (!zero && abs(num - i) > 1) continue;
		res += dfs(k - 1, zero && i == 0, i);
	}
	chmin(res, INF);
	return res;
}

void dfs2(int k, int zero, int num) {
	if (k == -1) return;
	
	REP(i, 10) {
		if (!zero && abs(num - i) > 1) continue;
		ll cur = dfs(k - 1, zero && i == 0, i);
		
		if (cur < K) K -= cur;
		else {
			ans.push_back(i + '0');
			dfs2(k - 1, zero && i == 0, i);
			break;
		}
	}
}

int main() {
	cin >> K;
	memset(dp, -1, sizeof(dp));
	dfs(10000, true, 0);
	dfs2(10000, true, 0);
	
	int idx = 0;
	REP(i, ans.size()) if (ans[i] != '0') {
		idx = i;
		break;
	}
	ans = ans.substr(idx);
	// reverse(ALL(ans));
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  string n;
  cin >> n;

  rep(i, (int)(n.length())) {
    if(n[i] == '9') cout << '1';
    else cout << '9';
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x
	
using namespace std;
int main()
{
	
	std::ios::sync_with_stdio(false);
	
		int r;
		cin>>r;
		double ans = 2*3.14159*r;
		cout<<ans<<endl;
		
	
	return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  vector<ll> x(n);
  rep(i,n) cin >> x[i];
  ll ans = 0;
  rep(i,n){
    if(i == 0) continue;
    ans += min(b,(x[i]-x[i-1])*a);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


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

  int N, M, P;

  while(1){
  cin >> N >> M >> P;

  if(N==0 && M==0 && P==0) break;

  int X[N];
  int tot = 0;

  REP(i, N){
    cin >> X[i];
    tot += 100*X[i];
  }

  tot = tot*(100-P)/100;

  if(X[M-1] != 0 ) cout << tot/X[M-1] << endl;
  if(X[M-1] == 0) cout << 0 << endl;
}
  return 0;
}

Measured memory_bytes: 3120
s = int(input())
array = [s]
for i in range(1, 100000):
    if array[i-1] % 2 == 0:
        tmp = array[i-1]//2
        if tmp in array:
            print(i+1)
            exit()
        array.append(tmp)
    else:
        tmp = 3*array[i-1] + 1
        if tmp in array:
            print(i+1)
            exit()
        array.append(tmp)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

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

int h, w;
string fi[110];
int dist[110][110];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> h >> w;
	int wnum = 0;
	rep(i, h) {
		cin >> fi[i];
		rep(j, w) {
			if (fi[i][j] == '.')wnum++;
		}
	}
	memset(dist, -1, sizeof(dist));
	dist[0][0] = 1;
	queue<P> que;
	que.push(P(0, 0));
	while (!que.empty()) {
		P cur = que.front();
		que.pop();
		int x = cur.first;
		int y = cur.second;
		rep(dir, 4) {
			int nx = x + dx[dir];
			int ny = y + dy[dir];
			if (nx < 0 || nx >= h || ny < 0 || ny >= w) {
				continue;
			}
			if (fi[nx][ny] == '#')continue;
			if (dist[nx][ny] == -1) {
				dist[nx][ny] = dist[x][y] + 1;
				que.push(P(nx, ny));
			}
		}
	}
	if (dist[h - 1][w - 1] == -1)cout << -1 << endl;
	else cout << wnum - dist[h - 1][w - 1] << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
bool seen[100000];
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

//dpTable
bool dp[100050];
int main(){
    int X;
    cin >> X;
    rep (i,106) {
        if (i == 0 || i == 100 || i == 101 || i == 102 || i == 103 || i == 104 || i == 105) dp[i] = true;
        else dp[i] = false;
    }
    for (int i = 106; i <= 100000; i++) {
        if (dp[i - 100] || dp[i - 101] || dp[i - 102] || dp[i - 103] || dp[i - 104] || dp[i - 105]) dp[i] = true;
        else dp[i] = false;
    }
    cout << (dp[X] ? 1 : 0) << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll ch[1000005];
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll out=0;
	
	for(ll i=2;i<=1000005;i++)
	{
		if(ch[i]==0)
		{
			for(ll j=i;j<1000005;j+=i)
			{
				ch[j]=1;
			}
			ll s=0;
			while(n%i==0)
			{
				n/=i;
				s++;
			}
			ll u=1;
			while(u<=s)
			{
				s-=u;
				out++;
				u++;
			}
		}
	}
	if(n>1)
	{
		out++;
	}
	cout<<out;
}

Measured memory_bytes: 11464
#include <iostream>
#include<vector>

using namespace std;
int main(void){
    int n,k;
    cin >> n >> k;
    vector<double> p(n);
    for(int i = 0;i < n;i++){
        cin >> p[i];
    }
    vector<double> a(n + 1,0);
    for(int i = 0;i < n;i++){
        a[i + 1] += a[i] + (1 + p[i]) / 2;
    }
    double ans = 0;
    for(int i = k;i <= n;i++){
        ans = max(ans,a[i] - a[i - k]);
    }
    printf("%.12f",ans);
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;

typedef pair<long long, int> P;
#define INF (1LL<<50)

int N, M;
long long X;
long long H[100100];
vector<P> edges[100100];
long long D[100100];

int main() {
  cin >> N >> M >> X;
  for (int i=0; i<N; i++) cin >> H[i];
  for (int i=0; i<M; i++) {
    int a, b, t;
    cin >> a >> b >> t;
    edges[a-1].push_back(P(t, b-1));
    edges[b-1].push_back(P(t, a-1));
  }

  for (int i=0; i<N; i++) D[i] = INF;

  priority_queue< P, vector<P>, greater<P> > q;
  q.push(P(0, 0));
  D[0] = 0;
  long long ans = -1LL;

  while (!q.empty()) {
    P p = q.top(); q.pop();
    int s = p.second;
    if (D[s] < p.first) continue;
    long long h = max(X-D[s], 0LL);

    for (P p2 : edges[s]) {
      int t = p2.second;
      long long r = p2.first;
      long long nh = h - p2.first;
      if (r > H[s]) continue;
      if (nh > H[t]) {
        r += nh - H[t];
        nh = H[t];
      }
      if (nh < 0) {
        r += abs(nh);
        nh = 0;
      }

      if (D[s] + r < D[t]) {
        D[t] = D[s] + r;
        if (t == N-1) ans = D[t] + (H[t] - nh);
        q.push(P(D[t], t));
      }
    }
  }

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

Measured memory_bytes: 23088
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

vector<vl> v;

ll modpow(ll a, ll x){
    if(x == 1) return a;
    if(x == 0) return 1;
    if(x%2 == 0){
        ll t = (modpow(a,x/2)%MOD);
        return (t*t)%MOD;
    }
    ll t = (modpow(a,x/2)%MOD);
    return (t*t*a)%MOD;
}

ll check(ll x,ll y, ll size){
    ll ans = 0;
    rep(i,x,x+size) rep(j,y,y+size){
        ans = (ans + v[i][j]*modpow(2,((i-x)*100 + (j-y))))%MOD;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,m;
    cin >> n >> m;

    rp(i,n) {
        vl temp;
        v.pb(temp);
        rp(j,n){
            char c;
            cin >> c;
            if(c == '#') v[i].pb(0LL);
            else v[i].pb(1LL);
        }
    }
    ll curH = 0;
    rp(i,m) {
        rp(j,m){
            char c;
            cin >> c;
            ll x;
            if(c == '#') x = 0;
            else x = 1;
            curH = (curH + x*modpow(2,((i)*100 + j)))%MOD;
        }
    }
    rp(i,n-m+1) rp(j,n-m+1){
         if(curH == check(i,j,m))
         {
             cout << "Yes"<<endl;
             return 0;
         }
    }
    cout << "No"<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<stdio.h>
#include<bitset>
#include<iostream>
#include<set>
#include<string.h>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<limits>
#include<math.h>
#include<string.h>

using namespace std;
  
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
 
#define pb push_back
#define ii pair<int, int> 
#define iii pair<int, ii > 
#define vai freopen("in","r",stdin);
#define inf 0x3f3f3f3f
#define f first
#define s second	

const ll INF = 1e18;
const double dinf = 12345678;       
const int mod = 1000000007;
const int maxn = 1e6;
const int MAX = 1e4 + 10;
 
 
int a, b ;
ll pa ( ll n) {
	return n * double(n+1)/2;
}


int main (){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
 
	cin >> a >> b;
	int dif = b - a;
	vector<ll>  v;
	for(int i = 0;i <= 999;i++)v.pb(pa(i));
	
	for(int i = 1 ;i < (int)v.size() ;i++)
		if ( v[i] - v[i-1] == dif){
			cout << v[i] - b << '\n'; return 0;
		}
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, h, a, num;
  cin >> n >> h;
  pql b;
  b.push(0);
  rep(_, n) {
    cin >> num;
    chmax(a, num);
    cin >> num;
    b.push(num);
  }
  
  ll ans=0;
  while(h>0) {
    ans++;
    if(a<b.top()) {
      h-=b.top();
      b.pop();
    }else h-=a;
  }
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 1400
n = int(input())
H = list(map(int, input().split()))

ans = "Yes"
for i in range(n - 1, 0, -1):
    if H[i] - H[i - 1] == 2:
        H[i] -= 1
    elif H[i - 1] - H[i] == 1:
        H[i - 1] -= 1
for i in range(1, n):
    if not(0 <= H[i] - H[i - 1]):
        ans = "No"

print(ans)

Measured memory_bytes: 14224
def i_input(): return int(input())


def i_map(): return map(int, input().split())


def i_list(): return list(i_map())


n = i_input()
h = i_list()
cost = [0] * n

for i in range(n):
    if i == 0:
        cost[i] = 0
    elif i == 1:
        cost[i] = abs(h[i] - h[i - 1])
    else:
        h_1 = abs(h[i] - h[i - 1])
        h_2 = abs(h[i] - h[i - 2])
        cost[i] = min(cost[i - 1] + h_1, cost[i - 2] + h_2)
print(cost[n - 1])


Measured memory_bytes: 20604
// +build ignore
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	A := sc.nextInt()
	B := sc.nextInt()

	if A+B < 10 {
		fmt.Println(A + B)
	} else {
		fmt.Println("error")
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n,k;
    cin >> n >> k;
    int h;
    priority_queue<int> q;
    for(int i=0;i<n;i++){
        cin >> h;
        q.push(h);
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        h = q.top();
        q.pop();
        if(i >= k) ans += h;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int Read() {
	int x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) {if(ch == '-')  f = -1; ch = getchar();}
	while(isdigit(ch)) {x = (x << 3) + (x << 1) + ch - '0'; ch = getchar();}
	return x * f;
}
int n, m, fa[1000005];
int getfa(int x) {return fa[x] == x ? x : fa[x] = getfa(fa[x]);}
signed main() {
	n = Read(), m = Read();
	for(int i = 1; i <= n; i++)  fa[i] = i;
	for(int i = 1; i <= m; i++) {
		int x = Read(), y = Read();
		int fx = getfa(x), fy = getfa(y);
		if(fx != fy)  fa[fx] = fy;
	}
	int ans = 0;
	for(int i = 1; i <= n; i++)  if(getfa(i) == i)  ++ans;
	cout << ans - 1 << endl;
	return 0;
}

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

int main(){
    int h,w;cin>>h>>w;
    char m[h+1][w+1];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>m[i][j];
        }
    }
    int j;
    for(int i=0;i<h;i++){
        for(j=0;j<w;j++){
            cout<<m[i][j];
        }
        cout<<endl;
        for(j=0;j<w;j++){
            cout<<m[i][j];
        }
        cout<<endl;
        
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int N = 200'009;

char s[N];
vector<int> g[N];
int cnt[N][2];
bool was[N];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  scanf("%s", s);
  for (int i = 0; i < n; ++i) {
    g[i].clear();
  }
  memset(cnt, 0, sizeof cnt);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x;
    --y;
    if (x == y) {
      ++cnt[x][(int)(s[x] - 'A')];
    } else {
      g[x].push_back(y);
      g[y].push_back(x);
      ++cnt[x][(int)(s[y] - 'A')];
      ++cnt[y][(int)(s[x] - 'A')];
    }
  }
  memset(was, false, sizeof was);
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    if (cnt[i][0] == 0 || cnt[i][1] == 0) {
      was[i] = true;
      a.push_back(i);
    }
  }
  int rem = n;
  while (!a.empty()) {
    vector<int> na;
    for (int x : a) {
      for (int y : g[x]) {
        if (was[y]) {
          continue;
        }
        --cnt[y][(int)(s[x] - 'A')];
        if (cnt[y][0] == 0 || cnt[y][1] == 0) {
          was[y] = true;
          na.push_back(y);
        }
      }
    }
    rem -= (int)a.size();
    a = na;
  }
  puts(rem != 0 ? "Yes" : "No");
}


Measured memory_bytes: 13052
#include<bits/stdc++.h>
#define lg long long int
using namespace std;
lg min(lg a,lg b)
{
    if(a<b)
        return a;
    else
        return b;

}
lg max(lg a,lg b)
{
    if(a>b)
        return a;
    else
        return b;

}
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n]={0};
    for(int i=0;i<k;i++)
    {
        int d;
        cin>>d;
        for(int j=0;j<d;j++)
        {
            int l;
            cin>>l;
            a[l-1]=1;
        }
    }
    int count=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
            count++;
    }
    cout<<count<<endl;
}


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

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    string s;
    cin >> s;
    int sum = 0;
    for (int i = 0; i < (int)s.size(); i++) {
        sum += (s[i]-'0');
        sum %= 9;
    }
    if (sum % 9 == 0) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion

int N,T;
vector<pair<int,int>> p;
int dp[6666];
void solve()
{
    cin>>N>>T;
    p.resize(N);
    forn(i, N) cin>>p[i].f>>p[i].s;
    //
    sort(p.begin(), p.end());
    for(auto& it: p)
    {
        for (int now = T - 1; now>= 0; --now)
        {
            dp[now+it.f] = max(dp[now+it.f], dp[now] + it.s);
        }
    }
    int ans = 0;
    forn(i, 6666) ans = max(ans, dp[i]);
    cout << ans << '\n';
}

signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(22);
    // cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3756
#include<stdio.h>
int main(void)
{
	int i,j,n,x;
	scanf("%d",&n);
	for(i=1;i<=n;i++) {
		scanf("%d",&x);
		printf("Case %d:\n",i);
		for(j=1;j<=10;j++) {
			x=x*x;
			x=x/100%10000;
			printf("%d\n",x);
		}
	}
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {
public:

	void Solve() {
		UL N; scanf("%d", &N);
		UL M = 0;
		UL K; scanf("%d", &K);
		rep(i, K) {
			UL m; scanf("%d", &m);
			M |= (1 << m);
		}
		UL p = M;
		rep(k, 1 << K) {
			printf("%d:", (M ^ p));
			rep(j, N) {
				if (((M ^ p) >> j) & 1) printf(" %d", j);
			}
			printf("\n");
			p = M & (p - 1);
		}
	}
};

int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}



Measured memory_bytes: 3212
#include<stdio.h>

int main(void)
{
	unsigned long int a, b, c;


	scanf("%ld", &a);

	switch (a % 10) {
	case 3:
		printf("bon");
		break;
	case 0:
	case 6:
	case 8:
	case 1:
		printf("pon");
		break;
	default:
		printf("hon");
	}

	return 0;
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
const int mod = 1e9 + 7;
map<pair<int,string>, ll> dp;
int n;
string a = "AGCT";
ll solve(int idx, string s){
    if(s.size() > 2 and (s.substr(s.size() - 3) == "AGC" || s.substr(s.size() - 3) == "ACG" || s.substr(s.size() - 3) == "GAC")) return 0;
    else if(s == "AAGC" || s == "ACGC" || s == "AGGC" || s == "ATGC") return 0;
    else if(s == "AGAC" ||s == "AGGC" ||s == "AGCC" ||s == "AGTC") return 0;

    if(idx >= n) return 1;
    if(dp.find({idx, s}) != dp.end()) return dp[{idx, s}];

    ll ans = 0;
    for(int i = 0; i < a.size(); i++){
        s += a[i];
        if(s.size() <= 4) ans = (ans + (solve(idx + 1, s) % mod))% mod;
        else{
            string temp = "";
            for(int j = 1; j < s.size(); j++) temp += s[j];
            ans = (ans + (solve(idx + 1, temp) % mod))% mod;
        }
        s.pop_back();
    }
    dp[{idx, s}] = ans;
    return dp[{idx, s}];
}
int main(){
    Hello
    cin >> n;
    cout << solve(0, "");
    return 0;
}


Measured memory_bytes: 5664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    int N, M, C; cin >> N >> M >> C;
    vector<int> B(M);
    for(int i=0; i<M; i++) cin >> B[i];

    int ans = 0;

    for(int i=0; i<N; i++){
        int sum = 0;
        for(int j=0; j<M; j++){
            int a; cin >> a;
            sum += a*B[j];
        }
        if(sum + C > 0) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#B - すぬけ君の塗り絵 2 イージー
W, H,N = map(int, input().split())
a = [input().split() for l in range(N)]
tmpx = W
tmpx1 = 0
tmpy = H
tmpy1 = 0
for i in range(N):
    if a[i][2] == "1":
        if tmpx1 < int(a[i][0]):
            tmpx1 = int(a[i][0])
        else:
            pass
    elif a[i][2] == "2" :
        if tmpx > int(a[i][0]):
            tmpx = int(a[i][0])
        else:
            pass
    elif a[i][2] == "3" :
        if tmpy1 < int(a[i][1]):
            tmpy1 = int(a[i][1])
    elif a[i][2] == "4" :
        if tmpy > int(a[i][1]):
            tmpy = int(a[i][1])
    else:
        print(0)
        exit()

if tmpx-tmpx1 <= 0 or tmpy - tmpy1 <=0:
    print(0)
else:
    print(abs(tmpx-tmpx1)*abs(tmpy-tmpy1))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef array<ll,2> pll;
const ll NMAX=100005;
ll h[NMAX],dp[NMAX];
int main()
{
    ll n,k;
    cin>>n>>k;
    for(ll i=1;i<=n;i++){
        cin>>h[i];
        if(i>1) dp[i]=2e9;
        for(ll j=i-1;j>=i-k && j>0;j--)
            dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 5172
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main(){
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	s1[0]-=32;
	s2[0]-=32;
	s3[0]-=32;
	cout<<s1[0]<<s2[0]<<s3[0]<<"\n";
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=list(map(int,input().split()))
    cunt=[0]*(n+1)
    cunt[0]=3
    ans=1
    mod=10**9+7
    for a in A:
        ans=ans*cunt[a]%mod
        if ans==0:break
        cunt[a+1]+=1
        cunt[a]-=1
    print(ans)
    

if __name__=='__main__':
    main()

Measured memory_bytes: 14008
import sys
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

class UnionFind():
    def __init__(self, n):
        self.par = [-1 for i in range(n)]

    def root(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.root(self.par[x]) # contraction
            return self.par[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            if self.par[x] > self.par[y]: # merge technique
                x, y = y, x
            self.par[x] += self.par[y]
            self.par[y] = x

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

    def size(self, x):
        return -self.par[self.root(x)]

n, k, l = map(int, input().split())
uf_r = UnionFind(n)
for i in range(k):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    uf_r.unite(p, q)
uf_t = UnionFind(n)
for i in range(l):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    uf_t.unite(r, s)

root_r = defaultdict(set)
root_t = defaultdict(set)
for i in range(n):
    root_r[uf_r.root(i)].add(i)
    root_t[uf_t.root(i)].add(i)

ans = []
memo = dict()
for i in range(n):
    if (uf_r.root(i), uf_t.root(i)) not in memo:
        memo[(uf_r.root(i), uf_t.root(i))] = len(root_r[uf_r.root(i)] & root_t[uf_t.root(i)])
    ans.append(str(memo[(uf_r.root(i), uf_t.root(i))]))

print(' '.join(ans))


Measured memory_bytes: 172152
#include<stdio.h>

int main(){

	int i, j, ans;

	for (i = 1 ; i <= 9 ; i++) {
		for (j = 1 ; j <= 9 ; j++) {
			ans = i * j;
			printf("%dx%d=%d\n", i, j, ans);
		}
	}

    return 0;
}

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

const int maxn=2e5+7;
int a[maxn],c[maxn],ans,n;

int lowbit(int x)
{
	return x&-x;
}

void modify(int x,int d)
{
	while(x<=n) {
		c[x]+=d;
		x+=lowbit(x);
	}
}

int query(int x)
{
	int ans=0;
	while(x) {
		ans+=c[x];
		x-=lowbit(x);
	}
	return ans;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",a+i);
	for(int i=1;i<=n;++i) {
		if(query(a[i])==0) ans++;
		modify(a[i],1);
	}
	printf("%d",ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

class Dinic{
    // to:頂点インデックス, cap:容量, rev:逆辺を表すGのインデックス
    struct edge{int to, cap, rev;};
    void bfs(int s);
    int dfs(int v, int t, int f);
    public:
        // G:隣接リスト, level:sからの距離, iter:調べたかどうかのフラグ
        vector<edge> G[MAX_V];
        int level[MAX_V];
        int iter[MAX_V];
        Dinic(mat g);
        int solve(int s, int t);
};

Dinic::Dinic(mat g){
    // g : 隣接行列, Dinic.G : 隣接リスト
    REP(from, g.size()) REP(to, g.size()){
        if (g[from][to] > 0){
            G[from].pb((edge){to, g[from][to], G[to].size()});
            G[to].pb((edge){from, g[to][from], G[from].size()-1});
        }
    }
}

// フローを流せる全ての頂点について，頂点sからの最短距離をBFSで計算する
void Dinic::bfs(int s){
    memset(level, -1, sizeof(level));
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        REP(i, G[v].size()){
            edge &e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                q.push(e.to);
            }
        }
    }
}

int Dinic::dfs(int v, int t, int f){
    if (v == t) return f;
    for (int i=iter[v]; i<G[v].size(); i++){
        edge &e = G[v][i];
        if (e.cap > 0 && level[v] < level[e.to]){
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int Dinic::solve(int s, int t){
    int flow = 0;
    while(true){
        bfs(s);
        if (level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        int f;
        while ((f = dfs(s, t, INF)) > 0){
            flow += f;
        }
    }

}

int main(){
    int V, E; cin >> V >> E;
    mat g_mat(V, vi(V, 0));
    REP(i, E){
        int u, v, c;
        cin >> u >> v >> c;
        g_mat[u][v] = c;
    }
    Dinic dn(g_mat);
    int ans = dn.solve(0, V-1);
    cout << ans << endl;
}


Measured memory_bytes: 6388
N=int(input())
L=[]
ans=0
A=0
B=0
AB=0
for i in range (N):
        L.append(input())
        ans+=L[i].count("AB")
        A+=L[i][-1].count("A")
        B+=L[i][0].count("B")
        if L[i][-1]=="A" and L[i][0]=="B":
                AB += 1
if A>=B:
        ans+=B
        if AB==A and AB>=1:
                ans-=1
else:
        ans+=A
        if AB==B and AB>=1:
                ans-=1            
print(ans)

Measured memory_bytes: 3700
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

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

		char[] c = n.toCharArray();
		for (int i = 0; i < n.length(); i++) {
			if (c[i] == '1')
				c[i] = '9';
			else
				c[i] = '1';

		}

		String s = String.valueOf(c);

		System.out.println(s);

	}
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  cout << (H - h) * (W - w) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 1100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;



int main(){
    vector<P> ans;
    int N;
    cin>>N;
    ll a[60],temp=0,x;
    for(int i=0;i<N;i++){
        cin>>a[i];
        if(abs(a[i])>temp){
            temp=abs(a[i]);
            x=i;
        }
    }
    cout<<(N-1)+(N-1)<<endl;
    for(int i=0;i<N;i++){
        if(i==x) continue;
        cout<<x+1<<" "<<i+1<<endl;
    }
    if(a[x]<0){
        for(int i=N;i>=2;i--) cout<<i<<" "<<i-1<<endl;
    }else{
        for(int i=1;i<=N-1;i++) cout<<i<<" "<<i+1<<endl;
    }

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(),M=sc.nextInt();
		long[][] ab = new long[N][2];
		long[][] cd = new long[M][2];
		long[] array = new long[N];
		long min = 9223372036854775807L;

		for(int i=0;i<N;i++) {
			ab[i][0] = sc.nextLong();
			ab[i][1] = sc.nextLong();
		}
		for(int i=0;i<M;i++) {
			cd[i][0] = sc.nextLong();
			cd[i][1] = sc.nextLong();
		}
		for(int i=0;i<N;i++) {
			for(int j=0;j<M;j++) {
				long buff = Math.abs((ab[i][0]-cd[j][0]))+Math.abs((ab[i][1]-cd[j][1]));
				//System.out.print(buff+" ");
				if(min>buff){
					array[i] = j;
					min = buff;
				}
			}
			//System.out.println();
			min = 9223372036854775807L;
		}


		for(int i=0;i<N;i++) {
			System.out.println(array[i]+1);
		}
	}

	public static int sample() {
		return 1;
	}

}


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

long long int calc(long long int m){
  --m;
  long long int t = 1LL, ret = 0LL, l = 1LL;
  ret += m/3*4 + m/5*4;
  while(t*10 < m){
    ret += l*(t*10 - t*10/3 - t*10/5 + t*10/15 - t + t/3 + t/5 - t/15);
    t *= 10LL;
    ++l;
  }
  ret += l*(m - m/3 - m/5 + m/15 - t + t/3 + t/5 - t/15);
  ++ret;
  return ret;
}

string solve(long long int s){
  //s += 8;
  long long int ok = -1, ng = 1e18;
  
  while(ng - ok > 1){
    long long int m = (ok + ng)/2;
    if(calc(m) < s) ok = m;
    else ng = m;
  }
  string t, ret;
  if(ok > 0){
    if(ok%3 == 0) t += "Fizz";
    if(ok%5 == 0) t += "Buzz";
    if(ok%3 && ok%5) t += to_string(ok);
  }
  --s;
  int d = s - calc(ok);
  if(d <= t.length()) ret += t.substr(d);
  while(ret.length() <= 20){
    ++ok;
    if(ok%3 == 0) ret += "Fizz";
    if(ok%5 == 0) ret += "Buzz";
    if(ok%3 && ok%5) ret += to_string(ok);
  }
  return ret.substr(0,20);
}

int main(){
  //for(int i = 0; i < 20; ++i) cout << i << " " << calc(i) << endl;
  long long int s;
  cin >> s;
  cout << solve(s) << endl;
  return 0;
}



Measured memory_bytes: 3292
#include <algorithm>
#include <cstdio>
#include <iostream>
#include<string>
using namespace std;
#define ll long long
const int maxn = 3e5 + 9;
int main() {
    int n[2];
    string a[2], b;
    cin >> a[0] >> a[1] >> n[0] >> n[1] >> b;
    if(a[0]==b){
        printf("%d %d\n", n[0]-1, n[1]);
    }
    else if(a[1]==b){
        printf("%d %d\n", n[0], n[1]-1);
    }
    return 0;
}

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


long long int gcd(long long int x, long long int y)
{
    if (x % y == 0) {
        return y;
    } else {
       gcd(y, x%y);
    }
}

int main()
{
    long long int a,b,c,d;
    cin >> a >> b >> c >> d;
    long long int ans_a, ans_b;
    long long int y = gcd(c, d);

    ans_a = (a-1) - ((a-1)/c) - ((a-1)/d) + (a-1)/((c*d)/y);
    ans_b = b - (b/c) - (b/d) + b/((c*d)/y);

    cout << ans_b - ans_a << endl;

    return 0;
}

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

int m,n;

void makeboard(int **board,int x,int y,int rank);
int countboard(int **board,int x,int y,int rank);

int main(void){
  int s,t;
  int i,j,k,count=0,counts;
  int place[10][2];
  int **board,**copyboard;
  
  while(scanf("%d",&m) && m!=0){
    count=0;
    scanf("%d",&n);
    board=(int **)calloc(m,sizeof(int *));
    for(i=0;i<m;i++) *(board+i)=(int *)calloc(n,sizeof(int));
    copyboard=(int **)calloc(m,sizeof(int *));
    for(i=0;i<m;i++) *(copyboard+i)=(int *)calloc(n,sizeof(int));
    
    for(i=0;i<m;i++) for(j=0;j<n;j++) *(*(board+i)+j)=999;
    scanf("%d",&s);
    for(i=0;i<s;i++) scanf("%d %d",&place[i][0],&place[i][1]);
    for(i=0;i<s;i++) makeboard(board,place[i][0]-1,place[i][1]-1,0);
    
    scanf("%d",&t);
    for(i=0;i<t;i++) scanf("%d %d",&place[i][0],&place[i][1]);
    for(i=0;i<t;i++){
      for(j=0;j<m;j++) for(k=0;k<n;k++) *(*(copyboard+j)+k)=*(*(board+j)+k);
      makeboard(copyboard,place[i][0]-1,place[i][1]-1,0);
      counts=0;
      for(j=0;j<m;j++) for(k=0;k<n;k++) if(*(*(copyboard+j)+k)!=*(*(board+j)+k)) counts++;
      if(count<counts) count=counts;
    }
    printf("%d\n",count);
    for(i=0;i<m;i++) free(*(board+i));
    for(i=0;i<m;i++) free(*(copyboard+i));
    free(board);
    free(copyboard);
  }
  return 0;
}

void makeboard(int **board,int x,int y,int rank){
  if(*(*(board+x)+y)<=rank) return;
  *(*(board+x)+y)=rank;
  if(x>0) makeboard(board,x-1,y,rank+1); 
  if(x<m-1) makeboard(board,x+1,y,rank+1); 
  if(y%2==0){
    if(x>0 && y>0) makeboard(board,x-1,y-1,rank+1);
    if(y>0) makeboard(board,x,y-1,rank+1);
    if(x>0 && y<n-1) makeboard(board,x-1,y+1,rank+1);
    if(y<n-1) makeboard(board,x,y+1,rank+1);
  }else{
    if(y>0) makeboard(board,x,y-1,rank+1);
    if(x<m-1 && y>0) makeboard(board,x+1,y-1,rank+1);
    if(y<n-1) makeboard(board,x,y+1,rank+1);
    if(x<m-1 && y<n-1) makeboard(board,x+1,y+1,rank+1);
  }
}
 

Measured memory_bytes: 0