akhauriyash/Code-Regression huggingface dataset:
N, M = (int(x) for x in input().split())

A = [list(map(int, input().split())) for i in range(M)]

X = ['0' for i in range(N)]#0で埋めつくす
X[0] = '1'
for i in A:
    X[i[0] - 1] = str(i[1])#条件関係なしに代入
    #print(X)

F = 1
for i in A:
    if N > 1 and i[0] == 1 and i[1] == 0:#条件から逸脱する条件
        F = 0
    for j in A:
        #print(j)
        if i[0] == j[0] and i[1] != j[1]:
            F = 0
            
if N == 1 and M == 0:
    print(0)
elif F == 1:
    print(''.join(X))
else:
    print(-1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    int Q;
    cin >> Q;

    int N = (int)S.size();
    deque<char> deq;
    for (int i = 0; i < N; i++) {
        deq.push_back(S[i]);
    }

    int ord = 0;
    for (int q = 0; q < Q; q++) {
        int T;
        cin >> T;
        if (T == 1) {
            ord ^= 1;
        } else if (T == 2) {
            int F;
            char C;
            cin >> F >> C;
            F--;
            if ((ord ^ F) == 0) {
                deq.push_front(C);
            } else {
                deq.push_back(C);
            }
        }
    }

    if (ord == 0) {
        while (!deq.empty()) {
            char c = deq.front();
            deq.pop_front();
            cout << c;
        }
    } else if (ord == 1) {
        while (!deq.empty()) {
            char c = deq.back();
            deq.pop_back();
            cout << c;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3988
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

//vector//
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

typedef pair<int,int> P;  //q(p.first,p.second)

struct Point{
    double x,y;
};

void KochCurve(int n, Point a, Point b){

    if(n==0) return;

    Point s,t,u;
    double th = M_PI * 60.0 / 180.0;
    s.x = (2.0 * a.x + 1.0 * b.x)/3.0;
    s.y = (2.0 * a.y + 1.0 * b.y)/3.0;
    t.x = (1.0 * a.x + 2.0 * b.x)/3.0;
    t.y = (1.0 * a.y + 2.0 * b.y)/3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    KochCurve(n-1, a, s);
    cout << s.x << ' ' << s.y << endl;
    KochCurve(n-1, s, u);
    cout << u.x << ' ' << u.y << endl;
    KochCurve(n-1, u, t);
    cout << t.x << ' ' << t.y << endl;
    KochCurve(n-1, t, b);
}

int main (){
    int n;
    cin >> n;

    Point a,b;
    a.x = 0.0;
    a.y = 0.0;
    b.x = 100.0;
    b.y = 0.0;

    // cout << a.x << ' ' << a.y << endl;
    printf("%.8f %.8f\n",a.x,a.y);
    KochCurve(n, a, b);
    // cout << b.x << ' ' << b.y << endl;
    printf("%.8f %.8f\n",b.x,b.y);

}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  vll a(4); rep(i, 4) cin >> a[i];
  sort(all(a));
  fin(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9?"YES":"NO")
  return;
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
  double r;
  cin >> r;
  double ans=2*r*3.14159265;
  cout << fixed <<setprecision(7)<< ans << endl;
  
}


Measured memory_bytes: 3764
using System;

class Program
{
  public static void Main(string[] args)
  {
    int a = int.Parse(Console.ReadLine());
    int b = int.Parse(Console.ReadLine());
    int c = int.Parse(Console.ReadLine());
    int x = int.Parse(Console.ReadLine());
    int count = 0;
    for (int i = 0; i <= a; i ++) {
      for (int j = 0; j <= b; j ++) {
        for (int k = 0; k <= c; k ++) {
          if(500 * i + 100 * j + 50 * k == x) count ++;
        }
      }
    }
    Console.WriteLine(count);
  }
}


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

S=[[-1]*N for _ in range(N)]
for i in range(N):
  A=int(input())
  for _ in range(A):
    x, y=map(int, input().split())
    S[i][x-1]=y
ans=0   
for s in range(2**N):
  ok=True
  for i in range(N):
    #正直者について見ていく
    if (s>>i&1)==1:
      for j in range(N):
        #それぞれ正直者の証言が矛盾ないか
        if S[i][j]!=-1 and (s>>j&1)!=S[i][j]:
          ok=False
  if ok:
    ans=max(ans, bin(s).count("1"))
    
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

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

  int mi = 0;
  int ma = 1000000;
  int L, R;
  REP(i, 0, M){
    cin >> L;
    cin >> R;
    mi = max(mi, L);
    ma = min(ma, R);
  }

  cout << max(ma - mi + 1, 0) << endl;

  return 0;
}


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

typedef long long ll;

const int MAXN = 1e5 + 10;

int vis[MAXN][2], N;
ll dp[MAXN][2], arr[MAXN];

ll solve(int a, int sign){
	if(a == N) return (sign == 0) ? arr[a] : -arr[a];
	if(vis[a][sign]) return dp[a][sign];
	vis[a][sign] = 1;
	if(sign == 0) return dp[a][sign] = max(arr[a] + solve(a+1,0), -arr[a] + solve(a+1, 1));
	else return dp[a][sign] = max(-arr[a] + solve(a+1,0), arr[a] + solve(a+1, 1));
}

int main(){

	cin >> N;
	for(int i = 1;i<=N;i++) cin >> arr[i];

	cout << solve(1, 0) << endl;

	return 0;

}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define var(n) int n; scn(n)
#define F first
#define S second 
#define pb push_back
const int N=1e5+5;
// const ll M = 998244353;
const ll M=1e9+7;
const ll inf=1e18;

ll dp[102][N]; // dp[i] is the maximum value wih weight i

int main()
{
	var(n);var(w);
	rep(i,1,n+1)
	{
		var(wt);
		var(val);
		for(int j=1;j<=w;j++)
		{
			if(j>=wt)
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-wt]+val);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	lpri(dp[n][w]);
}

Measured memory_bytes: 78336
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node);
/*Node treeMaximum(Node);*/
Node treeSearch(Node,int);
Node treeSuccessor(Node);
void treeDelete(Node);
void insert(int);
void inorder(Node);
void preorder(Node);




