akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	katamuki = []
	for i,val in enumerate(A):
		if i == 0:
			continue
		if val < A[i-1]:
			katamuki.append("down")
		elif val > A[i-1]:
			katamuki.append("up")
		else:
			katamuki.append("to")

	ans = 1000
	for i,val in enumerate(A):
		if i == len(A)-1:
			break
		if val <= ans:
			if katamuki[i] == "up":
				tmp = ans // val
				ans = ans - (val * tmp)
				ans = ans + (tmp * A[i+1])

	print(ans)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 83652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;
int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<char> v[2];
    bool d = 1;
    while (q--) {
        int cmd;
        cin >> cmd;
        if (cmd == 1) {
            d = (!d);
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                v[d].push_back(c);
            } else {
                v[!d].push_back(c);
            }
        }
    }
    if (d) {
        for (int i = v[1].size() - 1; i >= 0; i--) {
            cout << v[1][i];
        }
        cout << s;
        for (int i = 0; i < v[0].size(); i++) {
            cout << v[0][i];
        }
        cout << endl;
    } else {
        for (int i = v[0].size() - 1; i >= 0; i--) {
            cout << v[0][i];
        }
        reverse(s.begin(), s.end());
        cout << s;
        for (int i = 0; i < v[1].size(); i++) {
            cout << v[1][i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#define MAX 20001

//水たまりの面積：S　何番目の文字列に水たまりがあるか:idx 
typedef struct Index{
   int idx;
   int S;
}Index;
 
 
//stackに\が入力された時、\が何番目かを入力する
void push1(int S[],int x,int *top){
   S[*top] = x;
   (*top)++;
   return;
}
 
//インデックス型のSに面積と何番目の文字列に水たまりがあるかstackで管理
void push2(Index S[],int idx,int s,int *top){
   S[*top].idx = idx;
   S[*top].S = s;
   (*top)++;
   return;
}
 
int pop(int S[],int *top){
   (*top)--;
   return S[*top];
}

//水たまりの結合
void Uni(Index S[],int *top){
   int i;
 
   for(i = (*top) - 1 ; i > 0 ; i--){
 
      //水たまりの場所が\を入力することで逆になった場合
      //2つの水たまりを結合させる
      if(S[i].idx < S[i-1].idx){
         (*top)--;
         S[i-1].idx = S[i].idx;
         S[i-1].S += S[i].S;
      }
   }
 
   return;
}
 
int main(){
   int i, j, idx, top1 = 0, top2 = 0, sum = 0;
   char str[MAX];
   int Stack1[MAX];
   Index Stack2[MAX];

   scanf("%s", str);

   for(i = 0 ; i < strlen(str) ; i++) {
      switch(str[i]) {
         case '\\':push1(Stack1, i, &top1);
                   break;
         case '/' :if(top1 == 0)
                      break;
                   idx = pop(Stack1, &top1);
                   sum += (i-idx);
                   push2(Stack2, idx, i - idx, &top2);
                   Uni(Stack2, &top2);
                   break;
      }
 
   }
   printf("%d\n", sum);
   if(top2 == 0) printf("%d\n", top2);
   else {
      printf("%d ", top2);
      for(i = 0 ; i < top2 - 1 ; i++) printf("%d ", Stack2[i].S);
      printf("%d\n", Stack2[top2-1].S);
   }
 
return 0;
}


Measured memory_bytes: 2100
N = int(input())
H = list(map(int, input().split()))
ans = [0] * N
for i in range(N - 1, 0, -1):
    if H[i] <= H[i - 1]:
        ans[i - 1] = ans[i] + 1
    else:
        ans[i - 1] = 0
print(max(ans))


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

int main()
{
	int n,b;
	cin>>n;
	if(n%1000!=0)
	b=n/1000+1;
	 else
	b=n/1000;
	
	b=b*1000;
	cout<<(b-n)<<endl;
	 
	return 0;
	
}

Measured memory_bytes: 3668
#include<iostream>

using namespace std;

int main(){
  string s,t;
  cin>>s>>t;
  int ans = 0;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      ++ans;
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3924
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    cout << max(0,a-2*b);

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int p[1005][5];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> p[i][0] >> p[i][1] >> p[i][2];
    sort(p[i],p[i]+3);
  }
  int cnt = 0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(p[i][0] == 0 || p[j][0] == 0) continue;
      if(p[i][0] == p[j][0] && p[i][1] == p[j][1] && p[i][2] == p[j][2]){
	p[j][0] = 0;
	cnt++;
      }
    }
  }
  cout << cnt << endl;
  return(0);
}



Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  ll A, B;
  cin >> A >> B;

  if (A!=1 && B!=1) cout << 1 << "\n";
  if (A!=2 && B!=2) cout << 2 << "\n";
  if (A!=3 && B!=3) cout << 3 << "\n";
  return 0;
}


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

