akhauriyash/Code-Regression huggingface dataset:
/* 
  		!!~~~~~~~~~~~~~~~~~~     
  	#include < ~_~ Ajay > 
 	 	~~~~~~~~~~~~~~~~~~~~!!   
*/

#include<iostream>
#include<map>
#include<list>
#include<queue>
#include<vector>
#include<algorithm>
#include<climits>

using namespace std;

#define int long long
#define lmax LLONG_MAX
#define lmin LLONG_MIN
#define pb push_back
#define mp make_pair
#define f   first
#define s   second    
#define vi   vector<int> 
#define vpii   vector<pair<int,int> >
#define varr   vector<int> v[1000000]
#define mii    map<int,int>
#define msi    map<string,int>
#define mlist  map<int,list>

#define wloop   int t\
               ;cin>>t\
               ;while(t--)
#define forxNi(x,n) for(int i=x;i<n;i++)
#define forxNj(x,n) for(int j=x;j<n;j++)
#define forNxi(n,x) for(int i=n;i>=x;i--)
#define forNxj(n,x) for(int j=n;j>=x;j--)

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

//------Code begins--->

int32_t main(){
	fastio;
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	forxNi(0,n){
		cin>>a[i]>>b[i]>>c[i];
	}
	int dp[n][3];
	forxNi(0,n){
		forxNj(0,3){
			dp[i][j]=0;
		}
	}
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	forxNi(1,n){
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
	}
	int maxim=lmin;
	forxNi(0,3){
		if(dp[n-1][i]>maxim)maxim=dp[n-1][i];
	}
	cout<<maxim;
	cout<<'\n';
	
	return 0;
}

Measured memory_bytes: 8332
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    ll x,a,b;
    cin>>x>>a>>b;
    if(0<=a-b) cout<<"delicious"<<endl;
    else{
        if(x>=b-a) cout<<"safe"<<endl;
        else cout<<"dangerous"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split(' '))
ls, rst = [], 0
for i in range(H):
    ls.append(input())
for i in range(1 << H):
    for j in range(1 << W):
        cnt = 0
        for s in range(H):
            if i >> s & 1:
                continue
            for t in range(W):
                if j >> t & 1:
                    continue
                if ls[s][t] == '#':
                    cnt += 1
        if cnt == K:
            rst += 1
print(rst)

Measured memory_bytes: 9204
#include <iostream>
#include <vector>

