akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i,0,n)

typedef vector<pii> vp;
typedef vector<vp> vvp;
struct node{
  int index,gas, cost;
  node(int index,int gas,int cost):index(index),gas(gas),cost(cost){}
  bool operator<(const node& other)const{
    return cost>other.cost;
  }
};
const int MAX=INT_MAX/2-10;
const int NONE=-1;

int main(){
  int r,m,cap;
  while(cin>>r>>m>>cap,r|m|cap){
    cap*=10;
    string src,dest;
    cin>>src>>dest;
    int start;
    int goal;
    vvp dist;
    vs cities;
    REP(i,r){
      string a,b;
      cin>>a>>b;
      int d;
      cin>>d;
      int ai,bi;
      vs::iterator it_a=find(ALL(cities),a);
      if(it_a!=cities.end()){
        ai=it_a-cities.begin();
      }else{
        cities.push_back(a);
        ai=cities.size()-1;
        dist.push_back(vp());
      }
      vs::iterator it_b=find(ALL(cities),b);
      if(it_b!=cities.end()){
        bi=it_b-cities.begin();
      }else{
        cities.push_back(b);
        bi=cities.size()-1;
        dist.push_back(vp());
      }
      dist[ai].push_back(make_pair(bi,d));
      dist[bi].push_back(make_pair(ai,d));
      if(a==src){ start=ai; }
      if(b==src){ start=bi; }
      if(a==dest){ goal=ai; }
      if(b==dest){ goal=bi; }
    }
    int n=cities.size();
    vi is_station(n);
    REP(i,m){
      string s;
      cin>>s;
      vs::iterator it=find(ALL(cities),s);
      if(it!=cities.end()){
        is_station[it-cities.begin()]=1;
      }
    }

    priority_queue<node> q;
    q.push(node(start,cap,0));
    vvi cost(n,vi(cap+1,MAX));
    cost[start][cap]=0;
    while(!q.empty()){
      node cnode=q.top();q.pop();
      if(cost[cnode.index][cnode.gas]<cnode.cost){
        continue;
      }
      REP(ii,dist[cnode.index].size()){
        int i=dist[cnode.index][ii].first;
        int dd=dist[cnode.index][ii].second;
        if(i!=cnode.index&&dd!=NONE){
          int newcost=cnode.cost+dd;
          int newgas=cnode.gas-dd;
          if(newgas>=0){
            if(is_station[i]){
              newgas=cap;
            }
            if(cost[i][newgas]>newcost){
              cost[i][newgas]=newcost;
              q.push(node(i,newgas,newcost));
            }
          }
        }
      }
    }
    int ans=MAX;
    REP(i,cap+1){
      ans=min(ans,cost[goal][i]);
    }

    cout<<(ans==MAX?-1:ans)<<endl;
  }
}

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

struct Op {
	int x0, y0, x1, y1;
	Op(int _x0, int _y0, int _x1, int _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
};

int main() 
{
	int H, W;
	cin >> H >> W;
	vector< vector<int> > board;
	for (int i = 0; i < H; i++) {
		vector<int> v;
		for (int j = 0; j < W; j++) {
			int val;
			cin >> val;
			v.push_back(val);
		}
		board.push_back(v);
	}
	vector<Op> ans;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (board[i][j] % 2 != 0) {
				if (j != W - 1) {
					board[i][j]--;
					board[i][j + 1]++;
					ans.push_back(Op(i, j, i, j + 1));
				} else if (i != H - 1) {
					board[i][j]--;
					board[i + 1][j]++;
					ans.push_back(Op(i, j, i + 1, j));
				}
			}
		}
	}
	int N = ans.size();
	cout << N << "\n";
	for (int i = 0; i < N; i++) 
		cout << ans[i].x0 + 1 << " " << ans[i].y0 + 1 << " " 
			 << ans[i].x1 + 1 << " " << ans[i].y1 + 1 << "\n"; 
		
	return 0;
}

Measured memory_bytes: 5232
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);

		String x = sc.nextLine();
		x += x;
		String y = sc.nextLine();

		if(x.contains(y)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

		sc.close();
	}
}


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

int main()
{
    int n;cin>>n;
    vector<int>arr(n);
    int cnt=0;
    for(int i=0 ; i<n ; i++)
    {
      cin>>arr[i];
      if(i%2==0 and arr[i]%2!=0) cnt++;
    }
    cout<< cnt;

    return 0;

}

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

using namespace std;

