akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	int n,m;
	cin >> n >> m;
	
	int matrix[n][m], vector[m];
	
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cin >> matrix[i][j];
		}
	}
	
	for(int i=0; i<m; i++){
		cin >> vector[i];
	}
	
	for(int i=0; i<n; i++){
		int s=0;
		
		for(int j=0; j<m; j++){
			s += matrix[i][j]*vector[j];
		}
		cout << s << endl;
		
	}
	return 0;
}

Measured memory_bytes: 1196
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let  s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

type Wall = Vec<Vec<bool>>;
type Stack = Vec<(usize, usize)>;

fn main() {
    input! {
        h: usize, w: usize,
        a: [chars; h]
    }
    let mut wall: Wall = a
        .iter()
        .map(|v| v.iter().map(|c| *c == '#').collect())
        .collect();
    let mut stack: Stack = find_wall(&wall);

    let mut count = 0;

    while !all_wall(&wall) {
        count += 1;
        let mut temp: Stack = Vec::new();
        for &(px, py) in stack.iter() {
            for (dx, dy) in vec![(1, 0), (0, 1), (-1, 0), (0, -1)] {
                let nx = px as i32 + dx;
                let ny = py as i32 + dy;
                if nx < 0 || ny < 0 || nx >= w as i32 || ny >= h as i32 {
                    continue;
                }
                let nx = nx as usize;
                let ny = ny as usize;
                if wall[ny][nx] {
                    continue;
                }
                wall[ny][nx] = true;
                temp.push((nx, ny));
            }
        }
        stack = temp;
    }

    println!("{}", count);

    fn find_wall(m: &Wall) -> Stack {
        let mut vec = Vec::new();
        for (j, v) in m.iter().enumerate() {
            for (i, c) in v.iter().enumerate() {
                if *c {
                    vec.push((i, j));
                }
            }
        }
        vec
    }

    fn all_wall(w: &Wall) -> bool {
        for v in w.iter() {
            for c in v.iter() {
                if !*c {
                    return false;
                }
            }
        }
        true
    }
}


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

int main()
{
    long long n, a, b;
    cin >> n >> a >> b;
    if(a > b)
    {
        cout << 0 << endl;
        return 0;
    }
    if(n == 1)
    {
        if(a != b)
            cout << 0 << endl;
        else cout << 1 << endl;
        return 0;
    }
    long long maxsum = (n-1) * b + a;
    long long minsum = (n-1) * a + b;
    cout << maxsum - minsum + 1 << endl;
    return 0;
}


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

using namespace std;

