akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    while(a+1 != b){
        a++;
        if(a+1 == b){
            cout << "Alice" << endl;
            return 0;
        }
        b--;
    }
    cout << "Borys" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;
#define MAX 2000007
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void fact() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; ++i){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long comb(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
// a^n mod を計算する
//ただしmodとaが互いにその時のみ
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    fact();
    ll K;
    cin >> K;
    string S;
    cin >> S;
    ll N=S.size();
    ll ans=0;
    for(ll i=N-1;i<N+K;++i){
        ans+=comb(i,N-1)*modpow(25,i-(N-1),MOD)%MOD*modpow(26,N+K-i-1,MOD)%MOD;
        ans%=MOD;
    }
    prt(ans);

    return 0;
}



Measured memory_bytes: 51088
#include <stdio.h>
#include <math.h>
#include <limits.h>

int r[100], c[100];
int M[100][100];

int matrix(int left, int right)
{
  int res, i;

  if (M[left][right] >= 0){
    return M[left][right];
  }
  if (left == right){
    return 0;
  }
  res = INT_MAX;
  for (i = left; i < right; i++){
    res = fmin(res, matrix(left, i) + matrix(i + 1, right) + r[left] * c[i] * c[right]);
  }
  M[left][right] = res;
  return M[left][right];
}

int main()
{
  int N;
  int i, j;
  
  scanf("%d", &N);
  for (i = 0; i < N; i++){
    scanf("%d %d", &r[i], &c[i]);
  }
  for(i = 0; i < 100; i++){
    for(j = 0; j < 100; j++){
      M[i][j] = -1;
    }
  }
  printf("%d\n", matrix(0, N - 1));
  return 0;
}

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

int main(){
    using namespace std;
    unsigned long k, q;
    cin >> k >> q;
    vector<unsigned long> d(k);
    for(auto& i : d)cin >> i;
    const auto& query = [&](unsigned long n, unsigned long x, unsigned long m) -> unsigned long {
        x %= m;
        unsigned long S{x + n}, c{n + k - 1};
        for(const auto& i : d)S += c-- / k * ((i + m - 1) % m);
        return n - S / m + x / m;
    };
    for(unsigned long i{0}, n, x, m; i < q; ++i){
        cin >> n >> x >> m;
        cout << query(n - 1, x, m) << endl;
    }
    return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split())

def factorize(x):
    fac = []
    for i in range(1, int(x**0.5)+1):
        if (x % i) == 0:
            fac.append(i)
            fac.append(M//i)
    return sorted(fac)

fac = factorize(M)
fac = filter(lambda x: x <= int(M/N), fac)

print(max(fac))

Measured memory_bytes: 3188
import java.awt.geom.Point2D;
import java.util.*;


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

		new AOJ0179();


	}

	class AOJ0179{
		public AOJ0179() {
			while(true){
				String warm = in.next();
				if(warm.equals("0"))break;
				int ans = get_warm(warm);
				System.out.println(ans==-1? "NA":ans);
			}
		}
		
		int get_warm(String input){
			Queue<String> warm = new LinkedList<String>();
			Queue<Integer> cnt = new LinkedList<Integer>();
			HashMap<String, Boolean> memo = new HashMap<String, Boolean>();
			memo.put(input,true);
			warm.add(input);
			cnt.add(0);
			while(warm.size()>0){
				String a = warm.remove();
				int step = cnt.remove();
//				System.out.println(a+" "+step);//deba
				boolean sw = true;
				for(int i=0;i<a.length()-1;i++)if(a.charAt(i)!=a.charAt(i+1))sw=false;
				if(sw)return step;
				//ここから
				for(int i=0;i<a.length()-1;i++)if(a.charAt(i)!=a.charAt(i+1)){
					String b = a.substring(0,i)+getColor(a.charAt(i),a.charAt(i+1))+a.substring(i+2,a.length());
					if(memo.containsKey(b))continue;
					warm.add(b);
					cnt.add(step+1);
					memo.put(b, true);
				}
			}
			return -1;
		}
		
		String getColor(char a, char b){
			if(a=='r'&&b=='b'||a=='b'&&b=='r')return "gg";
			else if(a=='r'&&b=='g'||a=='g'&&b=='r')return "bb";
			else return "rr";
		}
		
	}

}

Measured memory_bytes: 99384
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1])
index = N-1
ans = 0
limit = 0

for j in range(M-1, -1, -1):
    Bj = BC[j][0]
    Cj = BC[j][1]
    while True:
        if (A[index]<Cj):
            break
        else:
            ans += A[index]
            index -= 1
            if (index < 0):
                break
    if (Bj > index - limit + 1):
        ans += Cj*(index - limit + 1)
        limit = index + 1
        break
    ans += Bj*Cj
    limit += Bj
    
ans += sum(A[limit:index+1])

print(ans)


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

