akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
#define F first
#define S second
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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;
}
int main() {
  cout << fixed << setprecision(10);
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll a = 1; a<=n; a++){
    for(ll b=1; a*b<=n; b++){
      ll c = n-a*b;
      if(c>0) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3644
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


# nCrをすべてのr(0<=r<=n)について求める
def combination(n, mod):
    lst = [1]
    for i in range(1, n+1):
        lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
    return lst

H, W, A, B = map(int, input().split())
x, y = B, H-A-1
n1 = x+y
n2 = W+H-n1-2
mod = 10**9+7
C1 = combination(n1, mod)
C2 = combination(n2, mod)
ans = 0
while x<W and y>=0:
    ans += C1[x] * C2[W-x-1]
    ans %= mod
    x += 1
    y -= 1
print(ans)


Measured memory_bytes: 11064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007
using namespace std;
int main(){
    int n;  cin>>n;
    vector<int> R(n);
    rep(i,n) cin>>R[i];
    
    int maxV=-2000000000;
    int minV=R[0];
    for(int i=1;i<n;++i){
        maxV=max(maxV,R[i]-minV);
        minV=min(minV,R[i]);
    }
    cout<<maxV<<endl;
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    long[] a = sc.nextLongArray(n);
    long[][] sum = new long[n + 1][2];
    sum[0][0] = 0L;
    sum[0][1] = -1_000_000_001L;
    for (int i = 0; i < n; i++) {
      sum[i + 1][0] = Math.max(sum[i][0] + a[i], sum[i][1] - a[i]);
      sum[i + 1][1] = Math.max(sum[i][0] - a[i], sum[i][1] + a[i]);
    }
    System.out.println(sum[n][0]);
  }
}


Measured memory_bytes: 45908
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    vector<int> v;
    for (int i = 0; i < 5; ++i)
    {
        int a;
        cin >> a;
        v.push_back(a);
    }

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

    int k;
    cin >> k;
    if (v[4] - v[0] > k)
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;


int main(){
    ll N;
    cin>>N;
    ll n,h,w;
    for(n=1;n<=3500;n++){
        for(h=1;h<=3500;h++){
            if(4*n*h-N*n-N*h<=0) continue;
            if((N*h*n)%(4*n*h-N*n-N*h)==0){
                w=(N*h*n)/(4*n*h-N*n-N*h);
                cout<<h<<" "<<n<<" "<<w<<endl;
                return 0;
            }
        }
    }
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in(),M=in();
	vector<int> AC(N,0),WA(N,0);
	REP(i,M){
		int v=in()-1;
		string S=in<string>();
		if(S=="AC"){
			if(!AC[v]) AC[v]=1;
		}
		else{
			if(!AC[v]) WA[v]++;
		}
	}
	int A=accumulate(ALL(AC),0),B=0;
	REP(i,N){
		if(AC[i]) B+=WA[i];
	}
	out(A,B);
	return 0;
}

Measured memory_bytes: 1024
from math import sqrt
while True:
    n = int(input())
    if n == 0:
        break
    else:
        s = list(map(int, input().split()))
        ave = sum(s)/n
        tmp = 0
        for i in range(n):
            tmp += (s[i]-ave)**2
        print(sqrt(tmp/n))


Measured memory_bytes: 5700
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	int now=1,ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=now) ans++;
		else now++;
	}
	if(now==1) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
x1,y1,x2,y2 = list(map(int,input().split()))

d = [x2-x1,y2-y1]

def rot90(x):
    return [-x[1], x[0]]
    
d23 = rot90(d)
d34 = rot90(d23)

x3 = x2+d23[0]
y3 = y2+d23[1]
x4 = x3+d34[0]
y4 = y3+d34[1]

print(x3,y3,x4,y4)

Measured memory_bytes: 3064
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let X: usize = sc.get();
    let Y: usize = sc.get();
    let Z: usize = sc.get();
    println!("{} {} {}", Z, X, Y);
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int A = int.Parse(input[1]);
        int B = int.Parse(input[2]);

        if(N*A>B){
            Console.WriteLine(B);
        } else {
            Console.WriteLine(N*A);
        }
    }
}

Measured memory_bytes: 13140
fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    
    val ds = readInputLine().split(" ").map { it.toInt() }
    
    val dsList = mutableListOf<Int>()
    
    for (d in ds) {
        dsList.add(d)
    }
    
    dsList.sort()
    
    println("${dsList[n / 2] - dsList[n / 2 - 1]}")
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 59652
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll a[100002];
ll b[100001]={};

