akhauriyash/Code-Regression huggingface dataset:
/* Nested Controls II Spreadsheet */
#include<stdio.h>

int main(void){
/* Get demension */
int r, c;

scanf("%d %d", &r, &c);

/* printf("%d %d\n", r, c); /* for debug */

/* Read Data */
int matrix[c+1][r+1];       /* matrix       */
int i, j;                   /* loop counter */

for (i = 0; i < r; i++) {
for (j = 0; j < c; j++) {
        scanf("%d", &matrix[j][i]);
}
}

/* Calculate sum */
for (i = 0; i < r + 1 ; i++) {
matrix[c][i]=0;
}
for (i = 0; i < c + 1 ; i++) {
matrix[i][r]=0;
}

for (i = 0; i < r; i++) {
for (j = 0; j < c; j++) {
        matrix[c][i] = matrix[c][i] + matrix[j][i];
        matrix[j][r] = matrix[j][r] + matrix[j][i];
        matrix[c][r] = matrix[c][r] + matrix[j][i];
}
}

/* Print matirx */
for (i = 0; i < r + 1 ; i++) {
for (j = 0; j < c + 1 ; j++) {
if ( j != c ) {
        printf("%d ", matrix[j][i]);}
else {
        printf("%d\n", matrix[j][i]);}
}
}
return 0;
}

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


int main(int argc, char const *argv[])
{
	int n,m,a;
	priority_queue<int> q;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		q.push(a);
	}
	while(m--)
	{
		int x=q.top()>>1;
		q.pop();
		q.push(x);
	}
	long long s=0;
	while(!q.empty())
	{
		s+=q.top();
		q.pop();
	}
	printf("%lld\n", s);
	return 0;
}

Measured memory_bytes: 892
XS = list(map(int, open(0).read().split()))
for i in range(0, len(XS), 2):
    n,x = XS[i:i+2]
    if n == 0 and x == 0:
        break
    ans = 0
    for j1 in range(1, n+1):
        for j2 in range(j1+1, n+1):
            for j3 in range(j2+1, n+1):
                if j1 + j2 + j3 == x:
                    ans += 1
    print(ans)


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

using namespace std;


