akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
int x,y,z;
int main(){
	cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);
	printf("%d %d %d\n",x,y,z);
	return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    String s = sc.next();
    String t = sc.next();

    String ans = "";

    List<String> candidate = new ArrayList<>();
    for (int i = 0; i + t.length() <= s.length(); i++) {
      if (ok(s.substring(i, i + t.length()), t)) {
        candidate.add(generateCandidate(s, t, i));
      }
    }

    candidate.sort(String::compareTo);

    if (candidate.isEmpty()) {
      os.println("UNRESTORABLE");
    } else {
      os.println(candidate.get(0));
    }
  }

  private static boolean ok(String s, String t) {
    for (int i = 0; i < t.length(); i++) {
      if (s.charAt(i) != t.charAt(i) && s.charAt(i) != '?') return false;
    }
    return true;
  }

  private static String generateCandidate(String s, String t, int start) {
    String ans = "";
    for (int i = 0; i < start; i++) {
      if (s.charAt(i) == '?') ans += "a";
      else ans += String.valueOf(s.charAt(i));
    }
    ans += t;
    for (int i = start + t.length(); i < s.length(); i++) {
      if (s.charAt(i) == '?') ans += "a";
      else ans += String.valueOf(s.charAt(i));
    }
    return ans;
  }
}


Measured memory_bytes: 27220
#include<stdio.h>

int max(int a, int b){
	return a>b? a:b;
}

int main(){
	while(1){
		int n, i, j;
		scanf("%d", &n);
		if(n==0) break;

	
		int grid[3*n][3*n];
		for(i=0; i<3*n; i++) for(j=0; j<3*n; j++) grid[i][j]=0;
		for(i=0; i<n; i++){
			char s[300];
			scanf("%s", s);
			for(j=0; j<n; j++){
				grid[n+i][n+j] = s[j]-'0';
			}
		}
		

		int ans = 0;
		for(i=n; i<n*2; i++){
			int tmp=0;
			for(j=n; j<n*2; j++){
				if(grid[i][j]==1) tmp++;
				else tmp=0;
				ans = max(ans, tmp);
			}
		}
		for(i=n; i<n*2; i++){
			int tmp=0;
			for(j=n; j<n*2; j++){
				if(grid[j][i]==1) tmp++;
				else tmp=0;
				ans = max(ans, tmp);
			}
		}
		int ltor=0, rtol=0;
		for(i=0; i<n*2; i++){
			for(j=0; j<n*2; j++){
				if(grid[n+j][i+j]==1) ltor++;
				else ltor=0;
				if(grid[n+j][3*n-i-j]==1) rtol++;
				else rtol=0;
				ans = max(ans, max(ltor, rtol));
			}
		}

		printf("%d\n", ans);

	}
	return 0;
}


Measured memory_bytes: 3988
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAXOP 100
#define NUMBER '0'

int getop(char []);
void push(double);
double pop(void);

int main(){
	int type;
	double op2;
	char S[MAXOP];

	while((type = getop(S)) != EOF) {
		switch (type) {
		case NUMBER:
			push(atof(S));
			break;
		case '+':
			push(pop() + pop());
			break;
		case '*':
			push(pop() * pop());
			break;
		case '-':
			op2 = pop();
			push(pop() - op2);
			break;
		case '/':
			op2 = pop();
			if (op2 != 0.0)
				push(pop() / op2);
			else
			break;
		case '\n':
			printf("%g\n", pop());
			break;
		default:
			break;
		}
	}
	return 0;
}

#define MAXVAL 100

int sp = 0;
double val[MAXVAL];


void push(double f){
	if (sp < MAXVAL)
		val[sp++] = f;
}

double pop(void){
	if (sp > 0)
		return val[--sp];
	else {
		return 0.0;
	}
}

#include <ctype.h>

int getch(void);
void ungetch(int);
int getop(char s[]){
	int i, c;

	while ((s[0]= c = getch()) == ' ' || c == '\t')
		;
	s[1] = '\0';
	if (!isdigit(c) && c != '.')
		return c;
	i = 0;
	if (isdigit(c)) 
		while (isdigit(s[++i] = c = getch()))
			;
	if (c == '.') 
		while (isdigit(s[++i] = c = getch()))
			;
	s[i] = '\0';
	if (c != EOF)
		ungetch(c);
	return NUMBER;
}

#define BUFsIZE 100

char buf[BUFsIZE];
int bufp =0;

int getch(void) {
	return (bufp > 0) ? buf[--bufp] : getchar();
}

void ungetch(int c) {
	if (bufp >= BUFsIZE)
		printf("ungetch\n");
	else
		buf[bufp++] = c;
}

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

using namespace std;

#define int long long

