akhauriyash/Code-Regression huggingface dataset:
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

template <typename T>
std::vector<T> make_v(usize a) { return std::vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(usize a, Ts... ts) {
  return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t) fill_v(e, v);
}

template <typename T, typename V>
inline void chmin(T &a, V b) {
  if (a > b) a = b;
}
template <typename T, typename V>
inline void chmax(T &a, V b) {
  if (a < b) a = b;
}

} // namespace null_null

#include <algorithm>
#include <iostream>
#include <utility>

namespace null_null {

void main_() {
  int K, X;
  std::cin >> K >> X;
  for (i32 i = X - K + 1; i <= X + K - 1; i++) {
    if (i != X - K + 1) std::cout << " ";
    std::cout << i;
  }
  std::cout << std::endl;
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long long
using namespace std;

signed main() {
 	int N;
 	cin >> N;
 	int answer = 100;
 	for(int i = 1;i * i <= N;i++) {
 		if(N % i == 0) {
 			int A = N / i;
 			int count = 0;
 			while(A != 0) {
 				count++;
 				A = A / 10;
 			}
 			answer = min(answer,count);
 		}
 	}
 	cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main() {
    int n,m;
    cin>>n>>m;
    int c[m];
    rep(i,m) cin>>c[i];

    int dp[50001]={0};
    for(int i=1;i<=50000;i++) dp[i]=INF;
    
    for(int i=0;i<=50000;i++){
        rep(j,m){
            if(i+c[j]<=n){
                dp[i+c[j]]=min(dp[i+c[j]],dp[i]+1);
            }
        }
    }

    cout<<dp[n]<<endl;
}




Measured memory_bytes: 3292
#include<stdio.h>

int main()
{
	int n, count = 0, i;
	scanf("%d", &n);
	int arr[n];

	for(i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
		if(arr[i] != i + 1)
		{
			count++;
		}
	}

	if(count <= 2) printf("YES\n");
	else printf("NO\n");
}


Measured memory_bytes: 128
if __name__ == '__main__':
    N = int(input())
    S = [input() for _ in range(3)]

    ans = 0
    for n in range(N):
        chars = [0 for _ in range(ord('z') - ord('a') + 1)]
        for s in S:
            chars[ord(s[n]) - ord('a')] += 1
        ans += sum(sorted(chars, reverse=True)[1:])
    print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int h,n; cin>>h>>n;
    vector<ll> a(n),b(n);

    rep(i,n) cin>>a[i]>>b[i];

    vector<ll> dp(h+1,LINF);
    dp[0] = 0;

    for (int j = 0; j <= h; ++j) {
        rep(i,n) {
            chmin(dp[min(j+a[i],(ll)h)], dp[j]+b[i]);
        }
    }

    cout << dp[h] << '\n';

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int,int> > v;
char ch[1001][1001];
bool vis1[1001][1001];
void dfs(int c1,int c2,int n,int m)
{
  if(vis1[c1][c2]==1) return ;
  vis1[c1][c2]=1;
  v.push_back({c1,c2});
  if((c1+1)<=n&&ch[c1+1][c2]=='.')
   dfs(c1+1,c2,n,m);
  if((c1-1)>0&&ch[c1-1][c2]=='.')
   dfs(c1-1,c2,n,m);
  if(c2+1<=m&&ch[c1][c2+1]=='.')
    dfs(c1,c2+1,n,m);
  if(c2-1>0&&ch[c1][c2-1]=='.')
   dfs(c1,c2-1,n,m);
}
int32_t main()
{
  int t,n,m,i,j,k=1e9+7,l=0,x=-1,l1,l2,c1,c2,d1,d2;
  cin>>n>>m;
   cin>>c1>>c2;
   cin>>d1>>d2;
  for(i=1;i<=n;i++)
   for(j=1;j<=m;j++) cin>>ch[i][j];
  queue<pair<int,pair<int,int> > >q;
  q.push({c1,{c2,0}});
  bool vis[n+1][m+1];
  for(i=1;i<=n;i++)
   for(j=1;j<=m;j++) vis[i][j]=0;
   memset(vis1,0,sizeof(vis1));
  while(!q.empty())
  {
    auto it=q.front();
    j=it.first;k=it.second.first;l=it.second.second;
    q.pop();
    if(vis[j][k]==1)
     continue;
    vis[j][k]=1;
    dfs(j,k,n,m);
    for(i=0;i<v.size();i++)
    {
      l1=v[i].first,l2=v[i].second;
      vis[l1][l2]=1;
      if(l1==d1&&l2==d2)
      {
        x=l;
        break;
      }
    }
    if(x!=-1) break;
    for(i=0;i<v.size();i++)
    {
      l1=v[i].first,l2=v[i].second;
      for(j=l1-2;j<=l1+2;j++)
      {
        for(k=l2-2;k<=l2+2;k++)
        {
          if(j>=1&&j<=n&&k>=1&&k<=m)
          {
            if(ch[j][k]=='.'&&vis[j][k]==0)
            { 
              if(j==d1&&k==d2)
              {
                x=l+1;
                break;
              }
              q.push({j,{k,l+1}});
            }
          }
          if(x!=-1) break;
        }
        if(x!=-1) break;
      }
      if(x!=-1) break;
    }
    if(x!=-1) break;
    v.clear();
  }
  cout<<x;
}

Measured memory_bytes: 6924
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll X[100010];
    rep(i,0,M) cin >> X[i];
    if(N >= M){
        print(0);
        return 0;
    }
    sort(X, X+M);
    vector<ll> diff;
    rep(i,0,M-1){
        diff.push_back(X[i+1] - X[i]);
    }
    sort(diff.begin(), diff.end());
    ll ans = 0;
    rep(i,0,M-N){
        ans += diff[i];
    }
    print(ans);



}


Measured memory_bytes: 2168
{-# LANGUAGE BangPatterns, MultiWayIf #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> VU.Vector Int -> Int
solve !n !an = dp V.! (n - 1) VU.! (n - 1)
 where
  dp :: V.Vector (VU.Vector Int)
  dp = V.postscanl'
    (\(!dpi) (!i) -> VU.postscanl'
      (\(!dpij) (!j) -> if
        | i > j -> 0
        | even (n - 1 - j + i) -> max (dpi VU.! j + an VU.! i)
                                      (dpij + an VU.! j)
        | otherwise -> min (dpi VU.! j - an VU.! i) (dpij - an VU.! j)
      )
      0
      (VU.fromList [0 .. n - 1])
    )
    (VU.replicate n 0)
    (V.convert $ VU.reverse $ VU.fromList [0 .. n - 1])

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\(!vec) -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  an <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n an


Measured memory_bytes: 1788
h,w,d = map(int, input().split())


tab = [ [0,0] ]*(w*h)

for hi in range(h):

    t = list(map(int,input().split()))

    for wi in range(w):
        tab[ t[wi]-1 ] = [hi, wi]

#print(tab)


cost = [0]*(w*h)
for i in range(d, w*h):
    a = tab[i-d]
    b = tab[i]

    cost[i] = abs( a[0]-b[0] ) + abs( a[1]-b[1] ) + cost[i-d]

#print(cost)

q = int(input())

for i in range(q):
    l, r = map(int, input().split())

    print(cost[r-1] - cost[l-1])


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

int main() {
  int N;
  string X,Y;
  cin>>N>>X>>Y;
  vector<string> ans(2*N,"o");
  for(int i=0; i<2*N; i++){
    if(i%2 == 0){
      ans.at(i) = X.at(i/2);
    }
    else{
      ans.at(i) = Y.at(i/2);
    }
  }
  for(int i=0; i<2*N; i++){
    if(i<2*N){
      cout<<ans.at(i);
    }
    else{
      cout<<endl;
    }
  }
}

Measured memory_bytes: 256
def main(x1,y1,x2,y2):
    x,y = [x2-x1, y2-y1]
    p3 = [x2-y, y2+x]
    p4 = [x1-y, y1+x]
    print(p3[0],p3[1],p4[0],p4[1]) 

x1,y1,x2,y2 = map(int,input().split())
main(x1,y1,x2,y2)

Measured memory_bytes: 3060
fun main() {
//    a()
//    b()
    c()
}

fun c() {
    val k = readLine()!!.toInt()
    val l = if (k.rem(7) == 0) 9 * k / 7 else 9 * k
    var tenPowerMod = 1
    for (i in 1..9000000) {
        tenPowerMod = (tenPowerMod * 10) % l
        if (tenPowerMod == 1) {
            println(i)
            return
        }
    }
    println(-1)
}

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

using namespace std;

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

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



signed main() {

	int M, K;
	cin >> M >> K;

	int t = 0;
	for (int i = 0; i < (1 << M); i++)
		t ^= i;

	if (K == 0) {
		rep(i, (1 << M)) {
			cout << i << endl;
		}
		for (int i = (1 << M) - 1; i >= 0; i--) {
			cout << i << endl;
		}
		return 0;
	}

	if (t != 0) {
		cout << -1 << endl;
		return 0;
	}
	if(K>=(1<<M)) {
		cout << -1 << endl;
		return 0;
	}

	cout << K << endl;
	rep(i, (1 << M)) {
		if(i!=K)
			cout << i << endl;
	}
	cout << K << endl;
	for(int i=(1<<M)-1; i>=0; i--){
		if (i != K)
			cout << i << endl;
	}

	return 0;
}


Measured memory_bytes: 1792
N = int(input())
S = (list(input() for i in range(N)))
cot = 0
cot_a = 0
cot_b = 0
cot_ab = 0

for s in S:
    for j in range(len(s)-1):
        if s[j] == "A" and s[j+1] == "B":
            cot += 1

for s in S:
    if s[-1] == 'A' and s[0] == 'B':
        cot_ab += 1
    elif s[-1] == 'A':
        cot_a += 1
    elif s[0] == 'B':
        cot_b += 1

if cot_ab == 0:
    cot += min(cot_a, cot_b)
elif cot_a + cot_b >0:
    cot += cot_ab + min(cot_a, cot_b)
else:
    cot += cot_ab - 1
print(cot)

Measured memory_bytes: 3828
H, W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
c = [[None]*W for _ in range(H)]
dirs = [(0,1),(1,0),(0,-1),(-1,0)]
i,j = 0,0
d = 0
color = 0
for _ in range(H*W):
    c[i][j] = color+1
    a[color] -= 1
    if a[color] == 0:
        color += 1
    di,dj = dirs[d]
    ni,nj = i+di,j+dj
    if 0 <= ni < H and 0 <= nj < W and c[ni][nj] == None:
        i,j = ni,nj
        continue
    d = (d+1) % 4
    di,dj = dirs[d]
    i,j = i+di,j+dj
for l in c:
    print(*l)

Measured memory_bytes: 9504
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] arr = new Integer[N];
        for(int i = 0; i < N; i++) arr[i] = sc.nextInt();
        Arrays.sort(arr, Comparator.reverseOrder());
        long res = 0;
        res = arr[0];
        for(int i = 1; i < Math.floor(N/2); i++) {
            if(N%2==0) {
                res+=arr[i]*2;
            } else {
                if(i == 1) {
                    res += arr[i]*2;
                    res += arr[(int)Math.ceil(N/2)];
                } else {
                    res += arr[i] *2;
                }
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 63496
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define MOD 1000000007

#define fast ios_base::sync_with_stdio(false)
#define itt cin.tie(0)
#define now cout.tie(0)

using namespace std;

int s,w;

int main()
{
	cin>>s>>w;
	if(w>=s)
		cout<<"unsafe"<<endl;
	else
		cout<<"safe"<<endl;
	return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a, b, c;
    cin >> a >> b >> c;

    cout << a*b/2 << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  vll a(3);
  rep(i, 3) {
    cin >> a[i];
  }

  sort(all(a));
  reverse(all(a));
  cout << (a[0] * 10 + a[1] + a[2]) << endl;

  return 0;
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H=I()
    W=I()
    N=I()
    print(ceil(N/max(H,W)))
if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    n = read()
    d = ['..', '.#', '#.', '##']
    s1 = s2 = ''
    flag = True
    i = 0
    while True:
        if flag:
            print(s1 + d[i%4][0], flush=True)
            print(s2 + d[i%4][1], flush=True)
        else:
            print(d[i%4][0] + s1, flush=True)
            print(d[i%4][1] + s2, flush=True)
        r = input()
        if r == 'T':
            if flag:
                s1 = s1 + d[i%4][0]
                s2 = s2 + d[i%4][1]
            else:
                s1 = d[i%4][0] + s1
                s2 = d[i%4][1] + s2
            i = -1
        elif r == 'F':
            if i == 3:
                i = -1
                flag = False
        else:
            return
        i += 1

main()

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

int N, M;
vector<vector<int>> G;
vector<int> res;

void bfs() {
    res[0] = 0;
    queue<int> que;
    que.push(0);
    while(!que.empty()) {
        int v = que.front();
        que.pop();
        for(int to : G[v]) {
            if(res[to] != -1) continue;
            res[to] = v;
            que.push(to);
        }
    }
}

int main() {
    int N, M; cin >> N >> M;
    G.resize(N); res.resize(N, -1);
    for(int i=0; i<M; ++i) {
        int a, b; cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }

    bfs();

    if(count(begin(res), end(res), -1)) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        for(int i=1; i<N; ++i) {
            cout << res[i] + 1 << '\n';
        }
    }
}

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

char s[100];
bool bit[20];
int n;

long dfs(int i){
	if(i == n - 1) {
		long ret = 0;
		long a = s[0];
		for(int j = 0;j < n - 1;j++) {
			if(bit[j]) {
				ret += a;
				a = s[j + 1];
			}else {
				a *= 10;
				a += s[j + 1];
			}
		}
		return ret + a;
	}

	bit[i] = 1;
	long ret = dfs(i + 1);
	bit[i] = 0;
	ret += dfs(i + 1);
	return ret;
}
int main(){
	cin >> s;
	for(int i = 0;s[i] != '\0';i++)n++;

	for(int i = 0;i < n;i++)
		s[i] -= '0';

	cout << dfs(0) << endl;
	return 0;
}



Measured memory_bytes: 256
n,y = map(int, input().split())
a = []
for i in range(0,n+1,1):
  for j in range(0,n+1,1):
    if 9000*i+4000*j == y-1000*n and n-i-j >= 0:
      a = [i,j,n-i-j]
if a == []:
  print(-1,-1,-1)
else:
  print(a[0],a[1],a[2])
      

Measured memory_bytes: 9064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <algorithm>

using namespace std;
using LL = long long;
const int N = 200005;
const int inf = 1e9;
int a[N], b[N];
LL suma[N], sumb[N];
int main()
{
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);

	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), suma[i] = suma[i - 1] + a[i];
	for (int j = 1; j <= m; ++j) scanf("%d", &b[j]), sumb[j] = sumb[j - 1] + b[j];

	int res = 0;

	for (int i = 0; i <= n; ++i)
	{
		LL t = k - suma[i];
		if (t < 0) break;
		int u = upper_bound(sumb + 1, sumb + m + 1, t) - sumb;
		--u;
		res = max(res, i + u);
	}

	printf("%d\n", res);

	return 0;
}


Measured memory_bytes: 8440
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
typedef pair<int, pi> node;
#define oset tree<pi, null_type,greater<pi>, rb_tree_tag,tree_order_statistics_node_update>


int main()
{
    lli n;
    cin >> n;
    lli a[n+1], b[n];
    for(auto &x: a)cin >> x;
    for(auto &x: b) cin >> x;
    lli ans = 0;
    for(int i=0; i<n; i++){
        if(a[i] > b[i]){
            ans += b[i];
        }
        else{
            ans += a[i];
            b[i] -= a[i];
            if(a[i+1]>b[i]){
                ans += b[i];
                a[i+1] -= b[i];
            }
            else{
                ans += a[i+1];
                a[i+1] = 0;
            }
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 5084
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int n;
    cin >> n;
    int m = n;
    double ans = 0;
    while(n > 0){
        if(n%2==1)ans++;
        n -= 1;
    }
    printf("%.10f\n",ans/m);
}

Measured memory_bytes: 3744
#include <iostream>
int main(){int N,A[60000],i=0,j=1,x=1,c=101;std::cin>>N;for(;i<N;i++)A[i]=0;for(;x<c;x++)for(int y=1;y<c;y++)for(int z=1;z<c;z++)A[x*x+y*y+z*z+x*y+y*z+z*x]++;for(;j<=N;j++)std::cout<<A[j]<<std::endl;}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  vector<int> in(n, 0);
  rep(i,m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].emplace_back(y);
    in[y] = 1;
  }
  vector<int> s;
  for (int i = 0; i < n; i++) if (!in[i]) s.emplace_back(i);
  vector<int> dp(n,-1);
  auto dfs = [&](auto& f, int p, int u) -> int {
    if (dp[u] != -1) return dp[u];
    dp[u] = 0;
    for (auto v : g[u]) {
      if (v == p) continue;
      dp[u] = max(dp[u], f(f, u, v) + 1);
    }
    return dp[u];
  };
  int res = 0;
  for (auto e : s) {
    res = max(res, dfs(dfs, -1, e));
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 10496
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
ans = [''] * M
num = [1] * N

for i, v in sorted(enumerate(X), key=lambda x: (x[1][0], x[1][1])):
    ans[i] = '{:06}{:06}'.format(v[0], num[v[0] - 1])
    num[v[0] - 1] += 1
    
print('\n'.join(ans))

Measured memory_bytes: 47328
a,b,c,d=0,0,0,0
for i in range(int(input())):
  s=input()
  if s=="AC":
    a+=1
  elif s=="WA":
    b+=1
  elif s=="TLE":
    c+=1
  else:
    d+=1
print("AC x",a,"\nWA x",b,"\nTLE x",c,"\nRE x",d)

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

long long dp[3010][3010];

int main() {
    int n; cin >> n;
    vector<long long> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int k = 1; k <= n; k++) {
        for (int i = 0; i < n; i++) {
            if (i+k > n) continue;
            if ((n-k)%2 == 0) {
                dp[i][i+k] = max(dp[i][i+k-1]+v[i+k-1], dp[i+1][i+k]+v[i]);
            } else {
                dp[i][i+k] = min(dp[i][i+k-1]-v[i+k-1], dp[i+1][i+k]-v[i]);
            }
        }
    }
    cout << dp[0][n] << endl;
    return 0;
}

Measured memory_bytes: 70016
def main(argv)
  n = gets.chomp.to_i
  w = gets.chomp.split(' ').map(&:to_i)
  
  total = w.reduce(:+)
  
  min_diff = 1e+9
  sum = 0
  n.times do |t|
    sum += w[t]
    
    min_diff = [min_diff, (total - 2 * sum).abs].min
  end
  
  puts min_diff.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

 #include<bits/stdc++.h>

#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;
int main() {

	int d,n;
	cin >> d >>n;


	int hund = 1;
	REP(i, d) {
		hund *= 100;
	}

	if (n == 100) n++;

	cout << n * hund << endl;
	return 0;


}

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

int main()
{
    int N,K;
    cin >> N >> K;

    vector<bool> SNUKE(N,false);

    for(int i=0;i<K;i++)
    {
        int d;
        cin >> d;
        for(int j=0;j<d;j++)
        {
            int Ai;
            cin >> Ai;
            SNUKE[Ai-1] = true;
        }
    }

    int total = 0;
    for(int i=0;i<N;i++)
    {
        if(!SNUKE[i]) total++;
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 3628
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		ArrayList<ArrayList<Info>> list = new ArrayList<ArrayList<Info>>();
		for(int i = 0; i < N; i++) list.add(new ArrayList<Info>());
		
		for(int i = 0; i < M; i++){
			int index = i;
			int P = sc.nextInt();
			int Y = sc.nextInt();
			Info f = new Info();
			f.index = i;
			f.year = Y;
			list.get(P-1).add(f);
		}
		
		for(int i = 0; i < N; i++) Collections.sort(list.get(i), new yearComparator());
		
		ArrayList<Info> ansList = new ArrayList<Info>();
		for(int i = 0; i < N; i++){
			ArrayList<Info> pList = list.get(i);
			for(int j = 0; j < pList.size(); j++){
				Info f = pList.get(j);
				String number = String.format("%06d%06d", (i + 1), (j + 1));
				f.number = number;
				ansList.add(f);
			}
		}
		
		Collections.sort(ansList, new indexComparator());
		
		for(Info f : ansList){
			System.out.println(f.number);
		}
		
		/*
		for(int i = 0; i < N; i++){
			for(Info f : list.get(i)){
				System.out.println(f.index + " " + f.year + " " + f.number);
			}
		}
		*/
	}
	
	public static class yearComparator implements Comparator<Info> {
		@Override
		public int compare(Info info1, Info info2) {
			return info1.year < info2.year ? -1 : 1;
		}
	}
	
	public static class indexComparator implements Comparator<Info> {
		@Override
		public int compare(Info info1, Info info2) {
			return info1.index < info2.index ? -1 : 1;
		}
	}
	
	public static class Info{
		int index = 0;
		int year = 0;
		String number = "";
	}
}

Measured memory_bytes: 165012
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from sys import maxsize


def irange(start, stop=None):
    if stop:
        return range(start, stop + 1)
    else:
        return range(start + 1)


def count(ms):
    n = len(ms)

    p = [0] * (n + 1)
    for i in range(n):
        p[i] = ms[i][0]
        p[i + 1] = ms[i][1]

    m = [[None] * (n + 1) for _ in irange(n)]
    for i in irange(1, n):
        m[i][i] = 0
    for l in irange(2, n):
        for i in irange(1, n - l + 1):
            j = i + l - 1
            m[i][j] = maxsize
            for k in irange(i, j - 1):
                m[i][j] = min(
                    m[i][j],
                    m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]
                )

    return m[1][n]


def main():
    n = int(input())

    m = []
    for _ in range(n):
        m.append(tuple(int(x) for x in input().split()))
    c = count(m)
    print(c)


if __name__ == '__main__':
    main()



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


char F(char c){
	if(c=='A')return 'z';
	if(c=='a')return 'Z';
	return c-1;
}

char G(char c,int num){
	for(;num;num--){
		c=F(c);
	}
	return c;
}


int main(){
	int n;
	while(cin>>n,n){
		string s;
		vector<int>V;
		for(int i=0;i<n;i++){
			int tmp;
			cin>>tmp;
			V.push_back(tmp);
		}
		cin>>s;
		
		
		for(int i=0;i<s.size();i++){
			s[i]=G(s[i],V[i%n]);
			
		}
		cout<<s<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<ll,P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000
//union_find木テンプレ
//問いに応じて最大の頂点数を定めること
#define MAXN 100100
long int par[MAXN];//親番号
long int rank[MAXN];//木の深さ
long int siz[MAXN];//属する集団のサイズ
//初期化関数
void init(int n) {
    rep(i, n) { par[i] = i; ::rank[i] = 0; siz[i] = 1; }
}
//木の根を求める関数
int find(int x) {
    if (par[x] == x) { return x; }
    else { return par[x] = find(par[x]); }
}
//xとｙの集合を併合する関数
void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y)return;
    if (::rank[x] < ::rank[y]) {
        par[x] = y;
        siz[y] += siz[x];
    }
    else {
        par[y] = x;
        siz[x] += siz[y];
        if (::rank[x] == ::rank[y])::rank[x]++;
    }
}
//同じかどうかとサイズがいくらか。
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) { return siz[find(x)]; }

int main() {
  int N,M;
  cin>>N>>M;
  init(N);
  rep(i,M){
    int x,y,z;
    cin>>x>>y>>z;
    x--;y--;
    unite(x,y);
  }
  set<int>st;
  int cnt=0;
  rep(i,N){
    int p=find(i);
    if(!st.count(p)){
      cnt++;
      st.insert(p);
    }
  }
  cout<<cnt;
}




Measured memory_bytes: 10544
#include <stdio.h>
#include <math.h>
int main(){
    double r,a,c;
    double PI = 3.141592653589;
    scanf("%lf", &r);
    a = r * r * PI;
    c = r * 2 * PI;
    printf("%lf %lf\n",a,c);
    return 0;
}


Measured memory_bytes: 2100
import sys
from collections import deque
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    n, k = LI()
    g = [[] for i in range(n+1)]
    for i in range(n-1):
        a, b = LI()
        g[a].append(b)
        g[b].append(a)