int main () {

	ios_base :: sync_with_stdio (0); cin.tie (NULL);

	int N;
	cin >> N;

	for (int x = 1; x <= N; ++x) {
		int y = N / x;
		if ((y * x == N) && (max (x, y) < 10)) {
			cout << "Yes" << '\n';
			return 0;
		}
	}

	cout << "No" << '\n';
	
	return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main 
{
	static int w;
	static int h;
	static Scanner scan = new Scanner(System.in);
	static int[][] map;
	static int count = 0;
	
	static void vanquish(int xpos, int ypos)
	{
		if(xpos < 0 || ypos < 0 || xpos >= w || ypos >= h) {return;}
		if(map[xpos][ypos] == 1)
		{
			map[xpos][ypos] = 0;
			vanquish(xpos+1,ypos);
			vanquish(xpos-1,ypos);
			vanquish(xpos,ypos+1);
			vanquish(xpos,ypos-1);
			vanquish(xpos-1,ypos-1);
			vanquish(xpos+1,ypos-1);
			vanquish(xpos+1,ypos+1);
			vanquish(xpos-1,ypos+1);
		}
	}

	public static void main(String[] args) 
	{
		while(true)
		{
			w = scan.nextInt();
			h = scan.nextInt();
			if(w == 0) {break;}
			count = 0;
			
			map = new int[w][h];
			
			for(int i = 0; i < h; i++)
			{
				for(int j = 0; j < w; j++)
				{
					map[j][i] = scan.nextInt();
				}
			}
			
			for(int i = 0; i < h; i++)
			{
				for(int j = 0; j < w; j++)
				{
					if(map[j][i] == 1)
					{
						count += 1;
						vanquish(j,i);
					}
				}
			}
			
			System.out.println(count);
			
			
		}
	}

}



Measured memory_bytes: 45868
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, T; cin >> N >> T;
	vector<int> t(N); rep(i, 0, N) { cin >> t[i]; }
	int X(0), e(0), s(0);
	bool botton(false);
	rep(i, 0, N) {
		if (t[i] <= e) {
			e = t[i] + T;
			botton = true;
		}
		else {
			X += e - s;
			s = t[i];
			e = t[i] + T;
			botton = false;
		}
		dump(s, e, X, botton);
	}
	X += e - s;
	cout << X << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>

using std::begin;
using std::end;

bool isPrime(int n) {
  int r = std::sqrt(n);

  for(int i{2}; i <= r; ++i) {
    if(n % i == 0) return false;
  }
  return true;
}

int main() {
  int n;
  std::cin >> n;
  int cnt{0};

  for(int i{0}; i < n; ++i) {
    int t;
    std::cin >> t;
    if(isPrime(t)) ++cnt;
  }

  std::cout << cnt << std::endl;

  return 0;
}



Measured memory_bytes: 3088
#include<cstdio>

using int64=long long;

int cnt[200001];

int main(){
	int N,K;scanf("%d %d",&N,&K);
	const int n=N,k=K;
	int64 ans=0;

	for(int i=1;i<=n;++i)
		++cnt[i%k];

	for(int i=0;i<k;++i)
		if((k-i+k-i)%k==0)
			ans+=(int64)cnt[i]*cnt[(k-i)%k]*cnt[(k-i)%k];

	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <stack>
#include <cstdlib>

using namespace std;

int main() {
	stack <int> nums;
	char input[398];
	char num[10];
	int a = 0;
	int b = 0;
	int counter = 0;
	bool check = 0;

	scanf("%[^\n]%*c", input);
	for (int i = 0; input[i] != '\0'; i++) {
		switch(input[i]) {
			case '+':
				a = nums.top();
				nums.pop();
				b = nums.top();
				nums.pop();
				a = a + b;
				nums.push(a);
				check = 1;
				break;
			case '-':
				a = nums.top();
				nums.pop();
				b = nums.top();
				nums.pop();
				a = b - a;
				nums.push(a);
				check = 1;
				break;
			case '*':
				a = nums.top();
				nums.pop();
				b = nums.top();
				nums.pop();
				a = a * b;
				nums.push(a);
				check = 1;
				break;
			case ' ':
				if (check) {
					break;
				}
				for (int j = i - counter; j < i; j++) {
					num[j-i+counter] = input[j];
				}
				a = atoi(num);
				nums.push(a);
				for (int j = 0; j < 10; j++) {
					num[j] = '\0';
				}
				counter = 0;
				break;
			default:
				check = 0;
				counter++;
		}
	}
	printf("%d\n", nums.top());
	return 0;
}



Measured memory_bytes: 2760
a,b,c,d = map(int,input().split())

ans = -10000000000000000000

if a*c>ans:
    ans = a*c
if b*d>ans:
    ans = b*d
if a*d>ans:
    ans = a*d
if c*b>ans:
    ans = c*b

print(ans)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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

#define MAX_V 10000
struct edge{int to;long long cap,rev;};

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,long long cap){
	G[from].push_back((edge){to,cap,(ll)G[to].size()});
	G[to].push_back((edge){from,0,(ll)G[from].size()-1});
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty())	{
		int v = que.front();que.pop();
		for(int i = 0;i < G[v].size();++i){
			edge &e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v ,int t,long long f){
	if(v == t)return f;
	for(int &i = iter[v];i < G[v].size() ;++i){
		edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]){
			long long d = dfs(e.to,t,min(f,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

long long Dinic(int s,int t){
	long long flow = 0;
	while(1){
		bfs(s);
		if(level[t] < 0)return flow;
		memset(iter,0,sizeof(iter));
		long long f;while((f = dfs(s,t,INF)) > 0)flow += f;
	}
}

int main(){
	ll st = 1000, en = 1001;
	ll n, m;cin >> n >> m;
	string str;cin >> str;

	REP(i, n){
		ll a;cin >> a;
		if(str[i] == 'R'){
			add_edge(st, i, 0);
			add_edge(i, en, a);
		}
		else {
			add_edge(st, i, a);
			add_edge(i, en, 0);
		}
	}

	REP(i, m){
		ll a, b ,c;cin >> a >> b >> c;
		a--;b--;
		if(a > b)swap(a, b);
		add_edge(b, a, c);
	}

	cout << Dinic(st, en) << endl;

	return 0;
}



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

int N, W;
int f[100003];

inline int Rd() {
	int x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x;
}
inline void ChkMin(int &aa, int bb) {
	if(aa > bb) aa = bb;
	return;
}

int main()  {
	int w, v;
	N = Rd(), W = Rd();
	memset(f, 63, sizeof f), f[0] = 0;
	for(register int i = 1; i <= N; ++i) {
		w = Rd(), v = Rd();
		for(register int j = 100000; j >= v; --j)
			ChkMin(f[j], f[j - v] + w);
	}
	for(register int i = 100000; i >= 0; --i)
		if(f[i] <= W) {
			cout << i << endl;
			break;
		}
	return 0;
}

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

int main(){
    vector<int> N(4);

    rep(i,5){
        cin >> N[i];
    }
    rep(i,5){
        if(N[i]==0){cout << i+1 << endl; break; }
    }
}

Measured memory_bytes: 3608
#include <stdio.h>
#define BUILDING_NUM 4
#define FLOOR_NUM 3
#define ROOM_NUM 10

int main(void) {

    int i, j, k;
    int data_num;
    int building;
    int floor;
    int room;
    int value;
    int data[BUILDING_NUM][FLOOR_NUM][ROOM_NUM] = { 0 };

    scanf("%d", &data_num);

    for (i = 0; i < data_num; i++) {

        scanf("%d %d %d %d", &building, &floor, &room, &value);

        data[building - 1][floor - 1][room - 1] += value;

        if(data[building - 1][floor - 1][room - 1] < 0) {
            data[building - 1][floor - 1][room - 1] = 0;
        }
    }

    for (i = 0; i < BUILDING_NUM; i++) {
        for (j = 0; j < FLOOR_NUM; j++) {
            for (k = 0; k < ROOM_NUM; k++) {
                printf(" %d", data[i][j][k]);
            }
            printf("\n");
        }
        if (i != BUILDING_NUM - 1) {
            puts("####################");
        }
    }

    return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin>>k;
  int temp=7;
  for(int i=0;i<k;i++){
      if(temp%k==0){
          cout<<i+1<<endl;
          return 0;
      }
      temp=(temp*10+7)%k;
  }
  cout<<-1<<endl;
  return 0;

}

Measured memory_bytes: 3564
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        List<int> preorder = Console.ReadLine().Split(' ')
                                    .Select(val => int.Parse(val))
                                    .ToList();
        int[] inorder = Console.ReadLine().Split(' ')
                                    .Select(val => int.Parse(val))
                                    .ToArray();
        BinaryTree btree = new BinaryTree(n);
        btree.Rebuild(ref preorder, inorder);
        btree.PostorderDisplay();
    }
}

class BinaryTree
{
    internal class Node
    {
        internal int Value {get; set;}
        internal Node parent, left, right;

        internal Node() : this(0) {}
        internal Node(int val) : this(val, null, "") {}
        internal Node(int val, Node parent, string direction)
        {
            this.Value = val;
            this.parent = parent;
            switch (direction)
            {
                case "right": this.parent.right = this; break;
                case "left": this.parent.left = this; break;
            }
        }

        public override string ToString()
        {
            return this.Value.ToString();
        }
    }


    private Node[] nodes;
    private Node this[int i]
    {
        get
        {
            return nodes[i];
        }
        set
        {
            this[i] = value;
        }
    }
    private Node root;

    public BinaryTree(int n)
    {
        nodes = new Node[n + 1];
        nodes[0] = new Node();
    }

    public Node Rebuild(ref List<int> preorder, int[] inorder)
    {
        if(preorder.Count <= 0 || inorder.Length <= 0) return null;
        int center = preorder[0];
        preorder.RemoveAt(0);
        nodes[center] = new Node(center);
        if(this.root == null) this.root = nodes[center];
        int splitPoint = Array.IndexOf(inorder, center);
        if(splitPoint == -1) return null;
        if(splitPoint > 0)
        {
            int[] leftTree = new int[splitPoint];
            Array.Copy(inorder, 0, leftTree, 0, splitPoint);
            this[center].left = Rebuild(ref preorder, leftTree);
        }
        if(inorder.Length > splitPoint + 1)
        {
            int[] rightTree = new int[inorder.Length - splitPoint - 1];
            Array.Copy(inorder, splitPoint + 1, rightTree, 0, inorder.Length - splitPoint - 1);
            this[center].right = Rebuild(ref preorder, rightTree);
        }
        return this[center];
    }

    public void PostorderDisplay()
    {
        string str = "";
        Console.WriteLine(PostorderString(ref str, this.root).Trim());
    }
    private string PostorderString(ref string result, Node node)
    {
        if(node.left != null) PostorderString(ref result, node.left);
        if(node.right != null) PostorderString(ref result, node.right);
        result += " " + node.ToString();
        return result;
    }
}

Measured memory_bytes: 10068
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

#define def 0
template<class V, int NV> struct SegTree { //[l,r)
  V comp(V& l, V& r) { return max(l, r); };

  vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
  V get(int x, int y, int l = 0, int r = NV, int k = 1) {
    if (r <= x || y <= l)
      return def;
    if (x <= l && r <= y)
      return val[k];
    auto a = get(x, y, l, (l + r) / 2, k * 2);
    auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
    return comp(a, b);
  }
  void update(int i, V v) {
    i += NV;
    val[i] = v;
    while (i>1) {
      i >>= 1;
      val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
  }
  void add(int i, V v) {
    update(i, val[i + NV] + v);
  }
  V operator[](int x) {
    return get(x, x + 1);
  }
};

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"
const int MAX_N = 2e5;

int H[MAX_N], A[MAX_N];
SegTree<ll, (1 << 18)> dp;
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  IN(N);

  REP(i, N)
    cin >> H[i];
  REP(i, N)
    cin >> A[i];


  REP(i, N) {
    ll opt = dp.get(0, H[i]) + A[i];
    dp.update(H[i], max(dp[H[i]], opt));
  }

  OUT(dp.get(0, 1 << 18));

  // ll dp[N+1];
  // REP(h, N+1)
  //   dp[h] = 0;
  // REP(i, N) {
  //   dp[H[i]] = A[i];
  //   REP(j, i) {
  //     if (H[i] < H[j])
  //       continue;
  //     dp[H[i]] = max(dp[H[i]], (ll)dp[H[j]] + A[i]);
  //   }
  // }
  // ll ans = 0;
  // REP(h, N+1)
  //   ans = max(ans, dp[h]);
  // OUT(ans);

  // dp[h] = 一番右の花の高さがhのときの美しさの総和の最大値

  return 0;
}


Measured memory_bytes: 5888
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = min(a, k);
  k -= min(k, a);
  k -= min(k, b);
  ans += -1 * min(k, c);
  cout << ans << endl;  

  return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x[] = new int[n];
		int low = 100,high = -100;
		for(int i =0 ; i < n; i++){
			x[i] =  scan.nextInt();
			if(x[i] >= high)high = x[i];
			if(x[i] <= low)low = x[i];
		}
		
		int cost, min = 10000000;
		for(int i = -100; i <= 100; i++){
			cost = 0;
			for(int j = 0; j < n; j++){
				cost += (x[j] - i)*(x[j] - i);
			}
			if(cost <= min )min = cost;
		}
		System.out.print(min);
	}

}

Measured memory_bytes: 21972
r,g,b,n=map(int,input().split())
def INT(m):
  if int(m)==m:
    return True
  return False
aa=[r,g,b]
aa.sort()
a,b,c=aa[0],aa[1],aa[2]
ans=0
for i in range(n//c +1):
  for j in range((n-i*c)//b +1):
    if INT((n-i*c-j*b)/a):
      ans+=1
print(ans)

Measured memory_bytes: 41068
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int h, w, n;

	cin>>h>>w>>n;

	vi a(n);

	vvi c(h, vi(w));

	rep(i, n) cin>>a[i];

	int k=0;
	rep(i, h){
		if(i%2){
			reprev(j, w){
				if(a[k]==0) k++;
				c[i][j]=k+1;
				a[k]--;
			}
		}else{
			rep(j, w){
				if(a[k]==0) k++;
				c[i][j]=k+1;
				a[k]--;
			}
		}
	}
	rep(i, h){
		rep(j, w){
			cout<<c[i][j];
			if(j!=w-1) cout<<" ";
		}
		cout<<endl;
	}
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (3006)
ll n, q, A[MAXN], X[MAXN], Y[MAXN], mod=1e9+7, dp[MAXN][MAXN];
ll qexp(ll x,ll e){ll sum=1;for(;e;e>>=1,x*=x,x%=mod)if(e&1)sum*=x,sum%=mod;return sum;}
int main(){
	FAST
	cin>>n>>q;
	FOR(i,1,n)cin>>A[i];
	FOR(i,1,q)cin>>X[i]>>Y[i];
	ll inv=qexp(2,mod-2);
	FOR(i,1,n)FOR(j,1,n){
		dp[i][j] = (A[i] > A[j]);
	}
	FOR(i,1,q){
		FOR(j,1,n)if(j^X[i])if(j^Y[i]){
			ll jX=dp[j][X[i]], Xj=dp[X[i]][j], jY=dp[j][Y[i]], Yj=dp[Y[i]][j];
			dp[j][X[i]] *= inv, dp[j][X[i]] %= mod, dp[j][X[i]] += jY * inv % mod, dp[j][X[i]]%=mod;
			dp[X[i]][j] *= inv, dp[X[i]][j] %= mod, dp[X[i]][j] += Yj * inv % mod, dp[X[i]][j]%=mod;
			dp[j][Y[i]] *= inv, dp[j][Y[i]] %= mod, dp[j][Y[i]] += jX * inv % mod, dp[j][Y[i]]%=mod;
			dp[Y[i]][j] *= inv, dp[Y[i]][j] %= mod, dp[Y[i]][j] += Xj * inv % mod, dp[Y[i]][j]%=mod;
		}
		ll XY=dp[X[i]][Y[i]],YX=dp[Y[i]][X[i]];
		dp[X[i]][Y[i]] *= inv, dp[X[i]][Y[i]] %= mod, dp[X[i]][Y[i]] += YX * inv % mod, dp[X[i]][Y[i]]%=mod;
		dp[Y[i]][X[i]] *= inv, dp[Y[i]][X[i]] %= mod, dp[Y[i]][X[i]] += XY * inv % mod, dp[Y[i]][X[i]]%=mod;
	}
	ll ans = 0;
	FOR(i,1,n)FOR(j,i+1,n)ans += dp[i][j], ans %= mod;
	ans *= qexp(2, q), ans %= mod;
	cout<<ans<<'\n';
}


Measured memory_bytes: 74192
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(a, b, c) for(ll c=a;c<b;c++)
#define re(b, c) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  ll x, y;std::cin >> x >> y;
  ll c = 0;
  bitset<17000> v, h;
  ll st = 8500;
  v[st] = 1, h[st] = 1;

  ll k = 0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='T') {
      if(k>0){
        if(c==0) h = (h<<k);
        else if(c%2==0) h = (h<<k)|(h>>k);
        else v = (v<<k)|(v>>k);
        k = 0;
      }
      c++;
    }else k++;
    if(i==s.size()-1&&k>0){
      if(c==0) h = (h<<k);
      else if(c%2==0) h = (h<<k)|(h>>k);
      else v = (v<<k)|(v>>k);
      k = 0;
    }
  }
  if(h[st+x]&&v[st+y]){
    std::cout << "Yes" << '\n';
  }else{
    std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
N,L=map(int,raw_input().split())
def F(i):
    return L+i
m=114514
r=None
s=0
for i in range(N):
    if abs(F(i))<m:
        m=abs(F(i))
        r=F(i)
    s+=F(i)
print(s-r)


Measured memory_bytes: 2568
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<int>& a, vector<int>& b) {
	return a[0] < b[0];
}

int ycomp(vector<int>& a, vector<int>& b) {
	return a[1] < b[1];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)
#define YSORT(c) sort((c).begin(),(c).end(),ycomp)

#define ALL(x) (x).begin(),(x).end()


LL mod = 1000000007;
int main() {
	LL K, S;
	cin >> K >> S;
	LL nowK = K;
	LL sum = 0;
	while (true) {
		if (nowK * 3 < S) {
			break;
		}
		else 
		if(nowK*3==S){
			sum++;
			break;
		}
		else {
			LL hoge = S - nowK;
			LL M = min(nowK, hoge);
			while (true) {
				if (M < hoge - M) {
				break;
				}else
					if (M == hoge - M) {
						sum += 3;
						break;
					}
					else {
						if (M == nowK) {
							sum += 3;
						}
						else {
							sum += 6;
						}
						M--;
					}
			}
		}
		nowK--;
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>

const int N = 7;
const int DICE_COUNT = 2;

const int ROTATION_MAX = 4;
const int ROTATION_KIND = 3;

const int ROTATION_X = 0;
const int ROTATION_Y = 1;
const int ROTATION_Z = 2;

const int ROTATION_MAP[3][N] = {
  {0, 2, 6, 3, 4, 1, 5},
  {0, 3, 2, 6, 1, 5, 4},
  {0, 1, 3, 5, 2, 4, 6}
};

typedef struct {
  int origin[N];
  int panels[N];
} Dice;

void rotate_dice(int op, Dice *dice) {
  int a[N] = {0};
  
  for (int i = 1; i < N; i++) {
    a[ROTATION_MAP[op][i]] = dice->panels[i];
  }

  for (int i = 1; i < N; i++) {
    dice->panels[i] = a[i];
  }  
}

void swap(int *x, int *y) {
  int tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(void) {
  const int base = 0;
  const int compared = 1;  
  
  Dice dices[DICE_COUNT];

  for (int i = 0; i < DICE_COUNT; i++) {
    for (int j = 1; j < N; j++) {
      std::cin >> dices[i].origin[j];
      
      dices[i].panels[j] = dices[i].origin[j];
    }
  }

  int rotationTable[ROTATION_MAX * ROTATION_MAX * ROTATION_MAX][ROTATION_KIND] = {0};
  int count = 0;
  
  for (int i = 0; i < ROTATION_MAX; i++) {
    for (int j = 0; j < ROTATION_MAX; j++) {
      for (int k = 0; k < ROTATION_MAX; k++) {
	rotationTable[count][ROTATION_X] = i;
	rotationTable[count][ROTATION_Y] = j;
	rotationTable[count][ROTATION_Z] = k;

	count++;
      }
    }
  }

  bool found = false;

  for (int n = 0; n < (ROTATION_MAX * ROTATION_MAX * ROTATION_MAX); n++) {
    for (int i = 1; i < N; i++) {
      dices[compared].panels[i] = dices[compared].origin[i];
    }
    
    for (int i = 0; i < rotationTable[n][ROTATION_X]; i++) {
      rotate_dice(ROTATION_X, &dices[compared]);
    }
    
    for (int i = 0; i < rotationTable[n][ROTATION_Y]; i++) {
      rotate_dice(ROTATION_Y, &dices[compared]);      
    }

    for (int i = 0; i < rotationTable[n][ROTATION_Z]; i++) {
      rotate_dice(ROTATION_Z, &dices[compared]);
    }

    found = true;

    for (int i = 1; i < N; i++) {
      if (dices[base].panels[i] != dices[compared].panels[i]) {
	found = false;
	
	break;
      }
    }

    if (found) {
      break;
    }
  }

  if (found) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }  
  
  return 0;
}

Measured memory_bytes: 1160
N = int(input())
H = [int(x) for x in input().split()]
ans = 0
tmp = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        tmp += 1
    else:
        ans = max(tmp, ans)
        tmp = 0
else:
    ans = max(tmp, ans)
    print(ans)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define MAX int(1e9 + 7)

using namespace std;
typedef long long ll;


int const mm = 1500;
ll dp[mm][mm];
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // ONLINE_JUDGE

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

    for(int i = 0; i < n; ++i) dp[i][0] = 0;
    for(int i = 0; i < m; ++i) dp[0][i] = 0;
    dp[1][1] = 1;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            char c; cin>>c;
            if(i == 1 && j == 1)continue;
            if(c == '#') continue;
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MAX;
        }
    }
    cout<<dp[n][m];
    return 0;
}