int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t;
      t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
	else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
    else if(com[0]='m'){
      printf(" %d\n",treeMinimum(root)->key);
    }
  }

  return 0;
}

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
      }
  return x;

}

/*Node treeMaximum(Node x){


} */

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key)
    return u;
    if(k<u->key) return treeSearch(u->left,k);
    else  return treeSearch(u->right,k);


}

Node treeSuccessor(Node x){
  
  if(x->right!=NIL)
    return treeMinimum(x->right);
  Node y = x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
  

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL)
    y=z;
  else y=treeSuccessor(z);
  if(y->left!=NIL)
    x=y->left;
  else
    x=y->right;
  if(x!=NIL)
    x->parent=y->parent;
  if(y->parent==NIL)
    root=x;
  else if(y==y->parent->left)
    y->parent->left=x;
  else
    y->parent->right=x;
  if(y!=z)
    z->key=y->key;
  free(y);


  }

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key)
      x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)
    root=z;
  else if(z->key < y->key)
    y->left=z;
  else
    y->right=z;
 




}

void inorder(Node u){
  if(u->left==NIL&&u->right==NIL){
    printf(" %d",u->key);
    return;
  }
   if(u->left!=NIL)
  inorder(u->left);
  printf(" %d",u->key);
  if(u->right!=NIL)
  inorder(u->right);

}
void preorder(Node u){
  if(u->left==NIL&&u->right==NIL){
    printf(" %d",u->key);
      return;
  }
  printf(" %d",u->key);
  if(u->left!=NIL)
  preorder(u->left);
  if(u->right!=NIL)
  preorder(u->right);

}



Measured memory_bytes: 20492
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  long long int q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;

  h = min(h, q*2);
  s = min(s, h*2);
  d = min(d, s*2);

  long long int ans = 0;
  ans += d * (n / 2);
  n %= 2;
  ans += s * n;
  cout << ans << endl;

  return 0;
}



//


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

using namespace std;

typedef long long ll;

string beautify(string str) {
	string ret = "";
	for (int i = 0; i < str.size(); ++i) {
		char c = str[i];
		if ('a' <= c && c <= 'z') ret += c;
		else if ('A' <= c && c <= 'Z') ret += (char)(c-'A'+'a');
	}
	return ret;
}

class Dice {
private:
	int v[6];

public:
	int GetTop() {
		return v[0];
	}
	int GetFront() {
		return v[1];
	}
	int GetRight() {
		return v[2];
	}
	void Rotate(char op) {
		int newV[6];
		switch (op) {
		case 'N':
			newV[0] = v[1];
			newV[1] = v[5];
			newV[2] = v[2];
			newV[3] = v[3];
			newV[4] = v[0];
			newV[5] = v[4];
			break;

		case 'S':
			newV[0] = v[4];
			newV[1] = v[0];
			newV[2] = v[2];
			newV[3] = v[3];
			newV[4] = v[5];
			newV[5] = v[1];
			break;

		case 'E':
			newV[0] = v[3];
			newV[1] = v[1];
			newV[2] = v[0];
			newV[3] = v[5];
			newV[4] = v[4];
			newV[5] = v[2];
			break;

		case 'W':
			newV[0] = v[2];
			newV[1] = v[1];
			newV[2] = v[5];
			newV[3] = v[0];
			newV[4] = v[4];
			newV[5] = v[3];
			break;
		}
		for (int i = 0; i < 6; ++i) v[i] = newV[i];
	}
	void Spin(char op) {
		switch (op) {
		case 'R':
			Rotate('N');
			Rotate('E');
			Rotate('S');
			break;

		case 'L':
			Rotate('N');
			Rotate('W');
			Rotate('S');
			break;
		}
	}
	Dice(int v1, int v2, int v3, int v4, int v5, int v6) {
		v[0] = v1;
		v[1] = v2;
		v[2] = v3;
		v[3] = v4;
		v[4] = v5;
		v[5] = v6;
	}
};

