akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))

//*
//遅延セグ木ここから
//↓ここを変える
typedef struct sayouso{ll a,b;}sayouso;
typedef struct atai{ll a,b;}atai;
//↑ここを変える

typedef struct node{sayouso T;atai x;}node;
node *lsegN,*lseg;
ll lsegNUM,lsegk;

//↓ここから変える
sayouso sid={0,0};
atai aid={0,0};
atai xx(atai x,atai y){
	return x;
}
atai Tx(sayouso T,atai x){
	atai ret;
	ret.a=T.a+x.a;
	ret.b=T.b+x.b;
	return ret;
}
sayouso TT(sayouso S,sayouso T){
	sayouso ret;
	ret.a=S.a+T.a;
	ret.b=S.b+T.b;
	return ret;
}
sayouso fT(sayouso T,ll k){
	return T;
}
//↑ここまで変える

//要素数(2ベキ)でこれを呼ぶ
void lseguse(ll n){
	lsegN=(node*)calloc(2*n,sizeof(node));
	lsegNUM=n;
	lseg=lsegN+lsegNUM;
	lsegk=0;while(n/=2)lsegk++;
	rep(i,1,2*lsegNUM){
		lsegN[i].x=aid;
		lsegN[i].T=sid;
	}
}
//lseg[i].xに値を与えてから初期化
void lseginit(){
	for(ll i=lsegNUM-1;i>0;i--)lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
}
void lsegupdatesub(ll l,ll r,sayouso T,ll i,ll cl,ll cr,ll ck){
	if(l>=r)return;
	//disjointなとき
	if(cr<=l||r<=cl)return;
	//完全に含むとき
	if(l<=cl&&cr<=r){
		lsegN[i].T=TT(T,lsegN[i].T);
		return;
	}
	//どちらでもないとき
	//遅延伝播
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	//再帰的に更新
	ll cm=(cl+cr)/2;
	lsegupdatesub(l,r,T,2*i  ,cl,cm,ck-1);
	lsegupdatesub(l,r,T,2*i+1,cm,cr,ck-1);
	//自身のnodeを更新
	lsegN[i].x=xx(Tx(fT(lsegN[2*i].T,ck-1),lsegN[2*i].x),Tx(fT(lsegN[2*i+1].T,ck-1),lsegN[2*i+1].x));
	lsegN[i].T=sid;
}
void lsegupdate(ll l,ll r,sayouso T){lsegupdatesub(l,r,T,1,0,lsegNUM,lsegk);}
atai lsegcalcsub(ll l,ll r,ll i,ll cl,ll cr,ll ck){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return Tx(fT(lsegN[i].T,ck),lsegN[i].x);

	ll cm=(cl+cr)/2;
	//遅延伝播(変更はないので配るだけで良い)
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	lsegN[i].x=Tx(fT(lsegN[i].T,ck),lsegN[i].x);
	lsegN[i].T=sid;

	//左側だけ
	if(r<=cm)return lsegcalcsub(l,r,2*i  ,cl,cm,ck-1);
	//右側だけ
	if(cm<=l)return lsegcalcsub(l,r,2*i+1,cm,cr,ck-1);
	//両方
	return xx(lsegcalcsub(l,r,2*i,cl,cm,ck-1),lsegcalcsub(l,r,2*i+1,cm,cr,ck-1));
}
atai lsegcalc(ll l,ll r){return lsegcalcsub(l,r,1,0,lsegNUM,lsegk);}
//遅延セグ木ここまで
//*/

ll s[1010][1010];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	lseguse(1<<17);
	rep(i,0,m){
		int a,b;
		scanf("%d%d",&a,&b);
		if(b<1000){
			rep(j,0,b)s[b][j]+=(a+j)%b;
		}else{
			sayouso T={1,a};
			lsegupdate(1,b-a,T);
			for(int l=b-a;l<=n;l+=b){
				int r=min(l+b,n+1);
				sayouso T={1,-l};
				lsegupdate(l,r,T);
			}
		}
	}
	rep(i,1,n+1){
		atai x=lsegcalc(i,i+1);
		ll ans=x.a*i+x.b;
		rep(j,1,1000)ans+=s[j][i%j];
		printf("%lld\n",ans);
	}
}



