akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int,int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define error(x) cerr << #x << " = " << x << endl
#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int INF = 1e9 + 7;

int f(int x, int y) {
    if (max(x, y) <= 1) return 0;
    for (int i = 1; 2 * i <= x; ++i)
        if (f(x-2*i, y+i) == 0) return 1;
    for (int i = 1; 2 * i <= y; ++i)
        if (f(x+i, y-2*i) == 0) return 1;
    return 0;
}

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(nullptr);
    ll x, y; cin >> x >> y;
    if (llabs(x - y) > 1) cout << "Alice\n";
    else cout << "Brown\n";
    return 0;
}


Measured memory_bytes: 256
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60

N, M, Q = map(int, readline().split())
G = [[0] * N for _ in range(N)]
for _ in range(M):
    l, r = map(int, readline().split())
    G[l - 1][r - 1] += 1

csum = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(N):
        csum[i + 1][j + 1] = csum[i + 1][j] + csum[i][j + 1] - csum[i][j] + G[i][j]

ans = []
for _ in range(Q):
    p, q = map(int, readline().split())
    ans.append(csum[q][q] - csum[q][p - 1] - csum[p - 1][q] + csum[p - 1][p - 1])

print(*ans, sep='\n')


Measured memory_bytes: 56156
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main{
	static Map<Long,Long> map= new TreeMap<>();
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  long n=sc.nextLong();
	  for(long i=1;i<=n;i++)primeEnum(i);
	  long res=1;
	  for (long key : map.keySet()){
	    	res*=(map.get(key)+1);
	    	res%=1000000007;
	    	//System.out.println(key+" "+map.get(key));
	    }
	  System.out.println(res);

  }
	public static Map<Long,Long> primeEnum(long n) {
		for(long i=2;i<=Math.sqrt(n);i++) {
			if(n%i!=0)continue;
			long e=0;
			while(n%i==0) {
				e++;
				n/=i;
			}
			if(map.containsKey(i)) {
				map.put(i, e+map.get(i));
			}else {
				map.put(i, e);
			}
		}
		if(n!=1) {
			if(map.containsKey(n)) {
				map.put(n, 1+map.get(n));
			}else {
				map.put(n, 1L);
			}
		}
		return map;
	}
}



Measured memory_bytes: 21716
#include<algorithm>
#include<cstdio>
using namespace std;

int n;
int l[2000];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &l[i]);
    sort(l, l + n);
    long ans = 0;
    for (int i = n - 1; i >= 2; i--) {
        for (int j = i - 1; j >= 1 && 2 * l[j] > l[i]; j--) {
            int k = upper_bound(l, l + n, l[i] - l[j]) - l;
            ans += j - k;
        }
    }

    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

pair<int,int> dfs1(const vector<vector<int>>&edges, const vector<int>&scores, int pre,int now,int  num) {
	num+=scores[now];
	pair<int,int>ans(make_pair(num,now));
	for (auto e : edges[now]) {
		if (pre != now) {

			auto p=dfs1(edges, scores, now,e, num);
			ans=max(ans,p);
		}
	}
	return ans;
}

int solve(const vector<vector<int>>&edges,const vector<int>&scores) {
	auto p1(dfs1(edges,scores,-1,0,0));
	auto p2(dfs1(edges,scores,-1,p1.second,0));
	return p2.first;
}

int main(){
	int N,M;cin>>N>>M;
	vector<int>ws(N);
	vector<int>sum_ws(N+1);
	for (int i = 0; i < M; ++i) {
		string st;cin>>st;
		for (int j = 0; j < N; ++j) {
			if(st[j]=='W')ws[j]++;
		}
	}
	for (int i = 0; i < N; ++i) {
		sum_ws[i+1]=sum_ws[i]+ws[i];
	}

	pair<int,int>ans(1e9,-1);
	for (int i = 0; i <= N; ++i) {
		int er_cnt=(M*i-sum_ws[i])+(sum_ws[N]-sum_ws[i]);
		pair<int,int>p(er_cnt,i);
		if(p<ans)ans=p;
	}
	cout<<ans.second<<" "<<ans.second+1<<endl;
	return 0;
}




Measured memory_bytes: 3332
while 1:
	day = ['Wednes','Thurs','Fri','Satur','Sun','Mon','Tues']
	month = [0,31,60,91,121,152,182,213,244,274,305,335]
	m,d=map(int,input().split())
	if m == 0:
		break
	print(day[(month[m-1]+d)%7]+'day')


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

const int N = 1007;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
char ch[] = {'R', 'L', 'U', 'D'};

