akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 998244353
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

ll h,w;
char s[55][55];
bool visit[55][55];
ll dy[4] = {1,0,-1,0};
ll dx[4] = {0,1,0,-1};

bool in(ll y, ll x){
    return 0<=y && y<h && 0<=x && x<w;
}

int main(){
    while(1){
        cin >> w >> h;
        if(h==0 && w==0) break;
        rep(i,h){
            rep(j,w) cin >> s[i][j];
        }
        P ans = P(0,0);
        rep(i,h){
            rep(j,w){
                rep(k,h) rep(l,w) visit[k][l] = false;
                if(s[i][j] != '.') continue;
                bool W = false;
                bool B = false;
                queue<P> q;
                q.push(P(i,j));
                visit[i][j] = true;
                while(!q.empty()){
                    P p = q.front(); q.pop();
                    ll y = p.first;
                    ll x = p.second;
                    rep(i,4){
                        ll ny = y + dy[i];
                        ll nx = x + dx[i];
                        if(in(ny,nx)){
                            if(visit[ny][nx]) continue;
                            visit[ny][nx] = true;
                            if(s[ny][nx]=='W') W = true;
                            else if(s[ny][nx]=='B') B = true;
                            else q.push(P(ny,nx));
                        }
                    }
                }
                if(W == B) continue;
                else{
                    if(B) ans.first++;
                    else ans.second++;
                }
            }
        }
        cout << ans.first << " " << ans.second << endl;
    }
}



Measured memory_bytes: 3124
public class Main {
	 public static void main(String[] args) {
		    java.util.Scanner scanner = new java.util.Scanner(System.in);
		    int n = scanner.nextInt();
		    int ninzu = 0;
		    for (int i = 0; i < n; i++) {
		    	int l = scanner.nextInt();
		    	int r = scanner.nextInt();
		    	ninzu = ninzu + (r - l) + 1;
		    }
		    	System.out.println(ninzu);
		 }
}

Measured memory_bytes: 25808
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int n;
	cin>>n;
	ll a = 1, b = 2;
	while(--n){
		ll c = a+b;
		b = a;
		a = c;
	}
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 256
def prime(x):
    isprime = [True]*(x+1)
    isprime[0] = False
    isprime[1] = False
    for i in range(2,int(x**0.5)+1):
        if not isprime[i]:
            continue
        for j in range(i**2,x+1,i):
            isprime[j] = False
    return [i for i in range(x+1) if isprime[i]]

x = int(input())
lst = prime(10**6)
lst2 = [lst[i] for i in range(len(lst)) if lst[i] >= x ]
print(min(lst2))

