akhauriyash/Code-Regression huggingface dataset:
n=int(input())
s=int(input())

b_ans=1



if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break

if b_ans==1:
  for p in range(int(n**0.5),0,-1):
    b=(n-s+p)/p

    if b.is_integer() and 0<=s-p<b and b>n**0.5:
      b_ans=int(b)
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)

Measured memory_bytes: 3188
using System;

namespace abc160_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if(s.Length < 6)
            {
                return;
            }
            string s3 = s.Substring(2,1);
            string s4 = s.Substring(3, 1);
            string s5 = s.Substring(4, 1);
            string s6 = s.Substring(5, 1);
            if(s3.Equals(s4) && s5.Equals(s6))
            {
                Console.WriteLine("Yes");
                return;
            }
            Console.WriteLine("No");
        }
    }
}


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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int N;

    ist >> N;

    /* ------- 計算 ------- */

    long long sum = 0;

    for (int i = 1; i <= N; i++)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            sum += i;
        }
    }

    ost << sum << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int A,B;
  cin >> A >> B;
  cout << max({A+B,A-B,A*B});

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())

void print(int a)
{
    if (a != 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

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

    bool like[31];
    rep(i, 0, m) like[i] = true;

    int a[31][31] = {}, k[31] = {};
    rep(i, 0, n)
    {
        cin >> k[i];
        rep(j, 0, k[i])
        {
            cin >> a[i][j];
        }
    }

    int ans = 0;
    rep(l, 1, m + 1)
    {
        //cout << "l=" << l << endl;
        rep(i, 0, n)
        {
            bool f = true;
            rep(j, 0, k[i])
            {
                //cout << a[i][j] << " ";
                if (a[i][j] == l)
                {
                    if (i == n - 1)
                    {
                        ans++;
                        //f = false;
                    }
                    break;
                }
                if (j == k[i] - 1)
                    f = false;
            }
            //cout << endl;
            if (!f)
                break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    char a;
    cin >> a;
    if(a == 'T'){
        cout << 'A';
    }
    else if(a == 'G'){
        cout << 'C';
    }
    else if(a == 'C'){
        cout << 'G';
    }
    else
    {
        cout << 'T';
    }
    
    cout << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
const unsigned long long INF = 1000000000000000000;

int main()
{
    int N;
    cin >> N;
    vector<unsigned long long> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    unsigned long long sum = 1;
    for (int i = 0; i < N; i++)
    {
        if(A[i] > INF/sum){
            cout << -1 << endl;
            return 0;
        }
        sum *= A[i];
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,K,R;
	cin >> N >> K;
	R = 1;
	
	for (int i=0; i<N; i++){
		if ( R <= K) {
			R += R;
		}
		else {
			R += K;
		}
	}
	
	cout << R << endl;
}


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

#define mem(x, y) memset(x, y, sizeof(x))
#define PI acos(-1.00)
#define ERR 1e-9
#define __                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
#define file                           \
    freopen("input.txt", "rt", stdin); \
    freopen("output.txt", "wt", stdout);
#define MAX 1001010
const int inf = 0x7FFFFFFF;
typedef long long ll;

ll _GCD(ll a, ll b) { return b ? _GCD(b, a % b) : a; } //gcd

ll mark[MAX];
vector<ll> Prime;

void sieve()
{
    mem(mark, 0);
    mark[0] = mark[1] = 1;
    for (int i = 4; i < MAX; i += 2)
        mark[i] = 1;
    Prime.push_back(2);
    for (ll i = 3; i < MAX; i += 2)
    {
        if (!mark[i])
        {
            Prime.push_back(i);
            for (ll j = i * i; j < MAX; j += 2 * i)
            {
                mark[j] = 1;
            }
        }
    }
}
ll N, P;

//prototypes
ll solution();

int main()
{
    //__;
    //file;
    int tc = 1, cas = 0;
    sieve();
    //cin>>tc;
    while (tc--)
    {
        //printf("Case %d: ",++cas);
        solution();
    }
    return 0;
}

ll solution()
{
    cin >> N >> P;
    if (N == 1)
    {
        cout << P;
        return 0;
    }
    ll ans = 1;
    ll lim = sqrt(P);
    for (ll i = 0;i!=Prime.size()&& Prime[i] <= lim; i++)
    {

        if(P%Prime[i]==0){
            ll count = 0;
            while (P % Prime[i] == 0)
            {
                P /= Prime[i];
                count++;
            }
            lim = sqrt(P);
            count /= N;
            if (count)
                ans *=pow(Prime[i], count);
        }
    }
    cout << ans;

    return 0;
}

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

int main(){
    int A[4][3][10];
    int b, f, r, v;
    for(b = 0; b < 4; b++){
        for(f = 0; f < 3; f++){
            for(r = 0; r < 10; r++){
                A[b][f][r] = 0;
            }
        }
    }
    int i, n;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        A[b - 1][f - 1][r - 1] += v;
    }
    for(b = 0; b < 4; b++){
        for(f = 0; f < 3; f++){
            for(r = 0; r < 10; r++){
                cout << " " << A[b][f][r];
            }
            cout << endl;
        }
        if(b == 3) break;
        for(i = 0; i < 20; i++) cout << "#";
        cout << endl;
    }
    return 0;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int c1 = 0; // 2の倍数でも4の倍数でもない
  int c2 = 0; // 2の倍数の数
  int c4 = 0; // 4の倍数の数
  rep(i, n) {
    if (a.at(i) % 4 == 0) {
      c4++;
    } else if (a.at(i) % 2 == 0) {
      c2++;
    } else {
      c1++;
    }
  }
  bool ok;
  if (c2 > 0) {
    ok = c1 <= c4;
  } else {
    ok = c1 <= (c4 + 1);
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 640
void main() {
  problem();
}

void problem() {
  auto N = scan!int;
  auto A = scan!long(N);

  long solve() {
    ulong ans;
    long sumA;
    foreach(a; A) sumA = (sumA + a) % MOD;

    foreach(i; 0..N-1) {
      sumA -= A[i];
      if (sumA < 0) sumA += MOD;

      auto add = (A[i] * sumA) % MOD;
      ans = (ans + add) % MOD;
    }
    
    return ans;
  }

  solve().writeln;
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
const MOD = 7 + 10^^9;

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


Measured memory_bytes: 10132
k,a,b = map(int,input().split())
if b-a <= 2:
  print(k+1)
elif  a >= b:
  print(k+1)
else:
  ans = a+int((k+1-a)/2)*(b-a)
  if (k+1-a)%2 == 1:
    ans+=1
  print(ans)

Measured memory_bytes: 3060
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let (a, b): (u32, u32) = stdin.lock().gets().split(' ').values();
    if a + b == 15 {
        println!("+");
    } else if a * b == 15 {
        println!("*");
    } else {
        println!("x");
    }
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }

trait Values<T> { fn values(&mut self) -> T; }
impl<'a, I, T1, T2> Values<(T1, T2)> for I
    where I: Iterator<Item=&'a str>,
          T1: std::str::FromStr, T1::Err: std::fmt::Debug,
          T2: std::str::FromStr, T2::Err: std::fmt::Debug {
    fn values(&mut self) -> (T1, T2) {
        (self.next().unwrap().parse().unwrap(),
         self.next().unwrap().parse().unwrap())
    }
}


Measured memory_bytes: 4352
A,B,K = map(int,input().split())


if B-A+1 <= 2*K:

    for i in range(B-A+1):
        print (A+i)

else:

    for i in range(K):
        print (A+i)

    for i in range(K):
        print (B-K+1+i)

        


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

int min(int a, int b){
    return a<b?a:b;
}

void solve(){
    int a, b, c, k;
    cin>>a>>b>>c>>k;
    int res = 0;
    res += min(a, k);
    k -= min(a, k);
    k -= min(k, b);
    res -= min(k, c);
    cout<<res<<endl;
}


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

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n; cin >> n;
  set<int> cnt;
  for(int i = 0; i < n; i++) {
    int a; cin >> a;
    cnt.insert(a);
  }

  if(n == cnt.size()) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 9600
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((a * b) % 2 == 0)
            System.out.println("Even");
        else
            System.out.println("Odd");
    }
}

Measured memory_bytes: 22868
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { //Partition babyyyyyyyyy
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		ArrayList<Long> can = new ArrayList<Long>();
		ArrayList<Long> must = new ArrayList<Long>();
		for (int i = 0; i < N; i++) can.add(I.nextLong());
		int M = I.nextInt();
		for (int i = 0; i < M; i++) must.add(I.nextLong());
		Collections.sort(can);
		Collections.sort(must);
		int req = 0; //Pointer of requirement array-list
		for (int i = 0; i < N; i++) {
			//O.pln(can.get(i)+" "+must.get(req));
			long x = can.get(i);
			long y = must.get(req);
			if (x==y) req++;
			if (req==M) break;
		}
		O.pln(req==M?"YES":"NO");
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 77400
#include <string>
#include <vector>
#include <map>
#include <iostream>
#define ll long long
using namespace std;

ll A[222222];
ll evens[222222];
ll opt_fwd[222222];
ll opt_bck[222222];


int main() {
    int L;
    cin>>L;
    for(int i=1;i<=L;i++) {
       cin>>A[i];
       // A[i]=rand()%100000000;
    }
    A[L+1]=0;
    
    // i to j (number of evens from i to j-1)
    // evens[j-1]-evens[i-1]+bck[i-1]+fwd[j+1]
    
    // evens[j-1]+fwd[j+1]-max(evens[i-1]-bck[i-1])
    
    
    evens[0]=0;
    for(int i=1;i<=L+1;i++) {
        evens[i]=evens[i-1]+(A[i]%2==0);
    }

    
    
    
    opt_bck[0]=0;
    ll cumul = 0;
    for(int i=1;i<=L+1;i++) {
        cumul += A[i];
        opt_bck[i]=min(opt_bck[i-1]+(A[i]>=2 ? A[i]%2==1 : 2-A[i]), cumul);
    }
    
    cumul = 0;
    opt_fwd[L+1]=0;
    for(int j=L;j>=0;j--) {
        cumul += A[j+1];
        opt_fwd[j]=min(opt_fwd[j+1]+(A[j+1]>=2 ? A[j+1]%2==1 : 2-A[j+1]),cumul);
        
       // printf("at %d :: fwd=%lld\n",j,opt_fwd[j]);
        
    }
    
    
    ll ans = (1ll<<61);


    ll minval = opt_bck[0]-evens[0];
    for(int j=1;j<=L+1;j++) {
        minval = min(minval, opt_bck[j]-evens[j]);
        ans = min(ans, opt_fwd[j]+evens[j]+minval);
    }
    
    

    cout << ans << endl;
    

}

Measured memory_bytes: 6784
#include <iostream>
#include <complex>
#include <cstdio>

using namespace std;
typedef complex<double> Vector;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N;
        cin >> N;
        if(N == -1) break;

        Vector pos(1, 0);
        N--;
        while(N--) {
            Vector v(-pos);
            v *= Vector(0, -1);
            const double len = abs(v);
            pos += v / len;
        }
        printf("%f\n%f\n", pos.real(), pos.imag());
    }
    return 0;
}

Measured memory_bytes: 1256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
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(){
    string S, T;
    cin >> S >> T;

    if (S.size() + 1 == T.size()){
        T.pop_back();
        if (S == T){
            cout << "Yes" << endl;
            return 0;
        }

    }
    cout << "No" << endl;

    return 0;
}


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

main :: IO ()
main = do
  n <- readLn :: IO Int
  xys <- replicateM n $ (\(a:b:_) -> (a,b)) . map read . words <$> getLine :: IO [(Int, Int)]
  print $ solve n xys

solve n xys 
  | n == 1 = 1
  | otherwise = n - (maximum . Map.elems . toCountMap $ distances xys)

distances xys = nEq ++ eq
  where
    nEq = do
      (ax, ay) <- xys
      (bx, by) <- xys
      guard $ ax < bx
      return (ax - bx, ay - by)
    eq = do
      (ax, ay) <- xys
      (bx, by) <- xys
      guard $ ax == bx
      guard $ ay < by
      return (ax - bx, ay - by)

toCountMap :: (Ord k) => [k] -> Map.Map k Int
toCountMap xs = Map.fromListWith (+) $ zip xs (repeat 1)


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#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]) << " ";} cout<<endl;
inline bool isPrime(ll x){ //素数かどうか判定
    if(x<2) return false;
    if(x==2) return true;
    if(x%2==0) return false;
    for(ll i=3;i<=sqrt(x)+1;i+=2) if(x%i==0) return false;
    return true;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    map<ll,ll> mp;
    rep(i,1,N+1){
        if(isPrime(i)){
            ll t = i;
            while(t <= N){
                mp[i] += N / t;
                t *= i;
            }
        }
    }
    ll ans = 1;
    for(auto &e: mp) (ans *= e.second + 1) %= MOD;
    print(ans);
    
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 1000005

int ans[505][505] ;
char s[505][505] ;

int main()
{
    int n , m  , k ;

    scanf("%d %d %d",&n,&m,&k) ;

    for(int i=0 ; i<n ; i++)
    {
        scanf("%s",s[i]) ;
    }

    memset(ans,-1,sizeof(ans)) ;

    int cur = 0 ;

    for(int i=0 ; i<n ; i++)
    {
        int tot = 0 ;
        for(int j=0 ; j<m ; j++)
        {
            if( s[i][j] == '#' ) tot++ ;
        }

        if(tot==0)
        {
            if( i==0 || ans[i-1][0] == -1 ) continue ;
            for(int j=0 ; j<m ; j++) ans[i][j] = ans[i-1][j] ;
            continue ;
        }

        int fl = 0 ;
        for(int j=0 ; j<m ; j++)
        {
            if( s[i][j]=='#' )
            {
                fl = 1 ;
                cur++ ;
                ans[i][j] = cur ;
            }
            else
            {
                if( fl ) ans[i][j] = cur ;
            }
        }
        for(int j=m-2 ; j>=0 ; j--)
        {
            if( ans[i][j]==-1 ) ans[i][j] = ans[i][j+1] ;
        }
    }

    for(int i=n-1 ; i>=0 ; i--)
    {
        for(int j=0 ; j<m ; j++)
        {
            if( ans[i][j] == -1 ) ans[i][j] = ans[i+1][j] ;
        }
    }

    for(int i=0 ; i<n ; i++)
    {
        for(int j=0 ; j<m ; j++) printf("%d ",ans[i][j]) ;
        printf("\n") ;
    }

    return 0 ;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

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

	LL N, A;
	cin >> N;
	cin >> A;

	LL r = N % 500;
	if(r <= A){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	int max = 0;
	int sum = 0;
	int i;
	for(i = 0;i<N;i++){
		int L;
		scanf("%d",&L);
		if(L > max)max = L;
		sum += L;
	}
	if(max < sum - max)
		printf("Yes\n");
	else
		printf("No\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int h,w; cin >> h >> w;
	vector<string> v(h);
	rep(i,h) cin >> v[i];
	vector<vector<int> > vv(h, vector<int>(w,0));
	rep(i,h)rep(j,w){
		if (v[i][j] == '#'){
			vv[i][j] = -1;
			int x[3] = {-1,0,1};
			int y[3] = {-1,0,1};
			rep(k,3)rep(l,3){
				if (k == 1 && l == 1) continue;
				if (0 <= i+y[k] && i+y[k] < h && 0 <= j+x[l] && j+x[l] < w){
					if (vv[i+y[k]][j+x[l]] == -1) continue;
					vv[i+y[k]][j+x[l]]++;
				}
			}
		}
	}
	rep(i,h){
		rep(j,w){
			if (vv[i][j]>-1){
				cout << vv[i][j];
			}else {
				cout << '#';
			}
		}
		cout << endl;
	}
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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


vint inv(vint P){
	vint Q(P.size());
	rep(i,P.size())Q[P[i]]=i;
	return Q;
}

vint mul(vint P,vint Q){
	vint R(P.size());
	rep(i,P.size())R[i]=Q[P[i]];
	return R;
}

vint po(vint X,int K){
	vint ret(X.size());rep(i,X.size())ret[i]=i;
	while(K){
		if(K&1)ret=mul(ret,X);
		X=mul(X,X);
		K>>=1;
	}
	return ret;
}

void test(vint P,vint Q,int K){
	while(K){
		K--;
		vint R=mul(inv(P),Q);
		P=Q;Q=R;
	}
	rep(i,P.size())cout<<P[i]+1<<" ";cout<<endl;

}

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

	vector<int>P(N),Q(N);


	rep(i,N)cin>>P[i],P[i]--;
	rep(i,N)cin>>Q[i],Q[i]--;
	while(K%6){
		K--;
		vint R=mul(inv(P),Q);
		P=Q;Q=R;
	}

	vint X=P;
	X=mul(X,inv(Q));
	X=mul(X,inv(P));
	X=mul(X,Q);

	vint Z=po(X,K/6);
	vint ans=mul(inv(Z),P);
	ans=mul(ans,Z);
	rep(i,N){
		if(i)cout<<" ";
		cout<<ans[i]+1;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 7052
from collections import defaultdict

BIG = 10000

h, w = map(int,input().split())

s = ['']*h
for i in range(h):
    s[i] = input()

cost = [[0]*w]*h

if s[0][0] == '#':
    cost[0][0] = 1

for r in range(h):
    for c in range(w):
        if (r, c) == (0, 0): continue
        x = BIG
        if s[r][c] == '.':
            if r > 0:
                x = min(x, cost[r-1][c])
            if c > 0:
                x = min(x, cost[r][c-1])
        else:  # black
            if r > 0:
                if s[r-1][c] == '#':
                    x = min(x, cost[r-1][c])
                else:
                    x = min(x, cost[r-1][c]+1)
            if c > 0:
                if s[r][c-1] == '#':
                    x = min(x, cost[r][c-1])
                else:
                    x = min(x, cost[r][c-1]+1)
        cost[r][c] = x

print(cost[h-1][w-1])

Measured memory_bytes: 42096
#include <iostream>
#include <cstdlib>
#include <string>

int calc(std::string s); 

int main(void) {
    std::string input;
    int answer;
    std::cin >> input;
    while (input != "0") {
        answer = calc(input);
        std::cout << answer << std::endl;
        std::cin >> input;
    }
    return EXIT_SUCCESS;
}

int calc(std::string s) {
    int ans = 0;
    int digit = int(s.std::string::size());
    for (int i = 0; i < digit; i++) {
        ans += int(s[i] - '0');        
    }
    return ans;
}

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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    cout << vec.at(i);
    if (i < vec.size() - 1)
    {
      cout << ", ";
    }
  }
  cout << "]...size: " << vec.size() << endl;
}

int main()
{
  int w, h;
  char c;
  cin >> w >> h >> c;

  rep(i, h)
  {
    rep(j, w)
    {
      if (i == 0 || i == h - 1)
      {
        if (j == 0 || j == w - 1)
        {
          printf("+");
        }
        else
        {
          printf("-");
        }
      }
      else
      {
        if (j == 0 || j == w - 1)
        {
          printf("|");
        }
        else if (i == h / 2 && j == w / 2)
        {
          printf("%c", c);
        }
        else
        {
          printf(".");
        }
      }
    }
    printf("\n");
  }
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b;
cin>>a>>b;
cout<<max(a+b,max(a-b,a*b))<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
  return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
  template <class C>
  static char test(typename C::const_iterator*);
  template <class C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o, const C& c) {
  o << '[';
  for (auto it = c.begin(); it != c.end();)
      o << *it << (++it != c.end() ? ", " : "");
  return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
  return o << '(' << p.fi << ", " << p.se << ')';
}

void solve() {
  int x, n;
  cin >> x >> n;
  bitset<102> found;
  F0R (_, n) {
    int a;
    cin >> a;
    found[a] = 1;
  }
  ii best{200, -1};

  F0R (i, 102) {
    if (!found[i])
      ckmin(best, mp(abs(x - i), i));
  }

  cout << best.se << endl;
}

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

  int tt = 1;
  FOR (t, 1, tt + 1) {
      // cout << "Case #" << t << ": ";
      solve();
  }

  return 0;
}


Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include <vector>
using namespace std;
const int N=4e5+20;
typedef long long ll; 
typedef pair<ll,ll> ii;

int n,q,vis[N],num;
ll dis[N];//¸ùµ½½áµãµÄ¾àÀë 
ll dep[N];//µÚi´Î·ÃÎÊµÄ½áµãÉî¶È
ll vs[N];//vs[i] dfsµÚi´Î·ÃÎÊµ½µÄ½áµã
ll pos[N];//pos[v] ½áµãvµÚÒ»´Î±»·ÃÎÊµ½µÄÎ»ÖÃ 
vector<ii> e[N];
ll d[N][30];//d[i][j] ÐòºÅi~2^jµÄ×îÐ¡depÐòºÅ 
void init()
{
	for(int i=0;i<=n;i++)
	e[i].clear();
	
	num=0;
	memset(dis,0,sizeof(dis));
	memset(vis,0,sizeof(vis));
	memset(pos,-1,sizeof(pos));
}
void dfs(int u,int depth)
{
	vs[++num]=u;
	dep[num]=depth;
	if(pos[u]==-1)
	pos[u]=num;
	
	vis[u]=1;
	for(int i=0;i<e[u].size();i++)
	{
		int v=e[u][i].first;
		int w=e[u][i].second;
		if(vis[v])
		continue;
		
		dis[v]=dis[u]+w;
		dfs(v,depth+1);
		
		//¼ÇÂ¼Â·¾¶
		vs[++num]=u;
		dep[num]=depth;
		 
	}
}
void RMQ(ll len)//Çó(u,v)Â·¾¶ÖÐÉî¶È×îÐ¡µÄ½áµãµÄ·ÃÎÊÐòºÅ¼´LCA(u,v) 
{
	for(int i=0;i<=len;i++)
	d[i][0]=i;
	
	for(int j=1;(1<<j)<=len;j++)
	{
		for(int i=1;i+(1<<j)<=len;i++)
		{
			int x=d[i][j-1],y=d[i+(1<<(j-1))][j-1];
			if(dep[x]<=dep[y])
			d[i][j]=x;
			else
			d[i][j]=y;	
		} 
	}
}
ll LCA(ll x,ll y)
{
	int a=pos[x],b=pos[y];
	if(a>b)
	swap(a,b);
	
	//·ÃÎÊÐòºÅ(a,b)ÖÐÉî¶È×îÐ¡µÄµã¼´ÎªLCA(x,y)
	int k=0;
	while((1<<k+1)<=b-a+1) k++;
	
	int l=d[a][k],r=d[b-(1<<k)+1][k];
	if(dep[l]<dep[r])
	return vs[l];
	else
	return vs[r]; 
}
ll query(int u,int v)
{
	return dis[u]+dis[v]-2*dis[LCA(u,v)];
}
int main()
{

		cin>>n;
		init();
		for(int i=1;i<=n-1;i++)
		{
			int u,v;
			ll w;
			scanf("%d%d%lld",&u,&v,&w);
			e[u].push_back(ii(v,w));
			e[v].push_back(ii(u,w));
		}
		//Çódist(u,v) ÓÃ×î¶ÌÂ·floldÏÔÈ»³¬Ê± ÓÉÓÚÊÇÊ÷,Ôò¿ÉÒÔO(n)Çó³öw=LCA(u,v)
		//dist(u,v)=d(u)+d(v)-2*d(w); d(i)Îª¸ùµ½½áµãiµÄ¾àÀë 
		dfs(1,1);
		int k;
		cin>>q>>k; 
		RMQ(num);
		while(q--)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			ll ans=query(u,k)+query(k,v);
			cout<<ans<<endl;
		}
	
	return 0;
}


Measured memory_bytes: 84864
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int j,i,k,s[6];
    bool ans=false;
    for(i=0;i<5;i++)
        cin>>s[i];
    cin>>k;
    for(i=0;i<4;i++)
    {
        for(j=i+1;j<5;j++)
        {
            if(abs(s[i]-s[j])>k)
            {
                ans=true;
                break;
            }
        }
        if(ans)
            break;
    }
    cout<<(ans?":(":"Yay!")<<endl;
}


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

#define int       long long
#define nn        101
#define kn        100005
#define FAST      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

string solve(vector<int> &v,int k){
    bool dp[k+1];
    memset(dp, 0, sizeof(dp));

    for(int i=1;i<=k;i++){
        for(int move : v){
            if(move > i)
                continue;
            if(dp[i-move] == 0)
                dp[i] = 1;
        }
    }

    return dp[k] ? "First" : "Second";
}

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

    cout<<solve(a, k);
}

Measured memory_bytes: 384
dict = {}
for i in range(int(input())):
    a = input()
    if dict.get(a):
        dict[a] += 1
    else:
        dict[a] = 1

max_v = max(dict.values())


ans = [key for key, value in dict.items() if value == max_v]
ans.sort()
for i in ans:
    print(i)


Measured memory_bytes: 32096
fun main(args: Array<String>) {
    var n = readLong()
    var ans = ""
    while (true) {
        n--
        ans += ('a' + (n % 26).toInt())
        n /= 26
        if (n == 0L) break
    }
    println(ans.reversed())

}


private fun read() = readLine()!!

private fun readInt() = read().toInt()

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readListString() = read().split(" ")

private fun readListInt() = readListString().map { it.toInt() }

private fun readListLong() = readListString().map { it.toLong() }

private fun readListDouble() = readListString().map { it.toDouble() }

private fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



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

using namespace std;



int main(){


	int ans = 1;

	int N,K;
	cin >> N >> K;

	for(int i = 0;i < N;i++){
		ans = min(ans*2,ans + K);
	}

	cout << ans << endl;

	return 0;


}


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

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

    int tmp = 1;
    for(int i = 0; i < d; i++){
        tmp *= 100;
    }


    int ans = n * tmp;
    if(n == 100){
        if(d == 0) ans += 1;
        else if(d == 1) ans += 100;
        else ans += 10000;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('a1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main_0():
    H, A = read_int_list()
    res = 0
    for i in range(10001):
      H = H - A
      res += 1
      if H <= 0:
        break
    print(res)


def main():
    C = read_str()
    res = chr(ord(C) + 1)
    print(res)

main()


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

ll now=100,x;

int main()
{
    scanf("%lld",&x);
    int cnt=0;
    while(now<x)
    {
        cnt++;
        now=now+now/100;
    }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 3828
def main():
    n, k = list(map(int, input().split()))
    a_list = list(map(int, input().split()))
    
    roop_count = []
    for i in range(n):
        roop_count.append(0)
    
    town = 1
    town_candidate = []
    roop_count[0] = 1
    roop_1 = 0
    roop_2 = 0
    count = 0
    for i in range(k):
        town = a_list[town-1]
        roop_count[town-1] += 1
        if roop_count[town-1] == 1:
            roop_1 += 1
        elif roop_count[town-1] == 2:
            roop_2 += 1
            town_candidate.append(town)
        elif roop_count[town-1] == 3:
            break
        count = i
    #print(roop_count)
    
    if count == k-1:
        print(town)
    else:
        town = (k-roop_1) % roop_2 -1
        print(town_candidate[town])

if __name__ == '__main__':
    main()

Measured memory_bytes: 33320
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>

using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a<=5){
    b = 0;
  }else if(a>=6 && a<=12){
    b /= 2;
  }
  cout << b << endl;
}


Measured memory_bytes: 256
A = input()
a, b, c, d = A[0], A[1], A[2], A[3]
op = '+-'
for i in op:
    for j in op:
        for k in op:
            s = a + i + b + j + c + k + d
            if eval(s) == 7:
                print(s+'=7')
                exit()

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

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;
int arr[N];
int n;

ll calc(int b)
{
  ll ans = 0;
  for(int i = 1; i <= n; i++)
    ans += abs(arr[i] - (b + i));
  return ans;
}
int main()
{
 ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
 cin >> n;
 for(int i = 1; i <= n; i++)
  cin >> arr[i];
 int st = -2e9, en = 2e9;
 ll ans;
 while (st <= en)
 {
   int mid = (st + en) / 2;
   ll sol1 = calc(mid), sol2 = calc(mid - 1);
   if(sol1 < sol2)
    ans = sol1, st = mid + 1;
   else
    ans = sol2, en = mid - 1;
 }
 cout << ans;
 return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<31;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

const int mod = 1e9+7;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

mint dp[700][2005];

int main() {
    int s; cin >> s;
    for (int j = 3; j <= s; j++) {
        dp[1][j] = 1;
    }
    for (int i = 2; i <= s/3; i++) {
        for (int j = 3*i; j <= s; j++) {
            dp[i][j] = dp[i][j-1] + dp[i-1][j-3];
        }
    }
    mint ans = 0;
    REP(i,s/3+1) ans += dp[i][s];
    cout << ans << endl;
}

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

typedef long long ll;

const int MAXN = 2e5 + 5;

struct edge {
	int a, b, c;
	void input() {
		scanf("%d%d%d", &a, &b, &c);
		b += MAXN / 2;
	}
	bool operator <(const edge &rhs) const {
		return c > rhs.c;
	}
};

int N, H, W;
int dad[MAXN], rnk[MAXN];
bool full[MAXN];
edge e[MAXN];

void load() {
	scanf("%d%d%d", &N, &H, &W);
	for (int i = 0; i < N; i++)
		e[i].input();
}

int find(int x) {
	return dad[x] == x ? x : dad[x] = find(dad[x]);
}

bool join(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) {
		if (full[x])
			return false;
		full[x] = true;
		return true;
	}
	if (full[x] && full[y])
		return false;
	if (rnk[x] > rnk[y])
		swap(x, y);
	dad[x] = y;
	rnk[y] += rnk[x] == rnk[y];
	full[y] |= full[x];
	return true;
}

ll solve() {
	sort(e, e + N);
	
	for (int i = 0; i < MAXN; i++)
		dad[i] = i;
	
	ll sol = 0;
	for (int i = 0; i < N; i++)
		if (join(e[i].a, e[i].b))
			sol += e[i].c;
	
	return sol;
}

int main() {
	load();
	printf("%lld\n", solve());	
	return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int N, M, C;
  int tmp = 0;
  int count = 0;
  cin >> N >> M >> C;
  vector<int> B(M);
  vector<vector<int> > A(N, vector<int>(M));
  for(int i = 0; i<M; i++){
    cin >> B[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      tmp += A[i][j] * B[j];
    }
    tmp += C;
    if(tmp > 0){
      count++;
    }
    tmp = 0;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
MAX_INT = int(10e9)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def judge(a,b,i,left,right):
  if (a+b)%2 == 0:
    ans[left] = (a+b)//2
    ans[right] = (a+b)//2
  else:
    num = (a+b)//2
    num2 = (a+b)-(a+b)//2
    if a >= b:
      if (a-1)%2 == 0:
        ans[left] = num2
        ans[right] = num
      else:
        ans[left] = num
        ans[right] = num2
    else:
      if (b-1)%2 == 0:
        ans[left] = num
        ans[right] = num2
      else:
        ans[left] = num2
        ans[right] = num

s = S()
N = len(s)
ans = [0]*N

r = 0
l = 0
f = 0

ll = 0
rr = 0
for i in range(N):
  if f == 0:
    if s[i] == "R":
      r += 1
    else:
      l += 1
      f = 1
      if s[i-1] == "R":
        rr = i-1
        ll = i
  else:
    if s[i] == "R":
      judge(r,l,i,rr,ll)
      r = 0
      l = 0
      r += 1
      f = 0
      indef = 0
    else:
      l += 1
      f = 1
else:
  judge(r,l,i,rr,ll)

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

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

int main() {
    string S;
    int K;
    cin >> S >> K;
    int N = S.size();

    vector<pair<char, int>> s;
    for (int i = 0, j; i < N; i = j) {
        for (j = i + 1; j < N; ++j) {
            if (S[j] != S[i]) break;
        }

        s.emplace_back(S[i], j - i);
    }

    if (s.size() == 1) {
        ll ans = (ll)K * N / 2;
        write(ans);
        return 0;
    }

    ll inS = 0;
    for (int i = 1; i < s.size() - 1; ++i) {
        inS += s[i].second / 2;
    }

    if (s.front().first == s.back().first) {
        ll ans = inS * K;
        ans += s.front().second / 2 + s.back().second / 2;
        ans += (ll)(K - 1) * ((s.front().second + s.back().second) / 2);
        write(ans);
    }
    else {
        inS += s.front().second / 2 + s.back().second / 2;
        ll ans = inS * K;
        write(ans);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;


int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n+2); // 0 v[1] v[2] ... v[n] 0
    vector<int> d(n+1); // v[i] - v[i-1]
    int dsum = 0;
    REP(i,n) {
        cin >> v[i+1];
        d[i] += abs(v[i+1] - v[i]); 
        dsum += d[i];
    }
    d[n] = abs(v[n+1] - v[n]);
    dsum += d[n];

    REP(i,n) {
        int ans = dsum - (d[i] + d[i+1]) + abs(v[i+2] - v[i]);
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
bool S, E, N, W;
string s;
int main ()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> s;
	for (register int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'S') S = 1;
		if (s[i] == 'E') E = 1;
		if (s[i] == 'N') N = 1;
		if (s[i] == 'W') W = 1;
	}
	if ((S ^ N) || (E ^ W)) puts ("No");
	else puts ("Yes");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<unordered_set>
using namespace std;
const int N=1e5+2;
const int inf=1e9+1;
vector<int> adj[N],topoo;
unordered_set<int> back[N];
bool used[N];
int head[N],pos[N];
void build_topo(int x){
	for(int i=0;i<adj[x].size();i++){
		if(!used[adj[x][i]]){
			used[adj[x][i]]=true;
			build_topo(adj[x][i]);
		}
	}
	pos[x]=topoo.size();
	topoo.push_back(x);
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	unordered_set<int>::iterator ite;
	int i,j,k,n,m,root;
	cin>>n>>m;
	for(i=1;i<=n-1+m;i++){
		cin>>j>>k;
		adj[j].push_back(k);
		back[k].insert(j);
	}
	for(i=1;i<=n;i++){
		if(back[i].size()==0){
			root=i;
			break;
		}
	}
	used[root]=true;;
	build_topo(root);
	for(i=0;i<topoo.size()-1;i++){
		if(back[topoo[i]].find(topoo[i+1])!=back[topoo[i]].end()){
			head[topoo[i]]=topoo[i+1];
		}
		else{
			root=inf;
			for(ite=back[topoo[i]].begin();ite!=back[topoo[i]].end();ite++){
				if(pos[*ite]<root){
					root=pos[*ite];
					head[topoo[i]]=*ite;
				}
			}
		}
	}
	for(i=1;i<=n;i++){
		cout<<head[i]<<endl;
	}
}

Measured memory_bytes: 22520
#include <bits/stdc++.h>
// #define vec(v) vector<int>(v)
// #define be(v) (v).begin(), (v).end()
// #define pb(q) push_back(q)
// #define mapci(mp) map<char*,int>(mp)
// #define mapcc(mp) map<char*,char*>(mp)
// typedef long long ll;
using namespace std;

int main(){

    int n,x;
    cin>>n>>x;
    int l[n];
    for(int i=0; i<n; i++) cin>>l[i];
    int ans=0,num=0;
    while(num<=x){
        num+=l[ans];
        ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256