Measured memory_bytes: 15288
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

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;
}

const ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

int main() {
    int n,m;
    cin >> n >> m;
    vector<ll> h(n);
    vector<bool> check(n,true);
    rep(i,n) {
        cin >> h.at(i);
    }
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        if(h.at(a-1)>=h.at(b-1)) {
            check.at(b-1)=false;
        }
        if(h.at(a-1)<=h.at(b-1)) {
            check.at(a-1)=false;
        }
    }
    int cnt=0;
    rep(i,n) {
        if(check.at(i)) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4788
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
const int N = 100001;
int t;
int n,k;
int a[N],dp[N];
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    
    for(int i=2;i<n;i++){
        for(int j=1;j<=k&&i-j>=0;j++)
            dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 3984
// Aizu 2131: Pi is Three
// 2017.9.22 bal4u@uu

#include <stdio.h>
#include <math.h>

#define EPS 1e-9
#define PI 3.1415926535897932384626433832795

int main(void)
{
	int k, t;
	double r;

	while (scanf("%lf", &r) && fabs(r) > EPS) {
		for (k = 1 ; ; k++) {
			t = (int)(k * PI);
			if (fabs((double)t  /k - PI) <= r) break;
			if (fabs((double)++t/k - PI) <= r) break;
		}
		printf("%d/%d\n", t, k);
    }
	return 0;
}

Measured memory_bytes: 1736
[n, m, c] = [int(i) for i in input().split()]
list_b = [int(i) for i in input().split()]
lists = [[int(j) for j in input().split()] for i in range(0, n)]

cnt = 0
for a in lists:
    total = 0
    for (idx, b) in enumerate(list_b):
        total = total + a[idx] * b
    total = total + c
    if total > 0:
        cnt = cnt + 1
print(cnt)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << (x) << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int n;
vector< int > graph[100];
bool flag[100];

int solve(int p, int cnt);

int main() {
    int m;
    int a, b;
    cin >> n >> m;

    REP(i, m) {
        scanf("%d%d", &a, &b);
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    OUT(solve(1, 1));

    return 0;
}

int solve(int p, int cnt)
{
    if (flag[p]) return 0;
    if (cnt == n) return 1;

    flag[p] = true;
    int ret = 0;
    for (auto next : graph[p]) {
        ret += solve(next, cnt + 1);
    }
    flag[p] = false;

    return ret;
}


Measured memory_bytes: 256
#include <iostream>
 using namespace std;
 int main(){
 int N,K;
 cin>>N>>K;

 int cnt=0;
 for(int i=0;i<N;i++){
	 int h;
 cin>>h;
 if(h>=K) cnt++;
 }

cout<<cnt<<endl;
return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int n, m;
struct Card {
	int val, num;
	bool operator<(const Card &x) const{ return val < x.val; }
}card[1000010];


int main()
{
	int b, c;
	int total(0);
	long long ans(0ll);
	
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &c);
		card[i].val = c;
		card[i].num = 1;
	}
	for (int i = n; i < n + m; ++i) {
		scanf("%d%d", &b, &c);
		card[i].val = c;
		card[i].num = b;
	}
	sort(card, card + n + m);
	for (int i = n + m - 1; ~i; --i)
		if (total + card[i].num < n) {
			ans += (long long)card[i].val * card[i].num;
			total += card[i].num;
		}
		else {
			ans += (long long)card[i].val * (n - total);
			total = n;
			break;
		}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

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

	int cnt = 0;
	int flag = 0;
	for (int i = 0; i < 3; ++i) {
		if (str[i] == 'R') {
			if (flag == 0) {
				cnt = 1;
			}
			else {
				cnt++;
			}
			flag = 1;
		}
		else {
			flag = 0;
		}
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;
vector<string> vs;
bool used[100];

string changes(ll n) {
	string t = s;
	//cout << n << endl;
	rep(i, s.size()) {
		//cout << (n&(1 << (s.size() - 1 - i)));
		if (n&(1 << i))t[i]++;
	}
	//cout << endl;
	return t;
}

int main() {
	while (cin >> s&&s != "#") {
		int ans = 0;
		rep(i, (1 << s.size())) {
			bool f = 1;
			fill(used, used + 100, 0);
			rep(j, s.size()) {
				if (i&(1 << j)) {
					if (s[j] == 'z')f = 0;
					if (used[s[j] - 'a' + 1])f = 0;
					used[s[j] - 'a' + 1] = 1;
				}
				else {
					if (s[j] != 'a' &&!used[s[j] - 'a'])f = 0;
				}
			}
			if (f)vs.push_back(changes(i));
		}
		cout << vs.size() << endl;
		sort(ALL(vs));
		if (vs.size() > 10) {
			rep(i, 5) {
				cout << vs[i] << endl;
			}
			rep(i, 5) {
				cout << vs[vs.size() - 5 + i] << endl;
			}
		}
		else {
			rep(i, vs.size()) {
				cout << vs[i] << endl;
			}
		}
		vs.clear();
	}
}



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

int main()
{
  vector<string> chars(27);
  chars[0] = 'z';
  for (int i = 1; i <= 26; i++) {
    chars[i] = 'a' + i - 1;
  }
  ll n;
  cin >> n;
  string ans = chars[n % 26];
  if (n % 26 == 0) n -= 26;
  n /= 26;
  while (n > 0) {
    if (n <= 26) {
      ans = chars[n] + ans;
      break;
    }
    ans = chars[n % 26] + ans;
    if (n % 26 == 0) n -= 26;
    n /= 26;

  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define inf 1001001001
using namespace std;
typedef long long ll;
int main(void) {
    int n; cin >> n;
    int ans = 0;
    rep(i, 9) {
        if(n > i*111) {
            ans = i+1;
        }
    }
    cout << ans * 111;
}


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

const int H = 12;
const int W = H;
const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};
char G[H][W];

void dfs(int i, int j) {
  G[i][j] = '0';
  for(int k = 0; k < 4; ++k) {
    int ni = i + di[k];
    int nj = j + dj[k];
    if(ni < 0 || ni >= H) continue;
    if(nj < 0 || nj >= W) continue;
    if(G[ni][nj] != '1') continue;
    dfs(ni,nj);
  }
}

int main() {
  while(1) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        if(cin >> G[i][j]) ; else return 0;
      }
    }

    int ans = 0;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        if(G[i][j] == '1') {
          ++ans;
          dfs(i, j);
        }
      }
    }
    cout << ans << endl;

  }
  return 0;
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
using namespace std;
template<class T>void gi(T &x){
	int f;char c;
	for(f=1,c=getchar();c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(x=0;c<='9'&&c>='0';c=getchar())x=x*10+(c&15);x*=f;
}
const int N=2e5+10;
int n,a[N];
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)gi(a[i]);
  long long ans=0;
  if(a[1])puts("-1"),exit(0);
  for(int i=2;i<=n;i++){
	  if(a[i]>a[i-1]+1)puts("-1"),exit(0);
	  if(a[i]==a[i-1]+1)ans++;
	  else ans+=a[i];
  }
  cout<<ans<<endl;
  return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL n;
    cin >> n;
    vector<LL> d = Div(n - 1);
    set<LL> st;
    for(int i = 1; i < d.size(); ++i) {
        st.insert(d[i]);

    }
    vector<LL> nd = Div(n);
    int c = d.size();
    for(int i = 1; i < nd.size(); ++i) {
        LL t = n;
        while(t >= nd[i] && t % nd[i] == 0) {
            t = t / nd[i];

        }
        t = t % nd[i];
        if(t == 1) ++c;

    }
    cout << c - 1 << endl;

    return 0;
}


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

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var h = int.Parse(Console.ReadLine());

            var s = (a + b) * h / 2;
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

  if(N%2){
    cout<<0<<endl;
    return 0;
  }else if(N<10){
    cout<<0<<endl;
    return 0;
  }

  ll ans=0;
  for(ll i=5;2*i<=N;i*=5){
      ans+=N/(2*i);
  }
  cout<<ans<<endl;

  return 0;
}


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