int main(){
    int n,l;
    cin>>n>>l;
    string s[101];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s,s+n);
    for(int i=0;i<n;i++){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define M 1001

int main(void)
{
	int n, i, j, temp, sa, a[M];
	
	while(scanf("%d",&n))
	{
		if(n==0)
			break;
		else
		{
			for(i=0;i<n;i++)
				scanf("%d",&a[i]);
			sa = 1000000;
			for(i=0;i<n-1;i++)
			{
				for(j=i+1;j<n;j++)
				{
					temp = a[i]-a[j];
					if(temp<0)
						temp = temp * (-1);
					if(sa>temp)
						sa = temp;
				}
			}
			printf("%d\n",sa);
		}
	}
	return 0;
}

Measured memory_bytes: 600
def f(h, w):
    s, t = "#" * w, "#" + "." * (w-2) + "#"
    print(s)
    for _ in range(h-2):
        print(t)
    print(s)
    print()

while True:
    s = input()

    if s == "0 0":
        break
    else:
        h, w = list(map(int, s.split()))
        f(h, w)

Measured memory_bytes: 7648
using System;

class Program
{
    static void Main(string[] args)
    {

        string[] input = Console.ReadLine().Split(' ');

        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);

        int ans = c - (a - b);

        Console.WriteLine(Math.Max(ans, 0));


    }
}



Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

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

	int ans = (N % 2 == 0) ? N / 2 - 1 : N / 2;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch PickingUp | diff PickingUp.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address PickingUp.cpp && ./a.out

/*
 
 6/15/2019
 
 5:03-5:15 AC
 
 https://img.atcoder.jp/diverta2019-2/editorial.pdf
 
 Editorial is showing more efficient way.
     (p,q) is determined
 <=> optimal sequence of points of 0 cost is uniquely determined. res=N-cnt(diff {p,q} for all pairs)
 
 */

const int MAX_N=100+1;
LL X[MAX_N],Y[MAX_N];
int N;

void solve() {
  map<II,int> cnt;
  REP(i,N)REP(j,N)if(i!=j) cnt[{X[j]-X[i],Y[j]-Y[i]}]++;
  int maxp=0;
  FORR(kvp, cnt) SMAX(maxp, kvp.second);
  cout<<N-maxp<<endl;
}

void solve_org() {
  vector<pair<LL,LL>> A;
  REP(i,N)A.emplace_back(X[i],Y[i]);
  //sort(ALL(A));
  set<pair<LL,LL>> S(ALL(A));
  LL res=N;
  REP(i,N)REP(j,N)if(i!=j) {
    LL dx=A[i].first-A[j].first,dy=A[i].second-A[j].second;
    LL sum=N;
    REP(k,N) {
      pair<LL,LL> cur={A[k].first,A[k].second};
      if(S.count({cur.first+dx,cur.second+dy}))--sum;
    }
     SMIN(res,sum);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>X[i]>>Y[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
bool used[301];
int pref[301][301],ord[301][301],cnt[301];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)
	{
		for (int j=1;j<=m;++j)
		{
			scanf("%d",&pref[i][j]);
			ord[i][pref[i][j]]=j;
		}
	}
	for (int i=1;i<=m;++i)
		used[i]=true;
	int ans=1000000000;
	for (int i=1;i<=m;++i)
	{
		memset(cnt,0,sizeof(cnt));
		for (int i=1;i<=n;++i)
		{
			int mn=m+1,mnj;
			for (int k=1;k<=m;++k)
				if (used[k]&&ord[i][k]<mn)
				{
					mn=ord[i][k];
					mnj=k;
				}
			++cnt[mnj];
		}
		int tans=0,ti;
		for (int i=1;i<=m;++i)
			if (cnt[i]>tans)
			{
				tans=cnt[i];
				ti=i;
			}
		ans=min(ans,tans);
		used[ti]=false;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 896
def II(): return int(input())
def MI(): return map(int,input().split())
def LMI(): return list(map(int,input().split()))
def LIIN(n): return list(int(input()) for _ in range(n))
def LMIN(n): return [list(map(int, input().split())) for _ in range(n)]
def IS(): return input()
def MS(): return map(str,input().split())
def LMS(): return list(map(str,input().split()))
def LISN(n): return list(input() for _ in range(n))
def LMSN(n): return [input().split() for _ in range(n)]
MOD = 10**9+7
INF = 10**18

def main():
    n = II()
    x = LMI()
    a = sum(x) // len(x)
    a2 = a + 1
    print(min(sum([(i-a)**2 for i in x]),sum([(i-a2)**2 for i in x])))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
a, b, c = list(map(int, input().split()))
#a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
k = int(input())
#a = list(map(int, input().split()))
# b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
#x = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
# for i in range(1, int(n**0.5)+1):
if a < b and b < c:
    print("Yes")
    exit()

for i in range(k):
    if a >= b:
        b *= 2
    elif b >= c:
        c *= 2

    if a < b and b < c:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 9180
#include <iostream>
#define rep(i, n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MAX_K = 2 * 1e5;
const int INF = 1e9;
int R, C, K;
int items[3001][3001];
// (i, j)で１行でitemをk個拾ってる時の最大値
ll dp[3001][3001][4];

void solve() {
  //dp
  rep (i, R) {
    rep (j, C) {
      // 現在地の更新
      for (int k = 2; k >= 0; k--) {
        // item使うパターン
        dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + items[i][j]);
      }
    
      //　右隣と真下のマスを更新
      rep(k, 4) {
        dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]); // 次行はitemがリセットされる
        dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]); // item使わないパターン
      }
    }
  }

  cout << dp[R][C-1][0]; //真下は更新している
}

