akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define second sec
#define first fir
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

	int n;
	cin >> n;
	int a[n];
	rep(i, n) cin >> a[i];
	bool f = 1;
	rep(i, n) {
		if(a[i] % 2 == 0) {
			if(a[i] % 3 != 0 && a[i] % 5 != 0) f = 0;
		}
	}
	if(f) puts("APPROVED");
	else puts("DENIED");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <functional>
using namespace std;

int main()
{
	string str;
	int n,k;

	cin >> n >> k;
	cin >> str;

	str[k-1] += 0x20;

	cout << str << endl;

	return 0;
}


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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

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

	while(a >= b) {b*=2; k--;}
	while(b >= c) {c*=2; k--;}

	cout << (k>=0 ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int min_diff = 753;
    
    cin >> s;
    for(int i = 0; i < s.size() - 2; i++)
        min_diff = min(min_diff, abs(stoi(s.substr(i, 3)) - 753));
    
    cout << min_diff << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
using namespace std;

int main(){
  int n,ans=0;
  cin>>n;
  string s[n];
  map<string,int> mp;
  rep(i,n){
    cin>>s[i];
    mp[s[i]]++;
  }
  for(auto p:mp){
    ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 25508
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100010

int ConvertTable[128] = { 0 };

char AnsStr[MAX];

int main() {
	int N, M;
	char inpStr[30];
	
	while (1) {
		fgets(inpStr, 5, stdin);
		N = atoi(inpStr);
		if (!N)break;
		for (int num = 0; num < 128; num++) ConvertTable[num] = 0;
		for (int i = 0; i < N; i++) {
			fgets(inpStr, 5, stdin);
			ConvertTable[inpStr[0]] = inpStr[2];
		}
		fgets(inpStr, 10, stdin);
		M = atoi(inpStr);
		for (int i = 0; i < M; i++) {
			fgets(inpStr, 5, stdin);
			if (ConvertTable[inpStr[0]] == 0)AnsStr[i] = inpStr[0];
			else AnsStr[i] = ConvertTable[inpStr[0]];
		}
		AnsStr[M] = '\0';
		printf("%s\n", AnsStr);
	}
	return 0;
}


Measured memory_bytes: 2032
# cf16-finalA - Where's Snuke?
from string import ascii_uppercase


def main():
    h, w = list(map(int, input().rstrip().split()))
    A = [input().rstrip().split() for _ in range(h)]
    S = ascii_uppercase
    for i in range(h):
        for j in range(w):
            if A[i][j] == "snuke":
                print(S[j], i + 1, sep="")
                return


if __name__ == "__main__":
    main()

Measured memory_bytes: 3768
function Main(input){
    input = input.split("\n");
    var mem = input[0].split(" ").map(Number);
    var arr = input[1].split(" ").map(Number);
    var x= mem[2];
    var a = 0,b=0;
    for(var i=0;i<arr.length;i++){
        if(arr[i]<x)a++;
        else b++;
    }
    console.log(Math.min(a,b))
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    ll dp[n][n+1];
    for(int i = 0; i < n; ++i)
        dp[i][1] = a[i];
    for(int l = 2; l <= n; ++l) {
        for(int i = 0; i+l-1 < n; ++i) {
            dp[i][l] = max(a[i] - dp[i+1][l-1],
                            a[i+l-1] - dp[i][l-1]);
        }
    }
    cout << dp[0][n];
    return 0;
}


Measured memory_bytes: 70400
// Aizu Vol0 0074: Videotape
// 2017.7.30

#include <stdio.h>
#include <stdlib.h>


int main()
{
	int T, H, S;
	int t;

	while (1) {
		scanf("%d%d%d", &T, &H, &S);
		if (T < 0) break;
		t = 7200 - (3600 * T + 60 * H + S);
		printf("%02d:%02d:%02d\n", t / 3600, (t % 3600) / 60, t % 60);
		t *= 3;
		printf("%02d:%02d:%02d\n", t / 3600, (t % 3600) / 60, t % 60);
	}
	return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX_N=50;
const int MAX_M=50;
int N,M;
int A[MAX_M],B[MAX_M];
vector<int>G[MAX_N];
bool visited[MAX_N];

void dfs(int i,int o,int k){//oは親、kは子供
  	visited[k]=true;
    for(auto v:G[k]){
        if(!visited[v]&&(!(v==A[i]&&k==B[i]))&&(!(v==B[i]&&k==A[i])))dfs(i,k,v);
    }
}

signed main(){
    cin>>N>>M;
    REP(i,M){
        int a,b;cin>>a>>b;a--;b--;
        A[i]=a;B[i]=b;
        G[a].eb(b);
        G[b].eb(a);
    }
    int ans=0;
    REP(i,M){
        REP(j,N)visited[j]=false;
        dfs(i,-1,A[i]);
        if(!visited[B[i]])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
ll p[5000];
ll c[5000];
	ll k;
	ll n;

	ll func(int x) {
		ll q = k;
		ll i = 0;
		ll v = x;
		ll tmp=0;
		ll ans=-1000000000000000;//一時的な最大値
		int a[5000];
		rep(i, 5000) {
			a[i] = 0;
		}
		while (a[v] == 0&&q>0) {
			a[v] = 1;
			tmp += c[p[v]];
			ans=max(ans, tmp);
			v = p[v];
			q--;
			i++;
		}
		if (tmp <= 0||q==0) {
			return ans;
		}
		else {
			tmp = tmp * ((k / i)-1);
			ll j = k % i+i;
			while (j>0) {
				tmp += c[p[v]];
				ans = max(ans, tmp);
				v = p[v];
				j--;
				
			}
			return ans;

		}
		

	}
//小文字=大文字+32
int main() {
	cin >> n;
	cin >> k;
	rep(i, n) {
		cin >> p[i];
		p[i]--;
	}
	rep(i, n) {
		cin >> c[i];
	}
	ll tmp;
	ll ans=-10000000000000000;
	rep(i, n) {
		tmp = func(i);
		ans = max(tmp, ans);
	}
	cout << ans;


}
	



Measured memory_bytes: 3680
#include<cstdio>
#include<deque>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
	int a[3];
	for(int i=0;i<3;i++)
		scanf("%d",&a[i]);
	sort(a,a+3);
	if((2*a[2]-a[1]-a[0])%2)
		printf("%d\n",(2*a[2]-a[1]-a[0])/2+2);
	else
		printf("%d\n",(2*a[2]-a[1]-a[0])/2);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; i++)
int main(){
    string s; cin >> s;
    ll k; cin >> k;
    int cnt=0,ans = 1;
    rep(i,s.size()){
        if(s[i] != '1'){
            cnt = i;
            ans = s[i] - '0';
            break;
        }
    }
    if(cnt < k){
        cout << ans << endl;
    }else{
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

def CheckColor(a, count):
    if 1 <= a and a <= 399:
        count[0] += 1
    elif 400 <= a and a <= 799:
        count[1] += 1
    elif 800 <= a and a <= 1199:
        count[2] += 1
    elif 1200 <= a and a <= 1599:
        count[3] += 1
    elif 1600 <= a and a <= 1999:
        count[4] += 1
    elif 2000 <= a and a <= 2399:
        count[5] += 1
    elif 2400 <= a and a <= 2799:
        count[6] += 1
    elif 2800 <= a and a <= 3199:
        count[7] += 1
    else:
        count[8] += 1

ans = 0
count = [0 for _ in range(9)]

for a in A:
    CheckColor(a, count)

for c in count[:8]:
    if c != 0:
        ans += 1

print(max(ans, 1), ans + count[8])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;

ll fastpowMOD(ll a, ll p,ll MOD);
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }

int main(){
  ll k,x;
  cin>>k>>x;
  if(k*500>=x){
    cout<<"Yes\n";
  }
  else{
    cout<<"No\n";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,t,a;
    cin>>n>>t>>a;

    vector<pair<double,int>>x(n);

    for (int i=0;i<n;i++) {
        int h;
        cin>>h;

        double y=abs(a-(t-h*0.006));
        int z=i+1;

        x[i]=make_pair(y,z);
    }

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

    cout<<x[0].second<<endl;

}


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

int A, B, C;

int main(){
  cin >> A >> B >> C;

  if(A == B && B != C || B == C && A != B || A == C && B != A) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
program meow
implicit none

integer(8) :: i,j,k,n,a(300000),bits(0:300000,50)=0,test(50),ans=0,last_success=0

read(*,*) n
read(*,*) (a(i),i=1,n)

do i= 1,n
	do j= 1,50
		if(BTEST(a(i),j-1)) then
			bits(i,j) = bits(i-1,j) + 1
		else
			bits(i,j) = bits(i-1,j)
		endif
	enddo
enddo

i=1
j=1
do
	do
		test(1:50) = bits(j,1:50) - bits(i-1,1:50)
		if(maxval(test(1:50))<=1) then
!			write(*,*) i,j,"o"
			last_success = 1
			if(j==n) then
				!スコア加算
				ans = ans + (j-i+1)
				if(i==n) then
					goto 100
				else
					i = i+1
				endif
			else
				j=j+1
			endif
		else
!			write(*,*) i,j,"x"
			if(last_success==1) then
				ans = ans + (j-i)
			endif
			i=i+1
		endif
	enddo
enddo

100 continue
write(*,*) ans

end program

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

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

using namespace std;

int main(){
  int n;cin>>n;
  vector<pair<ll, ll>> xy;
  rep(i, n){
    int x,y;cin>>x>>y;
    xy.emplace_back(x,y);
  }

  map<pair<ll, ll>, int> logger;
  int maxc=0;
  rep(i, n)rep(j, n){
    if(i==j)continue;
    ll dx = xy[i].first-xy[j].first;
    ll dy = xy[i].second-xy[j].second;
    auto k = make_pair(dx,dy);
    logger[k]++;
    maxc=max(maxc, logger[k]);
//cout<<k.first<<' '<<k.second<<endl;
  }
//cout<<endl;
  cout<<(n-maxc)<<endl;
//cout<<n<<' '<<maxc;

  return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> g(n, vector<bool>(n));
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a][b] = g[b][a] = true;
    }
    vi b(n-1);
    rep(i, n-1) b[i] = i + 1;
    ll ans = 0;
    do {
        bool ok = true;
        if (!g[0][b[0]]) ok = false;
        rep(i, n-2) {
            if (!g[b[i]][b[i+1]]) ok = false;
        }
        if (ok) ++ans;
    } while (next_permutation(all(b)));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fs first
#define sc second
#define int long long

using namespace std;

bool used[256];
signed main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        used[s[i]] = true;
    }
    for (char i = 'a'; i <= 'z' ; i++)
        if (!used[i]) {
            cout << s << i;
            return 0;
        }
    for (int i = s.size() - 2; i >= 0; i--) {
        char minn = 'z' + 1;
        for (int j = i + 1; j < s.size(); j++) {
            if (s[j] > s[i]) {
                minn = min(minn, s[j]);
            }
        }
        if (minn != 'z' + 1) {
            for (int j = 0; j < i; j++)
                cout << s[j];
            cout << minn;
            return 0;
        }
    }
    cout << -1;
    return 0;
}


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

int main() {
  ll n,sum,ans = 1e9;
  cin>>n;
  vector<ll> x(n);
  for(ll i=0; i<n; i++) cin>>x[i];
  sort(x.begin(),x.end());
  for(ll i=x[0]; i<=x[n-1]; i++){
    for(ll j=0; j<n; j++){
      sum += pow(x[j]-i,2);
    }
    ans = min(ans,sum);
    sum = 0;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const int vx[]={1,0,-1,0}, vy[]={0,1,0,-1};
const ll LINF=1e18;
const ld PI=abs(acos(-1));

ld x[5], y[5];

int main(){
	REP(i,0,3) cin >> x[i] >> y[i];
	
	
	ld ma = 0, s = 0, S = abs((x[0] - x[2]) * (y[1] - y[2]) - (x[1] - x[2]) * (y[0] - y[2])) / 2.0;
	REP(i,0,3){
		s += sqrt((x[i] - x[(i + 1) % 3]) * (x[i] - x[(i + 1) % 3]) + (y[i] - y[(i + 1) % 3]) * (y[i] - y[(i + 1) % 3]));
		ma = max(ma, sqrt((x[i] - x[(i + 1) % 3]) * (x[i] - x[(i + 1) % 3]) + (y[i] - y[(i + 1) % 3]) * (y[i] - y[(i + 1) % 3])));
	}
	
	ld r = 2 * S / s;
	
	cout << fixed << setprecision(9);
	cout << (ld)ma * (ld)r / (ld)(2 * r + ma) << endl;
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pl;

int main() {
    int n,m;
    vector<pl> v;
    cin >> n >> m;
    for(int i=0;i<n;i++) {
        ll a,b;
        cin >> a >> b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(), v.end(), [](const pl &s1, const pl &s2) {
        return s1.first < s2.first;
    });
    ll expence=0;
    ll remain = m;
    for(auto it = v.begin();it !=v.end();it++) {
        //cout << (*it).first << (*it).second << endl;
        ll buy = min(remain, (*it).second);
        remain -= buy;
        expence += buy * (*it).first;
        if (remain <= 0) {
            break;
        }
    }
    cout << expence << endl;
    return 0;
}

Measured memory_bytes: 2420
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int[] c = new int[2*n];
		int[] d = new int[2*n];
		
		for(int i=0;i<2*n;i++) c[i] = i+1;
		
		int k = 0;
		for(int i=0;i<m;i++){
			k = sc.nextInt();
			if(k==0){
				for(int j=0;j<n;j++) d[j] = c[n+j];
				for(int j=n-1;j>=0;j--) c[2*j] = c[j];
				for(int j=n-1;j>=0;j--) c[2*j+1] = d[j];
			}else{
				for(int j=0;j<k;j++) d[j] = c[j];
				for(int j=k;j<2*n;j++) c[j-k] = c[j];
				for(int j=0;j<k;j++) c[2*n-k+j] = d[j];
			}
		}
		for(int i=0;i<2*n;i++) System.out.println(c[i]);	
	}	
}

Measured memory_bytes: 23864
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

double dist(double x1,double y1,double x2,double y2){
    return pow(x2-x1,2) + pow(y2-y1,2);
}

int main(){
    int r,n;
    while(cin >> r >> n,r|n){
        vector<int> height(41,0);
        rep(i,n){
            int a,b,h;
            cin >> a >> b >> h;
            a+=20,b+=20;
            for(int i=a;i<b;i++){
                height[i]=max(height[i],h);
            }
        }
        int flag=0;
        for(double c=-r;c<=20.0;c+=0.0005){
            for(int i=-r;i<=r;i++){
                if(dist((double)i,(double)min(height[i+20],height[i+20-1]),0.0,c)<(double)r*(double)r){
                    cout << c+r << endl;
                    flag=1;
                    break;
                }
            }
            if(flag)break;
        }
    }
    return 0;
}


Measured memory_bytes: 3224
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
#define M 1000000007

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll>a(n);
    unordered_map<ll,ll>m;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        m[i-a[i]]++;
        //m[a[i]-i]++;
    }
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        ans=ans+ m[i+a[i]];
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 20152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] d = new int[n];
		int ans = 0;

		for(int i = 0; i < n; i++) d[i] = sc.nextInt();

		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				ans += d[i]*d[j];
			}
		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
    int h, w, y, x;
    cin >> h >> w >> y >> x;
    cout << (h*w)-(y*w+x*h-y*x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int w, h, x, y, r;
	
	cin >> w >> h >> x >> y >> r;
	
	if (x >= r && x <= (w - r) && y >= r && y <= (h - r))
	{
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
}



Measured memory_bytes: 3096
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    x=ii()
    print(1 if x == 0 else 0)





if __name__ == "__main__":
    main()

Measured memory_bytes: 61884
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) ((int)x.size())

const int mod = 1000*1000*1000 + 7;
vector<int> a(1<<21, 0);
vector<int> b[25];
int r[25][25];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    a[0] = 1;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> r[i][j];
    a[0] = 1;
    for(int i = 1; i < (1<<n); i++)
        b[__builtin_popcount(i)].pb(i);
    for(int i = 1; i <= n; i++)
        for(auto &mask: b[i])
            for(int m = 0; m < n; m++)
                if(((1<<m)&mask) && r[m][i-1])
                    a[mask] += a[mask^(1<<m)], a[mask] %= mod;
    cout << a[(1<<n)-1] << endl;
}

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

int main() {
  int N;
  cin >> N;
  double A[105], avg = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    avg += A[i];
  }
  avg     = round(avg / N);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += (A[i] - avg) * (A[i] - avg);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long int LL;
const LL mod = 1000000000+7;
LL mul(LL a, LL b){ return ((a%mod)*(b%mod))%mod;   }
LL add(LL a, LL b){ return ((a%mod)+(b%mod))%mod;   }

void solve(){
	LL X;
	cin>>X;
	LL a = 100;
	LL k=0;
	while(a<X){
		a=a*1.01;
		k++;
	}
	cout<<k<<endl;
	return ;
}

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

	solve();

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

	return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
int gcd(int a, int b)
{
	int r = a % b;
	while (r > 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	char s[100005], t[100005];
	scanf("%s%s", s, t);
	int g;
	g = gcd(n, m);
	int i;
	for (i = 0; i < g; i++)
	{
		if (s[i * n / g] != t[i * m / g])
		{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", (long long int)n * (long long int)m / (long long int)g);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int N, M, Q;
  cin >> N >> M >> Q;
  vector<int> L(M), R(M);
  rep(i, M) cin >> L[i] >> R[i];
  vector<int> p(Q), q(Q);
  rep(i, Q) cin >> p[i] >> q[i];

  vector<vector<int>> sum(N+1, vector<int>(N+1, 0));
  rep(i, M) sum[L[i]][R[i]]++;
  rep(i, N) rep(j, N) {
    sum[i+1][j+1] += sum[i+1][j] + sum[i][j+1] - sum[i][j];
  }
  
  rep(i, Q) {
    int ans = sum[q[i]][q[i]] - sum[p[i]-1][q[i]] - sum[q[i]][p[i]-1] + sum[p[i]-1][p[i]-1];
    cout << ans << endl;
  }
}


Measured memory_bytes: 4352
N, K = map(int, input().split())



y = abs(N - K)
N = y
y2 = abs(N - K)
c=1
dif = (y, y2)

if dif[c-1] < dif[c]:
    dif += (dif[-1],)
    
if dif[c-1] > K:

    dif += (dif[c-1]%K,)
    c += 1

while dif[c-1] > dif[c]:

    yy = abs(dif[c] - K)
    dif += (yy,)
    c += 1


print(min(dif))
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 666666666

ll DP[101][100001];
ll pf[101][100001];
ll A[101];
ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        cin>>A[i];

    for(int i=0; i<=n; i++)
        DP[i][0]=pf[i][0]=1;

    for(int j=0; j<=k; j++)
        DP[0][j]=pf[0][j]=1;

    for(int i=1; i<=n; i++)
    for(int j=1; j<=k; j++)
    {
        DP[i][j]+=pf[i-1][j] - (j-A[i]-1 >=0 ? pf[i-1][j-A[i]-1] : 0);
        DP[i][j]%=mod;
        DP[i][j]+=mod;
        DP[i][j]%=mod;

        pf[i][j]=(pf[i][j-1]+DP[i][j])%mod;
    }

    cout<<DP[n][k];
}


Measured memory_bytes: 158080
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<int,int> pa;
const int N=4e6+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
}int r,c,n;
vector<pa>o;
int P(int x,int y){
	if(!x)return y;
	if(y==c)return c+x;
	if(x==r)return c+c+r-y;
	if(!y)return c+c+r+r-x;
	return -1;
}
int main(){
	read(r,c,n);
	rep(i,1,n){int x1,y1,x2,y2;
		read(x1,y1);read(x2,y2);
		int i1=P(x1,y1),i2=P(x2,y2);
		if(i1!=-1&&i2!=-1)o.pb(pa(i1,i)),o.pb(pa(i2,i));
	}
	sort(all(o));
	vector<int>q;
	re(i,0,o.size()){
		if(!q.size()||q.back()!=o[i].w2)q.pb(o[i].w2);
			else q.pop_back();
	}
	if(!q.size())puts("YES");else puts("NO");
}

Measured memory_bytes: 3444
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n+1];
        for(int i=1; i<=n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        int[] b = new int[n+1];
        b[0] = 1;
        int i= 1;
        int ans = -1;
        while(i <= n) {
            b[i] = a[b[i-1]];
            if(b[i] == 2) {
                ans = i;
                break;
            }
            i++;
        }
        
        System.out.println(ans);
    }

}


Measured memory_bytes: 50112
import sys
from fractions import gcd
import bisect
 
stdin = sys.stdin
 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

num = na()
num.sort()

print(num[2] - num[0])

Measured memory_bytes: 5076
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine().Replace(" ",""));
            double sqrt = Math.Sqrt(num);
            if (sqrt == (int)sqrt)
            {
                Console.WriteLine("Yes");
            }
            else 
            {
                Console.WriteLine("No");
            }

        }
    }
}


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

