akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
  int n; cin >> n;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    res += (r - l + 1);
  }
  cout << res << endl;

  return 0;
}

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

using namespace std;

int main() {

    int n;
    
    cin>>n;
    
   int a[n+1]={0};
   
   for(int i=0;i<n-1;i++)  {
       int c;
       cin>>c;
       a[c]++;
   }
   
   for(int i=1;i<=n;i++) {
       cout<<a[i]<<endl;
   }
   
   
    
    return 0;
}

Measured memory_bytes: 4416
S=input()
if S=="SUN":
    print(7)
elif S=="MON" :
    print(6)
elif S=="TUE" :
    print(5)
elif S=="WED" :
    print(4)
elif S=="THU" :
    print(3)
elif S=="FRI" :
    print(2)
else:
    print(1)
    

Measured memory_bytes: 2940
import math

def input_num():
	ls = input().strip().split(" ")
	return [int(e) for e in ls]

a = input().strip()
b = input().strip()

if len(b) == 0:
	print("No")
else:
	if a == b[:-1]:
		print("Yes")
	else:
		print("No")


Measured memory_bytes: 9044
import sys
from io import StringIO
import unittest

def resolve():
    import math
    n, k = map(int, input().split())
    i = 1
    count = 1
    while k**i <= n:
        count += 1
        i += 1
    print(count)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """11 2"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1010101 10"""
        output = """7"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """314159265 3"""
        output = """18"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

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

int main(void)
{
    int puzzle[9][9];
    char flag[9][9];
    int n;
    int i, j, k, l;
    
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        for (j = 0; j < 9; j++){
            for (k = 0; k < 9; k++){
                scanf("%d", &puzzle[j][k]);
            }
        }
        memset(flag, ' ', sizeof(flag));
    
        for (j = 0; j < 9; j++){
            for (k = 0; k < 9 - 1; k++){
                for (l = k + 1; l < 9; l++){
                    if (puzzle[j][k] == puzzle[j][l]){
                        flag[j][k] = flag[j][l] = '*';
                    }
                    if (puzzle[k][j] == puzzle[l][j]){
                        flag[k][j] = flag[l][j] = '*';
                    }
                    if (puzzle[j / 3 * 3 + k / 3][j % 3 * 3 + k % 3] == 
                        puzzle[j / 3 * 3 + l / 3][j % 3 * 3 + l % 3]){
                            
                        flag[j / 3 * 3 + k / 3][j % 3 * 3 + k % 3] =
                        flag[j / 3 * 3 + l / 3][j % 3 * 3 + l % 3] = '*';
                    }
                }
            }
        }
        
        if (i >= 1){
            printf("\n");
        }
        for (j = 0; j < 9; j++){
            for (k = 0; k < 9; k++){
                printf("%c%d", flag[j][k], puzzle[j][k]);
            }
            printf("\n");
        }
    }
    return (0);
}

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

#define N 200123
#define mod 1000000007

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    if(fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int k, ans = 0;
    cin >> k;
    for(int i = 1 ; i <= k ; i++)
    	for(int j = 1 ; j <= k ; j++)
    		for(int jj = 1 ; jj <= k ; jj++)
    			ans += __gcd(i, __gcd(j, jj));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3656
import re

r = input()
if r.startswith("A"):
  if len(re.findall("C",r[2:-1])) == 1:
    r = r[1:2]+r[2:-1].replace("C","")+r[-1]
    if r.islower():
      print("AC")
    else:
      print("WA")
  else:
    print("WA")
else:
  print("WA")

Measured memory_bytes: 3188
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
 
 
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
int tc;
const int N=1e6+5,M=3e5+5,MOD=1e9+7,OO=1e9;

int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	//file();
 	
 	ll a,b;

 	cin>>a>>b;

 	cout<<(a*b)/__gcd(a,b)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <fstream>

using std::cin;
using std::cout;
using std::endl;
using std::terminate;

template<class T> inline T max(T X, T Y) {
    return X > Y ? X : Y;
}

void solve() {
    int k, n; cin >> k >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int b = 0;
    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            b = max(b, a[i] + (k - a[n - 1]));
        } else {
            b = max(b, a[i] - a[i - 1]);
        }
    }

    cout << k - b << endl;
}

int main() {

#ifdef DEV
    std::ifstream in("AtCoder/ABC160/Traveling Salesman around Lake.input");
    cin.rdbuf(in.rdbuf());

    int t; cin >> t;
    for (int x = 1; x <= t; ++x) {
        solve();
    }
#else
    solve();
#endif

    return 0;
}


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

#define MAX_N 4010