int main() {
  cin >> R >> C >> K;
  rep (i, K) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    items[a][b] = c;
  }
  
  solve();
}

Measured memory_bytes: 320040
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

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

ll n, d[100000];
vector<P> g[100000];

void dijkstra(ll s) {
    fill(d, d + n, INF);
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push({0, s});
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll u = p.second;
        if (p.first > d[u]) continue;
        REP(i, g[u].size()) {
            ll v = g[u][i].first, cost = g[u][i].second;
            if (d[v] > d[u] + cost) {
                d[v] = d[u] + cost;
                que.push({d[v], v});
            }
        }
    }
}

int main() {
    cin >> n;
    REP(i, n) {
        ll from, k;
        cin >> from >> k;
        REP(j, k) {
            ll to, c;
            cin >> to >> c;
            g[from].push_back({to, c});
        }
    }
    dijkstra(0);
    REP(i, n) printf("%ld %ld\n",i,d[i]);
    return 0;
}


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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  REP(i,n) cin >> p[i];
  vector<int> s(n+1,0);
  REP(i,n) { s[i+1] = s[i] + p[i]; }

  int ind, ma = -1001001001;
  for(int i = 0; i <= n-k; i++) {
    int v = s[k+i] - s[i];
    if (ma < v) {
      ma = v;
      ind = i;
    }
  }
  double ans=0;
  for (int i = ind; i < ind+k; i++) {
    ans += (double)((1.0+p[i])*p[i]) / (2.0 * p[i]);
  }
  cout << fixed << setprecision(12) << ans << endl;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;cin>>s;

  for(int i=0;i<=7;i++){
    string res = "";
    res += s.substr(0,i);

    int len = 7-i;
    res += s.substr(s.size()-len,len);
    if(res=="keyence"){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextInt();
        var M = sc.nextInt();
        var p = sc.ArrayInt(N);
        var ds = new DisjointSet(N + 1);
        for (int i = 0; i < M; i++) {
            ds.Unite(sc.nextInt(), sc.nextInt());
        }

        var ans = 0;
        var sorted = p.OrderBy(i => i).ToArray();
        for (int i = 0; i < N; i++) {
            if (p[i] == sorted[i]) {
                ans++;
            } else {
                if (ds.Same(p[i], sorted[i])) {
                    ans++;
                }
            }
        }

        WriteLine(ans);
    }
}

class DisjointSet {
    int[] rank;
    int[] p;

    public DisjointSet(int size) {
        rank = new int[size];
        p = new int[size];
        for (int i = 0; i < size; i++) MakeSet(i);
    }

    public bool Same(int x, int y) {
        return FindSet(x) == FindSet(y);
    }

    public void Unite(int x, int y) {
        Link(FindSet(x), FindSet(y));
    }

    void MakeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }

    void Link(int x, int y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }

    int FindSet(int x) {
        if (x != p[x]) {
            p[x] = FindSet(p[x]);
        }
        return p[x];
    }
}




class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {


        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

Measured memory_bytes: 27848
N,A,B = map(int,input().split())
S = input()

D=[]
F = []
ans=[]
f = 0
for i in range(N):
    tmp = S[i]
    if tmp == "a":
        if (len(D)+len(F))<(A+B):
            D.append(tmp)
            ans.append("Yes")
        else:
            ans.append("No")
    elif tmp == "b":
        f += 1
        if (len(D)+len(F))<(A+B) and f<=B:
            F.append(tmp)
            ans.append("Yes")
        else:
            ans.append("No")
    else:
        ans.append("No")

for i in range(N):
    print(ans[i])

Measured memory_bytes: 84896
h,w,k = map(int, input().split())
board = [[int(j=="#") for j in input()] for i in range(h)]
from itertools import accumulate
ans = [[] for i in range(h)]
cnt = 1
def rec(i):
    if i==h:
        return
    global cnt
    a = list(accumulate(board[i]))
    if a[-1] == 0:
        return
    nxt = []
    f = 1
    for j in range(w):
        if a[j] == f+1:
            cnt += 1
            f += 1
        nxt.append(cnt)
    ans[i] = nxt
    cnt += 1
for i in range(h):
    rec(i)

for i in range(h-1):
    if ans[i] and not ans[i+1]:
        ans[i+1] = ans[i]
for i in range(h-1,0,-1):
    if ans[i] and not ans[i-1]:
        ans[i-1] = ans[i]
for i in range(h):
    print(*ans[i])

Measured memory_bytes: 8272
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  if(A==1&&B==2||A==2&&B==1)cout<<3<<endl;
  if(A==1&&B==3||A==3&&B==1)cout<<2<<endl;
  if(A==2&&B==3||A==3&&B==2)cout<<1<<endl;
}