int main(){
	string s,s2;
	cin >> s >> s2;
	if(s.size()>s2.size()) cout << "GREATER" << endl;
	else if(s.size()<s2.size()) cout << "LESS" << endl;
	else if(s.size()==s2.size()){
		if(s==s2) cout << "EQUAL" << endl;
		else if(s>s2) cout << "GREATER" << endl;
		else cout << "LESS" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

n, x, y = map(int, input().strip().split())

x -= 1
y -= 1

dist_counts = defaultdict(int)
for i in range(n):
    for j in range(i + 1, n):
        path1 = abs(j - i)
        path2 = abs(x - i) + 1 + abs(y - j)
        dist = min(abs(j - i), path2)
        dist_counts[dist] += 1

for k in range(1, n):
    print(dist_counts[k])


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int main(void)
{
    int x,y;
    cin >> x >> y;
    int res = x + y / 2;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
tmp = gets.chomp.split(" ").map{|n| n.to_i}

n = tmp[0]
rest = tmp[1]
mounts = []
total = n

n.times do
  mi = gets.chomp.to_i
  rest -= mi
  mounts << mi
end

# plan1. 最小で
total += rest / mounts.min

puts total


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;
int p[60];
int main()
{
    int n;
    cin >> n;
    REP(i, n)
    cin >> p[i];

    int cnt = 0;
    int max = p[0];
    int j = 0,k=0;
    for (int i = 0; i < n-1; i++)
    {
        if ((p[i] > p[i + 1]) && cnt == 0)
        {
            j = i;
            cnt++;
        }

        else if ((p[i] > p[i + 1]) &&cnt == 1)
        {
            k = i+1;
            cnt++;
            break;
        }
   }
   int tmp = p[j];
   p[j] = p[k];
   p[k] = tmp;
  // cerr << j << "" << k << endl;
   bool flag = true;
   for (int i = 0; i < n-1; i++)
   {
       if(p[i]>p[i+1]){
           flag = false;
       }
   }
   if(flag){
       cout << "YES" << endl;
   }
   else{
       cout << "NO" << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string ans = "No";
  char a,b,c,d;
  cin >> a>>b>>c>>d;
  if ((a==b&&c==d&&a!=c) || (a==c&&b==d&&a!=b) ||
      (a==d&&b==c&&a!=b)) {
    ans = "Yes";
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
int main() {
  double a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << fixed << setprecision(10) << sqrt((c-a)*(c-a)+(d-b)*(d-b)) << endl;
}


Measured memory_bytes: 3292
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	ll N,a,b,c,Q,K,x,y; cin>>N;
	vector< vector<pair<ll,ll>> > path(N,vector<pair<ll,ll>>());
	rep(i,N-1){
		cin>>a>>b>>c;
		--a; --b;
		path[a].push_back(make_pair(b,c));
		path[b].push_back(make_pair(a,c));
	}
	cin>>Q>>K;
	vector<ll> dist(N,INF);
	queue<int> q;
	q.push(--K);
	dist[K] = 0;
	while(!q.empty()){
		int f = q.front();
		q.pop();
		for(auto x: path[f]){
			int t = x.first;
			ll wei = x.second;
			if(dist[t] == INF){
				dist[t] = dist[f] + wei;
				q.push(t);
			}
		}
	}
	vector<P> query(Q);
	rep(i,Q){
		cin>>x>>y;
		--x; --y;
		query[i].first = x;
		query[i].second = y;
	}
	rep(i,Q){
		cout<<dist[query[i].first] + dist[query[i].second]<<endl;
	}
	return 0;
}

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

using namespace std;

bitset<2222 * 2222> b = 1, c;
int main()
{
	int n, s = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		s += a;
		c = b;
		c <<= a;
		b |= c;
	}
	for (n = (s + 1) / 2; !b[n]; n++);
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 1408
# include <bits/stdc++.h>
# define FILE

using namespace std;

int main(){

    # ifdef FILEs
        freopen( "input.txt", "r", stdin );
        freopen( "output.txt", "w", stdout );
    # endif
       string s, t;
       cin >> s >> t;
       cout << t << s;
    
}	




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

int main() {
  int N;
  cin >> N ;
  vector<int> d(N);
  
  int i;
  for (i=0; i<N; i++){    
    cin >> d.at(i);
  }
  int count = 0;
  
  sort(d.begin(), d.end());
  //for(i=0; i<d.size(); i++) cout << d.at(i) << endl;
  
  auto index = unique(d.begin(), d.end());
  d.erase(index, d.end());
  
  cout << d.size() << endl;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n - 1):
  if p[i - 1] < p[i] < p[i + 1]:
    ans += 1
  if p[i - 1] > p[i] > p[i + 1]:
    ans += 1

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n, a, b, x = 0, bx = 0; cin >> n >> a >> b;
	string s; cin >> s;
	for (int i = 0; i < n; i++) {
		if (s.at(i)=='a') {
			if (x < a + b) {
				cout << "Yes" << endl;
				x++;
			}
			else cout << "No" << endl;
		}
		else if (s.at(i)=='b') {
			if (x < a + b && bx < b) {
				cout << "Yes" << endl;
				x++; bx++;
			}
			else cout << "No" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


int main() {
	ll a, b;
	cin >> a >> b;
	cout << a % b << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  int tmp;
  int ans=0;
  for(int i=0;i<N;i++)
  {
    cin>>tmp;
    if(i%2==0 && tmp%2==1)
      ans++;
  }
  cout<<ans;
}
   
  

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

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

    long long n, k;
    cin >> n >> k;

    if (n >= k) n = n % k;
    cout << min(n, k - n) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=5e3+50;
const int mod=1e9+7;
int n;
int main()
{
    double n;
    scanf("%lf",&n);
    printf("%.12lf",n*n*n/27);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int N;

void solve() {
    cin >> N;
    vector<P> edges;
    vector<vector<int>> g(N);
    int maxNodeNum = 0;
    int maxN = 0;
    for (int i = 0; i < N - 1; ++i) {
        int a, b; cin >> a >> b; a--; b--;
        edges.push_back(P(a, b));
        g[a].push_back(b);
        g[b].push_back(a);
        if (maxN < (int)g[a].size()) {
            maxNodeNum = a;
            maxN = (int)g[a].size();
        }
        if (maxN < (int)g[b].size()) {
            maxNodeNum = b;
            maxN = (int)g[b].size();
        }
    }
    map<P, int> I;
    vector<int> gc(N, 0);
    vector<bool> memo(N, false);
    queue<int> q;
    q.push(maxNodeNum);
    memo[maxNodeNum] = true;
    while(!q.empty()) {
        int node = q.front(); q.pop();
        int cur = 1;
        for (int n_node : g[node]) {
            if (memo[n_node]) continue;
            if (cur == gc[node]) cur++;
            gc[n_node] = I[P(node, n_node)]=I[P(n_node, node)] = cur++;
            memo[n_node] = true;
            q.push(n_node);
        }
    }

    cout << maxN << endl;
    for (int i = 0; i < N-1; ++i) {
        P e = edges[i];
        printf("%d\n", I[e]);
    }
}

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


Measured memory_bytes: 19700
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>

#define Max 1000000

int64_t cnt = 0;

void insertionSort(int *A,int n, int g){
	int v=0,j=0;
	//?????????g????£???§?????\?????????????????£?????????
	for(int i = g;i < n;++i){
		v = A[i];
		j = i-g;
		while(j >= 0 && A[j] > v){
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

std::vector<int> G;

void  shellSort(int A[],int n){
	//g(n+1) =3g(n) + 1????????????????????????
	for(int i=1; ; ){
		if(i > n)
			break;
		G.push_back(i);
		i = 3*i + 1;
	}


	for(int i=G.size() - 1; i >= 0;i--){
		insertionSort(A,n,G[i]);
	}
}


int main(){
	int n=0;
	int A[1000000];

	std::cin>>n;
	for(int i=0;i<n;++i)
		scanf("%d",&A[i]);
	
	shellSort(A,n);
	
	std::cout<<G.size()<<std::endl;
	for(int i=G.size() - 1; i >= 0;i--){
		if(i == G.size() -1){
			std::cout<<G[i];
			continue;
		}
		std::cout<<" " <<G[i];
	}
	std::cout<<std::endl;
	
	std::cout<<cnt<<std::endl;

	for(int i=0;i<n;i++){
		std::cout<<A[i]<<std::endl;
	}

	return 0;
}

Measured memory_bytes: 5172
#include <iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a>b){
        cout << "a > b" << endl;
    }
    else if(a<b){
        cout << "a < b" << endl;
    }
    else{
        cout << "a == b" << endl;
    }
    return 0;
}


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,m,i,j,p,y,t=1;
	cin>>n>>m;
	vector<pair<int,int>> a(m);
	vector<tuple<int,int,int>> g;
	for (i=0;i<m;i++){
		cin>>p>>y;
		g.push_back(make_tuple(p,y,i));
	}
	sort(g.begin(),g.end());
	for (i=0;i<g.size();i++){
		if (i==0){
			a[get<2>(g[i])].first=get<0>(g[i]);
		    a[get<2>(g[i])].second=t;
		}
		else {
			if (get<0>(g[i])==get<0>(g[i-1])){
				t++;
			}
			else {
				t=1;
			}
			a[get<2>(g[i])].first=get<0>(g[i]);
			a[get<2>(g[i])].second=t;
		}  
	}
	for (i=0;i<a.size();i++){
		t=a[i].first;
		int r=0;
		while (t>0){
			t/=10;
			r++;
		}
		for (j=0;j<6-r;j++){
			cout<<"0";
		}
		cout<<a[i].first;
		t=a[i].second;
		r=0;
		while (t>0){
			t/=10;
			r++;
		}
		for (j=0;j<6-r;j++){
			cout<<"0";
		}
		cout<<a[i].second<<"\n";
	}
	return 0;
}

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

int main(){
  int N, M, C, sum = 0 ,ans = 0;
  cin >> N >> M >> C;
  int B[M], A;
  for(int i = 0; i < M; i++){
    cin >> B[i];
  }
  for(int j = 0; j < N; j++){
    sum = 0;
    for(int i = 0; i < M; i++){
      cin >> A;
      sum += A * B[i];
    }
    sum += C;
    if(sum > 0) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#pragma GCC optimize ("O3")

inline static int gl(void){
    int x = 0;
    for(;;){
        unsigned int c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

inline static void pl(unsigned int s){
    char str[9];
    int pos=9;
    if(s==0){
        putchar_unlocked('0');
        return;
    }
    do{
        pos--;
        str[pos]=s%10+48;
        s/=10;
    }while(s!=0);
    for(; pos<9; pos++){
        putchar_unlocked(str[pos]);
    }
}

char a[501];
unsigned short out[1000000];

int main(void){
    const int h=gl(), w=gl();
    int pos=0;
    {
        char haveCoin = 0;
        short old_y, old_x;
        for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
                int t = getchar_unlocked() - 48;
                getchar_unlocked();
                a[j] = t;
            }
            if(i%2==1){
                for(int j=1; j<=w; j++){
                    if(haveCoin){
                        out[4*pos+0]=old_y;
                        out[4*pos+1]=old_x;
                        out[4*pos+2]=i;
                        out[4*pos+3]=j;
                        pos++;
                    }
                    haveCoin ^= a[j]&1;
                    old_y = i;
                    old_x = j;
                }
            }else{
                for(int j=w; j>0; j--){
                    if(haveCoin){
                        out[4*pos+0]=old_y;
                        out[4*pos+1]=old_x;
                        out[4*pos+2]=i;
                        out[4*pos+3]=j;
                        pos++;
                    }
                    haveCoin ^= a[j]&1;
                    old_y = i;
                    old_x = j;
                }
            }
        }
    }
    pl(pos); putchar_unlocked('\n');
    for(int i=0; i<pos; i++){
        pl(out[4*i+0]); putchar_unlocked(' ');
        pl(out[4*i+1]); putchar_unlocked(' ');
        pl(out[4*i+2]); putchar_unlocked(' ');
        pl(out[4*i+3]); putchar_unlocked('\n');
    }
    return 0;
}


Measured memory_bytes: 2944
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MAX = 1e5 + 5, MOD = 1e9 + 7;
constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;



int main() {
    int A, B, T;
    cin >> A >> B >> T;
    int ans = (T) / A * B;
    write(ans);
}

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

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

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

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

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

using ll = long long;

using namespace std;

int prime[int(1e7) + 1];

ll calc(int x) {
  map<ll, ll> m;
  while (x > 1) {
    m[prime[x]]++;
    x /= prime[x];
  }
  ll ret = 1;
  for (auto [k, v] : m) {
    ret *= v + 1;
  }
  return ret;
}

int main() {
  in(ll, n);
  ll ans = 1;
  for (int i = 2; i <= n; ++i) {
    if (prime[i] == 0) {
      prime[i] = i;
      for (int j = i + i; j <= n; j += i) {
        prime[j] = i;
      }
    }
    ans += i * calc(i);
  }
  out(ans);
}


Measured memory_bytes: 42660
import sys

def solve():
    input = sys.stdin.readline
    S = input().strip("\n")
    z, o = 0, 0
    for i in range(len(S)):
        if S[i] == "0": z += 1
        else: o += 1
    print(2 * min(z, o))
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3188
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
if a + b + c + d == 7:
  print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a + b + c - d == 7:
  print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a + b - c - d == 7:
  print('{}+{}-{}-{}=7'.format(a,b,c,d))
elif a - b - c - d == 7:
  print('{}-{}-{}-{}=7'.format(a,b,c,d))
elif a + b - c + d == 7:
  print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a - b - c + d == 7:
  print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a - b + c - d == 7:
  print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a - b + c + d == 7:
  print('{}-{}+{}+{}=7'.format(a,b,c,d))

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

int main(){
  int n; cin >> n;
  long a[n];
  rep(i, n) cin >> a[i];
  long ans = 0;
  long ss = 0;
  long sx = 0;
  int r = 0;
  rep(l, n){
    if(l > r) r = l;
    while(r<n && (ss+a[r])==(sx^a[r])){
      ss += a[r];
      sx ^= a[r];
      r++;
    }
    ans += r - l;
    ss -= a[l];
    sx ^= a[l];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
A,B,C,D=[int(x) for x in input().rstrip().split()]
import sys
#体力A,C、攻撃B,D
flag=1
while(flag==1):
  if C!=0:
    C-=B
    if C<=0:
      print("Yes")
      sys.exit()

  if A!=0:
    A-=D
    if A<=0:
      print("No")
      sys.exit()




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

int main() {
   int a;
   cin>>a;
   vector<double> vec(a);
   double sum=0;
   rep(i,a){
       cin>>vec.at(i);
   }
   sort(vec.begin(),vec.end());
   sum=(vec.at(0)+vec.at(1))/2;
   for(int i=2;i<a;i++){
       sum=(sum+vec.at(i))/2;
   }
   cout<<sum<<endl;
}



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

using namespace std;

struct Card {
	string suit;
	int number;
};
using vec = vector<Card>;

void QuickSort(Card* A, const int p, const int r);
int Partition(Card* A, const int p, const int r);
bool isStable(const vec A, const vec B);

int main() {
	int n;
	vec cards;

	cin >> n;
	cards.resize(n);
	for(auto&& e : cards) {
		cin >> e.suit >> e.number;
	}
	vec org = cards;
	QuickSort(cards.data(), 0, n - 1);

	cout << ((isStable(cards, org) ? "Stable" : "Not stable")) << endl;
	for(const auto& e : cards) {
		cout << e.suit << " " << e.number << endl;
	}

	return 0;
}

void QuickSort(Card* A, const int p, const int r) {
	if(p < r) {
		const int q = Partition(A, p, r);
		QuickSort(A, p, q - 1);
		QuickSort(A, q + 1, r);
	}
}

int Partition(Card* A, const int p, const int r) {
	const Card x = A[r];
	int i = p - 1;
	for(int j = p; j < r; j++) {
		if(x.number >= A[j].number) {
			swap(A[++i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

bool isStable(const vec A, const vec B) {
	int num = A[0].number;
	int count = 0;
	string str[4];

	for(int i = 0; i < A.size(); i++) {
		if(num == A[i].number) {
			str[count++] = A[i].suit;
		}
		else{
			int strIdx = 0;
			for(const auto& e : B){
				if(e.number != num) { continue; }

				if(e.suit != str[strIdx++]){
					return false;
				}
				if(strIdx > count) { break; }
			}
			num = A[i].number;
			count = 1;
			str[0] = A[i].suit;
		}
	}
	return true;
}



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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll d; cin >> d;

    vector<ll> c(26);
    for (ll i = 0; i < 26; ++i) {
        cin >> c[i];
    }

    vector<vector<ll>> s(d, vector<ll>(26));
    for (ll i = 0; i < d; ++i) {
        for (ll j = 0; j < 26; ++j) {
            cin >> s[i][j];
        }
    }

    vector<ll> t(d);
    for (ll i = 0; i < d; ++i) {
        ll idx = 0;
        ll mx = 0;
        for (ll j = 0; j < 26; ++j) {
            if (mx < s[i][j]) {
                mx = s[i][j];
                idx = j;
            }
        }
        t[i] = idx;
    }

    vector<ll> score(d, 0);
    vector<vector<ll>> last(d, vector<ll>(26, 0));

    auto re_score = [&](ll start) {
        for (ll i = start; i < d; ++i) {
            score[i] = (i - 1 >= 0 ? score[i - 1] : 0) + s[i][t[i]];

            if (i - 1 >= 0) {
                last[i] = last[i - 1];
            } else {
                for (ll j = 0; j < 26; ++j) {
                    last[0][j] = 0;
                }
            }

            last[i][t[i]] = i + 1;

            ll j = i + 1;

            for (ll k = 0; k < 26; ++k) {
                score[i] -= c[k] * (j - last[i][k]);
            }
        }
    };

    re_score(0);

    ll mx_score = score[d - 1];
    for (ll i = 0; i < d; ++i) {
        for (ll j = 0; j < 26; ++j) {
            ll tmp = t[i];

            t[i] = j;
            re_score(i);

            if (mx_score >= score[d - 1]) {
                t[i] = tmp;
                re_score(i);
            } else {
                mx_score = score[d - 1];
            }
        }
    }

    for (ll i = 0; i < d; ++i) {
        cout << t[i] + 1 << endl;
    }
}

Measured memory_bytes: 3796
#include <iostream>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int H, W; in(H); in(W);

  char A[H][W];
  rep(i, H) rep(j, W) {
    in(A[i][j]);
  }
  rep(i, H) rep(j, W) {
    if (i+1 < H && A[i+1][j] == '#' && j+1 < W && A[i][j+1] == '#') {
      out("Impossible");
      return 0;
    }
  }
  out("Possible");

  return 0;
}


Measured memory_bytes: 256
my $s = <STDIN>;
my @s = split(/ /,$s);
my $ans = &ceil($s[0]/$s[1],0);
print "$ans";

sub ceil {
	my $val = shift;	# 切り上げる数
	my $col = shift;	# 小数点以下のどこまで残すか
	my $r = 10 ** $col;
	if ($val > 0) {
		my $tmp = $val * $r;
		if ($tmp == int($tmp)) {
			return $tmp / $r;
		} else {
			return int($tmp + 1) / $r;
		}
	} else {
		return int($val * $r) / $r;
	}
}

Measured memory_bytes: 512
import java.util.*;
class Main
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();
		if(Math.abs(x-a)>Math.abs(x-b))
		{
			System.out.println("B");
		}
		else
		{
			System.out.println("A");
		}
	}
}

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

int N,Q;
string S;
vector<set<int>> abc(26);

void add(int i, char c){//type1
	if(S[i] == c) return;
	abc[S[i]-'a'].erase(i);
	S[i] = c;
	abc[S[i]-'a'].insert(i);
}

void out(int l, int r){//type2
	int ans = 0;
	rep(i,26){
		if(abc[i].size() <= 0) continue;
		auto it = abc[i].lower_bound(l);
		if(it == abc[i].end()) continue;
		if(*it <= r) ans++;
	}
	printf("%d\n",ans);
}

int main(){
	cin>>N>>S>>Q;
	rep(i,N) abc[S[i]-'a'].insert(i);
	rep(i,Q){
		int t,a;
		cin>>t;
		if(t-1){//type2
			int b;
			cin>>a>>b;
			out(a-1, b-1);
		}
		else{//type1
			char b;
			cin>>a>>b;
			add(a-1, b);
		}
	}
}

Measured memory_bytes: 24196
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var ans = getAns(s);
        Console.WriteLine(ans);
    }
    static int getAns(string s)
    {
        var ans = 0;
        var sL = s.Length;
        for (int i = 0; i < sL; i++)
        {
                var t = 0;
                for (int j = i; j < sL; j++)
                {
                    var a = s[j];
                if (a == 'A' | a == 'T' | a == 'C' | a == 'G') { t++; ans = Max(ans, t); }
                else { goto next; }
                }
            next:;
        }
        return ans;
    }
}

Measured memory_bytes: 13140
program forbidden_list
  implicit none
  integer :: x, n, p(100) = 0, i, d = 1e9, m = -1e9
  logical :: u(-2:102) = .false.
  read(*,*) x, n
  if (n == 0) then
    write(*,'(i0)') x
    stop
  end if
  read(*,*) p(1:n)
  do i = 1, n
    u(p(i)) = .true.
  end do
  do i = -2, 102
    if (u(i)) cycle
    if (d > abs(i-x)) then
      d = abs(i-x)
      m = i
    end if
  end do
  write(*,'(i0)') m
end program forbidden_list

Measured memory_bytes: 2928
import sys

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


def main():
    N = int(readline())

    ans = (pow(10, N, MOD) - pow(9, N, MOD) * 2 % MOD + pow(8, N, MOD)) % MOD
    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61720
#include <iostream>
#include <string>
using namespace std;
int keisan(int,int);
int keisanz(int,int);
int main(){
	int a,b,c;
	string str;
	int data,data2;
	for (int i=0;i<9;i++){
		cin>>str>>a>>b;
		data=keisan(a,b);
		data2=keisanz(a,b);
		cout<<str<<" "<<data<<" "<<data2<<endl;
	}
	return 0;
}
int keisan(int a,int b){
	int k=0;
	k=a+b;
	return k;
}
int keisanz(int a,int b){
	int l=0;
	l=a*200+b*300;
	return l;
}



Measured memory_bytes: 3136
N,y = (int(x) for x in input().split())
Y = y / 1000
o = 0
for a in range (N+1):
    for b in range (N-a+1):
        c = N - (a+b)
        if Y == 10*a + 5*b + c and o == 0:
            print (a,b,c)
            o = 1
if o == 0:
    print (-1,-1,-1)

Measured memory_bytes: 8972
MOD = 1000000007

def power(a, n)
  return 1 if n == 0
  return a if n == 1
  if n % 2 == 0
    p = power(a, n / 2)
    return p * p % MOD
  else
    p = power(a, n - 1)
    return p * a 
  end
end

def main

  n = gets.chomp.to_i
  costs = gets.chomp.split.map(&:to_i)
  costs.sort!.reverse!
   
#コストにかかる係数
  step = n == 1 ? 0 : power(2, n - 2)
  base = n == 1 ? 1 : step * 2
   
  if n == 1
    coef = [1]
  else
    coef = n.times.map {|v| 
      base + step * v
    }
  end
  
  ans = 0
  n.times do |i|
    ans += costs[i] * coef[i] % MOD
  end
   
  ans = ans << n
  puts ans % MOD
end

main


Measured memory_bytes: 23980
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31))

//seg木でCHTするやつ(Li Chao Segment Tree)
//最小値を求める
typedef struct line{ll a,b;}L;
typedef struct node{
	int flag;
	L L;
	ll l,m,r;
	//葉ではl=m=rとしておく、左端は|最小値|*(-2),右端は|最大値|+iとかで埋めとく
}node;
int segNUM;
node segN[1<<21],*seg;
void seguse(int n){segNUM=n;seg=segN+segNUM;}
//葉に値を与えてから初期化
void seginit(){
	for(int i=segNUM-1;i;i--){
		segN[i].l=segN[2*i].l;
		segN[i].m=segN[2*i].r;
		segN[i].r=segN[2*i+1].r;
	}
}
void segpush(L f){
	//seg木にfを追加する
	int i=1;
	while(1){
		if(segN[i].flag==0){
			segN[i].flag=1;
			segN[i].L=f;
			return;
		}
		ll fl=f.a*segN[i].l+f.b;
		ll fm=f.a*segN[i].m+f.b;
		ll fr=f.a*segN[i].r+f.b;
		ll Ll=segN[i].L.a*segN[i].l+segN[i].L.b;
		ll Lm=segN[i].L.a*segN[i].m+segN[i].L.b;
		ll Lr=segN[i].L.a*segN[i].r+segN[i].L.b;
		if(Ll<=fl&&Lm<=fm&&Lr<=fr)return;
		else if(Ll>=fl&&Lm>=fm&&Lr>=fr){
			segN[i].L=f;
			return;
		}
		else if(Lm<=fm){
			if(fl<=Ll)i=i*2;//左へ進む
			else i=i*2+1;//右へ進む
		}else{
			L temp=f;
			f=segN[i].L;
			segN[i].L=temp;
			if(Ll<=fl)i=i*2;//左へ進む
			else i=i*2+1;//右へ進む
		}
	}
	return;
}

//i番目の葉の値を取ってくる
ll segcalc(int i){
	ll ans=INF;
	ll x=segN[segNUM+i].l;
	for(i+=segNUM;i;i/=2)if(segN[i].flag)ans=min(ans,segN[i].L.a*x+segN[i].L.b);
	return ans;
}
//セグ木ここまで
//*/

ll dp[200010];
ll h[200010];
int main(){
	ll n,c;
	scanf("%lld%lld",&n,&c);
	rep(i,1,n+1)scanf("%lld",h+i);
	//dp[i]=(h[i]^2+C)+min(-2*h[j]*(h[i])+(dp[j]+h[j]^2))
	
	seguse(1<<18);
	rep(i,1,n+1)seg[i].l=seg[i].m=seg[i].r=h[i];
	seg[0].l=seg[0].r=h[1]*-2;
	rep(i,n+1,1<<18)seg[i].l=seg[i].m=seg[i].r=h[n]+i;	
	seginit();
	
//	rep(i,0,16)	printf("%lld %lld\n",segN[i].l,segN[i].r);
	
	rep(i,2,n+1){
		//i-1をpush
		L f;
		f.a=-2*h[i-1];
		f.b=dp[i-1]+h[i-1]*h[i-1];
		segpush(f);
		dp[i]=segcalc(i)+h[i]*h[i]+c;
	}
	printf("%lld\n",dp[n]);
	return 0;
}

Measured memory_bytes: 29952
use proconio::input;
fn main() {
  input! {
  	n: u32,
  }
  let mut ans = 0;
  
  for i in 0..n {
    
    let f = n - i;
    let t = n/f;
    for j in 1..t+1 {
      let m = f*j;
      if n - m != 0 { ans += 1; }
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 2140
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int x, a, b;

int main()
{
	scanf("%d%d%d", &a, &b, &x);
	if(x <= a + b && x >= a) printf("YES\n");
	else printf("NO\n");

	return 0;
}

Measured memory_bytes: 256
N = int(input())
dp = [0] * (N+1)

if N<=2:
    print(0)
elif N==3:
    print(1)
else:
    dp[1]=0
    dp[2]=0
    dp[3]=1
    for i in range(4,N+1):
        dp[i] = sum(dp[3:i-2]) + 1

    print(dp[N] % (10**9+7))

Measured memory_bytes: 73924
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		int[] A = new int[N];
		for(int i=0; i<N; i++)
			A[i] = sc.nextInt();

		long sum = 0;
		for(int i=0; i<N; i++)
			sum += A[i];
		
		ArrayList<Integer> factor = new ArrayList<>();
		for(int i=1; (long)i*i<=sum; i++)
			if(sum%i==0)
				factor.add(i);
		
		for(int i=0; i<factor.size(); i++) {
			long gcd = sum/factor.get(i);
			if(check(A, K, gcd)) {
				System.out.println(gcd);
				sc.close();
				return;
			}
		}
		
		for(int i=0; i<factor.size(); i++) {
			long gcd = factor.get(factor.size()-i-1);
			if(check(A, K, gcd)) {
				System.out.println(gcd);
				sc.close();
				return;
			}
		}
	}
	
	static boolean check(int[] A, long K, long gcd) {
		int N = A.length;
		int[] norm = A.clone();
		for(int i=0; i<N; i++)
			norm[i] %= gcd;
		
		Arrays.sort(norm);
		if(norm[N-1]==0)
			return true;
		
		long sum = 0;
		for(int i=0; i<N; i++) {
			sum += norm[i];
		}
		
		long operation = 0;
		for(int i=0; i<N-sum/gcd; i++)
			operation += norm[i];

		return operation <= K;
		
	}
}


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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int n, cnt = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n-2; i++)
    {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
            ++cnt;
    }
    cout << cnt; 
    
    return 0;
}

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

using namespace std;

const int maxn=1e2+5;

int s[maxn][maxn];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x,cnt;
        scanf("%d%d",&x,&cnt);
        for(int j=0;j<cnt;j++){
            int y;
            scanf("%d",&y);
            s[x][y]=1;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(j!=1){
                printf(" ");
            }
            printf("%d",s[i][j]);
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 3228
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
#include <limits>
using namespace std;
int gcd(int a, int b)//最大公約数
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}
vector<int> divisor(int n) {//約数発見
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    std::sort(ret.begin(), ret.end());
    return ret;
}
long nc2(long n){
    return n*(n-1)/2;
}
template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
	static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string ret;
	static numeric_limits<TypeInt> t;
	TypeInt n = v;
	if (t.is_signed) {
		if (v < 0) n *= -1;
	}

	while (n >= base) {
		ret += table[n%base];
		n /= base;
	}
	ret += table[n];
	if (t.is_signed) {
		if (v < 0 && base == 10) ret += '-';
	}
	// 文字列の順番を逆にする
	std::reverse(ret.begin(), ret.end());

	return ret;
}

int main(){
    //std::stack<int> stack;
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    vector<int> ans(4,0);
    for(int i = 0; i < n; i++){
        if(s[i] == "AC"){
            ans[0] ++;
        }else if(s[i] == "WA"){
            ans[1] ++;
        }else if(s[i] == "TLE"){
            ans[2] ++;
        }else{
            ans[3] ++;
        }
    }
    cout << "AC x ";
    cout << ans[0]<< endl;
    cout << "WA x ";
    cout << ans[1]<< endl;
    cout << "TLE x ";
    cout << ans[2]<< endl;
    cout << "RE x ";
    cout << ans[3]<< endl;
    return 0;
}






Measured memory_bytes: 6376
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
  
  string N;
  cin>>N;
  int ans=0;
  vector<int>keta(N.length());
  for(size_t i=0;i<=N.length()-1;i++){
  
    keta[i]=N[i];
  }
  bool flag=0;
  for(size_t i=1;i<=N.length()-1;i++){
  
    if(keta[i]!=57){
    
      flag=1;
      break;
    }
  }
  if(flag==0){
  
    cout<<keta[0]+(N.length()-1)*9-48<<endl;
  }
  else{
  
    cout<<keta[0]-1+(N.length()-1)*9-48<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m;
int a[1252];

int main(){
  scanf("%d%d",&n,&m);
  REP(i,n)scanf("%d",a+i);
  ll ans = 0;
  int gr = n/__gcd(n,m);
  int head = 0;
  REP(_,gr){
    int mn = 1e9, mx = -1e9;
    REP(i,m){
      CHMIN(mn,a[head]);
      CHMAX(mx,a[head]);
      head++;
      if(head==n)head=0;
    }
    ans += mx-mn;
  }
  printf("%lld\n",ans);
  return 0;
}

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

ll minimum;

ll frog(ll *A,ll n,ll k)
{
    ll ans=0,p=0;
    
    ll t[n+1];
    for(int i=0;i<=n;i++)
    t[i]=INT_MAX;
    
    for(int i=1;i<=n;i++)
    {
        if(i==1)
        t[i]=0;
    
        else if(i>=3&&k>=2)
        {
        for(int j=i-1;j>=max(i-k,p);j--)
            {
            ans=abs(A[i]-A[j])+t[j];
            t[i]=min(ans,t[i]);
            }
        }
        
        else t[i]=abs(A[i]-A[i-1])+t[i-1];
    }
    
    return t[n];
}

int main()
{
    ll n,k,sum=0;
    cin >>n>>k;
    
    minimum=INT_MAX;
    
    ll A[n];
    
    for(int i=1;i<=n;i++)
    cin >>A[i];
    
    if(k==1)
    {
        for(int i=1;i<n;i++)
        sum+=abs(A[i]-A[i+1]);
        
        cout <<sum;
    }
    else cout <<frog(A,n,k);
}

Measured memory_bytes: 5132
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
lint sum[100100],a[100100];
lint mo=1000000007,out=0;
int main()
{
	int n;
	cin>>n;
	rep(i,n) cin>>a[i];
	sum[0]=0;
	rep(i,100010) sum[i+1]=(sum[i]+invMod(i+1,mo))%mo;
	rep(i,n){
		out+=a[i]*(sum[i+1]+sum[n-i]-1);
		out%=mo;
	}
	REP(i,1,n+1){
		out*=i;out%=mo;
	}
	cout<<out<<endl;
}


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

using namespace std;

typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define pb push_back
#define F first
#define S second
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;


void solve()
{
	ll n;
	cin>>n;
	ll sum=0;
	for(ll i=1;i*i<=n;i++)
	{
		if((n%i==0))
		{
			ll x=n/i;
			if(x-1>i)
			{
				sum+=(x-1);
			}
			// x--;
			// sum+=x;

		}
	}
	cout<<sum<<endl;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	solve();
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	k := scanInt()
	s := scanInt()

	a := make([]int, n+1)

	for i := 0; i < k; i++ {
		if i!= 0 {a[i] = a[i-1]+1}
		a[n-1-k+1+i] = a[i]+s
	}

	b := 1
	if s == int(1e9) {
		b = -1
	}

	for i := 0; i < n; i++ {
		if i < k {
			a[i+1] = a[i]+s
		} else {
			a[i+1] = a[i]+s+b
		}
	}

	// fmt.Fprintln(os.Stderr, a)
	for i := 0; i < n; i++ {
		fmt.Fprintf(wr, "%d ", a[i+1]-a[i])
	}
}


Measured memory_bytes: 3328
(let* ((n (read))
       (a (make-array n :element-type 'integer))
       (x 0)
       (y 0)
       (res 0))
  (dotimes (i n)
    (setf (aref a i) (read)))
  (setf x (aref a 0)
        y (loop for i from 1 below n sum (aref a i))
        res (abs (- x y)))
  (loop for i from 1 below (1- n)
        for ai = (aref a i) do
        (incf x ai)
        (decf y ai)
        (setf res (min res (abs (- x y)))))
  (format t "~A~%" res))

Measured memory_bytes: 59752
N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
a.append(-1)

dp = [0 for i in range(N + 1)]
dp[0] = 1
point = 0
if a[point] == 1:
    dp[1] = 0
    point += 1
else:
    dp[1] = 1
for i in range(2, N + 1):
    if i == a[point]:
        dp[i] = 0
        point += 1
    else:
        dp[i] = (dp[i - 2] + dp[i - 1]) % (10 ** 9 + 7)
print(dp[N])


Measured memory_bytes: 7832
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
    int n,b[100],temp;
    scanf("%d", &n);
    for (int i = 0; i <= n-1; i++) {
        scanf("%d", &b[i]);
    }
    for (int i = 0; i <= n /2 - 1; i++) {
        temp = b[n - 1 - i];
        b[n - 1 - i] = b[i];
        b[i] = temp;
    }
    for (int j = 0; j <= n - 1; j++) {
        printf("%d", b[j]);
        if (j != n - 1)printf(" ");
        else printf("\n");
    }
    return 0;
}


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

int main() {
	string S; long long K;
	cin >> S >> K;
	for (int i = 0; i < min((long long)S.size(), K); i++) {
		if (S[i] >= '2') { cout << S[i] << endl; return 0; }
	}
	cout << '1' << endl;
	return 0;
}


Measured memory_bytes: 3596