int main() {
	int v[6];
	for (int i = 0; i < 6; ++i) cin >> v[i];
	Dice dice(v[0], v[1], v[2], v[3], v[4], v[5]);

	int n; cin >> n;
	for (int q = 0; q < n; ++q) {
		int t, f; cin >> t >> f;
		int v = -1;
		for (int k = 0; k < 4; ++k) {
			for (int i = 0; i < 4; ++i) {
				for (int j = 0; j < 4; ++j) {
					if (dice.GetTop() == t && dice.GetFront() == f) {
						v = dice.GetRight();
						break;
					}
					dice.Rotate('N');
				}
				if (v != -1) break;
				dice.Spin('R');
			}
			if (v != -1) break;
			dice.Rotate('E');
		}
		cout << v << endl;
	}
}

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

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

  string S[3];
  cin >> S[0] >> S[1] >> S[2];
  rep(i, 3){
    S[i][0] -= 32;
  } 
  cout << S[0][0] << S[1][0] << S[2][0] << endl;
}

Measured memory_bytes: 256
class segtree:
    def __init__(self, bin_level):
        self.bl = bin_level
        self.st = [[0 for __ in range(1<<_)] for _ in range(bin_level+1)]
    
    def st_make(self, n, arr):
        for j in range(n):
            tmp = j
            for i in range(self.bl, -1, -1):
                self.st[i][tmp] += arr[j]
                tmp >>= 1
    
    def st_add(self, i, p):
        tmp = i
        for i in range(self.bl, -1, -1):
            self.st[i][tmp] += p
            tmp >>= 1
    
    def st_sum(self, x):
        if x < 0:
            return 0
        S = 0
        pnt = 0
        b = 1 << (self.bl)
        for i in range(self.bl+1):
            pnt <<= 1
            if x >= b:
                S += self.st[i][pnt]
                pnt += 1
                x -= b
            b >>= 1
        return S

N, Q = map(int, input().split())
def powlimit(n):
    y = 1
    cnt = 0
    while y < n:
        y *= 2
        cnt += 1
    return cnt
st = segtree(powlimit(N))
st.st_make(N, list(map(int, input().split())))
for i in range(Q):
    t, l, r = map(int, input().split())
    if t:
        print(st.st_sum(r) - st.st_sum(l))
    else:
        st.st_add(l, r)

Measured memory_bytes: 144716
inp=[int(input()) for _ in range(5)]
k=int(input())
flg=True
for i in range(len(inp)-1):
    if flg:
        for j in range(i+1,len(inp)):
            if inp[j]-inp[i]>k:
                print(':(')
                flg=False
                break
if flg:
    print('Yay!')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,m,r,s,k,c1,c2,c3,c4,i;
    c1=c2=c3=c4=0;
    cin>>n;
    string ch;
    for(i=0;i<n;i++){
        cin>>ch;
        if(ch=="AC")c1++;
        else if(ch=="WA")c2++;
        else if(ch=="RE")c3++;
        else if(ch=="TLE")c4++;
    }
    cout<<"AC x "<<c1<<endl;
    cout<<"WA x "<<c2<<endl;
    cout<<"TLE x "<<c4<<endl;
    cout<<"RE x "<<c3<<endl;
}


Measured memory_bytes: 3576
#include <cstdio>
#include <set>
#include <iostream>

const int STEP_NUM = 4;
const int STEP[STEP_NUM][STEP_NUM] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

const int MAX_SIZE = 1000;
char field[MAX_SIZE + 1][MAX_SIZE + 1];

const int MAXN = 10;
int locationsX[MAXN];
int locationsY[MAXN];
 
int H, W, N;

int get_shortest_distance(int current_HP)
{
	int sx = locationsX[current_HP-1];
	int sy = locationsY[current_HP-1];
	int ex = locationsX[current_HP];
	int ey = locationsY[current_HP];

	bool is_visit[H + 1][W + 1]={};
	
	std::set<std::pair<int,int>> frontier;
	frontier.insert(std::pair<int,int>{sx,sy});
	int nx,ny;
	for(int step=0;step<100000000;step++)
	{
		for(auto p:frontier)
		{
			if(p.first==ex && p.second==ey)	return step;
			is_visit[p.first][p.second] = true;
		}
		std::set<std::pair<int,int>> next_frontier;
		for(auto p:frontier)
		{
			for(int i=0;i<STEP_NUM;i++)
			{
				nx = p.first+STEP[i][0];
				ny = p.second+STEP[i][1];
				if(nx<0 || H<=nx) 		continue;
				if(ny<0 || W<=ny) 		continue;
				if(field[nx][ny]=='X') 	continue;
				if(is_visit[nx][ny]) 	continue;
				next_frontier.insert(std::make_pair(nx,ny));
			}
		}
		frontier = next_frontier;
	}
	return -1;
}

int solve()
{
	int total_step = 0;
	for(int i=1;i<N+1;i++)
		total_step += get_shortest_distance(i);
	return total_step;
}