int st[105];
int C[105][105];

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int k;
    st[0]= 1;
    for (int i = 1; i <= 4; ++i) st[i] = st[i - 1] * 9;
    for (int i = 0; i <= 100; ++i) C[i][0] = 1;
    for (int i = 1; i <= 100; ++i) {
        for (int j = 1; j <= 3; ++j) {
            if (j > i) continue;
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
        }
    }
    cin >> k;
    int ans = 0;
    int cnt = 0;
    for (int i = 0; i < (int)s.size(); ++i) {
        for (int j = 0; j < s[i] - '0'; ++j) {
            if (j != 0) cnt++;
            if (i == (int)s.size() - 1) {
                if (cnt == k) ans++;
            }
            else {
                if (cnt <= k) {
                    ans += C[(int)s.size() - i - 1][k - cnt] * st[k - cnt];
                }
            }
            if (j != 0) cnt--;
        }
        if (s[i] != '0') cnt++;
    }
    if (cnt == k) ans++;
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
  char a[5];
  int  b=0;
  cin>>a;
  if(a[0]=='1')
    b++;
  if(a[1]=='1')
    b++;
  if(a[2]=='1')
    b++;
  cout<<b<<endl;
    
   return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll h[100005];
bool ok(ll k,ll &n,ll &a,ll &b)
{
	ll temp=b*k;
	for(int i=0;i<n;i++)
	{
		if(h[i]>temp)k-=ceil((double)(h[i]-temp)/((a-b)*1.0));
		if(k<0)return false;
	}
	return true;
}

int main()
{
   std::ios_base::sync_with_stdio(false);
   ll n,a,b;
   cin>>n>>a>>b;
   for(int i=0;i<n;i++)cin>>h[i] ;
   sort(h,h+n,greater<int>());
   int lo=1,hi=1e9+1;
   while(lo<hi)
   {
   	int mid=lo+(hi-lo)/2 ;
   	bool temp=ok(mid,n,a,b);
   	//cout<<mid<<" "<<temp<<" ";
   	if(temp)hi=mid;
   	else lo=mid+1 ;
   }
   cout<<lo ;
}

Measured memory_bytes: 1024
#include<iostream>

int main(void){
    std::string s, t;
    std::cin >> s >> t;
    int ss = s.size();

    if(ss + 1 != t.size()){
	std::cout << "No" << std::endl;
	return 0;
    }

    for(int i = 0; i < ss; i++){
	if(s[i] != t[i]){
	    std::cout << "No" << std::endl;
	    return 0;
	}
    }


    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 3584
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> Q;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int t[301];
vector<Q> re;
int main()
{
	while(1)
	{
		re.clear();
	for(int i=0;i<301;i++)
	{
		t[i]=2;
	}
	int a,b,c;
	cin >> a >> b >> c;
	if(a==0&&b==0&&c==0)break;
	int N;
	cin >> N;
	for(int i=0;i<N;i++)
	{
		Q p;
		cin >> p.fi.fi >> p.fi.sec >> p.sec.fi >> p.sec.sec;
		if(p.sec.sec==1)
		{
			t[p.fi.fi]=1;
			t[p.fi.sec]=1;
			t[p.sec.fi]=1;
		}
		else
		{
			re.pb(p);
		}
	}
	for(int i=0;i<sz(re);i++)
	{
		if(t[re[i].fi.fi]==1&&t[re[i].fi.sec]==1&&t[re[i].sec.fi]!=1)
		{
			t[re[i].sec.fi]=0;
		}
		else if(t[re[i].fi.fi]!=1&&t[re[i].fi.sec]==1&&t[re[i].sec.fi]==1)
		{
			t[re[i].fi.fi]=0;
		}
		else if(t[re[i].fi.fi]==1&&t[re[i].fi.sec]!=1&&t[re[i].sec.fi]==1)
		{
			t[re[i].fi.sec]=0;
		}
		else
		{}
	}
	for(int i=1;i<=(a+b+c);i++)
	{
		cout << t[i] << endl;
	}
	}
	return 0;
}

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

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

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

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

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

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

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

int ans[MX];
int pref[MX];
vector<vi> graph(MX);

void dfs(int v, int p, int val) {
    val += pref[v];
    ans[v] = val;
    F0R(i, sz(graph[v])) {
        int nxt = graph[v][i];
        if (nxt == p) continue;
        dfs(nxt, v, val);
    }
}

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

    int N; cin >> N;
    int Q; cin >> Q;
    F0R(i, N-1) {
        int A, B; cin >> A >> B;
        graph[A-1].pb(B-1); graph[B-1].pb(A-1);
    }
    F0R(i, N) ans[i] = 0, pref[i] = 0;

    F0R(i, Q) {
        int A, B;
        cin >> A >> B;
        pref[A-1] += B;
    }

    dfs(0, -1, 0);

    F0R(i, N) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343
// license: https://github.com/bqi343/USACO/blob/master/LICENSE

Measured memory_bytes: 20480
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )



X, Y = map(int, input().split())

if not (X+Y) % 3 == 0:
    print(0)
else:
    # 2n + m = X
    # n + 2m = Y
    n = (Y - 2*X) // -3
    m = X - (2 * n)
    if n < 0 or m < 0:
        print(0)
    else:
        print(cmb(n+m, n, mod))


Measured memory_bytes: 127560
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2003;

int f[N][N];
int pre[N][N],suf[N][N];
int ans;
int n,k;
struct edge{
	int x,nxt;
}e[N*2];
int h[N],tot;
int fa[N];
bool bz[N];
int son[N],m;

void inse(int x,int y){
	e[++tot].x=y;
	e[tot].nxt=h[x];
	h[x]=tot;
}

