akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
using namespace std;
//D - AtCoder Express 2
int main(void){
    int N,M,Q;
    std::cin >> N >> M >>Q;
    int t[501][501]={},c[501][501]={};
    for (int i = 1; i <= M; i++) {
        int l,r;
        std::cin >> l >>r;
        t[l][r]++;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            c[i][j]=c[i][j-1]+t[i][j];
        }
    }
    for (int i = 0; i < Q; i++) {
        int p,q;
        std::cin >> p >>q;
        int sum=0;
        for (int j = p; j <= q; j++) {
            sum+=c[j][q]-c[j][p-1];
        }
        std::cout << sum << std::endl;
    }
}


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

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

	if (S == "RRR") cout << 3 << endl;
	else if (S == "RRS") cout << 2 << endl;
	else if (S == "SRR") cout << 2 << endl;
	else if (S == "SSS") cout << 0 << endl;
	else cout << 1 << endl;

	return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,m,x,y,depth[500010],ans=0;
vector <int> g[500010];
bool vis[500010];

int dfs(int pos,int no,int d)
{
	vis[pos]=true;
	depth[pos]=d;
	int low=d;
	rep(i,g[pos].size())
	{
		if(g[pos][i]==no) continue;
		if(depth[g[pos][i]]<d) low=min(low,depth[g[pos][i]]);
		else if(!vis[g[pos][i]])
		{
			int tmp=dfs(g[pos][i],pos,d+1);
			low=min(low,tmp);
			if(tmp>d) ans++; 
		}
	}
	return low;
}