Measured memory_bytes: 10856
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
const int MAX = 1000;
long long n,m;
vector<vector<int> > dp(MAX+1,vector<int>(MAX+1,-1));
vector<vector<char> > v(1000+1,vector<char> (1000+1));
long long ways(long r,long c){
    // cout<<"start\n";
    if(r==n&&c==m){
        // cout<<"break\n";
        return dp[r][c]=1;
    }
    if(dp[r][c]!=-1){
        return dp[r][c]%mod;
    }else{
        // cout<<"else\n";
        long long val1=0,val2=0;
        if(c+1<=m&&v[r][c+1]!='#'){
            // cout<<"c+1\n";
            val1=ways(r,c+1);
        }
        if(r+1<=n&&v[r+1][c]!='#'){
            val2=ways(r+1,c);
        }
        return dp[r][c]=((val1)%mod+(val2)%mod)%mod;
    }
}
int main() {
	
	cin>>n>>m;
	
	for(int i=1;i<=n;i++){
	    for(int j=1;j<=m;j++){
	        cin>>v[i][j];
	    }
	}
    long long ans=ways(1,1);
    cout<<ans<<"\n";
	// for(int i=1;i<=n;i++){
 //        for(int j=1;j<=m;j++){
 //            cout<<dp[i][j]<<" ";
 //        }
 //        cout<<"\n";
 //    }
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

const ll MOD = 1e9 + 7;

int main(){
    ll a, b;
    cin >> a >> b;
    ll a1 = a + b;
    ll a2 = a - b;
    ll a3 = a * b;
    if (a1>a2){
        if (a1>a3) cout << a1 << endl;
        else cout << a3 << endl;
    } else {
        if (a2>a3) cout << a2 << endl;
        else cout << a3 << endl;
    }
}

Measured memory_bytes: 256
def partition(a, p, r):
	x = a[r]
	i = p - 1
	for j in range(p, r):
		if a[j] <= x:
			i += 1
			swap(a, i, j)
	swap(a, i + 1, r)
	return i + 1

def swap(a, i, j):
	tmp = a[i]
	a[i] = a[j]
	a[j] = tmp
	
n = int(input())
a = list(map(int, input().split()))
idx = partition(a, 0, len(a) - 1)
if idx == 0:
	print('[' + str(a[0]) + ']', end='')
else:
	print(a[0], end='')
for i in range(1, n):
	print(' ', end='')
	if idx == i:
		print('[' + str(a[i]) + ']', end='')
	else:
		print(a[i], end='')
print()



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

using namespace std;
using ll = long long;

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

  string s;
  cin >> s;

  int n = s.size();

  ll ans = 0;

  for (int b = 0; b < (1 << n); b++) {
    ll sum = 0;
    for (int i = 0; i < n; i++) {
      if (b & (1 << i)) {
        ans += sum;
        sum = 0;
      } else {
        sum = sum * 10 + (s[i] - '0');
      }
    }
    ans += sum;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int c0=0, c1 = 0;
        for(int i=0; i<s.length(); i++){
            if(s.charAt(i) == '0'){
                c0++;
            }else{
                c1++;
            }
        }
        
        System.out.println(Math.min(c0, c1)*2);
    }
}

Measured memory_bytes: 26028
#include<stdio.h>
int main(void)
{
	int n,m,i,flg,flg1;
	int a[7]={1,3,5,7,8,10,12};
	int b[4]={4,6,9,11};
	scanf("%d %d",&n,&m);
	if(n==2||m==2) printf("No\n");
	flg=0; flg1=0;
	if(n!=2&&m!=2){
		for(i=0;i<7;i++){
			if(a[i]==n) flg=1;
			if(a[i]==m) flg1=1;
		}
		if(flg==0&&flg1==0){
			for(i=0;i<4;i++){
				if(b[i]=n) flg=1;
				if(b[i]=m) flg1=1;
			}
		}
		if(flg==1&&flg==1) printf("Yes\n");	
		else printf("No\n");
	}	
	return 0;
}

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

int main() {
    // 入力
    int N;
    cin >> N;
    vector<int>a(N);
    vector<int>b(N);
    vector<int>c(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }

    // i日目にA,B,Cを行った後の幸福度の総和の最大値がHappiness[*][i-1]
    vector<vector<int>> Happiness (3, vector<int>(N));
    Happiness[0][0] = a[0];
    Happiness[1][0] = b[0];
    Happiness[2][0] = c[0];
    for (int i = 1; i < N; ++i) {
        Happiness[0][i] = max(Happiness[1][i-1], Happiness[2][i-1]) + a[i];
        Happiness[1][i] = max(Happiness[2][i-1], Happiness[0][i-1]) + b[i];
        Happiness[2][i] = max(Happiness[0][i-1], Happiness[1][i-1]) + c[i];
    }

    // 出力
    int res;
    res = max(Happiness[0][N-1], Happiness[1][N-1]);
    res = max(res, Happiness[2][N-1]);
    cout << res;
    return 0;
}

Measured memory_bytes: 3072
//Disjoint Set of Common Divisors

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, ll>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

signed main (){
    int a,b;cin>>a>>b;
    int gd=__gcd(a,b);
    set<int>m{gd};
    rep(i,1,(int)floor(sqrt(gd))+1){
        if(gd%i==0){
            m.insert(i);
            m.insert(gd/i);
        }
    }
    int ans = 1;
    for(auto i:m){
        if(IsPrime(i))ans++;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3824
N, a, b, c = gets.split.map(&:to_i)
v = {'A' => a, 'B' => b, 'C' => c}
T = []
N.times do
    T << gets.chomp
end

flag = false
success = true
result = []
i = 0
while i < N
    s1, s2 = T[i][0], T[i][1]
    v1, v2 = v[s1], v[s2]
    if v1 == 0 && v2 == 0
        if flag == false
            success = false
            break
        else
            v = flag
            flag = false
            result.pop
            i -= 1
            T[i][0], T[i][1] = T[i][1], T[i][0]
            next
        end
    elsif v1 == 1 && v2 == 1
        flag = v.dup
        v[s1] -= 1
        v[s2] += 1
        result << s2
    else
        if v1 > v2
            v[s1] -= 1
            v[s2] += 1
            result << s2
        else
            v[s1] += 1
            v[s2] -= 1
            result << s1
        end
    end 
    i += 1
end

if success
    puts "Yes"
    puts result
else
    puts "No"
end

Measured memory_bytes: 30804
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    N, W = map(int, input().split())
    VW = [list(map(int, input().split())) for _ in range(N)]

    dp = [[0] * (W + 1) for _ in range(N + 1)]
    for i in range(1, N + 1):
        v, w = VW[i - 1]
        for j in range(1, W + 1):
            if j - w >= 0:
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
            else:
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j])
    print(dp[-1][-1])