#define MAXN 1046527  //散列表最大长度，也是模数 
#define MAXSTR 15

#define EXIST 2
#define NOT_EXIST 3

//散列表（全局） 
char HashTable[MAXN][MAXSTR];

//将字符转换为数字
int charToInt(char ch)
{
	switch(ch) {
		case 'A':
			return 1;
			break;
		case 'C':
			return 2;
			break;
		case 'G':
			return 3;
			break;
		case 'T':
			return 4;
			break;
		default:
			break;
	}
}

//将字符串转换成数值并生成key 
long long getKey(char str[])
{
	long long sum = 0;
	int item = 1;
	int len = strlen(str);
	for (int i = 0; i < len; i++) {
		sum += item * charToInt(str[i]);
		item *= 5;
	}
	
	return sum;
}

//散列函数
long long h1(long long key)
{
	return key % MAXN;
}

//开放定址法处理冲突 
long long h2(long long key)
{
	return key % (MAXN - 1) + 1;
}

//配合（双散列）散列函数、开放定址法等对字符串进行散列 
int insert(char str[])
{
	long long key;
	int index;
	key = getKey(str);
	
	for (int i = 0; ; i++) {
		index = (h1(key) + i * h2(key)) % MAXN;
		if (strcmp(HashTable[index], str) == 0) {
			return 1;
		}
		else if (strlen(HashTable[index]) == 0) {
			strcpy(HashTable[index], str);
			return 0;
		}
	}
	
	return 0;
}