int main()
{
	cin>>n>>m;
	rep(i,m)
	{
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	rep(i,500005) depth[i]=1e9; 
	dfs(1,0,0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 17332
#include<bits/stdc++.h>
#define pb       push_back
#define mp       make_pair
#define mod      1000000007
#define pi       acos(-1.0)
typedef long long ll;
using namespace std;
int main()
{

     ios::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
     string s;
     int n;
     cin>>n;
     if(n)
     cout<<0<<endl;
     else
     cout<<1<<endl;  



      return 0;
 }

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

int main()
{
  int H, W;

  while(1)
  {
    cin >> H >> W;

    if(H == 0 && W == 0) break;

    for(int i = 0; i < H; i++)
    {
      for(int j = 0; j < W; j++)
      {
        if( (i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1) )
        {
          cout << "#";
        }
        else
        {
          cout << ".";
        }
      }
      cout << endl;
    }
  cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3096
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); i++)
#define rep1(i,n) for(int (i) = 1; (i) <= (int)(n); i++)
#define INF 1000000
#define MOD (ll)(1e9 + 7)





int main()
{
    
    ll N,A,B;
    cin >> N >> A >> B;
    
    ll block = N / (A + B);
    ll res = N % (A + B);
    
    cout << A * block + min(res, A) << endl;
    
    
    
    return 0;
}



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

int main(){
	int t;
	cin>>t;
	int a=0,w=0,tl=0,r=0;
	while(t--){
		string s;
		cin>>s;
			if(s=="AC"){
			a++;
		}
		else if(s=="WA"){
			w++;
		}
		else if(s=="TLE"){
			tl++;
		}
		else{
			r++;
		}
		
	}

     cout<<"AC x "<<a<<endl;
      cout<<"WA x "<<w<<endl;
       cout<<"TLE x "<<tl<<endl;
        cout<<"RE x "<<r<<endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

int main() {
    int T, X; cin >> T >> X;

    cout << fixed;
    cout << setprecision(8) << (double) T / X << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long
#define mp make_pair
bool cost[1000];
int n,m,x;
int main()
{
	cin>>n>>m>>x;
	for(int i=0;i<m;i++){
		int a;
		cin>>a;
		cost[a]=1;
	}
	int cnt1=0,cnt2=0;
	for(int i=x;i>=0;i--){
		if(cost[i]==1){
			cnt1++;
		}
	}
	for(int i=x;i<=n;i++){
		if(cost[i]==1){
			cnt2++;
		}
	}
	cout<<min(cnt1,cnt2);
    return 0;
}


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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = ((int)b); i <= ((int)e); i++)
#define RPT0(i, n) RPT(i, 0, ((int)n) - 1)
#define RPT1(i, n) RPT(i, 1, (n))
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

void resolve()
{
    vector<int> x(5);
    RPT0(i, 5) cin >> x[i];

    RPT0(i, 5)
    {
        if (x[i] == 0) {
            cout << (i + 1) << endl;
            return;
        }
    }
}

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


Measured memory_bytes: 3652
s = input()
t = input()

s1 = sorted(s)
s2 = "".join(s1)
t1 = sorted(t, reverse=True)
t2 = "".join(t1)

l = [s2, t2]
l.sort()

if s == t:
  print("No")
elif l[0] == s2:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;


int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;

//    readint(test_cases);
     int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(a); readint(b);

        cout << a*b <<  endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int flag;
  char c1,c2;

  cin >> c1 >> c2;

  if(c1 == 'H'){
    flag=1;
  } else{
    flag=0;
  }

  if(c2 == 'D'){
    flag = flag^1;
  }

  if(flag) cout << 'H' << endl;
  else cout << 'D' << endl;

  return 0;
}


Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc080
// status:

#define SUBMIT
//#define DEBUG

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <queue>
#include <numeric>
#include <limits>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int MAX_K = 10;
const int MAX_N = 100;

int F[MAX_N][MAX_K];
int P[MAX_N][MAX_K + 1];
int n_opens[MAX_N + 1];
int N;

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    auto program_input = std::string(R"(2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
)");
    stringstream stream(program_input);
#endif
    stream >> N;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < MAX_K; ++j) {
            stream >> F[i][j];
        }
    }
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < MAX_K + 1; ++j) {
            stream >> P[i][j];
        }
    }

    auto ans = numeric_limits<int>::min();
    // bit = 1で始めているのは必ず1つ以上の時間帯で店を盛業しなければならないため
    for (int bit = 1; bit < (1 << MAX_K); ++bit) {
        auto sum = 0;
        memset(n_opens, 0, sizeof(n_opens));

        for (int j = 0; j < MAX_K; ++j) {
            if (bit & (1 << j)) {
                for (int i = 0; i < N; ++i) n_opens[i] += F[i][j];
            }
        }

        for (int i = 0; i < N; ++i) sum += P[i][n_opens[i]];
        ans = max(ans, sum);
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool tizu[20][20];
int a,b,c,kazu;
int tansa(int y,int x){
    if(y>b-1||x>a-1){return 0;}
    if(tizu[y][x]==1){return 0;}
    if(y==b-1&&x==a-1){kazu++;return 1;}
    tansa(y+1,x);tansa(y,x+1);
}
int main(){
    while(1){
        for(int i=0;i<20;i++){ 
            for(int j=0;j<20;j++){ tizu[i][j]=0; } 
        }
        kazu=0;
        cin>>a>>b;
        if(a+b==0)break;
        cin>>c;
        for(int i=0;i<c;i++){
            int x,y;
            cin>>x>>y;
            tizu[y-1][x-1]=1;
        }
        tansa(0,0);
        cout<<kazu<<endl;
    }
}

Measured memory_bytes: 3092
import collections
import math

def main():
    A, B = map(int, input().split())
    ans = 0

    if A < B:
        ans+=B
        B-=1
    else:
        ans+=A
        A-=1
    if A < B:
        ans+=B
        B-=1
    else:
        ans+=A
        A-=1
    print(ans)

    return 0


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
s = input()
n = int(s)
keta = len(s)
k = int(input())
# k=1,2,3
ans = 0

dp = [[[0] * (2) for _ in range(k + 1)] for _ in range(keta + 1)]
dp[0][0][0] = 1
for i in range(keta):
    d = int(s[i])
    for j in range(k + 1):
        for smaller in range(2):

            for t in range(10):
                ni = i + 1
                nj = j
                nsmaller = smaller
                if t > 0:
                    nj = j + 1
                if nj > k:
                    continue
                if nsmaller == 0:
                    if t > d:
                        continue
                    if t < d:
                        nsmaller = 1
                dp[ni][nj][nsmaller] += dp[i][j][smaller]
print(dp[keta][k][1] + dp[keta][k][0])


Measured memory_bytes: 41072
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	char a[10001],b[10001];
	int lena,lenb,k=0,i=0,j=0;
	cin>>a>>b;
	lena=strlen(a);
	lenb=strlen(b); 
	while(k<=lena+lenb-1)
	{
		if(i==lena)
		{
			while(j!=lenb)
			{
				cout<<b[j];
				j++;
			}
			return 0;
		}
		else if(j==lenb)
		{
			while(i!=lena)
			{
				cout<<a[i];
				i++;
			}
			return 0;
		}
		k++;
		if(k%2!=0)
		{
			cout<<a[i];
			i++;
		}
		else
		{
			cout<<b[j];
			j++;
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  int n;
  cin >> n;
  vi t(n + 1), x(n + 1), y(n + 1);
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  rep2(i, 1, n + 1) cin >> t[i] >> x[i] >> y[i];
  int ct = 0, cx = 0, cy = 0;
  rep2(i, 1, n + 1) {
    int dd = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
    int dt = t[i] - t[i - 1];
    if(dd > dt || (dt - dd) % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1408
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
string s;
int n,d,f[11111][111][2],a[11111];
void u(int &x,int y){
    x+=y;
    if(x>=orz)x-=orz;
}
int main(){
    cin>>s;
    cin>>d;
    n=s.size();
    for(int i=0;i<n;++i)a[i]=s[i]-48;
    f[0][0][1]=1;
    for(int i=0;i<n;++i){
        for(int j=0;j<d;++j){
            u(f[i+1][(j+a[i])%d][1],f[i][j][1]);
            for(int k=0;k<a[i];++k)u(f[i+1][(j+k)%d][0],f[i][j][1]);
            for(int k=0;k<10;++k)u(f[i+1][(j+k)%d][0],f[i][j][0]);
        }
    }
    int ans=orz-1;
    u(ans,f[n][0][0]);
    u(ans,f[n][0][1]);
    cout<<ans<<endl;
	//system("pause");
	return 0;
}


Measured memory_bytes: 9088
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
ans=0
N=int(input())
if N<105:
    print(0)
    exit(0)
for i in range(104,N+1):
    if i%2==1 and len(make_divisors(i))==8:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
	string S, T;
	cin >> S >> T;
	ll b = S.size() - T.size();
	ll ans = T.size();
	rep(i, b + 1) {
		ll counter = 0;
		rep(j, T.size()) {
			if (S.at(i + j) != T.at(j)) { counter++; }
		}
		ans = min(ans, counter);
	}
	cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll mod = 1e9 + 7;
#define EPS 1e-1
#define PI 3.14159265

#define iofile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;

ll fastpow(ll base, ll pow)
{
    if (!base)
        return 0;
    if (!pow)
        return 1;
    if (pow == 1)
        return base;
    ll x = fastpow(base, pow / 2) % mod;
    x *= x;
    x %= mod;
    if (pow % 2)
        x *= base;
    return x % mod;
}

ll inverse(ll x)
{
    return fastpow(x, mod - 2) % mod;
}

ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];
void init()
{
    fact[0] = inv[0] = 1;
    for (int i = 1; i <= 1e6; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = inverse(fact[i]);
    }
}

void factorize(ll x, map<int, int> &ss)
{
    while (x % 2 == 0)
        ss[2]++, x /= 2;
    for (int i = 3; i <= sqrt(x); i += 2)
        while (x % i == 0)
            ss[i]++, x/= i;
    if (x > 2)
        ss[x]++;
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

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

char grid[1005][1005];
int dp[2005][2005];
int n, m;

ll solve(int i, int j)
{
    if (i >= n || j >= m)
        return 0;
    if (grid[i][j] == '#')
        return 0;
    if (i == n - 1 && j == m - 1)
        return 1;
    if (dp[i][j] != -1)
        return dp[i][j];
    return dp[i][j] = ((solve(i + 1, j) % mod) + (solve(i, j + 1) % mod)) % mod;
}

int main()
{
    fastio
    memset(dp, -1, sizeof dp);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> grid[i][j];
    cout << solve(0, 0);
    return 0;
}


Measured memory_bytes: 18816
import sys
s = str(input())

A = []
for i in range(len(s)):
  A.append(s[i])
  
for i in range(2**3):
  p = []
  for j in range(3):
    if (i>>j)&1 == 1:
      p.append("+")
    else:
      p.append("-")
  temp = s[0]
  for t in range(3):
    temp += p[t]
    temp += s[t+1]
  #print(temp)
  if eval(temp) == 7:
    ans = temp+"=7"
    print(ans)
    sys.exit()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e3 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, dp[maxn][maxn];
vector<string>grid;
bool ok(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] == '.';
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        grid.pb(s);
    }
    dp[0][0] = 1;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
        {
            if(ok(i - 1, j)) dp[i][j] += dp[i - 1][j];
            if(ok(i, j - 1)) dp[i][j] += dp[i][j - 1];
            dp[i][j] %= mod;
        }
    cout << dp[n - 1][m - 1] << "\n";
    return 0;
}


Measured memory_bytes: 5632
n = gets.to_i
rain = gets.split.map(&:to_i)
ans = 0
for i in 0..n-1
  if i % 2 == 0
    ans += rain[i]
  else
    ans -= rain[i]
  end
end
  print "#{ans}"
for i in 0..n-2
  ans = (rain[i] - (ans/2))*2
  print " #{ans}"
end
puts ""


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

using namespace std;

#define M 200005
#define mp make_pair

int n, fa[M];

set<int> se[M];
map< pair<int, int>, int > ext;
queue< pair<int, int> > q;

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

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '0') f = -1; ch = getchar(); }
	while (isdigit(ch)) { (x *= 10) += ch - '0'; ch = getchar(); }
	return x * f;
}