LL a[50];
int n, x[N], y[N], c[2];
int len;
char ans[N];

inline LL calc(LL x, LL y) {
    LL ret = max(abs(x + y), abs(x - y));
    if(ret == 0) return -1;
    ret >>= 1;
    return lower_bound(a, a + 39, ret) - a;
}

void go(LL x, LL y, LL p) {
    if(!x && !y) return;
    LL step = 1LL << p;
    LL nx, ny;
    for(int dir = 0; dir < 4; dir++) {
        nx = x + dx[dir] * step;
        ny = y + dy[dir] * step;
        if(calc(nx, ny) <= p - 1) {
            ans[len++] = ch[dir ^ 1];
            go(nx, ny, p - 1);
            break;
        }
    }
}

int main() {
    a[0] = 0;
    a[1] = 1;
    for(int i = 2; i < 39; i++) {
        a[i] = a[i - 1] + (1LL << i - 1);
    }
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d%d", &x[i], &y[i]);
        c[x[i] + y[i] & 1]++;
    }
    if(c[0] && c[1]) return puts("-1"), 0;
    if(c[1]) {
        puts("39");
        for(int i = 0; i < 39; i++) printf("%lld ", 1LL << i);
        puts("");
    }
    else {
        puts("40");
        for(int i = 0; i < 39; i++) printf("%lld ", 1LL << i);
        puts("1");
    }
    for(int i = 1; i <= n; i++) {
        len = 0;
        if(c[0]) x[i]--, ans[len++] = 'R';
        go(x[i], y[i], 38);
        ans[len] = '\0';
        reverse(ans, ans + len);
        puts(ans);
    }
    return 0;
}

/*
1
2 -1
*/


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int yaku8(int n){
    int ans = 0;
    for (int i = 1; i <= n; i += 2){
        int count = 0;
        for (int j = 1; j * j <= i; j++){
            if (j * j == i){
                count ++;
            }else if(i % j == 0){
                count += 2;
            }
        }
        if (count == 8){
            ans += 1;
        }
    }
    return ans;
}

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

    cout << yaku8(n) << endl;

    return 0;
}

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

const int N = 1e5;

int in[N+10],out[N+10],n;

int main() {
	//freopen("F:\\rush.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		int l, r;
		cin >> l >> r;
		cnt += r - l + 1;
	}
	cout << cnt << endl;
	return 0;
}

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

#define FOR(i,x,y) for(int i = (x);i < (y);i++)
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) (int) (x).size()
typedef long long ll;

int N,L;
vector<ll> A;

int main()
{
	scanf("%d%d",&N,&L);
	A.resize(N);
	FOR(i,0,N){
		scanf("%d",&A [i]);
	}
	FOR(i,1,N){
		if(A [i - 1] + A [i] >= L){
			printf("Possible\n");
			for(int j = 1;j < i;j++){
				printf("%d\n",j);
			}
			for(int j = N - 1;j > i;j--){
				printf("%d\n",j);
			}
			printf("%d\n",i);
			return 0;
		}
	}

	printf("Impossible\n");

	return 0;
}


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

int main() {
  int N,Q;
  string S;
  cin>>N>>Q>>S;
  vector<int>p={};
  for(int i=0;i<N-1;i++){
    if(S.at(i)=='A'&&S.at(i+1)=='C'){
      p.push_back(i);
    }
  }
  for(int i=0;i<Q;i++){
    int l,r;
    cin>>l>>r;
    int A=lower_bound(p.begin(),p.end(),l-1)-p.begin();
    int B=lower_bound(p.begin(),p.end(),r-1)-p.begin();
    cout<<B-A<<endl;
  }


}

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

const int N = 100005;

int q, m, n, dsu[2 * N];
long long ans = 0;
bool vis[2 * N];

struct SQuery {
    int v, x, y;
} a[N];

int trace(int u) {
    return dsu[u] < 0 ? u : dsu[u] = trace(dsu[u]);
}

bool connect(int u, int v) {
    u = trace(u); v = trace(v);
    if (vis[u] && vis[v]) {
        return false;
    }
    if (u == v) {
        vis[u] = true;
    } else {
        if (dsu[u] > dsu[v]) {
            swap(u, v);
        }
        dsu[u] += dsu[v];
        vis[u] |= vis[v];
        dsu[v] = u;
    }
    return true;
}

int main() {
    cin >> q >> m >> n;
    for (int i = 1; i <= q; i++) {
        cin >> a[i].x >> a[i].y >> a[i].v;
        a[i].y += m;
    }
    fill(dsu + 1, dsu + m + n + 1, -1);
    sort(a + 1, a + q + 1, [](const SQuery &a, const SQuery &b) {
        return a.v > b.v;
    });
    for (int i = 1; i <= q; i++) {
        if (connect(a[i].x, a[i].y)) {
            ans += a[i].v;
        }
    }
    cout << ans;
}


