akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n, k;
    cin >> n >> k;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    set<int> s;
    multiset<int> ss;
    int l = 0, r = 0;
    int minwidth = 1e9;
    while (1) {
        if (s.size() < k) {
            if (r == n) break;
            if (as[r] <= k) {
                ss.insert(as[r]);
                s.insert(as[r]);
            }
            r++;
            continue;
        }
        minwidth = min(minwidth, r - l);
        if (ss.find(as[l]) != ss.end()) {
            ss.erase(ss.find(as[l]));
            if (ss.find(as[l]) == ss.end()) {
                s.erase(as[l]);
            }
        }
        l++;
    }
    cout << (minwidth == 1e9 ? 0 : minwidth) << endl;
}


Measured memory_bytes: 12860
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

int main() {
	ll n, a[100001] = {};
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}

	ll ans = 0;
	for(int i = 0;i < n;i++){
		ans += a[i] / 2;
		a[i] %= 2;

		if(i > 0 && a[i] >= 1 && a[i - 1] >= 1){
			ans++;
			a[i]--;
			a[i - 1]--;
		}
		if(a[i] >= 1 && a[i + 1] >= 1){
			ans++;
			a[i]--;
			a[i + 1]--;
		}
	}

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

Measured memory_bytes: 1024
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int32_t main(){
    IOS;
    int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    int p = x/d;
    if(k <= p){
        cout << x - k*d << endl;
        return 0;
    } 
    x -= p*d;
    if((k-p)&1) cout << abs(x-d) << endl;
    else cout << x << endl;
    
    return 0;
    
       
}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> e(m);
  for (auto& x : e) {
    cin >> x.first >> x.second;
    x.first--;
    x.second--;
  }
  vector<int> par(n, -1);
  auto root = [&](int t) {
    if (par[t] < 0) return t;
    for (int i = t;; i = par[i])
      if (par[i] < 0) return par[t] = i;
  };
  vector<ll> ans;
  ll a = (ll)n * (n - 1) / 2;
  for (int i = m; i--;) {
    ans.push_back(a);
    int r1 = root(e[i].first), r2 = root(e[i].second);
    if (r1 != r2) {
      a -= (ll)par[r1] * par[r2];
      if (par[r1] > par[r2]) swap(r1, r2);
      par[r1] += par[r2];
      par[r2] = r1;
    }
  }
  reverse(ans.begin(), ans.end());
  for (auto x : ans) cout << x << "\n";
}


Measured memory_bytes: 3444
#include<stdio.h>
#include<string.h>
#include<math.h>
#define Min(x,y) ((x<y)?x:y)

typedef struct b{
	int n,x,y;
}B;
B a[1010];
double d[1010][1010],v[1010];
int u[1010],pre[1010],t[1010],num[1010];
int main(){
	int i,j,n,m,x,y,s,g;
	
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d%d%d",&a[i].n,&a[i].x,&a[i].y);
			num[a[i].n]=i;
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(i!=j){
					x=a[i].x-a[j].x;
					y=a[i].y-a[j].y;
					if(x*x+y*y<=2500)d[i][j]=d[j][i]=sqrt(x*x+y*y);
					else d[i][j]=d[j][i]=2000000;
				}
				else d[i][i]=2000000;
				//printf("%04.2lf ",d[i][j]);
			}
			//printf("\n");
		}
		scanf("%d",&m);
		while(m--){
			scanf("%d%d",&s,&g);
			//s--;g--;
			s=num[s];
			g=num[g];
			memset(u,-1,sizeof(u));
			memset(pre,-1,sizeof(pre));
			for(i=0;i<n;i++)v[i]=1000000;
			v[s]=0;
			while(1){
				x=-1;
				for(i=0;i<n;i++){
					if(u[i]==-1 && (x==-1 || v[i]<v[x]))x=i;
				}
				if(x==-1)break;
				u[x]=0;
				for(i=0;i<n;i++){
					if(v[x]+d[x][i]<v[i]){
						pre[i]=x;
						v[i]=v[x]+d[x][i];
					}
				}
			}
			if(pre[g]==-1)printf("NA\n");
			else{
				x=0;
				t[0]=g;
				while(t[x]!=s){
					t[x+1]=pre[t[x]];
					x++;
				}
				for(i=x;i>=0;i--)printf("%d%s",a[t[i]].n,(i==0)?"\n":" ");
			}
		}
	}
	
	return 0;
}

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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int H, W, D;
int A[301][301], x[90001], y[90001];
int d[90001];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    cin >> H >> W >> D;
    rep(i, H) rep(j, W) cin >> A[i][j];
    rep(i, H) rep(j, W) {
        x[A[i][j]] = j;
        y[A[i][j]] = i;
    }
    FOR(i, D + 1, H * W + 1) {
        d[i] = d[i - D] + abs(y[i] - y[i - D]) + abs(x[i] - x[i - D]);
    }
    int query;
    cin >> query;
    rep(i, query) {
        int L, R;
        cin >> L >> R;
        cout << d[R] - d[L] << endl;
    }
    return 0;
}

