akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
using namespace std;

int main(){
int h[100000];
int n,m;
cin>>n>>m;
int ans[100000];
for(int i=0;i<n;i++){
	cin>>h[i];
	ans[i]=1;
}
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
a--;b--;
if(h[a]<=h[b]){ans[a]=0;}
if(h[b]<=h[a]){ans[b]=0;}
}
int u=0;
for(int i=0;i<n;i++){
u+=ans[i];
}
cout<<u<<endl;
}

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

int main()
{
    int n,k;
    string s;
    bool part1=false , part2=false;
   cin>>s;
   string y=s.substr(0,2);
   int yy=stoi(y);
   if(yy>=1&&yy<=12) part1=true; 
    string x=s.substr(2,2);
    int xx=stoi(x);
   if(xx>=1&&xx<=12)part2=true;
    
    if(part1==true&&part2==true)cout<<"AMBIGUOUS"<<endl; 
    else if(part1==true&&part2==false)cout<<"MMYY"<<endl;
    else if(part1==false&&part2==true)cout<<"YYMM"<<endl;
    else if(part1==false&&part2==false)cout<<"NA"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a + b < 10) {
			System.out.println(a + b);
		}else {
			System.out.println("error");
		}

	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int H1, M1, H2, M2, K;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H1 >> M1 >> H2 >> M2 >> K;

	int st = H1 * 60 + M1;
	int gl = H2 * 60 + M2;

	int len = gl - st;
	int ans = len - K;
	cout << ans << endl;
}







Measured memory_bytes: 3608
from sys import stdin
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd
def ii(): return int(stdin.readline())
#def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
#def fmi(): return map(float, stdin.readline().split())
def li(): return [x for x in mi()]
#def si(): return stdin.readline()
n=int(input())
print(n*n)

Measured memory_bytes: 2940
def main():
    import sys
    import collections
    input = sys.stdin.readline
    N = int(input())
    S = [input() for i in range(N)]
    c = collections.Counter(S)
    max_num = c.most_common(1)[0][1]
    c_most = list(c.most_common())
    ss = [cc[0] for cc in c_most if cc[1] == max_num]
    ss.sort()
    print("".join(ss))

if __name__ == "__main__":
    main()

Measured memory_bytes: 50536
#include <cstdio>
#include <cstring>

char s[100010];
char s2[100010];
int res;

void solve()
{
	int i, j;
	int len = strlen(s);
	res = 0;
	while(1){
		int modi = 0;
		s2[0] = s[0];
		j = 1;
		for(i=1; i<len-1; i++){
			if(s[i-1] == s[i+1]){
				s2[j] = s[i];
				j ++;
			}
			else{
				modi = 1;
				res ++;
				i ++;
				if(i == len-1)
					break;
				s2[j] = s[i];
				j ++;
			}
		}
		s2[j] = s[len-1];
		j ++;
		if(modi == 1){
			for(i=0; i<j; i++)
				s[i] = s2[i];
			len = j;
		}
		else
			break;
	}
	if(res % 2 == 1)
		printf("First\n");
	else
		printf("Second\n");
}

int main()
{
	scanf("%s", s);
	solve();
	return 0;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)

def li():
    return [int(x) for x in input().split()]


N = int(input())

xs, ys = [], []
for i in range(N):
    x, y = li()
    xs.append(x)
    ys.append(y)


def get_max_manhattan_distanse(xs, ys):
    X = [xs[i] + ys[i] for i in range(len(xs))]
    Y = [xs[i] - ys[i] for i in range(len(xs))]
    # return max(max(X) - min(X), max(Y) - min(Y))
    X.sort()
    Y.sort()
    return max(X[-1] - X[0], Y[-1] - Y[0])

ans = get_max_manhattan_distanse(xs, ys)
print(ans)

Measured memory_bytes: 121328
//AC

#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	string s; cin>>s;
	int len = s.size();
	
	int start = 0, end = 0;
	int s_flag = 0;
	for(int i = 0; i < len; i++){
		if(s[i] == 'A' && s_flag == 0){
			s_flag = 1;
			start = i;
		}
		else if(s[i] == 'Z'){
			end = i;
		}
	}
	
	cout<<end+1-start<<endl;
	return 0;
}



Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    i64 ans = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= n; k++)
            {
                ans += gcd(i, gcd(j, k));
            }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3640