Measured memory_bytes: 2304
n=int(input())
h=list(map(int,input().split()))
cost=[]
cost.append(0)
cost.append(abs(h[1]-h[0]))
for i in range(1,n-1):
    cost.append(min(abs(h[i+1]-h[i])+cost[i] ,abs(h[i+1]-h[i-1])+cost[i-1]))

print(cost[n-1])


Measured memory_bytes: 55400
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)

const int INF = 100000000;

using namespace std;


int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length() - 8; i++) {
		cout << s[i];
	}
	cout << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int a,b,c;
  a=0;
  b=0;
  c=0;
  cin >> str;
  int i;
  for(i=0;i<3;i++){
    if(str[i]=='a'){
      a=1;
    }
    if(str[i]=='b'){
      b=1;
    }
    if(str[i]=='c'){
      c=1;
    }
  }
  if(((a==1)&&(b==1))&&(c==1)){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int n,m;
	cin>>n>>m;
	
	vector<pair<int,int>> ans;
	if(n%2==0) {
		int i,j;
		set<int> s;
		for(i=1,j=n;i<j&&m&&s.find(j-i)==s.end() && j-i!=n-(j-i);m--,i++,j--) {
			cout<<i<<" "<<j<<"\n";
			ans.pb({i,j});
			s.insert(j-i);
			s.insert(n-(j-i));
		}
		j--;
		for(;i<j&&m;i++,j--) {
			ans.pb({i,j});
			cout<<(i)<<" "<<j<<"\n";
			m--;
		}
		
	}else {
		for(int i=1,j=n;i<j&&m;m--,i++,j--) {
			ans.pb({i,j});
			cout<<i<<" "<<j<<"\n";
		}
	}
	LOG(m);
	assert(m==0);
	
	//~ map<pair<int,int>,int> cnt;
	//~ for(auto i:ans) {
		//~ pair<int,int> akt=i;
		//~ akt.xx--;
		//~ akt.yy--;
		//~ for(int j=0;j<n;++j) {
			//~ cnt[{min(akt.xx,akt.yy),max(akt.xx,akt.yy)}]++;
			//~ akt.xx=(akt.xx+1)%n;
			//~ akt.yy=(akt.yy+1)%n;
		//~ }
	//~ }
	
	//~ for(auto i:cnt) {
		//~ cerr<<"{"<<(i.xx.xx)<<";"<<(i.xx.yy)<<"} -> "<<i.yy<<"\n";
		//~ assert(i.yy<2);
	//~ }
	return 0;
	
}


Measured memory_bytes: 7380
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, K;
    cin >> N >> K;

    string S;
    cin >> S;

    vector<int> LR;
    int cnt = 1;
    repd(i, 1, S.size()) {
        if (S[i] != S[i - 1]) {
            LR.push_back(cnt);
            cnt = 0;
        }
        cnt++;
    }

    LR.push_back(cnt);

    int index = K * 2 - 1;
    int ans = 0;

    int lenLR = LR.size();
    for (int i = 0; i <= index + 1; i++) {
        if (i >= lenLR) break;
        ans += LR[i];
    }

    for (int i = index + 2; i < lenLR; i++) {
        ans += LR[i] - 1;
    }

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

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 a, b;
    cin >> a >> b;
    if (a > 0 && b > 0) {
        cout << "Positive" << endl;
    } else if (a * b <= 0) {
        cout << "Zero" << endl;
    } else {
        cout << ((b - a + 1) % 2 ? "Negative" : "Positive") << endl;
    }
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f,N=1e6;
int n,m,cnt;
char ch[N];
queue<int>q;
int du[N],a[N],fir[N],to[N],nxt[N];
long long ans;
inline void add(int u,int v)
{
	to[++cnt]=v,nxt[cnt]=fir[u],fir[u]=cnt;du[v]++;
}
int mian()
{
	
}
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1)+1;
	for(int i=1;i<n;i++)
	if(ch[i]=='<')add(i,i+1);else add(i+1,i);
	for(int i=1;i<=n;i++)if(du[i]==0)q.push(i);
	while(!q.empty())
	{
		int x=q.front();q.pop();//cout<<x<<endl;
		ans+=a[x];
		for(int i=fir[x];i;i=nxt[i])
		{
			a[to[i]]=max(a[to[i]],a[x]+1);
			du[to[i]]--;if(!du[to[i]])q.push(to[i]);
		}
	}cout<<ans;
	return 0;
}