int main() {
  int n;
  std::string s;
  scanf("%d", &n);
  std::cin >> s;
  int leftR[MAX_N], rightR[MAX_N];
  int leftG[MAX_N], rightG[MAX_N];
  int leftB[MAX_N], rightB[MAX_N];
  leftR[0] = 0;
  leftG[0] = 0;
  leftB[0] = 0;
  rightR[n-1] = 0;
  rightG[n - 1] = 0;
  rightB[n - 1] = 0;
  for (int i = 0; i < n-1; i++) {
    leftR[i+1] = leftR[i] + (s[i] == 'R');
    leftG[i + 1] = leftG[i] + (s[i] == 'G');
    leftB[i + 1] = leftB[i] + (s[i] == 'B');
  }
  for (int k = n-1; k >= 1; k--) {
    rightR[k-1] = rightR[k] + (s[k] == 'R');
    rightG[k - 1] = rightG[k] + (s[k] == 'G');
    rightB[k - 1] = rightB[k] + (s[k] == 'B');
  }
  long long ans = 0;
  for (int j = 1; j < n-1; j++) {
    if (s[j] == 'R') {
      ans += leftG[j] * rightB[j];
      ans += leftB[j] * rightG[j];
      for (int i = 0; i < j; i++) {
        if (s[i] == 'G' && 2*j-i < n && s[2*j-i] == 'B') ans--;
        if (s[i] == 'B' && 2 * j - i < n && s[2 * j - i] == 'G')
          ans--;
      }
    }
    if (s[j] == 'G') {
      ans += leftR[j] * rightB[j];
      ans += leftB[j] * rightR[j];
      for (int i = 0; i < j; i++) {
        if (s[i] == 'R' && 2 * j - i < n && s[2 * j - i] == 'B')
          ans--;
        if (s[i] == 'B' && 2 * j - i < n && s[2 * j - i] == 'R')
          ans--;
      }
    }
    if (s[j] == 'B') {
      ans += leftG[j] * rightR[j];
      ans += leftR[j] * rightG[j];
      for (int i = 0; i < j; i++) {
        if (s[i] == 'G' && 2 * j - i < n && s[2 * j - i] == 'R')
          ans--;
        if (s[i] == 'R' && 2 * j - i < n && s[2 * j - i] == 'G')
          ans--;
      }
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 3296
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 998244353;

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

	int n;
	cin >> n;
	string str;
	cin >> str;

	ll res = 1;
	for (int i = 1; i <= n; ++i) res = (res * i) % MOD;

	vector<int> cou(3, 0);
	for (int i = 0; i < 3*n; ++i) {
		// Counts are x y z in increasing order, colors a b c
		// x - y have started, need b to continue
		// y - z have two, need c to complete
		// z are done
		vector<int> srt = cou;
		sort(srt.begin(), srt.end());

		int j = (str[i] == 'R' ? 0 : (str[i] == 'G' ? 1 : 2));
		if (cou[j] == srt[2]) {
			// Start
		} else if (cou[j] == srt[1]) {
			// Continue
			res = (res * (srt[2] - srt[1])) % MOD;
		} else if (cou[j] == srt[0]) {
			// Finish
			res = (res * (srt[1] - srt[0])) % MOD;
		}
		++cou[j];
	}
	cout << res << '\n';
}


Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<string> s(N);
    cin >> s[0];
    char a = s[0][s[0].size()-1];
    bool flag = true;
    string ans;
    for(int i=1; i<N; i++){
        cin >> s[i];
        if(s[i][0] != a){
            flag = false;
        }
        a = s[i][s[i].size()-1];
    }
    if(flag){
        for(int i=0; i<N; i++){
            for(int j=i; j<N; j++){
                if(j!=i && s[i] == s[j]){
                    flag = false;
                }
            }
        }
    }
    
    ans = flag ? "Yes" : "No";
    cout << ans << endl;
}


Measured memory_bytes: 256
eq = input().split()
stack = []
for o in eq:
    if (o == '+'):
        a = int(stack.pop())
        b = int(stack.pop())
        stack.append(b+a)
    elif (o == '*'):
        a = int(stack.pop())
        b = int(stack.pop())
        stack.append(b*a)
    elif (o == '-'):
        a = int(stack.pop())
        b = int(stack.pop())
        stack.append(b-a)
    else:
        stack.append(o)
print(stack[0])



Measured memory_bytes: 5600
n = int(input())
s = input()
ans = 0
for a in range(10):
  for b in range(10):
    for c in range(10):
      a, b, c = str(a), str(b), str(c)
      a_find = s.find(a)
      if a_find == -1:
        continue
      b_find = s.find(b, a_find + 1)
      if b_find == -1:
        continue
      c_find = s.find(c, b_find + 1)
      if c_find == -1:
        continue
      ans += 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ




//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, r ;
  cin >> n >> r ;
  if(n>=10){
    cout << r <<endl ;
  }
  else{
    cout << r+100*(10-n) <<endl ;
  }
  
  
  
  return 0 ;
}




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

using namespace std;

#define LL long long
#define u64 unsigned long long
#define u32 unsigned int
#define reg register
#define Raed Read
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)
#define erep(i,x) for(reg int i=Head[x]; i; i=Nxt[i])

