akhauriyash/Code-Regression huggingface dataset:
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, W = rli()
	weight = [0 for _ in range(n)]
	val = [0 for _ in range(n)]
	for i in range(n):
		w, v = rli()
		weight[i], val[i] = w, v
	#dp(i, j) = max val using items 1,...,i at 
	#			weight j

	dp = [[NINF for c in range(W+1)] for r in range(n+1)]
	for r in range(n+1):
		dp[r][0] = 0
	for c in range(W+1):
		dp[0][c] = 0
	for r in range(1, n+1):
		w, v = weight[r-1], val[r-1]
		for c in range(1, W+1):
			dp[r][c] = dp[r-1][c]
			if c - w >= 0:
				dp[r][c] = max(dp[r][c], dp[r-1][c], v + dp[r-1][c-w])
	print(dp[-1][-1])
	stdout.close()

if __name__ == "__main__":
	main()

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

string inttos(int num)
{
    return to_string(num);
}

int stoint(string sss)
{
    return stoi(sss);
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));	
	int a,b,c,k;
	cin >> a >> b >> c >>k;
	int ans = 0;
	int x = min(k,a);
	ans += x;
	k = k-x;
	x = min(k,b);
	k = k-x;
	x = min(k,c);
	k = k -x;
	ans -= x;
	cout << ans;
}


Measured memory_bytes: 3632
from sys import stdin,stdout
for _ in range(1):#int(stdin.readline())):
    n=int(stdin.readline())
    a=list(map(int,stdin.readline().split()))
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if len(set([a[i],a[j],a[k]]))==3 and a[i]+a[j]>a[k] and a[j]+a[k]>a[i] and a[i]+a[k]>a[j]:ans+=1
    print(ans)

Measured memory_bytes: 9208
n = int(input())
a = list(map(int,input().split()))


b = [None]*n
b[0] = a[0]

for i in range(n-1):
    b[i+1] = (b[i] + a[i+1]) % 1000000007;

con = 0;

for v in range(1,n):
    x = (a[-v] * b[-v-1]) % 1000000007;
    con = (con + x) % 1000000007;

print(con)

Measured memory_bytes: 31432
#include<iostream>
#include<cstring> 
using namespace std;
int main()
{
	char a[20];
	int n,A=0,B=0,C=0,ans=0;
	cin>>n;
	while(n--)
	{
		cin>>a;
		int len = strlen(a);
		if(a[0]=='B')
		B++;
		if(a[len-1]=='A')
		A++;
		if(a[0]=='B'&&a[len-1]=='A')
		C++;
		for(int i=0;i<len;i++)
		{
			if(a[i]=='A'&&a[i+1]=='B')
			ans++;
		}
	}
	int t;
	if(A>B) 
	t = B;
	else
	t = A;
	if(A == C&&B == C&&C!=0)
		ans--;
	cout<<ans+t;
	return 0;
}

Measured memory_bytes: 256
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    var tableC = [[Int]](repeating: [Int](repeating: 0, count: 3), count: 3)
    for i in 0..<3 {
        tableC[i] = readInts()
    }
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var isMatch = true
    let diff = [tableC[0][0] - tableC[0][1], tableC[0][1] - tableC[0][2]]
    for i in 1..<3 {
        if tableC[i][0] - tableC[i][1] != diff[0] || tableC[i][1] - tableC[i][2] != diff[1] {
            isMatch = false
        }
    }
    print(isMatch ? "Yes": "No")
}
main()


Measured memory_bytes: 13564
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define si scanf
#define so printf
#define N 
#define M 
#define INF  
template<typename TP>inline bool rd(TP& r)
{
	r=0;
	char tmp=getchar();
	while(tmp<'0'||tmp>'9')
	{
		if(tmp==EOF)
			return 0;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		r=(r<<3)+(r<<1)+tmp-'0';
		tmp=getchar();
	}
	return 1;
	
} 
long long n,a,b;
int main()
{
	rd(n),rd(a),rd(b);
	if(n==1)
	{
		if(a==b)
			so("1\n");
		else
			so("0\n");
		return 0;
	}
	if(a>b)
	{
		so("0\n");
		return 0;
	}
	so("%lld\n",((n-1)*b+a)-((n-1)*a+b)+1);
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)
 
#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
//grobal var
//------------------------------------------

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int W,H,x,y;
  while(cin >> W >> H >> x >> y){
    int ans2=0;
    double ans1=(double)W*H/2.0;
    if((double)x==(double)W/2.0&&(double)y==(double)H/2.0) ans2=1;
    printf("%f %d\n",ans1,ans2);
  }

  return 0;
}

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

#define MAX_H 5000
#define MAX_N 300
#define MAX_M 150