    s = 1
    Q = deque([s])
    ans = k
    Qappend = Q.append
    searched = [0] * (n+1)
    searched[s] = 1
    while len(Q) != 0:
        v = Q.popleft()
        if v == s:
            cand = k - 1
        else:
            cand = k - 2
        for i in g[v]:
            if searched[i] == 1:
                continue
            searched[i] = 1
            ans = ans * cand % MOD
            cand -= 1
            Qappend(i)
    print(ans % MOD)


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    double t, x;
    cin>>t>>x;

    cout<<fixed<<setprecision(10)<<t/x<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  string T = S;
  rep(i, N) {
    rep(j, max(T.size(), (size_t)1) - 1) {
      if (T[j] == '(' && T[j + 1] == ')') {
        T.erase(T.begin() + j, T.begin() + j + 2);
        continue;
      }
    }
  }

  int cnt_l = 0, cnt_r = 0;
  rep(i, T.size()) {
    if (T[i] == ')')
      cnt_r++;
    else
      cnt_l++;
  }

  reverse(all(S));
  rep(i, cnt_r) {
    S.pb('(');
  }

  reverse(all(S));
  rep(i, cnt_l) {
    S.pb(')');
  }

  cout << S << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner;

    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        String a = scanner.next();
        if (a.equals(a.toLowerCase())) {
            System.out.println("a");
        } else {
            System.out.println("A");
        }
    }

    public static void println(Object o) {
        System.out.println(o);
    }

    public static void print(Object o) {
        System.out.print(o);
    }

    public static void printf(String format, Object... o) {
        System.out.printf(format, o);
    }

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

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

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

    public static short nextShort() {
        return Short.parseShort(scanner.next());
    }

    public static float nextFloat() {
        return Float.parseFloat(scanner.next());
    }

    public static void printYes() {
        System.out.println("Yes");
    }

    public static void printYES() {
        System.out.println("YES");
    }

    public static void printNo() {
        System.out.println("No");
    }

    public static void printNO() {
        System.out.println("NO");
    }

    public static void nextLine() {
        scanner.nextLine();
    }

    public static double distance(double x, double y, double x2, double y2) {
        return Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
    }

    public static int MOD = 1_000_000_007;
    public static int MAX = 100000;
    public static long[] fac = new long[MAX];
    public static long[] finv = new long[MAX];
    public static long[] inv = new long[MAX];

    public static void combinit() {
        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;
        }
    }

    public static long combination(int n, int k) {
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    public static long factorial(long n) {
        return n <= 0 ? 1 : n * factorial(n - 1);
    }
}