if __name__ == '__main__':
    resolve()



Measured memory_bytes: 25516
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

#define int long long

const int N=1000+10;
const int M=2000+10;
const int MOD=1000000007;

int n,m,X;

int id[M],u[M],v[M],d[M],fa[N];

int A,B,C;

int find(int x)
{
	return (fa[x]==x)?x:(fa[x]=find(fa[x]));
}

void hb(int x,int y)
{
	fa[find(x)]=find(y);
}

void U(int e)
{
	int i,sum(0);
	for(i=1;i<=n;++i)
		fa[i]=i;
	hb(u[e],v[e]);
	sum+=d[e];
	for(i=1;i<=m;++i)
	{
		e=id[i];
		if(find(u[e])!=find(v[e]))
		{
			hb(u[e],v[e]);
			sum+=d[e];
		}
	}
	if(sum<X)
		++A;
	else if(sum==X)
		++B;
	else if(sum>X)
		++C;
}

int cmp(int x,int y){return d[x]<d[y];}

int quickpow(int x,int y)
{
	int res(1);
	for(;y;y>>=1,(x*=x)%=MOD)if(y&1)
		(res*=x)%=MOD;
	return res;
}

signed main()
{
	scanf("%lld%lld%lld",&n,&m,&X);
	int i;
	for(i=1;i<=m;++i)
	{
		scanf("%lld%lld%lld",u+i,v+i,d+i);
		id[i]=i;
	}
	sort(id+1,id+m+1,cmp);
	for(i=1;i<=m;++i)
		U(i);
	if(B)
	{
		int ans(quickpow(2,C)),a(quickpow(2,B)-1);
		if(a<0)
			a+=MOD;
		if(A)
		{
			a+=a;
			if(a>=MOD)
				a-=MOD;
		}
		else
		{
			--a;
			if(a<0)
				a+=MOD;
		}
		printf("%lld",ans*a%MOD);
	}
	else
		putchar(48);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=100005;
int n,cnt[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        cnt[x]++;
    }
    int ans=0;
    for(int i=1;i<=100000;i++)ans=max(ans,cnt[i]+cnt[i-1]+cnt[i+1]);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

ll solve(ll W, ll H) {
    ll mi = min(W, H);
    for (ll i = 1; i < W; i++) {
        ll wi = W - i;
        ll C1 = i * H;
        ll C2 = wi*(H/2);
        ll C3 = wi*((H/2) + (H%2 == 1));
        ll sma = max({C1,C2,C3});
        ll smi = min({C1,C2,C3});
        mi = min(mi, sma - smi);
    }
    return mi;
}
int main() {
    ll H, W; cin >> H >> W;
    if (H % 3 == 0 || W % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }

    cout << min(solve(W, H), solve(H, W)) << endl;
}


Measured memory_bytes: 256
#include <iostream>
// #include <vector>
#include <algorithm>

int main(){
	long long n, a, b, ans=0;
	std::cin >> n >> a >> b;
	n--;
	a--;
	b--;
	if(a>b) std::swap(a,b);
	if((b-a)%2==0) ans = (b-a)/2;
	else{
		long long d1 = n-b;
		long long d2 = a;
		if(d1>=d2){
			ans += d2;
		}else{
			ans += d1;
		}
		ans += (b-a+1)/2;
	}

	std::cout << ans <<std::endl;
	return 0;
}


Measured memory_bytes: 256
//Classic
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define endl "\n"
#define debug(x) cout<<"AA Baju Smit------> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define mint map<int,int>
#define mod 1000000007
#define ciN cin
#define X INT_MAX
#define N INT_MIN
////////////////////////////////////////////////////////////////


void solve() {
	int n; ciN >> n;
	vi v(n); For(i, 0, n)cin >> v[i];
	ll here = v[0];
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		ans += (1LL * here * v[i]) % mod;
		here += v[i];
		here %= mod;
	}
	cout << ans % mod << endl;
}




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


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

	//int t; cin >> t;
	//while (t--)
	solve();


	return 0;
}