short dx1[7] = { 0,1,1,0,-1,-1,0 };
short dy1[7] = { 1,0,-1,-1,-1,0,0 };
short dx2[7] = { 0,1,1,0,-1,-1,0 };
short dy2[7] = { 1,1,0,-1,0,1,0 };
short dp[2][MAX_N + 1][MAX_N + 1], n, sx, sy, gx, gy, x, y, lx, ly;
short X[MAX_N + 1][MAX_N + 1], minx = (1 << 14);

int main() {
	cin >> sx >> sy >> gx >> gy;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		X[x + MAX_M][y + MAX_M] = 1;
	}
	cin >> lx >> ly;
	for (int i = 0; i <= MAX_N; i++) {
		for (int j = 0; j <= MAX_N; j++) {
			if (abs(i - MAX_M) > lx || abs(j - MAX_M)>ly) {
				X[i][j] = 1;
			}
		}
	}
	memset(dp, 127, sizeof(dp));
	dp[0][sx + MAX_M][sy + MAX_M] = 0;
	for (int i = 0; i < MAX_H; i++) {
		for (int j = 0; j < MAX_N; j++) {
			for (int k = 0; k < MAX_N; k++) {
				dp[(i + 1) % 2][j][k] = (1 << 14);
			}
		}
		for (int j = 0; j <= MAX_N; j++) {
			for (int k = 0; k <= MAX_N; k++) {
				if (dp[i % 2][j][k] < (1 << 14)) {
					int t = abs(i*(j - MAX_M)*(k - MAX_M)) % 6;
					if (abs(j - MAX_M) % 2 == 0) {
						for (int l = 0; l < 7; l++) {
							if (l == t) {
								if (X[j + dx1[l]][k + dy1[l]] == 0) {
									dp[(i + 1) % 2][j + dx1[l]][k + dy1[l]] = min(dp[(i + 1) % 2][j + dx1[l]][k + dy1[l]], dp[i % 2][j][k]);
								}
							}
							else {
								if (X[j + dx1[l]][k + dy1[l]] == 0) {
									dp[(i + 1) % 2][j + dx1[l]][k + dy1[l]] = min(dp[(i + 1) % 2][j + dx1[l]][k + dy1[l]], (short)(dp[i % 2][j][k] + 1));
								}
							}
						}
					}
					if (abs(j - MAX_M) % 2 == 1) {
						for (int l = 0; l < 7; l++) {
							if (l == t) {
								if (X[j + dx2[l]][k + dy2[l]] == 0) {
									dp[(i + 1) % 2][j + dx2[l]][k + dy2[l]] = min(dp[(i + 1) % 2][j + dx2[l]][k + dy2[l]], dp[i % 2][j][k]);
								}
							}
							else {
								if (X[j + dx2[l]][k + dy2[l]] == 0) {
									dp[(i + 1) % 2][j + dx2[l]][k + dy2[l]] = min(dp[(i + 1) % 2][j + dx2[l]][k + dy2[l]], (short)(dp[i % 2][j][k] + 1));
								}
							}
						}
					}
				}
			}
		}
		minx = min(minx, min(dp[0][gx + MAX_M][gy + MAX_M], dp[1][gx + MAX_M][gy + MAX_M]));
	}
	if (minx == (1 << 14)) { cout << "-1" << endl; }
	else { cout << minx << endl; }
	return 0;
}

Measured memory_bytes: 3628
n, y = map(int,input().split())
m,g,s = 0,0,y // 1000
ans = ["-1","-1","-1"]

for i in range(2001):
    for j in range(2001):
        if s - n == 9 * i + 4 * j and n-i-j>=0:
            ans[0] = str(i)
            ans[1] = str(j)
            ans[2] = str(n-i-j)
            break

print(' '.join(ans))

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

int main() {
	int W, H, N, x, y, a;
	cin >> W >> H >> N;
	int xmin = 0, xmax = W, ymin = 0, ymax = H; // 白い長方形の領域
	for (int i = 0;i < N;i ++) {
		cin >> x >> y >> a;
		switch(a) {
			case 1: // xi未満の領域を全て塗りつぶす
				xmin = max(xmin, x);
				break;
			case 2: // xiより大きい領域を全て塗りつぶす
				xmax = min(xmax, x);
				break;
			case 3: // yi未満の領域を全て塗りつぶす
				ymin = max(ymin, y);
				break;
			case 4: // yiより大きい領域を全て塗りつぶす
				ymax = min(ymax, y);
				break;
		}
	}
	if (xmax < xmin) cout << 0;
	else if (ymax < ymin) cout << 0;
	else cout << (xmax - xmin) * (ymax - ymin);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

各方向に独立なので、まずa_i==1の時で考えよう
この時、複数のa_i==1のデータがあり、その時の与えられたxが順にx_1,...,x_nとするよ
そうすると、max(x_1,...,x_n)の中に全ての塗りつぶし領域が来るから、1個のmax(x_1,...,x_n)のデータを受け取った時と同じになるわけだ
同様にa_i==2,...,a_i==4についても1個に纏められるから、実質4個のデータだけ持てばいいのね
後は塗られていない領域を調べるのは簡単
*/

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  if (count(ALL(a), 1) == 0) {
    cout << -1 << '\n';
    return 0;
  }
  int now = 1;
  REP(i, n) {
    if (a[i] == now) ++now;
  }
  cout << n - now + 1 << '\n';
  return 0;
}