int main() {

	int n;

	cin>>n;

	rep(i,n+1){
		cin>>a[i];
	}
	rep(i,n){
		cin>>b[i+1];
	}

	ll t=0;
	rep(i,n+1){
		if(b[i]>=a[i]){
			t+=a[i];
			a[i]=0;
		}else{
			t+=b[i];
			a[i]-=b[i];
		}
		if(b[i+1]>=a[i]){
			t+=a[i];
			b[i+1]-=a[i];
		}else{
			t+=b[i+1];
			b[i+1]=0;
		}
	}
	cout<<t<<endl;
	return 0;

}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>

using namespace std;

#define size_t int

int main(int argc, char const *argv[]) {
  int N, K;
  scanf("%d %d", &N, &K);
  int h[N];
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &h[i]);
  }
  sort(h, h + N);
  int r = INT_MAX;
  for (size_t i = 0; i < N - K + 1; i++) {
    int t = h[i + K - 1] - h[i];
    if (t < r) {
      r = t;
    }
  }
  printf("%d\n", r);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

const int MX = 1000001;
int n, x;
bool tbl[MX], sieve[MX];
int v[30];

void makeSieve() {
    memset(sieve, false, sizeof sieve);
    sieve[0] = sieve[1] = true;
    for (int i=2; i*i<MX; ++i) {
        if ( ! sieve[i]) {
            for (int j=i*i; j<MX; j+=i) {
                sieve[j] = true;
            }
        }
    }
}

int main() {
    makeSieve();
    while (cin >> n >> x, n) {
        for (int i=0; i<n; ++i) {
            cin >> v[i];
        }
        memset(tbl, false, sizeof tbl);
        tbl[0] = true;
        for (int i=0; i<n; ++i) {
            for (int j=v[i]; j<=x; ++j) {
                tbl[j] |= tbl[j-v[i]];
            }
        }
        bool ok = false;
        for (int i=x; i>=0; --i) {
            if (tbl[i] && ! sieve[i]) {
                cout << i << endl;
                ok = true;
                break;
            }
        }
        if ( ! ok) {
            cout << "NA" << endl;
        }
    }
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define PRINT(a)   cout << (a) << endl
#define RALL(v) rbegin(v), rend(v)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  char a;
  cin >> a;
  if(a - 'a' >= 0 &&  a - 'a' <= 25){
    cout << 'a' << endl;
  }else{
    cout << 'A' << endl;
  }
}



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

int main()
{
    int n, m;
    cin >> n >> m;
    if (abs(n - m) > 1)
    {
        cout << 0 << endl;
    }
    else
    {
        long long ans = 1;
        for (int i = n; i > 0; i--)
        {
            ans = (ans * (i % 1000000007)) % 1000000007;
        }
        for (int i = m; i > 0; i--)
        {
            ans = (ans * (i % 1000000007)) % 1000000007;
        }
        if (abs(n - m) % 2 == 0)
        {
            ans = (ans * 2) % 1000000007;
        }
        cout<<ans<<endl;
    }
}


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

