akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2005;
struct node{
    int u,v,nxt;
}edge[N*2];
int head[N],mcnt;
void add_edge(int u,int v){
    mcnt++;
    edge[mcnt].u=u;
    edge[mcnt].v=v;
    edge[mcnt].nxt=head[u];
    head[u]=mcnt;
}
int n,k;
int du[N];
int deep[N];
void dfs(int u,int fa,int d){
    deep[u]=d;
    for(int i=head[u];i;i=edge[i].nxt){
        int v=edge[i].v;
        if(v==fa)
            continue;
        dfs(v,u,d+1);
    }
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add_edge(u,v);
        add_edge(v,u);
        du[u]++;
        du[v]++;
    }
    int ans=n;
    if(k&1)
        for(int u=1;u<=n;u++)
            for(int i=head[u];i;i=edge[i].nxt){
                int v=edge[i].v;
                if(v<u)
                    continue ;
                dfs(u,v,0);
                dfs(v,u,0);
                int cnt=0;
                for(int j=1;j<=n;j++)
                    if(deep[j]>k/2)
                        cnt++;
                ans=min(ans,cnt);
            }
    else
        for(int u=1;u<=n;u++){
            dfs(u,0,0);
            int cnt=0;
            for(int j=1;j<=n;j++)
                if(deep[j]>k/2)
                    cnt++;
            ans=min(ans,cnt);
        }
    printf("%d\n",ans);
}


Measured memory_bytes: 384
n = int(input())
S = input()
m = n//2
l,r = 0,n-1
ans = 0
def check(m):
    Se = set()
    for i in range(n-2*m+1):
        Se.add(S[i:i+m])
        if S[i+m:i+2*m] in Se:
            return True
    return False

while l<=r:
    m = (l + r) // 2
 #   print("m = ", m)
    if check(m):
        fl = True
        l = m+1
        ans = l-1
 #       print(l-1,"にて共通部分有")
    else:
        r = m-1
 #       print(r+1,"にて共通部分無")
print(ans)

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

using namespace std;

class SparseTable {
private:
    vector<int> a_;
    vector<vector<int>> t_;
    int (*f_)(int, int);
public:
    SparseTable(vector<int> a, int (*f)(int, int)) : a_(a), f_(f) {
        int n = a_.size();
        int logn = ceil(log2(n));
        if ((1 << logn) <= n) ++logn;
        t_.assign(n, vector<int>(logn));
        for (int i = 0; i < n; ++i) {
            t_[i][0] = a_[i];
        }
        for (int j = 1; (1 << j) <= n; ++j) {
            for (int i = 0; i + (1 << j) <= n; ++i) {
                int k1 = t_[i][j - 1], k2 = t_[i + (1 << (j - 1))][j - 1];
                t_[i][j] = f_(k1, k2);
            }
        }
    }
    int query(int i, int j) {
        int len = j - i + 1;
        int k = log2(len);
        return f_(t_[i][k], t_[j - (1 << k) + 1][k]);
    }
};

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

    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    for (int i = 0; i < N; ++i) {
        cin >> P[i];
    }
    SparseTable stmx(P, [](int a, int b) {return max(a, b);});
    SparseTable stmn(P, [](int a, int b) {return min(a, b);});
    int res = 1;
    deque<int> mn;//, mx;
    for (int i = 0; i < K; ++i) {
        while (!mn.empty() && mn.back() > P[i]) {
            mn.pop_back();
        }
        mn.push_back(P[i]);
        //while (!mx.empty() && mx.back() < P[i]) {
        //    mx.pop_back();
        //}
        //mx.push_back(P[i]);
    }
    bool was_sorted = ((int)mn.size() == K);
    for (int i = 0; i + K < N; ++i) {
        assert(!mn.empty());
        if (mn.front() == P[i]) mn.pop_front();
        while (!mn.empty() && mn.back() > P[i + K]) {
            mn.pop_back();
        }
        mn.push_back(P[i + K]);
        int cmn = stmn.query(i, i + K);
        int cmx = stmx.query(i, i + K);
        if (P[i] == cmn && P[i + K] == cmx) {
            if ((int)mn.size() == K) {
                was_sorted = true;
            }
        } else {
            if ((int)mn.size() == K) {
                res += !was_sorted;
                was_sorted = true;
            } else {
                ++res;
            }
        }
        
        
    }
    cout << res << "\n";


    return 0;
}