Measured memory_bytes: 1024
def d_decrease(K):
    # 1つ要素を選び、値を+Nし、それ以外の要素を-1する。この操作後に、
    # 選んだ要素の値が最大となり、その他の要素の値が負でない
    # ようにしたい。そのためには、range(N)という数列を考え、0番からN-1番の順に
    # 上の操作を行っていくことをK回行えばいい。N回操作を行うごとに数列全体の要素が
    # 1ずつ増えるので、最後の K%N 回だけシミュレーションすればいい。
    N = 50  # Nの値の制約による
    q, r = K // N, K % N  # q回数列全体は+1され、r回シミュレーションする
    seq = list(map(lambda x: x + q, range(N)))
    for i in range(r):
        seq[i] += N
        for j in range(N):
            if i != j:
                seq[j] -= 1
    ans = '{}\n{}'.format(N, ' '.join(map(str, seq)))
    return ans

K = int(input())
print(d_decrease(K))

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

typedef long long int64;

#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
    int64 n, w;
    scanf("%lld %lld", &n, &w);

    int64 *arr[2] = {
        malloc(sizeof(int64) * n),
        malloc(sizeof(int64) * n),
    };
    
    for(int64 i = 0; i < n; i++) 
        scanf("%lld %lld", &arr[0][i], &arr[1][i]);

    int64 *dp = malloc(sizeof(int64) * (w + 1));
    memset(dp, 0, (w + 1) * sizeof(int64));
    
    for(int64 i = 0; i < n; i++) {
        int64 wi = arr[0][i];
        int64 ci = arr[1][i];

        for(int64 curr_w = w - wi; curr_w >= 0; curr_w--) {
            dp[curr_w + wi] = max(dp[curr_w + wi], dp[curr_w] + ci);
        }

    }
    
    int64 result = 0;
    for(int64 i = 0; i <= w; i++)
        if(dp[i] > result)
            result = dp[i];

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



Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace  std;
int A[2000], n;
int solve (int i,int m)
{
    if(m==0) return 1;
    if(i >=n) return 0;
    int res = solve(i+1,m) || solve(i+1, m-A[i]);
    return res;
}
int main()
{
    
    cin >>n;
    for(int i = 0;i<n;i++)
    {
        cin >>A[i];
    }
    int q;
    cin >>q;
    for(int i = 0;i<q;i++)
    {
        int m;
        cin >>m;
        if(solve(0,m)) printf("yes\n");
        else printf("no\n");
    }
    
    return 0;
}



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

const int MAXN = 805;

struct point {
	int x, y, d;
};

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

int n, m, k;
char str[MAXN][MAXN];
int vis[MAXN][MAXN];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++)
		cin >> str[i]+1;
	point rt;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (str[i][j] == 'S')
				rt = (point){i, j, 0};
	static queue<point> que;
	int ans = INT_MAX;
	auto div_up = [](int a, int b){ return a/b+(a%b!=0); };
	vis[rt.x][rt.y] = 1, que.push(rt);
	while (!que.empty()) {
		point nd = que.front(); que.pop();
		if (nd.d > k) continue;
		ans = min(ans, div_up(min(min(nd.x-1, n-nd.x), min(nd.y-1, m-nd.y)), k)+1);
		for (int i = 0; i < 4; i++) {
			int x = nd.x+dx[i], y = nd.y+dy[i];
			if (x < 1 || x > n || y < 1 || y > m || str[x][y] == '#' || vis[x][y]) continue;
			vis[x][y] = 1;
			que.push((point){x, y, nd.d+1});
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    for(ll i = 0; i <= 999; i++){
        ll first = i / 10 / 10 % 10;
        ll second = i / 10 % 10;
        ll third = i % 10;
        vector<ll> vec{first, second, third};
        ll flag = 0;
        for(ll j = 0; j < s.size(); j++){
            if(vec[flag] == (int)s[j] - 48){
                flag++;
                if(flag == 3){
                    break;
                }
            }
        }
        if(flag == 3) ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        mut n: i128,
    }

    let mut sum = n / 11 * 2;
    n = n % 11;
    if n > 6 { sum += 2 }
    if 6 >= n &&n > 0 { sum += 1 }

    println!("{}", sum);
}

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

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=Integer.parseInt(in.next()),A[]=new int[n];
        for(int i=0; i<n; i++) {
            A[i] =Integer.parseInt(in.next());
        }
        int q=Integer.parseInt(in.next());
        for(int i=0;i<q;i++) {
            int key = Integer.parseInt(in.next());
            if (Arrays.binarySearch(A, key) >= 0 ) {
                System.out.println(1);
            }
            else {
                System.out.println(0);
            }
        }
    }
}


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