Measured memory_bytes: 3968
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
//        int n = sc.nextInt();
//        System.out.println((int)(n+Math.pow(n,2)+Math.pow(n,3)));
        String s = sc.next();
        String t = sc.next();
        int count = 0;

        for (int i = 0;i<s.length();++i)
        {
            String ss = s.substring(i,i+1);
            String tt = t.substring(i,i+1);
            if (!ss.equals(tt)) ++count;
        }
        System.out.println(count);
        sc.close();
    }
}

Measured memory_bytes: 55828
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) {
		cout << "a > b" << endl;
	}
	if (a == b) {
		cout << "a == b" << endl;
	}
	if (a < b) {
		cout << "a < b" << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
long N,i,j,mod=1e9+7,ans,cnt;
int main(){
  cin>>N;
  vector<long>A(N);
  for(auto& a:A)cin>>a;
  for(i=0;i<60;i++){
    cnt=0;
    for(auto& a:A)cnt+=a>>i&1;
    cnt=cnt*(N-cnt)%mod;
    for(j=0;j<i;j++)cnt=cnt*2%mod;
    ans+=cnt;
  }
  cout<<ans%mod<<endl;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 200000






int main(){
	char a[10][10];
	f(i, 8){
		scanf("%s", a[i]);
	}
	printf("90\n");
	f(i, 8){
		f(j, 8){
			printf("%c", a[7-j][i]);
		}
		printf("\n");
	}
	printf("180\n");
	f(i, 8){
		f(j, 8){
			printf("%c", a[7 - i][7 - j]);
		}
		printf("\n");
	}
	printf("270\n");
	f(i, 8){
		f(j, 8){
			printf("%c", a[j][7 - i]);
		}
		printf("\n");
	}




	return 0;
}


Measured memory_bytes: 2576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<double> x(N);
  vector<string> u(N);
  for (int i=0; i<N; i++){
    cin >> x.at(i) >> u.at(i);
  }
  double money=0;
  for(int i=0; i<N; i++){
    if(u.at(i) == "JPY")
      money += x.at(i);
    else
      money += x.at(i) * 380000;
  }
  cout << money << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#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(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (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 i = 0;i < (n);i++)cerr << v[i] << ' ';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()

using namespace std;

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

double p,q,a,n,syou;
int ans;

int check(double a,double b)
{
	if(a - b < 1e-9 && b - a < 1e-9)return 0;
	else return 1;
}


void dfs(double sum,int seki,int now,int mae)
{
	for(int i = mae;i < a;i++)
	{
		if(seki * i > a)break;
		double aa = (double)1/i;
		int tmp = check(syou,sum+aa);
		if(tmp == 0)
		{
			ans++;
		}
		else if(sum+aa < syou && now < n)
		{
			dfs(sum+aa,seki*i,now+1,i);
		}
	}
}

int main()
{
	
	while(cin>>p>>q>>a>>n,p != 0)
	{
		syou = p/q;
		ans = 0;
		dfs(0,1,1,1);
		cout << ans << endl;
	}	
	
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int main(){
  int n;cin>>n;
  int s[100001]={};
    rep(i,100000){
      string p=to_string(i+1);
      int ssz=p.size();
      if(ssz%2)s[i+1]=s[i]+1;
      else s[i+1]=s[i];
    }
  cout<<s[n]<<endl;
}

Measured memory_bytes: 640
/* ex 7_1
   riverstone */

#include <stdio.h>

//頂点を表す構造体
typedef struct point{
    int x_elem;
    int y_elem;
}point;

//関数shift_pointの定義
//ある基点point_baseから指定された移動方向に移動させたポイントを返す
point shift_point(point point_base,point point_shift){
    point point_ret;
    point_ret.x_elem = point_base.x_elem + point_shift.x_elem;
    point_ret.y_elem = point_base.y_elem + point_shift.y_elem; 
    return point_ret;
}

int main(void){
    point point1, point2, point3, point4,point_dif;
    //入力を受け取る
    scanf("%d %d %d %d", &point1.x_elem, &point1.y_elem, &point2.x_elem, &point2.y_elem);

    //残り2点の座標を求める
    //頂点1から頂点4へのベクトル(=頂点2から頂点3へのベクトル)を定義
    point_dif.x_elem = -point2.y_elem + point1.y_elem;
    point_dif.y_elem = point2.x_elem - point1.x_elem;
 
    //頂点2を基点にして頂点3を求める
    point3 = shift_point(point2,point_dif);
    //頂点1を基点にして頂点4を求める
    point4 = shift_point(point1,point_dif);

    //出力
    printf("%d %d %d %d\n", point3.x_elem, point3.y_elem, point4.x_elem, point4.y_elem);
    return 0;
}

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

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

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

using mint = modint998244353;

mint table[10][MAX];

struct S {
    mint n;
    int size;
};

struct F {
    char d;
    bool id;
};

S op(S a, S b) {
    return S{a.n * mint(10).pow(b.size) + b.n, a.size + b.size};
}

S e() { return S{0, 0}; }

S mapping(F l, S r) {
    return (l.id)? r : S{table[l.d - '0'][r.size], r.size};
}

F composition(F l, F r) {
    if (l.id) {
        return (r.id)? l : r;
    } else {
        return l;
    }
}

F id() { return F{'0', true}; }

int main(){
    int N, Q;
    cin >> N >> Q;

    for (int i = 1; i < 10; ++i) {
        rep(j, N) {
            table[i][j+1] = table[i][j] * 10 + i;
        }
    }

    vector<S> v(N);
    rep(i, N) {
        v[i].n = 1;
        v[i].size = 1;
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> st(v);

    rep(i, Q) {
        int l, r;
        char d;
        cin >> l >> r >> d;
        l--;

        st.apply(l, r, F{d, false});
        cout << st.all_prod().n.val() << endl;
    }
}

Measured memory_bytes: 17296
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ax = 0
for aa in range(a+1):
  for bb in range(b+1):
    for cc in range(c+1):
      if aa * 500 + bb * 100 + cc * 50 == x:
        ax += 1
print(ax)


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{

    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] h = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int output = 0;
            while (true)
            {
                if (h.Sum() == 0) break;

                int i = 0;
                for (; i < N; i++)
                {
                    if (h[i] != 0)
                    {
                        break;
                    }

                }
                int j = i;
                for (; j < N; j++)
                {
                    if (h[j] == 0)
                    {

                        break;
                    }

                }
                j--;


                for (int k = i; k <= j; k++)
                {
                    h[k]--;

                }

                output++;
            }

            Console.WriteLine(output);
        }

    }
}

Measured memory_bytes: 13396
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);

        int k=sc.nextInt();
        if(k%2==1){
            System.out.println(""+(k/2)*(k/2+1));
        }else{
            System.out.println(""+(k/2)*(k/2));
        }
    }
}

Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;
const int N = 3e3 + 3;
const int mod = 1e9 + 7;
int n , m;
char str[N];
int sum[N];
int arr[N];
int a , b;
int dp[N][N];
int solve(int l , int r , int cnt){
    if(cnt > r - l + 1){
        return 0;
    }
    if(l > n){
        return 1;
    }
    if(arr[l] > r){
        cnt += sum[arr[l]] - sum[r];
        r = arr[l];
    }
    if(dp[l][cnt] != -1){
        return dp[l][cnt];
    }
    int res = 0;
    if(cnt){
        res += solve(l + 1 , r , cnt - 1);
    }
    res += solve(l + 1 , r , cnt);
    if(res >= mod){
        res -= mod;
    }
    return dp[l][cnt] = res;
}
int main(){
    scanf("%d %d" , &n , &m);
    scanf("%s" , str + 1);
    sum[0] = 0;
    for(int i = 1 ; i <= n ; ++i){
        sum[i] = sum[i - 1] + str[i] - '0';
    }
    for(int i = 1 ; i <= n ; ++i){
        arr[i] = i;
    }
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d %d" , &a , &b);
        arr[a] = max(arr[a] , b);
    }
    memset(dp , -1 , sizeof(dp));
    printf("%d\n" , solve(1 , 0 , 0));
}