int main()
{
	scanf("%d %d %d", &H, &W, &N);
	for(int i=0; i<H; i++)
		scanf("%s", field[i]);
	for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
		{
			int HP=-1;
			if(field[i][j]=='S')	HP=0;
			if(field[i][j]=='1')	HP=1;
			if(field[i][j]=='2')	HP=2;
			if(field[i][j]=='3')	HP=3;
			if(field[i][j]=='4')	HP=4;
			if(field[i][j]=='5')	HP=5;
			if(field[i][j]=='6')	HP=6;
			if(field[i][j]=='7')	HP=7;
			if(field[i][j]=='8')	HP=8;
			if(field[i][j]=='9')	HP=9;
			if(HP!=-1)
			{
				locationsX[HP]=i;
				locationsY[HP]=j;
			}
		}
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 5068
// https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, K;
  cin >> N >> K;

  VL as(N);
  rep(i, N) cin >> as[i];

  // 一回の操作で配列の合計が 2 倍程度になる
  // よって O(log(N)) 程度の操作で収束。

  rep(ki, K) {
    VL bs(N + 1);

    rep(i, N) {
      bs[max(0ll, i - as[i])] += 1;
      bs[min(N, i + as[i] + 1)] -= 1;
    }

    rep(i, N) bs[i + 1] += bs[i];
    bs.pop_back();

    if (as == bs) break;

    swap(as, bs);
  }

  rep(i, as.size()) {
    if (i > 0) cout << " ";
    cout << as[i];
  }
  cout << "\n";
}


Measured memory_bytes: 6324
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll d[100];

int main(){
	clr(d,0);
	ll n,m;
	cin>>n>>m;
	rep(i,0,n){
		ll a;
		cin>>a;
		rep(i,0,a){
			ll b;
			cin>>b;
			b--;
			d[b]++;
		}
	}
	ll ans = 0;
	rep(i,0,m){
		if(d[i]==n)ans++;
	}
	cout << ans << endl;
 	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

x, y = map(int, input().split())
gloup_a = [1, 3, 5, 7, 8, 10, 12]
gloup_b = [4, 6, 9, 11]
gloup_c = [2]
if ((x in gloup_a) and (y in gloup_a)) or ((x in gloup_b) and (y in gloup_b)) or ((x in gloup_c) and (y in gloup_c)):
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

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

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int32_t main(){
    boost;
    string s;

    cin >> s;

    for(int i = 0 ; i < s.length()-1 ; ++i){
    	if(s[i] == s[i+1]){
    		cout << i+1 << " " << i+2;
    		return 0;
    	}
    }


    for(int i = 0 ; i < s.length()-2; ++i){
    	if(s[i] == s[i+2]){
    		cout << i+1 << " " << i+3;
    		return 0;
    	}
    }

    cout << -1 << " " << -1;
    return 0;
}

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

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
    int N,K,p[1010]={};
    cin>>N>>K;
    for(int i=0;i<N;i++){
        cin>>p[i];
    }

    sort(p,p+N);

    int ans =0;
    for(int i=0;i<K;i++){
        ans+=p[i];
    }

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

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
typedef pair<int, int> P;
 
char mapd[2000][2000];
int N, M;
int sx, sy;
int gx, gy;
 
int d[21][21];
 
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ans = 0;
void bfs() {
    queue<P> que;
    
    rep(i, N) rep(j, M) d[i][j] = INF;
    que.push(P(sx, sy));
    d[sx][sy] = 0;
 
    while(que.size()) {
        P p = que.front(); que.pop();
        //if (p.first == gx && p.second == gy) break;
        rep(i, 4) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && nx < N && 0 <= ny && ny < M && mapd[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
                ans = max(ans, d[nx][ny]);
                //cout << "d[" << nx << "][" << ny << "] = " << d[nx][ny] << endl;
            }
        }
    }
    return;
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    int H = N;
    int W = M;
    rep(i, H) rep(j, W) cin >> mapd[i][j];
    rep(i, H) rep(j, W) {
        if (mapd[i][j] == '.') {
            sx = i;
            sy = j;
            bfs();
        }
    }
    cout << ans << endl;

    

    return 0;
}


Measured memory_bytes: 256
'use strict'

const INF = 900719925474099;
function mapint(temp){
    return temp.split(' ').map((v)=>parseInt(v));
}

function lower_bound(d,a,b,e){
    for(var c;1<b-a;)
        d[c=0|(a+b)/2]<e ? a=c : b=c;
    return d[a]<e?b:a
};

const MOD = 1000000007;

