akhauriyash/Code-Regression huggingface dataset:
def main():
    H, W = (int(i) for i in input().split())
    N = int(input())
    A = [int(i) for i in input().split()]
    c = [[0]*W for _ in range(H)]
    i = 0
    color = 1

    for h in range(H):
        if h % 2 == 0:
            range_W = range(W)
        else:
            range_W = range(W)[::-1]
        for w in range_W:
            c[h][w] += color
            A[i] -= 1
            if A[i] == 0:
                i += 1
                color += 1

    for i in range(H):
        print(*c[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3920
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "

ll eval(const l4 &a)
{
  return abs(a.first - a.second);
}
bool operator<(const l4 &l ,const l4 &r)
{
  return eval(l) < eval(r);
}
vector<l4> solve(vector<ll> v)
{
  assert(v.size() >= 4);
  vector<l4> ret(v.size());
  for (ll i = 1, j = 0, sumi = v[0], sumj = v[0]; i + 2 < v.size(); ++i)
    {
      sumi += v[i];
      while (j < i && sumj * 2 <= sumi) ++j, sumj += v[j];
      sumj -= v[j], --j;
      l4 ans = mp(sumj, sumi-sumj);
      if (j+1 != i)
        {
          l4 nxt = mp(sumj+v[j+1], sumi-sumj-v[j+1]);
          if (nxt < ans) ans = nxt;
        }
      ret[i] = ans;
    }
  for (auto & e : ret) if (e.first > e.second) swap(e.first, e.second);
  return ret;
}
int main()
{
  int n; scanf("%d", &n);
  vector<ll> v(n);
  for (auto & e : v) scanf("%lld", &e);
  auto left = solve(v);
  reverse(v.begin(), v.end());
  auto right = solve(v);
  reverse(right.begin(), right.end());
  ll ans = -1;
  for (int i = 1; i + 2 < v.size(); ++i)
    {
      ll tmp = max(left[i].second, right[i+1].second) - min(left[i].first, right[i+1].first);
      if (ans == -1 || ans > tmp)
        ans = tmp;
    }
  printf("%lld\n", ans);
}


Measured memory_bytes: 9572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = 0;
		int A = 0;
		// ゼロでいい？
		try {
			N = sc.nextInt();
			A = sc.nextInt();
		} catch (Exception e) {
			System.out.println("整数のみ入力してください");
			// ログに出力？
			// エラースタックトレースは？いる？
			// e.printStackTrace();
		}
		// 入力チェックは？
		// 数字？少数？文字？マイナス？
		// 一つだけ入力されたときは？
		// ⇒外部仕様上大丈夫

		int i = N % 500;
		// 500 が変わる可能性は？1000円に変わる可能性は？B？
		if (i <= A) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22228
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;

int main(){
    int N;
    cin >> N;
    int H[200000];
    int ans = 0;
    int counter = 0;
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    for(int i = 0; i < N - 1; i++){
        if(H[i] >= H[i + 1]){
            counter++;
        }
        else{
            ans = max(ans, counter);
            counter = 0;
        }
    }
    ans = max(ans, counter);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int A, B, C;

int main() {
    cin >> A >> B >> C;
    cout << min(C, B / A) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("test.inp","r",stdin);
    int n, dem=0;
    string a,b,c;
    cin>>n>>a>>b>>c;
    static int res[25];
    for (int i=0;i<n;i++)
    {
         res[a[i]-97]=0;
         res[b[i]-97]=0;
         res[c[i]-97]=0;
         res[a[i]-97]++;
         res[b[i]-97]++;
         res[c[i]-97]++;
         dem+=3-max(res[a[i]-97],max(res[b[i]-97],res[c[i]-97]));
    }
    cout<<dem;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;



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

    ll n, k; cin >> n >> k;
    ll ans = 0;
    ans = min(n%k, (n%k - k)*(-1));
  
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

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

	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int t1 = 60 * h1 + m1,
		t2 = 60 * h2 + m2;
	cout << max(0, t2 - t1 - k) << '\n';
}


Measured memory_bytes: 3648
/** Programming problem solution 5.
 *  Copyright (c) 2020 Peter Winchester. All rights reserved.
 *  
 *  This program is written by Peter Winchester.
 *  Peter use this program to solve a programming problem.
 *  If you are not allowed to copy the code, don't copy the
 *  following code.
 */

// code:
#include <iostream>

using namespace std;

int n;
int a[200001];
long long ans;

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 2; i <= n; i++)
	{
		if (a[i] < a[i - 1])
		{
			ans += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if ( A == B ) {
  cout << C << endl;
  }
  else if ( A == C ) {
    cout << B << endl;
  }
  else {
    cout << A <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define pb push_back
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define DEBUG false
#pragma GCC optimize "trapv"
 
void solve(string s1,string s2,int l1,int l2)
{
    int lcs[l1+1][l2+1];
    for(int i=0;i<=l1;i++)
    {
        for(int j=0;j<=l2;j++)
        {
            if(i==0 || j==0)
            lcs[i][j]=0;
            else if(s1[i-1]==s2[j-1])
            lcs[i][j]=lcs[i-1][j-1]+1;
            else
            lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
        }
    }
    int ind=lcs[l1][l2];
   // cout<<ind<<endl;
    string s="";
    int i=l1,j=l2;
    while(i>0 && j>0)
    {
        if(s1[i-1]==s2[j-1])
        {
            s+=s1[i-1];
            i--;j--;ind--;
        }
        else if(lcs[i-1][j]>lcs[i][j-1])
        i--;
        else
        j--;
    }
  //  cout<<s<<endl;
    reverse(s.begin(),s.end());
    cout<<s<<'\n';
}
 
int32_t main()
{
    nitro;
    string s1,s2;
    cin>>s1>>s2;
    solve(s1,s2,s1.size(),s2.size());
return 0;
}

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

int main(){
	
	int n,t;
	cin >> n >> t;
	vector<int> a(n), b(n);
	rep(i,n) cin >> a[i] >> b[i];
	
	vector<vector<int>> L(n, vector<int>(t));
	vector<vector<int>> R(n, vector<int>(t));
	
	
	// make L
	for(int i = a[0]; i < t; i++) L[0][i] = b[0];
	rep(i,n-1){
		rep(j,t){
			if(j-a[i+1]>=0){
				L[i+1][j] = max(L[i][j-a[i+1]]+b[i+1], L[i][j]);
			}
			else{
				L[i+1][j] = L[i][j];
			}
		}
	}
	
	// make R
	for(int i = a[n-1]; i < t; i++) R[n-1][i] = b[n-1];
	for(int i = n-1; i >= 1; i--){
		rep(j,t){
			if(j-a[i-1]>=0){
				R[i-1][j] = max(R[i][j-a[i-1]]+b[i-1], R[i][j]);
			}
			else{
				R[i-1][j] = R[i][j];
			}
		}
	}
	
	int res = 0;
	rep(i,n){
		if(i==0) res = max(res, b[i] + R[i+1][t-1]);
		else if(i==n-1) res = max(res, b[i] + L[i-1][t-1]);
		else{
			rep(j,t) res = max(res, b[i] + L[i-1][j] + R[i+1][t-1-j]);
		}
	}
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 70784
import java.util.Scanner;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt(),W=sc.nextInt(),i,w[] = new int[N],v[]=new int[N];
		for(i=0;i<N;i++) {
			w[i]=sc.nextInt();
			v[i]=sc.nextInt();
		}
		long[][] dp=new long[N+1][W+1];
		for(i=0;i<=W;i++) dp[0][i]=0;
		for(int wei=1;wei<=W;wei++) {
			for(i=0;i<N;i++) {
				if(wei>=w[i]) {
					dp[i+1][wei]=Math.max(dp[i][wei-w[i]]+v[i], dp[i][wei]);
				}else {
					dp[i+1][wei]=dp[i][wei];
				}
			}
		}
		System.out.println(dp[N][W]);
	}
}

Measured memory_bytes: 140408
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cstdio>

#define rg register
#define il inline
#define MX (200000 + 233)
#define LL long long

int head[MX] ,tot;
struct edge{
	int node ,next;
}h[MX << 1];
void addedge(int u ,int v ,int flg = true){
	h[++tot] = (edge){v ,head[u]} ,head[u] = tot;
	if(flg) addedge(v ,u ,false);
}

struct node{
	int l ,r;
	LL sum ,add;
	node *lch ,*rch;
}*root;
void pushup(node *x){
	x->sum = 0;
	if(x->lch != nullptr) x->sum += x->lch->sum;
	if(x->rch != nullptr) x->sum += x->rch->sum;
}

void doadd(node *x ,LL v){
	x->sum += (x->r - x->l + 1) * v;
	x->add += v;
}
void pushdown(node *x){
	if(x->add){
		doadd(x->lch ,x->add);
		doadd(x->rch ,x->add);
		x->add = 0;
	}
}

node *newnode(int l ,int r){
	node *x = new node;
	x->l = l ,x->r = r ,x->sum = x->add = 0;
	return x;
}

void spread(node *x){
	int mid = (x->l + x->r) >> 1;
	if(x->lch == nullptr){
		x->lch = newnode(x->l ,mid);
		x->rch = newnode(mid + 1 ,x->r);
	}
}

int query(node *x ,int p){
	if(x->l == x->r) return x->sum;
	spread(x) ,pushdown(x);
	int mid = (x->l + x->r) >> 1;
	if(p <= mid) return query(x->lch ,p);
	return query(x->rch ,p);
}

void cov(node *x ,int p ,int v){
	if(x->l == x->r){x->sum = v; return;}
	spread(x) ,pushdown(x);
	int mid = (x->l + x->r) >> 1;
	if(p <= mid) cov(x->lch ,p ,v);
	else cov(x->rch ,p ,v);
	return pushup(x);
}

node *merge(node *x ,node *y){
	if(x == nullptr)	return y;
	if(y == nullptr)	return x;
	if(x->l == x->r){
		return x->sum += y->sum ,x;
	}
	x->add += y->add;
	x->lch = merge(x->lch ,y->lch);
	x->rch = merge(x->rch ,y->rch);
	return pushup(x) ,x;
}

int n;
LL cnt(LL a){
	return a * (a - 1) / 2 + a;
}
int c[MX]; LL Ans[MX];
node *solve(int x ,int f){
	node *now = newnode(1 ,n);
	for(int i = head[x] ,d ; i ; i = h[i].next){
		if((d = h[i].node) == f) continue;
		merge(now ,solve(d ,x));
		LL qwq = query(now ,c[x]);
		Ans[c[x]] -= cnt(qwq);
		cov(now ,c[x] ,0);
	}
	now->add += 1;
	cov(now ,c[x] ,0);
	return now;
}

int main(){
	scanf("%d" ,&n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" ,c + i);
		Ans[i] = cnt(n);
	}
	for(int i = 1 ,u ,v ; i < n ; ++i){
		scanf("%d%d" ,&u ,&v);
		addedge(u ,v);
	}
	root = solve(1 ,0);
	for(int i = 1 ; i <= n ; ++i){
		Ans[i] -= cnt(query(root ,i));
		printf("%lld\n" ,Ans[i]);
	}
	return 0;
}

Measured memory_bytes: 375488
//26
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(;;){
    int n[8];
    for(int i=0;i<8;i++){
      if(!(cin>>n[i]))return 0;
    }
    int hit=0;
    for(int i=0;i<4;i++){
      hit+=n[i]==n[i+4];
    }
    int blow=-hit;
    for(int i=0;i<4;i++){
      blow+=find(n+4,n+8,n[i])!=n+8;
    }
    cout<<hit<<' '<<blow<<endl;
  }
}

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

typedef long long ll;





int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> arr(n);
    int ans = 0;
    for(int i = 0; i < n; i++)cin >> arr[i];
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            for(int k = j + 1; k < n; k++){
                if(arr[i] + arr[j] > arr[k] && arr[j] + arr[k] > arr[i] && arr[k] + arr[i] > arr[j] && arr[i] != arr[j] && arr[j] != arr[k] && arr[k] != arr[i])ans++;
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3648
input1 = input().split()

a = input1[0]
b = input1[1]
a = int(a)
b = int(b)

total = 0

for c in range(2, 0, -1):
    if a >= b:
        total += a
        a -= 1
    else:
        total += b
        b -= 1

print(total)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, a[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> a[i];

	int tot = 0;
	rep(i, 0, N) tot ^= a[i];
	
	rep(i, 0, N) {
		if(i) printf(" ");
		printf("%d", tot ^ a[i]);
	}
	printf("\n");
}







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


int main(void){
    int n;
    cin>>n;
    string ox;
    cin>>ox;
    ox+=ox;
    vector <int> ss(n+2);
    ss[0]= 1;ss[1]= 1;
    
    for(int j=0;j<4;j++){
        for(int i=2;i<=n+1;i++){
            if(ss[i-1]==1){
                if(ox[i-1]=='o'){
                    ss[i]=ss[i-2];
                }else{
                    ss[i]=ss[i-2]*(-1);
                }
            }else{
                if(ox[i-1]=='o'){
                    ss[i]=ss[i-2]*(-1);
                }else{
                    ss[i]=ss[i-2];
                }
            }
        }
    
        if(ss[0]==ss[n] and ss[1]==ss[n+1])
        {
            for(int i=0;i<n;i++){
                if(ss[i]==1) cout<<'S';
                else cout<<'W';
            }
            cout<<endl;
            return 0;
        }
        
        if(j%2==0) ss[0]*=(-1);
        else ss[1]*=(-1);
    
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 1052
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int l=0;l<n;l++){
		int num[2][9],a[2][9],geitu,jacky;
		double winrate1=0,winrate2=0;
		for(int j=0;j<2;j++){
			for(int k=0;k<9;k++)cin>>a[j][k];
		}
		for(int z=0;z<9;z++){
			num[0][0]=0;
			num[1][0]=0;
			if(a[0][0]>a[1][z])num[0][0]=(a[0][0]+a[1][z]);
			else num[1][0]=(a[0][0]+a[1][z]);
			for(int b=0;b<9;b++){
				if(b==z)continue;
				num[0][1]=0;
				num[1][1]=0;
				if(a[0][1]>a[1][b])num[0][1]=(a[0][1]+a[1][b]);
				else num[1][1]=(a[0][1]+a[1][b]);
				for(int c=0;c<9;c++){
					if(c==z||c==b)continue;
					num[0][2]=0;
					num[1][2]=0;
					if(a[0][2]>a[1][c])num[0][2]=(a[0][2]+a[1][c]);
					else num[1][2]=(a[0][2]+a[1][c]);
					for(int d=0;d<9;d++){
						if(d==z||d==b||d==c)continue;
						num[0][3]=0;
						num[1][3]=0;
						if(a[0][3]>a[1][d])num[0][3]=(a[0][3]+a[1][d]);
						else num[1][3]=(a[0][3]+a[1][d]);
						for(int e=0;e<9;e++){
							if(e==z||e==b||e==c||e==d)continue;
							num[0][4]=0;
							num[1][4]=0;
							if(a[0][4]>a[1][e])num[0][4]=(a[0][4]+a[1][e]);
							else num[1][4]=(a[0][4]+a[1][e]);
							for(int f=0;f<9;f++){
								if(f==z||f==b||f==c||f==d||f==e)continue;
								num[0][5]=0;
								num[1][5]=0;
								if(a[0][5]>a[1][f])num[0][5]=(a[0][5]+a[1][f]);
								else num[1][5]=(a[0][5]+a[1][f]);
								for(int g=0;g<9;g++){
									if(g==z||g==b||g==c||g==d||g==e||g==f)continue;
									num[0][6]=0;
									num[1][6]=0;
									if(a[0][6]>a[1][g])num[0][6]=(a[0][6]+a[1][g]);
									else num[1][6]=(a[0][6]+a[1][g]);
									for(int h=0;h<9;h++){
										if(h==z||h==b||h==c||h==d||h==e||h==f||h==g)continue;
										num[0][7]=0;
										num[1][7]=0;
										if(a[0][7]>a[1][h])num[0][7]=(a[0][7]+a[1][h]);
										else num[1][7]=(a[0][7]+a[1][h]);
										for(int i=0;i<9;i++){
											if(i==z||i==b||i==c||i==d||i==e||i==f||i==g||i==h)continue;
											num[0][8]=0;
											num[1][8]=0;
											if(a[0][8]>a[1][i])num[0][8]=(a[0][8]+a[1][i]);
											else num[1][8]=(a[0][8]+a[1][i]);
											geitu=0;
											jacky=0;
											for(int m=0;m<9;m++){
												geitu+=num[0][m];
												jacky+=num[1][m];
											}
											if(geitu>jacky)winrate1++;
											else if(geitu<jacky)winrate2++;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		double ans,ans2;
		ans=winrate1/362880;
		ans*=100000;
		ans+=0.5;
		ans=int(ans);
		ans/=100000;
		ans2=winrate2/362880;
		ans2*=100000;
		ans2+=0.5;
		ans2=int(ans2);
		ans2/=100000;
		cout<<ans<<" "<<ans2<<"\n";
	}
	return 0;
}

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int a,b,c;cin>>a>>b>>c;
  if(a==b&&b!=c){
    puts("Yes");
  }else if(a==c&&b!=c){
    puts("Yes");
  } else if(b==c&&b!=a){
    puts("Yes");
  }else{
    puts("No");
  }

  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
#define ii pair<int, int>
#define fi first
#define se second
const int MAX = 200000; //2 * 10^5
const int MOD = 1000000007; //10^9 + 7
const int OO = 0x3f3f3f3f; // 0x3f3f3f3f;

int32_t main()
{
	string s;
	cin >> s;
	cout << (count(s.begin(), s.end(), '7') ? "Yes" : "No") << endl;



	return 0;
}

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

const int N = 100010;

int main()
{
   string s, t;
   cin >> s >> t;
   int ans=0;
   for(int i=0; i<s.size(); i++){
      if(s[i] != t[i]){
         ans++;
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a,b;
  cin >> a >> b;
  if (a == 'H' && b == 'H' || a == 'D' && b == 'D') {
    cout << 'H';
  } else {
    cout << 'D';
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
   int n,x,i;
   cin >> n;
   for(i=1;i<=n;i++)
    {   
        cin >> x;
        if(x%2==0)
        {
            if(!(x%3==0 || x%5==0))
            {
                cout <<"DENIED";
                return 0;
            }
        }
    }
    cout <<"APPROVED";
   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
	int a, i, c = 0;
	char s[150];

	scanf("%s", s);
	a = strlen(s);

	for (i = 0; i < a / 2; i++)
		c += (s[i] != s[a- 1 - i]);

		printf("%d", c);

		return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int n, m, a[1123456], b[1123465];

bool c[710][710];

V g[710];

int color[710];

vector<P> p;

bool check;

void dfs(int s, int t)
{
    if (color[s] != -1)
    {
        if (color[s] != t)
            check = false;
        return;
    }

    color[s] = t;

    if (t == 0)
        p[p.size() - 1].first++;
    else
        p[p.size() - 1].second++;

    for (int i : g[s])
        dfs(i, 1 - t);

    return;
}

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

    cin >> n >> m;

    REP(i, n)
    REP(j, n)
    c[i + 1][j + 1] = i + 1 == j + 1;

    REP(i, m)
    {
        cin >> a[i] >> b[i];

        c[a[i]][b[i]] = true;
        c[b[i]][a[i]] = true;
    }

    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            if (!c[i][j])
            {
                g[i].push_back(j);
                g[j].push_back(i);
            }
        }
    }

    memset(color, -1, sizeof(color));

    check = true;

    while (true)
    {
        bool ch = false;
        for (int i = 1; i <= n; i++)
        {
            if (color[i] == -1)
            {
                p.push_back({0, 0});
                dfs(i, 0);
                ch = true;
            }
        }

        if (!ch)
            break;
    }

    if (!check)
    {
        cout << -1 << endl;
        return 0;
    }

    bool dp[2][1000];

    auto *cur = dp[0];
    auto *nex = dp[1];

    fill(cur, cur + n + 1, false);
    fill(nex, nex + n + 1, false);

    cur[0] = true;

    V num;

    REP(j, p.size())
    {
        for (int i = 0; i < 1000; i++)
        {
            if (!cur[i])
                continue;

            if (i + p[j].first < 1000)
                nex[i + p[j].first] = true;

            if (i + p[j].second < 1000)
                nex[i + p[j].second] = true;
        }

        swap(cur, nex);
        fill(nex, nex + n + 1, false);
    }

    int res = INT_MAX;

    for (int i = 0; i <= n; i++)
    {
        if (!cur[i])
            continue;

        int tmp = (i * (i - 1) / 2) + ((n - i) * (n - i - 1) / 2);
        res = min(res, tmp);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4352
#include <iostream>

int main() {
	using namespace std;

	int n;
	string s;
	int red = 0;
	int blue = 0;

	cin >> n >> s;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			red++;
		} else {
			blue++;
		}
	}

	if (red > blue) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;

int mod;
vi use(8), res, adjustment;

void dfs(const int n, map<int, Graph> &G, vi &order, int &sum) {
  for (auto v : adjustment) {
    sum += v;
    order.push_back(use[v+mod]);

    if (order.size() * mod + sum <= n) {
      if (res[sum%mod] > sum) {
        res[sum%mod] = sum;
        G[sum%mod] = Graph(1, order);
        dfs(n, G, order, sum);
      }

      else if (res[sum%mod] == sum) {
        G[sum%mod].push_back(order);
        dfs(n, G, order, sum);
      }
    }

    sum -= v;
    order.pop_back();
  }
}

int main() {
  int n, m; cin >> n >> m;
  vi a(m);
  rep(i,m) cin >> a[i];
  
  vi match = {0,2,5,5,4,5,6,3,7,6};
  set<int> stick;
  for (auto v : a) {
    use[match[v]] = max(use[match[v]], v);
    stick.insert(match[v]);
  }

  mod = *begin(stick);

  if (n%mod == 0) {
    rep(i,n/mod) cout << use[mod];
    cout << endl;
    return 0;
  }

  stick.erase(mod);
  for (auto v : stick) adjustment.push_back(v-mod);
  res.assign(mod, 100);
  res[0] = 0;

  int sum = 0;
  map<int, Graph> G;
  vi order;

  dfs(n, G, order, sum);

  int r = min(mod-1, (n-res[n%mod])/mod);
  for (auto &vec : G[n%mod]) {
    int sz = vec.size();
    sz = min(sz, mod-1);
    rep(i,r-sz) vec.push_back(use[mod]);
    sort(ALL(vec), greater<int>());
  }

  vi ans(r, 0);

  for (auto vec : G[n%mod]) {
    rep(i,r) {
      if (ans[i] < vec[i]) {
        ans = vec;
        break;
      }
      if (ans[i] > vec[i]) break;
    }
  }

  rep(i,(n-res[n%mod])/mod-r) ans.push_back(use[mod]);
  sort(ALL(ans), greater<int>());
  for (auto p : ans) cout << p;
  cout << endl;
  return 0;
}


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

namespace AtCoderProg {
    class C_Traveling {
        static void Main(string[] args) {
            int count = int.Parse(Console.ReadLine());
            int reslutCount = count;
            int reslut = 0;

            while(count > 0) {
                string[] input = Console.ReadLine().Split(' ');
                int time = int.Parse(input[0]);
                int num = int.Parse(input[1]) + int.Parse(input[2]);

                if ((time - num)%2 == 0 && (time >= num)) {
                    reslut++;
                }
                count--;
            }
            if (reslutCount == reslut) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 15160
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> cityRoads(N);

    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;

        cityRoads.at(a-1) += 1;
        cityRoads.at(b-1) += 1;
    }

    for(int i = 0; i < N; i++){
        cout << cityRoads.at(i) << endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
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; }

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

const int INF = 1001001001;


int main(){
    string al[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z","A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
    string s;
    int n;
    cin >> n >> s;
    for (int i=0; i<s.size(); i++){
        int idx = s[i]-'A';
        cout << al[idx+n];
    }
    cout << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector <long long> A(N), A_sort(N), A_operated(N);
  
  // A_sort, A 初期化
  for (int i; i < N; i++){
    cin >> A.at(i);
    A_sort.at(i) = A.at(i);
  }
  
  sort(A_sort.begin(), A_sort.end());
  
  //A_operated 初期化
  for (int i; i<N; i++){
    A_operated.at(i) = A_sort.at(i);
  }

  
  int B, C;  
  vector<pair<int, int>> CB_pair(M);
  for (int i=0; i<M; i++){
    cin >> B >> C;
    CB_pair.at(i) = make_pair(C, B);
  }
    
  sort(CB_pair.begin(), CB_pair.end());
  
  int i_start = M-1;
  int number_of_C = CB_pair.at(M-1).second;
  //summary_tempに対して後ろから、B (枚数) を足し続ける。
  
  while(number_of_C < N && i_start > 0){
    number_of_C += CB_pair.at(i_start-1).second;
    i_start--;
  }
  
  vector <int> C_all(number_of_C);
  int k = 0;  
  for(int i = i_start; i<M; i++){
    for(int j = 0; j<CB_pair.at(i).second; j++){
      C_all.at(k++) = CB_pair.at(i).first;
    }
  }
    
  int i = 0;
  while (i < min(N,number_of_C) && A_operated.at(i) < C_all.at(number_of_C-1-i)){
    A_operated.at(i) = C_all.at(number_of_C-1-i);
    i++;
  }
    
    
    
    
  long long answer1;
  
  for (int i; i<N; i++){
    answer1 += A_operated.at(i);
  }
  
  cout << answer1 << endl;
    
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll K;
ll dp[10000][10];

ll dpf(int keta, int mtb){
  if(dp[keta][mtb]>0)return dp[keta][mtb];
  else if(keta==1){
    if(mtb==0) dp[keta][mtb]=0;
    else dp[keta][mtb]=1;
    return dp[keta][mtb];
  }else{
    dp[keta][mtb] = dpf(keta-1, mtb);
    int count = 0;
    if(mtb+1<=9) count++;
    if(mtb<=9 and mtb>=0) count++;
    if(mtb-1>=0)count++;
    dp[keta][mtb] *= count;
    return dp[keta][mtb];
  }
}



/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> K;
  vector<ll> v;
  vector<ll> mae;
  ll count = 0;
  rep(i, 9){
    v.push_back(i+1);
    mae.push_back(0);
  }
  ll i = 0;
  while(true){
    count++;
    //cout << count << " " << v[i]+mae[i]<<endl;
    if(count==K){
      cout<<mae[i]+v[i];
      return 0;
    }
    if(v[i]-1>=0){
      v.push_back(v[i]-1);
      mae.push_back(mae[i]*10+v[i]*10);
    }
    if(v[i]>=0 and v[i]<=9){
      v.push_back(v[i]);
      mae.push_back(mae[i]*10+v[i]*10);
    }
    if(v[i]+1<=9){
      v.push_back(v[i]+1);
      mae.push_back(mae[i]*10+v[i]*10);      
    }
    i++;
    /*if(i>1e5){
      cout << "failed";
      return 0;
      }*/
  }
  
  
  /*
  ll ans = 0;
  ll ansi, ansj;
  rep(j, 10){
    rep(i, 10){
      ans += dpf(j+1, i);
      if(ans>=K){
        ansi = i;
        break;
      }
    }
    if(ans>=K){
      ansj = j;
      break;
    }
    }

    cout << ansj+1 << " " << ansi;*/
  return 0;
}


Measured memory_bytes: 10336
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

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

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
        string s;
        cin >> s;
        int n = s.size();
        int left,right;
        char value;
        if(n%2){
                // nが奇数
                left=right=(n-1)/2;
                value = s[left];
        }else{
                // nが偶数
                right=n/2;
                left=right-1;
                value = s[left];
        }
        int k;
        for(k=n/2+1;k<=n;k++){
                if(!((s[left]==value)&&(s[right]==value))) break;
                // 一致していれば継続
                left--;
                right++;
        }
        cout << k-1 << endl;


        return 0;
}



Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
    int b1,b2,b3;
    scanf("%d %d %d",&b1,&b2,&b3);
    if(b1==1&&b2==1||b1==0&&b3==1)printf("Open\n");
    else printf("Close\n");
    return 0;
}

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

using namespace std;

typedef long long ll;

#define INF 10000000
#define mp make_pair
#define fi first
#define se second

int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,k;
    cin >> n >> k;
    int gc;
    cin >> gc;
    int sk;
    int mx = gc;
    for(int i = 1;i<n;i++){
        cin >> sk;
        mx = max(mx,sk);
        gc = __gcd(gc,sk);
    }
    //cout << mx << "\n";
    if(k%gc==0 && k<=mx){
        cout << "POSSIBLE";
    }
    else{
        cout << "IMPOSSIBLE";
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using data = pair<ll, vector<ll>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    for (int i = 0; i < x; i++)
        cin >> a[i];
    for (int i = 0; i < y; i++)
        cin >> b[i];
    for (int i = 0; i < z; i++)
        cin >> c[i];

    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());

    priority_queue<data> pque;
    set<data> st;
    pque.push(data(a[0] + b[0] + c[0], vector<ll>({0, 0, 0})));
    st.insert(data(a[0] + b[0] + c[0], vector<ll>({0, 0, 0})));
    for (int i = 0; i < k; i++)
    {
        auto ele = pque.top();
        pque.pop();
        cout << ele.first << endl; // 一番上が最大

        if (ele.second[0] + 1 < x)
        {
            ll sum = ele.first - a[ele.second[0]] + a[ele.second[0] + 1];
            auto num = ele.second;
            num[0]++;
            if (!st.count(data(sum, num)))
            {
                st.insert(data(sum, num));
                pque.push(data(sum, num));
            }
        }

        if (ele.second[1] + 1 < y)
        {
            ll sum = ele.first - b[ele.second[1]] + b[ele.second[1] + 1];
            auto num = ele.second;
            num[1]++;
            if (!st.count(data(sum, num)))
            {
                st.insert(data(sum, num));
                pque.push(data(sum, num));
            }
        }

        if (ele.second[2] + 1 < z)
        {
            ll sum = ele.first - c[ele.second[2]] + c[ele.second[2] + 1];
            auto num = ele.second;
            num[2]++;
            if (!st.count(data(sum, num)))
            {
                st.insert(data(sum, num));
                pque.push(data(sum, num));
            }
        }
    }

    return 0;
}

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

int main(){
	int n;
	while(cin>>n,n){
		int k=1;
		map<int,char> id;
		map<char,int> key;
		vector<int> num(n+1,0);
		char X;
		bool did = false;
		for(int i=0;i<n;i++){
			cin >> X;
			if(id[X]==0){
				id[X] = k;
				key[k] = X;
				k++;
			}
			num[id[X]]++;
			int mx=0,mx2=0,ind1;
			for(int j=1;j<n+1;j++){
				if(mx<num[j]){
					mx2 = mx;
					mx=num[j];
					ind1 = j;
				}else if(mx2<num[j]){
					mx2 = num[j];
				}
			}
			if(mx2+(n-i-1)<mx && !did){
				cout << (char)key[ind1] << " " << i+1 << endl;
				did = true;
			}
		}
		if(!did){
			cout << "TIE" << endl;
		}
	}
}


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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

typedef vector<vint>mat;
const int mod=1000000007;

mat mul(mat A,mat B){
     mat C(A.size(),vint(B[0].size()));
     rep(i,C.size()){
        rep(j,C[0].size()){
            rep(k,A[0].size()){
                (C[i][j]+=A[i][k]*B[k][j])%=mod;
            }
        }
     }
     return C;
}

mat mpow(mat A,int m){
    mat B(A.size(),vint(A.size()));
    rep(i,A.size())B[i][i]=1;
    for(;m;m>>=1,A=mul(A,A))if(m&1)B=mul(A,B);
    return B;
}

int N,K,C,T;
int a[114514],b[114514],t[114514];
signed main(){
    cin>>N>>K>>C>>T;C--;
    rep(i,K)cin>>a[i]>>b[i]>>t[i],a[i]--;

    mat X(N*5,vint(1)),A(N*5,vint(N*5));
    X[C][0]=1;
    rep(i,N*4)A[N+i][i]=1;
    rep(k,K){
        int bb=(t[k]-1)*N;
        rep(i,N){
            if(i<a[k])A[i+b[k]][bb+i]++;
            else if(i<a[k]+b[k])A[i-a[k]][bb+i]++;
            else A[i][bb+i]++;
        }
    }


    X=mul(mpow(A,T),X);
    cout<<X[0][0]<<endl;
    return 0;
}

Measured memory_bytes: 3116
N,K,C = map(int,input().split())
S = list(input())
L = [(0,-C) for i in range(N+1)]
R = [(0,N+C+1) for i in range(N+1)]
for i in range(N):
	l = L[i]
	s = S[i]
	if s == "o" and l[1] + C < i+1:
		L[i+1] = (l[0]+1, i+1)
	else:
		L[i+1] = L[i]

	r = R[N-i]
	s = S[N-1-i]
	if s == "o" and N-i + C < r[1]:
		R[N-i-1] = (r[0]+1, N-i)
	else:
		R[N-i-1] = R[N-i]

R = [(0,0)] + R

for n in range(N):
	d = n+1
	if d == 1:
		if R[2][0] < K:
			print(d)
		continue
	if d == N:
		if L[N-1][0] < K:
			print(d)
		continue
	l = L[d-1]
	r = R[d+1]
	w_l, w_r=0, 0
	if l[1] + C > N:
		w_l = l[0]
	else:
		w_l = l[0] + R[max(d+1, l[1]+C)][0]
	if r[1] - C <= 0:
		w_r = r[0]
	else:
		w_r = r[0] + L[min(d-1, r[1]-C)][0]
	if w_l < K and w_r < K:
		print(d)


Measured memory_bytes: 79688
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(V) V.begin(), V.end()
#define PB push_back
using namespace std;
typedef long long ll;

int main() {
    int n,x,t;
    cin >> n >> x >> t;
    int ans = 0;
    int a = n /x;
    ans = a*t;
    if(n % x != 0){
        ans+= t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
S,M = gets.to_i,1000000007
H = lambda{|n,r|
	next (n+r-1).downto(n+1).inject(1){|p,n| p*n%M } * (r-1).downto(2).inject(1){|p,n| p*n.pow(M-2,M) }
}

p ((0..(S/3-1)).sum{|n| H[S%3+3*n, S/3-n]%M })%M


Measured memory_bytes: 17564
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

class UnionFind:
    def __init__(self, n):
        self.parents = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.length = [1 for _ in range(n)] 

    def makeSet(self, n):
        self.parents = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.length = [1 for _ in range(n)]

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parents[x] = y
            self.length[y] += self.length[x]
        else:
            self.parents[y] = x
            self.length[x] += self.length[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def getLength(self, x):
        x = self.find(x)
        return self.length[x]        

    def isSameGroup(self, x, y):
        return self.find(x) == self.find(y)


def main():
    n, m = map(int, readline().split())
    uf = UnionFind(n)
    for _ in range(m):
        x, y, z = map(int, readline().split())
        x-=1
        y-=1
        uf.unite(x, y)
    s = set()
    for i in range(n):
        s.add(uf.find(i))
    print(len(s))
if __name__ == '__main__':
    main()


Measured memory_bytes: 17576
#include <bits/stdc++.h>
using namespace std;
#define itn int

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

    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<int> cs(n);
    for (int i = 0; i < n; i++) cin >> cs[i];
    sort(cs.rbegin(), cs.rend());

    long long nax = 0;
    vector<int> ans(n), best;
    int idx = 0;
    function<void(int, int)> dfs = [&](int v, int p) {
        ans[v] = cs[idx++];
        for (int s : adj[v]) {
            if (s != p) {
                dfs(s, v);
            }
        }
    };

    dfs(0, -1);
    idx = 0;

    long long sum = 0;
    for (int a = 0; a < n; a++) {
        for (int b : adj[a]) {
            if (a < b) {
                sum += min(ans[a], ans[b]);
            }
        }
    }

    if (sum > nax) {
        nax = sum;
        best = ans;
    }
    
    cout << nax << endl;
    for (int a : best) cout << a << ' ';
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_H = 25;

int H, W;
char F[MAX_H][MAX_H];

bool canMove(int x, int y) {
  return 0 <= x && x < W && 0 <= y && y < H && F[y][x] == '.';
}

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dist[MAX_H][MAX_H];
int calc(int x, int y)
{
  memset(dist, -1, sizeof(dist));
  dist[y][x] = 0;

  queue<II> que;
  que.push(II(x, y));

  int ans = 0;

  while(que.size()) {
    II pos = que.front(); que.pop();
    REP(d,4) {
      int nx = pos.first + dx[d];
      int ny = pos.second + dy[d]; 
      if(canMove(nx,ny) && dist[ny][nx] == -1) {
        dist[ny][nx] = dist[pos.second][pos.first]+1;
        ans = max(ans, dist[ny][nx]);
        que.push(II(nx, ny));
      }
    }
  }

  return ans;
}

signed main()
{
  cin >> H >> W;

  REP(h,H) {
    REP(w,W) {
      cin >> F[h][w];
    }
  }

  int ans = -1;
  REP(y,H) {
    REP(x,W) {
      if(F[y][x] == '.') {
        ans = max(ans, calc(x,y));
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[105];
int main(){
	long long n,cnt=0;
	cin>>n;
	while(n){
		n--;
		a[cnt++]=n%26+'a';
		n/=26;
	}
	for(int i=cnt-1;i>=0;i--)
	    cout<<a[i];
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int md = 1000000, piv = -1;

int main() {
	int N;
	cin >> N;
	int s = 0;
	vi vec(N);
	rep(i, N) {
		cin >> vec[i];
		s += vec[i];
	}
	rep(i, N) {
		int d = abs(vec[i] * N - s);
		if (d < md) {
			md = d;
			piv = i;
		}
	}
	cout << piv << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;

int main()
{
	lld n;
	string s[50];

	cin >> n;

	for(int i = 0; i < n; i++)
	{
		cin >> s[i];
	}

	int al[50][26] = {0};

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < s[i].size(); j++)
		{
			int m = (int)s[i][j] - 'a';
			al[i][m]++;
		}
	}

	int alpha[26] = {0};

	for(int i = 0; i < 26; i++)
	{
		int min = INF;
		for(int j = 0; j < n; j++)
		{
			if (min > al[j][i])
			{
				min = al[j][i];
			}
		}

		alpha[i] = min;
	}

	for(int i = 0; i < 26; i++)
	{
		for(int j = 1; j <= alpha[i]; j++)
		{
			cout << (char)('a'+i);
		}
	}

	cout << endl;

	
	return 0;
}
	

Measured memory_bytes: 256