template<long long modulus>
class ModInt{
    long long num;

    long long mod(long long n){
        if(n < 0LL){
            n += (abs(n + 1LL) / modulus + 1LL) * modulus;
        }
        return n % modulus;
    }

    long long ext_gcd(long long a, long long b, long long &x, long long &y){
        if(b == 0LL){
            x = 1;
            y = 0;
            return a;
        }

        long long d = ext_gcd(b, a % b, y, x);
        y -= a / b * x;

        return d;
    }

    long long get_inv(long long n){
        long long x, y;
        ext_gcd(n, modulus, x, y);
        return mod(x);
    }

public:
    ModInt(long long n = 0LL){
        init(n);
    }

    void init(long long n = 0LL){
        num = mod(n);
        return;
    }

    long long get(void){
        return num;
    }

    ModInt &operator+=(const ModInt &rhs){
        num += rhs.num;
        if(num >= modulus){
            num -= modulus;
        }
        return *this;
    }

    ModInt &operator-=(const ModInt &rhs){
        num -= rhs.num;
        if(num < 0LL){
            num += modulus;
        }
        return *this;
    }

    ModInt &operator*=(const ModInt &rhs){
        num = num * rhs.num % modulus;
        return *this;
    }

    ModInt &operator/=(const ModInt &rhs){
        long long inv = get_inv(rhs.num);
        num = num * inv % modulus;
        return *this;
    }