//散列查找
int find(char str[])
{
	long long key;
	int index;
	key = getKey(str);
	
	for (int i = 0; ; i++) {
		index = (h1(key) + i * h2(key)) % MAXN;
		//test-def
		//printf("\nindex=%d %s %s\n", index, HashTable[index], str);
		//test-end
		if (strcmp(HashTable[index], str) == 0) {
			return EXIST;
		}
		else if (strlen(HashTable[index]) == 0) {
			return NOT_EXIST;
		}
	}
	
	return NOT_EXIST;
 } 

int main(void)
{
	int n;
	char op[MAXSTR], str[MAXSTR];
	
	//初始化散列表
	for (int i = 0; i < MAXN; i++) {
		HashTable[i][0] = '\0';
	}
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s %s", op, str);
		if (strcmp(op, "insert") == 0) {
			//test-def
			//printf("\n%s\n", str);
			//test-end
			insert(str);
		}
		else {
			if (find(str) == EXIST) {
				printf("yes\n");
			}
			else {
				printf("no\n");
			}
		}
	}
	
	return 0;
 } 


Measured memory_bytes: 18080
while True:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    mp = {}
    for r in range(h):
        s = input()
        for c in range(w):
            mp[s[c]] = [r, c]
    s = input()
    now = [0, 0]
    ans = 0
    for i in range(len(s)):
        to = mp[s[i]]
        ans += abs(now[0] - to[0]) + abs(now[1] - to[1]) + 1
        now = to
    print(ans)


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
i=y j=x
R=y C=x

