akhauriyash/Code-Regression huggingface dataset:
// Problem : B - Battle
// Contest : AtCoder - AtCoder Beginner Contest 164
// URL : https://atcoder.jp/contests/abc164/tasks/abc164_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		while(1)
		{
			c-=b;
			if(c<=0)
			{
				cout<<"Yes";
				return 0;
			}
			a-=d;
			if(a<=0)
			{
				cout<<"No";
				return 0;
			}
		}    	
    }
    return 0;
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>  
using namespace std; 
  
int max(int a, int b);  
  
string lcs(string X, string Y, int m, int n )  
{  
    int L[m + 1][n + 1];  
    int i, j;  
      
    for (i = 0; i <= m; i++)  
    {  
        for (j = 0; j <= n; j++)  
        {  
        if (i == 0 || j == 0)  
            L[i][j] = 0;  
      
        else if (X[i - 1] == Y[j - 1])  
            L[i][j] = L[i - 1][j - 1] + 1;  
      
        else
            L[i][j] = max(L[i - 1][j], L[i][j - 1]);  
        }  
    }  

    int index = L[m][n];
    char lcs[index+1]; 
    lcs[index] = '\0'; 
    i = m, j = n; 
    while (i > 0 && j > 0) 
    { 
        if (X[i-1] == Y[j-1]) 
        { 
            lcs[index-1] = X[i-1]; 
            i--; j--; index--;     
        } 
    
        else if (L[i-1][j] > L[i][j-1]) 
            i--; 
        else
            j--; 
    } 
    
    return lcs;
}  
  
int max(int a, int b)  
{  
    return (a > b)? a : b;  
}  
  
int main()  
{  
    string s, t;
    cin >> s >> t; 
      
    int m = s.length();  
    int n = t.length();  
      
    cout << lcs(s, t, m, n);  
      
    return 0;  
}

Measured memory_bytes: 35456
#include <stdio.h>

int
main()
{
        char buf[8];
        int i, d, s;

        while (fgets(buf, 8, stdin)) {
                sscanf(buf, "%d", &d);
                for (i = 0, s = 0; i < 600; i += d)
                        s += i * i * d;
                printf("%d\n", s);
        }

        return 0;
}

Measured memory_bytes: 604
using System;

public class p2259{
	p2259(){
		string str;
		string[] st;
		int n, mx, cnt;
		
		while((str=Console.ReadLine())!=null){
			st = str.Split(' ');
			n = int.Parse(st[0]);
			mx = 0;
			
			while(0 < n--){
				st = (Console.ReadLine()).Split(' ');
				cnt = 0;
				foreach(string s in st)
					cnt += int.Parse(s);
				mx = Math.Max(cnt, mx);
			}
			Console.WriteLine("{0}", mx);
		}
	}
	
	public static int Main(string[] args){
		new p2259();
		return 0;
	}
}

