akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;
typedef vector<vector<LL>> mat;

mat mul(mat A,mat B){
    mat C(A.size(),vector<LL> (B[0].size()));
    for(int i=0;i<A.size();i++){
        for(int k=0;k<B.size();k++){
            for(int j=0;j<B[0].size();j++){
                C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod;
            }
        }
    }
    return C;
}

mat pow(mat A,LL n){
    mat B(A.size(),vector<LL> (A.size()));
    for(int i=0;i<A.size();i++){
        B[i][i]=1;
    }
    while(n>0){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}


int main(){
    int N;cin >> N;
    LL K;cin >> K;
    mat dp(N,vector<LL> (N));
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> dp[i][j];
        }
    }
    mat t=pow(dp,K-1);
    LL ans=0;
    for(int i=0;i<N;i++){
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                ans=(ans+dp[i][j]*t[j][k])%mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int cnt_t = (c + b - 1) / b;
    int cnt_a = (a + d - 1) / d;
    cout << (cnt_t <= cnt_a ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

int a[100], mod = 1e9+7;
signed main(){
  int n;string str;
  cin >> n >> str;
  rep(i,n)a[str[i]-'a']++;
  int ans = 1;
  rep(i,26){ans *= a[i]+1;ans %= mod;}
  cout << ans-1 << endl;
  return 0;
}





Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

const int mod = 1009;
int value[mod];
int cnt[mod];

int main(){
  while(int n = getInt()){
    int ans = -1;
    const int n2 = n / 2;

    for(int i = 0; i < mod; i++){
      value[i] = -1;
      cnt[i] = 0;
    }

    for(int i = 0; i < n; i++){
      int a = getInt();
      int m = a % mod;
      if(value[m] == -1) value[m] = a;
      if(++cnt[m] > n2) ans = a;
    }

    if(ans == -1)
      puts("NO COLOR");
    else
      printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 844
N=int(input())
An=[1 for _ in range(N)]
for i in range(N):
  An[i]=int(input())
Bn=sorted(An)
Max=Bn[-1]
Max2=Bn[-2]

for n in range(len(An)):
  if An[n]!=Max:
    print(Max)
  else:
    print(Max2)


Measured memory_bytes: 14120
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


class Dinic:
    def __init__(self, n):
        self.n = n
        self.G = [[] for _ in range(n)]
        self.level = None
        self.it = None

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [-1] * self.n
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] == -1:
                    level[w] = lv
                    deq.append(w)
        return level[t] != -1

    def dfs(self, v, t, f):
        if v == t:
            return f
        for e in self.it[v]:
            w, cap, rev = e
            if cap and self.level[v] < self.level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10 ** 18
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow

h, w = LI()
dinic = Dinic(h + w + 2)
s = SR(h)
for i in range(h):
    for j in range(w):
        if s[i][j] == 'o':
            dinic.add_multi_edge(i, h + j, 1, 1)
        elif s[i][j] == 'S':
            dinic.add_edge(h + w, i, INF)
            dinic.add_edge(h + w, h + j, INF)
        elif s[i][j] == 'T':
            dinic.add_edge(i, h + w + 1, INF)
            dinic.add_edge(h + j, h + w + 1, INF)

ans = dinic.flow(h + w, h + w + 1)
print(ans if ans < INF else -1)

Measured memory_bytes: 48476
import java.util.*;
import java.io.*;
class Main{
	public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out, true);
		int n = in.nextInt();
		int base = 1000;
		int ans = 0;
		for(int i=1;;i++){
			int cash = base*i;
			if(cash >= n){
				ans = cash - n;
				break;
			}
		}
		out.println(ans);
	}
}	


Measured memory_bytes: 35908
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,m;
  cin >> n >> m;
  ll ans=0;
  if(2*n>m) {
    ans=m/2;
  }
  else {
    m-=2*n;
    ans=n+m/4;
  }
  cout << ans << endl;
}

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