    ModInt operator+(const ModInt &rhs) const {
        return ModInt(*this) += rhs;
    }

    ModInt operator-(const ModInt &rhs) const {
        return ModInt(*this) -= rhs;
    }

    ModInt operator*(const ModInt &rhs) const {
        return ModInt(*this) *= rhs;
    }

    ModInt operator/(const ModInt &rhs) const {
        return ModInt(*this) /= rhs;
    }

    ModInt &operator=(const ModInt &rhs){
        num = rhs.num;
        return *this;
    }

    bool operator<(const ModInt &rhs) const {
        return num < rhs.num;
    }
};

template<long long modulus>
istream &operator>>(istream &lhs, ModInt<modulus> &rhs){
    long long val;
    lhs >> val;
    rhs.init(val);
    return lhs;
}

template<long long modulus>
ostream &operator<<(ostream &lhs, ModInt<modulus> rhs){
    lhs << rhs.get();
    return lhs;
}

using mint = ModInt<1000000007LL>;

mint dp[100001][13];

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

    int n = s.size();

    dp[0][0] = mint(1);

    for(int i = 0 ; i < n ; ++i){
        for(int j = 0 ; j < 13 ; ++j){
            for(int d = 0 ; d < 10 ; ++d){
                if(s[i] != '?' && s[i] - '0' != d){
                    continue;
                }
                dp[i + 1][(j * 10 + d) % 13] += dp[i][j];
            }
        }
    }

    cout << dp[n][5] << endl;

    return 0;
}

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

