akhauriyash/Code-Regression huggingface dataset:
n, x, m = gets.split.map(&:to_i)
a = Array.new(m, nil)
flag = Array.new(m, false)
accum = Array.new(m, 0)
prev = 0
j = n
for i in 0...m do
  a[i] = x
  accum[i] = prev + x
  prev = accum[i]
#  puts "#{a[i]} #{accum[i]}"
  flag[x] = true
  y = x ** 2 % m
  if flag[y]
    j = a.index(y)
#    puts "! #{j}"
    break
  end
  x = y
end
pre_len = j
loop_len = i - j + 1
post_len = ((n - j) % loop_len)
ans = accum[j - 1]
ans += (accum[i] - accum[j - 1]) * ((n - j) / loop_len)
ans += (accum[j + post_len - 1] - accum[j - 1])
puts ans


Measured memory_bytes: 16732
n, k = map(int, input().split())
aaa = list(map(lambda x: int(x) - 1, input().split()))
visited = [0] * n
next_town = 0
order = []
while True:
    if visited[next_town]:
        break
    order.append(next_town)
    visited[next_town] = 1
    next_town = aaa[next_town]
first_loop = len(order)
offset = order.index(next_town)
second_loop = first_loop - offset
if k < first_loop:
    print(order[k] + 1)
else:
    print(order[offset + (k - first_loop) % second_loop] + 1)

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



int main(){
	std::string str;
	u_int data_num;
	std::cin >> data_num;
	std::cin.ignore();
	for(u_int i = 0; i < data_num; ++i){
		int loc = 0;
		std::getline(std::cin, str);
		while((loc = str.find("Hoshino", loc)) != -1){
			str[loc+6] = 'a';	
		}
		std::cout << str << std::endl;
	}
	
	return 0;
}
		

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >>N;
  vector<int> M(N);
  for(int i=0;i<N;i++){
    cin >> M[i];
  }
  sort(M.begin(),M.end());
  int sum=M[0];int x=0;
  for(int i=1;i<N+1;i++){
    if(sum==M[i]){
      sum=M[i];
      x++;
    }
    else if(sum<M[i]){
      sum=M[i];
    }
  }
  cout <<N-x<<endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N;
	cin >> N;
	vector<int> x(N), y(N), h(N);
	REP(i, N) cin >> x[i] >> y[i] >> h[i];
	vector<vector<int>> res;
	int id = 0;
	while (h[id] == 0) id++;
	REP(i, 101)REP(j, 101) {
		int H = h[id] + abs(x[id] - i) + abs(y[id] - j);
		if (H >= 1) res.push_back({ i,j,H });
	}
	int n = res.size();
	vector<bool> b(n, true);
	REP(i, N) {
		REP(j, n) {
			if (!b[j]) continue;
			if (h[i] > 0) {
				if (res[j][2] - abs(x[i] - res[j][0]) - abs(y[i] - res[j][1]) != h[i])
					b[j] = false;
			}
			else {
				if (res[j][2] - abs(x[i] - res[j][0]) - abs(y[i] - res[j][1]) > 0)
					b[j] = false;
			}
		}
	}

	REP(j, n)REP(i, 3) {
		if (b[j]) {
			cout << res[j][i];
			if (i == 2) cout << "\n";
			else cout << " ";
		}
	}
	
	return 0;
}

Measured memory_bytes: 896
// ------------------------------------
// Date:2018/ 2/23
// Problem:ABC 045 GameForThree b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;

int main()
{
  string a,b,c;
  char card = 'a';
  char output;
  int aCnt,bCnt,cCnt;
  bool flag = false;
  cin >> a;
  cin >> b;
  cin >> c;
  aCnt = bCnt = cCnt = 0;
  REP(i,a.size()+b.size()+c.size()) {
    switch(card) {
      case 'a':
        card = a[aCnt];
        if (++aCnt == a.size()+1) {
          flag = true;
          output = 'A';
        }
        break;
      case 'b':
        card = b[bCnt];
        if (++bCnt == b.size()+1) {
          flag = true;
          output = 'B';
        }
        break;
      case 'c':
        card = c[cCnt];
        if (++cCnt == c.size()+1) {
          flag = true;
          output = 'C';
        }
        break;
    }
    if (flag) break;
  }
  cout << output << endl;
  return 0;
}



Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val str = io.StdIn.readLine()
    var total_change_char = 0
    (0 until str.length/2).foreach { i =>
      if(str(i) != str(str.length - (1 + i))) total_change_char += 1
    }
    println(total_change_char)
  }
}