const int N = 300 + 77;
int n , a[4];
long double dp[N][N][N];
vector < pair < int , int > > V;
int main(){
   ios::sync_with_stdio(0);cin.tie(0);
   cin >> n;
   for(int x , i = 1;i <= n;++ i)
      cin >> x , ++ a[x];
   for(int i = 0;i <= n;++ i)
      for(int j = 0;j <= n;++ j)
         for(int k = 0;k <= n;++ k){
            if(i + j + k > n)
               continue ;
            V.push_back(make_pair(j + k * 2 + (n - i - j - k) * 3 , i * N * N + j * N + k));
         }
   sort(V.begin() , V.end());
   for(auto x : V){
      int nw = x.second;
      int k = nw % N;nw /= N;
      int j = nw % N;nw /= N;
      int i = nw % N;nw /= N;
      if(i == n)
         continue ;
      int t0 = i , t1 = j , t2 = k , t3 = n - i - j - k;
      long double sum = 0;
      if(t1 > 0)
         sum += (long double) t1 / (long double) n * dp[i + 1][j - 1][k];
      if(t2 > 0)
         sum += (long double) t2 / (long double) n * dp[i][j + 1][k - 1];
      if(t3 > 0)
         sum += (long double) t3 / (long double) n * dp[i][j][k + 1];
      long double ts = 1 - ((long double) t0 / (long double) n);
      dp[i][j][k] = (sum + 1) / ts;
   }
   cout << fixed << setprecision(10) << dp[0][a[1]][a[2]] << '\n';
   return 0;
}


Measured memory_bytes: 700892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, t, a;
    cin >> n >> t >> a;
    double h[n];
    for (int i = 0; i < n; i++) cin >> h[i];
    double minv = 1e9, tmp;
    int ans;
    for (int i = 0; i < n; i++) {
        tmp = minv;
        minv = min(minv, abs(t - (h[i] * 0.006) - a));
        if (tmp != minv) ans = i + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	int n, m;
	String s, t;

	public static long gcd(long n2, long m2) {
		return m2 > 0 ? gcd(m2, n2 % m2) : n2;
	}

	public static long min(long a,long b) {
		if(a < b) {
			return a;
		}else {
			return b;
		}
	}

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		String nm = sc.nextLine();
		String[] len = nm.split(" ");

		long n = Integer.parseInt(len[0]);
		long m = Integer.parseInt(len[1]);

		String s = sc.nextLine();
		String t = sc.nextLine();

		for (int i = 0; i < min(m,n); i++) {
			if ((((m * i) % n == 0) && ((m * i) / n < m) && (s.charAt(i) != t.charAt((int) ((m * i) / n)))) ||
				(((n * i) % m == 0) && ((n * i) / m < n) &&(t.charAt(i) != s.charAt((int) ((n * i) / m))))) {
				System.out.println("-1");
				return;
			}
		}

		System.out.println(n*m/gcd(n,m));
		return;
	}

}

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

const string YES = "Yes";
const string NO = "No";

void solve(string N){
    if(N[0] == N[2]) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    string N;
    cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int r = int.Parse(input[0]);
        int d = int.Parse(input[1]);
        int x = int.Parse(input[2]);

        var retValue = new List<int>();
        var cal = x;

        for (int i = 1; i <= 10; i++)
        {
            cal = (r * cal) - d;
            retValue.Add(cal);
        }
        foreach(var rec in retValue)
        {
            //出力
            Console.WriteLine(rec);
        }
    }
}

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

inline void write(ll x)
{
    char F[200];
    int tmp = x > 0 ? x : -x;
    if (x < 0)
        putchar('-');
    int cnt = 0;
    while (tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while (cnt > 0)
        putchar(F[--cnt]);
}
inline ll read()
{
    ll x = 0;
    char c = getchar();
    while (c < '0' || c > '9')
        c = getchar();
    while (c >= '0' && c <= '9')
        x = x * 10 + c - '0', c = getchar();
    return x;
}
int sum,a[200010];
ll n, p, q, t,l;
void Imsuperman()
{
    cin>>n;
    ll ans=0;
    for(int i=0;i<n;i++){
        a[i]=read();
        while((sum^a[i])!=sum+a[i]) sum^=a[l++];
        ans+=i-l+1;
        sum^=a[i];
    }
    cout<<ans<<endl;
}
int main()
{
    Imsuperman();
    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"sort"
)

func main() {
	// Code for A - ringring
	a := make([]int, 3)
	fmt.Scanf("%d %d %d", &a[0], &a[1], &a[2])

	sort.Sort(sort.IntSlice(a))
	fmt.Println(a[0] + a[1])
}


Measured memory_bytes: 1836
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int h,m,s;
        Scanner timeScan = new Scanner(System.in);
        int time = timeScan.nextInt();

        h = 0;
        m = 0;
        s = 0;

        if(time < 0 || 86400 < time) {
            throw new RuntimeException("範囲外");
        }
        s = time % 60;
        m = (time / 60) % 60;
        h = (time / 60) / 60;

        System.out.println(h+":"+m+":"+s);
    }
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N,M;
    string S;
    cin >> N>>M;

    vector<ll> X(M);
    REP(i, M)
        cin >> X.at(i);
    
    sort(X.begin(), X.end());

    vector<ll> sa(M-1);
    REP(i,M-1){
        sa.at(i) = X.at(i + 1) - X.at(i);
    }
    sort(sa.begin(), sa.end());

    ll ans = 0;
    if(N>=M){
        
    }
    else{
        REP(i, M - N)
        {
            ans += sa.at(i);
        }
    }

    cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