n,k = [int(i) for i in input().split()]
r,s,p = [int(i) for i in input().split()]
t = input()
res = 0
for i in range(0,k):
    pre = True
    for j in range(0,n//k+1):
        index = j*k + i
        if index < n:
            if pre:
                if t[index] == 'r':
                    res += p
                elif t[index] == 's':
                    res += r
                else:
                    res += s
                pre = False
            else:
                if t[index] == t[index-k]:
                    pre = True
                else:
                    if t[index] == 'r':
                        res += p
                    elif t[index] == 's':
                        res += r
                    else:
                        res += s
print(res)


Measured memory_bytes: 3316
use proconio::{input, fastout};
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let mut nnn = n;
    let mut charvec: VecDeque<char> = VecDeque::new();
    loop {
        let r = nnn % 26;
        let c = 96 + {
            if r == 0 {
                nnn -= 26;
                26
            } else { r }
        } as u8;
        charvec.push_front(c as char);
        nnn = nnn/26;
        if nnn == 0 { break; }
    }
    let mut ans = String::new();
    for c in charvec {
        ans.push(c);
    }
    println!("{}", ans);
}

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

int main(void){
    int K,S;
    cin>>K>>S;
    int cnt = 0;
    rep(x,K+1)rep(y,K+1){
        int z = S-y-x;
        if(z>=0 && z<=K) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll a[3];
    rp(i,3) cin >> a[i];
    sort(a,a+3);
    if(a[0] + a[1] == a[2]) cout << "Yes" << endl;
    else cout << "No"<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N, M;
  cin >> N >> M;
  vector<P> A(N);
  REP(i, N) cin >> A[i].first >> A[i].second;
  sort(A.begin(), A.end());
  ll ans = 0, num = 0;

  REP(i, N) {
    REP(j, A[i].second) {
      ans += A[i].first;
      num++;
      if (num == M) {
        cout << ans << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int main() {
  int k; cin >>k;
  vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout <<v[k-1] <<endl;
}

Measured memory_bytes: 256
from sys import stdin
N,M,X=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]
cost_l=0
cost_r=0
for i in data:
    if i < X:
        cost_l+=1
    else:
        cost_r+=1
print(min(cost_l,cost_r))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

bool match(char x, char y) {
	if (x == y || x == '?' || y == '?')return true;
	else return false;
}

string a, b, c;
bool ab[100000], bc[100000], ac[100000];
//ab[i] := bの置く場所がaの置く場所からの距離がi - 50000のときに、問題なくマッチできるか？
//trueなら不可能

int main() {
	
	cin >> a >> b >> c;
	int A = a.size(), B = b.size(), C = c.size();

	for (int i = 0; i < A; i++)
		for (int j = 0; j < B; j++)
			if (!match(a[i], b[j]))ab[50000 + i - j] = true;

	for (int i = 0; i < A; i++)
		for (int j = 0; j < C; j++)
			if (!match(a[i], c[j]))ac[50000 + i - j] = true;

	for (int i = 0; i < B; i++)
		for (int j = 0; j < C; j++)
			if (!match(b[i], c[j]))bc[50000 + i - j] = true;

	int ans = 1145141919;
	for (int i = -4050; i <= 4050; i++) {
		for (int j = -4050; j <= 4050; j++) {
			//bはaからの相対距離がi、cはaからの相対距離がj
			if (!ab[i + 50000] && !ac[j + 50000] && !bc[j - i + 50000]) {
				int L, R;//[L, R]
				L = min(0, min(i, j));
				R = max(A, max(i + B, j + C)) - 1;
				ans = min(ans, R - L + 1);
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;
typedef long long ll;
int main()
{

    int n;
    cin >> n;

    vector<ll> x;
    vector<ll> s;

    for (int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        x.push_back(a);
        s.push_back(a);
    }
    sort(x.begin(), x.end());

    for (int i = 0; i < n; i++)
    {
        if (s[i] < x[n / 2])
        {
            cout << x[n / 2] << endl;
        }
        else
        {
            cout << x[(n / 2) - 1] << endl;
        }
    }

    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
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; }
//template end



int main(){
    string s,t; cin>>s>>t;
    t+=s; cout<<t<<endl;
    return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, a, b);
  out(max(0, a - b * 2));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <time.h>
#include <complex>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
#define TEMP(type,x,y) do {temp temp=x,x=y,y=temp}while(0)
const ll INF = (1LL << 50);

int main() {

	int N, M;
	cin >> N >> M;
	vector<ll>A(N);
	priority_queue<ll>money;

	REP(i, N) {
		cin >> A[i];
		money.push(A[i]);
	}

	REP(i, M) {
		ll dis = money.top() / 2;
		money.pop();
		money.push(dis);
	}

	ll total = 0;
	REP(i, N) {
		total += money.top();
		money.pop();
	}
	
	cout << total << endl;

	return 0;

}

Measured memory_bytes: 2168
#include <math.h>
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	for (int i = sqrt(1e9); i > 0; i--) {
		if (n >= i * i) {
			printf("%d\n", i * i);
			break;
		}
	}
	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);
		String s = sc.nextLine();
		String[] st = s.split(" ");

		int[] in = new int[3];
		for (int i = 0; i < 3; i++) {
			in[i] = Integer.parseInt(st[i]);
		}

		int x = 0;
		while (in[0] <= in[1]) {
			if (in[2] % in[0] == 0) {
				x++;
			}
			in[0]++;
		}
		System.out.println(x);
	}

}

Measured memory_bytes: 26176
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        es: [(usize1, usize1); n-1],
    }

    let mut g = vec![vec![]; n];

    for &(u, v) in es.iter() {
        g[u].push(v);
        g[v].push(u);
    }

    let (p, _) = far(&g, 0);
    let (_q, r) = far(&g, p);

    // dbg!(r);

    let ans = if r % 3 != 1 { "First" } else { "Second" };

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

fn far(g: &Vec<Vec<usize>>, s: usize) -> (usize, usize) {
    let n = g.len();
    let mut dist = vec![None; n];
    let mut q = std::collections::VecDeque::new();

    q.push_back((s, 0));

    while let Some((u, dep)) = q.pop_back() {
        if dist[u].is_some() {
            continue;
        }

        dist[u] = Some(dep);

        for &v in g[u].iter() {
            if dist[v].is_some() {
                continue;
            }
            q.push_back((v, dep + 1));
        }
    }

    // dbg!(&dist);

    let mut ret = (0, 0);
    for i in 0..n {
        if let Some(d) = dist[i] {
            if d > ret.1 {
                ret = (i, d);
            }
        }
    }

    ret
}


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

using namespace std;

#define rep(i,n) for(int i = 0 ; i < n ; i++)

int main(){
  int N;

  cin >> N;
  double x[N], y[N];
  rep(i,N){
    cin >> x[i]; 
  }
  rep(i,N){
    cin >> y[i];
  }

  double p1 = 0, p2 = 0, p3 = 0, pINF = 0;
  rep(i,N){
    double diff = fabs(x[i]-y[i]);
    p1 += diff;
    p2 += pow(diff, 2.);
    p3 += pow(diff, 3.);
    pINF = max(pINF, diff);
  }
  p2 = sqrt(p2);
  p3 = pow(p3, 0.33333333333333333333);
  printf("%.6f\n%.6f\n%.6f\n%.6f\n" ,p1 ,p2 ,p3, pINF);

  return 0;
}

Measured memory_bytes: 1308
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C


def dfs(i: int):
    global count

    if i == n - 1:
        count += eval(''.join(numbers))
        return

    numbers[2 * i + 1] = ""
    dfs(i + 1)
    numbers[2 * i + 1] = "+"
    dfs(i + 1)


if __name__ == '__main__':
    s = input()
    n = len(s)
    numbers = [""] * (2 * n - 1)
    count = 0

    for i in range(n):
        numbers[2 * i] = s[i]

    dfs(0)
    print(count)


Measured memory_bytes: 3064
#include<bits//stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
bool isPrime(int x) {
    int i;
    if (x < 2)return 0;
    else if (x == 2) return 1;
    if (x % 2 == 0) return 0;
    for (i = 3; i * i <= x; i += 2) if (x % i == 0) return 0;
    return 1;
}
int main() {
	int q, l, r;int k[100001];cin >> q;k[1] = 0;
	for (int i = 3;i < 100001;i += 2) {
        k[i] = k[i - 2];
        int o = (i + 1) / 2;
        if (isPrime(i) && isPrime(o)) k[i]++;
	}
    for (int i = 0; i < q;i++) {
        cin >> l >> r;
        if (l != 1) cout << k[r] - k[l - 2] << endl;
        else cout << k[r] << endl;
    }
}

Measured memory_bytes: 3988
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#define ll long long int

int main()
{
    int r , D , x;

    scanf("%d %d %d",&r,&D,&x);
    int array[10];

    for (int i = 0;i<10;i++)
    {
      array[i] = x*r - D;
      printf("%d\n",array[i]);
      x=array[i];

    }

   
    return 0;
}



Measured memory_bytes: 128
N,M,C=map(int,input().split())
b=list(map(int,input().split()))
a=[input().split() for i in range(N)]

D=0 
ans=0
for k in range(N):
  for s in range(M):
   D=D+int(a[k][s])*int(b[s])
  if D > -C:
   ans=ans+1 
   D=0
  else:
   ans=ans 
   D=0

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
ll mod = pow(10,9) + 7;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}
int main() {
	int a,b,c,d; cin >> a >> b >> c >> d;
	cout << (a*b > c*d? a*b: c*d) << endl;
}

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

#define int long long int
#define mp make_pair
#define mod 1000000007
using namespace std;

int dp[102][100002];

int32_t main() {
    int n,k;
    scanf("%lld", &n);
    scanf("%lld", &k);
    vector <int> v(n);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &v[i]);
    }
    vector <int> pre(k+2);
    for (int i = 0; i <= v[n-1] ; ++i) {
        dp[n-1][i] = 1;
    }
    for (int i = 0; i <= k; ++i) {
        if(i == 0){
            pre[i] = dp[n-1][i];
        }
        else{
            pre[i] = ((pre[i-1]%mod) + (dp[n-1][i]%mod))%mod;
        }
    }
    for (int i = n-2; i >= 0 ; --i) {
        for (int j = k; j >= 0 ; --j) {
            int end = j;
            int start = j - min(j , v[i]);
            if(start != 0){
                dp[i][j] = (pre[end] - pre[start - 1] + mod)%mod;
            }
            else{
                dp[i][j] = pre[end] ;
            }
        }
        for (int j = 0; j <= k; ++j) {
            if(j == 0){
                pre[j] = dp[i][j];
            }
            else{
                pre[j] = ((pre[j-1]%mod) + (dp[i][j]%mod))%mod;
            }
        }
    }
    printf("%lld",dp[0][k]);
    return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200;
ll v[1 + nmax];

class IndependentSet{
private:
  std::vector<std::pair<ll,int>> v;
public:
  ll reduce(ll number) {
    for(int i = 0; i < v.size(); i++)
      if(0 < ((1LL<<v[i].second) & number))
        number ^= v[i].first;
    return number;
  }
  void _insert(ll number) {
    number = reduce(number);
    if(0 < number) 
      v.push_back({number, __builtin_ctzll(number)});
  }
};

int solve() {
  int n;
  std::cin >> n;
  for(int i = 1; i <= n; i++)
    std::cin >> v[i];
  std::string s;
  std::cin >> s;
  s = "#" + s;
  IndependentSet myset;
  for(int i = n; 1 <= i; i--) {
    if(s[i] == '0')
      myset._insert(v[i]);
    else {
      if(0 < myset.reduce(v[i]))
        return 1;
    }
  }
  return 0;
}

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

  int t;
  std::cin >> t;
  for(int testcase = 1; testcase <= t; testcase++)
    std::cout << solve() << '\n';
  return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<uint> vuint;
typedef vector<ull> vull;
typedef vector<ll> vll;

#define init(type,var) type var;cin>>var;
#define vinit(vtype,var,n) vtype var((uint)n);loop(i,0,n)cin>>var[i];
#define range(container) container.begin(),container.end()
#define loop(i,first,end) for(ull i=(first);i<(end);i++)
#define outl(out) cout<<out<<endl;

const ull INF = (ull)(-1LL);

int main(void){
	init(ull, n);
	vinit(vull, h, n);

	ull c, m;
	c = m = 0;

	loop(i, 0, n-1){
		if (h[i] >= h[i + 1]){
			c++;
			if (c > m)m = c;
		}
		else c = 0;
	}

	outl(m);

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=500005;
//i_am_noob
int n,m,fact[maxn],invfact[maxn],a[maxn],ans=0;

inline int C(int m, int n){return fact[m]*invfact[n]%MOD*invfact[m-n]%MOD;}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    fact[0]=invfact[0]=1;
    rep2(i,1,maxn) fact[i]=i*fact[i-1]%MOD;
    rep2(i,1,maxn) invfact[i]=inverse(fact[i]);
    a[1]=0,a[2]=1;
    rep2(i,3,maxn) a[i]=(i-1)*(a[i-1]+a[i-2])%MOD;
    m-=n;
    if(m==0){
        print1(a[n]*fact[n]%MOD);
        return 0;
    }
    if(n==1){
        print1((m+1)*m%MOD);
        return 0;
    }
    rep3(i,n,2){
        ans=add(ans,a[i]*fact[n]%MOD*invfact[i]%MOD*C(m-1+(n-i),m-1)%MOD);
    }
    rep2(i,1,m+1){
        ans=add(ans,i*fact[n]%MOD*C(n-2+(m-i),n-2)%MOD);
    }
    print1(ans*C(n+m,n)%MOD*fact[n]%MOD);
    return 0;
}


Measured memory_bytes: 15340
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define endl "\n"
#define goat() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
typedef long long ll;
int arr[10005];
int main() {
	goat();
	int n, k, i, x, y, z;
	ll c = 0;
	cin >> n>>k;
	for (i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	for (i = 0; i < k; i++) {
		c += arr[i];
	}
	cout << c << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    scanf("%lld",&n);
    ll sum = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if( i * j < n ){
                sum++;
            }else{
                break;
            }
        }
    }
    printf("%lld\n",sum);
}


Measured memory_bytes: 3824
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n): #累積和ai,bjを求める
 acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
 acum2.append(acum2[-1]+arr2[i])