function Main(input){
    let temp = input.trim();
    let t2 = mapint(temp);
    let n = t2[0];
    let l = t2[1];

    let f0=false;
    let a,sum=0;
    for(let i=0;i<n;i++){
      a = l + i;
      if(a==0) f0=true;
      sum += a;
    }
    //console.log('sum:',sum,f0);
    if(f0==true) console.log(sum);
    else if(sum<0) console.log( sum - (l + n - 1));
    else console.log( sum - l );
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll dp[301][100000];
ll a[100000];

signed main(){
	int n,m,k;scanf("%d%d%d",&n,&m,&k);
	rep(i,n){
		scanf("%lld",&a[i]);
		dp[0][i]=a[i];
	}
	for(int i=1;i<k;i++){
		deque<ll>que;
		for(int j=1;j<n;j++){
			while(!que.empty()&&que.front()<j-m)que.pop_front();
			if(dp[i-1][j-1]){
				while(!que.empty()&&dp[i-1][que.back()]<=dp[i-1][j-1])que.pop_back();
				que.push_back(j-1);
			}
			if(!que.empty())dp[i][j]=dp[i-1][que.front()]+(i+1)*a[j];
		}
	}
	ll Max=0;
	rep(i,n)Max=max(Max,dp[k-1][i]);
	cout<<Max<<endl;
}

Measured memory_bytes: 235904
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 200005
#define M 100000
bool mark[N];
int xi[N],E,L,R;
vector <int> G[N];
void dfs(int now,bool l) {
	E ++;
	if(mark[now]) return ;
	mark[now] = 1;
	if(l) L ++;
	else R ++;
	for(int i=0; i<G[now].size(); i++) {
		int e = G[now][i];
		dfs(e,!l);
	}
	return ;
}
int main () {
	int n;
	scanf("%d",&n);
	for(int i=1,x,y; i<=n; i++) {
		scanf("%d%d",&x,&y);
		G[x].push_back(y+M),G[y+M].push_back(x);
	}
	LL ans = 0;
	for(int i=1; i<=M; i++) {
		if(!mark[i]) {
			E = -1,L = 0,R = 0;
			dfs(i,1);
			if(L < 2 || R < 2) continue;
			ans += 1LL*L*R - E/2;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11136
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    x,y,a,b,c = LI()
    p = LI()
    q = LI()
    r = LI()
    s = [(i,0) for i in p]+[(i,1) for i in q]+[(i,2) for i in r]
    s.sort(reverse = True)
    ans = 0
    f = [0,0]
    l = [x,y]
    q = deque()
    q2 = deque()
    for a,i in s:
        if i > 1:
            q.append(a)
        else:
            if f[i] < l[i]:
                ans += a
                f[i] += 1
                q2.append(a)
    s = ans
    while q and q2:
        s -= q2.pop()
        s += q.popleft()
        if ans < s:
            ans = s
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 115308
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n; cin>>n;
    int d[n];
    rep(i,0,n) cin>>d[i];
    ll ans=0;
    rep(i,0,n-1){
        rep(j,i+1,n){
            ans+=d[i]*d[j];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    lint X;
    cin >> X;
    lint ans=0;
    lint f,f2;
    f=X/500;
    ans+=f*1000;
    X-=f*500;
    ans+=(X/5)*5;
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int,input().split(' '))
a = set([int(input()) for i in range(M)])
ans = [0]*(N+1)
ans[0] = 1
for i in range(1,N+1):
  if i in a:
    ans[i] = 0
  else:
    ans[i] = (ans[i-1]+ans[i-2])%(10**9+7)
print(ans[N])

Measured memory_bytes: 13216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

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

        static int Solve(int N, int[] P)
        {
            int count = 0;
            for (int i = 0; i < N; ++i)
            {
                if (P[i] == i + 1)
                {
                    if (i + 1 < N)
                    {
                        int tmp = P[i];
                        P[i] = P[i + 1];
                        P[i + 1] = tmp;
                    }
                    ++count;
                }
            }
            return count;
        }

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


Measured memory_bytes: 18912
from collections import defaultdict
N, K = map(int, input().split())
nums = [int(i) for i in input().split()]

num_freq = defaultdict(int)
for num in nums:
    num_freq[num] += 1

_sorted_nums = [[i] * j for i,
                j in sorted(num_freq.items(), key=lambda x:x[1])]
sorted_nums = []
for i in _sorted_nums:
    sorted_nums += i

borders = []
for i in range(1, N):
    if sorted_nums[i-1] != sorted_nums[i]:
        borders.append(i)

if len(num_freq) <= K:
    print(0)
else:
    border = borders[-K]
    print(len(sorted_nums[:border]))


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

vector<vector<long long>> comb(int n, int r) {
  vector<vector<long long>> v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k])%1000000007;
    }
  }
  return v;
}

int main(){
    int N,K;
    cin>>N>>K;
    vector<vector<ll>> C=comb(N,N);
    for(int i=1;i<=K;i++){
        ll a=C[K-1][i-1];
        ll b=C[N-K+1][i];
        cout<<(a*b)%1000000007<<endl;
    }

    return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <string>
//#include <math.h>
using namespace std;

int main(){
  long long int a;
  cin >> a;
  long long int b;
  b = a / 500 * 1000;
  a = a - a / 500 * 500;
  b = b + a / 5 * 5;
  cout << b << '\n';
  return 0;
}


Measured memory_bytes: 256
//      https://youtu.be/X_hMZYDMps4

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

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;    // 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nl                  "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define pf                  push_front
#define all(x)              x.begin(),x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"

int main()
{
    fast;
    ll t,i,j,k,l,m,n,o,p,q,temp,ans=0,flag=0,mod=1000000007,odd=0,even=0;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>temp;
        if(temp%2) odd++;
        else even++;
    }
    if(odd%2 && n!=1) cout<<"NO";
    else cout<<"YES";
}


Measured memory_bytes: 3616
import numpy as np
from numpy.fft import rfft, irfft
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
X = np.zeros(10**5+1)
l = 2*(10**5)+10
for i in range(N):
    X[A[i]] += 1
data = np.rint(irfft(rfft(X, l)**2 ))
num = 0
ans = 0
for i in range(len(data) -1 ,0,-1):
    if data[i] != 0:
        if num + data[i] >= M:
            ans += (M - num) * i
            break
        else:
            ans += data[i]*i
            num += data[i]
print(int(ans))

Measured memory_bytes: 30000
import bisect
import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n,m=getints()

if abs(n-m) > 1:
    print(0)
    exit(0)

mod = 10**9 + 7
def factorial(n):
    res = 1
    for i in range(1,n+1):
        res *= i
        res %= mod
    return res

res = 0
if n == m:
    res = factorial(n) * factorial(m) * 2 % mod
else:
    res = factorial(n) * factorial(m) % mod

print(res)


Measured memory_bytes: 38512
l=int(input())
A=[int(input())for _ in range(l)]
dp=[0]*5
for i in range(l):
    a,b,c,d,e,f=dp+[A[i]]
    p=int(f==0)*2
    dp=[a+f,min(a,b)+f%2+p,min(a,b,c)+(f+1)%2,min(b,c,d)+f%2+p,min(b,c,d,e)+f]
print(min(dp))

Measured memory_bytes: 62552
#include<stdio.h>
 
int main(){
   int a,b,aa,ans;
   scanf("%d %d", &a,&b);
  ans = 1;
  aa = a;
   while(aa<b){
   		aa = a-1 + aa;
     	ans++;
   
   }
	if(b==1){ ans = 0;}
 
  	printf("%d", ans);
	return 0;
 
}

Measured memory_bytes: 128
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
inline int read(){
	int x=0,c=getchar(),f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(int x){
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

const int N = 105;
int n,sum;
int a[N];

int main(){
	n = read();
	for(int i = 1;i <= n;i++){
		a[i] = read();
		sum += a[i];
	}
	sort(a+1,a+n+1);
	if(sum % 10 != 0){
		printf("%d\n", sum);
		return 0;
	}
	for(int i = 1;i <= n;i++){
		if(a[i] % 10 != 0){
			printf("%d\n", sum-a[i]);
			return 0;
		}
	}
	printf("0\n");
	return 0;
}

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

using namespace std;
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

ll modpow(ll n,ll r){
  ll res = 1;
  while(r){
    if(r & 1)res = res*n%MOD;
    n = n*n%MOD;
    r >>= 1;
  }
  return res;
}

int main(){
  
  int n;
  cin >> n;
  ll res = 0;
  res = modpow(10,n);
  res = (res-modpow(9,n)+MOD)%MOD;
  res = (res-modpow(9,n)+MOD)%MOD;
  res = (res+modpow(8,n))%MOD;
  cout << res << "\n";
  



  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;

    for (int i = 1; i <= n; i += 1) {
        double x = i * 1.08;
        if (floor(x) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define BR cout<<endl;
#define LEN(s) s.length();
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod=1000000007;

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];

    rep(i,n){
        if(a[i]%2 == 0){
            if(a[i]%3==0 or a[i]%5==0){

            }
            else{
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;

    return 0;
}



Measured memory_bytes: 3564
// basically Ak=Ak-1*(adj matrix)// number of pairs having these paths so A1=adj=> A2=adj*A1.... Ak=(Adj)^k
// Ak=(adj)^k can be done in o(n^3Log(k)) time compx using binary exponentiation texhnique.

#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int mod=1e9 +7;

vector<vector<ll>> multipy(vector<vector<ll>> A, vector<vector<ll>> B ){

    int n=A.size();

    vector<vector<ll>> res(n,vector<ll>(n,0));

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){

            for(int x=0;x<n;x++){
                res[i][j]=(res[i][j]+A[i][x]*B[x][j])%mod;
            }
        }
    }

    return res;



}

vector<vector<ll>> power(vector<vector<ll>> mat,ll k){

    if(k==1){
        return mat;
    }

    vector<vector<ll>> res=power(mat,k/2);
    
    if(k%2==0){
        return multipy(res,res);

    }else{
        return multipy(res,multipy(res,mat));
    }


}


ll numberOfPathsWithKLength(vector<vector<ll>> mat, int n, ll k){

    vector<vector<ll>> res=power(mat,k);
    ll ans=0;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            ans+=res[i][j];
            ans%=mod;

        }
    }

    return ans;


}


int main() {
    int n;
    ll k;
    cin>>n>>k;

     vector<vector<ll>> mat(n,vector<ll> (n));

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

    cout<<numberOfPathsWithKLength(mat,n,k);

}



Measured memory_bytes: 4896
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define PI 3.14159265
#define ll long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 300000000000000001
#define infx 9223372036854775806
#define all(c) c.begin(),c.end()
#define mk(x,yy) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x,y)           (x>y)?x:y
#define min2(x,y)           (x<y)?x:y
#define mid(s,e)               (s+(e-s)/2)
#define mini                   INT_MIN
#define maxo                   INT_MAX
#define rep(i,a,b) for(int i=a;i<(int)(b);++i)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define show(a,n) for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl
#define ene cout<<"\n";

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll power(ll x,  ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
 
bool compr(std::vector<ll> a, std::vector<ll> b)
{
    if(a[0]==b[0])
        return a[1]<b[1];
    else
        return a[0]<b[0];
}

bool comp(std::vector<ll> a, std::vector<ll> b)
{
    if(a[1]==b[1]&&a[2]==b[2])
        return a[0]<b[0];
    else if(a[1]==b[1])
        return a[2]>b[2];
    else
        return a[1]<b[1];
}

vector<ll> dfs(vector<ll> adj[], ll x, ll visited[])
{
    visited[x] = 1;
    vector<ll> tmp;
    ll black = 1;
    ll white = 1;
    for(ll i=0;i<adj[x].size();i++)
    {
        if(visited[adj[x][i]]==0)
        {
            vector<ll> v = dfs(adj,adj[x][i], visited);
            black = (black*v[0])%mod;
            white = (white*(v[0]+v[1]))%mod;
        }
    }
    tmp.push_back(white);
    tmp.push_back(black);
    return tmp;
}
int main()
{
    #ifdef SHIVANSH 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> adj[n];
    for(ll i=0;i<n-1;i++)
    {
        ll x,y;
        cin>>x>>y;
        x--;y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    ll visited[n] = {};
    vector<ll> v = dfs(adj,0,visited);
    cout<<(v[0]+v[1])%mod<<endl;
}

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

int main(){
	int a, b, c;
	int tmp;
	cin >> a >> b >> c;
	
	if(a > b){
		tmp = a;
		a = b;
		b = tmp;
	}
	if(b > c){
		tmp = b;
		b = c;
		c = tmp;
	}
	if(a > b){
		tmp = a;
		a = b;
		b = tmp;
	}
	cout << a <<" " << b << " " << c << endl;
    return 0;
}

Measured memory_bytes: 3104
<?php
list($N, $K, $Q) = explode(" ", trim(fgets(STDIN)));

$arr = array_fill(0, $N, $K-$Q);

for ($i = 0; $i < $Q; $i++) {
	$a = intval(trim(fgets(STDIN)));
	$arr[$a-1]++;
}

for ($i = 0; $i < $N; $i++) {
	echo ($arr[$i] <= 0 ? 'No' : 'Yes') . PHP_EOL;
}


Measured memory_bytes: 9080
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
#define MAXN 1000
#define MAXM 2000
#define MO 1000000007
#define LL long long
int n,m;
LL x,sum;
int diff[MAXM+5],fa[MAXN+5];
LL bits[MAXM+5];
int deep[MAXN+5],val[MAXN+5];
bool used[MAXM+5];
vector<int>G[MAXN+5],W[MAXN+5];
struct node
{
	int u,v,len;
}line[MAXM+5];
bool cmp(node a,node b)
{
	return a.len<b.len;
}
void Pre()
{
	bits[0]=1;
	for(int i=1;i<=m;i++)
		bits[i]=(2LL*bits[i-1])%MO;
}
int FindSet(int x)
{
	if(fa[x]==0) return x;
	fa[x]=FindSet(fa[x]);
	return fa[x];
}
void Build(int u,int pa)
{
	fa[u]=pa;
	deep[u]=deep[pa]+1;
	for(int i=0;i<G[u].size();i++)
		if(G[u][i]==pa)
			val[u]=W[u][i];
		else Build(G[u][i],u);
}
int Find_max(int u,int v)
{
	int ret=0;
	if(deep[u]<deep[v])
		swap(u,v);
	while(deep[u]>deep[v])
	{
		ret=max(ret,val[u]);
		u=fa[u];
	}
	while(u!=v)
	{
		ret=max(ret,max(val[u],val[v]));
		u=fa[u],v=fa[v];
	}
	return ret;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&x);
	for(int i=0;i<m;i++)
		scanf("%d%d%d",&line[i].u,&line[i].v,&line[i].len);
	sort(line,line+m,cmp);
	Pre();
	for(int i=0;i<m;i++)
	{
		int u=FindSet(line[i].u);
		int v=FindSet(line[i].v);
		if(u!=v)
		{
			fa[u]=v;
			sum+=line[i].len;
			used[i]=1;
			G[line[i].u].push_back(line[i].v);
			G[line[i].v].push_back(line[i].u);
			W[line[i].u].push_back(line[i].len);
			W[line[i].v].push_back(line[i].len);
		}
	}
	x=x-sum;
	if(x<0)
	{
		printf("0");
		return 0;
	}
	memset(fa,0,sizeof fa);
	Build(1,0);
	int cnt=0;
	for(int i=0;i<m;i++)
		if(!used[i])
		{
			int maxd=Find_max(line[i].u,line[i].v);
			diff[++cnt]=line[i].len-maxd;
		}
	sort(diff+1,diff+1+cnt);
	LL ans=0;
	if(x==0)
		ans=(bits[m]-2LL*bits[m-n+1]+2LL*MO)%MO;
	for(int i=1;i<=cnt;i++)
		if(diff[i]==x)
		{
			ans+=2LL*bits[cnt-i];
			ans%=MO;
		}
	printf("%lld\n",ans);
}

Measured memory_bytes: 512
while True:
    try:
        f = [list(raw_input()) for _ in xrange(3)]
    except EOFError:
        break
    g = map(lambda x:"".join(x),
            f+zip(*f)+zip(*[(f[i][i],f[2-i][i]) for i in xrange(3)]))
    print "b" if "b"*3 in g else "w" if "w"*3 in g else "NA"

Measured memory_bytes: 4216
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;


int main(){
	int n,m;
	cin>>n>>m;
	int c[10];
	rep(i,10)cin>>c[i];
	int minc=*min_element(c,c+10);
	if(m<n*minc){
		cout<<"NA"<<endl;
		return 0;
	}

	string digit;
	while(digit.size()<n && (n-digit.size())*minc<=m){
		int b=-1;
		rep(i,10){
			if((n-digit.size()-1)*minc+c[i]<=m){
				b=i;
				break;
			}
		}
		m-=c[b];
		digit+=b+'0';
	}
	cout<<digit<<endl;
	return 0;
}


Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
bool checkValue(long long v){
    while(v>0){
        if((v%7!=0)||(v%10==0))return false;
        v/=10;
    }
    return true;
}
int main(){
    long long x;
    cin >> x;
    unsigned long long value = 7;
    set <long long> result;
    long long cnt = 0;
    while(value>0){
        cnt++;
        //cout << value%x << endl;
        value = value%x;
        if(value==0){
            cout << cnt << endl;
            return 0;
        }
        //if(result.size()%10000!=0){
            //for(long long i = 0; i < result.size(); i++){
                //if(result[i]==value){
                    //cout << -1 << endl;
                    //return 0;
                //}
            //}
        //}
        if(result.count(value)!=0){
            cout << -1 << endl;
            return 0;
        }
        result.insert(value);
        value = value*10+7;
    }
    return 0;
}

Measured memory_bytes: 50476
A = int(input())
B = int(input())
C = int(input())
X = int(input())
n = X // 500 + 1
count = 0
for i in range(n):
  if i <= A:
    m = (X-500*i)//100+1
    for j in range(m):
      if j <= B and (X-500*i - 100*j) % 50 == 0 and ((X-500*i - 100*j) / 50) <= C:
        if not (i==0 and j ==0 and ((X-500*i - 100*j) / 50)==0): 
          count += 1

print(count)
    

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 100005
#define M 305
#define INF 1000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
ll dp[2*N];
ll fac[2*N];
ll rev[2*N];
ll inv[2*N];
ll get(ll x,ll y)
{
    if(x == 0||y == 0)return 1;
    return fac[x+y]*rev[x]%MOD*rev[y]%MOD;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m,a,b;
    while(cin>>n>>m>>a>>b)
    {
        fac[1] = 1;
        rev[1] = inv[1] = 1;
        FOR(i,2,m+n)
        {
            fac[i] = fac[i-1]*i%MOD;

            ll t = MOD / i;
            ll k = MOD % i;
            inv[i] = (MOD - t) * inv[k] % MOD;
            rev[i] = rev[i-1]*inv[i]%MOD;
        }
        ll ans = 0;
        ll j = b+1;
        for(ll i = n-a;i>0&&j<=m;i--,j++)
        {
            //cout<<i-1<<" "<<j-1<<" "<<n-i<<" "<<m-j<<" "<<get(i,j)<<" "<<get(n-i,m-j)<<endl;
            ans = (ans+get(i-1,j-1)*get(n-i,m-j)%MOD)%MOD;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

set<string> S;
string s;
int K;
vector<string> V;
int main(void) {

	cin >> s;
	cin >> K;
	int N = s.size();


	string str;
	for (int i = 0; i <= 5005;i++) {
		str += "z";
	}
	for (int i = 0; i < K; i++) { V.push_back(str); }

	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			string tmp=s.substr(i, j - i + 1);
			int sign = 0;
			for (int m = 0; m < K; m++) { if (V[m] == tmp) { sign = 1; break; } }
			if (sign == 1) { continue; }
			if (V[K - 1] > tmp) { V[K - 1] = tmp; sort(V.begin(), V.end()); }

		}
	}

	
	cout << V[K-1] << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
   ll a,b;cin>>a>>b;
   ll lcm;
   ll g=__gcd(a,b);
   lcm=a*b/g;
   cout<<lcm<<endl;
}

Measured memory_bytes: 256