akhauriyash/Code-Regression huggingface dataset:
import sys
n,x,m = map(int,input().split())

lst_sum = [0,x]
loop = [0]*(10**5)
loop[x] = 1
s = 1
for i in range(2,n+1):
  y = ((lst_sum[-1] - lst_sum[-2])**2)%m
                          
  if loop[y] != 0:
    l = i-loop[y]
    d = (n-loop[y]+1) // l
    q = (n-loop[y]+1) % l
    sum_loop = lst_sum[-1]-lst_sum[loop[y]-1]
    sum_first = lst_sum[loop[y]-1]
    if q == 0:
      sum_rest = 0
    else:
      sum_rest = lst_sum[loop[y] + q-1] - lst_sum[loop[y]-1]
    print(sum_first+d*sum_loop+sum_rest)
    sys.exit()      
  else:
    s += 1
    loop[y] = s
    lst_sum.append(lst_sum[-1] + y)
    
print(lst_sum[-1])    

    
    
    
  




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

#pragma warning(disable:4996)
using namespace std;
using ld = long double;

vector<pair<long long int, long long int>>ps;
long long int g(long long int x, long long int place) {
	return ps[x].first + ps[x].second*(place);
}

int main() {
	long long int N, L, K; cin >> N >> L >> K;
	vector<long long int>sums(N + 1);
	for (int i = 0; i < N; ++i) {
		int a, d; cin >> a >> d;
		ps.emplace_back(a, d);

		sums[i + 1] = sums[i] + (a + (a + d*(L - 1)))*L / 2;
	}

	long long int answer = 0;
	if (N == 1) {
		answer = (g(0, L - K) + g(0, L - 1))*K / 2;

	}
	else if (N*L == K) {
		answer = sums[N];
	}
	else {

		const long long int t = K / L;

		for (long long int len = t - 1; len <= t; ++len) {
			for (int l = 1; l + len < N; ++l) {
				int r = l + len;

				long long int rest = K - L*len;

				if (rest <= L) {

					long long int now_ans = sums[r] - sums[l] +
						(g(l - 1, L - rest) + g(l - 1, L - 1))*
						rest / 2;

					long long int r_minus_l_start = g(r, 0) - g(l - 1, L - rest);
					long long int r_minus_l_sa = ps[r].second - ps[l - 1].second;

					long long int max_cnt;
					if (r_minus_l_sa > 0) {
						max_cnt = rest;
					}
					else if (r_minus_l_sa == 0) {
						if (r_minus_l_start > 0) {
							max_cnt = rest;
						}
						else {
							max_cnt = 0;
						}
					}
					else {
						if (r_minus_l_start > 0) {
							long long int k = r_minus_l_start / (-r_minus_l_sa) + 1;
							max_cnt = min(rest, k);
						}
						else {
							max_cnt = 0;
						}
					}

					long long int max_ans = now_ans + r_minus_l_start*max_cnt +
						r_minus_l_sa*(max_cnt - 1)*max_cnt / 2;

					answer = max(answer, now_ans);
					answer = max(answer, max_ans);
					answer = max(answer,
						now_ans + r_minus_l_start*rest +
						r_minus_l_sa*(rest - 1)*rest / 2);

				}
				else {

					long long int now_ans = sums[r] - sums[l - 1]
						+ (ps[r].first + (ps[r].first + ps[r].second*(rest - L - 1)))*(rest - L) / 2;

					long long int r_minus_l_start = g(r, rest - L) - g(l - 1, 0);
					long long int r_minus_l_sa = ps[r].second - ps[l - 1].second;

					long long int max_cnt;
					if (r_minus_l_sa > 0) {
						max_cnt = 2 * L - rest;
					}
					else if (r_minus_l_sa == 0) {
						if (r_minus_l_start > 0) {
							max_cnt = 2 * L - rest;
						}
						else {
							max_cnt = 0;
						}
					}
					else {
						if (r_minus_l_start > 0) {
							long long int k = r_minus_l_start / (-r_minus_l_sa) + 1;
							max_cnt = min(2 * L - rest, k);
						}
						else {
							max_cnt = 0;
						}
					} 
					long long int max_ans = now_ans + r_minus_l_start*max_cnt +
						(r_minus_l_sa*(max_cnt - 1)*max_cnt) / 2ll;

					long long int kk=(g(l-1,max_cnt)+g(l-1,L-1))*(L-max_cnt)/2+
						sums[r] - sums[l]+
						(g(r,0)+g(r,rest-L-1+max_cnt))*(rest-L+max_cnt)/2;
					
					answer = max(answer, now_ans);
					answer = max(answer, max_ans);
					answer = max(answer,
						now_ans + r_minus_l_start*(2 * L - rest) +
						r_minus_l_sa*((2 * L - rest) - 1)*(2 * L - rest) / 2);

				}
			}
		}
	}


	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 5712
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <string.h>

using namespace std;

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

    if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
        cout<<"Yes";
    }
    else {
        cout<<"No";
    }

}