int main(){

    int N;
    cin >> N;
    vector<int> cnt(100005, 0);

    int a, b;
    for(int i = 0; i < N; i++){
        cin >> a >> b;
        cnt[a]++;
        cnt[b + 1]--;
    }

    vector<int> acc(100005);
    acc[0] = 0;
    for(int i = 1; i < N + 3; i++){
        acc[i] = acc[i - 1] + cnt[i];
    }

    for(int i = N + 1; i >= 0; i--){
        if(i - 1 <= acc[i]){
            cout << i - 1 << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3628
n=int(input())
x=[]
y=[]
for i in range(n):
  xx,yy=map(int,input().split())
  x.append([xx,i])
  y.append([yy,i])
x.sort()
y.sort()
px=[]
py=[]
for i in range(n-1):
  px.append([x[i+1][0]-x[i][0],x[i][1],x[i+1][1]])
  py.append([y[i+1][0]-y[i][0],y[i][1],y[i+1][1]])
p=px+py
x=[]
y=[]
px=[]
py=[]
p.sort()
r=[i for i in range(n)]
rank=[1 for i in range(n)]
def root(x):
  if x==r[x]:
    return x
  else:
    r[x]=root(r[x])
    return r[x]
def union(path):
  rx=root(path[1])
  ry=root(path[2])
  if rx==ry:
    return 0
  else:
    if rank[rx]>rank[ry]:
      r[rx]=ry
      rank[rx]+=rank[ry]
    else:
      r[ry]=rx
      rank[ry]+=rank[rx]
    return path[0]
ans=0
for i in range(len(p)):
  ans+=union(p[i])
print(ans)

Measured memory_bytes: 61468
T=str(input())
P=str(input())
l1=len(T)
l2=len(P)
i=0
for i in range(l1-l2+1):
    i+=1
    x=T.find(P,i-1,i+l2-1)
    if x==-1:
        pass
    else:
        print(x)


Measured memory_bytes: 5572
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>

#define ok printf("ok\n");
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	int a,b=0,c;
	string s,t;
	vi v;
	cin>>s;
	rep(i,3)
	if(s[i]=='1')
	b++;
	
	cout<<b;

	
	return 0;
}

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

int main()
{
	int i;
    double n,s[1001],sum,ave,a;
	while(1){
		cin>>n;
		if(n==0)break;
		for(i=0,sum=0;i<n;i++){
			cin>>s[i];
			sum+=s[i];
		}
		ave=sum/n;
		for(i=0,sum=0;i<n;i++){
			sum+=pow(s[i]-ave,2.0);
		}
		a=sqrt(sum/n);
		printf("%10f\n",a);
	}
	
    return 0;
}

Measured memory_bytes: 1252
def draw_rect(h, w)
  h.times do
    puts "#" * w
  end
end

loop do
  h, w = gets.chomp.split(" ").map(&:to_i)
  if h == 0 && w == 0
    break
  else
    draw_rect(h, w)
    print "\n"
  end
end

Measured memory_bytes: 8704
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

h, w = MAP()
a = [[1 if i == '#' else 0 for i in STR()] for _ in range(h)]
s = 0
for i in range(h):
    s += sum(a[i])
if s != h + w - 1:
    print('Impossible')
    exit()
y = 0
x = 0
d = [[1, 0], [0, 1]]
while y < h - 1 or x < w - 1:
    flag = [False, False]
    for i in range(2):
        if x + d[i][0] < w and y + d[i][1] < h and a[y + d[i][1]][x + d[i][0]] == 1:
            flag[i] = True
    if (flag[0] and flag[1]) or (not flag[0] and not flag[1]):
        print('Impossible')
        exit()
    if flag[0]:
        x += 1
    else:
        y += 1
print('Possible')

Measured memory_bytes: 64492
#include<iostream>
using namespace std;
int main()
{
	int a1,a2,a3;
    cin>>a1>>a2>>a3;
    if (a1<=13 && a1>=1 && a2>=1 && a3>=1 && a2<=13 && a3<=13){
    if((a1+a2+a3)>=22)
    cout<<"bust";
    else
    cout<<"win";
    }
}


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

using namespace std;

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

    set<long long> cur;
    for (int i = 1; i <= 9; i++) {
        cur.insert(i);
    }

    set<long long> s;
    while (static_cast<int>(s.size()) < k) {
        for (set<long long>::iterator j = cur.begin(); j != cur.end(); j++) {
            s.insert(*j);
        }

        set<long long> next;
        for (set<long long>::iterator j = cur.begin(); j != cur.end(); j++) {
            next.insert(10 * *j + max((*j % 10) - 1, 0LL));
            next.insert(10 * *j + (*j % 10));
            next.insert(10 * *j + min((*j % 10) + 1, 9LL));
        }

        cur = next;
    }

    set<long long>::iterator res = s.begin();
    for (int i = 0; i < k - 1; i++) {
        res++;
    }

    cout << *res << endl;
}


Measured memory_bytes: 45312
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <time.h>
#define _USE_MATH_DEFINES
#define LL long long
#define UN unsigned
using namespace std;
const double PI = acos(-1.0);

int max_num(int ary[], int length) {
	int max = ary[0];
	for (int i = 1; i < length; i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int max_ord(int ary[], int length) {
	int max;
	max = max_num(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == max) return i;
	}
	return -1;
}

int min_num(int ary[], int length) {
	int min = ary[0];
	for (int i = 1; i < length; i++)
		if (min > ary[i]) min = ary[i];
	return min;
}

int min_ord(int ary[], int length) {
	int min;
	min = min_num(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == min) return i;
	}
	return -1;
}

int mp[10000][10000];

int main() {
	int h, w, n, a[10000], big = 1, small = 1;
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) cin >> a[i];

	for (int i = 0; i < h; i++) {
		if (i % 2 == 0)
			for (int j = 0; j < w; j++, small++) {
				mp[i][j] = big;
				if (small == a[big - 1]) {
					big++;
					small = 0;
				}
			}
		else
			for (int j = w - 1; j >= 0; j--, small++) {
				mp[i][j] = big;
				if (small == a[big - 1]) {
					big++;
					small = 0;
				}
			}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << mp[i][j];
			cout << "  ";
		}
		cout << endl << endl;
	}

	return 0;
	return 0;
}


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

