akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from collections import deque
class HopcroftKarp:
    def __init__(self, N0, N1):
        self.N0 = N0
        self.N1 = N1
        self.N = N = 2+N0+N1
        self.G = [[] for i in range(N)]
        for i in range(N0):
            forward = [2+i, 1, None]
            forward[2] = backward = [0, 0, forward]
            self.G[0].append(forward)
            self.G[2+i].append(backward)
        self.backwards = bs = []
        for i in range(N1):
            forward = [1, 1, None]
            forward[2] = backward = [2+N0+i, 0, forward]
            bs.append(backward)
            self.G[2+N0+i].append(forward)
            self.G[1].append(backward)

    def add_edge(self, fr, to):
        #assert 0 <= fr < self.N0
        #assert 0 <= to < self.N1
        v0 = 2 + fr
        v1 = 2 + self.N0 + to
        forward = [v1, 1, None]
        forward[2] = backward = [v0, 0, forward]
        self.G[v0].append(forward)
        self.G[v1].append(backward)

    def bfs(self):
        G = self.G
        level = [None]*self.N
        deq = deque([0])
        level[0] = 0
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        self.level = level
        return level[1] is not None

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

    def flow(self):
        flow = 0
        G = self.G
        bfs = self.bfs; dfs = self.dfs
        while bfs():
            *self.it, = map(iter, G)
            while dfs(0, 1):
                flow += 1
        return flow

    def matching(self):
        return [cap for _, cap, _ in self.backwards]

def resolve():
    n=int(input())
    AB=[tuple(map(int,input().split())) for _ in range(n)]
    CD=[tuple(map(int,input().split())) for _ in range(n)]

    mm=HopcroftKarp(n,n)
    for i in range(n):
        a,b=AB[i]
        for j in range(n):
            c,d=CD[j]
            if(a<c and b<d):
                mm.add_edge(i,j)
    print(mm.flow())
resolve()

Measured memory_bytes: 45036
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

ll get(ll x){
  if(x<0) return 0;
  if(x%4==0) return x;
  if(x%4==1) return 1;
  if(x%4==2) return x+1;
  return 0;
}

int main(){FIN;
  ll l,r; cin >> l >> r;
  cout << (get(r)^get(l-1)) << "\n";
}

Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> > 
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

int mul(int a, int b) {
  a += mod; b += mod; 
  a %= mod; b %= mod; return ((a * b) % mod);
}

void solve() {
  int n, k, ans = 1, K; cin >> n >> k;
  K = k;
  vector <int> p, neg, z;
  vector <pii> v;
  for(int i = 0; i < n; i++) {
    int x, s; cin >> x;
    if(x > 0) {
      p.pb(x);
      s = 1;
    }
    if(x < 0) {
      neg.pb(abs(x));
      s = -1;
    }
    if(x == 0) {
      z.pb(x);
      s = 1;
    }
    v.pb({abs(x), s});
  }
  sort(all(p)); sort(all(neg)); sort(all(z)); sort(all(v));
  int i = sz(p)-1, j = sz(neg)-1;
  
  if(k%2) {
    if(!p.empty()) {
      k--; ans = mul(ans, p[i]);
      i--;
    } 
  }

  while(k && (i > 0 || j > 0)) {
     int a = -INF, b = -INF;
     if(i >= 1) {
       a = p[i] * p[i-1];
     }
     if(j >= 1) {
       b = neg[j] * neg[j-1];
     }
     if(a > b) {
       ans = mul(ans, a);
       k-=2; i-=2;
     }
     else {
       ans = mul(ans, b);
       k-=2; j-=2;
     }
  }
  if(k) { 
    if(!z.empty()) {
      ans = 0;
    } else {
      ans = 1;
      for(int l = 0; l < K; l++) {
         ans = mul(ans, v[l].ss * v[l].ff);
      }
    }
  }
  cout << ans << '\n';
}

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

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1;  //cin >> t;
   for(int i = 1; i <= t; i++) {
     solve();
  }
}    
  

Measured memory_bytes: 9484
# # # # class Segtree # # # #

#      0
#   1     2
# 3   4  5  6
#       :
# leaf i - n-1+i
# parent   - (i-1)//2
# children - 2*i+1, 2*i+2