Measured memory_bytes: 3628
#include <iomanip>
#include <utility>
#include <algorithm>
#include <type_traits>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
#include <cassert>
#include <memory>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <queue>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <forward_list>
#include <iomanip>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <numeric>

using namespace std;
#define MFOR(i,end) for(size_t i = 0, end_i = (end); i < end_i; ++ i)

int pos1_x, pos1_y, pos2_x, pos2_y;

int main()
{
	std::cin >> pos2_x >> pos2_y;
	size_t N;
	std::cin >> N;
	for (size_t i = 0; i < N; ++i)
	{
		int x, y,a;
		std::cin >> x >> y >> a;
		switch (a)
		{
		case 1:
			pos1_x = std::max(pos1_x, x);
			break;
		case 2:
			pos2_x = std::min(pos2_x, x);
			break;
		case 3:
			pos1_y = std::max(pos1_y, y);
			break;
		case 4:
			pos2_y = std::min(pos2_y, y);
			break;
		default:
			break;
		}
	}
	int width = pos2_x - pos1_x;
	int height = pos2_y - pos1_y;
	if (0 < width && 0 < height) {
		std::cout << width*height << std::endl;
	}
	else {
		std::cout << 0 << std::endl;
	}
}

Measured memory_bytes: 888
// Problem: A - Takahashikun, The Strider
// Contest: AtCoder - AtCoder Grand Contest 046
// URL: https://atcoder.jp/contests/agc046/tasks/agc046_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e6 + 1;

int x;

int32_t main() { cin.tie(0)->sync_with_stdio(0);
  cin >> x;
  cout << 360 / __gcd(x, 360);
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

const int MAX_N = 10000;
const int MAX_E = 10000;
struct edge{ ll from, to, cost; };
edge es[MAX_E]; //辺
ll d[MAX_N]; //最短距離
ll n,m,p; //頂点数、辺数

bool bellmanford(int s){
    rep(i,n) d[i] = INF;
    d[0] = 0;
    rep(i,n){
        bool update = false;
        rep(j,m){
            edge e = es[j];
            if (d[e.from] == INF) continue;
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if (!update) break;
    }

    bool negative[MAX_N];
    rep(i,n) negative[i] = false;
    rep(i,n) {
        rep(j,m){
            edge e = es[j];
            if (d[e.from] == INF) continue;
            if (d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                negative[e.to] = true;
            if (negative[e.from]) negative[e.to] = true;
            }
        }
    }
    if (negative[n-1]) return false;
    return true;
}

void solve(){
    cin >> n >> m >> p;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        es[i]=edge{a-1,b-1,p-c};
    }
    bool t=bellmanford(0);
    if (!t) cout << -1 << endl;
    else cout << max((ll)0,-1*d[n-1]) << endl;

}

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

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<ll> v;

    ll nb = n;
    if(nb==0){
        cout << '0' << endl;
        return 0;
    }

    ll p = 1;
    while(nb != 0){
        ll tmp = pow(2, p);
        ll d = 0;
        if(nb%tmp==0){
            v.push_back(0);
            d = 0;
        }else{
            v.push_back(1);
            d = 1;
        }
        nb -= pow(-2, p-1)*d;
        p++;
    }
    string ans = "";
    rep(i, v.size()){
        ans += to_string(v[v.size()-1-i]);
    }
    cout << ans << endl;
}

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

using namespace std;

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

	long long l=0;
	for(auto i:s)
		l+=(int)(i-'0');

	if(l%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

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


int main() {
  int n, k;
  cin >> n >> k;
  if (n % k == 0) cout << 0 << endl;
  else cout << 1 << endl;
}

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




int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    vector<int> dp(n);
    
    for(int i=0;i<n;i++) cin>>h[i];
    dp[0]=0;
    dp[1]= abs(h[1]-h[0]);
 //   dp[2]= min(dp[1]+ abs(h[2]-h[1]), dp[0]+abs(h[2]-h[0]));
    for(int i=2;i<n;i++){
        
        dp[i]= min(dp[i-1]+ abs(h[i]- h[i-1]), dp[i-2]+ abs(h[i]-h[i-2]));
        
       // cout<<dp[i]<<"  ";
    }
    cout<<dp[n-1]<<endl;
    
    
}

Measured memory_bytes: 1024
import scala.io.StdIn._
import scala.collection.mutable.{ArrayBuffer, PriorityQueue}
object Main extends App {
  val Array(n, m) = readLine.split(" ").map(_.toInt)
  val arbeits = Array.fill(100001)(new ArrayBuffer[Int]())
  for (i <- 1 to n) {
    val Array(a, b) = readLine.split(" ").map(_.toInt)
    arbeits(a) += b
  }

  val possible = PriorityQueue[Int]()
  def exec(day: Int, income: Int): Int = {
    if (day > m) income
    else {
      possible ++= arbeits(day)
      exec(day + 1, income + (if (possible.isEmpty) 0 else possible.dequeue()))
    }
  }

  println(exec(1, 0))
}

Measured memory_bytes: 81000
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn readln<T>() -> T
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().parse().unwrap()
}