int main()
{
    int N = 0;
    std::vector<long long int> pools;

    std::cin >> N;
    pools.resize(N);

    long long int sum = 0, mounts_sum_except_first = 0;
    for (int i = 0; i < N; i++) {
        std::cin >> pools[i];
        sum += pools[i];
        if (i % 2 == 1) {
            mounts_sum_except_first += pools[i];
        }
    }

    std::vector<long long int> mounts;
    mounts.resize(N);
    mounts[0] = sum - 2 * mounts_sum_except_first;

    for (int i = 1; i < N - 1; i += 2) {
        mounts[i] = 2 * pools[i - 1] - mounts[i - 1];
        mounts[i + 1] = 2 * pools[i] - mounts[i];
    }

    for (auto& mount : mounts) {
        std::cout << mount << ' ';
    }

    return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>


long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

int H,W,A,B;
cin>>H>>W>>A>>B;
//ある行と列の1の数
int wide[1000]={};//ある行の1の数
int height[1000]={};//ある列の1の数
for(int i=0;i<H;i++){
    for(int k=0;k<W;k++){
        if( (wide[i]<A || wide[i]<W-A) && (height[k]<B || height[k]<H-B)){
            cout<<"1";
            height[k]++;
            wide[i]++;
        }
        else{
            cout<<"0";
        }
    }
    cout<<endl;
}

 return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquestring;
typedef priority_queue<int> priqueint;
typedef priority_queue<ll> priquell;
typedef priority_queue<char> priquechar;
typedef priority_queue<string,vector<string>,greater<string>> rpriquestring;
typedef priority_queue<int,vector<int>,greater<int>> rpriqueint;
typedef priority_queue<ll,vector<ll>,greater<ll>> rpriquell;
typedef priority_queue<char,vector<char>,greater<char>> rpriquechar;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

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

void next(vector<int> &use){
    bool ans=true;
    int cnt=0;
    while(ans){
        use[cnt]++;
        if(use[cnt]<=2)ans=false;
        else use[cnt]=0;
        cnt++;
    }
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    int a,b;cin >> a >> b;cout << a*b << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int r,g,b,n;
  cin>>r>>g>>b>>n;
  int count=0;
  rep(i,3001){
    rep(j,3001){
      int wont=n;
      wont-=r*i; wont-=g*j;
      if(wont<0){
        continue;
      }
      if(wont==0){
        count++;
      }
      else if(wont%b==0){
        count++;
      }
    }
  }
  cout<<count<<'\n';
  return(0);
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	d := sc.nextIntSlice(N)
	sort.Ints(d)
	mid := N/2 - 1
	if d[mid] < d[mid+1] {
		fmt.Println(d[mid+1] - d[mid])
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 2048
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	N = int(input())
	A = getlist()
	A = sorted(A)
	if N % 2 == 0:
		ans = 0
		M = int(N // 2)
		for i in range(M):
			ans += A[-1 - i] * 2
		ans -= A[-1]
		print(ans)
	else:
		ans = 0
		M = int(N // 2)
		for i in range(M + 1):
			ans += A[-1 - i] * 2

		ans -= A[-1]
		ans -= A[-1 - M]
		print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 93384
// Problem : C - Repsept
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N;
	cin>>N;
	int val=7%N;
	F0R(x,1e8)
	{
		if(val==0)
		{
			cout<<x+1;
			return 0;
		}
		val=(val*10)+7;
		val%=N;
	}
	cout<<-1<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

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

const int maxn = 5005;
int dp[maxn];
int dp1[maxn * maxn];

int n;
int g1, s1, b1, g2, s2, b2;

int32_t main() {
	cin >> n;
	cin >> g1 >> s1 >> b1 >> g2 >> s2 >> b2;
	for(int i = 0; i <= n; i++) {
		if(i - g1 >= 0) 
			dp[i] = max(dp[i - g1] + (g2 - g1), dp[i]);
		if(i - s1 >= 0)
			dp[i] = max(dp[i - s1] + (s2 - s1), dp[i]);
		if(i - b1 >= 0)
			dp[i] = max(dp[i - b1] + (b2 - b1), dp[i]);
	}
	int A = n + dp[n];
	for(int i = 0; i <= A; i++) {
		if(i - g2 >= 0) 
			dp1[i] = max(dp1[i - g2] + (g1 - g2), dp1[i]);
		if(i - s2 >= 0)
			dp1[i] = max(dp1[i - s2] + (s1 - s2), dp1[i]);
		if(i - b2 >= 0)
			dp1[i] = max(dp1[i - b2] + (b1 - b2), dp1[i]);
	}
	cout << dp1[A] + A;
}

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

int main(){
    int d,n,m=0;
    cin >> d >> n;
    if(d==2){
        if(n!=100){
            for(int i=0;i<n;i++){
                m+=10000;
            }
        }else{
            m=1010000;
        }
    }
    if(d==1){
        if(n!=100){
            for(int i=0;i<n;i++){
                m+=100;
            }
        }else{
            m=10100;
        }
    }
    if(d==0){
        if(n!=100){
            for(int i=0;i<n;i++){
                m++;
            }
        }else{
            m=101;
        }
    }
    cout << m;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    // static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    static long[] fact = new long[100];

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        if(s.length()<=n){
            System.out.println(s);
            return;
        }
        s = s.substring(0,n);
        System.out.println(s+"...");

    }
}


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

using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll N, K, x[100005], dist = 2e9;
	cin >> N >> K;
	for (int i = 1; i <= N; ++i){
		cin >> x[i];
	}
	x[0] = -1e9-1;
	x[N+1] = 1e9+1;
	for (int i = 1; i <= N-K+1; ++i){
		if (x[i+K-1] <= 0){
			dist = min(dist,-x[i]);
		}
		else if (x[i] >= 0){
			dist = min(dist,x[i+K-1]);
		}
		else if (x[i] <= 0 && x[i+K-1] > 0){
			dist = min(dist,x[i+K-1]-x[i]+min((ll)abs(x[i]),x[i+K-1]));
		}
	}
	cout << dist << '\n';

}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let n: i32 = read();
    let mut max: i32 = 0;
    let mut sum: i32 = 0;
    for _i in 0..n{
	let number: i32 = read();
	if max < number {
	    max = number;
	}
	sum += number;
    }
    if 2*max < sum {
	println!("Yes");
    }else{
	println!("No");
    }
}


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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}
int t[100005];
int x[100005];
int y[100005];

int main(void){
    int n;
    scanf("%d", &n);
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    int flag = 0;
    
    for (int i = 1; i <= n; i++){
        scanf("%d %d %d", &t[i], &x[i], &y[i]);
    }
    for (int i = 1; i <= n; i++){
        if (abs(x[i]-x[i-1])+abs(y[i]-y[i-1]) <= t[i]-t[i-1] &&
             ((t[i]-t[i-1]) - (abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))) % 2 == 0){
                 flag = 1;
             }else{
                 printf("No\n");
                 return 0;
             }
    }
    printf("Yes\n");


    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>
#include<random>



#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 3000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
int N, K;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> K;
	COMinit();
	FOR(i, 1, K + 1) {
		int res1, res2;
		if (i == 1) {
			res1 = 1;
			res2 = mult(fac[N - K + i], finv[N - K]);
			res2 = mult(res2, finv[i]);
			int ans = mult(res1, res2);
			print(ans);
		}
		else {
			res1 = 1;
			res1 = ((res1*fac[K - 1] % MOD)*finv[K - i] % MOD)*finv[i - 1] % MOD;
			res1 %= MOD;
			int C = N - K;
			res2 = 1;
			res2 = ((res2*fac[C + 1] % MOD)*finv[C - i + 1] % MOD)*finv[i] % MOD;
			res2 %= MOD;
			//pe(res1)print(res2);
			int ans = res1 * res2%MOD;
			if (C < i - 1) {
				print(0);
				continue;
			}
			print(ans);
		}
	}
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}


	boolean p[] = new boolean[100001];
	public void run() {
		Scanner sc = new Scanner(System.in);
		int q=sc.nextInt();

		for(int i=0; i<=100000; i++) {
			p[i]=true;
		}

		p[0]=false;
		p[1]=false;
		for(int i=2; i*i<=100000; i++) {
			if(p[i]) {
				for(int j=i+i; j<=100000; j+=i) {
					p[j]=false;
				}
			}
		}

		int sum[]= new int[100001];
		sum[0]=0;
		for(int i=0; i<100000; i++) {
			if(i%2==0) {
				sum[i+1] = sum[i];
			}else {
				if(p[i] && p[(i+1)/2]) {
					sum[i+1] = sum[i]+1;
				}else {
					sum[i+1] = sum[i];
				}
			}

		}

		for(int i=0; i<q; i++) {
			int l=sc.nextInt();
			int r=sc.nextInt();
			int ans = sum[r+1] - sum[l];
			System.out.println(ans);
		}

		sc.close();
	}

}