int main(){
    int n;
    scanf("%d", &n);
    vector<int>v;
    for(int i = 0; i < n; i++){
        int z;
        scanf("%d", &z);
        z--;
        v.push_back(z);
    }
    int now = 0, c = 0;
    for(;;){
        if(now ==  1){
            printf("%d\n", c);
            break;
        }
        if(c >= n){
            printf("-1\n");
            break;
        }
        c++;
        now = v[now];
    }
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
#define INF 1000000000
#define MOD 1000000007
 
using namespace std;

 ll mod=1e9+7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}

ll expo2(ll base,ll exponent)
{
	ll ans=1;
	while(exponent!=0)
	{
		if(exponent & 1) ans=(1LL*ans*base);
		base=(1LL*base*base);
		exponent>>=1;
	}
	return ans;
}

vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}


int main()
{
    
    // #ifndef ONLINE_JUDGE
    //     freopen ("data.in","r",stdin);
    //     freopen ("E.out","w",stdout);
    // #endif
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // Sieve();
    int tests=1;
    // cin>>tests;
    while(tests--)
    {	
    	ll i,j,n,sum=0;
    	cin>>n;
    	vector<ll>a(n);
    	rep(i,0,n-1) {cin>>a[i];sum+=a[i];}
    	ll ans=0;
    	rep(i,0,n-1)
    	{
    		sum-=a[i];
    		ans+=(a[i]*((sum)%mod))%mod;
    		ans%=mod;
    	}
    	cout<<ans;
    }
    	return 0;
    
}

Measured memory_bytes: 15876
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;

#define rep(i,a) for(int i=0;i<(a);++i)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

int parse(string str)
{
    int ret = 0;
    int tmp = 1;
    for(int j = 0; j < str.size();)  {
        if(str[j] >= '2' &&  str[j] <= '9') {
            if(tmp == 1) {
                tmp = str[j] - '0';
            } else {
                tmp = tmp * 10 + (str[j] - '0');
            }
            j++;
        } else {
            if(str[j] == 'm') {
                ret += tmp * 1000;
            } else if(str[j] == 'c') {
                ret += tmp * 100;
            } else if(str[j] == 'x') {
                ret += tmp * 10;
            } else {
                ret += tmp;
            }
            j++;
            tmp = 1;
        }
    }
    return ret;
}

string comp(int num)
{

    string ret = "";
    
    int tmp;
    tmp = num / 1000;

    if(tmp == 1) {
        ret = ret + "m";
    } else if(tmp >= 2) {
        ret = ret + string(1, '0' + tmp) + "m";
    }

    num = num % 1000;
    tmp = num / 100;

    if(tmp == 1) {
        ret = ret + "c";
    } else if(tmp >= 2) {
        ret = ret + string(1, '0' + tmp) + "c";
    }

    num = num % 100;
    tmp = num / 10;

    if(tmp == 1) {
        ret = ret + "x";
    } else if(tmp >= 2) {
        ret = ret + string(1, '0' + tmp) + "x";
    }

    num = num % 10;
    tmp = num;

    if(tmp == 1) {
        ret = ret + "i";
    } else if(tmp >= 2) {
        ret = ret + string(1, '0' + tmp) + "i";
    }

    return ret;
    
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        string a, b;
        cin >> a >> b;
        
        int ai, bi, sum;
        ai = parse(a); bi = parse(b);
        //cout << ai << " " << bi << endl;
        sum = ai + bi;
        
        //cout << sum << endl;
        
        cout << comp(sum) << endl;
    }
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	string s;
	string t;
	int count = 0;

	cin >> s;
	while (1) {
		cin >> t;
		if (t == "END_OF_TEXT") {
			break;
		}else{
			transform(t.begin(), t.end(), t.begin(), ::tolower);
			if (s == t) {
				count++;
			}
		}

	}

	cout << count << endl;


	
	return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