ans=0
j=m
for i in range(n+1):
 if acum1[i]>k: #ai>Kであれば、どのようにjを選んでもai+bj<=Kとなることはないので探索を終了する
   break
 while acum2[j]>k-acum1[i] and j>0: #各iについて、bj<=K-aiを満たす最大のjを求める
   j-=1
 ans=max(ans,i+j)
print(ans)

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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;
typedef pair<ll,string>Pc;


const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()


string s,t,ans;
PP dp[3010][3010];

void input(){
	cin>>s;
	cin>>t;
	return;
}

void solve(){
	for(int i=0;i<=s.size();i++){
		for(int j=0;j<=t.size();j++){
			dp[i][j].sc=P(-1,-1);
		}
	}
	for(int i=0;i<s.size();i++){
		for(int j=0;j<t.size();j++){
			if(s[i]==t[j]){
				dp[i+1][j+1].fr=dp[i][j].fr+1;
				dp[i+1][j+1].sc=P(i,j);
			}
			else {
				if(dp[i][j+1]<dp[i+1][j])dp[i+1][j+1].fr=dp[i+1][j].fr,dp[i+1][j+1].sc=dp[i+1][j].sc;
				else dp[i+1][j+1].fr=dp[i][j+1].fr,dp[i+1][j+1].sc=dp[i][j+1].sc;
			}
		}
	}
	int i=s.size(),j=t.size();
	while(dp[i][j].sc.fr!=-1){
		ans+=s[dp[i][j].sc.fr];
		int ni=i,nj=j;
		i=dp[ni][nj].sc.fr;
		j=dp[ni][nj].sc.sc;
	}
	reverse(ALL(ans));
	cout<<ans<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}