Measured memory_bytes: 35712
MOD = 1e9 + 7

N, M = [int(i) for i in input().split()]
issafe = [True] * (N + 1)
for i in range(M):
    a = int(input())
    # a 段目は壊れている
    issafe[a] = False

# dp
dp = [0] * (N + 1)
# 初期化
dp[0] = 1
if issafe[1]:
    dp[1] = 1

for i in range(2, N + 1):
    # i - 1 段目が安全なら
    if issafe[i - 1]:
        dp[i] += dp[i - 1]
    # i - 2 段目が安全なら
    if issafe[i - 2]:
        dp[i] += dp[i - 2]
    dp[i] %= MOD
print(int(dp[N]))


Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

const int INF = 1e9;
const int NIL = 2e9;

int n, m;
int a[51], b[51];
int as[51], bs[51];

// ???????????????????????????????????????-1?????????????????????
int dp[51][51][51][51][3][2];

int sum(int l, int r, int *a){
    return a[r] - a[l];
}

// x, y: ?¬????????????????????????????
// lx, ly: ?¶???????????°??????????????????????
int rec(int x, int y, int lx, int ly, int p, int t){
    int &res = dp[x][y][lx][ly][p][t];
    if(res != NIL) return res;
    if(t == 0){
        res = -INF;
        if(x != n){
            int cand = rec(x+1, y, lx, (a[x] ? ly : y), 0, !t);
            res = max(res, cand);
        }
        {
            int cand = sum(lx, x, as) - sum(ly, y, bs);
            if(p != 2) cand += rec(x, y, x, y, p+1, !t);
            res = max(res, cand);
        }
    } else {
        res = INF;
        if(y != m){
            int cand = rec(x, y+1, (b[y] ? lx : x), ly, 0, !t);
            res = min(res, cand);
        }
        {
            int cand = sum(lx, x, as) - sum(ly, y, bs);
            if(p != 2) cand += rec(x, y, x, y, p+1, !t);
            res = min(res, cand);
        }
    }
    return res;
}