int a[200010];
int flag[200010];
int main() {
  long long n, k;
  cin >> n >> k;
  for(int i = 1; i <= n; i++) cin >> a[i];
  
  int pos = 1, cnt = 0;
  while(k) {
    pos = a[pos];
    k--;
    cnt++;
    if(flag[pos]) k %= (cnt-flag[pos]);
    else flag[pos] = cnt;
  }
  cout << pos << "\n";
}

Measured memory_bytes: 5192
#include<bits/stdc++.h>
int main()
{
    long long int i,j,l,m,n,p;
    scanf("%lld%lld%lld",&m,&n,&p);
    if(p>=m)
    {
        printf("0");
        p=p-m;
    }
    else
    {

        m=m-p;
        printf("%lld",m);
        p=0;
    }
    printf(" ");
    if(p>=n)
    {
        printf("0");
    }
    else
    {
        n=n-p;
        printf("%lld",n);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
/*
 *  author : Atul Anand   
 *  created on : Sat Mar 28 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        String s = in.next();
        if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)){
            println("Yes");
        }
        else{
            println("No");
        }
        
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main(){long long n,a,b,c,m,d,k;
cin>>n>>a>>b;
c=(n/(a+b));
m=(n%(a+b));
if(m>=a)
d=a;
else
d=m;
k=c*a+d;
cout<<k;


  return 0;
}


Measured memory_bytes: 256
<?php
const MOD = 10 ** 9 + 7;
list($n, $k) = ints();
$ans = 0;
init($n);
for ($i = 0; $i <= min($k, $n - 1); ++$i)
    $ans = modAdd($ans, modMul(nCr2($n, $i), nCr2($n - 1, $n - $i - 1)));
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// SUM
function modSum(...$xs)
{
    $res = 0;
    foreach ($xs as $x) $res = modAdd($res, $x);
    return $res;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// PRODUCT
function modProd(...$xs)
{
    $res = 1;
    foreach ($xs as $x) $res = modMul($res, $x);
    return $res;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modMul(nPr($n, $r - 1), $n - $r + 1);
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}

// 階乗、逆元を前処理
function init($n)
{
    global $fact, $ifact;
    $fact[0] = 1;
    for ($i = 1; $i <= $n; ++$i) $fact[$i] = modMul($fact[$i - 1], $i);
    $ifact[$n] = modDiv(1, $fact[$n]);
    for ($i = $n; $i >= 1; --$i)
        $ifact[$i - 1] = modMul($ifact[$i], $i);
}

// 順列（前処理）
function nPr2($n, $r)
{
    global $fact, $ifact;
    return modMul($fact[$n], $ifact[$n - $r]);
}

// 組み合わせ（前処理）
function nCr2($n, $r)
{
    global $fact, $ifact;
    return modMul(modMul($fact[$n], $ifact[$r]), $ifact[$n - $r]);
}


Measured memory_bytes: 34252
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] a = new int[N];
        int ans = 0;

        for(int i=0; i<N; i++){
            a[i] = sc.nextInt();
            ans += a[i] -1;
        }
        System.out.println(ans);
    }
}

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

template<class Monoid> struct SegmentTree {
    using Function = function< Monoid(Monoid, Monoid) >;

    int N; vector<Monoid> segment;
    const Function func;
    const Monoid id;

    SegmentTree(int n, const Function func, const Monoid id) : func(func), id(id) {
        N = 1;
        while (N < n) N <<= 1;
        segment.assign(2 * N, id);
    }

    void set(int num, Monoid x) {
        segment[N + num] = x;
    }
    void build() {
        for (int k = N - 1; k > 0; k--) {
            segment[k] = func(segment[2*k], segment[2*k+1]);
        }
    }
    void update(int k, Monoid x) {
        k = k + N; segment[k] = x;
        while(k >>= 1) {
            segment[k] = func(segment[2*k], segment[2*k+1]);
        }
    }

    // query:[a, b)
    Monoid query(int a, int b) {
        Monoid L = id; Monoid R = id; a += N; b += N;
        for (; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = func(L, segment[a++]);
            if (b & 1) R = func(segment[--b], R);
        }
        return func(L, R);
    }
    // 0-based numbering;
    Monoid operator[](const int k) const {
        return segment[N+k];
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n+1), p(n+1, 0), u(n+1, 0);
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (n == 2) {
        if (a[1] == 2 && a[2] == 1) cout << -1 << "\n";
        else {
            if (a[1] == 2) cout << 2 << " " << 1 << "\n";
            else cout << 1 << " " << 2 << "\n";
        }
        return 0;
    }
    for (int i = 1; i <= n; i++) if (i != a[i]) p[a[i]]++;
    using dat = pair<int, int>;
    SegmentTree<dat> s(n+1, [](dat a, dat b){return max(a, b);}, {-1, -1e9});
    for (int i = 1; i <= n; i++) {
        s.set(i, {p[i], -i});
    }
    s.build();
    vector<int> v;
    int curr = 1;
    for (int i = 0; i < n-3; i++) {
        while (u[curr]) curr++;
        auto maxi = s.query(0, n+1);
        //cout << maxi.first << " " << maxi.second << "\n";
        int x = curr;
        if (i && a[v[i-1]] == x) {
            x++;
            while (u[x]) x++;
        }
        if (maxi.first >= (n-i-1)) x = -maxi.second;
        v.emplace_back(x);
        u[x] = true;
        auto y = a[x];
        auto z = s[y];
        s.update(x, {-1, -1e9});
        if (!u[y]) s.update(y, {z.first-1, z.second});        
    }
    vector<int> w;
    for (int i = 0; i < 3; i++) {
        auto maxi = s.query(0, n+1);
        w.emplace_back(-maxi.second);
        s.update(-maxi.second, {-1, -1e9});
    }
    sort(w.begin(), w.end());
    do {
        if (!v.empty() && a[v.back()] == w[0]) continue;
        bool ok = true;
        for (int i = 0; i < 2; i++) {
            if (a[w[i]] == w[i+1]) ok = false; 
        }
        if (ok) break; 
    } while (next_permutation(w.begin(), w.end()));
    for (auto &x: w) v.emplace_back(x);
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << v[i];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 4600
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
const int MAX_N = 100000 + 2;
int dp[MAX_N];
vector<int> G[MAX_N];
bool seen[MAX_N];
vector<int> order;

void rec(int v) {
  seen[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int next = G[v][i];
    if (seen[next]) continue;
    rec(next);
  }
  order.push_back(v);
}

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  int N, M;
  cin >> N >> M;

  int x, y;
  for (int i = 0; i < M; i++) {
    cin >> x >> y;
    x--; y--;
    G[x].push_back(y);
  }

  fill(seen, seen + MAX_N, false);
  
  for (int v = 0; v < N; v++) {
    if (seen[v]) continue;
    rec(v);
  }
  reverse(order.begin(), order.end());

  fill(dp, dp + MAX_N, 0);
  
  for (int i = 0; i < order.size(); i++) {
    int v = order[i];
    for (int j = 0; j < G[v].size(); j++) {
      int vn = G[v][j];
      dp[vn] = max(dp[vn], dp[v] + 1);
    }
  }

  int ans = -1;
  for (int i = 0; i < order.size(); i++) ans = max(dp[i], ans);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var strs = new string[num];
        for (var i = 0; i < num; i++)
            strs[i] = ReadLine();
        var al = "abcdefghijklmnopqrstuvwxyz";
        var dic = new Dictionary<string, int>();
        for (var i = 0; i < al.Length; i++)
            dic[al.Substring(i,1)] = 100;
        for(var i = 0; i < num; i++)
        {
            var subdic = new Dictionary<string, int>();
            for(var j = 0; j < strs[i].Length; j++)
            {
                var s = strs[i].Substring(j, 1);
                if (subdic.ContainsKey(s)) subdic[s]++;
                else subdic[s] = 1;
            }
            for (var j = 0; j < al.Length; j++)
            {
                var a = al.Substring(j, 1);
                if (subdic.ContainsKey(a))
                    dic[a] = Min(dic[a], subdic[a]);
                else dic[a] = 0;
            }
        }
        var result = "";
        foreach(var d in dic)
            for (var i = 0; i < d.Value; i++)
                result += d.Key;
        WriteLine(result);
    }
}

Measured memory_bytes: 11232
#include <stdio.h>
#define n 100000
int sosu[100000];
int i,k;
//sosu[i]=1: i is prime
void sieve(){
  sosu[0]=0;
  sosu[1]=0;
  sosu[2]=1;
  int j=0;
  for(i=3;i<n;i++)sosu[i]=1;
  for(i=2;i<n;i++){
    if(sosu[i]==1){
      for(j=i*2;j<n;j+=i)sosu[j]=0;
    }
  }

}
int main(){
  sieve();
  int l;
  int j=0;
  unsigned char uch;
  scanf("%d", &l);
  int ans[55];
  for(i=0;i<n;i++){
    if(sosu[i]&&(i-1)%5==0)ans[j++]=i;
    if(j>l)break;
  }
  for(i=0;i<l;i++){
    printf("%d ", ans[i]);
  }
  int cnt=0;
  for(i=0;i<n;i++){
    if(sosu[i]){
      if((sosu[i]-1)%5==0){
        cnt+=1;
      }
    }
  }
  printf("\n");
  return 0;

}


Measured memory_bytes: 640
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] A =new int[N];
		int[] B = new int[N];
		boolean[] flag = new boolean[100001];
		flag[0] = true;
		flag[1] = true;

		int[]dp = new int[100001];
		dp[0] = dp[1] = 0;

		for(int i = 0; i < N; i++) {
			A[i] = scanner.nextInt();
			B[i] = scanner.nextInt();
		}
		for(int i = 2;i < 100001;i++){
			if(flag[i]){					//flag立ってたら前と一緒
				dp[i] = dp[i-1];
				continue;
			}
			if(!flag[(i+1)/2]){
				dp[i] = dp[i-1]+1;
			}else{
				dp[i] = dp[i-1];
			}
			for(int j = i*2;j < 100001;j+=i){			//倍数全部flag立てる
				flag[j] = true;
			}
		}
		for(int i = 0; i < N; i++) {
			System.out.println(dp[B[i]] - dp[A[i] - 1]);
		}

	}



}



Measured memory_bytes: 94992
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int dp[5000];
vector<int> v[5000];
int x[5000];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int p[n];
    rep(i,1,n){
        cin>>p[i];
        p[i]--;
        v[p[i]].push_back(i);
    }
    rep(i,0,n)cin>>x[i];
    queue<int> q;
    rep(i,0,n){
        if(v[i].size()==0)q.push(i);
    }
    int ans[n];
    int cnt[n];
    fill(cnt,cnt+n,0);
    while(q.size()>0){
        int now=q.front();q.pop();
        bool ok[v[now].size()+1][x[now]+1];
        memset(ok,false,sizeof ok);
        ok[0][0]=true;
        rep(i,0,v[now].size()){
            int ne=v[now][i];
            int mi=min(x[ne],dp[ne]-x[ne]);
            rep(j,0,x[now]+1){
                if(j+mi>x[now])break;
                if(j+x[ne]<=x[now])ok[i+1][j+x[ne]]|=ok[i][j];
                if(j+dp[ne]-x[ne]<=x[now])ok[i+1][j+dp[ne]-x[ne]]|=ok[i][j];
            }
        }
        ans[now]=-1;
        rrep(i,x[now],0){
            if(ok[v[now].size()][i]){
                ans[now]=x[now]-i;
                break;
            }
        }
        if(ans[now]==-1){
            cout<<"IMPOSSIBLE"<<endl;
            return 0;
        }
        dp[now]+=ans[now];
        if(now==0)break;
        dp[p[now]]+=dp[now];
        cnt[p[now]]++;
        if(cnt[p[now]]==v[p[now]].size())q.push(p[now]);
    }
    //rep(i,0,n)cout<<ans[i]<<" ";
    cout<<"POSSIBLE"<<endl;
}





Measured memory_bytes: 640
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define ll long long int
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)

using namespace std;
using mii=map<int, int>;
using mll=map<ll, ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int mod = 1000000007;

ll desc(ll x, ll y)
{
    return x > y;
}

int main() {
    fastIO
    int n, i;
    cin >> n;

    vi a(n, 0);
    fo(i, n)
    cin >> a[i];

    int j = 0;

    int ans = INT_MAX;
    ll s2 = accumulate(a.begin(), a.end(), 0);
    ll s1 = 0;

    for(i = 0; i < n; ++i)
    {
        s1 += a[i];
        s2 -= a[i];
        int temp = (int)abs(s2 - s1);
        ans = min(ans, temp);
    }

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

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

#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(c,x)       ((c).find(x) != (c).end())
#define isp(c,x)      (find(all(c),x) != (c).end())
#define pb             push_back
#define ppb            pop_back
#define sz(x)          (int)x.size()
#define fill(a,v)      memset(a, v, sizeof a)
#define fs first
#define sc second
#define ub upper_bound
#define lb lower_bound
#define en '\n'

typedef long long int lli;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair< int, int > pii;
typedef pair< lli, lli > plli;
typedef list<int> li;
typedef map<int, int> mi;
typedef map<lli, lli> mlli;
lli gcd(lli a,lli b){return (!b)?a:gcd(b,a%b);}
int t = 1; int ti;



const int N1 = 1e2 + 5, N = 1e5 + 5;
lli dp[N1][N], n, mw, w[N1],v[N1];

void solve(){
    cin>>n>>mw;

    lli mv = 0;

    fori(i, 1, n){
        cin>>w[i]>>v[i];
        mv = max(mv, v[i]);        
    }

    mv *= n;

    fori(i, 0, n){
        fori(j, 0, mv){
            dp[i][j] = INT64_MAX;
        }
    }


    dp[0][0] = 0;


    fori(i, 1, n){
        dp[i][0] = 0;

        fori(j, 1, mv){
            if(j >= v[i] && dp[i-1][j-v[i]] < INT64_MAX){
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i]);
            }

            if(dp[i-1][j] < INT64_MAX){
                dp[i][j] = min(dp[i][j], dp[i-1][j]);
            }
        }
    }

    int mxv = 0;

    ford(i, mv, 0){
        if(dp[n][i] <= mw){
            mxv = max(mxv, i);
        }
    }

    cout<<mxv;

}
//THINK OF SPECIAL CASES, ARRAY LIMITS, LLI vs INT, 1LL

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

    // cin>>t;

    // for(ti= 1; ti <= t; ti++)
    solve();

//    cout<<"\nTHINK OF SPECIAL CASES, ARRAY LIMITS, LLI vs INT, 1LL";
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
typedef struct{ll to;ll cost;} Graphs;
typedef V<V<Graphs>> AdjList;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
   
  
  str s;
  cin>>s;
  SORT(s);
  if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2])out("Yes");
  else out("No");


  return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n,a,b,c;
vector<int>v[100010];
int vis[100010],cnt[100010];


void input(){
	cin>>n;
	c=n;
	for(int i=0;i<n-1;i++){
		cin>>a>>b;
		a--,b--;
		v[a].eb(b);
		v[b].eb(a);
	}
	return;
}

void solve(){
	queue<int>q;
	for(int i=0;i<n;i++){
		cnt[i]=v[i].size();
		if(cnt[i]==1){
			q.push(v[i][0]);
		}
	}
	while(!q.empty()){
		int p=q.front();
		q.pop();
		if(vis[p])continue;
		vis[p]=1;
		int sum=0;
		for(int u:v[p]){
			if(cnt[u]==1){
				sum++;
				vis[u]=2;
			}
			cnt[u]--;
			cnt[p]--;
			if(cnt[u]==1){
				for(int x:v[u]){
					if(!vis[x]){
						q.push(x);
						break;
					}
				}
			}
		}
		if(sum>=2){
			cout<<"First"<<endl;
			return;
		}
	}
	for(int i=0;i<n;i++){
		if(vis[i]==2){
			for(int u:v[i]){
				if(vis[u]==1)vis[u]=3;
			}
		}
	}
	for(int i=0;i<n;i++){
		if(vis[i]==1){
			cout<<"First"<<endl;
			return;
		}
	}
	cout<<"Second"<<endl;
	return;
}

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


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

int n,m,cap[300][300];
vector<bool> used(300);

int dfs(int v,int t,int f){
    if(v==t) return f;
    used[v]=true;
    rep(i,0,n){
        if(used[i] or !cap[v][i]) continue;
        int d=dfs(i,t,f);
        if(d>0){
            cap[v][i]-=d;
            if(!cap[i][v]) cap[i][v]+=d;
            return d;
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow=0;
    while(true){
        fill(used.begin(),used.end(),false);
        int f=dfs(s,t,1);
        if(f==0) return flow;
        flow+=f;
    }
}
void solve(){
    int s,t;
    cin >> n >> m;

    vector<pii> edges;
    rep(i,0,m){
        int x,y;
        cin >> x >> y;
        --x;
        --y;
        cap[x][y]=1;
        cap[y][x]=1;
        edges.emplace_back(make_pair(x,y));
    }
    cin >> s >> t;
    --s;
    --t;

    cout << max_flow(s,t) << endl;
    vector<int> ids;
    rep(i,0,m) if(cap[edges[i].first][edges[i].second] and !cap[edges[i].second][edges[i].first]) ids.emplace_back(i+1);
    cout << ids.size() << endl;
    for(const auto id:ids) cout << id << endl;
}

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

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

typedef pair<int, int> P;

int main() {
	int H, W;
	while (cin >> H >> W && H && W) {
		string *field = new string[H];
		for (int i = 0; i < H; i++)
			cin >> field[i];
		int x = 0, y = 0;
		vector<P> v;
		while (1) {
			v.push_back(make_pair(x, y));
			if (field[y][x] == '>')
				x++;
			if (field[y][x] == '<')
				x--;
			if (field[y][x] == '^')
				y--;
			if (field[y][x] == 'v')
				y++;
			if (field[y][x] == '.') {
				cout << x << " " << y << endl;
				break;
			}
			int loop = 0;
			vector<P>::iterator it = v.begin();
			while (it != v.end()) {
				if (it->first == x && it->second == y) {
					cout << "LOOP" << endl;
					loop = 1;
					break;
				}
				it++;
			}
			if (loop)
				break;
		}
		delete[] field;
	}
	return 0;
}

Measured memory_bytes: 1236
/*
 ***
 Question Name:
 ***
 Question Link:
 
 ***
 Idea:
 */

#include <memory.h>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef unordered_set<int> ui;
typedef pair<LL,LL> pLL;

long K;
int main(){
    int N = 50;
    cin>>K;
    vL ans(N);
    for(int i=0;i<N;++i) ans[i] = i + K/N;
    for(int i=0;i<K%N;++i) ans[N-1-i]++;
    cout<<N<<endl;
    for(auto k:ans) cout<<k<<' ';
    cout<<endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    string zen,kou,r_zen,r_kou,r_s;
    zen = s.substr(0,(s.size()-1)/2);
    r_zen = zen;
    reverse(r_zen.begin(),r_zen.end());
    kou = s.substr(((s.size()+3)/2)-1,(s.size()-1)/2);
    r_kou = kou;
    reverse(r_kou.begin(),r_kou.end());
    r_s = s;
    reverse(r_s.begin(),r_s.end());
    if(zen == r_zen && kou == r_kou && s == r_s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

"""
crt = 0
ttl = 0
for i in range(n,0,-1):
  crt += a[i]
  ttl+= crt
  print(crt)
  crt = crt // 2 + crt % 2
  print("next:{}".format(crt))
if crt!=1:
  print(-1)
else:
  print(ttl)
"""

ans = 0
ls = [0 for _ in range(n+1)]
crt = 1
ttl = 1
for i,l in enumerate(a):
  ls[i] = crt
  if crt - l < 0:
    ans =-1
    break
  if i == n:
    break
  crt = (crt-l)*2
  #print("crt{}".format(crt))
  ttl += crt
  #print("ttl{}".format(ttl))

crt = 0
for i in range(n,0,-1):
  #print("ls")
  #print(ls[i])
  #print(a[i])
  #print(crt)
  if ls[i] - a[i] - crt > 0:
    ttl -= (ls[i] - a[i] - crt)
    crt = a[i] + crt
  else:
    crt = ls[i]

if ans == -1:
  print(ans)
else:
  print(ttl)


Measured memory_bytes: 674324
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;


// sortの仕方
// 	■ string s の場合
// 	昇順: sort(s.begin(), s.end())
// 	降順: sort(s.rbegin(), s.rend())
//
// 	■ ll a[N] の場合
// 	昇順: sort(a, a+N)
// 	降順: 不明

// vector の使い方
// 宣言：
// vector<int> v;
// vector<int> v(N);
// 初期化:
// vector<int> v(10, 5); 要素数10，全ての要素の値5．
// vector<int> v = {1, 2, 3};
// 代入：
// v[0] = 3;
// sort:
// sort(v.begin(), v.end());
//

// int alph2int(char character) {
//     int x = character - 'a';
//     return x;
// }

ll my_gcd(ll a, ll b){
	return (b==0) ? a : my_gcd(b, a%b);
}

ll my_lcm(ll a, ll b){
	return a*b / my_gcd(a,b);
}

ll factorial(ll a){
	ll ans = 1;
	for(ll i=a; i>0; i--){
		ans *= i;
	}
	return ans;
}

ll pow(ll a, ll b) {
	ll a_powered = 1;
	for (int i=0; i<b; i++) {
		a_powered *= a;
	}
	return a_powered;
}


int main(int argc, char *argv[]){
    int N;
    cin >> N;

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

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

    int sum = 0;
    for(int i=0; i<N-1; i++){
        sum += L[i];
    }

    if(sum > L[N-1]){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int M=max(a,max(b,c));
    if(a==M){
        cout<<a*pow(2,k)+b+c<<endl;
    }else if(b==M){
        cout<<a+b*pow(2,k)+c<<endl;
    }else{
        cout<<a+b+c*pow(2,k)<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  cout << min(c, b / a) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>

using namespace std;
using ll=long long;

#define PRI(n) cout << n <<endl;
#define PRI2(n, m) cout << n << " " << m << endl;
#define PRI3(n, m, o) cout << n << " " << m<< " " << o << endl;

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

#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)
#define FORInv(i, t, n)  for(int i = t; i >= (int)n; --i)

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) FORInv (j, min(i, r), 1)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}

struct edge {
    int to, cost;
    bool flag = false;
};
int N, M;
string S;
vector<edge> X[100010];
bool B[100010];
int D[100010];
char C[] = {'U','D','L','R'};
int main() {
    int sx, tx, sy, ty;
    cin >> sx >> sy >> tx >> ty;
    REP(i,ty-sy)cout << "U";
    REP(i,tx-sx)cout << "R";
    REP(i,ty-sy)cout << "D";
    REP(i,tx-sx)cout << "L";

    cout << "L";
    REP(i,ty-sy+1)cout << "U";
    REP(i,tx-sx+1)cout << "R";
    cout << "D";
    cout << "R";
    REP(i,ty-sy+1)cout << "D";
    REP(i,tx-sx+1)cout << "L";
    cout << "U"<<endl;
    return 0;

}

Measured memory_bytes: 2560
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, H: int, W: int):
    print((N-H+1) * (N-W+1))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(N, H, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5336