Measured memory_bytes: 62092
g=[0,0,0,0]
one=0
two=0

for i in range(3):
  a,b=map(int,input().split())
  g[a-1]+=1
  g[b-1]+=1
  
for i in range(len(g)):
  if g[i]==1:
    one+=1
  if g[i]==2:
    two+=1
if one==2 and two==2:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

bool cmp(ll n, P const& p)
{
    return ((p.first > n));
}

int n;
VI a(1000100),b(1000100);
vector<vector<P>> d(5000000,vector<P>(0));
int boarder=1023;

void dfs(int v){
	if(v>=boarder||v>=n)
		return;
	if(v==0){
		d[v].push_back({b[v],a[v]});
		d[v].push_back({0,0});
	}
	else{
		for(auto p:d[(v+1)/2-1]){
			d[v].push_back({p.first+b[v],p.second+a[v]});
			d[v].push_back({p.first,p.second});
		}
	}
	if((v+1)*2<=n)
		dfs((v+1)*2-1);
	if((v+1)*2+1<=n)
		dfs((v+1)*2);
	sort(ALL(d[v]));
	ll mx=0;
	REP(i,d[v].size()){
		mx=max(mx,d[v][i].second);
		d[v][i].second=mx;
	}
}

int main(){
	cin >> n;
	REP(i,n) cin >> a[i] >> b[i];
	dfs(0);
	int q; cin >> q;
	ll v, l;
	while(q--){
		cin >> v >> l; v--;
		if(v<boarder){
			int it=upper_bound(d[v].begin(),d[v].end(),l,cmp)-d[v].begin();
			if(it==0)
				cout << 0 << endl;
			else
				cout << d[v][it-1].second << endl;
		}
		else{
			VI s(0);
			while(v>=boarder){
				s.push_back(v);
				v=(v+1)/2-1;
			}
			ll ans=0;
			REP(i,1<<s.size()){
				ll suma=0, sumb=0;
				REP(j,s.size()) if(i>>j&1){
					suma+=a[s[j]];
					sumb+=b[s[j]];
				}
				if(l-sumb<0)
					continue;
				int it=upper_bound(d[v].begin(),d[v].end(),l-sumb,cmp)-d[v].begin();
				if(it==0)
					ans=max(ans,suma);
				else
					ans=max(ans,suma+d[v][it-1].second);
			}
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 147500
#include<stdio.h>
int main(void){
	int a,b;
	scanf("%d",&a); scanf("%d",&b);
	if((a+b)%2==1){
		printf("%d\n",(a+b)/2+1);
	}
		else{
			printf("%d\n",(a+b)/2);
		}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>  
#include<vector>
using namespace std;  
#define  max(x,y)   (x)>(y)?(x):(y)  
int main() 
{  
    int N,W;  
    cin>>N; 
    cin>>W;  
	vector<int> f(20, 0);
	vector<int> value(10, 0);
	vector<int> weight(10, 0);
    for (int i=1;i<=N; i++)  
    {  		
		if (i >= 10)
		{
			value.push_back(0);
			weight.push_back(0);
		}
        cin>>value[i]>>weight[i];
    }  
	if (W >= 20)
		for (int j=20; j<=W; j++)
			f.push_back(0);
    for (int i=1; i<=N; i++)  
        for (int j=W; j>=weight[i]; j--)  
                f[j] = max(f[j],f[j-weight[i]] + value[i]);         
    cout<<f[W]<<endl;
    return 0;
}

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

typedef int Digits[7];

int q;
int n;
set<int> used;

int Convert(int t, int *ds) {
  int cnt = 0;
  while (t > 0) {
    ds[cnt++] = t%10;
    t /= 10;
  }
  return cnt;
}

int Restore(int *ds, int n) {
  int ret = 0;
  for (int i=n-1; i>=0; i--) {
    ret = ret*10 + ds[i];
  }
  return ret;
}

int main() {
  scanf("%d", &q);
  for (int i=0; i<q; i++) {
    Digits ds;

    used.clear();
    scanf("%d", &n);

    int ans = 0;
    while (1) {
      used.insert(n);
      int k = Convert(n, ds);
      if (k <= 1) break;

      int maxi = 0;
      for (int i=1; i<k; i++) {
        maxi = max(maxi, Restore(ds, i) * Restore(ds+i, k-i));
      }
  
      if (used.count(maxi)) {
        ans = -1;
        break;
      }

      n = maxi;
      ans++;
    }

    printf("%d\n", ans);
  }
}

Measured memory_bytes: 3232
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
     
template<typename T>
T gcd(T a, T b){
	return b != 0 ? gcd(b, a % b) : a;
}    

int main() {
  ll x=0,y=0,z=0,k,n,m,h,w,ans=0,sum=0,Max=-1,Min=1e9+1;
  bool ok = true;
  string t;
  cin >> n;
  VLL cnt(10,VL(10));
  
  for(int i=1;i<=n;i++){
    string s = to_string(i);
    cnt[s.front()-'0'][s.back()-'0']++;
  }

  rep(i,10){
    rep(j,10){
      ans += cnt[i][j] * cnt[j][i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
S = [input() for i in range(N)]

A = Counter(S)
A = sorted(A.items(),key=lambda x:x[1],reverse = True)
i,s = A[0]
Ans = []
for i,j in A:
    if j==s:
        Ans.append(i)
    else:
        break
Ans = sorted(Ans)
for i in Ans:
    print(i)

Measured memory_bytes: 45040
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

int N;
int dArr[101];
int main() {
    cin >> N;
    rep(i, N) cin >> dArr[i];

    set<int> s;

    // 要素の検索
    set<int>::iterator ite;
    
    rep(i, N){
        ite = s.find(dArr[i]);
        if(ite == s.end()) {
            s.insert(dArr[i]);
        }
    }

    cout << s.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    map<string, int> mp;
    rep(i, N) {
        string s;
        cin >> s;
        mp[s]++;
    }

    int mx = 0;
    for (auto& p : mp) mx = max(mx, p.second);
    vector<string> ans;
    for (auto& p : mp) {
        if (p.second == mx) ans.push_back(p.first);
    }
    sort(all(ans));
    for (auto& s : ans) write(s);
}

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

using namespace std;

int main(){
    int k, s;
    cin >> k >> s;
    int ans = 0;
    int a = min(s, k);
    int b = max(0, s - k);
    if (a >= b) ans += (a - b + 1) * (s + 1) - (a + b) * (a - b + 1) / 2;
    a = min(k, s - k - 1);
    b = max(0, s - 2 * k);
    if (a >= b) ans += (a - b + 1) * (2 * k - s + 1) + (a + b) * (a - b + 1) / 2;

    cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
S=list(input())


a=0
b=0
bb=0
for s in S:
    if s=="(":
        a+=1
    else:
        if a>0:
            a-=1
            b+=1
        else:
            bb+=1
for i in range(bb):
    S.insert(0,"(")
for i in range(a):
    S.append(")")
S="".join(S)
print(S)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
#define max 100005
#define nil -1

struct data{
    int l,r,p;
};

struct data T[max];
int D[max];

void rec(int i,int p){
    D[i]=p;
    if(T[i].r!=nil)rec(T[i].r,p);
    if(T[i].l!=nil)rec(T[i].l,p+1);
    return;
}

void print(int i){
    int a;
    cout<<"node "<<i<<": parent = "<<T[i].p<<", depth = "<<D[i];
    if(D[i]==0)cout<<", root, ";
    else if(T[i].l==nil)cout<<", leaf, ";
    else cout<<", internal node, ";
    
    if(T[i].l!=nil){
        cout<<"["<<T[i].l;
        a=T[i].l;
        while(T[a].r!=nil){
            cout<<", "<<T[a].r;
            a=T[a].r;
        }
        cout<<"]"<<endl;
    }
    else cout<<"[]"<<endl;
    return;
}

int main(){
    int n,v,d,c,r,l;
    cin>>n;
    for(int i=0;i<n;i++) T[i].p=T[i].l=T[i].r= nil;
    for(int j=0;j<n;j++){
        cin>>v>>d;
        for(int i=0;i<d;i++){
            cin>>c;
            if(i==0) T[v].l=c;
            else T[l].r=c;
            l=c;
            T[c].p=v;
        }
    }
    for(int i=0;i<n;i++){
        if(T[i].p==nil) r=i;
    }
    rec(r,0);
    for(int i=0;i<n;i++) print(i);
   return 0;
}


Measured memory_bytes: 7684
#include <iostream>
using namespace std;
int a[20];
int n;
bool work(int r,int t)
{
    if(t==0)
        return true;
    if(r==1)
        return a[0]==t;
    return work(r-1,t)||work(r-1,t-a[r-1]);
}
int main()
{
    int q,i;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    cin>>q;
    while(q--)
    {
        cin>>i;
        if(work(n,i))
            cout<<"yes"<<endl;
        else
            cout<<"no"<<endl;
    }
    return 0;
}

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

total = 0
for i in range(n):
    total += a[i]*(1 if i%2==0 else -1)

ans = [total]

for i in range(0, n-1):
    ans.append(2*a[i]-ans[i])

print(" ".join(map(str, ans)))

Measured memory_bytes: 24888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int seq[100];

int main(void) {

    int N;
    scanf("%d", &N);

    int total = 0;
    for (int i = 0; i < N; ++i) {
        scanf("%d", seq + i);
        total += seq[i];
    }

    int mid = total % N == 0 ? total / N : total / N + 1;

    total = 0;
    for (int i = 0; i < N; ++i) {
        total += (mid - seq[i]) * (mid - seq[i]);
    }

    int total2 = 0;
    for (int i = 0; i < N; ++i) {
        total2 += (mid - 1 - seq[i]) * (mid - 1 - seq[i]);
    }

    printf("%d\n", total < total2 ? total : total2);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	int N; cin >> N; N %= 1000;
	if (N == 0) cout << "0" << endl;
	else cout << 1000 - N << endl;
	return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

mint dp[100005][13];


int main() {
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i,n) {
        int c;
        if (s[i] == '?') c = -1;
        else c = s[i] - '0';
        for (int j = 0; j <= 9; j++) {
            if (c != -1 && c != j) continue;
            for (int k = 0; k <= 12; k++) {
                dp[i+1][(k*10+j)%13] += dp[i][k];
            }
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 1; i <= m; i++) {
    for (int j = 0; j + 1 < n; j++) {
      if (a[j] % i > a[j + 1] % i) {
	swap(a[j], a[j + 1]);
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << a[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s1,s2;
  cin>>s1>>s2;
  int cnt=s2.size();
  for(int i=0;i<=static_cast<int>(s1.size()-s2.size());i++)
  {
    int x=0;
    for(int j=0;j<static_cast<int>(s2.size());j++)
    {
      if(s1[i+j]!=s2[j])
        	x++;
    }
    if(x<cnt)
      cnt=x;
  }
  cout<<cnt;
}


Measured memory_bytes: 3508
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

template<ll m, ll b>
struct RollingHash{
  vector<int> h;
  ll n;
  void init(const string &s, int len){
    n = s.length();
    h = vector<int>(n+1-len, 0);
    ll e = 1;
    ll c = 0;
    for(int i = 0; i < len; i++){
      e = e*b % m;
      c = (c*b + s[i]) % m;
    }
    h[0] = c;
    for(int i = 0; i < n-len; i++){
      c = ((c*b + s[i+len] - s[i]*e) % m + m) % m;
      h[i+1] = c;
    }
  }
  RollingHash(){}
  RollingHash(const string &s, int len){
    init(s, len);
  }
  ll get(int s){
    return h[s];
  }
};

int n;
string s[310];
string t[610];

RollingHash<MOD, 31> rhs[310];
RollingHash<MOD, 31> rht[310];

int main(){

  n = in();
  REP(i, n){
    s[i] = stin();
    t[i] = s[i];
    s[i] += s[i];
  }

  REP(i, n){
    REP(j, n){
      if(i < j){
        swap(t[i][j], t[j][i]);
      }
    }
  }
  REP(i, n){
    t[i] += t[i];
  }
  
  REP(i, n){
    rhs[i].init(s[i], n);
    rht[i].init(t[i], n);
  }

  ll ans = 0;
  REP(i, n){
    REP(j, n){
      bool ok = true;
      int si = i;
      int tj = j;
      REP(k, n){
        if(rhs[si].get(j) != rht[tj].get(i)){
          ok = false;
          break;
        }
        si = (si + 1 == n) ? 0 : (si + 1);
        tj = (tj + 1 == n) ? 0 : (tj + 1);
      }
      if(ok){
        ans++;
      }
    }
  }

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


Measured memory_bytes: 1408
// https://atcoder.jp/contests/dp/tasks/dp_b

#include <bits/stdc++.h>

using namespace std;

#define ll long long 
#define REPL(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
static const int MAX = 1000010;
static const ll INFTY = 1e12;
static const ll NUMMAX = 1000000007;
static const ll MOD = 1000000007;
#define LOOP 10000000
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 入力
int H, W;
vector<string> field;
int result = 100;
int dfs_res = 0;

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 long long INF = 1LL << 60;

// 入力
int N;

// DP テーブル
long long dp[110000];
int main() {
 
 
    int N, K;
    cin >> N >> K;
    vector<ll> h(N);
    REP(i, N){ cin >>h[i]; }
    int sum = 0;
 
    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INFTY;
 
    // 初期条件
    dp[0] = 0;
 
    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
 
    // 答え
    cout << dp[N-1] << endl;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/




Measured memory_bytes: 1920
#include <bits/stdc++.h>
    #include<iterator>
    #define HAR BAR LAGTA HAI APUN HI J BHAGWAAN HAI!!
    #define   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define ll long long int
    #define MAX 1e9
    #define MIN -1e9
    #define mod 1000000007
    #define pb push_back
    #define all(x) (x).begin(), (x).end()
    #define debug(x) cerr<<#x<<'='<<(x)<<endl;
    #define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;
    #define mxn 100005
    using namespace std;
    int main()
    {
        ll n,x,t;
        cin>>n>>x>>t;
        ll ans = 0;
        if(n%x==0) cout<<n*t/x<<endl;
        else cout<<t*(n/x + 1)<<endl;
        return 0;
    }

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

int gcd(int a,int b){
	int tmp;
	if(a > b){
		while(b != 0){
			tmp = b;
			b = a%b;
			a = tmp;
		}
		return a;
	}else{
		while(a != 0){
			tmp = a;
			a = b%a;
			b = tmp;
		}
		return b;
	}
}

int lcm(int a,int b){
	int max_common = gcd(a,b);
	return (a/max_common)*b;
}

int main(){
    long long a, b, c, d, cnt=0;
    cin >> a >> b >> c >> d;
    long long x = lcm(c,d);
    long long ans = (b-a+1) - ( (b/c - (a-1)/c) + ((b/d) - (a-1)/d) - (b/x-(a-1)/x) );
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL)
#define REP(i,a,b) for(int i=a,_b=b;i<=_b;i++)
#define rep(i,n) REP(i,0,n-1)
#define FORD(i,b,a) for(int i=b,_a=a;i>=_a;i--)
#define ford(i,n) FORD(i,n-1,0)
#define sqr(x) ((x)*(x))
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define vll vector<ll>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define add push_back
#define len(arr) arr.size()
#define print(x) cout<<(x)<<'\n'
using namespace std;


int main() {
	SPEED;
	//freopen("in.txt", "r", stdin);
	string s; cin >> s;
	if(s[0] != 'A'){
		print("WA");
		return 0;
	}
	int n = len(s);
	int idx = -1, cnt = 0;
	rep(i, n){
		if(s[i] == 'C'){
			if(idx == -1) idx = i;
			++cnt;
		}
	}
	
	if(cnt != 1){
		print("WA");
		return 0;
	}
	
	if((idx < 2 || idx > n - 2)){
		print("WA");
		return 0;
	}
	
	REP(i, 1, n - 1) if(i != idx){
		if(s[i] < 'a'){
			print("WA");
			return 0;
		}
	}
	
	print("AC");
	return 0;
}

Measured memory_bytes: 256
def c(s, n):
    s = list(s)
    for i in range(len(s)):
        if s[i] in alphabets:
            s[i] = alphabets[(alphabets.index(s[i]) + n) % 26]
    return ''.join(s)
def is_right(s):
    words = '.'.join(s.split(' ')).split('.')
    return 'the' in words or 'this' in words or 'that' in words
alphabets = 'abcdefghijklmnopqrstuvwxyz'
while True:
    try:
        line = input()
        if line == '*':
            break
    except:
        break
    for i in range(26):
        if is_right(c(line, i)):
            print(c(line, i))
            break

Measured memory_bytes: 7476
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#define llong long long
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(){
  int N, D, X;
  cin >> N >> D >> X;
  int A[N];
  Rep(i, N){
    cin >> A[i];
  }

  int ans = 0;
  Rep(i, N){
    int j=1;
    while(j <= D){
      j += A[i];
      ans++;
    }
  }
  ans += X;

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

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] A = new long[N];
		for( int i=0; i<N; i++ ){
			A[i] = sc.nextLong();
		}
		Arrays.sort(A);
		for( int i=0; i<N-1; i++ ){
			if( A[i]==A[i+1] ){
				System.out.println("NO");
				break;
			}
			if( i==N-2 ){
				System.out.println("YES");
			}
		}
	}
}

Measured memory_bytes: 89556
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    H, W = LI()
    a = SR(H)
    for h in range(H):
        for w in range(W):
            if a[h][w] == "#":
                t = True
                for mh, mw in [[0, 1], [1, 0]]:
                    mh += h
                    mw += w
                    if 0 <= mh < H and 0 <= mw < W:
                        if a[mh][mw] == "#":
                            if t:
                                t &= False
                            else:
                                print("Impossible")
                                return
                if t and (h != H - 1 and w != W - 1):
                    print("Impossible")
                    return
                t = True
                for mh, mw in [[0, -1], [-1, 0]]:
                    mh += h
                    mw += w
                    if 0 <= mh < H and 0 <= mw < W:
                        if a[mh][mw] == "#":
                            if t:
                                t &= False
                            else:
                                print("Impossible")
                                return
                if t and (h != 0 and w != 0):
                    print("Impossible")
                    return
    print("Possible")
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 40048
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	string s, t;	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.rbegin(), t.rend());
	if (s < t) {
		cout << "Yes" << endl;
		cin >> s;
		return 0;
	}
	cout << "No" << endl;
	cin >> s;
}

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int mx=max(a,max(b,c));
  int s=a+b+c;
  int ans=9*mx+s;
  cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
vector<int> a;
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	a.resize(n+1);
	double ans=0;

	for(int i=1; i<=n; i++) {
		cin>>a[i];
	}
	sort(a.begin()+1,a.end());
	ans=a[1];
	for(int i=2; i<=n; i++) {
		ans=(double)(ans+a[i])/2;
	}
	cout<<fixed<<setprecision(6)<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000)
n, m = map(int, input().split())
s = input()
out = [set() for _ in range(n)]
count = [[0, 0] for _ in range(n)]
def f(c):
    if c == 'A': return 0
    else: return 1
for _ in range(m):
    a, b = map(int, input().split())
    if a == b:
        count[a-1][f(s[a-1])] += 1
    elif b-1 not in out[a-1]:
        count[a-1][f(s[b-1])] += 1
        count[b-1][f(s[a-1])] += 1
    out[a-1].add(b-1)
    out[b-1].add(a-1)
elim = set()
def eliminate(x):
    elim.add(x)
    c = f(s[x])
    for node in out[x]:
        if node not in elim:
            count[node][c] -= 1
            if count[node][0] * count[node][1] == 0:
                eliminate(node)
for i in range(n):
    if i not in elim and count[i][0] * count[i][1] == 0:
        eliminate(i)
if len(elim) < n: print('Yes')
else: print('No')

Measured memory_bytes: 188504
#include <cstdio>
#include <algorithm>
using namespace std;

const double eps = 1e-9;

const int N = 6;

double P[N], Q[N];

double A[2][1 << N];
double V[1 << N];

int main() {
    for (int i = 0; i < 6; i++) {
        scanf("%lf", &P[i]);
        P[i] /= 100.0;
    }
    for (int i = 0; i < 6; i++) {
        scanf("%lf", &Q[i]);
        Q[i] /= 100.0;
    }
    for (int msk = 0; msk < (1 << N); msk++) {
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < N; j++) {
                double p = (i ? P : Q)[j];
                bool success = i == ((msk >> j) & 1);
                A[i][msk] += p * success;
            }
        }
    }
    /*for (int i = 0; i < 2; i++) {
        for (int j = 0; j < (1 << N); j++) {
            printf("%.2lf ", A[i][j]);
        }
        printf("\n");
    }
    for (double al = 0; al <= 1.0; al += 0.0001) {
        for (int i = 0; i < (1 << N); i++) {
            V[i] = al * A[0][i] + (1 - al) * A[1][i];
        }
        double mx = 0;
        mx = *min_element(V, V + (1 << N));
        printf("%.10lf\n", mx);
    }*/
    double l = 0, r = 1;
    for (int it = 0; it < 100; it++) {
        double a = 0, b = 1;
        double x = (l + r) / 2.0;
        for (int i = 0; i < (1 << N); i++) {
            double u = A[0][i], v = A[1][i];
            if (u > v + eps) {
                a = max(a, (x - v) / (u - v));
            } else if (v > u + eps) {
                b = min(b, (x - v) / (u - v));
            } else {
                if (u < x)
                    a = 42;
            }
        }
        if (a < b)
            l = x;
        else
            r = x;
    }
    printf("%.10lf\n", 1 - (l + r) / 2.0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 0

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

ll N, K;
#define MAX_N (2000)
#define MAX_A (2000)
ll A[MAX_N];
#define deno (1000*1000*1000+7)

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);
	cin >> N >> K;
	FOR(n,N) {
		cin >> A[n];
	}
	ll p=0;
	ll q=0;
	FOR(i,N) {
		FORUL(j,i+1,N) {
			if(A[i]>A[j]) {
				p+=1;
				p%=deno;
			}
		}
	}
	FOR(i,N) {
		FOR(j,N) {
			if(A[i]>A[j]) {
				q+=1;
				q%=deno;
			}
		}
	}

	DOUT << "p="<<p<<endl;
	DOUT << "q="<<q<<endl;

	ll ans = 0;
	p = (p*K)%deno;
	q = (q*(((K-1)*K/2)%deno))%deno;

	ans = (p+q)%deno;
	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 256