Measured memory_bytes: 211968
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    cin>>n>>t;
    if(n<10) cout<<t+100*(10-n);
    else cout<<t;

    return 0;
}



Measured memory_bytes: 892
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=[list(map(int,input().split())) for _ in range(n)]
    N=1<<n
    cost=[0]*N
    for mask in range(N):
        for j in range(n):
            for i in range(j):
                if((mask>>i)&1 and (mask>>j)&1):
                    cost[mask]+=A[i][j]
    dp=[-INF]*N
    dp[0]=0
    for mask in range(1,N):
        mask2=mask
        while(mask2):
            tmp=dp[mask&~mask2]+cost[mask2]
            dp[mask]=max(dp[mask],tmp)
            mask2=(mask2-1)&mask
    print(dp[-1])
resolve()

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

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

  vector<int> h(N, 0);
  rep(i, N) cin >> h.at(i);

  auto cost = [&h](int x, int y) { return abs(h.at(x) - h.at(y)); };

  vector<int> dp(N, INT_MAX);
  dp.at(0) = 0;

  for (int i = 1; i < N; i++) {
    for (int j = max(0, i - K); j < i; j++)
      dp.at(i) = min(dp.at(i), dp.at(j) + cost(j, i));
  }

  cout << dp.at(N - 1) << endl;
  return 0;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(N){
        ll a, b;
        cin >> a >> b;
        A[i] = a;
        B[i] = b;
    }
    ll total = 0;
    for(int i=N-1;i>=0;i--){
        int a = A[i], b = B[i];
        total += ((a+total) % b == 0 || a == 0) ? 0 : b - (a+total) % b;
    }
    cout << total;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

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