Measured memory_bytes: 21248
#include<iostream>
using namespace std;
#include<stdio.h>

int main(){
    int n; 
    scanf("%d\n", &n);
    int i = 0; 
    int x, min, max;
    long sum;
    min = 1000000;
    max = - 1000000;
    sum = 0; 
    while (i <= n){
        if(i == n){
            printf("%d %d %ld\n", min, max, sum); 
            break;}
        scanf("%d", &x);  
        if(x < min){
            min = x;
            }
        if(max < x){
            max = x;
            }
        sum += x; 
        i += 1;
    }
    return 0;
}

Measured memory_bytes: 1192
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;
  std::vector<int> f(n * 10);
  for (int ni = 0; ni < n; ++ni) {
    for (int di = 0; di < 5; ++di) {
      for (int ti = 0; ti < 2; ++ti) {
        std::cin >> f[ti + 2 * di + 10 * ni];
      }
    }
  }
  std::vector<std::vector<int>> p(n, std::vector<int>(11));
  for (int ni = 0; ni < n; ++ni) {
    for (int ci = 0; ci <= 10; ++ci) {
      std::cin >> p[ni][ci];
    }
  }
  int ans = -2e9;
  for (int i = 1; i < 1024; ++i) {
    int prof = 0;
    for (int ni = 0; ni < n; ++ni) {
      int c = 0;
      for (int j = 0; j < 10; ++j) {
        if (((i >> j) & 1) && f[j + 10 * ni]) {
          ++c;
        }
      }
      prof += p[ni][c];
    }
    ans = std::max(ans, prof);
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 888
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = [list(input()) for i in range(3)]
t = [[],[],[]]
for i in range(3):
    for j in range(len(s[i])):
        if s[i][j] == 'a':
            t[i].append(0)
        elif s[i][j] == 'b':
            t[i].append(1)
        else:
            t[i].append(2)
# print(s)
now = 0
while True:
    tmp = t[now][0]
    del t[now][0]
    now = tmp
    if not len(t[now]):
        break
if now == 0:
    print('A')
elif now == 1:
    print('B')
else:
    print('C')


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int liked[] = new int[31];
        for (int i = 0; i < N; ++i) {
            int K = sc.nextInt();
            for (int j = 0; j < K; ++j) {
                int A = sc.nextInt();
                ++liked[A];
            }
        }
        int res = 0;
        for (int i = 0; i < 31; ++i) {
            if (liked[i] == N) ++res;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
	int n;
	int all = 100;
	int a, b;
	//int a = 0;
	bool flag = false;

	//vector<int>vec;

	//string str;
	//char a[200000][10];

	cin >> n;
	cin >> a >> b;
	//all = n;

	for (int i = a; i <= b; i++)
	{
		//cin >> str[i];
		//cin >> a[i];
		//all += all / 100;
		//a++;
		if (i % n == 0)
		{
			flag = true;
			break;
		}
	}

	if (flag == true)
	{
		cout << "OK" << "\n";
	}
	else
	{
		cout << "NG" << "\n";
	}

	//cout << a;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	cout << s.substr(0,SZ(s)-8) << endl;
	return 0;
}

Measured memory_bytes: 256
'''
長さ 4 の数字列 S が与えられます。あなたは、この数字列が以下のフォーマットのどちらであるか気になっています。

YYMM フォーマット: 西暦年の下 2 桁と、月を 2 桁で表したもの (例えば 1 月なら 01) をこの順に並べたものMMYY フォーマット: 月を 2 桁で表したもの 
(例えば 1 月なら 01) と、西暦年の下 2 桁をこの順に並べたもの与えられた数字列のフォーマットとして考えられるものが YYMM フォーマットのみである場合 YYMM を、 
MMYY フォーマットのみである場合 MMYY を、 YYMM フォーマット と MMYY フォーマットのどちらの可能性もある場合 AMBIGUOUS を、 どちらの可能性もない場合 NA を出力してください。
'''

def main():
	'''
	メイン関数
	'''
	# 文字列
	S = input()

	# 表示
	mae = S[0] + S[1]
	ushiro = S[2] + S[3]

	m_M_flag = False
	u_M_flag = False

	if int(mae) > 0 and int(mae) < 13 :
		m_M_flag = True
		
	if int(ushiro) > 0 and int(ushiro) < 13 :
		u_M_flag = True

	if m_M_flag and u_M_flag:
		print("AMBIGUOUS")
	elif m_M_flag and not u_M_flag:
		print("MMYY")
	elif not m_M_flag and u_M_flag:
		print("YYMM")
	elif not m_M_flag and not u_M_flag:
		print("NA")
	


if __name__ == '__main__':
	main()


Measured memory_bytes: 3064
N = int(input())
s = [input() for _ in range(N)]
last = s[0][-1]

for i in range(1, N):
    if s[i][0] != last:
        print("No")
        break
    last = s[i][-1]
    if s.count(s[i]) > 1:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

// グリッド上の縦横移動
constexpr std::array<std::pair<int, int>, 4> dxdy = {
    std::pair<int, int>( 1,  0),
    std::pair<int, int>(-1,  0),
    std::pair<int, int>( 0,  1),
    std::pair<int, int>( 0, -1)
};

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

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

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

inline bool isIn(int x, int y, int H, int W){
    return 0 <= x and x < H and 0 <= y and y < W;
}
inline bool bitUP(int state, int k){ return (state >> k) & 1; }
inline bool bitUP(long long int state, int k){ return (state >> k) & 1;}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


std::multiset<int> S, T;

int main(void){
    int n; scanf("%d", &n);
    int N = 1 << n;
    REP(i, N){
        int a; scanf("%d", &a);
        S.insert(-a);
    }
    std::queue<int> Q;
    T.insert(*S.begin());
    S.erase(S.begin());
    for(int x = 0; x < n; ++x){
        for(auto itr = T.begin(); itr != T.end(); ++itr){
            auto itr2 = S.upper_bound(*itr);
            if(itr2 == S.end()){
                puts("No");
                return 0;
            }
            Q.push(*itr2);
            S.erase(itr2);
        }
        while(not Q.empty()) T.insert(Q.front()), Q.pop();
    }
    puts("Yes");

    

    
  



    return 0;
}

Measured memory_bytes: 13184
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const ijt mod = 1e9+7;
ijt f[200020];
int main(void) {

	f[0] = f[1] = 1;
	for (ijt i = 2; i <= 200010; i++) {
		f[i] = (f[i-1]*i) % mod;
	}
	
	ijt n;cin >> n;
	vector<pair<ijt,ijt>> a(2*n);
	for (int i = 0; i < 2*n; i++)
	{
		int x;cin >> x;
		if (i < n) {
			a[i] = mp(x,0);
		}
		else {
			a[i] = mp(x,1);
		}
	}
	sort(all(a));
	ijt ans = 1ll;

	ijt x = 0,y = 0;
	for (int i = 0; i < 2*n ; i++)
	{
		if (a[i].second == 0) {
			if(y == 0)x++;
			else {
				ans *= y; ans %= mod;
				y--;
			}
		}
		else {
			if(x == 0) y++;
			else {
				ans *= x;ans%=mod;
				x--;
			}
		}
	}
	//ans*=f[x];
	ans%=mod;
	cout << ans << endl;

}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
  int a,b,c;
  cin >>a >> b >> c;
  bool ans = false;

  for(int i = b; i <= c; i++){
      if(i % a == 0){
          ans = true;
          break;
      }
  }
  if(ans == true){
      cout << "OK" << endl;
  }else{
      cout << "NG"<< endl;
  }
}