2 5 5
1 1 3
2 4 20
1 2 1
1 3 4
1 4 2

3 1 4 2
0 0 0 20

k=1
3 3 4  4 4
3 3 4 20 20

k=2
0 4 7  7 7
0 4 7 24 24

000000
004777
00472424


*/
ll DP[3001][3001][4];
ll dt[3001][3001];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll R, C, K;
  cin >> R >> C >> K;
  rep(i, K){
    ll r, c, v;
    cin >> r >> c >> v;
    dt[r][c] = v;
  }
  for(int i=1; i<=R; i++){
    for(int j=1; j<=C; j++){
      //上から、0-3個データ。で、0にだけいれる
      //左から、0-3個データ。
      //自分が1個とれる場合、1-3更新
      rep(k, 4)
        chmax(DP[i][j][0] ,DP[i-1][j][k]); 
      rep(k, 4)
        chmax(DP[i][j][k] ,DP[i][j-1][k]); 
      if (dt[i][j]){
        for(int k=2; k>=0; k--){
          if (DP[i][j][k] == 0 && k > 0)
            continue;
          chmax(DP[i][j][k+1], DP[i][j][k]+dt[i][j]);
        }
      }
    }
  }
  ll ans = 0;
  rep(k, 4)
    chmax(ans, DP[R][C][k]);
  cout << ans << endl;
  
