akhauriyash/Code-Regression huggingface dataset:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    class UnionFind(object):
        def __init__(self, n=1):
            # 木の親要素を管理するリストparをつくります。
            # par[x] == xの場合には、そのノードが根であることを示します。
            # 初期状態では一切グループ化されていないので、すべてのノードが根になりますね。
            self.par = [i for i in range(n)]
            # 木の高さを持っておき、あとで低い方を高い方につなげる。初期状態は0
            self.rank = [0 for _ in range(n)]
            self.size = [1 for _ in range(n)]

        def find(self, x):
            """
            x が属するグループを探索：
            ある２つの要素が属する木の根が同じかどうかをチェックすればよい。
            つまり、親の親の親の・・・と根にたどり着くまで走査すればよい。
            再帰。
            """
            # 根ならその番号を返す
            if self.par[x] == x:
                return x
            # 根でないなら、親の要素で再検索
            else:
                # 一度見た値については根に直接繋いで経路圧縮
                # 親を書き換えるということ
                self.par[x] = self.find(self.par[x])
                return self.par[x]

        def union(self, x, y):
            """
            x と y のグループを結合
            """
            # 根を探す
            x = self.find(x)
            y = self.find(y)
            # 小さい木に結合して経路圧縮
            if x != y:
                if self.rank[x] < self.rank[y]:
                    x, y = y, x
                # 同じ長さの場合rankが1増える
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
                # 低い方の木の根を高い方の根とする
                self.par[y] = x
                self.size[x] += self.size[y]

        def is_same(self, x, y):
            """
            x と y が同じグループか否か
            """
            return self.find(x) == self.find(y)

        def get_size(self, x):
            """
            x が属するグループの要素数
            """
            x = self.find(x)
            return self.size[x]

    N, Q = map(int, input().split())
    uf = UnionFind(N)  # ノード数Nでクラス継承

    for i in range(Q):
        # A,Bはノード
        P, A, B = map(int, input().split())
        if P == 0:
            # 連結クエリ union
            uf.union(A, B)
        else:
            # 判定クエリ find
            if uf.is_same(A, B):
                print(1)
            else:
                print(0)


resolve()


Measured memory_bytes: 6136
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    string S; cin >> S;
    if (S == "RRR") cout << 3 << endl;
    else if (S == "RRS" || S == "SRR") cout << 2 << endl;
    else if (S == "SSS") cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}


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

int main() {
	
	int n; cin >> n;
	const int p = 26;
	vector<vector<int>> num(n, vector<int>(p, 0));
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 0; j < s[i].size(); j++) {
			num[i][s[i][j] - 'a']++;
		}
	}
	vector<int> ans(p, 1000);
	for (int i = 0; i < p; i++) {
		for (int j = 0; j < n; j++) {
			ans[i] = min(ans[i], num[j][i]);
		}
	}
	string res = "";
	for (int i = 0; i < p; i++) {
		for (int j = 0; j < ans[i]; j++) {
			string tmp{ (char)(i + 'a') };
			res += tmp;
		}		
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<stdio.h>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109311;
const long double pi = 3.1415926535897932384626433;
typedef pair<int, int> P;
struct edge { int to, cost; };

signed main() {
	int n, a, b, c; cin >> n >> a >> b >> c;
	cout << n - a - b + c << endl;
}


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

      int n = sc.nextInt();
      int x = sc.nextInt();

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

      Arrays.sort(m);

      for (int i = 0; i < m.length; i++) {
         x = x - m[i];
      }

      x = x / m[0];
      
      System.out.println(n + x);

   }
}

Measured memory_bytes: 21844
l,r=map(int,input().split())
if l//2019 < r//2019:
    print(0)
else:
    l%=2019
    r%=2019
    ans = 2019
    for i in range(l,r):
        for j in range(i+1,r+1):
            ans = min(ans,(i*j)%2019)
    print(ans)


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