///////////////////////////////////////////////////////////////////////////////////////////
//Kai baju bhai???



Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  string S;
  cin >> S;
  string T = S;
  reverse(all(T));

  int ans = 0;
  rep(i, sz(S) / 2) {
    if (S[i] != T[i])
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    m, f, r = [int(i) for i in input().split()]
    if m == f == r == -1:
        break
    total = m + f
    if -1 in [m, f]:
        grade = "F"
    elif total >= 80:
        grade = "A"
    elif total >= 65:
        grade = "B"
    elif total >= 50:
        grade = "C"
    elif total >= 30:
        if r >= 50:
            grade = "C"
        else:
            grade = "D"
    else:
        grade = "F"
    print(grade)



Measured memory_bytes: 5604
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	int K;
	int A, B;
	cin >> K;
	cin >> A >> B;

	int v;
	bool jdg = false;
	for (int i = A; i <= B; i++) {
		v = i % K;
		if (v == 0) {
			jdg = true;
			break;
		}
	}

	if (jdg == true) {
		cout << "OK" << endl;
	}
	else {
		cout << "NG" << endl;
	}

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
typedef double d;
typedef int i;
 
int main() {
  string a , b;
  cin >> a >> b;
  for ( int i = 0 ; i < b.length() ; i++ ) cout << a[i] << b[i];
  if ( a.length() > b.length() ) cout << a[a.length() - 1];
}

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

int main() {
  int N;
  cin>>N;
  vector<int64_t> p(N);
  vector<int64_t> q(N);
  for(int i=0;i<N;i++){
    int64_t a,b;
    cin>>a>>b;
    p[i]=a+b;
    q[i]=a-b;
  }
  sort(p.begin(),p.end());
  sort(q.begin(),q.end());
  cout<<max(p[N-1]-p[0],q[N-1]-q[0])<<endl;
}

Measured memory_bytes: 6424
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    string S; cin >> S;
    rep(i, S.size()) {
        char C = S.at(i);
        C += N;
        if (C > 'Z') C = C - 'Z' + 'A' - 1;
        S.at(i) = C;
    }
    cout << S << endl;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int m, n; string s; vector<int> r;
int main() {
	while(~scanf("%d%d", &m, &n)) {
		if(!m && !n) break; int pos = 0; r.clear();
		for(int i = 1; i <= m; i++) r.push_back(i);
		for(int i = 1; i <= n; i++) {
			cin >> s;
			if(i % 15 == 0) {
				if(s != "FizzBuzz" && r.size() - 1) r.erase(r.begin() + pos);
				else pos++;
			}
			else if(i % 3 == 0) {
				if(s != "Fizz" && r.size() - 1) r.erase(r.begin() + pos);
				else pos++;
			}
			else if(i % 5 == 0) {
				if(s != "Buzz" && r.size() - 1) r.erase(r.begin() + pos);
				else pos++;
			}
			else {
				if(s != to_string(i) && r.size() - 1) r.erase(r.begin() + pos);
				else pos++;
			}
			pos %= r.size();
		}
		for(int i = 0; i < r.size(); i++) {
			if(i) printf(" ");
			printf("%d", r[i]);
		}
		printf("\n");
	}
}

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

int main() {
	int n,k;
	cin>>n>>k;
	int a[n],i,j,dp[n];
	for(i=0;i<n;i++)
	cin>>a[i];
    for(i=0;i<n;i++)
    dp[i]=INT_MAX;
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        for(j=1;j<=k;j++)
        {
            
            int k=i+j;
            if(k>=n)
            break;
            int z=dp[i]+abs(a[k]-a[i]);
            dp[k]=min(dp[k],z);
        }
    }
    cout<<dp[n-1];
      
	
	
	return 0;
}

Measured memory_bytes: 4324
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
struct edge {int to, cost;};

signed main() {
	int n, t; cin >> n >> t;
	int ans = 114514;
	rep(i, n) {
		int a, b; cin >> a >> b;
		if (b <= t)ans = min(ans, a);
	}
	if (ans == 114514)puts("TLE");
	else cout << ans << endl;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(10);
          int n,c,k;
           cin>>n>>c>>k;
           vin t(n);
           rep(i,0,n)cin>>t[i];
           sort(all(t));
           int limit;
           int ans=0;
           int cnt=0;
           rep(i,0,n){
             limit=t[i]+k;
             cnt=0;
             cnt++;
             while(i+1<n&&t[i+1]<=limit&&cnt<c){
              i++;
              cnt++;
             }
             //cout<<cnt;
             //cout<<i<<endl;
             ans++;
           }
            
           cout<<ans<<endl;
          }

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

int t;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int l, r, d;
	cin >> l >> r >> d;
	int ans = floor(r*1.0 / d) - floor(l*1.0/d);
	if (l%d == 0 && r % d == 0) ans++;
	cout << ans;
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 