Measured memory_bytes: 44016
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;
static const uint64_t MOD = 1000000007LL;
// uint64_t dp[100005][13];

/* nCk == (n-1)C(k-1) + (n-1)Ck*/
// long mem[4000][4000];
// long combi(int n, int k)
// {
//     if (mem[n][k])
//         return mem[n][k];
//     long ret = 0;
//     if ((k == 0) || (n <= k)) {
//         ret = 1;
//     } else {
//         ret = (combi(n - 1, k - 1) + combi(n - 1, k)) % MOD;
//     }
// 
//     mem[n][k] = ret;
//     return ret;
// }

int dp[2001][2001];
long combi(int n, int r)
{
       if(n==r) return dp[n][r] = 1;
       if(r==0) return dp[n][r] = 1;
       if(r==1) return dp[n][r] = n;
       if(dp[n][r]) return dp[n][r];
           dp[n][r] = (combi(n-1,r) % MOD + combi(n-1,r-1) % MOD) % MOD;
       return dp[n][r];
}

int main()
{
    int n, k; /* k: Bule */
    cin >> n >> k;

    for (int i = 1; i <= k; i++) {
        if (i > (n - k + 1) ) {
            puts("0");
        } else {
           long cnt = ((long) combi(k - 1, i - 1) * combi(n - k + 1, i)) % MOD;
           cout << cnt << endl;
        }
    }
}

Measured memory_bytes: 14336
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();
        int y = sc.nextInt();
        for (int i = n; i >= 0; i--) {
            if (10000*i > y) {
                continue;
            }
            for (int j = n-i; j >= 0; j--) {
                if (10000*i + 5000*j > y) {
                    continue;
                }
                int k = n-i-j;
                if (10000*i + 5000*j + 1000*k == y) {
                    // 出力
                    System.out.println(i + " " + j + " " + k);
                    return;
                }
            }
        }
        // 出力
        System.out.println("-1 -1 -1");
    }
}


Measured memory_bytes: 22612
import collections
n, t = map(int, input().split())
a = list(map(int, input().split()))
mi = 10 ** 9
als = collections.defaultdict(list)
for i, v in enumerate(a):
    mi = min(mi, v)
    pft = v - mi
    als[pft] += [mi]
als = sorted(als.items(), reverse=True)
als = collections.Counter(als[0][1]).most_common()
print(len(als))


Measured memory_bytes: 35228
#include<iostream>
#include<stdio.h>

using namespace std;

int main() {

	int a, b, d, r;
	double f;

	cin >> a >> b;

	d = a / b;
	r = a%b;
	f = (double)a / b;

	printf("%d %d %f\n", d, r, f);

}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
const int MC = 111;
int N;
P2 r[MC],b[MC];
bool c[MC*2];
 
int main(){
	cin >> N;
	repp(i,0,N){
		int x,y;
		cin >> x >> y;
		r[i] = MP(x,y);
	}
	repp(i,0,N){
		int x,y;
		cin >> x >> y;
		b[i] = MP(x,y);
	}
	sort(r,r+N); sort(b,b+N);
	int ans = 0;
	int pr = 0 , pb = 0;
	r[N] = b[N] = MP(1234567,1234567);
	while(pr < N || pb < N){
		if(r[pr].first < b[pb].first){
			c[r[pr].second] = 1;
			++pr;
		} else {
			repm(k,b[pb].second-1,-1){
				if(c[k]){
					c[k] = 0;
					++ans;
					break;
				}
			}
			++pb;
		}
	}
	cout << ans << endl;
	return 0;
}

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

S=sum(t)
m=int(input())
ans=[0]*m

for i in range(m):
    a,b=map(int,input().split())
    ans[i]=S+b-t[a-1]

for i in range(m):
    print(ans[i])

Measured memory_bytes: 3064
import sys
from collections import defaultdict

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()

nums = defaultdict(int)
ans = 0
for v in a:
    ans += nums[v]
    nums[v] += 1

for v in a:
    print(ans - (nums[v]-1))


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define vi vector
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000007
#define pb push_back
#define ll long long int
#define db double
#define all(v) v.begin(),v.end()
#define inf 10000000000


using namespace std;