int main(){
    cin >> n >> m;
    rep(i, n){
        cin >> a[i];
        a[i] = max(0, a[i]);
        as[i+1] = as[i] + a[i];
    }
    rep(i, m){
        cin >> b[i];
        b[i] = max(0, b[i]);
        bs[i+1] = bs[i] + b[i];
    }
    fill((int*)begin(dp), (int*)end(dp), NIL);
    cout << rec(0, 0, 0, 0, 0, 0) << endl;
}

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

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

	std::vector<std::string> week(7);
	week[0] = "SAT";
	week[1] = "FRI";
	week[2] = "THU";
	week[3] = "WED";
	week[4] = "TUE";
	week[5] = "MON";
	week[6] = "SUN";

	auto i = std::find(week.begin(), week.end(), S) - std::begin(week) + 1;

	std::cout << i << std::endl;

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int H=sc.nextInt();
	int W=sc.nextInt();
	int h=sc.nextInt();
	int w=sc.nextInt();
	System.out.println((H-h)*(W-w));
}
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    vector<vector<int>> c(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> c[i][j];

    // a1を決め打ちして求める
    rep(i, min(c[0][0], min(c[0][1],c[0][2])) + 1) {
        int b1 = c[0][0] - i;
        int b2 = c[0][1] - i;
        int b3 = c[0][2] - i;
        if(c[1][0]-b1 == c[1][1]-b2 && c[1][1]-b2 == c[1][2]-b3) {
            if(c[2][0]-b1 == c[2][1]-b2 && c[2][1]-b2 == c[2][2]-b3) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

mod = 10**9 + 7
N, K = map(int, input().split())

edges = [[] * N for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

# 0をrootとする
dq = deque([0])

visited = [False] * N
visited[0] = True

# color[i] = i番目の頂点を塗ることが可能な色の数
# 全て更新するので初期値は任意
color = [0] * N
color[0] = K

"""
root = 0 から末端に向かって調べる

子1, 子2, 子3, ...と複数の「未着色」の子がある場合、塗ることが出来る色の数は
K-1, K-2, K-3,... (p==0 の場合)
K-2, K-3, K-4,... (p!=0 の場合)　のようになる

子が十分多い場合、どこかで「0」になるので、ans = 0　となる
故に、色の数が負になっても答えには影響しない
"""

while dq:
    # 親となる頂点
    p = dq.popleft()
    # 親をpとした時の、「未着色」な子の数
    cnt = 0
    for c in edges[p]:
        if not visited[c]:
            if p == 0:
                color[c] = (K - 1 - cnt) % mod
            else:
                color[c] = (K - 2 - cnt) % mod
            cnt += 1
            visited[c] = True
            dq.append(c)

ans = 1
for i in range(N):
    ans = (ans * color[i]) % mod

print(ans)


Measured memory_bytes: 91376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int INF = 1e9+5;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    multiset<int> st;
    rep(i,n){
        auto itr = st.lower_bound(a[i]);
        if (itr != st.begin()) st.erase(--itr);
        st.insert(a[i]);
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 8276
s = input()

x, y = None, None
for i in range(len(s)):
    if s[i] == 'A':
        x = i
        break
for i in range(len(s) - 1, -1, -1):
    if s[i] == 'Z':
        y = i
        break
print(len(s[x:y + 1]))


Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
      mint a = pow(t>>1);
      a *= a;
    if (t&1) a *= *this;
      return a;
  }
   mint inv() const { return pow(MOD-2);}
   mint& operator/=(const mint a) { return *this *= a.inv();}
   mint operator/(const mint a) const { return mint(*this) /= a;}
};
typedef vector<mint> vm;
typedef vector<vm> vvm;

  
int main() {
  int N,K;
  cin >> N >> K;
  vl sum(N+2,0);
  rep(i,N+1) {
    sum[i+1] = sum[i]+i;
  }
  mint ans = 0;
  srep(k,K,N+2) {
    ll ma = sum[N+1]-sum[N+1-k];
    ll mi = sum[k];
    ans += ma-mi+1;
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    lint q;
    cin >> q;

    deque<char> dq(s.begin(), s.end());
    bool foward = true;
    while(q--) {
        lint t;
        cin >> t;

        if(t == 1) {
            foward = !foward;
        }

        if(t == 2) {
            lint f;
            char c;
            cin >> f >> c;
            if(f == 1) {
                if(foward) {
                    dq.push_front(c);
                } else {
                    dq.push_back(c);
                }
            } else {
                if(foward) {
                    dq.push_back(c);
                } else {
                    dq.push_front(c);
                }
            }
        }
    }
    if(!foward)  reverse(dq.begin(), dq.end());

    for(auto& e : dq)  cout << e;
    cout << endl;
}

Measured memory_bytes: 896
// Problem : C - H and V
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_c
// Memory Limit : 1024 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

void GABS(int n, vector <vector <int>> &perms, vector <int> arr, int i) 
{ 
    if (i == n) { 
    	perms.push_back(arr); 
        return; 
    } 
   
    arr[i] = 0; 
    GABS(n, perms, arr, i + 1); 
  
    arr[i] = 1; 
    GABS(n, perms, arr, i + 1); 
} 


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h,w,k;
	cin>>h>>w>>k;
	
	vector <vector <char>> grid;
	for(int j = 0 ; j < h; j++)
	{
		vector <char> crow(w);
		for(int k = 0 ; k < w; k++)
		{
			cin>>crow[k];
		}
		grid.push_back(crow);
	}
		
	vector <vector <int>> perms_row;
	vector <int> arr_row(h);
	
	vector <vector <int>> perms_col;
	vector <int> arr_col(w);
	
	int counts = 0;
	
	GABS(h, perms_row, arr_row, 0);
	GABS(w, perms_col, arr_col, 0);
	
	for(int i = 0 ; i < (int) perms_row.size(); i++)
	{
		vector <int> cr = perms_row[i];
		for(int j = 0 ; j < (int) perms_col.size(); j++)
		{
			vector <int> cc = perms_col[j];
			int black_counts = 0;
			for(int k = 0 ; k < h; k++)
			{
				if(cr[k] == 1)
				{
					continue;
				}
				else
				{
					for(int l = 0 ; l < w; l++)
					{
						if(cc[l] != 1)
						{
							if(grid[k][l] == '#')
							{
								black_counts += 1;
							}
						}
					}
				}
			}
			if(black_counts == k)
			{
				counts += 1;
			}
		}
	}
	
	cout<<counts;
	
	return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
// typedef
using ll  = long long;
using str = string;
using PL  = pair<ll, ll>;
using P   = pair<int, int>;
using VL  = vector<ll>;
using VI  = vector<int>;
using VS  = vector<str>;
using VP  = vector<P>;
using VPL = vector<PL>;
using VVL = vector<VL>;
using VVI = vector<VI>;

// const num
const ll INF         = 1e18 + 18;
const ll MAX         = 100005;
const ll MOD         = 1000000007;
const long double PI = acosl(-1.0);

// loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(ll(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)

// YesNo
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
// All
#define ALL(v) v.begin(), v.end()
#define deduplicate(v) (v).erase(unique(ALL(d)), (v).end())

int main(void) {
	int n;
	cin >> n;
	VL a(n);
	VL sum(n + 1, 0);
	ll ans = 0;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		sum[i + 1] = sum[i] + a[i];
	}
	rep(i, n) {
		ll intvsum = (sum[n] - sum[i + 1]) % MOD;
		ans += a[i] * intvsum;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6408
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
const int INF=(1<<29);
int main()
{
   long long w,a,b;
   cin >>w>>a>>b;
   
       if((b>=a&&b<=a+w)||(b+w>=a&&b+w<=a+w))
        printf("0\n");
       else
       if(a+w<b)
        printf("%d\n",b-(a+w));
       else
        printf("%d\n",a-(b+w));
   
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<string> vs;
  FOR(i,0,n) {
    string s;
    cin >> s;
    vs.push_back(s);
  }
  string ans = "";
  for (char c = 'a'; c <= 'z'; c++) {
    int len = 100;
    FOR (i,0,n) {
      int cnt = 0;
      FOR (j,0,vs[i].size()) {
        if(vs[i][j] == c) cnt++;
      }
      len = min(len, cnt);
    }
    FOR (i,0,len) {
      ans.push_back(c);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){
    int n, k;
    cin >> n >> k;
    int p[n];
    
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }
    
    qsort(p, n, sizeof(int), compare_int);
    
    int sum = 0;
    
    for (int i = 0; i < k; i++){
        sum += p[i];
    }
    
    cout << sum << endl;
    
    return 0;
}


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

using namespace std;

int main()
{
    int n, r[200000];
    cin >> n;

    for (int i = 0; i < n; i++) cin >> r[i];

    int maxv = -1000000010;
    int minv = r[0];

    for (int i = 1; i < n; i++) {
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }

    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 3860
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  int c = sc.nextInt();
  int d = sc.nextInt();
  int x = c-a;
  int y = d-b;
  int e = c-y;
  int f = d+x;
  int g = e-x;
  int h = f-y;
  System.out.println(e+" "+f+" "+g+" "+h);
}}
  

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

long long nCk(long long n, long long k) {
  long long ret = 1;
  if (k > n-k) k = n-k;
  for (int i = n-k+1; i <= n; ++i) {
    ret *= i;
  }
  for (int i = 2; i <= k; ++i) {
    ret /= i;
  }
  return ret;
}

void solve() {
  int n, p; scanf("%d%d", &n, &p);
  int o = 0;
  for (int i = 0; i < n; ++i) {
    int a; scanf("%d", &a);
    o += a%2;
  }
  long long ansodd = 0;
  for (int i = p; i <= o; i+=2) {
    ansodd += nCk(o, i);
  }
  printf("%lld", ansodd << (n-o));

}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    ll n;
    cin>>n;
    vector<ll> v(n);
    map<ll,ll> mapi;
    ll csum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
        mapi[v[i]]++;
        csum += v[i];
    }
    ll query;
    cin>>query;
    while(query--)
    {
        ll b,c;
        cin>>b>>c;
        if(mapi.find(b)==mapi.end())
        {
            cout<<csum<<endl;
            continue;
        }

        ll d = mapi[b];
        csum -= (d*b);
        csum += (d*c);
        mapi.erase(b);
        if(mapi.find(c)==mapi.end()) mapi[c] = d;
        else mapi[c] += d;
        cout<<csum<<endl;
    }
}

Measured memory_bytes: 7852
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int w=gi();
	    int a=gi();
	    int b=gi();
	   

        //System.out.println(f(n));
        if (a<b) {
        	System.out.print(Math.max(b-a-w, 0));
        }else {
        	System.out.print(Math.max(a-b-w, 0));
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
	
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35548
#include<bits/stdc++.h>
using namespace std;
#define ll long long
class activity
{
public:
	ll int A;
	ll int B;
	ll int C;
};

string get_index(int a, int b)
{
	return to_string(a) + "" + to_string(b);
}

ll int solve(ll int i, ll int n, vector<activity>&v, ll int prev, map<string, ll int>&m)
{
	if (i == n)
	{
		return 0;
	}
	string indx = get_index(i, prev);
	if (m.find(indx) != m.end())
	{
		return m[indx];
	}

	if (prev == 0)
	{
		//agar B chuno
		ll int B_ans = v[i].B + solve(i + 1, n, v, 1 , m);
		//agar C chuno
		ll int C_ans =  v[i].C + solve(i + 1, n, v, 2, m);
		ll int ans = max(B_ans, C_ans);
		return m[indx] = ans;
	}
	else if (prev == 1)
	{
		//agar A chuno
		ll int A_ans = v[i].A + solve(i + 1, n, v, 0, m);

		//agar C chuno
		ll int C_ans = v[i].C + solve(i + 1, n, v, 2, m );
		ll int ans = max(A_ans, C_ans);
		return m[indx] = ans;
	}
	else //agar pichla C ho to
	{
		//agar A chuno
		ll int A_ans = v[i].A + solve(i + 1, n, v, 0, m );
		ll int B_ans = v[i].B + solve(i + 1, n, v, 1, m);
		ll int ans = max(A_ans, B_ans);
		return m[indx] = ans;
	}
}


int main()
{
	ll int n;
	cin >> n;
	vector<activity>v(n);
	for (ll int i = 0; i < n; i++)
	{
		ll int a, b, c;
		cin >> a >> b >> c;
		v[i].A = a;
		v[i].B = b;
		v[i].C = c;
	}
	map<string, ll int>m;

	ll int A_ans = solve(0, n, v, 0, m);
	ll int B_ans = solve(0, n, v, 1, m);
	ll int C_ans = solve(0, n, v, 2, m);
	ll int ans = max(A_ans, max(B_ans, C_ans));
	cout << ans << endl;
	// for (auto i : m)
	// {
	// 	cout << i.first << "  " << i.second << endl;
	// }
	return 0;
}

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



class SCC_BI {
public:
    int NV = 0, time;
    vector<vector<int> > E;
    vector<int> ord, llink, inin;
    stack<int> roots, S;
    vector<int> M; //point to group
    vector<int> ART; // out
    vector<vector<int> > SC; // out
    vector<pair<int, int> > BR; // out

    void init(int NV) { this->NV = NV; E.clear(); E.resize(NV); }
    void add_edge(int x, int y) { assert(NV); E[x].push_back(y); E[y].push_back(x); }
    void dfs(int cur, int pre) {
        int art = 0, conn = 0, i, se = 0;
        ord[cur] = llink[cur] = ++time;
        S.push(cur); inin[cur] = 1; roots.push(cur);
        rep(i, 0, E[cur].size()) {
            int tar = E[cur][i];
            if (ord[tar] == 0) {
                conn++; dfs(tar, cur);
                llink[cur] = min(llink[cur], llink[tar]);
                art += (pre != -1 && ord[cur] <= llink[tar]);
                if (ord[cur]<llink[tar]) BR.push_back(make_pair(min(cur, tar), max(cur, tar)));
            }
            else if (tar != pre || se) {
                llink[cur] = min(llink[cur], ord[tar]);
                while (inin[tar] && ord[roots.top()]>ord[tar]) roots.pop();
            }
            else se++; // double edge
        }

        if (cur == roots.top()) {
            SC.push_back(vector<int>());
            while (1) {
                i = S.top(); S.pop(); inin[i] = 0;
                SC.back().push_back(i);
                M[i] = SC.size() - 1;
                if (i == cur) break;
            }
            sort(SC.back().begin(), SC.back().end());
            roots.pop();
        }
        if (art || (pre == -1 && conn>1)) ART.push_back(cur);
    }
    void scc() {
        SC.clear(), BR.clear(), ART.clear(), M.resize(NV);
        ord.clear(), llink.clear(), inin.clear(), time = 0;
        ord.resize(NV); llink.resize(NV); inin.resize(NV);
        for (int i = 0; i<NV; i++) if (!ord[i]) dfs(i, -1);
        sort(BR.begin(), BR.end()); sort(ART.begin(), ART.end());
    }
};
//-----------------------------------------------------------------------------------
int VV, EE;
SCC_BI g;
//-----------------------------------------------------------------------------------
int main() {
    cin >> VV >> EE;
    
    g.init(VV);
    rep(i, 0, EE) {
        int a, b; scanf("%d %d", &a, &b);
        g.add_edge(a, b);
    }
    g.scc();

    for (int a : g.ART) printf("%d\n", a);
}

Measured memory_bytes: 5492
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;


int bitSearch(vector<vector<int>> s, vector<int> p, int N, int M)
{
    int ans = 0;
    for(int bit=0; bit<(1<<N); ++bit)
    {
        //bitset<N> s(bit);
        bool isCnt = true;
        for (int m=0; m<M; ++m)
        {
            int cnt = 0;
            for(int i=0; i<(int)s[m].size(); ++i)
            {
                if(bit & (1<<(s[m][i]-1))) ++cnt;
            }
            if(p[m]!=(cnt%2)) isCnt = false;
        }
        if(isCnt) ++ans;
    }
                   
    return ans;
}

int main()
{
    int N,M;
    cin >> N >> M;
    vector<vector<int> > s(M,vector<int>());
    for (int i=0; i<M; ++i)
    {
        //string str;
        int tmp;
        cin >> tmp;
        for (int k=0; k<tmp; ++k)
        {
            int tmp2;
            cin >> tmp2;
            s[i].push_back(tmp2);
        }
    }
    vector<int> p;
    for (int i=0; i<M; ++i)
    {
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    
    int ans = bitSearch(s,p,N,M);
    cout << ans << endl;
    //std::cout << "Hello, Wandbox!" << std::endl;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int i,m,f,r;
	for(i=0;i<50;i++){
		cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		if(m==-1||f==-1){
			cout<<"F"<<endl;
		}
		else if(r>=50){
			cout<<"C"<<endl;
		}
		else if(m+f>=80){
			cout<<"A"<<endl;
		}
		else if(m+f>=65&&m+f<80){
			cout<<"B"<<endl;
		}
		else if(m+f>=50&&m+f<65){
			cout<<"C"<<endl;
		}
		else if(m+f<30){
			cout<<"F"<<endl;
		}
		else if(m+f>=30&&m+f<50){
			cout<<"D"<<endl;
		}
	}
	return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	string pre,suf;
	cin >> pre >> suf;
	for(int i = 0; i < n; i++){
		string sp,ss;
		for(int j = i; j < n; j++){
			sp += pre[j];
		}
		for(int j = 0; j < n-i; j++){
			ss += suf[j];
		}
		if( sp == ss){
			cout << n + i << endl;
			return 0;
		}
	}
	cout << 2 * n << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
Dict = {}
flag = 0 

first_f = input()
Dict[first_f]=1
last_f = first_f[-1]

for _ in range(N-1):
  f = input()
  if f[0]!=last_f:
    flag=1
    break
  else:
    if f in Dict:
      Dict[f]+=1
    else:
      Dict[f]=1
  last_f = f[-1]
      
l = [i for i in list(Dict.values()) if i>=2]
if len(l)>=1:
  flag=1
if flag==1:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}
void primeFactors(int n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        cout << 2 << " ";  
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            cout << i << " ";  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        cout << n << " ";  
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
  // string s;
    long long int n1,m1,t;
 //   cin>>t;
   t=1;
    while(t--)
    {
   long long int i,j;
 //long long int b[1000000];
 //set<long long int >s;
       long long int f=1,p=0,z,o=0;
       double pie=3.141592653589793238;
    long long int c=0,n,m,l=0,r=0,k,min1=10000000000000,max2=-100;
 cin>>n;
 
 /*long long int a[n];
 for(i=0;i<n;i++)
 cin>>a[i];
 */
      string s;
 long long int a[4]={0};
 while(n--)
 {
     cin>>s;
     if(s=="AC")
     a[0]++;
     else if(s=="WA")
     a[1]++;
     else if(s=="TLE")
     a[2]++;

else if(s=="RE")
a[3]++;
     
 }
 cout<<"AC"<<" "<<"x"<<" "<<a[0]<<"\n";
 cout<<"WA"<<" "<<"x"<<" "<<a[1]<<"\n";
 cout<<"TLE"<<" "<<"x"<<" "<<a[2]<<"\n";
 cout<<"RE"<<" "<<"x"<<" "<<a[3]<<"\n";
 
 }
 return 0;
}


Measured memory_bytes: 3720
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ope = [list(map(int, input().split())) for _ in range(m)]
ope = sorted(ope, key=lambda x: x[1], reverse=True)
j = 0
for i in range(n):
    if a[i] < ope[j][1]:
        a[i] = ope[j][1]
        ope[j][0] -= 1
        if ope[j][0] == 0:
            j += 1
            if j == len(ope):
                break
    else:
        break
print(sum(a))


Measured memory_bytes: 82200
import java.util.Scanner;
 
public class Main{
    public static void main(String[] ss){
        int h,w,i,j;
        Scanner s = new Scanner(System.in);
        while(true){
        h = s.nextInt();
        w = s.nextInt();
        if(h*w==0)break;
        for(i=1;i<=h;i++){
            for(j=1;j<=w;j++){
                if((i+j)%2==0)System.out.print("#");
                else System.out.print(".");
            }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 37632
#include<bits/stdc++.h>
using namespace std;
int main(){
	int long long s=100000,l;
	int n;
	cin>>n;
	for(int p=0;p<n;p++){
		s=s+s/20;
		l=(s/1000)*1000;
		if(s>l){
			s+=1000;
			s=(s/1000)*1000;
		}
	}
	printf("%lld\n",s);
}


Measured memory_bytes: 3160
#include "bits/stdc++.h"
using namespace std;

// #include "debug.h"
#define debug(...) 42

void solve() {

   int n, k;
   cin >> n >> k;
   vector <int> v(n);
   for(int i = 0; i < n; i++) {
      cin >> v[i];
   }

   for(int i = k; i < n; i++) {
      if(v[i] > v[i - k]) {
         cout << "Yes" << endl;
      } else {
         cout << "No" << endl;
      }
   }

} 

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   }
   return 0;
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll n;
  cin >> n;
  ll res = 0;
  ll prime[n+1]={};
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j+=i){
      prime[j]+=1;
    }
  }
  for(ll i=1;i<=n;i++){
    res += prime[i]*i;
  }
  cout << res << endl;
      
  return 0;
}


Measured memory_bytes: 81744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <list>
#include <map>
#include <memory>
#include <queue>
using namespace std;

int main()
{
	int a,b,t;
	cin >> a>>b>>t;
	cout << (t / a) * b;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

typedef pair <pii, int> ppi;
int main()
{
	boost;
	int t, n, i;
	cin >> t;
	while(t--)
	{
		cin >> n;
		vector <ppi> v(n);
		fo(i, 0, n)
		cin >> v[i].s >> v[i].f.f >> v[i].f.s;
		
		vector <ppi> pos, neg;
		ll ans = 0;
		fo(i, 0, n) {
			if(v[i].f.f == v[i].f.s)
			ans += v[i].f.f;
			else if(v[i].f.f > v[i].f.s)
			pos.pb(v[i]);
			else
			neg.pb(v[i]); 
		}
		
		sort(all(pos), [&](const ppi &p1, const ppi &p2){if(p1.f.f-p1.f.s == p2.f.f-p2.f.s) return p1.s < p2.s; return p1.f.f-p1.f.s > p2.f.f-p2.f.s;});
		
		set <int> s;
		foe(i, 1, n)
		s.insert(i);
		
		int cnt = 0;
		for(ppi p : pos) {
			auto it = s.upper_bound(p.s);
			if(it == s.begin()) {
				neg.pb(p);
			}
			else {
				--it;
				ans += p.f.f;
				++cnt;
				s.erase(it);
			}
		}
		s.clear();
		foe(i, cnt + 1, n)
		s.insert(i);
		sort(all(neg), [&](const ppi &p1, ppi &p2){if(p1.f.s-p1.f.f == p2.f.s-p2.f.f) return p1.s > p2.s; return p1.f.s-p1.f.f > p2.f.s-p2.f.f;});
		
		for(ppi p : neg) {
			auto it = s.upper_bound(p.s);
			if(it == s.end()) {
				s.erase(s.begin());
				ans += p.f.f;
			}
			else {
				s.erase(it);
				ans += p.f.s;
			}
		}
		cout << ans << '\n';
	}
}


Measured memory_bytes: 17488
#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define l long 
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;
 int main()
 {
    
    l n,k;
     cin>>n>>k;
     vector<l>v(n);
      for(l i=0; i<n; i++)
      {
          cin>>v[i];
      }
      l dp[n];
       dp[0]=0;
       dp[1]=dp[0]+abs(v[1]-v[0]);
        for(l i=2; i<n; i++)
        {
             l mini=inf;
              for(int j=1; j<=k; j++)
              {
                   if(i-j<0)
                    break;
                  
                  mini=min((dp[i-j]+abs(v[i]-v[i-j])),mini);
              }
              dp[i]=mini;
        }
        
        cout<<dp[n-1];
       return 0;
     
 }
  

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

int main() {
  int A, B;
  cin >> A >> B;
  int r = 0;
  
  for (int i = A;i <= B;i++) {
    int s = i % 10;
    int t = i / 10000;
    int u = i / 10 % 10;
    int v = i / 1000 % 10;
    if (s == t && u == v)
      r++;
  }
  cout << r << endl;
}

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

using lli = long long int;

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

constexpr int INF = 1e9 + 1;

std::vector<int> A;


int main(void){
    int H, W, h, w; scanf("%d%d%d%d", &H, &W, &h, &w);
    if(H % h == 0 and W % w == 0) puts("No");
    else{
        puts("Yes");
        int V = 1001;
        int R = - V * (h * w - 1) - 1;
        REP(i, H){
            REP(j, W){
                printf("%d", ((i+1)%h==0 and (j+1)%w==0) ? R : V);
                putchar((j == W - 1) ? '\n' : ' ');
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1536