akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
grid = ["" for i in range(H)]
ans = [[0 for j in range(W)] for i in range(H)]

moves = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1)]

for i in range(H):
    grid[i] = input()
    
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            ans[i][j] = "#"
        else:
            count = 0
            for x, y in moves:
                cur_x = i + x
                cur_y = j + y
                if 0 <= cur_x and cur_x < H and 0 <= cur_y and cur_y < W and grid[cur_x][cur_y] == "#":
                    count += 1
            ans[i][j] = count
            
for i in range(H):
    print("".join(list(map(str, ans[i]))))

Measured memory_bytes: 3064
from collections import deque
import copy

def cha(maze,h,w):
    maze = copy.deepcopy(maze)
    for i in range(h):
        for j in range(w):
            if maze[i][j] == ".":
                maze[i][j] = 10**10
            if maze[i][j] == "#":
                maze[i][j] = -1
    return maze

def bfs(maze,sy,sx):
    maze = copy.deepcopy(maze)
    maze[sy][sx] = 0
    que = deque([[sy,sx]])
    while que:
        y,x = que.popleft()
        for next_y,next_x in [(y+1,x),(y-1,x),(y,x+1),(y,x-1)]:
            if maze[next_y][next_x] == -1:
                continue
            dist = maze[next_y][next_x]
            if dist > maze[y][x] + 1:
                maze[next_y][next_x] = maze[y][x] + 1
                que.append([next_y,next_x])
    return maze

def search(maze):
    c = 0
    for i in maze:
        i.append(c)
        c = max(i)
    return c

def _main():
    h,w = map(int,input().split())
    maze = [["#"]*w]
    for _ in range(h):
        maze.append(list(input()))
    maze.append(["#"]*w)
    for i in range(h+2):
        maze[i].insert(0,"#")
        maze[i].insert(w+1,"#")
    C = 0
    for sy in range(h+2):
        for sx in range(w+2):
            if maze[sy][sx] == ".":
                C = max((search(bfs(cha(maze,h+2,w+2),sy,sx)),C))
    print(C)

if __name__=="__main__":
    _main()



Measured memory_bytes: 54236
n, m = gets.split.map(&:to_i)
done = {}
pens = {}
m.times do
  q, res = gets.split
  q = q.to_i

  if !done[q] == true
    if res == "AC"
      done[q] = true
    else
      if pens[q] != nil
        pens[q] += 1
      else
        pens[q] = 1
      end
    end
  end
end

penres = 0
done.each do |doneq, res|
  qpen = pens[doneq]
  penres += pens[doneq] if qpen != nil
end
puts done.count.to_s + " " + penres.to_s

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