Measured memory_bytes: 29372
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 1000000000000000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<vector<int>,vector<char> > P;

string str;
map<char,int> num;

long long calc(long long a, long long b, char z){
	if(z == '+') return a+b;
	if(z == '-') return a-b;
	return a*b;
}

long long func(string str){
	vector<long long> nu, tmpnu;
	vector<char> ch, tmpch;
	rep(i,str.size()){
		if(str[i] == '('){
			int cn = 0, st = i;
			while(true){
				i++;
				if(str[i] == '(') cn++;
				if(str[i] == ')' && cn == 0){
					nu.push_back(func(str.substr(st+1,i-st-1)));
					break;
				}
				if(str[i] == ')') cn--;
			}
		} else if('0' <= str[i] && str[i] <= '9'){
			long long x = str[i]-'0';
			while(i != str.size()-1 && '0' <= str[i+1] && str[i+1] <= '9'){
				i++;
				x *= 10;
				x += str[i]-'0';
			}
			nu.push_back(x);
		} else{
			ch.push_back(str[i]);
		}
	}
	for(int i = 0; i < 4; i++){
		while(true){
			bool end = true;
			long long tmp;
			int pos;
			tmpnu.clear(); tmpch.clear();
			rep(j,ch.size()){
				if(num[ch[j]] != i) continue;
				tmp = calc(nu[j],nu[j+1],ch[j]);
				pos = j;
				end = false;
				break;
			}
			if(end) break;
			tmpnu.push_back(nu[0]);
			rep(j,ch.size()){
				if(j != pos){
					tmpnu.push_back(nu[j+1]);
					tmpch.push_back(ch[j]);
				} else{
					tmpnu.pop_back();
					tmpnu.push_back(tmp);
				}
			}
			nu = tmpnu;
			ch = tmpch;
		}
	}
	return nu[0];
}