typedef long long ll;
#define fori(n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair

ll power(ll base,ll e)
{
    ll answer=1;
    //ll e=1000000005;
    while(e)
    {
        if(e%2==1)
        {
            answer*=base;
        }
        base*=base;
       // base%=mod;
        e/=2;
       // answer%=mod;
    }
    return answer;
}

void mergearr(ll arr[], ll l,ll m, ll r)
{
    ll i,j,k;
    ll n1= m-l+1;
    ll n2 = r-m;
    ll L[n1],R[n2];
    for(i=0;i<n1;i++)
        L[i]=arr[l+i];
    for(i=0;i<n2;i++)
        R[i]=arr[m+1+i];

    i=0; j=0; k=l;
    while(i<n1 && j<n2)
    {
        if(L[i]<=R[j])
        {
            arr[k]=L[i];
            i++;
        }
        else
        {
            arr[k]=R[j];
            j++;
        }
        k++;
    }
    while(i<n1)
    {
        arr[k]=L[i]; i++; k++;
    }
    while(j<n2)
    {
        arr[k]=R[j]; j++; k++;
    }
}
void mergesort(ll arr[],ll l, ll r)
{
    if(l<r)
    {
        ll m = l+(r-l)/2;
        mergesort(arr,l,m);
        mergesort(arr,m+1,r);
        mergearr(arr,l,m,r);
    }
}


void sieveprimes(ll n)
{
        bool prime[n+1];
        memset(prime,true,sizeof(prime));

        for(ll i=2;i*i<=n;i++)
        {
            if(prime[i]==true)
            {
                for(ll j=i*i;j<=n;j+=i)
                {
                    prime[j]=false;
                }

            }

        }

        /*for (int p=2; p<=n; p++)
           if (prime[p])
              cout << p << " ";*/

    }


int main()
{

    char s;
    cin>>s;
    if(s>=65 && s<=90) cout<<'A'<<endl;
    else if(s>=97 && s<=122 ) cout<<'a'<<endl;

}




Measured memory_bytes: 3672
#include<stdio.h>
#include<string.h>