Measured memory_bytes: 256
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Wed May 30 20:13:57 2018
//
package main

import "fmt"

var s string

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	fmt.Scan(&s)

	a := 0
	b := 0
	c := 0

	for i := range s {
		switch s[i] {
		case 'a':
			a++
		case 'b':
			b++
		case 'c':
			c++
		}
	}

	if abs(a-b) <= 1 && abs(b-c) <= 1 && abs(c-a) <= 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1280
#include <cstdio>
#include <complex>
#include <vector>
#define P 200003

using namespace std;
typedef complex<double> cd;

int m[P], mp[P], a[P];

vector<cd> fft(vector<cd> &a, cd we){
    int n = a.size();
    if(n == 1)
        return a;
    cd w = 1;
    cd wn = exp(we * cd(2 * M_PI / n));
    vector<cd> a1, a2;
    for(int i = 0; i < n; i += 2){
        a1.push_back(a[i]);
        a2.push_back(a[i+1]);
    }
    vector<cd> y1 = fft(a1, we);
    vector<cd> y2 = fft(a2, we);
    vector<cd> y(n);
    for(int i = 0; i < n / 2; ++i){
        y[i] = y1[i] + y2[i] * w;
        y[i + n / 2] = y1[i] - y2[i] * w;
        w = w * wn;
    }
    return y;
}

int main(){
    int t = 1;
    long long ans = 0;
    for(int i = 0; i < P - 1; ++i){
        m[t] = i;
        mp[i] = t;
        t = (t * 2) % P;
    }

    int n;
    scanf("%d", &n);
    long long x;
    for(int i = 0; i < n; ++i){
        scanf("%lld", &x);
        ans -= (x*x) % P;
        if(x != 0)
            ++a[m[x]];
    }

    t = 1;
    while(t < P){
        t *= 2;
    }
    t *= 2;

    vector<cd> c;
    for(int i = 0; i < P; ++i)
        c.push_back(cd(a[i]));
    for(int i = P; i < t; ++i)
        c.push_back(cd(0));

    vector<cd> y1 = fft(c, cd(0, 1.0));
    vector<cd> y;

    for(int i = 0; i < t; ++i)
        y.push_back(y1[i] * y1[i]);
    vector<cd> w = fft(y, cd(0, -1.0));

    for(int i = 0; i < t; ++i)
        ans += (long long)(mp[i % (P - 1)]) * llround((w[i] / cd(t)).real());
    printf("%lld\n", ans / 2);
    return 0;
}


Measured memory_bytes: 67008
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
 
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;
 
struct dsu
{
	int pre[200005], plen[200005];
	vector<PII> siz[200005];
	void init(int n)
	{
		rep1(i, n) {
			plen[i] = INF;
			siz[i].push_back(MP(0, 1));
		}
	}
	int root(int x, int dis)
	{
		return plen[x] > dis ? x : root(pre[x], dis);
	}
	void unite(int u, int v, int dis)
	{
		u = root(u, dis);
		v = root(v, dis);
		if(u == v) return;
		if(siz[u].back().second > siz[v].back().second) swap(u, v);
		pre[u] = v;
		plen[u] = dis;
		int nsv = siz[v].back().second + siz[u].back().second;
		siz[v].push_back(MP(dis, nsv));
	}
	int getsize(int v, int dis)
	{
		v = root(v, dis);
		return (upper_bound(siz[v].begin(), siz[v].end(), MP(dis + 1, -1)) - 1)->second;
	}
}con;
 
 
int n;
vector<int> G[200005];
vector<int> E[200005];
int par[200005];
int maxd[200005];
 
int ans[200005];
 
void dfs(int v)
{
	if(v != 1) {
		ans[v] = ans[par[v]];
		if(v > maxd[par[v]]) {
			ans[v] ++;
			if(v <= maxd[v]) ans[v] += con.getsize(v, maxd[v] - 1) - 1;
			else rep(i, G[v].size()) {
				int u = G[v][i];
				if(u != par[v] && u <= maxd[v]) ans[v] += con.getsize(u, maxd[v] - 1);
			}
		} else if(par[v] > maxd[par[v]]) ans[v] += con.getsize(v, maxd[v] - 1) - con.getsize(v, maxd[par[v]] - 1);
	}
	
	rep(i, G[v].size()) {
		int u = G[v][i];
		if(u == par[v]) continue;
		par[u] = v;
		maxd[u] = max(v, maxd[v]);
		dfs(u);
	}
}
 