/*rep(i, R+1){
  rep(j, C+1){
    cout<<DP[i][j][2];
  }
  cout<<endl;
}*/
}


Measured memory_bytes: 355284
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	string a;
	cin >> a;
	int ans = 0;
	vector<int>aa(3);
	rep(i, 3) {
		if (a[i] == 'R') {
			++ans;
		}
		else {
			ans = 0;
		}
		aa[i] = ans;
	}
	sort(aa.rbegin(), aa.rend());

	cout << aa[0];
	
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
ll a[100010];
int main(){
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i] / 2;
    if (a[i]&1 && i != n - 1) {
      if (a[i + 1] != 0) {
        ans++;
        a[i + 1]--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main() {
  int D;
  cin >> D;

  if(D == 25){
    cout << "Christmas" <<endl;
  }else if(D == 24){
    cout << "Christmas Eve" <<endl;
  }else if(D == 23){    
    cout << "Christmas Eve Eve" <<endl;
  }else if(D == 22){   
    cout << "Christmas Eve Eve Eve" <<endl;
  }    
}

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

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = new String(in.readLine());
		String[] ss = s.split(" ");
		
		int a = Integer.parseInt(ss[0]);
		int b = Integer.parseInt(ss[1]);
		int c = Integer.parseInt(ss[2]);
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{System.out.println("No");}
		
	}

}