int main() {
  string str; cin >> str;
  ll N = str.size();
  ll s[N+1];
  s[0] = 1;
  for (ll i = 0; i < N; i++) {
    s[i+1] = str[i] - '0';
  }
  if (s[1] == 0) {cout << -1 << endl; return 0;}
  if (s[N] == 1) {cout << -1 << endl; return 0;}
  for (ll i = 1; i <= N-1; i++) {
    if (s[i] != s[N-i]) {cout << -1 << endl; return 0;}
  }
  ll from = 0;
  vector<P> es;
  for (ll i = 1; i <= N-1; i++) {
    if (s[i-1] == 1 && from == i-1) {
      from++;
      es.push_back(P(from, i+1));
    }
    if (s[i-1] == 1 && from < i-1) {
      from = i;
      es.push_back(P(from, i+1));
    }
    if (s[i-1] == 0) {
      es.push_back(P(from, i+1));
    }
  }
  for (ll i = 0; i < es.size(); i++) {
    cout << es[i].first << " " << es[i].second << endl;
  }
}

Measured memory_bytes: 4080
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	long long int a,b,x;
	cin >> a >> b >> x;
    
    int temp = a;
    if(a == 0)
        a++;

    ll ans =  (ull)(b/x) - (ull)((a-1)/x);
    if(temp == 0)
        ans++;
    
    cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    long long memo[87];

    memo[0] = 2;
    memo[1] = 1;
    for (int i = 2; i <= N; ++i) {
        memo[i] = memo[i - 1] + memo[i - 2];
    }

    cout << memo[N] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  string s;
  cin>>s;
  Int ans=0;
  map<char,char> r;
  r['(']=')';
  r[')']='(';
  for(Int i=0;i<(Int)s.size()/2;i++)
    if(isalpha(s[i])) ans+=(s[i]!=s[s.size()-(i+1)]);
    else ans+=(r[s[i]]!=s[s.size()-(i+1)]);
  if(s.size()&1) ans+=!isalpha(s[s.size()/2]);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <cmath>

using namespace std;

