akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    string a, b, c; cin >> a >> b >> c;
    if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
        cout << "YES" << endl;
    }

    else cout << "NO" << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


int main(){
  unsigned long long n, d;

  cin >> d >> n;

  unsigned long long ans;

  ans = pow(100, d) * n;

  if(n == 100)
    ans += pow(100, d);

  cout << ans << endl;

  return 0;
}

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

ll par[100010][2];

void init(ll n) {
	for (ll i = 0;i < n;i++) {
		par[i][0] = i;
		par[i][1] = 1;
	}
}

ll root(ll x) {
	if (par[x][0] == x)
		return x;
	else
		return par[x][0] = root(par[x][0]);
}

ll unite(ll x, ll y) {
	ll c = 0;
	x = root(x);
	y = root(y);
	if (x == y) return 0;
	c = par[x][1] * par[y][1];
	if (par[x][1] > par[y][1]) {
		par[y][0] = x;
		par[x][1] += par[y][1];
	} else {
		par[x][0] = y;
		par[y][1] += par[x][1];
	}
	return c;
}

int main() {
	int N, M; cin >> N >> M;
	vector<pair<ll, ll>> Br(M);
	ll a, b;
	for (int i = 0;i < M;i++) {
		cin >> a >> b;
		Br[i] = {a,b};
	}
	init(N);
	vector<ll> ls(M,0);
	ll ans=0;
	ll ac = 1LL * N * (N - 1) / 2;
	for (int i = 0;i < M;i++) {
		ls[M-1-i] = ac - ans;
		ans += unite(Br[M-1-i].first,Br[M-1-i].second);
	}
	for (int i = 0;i < M;i++)
		cout << ls[i] << endl;
}

Measured memory_bytes: 5248
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  string S;
  cin >> S;

  sort(S.begin(), S.end());
  for (int i = 0; i < S.size() - 1; i++) {
    if (S[i] == S[i+1]) {
      cout << "no" << endl;
      return;
    }
  }
  cout << "yes" << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

int main(){
  int M1,D1,M2,D2;
  cin>>M1>>D1>>M2>>D2;
  if(M1 != M2){
    cout<<1<<endl;
  }
  else{
    cout<<0<<endl;
  }
  return 0;
}



    

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	string s;
	cin>>s;
	int a = 10*(s[0]-'0')+(s[1]-'0');
	int b = 10*(s[2]-'0')+(s[3]-'0');
	if(0<a&&a<=12 &&0<b&& b<=12){
		cout<<"AMBIGUOUS"<<endl;
	}else if(0<a&&a<=12){
		cout<<"MMYY"<<endl;
	}else if(0<b&&b<=12){
		cout<<"YYMM"<<endl;
	}else{
		cout<<"NA"<<endl;
	}



	return 0;
}


Measured memory_bytes: 256
int main()
{
  int i,N,j,k;
  
  scanf("%d",&N); //要素の個数
  int A[N];
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  

  for(k=0;k<N;k++){
    if(k>0) printf(" ");
    printf("%d",A[k]);
  }
  printf("\n");
  int v;
  for(i=1;i<=N-1;i++){
    v = A[i];
    j = i-1;

    while(j>= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
     
    }

    A[j+1] = v;
    for(k=0;k<N;k++){
      if(k>0) printf(" ");
      printf("%d",A[k]);
    }
    printf("\n");
  }


  return 0;

}



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

int main() {
    int l[10], v1, v2;
    char c;
    while (cin >> l[0]) {
        int sum = l[0];
        for (int i=1; i<10; ++i) {
            cin >> c >> l[i];
            sum += l[i];
        }
        cin >> c >> v1 >> c >> v2;

        int d = 0;
        for (int i=0; i<10; ++i) {
            d += l[i];
            if (v1 * sum <= d * (v1 + v2)) {
                cout << i + 1 << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long a = input.nextLong();
        long b = input.nextLong();
        long n = input.nextLong();
        long x = Math.min(b-1,n);
        long ans = (a*x/b) - a*(x/b);
        System.out.println(ans);
    }
}

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

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

    int n = s.size();

    int count0 = 0;
    int count1 = 0;

    for(int i = 0; i < n; i++){
        if(s.at(i) == '0'){
            count0++;
        }
        else{
            count1++;
        }
    }

    int halfAns = min(count0, count1);
    int ans = halfAns * 2;

    printf("%d", ans);
    return 0;
    
}

Measured memory_bytes: 512
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

x1, y1, x2, y2 = list(map(int, sys.stdin.readline().split()))
x3 = x2 - (y2 - y1)
y3 = y2 - (x1 - x2)
x4 = x3 - (y3 - y2)
y4 = y3 - (x2 - x3)
print(x3, y3, x4, y4)


Measured memory_bytes: 13644
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m;
struct node{
	int x,y;
	double d;
	bool operator <(node a)const{
		return d>a.d;
	}
}edge[50000005];
int fa[10005];
int p[10006][2];
int find_father(int x){
	if(x==fa[x])
		return x;
	return fa[x]=find_father(fa[x]);
}
double dis(int x1,int y1,int x2,int y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&p[i][0],&p[i][1]);
	for(int i=1;i<=m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		double c=dis(p[a][0],p[a][1],p[b][0],p[b][1]);
		edge[i].x=a,edge[i].y=b,edge[i].d=c;
	}
	sort(edge+1,edge+m+1);
	double ans=0;
	for(int i=1;i<=n;i++)
		fa[i]=i;
	for(int i=1;i<=m;i++){
		int f1=find_father(edge[i].x),f2=find_father(edge[i].y);
		if(f1==f2)
			ans+=edge[i].d;
		else
			fa[f1]=f2;
	}
	printf("%.3lf",ans);
}