#pragma endregion

void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  char p = 'X';
  i64 ans = 0;
  rep(i, n) {
    if (s[i] == p) ans++;
    p = s[i];
  }
  ans += k * 2;
  cout << min(ans, (i64) n - 1) << endl;
}


Measured memory_bytes: 512
#include<stdio.h>


int main(){
    int n;
    scanf("%d",&n);
    int t[n+1],m,i;
    for(i=1;i<=n;i++)scanf("%d",&t[i]);
    scanf("%d",&m);
    int p[m+1],x[m+1];
    for(i=1;i<=m;i++)scanf("%d %d",&p[i],&x[i]);
    int sum=0;
    for(i=1;i<=n;i++)sum+=t[i];
    
    for(i=1;i<=m;i++){
        printf("%d\n",sum+x[i]-t[p[i]]);
    }
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

const int mod = 1000000007;
const int MXN = 1e6 + 7;

int n, type, a[MXN];
ll t[MXN * 2];

ll getsum (int v, int tl, int tr, int l, int r) {
    if(l > tr || r < tl) return 0;
    if(tl >= l && tr <= r) return t[v];
    else {
        int tm = (tl + tr) / 2;
        return getsum(v * 2, tl, tm, l, r) +
                getsum(v * 2 + 1, tm + 1, tr, l, r);
    }
}

void upd(int v, int tl, int tr, int pos, int val) {
    if(tl == tr) {
        a[pos] = val;
        t[v] = val;
    } else {
        int tm = (tl + tr) / 2;
        if(pos <= tm) upd(v * 2, tl, tm, pos, val);
        else upd(v * 2 + 1, tm + 1, tr, pos, val);
        t[v] = t[v * 2] + t[v * 2 + 1];
    }
}

int cnt, p;

ll x, y;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //freopen("A.in", "r", stdin);
  //freopen("A.out", "w", stdout);
  cin >>n >>x >>y;
  if((y - x) % 2 == 0) cout <<"Alice";
  else cout <<"Borys";
	return 0;
}


Measured memory_bytes: 256
S = input()
len = len(S)
ans = 0

for i in range(1<<(len-1)):
    temp = [c for c in S]
    plus = 0
    for j in range(len-1):
        if ((i>>j) & 1) == 1:
            temp.insert(j+1+plus, '+')
            plus += 1
    ans += eval("".join(temp))

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

//********************************template END****************************************//

void solve(void){
	int N;
	cin >> N;

	vecll as(N), es;
	map <ll, ll> mp;

	rep(N, i)
	{
		cin >> as[i];
		if (++mp[as[i]] >= 2)
		{
			es.pb(as[i]);
		}
	}

	sort(all(as));
	sort(all(es));
	uniq(as);
	uniq(es);
	reverse(all(es));

	ll ans = 0;

	repr((int)as.size(), i)
	{
		if (mp[as[i]] >= 4)
		{
			ans = max(ans, as[i]*as[i]);
		}
	}

	if ((int)es.size() >= 2)
	{
		ans = max(ans, es[0]*es[1]);
	}

	cout << ans << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	double a,b;
	cin >> a >> b;
	cout << ceil((a+b)/2) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        int k,p;
        cin >> k >> p;
        if(k%p == 0){
            cout << p << endl;
        }else{
            cout << k%p << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1e9+7;
int main(){
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 0; i < n; ++i){
        int a;
        scanf("%d",&a);
        sum ^= a;
        sum &= 1;
    }
    if(n == 0 || sum == 0)
        puts("YES");
    else
        puts("NO");
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Echizen
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a, b;
            a = in.nextInt();
            b = in.nextInt();
            a = a + b;
            if (a >= 10) {
                out.println("error");
            } else {
                out.println(a);
            }
        }

    }
}



Measured memory_bytes: 21844
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