int main(){
   long long N, K;
   cin >> N >> K;

   if(K==0){
      cout << N*N << endl;
      return 0;
   }

   long long ans = 0;
   for(long long b=K+1; b<=N; ++b){
      long long x = b-K;
      long long y = (N-K)/b;
      ans += x*y;
      ans += min(x,N-y*b-K+1);
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
from sys import exit
S = input()

if 0 < int(S[0:2]) < 13:
    if 0 < int(S[2:]) < 13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 0 < int(S[2:]) < 13:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 9084
mod=10**9+7
import math
n=int(input())
ans=1
l=[0]*n
for ii in range(2,n+1):
  i=ii
  for j in range(2,int(math.sqrt(i))+1):
    if i%j==0:
      cnt=0
      while  i%j==0:
        cnt+=1;i//=j
      l[j-1]+=cnt
  if i!=1:
    l[i-1]+=1
for i in l:
  ans*=(i+1)
  ans%=mod
print(ans)


Measured memory_bytes: 9116
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a > k){
        cout << ":(" << endl;
    }
    else {
        cout << "Yay!" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
U_MAP mp;
U_MAP mp1;
set<char> st;
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s>>k;
    rep(i,Size(s)){
        st.insert(s[i]);
    }
    if(Size(st)==1){
        ll moji=Size(s)*k;
        Cout(moji/2);
        return 0;
    }
    rrep(i,1,Size(s)){
        if(s[i]==s[i-1]&&mp[i-1]==0){
            mp[i]=1;
            cnt++;
        }
    }
    if(k==1){
        Cout(cnt);
        return 0;
    }
    ll cnt2=0;
    s+=s;
    rrep(i,1,Size(s)){
        if(s[i]==s[i-1]&&mp1[i-1]==0){
            mp1[i]=1;
            cnt2++;
        }
    }
    ll kousa=cnt2-cnt;
    ll syo=cnt;
    ans=syo+(k-1)*kousa;
    Cout(ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

typedef pair<int, int> p;
const int W = 0, H = 1;


int main()
{
    int n, w, d;
    while(cin >> n >> w >> d && w )
    {
        vector<p> cakes;
        cakes.push_back(p(w, d));
        REP(n)
        {
            int pn, s; cin >> pn >> s; pn--;
            int side[2]; side[W] = cakes[pn].first; side[H] = cakes[pn].second;
            vector<p>::iterator it = cakes.begin();
            rep(j,pn)++it;
            
            cakes.erase(it);
            int sn = W;
            while(side[sn] < s)
            {
                s -= side[sn];
                sn = (sn + 1) % 2;
            }
            int neww[2];
            neww[0] = min(s, side[sn] - s); neww[1] = max(s, side[sn] - s);
            if(sn == W)
            {
                cakes.push_back(p(neww[0], side[H]));
                cakes.push_back(p(neww[1], side[H]));
            }
            else
            {
                cakes.push_back(p(side[W], neww[0]));
                cakes.push_back(p(side[W], neww[1]));
            }
        }
        vector<int> ans;
        REP(n + 1) ans.push_back(cakes[i].first * cakes[i].second);
        sort(all(ans));
        REP(n) cout << ans[i] << " ";
        cout << ans[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
/*

This Submission is to determine how many 120/240 min const. delivery point there are.

//info
120 req. steps <= 5
*/
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)

unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
int gogo[1000][1000] = {};
void solve(vector<int> now, int level) {
	if (now.size() == 1) return;
	vector<int> A, B;
	REP(q, now.size()) {
		if (q % 2 == 0) {
			A.push_back(now[q]);
		}
		else {
			B.push_back(now[q]);
		}
	}
	for (int i = 0; i < A.size(); ++i) {
		REP(q, B.size()) {
			gogo[A[i]][B[q]] = level;
			gogo[B[q]][A[i]] = level;
		}
	}
	solve(A, level + 1);
	solve(B, level + 1);
}
int main() {
	int n;
	cin >> n;
	vector<int> tea;
	REP(i, n) {
		tea.push_back(i + 1);
	}
	solve(tea, 1);
	for (int i = 1; i <= n; ++i) {
		for (int q = i + 1; q <= n; ++q) {
			cout << gogo[i][q] << " ";
		}
		cout << endl;
	}
}

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

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

  map<string, int> m;
  rep(i,0,N-1) {
    string s;
    cin >> s;
    m[s]++;
  }

  vector<string> v;
  int n = 0;
  for (pair<string, int> p:m) {
    n = max(n, p.second);
  }

  for (pair<string, int> p:m) {
    if (p.second == n) cout << p.first << endl;
  }

  return 0;
}


Measured memory_bytes: 25216
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let mut uf = UnionFind::new(n);
	for _ in 0..m {
		let a: usize = s.next().unwrap().parse().unwrap();
		let a = a - 1;
		let b: usize = s.next().unwrap().parse().unwrap();
		let b = b - 1;
		uf.unite(a, b);
	}
	let mut ans = 0;
	for i in 0..n {
		let s = uf.size(i);
		if ans < s {
			ans = s;
		}
	}
	println!("{}", ans);
}

pub struct UnionFind {
	data: Vec<i32>,
}

impl UnionFind {
	pub fn new(n: usize) -> UnionFind {
		UnionFind { data: vec![-1; n] }
	}

	pub fn unite(&mut self, x: usize, y: usize) -> bool {
		let x = self.find(x);
		let y = self.find(y);
		if x == y {
			false
		} else {
			let (x, y) = if self.data[x] > self.data[y] {
				(y, x)
			} else {
				(x, y)
			};
			self.data[x] += self.data[y];
			self.data[y] = x as i32;
			true
		}
	}

	pub fn find(&mut self, i: usize) -> usize {
		if self.data[i] < 0 {
			i
		} else {
			let p = self.data[i] as usize;
			self.data[i] = self.find(p) as i32;
			self.data[i] as usize
		}
	}

	pub fn size(&mut self, i: usize) -> usize {
		let i = self.find(i);
		(-self.data[i]) as usize
	}
}


Measured memory_bytes: 5276
def dot(a,b):
    return a.real*b.real+a.imag*b.imag

x1, y1, x2, y2 = map(int, input().split())
p1=x1+y1*1j
p2=x2+y2*1j
l=p2-p1
l_norm=dot(l,l)         #lの大きさの２乗を計算
q=int(input())

for x3, y3 in (map(int, input().split()) for _ in [0]*q):
    p3=x3+y3*1j
    a=p3-p1
    k=dot(a,l)/l_norm
    projection_vector=k*l
    reflect_vector=projection_vector-a
    print(x3+2*reflect_vector.real,y3+2*reflect_vector.imag)


Measured memory_bytes: 5644
#include<iostream>
using namespace std;
int main(){
    int x, y;
    while(1){
        cin >> x>> y;
        if(x==0&y==0)break;
        else if(x<=y)cout<<x<<" "<<y<<endl;
        else if(x>=y)cout<<y<<" "<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 3024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int longest(vector<vector<int>>&a, vector<int>& dp, int n){
    if(dp[n]!=-1){return dp[n];}
    if(a[n].size()==0){dp[n]=0; return dp[n];}
    for(auto i:a[n]){
        dp[n]=max(dp[n],longest(a,dp,i)+1);
    }
    return dp[n];
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>dp(n,-1);
    vector<vector<int>>a(n);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        a[x-1].push_back(y-1);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        ans=max(ans,longest(a,dp,i));
    }
    cout<<ans;
    return 0;

}

Measured memory_bytes: 8832
#include <algorithm>
#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()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    ll N;
    cin >> N;
    ll cnt = 0;
    for (ll i = 1; i <= N; i++) {
        ll ma = (N - 1) / i;
        cnt += ma;
    }

    cout << cnt << endl;
}

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

#define N 8

int row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];

bool X[N][N];

void printBoard() {
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(X[i][j]){
                if(row[i] != j){
                    return;
                }
            }
        }
    }
    for (int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(row[i] == j){
                cout << "Q";
            }else{
                cout << ".";
            }
        }
        cout << endl;
    }
}