class Segtree:
    # modify UNIT and oper depending on the reduce operation

    UNIT = 0  # sum:0 min:BIG max:-BIG gcd:1 lcm:0 ..

    @classmethod
    def oper(c,x,y):
        return x|y  # sum:+ min/max/gcd/lcm:(same)

    def __init__(s,l):
        s.n = 1
        while s.n<l:
            s.n *= 2
        s.ary = [Segtree.UNIT for i in range(2*s.n-1)]

    def get(s,i):
        return s.ary[i+s.n-1]

    def set(s,i,v):
        k = i+s.n-1
        s.ary[k] = v
        while k>0:
            k = (k-1)//2
            s.ary[k] = Segtree.oper( \
                        s.ary[2*k+1], s.ary[2*k+2])

    def setary(s,a):
        for i,v in enumerate(a):
            s.ary[i+s.n-1] = v
        for k in range(s.n-2,-1,-1):
            s.ary[k] = Segtree.oper( \
                        s.ary[2*k+1], s.ary[2*k+2])

    def query(s,x,y):
        return s.querycore(x,y,0,0,s.n)

    # x,y: from query  k: suffix at focus l,r: range for k
    # right ends (y,r) not included

    def querycore(s,x,y,k,l,r):
        if r<=x or y<=l:
            return Segtree.UNIT
        if x<=l and r<=y:
            return s.ary[k]
        vl = s.querycore(x,y,2*k+1,l,(l+r)//2)
        vr = s.querycore(x,y,2*k+2,(l+r)//2,r)
        return Segtree.oper(vl, vr)

# # # # class Segtree end # # # #

inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()

n = inn()
sgt = Segtree(n)
ss = ins()
s = []
for i in range(n):
    sgt.set(i, 1<<(ord(ss[i])-ord('a')))

#ddprint("tree")
#for c in alpha:
#    ddprint(c)
#    ddprint(tr[c])

q = inn()
for qq in range(q):
    x,y,z = input().split()
    #ddprint(f"x {x} y {y} z {z}")
    if x == '1':
        i = int(y)-1
        c = z
        sgt.set(i, 1<<(ord(c)-ord('a')))
    else:
        l = int(y)
        r = int(z)
        sm = 0
        v = sgt.query(l-1,r)
        for i in range(26):
            if (v>>i)%2==1:
                sm += 1
        print(sm)


Measured memory_bytes: 115952
fun main() {
    var n = readInt()
    var s = arrayListOf<String>()
    repeat(n) {
        s.add(readString())
    }

    println(s.distinct().count())
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

Measured memory_bytes: 75892
#include<bits/stdc++.h>
using namespace std;
string ss;
bool w,n,e,s;
inline bool check()
{
    if(w==e&&n==s)return 1;
    return 0;
}
int main()
{
    getline(cin,ss);
    for(int i=0;i<ss.length();i++){
	    if(ss[i]=='W')w=1;
	    else if(ss[i]=='N')n=1;
	    else if(ss[i]=='E')e=1;
	    else s=1;
	}
	if(check())puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
/*mennseki*/
#include<stdio.h>
int main(void)
{
  int r,x;
  scanf("%d",&r);
  x=1;
  if(x*x*3.14<=r*r*3.14){
    printf("%d\n",r*r);
  }
  else{
    printf("%d\n",x);
  }
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main() {
	
	int S,h,h2,m,m2,s,s2;
	scanf("%d",&S);
	h2=S%3600;
	m2=S%60;
	s2=S%1;
	h=(S-h2)/3600;
	m=(S-m2-h*3600)/60;
	s=S-m*60-h*3600;
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}


Measured memory_bytes: 2668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n,ans=0,height=0;
  cin >> n;
  vector<int> v=input(n);
  rep(i,n){
    if(height<=v[i]){
      ans++;
    }
    height=max({height,v[i]});
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef long int li;
int main(){
  li a,b;
  scanf("%ld%ld",&a,&b);

  li term[40],over[40],end[40];
  li len=b-a+1;
  int i;
  term[0]=term[1]=4;
  for(i=2;i<40;i++) term[i]=term[i-1]*2;
  for(i=0;i<40;i++){
    over[i]=len%term[i];
    end[i]=b%term[i];
  }

  /*
  for(i=0;i<40;i++)
    printf("%2ld ",end[i]);
  printf("\n");
  for(i=0;i<40;i++)
    printf("%2ld ",over[i]);
  printf("\n");
  */

  int s[40]={};
  switch(over[0]){
  case 0: s[0]=0; break;
  case 1: s[0]=end[0]%2; break;
  case 2: s[0]=1; break;
  case 3: s[0]=1-end[0]%2; break;
  }


  li init,temp;
  for(i=1;i<40;i++){
    init=end[i]-over[i]+1;
    if(init<0){
      temp=init-1;
      init=end[i]+1;
      end[i]=term[i]+temp;
    }

    if(end[i]<term[i]/2) continue;
    if(init<term[i]/2) init=term[i]/2;
    s[i]=(end[i]-init+1)%2;
  }

  li ans=0,d=1;

  /*  
  for(;a<=b;a++){
    ans^=a;
  }
  printf("%ld\n",ans);
  ans=0;
  */
  
  for(i=0;i<40;i++){
    ans+=s[i]*d;
    d*=2;
  }


  
  printf("%ld",ans);

  /*
  for(i=0;i<40;i++)
    printf("%2ld ",end[i]);
  printf("\n");
  for(i=0;i<40;i++)
    printf("%2ld ",over[i]);
  printf("\n");
  for(i=0;i<40;i++)
    printf("%2ld ",s[i]);
  printf("\n");
  */  
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF 1e9

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,n; cin>>h>>n;
    vi a(n),b(n);
    int amax=0;
    rep(i,n){
        cin>>a[i]>>b[i];
        amax = max(amax, a[i]);
    }
    int sz = h+amax;
    vi dp(sz, INF);
    dp[0] = 0;
    rep(i,n)rep(j,sz){
        if (j>=a[i]) dp[j] = min(dp[j], dp[j-a[i]]+b[i]);
    }
    int ans = INF;
    for(int i=h; i<sz; i++){
        ans = min(ans, dp[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s, t;
    cin >> s >> t;
    vector<int> ns(26), nt(26);
    for(int i=0; i<s.size(); i++){
        ns[s[i] - 'a']++;
        nt[t[i] - 'a']++;
        // cout << "a" << s[i] - 'a' << endl;
    }
    
    bool ans = true;
    sort(ns.begin(), ns.end());
    sort(nt.begin(), nt.end());
    
    for(int i=0; i<26; i++){
        if(ns[i] != nt[i]) ans = false;
    }
    
    printf("%s\n", (ans) ? "Yes": "No");
}


Measured memory_bytes: 3904
# @author 

import sys

class DGatheringChildren:
    def solve(self):
        s = input().strip()
        n = len(s)
        i = 0
        last = 0
        ans = [0] * n
        while i < n - 1:
            if s[i] == 'R' and s[i + 1] == 'L':
                ans[i + 1] += 1
                for j in range(last, i + 1):
                    if (i - j) % 2 == 0:
                        ans[i] += 1
                    else:
                        ans[i + 1] += 1
                k = i + 2
                while k < n and s[k] == 'L':
                    if (k - i) % 2 == 0:
                        ans[i] += 1
                    else:
                        ans[i + 1] += 1
                    k += 1

                last = k
                i += 1

            i += 1

        print(*ans)

solver = DGatheringChildren()
input = sys.stdin.readline

solver.solve()


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

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
 
// a^{-1} mod を計算する
ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}
 
const int MAX = 510000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    COMinit();
    ll f_max = 0;
    ll f_min = 0;
    for (int i = 0; i < N; i++) {
        f_min += A[i] * COM(N - i - 1, K - 1);
        f_min %= MOD;
    }
    for (int i = N - 1; i >= 0; i--) {
        f_max += A[i] * COM(i, K - 1);
        f_max %= MOD;
    }
    cout << (f_max - f_min + 2 * MOD) % MOD << "\n";
    
    return 0;
}

Measured memory_bytes: 12928
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop

n=n0()
h=n1()

c=h[n-1]
f=True
for i in range(n-1,-1,-1):
    if c>h[i]:
        c=h[i]
    elif c+1>=h[i]:
        continue
    else:
        f=False
        break
    
p0(f)
    

Measured memory_bytes: 14704
#include <iostream>
using namespace std;
int main(void){
    char s[101];
    char p[101];
    cin >> s >> p;
    bool flg = false;
    int i = 0;
    while (s[i] != '\0') {
        int j = i;
        int k = 0;
        while (1) {
            if (p[k] == '\0') {
                flg = true;
                break;
            }
            if (s[j] != p[k]) break;
            j++;
            k++;
            if (s[j] == '\0') j = 0;
        }
        if (flg) break;
        i++;
    }
    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3096
import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      long num = sc.nextLong();
      long mini = sc.nextLong();
      while(sc.hasNext()){
        long a = sc.nextLong();
        if(a < mini){mini = a;}
      }
      if(num%mini != 0){System.out.println(num/mini + 5);}
      else{System.out.println(num/mini + 4);}
    }
}

Measured memory_bytes: 23252
#include <cstdio>
 
using namespace std;
 
int x, n;
bool used[105];
 
int main() {
  scanf("%d%d", &x, &n);
  for (int i = 0; i < n; i++) {
    int p; scanf("%d", &p);
    used[p] = true;
  }
  for (int i = 0; i < 100; i++) {
    if (!used[x - i]) {
      printf("%d\n", x - i);
      return 0;
    }
    if (!used[x + i]) {
      printf("%d\n", x + i);
      return 0;
    }
  }
}

Measured memory_bytes: 1736
# Aizu Problem 0217: Walking in the Hospital

import sys, math, os, fractions

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    n = int(input())
    if n == 0:
        break
    high = 0
    for _ in range(n):
        no, w1, w2 = [int(__) for __ in input().split()]
        w = w1 + w2
        if w > high:
            high = w
            patient = no
    print(patient, high)
        

Measured memory_bytes: 10144
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, k, fact[N], inv[N], ans;

inline int mult (int a, int b) {
   return 1ll * a * b % mod;
}

inline int add (int a, int b) {
   a += b;
   if (a >= mod) a -= mod;
   return a;
}

inline int binpow (int a, int b) {
   int res = 1;
   while (b) {
      if (b & 1) res = mult (res, a);
      a = mult (a, a);
      b >>= 1;
   }
   return res;
}

inline int C (int n, int k) {
   if (n < k) return 0;
   return mult (fact[n], mult (inv[k], inv[n - k]));
}

inline void f (int n, int m) {
   for (int i = 1; i < n; i ++) {
      ans = add (ans, mult (i, mult (C (n * m - 2, k - 2), mult (n - i, mult (m, m)))));
   }
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n >> m >> k;
   fact[0] = inv[0] = 1;
   for (int i = 1; i <= n * m; i ++) fact[i] = mult (fact[i - 1], i), inv[i] = binpow (fact[i], mod - 2);
   f (n, m);
   f (m, n);
   cout << ans;
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 1792
N, X = map(int, input().split());
L = [int(i) for i in input().split()];
D = [int(0) for _ in range(len(L) + 1)];
count = 1;
for i in range(1, len(L)+1):
    D[i] = D[i-1] + L[i-1];
    if D[i] > X:
        break;
    elif D[i] == X:
        count += 1;
        break;
    count += 1;
print(count);


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin >> n;
  vector<ll> a(n),sum(n+1);
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum[i+1]=sum[i]+a[i];
  }
  ll ans=1e15;
  for(int i=1;i<n;i++){
    ans=min(ans,abs(sum[n]-2*sum[i]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<int,int>;
using Graph =vector<string>;
Graph field;
queue<P> q;

int main() {
  ll n,w,k,ab;
  ab=0;
  ll ans=0;
  cin>>n>>w>>k;
  field.resize(7);
  rep(i,n){
    cin>>field[i];
  }
  vector<int> a(7,0);
  vector<int> b(7,0);
  rep(i,n){
    rep(j,w){
      if(field[i][j]=='#'){
        a[i]++;
        ab++;
      }
    }
  }
  rep(i,w){
    rep(j,n){
      if(field[j][i]=='#')b[i]++;
    }
  }
  rep(s,1<<(n+w)){
    ll abc=ab;
    queue<int> q1;
    queue<int> q2;
    vector<int> q3;
    rep(i,n){
      if(s>>i&1){
        abc-=a[i];
        q1.push(i);
      }
    }
    rep(i,w){
      if(s>>(i+n)&1){
        abc-=b[i];
        q2.push(i);
      }
    }
    while(!q2.empty()){
      ll d;
      d= q2.front();
      q3.emplace_back(d);
      q2.pop();
    }
    while(!q1.empty()){
      ll d;
      d=q1.front();
      q1.pop();
      for(auto d1:q3){
        if(field[d][d1]=='#'){
          abc++;
        }
      }
    }
    if(k==abc){
      ans++;
    }
  }
  cout<<ans<<endl;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	s[k-1] = tolower(s[k-1]);
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int INF = 1e9 + 7;
int _;

int main() {
	INIT
	int n;
	cin >> n;
	ll sum = 0;
	rep (i, 1, n + 1) {
		if (i % 3 == 0 || i % 5 == 0) {
			continue;
		}
		else sum += i;
	}
	cout << sum;

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

int main()
{
	ll H, W;
	cin >> H >> W;

	if (H == 1 || W == 1)
	{
		cout << 1 << "\n";
	}
	else if (H % 2 == 1 && W % 2 == 1)
	{
		if (H > W)
			swap(H, W);
		cout << H * (W - 1) / 2 + (H + 1) / 2 << "\n";
	}
	else
	{
		cout << H * W / 2 << "\n";
	}
}


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

n,a,b,c = map(int,input().split())

ab = []
ac = []
bc = []


s = [0]*n
for i in range(n):
    inp = input()
    #print(inp)
    if inp == "AB\n":
        ab.append(i)
    elif inp == "AC\n":
        ac.append(i)
        s[i] = 1
    else:
        bc.append(i)
        s[i] = 2

res = []
for i in range(n):
    if s[i] == 0:
        if a == b:
            if a == 0:
                print("No")
                exit()
            p = bisect.bisect_left(ac,i)
            q = bisect.bisect_left(bc,i)
            if p >= len(ac):
                a -= 1
                b += 1
                res.append("B")
            elif q >= len(bc):
                a += 1
                b -= 1
                res.append("A")
            else:
                if ac[p] > bc[q]:
                    a -= 1
                    b += 1
                    res.append("B")
                else:
                    a += 1
                    b -= 1
                    res.append("A")
        elif a > b:
            a -= 1
            b += 1
            res.append("B")
        else:
            a += 1
            b -= 1
            res.append("A")
    elif s[i] == 1:
        if a == c:
            if a == 0:
                print("No")
                exit()
            p = bisect.bisect_left(ab,i)
            q = bisect.bisect_left(bc,i)
            if p >= len(ab):
                a -= 1
                c += 1
                res.append("C")
            elif q >= len(bc):
                a += 1
                c -= 1
                res.append("A")
            else:
                if ab[p] > bc[q]:
                    a -= 1
                    c += 1
                    res.append("C")
                else:
                    a += 1
                    c -= 1
                    res.append("A")
        elif a > c:
            a -= 1
            c += 1
            res.append("C")
        else:
            a += 1
            c -= 1
            res.append("A")
    elif s[i] == 2:
        if b == c:
            if b == 0:
                print("No")
                exit()
            p = bisect.bisect_left(ab,i)
            q = bisect.bisect_left(ac,i)
            if p >= len(ab):
                b -= 1
                c += 1
                res.append("C")
            elif q >= len(ac):
                b += 1
                c -= 1
                res.append("B")
            else:
                if ab[p] > ac[q]:
                    b -= 1
                    c += 1
                    res.append("C")
                else:
                    b += 1
                    c -= 1
                    res.append("B")
        elif b > c:
            b -= 1
            c += 1
            res.append("C")
        else:
            b += 1
            c -= 1
            res.append("B")   

print("Yes")
print(*res,sep='\n')

Measured memory_bytes: 83276
n, x = input().split()

a = list(map(int, input().split()))
a.sort()

def distributeCandy(a):

    stock = int(x)
    result = 0

    for i in a:
        if stock < i:
            print(result)
            return

        if stock == 0:
            result += 1
            print(result)
            return

        result += 1
        stock -= i

    if stock == 0:
        print(result)
    else:
        print(result - 1)

distributeCandy(a)







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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }

    ll A = (W + 1) / 2;
    ll ans = ((H + 1) / 2) * A + (H / 2) * (W - A);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int n;
	long long a[10100],b[10100],c[10100];
	while(scanf("%lld",&n)!=EOF)
	{
		long long i,k=0,j=0;
		for(i=1;i<=n;i++)
		scanf("%lld",&a[i]);
		for(i=1;i<=n;i++)
		scanf("%lld",&b[i]);
		for(i=1;i<=n;i++)
		{
			c[i]=a[i]-b[i];
			if(c[i]<0)
			{
				k+=abs(c[i])/2;
			}
			else
			j+=c[i];
		}
		if(k>=j)
		printf("Yes\n");
		else
		printf("No\n");
		
	} 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    
    rep(i, N + 1) {
        if (i * 27 / 25 == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 305, mod = 1000000007;
#define rep(i, s, t) for(int i=s, tt=t; i<=tt; ++i)
int N, M;
int f[maxn][maxn][maxn];
vector<pair<int,int> > lm[maxn];
bool check(int r, int g, int b, int l, int x) {
    int c = (r >= l) + (g >= l) + (b >= l);
    return c == x;
}
int che(int r, int g, int b, int k) {
    for(int i = 0; i < (int)lm[k].size(); ++i)
	if(!check(r, g, b, lm[k][i].first, lm[k][i].second))
	    return f[r][g][b] = 0;
    return f[r][g][b];
}
void ext(int r, int g, int b, int k) {
    if(!che(r, g, b, k)) return;
    (f[k + 1][g][b] += f[r][g][b]) %= mod;
    (f[r][k + 1][b] += f[r][g][b]) %= mod;
    (f[r][g][k + 1] += f[r][g][b]) %= mod;
}
int main() {
    scanf("%d%d", &N, &M);
    for(int i = 1, l, r, x; i <= M; ++i) {
	scanf("%d%d%d", &l, &r, &x);
	lm[r].push_back(make_pair(l, x));
    }
    f[0][0][0] = 1, ext(0, 0, 0, 0);
    rep(k, 1, N - 1) rep(i, 0, k - 1) rep(j, 0, k - 1)
	ext(i, j, k, k), ext(i, k, j, k), ext(k, i, j, k);
    ll ans = 0;
    rep(i, 0, N - 1) rep(j, 0, N - 1)
	ans = ans + che(i, j, N, N) + che(i, N, j, N) + che(N, i, j, N);
    printf("%d\n", int(ans % mod));
    return 0;
}
// r g b


Measured memory_bytes: 110848
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int A, B; cin >> A >> B;
  char ans[100][100];
  REP(i, 50) REP(j, 100){
    ans[i][j] = '#'; ans[i+50][j] = '.';
  }
  int cnt = 0;
  for(int i = 0; i < 50; i+=2){
    for(int j = 0; j < 100; j+=2){
      if(cnt == A-1) continue;
      ans[i][j] = '.';
      cnt++;
    }
  }
  cnt = 0;
  for(int i = 99; i >= 50; i-=2){
    for(int j = 0; j < 100; j+=2){
      if(cnt == B-1) continue;
      ans[i][j] = '#';
      cnt++;
    }
  }
  cout << 100 << ' ' << 100 << endl;
  REP(i, 100){
    REP(j, 100) cout << ans[i][j];
    cout << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  set<int>s;
  map<int,int>m;
  for(int i=0;i<n;i++)
  {
    int d;
    cin>>d;
    if(s.count(d)==0)
    {
		m.insert(pair<int,int>(d,0));
    }
    m[d]++;
    s.insert(d);
  }
  long long ans=0;
  for(auto x:s)
  {
    if(m[x]!=x)
    {
      if(m[x]>x)ans+=m[x]-x;
      else ans+=m[x];
    }
  }
  cout<<ans<<endl;
  return 0;
}
   

Measured memory_bytes: 9216
public class Main {
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (a > b) {
				System.out.println("a > b");
			} else if (a < b) {
				System.out.println("a < b");
			} else {
				System.out.println("a == b");
			}
		}
	}
}


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

const int N = 100005;
typedef pair<int, int> ii;
	
int n, pos, sz[N];
long long sum;
long long d[N];
long long a[N];
long long res[N];
vector<ii> G[N];

void dfs(int u, int p) {
	sz[u] = 1;
	for (auto v : G[u]) {
		if (v.first == p) continue; 
		dfs(v.first, u), sz[u] += sz[v.first];
		if (n != 2 * sz[v.first]) {
			res[v.second] = (a[v.first] - a[u]) / (n - 2 * sz[v.first]);
		}
		else pos = v.first;
	}
}

void redfs(int u, int p) {
	sum += d[u];
	for (auto v : G[u]) {
		if (v.first == p) continue;
		d[v.first] = d[u] + res[v.second], redfs(v.first, u);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v;
		G[u].push_back(ii(v, i));
		G[v].push_back(ii(u, i));
	}
	for (int i = 1; i <= n; ++i) cin >> a[i];
	dfs(1, 1), redfs(1, 1);
	for (int i = 1; i < n; ++i) {
		if (!res[i]) res[i] = (a[1] - sum) / sz[pos];
		cout << res[i] << '\n';
	}
}

Measured memory_bytes: 16896
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main(void){
	ll n, k, ans = 0;
	cin >> n >> k;
	if (k == 0) {
		cout << n*n << endl;
		return 0;
	}
	for (ll i = 1;i <= n;i++) {
		if (n%i == 0) {
			ll num = n / i;
			if (i  - k >= 0) {
				ans = ans + num * (i -  k);
			}
		}
		else {
			ll num = n / i;
			if (i  - k >= 0) {
				ans = ans + num * (i -  k);
				if (n%i - k >= 0)ans = ans + n % i - k + 1;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 5e2 + 10;
long long a, b;
int main()
{
    cin >> a >> b;
    cout << abs((a - 2) * (b - 2));
}

Measured memory_bytes: 256
N = int(input())
A = input()
B = input()
MOD = 10 ** 9 + 7

i = 0
vh = []
while i < N:
    if A[i] == B[i]:
        vh.append('v')
        i += 1
    else:
        vh.append('h')
        i += 2
# print(vh)

if vh[0] == 'v':
    ans = 3
else:
    ans = 6
for j in range(1, len(vh)):
    if vh[j] == 'v':
        if vh[j - 1] == 'v':
            ans = (ans * 2) % MOD
        else:
            ans = (ans * 1) % MOD
    else:
        if vh[j - 1] == 'v':
            ans = (ans * 2) % MOD
        else:
            ans = (ans * 3) % MOD
print(ans)

Measured memory_bytes: 38480
import java.util.Scanner


object Main {


  case class Point(x: Long, y: Long) {
    def +(that: Point) = Point(this.x + that.x, this.y + that.y)

    def -(that: Point) = Point(this.x - that.x, this.y - that.y)
  }

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val posList = IndexedSeq.fill(n)(Point(sc.nextLong(), sc.nextLong()))
    (n, posList)
  }

  def solve(n: Int, posList: IndexedSeq[Point]): Long = {
    if(n == 1) return 1
    def solveSub(diff: Point): Long = {
      var cnt = 0

      for(posSrc <- posList) {
        for(posDst <- posList) {
          if(posDst - posSrc == diff){
            cnt += 1
          }
        }
      }
      n - cnt
    }

    val costList = for (pos1 <- posList; pos2 <- posList if pos1 != pos2) yield {
      val diff = pos2 - pos1
      solveSub(diff)
    }
    costList.min
  }

  def main(args: Array[String]): Unit = {
    val (n, posList) = read()
    println(solve(n, posList))
  }
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll r;
  cin >> r;
  cout << r*r << endl;
}


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

using namespace std;

#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define f(n) for(int i=0;i<n;++i)
#define f2(n) for(int j=0;j<n;++j)
#define f3(n) for(int k=0;k<n;++k)
#define F(i,x,n,y) for(i=x;i<n;i+=1)
#define fi(i) for(i=0;i<n;++i)
#define fa(x,y) for(auto x:y)

//Warsaw debug template
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1,debug&>::type operator<<(c i){
sim > struct rge {c b,e;};
sim > rge<c> range(c i, c j) {return rge<c>{i,j};}
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug{
#ifdef LOCAL
~debug() {cerr<<endl; }
eni(!=) cerr<< boolalpha << i; ris;}
eni(==) ris <<range(begin(i),end(i)); }
sim, class b dor(pair<b,c> d){
ris<<"("<<d.first<<","<<d.second<<")";
}
sim dor(rge<c> d){
    *this << "[";
    for(auto it=d.b;it!=d.e;++it)
        *this <<"," +(it==d.b)<< *it;
    ris<<"]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) "["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"
//End of debug template        
    

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int m=n;
    int s=0;
    while(n>0){
        s+=n%10;
        n/=10;
    }

    if(m%s==0) cout<<"Yes";
    else cout<<"No";
    cout<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A,B) << " " << max((A+B-N), 0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n,m;
    cin >> n >> m;
    vector<int>gate_l(m);
    vector<int>gate_m(m);
    rep(i,m){
        cin >> gate_l[i];
        cin >> gate_m[i];
    }
    sort(gate_l.begin(),gate_l.end());
    reverse(gate_l.begin(),gate_l.end());
    sort(gate_m.begin(),gate_m.end());

    int saitei = gate_l[0];
    int saikou = gate_m[0];
    
    int ans=0;
    for(int i=saitei; i<=saikou; i++) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 1024
// https://atcoder.jp/contests/dp/tasks/dp_l

#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    long long int a[n];
    for(int i = 0;i<n;i++)
        cin >> a[i];
    long long int dp[n][n] = { 0 };
    dp[n-1][n-1] = a[n-1];
    for(int i = n-2;i>=0;i--){
        for(int j =0;j<n;j++) {
            if(j < i){
                dp[i][j] = 0.0;
            }
            if(j == i){
                dp[i][j] = a[i];
            }
            if(j > i){
                dp[i][j] = max(a[j]-dp[i][j-1], a[i]-dp[i+1][j]);
            }
        }
    }
    // for(int i = 0;i<n;i++) {
    //     for(int j = 0;j<n;j++){
    //         cout <<dp[i][j]<< " ";
    //     }
    //     cout << endl;
    // }
    cout << setprecision(10) << dp[0][n-1]  << endl;

}

Measured memory_bytes: 70528
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    string s;
    cin>>s;
    int len = s.length();
    if(s[0] == s[len-1])
        if(len&1)printf("Second\n");
        else printf("First\n");
    else
        if(len&1)printf("First\n");
        else printf("Second\n");
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    int v = max(h,w);
    cout<<((n+v-1)/v)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N, K;
    cin >> N >> K;
    vll h(N), dp(N, INT_MAX); // dp[i] := 足場iに到着するまでに必要なコスト
    rep(i, N)
    {
        cin >> h[i];
    }
    dp[0] = 0;
    rep2(i, 1, K + 1)
    {
        dp[i] = abs(h[0] - h[i]);
    }
    ll cost = INT_MAX;
    rep(i, N - K)
    {
        cost = INT_MAX;
        rep(j, K)
        {
            if (i + j < N)
                chmin(cost, dp[i + j] + abs(h[i + K] - h[i + j])); //足場iから
        }
        dp[i + K] = cost;
    }
    cout << dp.back();
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define googletestcase(x) cout<<"CASE #"<<x<<": ";
using namespace __gnu_pbds;
using namespace std;
template <class T> using Tree = tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define readint(x) scanf("%d", &x)
#define readll(x) scanf("%lld", &x)
#define readstring(x) readint(x)
#define loop(i, a, b) for(int i=a;i<b;i++)
#define loop0(i, a) for(int i=0;i<a;i++)
#define loopi(i, a, b) for(int i=a;i<=b;i++)
#define trav(i, x) for(auto i: x)
#define travedit(i, x) for(auto &i: x)
#define sz(x) (long long)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define debug(a, x) cout<<a<<" IS "<<x<<'\n';
#define all(x) x.begin(), x.end()
#define ins insert
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
const int MOD=1000000007;//1e9+7
const int MX=1000001;
void setio(string s) {
	//ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
struct BIT{
    ll nput;
    int bit[MX];
    void init(){
        for(int i=0;i<=nput+9;i++){
            bit[i]=0;
        }
    }
    void update(ll k, ll x){
        while(k<=nput){
            bit[k]+=x;
            k+=k&-k;
        }
    }
    ll sum(ll k){
        ll sum1=0;
        while(k>=1){
            sum1+=bit[k];
            k-=k&-k;
        }
        return sum1;
    }
    ll query(ll a, ll b){
        return sum(b)-sum(a-1);
    }
};
struct DSU{
	int nput;
	int dsu[MX+1];
	int sizes[MX+1];
	void init() {
		for(int i=0;i<=nput;i++) {
			dsu[i]=i;
			sizes[i]=1;
		}
	}
	int find(int a) {
		if(dsu[a]==a)
			return a;
		return(dsu[a]=find(dsu[a]));
	}
	void join(int a, int b) {
		a=find(a);
		b=find(b);
		if(a!=b){
			if(sizes[a]<sizes[b]){
				dsu[a]=b;
				sizes[b]+=sizes[a];
			}
			else{
				dsu[b]=a;
				sizes[a]+=sizes[b];
			}
		}
	}
	bool sameset(int a, int b){
		return find(a)==find(b);
	}
};
int h[100000];
int dp[100000];
int n, k;
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>h[i];
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++){
        dp[i]=1e9;
    }
    for(int i=3;i<=n;i++){
        for(int j=i-k;j<i;j++){
            if(j<=0)continue;
            dp[i]=min(dp[i], dp[j]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n]<<'\n';
}




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

using namespace std;

int main(void)
{
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    int sum = 0;
    for(int i = 0;i < M;i++){
        cin >> A[i];
        sum += A[i];
    }

    if (sum > N) {
        cout << -1 << endl;
    }
    else{
        cout << N - sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h> 
using namespace std;
int main(int argc, char const *argv[])
{
    for (int i = 0; i < 5; ++i)
    {
        int num;
        cin >> num;
        if (!num)
            return cout << i + 1, 0;
    }
    return 0;
}

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

int main(){
  
    int a, b, t;
    cin >> a >> b >> t;
    int c = t%a;
   
    if(c == 0){
    cout << (t/a*b) <<endl;
    }
  
    else cout << (t-c)/a*b <<endl;

}


Measured memory_bytes: 256
ans = 0


def dfs(n, f1, f2, f3):
    if N < n:
        return

    global ans
    ans += 1 if f1 & f2 & f3 else 0

    dfs(n * 10 + 7, True, f2, f3)
    dfs(n * 10 + 5, f1, True, f3)
    dfs(n * 10 + 3, f1, f2, True)


N = int(input())

dfs(0, False, False, False)

print(ans)


Measured memory_bytes: 3060
s = int(input())
a = [s]
cnt = 1
while True:
    if s % 2 == 0:
        s = int(s / 2)
        cnt += 1
        if a.count(s) == 1:
            print(cnt)
            exit()
        a.append(s)
        
    else:
        s = 3 * s + 1
        cnt +=1
        if a.count(s) == 1:
            print(cnt)
            exit()
    
        a.append(s)

Measured memory_bytes: 3064