int main(void)
{
 int N, M;
 cin >> N >> M;
 vector<int> x(M);
 for(int i = 0; i < M; i++){
  cin >> x[i];
 }
 if(M <= N){
	 cout << 0 << endl;
	 return 0;
 }
 sort(x.begin(), x.end());
 vector<int> xsub(M-1);
 for(int i = 0; i < M-1; i++){
  xsub[i] = x[i+1] - x[i];
 }
 
 sort(xsub.begin(), xsub.end(), greater<int>());
 int length = x[M-1] - x[0];
 for(int i =0; i < N-1; i++){
  length -= xsub[i];
 }
 cout << length << endl;
 return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define ll long long 

ll int GCD(ll int x,ll int y){return y==0? x:GCD(y,x%y);}

int main(void){
	int n,i;
	scanf("%d",&n);
	ll int t,ans,t1;
	scanf("%lld",&t);
	ans = t;
	for(i=1;i<n;i++){
		scanf("%lld",&t1);
		ans = t/GCD(t,t1)*t1;
		t = ans;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
using AtCoderBeginnerContest154.Questions;
using AtCoderBeginnerContest154.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest154.Questions
{
    public class QuestionC : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var a = inputStream.ReadIntArray();
            Array.Sort(a);

            for (int i = 0; i < n - 1; i++)
            {
                if (a[i] == a[i + 1])
                {
                    yield return "NO";
                    yield break;
                }
            }
            yield return "YES";
        }
    }
}


namespace AtCoderBeginnerContest154
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionC();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest154.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest154.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 36316
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

class UnionFind{
public:
  vector<int> par;
  vector<int> rank;
  vector<int> sz;
  int N;

  UnionFind(int n){N=n;}

  //初期化
  void init(){
    for(int i=0;i<N;i++){
      par.push_back(i);
      rank.push_back(0);
      sz.push_back(1);
    }
  }

  //木の根を求める
  int find(int x){
    if(par[x]==x) return x;
    else{
      par[x]=find(par[x]);
      return par[x];
    }
  }

  //xとyの集合の併合
  void unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じ集合にあるか
  bool same(int x, int y){
    return find(x) == find(y);
  }

  //xの木のサイズ
  int size(int x){
    return sz[find(x)];
  }
};

//-------------------------------------------------
int main(){
  int N,M;
  cin >> N >> M;
  int p[N];
  int ind[N];//引数ノード
  for(int i=0;i<N;i++){
    cin >> p[i];
    p[i]--;
    ind[p[i]]=i;
  }
  int x[M],y[M];
  for(int i=0;i<M;i++){
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }

  UnionFind uf = UnionFind(N);
  uf.init();
  for(int i=0;i<M;i++){
    uf.unite(p[x[i]],p[y[i]]);
  }

  int ans = 0;
  for(int i=0;i<N;i++){
    if(uf.same(p[i],i)){
      ans++;
      int j = ind[i];
      p[i] = i;
      p[j] = p[i];
    }
  }

  cout << ans << endl;
  return 0;

}


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

int main() {
  int N,X,Y;
  cin>>N>>X>>Y;
  vector<int>kai(N);
  vector<vector<int>>G(N+2);
  for(int i=1;i<N;i++){
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);
  for(int aho=1;aho<=N;aho++){
 vector<int>dist(N+1,-1);
  queue<int>que;
  dist[aho]=0;
  que.push(aho);
  while(!que.empty()){
    int v=que.front();
    que.pop();
    for(int nv :G[v]){
      if(dist[nv] != -1) continue;
      dist[nv]=dist[v]+1;
      que.push(nv);
    }
  }
  for(int v=1;v<=N;v++){
    kai[dist[v]]++;
  }
  }
  for(int v=1;v<N;v++){
    cout<<kai[v]/2<<endl;
  }
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main{
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

                String ss=br.readLine();
                double n=Double.parseDouble(ss);
                double d=Math.pow(n/3,3);
                System.out.println(d);





        }catch(Exception e){
            System.out.println("kkkk");
        }
    }
    static boolean isPal(String s){
        for(int i=0;i<s.length()/2;i++){
            if(s.charAt(i)!=s.charAt(s.length()-i-1)){
                return false;
            }
        }
        return true;
    }
    static class pair{
        int a,b;
        public pair(int a,int b){
            this.a=a;
            this.b=b;
        }
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}
 
int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> penalty(n, 0);
    vector<int> is_ac(n, 0);
    for (size_t i = 0; i < m; i++)
    {
        int p;
        string s;
        cin >> p >> s;
        if(is_ac[p-1]==0)
        {
            if(s=="AC"){
                is_ac[p - 1] = 1;
            }
            else{
                penalty[p - 1] += 1;
            }
        }
    }
    int ac=0;
    int pe = 0;
    for (size_t i = 0; i < n; i++)
    {
        if(is_ac[i]==1){
            ac++;
            pe += penalty[i];
        }
    }
    cout << ac << " " << pe << endl;
 
    return 0;
}

Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Char
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as BS

main = do
  [n,k] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  -- 2 <= n <= 10^5, 1 <= k <= 100
  h <- V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  -- 1 <= hi <= 10^4
  let dp = V.constructN n $ \dp ->
        if V.null dp
        then 0
        else let !i = V.length dp
                 !h_i = h V.! i
             in V.minimum $ V.map (\(dp_j, h_j) -> dp_j + abs (h_i - h_j)) $ V.drop (i-k) $ V.zip dp h
  print (V.last dp :: Int)


Measured memory_bytes: 3708
def calc_mod(n):
  calc = (10 - n % 10)
  if calc == 10:
    return 0
  else:
    return calc

n = 5
t = [int(input()) for i in range(n)]

sum_time = sum(t)
mod_t = list(map(calc_mod, t))

print(sum(t)+sum(mod_t)-max(mod_t))


Measured memory_bytes: 2940
N,M = map(int,input().split())

Hight = [int(x) for x in input().split()]
judge = []
count = 0

for i in range(N):
    judge.append(True)

for i in range(M):
    A,B = map(int,input().split())
    if Hight[A-1] < Hight[B-1]:
        judge[A-1] = False
    elif Hight[A-1] == Hight[B-1]:
        judge[A-1] = False
        judge[B-1] = False
    else:
        judge[B-1] = False