int main()
{
	n = read();
	for (int i = 1, u = 0, v = 0; i <= n * 2 - 2; i++)
	{
		u = read(), v = read();
		se[u].insert(v); se[v].insert(u);
		ext[mp(u, v)]++; ext[mp(v, u)]++;
		if (ext[mp(u, v)] == 2) q.push(mp(u, v));
	}

	for (int i = 1; i <= n; i++) fa[i] = i;

	while (!q.empty())
	{
		int u = q.front().first, v = q.front().second; q.pop();
		int uf = findf(u), vf = findf(v);
		se[uf].erase(vf), se[vf].erase(uf);
		if (se[uf].size() < se[vf].size()) swap(uf, vf);
		for (auto to : se[vf])
		{
			ext[mp(to, vf)] = ext[mp(vf, to)] = 0;
			se[to].erase(vf); se[to].insert(uf); se[uf].insert(to);
			ext[mp(to, uf)]++; ext[mp(uf, to)]++;
			if (ext[mp(to, uf)] == 2) q.push(mp(to, uf));
		}
		fa[vf] = uf; se[vf].clear();
	}

	int cnt = 0;
	for (int i = 1; i <= n; i++)
		if (fa[i] == i) cnt++;
	puts(cnt > 1 ? "NO" : "YES");

	return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	long long answer = 0;
	for(int i = 0; i < n; ++i){
		if(a[i] > x){
			answer += a[i] - x;
			a[i] = x;
		}
	}
	for(int i = 1; i < n; ++i){
		const int t = a[i - 1] + a[i];
		if(t > x){
			answer += (t - x);
			a[i] -= (t - x);
		}
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        //static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var n = Sarray()[0];
            var ai = Slist();
            ai.Sort();
            var max = ai.Last();
            ai.RemoveAt(ai.Count - 1);
            var t1 = max / 2;
            var t2 = (max + 1) / 2;
            var ans = ai[0];
            foreach (var a in ai)
            {
                var t = Min(Abs(t1 - a), Abs(t2 - a));
                var tt = Min(Abs(t1 - ans), Abs(t2 - ans));
                if (t < tt) ans = a;
            }
            WriteLine($"{max} {ans}");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 21472
//fifer a tak luboin
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;

#define pb push_back
#define endl "\n"

// using namespace __gnu_pbds;
using namespace std;
// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 

char c[10][10];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    // freopen("input.in.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) cin >> c[i][j];
    }

    int ans = 0;
    for (int mask1 = 0; mask1 < (1 << n); mask1++) {
        for (int mask2 = 0; mask2 < (1 << m); mask2++) {
            set <int> st1;
            set <int> st2;
            for (int i = 0; i < n; i++) {
                if ((mask1 & (1 << i)) > 0) st1.insert(i);
            }

            for (int i = 0; i < m; i++) {
                if ((mask2 & (1 << i)) > 0) st2.insert(i);
            }

            int cnt = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (st1.count(i - 1) || st2.count(j - 1)) continue;
                    if (c[i][j] != '#') continue;
                    cnt++;
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
    return 0;  
}


Measured memory_bytes: 3656
use proconio::input;

fn main() {
    input! {
        n: i32,
        p: [i32; n],
        q: [i32; n]
    }

    let n_us = n as usize;
    let mut sum1: i32 = 0;
    let mut sum2: i32 = 0;
    let mut vec1: Vec<i32> = Vec::new();
    let mut vec2: Vec<i32> = Vec::new();

    for i_us in 0..n_us {
        let i = i_us as i32;
        let c1 = less_used_count(p[i_us], &vec1);
        let c2 = less_used_count(q[i_us], &vec2);
        sum1 += (p[i_us] - 1 - c1) * factorial(n - i - 1) + p[i_us];
        sum2 += (q[i_us] - 1 - c2) * factorial(n - i - 1) + q[i_us];

        vec1.push(p[i_us]);
        vec2.push(q[i_us]);
    }

    let ans = sum1 - sum2;

    println!("{}", ans.abs());
}

fn factorial(n: i32) -> i32 {
    if n == 0 || n == 1 {
        return 1;
    };
    return n * factorial(n - 1);
}

fn less_used_count(target: i32, vec: &[i32]) -> i32 {
    let mut count = 0;

    for &v in vec {
        if v < target {
            count += 1;
        }
    }

    return count;
}


Measured memory_bytes: 2132
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    a,b,c,d=MI()
    print(max(a*c,a*d,b*c,b*d))
    

        
        
        
        
    
if __name__=="__main__":
    main()



Measured memory_bytes: 67112
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> a(n, vector<bool>(m, false));
    rep(i, n) {
        int k;
        cin >> k;
        rep(j, k) {
            int x;
            cin >> x;
            x--;
            a[i][x] = true;
        }
    }
    int ans = 0;
    rep(j, m) {
        bool flag = true;
        rep(i, n) {
            if (!a[i][j]) flag = false;
        }
        if (flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define clr(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=100010;
int n,k;
bool vis[10];
bool cal(int x){
	while(x>0)
	{
		if(vis[x%10])return false;
		x/=10;
	}
	return true;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		int x;
		cin>>x;
		vis[x]=1;
	}
	for(int i=n;i<=99999;i++)
	{
		if(cal(i)){
			cout<<i<<endl;
			break;
		}
	}
}

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

for i in range(n):
  a[i] -= (i + 1)


a.sort()

if(n%2 == 1):
  b = a[int(n/2)]

else:
  t = 0
  for i in a:
    t += abs(i)
  ave = t/n

  p = int(n/2)
  if(abs(a[p] - ave) <= abs(a[p-1] -ave)):
    b = a[p]
  else:
    b = a[p-1]

k = list(map(lambda x:abs(x-b),a))

print(sum(k))

Measured memory_bytes: 98000
//Solution By SlavicG
#include <bits/stdc++.h>
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
#define mp                          make_pair
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int  main()
{
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 1; i <=n;i++)
	{
		if(i>=1&&i<=9)
			cnt++;
		if(i>=100&&i<=999)
			cnt++;
		if(i>=10000&&i<=99999)
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>

using namespace std;
 
int main(void){
 
    int N;
    cin >> N;
    int a[N];
 
   for(int i = 0; i < N ; i++){
       cin >> a[i];
   }

    sort(&a[0],&a[N]);

   int cnt = 1;
   int ans = 0;
   int tmp = a[0];
   for(int i = 1; i < N ; i++){
        if(a[i] == tmp){
             cnt++;
        }else{
             if(cnt % 2 == 1) ans++;
             tmp = a[i];
             cnt = 1; 
        }
   }
   if(cnt % 2 == 1) ans++;
   cout << ans << endl;
 
    return 0;
}

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

typedef long long ll;
ll const MOD = 1e9+7;

int main(void){
    string s;
    cin >> s;
    ll dp[s.length()+1][4];

    dp[s.length()][3] = 1;
    dp[s.length()][2] = 0;
    dp[s.length()][1] = 0;
    dp[s.length()][0] = 0;

    for(int i=s.length()-1; i>=0; i--){
        int m;
        if(s[i] == '?'){
            m = 3;
        }else{
            m = 1;
        }
        dp[i][3] = m*dp[i+1][3]%MOD;
    }

    for(int i=s.length()-1; i>=0; i--){
        for(int j=2; j>=0; j--){
            int m1, m2;
            if(s[i] == '?'){
                m1 = 3;
            }else{
                m1 = 1;
            }
            if(s[i] == '?' || s[i] == 'A' && j == 0 || s[i] == 'B' && j == 1 || s[i] == 'C' && j == 2){
                m2 = 1;
            }else{
                m2 = 0;
            }
            dp[i][j] = (m1*dp[i+1][j]%MOD + m2*dp[i+1][j+1]%MOD)%MOD;
        }
    }
    cout << dp[0][0] << endl;
}

/*
int main(void){
    string s;
    cin >> s;

    reverse(s.begin(), s.end());

    vector<ll> abc(s.length()+1, 0), bc(s.length()+1, 0), c(s.length()+1, 0);

    for(int i=1; i<=s.length(); i++){
        switch(s[i-1]){
            case 'C':
                c.at(i) = (c.at(i-1) + 1)%MOD;
                bc.at(i) = bc.at(i-1);
                abc.at(i) = abc.at(i-1); 
                break;
            case 'B':
                c.at(i) = c.at(i-1);
                bc.at(i) = (bc.at(i-1) + c.at(i-1))%MOD;
                abc.at(i) = abc.at(i-1);
                break;
            case 'A':
                c.at(i) = c.at(i-1);
                bc.at(i) = bc.at(i-1);
                abc.at(i) = (abc.at(i-1) + bc.at(i-1))%MOD;
                break;
            default:
                c.at(i) = (c.at(i-1) + 1)%MOD;
                bc.at(i) = (bc.at(i-1) + c.at(i-1))%MOD;
                abc.at(i) = (abc.at(i-1) + bc.at(i-1))%MOD;
        }
        cout << c.at(i) << " " << bc.at(i) << " " << abc.at(i) << endl;
    }

    cout << abc.back() << endl;

    return 0;
}
*/

Measured memory_bytes: 3584
#include<stdio.h>
int main()
{
	static char prime[10001];
	int i,j,a;
	for(i=1;i<=10000;i+=2){
		prime[i]=1;
	}
	prime[1]=0;
	prime[2]=1;
	for(i=1;i<=100;i+=2){
		if(prime[i]==1){
			for(j=3;i*j<=10000;j+=2){
				prime[i*j]=0;
			}
		}
	}
	
	while(1){
		scanf("%d",&a);
		if(a==0){
			break;
		}
		for(i=a;i>=2;i--){
			if(prime[i]&&prime[i-2]){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
	}
		return 0;
	}

Measured memory_bytes: 608
def main():
    x = int(input())

    q, r = divmod(x, 11)
    ans = q * 2
    if r == 0:
        pass  # 忘れていた
    elif r <= 6:
        ans += 1
    else:
        ans += 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import Control.Applicative

main = do
  ss <- getLine
  let is = read ss :: Int
  let s = show $ is `mod` 60
  let m = show $ is `div` 60 `mod` 60
  let h = show $ is `div` (60*60)
  let ans = h ++ ":" ++ m ++ ":" ++ s
  putStrLn ans


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N, M;
        N = input.nextInt();
        M = input.nextInt();
        if (N==M)
        System.out.print("Yes\n");
        else System.out.print("No\n");
    }
}


Measured memory_bytes: 35584
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

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

int main() {
	int h, w;
	string str[100];
	cin >> h >> w;
	
	REP(i, h) cin >> str[i];
	
	REP(i, h) REP(j, 2) cout << str[i] << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const LL MOD = 1000000007LL;
LL a[100000];
LL b[100000];
LL sum[100000];
LL cnt[100000];
int main() {
	int N;
	cin >> N;
	LL s = 0;
	for (int i = 0; i < N; i++) cin >> a[i], b[i] = a[i], s += a[i];
	vector<int> v;
	v.push_back(0);
	for (int i = 1; i < N; i++) {
		if (a[i] > a[v.back()]) v.push_back(i);
	}
	sort(b, b + N);
	sum[N - 1] = b[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		sum[i] += sum[i + 1];
		sum[i] += b[i];
	}
	LL prev = 0;
	for (int i = v.size() - 1; i > 0; i--) {
		int pos = lower_bound(b, b + N, a[v[i - 1]]) - b + 1;
		cnt[v[i]] = sum[pos] - a[v[i - 1]] * (N - pos) - prev;
		prev = sum[pos] - a[v[i - 1]] * (N - pos);
	}
	cnt[0] = s - prev;
	for (int i = 0; i < N; i++) cout << cnt[i] << endl;
}

Measured memory_bytes: 4728
n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]

monster_num = 0

for i in reversed(range(n)):
    
    monster_num += min(a[i+1], b[i])
    if b[i] - a[i+1] < 0:
        b[i] = 0
    else:
        b[i] -= a[i+1] 

    monster_num += min(a[i], b[i])
    if a[i] - b[i] < 0:
        a[i] = 0
    else:
        a[i] -= b[i]

print(monster_num)

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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

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

  vector<int> a;
  double ans = 0;

  int n;
  cin >> n;
  rep(i, 1, n) {
    int v;
    cin >> v;
    a.pb(v);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  rep(i, 1, n) {
    ans += double(a[i - 1]) / exp2(i);
  }
  ans += double(a[n - 1]) / exp2(n);
  cout << setprecision(10) << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9

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 N;
ll h[100010];

ll dp[100010];

int main(){
    int N; cin>>N;
    for(int i=0;i<N;i++) cin>>h[i];
    
    for(int i=0;i<100010;++i) dp[i]=INF;
    
    dp[0]=0;
    
    for(int i=1;i<N;i++){
        chmin(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1) chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    
    cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
    
int main()
{
  int N,K;
  cin >> N >> K;
  vector<ll> x(N), y(N), xc(N), yc(N);
  REP(i,N){
    cin >> x[i] >> y[i];
  	xc[i] = x[i];
    yc[i] = y[i];
  }
  sort(ALL(xc));
  sort(ALL(yc));
  ll ans = (1LL<<63)-1;
  REP(i,N){
    int x1 = xc[i];
    FOR(j,i+1,N){
      int x2 = xc[j];
      REP(k,N){
        int y1 = yc[k];
        FOR(l,k+1,N){
          int y2 = yc[l];
          int cnt = 0;
          REP(p,N){
            if(x1 <= x[p] && x[p] <= x2 && y1 <= y[p] && y[p] <= y2) cnt++;
          }
          if(cnt>=K) ans = min(ans,(xc[j]-xc[i])*(yc[l]-yc[k]));
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		boolean isFirst = true;
		boolean isInc = true;
		int min = arr[0];
		int max = arr[0];
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 1; i < n; i++) {
		    if (isFirst) {
		        if (arr[i - 1] < arr[i]) {
		            list.add(arr[i - 1]);
		            isFirst = false;
		        }
		    } else {
		        if (isInc) {
		            if (arr[i - 1] > arr[i]) {
		                list.add(arr[i - 1]);
		                isInc = false;
		            }
		        } else {
		            if (arr[i - 1] < arr[i]) {
		                list.add(arr[i - 1]);
		                isInc = true;
		            }
		        }
		    }
		}
		if (list.size() % 2 == 1) {
		    list.add(arr[n - 1]);
		}
		long money = 1000;
		long stock = 0;
		for (int i = 0; i < list.size(); i++) {
		    if (i % 2 == 0) {
		        stock = money / list.get(i);
		        money %= list.get(i);
		    } else {
		        money += stock * list.get(i);
		    }
		}
		System.out.println(money);
	}
}


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

int main()
{
    int N;
    cin >> N;
    map<string, int> m;
    string S;
    for (int i = 0; i < N; i++)
    {
        cin >> S;
        m[S]++;
    }
    int maximum = 0;
    for (pair<string, int> p : m)
    {
        maximum = max(maximum, p.second);
    }
    set<string> ans;
    for (pair<string, int> p : m)
    {
        if (p.second == maximum)
        {
            ans.insert(p.first);
        }
    }
    for (string a : ans)
    {
        cout << a << endl;
    }
}


Measured memory_bytes: 34560
#include "bits/stdc++.h"
using namespace std;
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
int main() {
	int n; int m;
	while (~scanf("%d%d", &n, &m)) {
		vector<vector<pair<int, int> > > gw(n);
		for (int i = 0; i < m; ++ i) {
			int u, v, w;
			scanf("%d%d%d", &u, &v, &w), -- u, -- v;
			gw[u].push_back(make_pair(v, w));
			gw[v].push_back(make_pair(u, w));
		}
		vector<pair<int, long long>> f(n);
		function<void(int, int)> rec = [&](int i, int p) {
			for (auto e : gw[i]) if (e.first != p) {
				int j = e.first, s = e.second;
				if(f[j].first == 0) {
					f[j] = { -f[i].first, s - f[i].second };
					rec(j, i);
				}
			}
		};
		f[0] = { 1, 0 };
		rec(0, -1);
		const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
		long long L = 1, U = INFL;
		bool ok = true;
		for (int i = 0; i < n; ++ i) {
			const int INF = 0x3f3f3f3f;
			int mins = INF;
			for (auto e : gw[i])
				amin(mins, e.second);
			if (f[i].first == 1)
				amin(U, mins - 1 - f[i].second);
			else
				amax(L, f[i].second - mins + 1);
		}
		for (int i = 0; i < n; ++ i) for (auto e : gw[i]) {
			int j = e.first, s = e.second;
			int a = f[i].first + f[j].first;
			auto b = f[i].second + f[j].second;
			if (a == 0) {
				if (b != s)
					ok = false;
			} else {
				if ((s - b) % a != 0 || (s - b) / a <= 0) {
					ok = false;
				} else {
					amax(L, (s - b) / a);
					amin(U, (s - b) / a);
				}
			}
		}
		ok &= L <= U;
		if (ok) {
			for (int i = 0; i < n; ++ i) for (auto e : gw[i]) {
				int j = e.first, s = e.second;
				auto t = f[i].first * L + f[i].second;
				auto u = f[j].first * L + f[j].second;
				ok &= t > 0 && u > 0 && t + u == s;
			}
		}
		auto ans = ok ? U - L + 1 : 0;
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
main()
{
	long long n,k;
	cin>>n>>k;
	
	vector<long long> v(n);
	
	for(int i=0;i<n;i++)
	cin>>v[i];
	
	/*long long dp[n][k+1]={0};
	
	memset(dp,0,sizeof(dp));
	
	for(int i=0;i<=k && i<=v[0];i++)
	dp[0][i]=1;
	
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<=v[i];j++)
		{
			for(int l=0;l+j<=k;l++)
			{
				dp[i][l+j]=(dp[i][l+j]+dp[i-1][l])%MOD;
			}
		}
	}
	
	cout<<dp[n-1][k];*/
	
	long long dp[k+1]={0};
	dp[0]=1;
	
	for(int i=0;i<n;i++)
	{
		long long tmp[k+1]={0};
		for(int j=k-1;j>=0;j--)
		{
			/*for(int l=1;l<=v[i] && l+j<=k;l++)
			{
				dp[l+j]=(dp[l+j]+dp[j])%MOD;
			}*/
			
			tmp[j+1]=(dp[j]+tmp[j+1])%MOD;
			if(min(j+v[i],k)+1<=k)
			tmp[min(j+v[i],k)+1]=(tmp[min(j+v[i],k)+1]-dp[j]+MOD)%MOD;
		}
		
		for(int j=2;j<=k;j++)
		tmp[j]=(tmp[j]+tmp[j-1])%MOD;
		
		for(int j=1;j<=k;j++)
		dp[j]=(tmp[j]+dp[j])%MOD;
	}
	
	/*for(int j=2;j<=k;j++)
	dp[j]=(dp[j]+dp[j-1])%MOD;*/
	
	cout<<dp[k]<<endl;
}

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

int main(){

    int n; cin >> n;
    vector<vector<int> > g(n * n);
    for(int i = 0; i < 2 * n * (n - 1); i++){
        int a, b; cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    map<pair<int, int>, int> M;
    vector<int> kado;
    for(int i = 0; i < n * n; i++) if(g[i].size() == 2) kado.push_back(i);
    vector<vector<int> > info(n * n, vector<int> (2));

    int s = kado[0];
    queue<pair<int, int> > que;
    vector<bool> used(n * n, false);
    que.push({s, 0});
    used[s] = true;
    
    while(!que.empty()){

        int node = que.front().first;
        int dis = que.front().second;
        info[node][0] = dis;
        que.pop();
        //cout << node << " " << dis << endl;
        for(int i = 0; i < (int)g[node].size(); i++){
            
            int next_node = g[node][i];
            int next_dis = dis + 1;
            if(!used[next_node]){
                used[next_node] = true;
                que.push({next_node, next_dis});
            }
        }
    }

    s = kado[1];
    if(info[s][0] > n) s = kado[2];
    queue<pair<int, int> > que2;
    vector<bool> used2(n * n, false);
    que2.push({s, 0});
    used2[s] = true;
    
    while(!que2.empty()){

        int node = que2.front().first;
        int dis = que2.front().second;
        info[node][1] = dis;
        que2.pop();

        for(int i = 0; i < (int)g[node].size(); i++){
            
            int next_node = g[node][i];
            int next_dis = dis + 1;
            if(!used2[next_node]){
                used2[next_node] = true;
                que2.push({next_node, next_dis});
            }
        }
    }


    for(int i = 0; i < n * n; i++){
        M[{info[i][0], info[i][1]}] = i;
    }


    /*for(int i = 0; i < n * n; i++){
        cout << i << ": " << info[i][0] << " " << info[i][1] << endl;
    }*/



    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int param_0 = i + j;
            int param_1 = n - i - 1 + j;
            cout << M[{param_0, param_1}] + 1 << " ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
using P = pair<ll, ll>;
using event = pair<ll, P>;
int main() {
    init();
    ll N, Q;
    cin >> N >> Q;
    vc<pair<ll,P>> E;
    rep(i,N){
        ll s, t, x;
        cin >> s >> t >> x;
        E.eb(s - x, P(0, x));
        E.eb(t - x, P(-1, x));
    }
    rep(i,Q){
        ll d;
        cin >> d;
        E.eb(d, P(1, i));
    }
    sort(all(E));
    vl ans(Q);
    multiset<ll> ms;
    for(auto e:E){
        ll x;
        P p;
        tie(x, p) = e;
        ll q, v;
        tie(q, v) = p;
        // x, q, v
        if (q == 0)
            ms.emplace(v);
        else if(q==-1)
            ms.erase(ms.lower_bound(v));
        else
            ans[v] = !ms.empty() ? *ms.begin() : -1;
    }
    for (auto a : ans) cout << a << endl;
    return 0;
}

Measured memory_bytes: 28132
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  int a=(N%10);
  if(a==2 || a==4||a==5||a==7||a==9) {cout<<"hon";}
  else if(a==3) {cout<<"bon";}
  else {cout<<"pon";}
  return 0;

}

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

int main() {
  int A, B, ans;
  cin >> A;
  cin >> B;
  if (A > 0 && A < 10 && B > 0 && B < 10) {
    ans = A * B;
  } else {
    ans = -1;
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
class coord{
	public:
		int x,y;
};
int main(void) {
	coord s,t;
	cin >> s.x >> s.y >> t.x >> t.y;
	rep(i,(t.x-s.x)) cout << "R";
	rep(i,(t.y-s.y)) cout << "U";
	rep(i,(t.x-s.x)) cout << "L";	
	rep(i,(t.y-s.y)) cout << "D";
	cout << "D";
	rep(i,(t.x-s.x)+1) cout << "R";	
	rep(i,(t.y-s.y)+1) cout << "U";
	cout << "L";
	cout << "U";
	rep(i,(t.x-s.x)+1) cout << "L";	
	rep(i,(t.y-s.y)+1) cout << "D";
	cout << "R";
	cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  map<ll, ll> s;
  vector<ll> l(n+1);
  s[l[0]]++;
  for(int i=0; i<n; i++){
    l[i+1] = l[i] + a[i];
    s[l[i+1]]++;
  }
  ll ans = 0;
  for(auto p : s){
    ll num = p.second;
    ans += (ll)num*(num-1)/2;
  }
  cout << ans << endl;
}

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

      int d = sc.nextInt();
      int n = sc.nextInt();

      int i = 0;

      int j = 1;

      if (n != 100) {

      while ( i < d ) {
         j = j * 100;
         i = i + 1;
      }
      System.out.println(n * j);


      }
      else {
         if (d == 0) {
            System.out.println(101);
         }
         else if (d == 1) {
            System.out.println(10100);
         }
         else {
            System.out.println(1010000);
         }
      }
   }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin>>s;
    string key="keyence";
    int lnth=s.length();
    
    
    for(int i=0;i<=7;i++){
    	bool ans=true;
    	int ind=0;
    	for(int j=0;j<i;j++){
    		if(key[ind++]!=s[j]){
    			ans=false;
    			//cout<<i<<" "<<j<<" "<<key[ind-1]<<endl;
    			break;
    			
    		}
    	}
    	for(int j=i+lnth-7;j<lnth;j++){
    		if(key[ind++]!=s[j]){
    			ans=false;
    			//cout<<i<<" "<<j<<" "<<key[ind-1]<<endl;
    			break;
    			
    		}
    	}
    	if(ans){cout<<"YES"<<endl;return 0;}
    }
    cout<<"NO"<<endl;
  	return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int r;

signed main () {
    cin >> r;
    cout << 3*r*r << endl;
}


Measured memory_bytes: 764