int main()
{
	scanf("%d", &n);
	rep(i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
		E[max(u, v)].push_back(min(u, v));
	}
	
	con.init(n);
	rep1(i, n) rep(j, E[i].size())
	con.unite(i, E[i][j], i);
	
	dfs(1);
	for(int i = 2; i <= n; i ++) printf("%d ", ans[i]); 
	return 0;
}

Measured memory_bytes: 49396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n,ans = 0;
  cin >> n;
  string s;
  unordered_map<string,ll> mp;
  while(n>0){
    cin >> s;
    sort(s.begin(),s.end());
    ans += mp[s];
    mp[s]++;
    n--;
  }
  cout << ans << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法

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



Measured memory_bytes: 10660
N,M = map(int,input().split())
A = [[0,1] for _ in range(N)]
A.insert(0,[0,0])
A[1][0] = 1
for _ in range(M):
    x,y = map(int,input().split())
    A[y][1] += 1
    if A[x][0]==1:
        A[y][0]=1
    A[x][1] -= 1
    if A[x][1]==0:
        A[x][0]=0
cnt = 0
for i in range(1,N+1):
    cnt += A[i][0]
print(cnt)

Measured memory_bytes: 86900
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define N 2000005
#define rep(i,l,r) for(i=l;i<=r;i++)
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
#define eps 0.00000001//偏差值1e8
#define pi acos(-1.0)//高精度圆周率
const int maxp = 1010;					//点的数量
ll a[N];
ll b[N];
ll c[N];
int main()
{
	ll i, j, k;
	ll n, ret = 0, maxn = 0, count = 0;
	ll ans = 0;
	ll t, x, y, len, pos = mod;
	cin >> n >> k;
	if (k == 0)ans = n * n;
	else
	{
		for (i = k + 1; i <= n; i++)
		{
			ans += (n / i) * (i - k);
			if (n % i >= k)ans += n % i - k + 1;
		}
	}
	cout << ans << endl;
}
		

	

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