/*

ll expo(ll n){
    ll t;
    if(n==0)return 1;
    else if(n==1) return 2;
    t=expo(n/2);
    if(n%2){
        return t*t*2;
    }
    else return t*t;
}

//ffrom geek for geek
ll exponentMod(ll A, ll B, ll C)  
{  
    if (A == 0)  
        return 0;  
    if (B == 0)  
        return 1;  
    ll y;  
    if (B % 2 == 0) {  
        y = exponentMod(A, B / 2, C);  
        y = (y * y) % C;  
    }  
    else {  
        y = A % C;  
        y = (y * exponentMod(A, B - 1, C) % C) % C;  
    }  
  
    return (ll)((y + C) % C);  
}

*/
/*
class dsu{
public:    
vi<ll> v;


void init(ll n){
    v.assign(n+1,-1);
}

 
ll dsufind(ll x){
    if(v[x]<0){
        return x;
    }
    v[x]=dsufind(v[x]);
    return v[x];
}
 
void dsujoin(ll x,ll y){
    x=dsufind(x);
    y=dsufind(y);
    
    if(x==y)
    return;
    if(v[x]>v[y])swap(x,y);
    v[y]+=v[x];
    v[x]=y;
}

};
*/



int main(){
    IOS;
    ll t;
    t=1;
   //cin>>t;
    while(t--){
        ll n;
        cin>>n;
        vi<ll> v(n+1,0);
        for(int i=1;i<n;i++){
            for(int j=i;j<n;j+=i){
                v[j]++;
            }
        }
        ll sm=0;
        for(int i=1;i<n;i++){
            sm+=v[i];
        }
        cout<<sm<<"\n";
    }
    return 0;
} 

Measured memory_bytes: 11120
// F - LCS
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
// void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }
// void vvprn(vector<vector<int>> &vv){
// 	for(auto v:vv) vprn(v);
// }