using namespace std;

int main(void){

    int n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    for(int i=0; i<n; i++) cin >> t[i];
    sort(t.begin(), t.end());
    
    int passenger = 0;
    int result = 0;
    int times = 0;
    for(int i=0; i<n; i++) {
        if(passenger == 0) {
            times = t[i];
        }
        passenger++;
        
        if(passenger == c) {
            passenger = 0;
            result++;
            continue;
        }
//        cout << times << " " << passenger << " "  << t[i] << " " << result << endl;
        if(i!=n-1) {
            if(t[i+1]==t[i]) {
                continue;
            }
            else {
                if(t[i+1]-times>k) {
//                    cout << "check" << endl;
                    if(passenger%c==0) result += passenger/c;
                    else result += passenger/c + 1;
                    passenger = 0;
                }
            }
        }
        else {
            if(passenger%c==0) result += passenger/c;
            else result += passenger/c + 1;
        }
        
    }
    
    cout << result << endl;

    return 0;
    
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    string S[110];
    rep(i, H) cin >> S[i];
    bool isH[110] = {};
    bool isW[110] = {};
    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '#') isH[i] = true;
        }
    }
    rep(j, W) {
        rep(i, H) {
            if (S[i][j] == '#') isW[j] = true;
        }
    }
    rep(i, H) {
        if(!isH[i]) continue;
        rep(j, W) {
            if (isW[j]) cout << S[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = Math.abs(sc.nextLong());
        long k = sc.nextLong();
        long d = sc.nextLong();
        long min = x % d;
        long count = x / d;
        if(count >= k) {
            System.out.println(x - k * d);
            return;
        }
        if((k - count) % 2 == 0) {
            System.out.println(min);
        } else {
            System.out.println(d - min);
        }
    }
}

Measured memory_bytes: 35664
N, A, B = map(int, input().split())
ans = []

def degitsum(x):
	string = str(x)
	array = list(map(int, string))
	return sum(array)

for i in range(N+1):
	if A <= degitsum(i) and degitsum(i) <= B:
		ans.append(i)
	else:
		continue
		
print(sum(ans))

Measured memory_bytes: 3404
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector< vector<long long int> > A(N,vector<long long int>(N));
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < N; ++j){
      cin >> A[i][j];
    }
  }
  long long int t = 0;
  
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < N; ++j){
      for(int k = 0; k < N; ++k){
        if(A[i][j] > A[i][k] + A[k][j]){
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < i; ++j){
      t += A[i][j];
      for(int k = 0; k < N; ++k){
        if(k == i || k == j) continue;
        if(A[i][j] == A[i][k] + A[k][j]){
          t -= A[i][j];
          break;
        }
      }
    }
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 1024
a = list(input())
a.sort()
s = 1
if (len(set(a))==2 and a[0]==a[1] and a[2]==a[3]):s = 0

def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')
y(s,0)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>

using namespace std;

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

  int digit[3] = { 1, 1, 1 };

  if (n / 100 == 1) digit[0] = 9;
  if ((n / 10) % 10 == 1) digit[1] = 9;
  if (n % 10 == 1) digit[2] = 9;

  stringstream ss;
  ss << digit[0] << digit[1] << digit[2];

  cout << ss.str() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;
#define toInt(_char) _char - '0'

using namespace std;
//
// Created by karayuu on 2018-12-18.
//

int main() {
    double n = 0;
    int c = 0;
    cin >> n >> c;
    n++;

    int sum = 0;
    FOR(i, 0, c) {
        int a;
        cin >> a;
        sum += a;
    }

    int cake = (int) ceil(sum / n);
    P(cake);
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int f(ll n) {
    int cnt = 0;
    while (n > 0) {
        n /= 10;
        cnt++;
    }
    return cnt;
}

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

    int ans = f(N);
    for (ll a = 1LL; a * a <= N; a++) {
        if (N % a != 0) continue;
        ll b = N / a;
        int tmp = max(f(a), f(b));
        chmin(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
SP = []


[SP.append(input().split() + [i])for i in range(N)]


for i in range(N):
    SP[i][1] = int(SP[i][1])
SP.sort(reverse=True)
SP.sort(key=lambda x: x[0])


for a, b, c in SP:      
	print(c + 1) 

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
map<string, int> mp;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    while(n--){
        string s; cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << "\n";
    cout << "WA x " << mp["WA"] << "\n";
    cout << "TLE x " << mp["TLE"] << "\n";
    cout << "RE x " << mp["RE"] << "\n";
}

Measured memory_bytes: 3664
s = list(input())

ans = [0]*10
for i in range(len(s)):
  if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
    ans[i] += 1
    
count = 0    
cnt = []
for i in range(10):
  if ans[i] == 0:
    cnt.append(0)
    count = 0
  else:
    count += 1
    cnt.append(count)
    
print(max(cnt))

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

using ll=long long;
const int Nmax=110;
const int Vmax=100010;
int N,W; 
ll dp[Nmax+1][Vmax+1];
ll v[Nmax];
ll w[Nmax];
const ll INF=1LL<<60;


int main(){
  cin >> N >> W;
  for (int i=1;i<=N;i++)
      cin >> w[i] >> v[i];
  for (int j=0;j<=Vmax;j++){
    for (int i=0;i<=N;i++){
      dp[i][j]=INF;
    }
  }
  dp[0][0]=0;
  for (int j=0;j<=Vmax;j++){
    for (int i=0;i<N;i++){
      if (j+v[i+1]<=Vmax) chmin(dp[i+1][j+v[i+1]],dp[i][j]+w[i+1]);
      chmin(dp[i+1][j],dp[i][j]);
    }
  }
  ll ans=0;
  for (int j=0;j<=Vmax;j++){
    if(dp[N][j]<=W) ans=j;
  }
    
  cout << ans << endl;
  
}

Measured memory_bytes: 80128
#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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll inf = 1LL<<59;

int N,K;
vector<pair<int, ll>> adj[100005];
vector<ll> d(100005, inf);

void bfs(){
    queue<pair<int, ll>> q;
    d[K] = 0;
    q.push(make_pair(K, 0));

    while(!q.empty()){
        pair<int, ll> pa = q.front(); q.pop();
        int now = pa.first;
        for(int i=0; i<adj[now].size(); i++){
            int nxt = adj[now][i].first;
            if(d[nxt] > d[now]+adj[now][i].second){
                d[nxt] = d[now]+adj[now][i].second;
                q.push(adj[now][i]);
            }
        }
    }
}

int main(){
    cin >> N;
    for(int i=0; i<N-1; i++){
        int a, b; ll c;
        cin >> a >> b >> c;
        adj[a].push_back(make_pair(b, c));
        adj[b].push_back(make_pair(a, c));
    }

    int Q;
    cin >> Q >> K;

    d[K] = 0;
    bfs();

    vector<ll> ans(Q);
    for(int i=0; i<Q; i++){
        int x, y; cin >> x >> y;
        ans[i] = d[x] + d[y];
    }

    for(auto e:ans) cout << e << endl;
}


Measured memory_bytes: 10752
// https://atcoder.jp/contests/abc160/tasks/abc160_d

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

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#if DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int N_MAX = 2*1e3;

int N, X, Y;
vector<int> ans;

int step1(int i, int j) {
  if (i >= X) return 0;
  return min(j, X) - i;
}

int step2(int i, int j) {
  if (i > Y || j < X) return 0;
  i = max(i, X);
  j = min(j, Y);
  return min(j - i, (i - X) + 1 + (Y - j));
}

int step3(int i, int j) {
  if (j <= Y) return 0;
  return j - max(i, Y);
}

int main() {
  cin >> N >> X >> Y;
  X--; Y--;
  ans = vector<int>(N, 0);
  REP(j, N) REP(i, j) {
    int d = step1(i, j) + step2(i, j) + step3(i, j);
    ans[d]++;
  }
  FOR(d, 1, N - 1) {
    cout << ans[d] << endl;
  }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
  string N;
  int K;
  cin>>N>>K;
  long long dp[100][1000];
  dp[1][1]=9;
  dp[2][1]=0;
  dp[3][1]=0;
  for(int i=2;i<=(int)N.size();i++){
    dp[1][i]=9*i;
    dp[2][i]=9*dp[1][i-1]+dp[2][i-1];
    dp[3][i]=9*dp[2][i-1]+dp[3][i-1];
    //cout<<dp[1][i]<<" "<<dp[2][i]<<" "<<dp[3][i]<<" "<<dp[1][i]+dp[2][i]+dp[3][i]<<endl;
  }
  if(K==1){cout<<dp[1][(int)N.size()-1]+(N.at(0)-'0')<<endl;}
  if(K==2){
    long long ans=dp[1][(int)N.size()-1]*(N.at(0)-'0'-1)+dp[2][(int)N.size()-1];
    while((int)N.size()>=2){
      N=N.substr(1);
      if(N.at(0)!='0'){
        ans+=dp[1][(int)N.size()-1];
        ans+=N.at(0)-'0';
        break;
      }
    }
    cout<<ans<<endl;
  }
  if(K==3){
    long long ans=dp[3][(int)N.size()-1]+dp[2][(int)N.size()-1]*(N.at(0)-'0'-1);
    while((int)N.size()>=3){
      N=N.substr(1);
      if(N.at(0)!='0'){
        ans+=dp[2][(int)N.size()-1];
        ans+=dp[1][(int)N.size()-1]*(N.at(0)-'0'-1);
        while((int)N.size()>=2){
          N=N.substr(1);
          if(N.at(0)!='0'){
            ans+=dp[1][(int)N.size()-1];
            ans+=N.at(0)-'0';
            if(ans!=0){
              cout<<ans<<endl;
              return 0;
            }
          }
          cout<<ans<<endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 3588
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
     String[] nyu=sc.nextLine().split(" ");

   //  String nyu=sc.nextLine();
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu);

//StringBuffer sb = new StringBuffer(nyu);
//		String dst = sb.reverse().toString();

//     String nyu2=sc.nextLine();
//int E=Integer.parseInt(nyu2);



//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

//int res=Math.min((A*B),C);

//for(String tem:nyu){
//if(tem.equals("1"))res++;
//}
//int res=0;
//for(int i=0;i<300;i++){
//if(num[i]==1)res=i;
//}

//char[] c = nyu.toCharArray();


//System.out.println(nyu+"-"+line_r_2+"-"+nyu2+"-"+line_r_1);


//if(nyu.equals(dst)){
//double res=Math.ceil((AB)/2);

System.out.println((A-1)*(B-1));
//}else if((int)c[0]>(int)c[2]){
//System.out.println(">");

//}else{
//System.out.println("No");

//}




	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
ll bit[500005];
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,ans,sum;
ll a,b,c,d,e,g,h,w;
ll x[500005],y[500005],z[500005];
ll l1[500005],l2[500005];

ll bitsum(ll i){
	ll s = 0;
	while(i>0){
		//p("hoi");
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
void bitadd(ll b,ll x){
	while(b <= n){
		//p("hoi");
		bit[b] += x;
		b += b & -b;
	}
}

int main(){
	cin >> a >> b >> r >> c >> d >> r >> r;
	r = 0;
	//ans += b;
	for(i=0;i<=min(a,min(c,d));i++){
		num = (a - i)/2 + (c - i)/2 + (d - i)/2;
		sum = b + num * 2 + 3 * i;
		ans = max(ans,sum);
		k ++;
		if(k >= 10)break;
	}

	p(ans);


	//p(ans);
    return 0;
}

Measured memory_bytes: 26624
n = int(input())
s = input()
d = [0,0,0]
for i in s:
    if(i == 'R'):d[0] += 1
    elif(i == 'G'):d[1] += 1
    elif(i == 'B'):d[2] += 1
c = d[0] * d[1] * d[2]

for i in range(n):
    for j in range(i+1,n):
        k = 2 * j - i
        if(k >= n):continue
        if(s[i] == s[j]):continue
        if(s[j] == s[k]):continue
        if(s[i] == s[k]):continue
        c -= 1

print(c)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;cin>>N;
    vector<int> A(N);
    REP(i,N) cin>>A[i];
    int cnt = 0;
    multiset<int> st;
    REP(i,N){
        auto itr = st.lower_bound(A[i]);
        if(itr == st.begin()){
            cnt++;
            st.insert(A[i]);
        }
        else{
            itr--;
            st.erase(itr);
            st.insert(A[i]);
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 5376