int main(){
	cin >> str;
	long long ans;
	for(int i = 0; i <= (1<<6); i++){
		num.clear();
		int I = i;
		num['+'] = I%4; I /= 4;
		num['-'] = I%4; I /= 4;
		num['*'] = I%4; I /= 4;
		if(i == 0) ans = func(str);
		else ans = max(ans,func(str));
	}
	cout << ans << endl;
}

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

int main(){
  int max,min,n,a;
  long sum;
  max = INT_MIN;
  min = INT_MAX;
  sum = 0;

  cin>>n;
  for(int i = 0;i<n;i++){
    cin>>a;
    sum+=a;
    if(a > max){
      max = a;
    }
    if(a < min){
      min = a;
    }
  }

  cout<<min<<" "<<max<<" "<<sum<<endl;

  return 0;
}

Measured memory_bytes: 3080
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	string s;
	string front = "";

	cin >> s;
	int q;
	cin >> q;
	int re = 0;

	for (int i = 0;i < q;i++) {
		int t;
		cin >> t;
		if (t == 1) {
			re++;
		}
		else {
			int f;
			string c;
			cin >> f >> c;
			if (re % 2 == 0) {
				if (f == 1) {
					front += c;
				}
				else {
					s.append(c);
				}
			}
			else
			{
				if (f == 1) {
					s.append(c);
				}
				else {
					front += c;
				}
			}
		}
	}
	reverse(front.begin(), front.end());
	s = front + s;

	if (re % 2 == 1) {
		reverse(s.begin(), s.end());
	}

	cout << s << endl;
	return 0;
}

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

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long // −9·10^18 to 9·10^18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