int     main() {
        int a, b;
        cin >>a >>b;
        if (15==a+b)
                cout <<'+' <<endl;
        else if (15==a*b)
                cout <<'*' <<endl;
        else
                cout <<'x' <<endl;
        return 0;
}

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

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,k;
const long long Mod = 1e9+7;
long long dp[2][200001];
long long Getsum(long long x)
{
    return x*(x-1)/2;
}
int main()
{
    cin>>n>>k;
    long long ans = 0;
    for(int len = k; len <=n+1 ; len++)
    {
        long long Min = Getsum(1LL*len);
        long long Max = Getsum(1LL*n+1) - Getsum(1LL*n-len+1);
        ans+=Max-Min+1;
        ans%=Mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ///////////////////////////////////////
  int k;
  string s;
  cin >> k >> s;
  if (s.length() <= k)
    cout << s << endl;
  else {
    rep(i, k) cout << s[i];
    cout << "..." << endl;
  }

  return 0;
}


Measured memory_bytes: 3648
s = input()

def isBeautiful(s):
  dict = {}
  for i in s:
    if i not in dict:
      dict[i] = 1
    else:
      dict[i] += 1
      
  for key in dict:
    if dict[key] % 2 != 0:
      return "No"
    
  return "Yes"
  
print(isBeautiful(s))

Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

//typedef __int64 lint;

const double EPS = 1e-10;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int INF = 1001001001;
//const lint INFLL = (__int64)1001001001001001001;

#define clear(a) memset((a), 0, sizeof(a))
#define mclear(a) memset((a), -1, sizeof(a))

#define show(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main()
{
	int N;
	while (scanf("%d", &N) && N){
		vector<int> player(N, 0);
		int mount = 0;
		char ch[128];
		
		scanf("%s", ch);
		
		for (int i = 0; i < 100; i++){
			if (ch[i] == 'M'){
				player[i % N]++;
			}
			else if (ch[i] == 'S'){
				mount += player[i % N] + 1;
				player[i % N] = 0;
			}
			else {
				player[i % N] += 1 + mount;
				mount = 0;
			}
		}
		
		sort(player.begin(), player.end());
		for (int i = 0; i < N; i++) printf("%d ", player[i]);
		printf("%d\n", mount);
	}
	return (0);
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    string s,t;
    cin >> s >> t;
    sort(all(s));
    sort(all(t));
    reverse(all(t));
    if(s<t){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

s = [0] * (N+1)
for i in range(N):
  s[i+1] = s[i] + A[i]

counter = Counter(s)
ans = 0
for key, val in counter.items():
  ans += val * (val-1) // 2

print(ans)

Measured memory_bytes: 41672
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <queue>
typedef long long ll;
using namespace std;
const int mod=1e9+7;
const ll inf=(1e14);

ll solve(){
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	int p[a],q[b],r[c];
	for(int &i:p) cin>>i;
	for(int &i:q) cin>>i;
	for(int &i:r) cin>>i;
	sort(p,p+a,greater<int>());sort(q,q+b,greater<int>());
	int ans[x+y+c],top=0;
	for(int i=0;i<x;i++) ans[top++]=p[i];
	for(int i=0;i<y;i++) ans[top++]=q[i];
	for(int i:r) ans[top++]=i;
	sort(ans,ans+top,greater<int>());
	ll res=0;
	for(int i=0;i<x+y;i++) res+=ans[i];
	return res;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--) cout<<solve()<<'\n';
    //while(t--) solve(),cout<<'\n';
    return 0;
}


Measured memory_bytes: 5836
class Vector(val n:Int) {
    val elems = (1..n).map{_ -> 0}.toMutableList()

    operator fun get(index: Int) = elems[index]
    operator fun set(index: Int, value: Int) = elems.set(index, value)
}

class Matrix(val m:Int, val n:Int) {
    val elems = (1..n).map {_ -> (1..m).map {_ -> 0}.toMutableList()}.toMutableList()

    operator fun get(row:Int, column:Int) = elems[row][column]
    operator fun set(row:Int, column: Int, value:Int) = elems[row].set(column, value)
}

fun main(args: Array<String>) {
    var inStr = readLine() ?: return
    val (n, m) = inStr.split(' ').map { e -> e.toInt() }

    val matrixA = Matrix(m, n)
    val vecB = Vector(m)

    for (i in 0..n - 1) {
        inStr = readLine() ?: return
        val rowOfA = inStr.split(' ').map { e -> e.toInt() }

        for (j in 0..m - 1) {
            matrixA[i, j] = rowOfA[j]
        }
    }
    for (i in 0..m - 1) {
        inStr = readLine() ?: return

        val ele = inStr.toInt()

        vecB[i] = ele
    }

    val vecC = Vector(n)
    for (i in 0..n - 1) {
        var cValue = 0
        for (j in 0..m - 1) {
            cValue += matrixA[i, j] * vecB[j]
        }
        vecC[i] = cValue
    }

    for (i in vecC.elems) {
        println(i)
    }
}



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

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

  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  ll ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    a[i] += ans;
    if (a[i] % b[i] == 0)
      continue;
    ll nb = (a[i] + b[i] - 1) / b[i] * b[i];
    ans += nb - a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

bool array[1000000];
int main()
{
	int n;
	array[0] = true;
	array[1] = true;
	n = 1000000;
	for (int i = 2; i < n; i++) {
		if (array[i] == false){
			for (int j = i * 2; j < n; j += i) {
				array[j] = true;
			}
		}
	}
	while (cin >> n){
		int pri = 0;
		for (int i = 0; i <= n; i++){
			if (array[i] == false) {
				pri++;
			}
		}
		cout << pri << endl;
	}
}

Measured memory_bytes: 3960
import heapq

def dijkstra(graph, node, start):
    dist = [float("inf") for _ in range(node)]

    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))

    while q:
        cost, cur_node = heapq.heappop(q)

        if dist[cur_node] < cost:
            continue

        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heapq.heappush(q, (dist[nex_node], nex_node))

    return dist

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append((c, b))
    adj[b].append((c, a))
shortest = []
for i in range(n):
     shortest.append(dijkstra(adj, n, i))
ans = 0
for i in range(n):
    for cost, j in adj[i]:
        if cost > shortest[i][j]:
            ans += 1
print(ans // 2)


Measured memory_bytes: 3572
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
using ll = long long;
using ull = unsigned long long;

vector<int> v;

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

    int a;
    rep(i, n){
        cin >> a;

        if(a % 2 == 0){
            if(!(a % 3 == 0 || a % 5 == 0)){
                println("DENIED");
                stop;
            }
        }
    }

    println("APPROVED");
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		long ans = 0;
		long upper = 0;
		for(int i=0; i<N; i++) {
			long t = sc.nextLong();
			if(upper <= t) {
				ans += T;
			} else {
				ans += (T+t) - upper;
			}
			upper = t+T;
		}
		sc.close();
		System.out.println(ans);
	}

}


Measured memory_bytes: 64180
n=int(input())
t=input().split()
for i in range(n):
    t[i] = int(t[i])

m=int(input())
p=[[] for _ in range(m)]
for i in range(m):
    pi,xi=map(int,input().split())
    p[i]=[pi,xi]

ans=sum(t)
for i in range(m):
    print(ans-t[p[i][0]-1]+p[i][1])