int main() {
  char ch;
  int a[26] = {};
  
  while (cin >> ch) {
    ch = tolower(ch);
    if (isalpha(ch)) a[ch - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    cout << (char)( i + 'a') << " : " << a[i] << endl;
  }
}



Measured memory_bytes: 3092
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, U, V, AB):
    g = defaultdict(list)
    for a, b in AB:
        g[a].append(b)
        g[b].append(a)

    def dfs(u):
        s = [u]
        d = {u: 0}
        while s:
            u = s.pop()
            for v in g[u]:
                if v in d:
                    continue
                d[v] = d[u] + 1
                s.append(v)
        return d

    du = dfs(U)
    dv = dfs(V)


    ans = 0
    for v in sorted(du.keys()):
        if du[v] < dv[v]:
            ans = max(ans, dv[v] - 1)

    return ans


def main():
    N, U, V = read_int_n()
    AB = [read_int_n() for _ in range(N-1)]
    print(slv(N, U, V, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 128104
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
#include<vector>
#include<cstring>
#include<set>
#include<queue>
#include<map>
#include<climits>
#include<cmath>
#include<iomanip>

#define F first
#define S second
#define vi vector
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000007
#define pb push_back
#define ll long long int
#define db double
#define all(v) v.begin(),v.end()
using namespace std;



ll expo(ll n){
    ll t;
    if(n==0)return 1;
    else if(n==1) return 2;
    t=expo(n/2);
    if(n%2){
        return t*t*2;
    }
    else return t*t;
}

//ffrom geek for geek
ll exponentMod(ll A, ll B, ll C)  
{  
    if (A == 0)  
        return 0;  
    if (B == 0)  
        return 1;  
    ll y;  
    if (B % 2 == 0) {  
        y = exponentMod(A, B / 2, C);  
        y = (y * y) % C;  
    }  
    else {  
        y = A % C;  
        y = (y * exponentMod(A, B - 1, C) % C) % C;  
    }  
  
    return (ll)((y + C) % C);  
}

/*
vi<ll> v;
 
ll dsufind(ll x){
    if(v[x]<0){
        return x;
    }
    v[x]=dsufind(v[x]);
    return v[x];
}
 
 
 
void dsujoin(ll x,ll y){
    x=dsufind(x);
    y=dsufind(y);
    
    if(x==y)
    return;
    if(v[x]>v[y])swap(x,y);
    v[y]+=v[x];
    v[x]=y;
}
 */

 



int main(){
    ll n;
    cin>>n;
    ll dp[2][3];
    cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
    FORE(i,1,n-1){
        ll score;

        FOR(j,3){
            cin>>score;
            dp[1][j]=score+max(dp[0][(j+1)%3],dp[0][(j+2)%3]);
        }

        FOR(j,3){
            swap(dp[0][j],dp[1][j]);
        }
    }
    ll ans=0;
    FOR(i,3){
        ans=max(ans,dp[0][i]);
    }
    cout<<ans<<"\n";
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    int ans = 0;
    rep(i, n) for (int j = i + 1; j < n; j++)
    {
        ans += d[i] * d[j];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    int n,ans=0;
    scanf("%d",&n);
    int s[n],a[n];
    for(int i=0;n>i;++i)
    s[i]=i+1;
    for(int i=0;n>i;++i){
        a[i]=0;
        while(s[i]>0){
            s[i]/=10;
            ++a[i];
        }
        if(a[i]%2==1)
        ++ans;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
typedef long long int lld;
 
int main(void) {
  lld n, b, s = 0;
  scanf("%lld", &n);
  b = n % 15;
  s = (n / 15) * (n / 15) * 60;
  for (int i = n - b; i <= n; i++) {
    if (i % 3 * i % 5 != 0) {
      s += i;
    }
  }
  printf("%lld\n", s);
}

Measured memory_bytes: 1700
import sys
def input():
    return sys.stdin.readline()[:-1]

V, E = map(int, input().split())
C = [[float('inf') for _ in range(V)] for _ in range(V)]
for i in range(V):
    C[i][i] = 0
for _ in range(E):
    s,t,d = map(int, input().split())
    C[s][t] = d

for k in range(V):
    for i in range(V):
        for j in range(V):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])

# 負の閉路の検出。自分自身への最短路が負
for i in range(V):
    if C[i][i] < 0:
        print('NEGATIVE CYCLE')
        exit()

ans = []
for i in range(V):
    tmp = []
    for j in range(V):
        if C[i][j] == float('inf'):
            tmp.append('INF')
        else:
            tmp.append(C[i][j])
    ans.append(tmp)

for i in range(V):
    print(*(ans[i]))




Measured memory_bytes: 6620
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class a {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int a, b;
        cin >> a >> b;

        int ans = -1;
        FOR(i, 1, 3) {
            if (i == a) continue;
            if (i == b) continue;
            ans = i;
        }
        cout << ans << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    a solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

d = [list(map(int,input().split())) for i in range(3)]
if d[0][0] + d[1][1] + d[2][2] == d[0][1] + d[1][2] + d[2][0] == d[0][2] + d[1][0] + d[2][1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
n = int(input())

t = 0
h = 0

for i in range(n):
    tc, hc = input().split()
    if tc > hc:
        t += 3
    elif tc < hc:
        h += 3
    elif tc == hc:
        t += 1
        h += 1
print(str(t)+' '+str(h))

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

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  if(s.at(k - 1) == 'A'){
    s.at(k - 1) = 'a';
  }
  if(s.at(k - 1) == 'B'){
    s.at(k - 1) = 'b';
  }
  if(s.at(k -1) == 'C'){
    s.at(k - 1) = 'c';
  }

  cout << s << endl;
}


Measured memory_bytes: 384
@S=(1)x(@p=@i=0..10**5);
$%-=<>;
sub f{my$U=pop;$p[$U]=$U-$p[$U]?f($p[$U]):$U}
/ />${*a=-$'}||(($u=f$a)-($v=f$`)and$S[$p[$v]=$u]+=$S[$v]),$a=$`for<>;
$%+=($u=${-$_})>0&&$S[f$u]for@i;
print$%

Measured memory_bytes: 56576
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	string s,t,u; 
	int x,y;
	cin>>s>>t>>x>>y>>u;
	if(s==u)x--;else y--;
	cout<<x<<' '<<y<<endl; 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a * b) / 2 << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 504
n=gets.to_i
a=gets.split.map(&:to_i)
m=a.delete(a.max)
l=0
lm=1/0.0
a.each do |aa|
  ab=(aa-m/2.0).abs
  lm,l=ab,aa if ab<lm
end
puts [m,l].join(" ")


Measured memory_bytes: 8452
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 double long double
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 
gp_hash_table<int, int> table;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};



inline int mul(int a,int b){return (a*1ll*b)%MOD;}
inline int add(int a,int b){a+=b;if(a>=MOD)a-=MOD;return a;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,MOD-2);}

int fac[N];
int invfac[N];



int n;
v<pi> arr;
int t;
int dp[3300][3300];

int get(int idx,int rem)
{
	if(rem<=0 or idx == n)return 0;
	int&ans = dp[idx][rem];
	if(ans!=-1)return ans;
	ans = 0;
	ans = arr[idx].Y + get(idx+1,rem-arr[idx].X);
	ans = max(ans,get(idx+1,rem));
	return ans;
}

void solve()
{
    cin>>n>>t;
	forn(i,1,n)
	{
		int a,b;
		cin>>a>>b;
		arr.pb({a,b});
	}
	sort(all(arr));
	st(dp,-1);
	cout<<get(0,t);
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;

	fac[0] = 1;
	invfac[0] = inv(1);
	forn(i,1,N-10)
	{
		fac[i] = fac[i-1]*i;
		fac[i]%=MOD;
		invfac[i] = inv(fac[i]);

	}

    while(t--)
    {
        solve();
    }



    return 0;

}

//       g++ -g c.cpp ; ./a.out

Measured memory_bytes: 101504
import sys
import numpy as np

input = sys.stdin.readline
N, M = map(int, input().split())
ss = [None] * M
for i in range(M):
    in_ = list(map(int, input().split()))
    ss[i] = [s-1 for s in in_[1:]]
ps = list(map(int, input().split()))

ans = 0
switch = [0] * N
for x in range(2**N):
    incl = 1
    bin_x = format(x, '0{}b'.format(N))
    switch = np.array([int(bin_x[i]) for i in range(N)])
    for i in range(M):
        if switch[ss[i]].sum() % 2 != ps[i]:
            incl = 0
            break
    ans += incl
        
print(ans)


Measured memory_bytes: 21428
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;


int main(){
    int n,k;
    cin >> n >> k;
    int d,a;
    vector<int> A(100);
    rep(i,k){
        cin >> d;
        rep(j,d){
            cin >> a;
            a--;
            A[a]++;
        }
    }    
    int ans = 0;
    rep(i,n){
        if(A[i] == 0){
            ans++;
        }
    }

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

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int palindrome = ((n % 10) * 100) + (((n % 100) / 10) * 10) + (n / 100);

		if (n == palindrome) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    for (int i=N; i<pow(10,9); i++){
        string s = to_string(i);
        char s0 = s.at(0);
        bool ans = true;
        for (int j=0; j<3; j++){
            if (s0 != s[j]){
                ans = false;
            }
        }

        if (ans){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_i
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define lengthof(x) (sizeof(x) / sizeof(*(x)))

const int INF = 100100100;
const int MOD = 1000000007;
const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// dp[i][j] : コインをi枚使い、j枚が表である確率
double dp[3001][3001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<double> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            // i-1回目で表の枚数がj-1で、i回目が表
            // i-1回目で表の枚数がjで、i回目が裏
            dp[i][j] =
                dp[i - 1][j - 1] * p[i - 1] + dp[i - 1][j] * (1.0 - p[i - 1]);
        }
    }
    double ans = 0;
    for(int i = n / 2 + 1; i <= n; i++) {
        ans += dp[n][i];
    }
    printf("%0.10f\n", ans);

    return 0;
}

Measured memory_bytes: 68992
#include <iostream>
using namespace std;
#define ll long long

ll dp[15], psum[15];

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

	dp[0] = psum[0] = 1;
	for (int i = 1; i <= 11; i++) {
		dp[i] = 26 * dp[i - 1];
		psum[i] = dp[i] + psum[i - 1];
	}

	ll N; cin >> N;

	int flag;
	for (flag = 1; flag <= 11; flag++)
		if (psum[flag] > N) break;

	for (int i = flag - 1; i >= 0; i--) {
		ll x = (N - psum[i]) % dp[i + 1];
		cout << (char)('a' + x / dp[i]);
	}

	return 0;
}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const MAX = 1e5 + 41;

int n;
ll c;
ll x[MAX];
ll v[MAX];

ll pref1[MAX];
ll pref2[MAX];
ll suf1[MAX];
ll suf2[MAX];
ll pref[MAX];
ll ans;

void solve() {
	fi(1, n) {
		pref[i] += pref[i - 1] + v[i];
	}
	fi(1, n) {
		pref1[i] = max(pref1[i - 1], pref[i] - x[i]);
		pref2[i] = max(pref2[i - 1], pref[i] - 2 * x[i]);
	}
	fdi(n, 1) {
		ll s = pref[n] - pref[i - 1];
		suf1[i] = max(suf1[i + 1], s - (c - x[i]));
		suf2[i] = max(suf2[i + 1], s - 2 * (c - x[i]));
	}
	ans = max(suf1[1], pref1[n]);
	fi(1, n - 1) {
		ans = max(ans, pref1[i] + suf2[i + 1]);
		ans = max(ans, pref2[i] + suf1[i + 1]);
	}
	printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d %lld", &n, &c);
	fi(1, n) {
		scanf("%lld %lld", &x[i], &v[i]);
	}  
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int k = scan.nextInt();
    int a = scan.nextInt();
    int b = scan.nextInt();
    int flag = 0;
    for (int i = a; i <=b; i++){
      if (i%k==0){
        flag++;
        System.out.println("OK");
        break;
      }
    }
    if (flag == 0){
      System.out.println("NG");
    }
  }
}

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

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
		sort(all(p));
		p[N-1] = p[N-1]/2;
		cout << accumulate(all(p),0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

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

    solve();
}

void solve() {
    char a;
    std::cin >> a;

    std::cout << (isupper(a) ? 'A' : 'a') << '\n';
}


Measured memory_bytes: 3584
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int a; int b;
    cin >> a >> b;
    int c = b - a;
    int d = c;
    while (c--) {
        d += c;
    }
    cout << d - b << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		
		int cou = 0;
		for(int i=0; i<=a; i++) {
			for(int j=0; j<=b; j++) {
				for(int k=0; k<=c; k++) {
					if(500*i + 100*j +50*k == x) {
						cou++;
					}
				}
		}
		}
		System.out.println(cou);
	}
}