Measured memory_bytes: 3280
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack>
#include <set>
#include <time.h>
#define _USE_MATH_DEFINES
#define LL long long
#define front top
using namespace std;
const double PI = acos(-1.0);

int max_num(int ary[],int length) {
	int max = ary[0];
	for (int i = 1; i < length; i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int max_ord(int ary[], int length) {
	int max;
	max = max_num(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == max) return i;
	}
	return -1;
}

int min_num(int ary[], int length) {
	int min = ary[0];
	for (int i = 1; i < length; i++)
		if (min > ary[i]) min = ary[i];
	return min;
}

int min_ord(int ary[], int length) {
	int min;
	min = min_num(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == min) return i;
	}
	return -1;
}

int main() {
	LL n, T, t[200000];
	LL sum = 0;
	cin >> n >> T;
	for (int i = 0; i < n; i++) cin >> t[i];
	for (int i = 0; i < n-1; i++) {
		if (T + t[i] >= t[i + 1])
			sum += t[i + 1] - t[i];
		else sum += T;
	}
	sum += T;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n;
  std::cin >> n;
  vt<char> s(n);
  rep(i,n) {
    std::cin >> s[i];
    if(s[i] == 'Y') {
      std::cout << "Four" << '\n';
      return 0;
    }
  }
  std::cout << "Three" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

vector<int> path[220000];
int s[220000];
int one=1,two=2,three=3;
int n,m;
bool used[220000];

void dfs(int pos,int bef=-1,int dis=0){
	if(dis%2==0){
		if(one>n)s[pos]=three,three+=3;
		else s[pos]=one,one+=3;
	}else{
		if(two>n)s[pos]=three,three+=3;
		else s[pos]=two,two+=3;
	}
	for(auto to:path[pos]){
		if(to==bef)continue;
		dfs(to,pos,dis+1);
	}
}

void dfs2(int pos,int t,int bef=-1){
	if(s[pos]%3==t){
		s[pos]+=3-t;
		used[s[pos]]=true;
	}else s[pos]=0;
	for(auto to:path[pos]){
		if(to==bef)continue;
		dfs2(to,t,pos);
	}
}

int main(){
	int i,j,k;
	int a,b,c;
	cin>>n;
	for(i=0;i<n-1;i++){
		cin>>a>>b;
		a--,b--;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	dfs(0);
	if(three>n+3){
		if(one>n)dfs2(0,2);
		else dfs2(0,1);
		j=1;
		for(i=0;i<n;i++){
			if(s[i]==0)s[i]=j++;
			if(used[j])j++;
		}
	}
	array_show(s,n);
}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

const int MOD = int(1e9) + 7;

int main() {
#if __APPLE__
    freopen("E.in", "r", stdin);
    freopen("E.out", "w", stdout);
#endif

    int n, m;
    while (scanf("%d%d", &n, &m) == 2) {
        vector<vector<pair<int, int>>> a(n + 1);
        for (int i = 0; i < m; ++i) {
            int l, r, x;
            scanf("%d%d%d", &l, &r, &x);
            a[r].push_back({l, x});
        }

        ll dp[n + 2][n + 2][n + 2];
        memset(dp, 0, sizeof dp);
        dp[0][0][0] = 1;
        ll ans = 0;
        for (int r = 0; r <= n; ++r) {
            for (int g = 0; g <= n; ++g) {
                for (int b = 0; b <= n; ++b) {
                    int k = max({r, g, b});
                    for (auto& x : a[k]) {
                        int l = x.fi;
                        int c = x.se;
                        int cnt = (r >= l) + (g >= l) + (b >= l);
                        if (cnt != c) {
                            dp[r][g][b] = 0;
                            break;
                        }
                    }
                    dp[k + 1][g][b] += dp[r][g][b];
                    if (dp[k + 1][g][b] >= MOD) dp[k + 1][g][b] -= MOD;
                    dp[r][k + 1][b] += dp[r][g][b];
                    if (dp[r][k + 1][b] >= MOD) dp[r][k + 1][b] -= MOD;
                    dp[r][g][k + 1] += dp[r][g][b];
                    if (dp[r][g][k + 1] >= MOD) dp[r][g][k + 1] -= MOD;
                    if (k == n) {
                        ans += dp[r][g][b];
                        if (ans >= MOD) ans -= MOD;
                    }
                }
            }
        }

        printf("%lld\n", ans);
        return 0;
    }
}


Measured memory_bytes: 215424
from itertools import product
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = sorted([a+b for a, b in product(A, B)], reverse=True)[:k]
E = sorted([c+d for c, d in product(C, D)], reverse=True)[:k]
[ print(ans) for ans in E ]

Measured memory_bytes: 144012
#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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int dp[100010][3];

void _main()
{
    int N;
    cin >> N;
    rep(i, 0, N)
    {
        array<int, 3> h;
        cin >> h[0] >> h[1] >> h[2];
        rep(j, 0, 3)
        {
            dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + h[j];
        }
    }
    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main(void){
    long long H,W;
    const int MAX = 100000;
    // input
    cin >> H >> W;
    // 制約
    if (H < 2 && H > MAX && W < 2 && W > MAX){
        return 0;
    }
    long long Sa,Sb,Sc,Smax,Smin;
    long long ans = 100000000000000;
    // 初期化
    if (H % 3 == 0 || W % 3 == 0){
        ans = 0;
    }else{
        ans = min(ans, min(H,W));
    }
    // 横 縦
    for (int i = 1;i < H;i++){
        Sa = i * W;
        long long w = W / 2;
        Sb = (H - i)*w;
        Sc = (H - i)*(W -w);
        Smax = max(Sa,max(Sc,Sb));
        Smin = min(Sa,min(Sc,Sb));
        ans = min(ans,Smax - Smin);
    }
    swap(H,W);
    // 縦 横
    for (int i = 1;i < H;i++){
        Sa = i * W;
        long long w = W / 2;
        Sb = (H - i)*w;
        Sc = (H - i)*(W -w);
        Smax = max(Sa,max(Sc,Sb));
        Smin = min(Sa,min(Sc,Sb));
        ans = min(ans,Smax - Smin);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;

int main(){
  ll n,y;
  cin>>n>>y;
  ll cu=0;
  ll a=0;
  ll q=0;
  ll w=0;
  rep(i,n+1){
    for(int j=0;j+i<=n;j++){
      if((y-10000*i-5000*j)/1000==n-i-j){
        cu=1;
        a=i;
        q=j;
        w=n-i-j;
        break;
      }
    }
    if(cu) break;
  }
  if(cu) cout<<a<<" "<<q<<" "<<w<<endl;
  else cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define maxn 110
using namespace std;
int n,W,sum;
int w[maxn],v[maxn],f[100010];
int main(){
	scanf("%d%d",&n,&W);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&w[i],&v[i]);
		sum+=v[i];
	}
	for(int i=1;i<=sum;i++)f[i]=1000000001;
	for(int i=1;i<=n;i++){
		for(int j=sum;j>=v[i];j--){
			f[j]=min(f[j],f[j-v[i]]+w[i]);
		}
	}
	int ans=0;
	for(int i=sum;i>=0;i--){
		if(f[i]<=W){
			ans=i;
			break;
		}
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

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

		while (true) {
			String str[] = br.readLine().split("");

			if (str[0].equals("."))
				break;

			boolean flag = true;
			Deque<String> stack = new ArrayDeque<>();
			for (int i = 0; i < str.length; i++) {
				if (str[i].equals("(")) {
					stack.push("(");
				} else if (str[i].equals("[")) {
					stack.push("[");
				} else {
					if (str[i].equals(")")) {
						if (stack.size() <= 0 || !stack.poll().equals("(")) {
							flag = false;
							break;
						}
					} else if (str[i].equals("]")) {
						if (stack.size() <= 0 || !stack.poll().equals("[")) {
							flag = false;
							break;
						}
					}
				}
			}
			if (stack.size() > 0)
				flag = false;
			if (flag)
				System.out.println("yes");
			else
				System.out.println("no");
		}
	}
}


Measured memory_bytes: 57160
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int mod=1000000007;
long long vex(int n)
{
	int i;
	long long ans=1;
	for(i=1;i<=n;i++)
	{
		ans=ans%mod*2;
		ans%=mod;
	}
	return ans;
}
int main()
{
	int a[100010],b[100010];
	long long ans;
	int n,i,k;
	while(cin>>n)
	{
		k=1;
		if(n%2==0)
		{
			memset(b,0,sizeof(b));
			for(i=1;i<=n;i++)
			{
				cin>>a[i];
				if(a[i]%2==0)
				{
					k=0;
				}
				b[a[i]]++;
			}
			for(i=1;i<=n-1;i+=2)
			{
				if(b[i]==2)
					continue;
				k=0;
			}
//			if(!k)
//			{
//				cout<<"0"<<endl;
//			}
		}
		else
		{
			memset(b,0,sizeof(b));
			for(i=1;i<=n;i++)
			{
				cin>>a[i];
				if(a[i]%2)
				{
					k=0;
				}
				b[a[i]]++;
			}
			if(b[0]!=1)
				k=0;
			else
				for(i=2;i<=n-1;i+=2)
				{
					if(b[i]==2)
						continue;
					k=0;
				}
			
		}
		if(!k)
		{
			cout<<"0"<<endl;
		}
		else
		{
			ans=vex(n/2);
			cout<<ans<<endl;
		}
	}
return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    string ans="APPROVED";

    rep(i, N) {
        if(A[i]%2==0){
            if((A[i]%3==0)||(A[i]%5==0)){
                ans = "APPROVED";
            }else{
                ans="DENIED";
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>


using namespace std;


#define EPS (1e-10)
#define equals(a,b) (fabs((a) - (b)) < EPS) //?????????????????????????????????


//??????????????????????????????
class Point {

public:

	double x, y;//??§?¨????????????????x,y??????

	Point(double x = 0, double y = 0) :x(x), y(y) {}

	Point operator + (Point p) {
		return Point(x + p.x, y + p.y);
	}

	Point operator - (Point p) {
		return Point(x - p.x, y - p.y);
	}

	Point operator * (double r) {
		return Point(x * r, y * r);
	}

	Point operator / (double r) {
		return Point(x / r, y / r);
	}

	double norm() {
		return x*x + y*y;
	}

	//?????????????????§???????????????
	double abs() {
		return sqrt(norm());
	}

	bool operator < (const Point &p) const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p) const {
		return fabs(x - p.x) < EPS &&  fabs(y - p.y) < EPS;
	}

};

typedef Point Vector;

//??????????????????????????????
double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

//??????????????????????????????
double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}



class Segment {
public:
	Point p1, p2;

	Segment() {}

	//?????¨????°???±?????????
	Point projection(Point p) {
		Vector base = p2 - p1;

		double r = dot(p - p1, base) / base.norm();
		return p1 + base * r;
	}

	//????°??????????
	Point reflection(Point p) {
		return p + (projection(p) - p)*2.0;
	}

};

//?????????????????´?????????
bool isOrthogonal(Vector a, Vector b) {
	return equals(dot(a, b), 0.0);
}

//??????????§??????¨?????????????????´?????????
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
	return isOrthogonal(a1 - a2, b1 - b2);
}

//???????????´?????????
bool isOrthogonal(Segment s1, Segment s2) {
	return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

//???????????????????????????
bool isParallel(Vector a, Vector b) {
	return equals(cross(a, b), 0.0);
}

//??????????§??????¨???????????????????????????
bool isParallel(Point a1, Point a2, Point b1, Point b2) {
	return isParallel(a1 - a2, b1 - b2);
}

//?????????????????????
bool isParallel(Segment s1, Segment s2) {
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

//?°???±?????????
Point projection(Segment s, Point p) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base * r;
}

//????°??????????
Point reflection(Segment s, Point p) {
	return p + (projection(s, p) - p)*2.0;
}

typedef Segment Line;

typedef vector<Point> Polygon;



//???
class Circle {
public:
	Point c;//??????
	double r;//??????
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};


int main(void)
{
	int n;

	Segment s;
	Point p;
	Point ref;

	cin >> s.p1.x >> s.p1.y >> s.p2.x >> s.p2.y;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> p.x >> p.y;
		ref = reflection(s, p);
		printf("%.9lf %.9lf\n", ref.x, ref.y);
	}

	return 0;
}

Measured memory_bytes: 3268
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	string s, t;
	cin >> s >> t;
	s = '2' + s;
	t = '3' + t;
	vector<vector<int>>dp(s.size(), vector<int>(t.size()));
	for (int i = 1; i < s.size(); i++) {
		for (int j = 1; j < t.size(); j++) {
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if(s[i]==t[j])	dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
		}
	}
	string ret;
	N = s.size() - 1;
	M = t.size() - 1;
	while (N | M) {
		if (s[N] == t[M]) {
			if (dp[N][M] - 1 == dp[N - 1][M - 1]) {
				ret.push_back(t[M]);
				N--;
				M--;
			}
		}
		else{
			if (N&&dp[N][M] == dp[N - 1][M])N--;
			else M--;
		}
	}
	reverse(ret.begin(), ret.end());
	cout << ret << endl;
}

Measured memory_bytes: 35584
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,ans=0;
    cin >> n;
    ans+=n/500*1000;
    n=n%500;
    ans+=n/5*5;
    cout << ans << endl;
    return 0;
}


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

#include <cstring>
#include <cassert>
using namespace std;

#ifdef LOCAL
    #define LLD_SPEC "%lld"
#else
    #define LLD_SPEC "%I64d"
#endif

const int MOD = 1e9 + 7;

inline void ModSum(int& x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
    if (x < 0) {
        x += MOD;
    }
}

inline void ModMul(int& x, int y) {
    x = (1LL * x * y) % MOD;
}

const int MAX_N = 5e3 + 100;

char s[MAX_N];

int pw2[MAX_N];

int main() {
    pw2[0] = 1;
    for (int i = 1; i < MAX_N; ++i) {
        pw2[i] = pw2[i - 1];
        ModMul(pw2[i], 2);
    }

    int n;
    scanf("%d", &n);
    scanf("%s", s);

    int m = strlen(s);

    vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int a = 0; a <= i - 1; ++a) {
            if (a > 0) {
                ModSum(dp[i][a - 1], dp[i - 1][a]);
            }
            ModSum(dp[i][a + 1], dp[i - 1][a]);
        }
    }

    int result = 0;
    for (int t = 0; t + t + m <= n; ++t) {
        int d = n - t - m;
        int dAdd = d - t;
        for (int tPrefix = 0; tPrefix <= t; ++tPrefix) {
            int dPrefix = dAdd + tPrefix;

            int cd = d - dPrefix;
            int ct = t - tPrefix;

            assert(cd == ct);

            int curResult = pw2[t];
            ModMul(curResult, dp[(m - 1) + 2 * ct][m - 1]);
            ModMul(curResult, dp[dPrefix + tPrefix][dAdd]);

            ModSum(result, curResult);
        }
    }

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

    return 0;
}

Measured memory_bytes: 98176
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>
#include <stack>

using namespace std;

#define long long long
#define fi first
#define se second
typedef pair<int,int> ii;

map<int, int> mp;
int A[1000003];

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	int n; scanf("%d", &n);

	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &A[i]);
		mp[A[i]]++;
	}

	if(mp.size() == 1)
	{
		if(mp[0] == n) printf("Yes\n");
		else printf("No\n");
	}
	else if(mp.size() >= 4 || n%3 != 0) printf("No\n");
	else if(mp.size() == 2)
	{
		vector<int> V;
		for(auto it : mp)
			V.push_back(it.fi);

		if(V[0] == 0 && mp[V[1]] == 2*mp[V[0]])
			printf("Yes\n");
		else printf("No\n");
	}
	else if(mp.size() == 3)
	{
		vector<int> V;
		for(auto it : mp)
			V.push_back(it.fi);

		if(mp[V[0]] != n/3 || mp[V[1]] != n/3 || mp[V[2]] != n/3)
			printf("No\n");
		else if(V[0] != (V[1]^V[2]))
			printf("No\n");
		else printf("Yes\n");
	}
}