Measured memory_bytes: 3064
//                                                  '-.-'
   //                                         ()      __.'.__
   //                                      .-:--:-.  |_______|
   //                               ()      \____/    \=====/
   //                               /\      {====}     )___(
   //                    (\=,      //\\      )__(     /_____\
   //    __    |'-'-'|  //  .\    (    )    /____\     |   |
   //   /  \   |_____| (( \_  \    )__(      |  |      |   |
   //   \__/    |===|   ))  `\_)  /____\     |  |      |   |
   //  /____\   |   |  (/     \    |  |      |  |      |   |
   //   |  |    |   |   | _.-'|    |  |      |  |      |   |
   //   |__|    )___(    )___(    /____\    /____\    /_____\
   //  (====)  (=====)  (=====)  (======)  (======)  (=======)
   //  }===={  }====={  }====={  }======{  }======{  }======={
   // (______)(_______)(_______)(________)(________)(_________)
   //
   // Credits :- Joan G. Stark
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
   //|                      AUTHOR - KASPAROVIAN                                     |
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define frr(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fr first
#define sc second
#define mk make_pair
#define endl '\n'
#define MOD 1000000007
#define in insert
#define sz(x) (ll)(x).size()
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef pair<int,pi> ppi;
typedef vector<vi> graph;
template<class T> void mxi(T & a, const T & b) { a = max(a, b); }
template<class T> void mni(T & a, const T & b) { a = min(a, b); }
ld EPS=1e-9;
void solve()
{
  int a;
  cin>>a;
  cout<<a+a*a+a*a*a<<endl;

}
signed main()
{
  fast;
  int t,tab;
  t=1;
  tab=t;
  while(t--)
  {
    //cout<<"Case #"<<(tab-t)<<": ";
    solve();
  }
}
//APPROACHING A QUESTION
//+ Think of binary search (max of min etc also if n<=2*10^5)
//+ Think of common dp states (Even if it appears as maths but constraints are small)
//+ Check constraints
//+ Keep calm and enjoy the question
//+ Be sure to remove MOD from binpow (if needed)
//+ Try bidirectional analysis for constructive questions
//+ If given some sequence try thinking of prefix sums
//+ If constraints are too large maybe its simple maths
//+ In questions with binary operations think of bits independently and also the change pattern
//+ If two or more binary operations are given mostly there is a relation between them and an arithmatic operator

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

int main(){
	int n,k;
	cin >> n >> k;
	vector<long long int> h(n);
	
	rep(i,n){
		cin >> h[i];
		h[i] = -h[i];	
	}	

	sort(h.begin(),h.end());

	long long int total = 0;

	rep(i,n){
		if(i + k >= n) break;
		total += -h[i + k];

	}

	cout << total << endl;

	return 0;
}


	


Measured memory_bytes: 1792
def main():
  _map, _range, _int = map, range, int
  n, q = _map(_int, input().split())
  values = [0] * (n + 1)
  parents = [0] * (n + 1)
  for i in _range(n - 1):
    a, b = _map(_int, input().split())
    parents[b] = a
  for _ in _range(q):
    p, x = _map(_int, input().split())
    values[p] += x
  for i in _range(1, n + 1):
    if parents[i] != 0:
      values[i] += values[parents[i]]
  print(*values[1:])
main()


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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll mod(ll a, ll m)
{
    return ((a % m) + m) % m;
}

ll solve(int, const vector<ll>& xs)
{
    ll ans = 0;

    for (ll mask = 1, i = 0; i < 61; ++i, mask <<= 1)
    {
        ll zeros = 0, ones = 0;

        for (auto x : xs)
            (x & mask) ? ++ones : ++zeros;

        ll total = mod(ones * zeros, MOD);
        ll amount = mod(mod(mask, MOD) * total, MOD);

        ans = mod(ans + amount, MOD);
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<ll> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i];

    auto ans = solve(N, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;

int main(){

	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);

	int a, b;
	cin >> a >> b;
	cout << a * b << endl;

	return 0;
}

Measured memory_bytes: 3580
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	int res = 0;
	rep(i, n){
		cin >> a[i];
		res += (a[i] % 2);
	}
	cout << (!res ? "second" : "first") << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/

Measured memory_bytes: 768
import std.algorithm,
       std.string,
       std.range,
       std.stdio,
       std.conv,
       std.math;

long f(long b, long n) {
 return (n < b)
          ? n
          : f(b, n/b) + n % b;
}

long solve(long N, long S) {
  if (N < S) {
    return -1;
  }

  if (N == S) {
    return N + 1;
  }


  foreach (i; 2.iota(sqrt(N.to!float) + 1)) {
    auto j = i.to!long;
    if (f(j, N) == S) {
      return j;
    }
  }
 
  long ans = long.max;

  foreach (i; 1.iota(sqrt(N.to!float) + 1)) {
    auto j = i.to!long;
    long b = (N - S) / j + 1;
    if (b == 1) continue;
    if (f(b, N) == S) ans = min(ans, b);
  }

  if (ans < long.max) {
    return ans;
  } else {
    return -1;
  }
}

void main() {
  long N = readln.chomp.to!long,
       S = readln.chomp.to!long;
  writeln(solve(N, S));
}

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

void solve()
{
    char x, y;
    cin >> x >> y;
    if (x < y)
        cout << "<" << endl;
    else if (x > y)
        cout << ">" << endl;
    else
        cout << "=" << endl;
}

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

Measured memory_bytes: 3620
import sys
import math
from collections import defaultdict, deque
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''D'''
n=r()
a=rl()
d=defaultdict(int)
for i in a:
    d[i]+=1
s=sum(a)
for i in range(r()):
    b,c=rm()
    m=d[b]
    s+=m*(c-b)
    d[c]+=m
    d[b]=0
    print(s)

Measured memory_bytes: 91068
def main():
    N  = int(input())
    S  = input()
    print(rot_n(S,N))


def rot_n(s, n):
    answer = ''
    for letter in s:
        answer += chr(ord('A') + (ord(letter)-ord('A')+n) % 26)

    return answer

if __name__ == '__main__':
    main()

Measured memory_bytes: 9216
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define X_MAX 1010
#define Y_MAX 1010
#define Z_MAX 1010
#define K_MAX 3001

void solv()
{
	int X,Y,Z,K;
	scanf("%d%d%d%d", &X, &Y, &Z, &K);

	long long int A[X_MAX], B[Y_MAX], C[Z_MAX];
	for (int i = 0; i < X; i++){
		scanf("%lld", A + i);
	}
	for (int i = 0; i < Y; i++){
		scanf("%lld", B + i);
	}
	for (int i = 0; i < Z; i++){
		scanf("%lld", C + i);
	}

	sort(A, A + X);
	sort(B, B + Y);
	sort(C, C + Z);

	priority_queue<pair<long long int, pair<int, pair<int, int> > > > pq;
	set<pair<int, pair<int, int> > > s;
	pq.push(make_pair(A[X - 1] + B[Y - 1] + C[Z - 1], make_pair(X - 1, make_pair(Y - 1, Z - 1))));
	s.insert(make_pair(X - 1, make_pair(Y - 1, Z - 1)));

	for (int i = 0; i < K; i++){
		printf("%lld\n", pq.top().first);
		pair<int, pair<int, int> > key = pq.top().second;
		pq.pop();
		if (0 != key.first && s.end() == s.find( make_pair(key.first - 1, make_pair(key.second.first,key.second.second))) ){
			pq.push(make_pair(A[key.first - 1] + B[key.second.first] + C[key.second.second], make_pair(key.first - 1, make_pair(key.second.first, key.second.second))));
			s.insert(make_pair(key.first - 1, make_pair(key.second.first, key.second.second)));
		}
		if (0 != key.second.first && s.end() == s.find(make_pair(key.first, make_pair(key.second.first-1, key.second.second)))){
			pq.push(make_pair(A[key.first] + B[key.second.first-1] + C[key.second.second], make_pair(key.first, make_pair(key.second.first-1, key.second.second))));
			s.insert(make_pair(key.first, make_pair(key.second.first-1, key.second.second)));
		}
		if (0 != key.second.second && s.end() == s.find(make_pair(key.first, make_pair(key.second.first, key.second.second-1)))){
			pq.push(make_pair(A[key.first] + B[key.second.first] + C[key.second.second-1], make_pair(key.first, make_pair(key.second.first, key.second.second-1))));
			s.insert(make_pair(key.first, make_pair(key.second.first, key.second.second-1)));
		}
	}

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

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


int main() {
    int A, B;
    cin >> A >> B;
    if (A >= 13) {
        cout << B << endl;
    }else if (6 <= A && A <= 12) {
        cout << B/2 << endl;
    }else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
typedef long long llong;
static const int MAX = 10;

int n, m;
int ans;
vector< vector<int> > M(MAX + 1);
int d[MAX + 1];

void dfs(int x){
    int check = 0;
    for (int i = 1; i <= n; i++){
        if (d[i] < 0) check++;
    }
    if (check == n){
        ans++;
        return;
    }

    for (int i = 0; i < M[x].size(); i++){
        if (d[M[x][i]] > 0){
            d[M[x][i]] = -1;
            dfs(M[x][i]);
            d[M[x][i]] = 1;
        }
    }
    return;
}

int main(){
    cin >> n >> m;
    int x, y;

    for (int i = 1; i <= n; i++) d[i] = 1;

    for (int i = 0; i < m; i++){
        cin >> x >> y;
        M[x].push_back(y);
        M[y].push_back(x);
    }
    ans = 0;
    d[1] = -1;
    dfs(1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
(h=Hash[q=[[$_.chop,0]]]
puts (while q[0]
s,c=q.shift
break c if s=~/^(r+|g+|b+)$/
(0..s.size-2).map{|i|s[i]!=s[i+1]&&(t=s.dup;t[i,2]="rgb".delete(t[i,2])*2;h[t]||=(q<<[t,c+1];0))}end)||:NA)while gets>?a

Measured memory_bytes: 8556