Measured memory_bytes: 20276
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  ll ans = 0;
  for (int i = 1; i < N - 1; i++) {
    if ((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
        (p[i + 1] < p[i] && p[i] < p[i - 1]))
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
    string s;
    cin>>s;
    f(i,3)
        cout<<s[i];
    return 0;
}

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

using namespace std; 

#define endl "\n"

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
   
   long long int n,i,ans1=1,ans2=2,ans3=1,m=1000000007;
   cin>>n;
   for(i=0;i<n;++i)
   {
       ans1*=10,ans1%=m,ans2*=9,ans2%=m,ans3*=8,ans3%=m;
   }
   ans1-=ans2-ans3;
 
   cout<<(m+ans1)%m;
   
  
     return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 5005
#define M 205
#define ll long long
int A[N], B[N][M], n, m;
int st[M][N][15], mlg[N];
ll S[N], ans[N];
void Read(int &p)
{
	p = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
}
int Getmax(int k, int l, int r)
{
	int t = mlg[r - l + 1];
	return max(st[k][l][t], st[k][r - (1 << t) + 1][t]);
}
void Divide(int l, int r, int L, int R)
{
	if (l > r)
		return;
	int mid = (l + r) >> 1, plc = 0;
	for (int i = L; i <= mid && i <= R; i++)
	{
		ll sum = -(S[mid] - S[i]);
		for (int j = 1; j <= m; j++)
			sum += Getmax(j, i, mid);
		if (sum > ans[mid])
			ans[mid] = sum, plc = i;
	}
	Divide(l, mid - 1, L, plc);
	Divide(mid + 1, r, plc, R);
}
int main()
{
	Read(n), Read(m);
	for (int i = 2; i <= n; i++)
	{
		Read(A[i]);
		S[i] = S[i - 1] + A[i];
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			Read(B[i][j]);
	for (int i = 2; i <= n; i++)
		mlg[i] = mlg[i >> 1] + 1;
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
			st[i][j][0] = B[j][i];
		for (int k = 1; k <= 13; k++)
		{
			int l = 1 << k;
			for (int j = 1; j + l <= n + 1; j++)
				st[i][j][k] = max(st[i][j][k - 1], st[i][j + l / 2][k - 1]);
		}
	}
	Divide(1, n, 1, n);
	ll ret = 0;
	for (int i = 1; i <= n; i++)
		ret = max(ret, ans[i]);
	printf("%lld\n", ret);
}


Measured memory_bytes: 64256
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
bool kwissq(long num) { long rt = sqrt(num); return(rt * rt == num); }//平方数判定


int main() {

	long res;
	long A, B; cin >> A >> B;
	long N; N = gcd(A, B);
	bool isprime[1000009];
	for (int i = 1; i < 1000005; i++) isprime[i] = true;

	long prima = INT_MIN;
	for (int i = 2; i < 1000005; i++) {
		if (isprime[i]) {
			prima = i;
			for (int j = 2; j * i < 1000005; j++) isprime[i * j] = false;
			if (N % i == 0) res++;
			if (i != 1) while (N % i == 0) N /= i;
		}
	}

	res++;
    if (N > prima) res++;
	cout << res << endl;
}

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

int main(){
  int i,j;
  char s[201];
  char tmp1[101],tmp2[101];
  
  scanf("%s",s);
  for(i=strlen(s)-1;i>=0;i--){
    if(i%2==0){
      for(j=0;j<i/2;j++){
        tmp1[j]=s[j];
        tmp2[j]=s[j+i/2];
      }
      tmp1[j]=tmp2[j]='\0';
      if(strcmp(tmp1,tmp2)==0){
        break;
      }
    }
  }
  printf("%d",i);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <queue>

using namespace std;

bool comp(int n1, int n2){
	return n1>n2;
}

int main () {
	int N;
	cin >> N;
	vector<int> list;
	int n1, n2;
	cin >> n1 >> n2;
	list.push_back(n1);
	list.push_back(n2);
	if (n1 > n2) swap(n1, n2);
	priority_queue<int> small;
	priority_queue<int> big;
	

	int left = 0, right = 0;
	for (int i = 2; i < N; i++){
		int A;
		cin >> A;
		list.push_back(A);
		if (A < n1){
			left ++;
			small.push(A);
		}
		else if (A > n2) {
			right ++;
			big.push(-1*A);
		}
		else {			
			small.push(n1);
			n1 = A;
			left ++;
		}
		if(abs(left-right)>=2){
			if (left>right) {
				left--;right++;
				big.push(-1*n2);
				n2=n1;
				n1=small.top();
				small.pop();
			}
			else{
				left++;right--;
				small.push(n1);
				n1=n2;
				n2=-1*big.top();
				big.pop();			
			}		
		}		
	}
	for(int i = 0; i < N; i++){
		if(list[i]<=n1) cout << n2 << endl;
		else cout << n1 << endl;	
	}

	return 0;
}

Measured memory_bytes: 4596
from collections import Counter

N = int(input())
D = Counter(list(map(int, input().split())))
M = int(input())
T = Counter(list(map(int, input().split())))

# print('D, T', D, T)

for key, value in T.items():
    if D.get(key) is None:
        print('NO')
        exit()
    if D.get(key) < value:
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 55264
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,ans;cin >> n;
  ans=0;
  for (int i=0;i<n;i++) {
    int a,b;cin >> a >> b;
	if (a==b) {ans++;}
	else if (ans<3) {ans=0;}
  }
  if (ans>2) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <stdlib.h>

using namespace std;

int main()
{
    long long int N;
    long long int ninzu[5],tmp[5] = {0};
 
    cin >> N;
    for(int i=0; i<5; i++){
        cin >> ninzu[i];
    }
 
    long long int min = 10000000000000010;
    int ju=10;
 
    for(int i=0; i<5; i++){
        if(ninzu[i] < min){
            min = ninzu[i];
            ju = i;
        }
    }
    
    long long int tmpn;
    if(N%min==0) tmpn = N/min;
    else tmpn = N/min + 1;
    cout << tmpn + 4 << endl;
 
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
using namespace std;

int main(){
    unsigned long long x, y;
    cin >> x >> y;
    int cnt = 0;
    while(true){
        x *= 2;
        if(x > y){break;}
        cnt++;
    }
    cout << cnt + 1 << endl;
}

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

void solver() {
  int n;
  cin >> n;

  string ans = "APPROVED";
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;

    if (a % 2 == 0) {
      if (a % 3 == 0 || a % 5 == 0) continue;
      else ans = "DENIED";
    }
  }

  cout << ans << "\n";
}

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


Measured memory_bytes: 256
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    N, M, Q = map(int, input().split())
    a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
    for i in range(Q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
        a[i] -= 1
        b[i] -= 1

    ans = 0

    def dfs(seq):
        nonlocal ans
        if len(seq) == N:
            score = 0
            for i in range(Q):
                if seq[b[i]] - seq[a[i]] == c[i]:
                    score += d[i]
            ans = max(ans, score)
            return

        score = 0
        for n in range(seq[-1], M + 1):
            seq.append(n)
            dfs(seq)
            seq.pop()

    dfs([1])
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;

    int sum = a1 + a2 + a3;
    if (sum >= 22) cout << "bust" << endl;
    else if (sum <= 21) cout << "win" << endl;

    return 0;
}

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

using namespace std;

int main() {
	int n; cin >> n;
	vector<string> s(n);
	map<string, int> mp;
	int maxi = 0;
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
		++mp[s[i]];
		maxi = max(maxi, mp[s[i]]);
	}
	vector<string> ans;
	for (auto it = mp.begin(); it != mp.end(); ++it)
		if (it->second == maxi) ans.push_back(it->first);
	sort(ans.begin(), ans.end());
	for (auto a : ans) cout << a << endl;

	return 0;
}

Measured memory_bytes: 28784
#include<stdio.h>
int main()
{
	int a,b;
	while(scanf("%d%d",&a,&b)!=EOF&&a&&b)
	{
		int i,j;
		for( i=0;i<a;i++)
		{
			for(j=0;j<b;j++)
			{
				printf("#");
			}
			printf("\n");
		}
		
			printf("\n");
	}
	return 0;
 } 

Measured memory_bytes: 1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramC
    {
        static void Main()
        {
            int n = NextInt, m = NextInt, x = NextInt;
            long min = int.MaxValue;
            var matrix = TakeLine(n).ToArray();

            for (int i = 1; i < (1 << n); i++)
            {
                var array = Enumerable.Repeat(0L, m + 1).ToArray();
                foreach (var list in Enumerable.Range(0, n).Where(j => ((1 << j) & i) > 0).Select(j => matrix[j]))
                {
                    for (int j = 0; j < m + 1; j++)
                    {
                        array[j] += list[j];
                    }
                }

                if (array.Skip(1).All(y => y >= x))
                {
                    min = Math.Min(min, array.First());
                }
            }

            if (min == int.MaxValue) System.Console.WriteLine(-1);
            else System.Console.WriteLine(min);
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 29968
#include<iostream>
#include<iomanip>
#include<set>
#include<vector>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>

using namespace std;

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;


int main(void)
{
  int n;
	int h[22];
	int ans = 1;
	bool p = false;

  cin >> n;
	rep(i,n) cin >> h[i];
	for(int i = n-1;i>0;i--){
		rep(j,i){
			if(h[i]<h[j]){
				p = false;
				break;
			}else{
				p = true;
			}
		}
		if(p) ans++;
	}

	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,K,Q;
cin>>N>>K>>Q;
vector<int>data(Q);
vector<int>point(N);
for(int i=0; i<N; i++){
point.at(i)=K-Q;
}
for(int i=0; i<Q; i++){
cin>>data.at(i);
}
for(int i=0; i<Q; i++){
point.at(data.at(i)-1)++;
}
for(int i=0;i<N; i++){
if(point.at(i)<1){
cout<<"No"<<endl;
}
else
cout<<"Yes"<<endl;
}
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
	int t=1;
	//cin>>t;
	ll a[3];
	while(t--){
	cin>>a[0]>>a[1]>>a[2];
	for(int i=0;i<3;i++) if(a[i]%2==0) return cout<<"0"<<endl, 0;
		sort(a,a+3);
		cout<<a[0]*a[1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
using namespace std;

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

int main() {
  int n;
  scanf("%i", &n);
  map<string, int> msi;
  FOR(i,n) {
    char buf[32];
    scanf("%s", buf);
    msi[buf]++;
  }
  int best = -1;
  for (auto &p : msi) best = max(best, p.second);
  for (auto &p : msi) if (p.second == best) printf("%s\n", p.first.c_str());
}


Measured memory_bytes: 23808
/*      Abhijith    */
#include<bits/stdc++.h>
#include<iomanip>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
using namespace std;

int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     string s;
     cin>>s;
     lld n=s.size();
     lld ans=0;
     rep(i,0,n-1)
     {
         lld temp=0;
         rep(j,i,n-1)
         {
            if(s[j]=='A'||s[j]=='G'||s[j]=='C'||s[j]=='T')
            {
                temp++;
            }
            else
            {
                ans=max(ans,temp);
                break;
            }
            if(j==n-1)
            {
                ans=max(ans,temp);
            }
         }
     }
     cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	int w, a, b;
	cin >> w >> a >> b;
	if ((b > (a + w) && (b + w) > a) || (b < a && (b + w) < (a + w)))
		cout << min(abs((a + w) - b), abs((w + b) - a));
	else
		cout << "0";
}

Measured memory_bytes: 3560
#include<cstdio>
#include<iostream>
#include<queue>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<cstdlib>
#include<stack>
#include<ctime>
#include<map>
#include<list>
#include<cctype>
using namespace std;

int a[200005];

int main()
{
	int n;
	long long ans=0;
	scanf("%d\n",&n);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	for(int i=1; i<=n; i++)
	{
		if(a[i]<a[i-1])
		{
			ans+=(long long)(a[i-1]-a[i]);
			a[i]=a[i-1];
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4484
let () =
  Scanf.scanf "%d %d" @@ fun n k ->
  let a = Array.init (n+1) (fun i -> if i = 0 then 1 else Scanf.scanf " %d" Fun.id) in

  let lv = Array.make (n+1) (-1) in
  let rec loop c i =
    if c = k then i
    else if lv.(i) >= 0 then
      let c' = lv.(i) in
      if (k - c) mod (c - c') = 0 then i
      else loop (c+1) a.(i)
    else begin
      lv.(i) <- c;
      loop (c+1) a.(i)
    end in

  Printf.printf "%d\n" (loop 0 1)

Measured memory_bytes: 9176
n, k = map(int,input().split())
li = list(map(int,input().split()))

for i in range(k):
    now = [0]*n

    for j in range(n):
        x = li[j]
        now[max(0,j-x)] += 1
        if j+x+1 < n:
            now[j+x+1] -= 1
    
    for j in range(n-1):
        now[j+1] += now[j]

    li = now
    if min(li) >= n:
        break

print(*li)


Measured memory_bytes: 151316
/*　　　　　　　{:i:i:|i:i:/l/l--　 　 　--l/li:i:i|i:i:i:i}
　　　　　　 　 {:rx|:i:i ィi芥ミ 　 　 .ィi芥ミｉ:ｉ|ﾍ:i:i:}
.　　　 　 　 　 ｛ﾏ|ｉ:  {::’:} 　 　 　{:‘::} :ｉ:i:|〉｝:/
　　 　 　 　 　 乂|:i:| ｀¨¨¨¨´ 　 　　｀¨¨¨´  :i:ｉ:|ｼ/
　 　 　 　 　 　 ﾉ:|:i|　　　　　　′　　　 　   |:i:i:|ﾂ
　　　　　　　　/:/|:i:| ､　　　 　_ _ 　　　　  |:i:i:|
　 　 　　 　 /:/ .|:i:|/ ＼　　　 　 　     ｨ〔|:i:/
　　 　 　  　 〈;/ く刈＿ 个 　   -   　＜}　./|/_〉
　　     　　 r-っ'~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ|___
　　 　     /／ニつ　　　　　　 ､　　　　　　　ノﾆﾆ　＼
.　　　     |　　ニ⊃ 　./　/　 ──   /　/　　..⊆ﾆﾆ　　:|
.　　　     |　　丁´　 /|￣|￣  ─‐ /|￣|￣ 　 .￣|丁 　|
.　　　     |　　ﾉ.  　 |￣|￣  ─‐  |￣|￣ 　 　.|八 　|
.　　　     |　　||. 　 |￣|￣ |￣| |￣|￣ 　   .|　|
.　 　 　   |  　||   　￣￣￣　￣ 　￣￣￣　　  .|　|  |
.　 　 　  　    ||＿＿＿＿＿＿＿＿＿＿＿＿______|__　　 ',
　 　      ,′　 | ７ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ}  ,′
.　　     {　　　|/　}ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ{/ 　 　
*///讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐。
#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

using namespace std;

#define rep(a) _rep(0,int(a))
#define _rep(a,b) for(int i=int(a);i<int(b);i++)
#define ll long long
#define fst first
#define snd second
#define pf(b) printf("%.12f\n",(double)b)
#define _GLIBCXX_DEBUG
#define int long long

//factorial(練習)　階乗
int fact(int n) {
	int a = 1;
	for (int i = 1;i <= n;i++) a *= i;
	return a;
}
int sa(int n, int m) {      //差！
	if (n < m)return m - n;
	else return n - m;
}

char r,t[12];
string s;
signed main() {
	cin >> s ;
	int a = s.size();
	for (int i = 0;i < a;i++) {
		cin >> t[i];
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}cout << "Yes" << endl;
}

Measured memory_bytes: 3628
from collections import defaultdict

N = int(input())
d = defaultdict(int)
for i in range(N):
  d[input().rstrip()] += 1

d2 = sorted(d.items(), key=lambda x: -x[1])
d3 = sorted(map(lambda x: x[0], filter(lambda x: x[1] == d2[0][1], d2)))

for s in d3:
  print(s)


Measured memory_bytes: 46076
#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 <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

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

    int a = S.size();

    string T;

    int b,c;

    int m = 999;

    for (int i = 0; i < a - 2; ++i) {
        T = S.substr(i, 3);
        b = stoi(T);
        c = abs(753 - b);
        m = min(m, c);
    }

    cout << m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;	ci(n);
  vll A(n);
  FOR(i,0,n) ci(A[i])
  SORT(A);
  ll l=A[0];
  ll r=A[n-1];
  FOR(i,1,n-1){
    if(A[i]<0) r-=A[i];
    else l-=A[i];
  }
  co(r-l)
    
   FOR(i,1,n-1){
    if(A[i]<0){
      co(A[n-1]<<" "<<A[i])
      A[n-1]-=A[i];
    }
    else{
      co(A[0]<<" "<<A[i])
      A[0]-=A[i];
    }
  }
  co(A[n-1]<<" "<<A[0])
}

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

int main(){
	int n;
	cin >> n;
	double dp[3000][3000];
	double p[3000];
	//for(int i = 0; i <= n; i++) dp[0][i] = 1;
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++) cin >> p[i];
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= i; j++){
			if(j > 0)dp[i][j] = dp[i - 1][j] * (1.0 - p[i]) + dp[i - 1][j - 1] * p[i];
			else dp[i][j] = dp[i - 1][j] * (1.0 - p[i]);
			//cout << dp[i][j] << endl;
		}
	}
	double ans = 0;
	for(int i = (n + 2)/2; i <= n; i++){
		ans += dp[n][i];
	}
	cout << std::fixed;
    cout << std::setprecision(10);
	cout << ans << '\n';
}

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

int main()
{
   int n, W;
   cin >> n >> W;
   vector<int> w(n);
   vector<ll> v(n);
   rep(i,n) cin >> w[i] >> v[i];
   //dp[i][j] i番目までで、価値jを選ぶ場合の最小の重さ
   vvl dp(n+1, vector<ll>(100001, INF));
   rep(i,n+1) dp[i][0] = 0;
   for(int i = 0; i < n; i++)
   {
      for(int j = 0; j <= 100000 ; j++)
      {
         if(j - v[i] >= 0) dp[i+1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
         else dp[i+1][j] = dp[i][j];
      }
   }
   int ans = 0;
   rep(i,100001) if(dp[n][i] <= W) ans = max(ans, i);
   cout << ans << endl;
}


Measured memory_bytes: 81520
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int prime[N], cnt;
bool st[N];
void init() {
    st[0] = st[1] = true;
    for(int i = 2; i < N; i++) {
        if(!st[i])  prime[cnt++] = i;
        for(int j = 0; j < cnt && i * prime[j] < N; j++) {
            st[i * prime[j]] = true;
            if(i % prime[j] == 0)   break;
        }
    }
}
int main() {
    init();
    // for(int i = 0; i < 10; i++)
    //     printf("%d ", st[i]);
    // puts("");
    int n, sum;
    while(cin >> n) {
        sum = 0;
        for(int i = 2; i <= n; i++)
            if(!st[i])
                sum++;
        printf("%d\n", sum);
    }
    return 0;
}


Measured memory_bytes: 4492
#include <string.h>

#include <algorithm>
#include <iostream>

#define rep1(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main(void) {
  int N;
  cin >> N;
  int A[N];
  rep1(i, N) cin >> A[i];
  ll B[N];  //累積和
  B[0] = A[0];
  rep2(i, 1, N) B[i] = B[i - 1] + A[i];

  ll ans = 0;
  ll sum;

  rep1(i, N - 1) {
    sum = (B[N - 1] - B[i]) % MOD;
    ans += (ll)A[i] * sum;
    ans %= MOD;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5936
#include<iostream>
#include<algorithm>
#define N 3001
using namespace std;
int r,c,n,i,j,d[N][N],a,b,x;
long long e[N][N][4];
bool v[N][N][4];
long long w(int x,int y,int k){
    if(x>r||y>c)return 0;
    if(x==r&&y==c)return k<3?d[x][y]:0;
    if(v[x][y][k])return e[x][y][k];
    v[x][y][k]=1;
    e[x][y][k]=max(w(x+1,y,0)+d[x][y],w(x,y+1,k));
    if(k<2){
        e[x][y][k]=max(e[x][y][k],w(x,y+1,k+1)+d[x][y]);
    }
    return e[x][y][k];
}
int main(){
    cin>>r>>c>>n;
    while(n--){
        cin>>a>>b>>x;
        d[a][b]=x;
    }
    cout<<w(1,1,0);
}


Measured memory_bytes: 355680
#include <iostream>
#include <bits/stdc++.h>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define INF 1000000000
#define MOD 1000000007
#define M 998244353
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define endl "\n"
#define fori(i, a, b) for(i=a; i<b; i++)
#define ford(i, a, b) for(i=a; i>b; i--)
using namespace std;
const ll N = 500043;
ll fact[N];
ll add(ll x, ll y)
{
	x += y;
	while(x >= MOD) x -= MOD;
	while(x < 0) x += MOD;
	return x;
}
ll mul(ll x, ll y)
{
	return (x * 1ll * y) % MOD;
}
ll mulmod(ll a, ll b)
{
    ll res = 0;
    a = a % MOD;
    while (b>0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
        a = (a * 2) % MOD;
        b /= 2;
    }
    return res % MOD; 
}
ll binpow(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}
ll inv(ll x)
{
	return binpow(x, MOD - 2);
}
ll divide(ll x, ll y)
{
	return mul(x, inv(y));
}
void precalc()
{
	fact[0] = 1;
	ll i;
	fori(i, 1, N)
		fact[i] = mul(i, fact[i - 1]);
}
ll C(ll n, ll k)
{
	if(k > n)
	    return 0;
	return divide(fact[n], mul(fact[n - k], fact[k]));
}

int printNonDivisible(int A[], int B[], int n, 
                                         int m) 
{ 
    int count = 0;
    int maxB = 0; 
    for (int i = 0; i < m; i++) 
        if (B[i] > maxB) 
            maxB = B[i]; 
  
    // Initialize all multiples as marked 
    int mark[maxB]; 
    memset(mark, 0, sizeof(mark)); 
  
    // Marking the multiples of all the 
    // elements of the array. 
    for (int i = 0; i < n; i++) 
        for (int x = A[i]; x <= maxB; x += A[i]) 
            mark[x]++; 
  
    // Print not marked elements 
    for (int i = 0; i < m; i++) 
        if (! mark[B[i]]) 
            count++;
    
    return count;
} 

int pre[1000005];
    bool flag[1000005];

int solve()
{
    
    int n, mx=-1;
    cin >> n;
    vector<int> a(n+1);
    a[0] = 0;
    int i;
    fori(i, 1, n+1)
    {
        cin >> a[i];
        pre[a[i]]++;
        if(mx<a[i])
            mx = a[i];
    }
    int j;
    fori(i, 1, n+1)
    {
        if(flag[a[i]] == 1)
            continue;
        for(j=a[i]*2; j<=mx; j+=a[i])
            flag[j] = 1;
    }
    int count = 0;
    fori(i, 1, n+1)
        if(flag[a[i]]==0 && pre[a[i]]==1)
            count++;
    return count;
}

int main()
{
    io
    int t;
    t=1;
    // cin >> t;
    while(t--)
        cout << solve() << endl;
        // solve();
    return 0;
}

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

string lcs(string a, string b) {
  int n = a.size(), m = b.size();
  vector<vector<int>> X(3001, vector<int>(3001));
  vector<vector<int>> Y(3001, vector<int>(3001));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a.at(i) == b.at(j)) {
        X.at(i + 1).at(j + 1) = X.at(i).at(j) + 1;
        Y.at(i + 1).at(j + 1) = 0;
      } else if (X.at(i + 1).at(j) < X.at(i).at(j + 1)) {
        X.at(i + 1).at(j + 1) = X.at(i).at(j + 1);
        Y.at(i + 1).at(j + 1) = 1;
      } else {
        X.at(i + 1).at(j + 1) = X.at(i + 1).at(j);
        Y.at(i + 1).at(j + 1) = -1;
      }
    }
  }
  string c;
  for (int i = n, j = m; i > 0 && j > 0;) {
    if (Y.at(i).at(j) > 0) {
      i--;
    } else if (Y.at(i).at(j) < 0) {
      j--;
    } else {
      c.push_back(a.at(i - 1));
      i--;
      j--;
    }
  }
  reverse(c.begin(), c.end());
  return c;
}

int main() {
  string S, T;
  cin >> S >> T;
  cout << lcs(S, T) << "\n";
}

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

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n; cin >> n;
    vi d(n); rep(i,n) cin >> d[i];
    sort(all(d));
    int itr1 = (SIZE(d))/2;
    int itr2 = itr1 - 1;
    int answer = d[itr1] - d[itr2];
    cout << answer << '\n';
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

bool check(string a){
    string b=a;
    reverse(b.begin(),b.end());
    if(a==b) return true;
    return false;
}

int main(){
    char str[101];
    string a,b,c;
    scanf("%s",&str);
    a=str;
    if(check(a)){
        int n1=(a.length()+1)/2-1;//cout<<n1<<endl;
        int n2=(a.length()+3)/2-1;//cout<<n2<<endl;
        b=a.substr(0,n1);//cout<<b<<endl;
        c=a.substr(n2);//cout<<c<<endl;
        if(check(b)&&check(c)){
            cout<<"Yes";return 0;
        }
    }
    cout<<"No";
}


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

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

    vector<int> A(N);
    vector<int> B(N);

    for (int i = 0 ; i < N; i++){
        A[i] = 0;
    }
    for (int i = 0 ; i < N; i++){
        cin >> A[i];
    }
    for (int i = 0 ; i < N; i++){
        B[A[i]-1] = i+1;
    }

    for (int i = 0 ; i < N; i++){
        cout << B[i] << " ";
    }
    cout << endl;

    



	return 0;
}



Measured memory_bytes: 1664
#include<stdio.h>
#define FREE 0
#define NOT_FREE 1
#define N 8
#define putQ 2
typedef struct{
  int row;
  int col;
} Q;
int A[N][N];
int row[N];
int col[N];
int dpos[2*N-1];
int dneg[2*N-1];
int k;
Q q[8];
void queen(int);
void print(void);
int main(){
  int i,j;
 
  scanf("%d",&k);
  for(j=0;j<k;j++){
    scanf("%d%d",&q[j].row,&q[j].col);
  }
  i=0;
  queen(i);
  return 0;
}
void queen(int i){
  int j,l,flag;
if(i==N){
  print();
  return;
 }
for(j=0;j<=N-1;j++){
  if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE) continue;
  row[i]=j;
  col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
  queen(i+1);
  col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
 }
}
void print(){
  int i,j,flag;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
    A[i][j]=0;
    }
    flag=0;
  }
  for(i=0;i<N;i++){
    A[i][row[i]]=putQ;
  }
  for(j=0;j<k;j++){
    if(A[q[j].row][q[j].col]==putQ) flag++;
  }
  if(flag==k){
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(A[i][j]==putQ)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
  }
}
      
    