Measured memory_bytes: 4224
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
a = na()

x = 0
y = 0
z = 0

def count(m):
    cnt = 0
    cnt += x == m
    cnt += y == m
    cnt += z == m
    return cnt

ans = 1
for i in range(n):
    ans *= count(a[i])
    if x == a[i]:
        x += 1
    elif y == a[i]:
        y += 1
    elif z == a[i]:
        z += 1

print(ans % mod)

Measured memory_bytes: 14396
N = int(input())
E = [[int(i) for i in input().split()] for i in range(N)] 

def hantei(t, z):
    if t >= z and t % 2 == z % 2:return 'Y'
    else: return 'N'
    
E.insert(0, [0, 0 , 0])

a=''
for i in range(1, len(E)):
    if 'Y' == hantei(E[i][0] - E[i-1][0] , (E[i][1] + E[i][2]) - (E[i-1][1] + E[i-1][2])):
        continue
    else:
        a = 'No'
        break
if a != 'No':
    a = 'Yes'
print(a)

Measured memory_bytes: 21108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader();
		int N = sc.nextInt();
		long[][] dp = new long[3][N+10]; 
		for (int i=1; i<=N; i++) {
			int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(); 
			dp[0][i] = Math.max(dp[1][i-1], dp[2][i-1]) + a; 
			dp[1][i] = Math.max(dp[0][i-1], dp[2][i-1]) + b; 
			dp[2][i] = Math.max(dp[0][i-1], dp[1][i-1]) + c; 
		}
		System.out.println(Math.max(dp[0][N], Math.max(dp[1][N], dp[2][N])));
	}

}