int main(){
	string S,T; cin>>S>>T;
	int Ns = S.size(), Nt = T.size();
	S = "*" + S; T = "*" + T;

	vvi dp(Nt+1, vi(Ns+1));
	for(int t=1; t<=Nt; t++)
		for(int s=1; s<=Ns; s++)
			if(T[t]==S[s]) dp[t][s] = dp[t-1][s-1] + 1;
			else dp[t][s] = max(dp[t][s-1], dp[t-1][s]);

	// vvprn(dp);//
	// cout<< dp[Nt][Ns] <<endl;

	string ans = "";
	int t = Nt, s = Ns;
	while(t>=1 && s>=1){
		if(dp[t][s]==dp[t][s-1]) s--;
		else if(dp[t][s]==dp[t-1][s]) t--;
		else{
			ans = S[s] + ans;
			t--; s--;
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 35584
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define N 100005
ll n,m,h[N];
vector<ll>G[N];
int main(){
	cin>>n>>m;
	for(ll i=1;i<=n;i++) cin>>h[i];
	for(ll i=1;i<=m;i++){
		ll x,y;
		cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
//	cout<<G[3][0];
	ll ans=0;
	for(ll i=1;i<=n;i++){
		bool flag=true;
		for(ll j=0;j<G[i].size();j++){
			if(h[i]<=h[G[i][j]]){
				flag=false;
				break;
			}
		}
		if(flag||G[i].size()==0) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
    ll n, m;
    cin >> n >> m;
    priority_queue <ll> pq;
    ll tmp = 0;
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        if (a >= n) {
            tmp++;
        } else {
            pq.push(a);
        }
    }
    if (tmp >= m-1) {
        cout << 0 << endl;
    } else {
        ll res = 0;
        rep(i, m-1-tmp) {
            ll j = pq.top(); pq.pop();
            res += n-j;
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3148
#!/usr/bin/env python3
import sys
import bisect as bi

def solve(N: int, L: "List[int]"):
    L.append(2001)
    L.sort()
    sum=0
    if len(L)<3:
        print(sum)
        return

    for i in range(N-2):
        for j in range(i+1,N-1):
            tansum=L[i]+L[j]
            if tansum<=L[j+1]:
                continue
            sum=sum+bi.bisect_left(L,tansum,j+1,N+1) - (j+1)
    print(sum)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
n,m = map(int,input().split())
digit = [0]*m
num = [0]*m
for i in range(m):
    digit[i], num[i] = map(int, input().split())
for i in range(1000):
    dum = str(i)
    flag = "ok"
    for j in range(m):
        #print(j)
        if len(dum) >= (digit[j]):
            if dum[digit[j]-1] != str(num[j]):
                flag = "ng"
                break
        else:
            flag = "ng"
            break
    if flag == "ok" and len(dum) == n:
        print(dum)
        break
else:
    print(-1)

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

struct Node
{
    vector<int> A;
    vector<Node*> C;
    int count;
    Node():A(26,0),C(26,nullptr),count(0){}
    void insert(string &s, int pos, vector<int> &B)
    {
        if(pos<0)
            return;
        int z = s[pos]-'a';
        if(C[z]==nullptr)
            C[z]=new Node();
        C[z]->insert(s,pos-1,B);
        B[z]=1;
        for(int i=0; i<26; ++i)
            A[i]+=B[i];
        ++count;
    }
    int query(string &s, int pos)
    {
        if(pos<0)
            return count;
        int z = s[pos]-'a';
        if(pos==0)
            return A[z];
        if(C[z]==nullptr)
            return 0;
        else
            return C[z]->query(s,pos-1);
        
    }
};
void solve()
{
    int N;
    cin>>N;
    vector<pair<int,string>> A(N);
    for(auto &a: A)
    {
        cin>>a.second;
        a.first = -a.second.size();
    }
    sort(A.begin(), A.end());
    int ans = 0;
    Node root{};
    for(auto &a: A)
    {
        ans+=root.query(a.second,a.second.size()-1);
        vector<int> B(26,0);
        root.insert(a.second,a.second.size()-1,B);
    }
    cout<<ans<<endl;
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        solve();
 
		
	return 0;
}

Measured memory_bytes: 450908
/**
 * Heaps - Complete Binary Tree
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

	private static int i;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		int h = parseInt(br.readLine());
		int[] heap = new int[h + 5];
		StringTokenizer st = new StringTokenizer(br.readLine());
		for (int i = 1; i < h + 1; i++) {
			heap[i] = parseInt(st.nextToken());
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i < h + 1; i++) {
			int parent, left, right;
			parent = parent(i);
			left = left(i);
			right = right(i);
			sb.append(String.format("node %d: key = %d, ", i, heap[i]));
			if (parent > 0) {
				sb.append(String.format("parent key = %d, ", heap[parent]));
			}
			if (left <= h) {
				sb.append(String.format("left key = %d, ", heap[left]));
			}
			if (right <= h) {
				sb.append(String.format("right key = %d, ", heap[right]));
			}
			sb.append("\n");
		}
		System.out.print(sb.toString());
	} //end main

	static int parent(int i) {
		return i / 2;
	}

	static int left(int i) {
		return i * 2;
	}

	static int right(int i) {
		return i * 2 + 1;
	}
}

Measured memory_bytes: 22956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
ll a[100009];

int main() {
	ll i,n,t,k,j,x=0,y=0,m;
  	cin>>n >>k >>m;
  	for(i=1;i<=m;i++){
    	cin >> x;
      	a[x]++;
    }
  for(i=1;i<=n;i++){
  	y=m-a[i];
    a[i]=-y;
    a[i]+=k;
  	
  }
  
  for(i=1;i<=n;i++){
  	if(a[i]>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

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

int main(){
    int x;
    cin >> x;
    int ans = 1;
    for(int i = 2; i<=sqrt(x);i++){
        for(int j=i;j<=x;j=j*i){
            ans = max(ans,j);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  priority_queue<double,vector<double>,greater<double> > pque;
  rep(i,N){
    double x;cin >> x;
    pque.push(x);
  }
  while(pque.size()!=1){
    double x = pque.top();pque.pop();
    double y = pque.top();pque.pop();
    pque.push((x+y)/2.0);
  }
  cout << pque.top() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

long long b[3001];
long long c[3001][3001];
long long dp[3001][3001][2];

int main() {
    int n, m, mod = 1000000007, i, j, k;
    long long ans = 0;
    
    scanf("%d %d", &n, &m);
    
    b[0] = 1;
    for (i = 1; i <= 3000; i++) b[i] = b[i - 1] * 2 % mod;
    
    for (i = 0; i <= 3000; i++) {
        c[i][0] = c[i][i] = 1;
        for (j = 1; j < i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
    }
    
    n--;
    m--;
    
    dp[0][0][1] = 1;
    for (i = 1; i <= n; i++) dp[0][i][0] = 1;
    
    for (i = 0; i < m; i++) {
        for (j = 0; j <= n; j++) {
            for (k = 0; k < 2; k++) {
                if (dp[i][j][k] == 0) continue;
                
                if (j + 1 <= n) {
                    dp[i + 1][j + 1][k] += dp[i][j][k];
                    if (dp[i + 1][j + 1][k] >= mod) dp[i + 1][j + 1][k] -= mod;
                }
                
                if (j - 1 >= 0) {
                    int nk = k;
                    
                    if (j - 1 == 0) nk = 1;
                    
                    dp[i + 1][j - 1][nk] += dp[i][j][k];
                    if (dp[i + 1][j - 1][nk] >= mod) dp[i + 1][j - 1][nk] -= mod;
                }
            }
        }
    }
    
    for (i = 0; i <= m; i++) {
        for (j = 0; j <= n; j++) {
            if (dp[i][j][1] == 0) continue;
            
            ans += c[m][i] * dp[i][j][1] % mod * b[m - i] % mod * 4 % mod;
        }
    }
    
    printf("%lld\n", ans % mod);
    
    return 0;
}


Measured memory_bytes: 211200
#include <bits/stdc++.h>
#define sqr(x) ((x)*(x))
 
using namespace std;
const double eps = 1e-9;
const int INF = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int MAXN =(int)1e6;
 
int main() {
    int n, k;
    cin >> n >> k;
    vector <ll> a(n), b(n);
    vector <int> good(n);
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        if (a[i] <= k) {
            sum += b[i];
            good[i] = 1;
        }
    }
 
    ll ans = 0;
    for (ll i = 30; (1 << i) >= 0; --i) {
int cur = (k >> i) & 1;
        if (cur == 0) {
            for (int j = 0; j < n; ++j) {
                if (good[j] && ((a[j] >> i) & 1)) {
                    good[j] = 0;
                    sum -= b[j];
                }
            }
        } else {
            ll cur_bad = 0;
            for (int j = 0; j < n; ++j) {
                if (good[j] && ((a[j] >> i) & 1)) {
                    cur_bad += b[j];
                }
            }
            ans = max(ans, sum - cur_bad);
        }
    }
    ans = max(ans, sum);
    cout << ans;
 
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
string x;
const int N = 1e6 + 5;
int v[N],n,dp[N][2];
int f(int i,int ac){
  if(i==n)return 0;
  if(dp[i][ac]!=-1)return dp[i][ac];
  int op1,op2;
  if(ac){
    op1 =     v[i]     + f(i+1 , ac);
    op2 = 1 + x[i]-'0' + f(i+1 , 0);
  }else{
    op1 = x[i]-'0' + f(i+1 , ac);
    op2 = 1 + v[i] + f(i+1 , 1);
  }
  return dp[i][ac] = min(op1,op2);
}
int main(){
  cin >> x;
  n = x.size();
  int ac = 0;
  for(int i=n-1 ; i>=0 ; i--){
    int d = -x[i]+'0'-ac;
    if(d < 0)ac = 1;
    else ac = 0;
    v[i] = (d+10)%10; 
  }
  memset(dp,-1,sizeof dp);
  cout << f(0,0) << endl;  
  return 0;
}

Measured memory_bytes: 59908
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))


using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(int a, int n) {//aのn乗を計算します。
	int x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;
vector<int> v;
map<int, int>mp;
int main() {
	int N;
	cin >> N;
	REP(i, N) {
		int A;
		cin >> A;
		v.push_back(A);
		mp[A]++;
	}
	VSORT(v);
	ll ans = 0;
	for (int i = 32; i > 0; i--) {
		REP(j, N) {
			if (mp[v[j]] > 0) {
				ll x = pow2(2, i) - v[j];
				if (binary_search(v.begin(), v.end(), x)) {
					if (v[j] == x) {
						if (mp[x] >= 2) {
							ans++;
							mp[x] -= 2;
						}
					}
					else {
						if (mp[x] >= 1) {
							ans++;
							mp[x]--;
							mp[v[j]]--;
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 10356
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    double x,y,z;
    long long n,d,i,s=0;
    cin>>n>>d;
    while(n--)
    {
        cin>>x>>y;
        z=sqrt((x*x)+(y*y));
        if(z<=(double)d)
        {
            s++;
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3740
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	var sum, sc, st int
	Xn := make([]int, N)
	for i := 0; i < N; i++ {
		Xn[i] = nextInt()
		sum += Xn[i]
	}
	ave := float64(sum) / float64(N)
	for i := 0; i < N; i++ {
		sc += int(math.Pow((float64(Xn[i]) - math.Ceil(ave)), 2.0))
		st += int(math.Pow((float64(Xn[i]) - math.Trunc(ave)), 2.0))
	}
	ans := MinOf(sc, st)
	fmt.Println(ans)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}


Measured memory_bytes: 32128
// abc148_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  vi v={1,2,3};
  int a,b;
  cin>>a>>b;
  for(auto it=v.begin();it!=v.end();) {
    if (*it == a || *it == b) {
      it=v.erase(it);
    }
    else {
      ++it;
    }
  }

  cout<<v.at(0)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long; 
using ld = long double;
#define endl "\n"
//#define int long long
#define all(V) V.begin(),V.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll fact_mod(ll n, ll mod) {
    ll f = 1; for (int i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
ll keta(ll n) {
    if (n == 0) return 1;
    ll count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll mch(ll n) {
    if (n == 1) return 1;
    else return n * mch(n - 1);
}
ll pow_mod(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % mod;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}
ll inv_mod(ll a, ll mod) { //逆元
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

//宣言とか
ll sum;
/*signed*/int main(void) {
    ll n, k;
    cin >> n >> k;
    vector<pair<ll, ll>> p(n);
    rep(i, n) cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());
    rep(i, n) {
        sum += p[i].second;
        if (sum >= k) {
            cout << p[i].first << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 4816
#include <atcoder/all>

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using namespace atcoder;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n, m; cin >> n >> m;
  vector<lint> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<lint> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }

  auto c = convolution(a, b);
  for (int i = 0; i < c.size(); i++) {
    cout << c[i];
    if (i + 1 == c.size()) cout << endl;
    else cout << " ";
  }
  return 0;
}


Measured memory_bytes: 27208
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

int isrunrun(ll a);
/*
int main(){
    int k;
    ll num = 0;
    int state = 0;
    cin >> k;
    if(k > 10000){
        num = 22111101;
        state = 10000;
    }
    while(state < k){
        num++;
        state += isrunrun(num);
        //num++;
    }
    //isrunrun(k);
    cout << num << endl;
    return 0;
}

int isrunrun(ll a){
    int runrun[100];
    //int del = 1;
    int b;
    int i = 0;
    
    for(i; a > 0; i++){
            runrun[i] = a%10;


        a /= 10;
        //del *= 10;
        //cout << "a " << a << " del " << del << endl;
        //cin >> b;
    }
    
    for(int j = 0; j < 6; j++){
        cout << runrun[j] << " ";
    }
    
    for(b = 1; b < i; b++){
        if(abs(runrun[b-1]-runrun[b]) > 1) break;
    }
    //cout << "b= " << b << endl;
    //cout << "i = " << i << endl;
    if(b == i)return 1;
    else return 0;
}
*/

int main(){
    queue<ll> que;
    int k;
    ll x;
    cin >> k;
    for(int i = 1; i < 10; i++){
        que.push(i);
    }

    for(int i = 0; i < k; i++){
        x = que.front();
        //cout << x << endl;
        que.pop();
        if(x%10 != 0) que.push(10*x+(x%10-1));
        que.push(10*x + x % 10);
        if(x%10 != 9) que.push(10*x + (x%10 + 1));
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;
#define sz              300005
#define Fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


int main(){
    Fast;
    int a,b,c, i,j, n,m,t, cs=1;

    cin>>n;
    n=n%10;
    if(n==2 || n==4|| n==5 || n==7 || n==9){
        cout<<"hon"<<endl;
    }
    else if(n==0 || n==1 || n==6 || n==8){
        cout<<"pon"<<endl;
    }
    else{
        cout<<"bon"<<endl;
    }






    return 0;
}

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

int dp[100002];
int dfs(vector<int> adj[], int i)
{
   if(dp[i]!=-1)
   	return dp[i];
   int l=0;
   for (int j = 0; j <adj[i].size() ; ++j)
   {
   	 l = max(l,dfs(adj,adj[i][j])); 
   }
   return dp[i] = 1+l;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp,-1,sizeof(dp));
  int n,m;
  cin>>n>>m;
  int x, y;
  vector<int> adj[n+1];
  for (int i = 0; i < m; ++i)
  {
  	cin>>x>>y;
    adj[x].push_back(y);
  }
  int ans=0;
  for (int i = 1; i <=n; ++i)
  {
  	ans = max(ans,dfs(adj, i));
  }
  
     cout<<(ans-1);

  return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, h[100000];

int main() {
	cin >> n;
	inc(i, n) { cin >> h[i]; }
	
	int ans = 0, p = 0, c = 0;
	inc(i, n) {
		if(h[i] <= p) { c++; } else { c = 0; }
		
		setmax(ans, c);
		p = h[i];
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
n = int(input())
hl = list(map(int, input().split()))

al = [0 for _ in range(n)]
for i in range(n-1,0,-1):
    if hl[i-1]>=hl[i]:
        al[i-1] = al[i]+1

print(max(al))


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265
ll mark[500000]={0};
int main()
{       
    IOS;
   	ll n;
   	string s,t;
   	cin>>n>>s>>t;
   	if(s==t)
   	{
   		cout<<n;
   		return 0;
   	}
   	for(ll i=n-1;i>=0;i--)
   	{
   		ll check=0;
   		ll ind=0;
   		for(ll j=n-i;j<n;j++)
   		{
   			if(s[j]!=t[ind++])
   			{
   				check=1;
   				break;
   			}
   		}
   		if(check==0)
   		{
   			cout<<2*n-i;
   			return 0;
   		}
   	}
}    	

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

ll inv_mod(ll a, ll MOD)
{
    ll b = MOD, u = 1, v = 0;
    while(b){
        ll t = a/b;
        a -= t*b;   swap(a,b);
        u -= t*v;   swap(u,v);
    }
    u %= MOD;
    if(u < 0) u+= MOD;
    return u;
}

int main()
{
    ll i,j;
    ll k;
    string s;
    cin >> k >> s;
    ll n = s.size();
    const ll MOD = 1e9 + 7;
    
    vector<ll> v26(k+1,1);
    vector<ll> v25(k+1,1);
    for(i = 0;i < k;++i){
        v26.at(i+1) = v26.at(i)*26%MOD;
        v25.at(i+1) = v25.at(i)*25%MOD;
    }

    ll tmp = 1;
    ll ans = tmp*v26.at(k-0)%MOD*v25.at(0)%MOD;

    for(i = 1;i <= k;++i){
        tmp = tmp*(n + i - 1)%MOD*inv_mod(i, MOD)%MOD;
        ans += tmp*v26.at(k-i)%MOD*v25.at(i)%MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 20072
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		long sum = 0;
		Scanner s = new Scanner(System.in);
		int n = Integer.parseInt(s.nextLine());
		int[] nums = new int[n];
		boolean flag = true;
		if(n>0 && n<=10000) {
			for(int i=0;i<n;i++) {
				nums[i] = s.nextInt();
			}
			for(int i=0;i<n;i++) {
				if(nums[i]>=-1000000 && nums[i]<=1000000) {
					sum += nums[i];
					flag = true;
				}else {
					flag = false;
					break;
				}
			
			}
		}
		if(flag==true) {
			Arrays.sort(nums);
			System.out.println(nums[0]+" "+nums[nums.length-1]+" "+sum);
		}
		
			
			
	}

}

Measured memory_bytes: 41836
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int K = sc.nextInt();
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = 0;
      for(int i=A;i<B+1;i++){
        if(i%K==0){
          C=C+1;
          break;
        }else{
          continue;
        }
      }if(C>0){
        System.out.println("OK");
      }else{
        System.out.println("NG");
      }
    }
}

Measured memory_bytes: 35840
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2);
}

void solve()
{
	int k;
	
	cin >> k;
	
	queue<string> q;
	
	for(char i = '1' ; i <= '9'; ++i) {
		string p;
		p += i;
		q.push(p);
	}
	
	while(k > 0) {
		string p = q.front();
		string s = p;
		string ss = p;
		string sss = p;
		
		q.pop();
		
		k--;
		
		if(k == 0) {
			cout << p;
			return;
		}
		
		if(p.back() > '0') {
			s += (p.back()-1);
			q.push(s);
		}
		
		ss += p.back();
		q.push(ss);
		
		if(p.back() < '9') {
			sss += (p.back() + 1);
			q.push(sss);
		}
	}
}

signed main() {
    fast;
    
    int t = 1;
    
    //cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 9332
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    vector<int> V(3);
    char tmp1, tmp2;
    string S;
    bool flag=true;
    
    cin >> A >> B;
    
    ans = A*A -B;
    cout << ans << endl;

    // if(S[0]=='9' || S[1]=='9')
    // 	cout << "Yes"<<endl;
    // else
    // 	cout << "No"<<endl;

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main(){
    ll a,b,c,x,ans;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &x);
    if(x % 2 == 0){
        ans = a-b;
    } else ans = b-a;
    printf("%lld\n", ans);
}


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

//#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int n;
string s;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	s = to_string(n);

	for (char c : s)
		if (c == '7') {
			cout << "Yes" << endl;
			return 0;
		}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3764
def gcd(p):
	ret = p[0]
	def f(s,t):
		return f(t,s%t) if t else s
	for d in p:
		ret = f(ret,d)
	return ret
n,x=map(int,input().split())
print(gcd(list(map(lambda t:abs(int(t)-x),input().split()))))

Measured memory_bytes: 14224
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep2(i,a,b)for(int i=a;i<b;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define ll long long

int n,k;
int x[111111],y[111111];

int rui[4001][4001];

int q(int x1,int y1,int x2,int y2){//半開区間での中のruiを返す
	
	if(x1>x2||y1>y2)return 0;
	int ret=0;
	ret=rui[y2][x2]-rui[y2][x1-1]-rui[y1-1][x2]+rui[y1-1][x1-1];

	return ret;
}

int main(){
	cin>>n>>k;
	rep(i,n){
	char c;
	cin>>x[i]>>y[i]>>c;
		if(c=='B')y[i]+=k;
		x[i]%=2*k;
		y[i]%=2*k;
		x[i]++;y[i]++;
	}



	rep(i,n){
		int ny=y[i],nx=x[i];
		rui[ny][nx]++;
	}


rep2(i,1,2*k+1){
		rep2(j,2,2*k+1)rui[i][j]+=rui[i][j-1];
	}
	
	rep2(i,1,2*k+1){
		rep2(j,2,2*k+1)rui[j][i]+=rui[j-1][i];
	}
	


	int ans=0;
	rep2(i,1,k+1){
		rep2(j,1,k+1){
			int tmp=q(i,j,i+k-1,j+k-1)+q(1,1,i-1,j-1)+q(i+k,1,2*k,j-1)+q(1,j+k,i-1,2*k)+q(i+k,j+k,2*k,2*k);
			ans=max(ans,max(n-tmp,tmp));//i,jが作る長方形が白か黒か
		}
	}
	
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 33280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
#include <functional>
#include <map>
#include <set>
using namespace std;
const int INF = 1000000009;

unsigned long n, k;
unsigned long a[100000];
unsigned long b[100000];

/*void binlook(int i){
	stack<int> st;
	while(i){
		st.push(i%2);
		i /= 2;
	}
	while(!st.empty()){
		printf("%d", st.top());
		st.pop();
	}
	return;
}*/

int main(){
	scanf("%ld%ld", &n, &k);
	for(int i = 0; i < n; i++){
		scanf("%ld%ld", &a[i], &b[i]);
	}
	unsigned long ans = 0;
	for(unsigned long i = 1; i <= k; i <<= 1){
		if(!(i & k)){
			continue;
		}
		unsigned long vis = ((k & (~i)) | (i-1));
		unsigned long res = 0;
		for(unsigned long x = 0; x < n; x++){
			if(vis == (vis | a[x])){
				//printf("%d ", a[x]);
				res += b[x];
			}
			//printf("\n");
		}
		//printf("i = %d, vis = %d -> res %d\n", i, vis, res);
		if(res > ans){
			ans = res;
		}
	}
	unsigned long res = 0;
	for(unsigned long i = 0 ; i < n; i++){
		if((a[i] | k) == k){
			res += b[i];
		}
	}
	ans = max(res, ans);
	printf("%ld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e3 + 10;
LL dp[N][N];
void init()
{
	for (int i = 0; i < N; i++) dp[i][0] = dp[i][i] = 1;
	for (int i = 1; i < N; i++)
	{
		for (int j = 1; j < i; j++)
		{
			dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
			if (dp[i][j] >= INF) dp[i][j] -= INF;
		}
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	init();
	for (int i = 1; i <= k; i++)
	{
		printf("%lld\n", dp[n - k + 1][i] * dp[k - 1][i - 1] % INF);
	}
	return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int counter=0;
    for(int i=1;i<s.size();i++)
    {
        if(s[i]==s[i-1])
        {
            if(s[i]=='1')s[i]='0';
            else s[i]='1';
            counter++;
        }
    }
    cout<<counter<<endl;
}


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

int main(){
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  map<int,int> mp;
  
  rep(i,A,B) mp[i]++;
  rep(i,C,D) mp[i]++;
  
  int ans = 0;
  int N = max({A,B,C,D});
  rep(i,0,N) if(mp[i]==2) ans++;
  cout <<ans<< endl;
}

Measured memory_bytes: 256