Measured memory_bytes: 16892
N = int(input())
A_list = [int(e) for e in input().split()]
A_list.sort(reverse=False)
ans = A_list[0]
for i in range(1,N):
    ans *= A_list[i]
    
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)

Measured memory_bytes: 21344
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int H,W,K,sum=1,MOD=1000000007;
  cin>>H>>W>>K;
  if(W==1){
    cout<<1<<endl;
    return 0;
  }
//余剰本数での組み合わせ増加数
  vector<int> X(9,0);
  X[0]=1;
  X[1]=1;
  X[2]=2;
  X[3]=3;
  X[4]=5;
  X[5]=8;
  X[6]=13;
  X[7]=21;
  X[8]=1;
  vector<ll> Z(W+2,0), NZ(W+2,0);
  Z[1]=1;
  for(int i=0; i<H; i++){
    for(int j=1; j<=W; j++){
      NZ[j]=Z[j-1]*X[max(j-2,0)]*X[W-j];
      NZ[j]%=MOD;
      NZ[j]+=Z[j]*X[j-1]*X[W-j];
      NZ[j]%=MOD;
      NZ[j]+=Z[j+1]*X[j-1]*X[max(W-(j+1),0)];
      NZ[j]%=MOD;
    }
    Z=NZ;
  }
  cout<<NZ[K]<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void counting_sort(int *A, int *B, int k, long n) {
  int i;
  long j,C[k+1];
  
  for (i = 0; i <= k; i++) {
    C[i] = 0;
  }
  for (j = 1; j <= n; j++) {
    C[A[j]]++;
  }
  for (i = 1; i <= k; i++) {
    C[i] += C[i-1];
  }
  for (j = n; j >= 1; j--) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

int main()
{
  long i,n;
  int *A,*B,k;
  scanf("%ld",&n);
  A = (int*)malloc(sizeof(int) * (n+1));
  B = (int*)malloc(sizeof(int) * (n+1));
  k = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d",A+i);
    if(k < A[i]) k = A[i];
  }
  counting_sort(A,B,k,n);

   for (i = 1; i < n; i++) {
     printf("%d ",B[i]);
   }
   printf("%d\n",B[i]);
  
  return 0;
}

Measured memory_bytes: 16308