typedef __int128_t intl; //−10^38 to 10^38
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef map<int,int> mi;

#define EPS 1e-9
#define INF LLONG_MAX
const int mod = 1000 * 1000 * 1000 + 7; //1e9+7

#define w(t) int t; cin>> t; while(t--)
#define isPowOfTwo(x) return (x && (!(x&(x-1))));
#define gcd(x,y) return __gcd(x,y);
#define cin2(x,y) int x,y; cin>>x>>y;


vi v[100005];
vi dist(100005,-1);
int ans =INF;


void bfs(int s)
{
    queue<int> q; 
    q.push(s); 
    dist[s]=0;
    while(!q.empty())
    {
        int par=q.front();
        q.pop();
        for(int i:v[par])
        {
            if(dist[i]==-1)//not visited
            {
                dist[i]=par;
                q.push(i);
            }
        }
    }
}
void solve()
{
    cin2(n,m); 
    unordered_set<int> node;
    while(m--)
    {
        cin2(s,d);
        v[s].pb(d);
        v[d].pb(s);
        node.insert({s,d});
    }
    if(node.size()!=n) { cout<<"No"<<endl; return; }
    cout<<"Yes"<<endl;
    bfs(1);
    for(int i=2;i<=n;i++)
        cout<<dist[i]<<endl;
}