Measured memory_bytes: 27320
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(){
    
    int num,a,b,c;
    cin >> num;
    
    for(int ii=0;ii<num;ii++){
        cin >> a >> b >> c;
        
        if(a * a + b * b == c * c){
            cout << "YES" << endl;
        }
        else if(a * a + c * c == b * b){
            cout << "YES" << endl;
        }
        else if(b * b + c * c == a * a){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
char a[1000];
int m,k;
int main()
{
    scanf("%s",a);
    k=strlen(a);
    k-=1;
    if(a[k]=='2'||a[k]=='4'||a[k]=='5'||a[k]=='7'||a[k]=='9')
    {
        cout<<"hon"<<endl;
    }
    else if(a[k]=='0'||a[k]=='1'||a[k]=='6'||a[k]=='8')
    {
        cout<<"pon"<<endl;
    }
    else if(a[k]=='3')
    {
        cout<<"bon"<<endl;
    }
}


Measured memory_bytes: 3684
N = int(input())
arr = list(map(int, input().split()))
target_n = max(arr)
target_m = 0
tmp = float('inf')
for i in range(N):
    if abs((target_n/2)-arr[i]) <= tmp and target_n != arr[i]:
        target_m = arr[i]
        tmp = abs((target_n/2)-arr[i])
print(target_n,target_m)

Measured memory_bytes: 14052
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N,M = map(int,(input().split()))
x = [[] for _ in range(N)]
for i in range(N):
    x[i] = list(map(int,(input().split())))
y = copy.deepcopy(x)

ans = 0
for i in range(2):
    for j in range(2):
        for k in range(2):
            if i == 1:
                for l in range(N):
                    y[l][0] = -x[l][0]
            else:
                for l in range(N):
                    y[l][0] = x[l][0]
            if j == 1:
                for l in range(N):
                    y[l][1] = -x[l][1]
            else:
                for l in range(N):
                    y[l][1] = x[l][1]
            if k == 1:
                for l in range(N):
                    y[l][2] = -x[l][2]
            else:
                for l in range(N):
                    y[l][2] = x[l][2]
            s = [-1]*N
            for l in range(N):
                s[l] = sum(y[l])
            s.sort(reverse=True)
            ans = max(ans,sum(s[:M]))
print(ans)

Measured memory_bytes: 46552
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>

using namespace std;

const int diff = 20;

bool solve() {
    int R, N;
    cin >> R >> N;
    if (R == 0) return false;

    vector<int> H(41, 0);
    for (int i = 0; i < N; ++i) {
        int l, r, h;
        cin >> l >> r >> h;
        l += diff, r += diff;
        for (int x = l; x < r; ++x) {
            H[x] = max(H[x], h);
        }
    }

    double ans = 20;
    for (int x = -R + 1; x < R; ++x) {
        int xi = x + diff;
        int h = min(H[xi - 1], H[xi]);
        ans = min(ans, h - sqrt(R * R - x * x) + R);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return true;
}

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


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



int main() {
    li n;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    set<li> st;
    st.insert(1);
    li now = 2;
    li sum = 1;
    while (sum < n) {
        st.insert(now);
        sum += now;
        ++now;
    }
    if (sum > n) {
        st.erase(sum - n);
    }
    foreach (it, st) {
        cout << *it << endl;
    }

    return 0;
}

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

int main( void )
{
    int a, b, c;
    cin >> a >> b >> c;
    if ( c >= a && c <= b )
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 256
// F - Strings of Eternity
#include <bits/stdc++.h>

using namespace std;

void z_func(const string &p, vector<int> &z)
{
	int n = p.size();
	z.assign(n, 0);
	for (int l = 0, r = 0, i = 1; i < n; i++)
		if (r >= i && z[i - l] < r - i + 1) {
			z[i] = z[i - l];
		} else {
			if (i > r) r = i;
			for (l = i; r < n && p[r - l] == p[r]; ) r++;
			z[i] = r - l;
			r--;
		}
}

int find(const string &s, const string &t)
{
	int m = t.size();
	string r = t + "|" + s;
	vector<int> z;
	z_func(r, z);
	vector<int> dp(z.size() + 1);
	for (int i = m; i < z.size(); i++)
		if (z[i] == m) dp[i + m] = max(dp[i + m], dp[i] + 1);
	return *max_element(dp.begin(), dp.end());
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	string s, t;
	cin >> s >> t;
	string r = s;
	while (r.size() <= s.size() + t.size() * 2) r += s;

	int ans = find(r, t);
	if (ans > 0 && find(r + r, t) != ans)
		ans = -1;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 50188
def main():
    from collections import Counter as ct
    n = int(input())
    s = list(map(int, input().split()))
    a = ct(s)
    a2 = sorted([i for i, j in a.items() if j == 1])
    a3 = sorted([i for i, j in a.items() if j > 1])
    s = set(s)

    ans = 0
    for i in a3:
        if i in s:
            k = i
            while k <= 10**6:
                if k in s:
                    s.remove(k)
                k += i
    for i in a2:
        if i in s:
            ans += 1
            k = i
            while k <= 10**6:
                if k in s:
                    s.remove(k)
                k += i
    print(ans)


main()

Measured memory_bytes: 131548
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a;
  cin >> a;
  
  int s1,s2,s3;
  s1=a/100;
  s2=(a-s1*100)/10;
  s3=(a-s1*100-s2*10);
  
  cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
#include <utility>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define finish(x) std::cout<< x <<endl
#define all(x) (x).begin(), (x).end()
#define forn(i, j) for(ll i = 0; i < j; i++)
#define rforn(i, j) for(ll i = j-1; i >= 0; i--)
#define forit(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll INF = 1e9;
const ll mod = 1e9 + 7;
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }


void solve() {
        int n;
        cin >> n;
        int a, b;
        cin >> a >> b;
        int x = (a/n);
        int y = (x + 1) * n;
        if(a%n == 0) {
                cout << "OK" <<endl;
                return;
        }
        if( y <= b ) {
                cout << "OK" <<endl;
        } else {
                cout << "NG" <<endl;
        }
}

int main() {

        boost;

        ll t;
        // cin >> t;
        t = 1;

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

Measured memory_bytes: 3612
#include<stdio.h>
#define min(a,b) ((a) < (b) ? a : b)
#define max(a,b) ((a) > (b) ? a : b)
main()
{

    int a,b,c,a1,b1,c1;

    while(scanf("%d %d %d",&a,&b,&c)!=EOF){

    a1=min(min(a,b),c);
    c1=max(max(a,b),c);
    if(a1!=a && c1!=a ) b1=a;
    else if (a1!=b && c1!=b) b1=b;
    else b1=c;
        printf("%d %d %d\n",a1,b1,c1);
    }

    return 0;




}



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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n,m,k; cin>>n>>m>>k;
    ll ans=0;
    vector<ll> a(n),b(m);
    rep(i,n) cin>>a[i];
    rep(i,m) cin>>b[i];
    vector<ll> sa(n+1,0),sb(m+1,0);
    rep(i,n) sa[i+1]=sa[i]+a[i];
    rep(i,m) sb[i+1]=sb[i]+b[i];

    ll j=m;
    rep(i,n+1){
        if(sa[i]>k) break;
        while(sa[i]+sb[j]>k)j--;
        ans=max(ans,i+j);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9592
/**
 * Title:
 * Url:
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int a, b;
    cin >> a >> b;
    for(int i=0; i<=1000; i++) {
        if(floor(i*0.08)==a&floor(i*0.1)==b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}
//////////////

void solve() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	A[N - 1] /= 2;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += A[i];
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

    int a, b, c, k, ans, max;
    cin >> a >> b >> c >> k;

    max = a;
    if (b > a)
        max = b;
    if (c > b)
        max = c;

    ans = a + b + c - max;

    int t = max;
    for (int i = 0; i < k; i++)
        max *= 2;

    ans += max;

    cout << ans << endl;

    return 0;
}

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

using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    
    vector<int> v;
    int num;
    for(int i=0; i<K; i++){
        cin >> num;
        v.push_back(num);
    }
    int n, ans = 0;
    bool flg = false;
    ans = N;
    while(!flg){
        N = ans;
        while(N!=0){
            n = N % 10;
            for(vector<int>::iterator it = v.begin(); it != v.end(); it++){
                if(n != *it){
                    flg = true;
                }else {
                    flg = false;
                    break;
                }
            }
            if(!flg){
                break;
            }
            N /= 10;
        }
        if(flg){
            cout << ans << endl;
            exit;
        }else{
            ans++;
        }
    }


    return 0;
}                                                                                                   


Measured memory_bytes: 256
/*
*
*	AUTHOR :- @soham01
*		// "WORK HARD AND NEVER GIVE UP" //
*
*/
#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define mp make_pair
#define vi vector<long long int >
#define vb vector<bool>
#define vs vector<string>
#define vd vector<double>
#define vvi vector<vector<long long int> >
#define vp vector<pair<long long int , long long int > >
#define seti set<long long int >
#define setc set<char>
#define setd set<double>
#define mod 1000000009
#define endl '\n'
typedef long long int lli;

// ITS MY REQUEST TO PLEASE PLEASE DO LOOK AT THE CONSTRAINS GIVEN CAREFULLY
// DO CHECK FOR CORNER CASES

/*-------LET THE GAME BEGIN-----------*/

void solve()
{
    lli x,y,a,b,c,i,j,s=0,f=0;
    cin>>x>>y>>a>>b>>c;
    lli arr[a],brr[b],crr[c],drr[x+y];
    for(i=0;i<a;i++)cin>>arr[i];
    for(i=0;i<b;i++)cin>>brr[i];
    for(i=0;i<c;i++)cin>>crr[i];
    sort(arr,arr+a,greater<int>());
    sort(brr,brr+b,greater<int>());
    sort(crr,crr+c,greater<int>());

    for(i=0;i<x;i++)
    {
        drr[i]=(arr[i]);
    }
    for(i=x;i<y+x;i++)
    {
       drr[i]=brr[i-x];
    }
   sort(drr,drr+(x+y));


    f=min(c,x+y);
   // cout<<f<<" "<<c<<" "<<l<<endl;
    for(i=0;i<f;i++)
    {
        if(drr[i]<crr[i])
        {
            drr[i]=crr[i];
        }
    }
    //for(i=0;i<x+y;i++)cout<<drr[i]<<endl;
    for(i=0;i<x+y;i++)
    {
        s+=drr[i];
    }
    cout<<s<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

		solve();
	return 0;
}




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

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

  for(ll i=1;i<=3500;i++){
    for(ll j=1;j<=3500;j++){
      ll p=n*i*j;
      ll q=4*i*j-n*i-n*j;
      if(q!=0&&p%q==0&&p/q>0){
	cout<<i<<' '<<j<<' '<<p/q<<endl;
	return(0);
      }
    }
  }

  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = j; i < (int)(k); ++i)
const int MAX_N  = 101;

int N;
long v[MAX_N][MAX_N], e[MAX_N][MAX_N];

long calc(int y1, int x1, int y2, int x2){
  long ret = e[y2][x2];
  if(x1 - 1 >= 0) ret -= e[y2][x1 - 1];
  if(y1 - 1 >= 0) ret -= e[y1 - 1][x2];
  if(x1 - 1 >= 0 && y1 - 1 >= 0) ret += e[y1 - 1][x1 - 1];
  return ret;
}

int main(){
  cin >>N;
  REP(i, N) REP(j, N) cin >>v[i][j];
  memset(e, 0, sizeof(e));
  e[0][0] = v[0][0];
  FOR(i, 1, N) e[i][0] = e[i - 1][0] + v[i][0];
  FOR(i, 1, N) e[0][i] = e[0][i - 1] + v[0][i];
  FOR(y, 1, N)
    FOR(x, 1, N)
      e[y][x] = v[y][x] + e[y - 1][x] + e[y][x - 1] - e[y - 1][x - 1];
  long ans = -10000 * 100 * 100 - 1;
  REP(y1, N)
    REP(x1, N)
      FOR(y2, y1, N)
        FOR(x2, x1, N){
          //cout <<"y1 = " <<y1 <<", x1 = " <<x1 <<", y2 = " <<y2 <<", x2 = " <<x2 <<" | " <<calc(y1, x1, y2, x2) <<endl;
          ans = max(ans, calc(y1, x1, y2, x2));
        }
  cout <<ans <<endl;
  return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)                                                             \
  sort(v.begin(), v.end());                                                    \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)

template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }

#define mod (int)(1e9 + 7)
#define INF LLONG_MAX

ll H, W;
vector<string> a;

bool is_col_empty(ll h) {
  rep(i, H) {
    if (a[i][h] == '#') {
      return 0;
    }
  }
  return 1;
}

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

  cin >> H >> W;

  a.reserve(H);

  rep(i, H) {
    string s;
    cin >> s;
    a.push_back(s);
  }

  rep(h, H) {
    if (a[h].find("#") == string::npos) {
      continue;
    }
    rep(w, W) {
      if (!is_col_empty(w)) {
        cout << a[h][w];
      }
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 1e9 + 7;

ll A[200000];
ll S[200001];

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

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

	for (int i=0; i<N; i++) {
		S[i+1] = (S[i] + A[i]) % MOD;
	}

	ll ans = 0;

	for (int i=0; i<N-1; i++) {
		ans = (ans + (((S[N] - S[i+1] + MOD) % MOD) * A[i]) % MOD) % MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6744
gets
x = gets.split(" ").map(&:to_f)
y = gets.split(" ").map(&:to_f)
d = [x,y].transpose.map{|c| c.inject(:-).abs}
(1..4).each do |i|
  puts ((i == 4) ? d.max : d.map{|c| c**(i)}.inject(:+)**(1.0/i))
end

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 9 && b <= 9) cout << a*b << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
h,w=map(int, input().split())
g={}
for i in range(h):
    l=input()
    length=len(l)
    for j,x in enumerate(l):
        if x == '#':
            continue
        pos=length*i+j
        g[pos]=[]
        if pos-1 in g.keys() and pos % length != 0:
            g[pos-1].append(pos)
            g[pos].append(pos-1)
        if pos-length in g.keys():
            g[pos-length].append(pos)
            g[pos].append(pos-length)

counts = []
for i in g.keys():
    l = [i]
    done = []
    count = 0
    while len(l):
        for _ in range(len(l)):
            x = l.pop(0)
            done.append(x)
            for y in g[x]:
                if y in done:
                    continue
                if y in l:
                    continue
                l.append(y)
        count=count+1
    counts.append(count)
print(max(map(lambda x: x-1, counts)))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<long double>x(N);
	std::vector<std::string>u(N);
	rep(i, N) in >> x[i] >> u[i];

	long double ans = 0;
	rep(i, N)
	{
		if (u[i] == "JPY") ans += x[i];
		else ans += x[i] * 380000.;
	}

	out << std::fixed << std::setprecision(10);
	out << ans << std::endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,D;
  cin >> N >> D;
  int result = 0;
  double count = 0;
  vector<vector<double>> A(N,vector<double>(D));
  for(int a = 0;a < N;a++){
   for(int b = 0;b < D;b++){
     cin >> A[a][b];
     
   }
  }
  for(int a = 0;a < N;a++){
    for(int b = a + 1;b < N;b++){
      count = 0;
      for(int c = 0;c < D;c++){
       count += (A[a][c] - A[b][c]) * (A[a][c] - A[b][c]);
      }
      count = sqrt(count);
      int d = count;
      if(d == count)result++;
      
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 3728
def dfs(cursor, a, b, c):
    if cursor == N:
        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else float("inf")
    ret0 = dfs(cursor + 1, a, b, c)
    ret1 = dfs(cursor + 1, a + l[cursor], b, c) + 10
    ret2 = dfs(cursor + 1, a, b + l[cursor], c) + 10
    ret3 = dfs(cursor + 1, a, b, c + l[cursor]) + 10
    return min(ret0, ret1, ret2, ret3)


N, A, B, C = [int(i) for i in input().split()]
l = [int(input()) for _ in range(N)]
print(dfs(0, 0, 0, 0))


Measured memory_bytes: 45276
#coding:utf-8
import numpy as np
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

count = 0

for item in a:
    #A*Bについて、今回は行列の積を求めているのと同じ
    if np.dot(item, b) + c > 0:
        count += 1

print(count)

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

#define EPS 1e-10
 
struct point{
	double x;
	double y;
};

struct line{
	double a;
	double b;
};

bool get_line( const point& a , const point& b , line *a_b );
istream& operator >> ( istream& s , point& p );
 
int main(void)
{
	point a, b, c, d;
 
    line a_b, c_d;
 
    bool result1 , result2;
 
    int num;
 
    cin >> num;
 
    for( int i = 0 ; i < num ; i++ )
    {
        cin >> a >> b >> c >> d;
 
        result1 = get_line( a , b , &a_b );
        result2 = get_line( c , d , &c_d );
 
        if( result1 == false && result2 == false )
        {
            cout << "YES" << endl;
        }
        else
        {
            if( fabs(a_b.a - c_d.a) < EPS ) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    }
 
    return 0;
}

istream& operator >> ( istream& s , point& p )
{
	return s >> p.x >> p.y;
}

bool get_line( const point& a , const point& b , line *a_b )
{
	if( fabs(a.x - b.x) < EPS ) return false;
	else{
		a_b->a = (a.y - b.y)/(a.x - b.x);
		a_b->b = a.y - (a.x * a_b->a);
		return true;
	}
}

Measured memory_bytes: 1228
/**********************************************************************/
/********                                                      ********/
/********                     Writer:孙~~                      ********/
/********                       Lang:C++                       ********/
/********                     Status:Unknow                    ********/
/********                                                      ********/
/**********************************************************************/
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cstring>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;

const int INF=0x3f3f3f3f;

int main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int l=max(max(a,b),c)*pow(2,k);
	int p=max(max(a,b),c);
	cout<<a+b+c-p+l;
	return 0;
}




Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
  public  static void main(String[] args)throws IOException{
	InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br=new BufferedReader(isr);
		String ad=br.readLine();
		String bd=br.readLine();
		int w = Integer.parseInt(ad);
		int n = Integer.parseInt(bd);
		int[] amida=new int[w+1];
		for(int i=1;i<=w;i++)
		    amida[i]=i;
		for(int i=0;i<n;i++){
		StringTokenizer st = new StringTokenizer(br.readLine(),",");
		int a=Integer.parseInt(st.nextToken());
		int b=Integer.parseInt(st.nextToken());
		int t=amida[a];
		amida[a]=amida[b];
		amida[b]=t;
		}
		for(int i=1;i<=w;i++)
		    System.out.println(amida[i]);
		
  }
    
}

Measured memory_bytes: 16884
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main () {
    vector<int> x;
    int N, cnt=1, ans=0;
    cin >> N;
    for (int i=0;i<N;i++){
        int a;
        cin >> a;
         x.push_back(a);
    }
    while (cnt){
        cnt=0;
        for (int i=0;i<N;i++){
            if (x[i]==i+1){
                cnt++;
                ans++;
                if (i!=N-1)
                    swap(x[i],x[i+1]);
                else
                    swap(x[i],x[i-1]);
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
using namespace std;
int n,a[100000];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
	int MIN=a[0],MAX=a[n-1],p=0,m=0;
	for(int i=1;i<n-1;i++){
		if(a[i]>0)p+=a[i];
		else m+=a[i];
	}
	cout<<MAX-m-(MIN-p)<<endl;
	for(int i=1;i<n-1;i++){
		if(a[i]>0){
			cout<<MIN<<" "<<a[i]<<endl;
			MIN-=a[i];
		}else{
			cout<<MAX<<" "<<a[i]<<endl;
			MAX-=a[i];
		}
	}
	cout<<MAX<<" "<<MIN<<endl;
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}


signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  vector<int> B(N);
  rep(i, N) {
    cin >> B[i];
  }


  int ans = INF;

  rep(b, bit(N)) {
    int num = __builtin_popcount(b);  // 裏
    if (num % 2 == 1)
      continue;

    vector<int> o, e;
    vector<int> place(N);
    vector<int> start(N);


    rep(i, N) {
      if ((b >> i) & 1) {  // 裏
        if (i % 2 == 0) {
          e.pb(B[i]);
          start[i] = B[i];
          place[i] = 1;
        } else {
          o.pb(B[i]);
          start[i] = B[i];
          place[i] = 0;
        }
      } else {  // 表
        if (i % 2 == 0) {
          o.pb(A[i]);
          start[i] = A[i];
          place[i] = 0;
        } else {
          e.pb(A[i]);
          start[i] = A[i];
          place[i] = 1;
        }
      }
    }

    if (!(len(o) == len(e) || len(o) == (len(e) + 1)))
      continue;

    auto o_cp = o, e_cp = e;

    sort(all(o));
    sort(all(e));

    int oo = 0, ee = 0;
    vector<int> goal(N);
    rep(i, N) {
      if (i % 2 == 0)
        goal[i] = o[oo++];
      else
        goal[i] = e[ee++];
    }

    bool ok = true;
    rep(i, N - 1) {
      if (goal[i] > goal[i + 1])
        ok = false;
    }
    if (!ok)
      continue;

    int cnt = 0;
    rep(i, N - 1) {
      int k;
      repp(j, i, N - 1) {
        if (goal[i] == start[j] && i % 2 == place[j]) {
          k = j;
          break;
        }
      }
      repr(j, k - 1, i) {
        swap(start[j], start[j + 1]);
        swap(place[j], place[j + 1]);
        cnt++;
      }
    }

    chmin(ans, cnt);
  }

  if (ans == INF) {
    puts("-1");
  } else {
    cout << ans << "\n";
  }
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int judge(int);
int main(){

  int n,i,cnt=0,*a;

  scanf("%d",&n);
  a=(int *)malloc(sizeof(int)*n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(judge(a[i])==1) cnt++;
  }
  free(a);
  printf("%d\n",cnt);
  return 0;
}

int judge(int a){
  int i;

  if((a==2)||(a==3)||(a==5)) return 1;
  if(a%2==0) return 0; 
  for(i=3;i<=(int)sqrt(a);i+=2){
    if(a%i==0) return 0;
  }
  return 1;
}
    

Measured memory_bytes: 628
#![allow(unused_imports)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
use proconio::marker::*;
use proconio::{fastout, input};
use rand::prelude::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        ar: [usize; n],
    }
    let n = 2e2 as usize;
    let res = solve(&ar);
    println!("{}", res)
}

fn solve(ar: &[usize]) -> usize {
    let modn = 1e9 as usize + 7;
    let mut sum = {
        let mut t = 0;
        for &a in ar {
            t += a;
            t %= modn;
        }
        t
    };
    let mut res = 0;
    for &a in ar {
        sum += modn;
        sum -= a;
        sum %= modn;
        res += sum * a % modn;
        res %= modn;
    }
    res
}



Measured memory_bytes: 5580
#include <iostream>
#include <array>

int main() {
	int n;
	std::cin >> n;

	std::array<int, 100000> a = {{}}; // K=Ax, V=報告した人数
	for (int i = 0; i < n; ++i) {
		int ax;
		std::cin >> ax;
		++a[ax];
	}

	// 人数奇数の場合は0が1、偶数(<人数)が2
	// 人数偶数の場合は、奇数(<人数)が2
	// チェックするのは<人数まででok
	if (n % 2 == 1) {
		if (a[0] != 1) {
			std::cout << 0 << std::endl;
			return 0;
		}
		for (int i = 2; i < n; i += 2) {
			if (a[i] != 2) {
				std::cout << 0 << std::endl;
				return 0;
			}
		}
	} else {
		for (int i = 1; i < n; i += 2) {
			if (a[i] != 2) {
				std::cout << 0 << std::endl;
				return 0;
			}
		}
	}

	int sum = 1;
	for (int i = 2; i <= n; i += 2) {
		sum = (sum << 1) % (1000 * 1000 * 1000 + 7);
	}
	std::cout << sum << std::endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int N, ac, wa, tle, re;
	ac = 0;
	wa = 0;
	tle = 0;
	re = 0;
	string S[100000];
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> S[i];
	for (int i = 0; i < N; i ++)
			if (S[i] == "AC")
				ac += 1;
			else if (S[i] == "WA")
				wa += 1;
			else if (S[i] == "TLE")
				tle += 1;
			else if (S[i] == "RE")
				re += 1;
	cout << "AC x " << ac << "\n";
	cout << "WA x " << wa << "\n";
	cout << "TLE x " << tle << "\n";
	cout << "RE x " << re << "\n";
}

Measured memory_bytes: 6732
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> cnt;
    REP(i, n){
        cin >> a[i];
        cnt[a[i]]++;
    }
    if(n % 3 > 0 && cnt.size() >= 2) {
        cout << "No" << endl;
    }
    else if(cnt.size() == 1){
        cout << (cnt.count(0) > 0 ? "Yes" : "No") << endl;
    }
    else if(cnt.size() == 2){
        vector<pii> t;
        // count, number
        for(auto p: cnt){
            t.push_back(make_pair(p.second, p.first));
        }
        sort(t.begin(), t.end());
        if(t[0].first * 2 != t[1].first){
            cout << "No" << endl;
        }
        else{
            cout << (t[0].second == 0 ? "Yes" : "No") << endl;
        }
    }
    else if(cnt.size() == 3){
        vector<pii> t;
        // count, number
        for(auto p: cnt){
            t.push_back(make_pair(p.second, p.first));
        }
        sort(t.begin(), t.end());
        if(t[0].first == t[1].first && t[1].first == t[2].first && (t[0].second^t[1].second)==t[2].second && (t[0].second^t[2].second)==t[1].second && (t[1].second^t[2].second)==t[0].second){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 4224
//Weight

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

bool g[65];

//?????????????????£??°??????????????°?????°??????
int count_bits(unsigned x){
    int count = 0;
    while(x){
        if(x & 1U) count++;
        x >>= 1;
    }
    return count;
}

//unsinged??????bit??°?????????
int int_bit(void){
    return count_bits(~0U);
}
//??£??°?????????????????§?????????????????????????????¨??????????°??????????????????????????´?????????????
void createArray(unsigned x){
    int n = int_bit();
    for(int i = 0; i < n; i++){
        if((x >> i) & 1U) g[i] = true; 
    }
}

int main(void){

    int i = 9;
    unsigned int x;
    int dp[10][10]; // i?????????????????????????????????weight
    //Dp??§???
    
    while((scanf("%d", &x)) != EOF){
       for(int i = 0; i < 65; i++) g[i] = false;
       createArray(x);
       
       //flag????????£???????????????????°???????????????¨???????????????
       for(int i = 0, j = 0; i < 10; i++) {
           if(g[i]) {
               if(j) printf(" ");
               printf("%d", (int)pow(2.0, (double)i));
               j++;
           }
       }
       putchar('\n');
       
    }
    
    return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
	long long A,B;
	char op;
	scanf("%lld %c %lld",&A,&op,&B);
	if(A>=1 && B>=1 && A<=pow(10,9) && B<=pow(10,9) && ((op=='+') || (op='-')))
	if(op=='+'){
		printf("%lld",(A+B));
	}
	else{
		printf("%lld",(A-B));
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;
int main()
{ 
    fastio;
    string s,t;
    cin>>s;
    cin>>t;
    bool comp=true;;
    range(i,0,t.length()-1)
    {
      if(s[i]!=t[i])
      {
        comp=false;
        break;
      }
    }
    if(s.length()<=10&&t.length()==s.length()+1&&comp)
    {
      cout<<"Yes";
    }
    else cout<<"No";
}



Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    int count = 0;
    while(true){
        for(int i = 0; i < N; i++){
            if(A[i] % 2 == 0) A[i] /= 2;
            else goto finish;
        }
        count++;
    }
    finish:
    cout<< count << endl;
}


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

using namespace std;

typedef long long ll; // ll  is 64bit same as double

int main() {
	
	// make input and output more efficient
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	double a, b;
	int h, m;
	
	cin >> a >> b >> h >> m;
	
	cout << fixed << setprecision(20);
	
	double ha = (90 - h * 30 - m/2.0) * M_PI / 180.0;
		
	double ma = (90 - m * 6) * M_PI / 180.0;
		
	double dist = sqrt(pow(a*cos(ha) - b*cos(ma),2) + pow(a*sin(ha) - b*sin(ma),2));
		
	cout << dist << "\n";
	
	return 0;
}

Measured memory_bytes: 4176
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2e5 + 7;

int a[N];

signed main()
{
	IO_OP;
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> a[i];
	while(k--) {
		vi b(n);
		for(int i = 0; i < n; i++) {
			int l = max(i - a[i], 0), r = min(i + a[i], n - 1);
			b[l]++;
			if(r + 1 < n) b[r+1]--;
		}
		bool change = false;
		for(int i = 0; i < n; i++) {
			if(i != 0) b[i] += b[i - 1];
			if(a[i] ^ b[i]) change = true;
			a[i] = b[i];
 		}
 		if(!change) break;
	}
	for(int i = 0; i < n; i++) cout << a[i] << " ";
	cout << endl;
	
}





Measured memory_bytes: 5224
#include <iostream>
using namespace std;
int main(void){
  int H1,M1,H2,M2,K,A,O;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  A = H2 - H1;
  O = M2 - M1;
  A = A * 60;
  A = A + O - K;
  cout << A << endl;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
vector< vector<long long int > > adj(200007);
vector<bool> vis(200007,false);
long long int cnt;
void DFS(long long int s)
{
    vis[s]=true;
    for(long long int j=0;j<adj[s].size();j++)
    {
        ll to=adj[s][j];
        if(vis[to]==false)
        {
            cnt++;
            DFS(to);
        }
    }
}
int main()
{
    ll n,m;
    cin >> n >> m;
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin >> x >>y;
        x--;y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    vector<ll> counters;
    for(ll i=0;i<n;i++)
    {
        if(vis[i]==false)
        {
            cnt=1;
            DFS(i);
            counters.push_back(cnt);
        }
    }
    sort(counters.begin(),counters.end());
    cout << counters[counters.size()-1];
    
}


Measured memory_bytes: 23372
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np
#import sympy

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n = int(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    for i in range(n-2):
        if numbers[i][0] == numbers[i][1] and numbers[i+1][0] == numbers[i+1][1] and numbers[i+2][0] == numbers[i+2][1]:
            print("Yes")
            exit()
    print("No")
    exit()


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9204
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;}


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

i64 X; cin >> X;

i64 y = 0;
i64 a = 100;
while(a < X) {
    a *= 1.01;
    ++y;
}


cout << y << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 3652
#ABC057B

n,m=map(int,raw_input().split())
ab=[]
for i in xrange(n):
 a,b=map(int,raw_input().split())
 ab.append([a,b])
cd=[]
for i in xrange(m):
 c,d=map(int,raw_input().split())
 cd.append([c,d])

for i in xrange(n):
 res=-1
 lm=10**9
 for j in xrange(m):
  l=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
  if l<lm:
   lm=l
   res=j
 print res+1


Measured memory_bytes: 2568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    VI a(n), e(n), l(n);
    FOR(i, 0, n)cin >> a[i];
    e[0] = a[0];
    l[n - 1] = a[n - 1];
    FOR(i, 1, n)e[i] = max(a[i], e[i - 1]);
    eFOR(i, 2, n)l[n - i] = max(a[n - i], l[n - i + 1]);

    cout << l[1] << "\n";
    FOR(i, 1, n - 1)cout << max(e[i - 1], l[i + 1]) << "\n";
    cout << e[n - 2] << "\n";
}

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

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

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;


void solve(long long K, long long A, long long B){
	FOR(i,A,B+1) {
		if(i%K == 0) {
			cout << "OK" <<endl;
			return;
		}
	}

	cout << "NG" <<endl;

}

int main(){
    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(K, A, B);
    return 0;
}



Measured memory_bytes: 3684