inline int Read() {
	int res = 0, f = 1;
	char c;
	while (c = getchar(), c < 48 || c > 57)if (c == '-')f = 0;
	do res = (res << 3) + (res << 1) + (c ^ 48);
	while (c = getchar(), c >= 48 && c <= 57);
	return f ? res : -res;
}

template<class T>inline bool Min(T &a, T const&b) {
	return a > b ? a = b, 1 : 0;
}
template<class T>inline bool Max(T &a, T const&b) {
	return a < b ? a = b, 1 : 0;
}

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

bool MOP1;

int A[N],flag;

bool MOP2;

inline void _main(void) {
	int n=Raed();
	rep(i,1,n)A[i]=Read();
	drep(i,n-1,1) {
		if(A[i]>A[i+1]) {
			A[i]--;
			if(A[i]>A[i+1]) {
				flag=1;
				break;
			}
		}
	}
	if(!flag)puts("Yes");
	else puts("No");
}

signed main() {
#define offline1
#ifdef offline
	freopen("chessboard.in", "r", stdin);
	freopen("chessboard.out", "w", stdout);
	_main();
	fclose(stdin);
	fclose(stdout);
#else
	_main();
#endif
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(string, s, t);
    t.pop_back();
    print((s == t) ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 3652
package main

import (
	"fmt"
)

func main() {
	var W, H, x, y float64
	fmt.Scan(&W, &H, &x, &y)

	area := W * H

	if W/2 == x && H/2 == y {
		fmt.Printf("%f %d\n", area/2, 1)
	} else {
		fmt.Printf("%f %d\n", area/2, 0)
	}
	// xSplits := []float64{x / W, 1 - (x / W)}
	// ySplits := []float64{y / H, 1 - (y / H)}
	// xDiff := math.Abs(xSplits[0] - xSplits[1])
	// yDiff := math.Abs(ySplits[0] - ySplits[1])

	// var res float64
	// if xDiff >= yDiff {
	// 	if ySplits[0] >= ySplits[1] {
	// 		res = area * ySplits[1]
	// 	} else {
	// 		res = area * ySplits[0]
	// 	}
	// }

	// if xDiff < yDiff {
	// 	if xSplits[0] >= xSplits[1] {
	// 		res = area * xSplits[1]
	// 	} else {
	// 		res = area * xSplits[0]
	// 	}
	// }

	// count := 0
	// if xDiff == yDiff {
	// 	count = 1
	// }
	// fmt.Printf("%f %d\n", res, count)

}


Measured memory_bytes: 512
n = int(input())
s = input()
listnum = [0] * (n + 1)
for i in range(n) :
    if s[i] == "I" :
        listnum[i + 1] = listnum[i] + 1
    elif s[i] == "D" :
        listnum[i + 1] = listnum[i] - 1
ans = max(listnum)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <string>

using namespace std;

int main()
{
    int n,x;
    cin >> n >> x;
    int d = 0;
    int count = 1;
    for(int i = 0; i < n; ++i)
    {
        int l;
        cin >> l;
        d += l;
        if(d > x)
        {
            break;
        }
        count += 1;
    }
    cout << count << '\n';
    return 0;
}


Measured memory_bytes: 256
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
let b = readInts()
let a1 = b[0]
let a2 = b[1]
let a3 = b[2]
let num = a1 + a2 + a3
if num >= 22 {
  print("bust")
} else { 
  print("win")
}

Measured memory_bytes: 8312
#include <stdio.h>

int main()
{
	int i, sum;
	char s[1001];

	while(1){
		scanf("%s", s);
		if(*s == '0') break;
		sum = 0;
		for (i = 0; s[i] != '\0'; i++) {
			sum += s[i] - '0';
		}
		printf("%d\n", sum);
	}
	return 0;
}


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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

int lcm(int a, int b) {
    return a / __gcd(a, b) * b;
}

void solve() {
    int n, m;
    cin >> n >> m;

    vector<int> v(n);

    int ans = 1;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        ans = lcm(ans, v[i] / 2);
        v[i] /= 2;
    }

    bool flag = true;
    for (int i = 0; i < n; i++) {
        if ((ans / v[i]) % 2 == 0)
            flag = false;
    }
    if (!flag)
        cout << 0 << endl;
    else
        cout << (m / ans + 1) / 2 << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int table[200][200]={{0}};
    int c,r;
    cin>>r>>c;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin>>table[i][j];
        }
    }
    
     for(int i=0;i<r+1;i++){
       int sum =0;
        for(int j=0;j<c;j++){
            sum+=table[i][j];
        }
      table[i][c] = sum;
    }
        
     for(int j=0;j<c+1;j++){
       int sum =0;
        for(int i=0;i<r;i++){
            sum+=table[i][j];
        }
      table[r][j] = sum;
    }
       
 
    
    for(int i=0;i<r+1;i++){
        for(int j=0;j<c+1;j++){
            cout<< table[i][j];
            if(j!=c)cout<<" ";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3256
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, H = map(int, input().split())
    A = []
    B = []
    for i in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    A.sort()
    B.sort(reverse=True)

    throw = []
    for i in range(N):
        if B[i] > A[-1]:
            throw.append(B[i])
    # print(throw)
    throw = throw[::-1]

    ans = 0

    while H > 0:
        if throw:
            H -= throw.pop()
            ans += 1
        else:
            need_try = (H + A[-1] - 1) // A[-1]
            ans += need_try
            break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12868
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        var n = long.Parse(Console.ReadLine());
        long[] numbers = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long ans = 0;
        long count = 0;
        for (int i = 0; i < n - 1; i++)
        {
            if (numbers[i] >= numbers[i + 1])
            {
                count += 1;
            }
            else
            {
                count = 0;
            }
            ans = Math.Max(ans, count);
        }

        Console.WriteLine(ans);

    }
}