for b in judge:
    if b:
        count += 1

print(count)

Measured memory_bytes: 20108
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = iota(H).map!(_ => readln.chomp).array;

    Tuple!(int, int)[] X;

    foreach (i; 0..H) foreach (j; 0..W) if (A[i][j] == 'B') {
        X ~= tuple(i, j);
    }

    int ans  = 0;
    foreach (i; 0..X.length.to!int) foreach (j; i+1..X.length.to!int) {
        ans = max(ans, abs(X[i][0] - X[j][0]) + abs(X[i][1] - X[j][1]));
    }

    ans.writeln;
}


Measured memory_bytes: 2552
n,x=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l)
ans=0
for i in l:
    x-=i
    ans+=1
    if x<0:
        break
if x!=0 and ans>0:    
    print(ans-1)
else:
    print(ans)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# いっこ入力
n =int(input())

answer =0

for i in range(1,n+1):
    yakusuu = 0
    if i % 2 ==0:
        continue
    for j in range(1,n+1):
        if i % j == 0:
            yakusuu += 1
    if yakusuu == 8:
        answer += 1

print(answer)


Measured memory_bytes: 21552
#include <bits/stdc++.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+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int n,k;
  cin >> n >> k;
  if(n%k == 0) cout << 0 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 256
def solve():
    S = list(input())
    print(dfs(S,0,"")+ "=7")

def dfs(S,idx,res):
    res += S[idx]
    if idx == len(S) - 1:
        return res
    
    res1 = dfs(S,idx+1,res+'+')
    res2 = dfs(S,idx+1,res+'-')

    if eval(res1) == 7:
        return res1
    else:
        return res2
    
if __name__ == '__main__':
    solve()

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

int main(){
    int ans=1 ;
    vector<int> color(3);
    cin>>color.at(0)>>color.at(1)>>color.at(2);
    sort(color.begin(),color.end());
    if (color.at(0)!=color.at(1)){
        ++ans;
    }
    if (color.at(1)!=color.at(2)){
        ++ans;
    }
    cout<<ans<<endl;
}

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

using namespace std;


void solve() {
    string s; cin >> s;
    int k; cin >> k;
    int n = s.size();
    set<string> candi;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i+j > n) continue;
            candi.insert(s.substr(i,j));
        }
    }
    for (int i = 1; i < k; i++) {
        candi.erase(candi.begin());
    }
    auto res = *candi.begin();
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105;
int main(){
	string s;
	cin >> s;
	if(s=="SUN")
	cout << 7 << endl;
	else if(s=="MON")
	cout << 6 << endl;
	else if(s=="TUE")
	cout << 5 << endl;
	else if(s=="WED")
	cout << 4 << endl;
	else if(s=="THU")
	cout << 3 << endl;
	else if(s=="FRI")
	cout << 2 << endl;
	else if(s=="SAT")
	cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

	int a,b,c;
	cin >> a >> b >> c;

	multiset<int> S;
	S.insert(a);
	S.insert(c);
	S.insert(b);

	if(S.count(5) == 2 && S.count(7) == 1)
		cout << "YES\n";
	else cout << "NO\n";

	return 0;
}


Measured memory_bytes: 3604
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.Math;

   public class Main
   {
      static final double EPS = 0.0000001;
      static final double EPS2 = 0.0000000001;
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int K = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         double low = EPS2;
         double high = 1.0*arr[0];
         for(int x: arr)
            high = Math.max(high, 1.0*x);
         while(low+EPS < high)
         {
            double mid = (low+high)/2;
            long moves = 0L;
            for(int x: arr)
            {
               int lol = (int)(x/mid);
               moves += lol;
               if(Math.abs(lol*mid-x) > EPS2)
                  moves++;
            }
            moves -= N;
            if(moves > K)
               low = mid;
            else
               high = mid;
         }
         int res = (int)Math.ceil(low);
         System.out.println(res);
      }
   }

Measured memory_bytes: 55464
H1,M1,H2,M2,K=map(int, input().split())

if H1 > H2:
  hour = H2+(24-H1)
else:
  hour = H2-H1

if M1 > M2:
  hour -= 1
  minutes = M2+(60-M1)
else:
  minutes = M2-M1
print(hour*60+minutes-K)


Measured memory_bytes: 9164
#include <stdio.h>