int32_t main()
{
	fio;

	solve();

	return 0;
}

Measured memory_bytes: 17552
#include <stdio.h>
#include <string.h>
 
#define Num 1001
 
void print (char* str,int a,int b);
void reverse (char* str,int a,int b);
void replace (char* str,int a,int b,char* rep);
 
int main () {
    char str[Num],func[Num],rep[Num];
    int a,b;
    int command;
     
    scanf ("%s",&str); //操作する文字列
    scanf ("%d",&command); //命令の数
     
    while (command != 0) {
        scanf ("%s",&func);
        if ( strcmp (func,"print") == 0) {
            scanf ("%d %d",&a,&b);
            print (str,a,b);
        } else if ( strcmp (func,"reverse") == 0) {
            scanf ("%d %d",&a,&b);
            reverse (str,a,b);
        } else if ( strcmp (func,"replace") == 0) {
            scanf ("%d %d %s",&a,&b,&rep);
            replace (str,a,b,rep);
        }
        command --;
    }
    return 0;
}
 
void print (char* str,int a,int b) {
    int i;
    for (i = a;i <= b;i ++) {
        printf ("%c",str[i]);
    }
    putchar ('\n');
}
 
void reverse (char* str,int a,int b) {
    int i;
    char rev[Num];
    for (i = 0;i < b - a + 1;i ++) { //b-a+1 個
        rev[i] = str[b -i];
    }
    for (i = 0;i < b - a + 1;i ++) {
        str[a + i] = rev[i];
    }
}
 