int main() {
	int n,ans;
	
	while(cin>>n){
		
		ans=n%39;
		
		if(ans==0)ans=39;
		
		if(ans/10==0){
			cout<<"3C0"<<ans<<endl;
		}else{
		cout<<"3C"<<ans<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3020
N = int(input())
P = [list(map(int, input().split())) for _ in range(N)]

flg = True
for p in P:
  t, x, y = p
  if t < x + y:
    flg = False
    break
  if t%2 != (x+y)%2:
    flg = False
    break

if flg:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 27300
#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 n,k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int sum = 0;
  rep(i, k) {
    sum += p[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 3588
/*
* @Author: _dp95
* @Date:   2020-04-04 09:44:27
*/
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

const int MAX = 1000*100 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

ll dp[101][MAX] ;
ll ar[MAX] ;

int main( ){
  timesaver ;
  ll n, k ;
  cin >> n >> k ;
  dp[0][0] = 1 ;
  for( ll i = 1 ; i <= n ; i++ )
    cin >> ar[i] ;
  for( ll i = 1 ; i <= n ; i++ ){
    for( ll j = 0 ; j <= k ; j++ ){
        int rem = j - ar[i]-1 ;
        dp[i][j] = ( dp[i-1][j] - (rem<0?0:dp[i-1][rem]) + MOD )%MOD ;
    }
    for( ll j = 1 ; j <= k ; j++ ){
        dp[i][j] += dp[i][j-1] ;
        if( dp[i][j] >= MOD )
            dp[i][j] %= MOD ;
    }
  }
  cout << dp[n][k] << nl ;
}

Measured memory_bytes: 78464
#include <stdio.h>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main(void) {
  int n, i, j, k, ans;
  scanf("%d", &n);
  ans = n;
  int p[n];
  rep(i, n) scanf("%d", &p[i]);
  sort(p, p + n, greater<int>());
  rep(i, n) {
    if(p[i] <= i + 1) {
      ans = i > p[i] ? i : p[i];
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2780
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                 as IM
import           Data.List
import qualified Data.Map                    as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
  [x, y] <- readInt
  let ans = length $ takeWhile (<= y) $ iterate (* 2) x
   in print ans


Measured memory_bytes: 380
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
int n,m;
ll D1[555][555];
ll D2[555][555];
ll go(string a,string b)
{
    for (int i = 0;i <= n;++i)
        for (int j = 0;j <= n;++j)
            D1[i][j] = (i * j ? D1[i - 1][j - 1] + (a[i - 1] == b[j - 1]) : 0);
    for (int i = 0;i <= n;++i)
        for (int j = 0;j <= n;++j)
            D2[i][j] = 1e18;
    D2[n][n] = 0;
    for (int i = n;i + 1;--i)
        for (int j = n;j + 1;--j)
        {
            if (i >= 1)
                D2[i - 1][j] = min(D2[i - 1][j],D2[i][j] + D1[i][j]);
            if (j >= 1)
                D2[i][j - 1] = min(D2[i][j - 1],D2[i][j] + D1[i][j]);
        }
    return D2[0][0];
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    fi>>n>>m;
    string s[1 << 20];
    for (int i = 1;i <= n;++i)
        fi>>s[i];
    string v[1 << 20];
    for (int i = 1;i <= n;++i)
        for (int j = 0;j < m;++j)
            v[j] += s[i][j];
    ll ans = 0;
    for (int i = 0;i < m - 1;++i)
        ans += go(v[i],v[i+1]);
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

Measured memory_bytes: 19584
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
int n, cnt[26];
string s;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    cin >> s;
    for(char c : s)
        cnt[c - 'a']++;
    ll ans = 1;
    for(int i = 0; i < 26; i++)
        ans *= cnt[i] + 1, ans %= mod;
    cout << (ans - 1 + mod) % mod << "\n";
    return 0;
}


Measured memory_bytes: 512
open System

let fizzbuzz n: uint64 =
    if n % 3 <> 0 && n % 5 <> 0 then uint64 n else uint64 0

[<EntryPoint>]
let main argv =
    seq { for i in 1 .. Console.ReadLine() |> int -> fizzbuzz i}
    |> Seq.sum
    |> printfn "%d"
    0


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

int main(){
    typedef pair<int, int> P;
    int h, w, d;
    cin >> h >> w >> d;
    vector<vector<P>> tree(h * w + 1);
    vector<P> start(d + 1);
    int x;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> x;
            if (x > d){
                tree[x - d].push_back({i, j});
            }
            else{
                start[x] = {i, j};
            }
        }
    }
    vector<int> distance(h * w + 1);
    for (int i = 1; i <= d; i++){
        distance[i] = 0;
        if (i + d <= h * w) distance[i + d] = abs(start[i].first - tree[i][0].first) + abs(start[i].second - tree[i][0].second);
        for (int j = i + d; j + d <= h * w; j += d){
            distance[j + d] = distance[j] + abs(tree[j - d][0].first - tree[j][0].first) + abs(tree[j - d][0].second - tree[j][0].second);;
        }
    }
    
    int q;
    cin >> q;
    int l, r;
    for (int i = 0; i < q; i++){
        cin >> l >> r;
        cout << distance[r] - distance[l] << endl;
    }
}


Measured memory_bytes: 6400
import sys,bisect
input = sys.stdin.readline


def main():
    n = int(input())
    a = tuple(map(int,input().split()))
    b = tuple(map(int,input().split()))


    res = 0
    p = 0

    for i in range(1,30):
        p += 1<<(i-1)
        A = []
        B = []

        for j in range(n):
            A.append(a[j]&p)
            B.append(b[j]&p)
        A.sort()
        B.sort()

        cnt = 0

        q2 = p+1
        q1 = q2>>1
        q3 = q2<<1

        k1,k2,k3,k4 = 0,0,0,0

        for j in range(n-1,-1,-1):
            while k1 < n and A[j]+B[k1] < q1:
                k1 += 1
            while k2 < n and A[j]+B[k2] < q2:
                k2 += 1
            while k3 < n and A[j]+B[k3] < 3*q1:
                k3 += 1
            while k4 < n and A[j]+B[k4] < q3:
                k4 += 1
            cnt += k4 + k2 - k1 - k3

        
        if cnt%2 != 0:
            res += 1<<(i-1)

    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 139660
#include <stdio.h>

/* 配列の要素を順番に出力 */
void trace(int A[],int N) {
    int i;
    for(i=0;i<N;i++) {
        /* 隣接する要素の間に1つの空白を出力 */
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
	puts("");
}

/* 挿入ソート(0オリジン配列) */
void insertionSort(int A[], int N) {
    int i,j,v;
    for(i=1;i<N;i++) {
        v=A[i];
        j=i-1;
        while(j>=0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}

int main(void)
{
    int N, i;
    int A[100];
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);
    
    trace(A,N);
    insertionSort(A,N);
    return 0;
}


Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define scl(x) scanf("%lld",x);
int n,m,i,c[100005],a,b,v,k,t[100005];
set<int> g[100005];
vector<int>first_half;
vector<int>second_half;
vector<int>total;
int par[209],group[209];
int arra[150000];
vector<int>arr;
map<char,int>cp;
map<ll,ll>mp;
deque<char>stp1;
deque<char>stp2;
map<int,int>pos;
map<string,int>check;
map<string,string>server;
vector<string>ans1;
vector<string>ans2;
vector<string>ans3;
string server1[1009];
string ip1[1009];
string server2[1009];
string ip2[1009];
ll cashier[109];
ll fir[10009];
ll sec[100009];
ll dice[109];
vector<ll>element;
map<ll,ll>skysc;
map<string,ll>iteams;
map<ll,ll>equal1;
map<ll,ll>equalcnt;
ll complete[200009][29];
map<ll,ll>vis_pos;
map<char,ll>haiku;
vector<string>original;
vector<string>sorted;
vector<char>stps;
map<string,ll>mps;
map<string,ll>cnteql;
map<string,ll>eql;
deque<char>tem;
map<string,ll>tot;
map<string,ll>vislr;
vector<ll>arry;
vector<ll>colr;
vector<ll>primes;
vector<ll>primesdiv;
map<ll,ll>summand;
map<ll,ll>vps;
map<ll,ll>cnt;
ll solve[200009][4];
int main()
{
  ll a=4,b=0,c,d,e,f,g,h=2,i,j,k,l,p,q,r=10,s,t,m,n,sum=0,x;
  string str;
  cin>>d;
  cin>>str;
  n=str.size();
  for(i=0;i<min(n,d);i++)
  {
     cout<<str[i];	
  }
  if(n>d)
    cout<<"...";

  
  
  
   
   
  
     
     	
  	
}

Measured memory_bytes: 8440
D=int(input())
c=list(map(int,(input().split())))
s=[]
t=[]
last=[0]*26
sat=0

for i in range(D):
  s.append(list(map(int,(input().split()))))
  for day in range(26):
    if(last[day]!=0):
      last[day]+=1

  for j in range(26):
    for k in range(26):
      s[i][j]-=c[k]*(1-last[k])
  sat+=max(s[i])+c[s[i].index(max(s[i]))]
  last[s[i].index(max(s[i]))]=1
  ans=s[i].index(max(s[i]))+1
  print(ans)

Measured memory_bytes: 9240
#include<stdio.h>

int main(void){
	double a, b, c, d, e, f;
	double x, y;
	
	
	while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){

		y = ((c*d) - (a*f)) / ((b*d) - (a*e));

		x = (c - b*y) / a;

		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    string S;
    cin >> S;
    int ans = 0;
    for(int i = 0; i < S.size(); i++){
        ans += (S[i] != S[S.size() - i - 1]);
    }
    cout << ans / 2 << endl;
}



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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
constexpr double EPS = 1e-10;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}

void solve() {
    double a, b, x;
    cin >> a >> b >> x;
    if (a * a * b / 2 < x) {
        cout << atan2((2 * b) - ((2 * x) / (a * a)), a) * 180 / M_PI<< EOL;
    } else {
        cout << atan2(b, (2 * x) / (a * b)) * 180 / M_PI << EOL;
    }
}



Measured memory_bytes: 512
#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;
    int ans=b;
    if(6<=a && a<=12){
        ans/=2;
    }else if(a<6){
        ans=0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int[] arr = new int[3];

    for (int i = 0; i < arr.length; i++) {
      arr[i] = sc.nextInt();
    }

    Arrays.sort(arr);

    System.out.println((arr[2] * 10) + arr[1] + arr[0]);

  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> S;
    int balance = 0;

    vector<pair<int, int>> pos_S, zero_S, neg_S;
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        int inner_balance = 0;
        int min_inner_balance = 0;
        for(int j=0;j<s.size();j++){
            if(s[j] == '('){
                inner_balance++;
            }else{
                inner_balance--;
            }
            min_inner_balance = min(min_inner_balance, inner_balance);
        }
        balance += inner_balance;
        if(inner_balance > 0){
            pos_S.emplace_back(min_inner_balance, inner_balance);
        }else if(inner_balance == 0) {
            zero_S.emplace_back(min_inner_balance, 0);
        }else{
            neg_S.emplace_back(min_inner_balance - inner_balance, -inner_balance);
        }
    }
    if(balance != 0){
        cout << "No" << endl;
        return 0;
    }

    int balance_left = 0;
    sort(pos_S.begin(), pos_S.end(), greater<pair<int, int>>());
    for(auto& p : pos_S){
        int min_innser_balance, inner_balance;
        tie(min_innser_balance, inner_balance) = p;
        if(balance_left + min_innser_balance < 0){
            cout << "No" << endl;
            return 0;
        }
        balance_left += inner_balance;
    }

    for(auto& p : zero_S){
        if(balance_left + p.first < 0){
            cout << "No" << endl;
            return 0;
        }
    }

    int balance_right = 0;
    sort(neg_S.begin(), neg_S.end(), greater<pair<int, int>>());
    for(auto& p : neg_S) {
        int min_innser_balance, inner_balance;
        tie(min_innser_balance, inner_balance) = p;
        if (balance_right + min_innser_balance < 0) {
            cout << "No" << endl;
            return 0;
        }
        balance_right += inner_balance;
    }
    // unnecessary?
    if(balance_left != balance_right){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 11332
def main():
    s = input()
    n = len(s) - 1
    f = s[0]
    for i in range(2**n):
        for j in range(n):
            if (i >> j) & 1:
                f += '+'
            else:
                f += '-'
            f += s[j+1]
        # print(f)
        if eval(f) == 7:
            print(f + '=7')
            break
        f = s[0]

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int a;
    cin >> a;
    int ans = 0;
    ans += a;
    ans += a*a;
    ans += a*a*a;
    cout << ans << endl;
}

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

int main() {
	int n, m, a;
	cin >> n >> m;
	int city[51] = {0};
	for(int i = 0; i < m * 2; i++){
		cin >> a;
		city[a-1]++;
	}
	for(int i = 0; i < n; i++){
		cout << city[i] << endl;
	}
	
	return 0;
}

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

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    long long n, a, b;
    cin >> n >> a >> b;

    if(a > b){
        swap(a, b);
    }

    if(abs(a-b) % 2 == 0){
        cout << abs(a-b)/2 << "\n";
    } else{
        cout << min( a + abs(1-b + a)/2, n - b + 1 + abs(a - b + 1)/2);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
typedef long long ll;
using namespace std;
long long int n,cnt=0,ans=0,a[100005],sum=0,pos,k;
int main(void){
      cin>>n>>k;
      ll ma=0;
      rep(i,n){
        cin>>a[i];
        ma=max(ma,a[i]);
      }
      if(ma<k)cout<<"IMPOSSIBLE"<<endl;
      else{
        pos=a[0];
        rrep(i,1,n){
          pos=__gcd(pos,a[i]);
        }
        if(k%pos==0)cout<<"POSSIBLE"<<endl;
        else cout<<"IMPOSSIBLE"<<endl;
      }
}


Measured memory_bytes: 1024
import sys
import bisect
input = sys.stdin.readline


def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    
    l, r = -1, 10**6
    while r-l > 1:
        k = (r+l)//2
        count = 0
        for i in range(n):
            count += n-bisect.bisect_left(a, k-a[i])
        
        if count > m:
            l = k
        else:
            r = k
    ans = 0
    count = 0
    b = [0]*(n+1)
    for i in range(n):
        b[i+1] += b[i]+a[i]
    for i in range(n):
        index = bisect.bisect_left(a, r-a[i])
        ans += b[n]-b[index]+a[i]*(n-index)
        count += n-index
    
    if count < m:
        ans += (m-count)*l
    
    print(ans)
    
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 83404
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

/*-----<Defines>-----*/
#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)size(x))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     flush           fflush(stdout)

using ull=unsigned long long;
using ll=long long;
using ld=long double;
/*-----</Defines>-----*/

/*-----<Debugging Stuff>-----*/
string to_string(char s)
{   string res="'''";res[1]=s;return res; }

string to_string(string s)
{   return '"'+s+'"'; }

string to_string(const char* s)
{   return to_string((string)s); }

string to_string(bool b)
{   return (b?"true":"false"); }

template<typename A, typename B>
string to_string(pair<A, B> p)
{   return "("+to_string(p.F)+", "+to_string(p.S)+")"; }

template<typename A>
string to_string(A v)
{
    bool first=1; string res="{";
    for(const auto &x:v)
    {
        if(!first)  res+=", ";
        first=0;
        res+=to_string(x);
    }
    res+="}";
    return res;
}

void debug() { cout<<"\n"; }
template<typename Head, typename... Tail>
void debug(Head H, Tail... T)
{
    cout<<" "<<to_string(H);
    debug(T...);
}

#define show(...) cout << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
/*-----</Debugging Stuff>-----*/

/*-----<Mod Operations>-----*/
const int M=1e9+7;
inline int add(int a,int b,int p=M){ a=a+b; if(a>=p) a-=p; return a; }
inline int sub(int a,int b,int p=M){ a=a-b; if(a<0) a+=p; return a; }
inline int mul(int a,int b,int p=M){ a=(a*1ll*b)%p; return a; }
/*-----</Mod Operations>-----*/

/*-----<Constants>-----*/
const ld pi=acos(-1),eps=1e-9;
const ll inf=1e18;
const int N=1;
/*-----</Constants>-----*/

void solve()
{
    string s,t;
    cin>>s>>t;

    int ans=0;
    int n=sz(s);
    for(int i=0;i<n;++i)
    {
        if(s[i]!=t[i])
            ++ans;
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <string>
#include <cassert>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

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

  int N, M;

  cin >> N >> M;

  std::map<std::pair<int, int>, bool> mp;

  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b, a--, b--;

    mp[{a, b}] = mp[{b, a}] = true;
  }

  for (int i = 1; i < N - 1; ++i) {
    if (mp[{0, i}] && mp[{i, N - 1}]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;

  return 0;
}

Measured memory_bytes: 37760
h,n=map(int,input().split())
dp=[10**9]*(h+1)
dp[0]=0
for i in range(n):
    a,b=map(int,input().split())
    for j in range(h):
        k=min(j+a,h)
        dp[k]=min(dp[k],dp[j]+b)
print(dp[h])

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

int sugar[3005], water[3005];

struct swater {
    int s, w;
    bool operator < (const swater & a) {
        return 1.*s / w < 1.*a.s / a.w;
    }
};

int main() {
    int a[2], b[2], e, f;
    cin >> b[0] >> b[1] >> a[0] >> a[1] >> e >> f;
    b[0] *= 100; b[1] *= 100;
    sugar[0] = water[0] = 1;
    for (int i = 0; i < 2; i ++)
        for (int j = a[i]; j <= f; j ++)
            if (sugar[j - a[i]]) sugar[j] = 1;
    for (int i = 0; i < 2; i ++)
        for (int j = b[i]; j <= f; j ++)
            if (water[j - b[i]]) water[j] = 1;
    swater ans = {0, min(b[0], b[1])};
    for (int w = 0; w <= f; w ++)
        if (water[w]) {
            for (int s = 0; s + w <= f && s <= w / 100 * e; s ++)
                if (sugar[s] && ans < (swater) {s, w})
            ans = {s, w};
        }
    cout << ans.s + ans.w << " " << ans.s << endl;
    return 0;
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}


vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component


// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != 0) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}
// Combination
ll modcomb(ll n, ll r)
{
  if(n < r) return 0;
  ll res = fact(n);
  (res *= ppow(fact(r), M-2)) %= M;
  (res *= ppow(fact(n-r), M-2)) %= M;
  return res;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find
// Find()
int parent[N], ran[N];
int find(int x)
{
    if(parent[x]==x)return x;
    else return parent[x]=find(parent[x]);
}
// Union()
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;

    if(ran[x]<ran[y])
        parent[x]=y;
    else{
        parent[y]=x;
        if(ran[x]==ran[y])ran[x]++;
    }
}

// Main Code
ll dist[N];
vector<pair<int, ll>> gg[N];
void dfs2(int curr, int par, ll num)
{
  dist[curr] = num;
  for(auto x: gg[curr])
    if(dist[x.f] > (dist[curr]+x.s))
      dfs2(x.f, curr, dist[curr]+x.s);
}

int main()
{
  int n;
  cin>>n;
  rep(i, 1, n)
  {
    int u, v, c;
    cin>>u>>v>>c;
    gg[u].pb({v, c});
    gg[v].pb({u, c});
    dist[i] = INF;
  }
  dist[n] = INF;
  dist[n+1] = INF;
  int q, k;
  cin>>q>>k;
  dfs2(k, -1, 0);
  llt ans[q];
  int i = 0;
  while(q--)
  {
    int a, b;
    cin>>a>>b;
    ans[i] = dist[a] + dist[b];
    i++;
  }
  // repn(i, 1, n)
  //   cout<<dist[i]<<" ";
  // cout<<endl;
  rep(j, 0, i)
  cout<<ans[j]<<endl;
  return 0;
}


Measured memory_bytes: 40576
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = ((n) - 1); i >= (a); --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(NULL); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
// all_of
// partial_sum, adjacent_difference

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#include "Geometry.h"
#include "Matrix.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

LL N;

int Digit(LL n) {
	int cnt = 0;
	while (n > 0) {
		n /= 10;
		++cnt;
	}
	return cnt;
}

int main() {
	cin >> N;
	int ans = INF;
	for (LL i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			ans = min(ans, max(Digit(i), Digit(N / i)));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int N, K;

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

  int T = 2*K;
  vector<vector<vector<int>>> C(2, vector<vector<int>>(T, vector<int>(T, 0)));

  rep(i,N) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    C[c == 'B'][y%T][x%T]++;
  }

  vector<vector<vector<int>>> SC(2, vector<vector<int>>(T+1, vector<int>(T+1, 0)));
  rep(c, 2) rep(i,T) rep(j,T) {
    SC[c][i+1][j+1] = C[c][i][j] + SC[c][i+1][j] + SC[c][i][j+1] - SC[c][i][j];
  }

  // [x0, x1) x [y0, y1)
  auto rangeSum = [&](int c, int y0, int y1, int x0, int x1) {
    return SC[c][y1][x1] - SC[c][y0][x1] - SC[c][y1][x0] + SC[c][y0][x0];
  };

  int ans = 0;
  rep(i,T) rep(j,T) {
    int flip = (j < K) ^ (i < K);
    int x1 = (j+K) % T, x2 = j;
    if(x1 > x2)swap(x1, x2);
    int y1 = (i+K) % T, y2 = i;
    if(y1 > y2)swap(y1, y2);

    ans = max(ans,
              rangeSum(flip^1, 0, y1, 0, x1) + rangeSum(flip^0, 0, y1, x1, x2) + rangeSum(flip^1, 0, y1, x2, T) +
              rangeSum(flip^0, y1, y2, 0, x1) + rangeSum(flip^1, y1, y2, x1, x2) + rangeSum(flip^0, y1, y2, x2, T) +
              rangeSum(flip^1, y2, T, 0, x1) + rangeSum(flip^0, y2, T, x1, x2) + rangeSum(flip^1, y2, T, x2, T));
  }

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


Measured memory_bytes: 78848
a[3],b[3],w;main(s){for(;~scanf("%d%d%d",a,a+1,a+2);w++){qsort(a,3,4,"\x8b\7+\6\xc3");if(a[0]+a[1]<=a[2])break;s=a[2]*a[2]-a[0]*a[0]-a[1]*a[1];b[s<0?1:s>0?2:0]++;}printf("%d %d %d %d\n",w,b[0],b[1],b[2]);exit(0);}

Measured memory_bytes: 600
import math

def intMap(): return map(int,input().split())
def intList(): return list(map(int, input().split()))

a,b,h,m = intMap()

#degreeH = (h + m / 60) * 30
#degreeM = m * 6

radH = h * math.pi / 6 + m * math.pi / 360
radM = m * math.pi / 30

xH = a * math.sin(radH)
yH = -a * math.cos(radH)

xM = b * math.sin(radM)
yM = -b * math.cos(radM)

x2 = (xH-xM) * (xH-xM)
y2 = (yH-yM) * (yH-yM)
d = math.sqrt(x2+y2)

print(d)

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

using namespace std;

double dp[3000][3000];
int n;
double arr[3000];

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

     cin>>n;
	
	for(int i=1;i<=n;i++)
	{
	cin>>arr[i];
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
	dp[i][0]=(1.00-arr[i])*dp[i-1][0];
	dp[0][i]=0;
	}
	
	

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			dp[i][j]=dp[i-1][j]*(1.00-arr[i])+dp[i-1][j-1]*arr[i];
		}
	}
	double ans =0;
   for(int i=n/2+1;i<=n;i++)
   {
   	ans+=dp[n][i];
   }
   cout<<fixed<<setprecision(11)<<ans;
	

}

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

int N, M, K;
int FoB[100010] = {0};  //Friend or Block

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}
  void init(int n){ par.assign(n, -1); }

  int root(int x){
    if(par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }

  bool is_same(int x, int y){
    return root(x) == root(y);
  }

  bool merge(int x, int y){
    x = root(x); y = root(y);
    if(x == y) return false;
    if(par[x] < par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x){
    return -par[root(x)];
  }
};

int main(){
  cin >> N >> M >> K;
  int a, b, c, d;

  UnionFind uf(N+1);

  /*友達なら、ノード接続*/
  for(int i = 0; i < M; i++){ cin >> a >> b; FoB[a] += 1; FoB[b] += 1; uf.merge(a, b); }

  /*同連結成分なら、ブロック機能が活躍*/
  for(int i = 0; i < K; i++){ cin >> c >> d; if(uf.is_same(c, d)){FoB[c] += 1; FoB[d] += 1; } }

  for(int i = 1; i <= N; i++){ cout << uf.size(i) - FoB[i] - 1 << " "; }
  cout << endl;
  return 0;

}




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

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	int cnt = 0;

	for (int i = 0; i < 3; i ++) {
		if (s[i] == t[i]) {
			cnt ++;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N;
	char S[128];
	char ans[256];

	int left, right;
	int sLeft, sRight;

	int i, j;

	scanf("%d", &N);
	scanf("%s", S);
	
	left = 0;
	right = 0;
	sLeft = 0;
	sRight = 0;
	for (i = 0; i < N; i++){
		if (i > 0 && S[i - 1] == ')' && S[i] == '('){
			if (right > left){
				sLeft += (right - left);

				left = 0;
				right = 0;
			} else {
				left -= right;
				right = 0;
			}
		}

		if (S[i] == '(') left++;
		else right++;
	}
	if (left > right){
		sRight = left - right;
	} else {
		sLeft += right - left;
	}

	for (i = 0; i < sLeft; i++){
		ans[i] = '(';
	}
	for (j = 0; j < N; j++){
		ans[i + j] = S[j];
	}
	i += j;
	for (j = 0; j < sRight; j++){
		ans[i + j] = ')';
	}
	ans[i + j] = '\0';

	puts(ans);

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;
const int inf = 1e9;

struct info{
    int t,rt,c;
    info(int t, int rt, int c):t(t),rt(rt),c(c){}
    info(){}
    bool operator<(const info &a) const{
        return t < a.t;
    }
};

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<info> s(n);
        for(int i=0; i<n; i++){
            int t,c;
            cin >> t >> c;
            s[i] = info(t, t, c);
        }
        sort(s.begin(), s.end());

        deque<info> lane[2];
        for(int i=0; i<n; i++){
            lane[0].push_back(s[i]);
        }
        int ans = 0;
        while(!lane[0].empty() || !lane[1].empty()){
            int rt[2] = {(!lane[0].empty())? lane[0].front().rt: inf,
                         (!lane[1].empty())? lane[1].front().rt: inf};
            int rtmin = min(rt[0], rt[1]);
            vector<info> wait[2];
            for(int d=0; d<2; d++){
                if(rt[d] <= rt[1-d]){
                    while(!lane[d].empty() && lane[d].front().rt <= rtmin){
                        info f = lane[d].front();
                        lane[d].pop_front();
                        f.rt = f.t;
                        if(d == 1) f.c--;
                        if(f.c > 0) wait[1-d].push_back(f);
                    }
                }
                for(deque<info>::iterator itr=lane[d].begin(); itr!=lane[d].end(); itr++){
                    itr->rt -= rtmin;
                }
            }
            for(int d=0; d<2; d++){
                sort(wait[d].begin(), wait[d].end());
                for(int i=0; i<(int)wait[d].size(); i++){
                    lane[d].push_back(wait[d][i]);
                }
            }
            ans += rtmin;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3144
n = int(input())
H = list(map(int, input().split()))

if n == 1:
    print(0)
    exit()

A = [0] * (n - 1)
for i in range(n - 1):
    if H[i] >= H[i + 1]:
        A[i] = 1

B = [0] * (n - 1)
for i in range(1, n - 1):
    if A[i] == 1 and A[i - 1] == 1:
        B[i] = B[i - 1] + 1

ans = max(B)
if ans == 0:
    print(0)
else:
    print(ans + 1)


Measured memory_bytes: 14252
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int N;
    cin>>N;
    vector<int> p(N);
    REP(i,N){
        cin>>p[i];
        p[i]--;
    }

    vector<int> ta(N,1),tb(N,1);
    int cnt=1;
    REP(i,N){
        ta[p[i]]+=cnt;
        tb[p[i]]+=cnt;
        cnt++;
    }
    REP(i,N-1){
        ta[i+1]+=ta[i];
        tb[N-2-i]+=tb[N-1-i];
    }
    REP(i,N){
        cout<<ta[i];
        if(i!=N-1) cout<<" ";
        else cout<<endl;
    }

    REP(i,N){
        cout<<tb[i];
        if(i!=N-1) cout<<" ";
        else cout<<endl;
    }

}

Measured memory_bytes: 3828
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node{ int p, l, r, lef;};
struct Node T[MAX]; 

void print(int u){

  int i=T[u].p, depth = 0;
  while(i != NIL){
    i = T[i].p;
    depth++;
  }

  if(depth == 0)printf("node %d: parent = %d, depth = %d, root, ",u, T[u].p, depth );
  else if(T[u].l == NIL)printf("node %d: parent = %d, depth = %d, leaf, ",u, T[u].p, depth);
  else printf("node %d: parent = %d, depth = %d, internal node, ", u, T[u].p, depth);

  i = T[u].l;
  printf("[");

  if(i != NIL) printf("%d", i);
  while (i != -1) {
  i = T[i].r;
  if(i != NIL)printf(", %d", i);
  }
  printf("]\n");
}

int main(){
  int i, j, d, v, c, l, n;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }

  for ( i = 0; i < n; i++ ){

    scanf("%d %d", &v, &d);

    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
       T[c].p = v;

       if(j == 0)T[v].l = c;
      else if(j > 0)T[l].r = c;
       l = c;

    }
  }  

  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}

Measured memory_bytes: 2176
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

constexpr LL mod = 1e9 + 7;
constexpr LL MAX = 6000;

LL fac[MAX];
LL inv[MAX];

LL pow_mod(LL n, LL p) {
    LL ret = 1;
    while (p > 0) {
        if (p & 1) ret = (ret * n) % mod;
        n = (n * n) % mod;
        p >>= 1;
    }
    return ret;
}

void setup() {
    fac[0] = fac[1] = 1;
    inv[0] = pow_mod(fac[0], mod - 2);
    inv[1] = pow_mod(fac[1], mod - 2);
    for (LL i = 2; i <= MAX - 2; i++) {
        fac[i] = fac[i - 1] * i;
        fac[i] %= mod;
        inv[i] = pow_mod(fac[i], mod - 2);
    }
}

LL comb(LL n, LL r) {
    return fac[n] * inv[r] % mod * inv[n - r] % mod;
}

LL f2(LL n, LL k) {
    return comb(n + k - 1, k - 1);
}

LL f(LL n, LL k) {
    if (n < k) return 0;
    if (n == 0 && k == 0) return 1;
    if (k < 1) return 0;
    return f2(n - k, k);
}

int main() {

    LL N, K;
    cin >> N >> K;

    setup();

    for (LL k = 1; k <= K; k++) {
        LL blue = f(K, k);
        LL red = 0;
        red += f(N - K, k - 1);
        red %= mod;
        red += f(N - K, k);
        red %= mod;
        red += f(N - K, k);
        red %= mod;
        red += f(N - K, k + 1);
        red %= mod;
        LL ans = (blue * red) % mod;
        cout << ans << endl;
    }

}

































Measured memory_bytes: 384
valid = True
n = int(input())
ds = [int(i) for i in input().split()]
if(ds[0]!=0):
    valid = False
    print(0)
ds.sort()
count = []
c = 1
for i in range(len(ds)-1):
    if(not i==0 and ds[i]==0):
        valid = False
        print(0)
        break
    if(ds[i]==ds[i+1]):
        c += 1
    elif(ds[i]==ds[i+1]-1):
        count.append(c)
        c = 1
    else:
        valid = False
        print(0)
        break
count.append(c)

s = 1
for i in range(len(count)-1):
    s *= count[i]**count[i+1]

if(valid):
    print(int(s)%998244353)


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a, b, c; cin >> a >> b >> c;

	if (a == b) cout << c << endl;
	else if (b == c)cout << a << endl;
	else cout << b << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split()))

ans = 0
S = 0
X = 0
end = 0

for i in range(1, N+1):
  S -= A[i-1]
  X ^= A[i-1]
  if end == N:
    ans += end - i + 1
    continue
  if end < N:
    end += 1
  for j in range(end, N+1):
    S += A[j]
    X ^= A[j]
    if S != X:
      S -= A[j]
      X ^= A[j]
      end = j-1
      break
    if j == N:
      end = j
  ans += end - i + 1

print(ans)

Measured memory_bytes: 32080