fn main() {
    let n: i64 = readln();

    'outer:
    for i in 1..3501 {
        for j in 1..3501 {
            let a = i * j * n;
            let b = 4 * i * j - i * n - j * n;

            if b > 0 && a % b == 0 {
                let k = a / b;
                println!("{} {} {}", i, j, k);
                break 'outer;
            }
        }
    }


}


Measured memory_bytes: 4352
#include <stdio.h>
#define max(a, b) ((a > b) ? a : b)

int main() {
    int a[1001];
    int n, m, i, j;

    while (1) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) { break; }
        for (i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        int ans = -1;
        for (i = 0; i < n; i++) {
            for (j = 0; j < n; j++) {
                // i == j のときはループを飛ばす
                if (i == j) { continue; }
                if (a[i] + a[j] <= m) {
                    ans = max(ans, a[i] + a[j]);
                }
            }
        }
        if (ans == -1) { puts("NONE"); }
        else { printf("%d\n", ans); }
    }
    return 0;
}



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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;

int main()
{
    ll n,k; cin >> n >> k;
    ll a[n];
    rep(i,n) cin >> a[i];
    ll sum[n+1]; rep(i,n+1) sum[i] = 0;
    rep(i,n){
        sum[i+1] = a[i]+sum[i];
    }
    map<ll,ll> mp;
    ll ans = 0;
    rep(i,n+1){
        mp[sum[i] % k]++;
    }
    for(auto i:mp){
        ll x = i.second;
        ans += ((x)*(x-1))/2;
    }
    cout << ans << endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  cout<<(10000-n)%1000<<endl;

  return 0;
}

Measured memory_bytes: 3632
//package atcoder.yahoo;