Measured memory_bytes: 46832
#include <iostream>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

int yoko[10], ryoko[10];
int tate[10], rtate[10];

void tobit(string str, int i){
  yoko[i] = 0;
  tate[i] = 0;
  ryoko[i] = 0;
  rtate[i] = 0;
  REP(j, 5){
    if(str[j] == '1'){
      yoko[i]  |= 1 << j;
      ryoko[i] |= 1 << (4 - j);
      tate[i]  |= 1 << (5 * j);
      rtate[i] |= 1 << (20 - 5 * j);
    }
  }
}

map<int, int> generate_bmask(const vector<int> &v, bool TATE){
  map<int, int> ans;
  int p[] = {0, 1, 2, 3, 4};
  
  do{
    REP(rmask, 1 << 5){
      int bmask = 0;
      REP(i, 5){
        if(PARITY(rmask >> i)){
          if(TATE) bmask |= tate[v[p[i]]] << i;
          else     bmask |= yoko[v[p[i]]] << (5 * i);
        }else{
          if(TATE) bmask |= rtate[v[p[i]]] << i;
          else     bmask |= ryoko[v[p[i]]] << (5 * i);
        }
      }
      ans[bmask]++;
    }
  }while(next_permutation(p, p + 5));
  return ans;
}

int main(){
  string strs[10];
  while(cin >> strs[0], strs[0]!= "END"){
    ll ans = 0;
    int mirror = 1;
    REP(i, 9) cin >> strs[i+1];
    REP(i, 10){
      tobit(strs[i], i);
      string rstr = strs[i];
      reverse(ALL(rstr));
      if(rstr == strs[i]) mirror++;
    }
    
    REP(mask, 1 << 10){
      if(__builtin_popcount(mask) != 5) continue;
      vector<int> T, Y;
      REP(i, 10){
        if(PARITY(mask  >> i)) T.PB(i);
        else Y.PB(i);
      }
      
      map<int, int> count1 = generate_bmask(T, true);
      map<int, int> count2 = generate_bmask(Y, false);
      
      FOREACH(it, count1){
        int c1 = it->second;
        int c2 = count2[0x1ffffff ^ (it->first)];
        ans += c1 * c2;
      }
    }
    cout << (ans >> (mirror+2)) << endl;
  }
  return 0;
}