void dfs(int x){
	bz[x]=1;
	for(int p=h[x];p;p=e[p].nxt)
	if (!bz[e[p].x]){
		fa[e[p].x]=x;
		dfs(e[p].x);
	}
	m=0;
	for(int p=h[x];p;p=e[p].nxt)
	if (fa[e[p].x]==x)son[++m]=e[p].x;
	fo(i,0,k)pre[0][i]=suf[m+1][i]=0;
	fo(i,1,m)fo(j,0,k)pre[i][j]=pre[i-1][j]+f[son[i]][j];
	fd(i,m,1)fo(j,0,k)suf[i][j]=suf[i+1][j]+f[son[i]][j];
	f[x][0]=1;
	fo(i,1,m)
		fo(j,0,k)
		f[x][j+1]=max(f[x][j+1],pre[i-1][min(k-2-j,j)]+suf[i+1][min(k-2-j,j)]+f[son[i]][j]+1);
	fo(j,1,k)f[x][j]=max(f[x][j],f[x][j-1]);
	ans=max(ans,f[x][k]);
}

int main(){
	n=get();k=get();
	fo(i,2,n){
		int x=get(),y=get();
		inse(x,y);
		inse(y,x);
	}
	if (k==1){
		if (n==1)printf("0\n");
		else printf("%d\n",n-2);
		return 0;
	}
	dfs(1);
	ans=n-ans;
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  int N,M,wans=0,aans=0;
  cin >> N >>M;
  vector<int> ac(N,0), wa(N,0);
  for(int i=0;i<M;i++){
    int p;
    string s;
    cin >> p >> s;
    if(s == "AC"){
      ac.at(p-1) = 1;
    }
    if(s == "WA" && ac.at(p-1) == 0){
      wa.at(p-1) +=1;
    }
  }
  for(int i=0;i<N;i++){
    if(ac.at(i)==1){
      aans++;
    }
  }
  for(int i=0;i<N;i++){
    if(ac.at(i)==1){
      wans += wa.at(i);
    }
  }
  cout << aans << " " << wans <<endl;
}

Measured memory_bytes: 1024
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        cnt = 0
        for k in range(d):
            cnt += (x[i][k] - x[j][k])**2
        if cnt**(1/2) % 1 == 0:
            ans += 1
        else:
            ans += 0
print(ans)

Measured memory_bytes: 3064
import collections
n = int(input())
arr = list(map(int, input().split()))
cnt = collections.Counter(arr)
total = 0
for i in cnt.keys():
  patern = cnt[i]*(cnt[i]-1)//2
  total += patern
for j in range(n):
  tmp = total
  total -= cnt[arr[j]]*(cnt[arr[j]]-1)//2
  total += (cnt[arr[j]]-1)*(cnt[arr[j]]-2)//2
  print(total)
  total = tmp
           

Measured memory_bytes: 26780
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(xx) cout << (xx) << endl
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

/* 
*/

//=================================================
int N,T;
struct keiro{
    int cost,time,index;
};
vector<keiro> cti;
//=================================================
void input()
{
    cin>>N>>T;
    cti.resize(N);
    rep(i,N){
        cin>>cti[i].cost>>cti[i].time;
        cti[i].index = i+1;
    }
}

//=================================================
void solve()
{
    int ans = INF;
    for (auto x: cti){
        if (x.time <= T && x.cost < ans){
            ans = x.cost;
        }
    }
    cout<< ((ans != INF) ? to_string(ans) : "TLE") << endl;

}

//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;

int n, k;
int moves[105];
bool przewyg[100005];

int main(){
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) scanf("%d", &moves[i]);
    przewyg[0] = false;
    for(int i = 1; i <= k; i++){
        przewyg[i] = false;
        for(int j = 1; j <= n; j++){
            if(moves[j] > i) break;
            if(przewyg[i - moves[j]] == false){
                przewyg[i] = true;
                break;
            }
        }
    }
    if(przewyg[k] == true) printf("First");
    else printf("Second");
    return 0;
}


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