int main() {
  int s, w;
  cin >> s >> w;

  bool res = w >= s;

  cout << (res ? "unsafe" : "safe") << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N, K;

  cin >> N >> K;

  if (N % K == 0)
    cout << 0 << endl;
  else
    cout << 1 << endl;

  return 0;
}


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

int main() {
	int N;
	cin >> N;
	if ( N%1111 == 0) {
		cout << "Yes" << endl;
	}
	else if ( (N/10)%111 ==0) {
		cout << "Yes" << endl;
	}
	else if ( (N%1000)%111 ==0) {
		cout << "Yes" << endl;
	  }
	else {
		cout << "No" << endl;
	}
  }



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
  int n;
  cin>>n;
  int a[n];
  int sum=0,ans=0,cnt=0;;
  rep(i,n) {
    cin>>a[i];
    sum+=a[i];
  }
  if(sum%n==0) {
    rep(i,n) {
      ans+=(a[i]-sum/n)*(a[i]-sum/n);
    }
    cout<<ans<<endl;
  }
  else {
    rep(i,n) {
      ans+=(a[i]-sum/n)*(a[i]-sum/n);
      cnt+=(a[i]-(sum/n+1))*(a[i]-(sum/n+1));
    }
    cout<<min(ans,cnt)<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;
const int MAX = 2005;

ll dp[MAX][MAX];

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    vector<P> p;
    rep(i,n) p.emplace_back(a[i],i);
    sort(p.rbegin(),p.rend());
    REP(i,n+1) {
        int pi = p[i-1].second;
        rep(l,i+1) {
            int r = i-l;
            if (l == i) dp[i][l] = dp[i-1][l-1]+(ll)(pi-l+1)*a[pi];
            else if (l == 0) dp[i][l] = dp[i-1][l]+(ll)(n-r-pi)*a[pi];
            else dp[i][l] = max(dp[i-1][l-1]+(ll)(pi-l+1)*a[pi],dp[i-1][l]+(ll)(n-r-pi)*a[pi]);
            // cout << dp[i][l] << endl;
        }
    }
    // rep(i,3) cout << dp[2][i] << endl;
    ll ans = 0;
    rep(i,n+1) ans = max(ans,dp[n][i]);
    cout << ans << endl;
}