Measured memory_bytes: 2108
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
long long A[50];
int main(){
  int i;
  int j;
  int fg;
  long long res = 0;
  long long t;
  long long s;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(;;){
    s = 0;
    for(i=(0);i<(N);i++){
      t = A[i] / N;
      s += t;
      A[i] -= t * (N+1);
    }
    if(s==0){
      break;
    }
    res += s;
    for(i=(0);i<(N);i++){
      A[i] += s;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190921-1

// --- original code ---
// int N; ll A[50];
// {
//   int i, j, fg;
//   ll res = 0, t, s;
//   rd(N,A(N));
//   for(;;){
//     s = 0;
//     rep(i,N){
//       t = A[i] / N;
//       s += t;
//       A[i] -= t * (N+1);
//     }
//     if(s==0) break;
//     res += s;
//     rep(i,N) A[i] += s;
//   }
//   wt(res);
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
int main()
{
    ll n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
    }
    a[n+1]=a[1];

    ll t=sum/(n*(n+1)/2);
    if(sum%(n*(n+1)/2))
    {
        cout<<"NO";
        return 0;
    }
    ll p=0;
    for(int i=1;i<=n;i++)
    {

        if(a[i+1]-a[i]>t)
        {
            cout<<"NO"<<'\n';
            return 0;
        }
        if((a[i+1]-a[i]-t)%n)
        {
            cout<<"NO"<<'\n';
            return 0;
        }
        p+=(t-(a[i+1]-a[i]))/n;
        //cout<<p<<'\n';
    }
    if(p!=t)
        {
            cout<<"NO"<<'\n';
            return 0;
        }
    cout<<"YES"<<'\n';
}


Measured memory_bytes: 1024
<?php
fscanf(STDIN, "%d", $n);

$array = [];
for ($i = 0; $i < $n; $i++) {
  fscanf(STDIN, "%d", $array[$i]);
}

$count = 1;
$b = 0;
$bb = 0;
while ($array[$b] !== 2) {
  $count = $count + 1;

  if ($array[$b] === -1) {
    echo -1;
    return;
  }

  $bb = $array[$b] - 1;
  $array[$b] = -1;
  $b = $bb;
}

echo $count;

Measured memory_bytes: 18036
<?php

fscanf(STDIN,"%d %d",$a,$b);

if(($a+$b)%3 == 0) {
    echo 'Possible';

}else if ($a%3 == 0 )
{
    echo 'Possible';   
}else if ($b%3 == 0 )
{
    echo 'Possible';   
}
else{
    echo 'Impossible';
}

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int32_t main(){
	string s;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	for(int i=1;i<=d-b;i++){
		s+='U';
	}
	for(int i=1;i<=c-a;i++){
		s+='R';
	}
	for(int i=1;i<=d-b;i++){
		s+='D';
	}
	for(int i=1;i<=c-a+1;i++){
		s+='L';
	}
	for(int i=1;i<=d-b+1;i++){
		s+='U';
	}
	for(int i=1;i<=c-a+1;i++){
		s+='R';
	}
	s+="DR";
	for(int i=1;i<=d-b+1;i++){
		s+='D';
	}
	for(int i=1;i<=c-a+1;i++){
		s+='L';
	}
	s+='U';
	cout<<s;
}


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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'


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


const int MOD = 1000000007;

//////////////////////////////////////////

int n, m;


void Input() {

    cin >> n >> m;
}

void Solve() {

    int L, R;

    int l_bound = 1;
    int u_bound = INT_MAX;

    for(int i = 0; i < m; i++) {

        cin >> L >> R;
        if(L > l_bound) l_bound = L;
        if(R < u_bound) u_bound = R;
    }

    //cout << l_bound << " " << u_bound << endl;

    if(l_bound <= u_bound) cout << u_bound - l_bound + 1 << endl;
    else cout << 0 << endl;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();
  return 0;

}



Measured memory_bytes: 256
use std::io::{self, Read};
use std::iter::FromIterator;

trait Source {
    fn next_chr(&mut self) -> char;
    fn next_str(&mut self) -> String;
}

#[allow(dead_code)]
fn from_stdin() -> SourceImpl {
    let mut data = String::new();
    io::stdin().read_to_string(&mut data).expect("Input error");
    from_str(&data)
}

fn from_str(s: &str) -> SourceImpl {
    let data = String::from(s);
    let chars = data.chars().collect::<Vec<char>>().into_iter();
    SourceImpl { chars: chars }
}

struct SourceImpl {
    chars: std::vec::IntoIter<char>,
}

impl Source for SourceImpl {
    fn next_chr(&mut self) -> char {
        self.chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .next()
            .expect("eof")
    }

    fn next_str(&mut self) -> String {
        let it = self
            .chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .take_while(|c| !char::is_whitespace(*c));
        let s = String::from_iter(it);
        if s.is_empty() {
            panic!("eof")
        } else {
            s
        }
    }
}

#[allow(unused_macros)]
macro_rules! input {
    ($src:expr; $($elem:tt)*) => {
        input_inner!($src, $($elem)*)
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($src:expr) => {};
    ($src:expr,) => {};
    ($src:expr, $var:ident : mut $ty:tt $($rest:tt)*) => {
        let mut $var = parse!($src, $ty);
        input_inner!($src $($rest)*)
    };
    ($src:expr, $var:ident : $ty:tt $($rest:tt)*) => {
        let $var = parse!($src, $ty);
        input_inner!($src $($rest)*)
    };
}

#[allow(unused_macros)]
macro_rules! parse {
    ($src:expr, ( $($ty:tt),* )) => {
        ( $(parse!($src,$ty)),* )
    };
    ($src:expr, char) => {
        $src.next_chr()
    };
    ($src:expr, [ $ty:tt; $len:expr ]) => {
        (0..$len).map(|_| parse!($src,$ty)).collect::<Vec<_>>()
    };
    ($src:expr, $ty:tt) => {
        parse_str!($src,$ty)
    };
}

#[allow(unused_macros)]
macro_rules! parse_str {
    ($src:expr, chars) => {
        $src.next_str().chars().collect::<Vec<char>>()
    };
    ($src:expr, $ty:ty) => {
        $src.next_str().parse::<$ty>().expect("Parse error")
    };
}

fn xor(a: u64) -> u64 {
    if a % 2 == 0 {
        a ^ (((a - 1) / 2) % 2)
    } else {
        a / 2 % 2
    }
}

fn main() {
    let mut src = from_stdin();
    input! { src; a: u64, b: u64 }

    println!("{}", xor(a - 1) ^ xor(b));
}


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  // L: true, R: false;
  vector<pair<char, int64_t> > rles;
  rles.push_back(make_pair('R',1));
  for(int64_t i = 1;
      i < s.length();
      ++i)
    {
      if(rles.back().first == s[i])
        {
          ++rles.back().second;
        }
      else
        {
          rles.push_back(make_pair(s[i],1));
        }
    }

  vector<int64_t> ans(s.length());
  for(int64_t i = 0;
      i < s.length();
      ++i)
    {
      ans[i] = 0;
    }
  int64_t pos = 0;
  for(int64_t i = 0;
      i < rles.size();
      ++i)
    {
      if(rles[i].first == 'R')
        {
          pos += rles[i].second;
          if(rles[i].second % 2)
            {
              ans[pos - 1] += (rles[i].second/2 + 1);
              ans[pos] += (rles[i].second/2);
            }
          else
            {
              ans[pos - 1] += (rles[i].second/2);
              ans[pos] += (rles[i].second/2);
            }
        }
      else
        {
          if(rles[i].second % 2)
            {
              ans[pos - 1] += (rles[i].second/2);
              ans[pos] += (rles[i].second/2 + 1);
            }
          else
            {
              ans[pos - 1] += (rles[i].second/2);
              ans[pos] += (rles[i].second/2);
            }
          pos += rles[i].second;
        }
    }

  for(int64_t i = 0;
      i < ans.size();
      ++i)
    {
      cout << ans[i] << " ";
    }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3056
from sys import stdin
S = list(map(int, list(stdin.readline().rstrip())))

n = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        if S[i+1]==1: S[i+1]=0
        elif S[i+1]==0: S[i+1]=1
        n += 1
print(n)


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

using namespace std;

char different(char c) {
    return c=='S' ? 'W' : 'S';
}

char neg(char c) {
    return c=='o' ? 'x' : 'o';
}

char gen(char prev, char says) {
    return says=='o' ? prev : different(prev);
}

char normalize(char who, char says) {
    return who=='W' ? neg(says) : says;
}

string gen_str(string ptn, int n, char fst, char snd) {
    string res(n, ' ');
    res[0] = fst;
    res[1] = snd;
    for(int i=2; i<n; i++) {
        res[i] = gen(res[i-2], normalize(res[i-1], ptn[i-1]));
    }
    return res;
}

bool judge(string ptn, string ans, int n) {
    return gen(ans[1], normalize(ans[0], ptn[0])) == ans[n-1] && gen(ans[n-2], normalize(ans[n-1], ptn[n-1])) == ans[0];
}

int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    string r;
    r = gen_str(s, n, 'S', 'S');
    if(judge(s, r, n)) {
        cout << r << endl;
        return 0;
    }
    r = gen_str(s, n, 'S', 'W');
    if(judge(s, r, n)) {
        cout << r << endl;
        return 0;
    }
    r = gen_str(s, n, 'W', 'W');
    if(judge(s, r, n)) {
        cout << r << endl;
        return 0;
    }
    r = gen_str(s, n, 'W', 'S');
    if(judge(s, r, n)) {
        cout << r << endl;
        return 0;
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 816