Measured memory_bytes: 3684
class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;
  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
}
const kitaiti = (arr) => {
  let r=0
  for(const a of arr){
    r+=a*(a+1)/2/a
  }
  return r
}
const main = () => {
  const o = new AtCoder()
  o.o(o.n()*2*Math.PI)
}
main();

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  reverse(a.begin(), a.end());
  if (a.at(0) == b.at(0)) {
    reverse(b.begin(), b.end());
    if (b.at(0) == c.at(0)) {
      cout << "YES" << endl;
    }
    else cout << "NO" << endl;
  }
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
    int H,W;
    while(1){
        cin >> H>> W;
        if(H==0&&W==0)break;
        for( int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cout << "#";
            }
        cout << "\n";
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3104
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int R = Cin.Ni();
        int G = Cin.Ni();
        int diff = G - R;
        Console.WriteLine(G + diff);

    }
}


public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string Next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return Next();
    }

    public static int Ni() {
        return int.Parse(Next());
    }

    public static long NextLong() {
        return long.Parse(Next());
    }

    public static double NextDouble() {
        return double.Parse(Next());
    }

}


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

const int N = 200005;
int a[N], b[N], aa[N], bb[N], n;

int low_binary(int pos, int value){
	int lo = 0, hi = n - 1, mid, res = -1;
	while(lo <= hi){
		mid = (lo + hi) >> 1;
		if(aa[pos] + bb[mid] >= value){
			res = mid;
			hi = mid - 1;
		}
		else{
			lo = mid + 1;
		}
	}
	return res;
}