void replace (char* str,int a,int b,char* rep) {
    int i;
    for (i = 0;i < b - a + 1;i ++) {
        str[a + i] = rep[i];
    }
}


Measured memory_bytes: 2112
P = 10**9 + 7

class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
            else:
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def samegrp(self, x, y):
        return self.root(x) == self.root(y)

N, M = [int(x) for x in input().split()]
X = UnionFind(N + 1)
for i in range(M):
    X.union(0, int(input()))

dp = [0]*(N + 1)
dp[0] = 1
if X.samegrp(0, 1):
    dp[1] = 0
else:
    dp[1] = 1
for i in range(2, N + 1):
    if X.samegrp(0, i):
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % P

ans = dp[N]
print(ans)

Measured memory_bytes: 80260
#include <stdio.h>
#define swap(x,y) ((x!=y)&&(x^=y,y^=x,x^=y))

int main() {
  int rank[3] = {0};
  int r, i, j;
  for (i = 0; i < 10; i++) {
    scanf("%d", &r);
    for (j = 0; j < 3; j++)
      if (r > rank[j]) swap(rank[j], r);
  }
  for(i = 0; i < 3; i++)
    printf("%d\n", rank[i]);
  return 0;
}

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

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

	string taro, hanako;
	int taro_point = 0;
	int hanako_point = 0;
	for (int i = 0; i < n; i++) {
		cin >> taro >> hanako;
		int flag, len;
		if (taro.length() == hanako.length()) {
			flag = 0;
			len = hanako.length();
		} else if (taro.length() > hanako.length()) {
			flag = 1;
			len = hanako.length();
		} else {
			flag = -1;
			len = taro.length();
		}

		int winner = 0;
		for (int j = 0; j < len; j++) {
			if (taro[j] - 'a' > hanako[j] - 'a') {
				winner = 1;
				break;
			} else if (taro[j] - 'a' < hanako[j] - 'a') {
				winner = -1;
				break;
			}
		}
		if (winner == 0)
			winner = flag;

		if (winner == 1) {
			taro_point += 3;
		} else if (winner == -1) {
			hanako_point += 3;
		} else {
			taro_point += 1;
			hanako_point += 1;
		}
	}
	cout << taro_point << " " << hanako_point << endl;

	return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