ll n, k;
constexpr ll mod = 1e9 + 7;
ll count(ll k) {
	ll a = k * (k - 1) / 2;
	ll b = k * (n + n - k + 1) / 2;
	return (b - a + 1) % mod;
}
int main() {
	scanf("%lld %lld", &n, &k);
	ll sum = 0;
	for (int i = k; i <= n + 1; i++)
		sum = (sum + count(i)) % mod;
	printf("%lld\n", sum);
}

Measured memory_bytes: 1732
#include <iostream>

using namespace std;

const int MAX_N = 1e5 + 5;

int arr [MAX_N];

int main () {
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (arr[arr[i]] == i) ans++;
  }
  ans /= 2;

  cout << ans << endl;
}


Measured memory_bytes: 4084
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

string change(string str);

int main(void)
{
	int n;
	string str;
	
	while (cin >> n, n){
		cin >> str;
		for (int i = 0; i < n; i++){
			str = change(str);
		}
		cout << str << endl;
	}
	
	return (0);
}

string change(string str)
{
	int len = str.size();
	string b = "";
	
	for (int i = 0; i < len; i++){
		int num = 0;
		char now = str[i];
		for (; i < len; i++){
			if (now == str[i]) {
				num++;
			}
			else {
				i--;
				break;
			}
		}
		char a[50];
		sprintf(a, "%d", num);
		b += a;
		b += now;
	}
	
	return b;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
//long long int sum=0,n,m,num,de;
//long long int b[1000005];
//int getMax(long long int *arr,int n){
//	long long int num=arr[0];
//	int a;
//	for(int i=0;i<n;i++){
//		if(arr[i]>num){
//			num=arr[i];
//			a=i;
//		}
//	}
//	return a;
//}

int main(){
//	cin>>n>>m;
//	
//	for(int i=0;i<n;i++){
//		cin>>de;
//		b[i]=de;
//	}
//	for(int i=0;i<m;i++){
//		b[getMax(b,n)]/=2;
//	}
//	for(int i=0;i<n;i++){
//		if(b[i]>0){
//			sum+=b[i];
//		}
//	}

	priority_queue<int> q ;
	int m,n,t;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>t;
		q.push(t);
	}
	long long sum=0;
	while(m){
		t=q.top()/2;
		q.pop();
		q.push(t);
		m--;
	}
	while(!q.empty()){
		sum+=q.top();
		q.pop();
	}
	printf("%lld",sum);
	return 0;
}


Measured memory_bytes: 892
h,w = map(int,input().split())
C = [list(input()) for i in range(h)]

queue = []
visited = [[0 for i in range(w)] for i in range(h)] #始点からの距離を格納、未踏なら0
ans = 0

for i in range(h): #始点(i,j)を全探索して最長経路を調べる
    for j in range(w):
        if C[i][j] == '.':
            queue.append([i,j])
            visited[i][j] = 1

            dy_dx = [[1,0],[0,1],[-1,0],[0,-1]] #[y][x]の順番に注意

            while len(queue) > 0:
                now = queue.pop(0)
                for k in range(4):
                    y = now[0]+dy_dx[k][0]
                    x = now[1]+dy_dx[k][1]
                    if 0 <= y < h and 0 <= x < w:
                        if C[y][x] == '.' and visited[y][x] == 0:
                            visited[y][x] = visited[now[0]][now[1]]+1 #移動回数のカウント
                            queue.append([y,x])
                    
        for l in range(h):
            for m in range(w):
                ans = max(ans,visited[l][m])
            
        queue = []
        visited = [[0 for i in range(w)] for i in range(h)]              
        
print(ans-1)