void recursive(int i){
    if(i == N){
        printBoard();
        return;
    }
    
    for(int j = 0; j < N; j++){
        if(col[j] == 1 || dpos[i + j] == 1 || dneg[i - j + N - 1] == 1){
            continue;
        }
        row[i] = j;
        col[j] = dpos[i + j] = dneg[i - j + N - 1] = 1;

        recursive(i + 1);
    
        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = 0;
    }
}

int main(){
    for(int i = 0; i < N; i++){
        for(int j = 0;j < N; j++){
            X[i][j] = false;
        }
    }

    int k;
    cin >> k;
    for(int i = 0; i < k; i++){
        int r, c;
        cin >> r >> c;
        X[r][c] = true;
    }

    recursive(0);
}



Measured memory_bytes: 3104
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


vector<ll> V;
void dfs(set<ll> s, ll cost, ll& ans) {
    if (s.size() == 5) {
        ans = min(cost, ans);
        return;
    }
    if (cost % 10 != 0) {
        cost = cost / 10 * 10 + 10;
    }
    rep (i, 5) {
        if (!s.count(i)) {
            s.ist(i);
            dfs(s, cost + V[i], ans);
            s.erase(i);
        }
    }
}


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    rep (i, 5) {
        ll v;
        cin >> v;
        V.pb(v);
    }
    ll ans = linf;
    dfs(set<ll>(), 0, ans);
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        ModInt res = 0;
        //k個選んだ時に取りうる値の範囲、k+1個の時に…
        for (long i = k; i <= (n + 1); i++)
        {
            var min = i * (i - 1) / 2;
            var max = min + i * (n - i + 1);
            res += max - min + 1;
        }
        Console.WriteLine(res);
    }
}


struct ModInt
{
    public const int Mod = 1000000007;
    const long POSITIVIZER = ((long)Mod) << 31;
    long Data;
    public ModInt(long data) { if ((Data = data % Mod) < 0) Data += Mod; }
    public static implicit operator long(ModInt modInt) => modInt.Data;
    public static implicit operator ModInt(long val) => new ModInt(val);
    public static ModInt operator +(ModInt a, int b) => new ModInt() { Data = (a.Data + b + POSITIVIZER) % Mod };
    public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
    public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= Mod ? res - Mod : res }; }
    public static ModInt operator -(ModInt a, int b) => new ModInt() { Data = (a.Data - b + POSITIVIZER) % Mod };
    public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
    public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + Mod : res }; }
    public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
    public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
    public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % Mod };
    public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { Data = a.Data * GetInverse(b) % Mod };
    public static bool operator ==(ModInt a, ModInt b) => a.Data == b.Data;
    public static bool operator !=(ModInt a, ModInt b) => a.Data != b.Data;
    public override string ToString() => Data.ToString();
    public override bool Equals(object obj) => (ModInt)obj == this;
    public override int GetHashCode() => (int)Data;
    static long GetInverse(long a)
    {
        long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
        while (true)
        {
            if (p == 1) return x2 + Mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p;
            if (a == 1) return x1 + Mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a;
        }
    }
}


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

int main(){
  int n,m;
  cin>>n>>m;
  int ans=0;
  if(n>1){
    ans+=n*(n-1)/2;
  }
  if(m>1){
    ans+=m*(m-1)/2;
  }
  
  
  cout<<ans;
}
    

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