int main(void){
    int room[4][3][10] = {0} ;
    int n=0 ;
    int b=0 ,f=0 ,r=0 ,v=0 ;
    int i=0 ,j=0 ,k=0 ;

    scanf("%d",&n);
    for (i=0 ;i<n ;i++){
        scanf("%d%d%d%d",&b ,&f ,&r ,&v);
        room[b-1][f-1][r-1]=room[b-1][f-1][r-1]+v;
    }

    for (i=0 ;i<4 ;i++){
        for (j=0 ;j<3 ;j++){
            for (k=0 ;k<10 ;k++){
                printf(" %d",room[i][j][k]);
            }
            printf("\n");
        }
        if (i<3) printf("####################\n");
    }

    return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(string S){
  int ans = 0;

  if (S[0] == '0') {
    if (S[1] != '0') {
      ans += 2;
    }
  } else if (S[0] = '1') {
    if (S[1] == '0' || S[1] == '1' || S[1] == '2') {
      ans += 2;
    }
  }
  if (S[2] == '0') {
    if (S[3] != '0') {
      ans += 1;
    }
  } else if (S[2] = '1') {
    if (S[3] == '0' || S[3] == '1' || S[3] == '2') {
      ans += 1;
    }
  }

  if (ans == 0) {
    std::cout << "NA" << std::endl;
  } else if (ans == 1) {
    std::cout << "YYMM" << std::endl;
  } else if (ans == 2) {
    std::cout << "MMYY" << std::endl;
  } else if (ans == 3) {
    std::cout << "AMBIGUOUS" << std::endl;
  }
}

int main(){
  string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vp vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()

int inf = 1e18;
const int N = 4e5+5;

/*void dfs(int u,int par,int maxx)
{


    for(int v:adj[u])
    {
        if(v==par)
            continue;
        dfs(v,u,maxx);
    }
}*/
vi freq(N);
vi arr(N);
vi dp(N);
bool help(int mid)
{


}


int32_t main()
{
    io
    int tt=1;
    //cin>>t;
    while(tt--)
    {
       int x;
       cin>>x;
       int arr[6] = {0,1,2,3,4,5};
       if(x<100)
       {
           cout<<0;
           return 0;
       }
       int num  = x/100;
       int mod  = x%(num*100);
       if(mod==0)
       {
           cout<<1<<el;
       }
       else
       {
           if(mod>5*num)
            cout<<0<<el;
           else
            cout<<1;
       }
    }



        return 0;
}


Measured memory_bytes: 9600
#include<stdio.h>

int main(void)
{
    int S, h, m, s;

    scanf("%d", &S);

    h = S / 3600;
    m = S / 60 % 60;
    s = S % 60;

    printf("%d:%d:%d\n", h, m, s);

    return 0;

}


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

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

    vector<int> a(n);
    vector<vector<pair<int, int>>> xy(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        xy[i].resize(a[i]);

        for (int j = 0; j < a[i]; j++) {
            int x, y;
            cin >> x >> y;
            xy[i][j] = make_pair(--x, y);
        }
    }

    int ans = -1;
    for (int i = 0; i < (1 << n); i++) {
        vector<int> v(n, 0);
        for (int j = 0; j < n; j++) {
            v[j] = (i >> j) & 1;
        }
        
        bool flag = true;
        for (int j = 0; j < n; j++) {
            if (v[j] == 0) continue;
            for (int k = 0; k < a[j]; k++) {
                if (xy[j][k].second != v[xy[j][k].first]) {
                    flag = false;
                    break;
                }
            }
        }

        if (flag) {
            ans = max(ans, (int)count(v.begin(), v.end(), 1));
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> e[n];
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    int ans[n];
    fill(ans,ans+n,0);
    queue<pair<int,int>> que;
    for(auto p = e[0].begin(); p!=e[0].end(); p++) que.push(make_pair(0,*p));
    while(!que.empty()){
        pair<int,int> p = que.front(); que.pop();
        int u = p.second;
        if(ans[u] != 0) continue;
        ans[u] = p.first+1;
        for(auto q = e[u].begin(); q!=e[u].end(); q++){
            if(*q == p.first) continue;
            que.push(make_pair(u,*q));
        }
    }
    cout << "Yes" << endl;
    for(int i=1; i<n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 11304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;

int main()
{
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    cout<<H*W - h*W - w*H + h*w;
    
    
}

Measured memory_bytes: 256
def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


r1, c1, r2, c2 = list(map(int, input().split()))
MOD = 10 ** 9 + 7
facts, invs = prepare(r2 + c2 + 1, MOD)
ans = 0
for i in range(r1, r2 + 1):
    d1 = facts[i + c2 + 1] * invs[c2] % MOD
    d2 = facts[i + c1] * invs[c1 - 1] % MOD
    ans = (ans + (d1 - d2) * invs[i + 1]) % MOD
print(ans)


Measured memory_bytes: 163372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
int main() {
    ll n,x,t;cin>>n>>x>>t;
    cout<<(n+x-1)/x*t<<endl;
    return 0;
}

Measured memory_bytes: 3628
a = int(input())
b = int(input())
c = int(input())
x = int(input())
 
ans = 0
 
for xx in range(a+1):
    A = 500*xx
    for y in range(b+1) :
        B = 100*y
        for z in range(c+1):
            C = 50*z
            if x == A+B+C:
                ans += 1
            else:
                continue
 
 
print(ans)

Measured memory_bytes: 3060
#include<iostream>

#include <math.h>
using namespace std;

typedef  long long ll;

int main(){
  	
	ll a[5];	
	ll min;
  	ll N;
  	cin >> N;
  	for(int i = 0; i < 5;i++){
      	cin >> a[i];
      	if(i==0)min =a[i];
      	else{
        	if(min>a[i]){
            	min = a[i];
            }
        
        }
    	
    }
  	ll ans;

	if(N>=min){
      if(min != 1)ans = N/min+5;
      else ans = N/min+4;
    }else{
      ans = 5;
    }
    ll b = 1.2;
	cout <<ans <<endl;

 
}

Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		200005									// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数
static int si1Pos[D_ARRAY_MAX];									// 位置[値]
static int si1LCnt[D_ARRAY_MAX];								// 操作回数(左側)[値]
static int si1RCnt[D_ARRAY_MAX];								// 操作回数(右側)[値]

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 配列数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列 - 取得
	for (i = 1; i <= siACnt; i++) {
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d", &si1Array[i]);
		si1Pos[si1Array[i]] = i;
	}

	// 操作回数(左側) - セット
	int liPos = 0;
	si1LCnt[0] = 0;
	for (i = 1; i <= siACnt; i++) {
		if (si1Pos[i] > liPos) {
			si1LCnt[i] = si1LCnt[i - 1];
		}
		else {
			si1LCnt[i] = i - 1;
		}
		liPos = si1Pos[i];
	}

	// 操作回数(右側) - セット
	liPos = INT_MAX;
	si1RCnt[siACnt + 1] = 0;
	for (i = siACnt; i >= 1; i--) {
		if (si1Pos[i] < liPos) {
			si1RCnt[i] = si1RCnt[i + 1];
		}
		else {
			si1RCnt[i] = siACnt - i;
		}
		liPos = si1Pos[i];
	}

	// 最小回数 - 取得
	int liMin = siACnt - 1;
	for (i = 1; i <= siACnt; i++) {
		int liSum = si1RCnt[i] + si1LCnt[i];

		// 最小回数 - 更新
		if (liMin > liSum) {
			liMin = liSum;
		}
	}

	return liMin;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// １行出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
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;
}

#define MAX 8
int n, m;
int g[MAX][MAX];


bool is_ok(vector<int> &perm) {
    if (perm.at(0) != 0) {
        return false;
    }
    for (int i = 1; i < n; i++) {
        if (!g[perm.at(i - 1)][perm.at(i)]) {
            // if (perm.at(0) == 0 && perm.at(1) == 1) {
            //     cout << "{1, 2, 3}" << endl;
            //     cout << i << endl;
            // }
            return false;
        }
    }
    return true;
}


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

    // cout << "g" << endl;
    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < n; j++) {
    //         cout << g[i][j];
    //     }
    //     cout << endl;
    // }
    vector<int> perm(n);
    for (int i = 0; i < n; i++) {
        perm.at(i) = i;
    }
    int ans = 0;
    do {
        // cout << "perm" << endl;
        // for (int p_i : perm) {
        //     cout << p_i << " ";
        // } 
        // cout << endl;
        if (is_ok(perm)) {
            // cout << "perm" << endl;
            // for (int p_i : perm) {
            //     cout << p_i << " ";
            // }    
            // cout << endl;
            ans++;
        }
    } while (next_permutation(begin(perm), end(perm)));
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define mod 1000000007
//#define mod 998244353
#define N 1000001
#define ll long long int
#define pr pair<ll,ll>
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define r(i,a,b) for(ll i=a;i>=b;i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define line cout<<'\n'
#define all(v) v.begin(),v.end()
#define rev(s) reverse(all(s))
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll tt = 1;
    //cin>>tt;
    f(t,1,tt){
        ll n,m;
        cin>>n>>m;
        vector<vector<ll>> adj(n+1);
        f(i,1,m){
            ll x,y;
            cin>>x>>y;
            adj[x].pub(y);
            adj[y].pub(x);
        }
        vector<ll> parent(n+1);
        vector<bool> mark(n+1,0);
        queue<ll> q;
        q.push(1);
        mark[1] = 1;
        while(!q.empty()){
            ll f = q.front();
            for(auto x:adj[f]){
                if(!mark[x]){
                    parent[x] = f;
                    mark[x] = 1;
                    q.push(x);
                }
            }
            q.pop();
        }
        ll cnt = 0;
        f(i,1,n){
            if(mark[i]) cnt++;
        }
        if(cnt==n){
            cout<<"Yes";
            line;
            f(i,2,n){
                cout<<parent[i];
                line;
            }
        }
        else cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 13100
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const int inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
    int h,w;
    char s[100][100];
    int dp[100][100];

    cin>>h>>w;
    rep(i,0,h)
    rep(j,0,w){
      cin>>s[i][j];
      dp[i][j]=inf;
    }

    if(s[0][0]=='#') dp[0][0]=1;
    else dp[0][0]=0;

    rep(i,0,h)
    rep(j,0,w){
      if(i==0 && j==0) continue;
      else if(j==0){
        if(s[i][j]=='.') dp[i][j]=dp[i-1][j];
        else{
          if(s[i-1][j]=='#') dp[i][j]=dp[i-1][j];
          else dp[i][j]=dp[i-1][j]+1;
        }
      }
      else if(i==0){
        if(s[i][j]=='.') dp[i][j]=dp[i][j-1];
        else{
          if(s[i][j-1]=='#') dp[i][j]=dp[i][j-1];
          else dp[i][j]=dp[i][j-1]+1;
        }
      }
      else{
        if(s[i][j]=='.') dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
        else{
          if(s[i-1][j]=='#' && s[i][j-1]=='#') dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
          else if(s[i-1][j]=='#' && s[i][j-1]=='.') dp[i][j]=min(dp[i-1][j],dp[i][j-1]+1);
          else if(s[i-1][j]=='.' && s[i][j-1]=='#') dp[i][j]=min(dp[i-1][j]+1,dp[i][j-1]);
          else if(s[i-1][j]=='.' && s[i][j-1]=='.') dp[i][j]=min(dp[i-1][j]+1,dp[i][j-1]+1);
        }

      }

    }
    cout<<dp[h-1][w-1]<<endl;
    /*rep(i,0,h){
      rep(j,0,w){
         cout<<dp[i][j]<<' ';
      }
      cout<<endl;
    }*/
}


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

// N以下でbitが立っている数
int cnt(int N, int bit){
	int k = (N / (1LL << bit));
	int ans = k *(1LL << (bit - 1));
	return ans + max(0LL,(N - k * (1LL << bit) - (1LL << (bit - 1))+1));
}

signed main(){

	int A, B;
	cin >> A >> B;

	int ans = 0;
	for (int i = 1; i < 45; i++){
//		for (int a = A; a <= B; a++){
//			cerr << i << " " << a << " " << std::bitset<8>(a) << " " << cnt(a, i) << endl;;
//		}
		if ((cnt(B, i) - cnt(A-1, i)) % 2 == 1) ans += (1LL << (i-1));
	}
	cout << ans << endl;

	
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimization ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<int,int>
#define push_back emplace_back
#define push emplace
#define insert emplace
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 10000000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin>>s;
	int n=s.size();
	reverse(s.begin(),s.end());
	int x=0,y=0;
	for(int i=n-1;i>=0;i--){
		if(s[i]=='1'){
			x=x+(power(2,y)*power(3,i))%mod;
			//cout<<x;
			y++;
		}
	}
	x+=power(2,y);
	x=x%mod;
	cout<<x;
	return 0;

}

Measured memory_bytes: 512
def solve(A):
    res = 0
    b = 0
    for a in A:
        a += b
        res += a//2
        if a == b:
            b = 0
        else:
            b = a%2
    return res

if __name__ == '__main__':
    N = int(input())
    A = [int(input()) for _ in range(N)]
    print(solve(A))

Measured memory_bytes: 80488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(long long r){
    cout << r * r << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0;i < n; i++)

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> h(n);
	
	bool ans = true;
	
	rep(i, n){
		cin >> h.at(i);
	}
	
	for(int i = 1; i < n; i++){
		if(h.at(i) - 1 >= h.at(i-1)) h.at(i) -= 1;
		if(h.at(i) < h.at(i-1)) ans = false;
	}
	
	if(ans)cout << "Yes";
	else cout << "No";
	cout << endl;
	
}

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

using i64 = int64_t;

int main(){
    deque<char> deq;
    string s;
    cin >> s;
    for(auto c: s)deq.push_back(c);
    int Q;
    cin >> Q;
    bool flag = false;
    for(int q=0;q<Q;++q){
        int t;
        cin >> t;
        if(t == 1){
            flag = !flag;
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(!flag && f == 1 || flag && f == 2)deq.push_front(c);
            else deq.push_back(c);
        }
    }

    if(!flag){
        for(auto e: deq)cout << e;
    }else{
        for(int i=deq.size()-1;i>=0;--i)cout << deq[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 896
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int[][] c = new int[10][10];
		for(int i = 0; i < 10; i++)
			for(int j = 0; j < 10; j++)
				c[i][j] = sc.nextInt();	
		for(int k = 0; k < 10; k++)
			for(int i = 0; i < 10; i++)
				for(int j = 0; j < 10; j++)
					c[i][j] = Math.min(c[i][j], c[i][k] + c[k][j]);
		int ans = 0;
		for(int i = 0; i < H*W; i++) {
			int x = sc.nextInt();
			if(x != -1)
				ans += c[x][1];
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 46164
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  print $ (fromIntegral $  div n 2 + mod n 2) / (fromIntegral n)

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct Dice{
  int s[6];
  int &top()   {return s[0];}
  int &south() {return s[1];}
  int &east()  {return s[2];}
  int &west()  {return s[3];}
  int &north() {return s[4];}
  int &bottom(){return s[5];}
  void roll(char c){
    //the view from above
    // N
    //W E
    // S
    string b("EWNSRL");
    int v[6][4]={{0,3,5,2},
                 {0,2,5,3},
                 {0,1,5,4},
                 {0,4,5,1},
                 {1,2,4,3},
                 {1,3,4,2}};
    for(int k=0;k<6;k++){
      if(b[k]!=c) continue;
      int t=s[v[k][0]];
      s[v[k][0]]=s[v[k][1]];
      s[v[k][1]]=s[v[k][2]];
      s[v[k][2]]=s[v[k][3]];
      s[v[k][3]]=t;
    }
  }
  using ll = long long;
  ll hash(){
    ll res=0;
    for(int i=0;i<6;i++) res=res*256+s[i];
    return res;
  }
  bool operator==(const Dice &d) const{
    for(int i=0;i<6;i++) if(s[i]!=d.s[i]) return 0;
    return 1;
  }
};

//INSERT ABOVE HERE
signed main(){
  vector<int> ts(6);
  do{
    for(int i=0;i<6;i++) cin>>ts[i];
    int sum=0;
    for(int t:ts) sum+=t;
    if(sum==0) break;

    auto check=
      [&](Dice d)->int{
        for(int i=0;i<6;i++)
          if(d.s[i]<0) return 0;
        int a=d.top()+d.bottom();
        int b=d.east()+d.west();
        int c=d.south()+d.north();
        if(a>b+c) return 0;
        if(b>(a+1)+c) return 0;
        if(c>(a+1)+b) return 0;
        return 1;
      };

    string ans(sum,'Z');
    sort(ts.begin(),ts.end());
    do{
      Dice d;
      for(int i=0;i<6;i++) d.s[i]=ts[i];
      if(!check(d)) continue;

      string res(sum,'Z');
      int flg=0;
      for(int i=0;i<sum;i++){
        string B="ENSW";
        string R="WSNE";
        for(int j=0;j<4;j++){
          d.roll(B[j]);
          d.bottom()--;
          if(check(d)){
            res[i]=B[j];
            break;;
          }
          d.bottom()++;
          d.roll(R[j]);
        }
        flg|=res[i]<ans[i];
        if(flg) continue;
        if(res[i]>ans[i]) break;
      }

      if(flg) ans=res;
    }while(next_permutation(ts.begin(),ts.end()));

    int p,q;
    cin>>p>>q;
    p--;
    if(ans[0]!='Z') cout<<ans.substr(p,q-p)<<endl;
    else cout<<"impossible"<<endl;
  }while(1);
  return 0;
}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int a, b, c, d, e;
	int sum=0;
	cin>> a >> b >> c >> d >> e;

	int min=a;

	if((b+9)%10<=(min+9)%10) min=b;
	if((c+9)%10<=(min+9)%10) min=c;
	if((d+9)%10<=(min+9)%10) min=d;
	if((e+9)%10<=(min+9)%10) min=e;

	sum+=(a/10+1)*10;
	sum+=(b/10+1)*10;
	sum+=(c/10+1)*10;
	sum+=(d/10+1)*10;
	sum+=(e/10+1)*10;

	if(min%10!=0) sum+=min%10-10;

	if(a%10==0) sum-=10;
	if(b%10==0) sum-=10;
	if(c%10==0) sum-=10;
	if(d%10==0) sum-=10;
	if(e%10==0) sum-=10;

	cout<< sum << endl;


}

Measured memory_bytes: 256