Measured memory_bytes: 1628
#include <iostream>

using namespace std;

const int mod = 1000000007;

int main() {
  int n; cin >> n;  // comment: width
  string s1, s2;
  cin >> s1 >> s2;

  long long ans;
  int i = 0;
  while (i < n) {
    if (i == 0) {
      // 縦棒のとき
      if (s1[i] == s2[i]) {
        ans = 3;
        i += 1;
      } else { // 横棒x2のとき
        ans = 6;
        i += 2;
      }
    } else {
      if (s1[i] == s2[i]) { // 縦棒のとき
        if (s1[i-1] == s2[i-1]) { // ひとつ前も縦棒
          ans *= 2;
        } else {
          ans *= 1;  // ひとつ前は横棒x2
        }
        i += 1;
      } else { // 横棒x2 のとき
        if (s1[i-1] == s2[i-1]) { // ひとつ前は縦棒
          ans *= 2;
        } else {
          ans *= 3;  // ひとつ前も横棒x2
        }
        i += 2;
      }
    }
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const ulong MOD9 = 1000000007;

    public static void Main()
    {
        var list = Console.ReadLine().Split(' ');
        var a = int.Parse(list[0]);
        var b = int.Parse(list[1]);
        var t = int.Parse(list[2]);

        Console.WriteLine(t / a * b);
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include<cstdio>
 
using namespace std;
 
typedef long long int ll;
 
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; }
 
typedef pair<int,int> pair;
 
int main(){
    string s,t,u;
    int a,b;
    cin >> s >> t >> a >> b >> u;
    
    if(s==u) a--;
    if(t==u) b--;

    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<string>
#include<utility>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)

long long N,M;
long long ans;




int main() {
	cin>>N>>M;
	if(N==1 && M==1){
		ans = 1;
	}
	else if(N==1 && M!=1){
		ans = M - 2;
	}
	else if(M==1 && N!=1){
		ans =N - 2;
	}
	else ans =(M-2)*(N-2);
	cout<<ans<<endl;
	
	return 0;
}

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

int main() {
  
  string s_str;
  long long int ans = 0;

  cin >> s_str;

  ans += stoll(s_str);
  for(int i=1; i<s_str.size(); i++) {
    for(int j=0; j<=i; j++) {
      if(j==0 || j==i){
        ans += stoll(s_str.substr(j, s_str.size()-i)) * pow(2, i-1);
      } else {
        ans += stoll(s_str.substr(j, s_str.size()-i)) * pow(2, i-2);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
    int a;
    long sum = 0;
    cin >> a;
    for (int i = 1; i <= a; ++i)
    {
        if ((i % 3 > 0) && (i % 5 > 0))
            sum += i;
    }
    cout << sum;
    return 0;
}

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

using namespace std;

int main(void){
	int num[3];

	cin >> num[0] >> num[1] >> num[2];
	sort(num, num+3);

	cout << num[0] << " " << num[1] << " " << num[2] << endl;

	return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
  int A, B, C, D, i, N=7, ans=0, X;
  string s;
  cin >> s;
  A = s[0]-'0';
  B = s[1]-'0';
  C = s[2]-'0';
  D = s[3]-'0';

  if (A+B+C+D == 7) printf("%d+%d+%d+%d=7", A,B,C,D);
  else if (A+B+C-D == 7) printf("%d+%d+%d-%d=7", A,B,C,D);
  else if (A+B-C+D == 7) printf("%d+%d-%d+%d=7", A,B,C,D);
  else if (A+B-C-D == 7) printf("%d+%d-%d-%d=7", A,B,C,D);
  else if (A-B+C+D == 7) printf("%d-%d+%d+%d=7", A,B,C,D);
  else if (A-B+C-D == 7) printf("%d-%d+%d-%d=7", A,B,C,D);
  else if (A-B-C+D == 7) printf("%d-%d-%d+%d=7", A,B,C,D);
  else if (A-B-C-D == 7) printf("%d-%d-%d-%d=7", A,B,C,D);

  return 0;
}


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

int main()
{
    int n,l,t[200000];
    scanf("%d %d",&n,&l);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&t[i]);
    }
    int ans = l;
    for (int i = 1; i < n; i++)
    {
        if(t[i] - t[i - 1] >= l)
        {
            ans += l;
        }
        else
        {
            ans += t[i] - t[i - 1];
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 896
using System;

class ITP1_4_A
{
    static void Main()
    {
        int a, b;
        string x = Console.ReadLine();
        string[] result;
        const char Space = ' ';
        char[] delimiters = new char[] { Space };
        result = x.Split(delimiters);
        a = int.Parse(result[0]);
        b = int.Parse(result[1]);

        int d, r;

        d = a / b;
        r = a % b;

        double f;
        double a1 = (double)a;
        double b1 = (double)b;

        f = a1 / b1;

        Console.WriteLine("{0} {1} {2,-8:F6}", d, r, f);
    }
}


Measured memory_bytes: 18004
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9) + 7)

ll max(ll a, ll b)
{
  if (a > b)
  {
    return a;
  }
  return b;
}

int main()
{
  int n,m,x;
  cin >> n >> m >> x;
  int A[n][m];
  int c[n];
  for(int i = 0;i < n;i++)
  {
    cin >> c[i];
    for(int j = 0;j <m;j++)
    {
      cin >> A[i][j];
    }
  }

  int ans = 12345678;
  int all = 1<<n;

  for(int mask = 0; mask < all; mask++){
        vector<int> level(m);
        int cost = 0;
        for(int i = 0; i < n; i++){
            if((mask>>i)&1){
                cost += c[i];
                for(int j = 0; j < m; j++){
                    level[j] += A[i][j];
                }
            }
        }
        bool ok = true;
        for(int j = 0; j < m; j++){
            if(level[j] < x) ok = false;
        }
        if(ok) ans = min(ans,cost);
    }
    if(ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
}


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

void Main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    vector<long> cost(n+1);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
        long c = 1e10;
        for (int j = 1; j <= k; j++)
            if(i>=j)
                c = min(c, cost[i-j] + abs(h[i-j]-h[i]));
        if(i==0) cost[i] = 0;
        else cost[i] = c;
    }
    
    cout << cost[n-1] << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


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

int main(){
	int n, m, k;
	while( cin >> n >> m >> k , n || m || k ){
		int s = n * m;
		double dp[2][s+5];
		for(int i=0 ; i < s+5 ; i++ ){
			dp[0][i] = dp[1][i] = 0.0;
		}
		dp[0][0] = 1.0;
		for(int i = 0 ; i < n ; i++ ){
			for(int j = i ; j < s+5 ; j++ ){
				for(int k = 1 ; k < m+1 ; k++ ){
					if( s + 5 < j + k ) break;
					dp[1][j+k] += dp[0][j] * (1.0 / m);
				}
			}
			for(int j = i ; j < s+5 ; j++ ){
				dp[0][j] = dp[1][j];
				dp[1][j] = 0;
			}
		}
		double ans = 0.0;
		for(int i = 1 ; i < s+5 ; i++ ){
			if( i - k <= 1 ){
				ans += dp[0][i];
			}else{
				ans += dp[0][i] * (i - k);
			}
		}
		printf("%.8f\n", ans);
	}
}

Measured memory_bytes: 1348
from collections import deque
N,Q = map(int,input().split())
AB = [[] for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  AB[a-1].append(b-1)
  AB[b-1].append(a-1)

count = [0]*N

for i in range(Q):
  p,x = map(int,input().split())
  count[p-1] += x

used = [0]*N
used[0] = 1
que = deque([0])

while que:
  i = que.popleft()
  for j in AB[i]:
    if used[j] != 0:
      continue
    used[j] = 1
    count[j] += count[i]
    que.append(j)

print(*count)


Measured memory_bytes: 56084
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
        self.size = [1] * n
        self.group_num = n

    def root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.root(self.table[x])
            return self.table[x]

    def get_size(self, x):
        r = self.root(x)
        return self.size[r]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def union(self, x, y):
        r1 = self.root(x)
        r2 = self.root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.size[r1] += self.size[r2]
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
            self.size[r2] += self.size[r1]
        self.group_num -= 1



n, m = LI()
lan = [[] for _ in range(m)]
uf = UnionFind(n)
for j in range(n):
    L = LI()
    k = L[0]
    for i in range(1, k + 1):
        lan[L[i] - 1] += [j]


for ll in lan:
    for s in range(len(ll)):
        uf.union(ll[s], ll[s - 1])

if uf.group_num == 1:
    print('YES')
else:
    print('NO')


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

using namespace std;

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

    int a;
    string s;
    cin >> a >> s;

    if (a >= 3200) {
      cout << s << endl;
    } else {
      cout << "red" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {

    public static void main(String[] args) throws IOException, InterruptedException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        pw.println(n*(n-1)/2+m*(m-1)/2);
        pw.flush();
    }
    static int gcd(int x,int y){
        if (x==0)
            return y;
        return gcd(y%x,x);
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }

}

Measured memory_bytes: 21076
n, a, b = map(int,input().split())
s = input()
a_pass = 0
b_pass = 0

for i in s:
    if i == 'a' and a_pass + b_pass < a + b:
        print('Yes')
        a_pass += 1
    elif i == 'b' and a_pass + b_pass < a + b and b_pass < b:
        print('Yes')
        b_pass += 1
    else:
        print('No')

Measured memory_bytes: 9140
<?php
error_reporting(0);
//$N = explode(" ",trim(fgets(STDIN)));
list($A,$B,$C) = explode(" ",trim(fgets(STDIN)));
//$N=trim(fgets(STDIN));

$m = max($A,$B,$C);

$diff[]=$m-$A;
$diff[]=$m-$B;
$diff[]=$m-$C;
$sum = 0;
for($i=0;$i<3;$i++) {
  $s = floor($diff[$i]/2);
  $diff[$i]-= $s*2;
  $sum+=$s;
}
switch(array_sum($diff)) {
case 1:
  $sum+=2;
  break;
case 2:
  $sum+=1;
  break;
}
printf("%d\n",$sum);


Measured memory_bytes: 3828
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 
int main(){ 
  string s;cin>>s;
  int n=s.size();
  for(int i=0;i<n;i++)
  {
    cout<<"x";
  }
}


Measured memory_bytes: 384
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
res = 0
d = defaultdict(int)
a = sorted(a)
a += [1e9+1]
tmp = 0
for i in range(n+1):
    if tmp < a[i] and tmp != d[tmp]:
        if tmp < d[tmp]:
            res += d[tmp] - tmp
        else:
            res += d[tmp]
        tmp = a[i]
        d[tmp] += 1
    else:
        tmp = a[i]
        d[tmp] += 1

print(res)


Measured memory_bytes: 19060
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int ans[250010], used[250010];

int main(){
	int N; cin >> N;
	vector<P> x;
	vector<int> arr;
	for(int i=0; i<N; i++){
		int xx; cin >> xx;
		x.push_back(P(xx, i+1));
		ans[xx] = i + 1;
		used[xx] = 1;
	}
	for(int i=1; i<=N*N; i++){
		if(used[i] == 0) arr.push_back(i);
	}
	sort(x.begin(), x.end());
	int cnt = 0, f = 0;
	for(int i=0; i<N; i++){
		cnt += x[i].second;
		if(cnt > x[i].first) f = 1;
	}
	cnt = 0;
	for(int i=N-1; i>=0; i--){
		cnt += N + 1 - x[i].second;
		if(cnt > N*N + 1 - x[i].first) f = 1;
	}
	if(f) cout << "No" << "\n";
	else{
		cout << "Yes" << "\n";
		int now = 0;
		for(int i=0; i<N; i++){
			for(int j=0; j<x[i].second - 1; j++){
				ans[arr[now]] = x[i].second;
				now++;
			}
		}
		now = N*N - N - 1;
		for(int i=N-1; i>=0; i--){
			for(int j=0; j<N - x[i].second; j++){
				ans[arr[now]] = x[i].second;
				now--;
			}
		}
		for(int i=1; i<=N*N; i++) cout << ans[i] << " ";
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 3964