int main() {
    char *a[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
    int   b[] = { 7, 6, 5, 4, 3, 2, 1 };
    char c[255];
    scanf("%s", c);
    int i = 0;
    while (strcmp(a[i], c) != 0) i++;
    printf("%d\n", b[i]);
    return 0;
}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

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

	string s1 = s.substr(0,n);
	string s2 = s.substr(n,n);
	reverse(s2.begin(),s2.end());

	map<pair<string, string>, ll> mp;
	for (int tmp = 0; tmp < (1 << n); tmp++){
		bitset<20> bit(tmp);
		string a = "";
		string b = "";
		rep(i, n) {
			if (bit.test(i)) a +=s1[i];
			else b += s1[i];
		}
		mp[make_pair(a,b)] ++;
	}

	ll ans = 0;
	for (int tmp = 0; tmp < (1 << n); tmp++){
		bitset<20> bit(tmp);
		string a = "";
		string b = "";
		rep(i, n) {
			if (bit.test(i)) a +=s2[i];
			else b += s2[i];
		}
		ans += mp[make_pair(a,b)];
	}
	cout << ans << endl;
}


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

#define ll long long 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int l; cin >> l;
	double l1 = l, V = (l1 * l1 * l1) / 27; 	
	cout << fixed;
	cout << setprecision(10) << V;	
	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 REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x);
#define CMIN(m, x)  m = min(m,x);
#define itn int
typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;

int cnt = 0;
bool dfs(vector<vector<int> > &bi, vector<vector<int> > &flag,int x, int y){
    bool re = false;
    if(bi[y][x] == 1){
        if(flag[y][x] == 0){
            flag[y][x] = cnt;
            re = true;
            for(int i = -1;i <= 1; i++){
                for(int j = -1; j <= 1; j++){
                    dfs(bi,flag,x + i,y + j);
                }
            }
        }
    }
    return re;
}
int main(){
    int w, h;
    vector<int> ans;
    while(1){
        cin >> w >> h;
        if(w == 0 && h == 0)
            break;
        w += 2;
        h += 2;
        vector<vector<int> > bi(h,vector<int>(w));
        vector<vector<int> > flag(h,vector<int>(w,0));
        REP(i,h - 2){
            REP(j,w - 2)
                cin >> bi[i + 1][j + 1];
        }
        REP(i,h){
            bi[i][0] = 0;
            bi[i][w -1] = 0;
        }
        REP(i,w){
            bi[0][i] = 0;
            bi[h - 1][i] = 0;
        }
        REP(i,h){
            REP(j,w){
                if(bi[i][j] == 1 && flag[i][j] == 0){
                    cnt++;
                    if(!dfs(bi,flag,j,i)) cnt --;
                }
            }
        }
        ans.push_back(cnt);
        cnt = 0;
    }
    
    REP(i,ans.size())
        cout << ans[i] << endl;
    return 0;
}



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