int main()
{ 
    LL n;
    cin>>n;
    LL a,b;
    cin>>a>>b;
    if((b-a)%2==0){cout<<(b-a)/2<<endl;}
    else{
        if((a-1)<(n-b)){
            cout<<(a+b-1)/2<<endl;
        }
        else{
            cout<<(2*n+1-a-b)/2<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
//(UNCOMMENT WHEN SUBMITTING)
//#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
// #pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

// clang-format off
#define range(i) for (int _ = 0; _ < i; _++)
#define vprnt(v) for (auto vi : v) cout << vi << " "; cout << endl;
#define fastio() ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace ::std;
int nxt() {int x;cin >> x;return x;}
ll nxtll() {ll x;cin >> x;return x;}
// clang-format on

int main() {
    fastio();

    vector<int> A(3);
    generate(all(A), nxt);
    sort(all(A));
    if (A[0] == 5 && A[1] == 5 && A[2] == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  sort(a.begin(), a.end(), greater<int>());
  int i = 0, j = 0;
  while (i < n - 1 && a[i + 1] > j) {
    i++;
    j++;
  }
  int x = a[i] - j;
  int y = 0;
  while (i < n - 1 && j == a[i + 1]) {
    i++;
    y++;
  }
  if (x % 2 == 1 || y % 2 == 1) {
    cout << "First\n";
  } else {
    cout << "Second\n";
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int64 n; cin >> n;
	int64 ans = 0;
	for (int64 i = 1; i <= n; ++i) {
		ans += (i - 1);
	}
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 256
#include <cstdio>

int a[101];
int b[101];

int main() {
	int i, n, r = 0;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		a[i] += a[i - 1];
	}
	for (i = 1; i <= n; i++) {
		scanf("%d", &b[i]);
		b[i] += b[i - 1];
	}
	for (i = 1; i <= n; i++) {
		if (r < a[i] + b[n] - b[i - 1]) r = a[i] + b[n] - b[i - 1];
	}
	printf("%d\n", r);
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector <int64_t> L(N + 1);
  L.at(0) = 2;
  L.at(1) = 1;
  for (int i = 2; i < (N + 1); i++) {
    L.at(i) = L.at(i - 1) + L.at(i - 2);
  }
  
  cout << L.at(N) << endl;
}


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

pair<unordered_multimap<int, int>::iterator, unordered_multimap<int, int>::iterator> getRange(
	int & x,
	unordered_multimap<int, int> & e)
{
	return e.equal_range(x);
}

void 
node_child (int & x, //parent
	const int & n, //target
	unordered_multimap<int, int> & e, 
	unordered_map<int, int> & mother,
	vector<int> & visted,
	queue<int> & adj)
{
	visted[x] = 1;
	
	auto range = getRange(x, e);
	
	for (auto it = range.first; it != range.second; ++it) 
	{
		int adj_e = it->second;
		if(adj_e != n)
		{
			if(visted[adj_e]==0)
			{
				adj.push(adj_e);
				mother[adj_e] = it->first;
			}
		}
		else
		{
			mother[adj_e] = it->first;
			return;
		}
	}
	if(!adj.empty())
	{
		x = adj.front();
		adj.pop();
		node_child(x, n, e, mother, visted, adj);
	}
}


int main()
{
    std::ios::sync_with_stdio(false);	
	int n;
	cin>>n;
	
	unordered_multimap<int, int> e;
	
	for(int i= 0 ; i < n-1 ; i++)
	{
		int a,b;
		cin>>a>>b;
		e.insert(make_pair(a,b));
		e.insert(make_pair(b,a));
	}
	
	vector<int> visted(n+1);
	queue<int> adj;
	unordered_map<int, int> mother;
	int parent = 1;
	node_child(parent, n, e, mother, visted, adj);
	
	
	vector<int> path;
	int root = n;
	path.push_back(root);
	do
	{
		root = mother[root];
		path.push_back(root);
	}while(root!=1);
	
	int n_mostF = path.size()/2; 
	int n_mostS = n_mostF-1;
	
	int mostF = path[n_mostF];
	int mostS = path[n_mostS];
	
	//cout<<mostF<<" "<<mostS;
	
	visted[mostF] = -1;
	visted[mostS] = -2;
	
	set<int> count_F;
	queue<int> F_group;
	
	do{
		count_F.insert(mostF);
		visted[mostF] = -1;
		auto range = getRange(mostF, e);
		for(auto it = range.first ; it != range.second ; it++)
		{
			int adj_e = it->second;
			if(visted[adj_e] != -1 && visted[adj_e] != -2)
			{
				F_group.push(adj_e);
				count_F.insert(adj_e);
			}
		}
		if(!F_group.empty())
		{
			mostF = F_group.front();
			F_group.pop();
		}
		else
		{
			break;
		}
	}while(true);
		
	bool winnerIsF = true;		
	if(2*count_F.size() <= n)
	{
		winnerIsF = false;
	}
	
	if(winnerIsF)
	{
		cout<<"Fennec";
	}
	else
	{
		cout<<"Snuke";
	}
    return 0;
}

Measured memory_bytes: 25160
n, m, x, y = gets.chomp.split.map(&:to_i)
X = gets.chomp.split.map(&:to_i)
Y = gets.chomp.split.map(&:to_i)
max = X.max
min = Y.min
ans = "War"
if max < min
  max += 1
max.upto(min) do |i|
  if x < i && i <= y
    ans = "No War"
  end
end
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
long long a[90]={2,1};
int main(){
	int n;
	cin>>n;
	for(int i=2;i<=n;i++){
		a[i]=a[i-1]+a[i-2];
	}
	cout<<a[n];
	return 0;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
   ll n, m, d;
   cin >> n >> m >> d;
   ll a = 2*(n-d)*(m-1);
   ll b = n*n;
   if(d!=0)cout << fixed << setprecision(10) << (double)a/b << endl;
   else cout << fixed << setprecision(10) <<  (double)a/(2*b) << endl;
}

Measured memory_bytes: 3832
x, k, d= map(int, input().split())


x= abs(x)

if k%2==1:
	x-= d
	k-=1

if k*d<x:
	print(x-k*d)

else:
	if x>0:
		x= x% (2*d)
		if x> abs(x-2*d):
			print(abs(x-2*d))
		else:
			print(x)
	else:
		if abs(x)>x+2*d:
			print(x+2*d)
		else:
			print(abs(x))


Measured memory_bytes: 9204
#include<iostream>

using namespace std;

int main( void ){
    std::string s;
    cin >> s;
    bool busNeeds = false;
    for( int i = 1; i < 3; i++ ){
         if( s[i-1] != s[i] ){
             busNeeds = true;
             break;
         }
    }
    if( busNeeds ) cout << "Yes" << endl;
    else           cout << "No" << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
struct mint{
	static constexpr int mod = 1e9+7;
	int x;
	mint(ll x=0): x((x %= mod) < 0 ? x+mod : x){}
	mint operator-(){return mint(mod-x);}
	mint &operator+=(const mint &n){if((x += n.x) >= mod) x -= mod; return *this;}
	mint &operator-=(const mint &n){if((x += n.x) >= mod) x -= mod; return *this;}
	mint &operator*=(const mint &n){x = (ll)x * n.x % mod; return *this;}
	mint &operator/=(const mint &n){return *this *= n.inv();}
	mint &operator^=(const mint &n){
		mint ret{1}, tmp{x};
		for(int t = n.x; t; t >>= 1){
			if(t&1) ret *= tmp;
			tmp *= tmp;
		}
		return *this = ret;
	}
	mint inv() const{return *this ^ (mod - 2);}
	mint operator+(const mint &n){return mint(*this) += n;}
	mint operator-(const mint &n){return mint(*this) -= n;}
	mint operator*(const mint &n){return mint(*this) *= n;}
	mint operator/(const mint &n){return mint(*this) /= n;}
	mint operator^(const mint &n) const{return mint(*this) ^= n;}
};
constexpr int MX = 200005;
int n, v, u, s[MX];
vector<int> G[MX];
mint ans[MX], ac = 1;
mint dfs(int u, int p){
	mint v{1};
	s[u] = 1;
	for(int nx: G[u]) if(nx != p){
		v *= dfs(nx, u);
		s[u] += s[nx];
	}
	v /= s[u];
	return v;
}
void dfs2(int u, int p){
	if(u != p) ans[u] = ans[p] * s[u] / (n-s[u]);
	for(int nx: G[u]) if(nx != p) dfs2(nx, u);
}
int main(){
	scanf("%d", &n);
	rep(i,n) ac *= i+1;
	rep(i,n-1){
		scanf("%d%d", &v, &u);
		v--; u--;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	ans[0] = dfs(0,0) * ac;
	dfs2(0,0);
	rep(i,n) printf("%d\n", ans[i].x);
}

Measured memory_bytes: 15476
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const a = parseInt(args[0][0], 10)
	const s = args[1][0]
	if (a >= 3200) console.log(s)
	else console.log('red')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 22076
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline

using namespace std;

int main(void)
{
    string s;
    cin >> s;
    int beg, end;
    beg = end = -1;

    for (int pos = 0;; ++pos)
    {
        if (s[pos] == 'A')
        {
            beg = pos;
            break;
        }
    }
    for (int pos = s.size()-1;; --pos)
    {
        if (s[pos] == 'Z')
        {
            end = pos;
            break;
        }
    }
 
    cout << (end - beg + 1) << endl;
 
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>

int main(void)
{
  int a, b, c, d, n, cnt;

  while (std::scanf("%d", &n) != EOF) {
    cnt = 0;
    for (a = 0; a <= 9; a++) {
      for (b = 0; b <= 9; b++) {
        for (c = 0; c <= 9; c++) {
          for (d = 0; d <= 9; d++) {
            if (a + b + c + d == n) {
              cnt++;
            }
          }
        }
      }
    }
    std::printf("%d\n", cnt);
  }
  return 0;
}



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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int N;
vector<vector<pair<int,int>>> graph(N);
vector<int> ans;

void dfs(int v,int p){
  if(p==-1) ans.at(v)=0;

  rep(i,sz(graph.at(v))){
    int nv=graph.at(v).at(i).fi;
    int c=graph.at(v).at(i).se %2;
    if(nv==p) continue;
    if(c==0)  ans.at(nv)=ans.at(v);
    else  ans.at(nv)=ans.at(v)^1;
    dfs(nv,v);
  }
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  cin >> N;
  graph.resize(N);
  rep(i,N-1){
    int u,v,w;
    cin >> u >> v >> w;
    u--;
    v--;
    graph.at(u).p_b(m_p(v,w));
    graph.at(v).p_b(m_p(u,w));
  }

  ans.resize(N);
  dfs(0,-1);
  rep(i,N)  cout << ans.at(i) << endl;

  return 0;
}

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

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main() {
    int a, K;
    int total=0;
    cin >> K;
    for (int i = 1; i <= K; ++i) {
      for (int j = 1; j <= K; ++j) {
          a = gcd(i,j);
          for (int k = 1; k <= K; ++k){
              total += gcd(a,k);
          } 
      }
    }

    cout << total << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n,m,q;
    cin>>n>>m>>q;
    int a[q];
    int b[q];
    int c[q];
    int d[q];
    for(int i= 0;i<q;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
    long kotae = 0;
    for(int i1 = 1;i1<=m;i1++){
    	for(int i2 = i1;i2<=m;i2++){
        	for(int i3=i2;i3<=m;i3++){
            	for(int i4=i3;i4<=m;i4++){
                	for(int i5 = i4;i5<=m;i5++){
                    	for(int i6 = i5;i6<=m;i6++){
                        	for(int i7 = i6;i7<=m;i7++){
                            	for(int i8=i7;i8<=m;i8++){
                                	for(int i9=i8;i9<=m;i9++){
                                    	for(int i10=i9;i10<=m;i10++){
                                        int A[] = {i1, i2, i3, i4, i5,i6,i7,i8,i9,i10};
                                        long g = 0;
                                        	for(int k = 0;k<q;k++){
                                              if(A[b[k]-1]-A[a[k]-1] == c[k]) g+= d[k];
                                            }
                                        kotae= max(kotae,g);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }     
        }  
    }
    cout<<kotae;
    return 0;
}

Measured memory_bytes: 3544
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll n,m;
ll x[100010],y[100010];
ll CalcXSum(){
    ll ret=0;
    for(ll i=0;i<n-1;i++){
        ll a_i=(i+1)*(n-i-1)%MOD;
        ret=(ret+a_i*(x[i+1]-x[i])%MOD)%MOD;
    }
    return ret;
}
int main(){
    cin>>n>>m;
    for(ll i=0;i<n;i++){
        cin>>x[i];
    }
    for(ll i=0;i<m;i++){
        cin>>y[i];
    }
    ll xSum=CalcXSum();
    ll ans=0;
    for(ll i=0;i<m-1;i++){
        ll b_i=(i+1)*(m-i-1)%MOD;
        ans=(ans+b_i*(y[i+1]-y[i])%MOD*xSum%MOD)%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
S = list(readline().decode('utf8').rstrip())

ans = 0
for i in range(1, len(S)):
    X = set(S[:i])
    Y = set(S[i:])
    n = len(X & Y)
    ans = max(n, ans)

print(ans)


Measured memory_bytes: 3064
import math
n = int(input())
l = [0 for i in range(n)]
p = min(101,math.ceil(math.sqrt(n))+1)
for x in range(1, p):
    for y in range(1, p):
        for z in range(1, p):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x;
            if s <= n:
                l[s-1] += 1
for i in range(n):
    print(l[i])


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main(){
    ll N;
    cin>>N;
    vector<ll> cnt(1000005);
    for(int i = 1; i < 1000005;i++){
        for(int j = 1;i*j<1000005;j++){
            cnt[i*j]++;
        }
    }
    ll ans = 0;
    for(int i = 1; i < N; i++) ans += cnt[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 11176
H,W=map(int,input().split())
S=[list(input())for _ in range(H)]

from collections import deque
def bfs(h,w,sy,sx,S):
    maze=[[10**9]*(W)for _ in range(H)]
    maze[sy-1][sx-1]=0
    que=deque([[sy-1,sx-1]])
    count=0
    while que:
        y,x=que.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            nexty,nextx=y+i,x+j
            if 0<=nexty<h and 0<=nextx<w:
                dist1=S[nexty][nextx]
                dist2=maze[nexty][nextx]
            else:
                continue
            if dist1!='#':
                if dist2>maze[y][x]+1:
                    maze[nexty][nextx]=maze[y][x]+1
                    count=max(count,maze[nexty][nextx])
                    que.append([nexty,nextx])
    return count

ans=0
for sy in range(H):
    for sx in range(W):
        if S[sy][sx]=='.':
            now=bfs(H,W,sy+1,sx+1,S)
            ans=max(ans,now)

print(ans)

Measured memory_bytes: 9452
#include<iostream>
#include<cstdio> 
#include<cmath>
#include<algorithm>
using namespace std;
#define MAX 1010
int nums[MAX];
int main(){
	long long n,k;
	scanf("%lld %lld",&n,&k);
	long long remain=n%k;
	long long res=0;
	if(remain==0){
		res=0;
	}else{
		res=min(remain,abs(remain-k));
	}
	printf("%lld",res);
	return 0;
}

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

using namespace std;

int H, W;
char ma[52][52];

inline int check(int r, int c)
{
	if (ma[r][c] == '.') return 1;
	int dr[] = {0, 0, 1, -1};
	int dc[] = {1, -1, 0, 0};
	for (int i = 0; i < 4; i++) {
		if (ma[r+dr[i]][c+dc[i]] == '#') return  1;
	}
	return 0;
}

int main()
{
	cin >> H >> W;
	for (int i = 0; i < 52; i++) for (int j = 0; j < 52; j++) ma[i][j] = '.';
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> ma[i+1][j+1];
	for (int i = 1; i < H + 1; i++) for (int j = 1; j < W + 1; j++) {
		if (check(i, j) == 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  string S;
  cin >> S; 
  int N = S.length();

  for(int i=0; i<N; i++){
    char c = S[i];

    if(i%2==0){
      if (c=='R' || c=='U' || c=='D'){
        continue;
      }else{
        cout << "No";
        return 0;
      }
    }else{
      if (c=='L' || c=='U' || c=='D'){
        continue;
      }else{
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
mat = [list(map(int,input().split())) for i in range(M)]
L = 0
R = 10**5+1
for i in range(M):
    if L < mat[i][0]:
        L = mat[i][0]
    if R > mat[i][1]:
        R = mat[i][1]
print(max([R-L+1,0]))

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    
    map<int,int> m;
    
    REP(i,N) m[A[i]] += 1;
    
    int ans = 0;
    for ( auto a: m){
        ans += ( a.second % 2 );
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define Int int64_t
 
using namespace std;
 
int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; ++i) { cin >> v[i]; }

	vector<vector<int>> cnt(100010, vector<int>(2, 0));
	for (int i = 0; i < N; ++i) { ++cnt[v[i]][i % 2]; }

	vector<pair<int, int>> x, y;
	for (int i = 0; i < cnt.size(); ++i) {
		if (cnt[i][0] > 0) { x.emplace_back(cnt[i][0], i); }
		if (cnt[i][1] > 0) { y.emplace_back(cnt[i][1], i); }
	}

	sort(x.rbegin(), x.rend());
	sort(y.rbegin(), y.rend());
	int ans = N;
	for (auto p : x) {
		int xx = N / 2 - p.first;
		int yy = 0;
		for (auto q : y) {
			if (q.second == p.second) { continue; }
			yy = q.first;
			break;
		}
		ans = min(ans, xx + (N / 2 - yy));
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 7064
//=template==================================================================//
// include
#include <vector>
#include <list>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

// namespace
using namespace std;

// define
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(i,n) FOR(i,0,n)

// typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long LL;

// conversion
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout<<x; return sout.str();}
//===========================================================================//

//=function prototype========================================================//

//===========================================================================//

//=variables=================================================================//
int n;
//===========================================================================//
int main(void)
{
  // Scan begin.
  cin >> n;
  // Scan done.

  // Code begin.
  if (n < 1000) {
    cout << "ABC" << endl;
  }
  else {
    cout << "ABD" << endl;
  }
  // Code done.

  // return begin.
  return 0;
  // return done.
}

//=functions=================================================================//

//===========================================================================//

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

int main(){
	string n;
	cin >> n;
	ll sum = 0;
	rep(i,n.size()){
		int x = n[i] - '0';
		sum += x % 9;
	}
	if(sum % 9 == 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
    return 0;
}



Measured memory_bytes: 3748
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <unordered_set>
//#include <unordered_map>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

VV(pii) v(101);
vvint vv;
int x,y,n;
vector<pair<int,pii>> in;
vvint ans;
int cnt;
void foo(int a){
	if(a==n){
		cnt++;
		ans=vv;
		return;
	}
	int yy=in[a].S.F;
	int xx=in[a].S.S;
	int tt=in[a].F;
	rep(i,v[tt].size()){
		int ty=v[tt][i].F;
		int tx=v[tt][i].S;
		reep(j,yy-ty+1,yy+1){
			reep(k,xx-tx+1,xx+1){
				if(j<0||j+ty-1>=y||k<0||k+tx-1>=x) continue;
				bool f=true;
				reep(jj,j,j+ty){
					reep(kk,k,k+tx){
						if(vv[jj][kk]!=0&&vv[jj][kk]!=a+1){
							f=false;
						}
					}
				}
				if(f){
					reep(jj,j,j+ty){
						reep(kk,k,k+tx){
							vv[jj][kk]=a+1;
						}
					}
					foo(a+1);
					reep(jj,j,j+ty){
						reep(kk,k,k+tx){
							vv[jj][kk]=0;
						}
					}
					vv[yy][xx]=a+1;
				}
			}
		}
	}
}
void mainmain(){
	reep(i,1,11){
		reep(j,1,11){
			v[i*j].PB(pii(i,j));
			v[i*j].PB(pii(j,i));
		}
	}
	rep(i,101){
		sort(ALL(v[i]));
		v[i].erase(unique(ALL(v[i])),v[i].end());
	}
	while(cin>>x>>y>>n,x||y||n){
		in=vector<pair<int,pii>>(n);
		initvv(vv,y,x);
		rep(i,n){
			int t;
			cin>>t;
			cin>>in[t-1].F;
		}
		rep(i,y){
			rep(j,x){
				cin>>vv[i][j];
				if(vv[i][j]!=0){
					in[vv[i][j]-1].S.F=i;
					in[vv[i][j]-1].S.S=j;
				}
			}
		}
		cnt=0;
		foo(0);
		if(cnt==1){
			rep(i,ans.size()){
				rep(j,ans[i].size()){
					if(j) cout<<" ";
					cout<<ans[i][j];
				}
				cout<<endl;
			}
			continue;
		}
		else{
			cout<<"NA"<<endl;
		}
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1224
import java.util.Scanner;

public class Main {
	final boolean DEBUG = false;
	int[] preIds, inIds, posIds;
	int preIndex, inIndex, posIndex;
	
	int prev, pos;
	int location(int l, int r, int id) {
		for (int i = l; i < r; i++)
			if (inIds[i] == id) return i;
		return -1;
	}

	void tree(int l, int r) {
		if (l < r) {
			int root = preIds[preIndex++];
			int m = location(l, r, root);
			tree(l, m);
			tree(m + 1, r);
			posIds[posIndex++] = root;
		}
	}

	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		preIds = new int[n];
		inIds =  new int[n];
		posIds = new int[n];
		preIndex = inIndex = posIndex = 0;

		for (int i = 0; i < n; i++)
			preIds[i] = scan.nextInt();
		for (int i = 0; i < n; i++)
			inIds[i] = scan.nextInt();
		tree(0, n);
		for (int i = 0; i < n; i++)
			System.out.print(posIds[i] + (i == n - 1 ? "\n" : " "));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 26148
#include <stdio.h>
 
	int main(void){
		int a,b,c;
 
	scanf("%d %d %d",&a,&b,&c);
 
	if(1<=a<=100 && 1<=b<=100 && 1<=c<=100){
 
		if(b-a == c-b){
			printf("YES\n");
 
		}else if(b-a != c-b){
			printf("NO\n");
 
		}
	}else{
		printf("Error\n");
 
  	}
  }

Measured memory_bytes: 128
import heapq
import itertools


def rev(x):
    return int(x) * -1


n, m = map(int, input().split())
a = list(map(rev, input().split()))

heapq.heapify(a)

for i in itertools.repeat(None, m):
    k = heapq.heappop(a)
    heapq.heappush(a, int(k / 2))

print(-sum(a))


Measured memory_bytes: 14180