int main(void)
{
	int c1;
	int c2;
	int c3;
	int left;
	static int num[11];
	int i;
	int count;
	
	while (scanf("%d", &c1) != EOF){
		scanf("%d %d", &c2, &c3);
		
		for (i = 1; i <= 10; i++){
			num[i] = 1;
		}
		
		count = 0;
		
		left = 20 - c1 - c2;
		
		num[c1] = 0;
		num[c2] = 0;
		num[c3] = 0;
		
		for (i = 1; i <= 10; i++){
			if (i <= left && num[i] == 1){
				count++;
			}
		}
		
		if (count > 3){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 580
#include<stdio.h>
#include<string.h>
char map[105][105];
int n,m,dx[]={0,0,-1,1},dy[]={1,-1,0,0},ans;
void dfs(int x,int y,char ch)
{
	map[x][y]=0;
	for(int i=0;i<4;++i)
	{
		int tx=x+dx[i],ty=y+dy[i];
		if(tx<0||tx>=n||ty<0||ty>=m||map[tx][ty]!=ch)
		{
			continue;
		}
		dfs(tx,ty,ch);
	}
}
int main()
{
	while(scanf("%d%d",&n,&m),n|m)
	{
		for(int i=0;i<n;++i)
		{
			scanf("%s",&map[i]);
		}
		ans=0;
		for(int i=0;i<n;++i)
		{
			for(int j=0;j<m;++j)
			{
				if(map[i][j])
				{
					++ans;
					dfs(i,j,map[i][j]);
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int A, B; cin >> A >> B;
  int result = 6 - A - B;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import Control.Monad

main = do
    n <- readLn :: IO Int
    let ans = solve n
    print $ length ans
    forM_ ans $ \(i,j) -> do
        putStrLn $ show i ++ " " ++ show j

solve n = if even n then evenSolve n else oddSolve n
    where evenSolve n = [(i,j)| i <- [1..n-1], j<-[i+1..n], i+j /= n+1]
          oddSolve n =  [(i,j)| i <- [1..n-1], j<-[i+1..n], i+j /= n]

Measured memory_bytes: 5488
n,a,b=map(int,input().split())
c=a+b
if n<=c:
    if n<=a:
        ans=n
    else:
        ans=a
else:
    x=n//c
    y=x*a
    z=x*c
    t=n-z
    if t<=a:
        ans=y+t
    else:
        ans=y+a
print(ans)


Measured memory_bytes: 2940
#include <cstdlib>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#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 < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)

const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
// long long dp[];

int main() {
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    cout<<min(A,B)+min(C,D)<<endl;
}


Measured memory_bytes: 256
N=int(input())
A=[]
for i in range(2**N):
    a=int(input())
    A.append(a)


for i in range(N):
    B=[]
    for j in range(len(A)):
        if j%2==1:
            if A[j]==A[j-1]:
                B.append(A[j])
            else:
                B.append(abs(A[j]-A[j-1]))
    A=B
print(A[0])

Measured memory_bytes: 18712
H_list=[]
W_list=[]
while True:
  H,W = map(int, input().split())
  if H == 0 and W == 0: 
    break
  H_list.append(H)
  W_list.append(W)

for (Hlist, Wlist) in zip(H_list,W_list):
  for i in range(Hlist):
    for i in range(Wlist):
        print("#", end="")
    print()
  print()


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, cnt = 0, ans = 0;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		int a;
		cin >> a;
		if (a == i) {
			cnt++;
		}
		else {
			ans += (cnt + 1) / 2;
			cnt = 0;
		}
	}
	cout << (ans += (cnt + 1) / 2) << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

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

  int ans = 0;
  vi p(n);
  rep(i,n) p[i] = i;
  do{
    bool ok = (p[0] == 0);
    rep(i,n-1){
      ok &= (g[p[i]][p[i+1]] > 0);
    }
    if(ok) ans++;
  }while(next_permutation(all(p)));

  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = []
x = []
for i in range(m):
    P, X = map(int, input().split())
    p.append(P)
    x.append(X)

num = sum(t)

for i in range(m):
    print(num - t[p[i]-1] + x[i])

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353

N, S = MAP()
A = LIST()

# dp0[i][j] := i番目の要素まで見て、総和がjで、使う区間が未確定の状態の通り数
dp0 = list2d(N+1, S+1, 0)
# dp1[i][j] := i番目の要素まで見て、総和がjで、使う区間がL確定済の状態の通り数
dp1 = list2d(N+1, S+1, 0)
# dp2[i][j] := i番目の要素まで見て、総和がjで、使う区間がLR確定済の状態の通り数
dp2 = list2d(N+1, S+1, 0)
dp0[0][0] = 1
for i, a in enumerate(A):
    for j in range(S+1):
        # aを総和に足さない遷移は全部OK
        dp0[i+1][j] += dp0[i][j]
        dp1[i+1][j] += dp0[i][j] + dp1[i][j]
        dp2[i+1][j] += dp0[i][j] + dp1[i][j] + dp2[i][j]
        # aを総和に足す遷移は、遷移元が状態2と遷移先が状態0は無理
        if j+a <= S:
            dp1[i+1][j+a] += dp0[i][j] + dp1[i][j]
            dp2[i+1][j+a] += dp0[i][j] + dp1[i][j]
        dp0[i+1][j] %= MOD
        dp1[i+1][j] %= MOD
        dp2[i+1][j] %= MOD
ans = dp2[N][S]
print(ans)


Measured memory_bytes: 246792
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<vector<int>> data(N, vector<int>(2));
	for (int i = 0; i < N; i++)
		cin >> data[i][0];
	for (int i = 0; i < N; i++)
		cin >> data[i][1];
	long long max = data[0][1];
	for (int i = 0; i < N; i++) { //スタート地点のfor
		long long score = 0;
		int next = i;
		long long sum = 0;
		int return_count = 0;
		vector<int> return_checker(N, 0);
		int j = 0;
		while (1) {
			next = data[next][0] - 1;
			if (return_checker[next] == 1) {
				return_count = j ;
				break;
			}
			else 
				return_checker[next] = 1;
			sum += data[next][1];
			j++;
		}
		
		if (sum > 0)
			score = (K / return_count - 1) * sum;
		next = i;
		for (int j = 0; j < (K % return_count)+return_count; j++) {
			next = data[next][0] - 1;
			score += data[next][1];
			if (score > max)
				max = score;
		}
			

	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3904
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        x: isize,
    }

    let mut ans: (isize, isize) = (0, 0);

    for a in -1000..1000 {
        for b in -1000..1000 {
            if (a as isize).pow(5) - (b as isize).pow(5) == x {
                ans = (a, b);
                break;
            }
        }
    }
    println!("{} {}", ans.0, ans.1);
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>

using lint = int64_t;
using namespace std;

#define rep(i, n) for (lint i = 0; i < (n); ++i)
#define rep1(i, n) for (lint i = 1; i < (n); ++i)
#define repn(i, a, b) for(lint i = (a); i < (b); ++i)
#define Rep(i, n) for (lint i = (n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define cend printf("\n")

using P = pair<int, int>;
using D = pair<double, double>;
//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1000'000'007LL;
constexpr lint inf = 3LL * mod * mod;
const double Pi = 2.0 * acos(0.0);

template<class T> using prique     = priority_queue<T>;
template<class T> using prique_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& rhs) { return is >> rhs.first >> rhs.second; }
template<class T, class U>inline ostream& operator<<(ostream& os, const pair<T, U>& rhs) { return os << rhs.first << " " << rhs.second << "\n"; }

constexpr bool pri(lint x) { for (lint i = 2; i * i <= x; ++i) if (x % i == 0) return false; return 1 < x; }

double dis(D a, D b) { return hypot(a.first - b.first, a.second - b.second); }

lint fact[3000000];
void fact_init(lint n) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
}

lint modpow(lint x, lint n, lint m = mod) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) {
			res *= x;
			if (m <= res) res %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return res;
}

lint intpow(lint x, lint n) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r) {
	if (r == 0 || r == n) return 1;
	lint res = fact[n] * modpow(fact[n - r], mod - 2, mod) % mod * modpow(fact[r], mod - 2, mod) % mod;
	return res < 0 ? res + mod : res;
}

map<lint, lint> factring(lint n) {
	map<lint, lint> res;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++res[i];
		}
	}
	if (n != 1) ++res[n];
	return res;
}

lint n, cnt, cnt1, cnt2;
bitset<2 * 100010>x;

lint f(lint a) {
	lint res = 1;
	while (a != 0) {
		a %= bitset<18>(a).count();
		++res;
	}
	return res;
}
int main() {
	cin >> n >> x;
	cnt = x.count();
	if (cnt != 1) {
		rep(i, n) {
			if (x[i]) {
				cnt1 += modpow(2, i, cnt - 1);
				cnt1 %= cnt - 1;
				cnt2 += modpow(2, i, cnt + 1);
				cnt2 %= cnt + 1;
			}
		}
	}
	Rep(i, n - 1) {
		if (cnt != 1) {
			lint t1 = modpow(2, i, cnt - 1), t2 = modpow(2, i, cnt + 1);
			if (x[i]) {
				cout << f((cnt1 - t1 + cnt - 1) % (cnt - 1)) << "\n";
			}
			else {
				cout << f((cnt2 + t2) % (cnt + 1)) << "\n";
			}
		}
		else {
			if (x[i]) cout << "0\n";
			else {
				if (!x[0] && (i != 0)) cout << "1\n";
				else cout << "2\n";
			}
		}
	}
}

Measured memory_bytes: 3736
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var NQ=(Arr.shift()).split(" ").map(Number);
var N=NQ[0];
var Q=NQ[1];
var str="kogakubu10gokan";
for(var i=0;i<N;i++){
   var arr=Arr[i].split(" ");
   var a=arr[0]-0;
   if(a<=Q)str=arr[1];
}
console.log(str);

Measured memory_bytes: 7648
def examA():
    AB = [I() for _ in range(2)]
    for i in range(1,4):
        if not i in AB:
            ans = i
            break
    print(ans)
    return

def examB():
    N = I()
    S,T = LSI()
    ans = ""
    for i in range(N):
        ans += S[i]+T[i]
    print(ans)
    return

def examC():
    return

def examD():
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()


Measured memory_bytes: 38384
<?php

$result = 0;
$s = trim(fgets(STDIN));
$s = str_replace(array("\r\n","\r","\n"), '', $s);
$s = str_split($s);

for ($i=0; $i<3; $i++) {
    if ($s[$i] != 0) {
        $result++;
    }
}

echo $result;


Measured memory_bytes: 16272
#include <bits/stdc++.h>
const int MAX=1e6+10;
const int modn=1e9+7;
typedef long long ll ;
#define endl '\n'
#define cwk     freopen("D:\\workplace\\CLion\\in.in","r",stdin),freopen("D:\\workplace\\CLion\\out.out","w",stdout)
using namespace std;
int n,a[MAX];
bool vis[MAX];
int cnt[MAX];
void prepare(){
    bool is=true;
    for(int i=2;i<MAX;i++){
        int ans=0;
        if(!vis[i]){
            for(int j=i;j<MAX;j+=i){
                if(cnt[j])
                    ans+=cnt[j];
            }
            if(ans>1){
                is=false;
            }
            if(ans==n){
                cout<<"not coprime\n";
                return;
            }
        }
    }
    if(is) cout<<"pairwise coprime";
    else cout<<"setwise coprime";
}
void solve(){
    cin>>n;
    for(int i=0;i<n;i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    prepare();

}
signed main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    //cwk;
    int _=1;
    //cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int A,B,D;

void input() {
	cin>>A>>B>>D;
}

void solve() {
	int res=B/D-A/D;
	if(A%D==0) res++;
	cout<<res<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

const ll MX=3e6;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,K;
  string s;
  cin>>N>>K>>s;
  deque<int> A(N);
  for(int i=0;i<N;i++){A[i]=s[i]=='A'?1:0;}
  int k=0;
  for(int i=0;i<min(K,MX);i++){
    if((A[0]^k)==1){A[0]^=1;}
    else{A.pop_front(); A.push_back(k); k^=1;}
  }
  K-=min(K,MX);
  if(K&1){
    A[0]^=N&1;
  }
  for(auto &I:A){cout<<((I^k)==0?"B":"A");}
  cout<<endl;
  
  return 0;
}


Measured memory_bytes: 1560
#include <stdio.h>

int main(){
  int N;
  scanf("%d",&N);

  if (N % 10 == 1 || N % 10 == 6 || N % 10 == 8 || N % 10 == 0) {
      printf("pon");
  }else if (N % 10 == 2 || N % 10 == 4||N % 10 == 5 || N % 10 == 7 || N % 10 == 9) {
      printf("hon");
  }else if (N % 10 == 3) {
      printf("bon");
  }

}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;
const int MAX_SIZE = 2 * 1e5;

void solve(){

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

    sort(all(A));

    vector<int> c;
    int i = 0;
    while(i < N){
        int tmp = A[i],cnt = 0;
        while(i < N && A[i] == tmp){
            i++;
            cnt++;
        }
        if (cnt != 0) {
            c.push_back(cnt);
        }
    }

    sort(all(c));
    int ans = 0;
    for (int i = 0; i < (int)c.size() - K; ++i) {
        ans += c[i];
    }
    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 2168
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define yorn(f) puts((f)?"Yes":"No")
ll n, a, b;
//ld ;
//string s;
 
int main() {
  cin >> n >> a >> b;
  ll ans1 = (n/(a+b)) * a;
  ll ans2 = min(n%(a+b),a);
  cout << ans1 + ans2 << endl;
  return 0;
}

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

int main(){
	int a;
	int b[100] = {};
	cin >> a;
	for(int i = 0; i < a; i++){
		cin >> b[i];
	}
	for(int j = a-1; j >= 0; --j){
		cout << b[j];
		if(j == 0){
			break;
		}
		cout << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;
string aki="AKIHABARA";
int main(void){
	cin >> str;
	int now=0;
	bool flag=true;
	for(int i=0;i<str.size();i++){
		if(now==aki.size())flag=false;
		else{
			if(aki[now]==str[i])now++;
			else{
				if(aki[now]=='A'){
					now++;
					i--;
				}
				else flag=false;
			}
		}
	}
	if(now<aki.size()){
		if(aki[now]=='A')now++;
	}
	if(now!=aki.size())flag=false;
	printf("%s\n",flag?"YES":"NO");
	return 0;
}

Measured memory_bytes: 764
#include <stdio.h>

int ceiling(int a, int b){
    int i;
    int temp = 0;
    for(i = 0; temp < a; i++)
        temp += b;
    return i;
}
int main(void){
    int n, x, t, a;

    scanf("%d %d %d", &n, &x, &t);
    a = ceiling(n, x);

    printf("%d\n", a * t);

    return 0;
}

Measured memory_bytes: 1724
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] s = in.nextIntArray(n);

            int sum = IntStream.of(s).sum();

            if (sum % 10 != 0) {
                out.println(sum);
                return;
            }

            int min = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                if (s[i] % 10 != 0) min = Math.min(min, s[i]);
            }

            out.println(min == Integer.MAX_VALUE ? 0 : sum - min);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

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

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 26580
#include<stdio.h>
#include<math.h>

int main(void)
{
	int n;
	int c;
	int m;
	int k;
	
	m = 0;
	c = 0;
	scanf("%d", &n);
	
	for(k = n; k > 0; k--){
		while(k % 2 == 0){
			c++;
			k /= 2;
		if(m < c){
			m = c;
		}
		}
	}
	printf("%d", (int)pow(2, c));
	return 0;
}	

Measured memory_bytes: 128
//(駅, 色)を頂点としたダイクストラだが、遷移を減らすために、改札(色0)を導入する。遷移は, 色i->0 (0), i->i (0), 0->i (1)とする。
//ちなみに：色i->iのコストが0でない場合、始点と終点を区別する必要があるため、(駅, 色, 始点 or 終点)を頂点としたい。
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

struct Edge { int from, to, cost; Edge() {} Edge(int from, int to, int cost) { this->from = from; this->to = to; this->cost = cost; } };
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int n, m;
int p[200000], q[200000], c[200000];
vector<P> states;
vector<int> colors[200000];
Graph graph;

int toId(int eki, int color) { return lower_bound(states.begin(), states.end(), P(eki, color)) - states.begin(); }
int dijkstra(Graph &g, int s, int t) {
	static priority_queue<P, vector<P>, greater<P> > que;
	vector<int> minCost;
	int i;
	
	minCost.resize(g.size());
	rep(i, g.size()) minCost[i] = 1145141919;
	
	que.push(P(0, s)); minCost[s] = 0;
	while (!que.empty()) {
		P now = que.top(); que.pop();
		int cst = now.first;
		int pos = now.second;
		rep(i, graph[pos].size()) {
			int npos = graph[pos][i].to;
			if (minCost[npos] > minCost[pos] + graph[pos][i].cost) {
				minCost[npos] = minCost[pos] + graph[pos][i].cost;
				que.push(P(minCost[npos], npos));
			}
		}
	}
	return minCost[t];
}

signed main() {
	int i, j;
	cin >> n >> m;
	rep(i, m) { cin >> p[i] >> q[i] >> c[i]; p[i]--; q[i]--; }
	rep(i, m) { states.push_back(P(p[i], c[i])); states.push_back(P(q[i], c[i])); }
	rep(i, n) { states.push_back(P(i, 0)); }	//改札
	sort(states.begin(), states.end());
	states.erase(unique(states.begin(), states.end()), states.end());
	
	rep(i, m) { colors[p[i]].push_back(c[i]); colors[q[i]].push_back(c[i]); }
	rep(i, n) { colors[i].push_back(0); }	//改札
	rep(i, n) {
		sort(colors[i].begin(), colors[i].end());
		colors[i].erase(unique(colors[i].begin(), colors[i].end()), colors[i].end());
	}
	
	graph.resize(states.size());
	rep(i, m) {
		int u = toId(p[i], c[i]);
		int v = toId(q[i], c[i]);
		graph[u].push_back(Edge(u, v, 0));
		graph[v].push_back(Edge(v, u, 0));
	}
	rep(i, n) {
		rep(j, colors[i].size()) {
			int u = toId(i, colors[i][j]);
			int v = toId(i, 0);
			graph[u].push_back(Edge(u, v, 0));
			graph[v].push_back(Edge(v, u, 1));
		}
	}
	
	//駅0から駅n - 1まで行く. (頂点0の改札から頂点n - 1の改札まで行くコストと等しい)
	int res = dijkstra(graph, toId(0, 0), toId(n - 1, 0));
	if (res >= 1145141919) cout << -1 << endl;
	else cout << res << endl;
	return 0;
}

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

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    
    if (a.at(a.size()-1) == b.at(0) and b.at(b.size()-1) == c.at(0)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int n = 50;
int main() {
  ll k;
  cin >> k;

  int m = k%n;
  k /= n;
  vector<ll> ans(n,k+n-1-m);
  rep(i,n){
    if(i<m) ans[i] += n+1;
  }
  cout << n << endl;
  rep(i,n) cout << ans[i] << " "; cout << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
def main():
    N, M = map(int, input().split())
    d = defaultdict(int)
    for _ in range(M):
        a, b = map(int, input().split())
        d[a] += 1
        d[b] += 1

    for i, j in d.items():
        if j % 2 == 1:
            print('NO')
            exit()

    print('YES')


if __name__ == "__main__":
    main()

Measured memory_bytes: 86920
#include<bits/stdc++.h>
using namespace std;
int a[27]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int main()
{
	string s;
	int i;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
      switch(s[i])
      {
          case'a':a[1]++; break;
          case'b':a[2]++; break;
          case'c':a[3]++; break;
          case'd':a[4]++; break;
          case'e':a[5]++; break;
          case'f':a[6]++; break;
          case'g':a[7]++; break;
          case'h':a[8]++; break;
          case'i':a[9]++; break;
          case'j':a[10]++; break;
          case'k':a[11]++; break;
          case'l':a[12]++; break;
          case'm':a[13]++; break;
          case'n':a[14]++; break;
          case'o':a[15]++; break;
          case'p':a[16]++; break;
          case'q':a[17]++; break;
          case'r':a[18]++; break;
          case's':a[19]++; break;
          case't':a[20]++; break;
          case'u':a[21]++; break;
          case'v':a[22]++; break;
          case'w':a[23]++; break;
          case'x':a[24]++; break;
          case'y':a[25]++; break;
          case'z':a[26]++; break;
      }
    }
    for(i=1;i<=26;i++) 
    {
    	if(a[i]>1) 
    	{
    		cout<<"no";
    		return 0;
		}
	}
    cout<<"yes";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define big long long
int main()
{
	//#ifndef ONLINE_JUDGE
		//freopen("take.in","r",stdin);
		//freopen("give.out","w",stdout);
	//#endif

	string s;
	cin>>s;
	int turn=0;

	int q;
	cin>>q;

	string a,b;

	while(q--)
	{
		int t;
		cin>>t;
		if(t==1)
		{
			turn++;
		}
		else
		{
			int f;
			char c;
			cin>>f>>c;
			if(f==1)
			{
				if(turn%2==0) a=c+a;
				else b=b+c;
			}
			else
			{
				if(turn%2==0) b=b+c;
				else a=c+a;
			}
		}
	}

	if(turn%2==1)
	{
		reverse(s.begin(),s.end());
		reverse(a.begin(),a.end());
		reverse(b.begin(),b.end());
		swap(a,b);
	}

	string ans=a+s+b;
	cout<<ans<<endl;

}

Measured memory_bytes: 1512