Measured memory_bytes: 35792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

#include <atcoder/all>
using namespace atcoder;

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    scc_graph G(n);
    rep(i,m){
        int a,b;
        scanf("%d%d",&a,&b);
        G.add_edge(a,b);
    }
    vector<vector<int>> ans = G.scc();

    printf("%d\n",(int)ans.size());
    rep(i,ans.size()){
        printf("%d ",(int)ans[i].size());
        rep(j,ans[i].size()){
            printf("%d ",ans[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 40596
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(n-2):
    if (p[i+1]<p[i] and p[i+1]<p[i+2]) or (p[i+1]>p[i] and p[i+1]>p[i+2]):
        pass
    else:
        ans+=1
print(ans)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int s, w;
  cin >> s >> w;
  if(w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  int q,p,r;cin>>p>>q>>r;
  cout << fixed << setprecision(10) << (double)(p*b-(b-a)*q) / (q+r) + b << endl;
}


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

using namespace std;

bool arrOdd(vector<int> arr) {
 	for (int i = 0; i < arr.size(); ++i) 
 		if (arr[i] % 2 != 0) 
 			return false;
	return true;
}
                   
int main() {  
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	int ans = 0;
	while(arrOdd(a))  {
		for (int i = 0; i < n; ++i)
			a[i] /= 2;
		++ans;
	}
	cout << ans;
}


Measured memory_bytes: 256
def main():
    n = input()
    A = map(int,raw_input().split())

    c = mergeSort(A,0,n)

    for i in range(n-1):
        print A[i],
    print A[-1]
    print c

def merge(A,left,mid,right):
    n1 = mid - left
    n2 = right - mid
    L = [A[left+i] for i in range(n1)]
    L += [float("inf")]
    R = [A[mid+i] for i in range(n2)]
    R += [float("inf")]
    i = 0
    j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return i+j

def mergeSort(A,left,right):
    if left+1 < right:
        mid = (left+right)/2
        k1 = mergeSort(A,left,mid)
        k2 = mergeSort(A,mid,right)
        k3 = merge(A,left,mid,right)
        return k1+k2+k3
    else:
        return 0


if __name__ == "__main__":
    main()

Measured memory_bytes: 49672
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) int(a.size())
#define re return
#define all(a) a.begin(),a.end()
using namespace std;
int a[10000];
int main()
{
	int n;
	cin>>n;
	int ans=0;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	for (int i=0;i<n;i++){
		for (int j=i+1;j<n;j++){
			ans+=a[i]*a[j];
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var vals = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToList();
        var dist = vals.Distinct().ToList();
        if (vals.Count == dist.Count)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 40220
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <iomanip>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  
	int n;
    cin>>n;

    string s;
    int p;
    vector<tuple<string,int,int>> r;
    for(int i=0; i<n; i++){
        cin>>s>>p;
        r.emplace_back(s,100-p,i);
    }

    sort(ALL(r));

    for(int i=0; i<n; i++){
        cout<<get<2>(r[i])+1<<endl;
    }
}

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

using namespace std;

bool check(int n)
{
    ostringstream ss;
    if(n<10) return true;
    ss << n;
    string str = ss.str();
    for(int i=1; i<str.size(); i++)
    {
        if(str[i] != str[0] + i) return false;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    int res = -1;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        for(int j=0; j<i; j++)
        {
            if(check(a[i]*a[j])) res = max(res, a[i]*a[j]);
        }
    }
    cout << res << endl;
}

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

int main() {
    int n;
    int ans = 1;
    cin >> n;
    int hi[n];
    for(int i = 0; i < n; i++)
        cin >> hi[i];
    int max = hi[0];
    for(int i = 1; i < n; i++) {
        if(hi[i] >= max) {
            ans++;
            max = hi[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    vector< ll >cnt(26,0);
    string s;cin>>s;
    ll ans = 1 , n=s.size();
    for(ll i=0;i<n;i++)
        ans+=i-cnt[s[i]-'a'] , cnt[s[i]-'a']++;
    cout<<ans;
}





Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef vector< P > vecp;

struct S{
  P p,q;
  S(P p,P q) : p(p),q(q) {}  
};

struct C{
  P p;  double r;
  C(P p,double r):p(p),r(r){}
};

double eps=1e-8,  PI=acos(-1),  PI2=PI*2.0;

bool eq(double a,double b){return (b-a<eps&&a-b<eps);}
bool eq(P a,P b){return (abs(a-b)<eps);}
double Sqrt(double x){  return ( x<0 ? 0.0 : sqrt(x) ); }
double dot(P a,P b){return real(b*conj(a));}
double cross(P a,P b){return imag(b*conj(a));}

double dist(P a,P b,P c){
  if(dot(b-a,c-a)<0)return abs(c-a);
  if(dot(a-b,c-b)<0)return abs(c-b);
  return abs(cross(b-a,c-a))/abs(b-a);
}

P project(P a,P b,P c){  b-=a; c-=a; return a+b*real(c/b); }

double getTime(P a,P b){
  assert( eq(cross(a,b),0) );
  return ( dot(a,b) < 0 ? -1.0 : 1.0 ) * abs(b);
}

double getArg(P a,P b){  return arg(b*conj(a)); }

vecp getCrossPoint(C a,S b, bool debug=false){
  vecp res;
  P base=b.q-b.p,  target=project(b.p,b.q,a.p);
  double length=abs(base), h=abs(a.p-target);
  base/=length;  
  if(a.r+eps<h)return res;
  double w=Sqrt(a.r*a.r-h*h);
  double L=getTime(b.q-b.p,target-b.p)-w,  R=L+w*2.0;
  if( -eps<L && L< length+eps )res.push_back(b.p+base*L);
  if( eq(L,R) )return res;
  if( -eps<R && R< length+eps )res.push_back(b.p+base*R);
  return res;
}

double getArea(C c,P a,P b){
  P va=c.p-a,  vb=c.p-b;
  double A=abs(va), B=abs(vb);
  double f=cross(va,vb), d=dist(a,b,c.p), res=0;
  if( eq(0, f ) )return 0;
  if(A<c.r+eps&&B<c.r+eps)return f*0.5;
  if(d>c.r-eps)return c.r*c.r*PI*getArg(va,vb)/PI2;
  
  vecp u=getCrossPoint(c, S(a,b) );
  assert( !u.empty() );
  u.insert(u.begin(), a),  u.push_back(b);

  for(int i=0;i+1<(int)u.size();i++) res+=getArea(c,u[i],u[i+1]);
  return res;
}

double getArea(vecp t,C c){
  int n=t.size();
  if(n<3)return 0;
  double res=0;
  for(int i=0;i<n;i++){
    P a=t[i], b=t[(i+1)%n];
    res+=getArea(c,a,b);
  }
  return res;
}


double calc(vector< vecp > &t, C c){
  vecp s;
  s.push_back(P(200,0));
  s.push_back(P(-200,0));
  s.push_back(P(-200,-200));
  s.push_back(P(200,-200));
  double sum=getArea(s,c);
  for(int i=0;i<(int)t.size();i++)
    sum+=getArea(t[i],c);
  return sum;
}

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

  vector<vecp> t;
  for(int i=0;i<n;i++){
    int x,w,h;
    cin>>x>>w>>h;
    vecp v;
    v.push_back( P(x,0) );
    v.push_back( P(x+w,0) );
    v.push_back( P(x+w,h) );
    v.push_back( P(x,h) );
    t.push_back(v);
  }

  double left=0,right=200,mid;
  for(int i=0;i<100;i++){
    mid=(left+right)*0.5;
    if( calc(t,C(P(0,mid),cr)) > cr*cr*PI*0.5 )left=mid;
    else right=mid;
  }
  printf("%.8f\n",left);
  return 0;
}

Measured memory_bytes: 3480
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>


using namespace std;

bool inIntArray(int n, int* array, int array_length){
  for(int i=0;i<array_length;i++){
    if(n == array[i]) return true;
  }
  return false;
}


bool bingo(bool card[3][3]){
  for(int i=0;i<3;i++){
    if(card[i][0] && card[i][1] && card[i][2]){
      return true;
    }
  }
  for(int j=0;j<3;j++){
    if(card[0][j] && card[1][j] && card[2][j]){
      return true;
    }
  }
  if(card[0][0] && card[1][1] && card[2][2]){
    return true;
  }
  if(card[0][2] && card[1][1] && card[2][0]){
    return true;
  }
  return false;
}

int main(){
  int A[3][3];
  int N;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> A[i][j];
    }
  }
  cin >> N;
  int b[N];
  for(int i=0;i<N;i++){
    cin >> b[i];
  }
  
  bool card[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      card[i][j] = inIntArray(A[i][j], b, N);
    }
  }
  
  string ans;
  if(bingo(card)){
    ans = "Yes";
  }else{
    ans = "No";
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

template <typename T>
std::vector<int> sort_indexes(const std::vector<T> &v) {
	std::vector<int> idx(v.size());
	std::iota(idx.begin(), idx.end(), 0);
	std::sort(idx.begin(), idx.end(), [&v](int i1, int i2) {return v[i1] < v[i2];});
	return idx;
}


int main() {
	int d;
	std::cin >> d;
	int N=26;
	std::vector<lnt> c(N);
	std::vector<std::vector<lnt> > v(d,std::vector<lnt>(N));
	rep(i,N) std::cin >> c[i];
	rep(i,d) {
		rep(j,N) {
			std::cin >> v[i][j];
		}
	}
	lnt best=-10000000;
	std::vector<int> besta;
	for(int x=0;x<5;x++) {
		for(int y=1;y<20;y++) {
			std::vector<int> ans; ans.reserve(d);
			std::vector<int> last(N,-1);
			rep(i,d) {
				std::vector<int> idx(N);
				std::iota(idx.begin(), idx.end(), 0);
				lnt X=x; lnt Y=y;
				auto f = [&](int ix) -> lnt {
					return c[ix]*(i-last[ix]+X)*Y+v[i][ix]*2;
				};
				std::sort(idx.begin(), idx.end(), [&](int i1, int i2) {return f(i1) > f(i2) ;});
				last[idx[0]]=i;
				ans.emplace_back(idx[0]);
				//print(idx[0]+1);
			}
			{
				lnt sum=0;
				std::vector<int> last(N,-1);
				rep(i,d) {
					int t=ans[i];
					sum+=v[i][t];
					last[t]=i;
					rep(j,N) sum-=(i-last[j])*c[j];
				}
				if(sum>best) {
					besta=ans;
					best=sum;
				}
			}
		}
	}
	rep(i,d) {
		print(besta[i]+1);
	}
}


Measured memory_bytes: 3760
#!/usr/bin/env python3
#AGC3 B

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n = I()
a = [I() for _ in range(n)]

ans = 0
for i in range(n):
    if a[i] % 2 == 0:
        ans += a[i] // 2
        a[i] = 0
    else:
        ans += a[i] // 2
        a[i] = 1
        if i < n-1:
            if a[i+1] >= 1:
                ans += 1
                a[i] -= 1
                a[i+1] -= 1
print(ans)


Measured memory_bytes: 44380
def main():
    s = input()
    n = len(s)
    ans = 0

    for i in range(1 << n-1):
        temp = 0
        for j in range(n-1):
            if i & (1 << j):
                ans += int(''.join(s[temp:j+1]))
                temp = j+1
        ans += int(''.join(s[temp:]))
    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
  int n; cin >> n;
  vector<int> p(n);
  rep( i, 0, n ) cin >> p.at(i);

  int Ans = 0;

  rep( i, 0, n-2 ) {
    int MinVal = min( p.at(i), p.at(i+2) );
    int MaxVal = max( p.at(i), p.at(i+2) );
    if ( MinVal < p.at(i+1) && p.at(i+1) < MaxVal ) Ans++;
  }

  cout << Ans <<endl;
}


Measured memory_bytes: 256
n = int(input())
d = list(input().split() for i in range(n))
#print(d)
flug=False
count = []
for i in range(n):
  if d[i][0] == d[i][1]:
    count.append(int(i))
#print(count)
for j in range(2, len(count)):
  if count[j-2] == count[j-1] - 1 and count[j-1] == count[j] - 1:
    print("Yes")
    flug = True
    break
if flug == False:
	print("No")
  
  

Measured memory_bytes: 9184
U,R,D,L="URDL"
d={i:[]for i in"URDL"}
_,*a=map(str.split,open(0))
for*z,u in a:d[u]+=[*map(int,z)],
N,P,M=9e9,"x+y,","x-y,"
for*F,S in(D,U,"x,y,"),(L,R,"y,x,"),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
 n=p=-9e9
 for x,y,r in sorted(eval(f"[({S}Q)for Q,P in enumerate(F)for x,y in d[P]]")):
  if x-n:
   if r:n,p=x,y
  elif r:p=y
  else:N=min(N,y-p)
print(["SAFE",N*5][N<9e9])

Measured memory_bytes: 131216
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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 || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    int N,M,Q; cin >> N >> M >> Q;
    int c[550][550],imos[550][550]; // c[ L ][ R ]
    memset(c,0,sizeof(c));
    memset(imos,0,sizeof(imos));

    for (int i = 0; i < M; i++){
        int l,r; cin >> l >> r;
        c[l][r]++;
    }

    for (int i = 0; i < 505; i++){
        for (int j = 0; j < 505; j++){
            if (j == 0) imos[i][j] = c[i][0];
            else imos[i][j] = c[i][j] + imos[i][j-1];
        }
    }
    vector<int> v(0);
    for (int i = 0; i < Q; i++){
        int p,q; cin >> p >> q;
        ll sum = 0;
        for (int num = p; num <= q; num++){
            sum += imos[num][q]-imos[num][p-1];
        }
        v.push_back(sum);
    }
    for (auto e : v){
        cout << e << endl;
    }
}

Measured memory_bytes: 3832
h, w = map(int, input().split())
a = []
for _ in range(h):
    a.append(input())

pos = (0, 0)
pre = 1
nxt = 0
while pos!=(w-1, h-1):
    x, y = pos
    if x<w-1 and a[y][x+1]=='#':
        nxt += 1
        pos = (x+1, y)
    if y<h-1 and a[y+1][x]=='#':
        nxt += 1
        pos = (x, y+1)
    if x>0 and a[y][x-1]=='#':
        pre += 1
    if y>0 and a[y-1][x]=='#':
        pre += 1
    if nxt!=1 or pre!=1:
        print('Impossible')
        break
    pre = 0
    nxt = 0
else:
    tmp = 0
    for i in a:
        tmp += i.count('#')
    if tmp!=h+w-1:
        print('Impossible')
    else:
        print('Possible')

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

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl //[l, r))

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n;
vi vec;
vi diff;

int ans=1;

signed main(){
    io();

    in(n);
    vec.resize(n);
    rep(i,n) in(vec[i]);

    REP(i,0,n-1){
        diff.pb(vec[i+1]-vec[i]);
    }
    bool inc;
    for(auto e:diff){
        if(e>0){
            inc=true;
            break;
        }else if(e<0){
            inc=false;
            break;
        }
    }

    rep(i,diff.size()){
        int e=diff[i];
        //show(i,inc,e,ans);
        if(e==0) continue;
	
        if(e>0&&!inc){
            ans++;
            REP(j,i+1,diff.size()){
                if(diff[j]==0) continue;
                if(diff[j]>0) inc=true;
                else if(diff[j]<0) inc=false;
                break;
            }
        }else if(e<0&&inc){
            ans++;
            REP(j,i+1,diff.size()){
                if(diff[j]==0) continue;
                if(diff[j]>0) inc=true;
                else if(diff[j]<0) inc=false;
                break;
            }
        }
    }
    out(ans);

    return 0;
}


Measured memory_bytes: 2168
use std::collections::HashSet;
use whiteread::parse_line;

fn main() {
    let s: String = parse_line().unwrap();
    let s = s.as_str();
    let mut set: HashSet<char> = HashSet::new();
    let mut alphabet: Vec<char> = Vec::new();

    for i in 0..26 {
        alphabet.push(('a' as u8 + i) as char);
    }
    for c in s.chars() {
        set.insert(c);
    }
    for c in set.iter() {
        alphabet.remove(alphabet.iter().position(|x| x == c).unwrap());
    }
    if alphabet.is_empty() {
        println!("None");
    } else {
        println!("{}", alphabet[0]);
    }
}


Measured memory_bytes: 2272