import java.io.*;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        HashMap<Integer, ArrayList<Integer>> adjacency = new HashMap<>();
        for (int i = 1; i <= 4; i++) {
            adjacency.put(i, new ArrayList<>());
        }
        for (int i = 0; i < 3; i++) {
            int a = s.nextInt();
            int b = s.nextInt();
            ArrayList<Integer> list = adjacency.get(a);
            list.add(b);
            adjacency.put(a, list);
            list = adjacency.get(b);
            list.add(a);
            adjacency.put(b, list);
        }
        
        boolean[] visited = new boolean[5];
        dfs(1, visited, adjacency);
        boolean bool = true;
        for (int i = 1; i < 5; i++) {
            if(!visited[i]) {
                bool = false;
                break;
            }
        }

        if(!bool) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }

    private static void dfs(int num, boolean[] visited, HashMap<Integer, ArrayList<Integer>> adjacency) {
        visited[num] = true;
        ArrayList<Integer> adj = adjacency.get(num);
        boolean bool = false;
        for (int i = 0; i < adj.size(); i++) {
            if(!visited[adj.get(i)] && !bool){
                dfs(adj.get(i), visited, adjacency);
                bool = true;
            }
        }
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <atcoder/scc>
using namespace std;
using namespace atcoder;

int main() {
	int n, m;
	cin >> n >> m;
	
	scc_graph g(n);
	
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		g.add_edge(u, v);
	}
	
	auto scc = g.scc();
	
	cout << scc.size() << endl;
	for (auto v : scc) {
		cout << v.size();
		for (int x : v) {
			cout << " " << x;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 40060
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


N = int(input())
done = False
for h in range(1, 3501):
    for n in range(1, 3501):
        v = (4*h*n) - N*(h+n)
        if v>0 and (N*h*n) % v == 0:
            ans = (h,n, (N*h*n) // v)
            print(" ".join(map(str, ans)))
            done = True
            break
    if done:
        break
    

Measured memory_bytes: 66184
#include<stdio.h>

int main(){
	int a,b;
	scanf("%d %d", &a,&b);
	if (a>b) {
		printf("a > b\n");
	} else if (a<b) {
		printf("a < b\n");
	} else {
		printf("a == b\n");
	}		
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

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

  if (n%2 != 0) {
    cout << 0 << endl;
    return 0;
  }

  n /= 2;
  ll ans = 0;
  ll mul = 5;
  while (true) {
    if (mul > n) break;
    ans += n / mul;
    mul *= 5;
  }

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

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

const int MAX = 1e5+5;

const int MOD = 1e9 + 7;



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int a , b , c;
    cin>>a>>b>>c;
    cout<<min(a*b , c)<<endl;
    return 0;
   
}

Measured memory_bytes: 384
#include <stdio.h>          // printf(), scanf()

#define MAX_N 1000000

int
main(int argc, char **argv)
{
	int val[MAX_N + 1];
	int n, q;
	int a, v;
	int ai, vi;
	int i;

	scanf("%d %d", &n, &q);
	for (i = 1; i <= n; ++i)
		val[i] = 0;

	a = 1, v = 0;
	while (q--)
	{
		scanf("%d %d", &ai, &vi);
		val[ai] += vi;
		if (vi > 0)
		{
			if (val[ai] > v || (val[ai] == v && ai < a))
			{
				a = ai;
				v = val[ai];
			}
		}
		else if (ai == a && val[a] < v)
		{
			a = 1, v = 0;
			for (i = n; i >= 1; --i)
			{
				if (val[i] >= v)
				{
					a = i;
					v = val[i];
				}
			}
		}

		printf("%d %d\n", a, v);
	}

	return 0;
}

Measured memory_bytes: 4504
#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
    int a, b;
    char op;
    while (std::cin >> a >> op >> b)
    {
    if (op == '+')
    {
        std::cout << a + b << std::endl;
    }
    else if (op == '-')
    {
        std::cout << a - b << std::endl;
    }
    else if (op == '*')
    {
        std::cout << a * b << std::endl;
    }
    else if (op == '/')
    {
        std::cout << a / b << std::endl;
    }
    else if (op == '?')
    {
        break;
    }
    }
    return 0;
}



Measured memory_bytes: 3108
#include<stdio.h>

int main (void) {

int a,b,d,r ;

double f ;

scanf("%d",&a) ;

scanf("%d",&b) ;

d=a/b ;

r=a%b ;

f=(double)a/(double)b ;

printf("%d %d %lf\n",d,r,f);

return 0;

}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  string S;
  cin >> S;
  if (regex_match(S, regex("(hi)+")))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int main(){
    long long int n,k,temp,ans = 0;
    cin >> n;
    vector<long long int> h;
    cin >> k;
    for (long long int i = 0; i < n; i++ ){
        cin >> temp;
        h.push_back(temp);
    }
    sort(h.begin(), h.end());
    if(n <= k) cout << 0 << endl;
    else{
        if(k == 0){
            for (long long int i = 0; i < n; i++ ){
                ans += h[i];
            }
            cout << ans << endl;
        }
        else{
            for (long long int i = 0; i < n - k; i++ ){
                ans += h[i];
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2548
def Z(): return int(input())

def main():
    S = [True] * 13
    H = [True] * 13
    C = [True] * 13
    D = [True] * 13
    n = Z()
    for _ in range(n):
        s, i = input().split()
        i = int(i) - 1
        if s == 'S': S[i] = False
        if s == 'H': H[i] = False
        if s == 'C': C[i] = False
        if s == 'D': D[i] = False
    for i in range(13):
        if S[i]: print('S', i+1)
    for i in range(13):
        if H[i]: print('H', i+1)
    for i in range(13):
        if C[i]: print('C', i+1)
    for i in range(13):
        if D[i]: print('D', i+1)

    return

if __name__ == '__main__':
    main()



Measured memory_bytes: 5612
s = list(input())
one_zero_list = ['0' if i%2==0 else '1' for i in range(len(s))]
zero_one_list = ['1' if i%2==0 else '0' for i in range(len(s))]

count_one_zero = len([0 for i in range(len(s)) if s[i]!=one_zero_list[i]])
count_zero_one = len([0 for i in range(len(s)) if s[i]!=zero_one_list[i]])

print(min(count_one_zero,count_zero_one))

Measured memory_bytes: 6188
L = [10, 50, 250, 1250, 6250, 31250, 156250, 781250, 3906250, 19531250, 97656250, \
     488281250, 2441406250, 12207031250, 61035156250, 305175781250, 1525878906250, \
     7629394531250, 38146972656250, 190734863281250, 953674316406250, \
     4768371582031250, 23841857910156250, 119209289550781250, 596046447753906250]
N = int(input())
A = 0
if N % 2 == 0:
  for i in L:
    A += N // i
print(A)

Measured memory_bytes: 2940
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_set>

using namespace std;
using ll = long long;
template<typename T> void print(T t) {cout << t << endl;}


char parityChar[] = { '#','.' };

struct group {
	bool p;
	int numB, numW;
	ll Count() { return (ll)numB * (ll)numW; }
};

bool calcP(int i, int j, char c) {
	return parityChar[(i + j) % 2] == c;
}

void searchB(vector<vector<char>>& board, group& g,  int i, int j) {
	if (board[i][j] != '!' && g.p == calcP(i, j, board[i][j])) {
		if (board[i][j] == '#') g.numB++;
		else g.numW++;
		
		board[i][j] = '!';
		searchB(board, g, i + 1, j);
		searchB(board, g, i - 1, j);
		searchB(board, g, i, j - 1);
		searchB(board, g, i, j + 1);
	}
}
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> board (H+2, vector<char>(W+2, '!'));
	for (int h = 1; h <= H; h++) {
		string S;
		cin >> S;
		for(int w=1; w<=W; w++){
			board[h][w] = S[w-1];
		}
	}

	ll ans = 0;
	for (int h = 1; h <= H; h++) {
		for (int w = 1; w <= W; w++) {
			if (board[h][w]!='!') {
				group g = group{ calcP(h ,w, board[h][w]),0,0 };
				searchB(board, g, h, w);
				ans += g.Count();
			}
		}
	}
	print(ans);
}

Measured memory_bytes: 16244
i,o,t,j,l,s,z=map(int,input().split())
res=0
if i>0 and j>0 and l>0 and i%2+j%2+l%2>=2:
    res+=3
    i-=1
    j-=1
    l-=1
res+=(i//2)*2
res+=o
res+=(j//2)*2
res+=(l//2)*2
print(res)


Measured memory_bytes: 3064
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
typedef modint<MOD> m;
#pragma endregion

int main() {
  string s,t,u;
  cin >> s >> t;
  cin >> A >> B;
  cin >> u;
  if(s == u) cout << A - 1 << " " << B;
  else cout << A << " " << B - 1;
}



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 downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int> > Matrix;
const int MOD = 1e9+7;


int main(){
  int m1,m2,d1,d2; cin>>m1>>d1>>m2>>d2;
  bool flag=1;
  if(d2!=1)flag=0;
  else{
   if(m1==m2-1){
     if(m1==1&&d1==30)flag=1;
     else if(m1==2&&d1==28)flag=1;
     else if(m1==3&&d1==31)flag=1;
     else if(m1==4&&d1==30)flag=1;
     else if(m1==5&&d1==31)flag=1;
     else if(m1==6&&d1==30)flag=1;
     else if(m1==7&&d1==31)flag=1;
     else if(m1==8&&d1==31)flag=1;
     else if(m1==9&&d1==30)flag=1;
     else if(m1==10&&d1==31)flag=1;
     else if(m1==11&&d1==30)flag=1;

   }else if(m1==12&&m2==1&&d1==31)flag=1;
   else flag=0;

  }
  
  cout<<(flag ? 1:0)<<endl;
}

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

int main() {
  int n,ans=0;
  cin>>n;
  map<string,int>p;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    p[s]++;
    if(p[s]==1){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 19168
N,K = map(int,input().split())
A = list(map(int,input().split()))

bs = [0] * 40
for a in A:
    for k in range(40):
        if a&(1<<k):
            bs[k] += 1

x = 0
for k in range(39,-1,-1):
    if x + (1<<k) > K: continue
    if bs[k] < (N+1)//2:
        x += (1<<k)

ans = 0
for a in A:
    ans += x^a
print(ans)

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

public class Main {	
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		String S = fs.next();
		int N = S.length();

		if(isPalindrome(S)) {
        } else {
			System.out.println("No");
			return;
        }
    

		for(int i=0; i<(N-1)/4; i++){
			if(i<=(N-1)/2-1-i&&S.charAt(i)==S.charAt((N-1)/2-1-i)){
			continue;
			}else{
			System.out.println("No");
			return;
			}

		}
		for(int i=0; i<(N-1)/4; i++){
			if((N+3)/2-1-i<=N-1-i&&S.charAt((N+3)/2-1+i)==S.charAt(N-1-i)){
			continue;
			}else{
			System.out.println("No");
			return;
			}

		}

		
		System.out.println("Yes");

		
		

	}
	
	public static boolean isPalindrome(String sentence) {
        int minIdx = 0;
        int maxIdx = sentence.length() - 1;
 
        while(minIdx < maxIdx) {
            if(sentence.charAt(minIdx++) != sentence.charAt(maxIdx--)) {
                return false;
            }
        }
        return true;
    }

	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");

		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

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

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

		public int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) {
				a[i]=nextInt();
			}
			return a;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}
	
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

vector<int> hh(320000);
vector<int> ww(320000);
vector<int> hlis[320000];

int main() {
  int H,W,M;
  cin >> H >> W >> M;
  int h[M],w[M];
  int ans = 0;
  multiset<int> Set;
  for (int i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
    h[i]--; w[i]--;
    hh[h[i]]++;
    ww[w[i]]++;
    hlis[h[i]].push_back(w[i]);
  }

  for (int i = 0; i < W; i++) {
    Set.insert(ww[i]);
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < (int)hlis[i].size(); j++) {
      auto itr = Set.lower_bound(ww[hlis[i][j]]);
      Set.erase(itr);
      Set.insert(ww[hlis[i][j]] - 1);
    }

    auto itr2 = prev(Set.end(),1);
    int res = *itr2 + hh[i];
    ans = max(ans,res);
    
    for (int j = 0; j < (int)hlis[i].size(); j++) {
      auto itr = Set.lower_bound(ww[hlis[i][j]] - 1);
      Set.erase(itr);
      Set.insert(ww[hlis[i][j]]);
    }
  }


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

Measured memory_bytes: 39148
#include <stdio.h>
#include <stdlib.h>
#define N 1000000
int count=0,n,m,C[N],*Q;

void insertionSort(int C[], int n, int e){
  int i,j,v;
  for(i=e;i<n;i++){
    v=C[i];
    j=i-e;
    while(j>=0&&C[j]>v){
      C[j+e]=C[j];
      j-=e;
      count++;
    }
    C[j+e]=v;
  }
}

void shellSort(int C[],int n){
  int i=0,k;

  Q=(int *)malloc(n * sizeof(int));
  for(k=1; ; ){
    if(k>n)
      break;
      Q[i]=k;
      i++;
      k=3*k+1;
    }
    m=i;
    for(i=m-1;i>=0;i--){
      insertionSort(C,n,Q[i]);
    }
  }

  int main(){
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d",&C[i]);
      count=0;
    }
    
    shellSort(C,n);

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

    for(i=m-1;i>=0;i--){
      printf("%d",Q[i]);
      if(i){
	printf(" ");
      }
    }
    printf("\n");
    printf("%d\n",count);
    for(i=0;i<n;i++){
      printf("%d\n",C[i]);
    }

      free(Q);
      return 0;
    }
      



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

using namespace std;

int cnt;
string s;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> s;
	for (int i=0; i<s.length(); i++) {
		if (s[i] != s[s.length() - i - 1]) cnt++;
	}
	cnt /= 2;
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>

using namespace std;

const int N = 100000 + 5;

int n, v;
int cnt[2][N];

int main() {
  // freopen("read.in", "r", stdin);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v);
    cnt[i&1][v]++;
  }
  pair<int, int> mx[2][2];
  for (int i = 1; i < N; i++) {
    for (int p = 0; p < 2; p++) {
      if (cnt[p][i] != 0) {
        pair<int, int> c = make_pair(cnt[p][i], i);
        if (c.first > mx[p][1].first) {
          swap(c, mx[p][1]);
        }
        if (mx[p][1].first > mx[p][0].first) {
          swap(mx[p][0], mx[p][1]);
        }
      }
    }
  }
  int ans;
  if (mx[0][0].second == mx[1][0].second) {
    ans = n - max(mx[0][1].first + mx[1][0].first, mx[0][0].first + mx[1][1].first);
  } else {
    ans = n - mx[0][0].first - mx[1][0].first;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		int[] a = new int[N];
		double sum =0;
		int p=0;
		
		for(int i=0;i<N;i++) {
			a[i]=input.nextInt();
			sum+=a[i];
		}
		for (int i = 0;i<N;i++ ) {
			if ((double)(sum/(4*M))<=a[i]) {
				p++;
			}
		}

		if (p>=M) {
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}
}


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

using namespace std;
typedef long long LL;

const int N=2010,Mod=924844033;

int n,k,P[N],f[N<<1][N][2],g[N],fact[N];
bool use[N<<1],ed[N<<1];

void Init() { scanf("%d%d",&n,&k); }

void Solve()
{
	int len=0;
	for (int i=1;i<=n;++i)
		for (int j=0;j<2;++j)
			if (!use[i<<1|j])
			{
				for (int x=i,op=j;x<=n;x+=k,op^=1)
					use[x<<1|op]=1,++len;
				ed[len]=1;
			}
	
	f[0][0][1]=1;
	for (int i=1;i<=2*n;++i)
		for (int j=0;j<=i/2;++j)
		{
			f[i][j][0]=(f[i-1][j][1]+f[i-1][j][0])%Mod;
			if (!ed[i-1] && j) f[i][j][1]=f[i-1][j-1][0];
		}
	for (int i=0;i<=n;++i)
		g[i]=(f[n<<1][i][0]+f[n<<1][i][1])%Mod;
	
	fact[0]=1; for (int i=1;i<=n;++i) fact[i]=1ll*fact[i-1]*i%Mod;
	
	LL ans=0;int op=1; 
	for (int i=0;i<=n;++i,op=-op)
		ans=(ans+1ll*g[i]*fact[n-i]*op%Mod+Mod)%Mod;
	
	printf("%lld\n",ans);
}

int main()
{
	Init();
	Solve();
	return 0;
}


Measured memory_bytes: 61568
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
  int dp[11][1010];
  for( int i=0; i<11;i++ )
    for( int j=0; j<1010;j++ )
      dp[i][j] = -1;
  dp[0][0] = 0;
  
  int D,G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  
  for( int i=0;i<D;i++ )
    cin >> p[i] >> c[i];

  
  for( int i=1; i<D+1;i++ )
    {
      for( int j=0; j<1001;j++ )
	{
	  if( dp[i-1][j] >= 0)
	    {
	      dp[i][j] = max(dp[i][j], dp[i-1][j]);
	      for( int k=1; k<p[i-1]; k++ )
		dp[i][j+k] = max(dp[i][j+k], dp[i-1][j]+k*i*100);
	      dp[i][j+p[i-1]] = max(dp[i][j+p[i-1]], dp[i-1][j]+p[i-1]*i*100+c[i-1]);
	    }
	}
    }

  int min_cnt = 1<<16;
  for( int i=1; i<D+1;i++ )
    for( int j=0; j<1001;j++ )
      {
	if( dp[i][j]>=G )
	  {
	    min_cnt = min(min_cnt, j);
	  }
      }
  cout << min_cnt << endl;
}


Measured memory_bytes: 256
N,M = gets.split.map(&:to_i)
K = readlines.map {|s| s.split.map(&:to_i) }
P = K.pop

puts (1<<N).times.count {|bit|
  sw = Array.new(N) {|i| (bit>>i) & 1 }
  P.each_with_index.all? do |f,i|
    K[i][1,K[i][0]].count {|j| sw[j-1] == 1 } % 2 == f
  end
}


Measured memory_bytes: 2044
using System;

class p0003
{

    static void Main(string[] args)
    {
        string[] s;
        int[] a = new int[3];


        int n = int.Parse(Console.ReadLine());

        while (0 < n--)
        {
            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < 3; ++i)
            {
                a[i] = int.Parse(s[i]);
                a[i] = a[i] * a[i];
            }

            Array.Sort(a);
            Console.WriteLine("{0}", ((a[2] == a[0] + a[1]) ? "YES" : "NO"));
        }

    }
    
}

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

int main(){
  int n;
  cin >>n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  int cnt = 0;
  rep(i,n){
    if(a[a[i]]==i) cnt++;
  }
  cout << cnt/2 << endl;
  return 0;
}

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

int main(){

int N,wa=0;
  cin >> N;
  
  
char S[N];
  for(int i=0;i<N;i++){
  	cin >> S[i];
  }
  for(int i=0;i<N-1;i++){
  	if(S[i] != S[i+1]){
    	wa++ ;
    }
  }
	cout << wa+1 <<endl;

}

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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if(a == b and a != c)
        cout << "Yes" << endl;
    else if(b == c and b != a)
        cout << "Yes" << endl;
    else if(c == a and c != b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
S = input()

count_0 = 0
count_1 = 0

for i,s in enumerate(S):
    if s == "0" and i%2==0:
        count_1 += 1
    elif s=="1" and i%2==0:
        count_0 += 1

    if s == "1" and i%2==1:
        count_1 += 1
    elif s=="0" and i%2==1:
        count_0 += 1

print(min(count_0,count_1))


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

int main() {
  int N, M;
  cin >> N >> M;
  
  int i;
  vector<int> counts(N);
  for (i = 0; i < M; i++) {
    int from, to;
  	cin >> from >> to;
    counts.at(from - 1) += 1;
    counts.at(to - 1) += 1;
  }
  for (i = 0; i < N; i++) {
    cout << counts.at(i) << endl;
  }
}



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

using namespace std;

int main(){
    int sum;
    string n;
    while(true){
        sum =0;
        cin >> n;
        if(n=="0"){break;}
        for(int i=0;i<n.length();i++){
            string t = "";
            t+= n[i];
            sum += stoi(t);
        }
        cout << sum << endl;
    }

    return 0;
}



Measured memory_bytes: 3176
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
int n;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	cout<<8-(n-400)/200;
	return 0;
}



Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] l = new long[n + 1];
		l[0] = 2;
		l[1] = 1;
		for(int i = 2 ; i <= n ; i++) {
			l[i] = l[i - 1] + l[i - 2];
		}
		System.out.println(l[n]);
	}
}

Measured memory_bytes: 22608
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<ctime>
#define ll long long
#define pr(x) cerr<<#x<<"="<<x<<endl
using namespace std;
int i;
char ch[10000];
int main()
{
	scanf("%s",ch);
	for (i=1;i<strlen(ch);i++)
	{
		if (ch[i-1]=='A'&&ch[i]=='C') 
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

bool check(int mid,int memo){
    if(mid*mid<=memo){
        return false;
    }
    else{
        return true;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int q;
    cin>>q;
    vec a(q),b(q);
    rep(i,q){
        cin>>a[i]>>b[i];
    }
    rep(i,q){
        ll memo=a[i]*b[i];
        int ng = 0, ok = 1000000000+10;
        while (abs(ng-ok)>1) {
          int mid = ng+(ok-ng)/2;
          (check(mid,memo)?ok:ng) = mid;
        }
        // debug(ng);
        // debug(ok);
        if(ng==a[i] && ng==b[i]){
            cout<<2*ng-2<<endl;;
        }
        else if(ng*ng==memo){
            cout<<2*ng-3<<endl;
        }
        else if(ng*(ng+1)<memo){
            cout<<2*ng-1<<endl;
        }
        else{
            cout<<2*ng-2<<endl;
        }
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<string,int> P;
struct node{
  node *next;
  P v;
  node(){next=NULL;}
  node(P v):v(v){next=NULL;}
};
struct mqueue{
  node *head,*cur;
  mqueue(){
    head=new node();
    cur=NULL;
  }
  void push(P v){
    node *tmp=new node(v);
    if(cur!=NULL) cur->next=tmp;
    cur=tmp;
    if(head->next==NULL) head->next=cur;
  }
  void pop(){
    if(head->next==NULL) return;
    node *tmp=head->next->next;
    if(tmp!=NULL) delete(head->next);
    head->next=tmp;
  }
  P front(){
    return head->next->v;
  }
  bool empty(){
    return head->next==NULL;
  }
};
signed main(){
  int n,q;
  cin>>n>>q;
  string name[n];
  int time[n];
  for(int i=0;i<n;i++) cin>>name[i]>>time[i];
  int cur=0;
  mqueue que;
  for(int i=0;i<n;i++) que.push(P(name[i],time[i]));
  while(!que.empty()){
    P p=que.front();que.pop();
    if(p.second<=q){
      cur+=p.second;
      cout<<p.first<<" "<<cur<<endl;
      continue;
    }
    p.second-=q;
    cur+=q;
    que.push(p);
  }
  return 0;
}

Measured memory_bytes: 7800
import java.util.*;
public class Main {
    static Scanner s = new Scanner(System.in);
    public static void main(String __[]) {
        int in[]= {s.nextInt(),s.nextInt(),s.nextInt()};
        Arrays.sort(in);
        System.out.println(in[0]==5&&in[1]==5&&in[2]==7?"YES":"NO");

    }
}


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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define uset unordered_set
#define umap unordered_map

#define endl "\n"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define all(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.k << ", " << p.v << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    cout << (s < t ? "Yes\n" : "No\n");
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a="AC"
arr=[0]*(n+1)
s=input()
for i in range(1,n+1):
    arr[i]=arr[i-1]+s[i-1:i+1].count(a)
for _ in range(m):
    x,y=map(int,input().split())
    print(arr[y-1]-arr[x-1])

Measured memory_bytes: 8020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int N;cin >> N;
    const int MAXN = 100000;
    ll A[MAXN];
    ll mi = LLONG_MAX;
    bool neg=false;
    ll ans = 0;
    rep(i,N)cin >> A[i];
    rep(i,N-1){
        ll a=A[i];
        if(a<0){
            A[i+1] = -A[i+1];
            mi = min(-a, mi);
            ans += -a;
        }else {
            ans += a; 
            mi = min(a,mi);
        }
    }
    if(A[N-1]<=0){
        if(mi>abs(A[N-1])){
            ans += A[N-1];
        }else {
            ans -= A[N-1];
            ans -= mi*2;
        }
        cout << ans << endl;

    }else if(A[N-1]>=0){
        ans += A[N-1];
        cout << ans << endl;
    }
    

    return 0;
}

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

int main() {
	int h,w;
	string raw;
	cin >> h >> w;
	int hh = h, ww = w;
	vector<vector<char>> masu(h, vector<char>(w));
	for (int i=0; i<h; i++) {
		cin >> raw;
		for (int j=0; j<w; j++) masu.at(i).at(j) = raw.at(j);
	}
	while (true) {
		int check=0;
		for (int i=0; i<h; i++) {
			int same=0;
			for (int j=0; j<w; j++) {
				if (masu.at(i).at(j) == '.') same++;
			}
			if (same == ww) {
				check++;
				hh--;
				for (int j=0; j<w; j++) masu.at(i).at(j) = ' ';
			}
		}
		for (int i=0; i<w; i++) {
			int same=0;
			char ch = masu.at(0).at(i);
			for (int j=0; j<h; j++) {
				if (masu.at(j).at(i) == '.') same++;
			}
			if (same == hh) {
				check++;
				ww--;
				for (int j=0; j<h; j++) masu.at(j).at(i) = ' ';
			}
		}
		if (check == 0) break;
	}
	for (int i=0; i<h; i++) {
		int count=0;
		for (int j=0; j<w; j++) {
			if (masu.at(i).at(j) == ' ') count++;
			else cout << masu.at(i).at(j);
		}
		if (count != w) cout << endl;
	}
	return 0;
}



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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    int cnt = 0;
    
    for(int j = 1; j <= n; j++){
      if(i%j == 0) cnt++;
    }
    
    if(cnt == 8 && i%2 == 1){
      ans++;
    }
  }
  cout << ans << endl;
}


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

int main(void){
        int S;
        int h;
        int m;
        int s;
        cin>>S;
        h=S/60/60;
        m=(S-60*h*60)/60;
        s=S-h*60*60-m*60;
        cout<<h;
        cout<<":";
        cout<<m;
        cout<<":";
        cout<<s;
        cout<<endl;
}


Measured memory_bytes: 3108
#include <stdio.h>
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  
  int est;
  
    if(a>b)
      est=a;
    else
      est=b;
    if(c>est)
      est=c;
  
  printf("%d",a+b+c-est);

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        // 配列
        int[] a = new int[n];
        a[0] = sc.nextInt();
        int mx = a[0];
        long sum = 0;
        for(int i=1;i<n;i++){
            a[i] = sc.nextInt();
            if(a[i] < mx) {
                sum += (mx - a[i]);
            } else {
                mx = a[i];
            }
        }
            System.out.println(sum);

    }
   
}



Measured memory_bytes: 61200
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    string S;
    ll K,cnt=0,ans=0;
    cin>>S>>K;
    for(ll i=0;i<S.size();i++){
        cnt++;
        if(S[i]!=S[i+1]||S.size()-1==i){
            if(cnt==S.size()){
                cout<<cnt*K/2<<endl;
                return 0;
            }
            ans+=cnt/2*K;
            cnt=0;
        }
    }
    if(S[0]==S[S.size()-1]){
        ll l,r;
        for(l=0;l<S.size();l++){
            if(S[l]!=S[l+1]) break;
        }
        l++;
        for(r=S.size()-1;r>=0;r--){
            if(S[r]!=S[r-1]) break;
        }
        r=S.size()-r;
        ans-=(l/2+r/2-(l+r)/2)*(K-1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256