#define N 100000
#define Q 50000

int S[N],a;
int binarySearch( int );


int binarySearch( int key ){
  
  int left = 0,right,mid;
  
  right = a ;

  while( left < right ){
    mid = ( left + right )/2;
    if( S[mid] == key )
      return 1;
    else if( S[mid] < key )
      left = mid + 1;
    else if( S[mid] > key )
      right = mid;
	}
  return 0;
}

main(){
  int T[Q],b,count=0,i;
  
  scanf("%d",&a);
  for( i =0 ; i < a ; i++ )
    scanf("%d",&S[i]);
  scanf("%d",&b);
  for( i = 0 ; i < b ; i++ ){
    scanf("%d",&T[i]);
    count += binarySearch(T[i]);
      }

  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

int main(){
  ll n;
  cin>>n;
  vector<ll> v(n);
  ll c=0;
  vector<ll> ans(n);
  for(ll i=0;i<n;i++)
    cin>>v[i];
  for(ll i=0;i<n-1;i+=2)
  {
      c+=v[i];
      c-=v[i+1];
  }
  c+=v[n-1];
  ans[0]=c;
  for(ll i=1;i<n;i++)
  {
      ans[i]=2*v[i-1]-ans[i-1];
  }
  for(ll i=0;i<n;i++)
    cout<<ans[i]<<" ";


   return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int r; cin >> r;
    cout << r*r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define fast_in ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp  make_pair
#define pb  push_back
#define  sz(x)   (int)x.size()
#define  all(x)  x.begin(), x.end()
#define	 allr(x)  x.rbegin(), x.rend()
#define  bit(x)  __builtin_popcountll(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
const int inf = (int) 1e9+99999, mod = (int)1e9+7;
const ll linf = (ll) 2e18+99999;
int mul (int x, int y) { return ((ll)x * y) % mod; } 
int sub (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int add (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }
 
const int maxn = (int) 3e5;
 
void solve () {
	ll res = 0;
	ll n; cin >> n;
	for (int i = 1; i <= n; i ++) {
		ll x; cin >> x;
		res += x;
	}
	res -= n;
	cout << res;
}

main () { fast_in;
    int t = 1; //cin >> t;
    while (t --) {
    	solve ();    
    }
	return 0;
}

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

using namespace std;


int main(){

string a;
cin>>a;
int k=a.length();
string s="";
for(int i=0;i<k;i++)
{
    if(a[i]>='a' && a[i]<='z')
    {
        s=s+'x';
    }
}
cout<<s;
    
}


Measured memory_bytes: 256
"use strict";
function main(input) {
  const kari = input[0].trim().split(" ").map(i => parseInt(i));
  let p = input[1].trim().split(" ").map(i => parseInt(i));
  let q = input[2].trim().split(" ").map(i => parseInt(i));
  let r = input[3].trim().split(" ").map(i => parseInt(i));

  const x = kari[0];
  const y = kari[1];
  const a = kari[2];
  const b = kari[3];
  const c = kari[4];

  p.sort(function(a, b) {
    return b - a;
  });
  p=p.slice(0,x);
  q.sort(function(a, b) {
    return b - a;
  });
  q=q.slice(0,y);
  r.sort(function(a, b) {
    return b - a;
  });
  r=r.slice(0,x+y);

  let preresult = p.concat(q).concat(r);
  preresult.sort(function(a, b) {
    return b - a;
  });

  let sum = 0;
  for(let i=0;i<x+y;i++){
    sum += preresult[i];
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 61152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		String s = kb.next();
		if (s.length() % 2 == 0) {
			System.out.println("No");
		} else {
			String p = "";
			String q = "";
			for (int i = 0; i < s.length() / 2; i++) {
				p += s.charAt(i);
				q += s.charAt(s.length() - i - 1);
			}
			String r = "";
			for (int i = 0; i < q.length(); i++) {
				r += q.charAt(q.length() - i -1);
			}
			if (p.equals(r)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
		kb.close();
	}

}


Measured memory_bytes: 22612