Measured memory_bytes: 3188
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
const int MaxN = 1e5 + 5;
int ans[MaxN];
struct NOOD{
	int x,y;
}pos[MaxN];
int main(){
	int n,m,d;
	scanf("%d%d%d",&n,&m,&d);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++){
			int a;
			scanf("%d",&a);
			pos[a].x = i;
			pos[a].y = j;
		}	
		for(int i = d+1; i <= m*n; i++){
			ans[i] =ans[i-d] + abs(pos[i-d].x-pos[i].x)+abs(pos[i-d].y-pos[i].y);
		}

	int t;
	scanf("%d",&t);
	while(t--){
			//for(int i = 1; i <= n*m; i++){
			//ans[i+d] += ans[i];
		//}
		int a,b;
		scanf("%d%d",&a,&b);
		printf("%d\n",ans[b]-ans[a]);
	}
	return 0;
}


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

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

  int ans = N;
  for (int i = 0; i <= N; i++) {
    int d = 0;
    int m = i;
    while (m > 0) {
      d += m % 6;
      m /= 6;
    }

    m = N - i;
    while (m > 0) {
      d += m % 9;
      m /= 9;
    }

    if (d < ans) ans = d;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 300020
#define MAXN 100000
using namespace std;
int n,m,sz[M],K[M],res,mp[2000000];
int od[M],ans; LL p[M],pri[M],t[M]; bool isp[M];
bool cmp(int x,int y){return t[x]<t[y];}
LL read(){
	LL nm=0,fh=1; char cw=getchar(); for(;!isdigit(cw);cw=getchar());
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
int main(){
	memset(isp,true,sizeof(isp));
	for(int i=2;i<MAXN;i++){
		if(!isp[i]) continue; pri[++m]=i;
		for(int j=(i<<1);j<MAXN;j+=i) isp[j]=false;
	}
	n=read();
	for(int j,i=1;i<=n;i++){
		for(p[i]=read(),K[i]=sz[i]=0,j=t[i]=1;j<=308;j++){
			if(p[i]%pri[j]) continue; int cnt=0;
			while(!(p[i]%pri[j])) p[i]/=pri[j],++cnt; cnt%=3;
			if(cnt) K[i]|=((cnt&1)<<sz[i]),sz[i]++,t[i]*=pri[j];
		}
		if(p[i]>1ll){
			if(p[i]<MAXN) K[i]|=(1<<sz[i]),sz[i]++,t[i]*=p[i];
			else {
				LL qq=sqrt(p[i]);
				if(qq*qq!=p[i]) ans++,i--,n--;
				else sz[i]++,t[i]*=qq;
			}
		}
	}
	for(int i=1;i<=n;i++) od[i]=i; sort(od+1,od+n+1,cmp);
	for(int l=1,r;l<=n;l=r+1){
		for(r=l;r<n&&t[od[r]]==t[od[r+1]];r++);
		if(t[od[l]]==1){ans++;continue;}
		int maxn=(1<<sz[od[l]])-1;
		for(int i=l;i<=r;i++) mp[K[od[i]]]++;
		for(int i=l;i<=r;i++){
			int x=K[od[i]],ot=(maxn^K[od[i]]);
			if(mp[x]>=mp[ot]) ans+=mp[x],mp[x]=mp[ot]=0;
		}
	} printf("%d\n",ans); return 0;
}

Measured memory_bytes: 13568
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

#define int ll
#define iint int

using namespace std;


signed main(void)
{
	//変数の宣言
	int n,m;
	int h,w;
	static int t[110];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	static int vec[100010];
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	static char stemp[100010];
	
	//データの読み込み


	scanf("%lld",&n);
//	scanf_s("%lld",&n);


//	scanf("%s",&s);
//	scanf_s("%s",&s,1000010);


	for(i=0;i<n;i++){
		scanf("%lld",&t[i]);
//		scanf_s("%lld",&t[i]);
	}

/*	//scanf("%c",&dummy);
	scanf_s("%c",&dummy);
	for(i=0;i<n;i++){
//		scanf("%c",&s[i]);
		scanf_s("%c",&s[i]);
	}*/


/*	for(i=0;i<3;i++){
//		scanf("%s",&s);
		scanf_s("%s",&s[i],100010);
	}*/


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();

	ans=1;

	for(i=0;i<n;i++){
		temp=ans;
		temp2=t[i];

		while(temp!=0&&temp2!=0){
			if(temp>temp2){
				temp=temp%temp2;
			}else{
				temp2=temp2%temp;
			}
		}
		ans=(ans/(temp+temp2))*t[i];
	}

	printf("%lld",ans);

//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	
	//printf("%d",(d[i-1][j-1]+1)/2);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {

    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int A;
    if (K >= N) {
        A = X*N;
        cout << A << endl;
    }
    else { 
        A = X*K + Y*(N - K); 
        cout << A << endl;
    }


    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200000+5,inf=0x3f3f3f3f;
int f[N],cyc[N];
int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}
struct node{
	int r,c,val;
	bool friend operator <(node i,node j){
		return i.val>j.val;
	}
}a[N];
signed main(){
	int n,H,W;
	cin>>n>>H>>W;
	for(int i=1;i<=H+W;++i)
		f[i]=i;
	for(int i=1;i<=n;++i)
		cin>>a[i].r>>a[i].c>>a[i].val;
	sort(a+1,a+n+1);int ans=0;
	for(int i=1;i<=n;++i){
		int x=find(a[i].r),y=find(a[i].c+H);
		if(x==y){
			if(cyc[x]) continue;
			cyc[x]=1;
		}
		else{
			if(cyc[x] && cyc[y]) continue;
			f[x]=y; cyc[y]+=cyc[x];
		}
		ans+=a[i].val;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8624
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
	string s;
	cin>>s;

	string st = s;
	reverse(all(st));
	int count = 0;
	forn(i,0,s.sze)
	{
		if(st[i] != s[i])
		{
			count++;
		}
	}
        
    cout<<(count/2);    












    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX = 18;
const int INF = 1<<29;
 
int t[MAX][MAX], n;
int dp[1<<16];
 
int solve(){
    for(int i = 0 ; i < (1<<n) ; i++){
	dp[i] = INF;
    }
 
    dp[0] = 0;
    for(int i = 0 ; i < (1<<n) ; i++){
	for(int j = 0 ; j < n ; j++){
	    if(!(i & (1<<j))){
		dp[i + (1<<j)] = min(dp[i + (1<<j)], t[j][0] + dp[i]);
		for(int k = 0 ; k < n ; k++){
		    if(i & (1<<k)){
			dp[i + (1<<j)] = min(dp[i + (1<<j)],dp[i]+t[j][k+1]);
		    }
		}
	    }
	}
    }
    return dp[(1<<n)-1];
}
 
int main(){
    while(cin >> n ,n){
	memset(t,0,sizeof(t));
	for(int i = 0 ; i < n ; i++){
	    for(int j = 0 ; j <= n ; j++){
		cin >> t[i][j];
	    }
	}    
	cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 3336
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  ll ans = 1;
  for(int i=1; i<=N; i++){
    ans *= i;
    ans %= mod;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main()
{
	int N,T,c,t,a=10000;
	scanf("%d%d",&N,&T);
	while(N--){
		scanf("%d%d",&c,&t);
		if( t<=T && c<a )
			a=c;
	}
	if(a==10000){
		printf("TLE\n");
		return 0;
	}
	printf("%d",a);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
   FAST/**/
   
   ll a,b;
   cin>>a>>b;
   
   ll temp = a-2*b;
   temp = max((ll)0,temp);
   cout<<temp;
   
   
   return 0;
}

Measured memory_bytes: 256
let none x = x
let n = Scanf.bscanf Scanf.Scanning.stdin "%d\n" none

let split_on_char char string = Str.split (Str.regexp char) string

let a_list =
  let str_list =
    Scanf.bscanf Scanf.Scanning.stdin "%[^\n]" (split_on_char " ") in
  List.map int_of_string str_list

let is_even n =
  if n mod 2 = 0
    then true
    else false


let count_half lst =
  let rec hojo lst count =
    if (List.fold_right (&&) (List.map is_even lst) true)
      then (hojo (List.map (fun n -> n/2) lst) count+1)
      else count
  in hojo lst 0

let () = print_int (count_half a_list)

Measured memory_bytes: 768
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);


typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
struct node{
	int y,x,dir;
	ll cost;
	node(int y,int x,int dir,ll cost):y(y),x(x),cost(cost),dir(dir){}
};
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
char dirs[]={'W','N','E','S'};
const ll MAX=LONG_MAX;
int main(){
	int h,w;
	ll l;
	while(cin>>h>>w>>l,h|w|l){
		vs c(h);
		pii start;
		int initdir;
		REP(i,h){
			cin>>c[i];
			REP(j,w){
				switch(c[i][j]){
				case 'W':
					start=make_pair(i,j);
					initdir=0;
					break;
				case 'N':
					start=make_pair(i,j);
					initdir=1;
					break;
				case 'E':
					start=make_pair(i,j);
					initdir=2;
					break;
				case 'S':
					start=make_pair(i,j);
					initdir=3;
					break;
				}
			}
		}
		vvvl cost(h,vvl(w,vl(4,MAX)));
		queue<node> q;
		cost[start.first][start.second][initdir]=l;
		q.push(node(start.first,start.second,initdir,l));
		while(!q.empty()){
			node cnode=q.front();q.pop();
			if(cnode.cost==0){
				cout<<cnode.y+1<<" "<<cnode.x+1<<" "<<dirs[cnode.dir]<<endl;
				break;
			}
			int d=cnode.dir;
			int y=cnode.y+dy[d];
			int x=cnode.x+dx[d];
			while(!(y>=0&&x>=0&&y<h&&x<w&&c[y][x]!='#')){
				d=(d+1)%4;
				y=cnode.y+dy[d];
				x=cnode.x+dx[d];
			}
			if(cost[y][x][d]!=MAX){
				ll diff=cost[y][x][d]-(cnode.cost-1);
				cost[y][x][d]=(cnode.cost-1)%diff;
				q.push(node(y,x,d,(cnode.cost-1)%diff));
			}else{
				cost[y][x][d]=cnode.cost-1;
				q.push(node(y,x,d,cnode.cost-1));
			}
		}
	}
}

Measured memory_bytes: 1980
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        
	        int N = sc.nextInt();
	        
	        
	        long ans = 1000-N%1000;
	        if(ans==1000)ans=0;
	        System.out.println(ans);

		 }
	}

Measured memory_bytes: 35796
#include<cstdio>
typedef long long ll;
int n;

int main(void){
	while(~scanf("%d",&n)){
		ll cnt=0;
		for(int i=0;i<=1000;i++){
			for(int j=0;j<=1000;j++){
				if(i+j<=n){
					int d=n-i-j;
					if(d<=1000)cnt+=(ll)(d+1);
					if(d>1000 && d<=2000)cnt+=(ll)(2000-d+1);
				}
			}
		}
		printf("%lld\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

        if(a % 2 == 0) System.out.println(0.5);
        else System.out.println(((float)(a / 2 + 1) / a));

    }

}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int B=315;
const int SZ=318;
// const int B=5;
// const int SZ=20202;

int dat[SZ][B]={};
int sumF[SZ]={}, sumG[SZ]={};
int flg[SZ];

void init(int n, string s)
{
    rep(i,SZ)rep(j,B)
    {
        int idx = i*B+j;
        if(idx<n) dat[i][j] = s[idx]-'0';
    }

    memset(flg,-1,sizeof(flg));

    // sumF
    rep(i,SZ)
    {
        rep(j,B) sumF[i]+=dat[i][j];
    }

    // sumG
    rep(i,SZ)
    {
        rep(j,B-1) sumG[i]+=dat[i][j]*dat[i][j+1];
    }
}

void update(int l, int r, int b)
{
    int lb = l/B, rb = r/B;
    if(lb==rb)
    {
        if(flg[lb]!=-1)
        {
            rep(i,B) dat[lb][i] = flg[lb];
            flg[lb] = -1;
        }

        for(int i=l-lb*B; i<=r-lb*B; ++i) dat[lb][i]=b;

        sumF[lb]=sumG[lb]=0;
        rep(i,B) sumF[lb]+=dat[lb][i];
        rep(i,B-1) sumG[lb]+=dat[lb][i]*dat[lb][i+1];
    }
    else
    {
        if(flg[lb]!=-1)
        {
            rep(i,B) dat[lb][i] = flg[lb];
            flg[lb] = -1;
        }
        for(int i=l-lb*B; i<B; ++i) dat[lb][i]=b;
        sumF[lb]=sumG[lb]=0;
        rep(i,B) sumF[lb]+=dat[lb][i];
        rep(i,B-1) sumG[lb]+=dat[lb][i]*dat[lb][i+1];

        for(int i=lb+1; i<rb; ++i)
        {
            flg[i]=b;
            sumF[i]=B*b;
            sumG[i]=(B-1)*b;
        }

        if(flg[rb]!=-1)
        {
            rep(i,B) dat[rb][i] = flg[rb];
            flg[rb] = -1;
        }
        for(int i=0; i<=r-rb*B; ++i) dat[rb][i]=b;
        sumF[rb]=sumG[rb]=0;
        rep(i,B) sumF[rb]+=dat[rb][i];
        rep(i,B-1) sumG[rb]+=dat[rb][i]*dat[rb][i+1];
    }
}

int F()
{
    int ret=0;
    rep(i,SZ) ret+=sumF[i];
    return ret;
}

int G()
{
    int ret=0;
    rep(i,SZ) ret+=sumG[i];

    rep(i,SZ-1)
    {
        int p=dat[i][B-1];
        if(flg[i]!=-1) p=flg[i];

        int q=dat[i+1][0];
        if(flg[i+1]!=-1) q=flg[i+1];

        ret+=p*q;
    }

    return ret;
}

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

    init(n,s);

    int q;
    scanf(" %d", &q);
    while(q--)
    {
        int l,r,b;
        scanf(" %d %d %d", &l, &r, &b);
        --l;
        --r;
        update(l,r,b);
        printf("%d\n", F()-G());
    }

    return 0;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
 
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<int> c(n), s(n), f(n);
	
	rep(i, n-1) cin >>c[i] >>s[i] >>f[i];
	
	rep(i, n-1){
		int cr =0;
		rep2(j, i, n-1){
			int t = max(0, (cr - s[j] + f[j] -1)/f[j] );

			cr = s[j] + f[j] * t + c[j];
			//dbg(i,j,t, cr);
		}
		cout << cr <<"\n";
	}
	cout << "0\n";
	return 0;
}


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

int n, l;
string ans;

int main() {
  cin >> n >> l;
  vector<string> s(n);
  rep (i, n) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  rep (i, n) {
    ans += s[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int main() {
	int n, p;
	while (cin >> n >> p&&n&&p) {
		int wan = p;
		int maxl = 0;
		int count[50] = {};
		while (maxl != p) {
			for (int i = 0; i < n; i++) {
				maxl = 0;
				if (wan != 0) {
					wan--;
					count[i]++;
				}
				else{
					wan = count[i];
					count[i] = 0;
				}
				for (int j = 0; j < n; j++) {
					maxl = max(maxl,count[j]);
				}
				if (maxl == p)break;
			}
		}
		for (int i = 0; i < n; i++) {
			if (count[i] == p)cout << i << endl;
		}
	}
	
}

Measured memory_bytes: 3044
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
	using namespace std;

	int V[5];
	for (int i = 0; i < 5; i++)
	{
		cin >> V[i];
	}

	int k;
	cin >> k;

	for (int i = 0; i < 5; i++)
	{
		for (int j = i + 1; j < 5; j++)
		{
			if (V[j] - V[i] > k)
			{
				cout << ":(" << endl;
				return 0;
			}
		}
	}

	cout << "Yay!" << endl;
}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int s, t, d;
    cin >> s >> t >> d;
    vector<Int> w(d);
    for (Int i = 0; i < d; i++) {
        cin >> w[i];
    }
    Int sum = accumulate(all(w), (Int)0);
    if (sum >= 0) {
        for (Int i = 0; i < d; i++) {
            s += w[i];
            if (s <= t) {
                print(i + 1);
                return 0;
            }
        }
        print(-1);
        return 0;
    }
    Int mi = 0;
    Int x = 0;
    for (Int i = 0; i < d; i++) {
        x += w[i];
        mi = min(mi, x);
    }
    Int a = max((s - t + mi) / abs(sum), (Int)0);
    if ((s - t + mi) > 0 and (s - t + mi) % abs(sum) != 0) a++;
    Int cur = s + a * sum;
    Int res = a * d;
    for (Int i = 0; i < d; i++) {
        res++;
        cur += w[i];
        if (cur <= t) {
            print(res);
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3628
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, _ := strconv.Atoi(input())
	ans := make([]int, n)
	for i := 0; i < n-1; i++ {
		a, _ := strconv.Atoi(input())
		ans[a-1]++
	}

	for i := 0; i < n; i++ {
		fmt.Println(ans[i])
	}
}


Measured memory_bytes: 6184
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const int MAXN = 1000;

char mat[MAXN + 1][MAXN + 1];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int n, m, a, b, i, j;
    ios::sync_with_stdio(false);
    cin >> n >> m >> a >> b;
    if(2 * (a + b) > n * m) {
        cout << "NO";
        return 0;
    }
    if(n == 1 && b > 0) {
        cout << "NO";
        return 0;
    }
    if(m == 1 && a > 0) {
        cout << "NO";
        return 0;
    }
    memset(mat, '.', sizeof(mat));
    if(n == 1) {
        for(i = 1; i <= 2 * a; i += 2) {
            mat[1][i] = '<';
            mat[1][i + 1] = '>';
        }
    }
    if(m == 1) {
        for(i = 1; i <= 2 * b; i += 2) {
            mat[i][1] = '^';
            mat[i + 1][1] = 'v';
        }
    }
    if(n > 1 && m > 1) {
        int l = 1;
        if(n % 2 == 1) {
            for(i = 1; i + 1 <= m && a > 0; i += 2) {
                mat[1][i] = '<';
                mat[1][i + 1] = '>';
                a--;
            }
            l = 2;
        }
        while(l <= n && a > 0) {
            for(i = 1; i + 1 <= m && a > 0; i += 2) {
                if(a > 1 || m % 2 == 0) {
                    mat[l][i] = '<';
                    mat[l][i + 1] = '>';
                    a--;
                    if(a > 0) {
                        mat[l + 1][i] = '<';
                        mat[l + 1][i + 1] = '>';
                        a--;
                    }
                }
                else {
                    mat[n][m - 1] = '<';
                    mat[n][m] = '>';
                    a--;
                }
            }
            l += 2;
        }
        for(i = 1; i < n && b > 0; i++) {
            for(j = 1; j <= m && b > 0; j++) {
                if(mat[i][j] == '.' && mat[i + 1][j] == '.') {
                    mat[i][j] = '^';
                    mat[i + 1][j] = 'v';
                    b--;
                }
            }
        }
        if(a > 0 || b > 0) {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES" << "\n";
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= m; j++) {
            cout << mat[i][j];
        }
        cout << "\n";
    }
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 2176