int main()
{
    int x, y,sum = 0;
    cin >> x >> y;

    for (int i = 0; i <= x; i++)
    {
        for (int j = 0; j <= x; j++)
        {
            sum = 2 * i + 4 * j;
            if (sum == y && i + j == x)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3640
N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (max(A) + 2)


for a in A:
    if a == 0:
        cnt[a] += 1
        cnt[a + 1] += 1
    else:
        cnt[a - 1] += 1
        cnt[a] += 1
        cnt[a+1] += 1

cnt.sort()
print(cnt[-1])


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int H, W;
std::string S[2100];
int cnt[4][2100][2100];

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

    std::cin >> H >> W;

    for(int i=0;i<H;++i){
        std::cin >> S[i];
    }

    for(int i=1;i<=H;++i){
        for(int j=1;j<=W;++j){
            if(S[i-1][j-1] == '#'){
                cnt[0][i][j] = 0;
            }else{
                cnt[0][i][j] = cnt[0][i][j-1] + 1;
            }
        }

        for(int j=W;j>=1;--j){
            if(S[i-1][j-1] == '#'){
                cnt[1][i][j] = 0;
            }else{
                cnt[1][i][j] = cnt[1][i][j+1] + 1;
            }
        }
    }

    for(int j=1;j<=W;++j){
        for(int i=1;i<=H;++i){
            if(S[i-1][j-1] == '#'){
                cnt[2][i][j] = 0;
            }else{
                cnt[2][i][j] = cnt[2][i-1][j] + 1;
            }            
        }

        for(int i=H;i>=1;--i){
            if(S[i-1][j-1] == '#'){
                cnt[3][i][j] = 0;
            }else{
                cnt[3][i][j] = cnt[3][i+1][j] + 1;
            }                        
        }
    }

    int res = 0;

    for(int i=1;i<=H;++i){
        for(int j=1;j<=W;++j){
            if(S[i-1][j-1] != '#'){
                res = std::max(res, cnt[0][i][j] + cnt[1][i][j] + cnt[2][i][j] + cnt[3][i][j] - 3);
            }
        }
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 72576
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long cnt,i,j,m,d;
	cin>>m>>d;
	cnt=0;
	for (i=1;i<=m;i++)
	{
	for (j=1;j<=d;j++)
	{
	if (j%10>=2 && j/10>=2 && (j/10)*(j%10)==i)
	{
		cnt++;
	}
	}
}
cout<<cnt<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  card = []
  bingo = numpy.zeros((3, 3))
  for i in range(3):
    card.append(list(map(int, input().split())))
  card = numpy.array(card)
  n = int(input())
  for _ in range(n):
    b = int(input())
    for i in range(3):
      for j in range(3):
        if card[i, j] == b:
          bingo[i, j]=1

  l, r = 0, 0
  for i in range(3):
    if sum(bingo[i, :]) == 3 or sum(bingo[:, i]) == 3:
      print('Yes')
      return 
    l += bingo[i, i]
    r += bingo[i, 2-i]
  if l == 3 or r == 3:
    print('Yes')
    return 
  print('No')
  


if __name__=='__main__':
  main()



Measured memory_bytes: 20876
//Malfurion_Drake
#include<bits/stdc++.h>
#define Maxn 100005
using namespace std;

int n,m,d;

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

void init(){
	cin>>n>>m>>d;
}

int main(){
	init();
	long double ans;
	if(d==0)
	ans=1.0*(m-1)/n;
	else ans=2.0*(n-d)*(m-1)/n/n;
	cout<<fixed<<setprecision(8)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;

namespace AtCoder
{
    class Node
    {
        public int Distance { get; set; }
        public List<Tuple<Node, int>> Children { get; private set; }
        public Node()
        {
            Distance = int.MaxValue;
            Children = new List<Tuple<Node, int>>();
        }
        public void Add(Node node, int cost)
        {
            Children.Add(new Tuple<Node, int>(node, cost));
        }
    }

    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static int Solve(int K)
        {
            var nodes = new Node[K];
            for (int i = 0; i < K; ++i) { nodes[i] = new Node(); }
            for (int i = 0; i < K; ++i)
            {
                nodes[i].Add(nodes[(i + 1) % K], 1);
                nodes[i].Add(nodes[(i * 10) % K], 0);
            }
            var q = new Queue<Node>();
            nodes[1].Distance = 1;
            q.Enqueue(nodes[1]);
            while (q.Count > 0)
            {
                Node node1 = q.Dequeue();
                foreach (var tuple in node1.Children)
                {
                    Node node2 = tuple.Item1;
                    int cost = tuple.Item2;
                    if (node1.Distance + cost < node2.Distance)
                    {
                        node2.Distance = node1.Distance + cost;
                        q.Enqueue(node2);
                    }
                }
            }
            return nodes[0].Distance;
        }

        static void Main(string[] args)
        {
            int K = ReadInt();
            Console.WriteLine(Solve(K));
        }
    }
}


Measured memory_bytes: 40712
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n, ans = MOD;
	cin >> n;
	vector<int> weight(n);
	vector<int> sum(n+1);
	sum[0] = 0;
	for (int i = 0; i < n; i++){
		cin >> weight[i];
	}
	for (int i = 1; i <= n; i++){
		sum[i] = sum[i-1] + weight[i-1];
	}
	for (int i = 1; i < n; i++){
		ans = min(ans, abs(2*sum[i]-sum[n]));
	}
	cout << ans << endl;
	return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<bool> b(10000, false);

    for (int i = 0; i < 1000; i++) {
        string ss;
        if (i < 100) {
            ss += '0';
            if (i < 10) {
                ss += '0' + to_string(i);
            } else {
                ss += to_string(i);
            }
        } else {
            ss += to_string(i);
        }

        bool t = false;
        int idx = 0;
        for (int j = 0; j < n; j++) {
            if (s[j] == ss[idx]) {
                idx++;
            }
        }

        if (idx >= 3) {
            t = true;
        } else {
            t = false;
        }

        b[i] = t;
    }

    int cnt = 0;
    rep(i, 1000) {
        if (b[i])
            cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    int n;
    cin >> n;
    int dp[3][n];

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < n; j++){
            dp[i][j] = 0;
        }

        int a;
        cin >> a;
        dp[i][0] = a;
    }

    for(int i = 0; i < n-1; i++){
        int a[3];

        for(int j = 0; j < 3; j++) cin >> a[j];

        dp[0][i+1] = max(dp[0][i+1],dp[1][i]+a[0]);
        dp[0][i+1] = max(dp[0][i+1],dp[2][i]+a[0]);
        dp[1][i+1] = max(dp[1][i+1],dp[0][i]+a[1]);
        dp[1][i+1] = max(dp[1][i+1],dp[2][i]+a[1]);
        dp[2][i+1] = max(dp[2][i+1],dp[0][i]+a[2]);
        dp[2][i+1] = max(dp[2][i+1],dp[1][i]+a[2]);
    }

    int ans = 0;

    for(int i = 0; i < 3; i++){
        ans = max(ans,dp[i][n-1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4732
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    rep(i,n) cin>>h[i];
    sort(all(h));
    ll mini=h[k-1]-h[0];
    repi(i,1,n-k+1){
        mini=min(mini,h[i+k-1]-h[i]);
    }
    cout<<mini<<endl;
}

Measured memory_bytes: 4032
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int reports=sc.nextInt();
		long takahashi=sc.nextLong();
		long aoki=sc.nextLong();
		for(int i=1; i<reports; i++) {
			long next_takahashi=sc.nextLong();
			long next_aoki=sc.nextLong();
			long multiplier=Math.max(takahashi/next_takahashi, aoki/next_aoki);
			while(next_aoki*multiplier<aoki || next_takahashi*multiplier<takahashi) {
				multiplier++;
			}
			takahashi=next_takahashi*multiplier;
			aoki=next_aoki*multiplier;
		}
		System.out.println(takahashi+aoki);
	}
}

Measured memory_bytes: 26452
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Triangle
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int X1 = 1000000000;
const int Y1 = 1;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  ll s;
  scanf("%lld", &s);

  // |x1y2-x2y1|=s -> X1y2-x2=s

  if (s == (ll)X1*X1)
    printf("0 0 %d 0 0 %d\n", X1, X1);
  else {
    ll y2 = s / X1 + 1, x2 = X1 - s % X1;
    printf("0 0 %d %d %lld %lld\n", X1, Y1, x2, y2);
  }
  return 0;
}


Measured memory_bytes: 256
/*
  AOJ 0098
  Title:Maximum sum of sequence
  @kankichi573
  2014/3/1 RTE
*/
#include <stdio.h>
#include <limits.h>
#define max(x,y) (((x)>(y))?(x):(y))
int N;
int array[100][100];
int row_sum[100][100][100];
void calc_row_sum()
{
  int i,j,k,s;
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      {
	s=0;
	for(k=0;k<=N-j;k++)
	  {
	    s += array[i][j+k];
	    row_sum[i][j][k]=s;
	  }
      }
}
dump()
{
  int i,j,k;
  for(i=0;i<N;i++)
    {
    for(j=0;j<N;j++)
      {
	for(k=0;k<N-j;k++)
	  printf("%02d|",row_sum[i][j][k]);
	printf("|");
      }
    printf("\n");
    }
}
int calc_matrix_sum(int top,int left,int height,int width)
{
  int i,ret=0;
  for(i=top;i<=top+height;i++)
    ret+=row_sum[i][left][width];
  return(ret);
}
main()
{
  int i,j,k,l,max_,v;
  scanf("%d ",&N);
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      scanf("%d",&array[i][j]);

  calc_row_sum();
  //dump();
  max_=INT_MIN;
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      for(k=0;k<=N-1-i;k++)
	for(l=0;l<=N-1-j;l++)
	  if(max_ < (v=calc_matrix_sum(i,j,k,l)))
	    {
	      //printf("%d %d %d %d:%d\n",i,j,k,l,v);
	      max_=v;
	    }
  printf("%d\n",max_);
  return(0);
}

Measured memory_bytes: 4544
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int main() {
  int N,T; cin>>N>>T;
  vi time(N);
  rep(i,N) cin>>time[i];
  ll ans = 0;
  int ct=0;
  rep(i,N){
    if(time[i]>=ct){
      ans += T;
    }
    else {
      ans = ans + time[i] - ct + T;
    }
    ct = time[i]+T;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3868
N = int(input())
XL = [tuple(map(int, input().split())) for i in range(N)]

XL.sort(key=lambda x: x[0])

hold = [XL[0]]

ans = 1
for i in range(1, N):
    if hold[-1][0] + hold[-1][1] > XL[i][0] - XL[i][1]:
        if hold[-1][0] + hold[-1][1] < XL[i][0] + XL[i][1]:
            continue
        else:
            hold.append(XL[i])
    else:
        ans += 1
        hold.append(XL[i])

print(ans)

Measured memory_bytes: 67160
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string str;cin >> str;
	
	vector<int> v;
	
	char now = str[0];
	int cou = 0;
	REP(i,str.size())
	{
		if(now == str[i])
		{
			cou++;
		}
		else
		{
			v.PB(cou);
			now = str[i];
			cou = 1;
		}
	}
	if(cou)v.PB(cou);
	
	SHOW1d(v,v.size());
	
	ll ans = 0;
	if(v.size() == 1)
	{
		cout << v[0] << endl;
		return 0;
	}
	if(v.size() == 2)
	{
		cout << max(v[0],v[1]) << endl;
		return 0;
	}
	ll tmp = 0;
	
	REP(i,v.size())
	{
		ll A = tmp+v[i];
		ll B = str.size() - tmp;
		ans = max(ans,min(A,B));		
		tmp += v[i];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;


void print() {
    cout << endl;
}
 
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}
 
template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}
 
template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}
 

int main(){
  int H, W;cin >> H >> W;
  int h, w;cin >> h >> w;
  cout << (H - h) * (W - w) << endl;
}    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n, m;
  cin >> n >> m;
  
  if (n % 2 == 1){
    for (int i = 1; i < m + 1; i++){
      cout << i << "  " << n - i << endl;
    }
  }
  else {
    for (int i = 1; i <= (m + 1)/2; i++){
      cout << i << " " << m + 2 - i << endl;
    }
    for (int i = 1; i <= m/2; i++){
      cout << i + m + 1 << " " << m + 1 - i + m + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3632
from collections import deque
n = int(input())
edge = [[] for _ in range(n)]
ans = [0]*(n-1)
for i in range(n-1):
    u, v = map(int, input().split())
    edge[u-1].append((i, v-1))
    edge[v-1].append((i, u-1))


ans[0] = 1
parents = [-1]*n
que = deque([[0, 0]])
while que:
    a, b = que.popleft()
    color = 1
    for i, j in edge[a]:
        if parents[a] == j:
            continue
        if color == b:
            color += 1
        ans[i] = color
        parents[j] = a
        que.append([j, color])
        color += 1
print(max(ans))
for i in ans: print(i)

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

int main(){
  int n;
  long long sum = 0;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v.push_back(a);
    sum += a;
  }
  sort(v.begin(), v.end());
  cout << v.at(0) << " " << v.at(n-1) << " " << sum << endl;
}


Measured memory_bytes: 3256
N = int(input())

def num2alpha(num):
    if num <= 26:
        return chr(64+num)
    elif num % 26 == 0:
        return num2alpha(num // 26 - 1) + chr(90)
    else:
        return num2alpha(num // 26) + chr(64 + num % 26)

print(num2alpha(N).lower())

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

int main() {
  int N;
  bool ans = 0;
  cin >> N;
  vector<int> kuku;
  for (int i = 1; i < 10; i++) for (int j = 1; j < 10; j++) {
    kuku.push_back(i * j);
  }
  
//  for (int i = 0; i < kuku.size(); i++) {
  //  if (kuku.at(i) == N) { 
    //  ans = 1;
      //break;
    //}
  //}
  
  for (int c : kuku) {
    if (c == N) {
      ans = 1;
      break;
    }
  }
  
  if (ans == 1) cout << "Yes";
  else cout << "No";
}

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

using namespace std;

int main(){
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  if(a>=k)cout << k << endl;
  else if(a+b>=k)cout << a << endl;
  else cout << a - (k-(a+b)) << endl;
}


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

const int MAX_V = 2000;
struct Edge {
	int dst, flow, rev;
	Edge() {}
	Edge(int d, int f, int r) {
		dst = d;
		flow = f;
		rev = r;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &g, int src, int dst, int flow) {
	g[src].push_back(Edge(dst, flow, g[dst].size()));
	g[dst].push_back(Edge(src, 0, g[src].size() - 1));
}

int dfs(Graph &g, int s, int t, int flow, bool visited[], int level[]) {
	visited[s] = true;
	if (s == t) return flow;
	for (int i = 0; i < g[s].size(); i++) {
		Edge edge = g[s][i];
		if (visited[edge.dst] || level[edge.dst] != level[s] + 1 || edge.flow == 0) continue;
		int f = dfs(g, edge.dst, t, min(flow, edge.flow), visited, level);
		if (f == 0) continue;
		int rev = g[s][i].rev;
		g[s][i].flow -= f;
		g[edge.dst][rev].flow += f;
		return f;
	}
	return 0;
}

void bfs(Graph &g, int s, int level[]) {
	int i;
	for (i = 0; i < g.size(); i++) level[i] = -1;
	queue<int> que;
	que.push(s);
	level[s] = 0;
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (int i = 0; i < g[v].size(); i++) {
			int nv = g[v][i].dst;
			if (level[nv] != -1 || g[v][i].flow == 0) continue;
			level[nv] = level[v] + 1;
			que.push(nv);
		}
	}
}

int maxflow(Graph &g, int s, int t) {
	bool visited[MAX_V];
	int level[MAX_V];
	int INF = 11451419;
	int maxFlow = 0;
	
	while (true) {
		bfs(g, s, level);
		if (level[t] == -1) break;
		while (true) {
			for (int i = 0; i < g.size(); i++) visited[i] = false;
			int flow = dfs(g, s, t, INF, visited, level);
			if (flow == 0) break;
			maxFlow += flow;
		}
	}
	return maxFlow;
}

int n, m;
int u, v, c;
Graph g;

int main() {
	cin >> n >> m;
	g.resize(n);
	for (int i = 0; i < m; i++) {
		cin >> u >> v >> c;
		add_edge(g, u, v, c);
	}
	cout << maxflow(g, 0, n - 1) << endl;
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    int64_t sum = 0;
    for (int i = 1; i <= n; i++) {
        if (i%3 != 0 && i%5 != 0) {
            sum += i;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
import scala.collection.mutable
import java.io.{BufferedReader, InputStreamReader}

object Main extends App {
  val in = new BufferedReader(new InputStreamReader(System.in))
  val map = mutable.HashMap[Int,Int]()

  val n = in.readLine.toInt
  in.readLine.split(" ").map(_.toInt)
    .foreach(e => {
      if(!map.contains(e)) map += e -> 1
      else map(e) +=1
    })

  val x = map.keys

  val ans = x./:(0)((acc,e) => {
      val cnt = map.getOrElse(e-1,0) + map.getOrElse(e,0) + map.getOrElse(e+1,0)
      math.max(acc, cnt)
    })

  println(ans)
}

Measured memory_bytes: 48704
#include<bits/stdc++.h>
using namespace std;
int n, a[2005];

int read()
{
	int x = 0,f = 1;
	char ch= getchar();
	while(ch<'0' || ch>'9')
	{
		if(ch == '-')
			f=-1;
		ch = getchar();
	} 
	while(ch>='0' && ch<='9')
	{
		x = (x<<1) + (x<<3) + ch-'0';
		ch = getchar();
	}
	return x*f;
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n = read();
	for(int i = 1;i <= n;i++)
		a[i] = read();
	sort(a + 1, a + 1 + n);
	int ans = 0;
	for(int i = 1;i <= n;i++)
	{
		for(int j = i + 1;j <= n;j++)
		{
			for(int k = j + 1;k <= n;k++)
			{
				if(a[j] + a[i] > a[k])
					ans++;
				else
					break;
			}
		}
	}
	printf("%d", ans);
	return 0;
} 

Measured memory_bytes: 256
#!/usr/bin/env python3
def main():
    import sys

    def calc(A: list):
        score = 0
        for a, b, c, d in lst:
            if A[b - 1] - A[a - 1] == c:
                score += d
        return score

    def dfs(A: list):
        nonlocal ans
        if len(A) == N:
            ans = max(ans, calc(A))
            return
        for v in range(A[-1] if A else 1, M + 1):
            A.append(v)
            dfs(A)
            A.pop()
    
    input = sys.stdin.readline

    N, M, Q = map(int, input().split())
    lst = [list(map(int, input().split())) for _ in range(Q)]

    ans = 0
    dfs([])
    print(ans)


main()


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define MOD  1000000007
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y

//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};
ll n,m,a[200005],b[200005];

ll bigmod(ll x,ll y,ll m)
{
    if(y==0)return 1;
    ll n=bigmod(x,y/2,m);
    n=(n*n)%m;
    if(y & 1)n=((n%m)*(x%m))%m;
    return n;
}

int main()
{
    ll var;
    sfl(n);sfl(m);
    c=0;

    z=n;
    j=n-1;
    a[1]=n+1;
    for(i=1;i<=n+1;i++)
    {
        a[i]=z-(c-1);
        z+=j;j--;
        c+=i;
    }
    z=0;
    for(i=m;i<=n+1;i++)
    {
        z+=a[i];
        z%=MOD;
    }
    cout<<z<<endl;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,M;
  cin>>N>>M;
  vector<pair<int,string>>p(M);
  for(int i=0;i<M;i++)cin>>p[i].first>>p[i].second;
  for(int i=0;i<M;i++)p[i].first--;
  int ac=0;
  vector<bool>b(N);
  vector<int>wa(N);
  for(int i=0;i<M;i++){
    if(!b[p[i].first]&&p[i].second=="AC")ac++,b[p[i].first]=true;
    else if(!b[p[i].first])wa[p[i].first]++;
  }
  int waa=0;
  for(int i=0;i<N;i++)if(b[i])waa+=wa[i];
  cout<<ac<<" "<<waa<<endl;
  return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if ((x - r >= 0 && x + r <= w) && (y - r >= 0 && y + r <= h)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

int a, b;

int main() {
	int c = 0;

	cin >> a >> b;
	int t;
	if (b / 10 == 0)
		t = 1;
	else if (b / 100 == 0)
		t = 2;
	else
		t = 3;
	int k = 1;
	for (int i = 1; i <= t; i ++)
		k *= 10;
	c = a * k + b;
	if ((int)(sqrt(c)) * (int)(sqrt(c)) == c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  int ans=0;
  for(int i=1;i<=N;++i){
    int sum=0;
    int temp=i;
    while(temp){
      sum+=temp%10;
      if(B<sum) break;
      temp/=10;
    }
    if(A<=sum && sum<=B) ans+=i;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3560
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000002
#define VMAX 10000

void countingSort(int);

short unsigned int *a, *b;

int main(){
 
  int c[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  a = malloc(sizeof(short)*n+1);
  b = malloc(sizeof(short)*n+1);

  for(i = 0; i < n; i++)
    {
      scanf("%d", &a[i]);
    }
    
  countingSort(n);

  for(i = 0; i < n-1; i++)
    {
      printf("%d ", b[i]);
    }
  printf("%d", b[i]);
  printf("\n");
  
  return 0;
}

void countingSort(int n)
{
  int i,sum;
  int c[VMAX];

  for( i = 0; i < VMAX; i++)c[i] = 0;
  
  for( i = 0; i < n; i++)
    {
      c[a[i]]++;
    }
  for(i = 1;i <= VMAX; i++)
    {
      c[i] = c[i] + c[i-1];
    }
  for(i = n-1; i >= 0; i--)
    {
      b[c[a[i]]-1] = a[i];
      c[a[i]]--;
    }

  return;
}



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

using namespace std;

int main(void) {

    string S;
    cin >> S;

    if (S.length()==2) {
        cout << S << endl;
    }
    else if (S.length()==3) {
        for (int i = S.length()-1; i >= 0; i--) {
            cout << S[i];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>
#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

const LL M = 1e7 + 1;
vector<LL> smallest;
LL cal(LL num)
{
    LL curr = num;
    int fac;
    //unordered_map<int, int> freq;
    LL ans = 1;
    int cnt;
    while (smallest[curr] != 1)
    {
        fac = smallest[curr];
        cnt=0;
        while(curr%fac==0)
        {
            curr/=fac;
            cnt++;
        }
        ans*=(cnt+1);
    }
    return ans;
}

void generate(LL n)
{
    smallest.resize(n+1);
    smallest.assign(n+1,-1);
    smallest[0] = 1;
    smallest[1] = 1;
    LL i,j;
    for (i = 2; i <=n; i++)
    {
        if (smallest[i] == -1)
        {
            smallest[i] = i;
            for (j = i * i; j <= n; j += i)
            {
                if (smallest[j] == -1)
                {
                    smallest[j] = i;
                }
            }
        }
    }
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc, a, b;
    cin >> n;
    generate(n);

    //cin >> n;
    LL sum = 5;
    if (n == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    else if (n == 2)
    {
        cout << 5 << endl;
        return 0;
    }
    else
    {
        LL add;
        for (i = 3; i <= n; i++)
        {
            add = cal(i);
            // debug(i);
             //debug(add);
            // part;
            sum += (add * i);
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 81344
n=int(input())
if len(str(n))==2:
  print(9)
elif len(str(n))==4:
  print(909)
elif len(str(n))==6:
  print(90909)
elif len(str(n))==1:
  print(n)
elif len(str(n))==3:
  print(n-90)
else:
  print(n-9090)
  
  

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

using namespace std;

static const int kModulo = 1000 * 1000 * 1000 + 7;

int main() {
    ios::sync_with_stdio(false);
    int N; cin >> N;

    vector<int> T(N), A(N);
    for (int i = 0; i < N; ++i)
        cin >> T[i];
    for (int j = 0; j < N; ++j)
        cin >> A[j];

    vector<int> low(N, 1), high(N, numeric_limits<int>::max());
    low[0] = high[0] = T[0];
    low[N - 1] = max(low[N - 1], A[N - 1]);
    high[N - 1] = min(high[N - 1], A[N - 1]);
    for (int i = 1; i < N; ++i) {
        if (T[i - 1] < T[i]) {
            low[i] = max(T[i], low[i]);
        }
        high[i] = min(high[i], T[i]);
    }

    for (int i = N - 2; i >= 0; --i) {
        if (A[i] > A[i + 1]) {
            low[i] = max(low[i], A[i]);
        }
        high[i] = min(high[i], A[i]);
    }

    for (int i = 0; i < N; ++i)
        if (low[i] > high[i]) {
            cout << 0 << "\n";
            return 0;
        }

    int answer = 1;
    for (int i = 0; i < N; ++i)
        answer = (1LL * answer * (high[i] - low[i] + 1)) % kModulo;
    cout << answer << "\n";
}


Measured memory_bytes: 1920
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################

n = int(input())
arr = []
for i in range(n):
	arr.append(list(map(int , input().split())))
f = 0
for i in range(n-3):
	if arr[i][0] == arr[i][1] and arr[i+1][0] == arr[i+1][1] and arr[i+2][0] == arr[i+2][1] :
		f = 1
i = 0
if arr[i][0] == arr[i][1] and arr[i+1][0] == arr[i+1][1] and arr[i+2][0] == arr[i+2][1] :
		f = 1
if f:
	print("Yes")
else:
	print("No")
	








'''
# Wrap solution for more recursion depth
#submit as python3
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)



threading.Thread(target=solve).start()
'''


Measured memory_bytes: 65900
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int n;
    long long T;
    cin >> n >> T;
    long long t[n], ans;
    ans = 0;
    for(int i = 0; i < n; i++){
        cin >> t[i];
    }

    for(int i = 0; i < n-1; i++){
        ans += min(T, t[i+1] - t[i]);
    }
    ans += T;
    cout << ans << endl;
    return 0;
}

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

int main() {
  int k,n;
  cin >> k >> n;
  vector<int> p(n);
  for(int i=0; i<n; i++){
    cin >> p.at(i);
  }
  
  int max=0;
  for(int i=1; i<=n-1; i++){
    if((p.at(i)-p.at(i-1)) >= max){
      max = (p.at(i)-p.at(i-1));
    }
  }
    if(k-p.at(n-1)+p.at(0) >= max){
      max = k-p.at(n-1)+p.at(0);
    }
  
  cout << k - max << endl;
	return 0;
}


Measured memory_bytes: 1024