Measured memory_bytes: 31452
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;
vector<ll> divisors(ll);

int main()
{
	ll n, m;
	cin >> n >> m;
	auto divList = divisors(m);
	rep(i, divList.size())
	{
		if(m/divList[i]>=n)
		{
			co(divList[i]);
			return 0;
		}
	}
	return 0;
}

vector<ll> divisors(ll a)
{
	vector<ll> res;
	for (ll i = 1; i*i <=a; i++)
	{
		if (a % i == 0)
		{
			res.push_back(i);
			res.push_back(a / i);
		}
	}
	sort(ALL(res),greater<ll>());
	return res;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

calc :: [Int] -> Int -> Int -> Int -> Int
calc [] n a d = a
calc (p : ps) n a d = calc ps n a' d'
  where
    ds = abs (n - p)
    d'
      | ds < d = ds
      | otherwise = d
    a'
      | ds < d = p
      | otherwise = a

main = do
  [x, n] <- getIntList
  ps <- getIntList
  if n == 0
    then print x
    else do
      let ps_max = maximum ps
      let ns = filter (\x -> x `notElem` ps) [1..ps_max+1]
      print $ calc ns x 0 x


Measured memory_bytes: 3784
N = int(input())
height = [int(i) for i in input().split()]
step = 0
for i, h in enumerate(height):
    if i == 0:
        pre = h
    else:
        if h < pre:
            step += (pre - h)
            pre = pre
        else:
            step += 0
            pre = h
print(step)

Measured memory_bytes: 32192
N = 2 # 入力は2行
for i in range(N):
    line = input() # 入力を1行受け取る
    if i == 0: # 1行目
        child_count, candy_sum_orig = map(int, line.split())
    else: # 2行目
        requirement_list = list(map(int, line.split()))
satisfied_count = 0
candy_sum = candy_sum_orig
requirement_list.sort() # 昇順に並び替え
for i in range(child_count): # len(requirement_list) == child_count
    requirement = requirement_list[i]
    # print(i, candy_sum, requirement)
    if i == child_count-1: # 最後の人(残りのお菓子がほしい数と一致するか)
        if requirement == candy_sum:
            satisfied_count += 1
    else: # 1人目からchild_count-1人目まで
        if requirement <= candy_sum:
            candy_sum -= requirement
            satisfied_count += 1
count_by_asc = satisfied_count

satisfied_count = 0
candy_sum = candy_sum_orig
requirement_list.reverse() # 降順に並び替え
for i in range(child_count): # len(requirement_list) == child_count
    requirement = requirement_list[i]
    # print(i, candy_sum, requirement)
    if i == child_count-1: # 最後の人(残りのお菓子がほしい数と一致するか)
        if requirement == candy_sum:
            satisfied_count += 1
    else: # 1人目からchild_count-1人目まで
        if requirement <= candy_sum:
            candy_sum -= requirement
            satisfied_count += 1
# print(satisfied_count, count_by_asc)
print(max(satisfied_count, count_by_asc))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
int x, y, z;
x = a + b;
y = a + c;
z = b + c;
printf("%d", min(min(x, y), z));
}

Measured memory_bytes: 256
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = ListBuffer.empty[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map.remove(l(1)).get
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Int](721)
    log.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = 1)
    })
    time.sum
  }

  def solve(s:String):Unit = {
    val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


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

using namespace std;

int n, m;
int a[101][101], b[101][101];
bitset<20001> f[101][101];

int main(int argc, char** argv)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> b[i][j];
	f[1][1].set(10000);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			int v1 = a[i][j] - b[i][j];
			int v2 = b[i][j] - a[i][j];
			if (v1 >= 0)
			{
				f[i + 1][j] |= (f[i][j] << v1);
				f[i][j + 1] |= (f[i][j] << v1); 
			}	
			else
			{
				v1 = -v1;
				f[i + 1][j] |= (f[i][j] >> v1);
				f[i][j + 1] |= (f[i][j] >> v1); 
			}	
			if (v2 >= 0)
			{
				f[i + 1][j] |= (f[i][j] << v2);
				f[i][j + 1] |= (f[i][j] << v2);
			}
			else
			{
				v2 = -v2;
				f[i + 1][j] |= (f[i][j] >> v2);
				f[i][j + 1] |= (f[i][j] >> v2);
			}	
		}
	int ans = 1e9;
	for (int i = 0; i <= 20000; i++)
		if (f[n][m].test(i))
		{       
			int v1 = i + a[n][m] - b[n][m];
			int v2 = i + b[n][m] - a[n][m];
			ans = min(ans, min(abs(v1 - 10000), abs(v2 - 10000)));
		} 
	cout << ans;	
}