Measured memory_bytes: 5644
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
int main(void){
    int n;
    cin>>n;
    vector<ll> a(n+1),b(n,INF);
    rep(i,0,n-1)cin>>b[i];
    a[0]=b[0];
    rep(i,1,n){
        a[i]=min(b[i-1],b[i]);
    }
    ll ans=0;
    rep(i,0,n)ans+=a[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

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

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

/// command for char arrays with spaces -> scanf(" %[^\n]", texto);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){

	double a, b;
	cin >> a >> b;
	double ans = ceil(a/b);
	cout << fixed << setprecision(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >;
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
using namespace std;
string s;
int main(){
	cin>>s;
	for(int i=0;i<sz(s);i++){
		if(i%2&&s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
			cout<<"No";
			re 0;
		}
		if(i%2==0&&s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
			cout<<"No";
			re 0;
		}
	}
	cout<<"Yes";
	re 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;

fn main() {
    let mut map: HashMap<String, usize> = HashMap::new();

    map.insert(String::from("AC"), 0);
    map.insert(String::from("WA"), 0);
    map.insert(String::from("TLE"), 0);
    map.insert(String::from("RE"), 0);

    let n: usize = read();
    let mut r: Vec<String> = vec![];
    for _ in 0..n {
        r.push(read());
    }

    for i in 0..r.len() {
        let ri = &r[i];
        let current = map.get_mut(ri).unwrap();
        *current += 1;
    }

    println!("AC x {}", map.get("AC").unwrap());
    println!("WA x {}", map.get("WA").unwrap());
    println!("TLE x {}", map.get("TLE").unwrap());
    println!("RE x {}", map.get("RE").unwrap());
}


Measured memory_bytes: 7568
#include "bits/stdc++.h"
using namespace std;


int main() {
	int N;
	cin >> N;
	for (int i = 0;i<=N/7;++i) {
		if (0 == (N-i*7)%4) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s.length() % 2) {
		cout << "No\n";
		return 0;
	}
	char* c = new char[s.length()];
	for (int i = 0;i < s.length();i++) {
		c[i] = s[i];
	}
	sort(c, c + s.length());
	for (int i = 0;i < s.length();i += 2) {
		if (c[i] != c[i + 1]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes\n";
}


Measured memory_bytes: 3092
bingo = [list(map(int,input().split())) for i in range(3)]
n = int(input())
num = [int(input()) for i in range(n)]
for i in num:
  for row in range(3):
    for col in range(3):
      if bingo[row][col] == i:
        bingo[row][col] = 0
if sum(bingo[0]) == 0 or sum(bingo[1]) == 0 or sum(bingo[2]) == 0 or sum([hoge[0] for hoge in bingo]) == 0 or sum([hoge[1] for hoge in bingo]) == 0 or sum([hoge[2] for hoge in bingo]) == 0 or sum([bingo[i][i] for i in range(3)]) == 0 or sum([bingo[i][2-i] for i in range(3)]) == 0:
  print('Yes')
else:
  print('No')
      

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

int s[10010];

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

	int n;
	cin >> n;

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

	int q;
	cin >> q;

	int ans = 0;
	for(int i = 0; i < q; ++i){
		int t;
		cin >> t;
		for(int j = 0; j < n; ++j){
			if(t == s[j]){
				++ans;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1228
N = int(input())
A_list = list(map(int, input().split()))

for i in range(N):
  if A_list[i] % 2 == 0:
    if A_list[i] % 3 != 0 and A_list[i] % 5 !=0:
      print("DENIED")
      exit()

print("APPROVED")

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

int main() {
    int N;
    cin >> N;
    int d[N];
    rep(i, N) cin >> d[i];

    sort(d, d + N);
    int mx = d[N/2];
    int mn = d[N/2-1]+1;
    cout << max(0, mx - mn + 1) << endl;
}

Measured memory_bytes: 640
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		Set<Integer> AB = new HashSet<>();
		AB.add(sc.nextInt());
		AB.add(sc.nextInt());
		
		// 結果の出力
		if (!AB.contains(1)) {
			System.out.println(1);
		}
		else if (!AB.contains(2)) {
			System.out.println(2);
		}
		else {
			System.out.println(3);
		}
		
		sc.close();
	}
}


Measured memory_bytes: 35520
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int h, w;
	cin >> h >> w;
	int si, sj, ti, tj;
	cin >> si >> sj >> ti >> tj;
	si--, sj--, ti--, tj--;
	vector<string> g(h);
	rep(i,h) cin >> g[i];

	deque<pii> q;
	vector<vector<int>> dist(h, vector<int>(w, INF));
	q.push_back(pii(si, sj));
	dist[si][sj] = 0;
	while (!q.empty()) {
		auto p = q.front(); q.pop_front();
		rep (d,4) {
			int ni = p.first + dy[d];
			int nj = p.second + dx[d];
			if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
			if (g[ni][nj] == '#') continue;
			if (dist[ni][nj] <= dist[p.first][p.second]) continue;
			dist[ni][nj] = dist[p.first][p.second];
			q.push_front(pii(ni, nj));
		}
		for (int di = -2; di <= 2; di++) {
			for (int dj = -2; dj <= 2; dj++) {
				int ni = p.first + di;
				int nj = p.second + dj;
				if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
				if (g[ni][nj] == '#') continue;
				if (dist[ni][nj] <= dist[p.first][p.second] + 1) continue;
				dist[ni][nj] = dist[p.first][p.second] + 1;
				q.push_back(pii(ni, nj));
			}
		}
	}
	int ans = dist[ti][tj];
	if (ans == INF) cout << -1 << endl;
	else cout << ans << endl;
}

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

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

count = 0
for i in reversed(range(n)):
    if a[i+1] <= b[i]:
        b[i] -= a[i+1]
        count += a[i+1]
        a[i+1] = 0
    else:
        a[i+1] -= b[i]
        count += b[i]
        b[i] = 0

    if a[i] <= b[i]:
        b[i] -= a[i]
        count += a[i]
        a[i] = 0
    else:
        a[i] -= b[i]
        count += b[i]
        b[i] = 0

print(count)

Measured memory_bytes: 19376
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
using namespace std;
long long int A[100008];
long long int B[100008];


typedef pair<long long int,long long int> Edge;

vector<Edge> S[50];
void serch(long long int X) {
	long long int Q[100008] = {};
	long long int W[100008] = {};

	for (long long int i = 0; i < (int)S[X].size(); i++) {
		Q[S[X][i].first]++;
		W[S[X][i].second]++;
	}
	for (long long int i = 0; i < 100007; i++) {
		if (Q[i] == W[i]&&Q[i]>0&&W[i]>0) {
			A[i]-=min(Q[i],W[i]);
			B[i]-= min(Q[i], W[i]);
		}
	}

}


int main() {
	long long int N, C;
	cin >> N >> C;
	
	long long  a, b, c;
	for (long long int i = 0; i < N; i++){
		
		cin >> a >> b >> c;
		A[a]++;
		B[b]++;
		S[c].push_back(Edge(a, b));
	}
	for (int i = 0; i < 31; i++) {
		serch(i);
	}
	long long int AA = 0;
	long long int BB = 0;
	long long int Z = 0;
	long long int z;
	for (long long int i = 0; i <100008 ; i++) {
		
		z = AA - BB+A[i];
		Z = max(Z,z );

		AA += A[i];
		BB += B[i];
	}

	cout << Z << endl;

	return 0;
}

Measured memory_bytes: 5888
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
s = input()
s = s + "2"
li_0 = []
li_1 = []
ct = 1
for i in range(n):
    if s[i] != s[i+1]:
        if s[i] == '0':
            li_0.append(ct)
            ct = 1
        else:
            li_1.append(ct)
            ct = 1
    else:
        ct += 1
if len(li_0) <= k:
    print(len(s)-1)
else:
    li_0 = deque(li_0)
    li_1 = deque(li_1)
    if s[0] == "0":
        li_1.appendleft(0)
    li_1.append(0)
    Sum_0 = sum(li_0[i] for i in range(k))
    Sum_1 = sum(li_1[i] for i in range(k+1))
    Max = Sum_0 + Sum_1
    for i in range(len(li_0)-k):
        Sum_0 = Sum_0 - li_0[i] + li_0[i+k]
        Sum_1 = Sum_1 - li_1[i] + li_1[i+k+1]
        Max = max(Max, Sum_0 + Sum_1)
    print(Max)








Measured memory_bytes: 4628
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] times = new int[n];
    
        boolean isOdd = (n & 1) == 1;
        int num = 0;
        for(int i = 0; i < n; i++) {
            num = sc.nextInt();

            if(isOdd && ((num & 1) == 1)) {
                System.out.println(0);
                return;
            } else if(!isOdd && ((num & 1) == 0)) {
                System.out.println(0);
                return;
            }
            
            times[num]++;
            if(times[num] > 2 || times[0] == 2) {
                System.out.println(0);
                return;
            }
        }
    
        long ans = 1;
		for(int i = 0; i < n/2; i++)
		    ans = 2 * ans % 1000000007;
		System.out.println(modPow(2L, n / 2));
    }
    static int MOD = 1000000007;
    static long modPow(long x, long n) {
        long res = 1L;
        while (n > 0) {
            if ((n & 1) == 1) {
                res = res * x % MOD;
            }
            x = x * x % MOD;
            n >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 49956
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int n;

void dfs(string s, char m) {
    if (s.size() == n) {
        cout << s << '\n';
        return;
    }
    for (char c = 'a'; c <= m + 1; ++c) {
        dfs(s + c, max(m, c));
    }
}

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    cin >> n;
    if (n == 1) {
        print("a");
        return 0;
    }
    dfs("a", 'a');

    return 0;
}



Measured memory_bytes: 1536
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {
            int w = sc.nextInt();
            int h = sc.nextInt();
            if (w + h == 0) {
                break;
            }
            int[][] field = new int[h+2][w+2];
            for (int i=1; i<=h; ++i) {
                for (int j=1; j<=w; ++j) {
                    field[i][j] = sc.nextInt();
                }
            }
            int counter = 0;
            for (int i=1; i<=h; ++i) {
                for (int j=1; j<=w; ++j) {
                    if (field[i][j] == 1) {
                        counter -= 1;
                        dfs(field, i, j, counter);
                    }
                }
            }
            System.out.println(counter * -1);
        }
        sc.close();
    }

    private static void dfs(int[][] field, int ifrom, int jfrom, int id) {
        field[ifrom][jfrom] = id;
        for (int i=ifrom-1; i<=ifrom+1; ++i) {
            for (int j=jfrom-1; j<=jfrom+1; j++) {
                if (field[i][j] == 1) {
                    dfs(field, i, j, id);
                }
            }
        }
    }
}



Measured memory_bytes: 47724
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000
#define vll vector<ll>
using namespace std;
const int N=5005;

void solve()
{
	
	ll n,i,j,ans=0,cnt;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		j=i;
		cnt=0;
		while(j)
		{
			cnt++;
			j/=10;
		}
		if(cnt&1) ans++;
	}
	cout<<ans;
}
 
int main() {
    
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
 
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>
#include<cctype>
#include<cstdio>

#define PRECISE "6"
#define BUF_SIZ 1024

using namespace std;

double CalcDoctorNewExpression(string &exp){
	stack<double> st;

	for(unsigned int i = 0; i < exp.length(); i++){
		double v1, v2, v;
		int sign = 1;

		if( exp[i] == ' ' ) continue;
		if( i+1 < exp.length() && exp[i] == '-' && isdigit(exp[i + 1]) ){ sign = -1; i++; goto PARSE_NUMBER; }

		switch( exp[i] ){
			case '+': case '-': case '*': case '/':
				v1 = st.top(); st.pop();
				v2 = st.top(); st.pop();
				switch( exp[i] ){
					case '+': v = v1 + v2; break;
					case '-': v = v2 - v1; break;
					case '*': v = v1 * v2; break;
					case '/': v = v2 / v1; break;
				}
				st.push( v );
				continue;
		}

PARSE_NUMBER:;		
		if( isdigit(exp[i]) ){
			double num = 0;
			do{
				num *= 10.0;
				num += (double)(exp[i] - '0');
				++i;
			}while( i < exp.length() && isdigit(exp[i]) );
			st.push( sign * num );
		}
	}
	return st.top();
}

int main(void){
	while( true ){
		char buf[BUF_SIZ];
		string s;

		cin.getline( buf, sizeof(buf)/sizeof(*buf) );
		if( cin.eof() ) break;

		s = buf;
		printf("%."PRECISE"f\n", CalcDoctorNewExpression( s ));
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int a[3][2],h,m,s;
	for (int i = 0;i < 3;i++){
		for (int j = 0;j < 2;j++){
			cin >> h >> m >> s;
			a[i][j] = h*3600+m*60+s;
		}
		int ans = a[i][1]-a[i][0];
		cout << ans/3600 << " ";
		ans %= 3600;
		cout << ans/60 << " ";
		ans %= 60;
		cout << ans << endl;
	}
	

	return 0;

}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

int counter(int x){
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

void solve(){
    int n = in();
    int A[20]; // 余分に
    int x[20][20], y[20][20];
    for(int i = 1; i <= n; i++){
        cin >> A[i];
        for(int j = 1; j <= A[i]; j++){
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for(int bits = 1; bits < (1 << n); bits++){
        bool ok = true;
        for(int i = 1; i <= n; i++){
            if(!(bits & (1 << (i - 1)))) continue;
            for(int j = 1; j <= A[i]; j++){
                if((bits >> (x[i][j] - 1) & 1) xor y[i][j]) ok = false;
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return;
}


signed main(void){
    solve();
    return 0;
}

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

using namespace std;

int main()
{
    int a, b, i;
    i = 0;
    string op;

    while (i <= 20000)
    {
        cin >> a >> op >> b;

        if (op == "+")
        {
            cout << a + b << endl;
        }
        else if (op == "-")
        {
            cout << a - b << endl;
        }
        else if (op == "*")
        {
            cout << a * b << endl;
        }
        else if (op == "/")
        {
            cout << a / b << endl;
        }
        else
        {
            break;
        }
        i++;
    }
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;


int32_t main(){
	IOS
	int n,m;cin>>n>>m;
	vector<int>cnt(n+1,1),clr(n+1,0);
	clr[1]=1;
	for(int i=1;i<=m;i++){
		int x,y;cin>>x>>y;
		if( !clr[x] ){
			cnt[y]+=1;
			cnt[x]-=1;
		}else{
			if( cnt[x] == 1){
				cnt[x]=0;
				clr[x]=0;
				clr[y]=1;
				cnt[y]+=1;
			}else{
				cnt[x]-=1;
				cnt[y]+=1;
				clr[y] =1;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=clr[i];
	}
	cout<<ans;
				
	
}
 
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int a,b,k;cin>>a>>b>>k;
    int cou = 0;
    for(int i = a*b;;i--){
        if(a%i==0&&b%i==0){
            cou++;
            if(cou==k){
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <queue>
#include <stack>
#include <cstring>
#include <ctime>
#include <cassert>


#define pb emplace_back
#define re return
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265359;

int n, k;
int main()
{
    //freopen("distance.in", "r", stdin);
    //freopen("distance.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    vector <ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(all(a));
    reverse(all(a));
    for (int i = 0; i < min(n, k); i++)
        a[i] = 0;
    cout << accumulate(all(a), 0ll);
}
/// ACTUAL CODE STARTS HERE:
//  I'm red in soul
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


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

int partition(int* a, int p, int r)
{
	int i = p - 1;
	int x = a[r];
	for (int j = p; j < r; j++) if (a[j] <= x) swap(a[++i], a[j]);
	swap(a[i+1], a[r]);
	return i+1;
}

int main()
{
	int n,*a;
	scanf("%d", &n); a = new int [n];
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	int index = partition(a,0,n-1);

	for (int i = 0; i < n; i++)
	{
		if (i > 0) printf(" ");
		if (i == index) printf("[%d]", a[i]);
		else printf("%d", a[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  string S;
  string ans = "No";
  cin >> n >> S;

  m = n / 2;
  //nが奇数の場合はかならず"No"となる
  if (n % 2 == 0) {
  
    //２重ループ文
    for (int i = 0; i < m; ++i) {
      if (S[i] == S[m+i]){
        ans = "Yes";
      }
      else {
        ans = "No";
        break;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=200005;
vector<pii>P[MAX],R[MAX];
struct query
{
	int l,r,d;
};
query Q[MAX];
vi ele[MAX];
int repr[MAX];
int dist[MAX];
bool O[MAX];

void zeruj(int n)
{
	for (int i=0;i<MAX;i++)O[i]=false;
}

void dfs(int u,int r)
{
	repr[u]=r;
	O[u]=true;
	for (auto it:P[u])
	{
		if (!O[it.st])
		{
			dist[it.st]=dist[u]+it.nd;
			dfs(it.st,r);
		}
	}
}

int32_t main()
{
  BOOST;
  int n,m;
  cin>>n>>m;
  for (int i=1;i<=m;i++)
  {
    cin>>Q[i].l>>Q[i].r>>Q[i].d;
    P[Q[i].l].pb(mp(Q[i].r,Q[i].d));
    R[Q[i].r].pb(mp(Q[i].l,Q[i].d));
  }
  
  for (int i=1;i<=n;i++)
  {
  	if (!sz(R[i]))
  	{
  		dist[i]=0;
  		dfs(i,i);
  	}
  }
  
  for (int i=1;i<=n;i++)
  {
  	if (!repr[i])
  	{
  		cout<<"No";
  		return 0;
  	}
  }
  
  for (int i=1;i<=m;i++)
  {
  	int a=Q[i].l,b=Q[i].r,d=Q[i].d;
  	if (dist[b]-dist[a]!=d)
  	{
  		cout<<"No";
  		return 0;
  	}
  }
  
  
  cout<<"Yes";
  return 0;
}


Measured memory_bytes: 28544
s = int(input())

cnt = 1
list = []
list.append(s)
while True:
    if s % 2 == 0:
        s = int(s/2)
    else:
        s = 3*s + 1
    cnt += 1
    if s in list:
        break
    list.append(s)

print(cnt)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long X;
    cin >> X;
    long long ans = 100;
    double k = 1.01;
    long long i = 0;
    while(1){
        ans *= k;
        i++;
        if(X<=ans)break;
    }cout << i << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
     ll n,k,i;
     cin>>n>>k;
     map<ll,ll>mp;
     ll a,b;
     for(i=0;i<n;i++)
     {
         cin>>a>>b;
         mp[a]+=b;
     }
     ll x=0 , ans;
     for(auto it:mp)
     {
         if(x>=k)
         {
             break;
         }
         x+=it.se;
         ans = it.fi;

     }

     cout<<ans<<endl;
}


Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String args[]) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		char ch1 = br.readLine().charAt(0);
		int ascii = (int)ch1;
		ascii++;
		
		char ch2 = (char) ascii;
		
		System.out.println(ch2);
		
	}

}


Measured memory_bytes: 20436
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();	
		int[]p=new int[n];
		
		//0番目とn番目を除いてループする
      	//2番目に小さい数字をカウントしていく
		for(int i=0;i<n;i++) {
			p[i]=sc.nextInt();
		}
		
		int count=0;
		for(int i=1;i<n-1;i++){
			if(p[i-1]<p[i]&&p[i]<p[i+1]){
				count++;
			}else if(p[i-1]>p[i]&&p[i]>p[i+1]){
				count++;
			}
		}
		System.out.println(count);
		sc.close();		
	}
}

Measured memory_bytes: 27036
/*author : Yashvardhan
Wednesday, May 08, 2019
6:56 PM
*/

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

typedef long long ll;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define endl '\n'

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n;
	cin>>n;


	int arr[6];
	
	int mini = inf;

	for(int i = 1; i <= 5 ; i++){
		cin>>arr[i];
		mini = min(mini,arr[i]);
	}
	
	int ans;
	if(n%mini == 0) ans = n/mini;
	else ans = (n/mini) + 1;
	
	ans += 4;
	cout<<ans<<endl;
	
	

	t2 = clock();
	cerr<<endl<<t2-t1<<endl;
	
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    //
    String a = sc.next();
    String ans;
 
	if(a.equals("ARC")){
      ans = "ABC";
    } else {
      ans = "ARC";
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 35672
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;


int main() {
	double W, H, x, y, ans, z = 0;
	cin >> W >> H >> x >> y;

	ans = W * H / 2;

	if (x == W / 2 && y == H / 2) {
		z = 1;
	}

	cout << setprecision(15) << ans << " " << z;
	
	return 0;

}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int N;
ll K;
vector<int> A, F;

/*
bool isOK(ll mid){
    ll count = 0;
    rep(i,N){
        count += max(0ll, A[i] - mid/F[i]);
    }
    if (count <= K) return true;
    else return false;
}
*/
ll binary_search(){
    ll ng = -1;
    ll ok = 1e12;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng) / 2;
        ll count = 0;
        rep(i,N){
            count += max(0ll, A[i] - mid/F[i]);
        }
        if(K >= count){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    return ok;
}

int main(){
    /*
    int N;
    ll K;
    */
    cin >> N >> K;
    
    //vector<int> A(N), F(N);
    A.assign(N,0), F.assign(N,0);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> F[i];

    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());
    /*
    ll ng = -1;
    ll ok = 1e12;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng) / 2;
        ll count = 0;
        rep(i,N){
            count += max(0ll, A[i] - mid/F[i]);
        }
        if(K >= count){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    */
    ll ok = binary_search();
    cout << ok << endl;
}

Measured memory_bytes: 4784
#include <iostream>

using namespace std;

int main()
{
    int n, cnt;
    while(cin >> n) {
        cnt = 0;
        for(int i = 0; i <= 9; i++) {
            for(int j = 0; j <= 9; j++) {
                for(int k = 0; k <= 9; k++) {
                    for(int l = 0; l <= 9; l++) {
                        if((i+j+k+l) == n) cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    static int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        String[][] table = new String[x + 2][y + 2];
        for (String[] t : table) {
            Arrays.fill(t, "#");
        }
        for (int i = 1; i <= x; i++) {
            String str = sc.next();
            for (int j = 1; j <= y; j++) {
                table[i][j] = String.valueOf(str.charAt(j - 1));
            }
        }
        
        int[][] dp = new int[x + 2][y + 2];
        for (int[] d : dp) {
            Arrays.fill(d, 1);
        }
        for (int i = 1; i <= x; i++) {
            for (int j = 1; j <= y; j++) {
                if (i == 1 && j == 1) continue;
                if (table[i][j].equals("#")) continue;
                
                boolean upToDown = table[i - 1][j].equals(".");
                boolean leftToRight = table[i][j - 1].equals(".");
                
                if (upToDown && leftToRight) {
                    dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
                } else if (upToDown) {
                    dp[i][j] = dp[i - 1][j];
                } else if (leftToRight) {
                    dp[i][j] = dp[i][j - 1];
                } else {
                    table[i][j] = "#";
                    if (i == x && j == y) {
                        dp[i][j] = 0;
                    }
                }
            }
        }
        
        System.out.println(dp[x][y]);
    }
}


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

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
    }

    int count = 0;
    for (int i = 1; i < N; i++) {
      if (a[i] == a[i - 1]) {
        count++;
        i++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21844
#include<iostream>

using namespace std;

const int N(1e5 + 9);
typedef long long ll;

int n, ans;
ll m, sum, a[N];
ll L[N], R[N];

ll gcd(ll a, ll b)
{
	return b == 0? a:gcd(b, a % b);
}
int main()
{
	cin>>n;
	sum = 1;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for (int i=1;i<=n;i++)
	{
		L[i] = gcd(L[i - 1], a[i]);
	}
	for (int i=n;i>=1;i--)
	{
		R[i] = gcd(R[i + 1], a[i]);
	}
	for (int i=1;i<=n;i++)
	{
		int tmp = gcd(L[i - 1], R[i + 1]);
		if (tmp > ans)
		{
			ans = tmp;
		}
	}
	cout<<ans<<endl;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);

void gen(LL N, LL S, LL W, VI& a){
  int g = S;
  for(int i=0; i<N; i++) {
	a[i] = (g/7) % 10;
	if( g%2 == 0 ) { g = (g/2); }
	else           { g = (g/2) ^ W; }
  }
}

LL powm(LL x, LL y, LL m){
  if(y == 0) return 1;
  return powm(x*x%m, y/2, m) * (y%2?x:1) % m;
}
LL inv(LL x, LL m){
  return powm(x, m-2, m);
}

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

  LL N, S, W, Q;
  while(cin>>N>>S>>W>>Q,N){
	VI as(N);
	gen(N, S, W, as);

	if(Q == 2){
	  LL ans = 0;
	  LL z = 0;
	  for(int i=N-1;i>=0;--i){
		if(as[i]){
		  ans += z + 1 - as[i] % 2;
		}
		z += 1 - as[i] % 2;
	  }
	  cout<<ans << endl;
	  continue;
	}
	else if(Q == 5){
	  LL ans = 0;
	  LL z = 0;
	  for(int i=N-1;i>=0;--i){
		if(as[i]){
		  ans += z + (as[i]%5==0? 1: 0);
		}
		z += as[i]%5==0? 1: 0;
	  }
	  
	  cout<<ans<<endl;
	  continue;
	}

	LL p = 1;
	VL xs(N);
	for(int i=N-1;i>=0;--i){
	  xs[i] = as[i] * p % Q;
	  (p *= 10) %= Q;
	}
	VL acc(N+1);
	REP(i,N)
	  acc[i+1] = (acc[i] + xs[i]) % Q;

	LL ans = 0;
	map<LL,LL> cnt;
	cnt[acc.back()]++;
	for(int l=N-1;l>=0;--l){
	  if(as[l] && cnt.count(acc[l])){
		ans += cnt[acc[l]];
	  }
	  cnt[acc[l]]++;
	}
	
	cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 10324
#include <stdio.h>
 
#define N 500000
#define AEN 1000000000
 
int merge(int *,int,int,int);
void mergeSort(int *,int,int);
 
int n,s[N],count=0,tmp[N],x[N];
 
int main()
{
 
  int i,x;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
 
    scanf("%d",&s[i]);
 
  }
 
  mergeSort(s,0,n-1);
 
  for(i=0;i<n-1;i++){
 
    printf("%d ",s[i]);
 
  }
  printf("%d\n",s[n-1]);
 
  printf("%d\n",count);
 
  return 0;
 
}
 
 
 
void mergeSort(int A[],int left,int right){
 
  int mid,i,j,k;
 
  if(left>=right) return;
 
  mid=(left+right)/2;
 
  mergeSort(A,left,mid);
  mergeSort(A,mid+1,right);
 
  for(i=left;i<=mid;i++){
    tmp[i]=A[i];}
 
  for(i=mid+1,j=right;i<=right;i++,j--){
    tmp[i]=A[j];
  }
 
  i=left;
  j=right;
 
  for(k=left;k<=right;k++){
 
    if(tmp[i]<=tmp[j]) A[k]=tmp[i++];
    else A[k]=tmp[j--];  
 
    count++;
  }
}

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

using namespace std;

int A[100005];
int main()
{
    int n,k,cont=0;

    cin>>n>>k;
    int x;
    int d;
    while(k--)
    {
        cin>>d;

        for(int i=1;i<=d;i++)
        {
            cin>>x;
            A[x]++;
        }
    }

    for(int i=1;i<=n;i++)
        if(A[i]==0)
            cont++;

    cout<<cont;

    return 0;
}

Measured memory_bytes: 3644
using System;

namespace _089c
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[,] txy = new int[N+1,3];
            txy[0,0] = 0;
            txy[0,1] = 0;
            txy[0,2] = 0;
            for(int i = 1; i <= N; i++){
                var read = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
                txy[i,0] = read[0];
                txy[i,1] = read[1];
                txy[i,2] = read[2];
            } 
            bool res = false;
            for(int i = 0; i < N ; i++){
                int t1 = txy[i,0];
                int x1 = txy[i,1];
                int y1 = txy[i,2];  
                int t2 = txy[i+1,0];
                int x2 = txy[i+1,1];
                int y2 = txy[i+1,2];
                int sa_x_y = Math.Abs(x2-x1)+Math.Abs(y2-y1);
                if(t2-t1>=sa_x_y){
                    if(t2-t1 ==sa_x_y){
                        res = true;
                    }else if(((t2-t1)-sa_x_y)%2==0){
                        res = true;
                    }else{
                        res = false;
                        break;
                    }
                }else{
                    res = false;
                    break;
                }  
            }
            Console.WriteLine(res?"Yes":"No");
        }
    }
}

Measured memory_bytes: 17304
#include<bits/stdc++.h>
using namespace std;
char a[500][500],b[500][500];
int h,w,ans,cou;
int main(){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int u=0;u<w;u++){
            cin>>a[i][u];
            if(a[i][u]=='#')cou++;
        }
    }

    for(int i=0;i<h;i++){
        for(int u=0;u<w;u++){
            b[i][u]='&';
        }
    }

    for(int i=0;i<h;i++){
        for(int u=0;u<w;u++){
            if(a[i][u]=='#'){
                if(a[i+1][u]=='#'&&i!=h-1){b[i+1][u]='#';b[i][u]='#';}
                if(a[i][u+1]=='#'&&u!=w-1){b[i][u+1]='#';b[i][u]='#';}
            }
        }
    }

    for(int i=0;i<h;i++){
        for(int u=0;u<w;u++){
            if(b[i][u]==a[i][u])ans++;
        }
    }

    if(ans==cou)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;



}


Measured memory_bytes: 256
use std::io;
use std::io::prelude::*;
use std::io::BufReader;

fn main() -> io::Result<()> {
    // let mut n = String::new();
    // io::stdin().read_line(&mut n)?;
    // let n: usize = n.trim_end().parse().unwrap();
    // let mut buf = vec![0; n];
    // io::stdin().read_exact(&mut buf)?;
    let mut reader = BufReader::new(io::stdin()).lines().skip(1);
    let buf: Vec<_> = reader.next().unwrap().unwrap().bytes().collect();
    let n = buf.len();
    let cnt = buf.iter().filter(|&&b| b == b'1').count();
    if cnt == 1 {
        let lone_1 = buf.iter().position(|&b| b == b'1').unwrap();
        for i in 0..n {
            if i == lone_1 {
                println!("0");
            } else if lone_1 == n - 1 || i == n - 1 {
                // lone_1かiがn-1の時、奇数を2で割ることになる
                println!("2");
            } else {
                println!("1")
            }
        }
    } else {
        let cnt0 = cnt + 1;
        let cnt1 = cnt - 1;
        let p0 = get_res_list(n, cnt0);
        let p1 = get_res_list(n, cnt1);
        let mut res0 = 0; // 0の時使う
        let mut res1 = 0; // 1の時使う
        for (i, &b) in buf.iter().enumerate() {
            if b == b'1' {
                res0 += p0[i];
                res1 += p1[i];
            }
        }
        let mut rest = vec![0; cnt0];
        for i in 1..rest.len() {
            rest[i] = 1 + rest[i % i.count_ones() as usize]
        }
        // println!("res0: {}, res1: {} cnt: {}", res0, res1, cnt);
        // println!("p0[0]: {}, p1[0]: {}", p0[0], p1[0]);
        // println!("{:?}", p0);
        // println!("{:?}", p1);
        // println!("{:?}", rest);
        for (i, &bit) in buf.iter().enumerate() {
            let res = if bit == b'0' {
                (res0 + p0[i]) % cnt0
            } else {
                (res1 - p1[i]) % cnt1
            };
            println!("{}", 1 + rest[res]);
        }
    }
    Ok(())
}
/// 2^0, 2^1, ... をcntで割ったあまり
fn get_res_list(n: usize, cnt: usize) -> Vec<usize> {
    let mut v = vec![0; n];
    let mut res = 1;
    for i in 0..n {
        res %= cnt;
        if res == 0 {
            break;
        }
        v[n - i - 1] = res;
        res <<= 1;
    }
    v
}


Measured memory_bytes: 5868
def main():
    S = input()[::-1]
    tar = {'maerd', 'remaerd', 'esare', 'resare'}
    i = 0
    while i < len(S):
        if S[i] == 'm':
            if S[i:i+5] == 'maerd':
                i += 5
            else:
                return print("NO")
        elif S[i] == 'e':
            if S[i:i+5] == 'esare':
                i += 5
            else:
                return print("NO")
        elif S[i] == 'r':
            if S[i:i+6] == 'resare':
                i += 6
            elif S[i:i+7] == 'remaerd':
                i += 7
            else:
                return print("NO")
        else:
            return print("NO")
    print("YES")
if __name__ == '__main__':
    main()

Measured memory_bytes: 40688