akhauriyash/Code-Regression huggingface dataset:
from collections import deque

L = deque([])
S = str(input())
q = int(input())
Q = [[] for _ in range(q)] 

for i in range(len(S)):
    L.append(S[i])

for i in range(q):
    A = input().split()
    Q[i] = A

num = 0

for i in range(q):
    if Q[i][0] == '1':
        num ^= 1
    if Q[i][0] == '2':
        if num == 0:
            if Q[i][1] == '1':
                L.appendleft(Q[i][2])
            else:
                L.append(Q[i][2])
        else:
            if Q[i][1] == '2':
                L.appendleft(Q[i][2])
            else:
                L.append(Q[i][2])

if num:
    L.reverse()

print(''.join(L))

Measured memory_bytes: 44660
#include <stdio.h>
int main(){

  int n, m, i, j, product=0;
  int a[101][101];
  int b[101];

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

  for(j = 1; j <= m; j++){
    scanf("%d", &b[j]);
  }

  for(i = 1; i <= n; i++){
    product=0;
    for(j = 1; j <= m; j++){
      product = a[i][j] * b[j] + product;
    }
    printf("%d\n", product);
  }
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    int n;
    cin >> n;
    while(n % 111)
        n++;
    cout << n << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int r;
	int c;
	
	scanf("%d%d", &r, &c);
	
	while(r != 0 && c != 0) {
		if(r * c % 2 == 0) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
		
		scanf("%d%d", &r, &c);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int r, g, b;
  cin >> r >> g >> b;
  
  if ( (r*100+g*10+b)%4 == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

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

using namespace std;

int main() {
  string s;
  string a = "ACGT";
  cin >> s;

  int ans = 0;
  for(int i=0; i < s.size(); i++) {
    if(!(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')) continue;
    ans = max(ans, 1);
    for(int j=i+1; j < s.size(); j++) {
      if(s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') ans = max(ans, j-i+1);
      else break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
s=input()
stack=0
needleft=0
needright=0
for c in s:
    if c=='(':
        needright+=1
    else:
        if needright>0:
            needright-=1
        else:
            needleft+=1
s='('*needleft+s
s+=')'*needright
print(s)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long x,xx,yy,xxx=0,yyy=0,xxyy=0;
	cin>>xx>>yy>>x;
	xxx=xx-x;yyy=yy+x;
	xxyy=xxx/yyy;
	cout<<xxyy<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

//関数プロトタイプ宣言
void OddEven(int a, int b);

int main(void) 
{
	int a, b;

	scanf("%d %d", &a, &b);

	OddEven(a, b);

	return 0;
}

void OddEven(int a, int b) 
{
	if ( (a * b) % 2 == 0)
	{
		printf("Even");
	}
	else
	{
		printf("Odd");
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int ans;
signed main()
{
    char s[5];
    cin>>s;
    for(ri int i=0;i<3;i++) ans+=(s[i]=='o')*100;
    printf("%lld\n",ans+700);
    return 0;
}

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

int main(){
    vector<int> x(3001);
    vector<int> y(3001);
    int i=0;
    for(;;i++){
        cin >> x[i] >> y[i];
        if(x[i]==0 && y[i] == 0){
            break;
        }
    }
    for(int j=0;j<i;j++){
        cout << min(x[j],y[j]) << " " << max(x[j],y[j]) << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


Measured memory_bytes: 3084
from itertools import count, takewhile, accumulate
from functools import reduce

N = int(input())
D, X = map(int, input().split())
A = [int(input()) for _ in range(N)]

print(sum([len(list(takewhile(lambda x: x <= D, map(lambda x: a * x + 1, count())))) for a in A]) + X)


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

int main() {
	string S, result;
	cin >> S;
	bool IsYAKI = false;
	if (S[0] == 'Y')
		if (S[1] == 'A')
			if (S[2] == 'K')
				if (S[3] == 'I')
					IsYAKI = true;
	result = (IsYAKI == true) ? "Yes" : "No";
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD=1e9+7;
int main()
{
    ll h,a;
    cin>>h>>a;
    if(h%a) cout<<h/a+1;
    else cout<<h/a;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
s = [[""]*W]*H
for i in range(H):
    s[i] = input()
for i in range(1,H-1):
    for j in range(1,W-1):
        if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j+1] == "." and s[i][j-1] == "." and s[i][j] == "#":
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);
	int[] in = new int[5];

	for ( int i = 0; i < 5; i++ ) {
	    in[i] = stdin.nextInt();
	}
	Arrays.sort( in );
	System.out.print( in[4] );
	for (int i = 3; i >= 0; i-- ) {
	    System.out.print( " " + in[i] );
	}
	System.out.println();
    }
    
}

Measured memory_bytes: 17184
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

class UnionFind{
public:
    vector<int> par;
    vector<int> rank;
    vector<int> sz;
    int uf_size;

    UnionFind(int n){
        par.resize(n);
        rank.resize(n);
        sz.resize(n);
        uf_size = n;
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) rank[x]++;
        uf_size--;
        par[y] = x;
        sz[x] = sz[x] + sz[y];
        return true;
    }

    int size(int x){
        return sz[find(x)];
    }
};

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

    int n, m, k; cin>>n>>m>>k;
    UnionFind uf(n);
    vector<int> deg(n, 0);
    for(int i=0; i<m; i++){
        int u, v; cin>>u>>v;
        u--, v--;
        deg[u]++, deg[v]++;
        uf.unite(u, v);
    }

    for(int i=0; i<k; i++){
        int u, v; cin>>u>>v;
        u--, v--;
        if(uf.same(u, v)){
            deg[u]++, deg[v]++;
        }
    }

    for(int i=0; i<n; i++){
        cout << uf.size(i) - 1 - deg[i] << " \n"[i == n - 1];
    }

    return 0;
}

Measured memory_bytes: 2432
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  ll N,M;
  cin >> N >> M;
  int a = N;
  int b = 1+M;
  int flag = 1;
  for(int i = 1;i <= M;i++){
    if(flag%2==1){
      cout << b << " " << b+i << endl;
      b--;
      flag--;
     }else{
       cout << a << " " << a-(N-i) << endl;
       a--;
       flag++;
    }
  }
}


Measured memory_bytes: 3628
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a,b,sum=0;
		a = sc.nextInt();
		b = sc.nextInt();
		
		
		if((a+b)%3==0 || a%3==0 || b%3==0)
			System.out.println("Possible");
		else
			System.out.println("Impossible");
	}
}

Measured memory_bytes: 22868
# coding:utf-8

import sys
import math
import time
import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength

def brick(a,n,m,N):#ABC 148
  #n番目以降にmがあるか調べる
  if not m in a[n:]:
    print(N-(m-1))
  else:
    #b = copy.deepcopy(a)
    brick(a,a[n:].index(m),m+1,N)

#X = str(input()).split()
#a = [int(x) for x in input().split()]
HA = str(input()).split()
H = int(HA[0])
A = int(HA[1])
a = [int(x) for x in input().split()]

count = 0

if(H<A):
    print(0)
else:
    a.sort()
    for i in range(H-A):
        count += a[i]
    print(count)


Measured memory_bytes: 43192
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct edge{ll to, cost;}; //edgeパラメータ
typedef pair<ll,ll> P;
struct graph{
  ll N; //ノードの個数
  vector<vector<edge> > G; //G[辺の元]((.to辺の先,.costコスト),...)
  vector<ll> dist; // dist[n] = ノードnまでのの重み
  vector<ll> parent;

  graph(ll n){ //グラフ生成時
    N = n+1;
    G.resize(N); //Edge情報
    dist.resize(N); //Node情報,ans
    parent.resize(N);
    rep(i,N){dist[i] = INF;}
  }

  void add_edge(ll s, ll t, ll cost){
    //edge E; E.to=t; E.cost=cost;
    G[s].emplace_back((edge){t,cost});
  }

  void dijkstra(ll s){
    rep(i,N){dist[i] = INF;}
    dist[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que; //ansが小さい順に出る
    que.push(P(0,s)); // P < ans , Node >
    while(!que.empty()){
      P p = que.top(); que.pop(); //pに <ans,Node> 入れる
      ll v = p.second; //vに Node 入れる
      if(dist[v] < p.first) continue; //すでに良い数値が入っているならパス
      for(auto E : G[v]){
        if(dist[E.to] > dist[v] + E.cost){ //更新するなら
          dist[E.to] = dist[v]+ E.cost;
          parent[E.to] = v;
          que.push(P(dist[E.to], E.to));
        }
      }
    }

  }
};

void Main(){

  ll N,M;

  cin>>N>>M;

  graph g(N);
  rep(i,M){
    int a,b,cost;
    cin>>a>>b>>cost;
    g.add_edge(a-1,b-1,cost);
    g.add_edge(b-1,a-1,cost);
  }

  set<pair<ll,ll>> se;

  rep(i,N){
    g.dijkstra(i);

    rep(j,N){
      if(i==j) continue;
      ll now=j;
      while(now!=i){
        ll pare=g.parent[now];
        se.insert({max(pare,now),min(pare,now)});
        now=pare;
      }
    }

  }

  cout << M-se.size() <<"\n";

}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 384
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
#define lc (x<<1)
#define rc ((x<<1)|1)
const int N=105;
char s[N];
int main(){
   // freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,n;
    scanf("%s",s+1);n=strlen(s+1);
    for (i=1;i<=n-8;i++) putchar(s[i]);
    puts("");

    return 0;
}


Measured memory_bytes: 256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define vz(x) x.size()
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
// const int N = ;
const int INF = 1e9 + 50;
const int MOD = 1e9 + 7;
int n;

int main() {
  in(n);
  vector <ii> v(n);
  for (int i = 0 ; i < n ; i++) {
    in(v[i].fi); in(v[i].se);
  }
  bool ok = 0;
  for (int i = 2 ; i < n ; i++) {
    if (v[i].fi == v[i].se && v[i - 1].fi == v[i - 1].se && v[i - 2].fi == v[i - 2].se) {
      ok = 1;
    }
  }
  puts(ok ? "Yes" : "No");
  return 0;
}

void in(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 3628
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val m = scn.nextInt()
	val dict = mutableMapOf<Int, Pair<Boolean, Int>>()
	repeat(m){
		val p = scn.nextInt()
		val s = scn.next()
		if (!dict.containsKey(p)){
			dict[p] = Pair(false, 0)
		}
		val d = dict[p]!!
		when(s){
			"AC" -> {
				dict[p] = Pair(true, d.second)
			}
			"WA" -> {
				if (!d.first) dict[p] = Pair(d.first, d.second+1)
			}
		}
	}

	val fd = dict.filterValues { pair -> pair.first }
	print(fd.size.toString()+" "+fd.values.sumBy { pair -> pair.second })
}

Measured memory_bytes: 75600
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
	return ans;
}
int yakusuunowa(int n) {
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (n%i == 0)ans += i;
	}
	return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int ketanowa(int n) {
	int cnt = 0, sum = 0;
	for (int i = 10; i <= n * 10; i *= 10) {
		if (i == 10)cnt += n % i;
		else sum += (n%i - n % (i / 10)) / (i / 10);
	}
	return cnt + sum;
}
pair<int, int>a[114514];
signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i].first>>a[i].second;
	sort(a, a + n);
	cout << a[n - 1].first + a[n - 1].second << endl;
	ll
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  double v[n];
  for(int i=0;i<n;i++)cin >> v[i];

  sort(v,v+n);

  double s=v[0];
  for(ll i=1;i<n;i++){
    s=(s+v[i])/2;
  }
  printf("%.8f",s);


}

Measured memory_bytes: 3696
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));
    int ans = abs(a[n - 1] - a[0]);
    cout << ans << "\n";
}


Measured memory_bytes: 256
num = [int(e) for e in input().split()]
men = [int(e) for e in input().split()]

N = num[0]
K = num[1]
i = 0
J = []
while i<=(N-1):
    if men[i]>= K:
        J.extend([i])
    i += 1
can = int(len(J))
print(can)


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

int main(void){
    int q; cin >> q;
    int dp[1001][1001];
    for(int i = 0; i < 1001; i++) dp[0][i] = dp[i][0] = 0;

    for(int i = 0; i < q; i++){
        string a, b; cin >> a >> b;
        int len_a = (int)a.size(), len_b = (int)b.size();
        for(int j = 1; j <= len_a; j++){
            for(int k = 1; k <= len_b; k++){
                if(a[j-1]==b[k-1]) dp[j][k] = dp[j-1][k-1] + 1;
                else dp[j][k] = max(dp[j-1][k], dp[j][k-1]);
                // cout << "(j, k) = " << j << ", " << k << ": dp = " << dp[j][k] << '\n';
            }
        }

        cout << dp[len_a][len_b] << '\n';
    }

    return 0;
}



Measured memory_bytes: 7048
#include <cstdint>

template <std::uint_fast64_t mod> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 v;

  constexpr modint(const u64 x = 0) noexcept : v(x % mod) {}
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    v += rhs.v;
    if (v >= mod)
      v -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (v < rhs.v)
      v += mod;
    v -= rhs.v;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    v = v * rhs.v % mod;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = mod - 2;
    while (exp != 0) {
      if (exp % 2 != 0)
        *this *= rhs;
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

#include <iostream>
#include <vector>

template <class T> T pow(T a, int b) {
  T res = 1;
  while (b != 0) {
    if (b % 2 != 0) {
      res *= a;
    }
    a *= a;
    b /= 2;
  }
  return res;
}

template <class T> void multiple_zeta(std::vector<T> &a) {
  int n = a.size();
  for (int i = 1; i != n; i += 1) {
    for (int j = 2 * i; j < n; j += i) {
      a[i] += a[j];
    }
  }
}

template <class T> void multiple_mobius(std::vector<T> &a) {
  int n = a.size();
  for (int i = n; i != 1;) {
    i -= 1;
    for (int j = 2 * i; j < n; j += i) {
      a[i] -= a[j];
    }
  }
}

int main() {
  using mint = modint<1000000007>;

  int n, k;
  std::cin >> n >> k;
  std::vector<mint> a(k + 1, 1);
  a[0] = 0;
  multiple_zeta(a);
  for (int i = 1; i != k + 1; i += 1) {
    a[i] = pow(a[i], n);
  }
  multiple_mobius(a);
  mint ans = 0;
  for (int i = 1; i != k + 1; i += 1) {
    ans += a[i] * i;
  }
  std::cout << ans.v << std::endl;
}


Measured memory_bytes: 4048
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N, M;
   cin >> N >> M;
   ll A[N];
   priority_queue<ll> que;
   ll ans = 0;
   for (int i = 0; i < N; i++) {
      cin >> A[i];
      que.push(A[i]);
      ans += A[i];
   }

   for (int i = 0; i < M; i++) {
      ll tmp = que.top();
      que.pop();
      ll tmp2 = tmp / 2;
      ans -= tmp - tmp2;
      if (tmp2 != 0) que.push(tmp2);
      if (que.empty()) break;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 1912
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

int sx,sy,tx,ty;

int main(){
  cin>>sx>>sy>>tx>>ty;
  int ab_x = tx - sx;
  int ab_y = ty - sy;
  for(int i = 0;i<ab_y;i++)
    cout<<"U";
  for(int i = 0;i<ab_x;i++)
    cout<<"R";
  for(int i = 0;i<ab_y;i++)
    cout<<"D";
  for(int i = 0;i<ab_x;i++)
    cout<<"L";
  cout<<"L";
  for(int i = 0;i<=ab_y;i++)
    cout<<"U";
  for(int i = 0;i<=ab_x;i++)
    cout<<"R";
  cout<<"DR";
  for(int i = 0;i<=ab_y;i++)
    cout<<"D";
  for(int i = 0;i<=ab_x;i++)
    cout<<"L";
  cout<<"U"<<endl;
  

  return 0;
}


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

titles=[]
times=[]

for i in range(N):
    data=input().split(" ")
    titles.append(data[0])
    times.append(int(data[1]))

X=input()


index=titles.index(X)

ans=0

for i in range(index+1,N):
    ans+=times[i]

print(ans)




Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	int m = n, k = 0;
	while(m){
		k += m % 10;
		m /= 10;
	}
	if(n % k == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

ll f(ll n) {
    ll ans = 0;
    while(n % 2 == 0) {
        ans++;
        n /= 2;
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll cnt = f(a[0]);
    ll lcm = a[0];
    if (cnt == 0) {
        cout << 0 << endl;
        return 0;
    }
    reps(i, 1, n) {
        if (cnt != f(a[i])) {
            cout << 0 << endl;
            return 0;
        }
        lcm = lcm / __gcd(lcm, a[i]) * a[i];
    }
    ll ans = m / (lcm / 2) - m / lcm;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cout<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int ans;
string s;
bool cf,ff;

main(){
    cin>>s;
    cout<<(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'?"Yes":"No")<<endl;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int main() {
    vector<bool> f(110, false);
    int n, k;
    cin >> n >> k;
    rep(i, k){
        int d; cin >> d;
        rep(j, d){
            int a; cin >> a;
            f[a] = true;
        }
    }
    int res = 0;
    for(int i = 1; i <= n; i++){
        if(f[i] == false) res++;
    }
    cout << res << ln;
}



Measured memory_bytes: 3628
## global variables

$ccache = []

### subroutines

def count(n)
  return 1 if n == 0
  return $ccache[n] if ! $ccache[n].nil?

  c = 0

  for i in (1..3)
    break if n < i
    c += count(n - i)
  end

  $ccache[n] = c
end

### main

while true
  n = gets.strip.to_i
  break if n == 0

  c = count(n)

  puts (c.to_f / 3650).ceil
end

Measured memory_bytes: 6108
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    over=0
    n=int(input())
    aa=LI()
    cnt=[0]*8
    for a in aa:
        if a>=3200:over+=1
        else:cnt[a//400]=1
    s=sum(cnt)
    print(max(1,s),s+over)

main()

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(){  
	int n,m,s=0;
	cin>>n>>m;
	int a[m];
	for(int i=0;i<m;i++){ cin>>a[i];}
	for(int i=0;i<m;i++){ s+=a[i];}	                                
	if(s <= n){ cout<<n-s;}else if(s>n){cout<<-1;}
	
}

Measured memory_bytes: 3192
#include <stdio.h>
 
void Shuffle(int [],int,int);
 
int main(void)
{
    int fuda[50];
    int r,n,c,i,p,j;
    while(1){
    do {
        scanf("%d %d",&n,&r);
        if(n == 0 && r == 0) goto LOOP;
    }while((0 > n) || (n > 51) || (0 > r) || ( r > 51));
    for(i = n - 1;i >= 0;i--){
        fuda[i] = n - i;
    }
     
    while(r > 0){
        do{
        scanf("%d %d",&p,&c);
        }while(!((p + c) <= (n + 1)));
        Shuffle(fuda,p,c);
        r--;
    }
    printf("%d\n",fuda[0]);
    }
    LOOP:
    return 0;
}
 
void Shuffle(int FUDA[],int p,int c){
    int wark[50],i,j;
    for(i = p - 1,j = 0;i < p + c - 1 ;i++,j++){
    wark[j] = FUDA[i];
    }
    for(i = p - 2;i >= 0;i--){
        FUDA[i + c] = FUDA[i];
    }
    for(i = 0;i < c;i++){
        FUDA[i] = wark[i];
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

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

  string S; cin >> S;
  int N = S.size();
  bool ok{};
  for(int i=1;i<N-1;i++){
    if(S[i-1] != S[i+1]){
      ok = true;
      break;
    }
  }
  if(ok){
    if(S[0] != S[N-1]){
      if(N % 2 == 1){
        cout << "First" << endl;
      }
      else{
        cout << "Second" << endl;
      }
    }
    else{
      if(N % 2 == 0){
        cout << "First" << endl;
      }
      else{
        cout << "Second" << endl;
      }
    }
  }
  else{
    cout << "Second" << endl;
  }
}

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

using namespace std;

void Main() {
    string SA, SB, SC;
    cin >> SA >> SB >> SC;

    int ia = 0;
    int ib = 0;
    int ic = 0;
    char turn = 'a';
    while (true) {
        if (turn == 'a') {
            if (ia == SA.size()) {
                cout << "A" << endl;
                return;
            }
            else {
                turn = SA[ia];
                ++ia;
            }
        }
        else if (turn == 'b') {
            if (ib == SB.size()) {
                cout << "B" << endl;
                return;
            }
            else {
                turn = SB[ib];
                ++ib;
            }
        }
        else {
            if (ic == SC.size()) {
                cout << "C" << endl;
                return;
            }
            else {
                turn = SC[ic];
                ++ic;
            }
        }
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3528
# C - Make a Rectangle

import collections

N = int(input())
A = list(map(int, input().split()))

# 2ペア以上ある棒のうち長い方から4本取ればよい

A_count = collections.Counter(A)
A_count = A_count.most_common()
pairs = [A_count[idx] for idx in range(len(list(A_count))) if A_count[idx][1] >= 2]
pairs = sorted(pairs, key = lambda x: x[0], reverse = True)

if len(pairs) == 0:
    print(0)
elif len(pairs) == 1 and pairs[0][1] < 4:
    print(0)
elif pairs[0][1] >= 4:
    print(pairs[0][0]**2)
else: 
    print(pairs[0][0] * pairs[1][0]) 

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

int main(){
  int n; cin >> n;
  
  vector<int> a(n); vector<int> b(n); vector<int> c(n-1);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  for(int i=0;i<n-1;i++){
    cin >> c[i];
  }
  int sum; sum=0;
  for(int i=0;i<n;i++){
    sum=sum+b[a[i]-1];
  }
  for(int i=0;i<n-1;i++){
    if(a[i]+1==a[i+1]){
      sum=sum+c[a[i]-1];
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

int main(int argc, char* argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	set<int> sets['z' + 1];
	int n;
	cin>>n;
	string s;
	cin >> s;
	s.insert(0, "#");
	for (int i = 1; i < s.size(); i++)
		sets[s[i]].insert(i);
	int q;
	cin >> q;
	while (q--)
	{
		int t;
		cin >> t;
		if (t == 1)
		{
			int pos;
			char c;
			cin >> pos >> c;
			sets[s[pos]].erase(pos);
			s[pos] = c;
			sets[c].insert(pos);
		}
		if (t == 2)
		{
			int l, r, res = 0;
			cin >> l >> r;
			for (int i = (int)'a'; i <= (int)'z'; i++)
			{
				if (sets[i].upper_bound(r) != sets[i].lower_bound(l))
					res++;
			}
			cout << res << endl;
		}
	}
}

Measured memory_bytes: 24348
import sys
import bisect
from itertools import zip_longest
from operator import itemgetter
readline = sys.stdin.readline
a,b,q = map(int, input().split(' '))
S = [int(readline()) for _ in range(a)]
T = [int(readline()) for _ in range(b)]
Q = [int(readline()) for _ in range(q)]
st = list(zip_longest([],S,fillvalue = 1))+list(zip_longest([],T,fillvalue = 2))
st.sort(key=itemgetter(1))
st_plc = [x[1] for x in st]
for i,x in enumerate(Q):
    nb = bisect.bisect(st_plc, x)
    if nb == 0:
        print(max(S[0],T[0])-x)
    elif nb == a+b:
        print(x-min(S[-1],T[-1]))
    else:
        if st[nb-1][0] == 1:
            nb2 = bisect.bisect(T,st_plc[nb-1])
            if nb2 == 0:
                ans1 = (x-st_plc[nb-1])*2 + (T[0]-x)
            elif nb2 == b:
                ans1 = x-T[-1]
            else:
                ans1 = x-st_plc[nb-1] + min(T[nb2]-st_plc[nb-1],st_plc[nb-1]-T[nb2-1])
        elif st[nb-1][0] == 2:
            nb2 = bisect.bisect(S,st_plc[nb-1])
            if nb2 == 0:
                ans1 = (x-st_plc[nb-1])*2 + (S[0]-x)
            elif nb2 == a:
                ans1 = x-S[-1]
            else:
                ans1 = x-st_plc[nb-1] + min(S[nb2]-st_plc[nb-1],st_plc[nb-1]-S[nb2-1])
        if st[nb][0] == 1:
            nb2 = bisect.bisect(T,st_plc[nb])
            if nb2 == 0:
                ans2 = T[0]-x
            elif nb2 == b:
                ans2 = (st_plc[nb]-x)*2 + (x-T[-1])
            else:
                ans2 = st_plc[nb]-x + min(T[nb2]-st_plc[nb],st_plc[nb]-T[nb2-1])
        elif st[nb][0] == 2:
            nb2 = bisect.bisect(S,st_plc[nb])
            if nb2 == 0:
                ans2 = S[0]-x
            elif nb2 == a:
                ans2 = (st_plc[nb]-x)*2 + (x-S[-1])
            else:
                ans2 = st_plc[nb]-x + min(S[nb2]-st_plc[nb],st_plc[nb]-S[nb2-1])
        print(min(ans1,ans2))

Measured memory_bytes: 32452
use std::io;

fn ceil_div(x: u32, y: u32) -> u32 { return (x + y - 1) / y; }

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut split = buf.split_whitespace();
    let (n, x, t): (u32, u32, u32) = (split.next().unwrap().parse().unwrap(), split.next().unwrap().parse().unwrap(), split.next().unwrap().parse().unwrap());
    println!("{}", ceil_div(n, x) * t);
}


Measured memory_bytes: 2116
#include<bits/stdc++.h>
#define line cout<<endl;
#define space cout<<" ";
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI 3.141592653589793238
typedef long long int ll;

using namespace std;

const int N = 1e9+7;

vector<ll> wt(100005);
vector<ll> val(100005);

ll dp[105][100005];

ll knapsackone(ll n,ll w)
{
    if(n==0||w==0)
        return 0;

    if(dp[n][w]!=-1)
        return dp[n][w];

    if(wt[n]<=w)
    {
        return  dp[n][w] = max(val[n]+knapsackone(n-1,w-wt[n]),knapsackone(n-1,w));
    }
    else
        return dp[n][w] = knapsackone(n-1,w);
}



void solve()
{
    memset(dp,-1,sizeof(dp));
    ll n,w;
    cin>>n;
    cin>>w;

    for(int i=1;i<=n;i++)
    {
        cin>>wt[i];
        cin>>val[i];
    }

    ll ans = knapsackone(n,w);
    cout<<dp[n][w];
}


int main()
{
   ll t;
   t = 1;
  // cin>>t;

   while(t--)
   {
       solve();
       cout<<endl;
   }


}



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

int64_t f(int64_t n,int64_t x){
  return n/x;
}


int main(){
  int64_t a,b,x;
  cin>>a>>b>>x;
  int64_t ans;
  if(a==0)ans=f(b,x)+1;
  else ans=f(b,x)-f(a-1,x);
//  if(a%x==0 || b%x==0)ans++;
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << '\n';
}

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int q = 1;

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

Measured memory_bytes: 256
s1,s2,s3 = map(int,input())
s = [s1,s2,s3]
S = s.count(1)
if(S == 0):
    print(0)
if(S == 1):
    print(1)
if(S == 2):
    print(2)
if(S == 3):
    print(3)


Measured memory_bytes: 2940
import sys,queue,math,copy,itertools
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

while True:
    M,N,D = LI()
    if N == 0 : break

    S = []
    for _ in range(N):
        S.extend(LI())

    x = []
    for i in range(N):
        for j in range(M):
            y = [0 for _ in range(N*M)]
            for p in range(-D,D+1):
                q1 = j + (D - abs(p))
                q2 = j - (D - abs(p))
                if 0 <= i + p < N and 0 <= q1 < M:
                    y[(i+p) * M + q1] = 1
                if 0 <= i+ p < N and 0 <= q2 < M:
                    y[(i+p) * M + q2] = 1
            y[i * M + j] = 1
            x.append(y)
    x.append(S)

    z = []
    for i in range(N*M):
        b = 0
        for j in range(N*M+1):
            b <<= 1
            b += x[j][i]
        z.append(b)


    c = [True for _ in range(N*M)]
    b = 1 << (N * M)
    for i in range(N*M):
        for j in range(N*M):
            if z[j] & b and c[j]:
                for k in range(N*M):
                    if k == j or z[k] & b == 0: continue
                    z[k] ^= z[j]
                    c[j] = False
                break
        b >>= 1

    if z.count(1):
        print (0)
    else:
        print (1)


Measured memory_bytes: 10632
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, child[MAXN];
ll f[MAXN];
vector<int> a[MAXN];
ll ways[MAXN], res[MAXN], ways2[MAXN];
ll MOD = MODBASE;

ll binPowMod(ll a, ll b) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1LL) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1LL;
    }
    return res;
}

ll add(ll a, ll b) {
    return (a + b) % MOD;
}

ll sub(ll a, ll b) {
    return (a - b + MOD) % MOD;
}

ll mul(ll a, ll b) {
    return a * b % MOD;
}

ll rev(ll a) {
    return binPowMod(a, MOD-2);
}

void dfs(int u, int p) {
    int branch = 0;
    child[u] = 0;
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i];
        if (v == p) continue;
        dfs(v, u);
        child[u] += child[v] + 1;
        branch++;
    }
    ways[u] = f[child[u]]; 
    if (branch) {
        FOR(i,0,SZ(a[u])-1) {
            int v = a[u][i];
            if (v == p) continue;
            ways[u] = mul(ways[u], ways[v]);
            ways[u] = mul(ways[u], rev(f[child[v] + 1]));
        }
    }
}

void dfs2(int u, int p) {
    res[u] = f[n-1];
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i];
        if (v == p) {
            res[u] = mul(res[u], ways2[v]);
            res[u] = mul(res[u], rev(f[n-1-child[u]]));
        }
        else {
            res[u] = mul(res[u], ways[v]);
            res[u] = mul(res[u], rev(f[child[v] + 1]));
        }
    }
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i];
        if (v == p) continue;
        ways2[u] = mul(res[u], mul(rev(ways[v]), mul(f[child[v] + 1], mul(rev(f[n-1]), f[n-1-child[v]-1]))));
        // cout << u << ' ' << v << ' ' << ways2[u] << endl;
        dfs2(v, u);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    f[0] = 1;
    FOR(i,1,n) f[i] = mul(f[i-1], i);
    FOR(i,1,n-1) {
        int u, v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    dfs(1, 0);
    dfs2(1, 0);
    FOR(i,1,n) cout << res[i] << "\n";
    return 0;
}


Measured memory_bytes: 20352
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
    if(s[0]==s[1] && s[2]==s[3] && s[2]!=s[0])
    {
    	cout<<"Yes"<<endl;
    	return 0;
    }
    if(s[0]==s[2] && s[1]==s[3] && s[1]!=s[0])
    {
    	cout<<"Yes"<<endl;
    	return 0;
    }
    if(s[0]==s[3] && s[1]==s[2] && s[1]!=s[0])
    {
    	cout<<"Yes"<<endl;
    	return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
// #define int long long
#define pb emplace_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;
 
#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif
 
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
 
ll pwr(ll a,ll b, ll mod){
    a %= mod;
   	ll ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
 
string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
void debug1(int a[], int l,int r) {
	#ifdef LOCAL
		vector<int> temp(a + l, a + r + 1);
		debug(temp);
	#endif
}

const int N = 1005;
const int MAX = 5005;

bool dp[N][MAX];
vector<pii> v[N];
int x[N], p[N];

void solve(){
	int n;
	cin >> n;
	fr(i, 2, n) {
		cin >> p[i];
	}
	fr(i, 1, n) {
		cin >> x[i];
	}
	for(int i = n; i >= 1; i--) {
		fr(j, 0, sz(v[i])) {
			fr(k, 0, MAX - 1) {
				dp[j][k] = 0;
			}
		}
		dp[0][0] = 1;
		int tot = 0;
		fr(j, 0, sz(v[i]) - 1) {
			tot += v[i][j].fi;
			tot += v[i][j].se;
			fr(k, 0, MAX - 1) {
				if(!dp[j][k]) continue;
				if(k + v[i][j].fi < MAX) {
					dp[j + 1][k + v[i][j].fi] = 1;
				}
				if(k + v[i][j].se < MAX) {
					dp[j + 1][k + v[i][j].se] = 1;
				}
			}
		}
		int z = -1;
		fr(j, 0, x[i]) {
			if(dp[sz(v[i])][j])
				z = j;
		}
		if(z == -1) {
			cout << "IMPOSSIBLE";
			return;
		}
		v[p[i]].pb(x[i], tot - z);
	}
	cout << "POSSIBLE";
}

signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
} 

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

int main(){
  string s;
  cin >> s;
  int l = s.size();
  
  int count = 0;
  for(int i = 0; i < l/2; i++){
    if(s.at(i) == s.at(l - i - 1)){
    }
    else{
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
"use strict";
function Main(input) {
  const args = input.split('\n');
  const N = parseInt(args.shift());
  const ws = args.shift().split(' ')
  .map( m => parseInt(m));
  let s2 = ws.reduce((p, c) => p + c);
  let s1 = 0;
  for (let i = 0; i < N; i++) {
    const s1b = s1;
    const s2b = s2;
    s1 += ws[i];
    s2 -= ws[i];
    if (s2 <= s1) {
      const ret1 = s1 - s2;
      const ret2 = s2b - s1b;
      console.log(ret1 < ret2 ? ret1 : ret2);
      return;
    }
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  int L, R, d;
  cin >> L >> R >>d;
  int ans=0;
  for(int i=L; i<=R; i++){
    if(i%d==0){
      ans++;
    }
  }

  cout << ans << endl;

return 0;
}


Measured memory_bytes: 3588