Measured memory_bytes: 26304
#include <cstdio>
#include <cstring>


#define MAX_N 10001
/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;
char s[MAX_N];

// char s[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


int main () {

	// 個数と長さの読込み
	scanf("%d %s", &N, s);

	for(int i = 0; i < strlen(s); i++) {
		s[i] = (s[i] + N > 'Z') ? s[i] + N - 26 : s[i] + N;   
	}
	printf("%s\n", s);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
# define inf 1e18+1
using namespace std;
long sum[(1<<16)];
long count(int mask,int**& arr){
    long c = 0;
    //cout<<mask<<'\n';
    for(int i = 0;i<17; i++){
        for(int j = i+1;j<17;j++){
            if((mask&(1<<i))!=0&&(mask&(1<<j))!=0){
                //cout<<i<<' '<<j<<'\n';
                c += arr[i][j];
            }
        }
    }
    //cout<<c<<'\n';
    return c;
}
void sum1(int**& arr,int n){
    for(int i=1;i<(1<<n);i++){
        sum[i] = count(i,arr);
    }
}
long solve(vector<long>& dp,int**& arr,int curr)
{
    if(curr==0){
        return 0;
    }
    if(dp[curr]!=inf){
        return dp[curr];
    }
    dp[curr] = 0;
    for(int i=curr;i!=0;i = (i-1)&curr){
        //cout<<i<<'\n';
        dp[curr] = max(dp[curr],sum[i] + solve(dp,arr,curr^i));
    }
    return dp[curr];
    
}
int main() {
	int n;
	cin>>n;
	int** arr = new int*[n];
	for(int i=0;i<n;i++){
	    arr[i] = new int[n];
	    for(int j=0;j<n;j++){
	        cin>>arr[i][j];
	    }
	}
// 	for(int i=0;i<n;i++){
// 	    for(int j=0;j<n;j++){
// 	        cout<<arr[i][j]<<' ';
// 	    }
// 	    cout<<'\n';
// 	}
	sum1(arr,n);
	vector<long> dp(1<<n,inf);
	//cout<<(1<<n)-1<<'\n';
	cout<<solve(dp,arr,(1<<n)-1)<<'\n';
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <cmath>

std::vector<bool> Eratosthenes(const int n){
    std::vector<bool> primes(n+1, true);
    primes[0] = primes[1] = false;

    for(int i=2; i<=std::sqrt(n); ++i){
        if(!primes[i])
            continue;
        for(int j=i*i; j<=n; j+=i)
            primes[j] = false;
    }
    return primes;
}

void MaximumTwinPrimes(const std::vector<bool> &primes){
    for(int i=primes.size()-1; i>=2; --i){
        if(primes[i] && primes[i-2]){
            std::cout << i-2 << " " << i << std::endl;
            return;
        }
    }
}

int main(){
    int n;
    while((std::cin >> n) && n > 0){
        std::vector<bool> primes = Eratosthenes(n);
        MaximumTwinPrimes(primes);
    }
}


Measured memory_bytes: 3000
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main()
{
  int n, m; cin >> n >> m;
  vector<bool> v(n, false);

  for (int i = 0; i < m; i++) {
    int a, l; cin >> a >> l;

    for (int j = 0; j < l; j++)
      v[(a+j)%n] = true;
  }

  int slit = -1;
  for (int i = 0; i < n; i++) {
    if (v[i] == false && v[(i+1)%n] == true)
      slit = (i+1)%n;
  }

  if (slit == -1) {
    cout << n << " " << 1 << endl;
    return 0;
  }

  int prev = -1;
  map<int, int> spans;
  for (int t = 0; t < n; t++) {
    int i = (slit + t) % n;
    if (v[i] == true && v[(i+1)%n] == false) {
      spans[-(t - prev)]++;
    }
    if (v[i] == false && v[(i+1)%n] == true) {
      prev = t;
    }
  }

  for (auto &p: spans)
    cout << -p.first << " " << p.second << endl;

  return 0;
}


Measured memory_bytes: 1200
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>
#include <sstream>

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int, int> pii;

#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)

ld EPS = (ld)1e-9L;
const double PI = 3.141592653589793238462;
const int INF = 1e9 + 7;
const li LINF = 4e18 + 7;


int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	li n, m;
	cin >> n >> m;

	if (n == 1 && m == 1) {
		cout << 1 << endl;
		return 0;
	}

	if (n == 1) {
		cout << m - 2 << endl;
		return 0;
	}

	if (m == 1) {
		cout << n - 2 << endl;
		return 0;
	}

	cout << (n - 2) * (m - 2) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int w,a,b,r;
    scanf("%d %d %d",&w,&a,&b);

    if(a<=b)
        r=a+w-b;
    else
        r=b+w-a;
    if(r>0)
        printf("0\n");
    else
        printf("%d\n",-r);
    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;



int a[200000], w[200000], p[200000];
signed main(){
  int n, L, T;
  scanf("%lld%lld%lld", &n, &L, &T);
  rep(i,n)scanf("%lld%lld", &a[i], &w[i]);
  rep(i,n){
    if(w[i] == 1)p[i] = (a[i]+T)%L;
    else p[i] = ((a[i]-T)%L+L)%L;
  }
  sort(p, p+n);
  
  int cnt = 0;
  rep(i,n){
    if(w[i] == 1)cnt += (a[i]+T)/L;
    else{
      int tmp = a[i]-L+1;
      cnt += (tmp-T)/L;
    }
  }
  // int cnt = 0;
  //   for (int i = 0; i < n; ++i) {
  //       if (w[i] == 1) cnt -= (T - (L - a[i]) + L) / L;
  //       else cnt += (T - (a[i] + 1) + L) / L;
  //   }
  // 
  // cout << cnt << endl;
  rep(i,n)printf("%lld\n", p[(i+cnt%n+n)%n]);
	return 0;
}









Measured memory_bytes: 4480
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int

using namespace std;


int main() {
	speed;
	int r, D, x[11];
	cin >> r >> D >> x[0];
	for (int i = 0; i < 10; i++) {
		x[i + 1] = r * x[i] - D;
	}
	for (int i = 1; i < 11; i++) {
		cout << x[i];
		ed;
	}
	ed;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    char s[100000];
    scanf("%s",s);

    int b=0;
    int w=0;
    int b2=0;
    int w2=0;



    for(int i=0;s[i]!='\0';i++){
        if(i%2==0){
            if(s[i]=='0'){
                w++;
            }else{
                b++;
            }
        }else{
            if(s[i]=='0'){
                w2++;
            }else{
                b2++;
            }
        }
    }

    int y=w+b2;
    int z=w2+b;

    if(y>=z){
        printf("%d",z);
    }else{
        printf("%d",y);
    }

    return 0;
}

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

#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl

typedef long long ll;
using namespace std;

typedef struct {
	int x;
	int y;
} Position;

double getS(Position p1, Position p2) {
	double ret = fabs(p1.x * p2.y - p1.y * p2.x);
	return ret / 2;
}

int main() {
	cin.tie(0); //?????±?????????????????????

	int n;
	Position pBase;
	Position pPrev;
	Position pNow;
	int count = 0;
	while (cin >> n, count++, n != 0) {
		int x, y;
		cin >> x >> y;
		Position pNow;
		Position pPrev { x, y };
		const Position pS { x, y };
		double sum = 0;
		for (int i = 1; i < n; i++) {
			cin >> x >> y;
			pNow = { x, y };
			sum += (pPrev.x - pNow.x) * (pPrev.y + pNow.y);
			pPrev = { pNow.x, pNow.y };
		}
		sum += (pNow.x - pS.x) * (pNow.y + pS.y);
		sum = fabs(sum);
		sum /= 2;
		printf("%d %.1lf\n", count, sum);
	}
  

	return 0;
}

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

int n,l,total=0,mn=500,pos,apples[200];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>l;
	for(int i=0;i<n;i++){
		apples[i]=l+i;
		total+=apples[i];
		if(abs(apples[i])<mn){
			mn=abs(apples[i]);
			pos=i;
		}
	}
	cout<<total-apples[pos];
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<string> s(n);
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        /* code */
        cin>>s[i]>>a[i];
    }
    vector<int> ord(n);
    iota(ord.begin(),ord.end(),0);
    sort(ord.begin(),ord.end(),[&](int x,int y){
        if (s[x]==s[y])
        {
            /* code */
            return a[x]>a[y];
        }
        return s[x]<s[y];
        
    });
    for (auto e:ord)
    {
        /* code */
        cout<<e+1<<endl;
    }
    
    
    
}

Measured memory_bytes: 256