Measured memory_bytes: 20108
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

constexpr int MOD = 1e9+7;

// [0, x]
ll sum(int x){
    return (ll)x*(x+1)/2;
}

// [x, y]
ll sum(int x, int y){
    return sum(y) - sum(x-1);
}

// C
int main(void){
    Cin(int, n, k);
    
    ll ans = 0;
    for(int c = k; c <= n+1; c ++){
        ll lb = sum(0, c-1);
        ll ub = sum(n-c+1, n);
        ans = (ans + ub-lb+1) % MOD;
    }
    Cout(ans);
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

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

int main(){
  long long h;
  int n, a;
  cin >> h >> n;
  int Sum = 0;
  rep(i, 0, n) 
  {
    cin >> a;
    Sum += a;
  }

  if (Sum >= h)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;
typedef long long ll;


int main(int argc, char *args[]) {
	int x1, y1, x2, y2;
	int x3, y3, x4, y4;
	cin >> x1 >> y1 >> x2 >> y2;
	y3 = y2 + (x2 - x1);
	x3 = x2 - (y2 - y1);
	y4 = y3 + (x3 - x2);
	x4 = x3 - (y3 - y2);
	cout << x3 <<" "<< y3 <<" "<< x4 <<" "<< y4 << endl;

}


Measured memory_bytes: 256
N = int(input())

r = [0] + [ i for i in map(int, input().split())]

dp = [None] * (N+1)
dp[0] = 0
dp[1] = 0
dp[2] = abs(r[2] - r[1])
for i in range(3, N+1):
    dp[i] = min(dp[i-1] + abs(r[i] - r[i-1]), dp[i-2] + abs(r[i] - r[i-2])) 
print(dp[N])



Measured memory_bytes: 13780
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
typedef long long LL;
using ld = long double;
using namespace std;
#define MAXN 500005
const double eps = (1e-11);
const int logn = 21;
const double pi = acos(-1.0);
int pp = 1000000007;
#define P pair<int,int>
#define se second
#define fi first
#define MP(i,j) make_pair(i,j)
//#define int LL
const int INF = 1e9;

//假题，贪心模拟^
struct peo {
	int l; int r;
};

peo p[MAXN];

//这里肯定是要从小到大，这样就可以尽量填小的了
bool cmp1(peo a, peo b) {
	if (a.l == b.l) return a.r < b.r;
	return a.l < b.l;
}

bool operator <(peo a, peo b) {
	return a.r > b.r;
}

priority_queue<peo> q;
priority_queue<int> q2;

signed main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &p[i].l, &p[i].r);
	}
	sort(p + 1, p + n + 1, cmp1);
	int left = 0;
	for (int i = 1; i <= n; i++) {
		q.push(p[i]);
		if (q.size() > p[i].l) {
			q2.push(q.top().r);
			q.pop();
		}
	}
	int ans = q.size();
	int r = m + 1;
	int ans2 = 0;
	while (!q2.empty()) {
		int tmp = q2.top(); q2.pop();
		r = min(tmp, r);
		r = max(tmp, ans + 1);
		if (ans2 < m - r + 1) {
			ans2++;
		}
	}
	ans += ans2; ans = n - ans;
	printf("%d", ans);
	return 0;
}

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