int high_binary(int pos, int value){
	int lo = 0, hi = n - 1, mid, res = -1;
	while(lo <= hi){
		mid = (lo + hi) >> 1;
		if(aa[pos] + bb[mid] >= value){
			hi = mid - 1;
		}
		else{
			res = mid;
			lo = mid + 1;
		}
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  	int i, bit;
	int ans = 0;
	cin >> n;
	for(i = 0; i < n; ++i)cin >> a[i];
	for(i = 0; i < n; ++i)cin >> b[i];
	for(bit = 0; bit < 31; ++bit){
		int T = (1 << bit);
		for(i = 0; i < n; ++i){
			aa[i] = a[i] % (2*T);
			bb[i] = b[i] % (2*T);
		}

		sort(bb, bb + n);

		int ct = 0, lower_bound, upper_bound;

		for(i = 0; i < n; ++i){
			lower_bound = low_binary(i, T);
			upper_bound = high_binary(i, 2*T);
			if(lower_bound != -1)
				ct = ct + (upper_bound - lower_bound + 1);
			lower_bound = low_binary(i, 3*T);
			upper_bound = high_binary(i, 4*T);
			if(lower_bound != -1)
				ct = ct + (upper_bound - lower_bound + 1);	
		}


		if(ct & 1)
			ans = ans + T;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
int main(void){
    char s[3];
    
    scanf("%c",&s[0]);
    scanf("%c",&s[1]);
    scanf("%c",&s[2]);
    
    if(s[1]=='B'){
        s[1]='R';
    }else{
        s[1]='B';
    }
    
    printf("%c%c%c\n",s[0],s[1],s[2]);
    
    return 0;
}

Measured memory_bytes: 2056
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define all(m) m.begin(), m.end()
#define uid uniform_int_distribution
#define init(m, x) memset(m, x, sizeof(m));
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    int a,b,x1,y1,x2,y2; cin>>a>>b>>x1>>y1>>x2>>y2;
    x1--, y1--, x2--, y2--;
    str m[a];
    for(int q=0; q<a; q++) cin>>m[q];
    int inf = 1e9;
    int o[a][b];
    for(int q=0; q<a; q++) fill(o[q], o[q]+b, inf);
    o[x1][y1] = 0;
    deque<pii> d = {{x1, y1}};
    for(; d.size(); ){
        int x = d.front().F;
        int y = d.front().S;
        d.pop_front();
        for(int dx=-2; dx<=2; dx++){
            for(int dy=-2; dy<=2; dy++){
                int nx = x+dx, ny = y+dy;
                if(nx<0 || ny<0 || nx>=a || ny>=b) continue;
                if(o[nx][ny]<=o[x][y] || m[nx][ny]=='#') continue;
                int fl = abs(dx)+abs(dy)==1;
                if(!fl) {
                    o[nx][ny] = o[x][y] + 1;
                    d.pb({nx, ny});
                }
                else{
                    o[nx][ny] = o[x][y];
                    d.push_front({nx, ny});
                }
            }
        }
    }
    cout<<(o[x2][y2]==inf ? -1 : o[x2][y2]);
}

Measured memory_bytes: 9308
import collections
n,m = map(int,input().split())
box = [[1,"white"] for i in range(n)]
box[0][1] = "red"
for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    if box[x][1] == "red":
        box[y][1] = "red"
    box[y][0] += 1
    box[x][0] -= 1
    if box[x][0] == 0:
        box[x][1] = "white"
ans = 0
for i in range(n):
    if box[i][1] == "red":
        ans += 1
print(ans)

Measured memory_bytes: 17852
#include<stdio.h>
int main()
{
	int t,n,i;
	for(i=0;i<4;i++){
		scanf("%d%d",&t,&n);
		switch(t){
		case 1:
			printf("%d\n",6000*n);
			break;
		case 2:
			printf("%d\n",4000*n);
			break;
		case 3:
			printf("%d\n",3000*n);
			break;
		default:
			printf("%d\n",2000*n);
		}
	}
	return 0;
}

Measured memory_bytes: 2736
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する

int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,n){
        cin>>h[i];
    }
    vector<int> dp(n);
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    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[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, k;
    cin >> n >> k;
    if(k <= (n-1)*(n-2)/2){
        cout << n-1 + (n-1)*(n-2)/2 - k << endl;
        for(int i=2;i<=n;i++){
            cout << 1 << " " << i << endl;
        }
        int x = (n-1)*(n-2)/2 - k;
        for(int i=2;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(x <= 0) return 0;
                cout << i << " " << j << endl;
                x--;
            }
        }
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

int solve(int x, int L, vector<pair<int, int> > &f){
    int len = f[L - 1].first + f[L - 1].second;
    if(x == 1 && L == 0) return 1;
    if(x == 1) return 0;
    else if(x < len + 2) return solve(x - 1, L - 1, f);
    else if(x == len + 2) return 1 + f[L - 1].second;
    else if(x < 2 * len + 3) return 1 + f[L - 1].second + solve(x - (len + 2), L - 1, f);
    else return 1 + 2 * f[L - 1].second;
}

signed main(){

    int n, x; cin >> n >> x;
    vector<pair<int, int> > f(n + 1);
    f[0] = {0, 1};
    for(int i = 0; i < n; i++){
        f[i + 1].first = 2 * f[i].first + 2;
        f[i + 1].second = 2 * f[i].second + 1;
    }

    cout << solve(x, n, f) << endl;

    return 0;
}

Measured memory_bytes: 256
//1.read question_2.read I/O_3.read test cases_4.read constraints(to decide TC of solution)_5.decide method_6.dry run_
//7.code_8.test_9.submit
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define _READ freopen("input.txt","r", stdin);
#define pb push_back
#define MP make_pair
#define _FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{

    _FAST
    lli n,t,i,j,k,ans=0,flag=0,a,b,m;
    cin>>n;
    vector<vector<lli>> v(n,vector<lli>(3,0));
    vector<vector<lli>> dp(n,vector<lli>(3,0));
    for(i=0;i<n;i++)
        cin>>v[i][0]>>v[i][1]>>v[i][2];
    dp[0][0]=v[0][0];
    dp[0][1]=v[0][1];
    dp[0][2]=v[0][2];
    for(i=1;i<n;i++)
    {
        dp[i][0]=v[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=v[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=v[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    //for(i=0;i<n;i++)
    //    cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<"\n";
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }
    //add x, [a, b)
    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }
    //getsum[a, b)
    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, D, A;
    cin >> N >> D >> A;
    vector<ll> X(N), H(N), idx(N);
    REP(i,N) cin >> X[i] >> H[i];
    iota(idx.begin(), idx.end(), 0);
    sort(idx.begin(), idx.end(), [&](int x, int y){return X[x] < X[y];});
    vector<ll> nH(N), nX(N);
    REP(i,N){
        nH[i] = H[idx[i]];
        nX[i] = X[idx[i]];
    }
    LazySegmentTree seg(nH);

    ll ans = 0;
    REP(i,N){
        ll cur = seg.getsum(i, i+1);
        if(cur <= 0) continue;
        ll need = (cur + A - 1) / A;

        ll right = nX[i] + D * 2;
        int next = upper_bound(nX.begin(), nX.end(), right) - nX.begin();

        seg.add(i, next, -need*A);
        ans += need;
    }
    cout << ans << endl;
}

Measured memory_bytes: 17792
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<62;
int main(){
    int n;
    cin>>n;
    string str;
    cin>>str;
    int ret = 0;
    for(int w=0;w<n;++w){
        auto S = str.substr(w);
        vector<int> A((int)S.size());
        int i=1;int j=0;
        A[0] = (int)S.size();
            while (i < (int)S.size()) {
                while (i+j < (int)S.size() && S[j] == S[i+j]) ++j;
                A[i] = j;
                if (j == 0) { ++i; continue;}
                int k = 1;
                while (i+k < (int)S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
                i += k; j -= k;
            }
        for(int i=1;i<(int)A.size();++i)ret = max(ret,(i+1<=A[i])?i:A[i]);
    }
    cout << ret << endl;
    return 0;
}



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

int gcd(int a, int b){
  if(b == 0) return a;
  return gcd(b, a%b);
}

int main(){
  int n; cin >> n;
  vector<int> l(n), r(n), a(n);

  for(int i=0; i<n; ++i) cin >> a[i];

  l[0] = a[0];
  for(int i=1; i<n; ++i){
    l[i] = gcd(l[i-1], a[i]);
  }

  r[n-1] = a[n-1];
  for(int i=n-2; i>=0; --i){
    r[i] = gcd(r[i+1], a[i]);
  }

  int ans = 0;
  ans = max(l[n-2], r[1]);
  for(int i=1; i<=n-2; ++i){
    ans = max(ans, gcd(l[i-1], r[i+1]));
  }

  cout << ans << endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> switches(m, vector<int>(0));
    for (int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x;
            cin >> x;
            --x;
            switches[i].emplace_back(x);
        }
    }
    vector<int> p(m);
    for (int l = 0; l < m; ++l) cin >> p[l];
    int ans = 0;
    for (int i = 0; i < (1 << n); ++i) {
        bitset<10> bs(i);
        bool flag = false;
        for (int j = 0; j < m; ++j) {
            int cnt = 0;
            for (int s : switches[j]) if (bs.test(s)) cnt++;
            if (cnt % 2 != p[j]) {
                flag = true;
                break;
            }
        }
        if (!flag) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    rep(i, N) {
        int t;
        cin >> t;
        if (!(A <= t && t < B)) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
L = list(map(int,input().split()))
LL = []
for i in range(n):
    kitai = (L[i]+1)/2
    LL.append(kitai)
num = [0]
for i in range(1,n+1):
    num += [num[-1]+LL[i-1]]
ans = 0
for i in range(n-k+1):
    ans = max(ans,num[i+k]-num[i])
print(ans)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 305, MOD = 998244353;
bitset<N> b[N];

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

    int n, m;
    cin >> n >> m;

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

    ll bad = 1;

    for (int i = 0, j = 0; i < m; i++) {
        int sel = -1;
        for (int k = j; k < n; k++) {
            if (b[k][i] == 1) {
                sel = k;
                break;
            }
        }
        if (sel == -1) {
            bad = bad * 2 % MOD;
        }
        else {
            swap(b[sel], b[j]);
            for (int k = 0; k < n; k++) {
                if (k != j && b[k][i] == 1) {
                    b[k] ^= b[j];
                }
            }
            j++;
        }
    }

    ll ans = 1;
    for (int i = 0; i < m; i++) {
        ans = ans * 2 % MOD;
    }

    ans = (ans - bad + MOD) % MOD;

    for (int i = 0; i < n - 1; i++) {
        ans = ans * 2 % MOD;
    }

    cout << ans << "\n";

    return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n){
    cin >> a[i];
  }

  ll ans = 0, cnt = 0, sum = 0;

  REP(i, n){
    sum += a[i];
    if(i % 2 == 1 && sum >= 0){
      cnt += sum + 1;
      sum = -1;
    }
    else if(i% 2 == 0 && sum <= 0){
      cnt += 1 - sum;
      sum = 1;
    }
  }
  ans = cnt;
  cnt = sum = 0;
  REP(i, n){
    sum += a[i];
    if(i % 2 == 0 && sum >= 0){
      cnt += sum + 1;
      sum = -1;
    }
    else if(i% 2 == 1 && sum <= 0){
      cnt += 1 - sum;
      sum = 1;
    }
  }
  ans = min(ans, cnt);
  cout << ans << endl;
  return 0;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	int c, d;
	c = max(a, b);
	d = min(a, b);
	if (c - d >= 1)cout << 2 * c - 1 << endl;
	if (c == d)cout << 2 * c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("unroll-loops,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
typedef complex<long double> com;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll h,n;
	cin >> h >> n;
	vector <ii> arr(n);
	for (int z=0;z<n;z++){
		cin >> arr[z].first >> arr[z].second;
	}
	vector <ll> health(h+1,LLONG_MAX);
	health[h] = 0;
	for (int z=h;z>=0;z--){
		if (health[z] == LLONG_MAX) continue;
		for (int x=0;x<n;x++){
			health[max(ll(0),ll(z-arr[x].first))] = min(health[max(ll(0),ll(z-arr[x].first))],health[z]+arr[x].second);
		}
	}
	cout << health[0] << endl;
}
 


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

const int MAX = 1000000000;

int main(void) {
    list<int> mem;
    int n;
    cin >> n;
    int ans = 0;
    map<int, bool> mp;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        mp[x] = !mp[x];
        if (mp[x])
            ans++;
        else
            ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	for (int i=0;i<s.size()-1;i++)
		if (s[i]=='A'&&s[i+1]=='C') return puts("Yes"),0;
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	long long n;
	cin>>n;
	long long MOD = 1e9 + 7;
	long long ans = 1;
	for(int i = 1; i < n + 1; i++){
		(ans *= i) %= MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
import numpy as np
n, d = map(int, input().split())
cnt = 0
X = []
for i in range(n):
    x = list(map(int, input().split()))
    X.append(x[:])
X = np.array(X)
for i in range(n):
    X_tmp = X[:]
    X_tmp -= X[i]
    for i in range(n):
        x = X_tmp[i]
        x_sq = x**2
        x_sq = np.sqrt(sum(x_sq))
        if x_sq % 1 == 0:
            cnt += 1
print((cnt-n)//2)

Measured memory_bytes: 12412