ll a,b,x;
ll f(ll n) {
	if (n == -1) return 0;
	else return n/x + 1;
} 
int main() {
	cin>>a>>b>>x;
	cout << f(b)-f(a-1) << endl;
	return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class Main {
	public static void main(String...args) throws IOException {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int times = Integer.valueOf(br.readLine());

		for(int i = 0; i < times; i++) {
			String[] command = br.readLine().split(" ");
			int start = Integer.valueOf(command[1]);
			int end   = Integer.valueOf(command[2]);
			switch(command[0]) {
				case "replace" :
					String replace = command[3];
					str = str.substring(0 , start) + replace + str.substring(end + 1, str.length());
					break;
				case "reverse" :
					StringBuffer rStr = new StringBuffer(str.substring(start , end + 1));
					str = str.substring(0 , start) + rStr.reverse().toString() + str.substring(end + 1, str.length());
					break;
				case   "print" :
					System.out.println(str.substring(start , end + 1));
					break;
		    }
	    }
    }
}



Measured memory_bytes: 25052
from collections import deque

N, D, A = map(int, input().split())
Monsters = [tuple(map(int, input().split())) for _ in range(N)]
Monsters.sort()
Attack = deque()
attack = 0
ans = 0
for x, h in Monsters:
    while Attack and Attack[0][0] <= x:
        y, at = Attack.popleft()
        attack -= at
    h -= attack
    num = max((h - 1) // A + 1, 0)
    attack += num * A
    ans += num
    Attack.append((x + 2 * D + 1, num * A))
print(ans)


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


#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int main() {
	int k,s;
	cin >> k >> s;
	int sum = 0;
	for(int x = 0;x <= k; x++) {
		for(int y = 0; y <= k; y++){
			int z = s-x-y;
			if(z >= 0 && z <= k) sum++;
		}
	}
	cout << sum <<endl;
}






Measured memory_bytes: 256
//>> OI Solution Info <<//
// Version: 2
// State: Progress
// Problem: Zigzag MST
// ID: AtCoder 2134
// Timeline:
//   --- ~ --- Initialize
// Review:
//   ---
//>> End <<//
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 y_0
#define y1 y_1
#define yn y_n
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;

struct Disjoint{
	int a[200005];
	void init(int n){for(int i=0;i<n;i++)a[i]=i;}
	int find(int x){return a[x]==x?x:a[x]=find(a[x]);}
	void merge(int x,int y){
//		printf("MERGING %d %d\n",x,y);
		a[find(x)]=find(y);
	}
};

struct Query{
	int a,b,c,id;
	Query():a(-1),b(-1),c(-1),id(-1){}
	Query(int a_,int b_,int c_,int id_):a(a_),b(b_),c(c_),id(id_){}
	bool operator<(const Query& r)const{
		if(c!=r.c)return c<r.c;
		if(a!=r.a)return a<r.a;
		if(b!=r.b)return b<r.b;
		return id<r.id;
	}
};

int n,m;
long long res;
Query q[200005];
vector<int> pos[2];
Disjoint dsu;

int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		q[i]=Query(a,b,c,i);
	}
	dsu.init(n);
	sort(q,q+m);
	int p=0;
	for(int i=q[0].c;i<=q[0].c+2*n;i++){
//		printf("Round %d\n",i);
		int ii=i&1;
		vector<int> tmp;
		for(size_t j=0;j<pos[ii].size();j++){
			int u=pos[ii][j],v=(pos[ii][j]+1)%n;
			if(dsu.find(u)!=dsu.find(v)){
				dsu.merge(u,v);
				res+=i;
				tmp.push_back(v);
			}
		}
		pos[ii].swap(tmp);
		while(p<m&&q[p].c==i){
//			printf("NEW QUERY %d - %d\n",q[p].a,q[p].b);
			if(dsu.find(q[p].a)!=dsu.find(q[p].b)){
				dsu.merge(q[p].a,q[p].b);
				res+=i;
			}
			pos[ii].push_back(q[p].b);
			pos[ii^1].push_back(q[p].a);
			p++;
		}
	}
	for(int i=1;i<n;i++)assert(dsu.find(i)==dsu.find(0));
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 6220
s = input()
n = len(s)
ok = True

def judge(s):
    # print(s)
    return 1 if s == s[::-1] else 0

if not judge(s):
    ok = False

if not judge(s[:((n-1)//2)]):
    ok = False

if not judge(s[((n+3)//2)-1:]):
    ok = False

if ok:
    print('Yes')
else:
    print('No')
# print(judge(s))

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int y,t,n,i,s,f,z,x;
	while(1){
		scanf("%d",&t);
		if(t==0)break;
		scanf("%d",&n);
		z=0;
		for(i=0;i<n;i++){
			scanf("%d %d",&s,&f);
			x=f-s;
			z+=x;
		}
		if(z>=t){
			printf("OK\n");
		}
		if(z<t){
			y=t-z;
			printf("%d\n",y);
		}
		x=0;
	}
	return 0;
}

Measured memory_bytes: 1044
day = input('')

if day == 'SUN':
    print('7')
elif day == 'MON':
    print('6')
elif day == 'TUE':
    print('5')
elif day == 'WED':
    print('4')
elif day == 'THU':
    print('3')
elif day == 'FRI':
    print('2')
else:
    print('1')

Measured memory_bytes: 8984
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def main():
    n=int(input())
    ret = 0
    for i in range(1,n+1):
        if i%3!=0 and i%5!=0:
            ret += i
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9152
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

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

	bool found = false;
	for (int i = 0; i != s.size(); i++)
	{
		if (s[i] == p[0])
		{
			found = true;
			for (int j = 0; j < p.size(); j++)
			{
				if (s[(i + j) % s.size()] != p[j])
				{
					found = false;
					break;
				}
			}
			if (found)
			{
				break;
			}
		}
	}
	if (found)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3212
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let W = read![[i64]];

    let mut T = 0;
    let mut S1 = 0; // 前から T 個の重さの総和
    let mut S2 = W.iter().sum::<i64>(); // 前から T 個以外の重さの総和
    let mut min_diff = std::i64::MAX;
    while T < N {
        // T の値を進めると同時に S1, S2 を更新する
        S1 += W[T];
        S2 -= W[T];
        T += 1;

        min_diff = min(min_diff, (S1 - S2).abs());
    }
    println!("{}", min_diff)
}


Measured memory_bytes: 4352
#include <iostream>
#include <set>
using namespace std;
int main(void){
    // Your code here!
    string n;
    cin >> n;
    int count = 0;
    for(int i=0; i<4; i++) {
        if(n[i] == '2') count++;
    }
    cout << count << endl;
    
}


Measured memory_bytes: 256