int main() {
  int N; cin >> N;
  int minN = 200000;
  vector<int> P(N); vector<int> minV(200000);
  for (int i =0; i<N; i++) {
    cin >> P.at(i);
    minN = min(P.at(i),minN);
    minV.at(i) = minN;
  }
  
  int ans =0;
  for (int i =0; i<N; i++) {
    if (P.at(i) == minV.at(i)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}
const int maxn = 107;
ll inf = 1e11 + 7;
ll dp[maxn][maxn][maxn][maxn];
vector<pl> aa(10);
vector<vl > ww(12);
ll n, w, ans = 0;
ll dps(int a, int b, int c, int d, ll W) {
	// trace(a, b, c, d, W, ans)
	if (W > w)return -inf;
	if (!dp[a][b][c][d]) {
		ll tans = 0;
		// trace("inside", a, b, c, d, W, ans)
		if (a < aa[0].S && W + aa[0].F <= w) {
			tans = max(tans, dps(a + 1, b, c, d, W + aa[0].F) + ww[0][a]);
		}
		if (b < aa[1].S && W + aa[1].F <= w) {
			tans = max(tans, dps(a, b + 1, c, d, W + aa[1].F) + ww[1][b]);
		}
		if (c < aa[2].S && W + aa[2].F <= w) {
			tans = max(tans, dps(a, b, c + 1, d, W + aa[2].F) + ww[2][c]);
		}
		if (d < aa[3].S && W + aa[3].F <= w) {
			tans = max(tans, dps(a, b, c, d + 1, W + aa[3].F) + ww[3][d]);
		}
		dp[a][b][c][d] = tans;
		ans = max(ans, tans);
		// trace(tans, ans)
	}
	// if (a == 0 && d == 1)trace("err")/**/
	return dp[a][b][c][d];
}
void solve() {
	cin >> n >> w;
	unordered_map<ll, ll>m;
	vector<pi> pp;
	rep(i, 0, n) {
		int wi, v;
		cin >> wi >> v;
		pp.pb({wi, v});
		m[wi]++;
	}
	ll wmin = 1e14 + 7;
	for (auto i : m) {
		aa.pb({i.F, i.S});
		wmin = min(wmin, i.F);
		// trace("1", i.F, i.S)
	}
	aa[0] = {wmin, m[wmin]};
	if (m[wmin + 1])aa[1] = {wmin + 1, m[wmin + 1]};
	else aa[1] = {0, 0};
	if (m[wmin + 2])aa[2] = {wmin + 2, m[wmin + 2]};
	else aa[2] = {0, 0};
	if (m[wmin + 3])aa[3] = {wmin + 3, m[wmin + 3]};
	else aa[3] = {0, 0};
	// sort(all(aa));
	sort(all(pp));
	rep(i, 0, (int)pp.size()) {
		// trace(pp[i].F)
		int wc = pp[i].F - wmin;
		int vc = pp[i].S;
		// trace(wc, vc)
		ww[wc].pb(vc);
	}
	rep(i, 0, 4) {
		reverse(all(ww[i]));
	}
	// while (aa.size() < 4)aa.pb({0, 0});
	// rep(i, 0, 4)trace(i, aa[i].F, aa[i].S)
	// rep(i, 0, 4) {
	// 	rep(j, 0, (int)ww[i].size()) {
	// 		trace(i, j, ww[i][j])
	// 	}
	// }
	// trace(1)
	cout << dps(0, 0, 0, 0, 0LL);
	// trace(1)
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int w = 15, h = 19;

typedef pair<int, pair<int, pii>> State;
#define F first
#define S second

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

int main(void){
    vs field(h + 2);

    rep(x, w + 2) field[0].pb('#'), field[h + 1].pb('@');

    pii s;
    map<pii, int> stone_id;
    int cnt_id = 0;

    range(y, 1, h + 1){
        cin >> field[y];
        field[y] = "#" + field[y] + "#";

        if(y == h) range(x, 1, w + 1) if(field[y][x] == '.') field[y][x] = '@';
        rep(x, w + 2){
            if(field[y][x] == 'O') s = mp(y, x), field[y][x] = '.';
            if(field[y][x] == 'X'){
                stone_id[mp(y, x)] = cnt_id++;
            }
        }
    }

    queue<State> q;
    q.push(mp(0, mp(0, s)));

    int res = -1;
    while(!q.empty()){
        int cur_stones = q.front().F; 
        pii cur_pos = q.front().S.S;
        int cur_turn = q.front().S.F; q.pop();

        if(field[cur_pos.F][cur_pos.S] == '@'){
            res = cur_turn;
            break;
        }

        rep(i, 8){
            int next_stones = cur_stones;
            pii next_pos = cur_pos;
            int next_turn = cur_turn + 1;
         
            while( field[next_pos.F + dy[i]][next_pos.S + dx[i]] == 'X' &&
                 !((next_stones >> stone_id[mp(next_pos.F + dy[i], next_pos.S + dx[i])]) & 1)){
                next_pos.F += dy[i];
                next_pos.S += dx[i];

                int id = stone_id[next_pos];
                next_stones |= (1 << id);
            }

            if(cur_pos == next_pos || field[next_pos.F += dy[i]][next_pos.S += dx[i]] == '#') continue;

            State next = mp(next_stones, mp(next_turn, next_pos));
            q.push(next);
        }
    }

    cout << res << endl;

	return 0;
}

Measured memory_bytes: 21612
#include<bits/stdc++.h>
#define ll long long int
//ll a[1000000+9]= {0};
using namespace std;
int main()
{
    ll n,i,j,k;
    ll m=0,a=0,r=0,c=0,h=0,res=0;
    string s;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>s;
        if(s[0]=='M')
        {
            m++;
        }
        else if(s[0]=='A')
        {
            a++;
        }
        else if(s[0]=='R')
        {
            r++;
        }
        else if(s[0]=='C')
        {
            c++;
        }
        else if(s[0]=='H')
        {
            h++;
        }
    }

    res+=(m*a*r);
    res+=(m*a*c);
    res+=(m*a*h);
    res+=(m*r*c);
    res+=(m*r*h);
    res+=(m*c*h);
    res+=(a*r*c);
    res+=(a*r*h);
    res+=(a*c*h);
    res+=(r*c*h);

    cout<<res<<endl;

    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int point[N][3];
    for(int i=0; i<N; i++){
        for(int j=0; j<3; j++){
            cin >> point[i][j];
        }
        if(point[i][0] > point[i][1]) swap(point[i][0], point[i][1]);
        if(point[i][1] > point[i][2]) swap(point[i][1], point[i][2]);
        if(point[i][0] > point[i][1]) swap(point[i][0], point[i][1]);
        if(point[i][1] > point[i][2]) swap(point[i][1], point[i][2]);

    }

    int count = 0;
    for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
        if(i == j || point[j][0] == 0) continue;
        if(point[i][0] == point[j][0] && point[i][1] == point[j][1] && \
            point[i][2] == point[j][2]){
            count++;
            point[j][0] = 0;
          }
      }
    }

    cout << count << endl;
}



Measured memory_bytes: 3092
// ABC172-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る

ll calc(ll n){
    return n*(n+1)/2;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=i*calc((n-n%i)/i);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3500
#include<iostream>
#include<algorithm> 
#include<cstdio>
#include<cctype>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int N = 2e5+5;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
void init(){
	ios::sync_with_stdio(false);cin.tie(0);
} 
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
vector<ll>a,b;
int main()
{
	init();
	ll n;int ans=0;
	cin>>n;
	for(ll i=2;i*i<=n;i++)
	if(n%i==0)
	{
		a.push_back(i);
		if(i*i!=n)a.push_back(n/i);
	}
	a.push_back(n);
	for(ll i=2;i*i<=n-1;i++)
	if((n-1)%i==0)
	{
		a.push_back(i);
		if(i*i!=n-1)a.push_back((n-1)/i);
	}
	b.push_back(n-1);
	for(int i=0;i<b.size();i++)
	if(n%b[i])ans++;
	for(int i=0;i<a.size();i++)
	{
		ll tmp=n;
		while(tmp%a[i]==0)tmp/=a[i];
		if(tmp%a[i]==1)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
int main(){
    string s;
    getline(cin,s);
    for(int i = 0;i < s.length();i++){
        if('A' <= s[i] && s[i] <= 'Z'){
            s[i] = s[i] + 'a' - 'A';
        }else if('a' <= s[i] && s[i] <= 'z'){
            s[i] = s[i] + 'A' - 'a';
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
const int maxN = 1e7 + 10;
using namespace std;

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

    int n;
    cin >> n;

    unsigned long long res = 0;
    for(int i = 1; i <= n; ++i)
    {
        long long j = floor(n / i);
        res += i * j * (j + 1) / 2;
    }

    cout << res;

}


Measured memory_bytes: 3648
#include <stdio.h>
int array[5001];
int n,i,sum,k=0;
void tansaku(int a)
{
	k += array[a];
	if(k > sum)
	{
		sum = k;
	}
	if(a == n-1)return;
	tansaku(a+1);
}
int main(void)
{
	while(1)
	{
		for(i=0;i<5001;i++)
		{
			array[i] = 0;
		}
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++)
		{
			scanf("%d",&array[i]);
		}
		sum = array[0];
		for(i=0;i<n;i++)
		{
			tansaku(i);
			k = 0;
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
using vec = vector<vector<vector<vector<int>>>>;
 int main(){
   in h,n;
   cin>>h>>n;
   vector<in> a(n);
   rep(i,n) cin>>a.at(i);
   in sum=0;
   rep(i,n) sum += a.at(i);
   if(h>sum) cout<<"No";
   else cout<<"Yes";
 }


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

int main()
{
	queue<int> a;  // ?????£??¨
	int n;
	int ball = 10;
	cin>>n;
	while( n-- > 0){
		int b=0, c=0;
		int k;
		for(int i=0;i<ball;i++){
			cin>>k;
			a.push( k );
		}
		
		// ??????????????????b?????\????????????
		b = a.front();
		a.pop();
		
		for(int i=0;i<ball-1;i++){
			if( a.front() > b && a.front() > c){
				if( a.front() - b > a.front() - c){
					c = a.front();
				}else{
					b = a.front();
				}
			}else if( a.front() > b){
				b = a.front();
			}else if( a.front() > c){
				c = a.front();
			}else{  // ?????????????????????
				cout<<"NO"<<endl;
				while(1){
					if( a.empty()){
						break;
					}else{
						a.pop();
					}
				}
				break;
			}
			
			a.pop();
			if( a.empty()){
				cout<<"YES"<<endl;
				while(1){
					if( a.empty()){
						break;
					}else{
						a.pop();
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
int n,q;
int a,v;
int tt[1000001]={0},ten[1000001]={0};
typedef pair<int,int> P;
priority_queue<P> qu;
int main(void)
{
	int i,j,flg,max,min,n1,nn,ten1;
	P ppp;
	
	cin>>n>>q;
	
	max=-1;
	min=1000000;
	
	for(i=0;i<q;i++){
	
		cin>>a>>v;
		
		ten[a]+=v;
		
		qu.push(P(ten[a],a*-1));
		
		while(1){
			ppp=qu.top();
			nn=ppp.second*-1;
			if(ten[nn]==ppp.first){
				max=ppp.first;
				min=nn;
				break;
			}
			qu.pop();
		}	
		
		cout<<min<<" "<<max<<endl;
		
	}
	
	return 0;
	
}		


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, x;
  cin >> n >> x;
  ll f0 = x, f1 = n - x;
  ll ans = f0 + f1;
  while (1) {
    if (f1 < f0) swap(f1, f0);
    if (f1 % f0 == 0) {
      ans += f0 * ((f1/f0) * 2 - 1);
      break;
    }
    if (f1 > f0) {
      ans += 2 * f0 * (f1 / f0);
      f1 %= f0;
    } else {
      ans += 2 * f1 * (f0 / f1);
      f0 %= f1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	s := ReadString()
	score := 0
	g := 0
	p := 0
	for _, c := range s {
		if c == 'p' {
			if p < g {
				p++
			} else {
				g++
				score--
			}
		} else {
			// 相手がgの場合
			if p < g {
				p++
				score++
			} else {
				g++
			}
		}
	}
	fmt.Println(score)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 2488
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <math.h>

using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define PRIME 1000000007
#define ADD(a, b) (((a) % PRIME + (b) % PRIME) % PRIME)
#define MUL(a, b) ((((a) % PRIME) * ((b) % PRIME)) % PRIME)
#define SUB(a, b) (((a) % PRIME - (b) % PRIME + PRIME) % PRIME)
#define ll long long
#define FIND_VECTOR(v, i) find((v).begin(), (v).end(), i)
#define IS_UNIQUE(v, i) (FIND_VECTOR(v,i) == (v).end())
#define INDEX(v, i) (FIND_VECTOR(v, i) - (v).begin())

map<ll, ll> m_ans;
ll n, a, b, c, d;
ll rec(ll _n) {
	if (m_ans.find(_n) != m_ans.end()) {
		return m_ans[_n];
	}
	ll ans_a1 = rec(_n / 2LL) + (_n % 2LL) * d + a;
	ll ans_b1 = rec(_n / 3LL) + (_n % 3LL) * d + b;
	ll ans_c1 = rec(_n / 5LL) + (_n % 5LL) * d + c;
	ll ans_a2 = rec((_n+1) / 2LL) + (2LL - _n % 2) * d + a;
	ll ans_b2 = rec((_n+2) / 3LL) + (3LL - _n % 3) * d + b;
	ll ans_c2 = rec((_n+4) / 5LL) + (5LL - _n % 5) * d + c;
	ll ans_d = _n * d;
	if (log10l(_n) + log10l(d) > 18 )ans_d = 1000000000000000000LL;
	ll ans = min(min(min(ans_a1, ans_b1), min(ans_c1, ans_d)), min(min(ans_a2, ans_b2), ans_c2));
	//cout << _n << " ";
	//cout << ans << endl;
	//cout << "a" << ans_a1 << endl;
	//cout << "b" << ans_b1 << endl;
	//cout << "c" << ans_c1 << endl;
	//cout << "a" << ans_a2 << endl;
	//cout << "b" << ans_b2 << endl;
	//cout << "c" << ans_c2 << endl;
	//cout << "d" << ans_d << endl;
	m_ans[_n] = ans;
	return ans;
}

void solve() {
	m_ans.clear();
	cin >> n >> a >> b >> c >> d;
	m_ans[0] = 0;
	m_ans[1] = d;
	cout << rec(n) << endl;/*
	for (auto m : m_ans) {
		cout << m.first << " " << m.second << endl;
	}*/
}

int main() {
	int t; cin >> t;
	REP(i, t) solve();
	return 0;
}

Measured memory_bytes: 4444
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string NO = "IMPOSSIBLE";

void solve(ll A, ll B) {
  if((A+B)%2) {
    cout << NO << endl;
    return;
  }
  cout << (A+B)/2 << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<cstdio>
using namespace std;
int main() {
	int a,b,sum;
	double ans;
	while(cin>>a>>b){
		sum=a+b;
		ans=log10((double)sum);
		cout<<(int)ans+1<<endl;
	}
	return 0;
}


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

int main(){
  ll n,p,q,c;
  scanf("%lld%lld%lld",&n,&p,&q);
  vector<ll> x(n);
  rep(i,n){
    scanf("%lld",&c);
    x[i] = c - (q+i)*p - (n-1-i)*2*p;
  }
  sort(x.begin(),x.end());

  ll res = p*(n*q + n*(n-1)/2), sum = res;
  rep(i,n){
    sum += x[n-1-i];
    res = max(res, sum + p*i*(i+1));
  }
  printf("%lld\n",res);
}

Measured memory_bytes: 4952