akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func main() {
	a, b := readInt(), readInt()
	switch {
	case a < b:
		s := strconv.Itoa(a)
		fmt.Println(strings.Repeat(s, b))
	case a >= b:
		s := strconv.Itoa(b)
		fmt.Println(strings.Repeat(s, a))
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {

    jaldi

    int n;
    cin>>n;
    vector<pair<int,int>> a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i].first;
        cin>>a[i].second;
    }
    int c=0;
    bool flag = false;
    for(int i=0;i<n;i++) {
        if(a[i].first== a[i].second){
            c++;
        }
        else {
            c=0;
        }
        if(c==3) {
            flag = true;
            break;
        }
    }
    if(flag) {
        cout<<"Yes"<<'\n';
    }
    else {
        cout<<"No"<<'\n';
    }
}


Measured memory_bytes: 3652
use std::io;
use std::str::FromStr;
use std::cmp::max;

fn main() {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let words:Vec<&str> = line.trim().split(" ").collect();

    let a = i32::from_str(&words[0]).unwrap();
    let b = i32::from_str(&words[1]).unwrap();
    let c = i32::from_str(&words[2]).unwrap();

    let answer = max(max(10 * a + b + c, 10 * b + a + c), 10 * c + a + b);
    println!("{}", answer)
}

Measured memory_bytes: 4352
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<char>>;
using P =pair<int,int>;

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

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    ll ans=0;
    rep(i,60){
        int x=0;
        rep(j,n){
            if((a[j]>>i)&1)++x;
        }
        ll sum=x*(n-x)%mod;
        rep(j,i){
            sum=sum*2%mod;
        }
        ans+=sum%mod;
    }
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
 int ans ,sum=0 ,cost1=0 , cost2=0;
cin>>n;
int a[n];
for(int i=0; i<n; i++)
{
cin>>a[i];
sum=sum+a[i];
}
ans=sum/n;
for(int i=0; i<n; i++)
cost1=cost1+((a[i]-ans)*(a[i]-ans));
ans=(sum/n)+1;
for(int i=0; i<n; i++)
cost2=cost2+((a[i]-ans)*(a[i]-ans));

cout<<min(cost1,cost2);
return 0;
}



Measured memory_bytes: 3548
#![allow(unused)]

use std::{cell, cmp, collections, fmt, ops};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use fmt::{Debug, Display};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        _input_inner!(iter, $($r)*)
    };
    ($($r:tt)*) => {
        let mut 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")
    };
}

#[cfg(feature = "debug")]
macro_rules! d {
    ($($args: tt)*) => { dbg!($($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! d {
    ($($args:tt)*) => {};
}

mod num {
    //
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

mod bits {
    pub fn is_high(bits: u64, pos: u64) -> bool {
        bits & (1 << pos) != 0
    }
}

fn main() {
    input!(stones_num: usize, pos_num: usize, pos: [i32; pos_num]);

    if stones_num >= pos_num {
        println!("{}", 0);
        return;
    }

    let mut pos = pos;
    pos.sort();

    let mut intervals = pos.windows(2).map(|w| w[1] - w[0]).collect::<Vec<_>>();
    intervals.sort_by(|d1, d2| d2.cmp(&d1));

    let ans = intervals.iter().skip(stones_num - 1).sum::<i32>();
    println!("{}", ans);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}


Measured memory_bytes: 6396
#include <iostream>
#include <vector>
#include <sstream>

using namespace std;

int main() {
    vector<int> stack;

    string line;
    getline(cin, line);
    istringstream iss(line);

    string in;
    while(iss >> in) {
        if (in == "+") {
            int b = stack.back();
            stack.pop_back();

            int a = stack.back();
            stack.pop_back();

            stack.push_back(a+b);
        } else if (in == "-") {
            int b = stack.back();
            stack.pop_back();

            int a = stack.back();
            stack.pop_back();

            stack.push_back(a-b);
        } else if (in == "*") {
            int b = stack.back();
            stack.pop_back();

            int a = stack.back();
            stack.pop_back();

            stack.push_back(a*b);
        } else {
            stack.push_back(stoi(in));
        }
    }

    cout << stack.back() << endl;

    return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

const int mod=1e9+7;

#include<map>
template<typename T> 
void factP(map<T,T> &m,T n)
{
	T x=n;
	for(T i=2;i*i<=n;i++)
	{
		while(x%i==0)
		{
			m[i]++;
			x/=i;
		}
	}
	if(x!=1)m[x]++;
	return;
}

int64_t pow(int64_t a,int64_t b,int64_t mod)
{
	if(b==0)return 1;
	if(b%2==0)
	{
		int64_t d=pow(a,b/2,mod);
		return (d*d)%mod;
	}else//if(b%2==1)
	{
		return (a*pow(a,b-1,mod))%mod;
	}
}

int64_t comb(int64_t n,int64_t r,int64_t p)
{
	int64_t ret=1;
	for(int64_t i=0;i<r;i++)
	{
		ret*=(n-i);
		ret%=p;
	}
	for(int64_t i=2;i<=r;i++)
	{
		ret*=pow(i,p-2,p);
		ret%=p;
	}
	return ret;
}

int64_t rcomb(int64_t n,int64_t r,int64_t p)
{
	return comb(n+r-1,r,p);
}

int main()
{
	int N,M;
	
	cin >> N >> M;
	
	map<int,int> m;
	factP(m,M);
	
	lint ans=1;
	for(auto&& i:m)
	{
		ans*=rcomb(N,i.second,mod);
		ans%=mod;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		int sum = 0;
		for(int i = 0; i < 4; i++){
			int a = in.nextInt();
			sum += a;
		}
		System.out.println(sum / 60);
		System.out.println(sum % 60);
	}

}

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

/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
//const ll INF = (1LL << 60);
//const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
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; }
/**************************************/

/******** User-defined Function *******/




/**************************************/

/********** Main()  function **********/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n; cin >> n;
  map<ll,ll> mp;
  ll s = 0;
  rep(i,n){
    ll a; cin >> a;
    s += a;
    mp[a]++;
  }

  int q; cin >> q;
  vector<ll> B(q),C(q);
  rep(i,q) cin >> B[i] >> C[i];
  rep(i,q){
    ll b = B[i], c = C[i];
    decltype(mp)::iterator it = mp.find(b);
    if (it == mp.end()) { 
      cout << s << endl;
      continue;
    }
  
    ll tmp = mp[b];
    mp[b] = 0;
    decltype(mp)::iterator it2 = mp.find(c);
    if (it2 == mp.end()) { 
      mp[c] = tmp;
    }else mp[c] += tmp;

    s -= ll(b * tmp);
    s += ll(c * tmp);

    cout << s << endl;
  }

  return 0;
}
/********  Main() Ends Here *************/


Measured memory_bytes: 9628
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
using Engine = tuple<int, int, double>;

int main()
{
    int n;
    vector<Engine> engines;
    cin >> n;
    int x, y;
    for (int i = 0; i < n; ++i)
    {
        cin >> x;
        cin >> y;
        engines.emplace_back(x, y, atan2(y, x));
    }
    sort(engines.begin(), engines.end(), [](const Engine& x, const Engine& y) { return get<2>(x) < get<2>(y); });

    double maxLength = 0;
    for (int begin = 0; begin < n; ++begin)
    {
        for (int count = 1; count <= n; ++count)
        {
            long long sumX = 0, sumY = 0;
            for (int i = 0; i < count; ++i)
            {
                Engine engine = engines[(begin + i) % n];
                sumX += get<0>(engine);
                sumY += get<1>(engine);
            }
            double length = sqrt(sumX * sumX + sumY * sumY);
            maxLength = max(maxLength, length);
        }
    }
    cout << setprecision(15) << maxLength << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    long long int a[n + 1];

    long long int b[n];
    for (int i =0; i< n +1;i++) {
        cin >> a[i];
    }

    for (int i =0; i< n;i++) {
        cin >> b[i];
    }
    
    long long int sum = 0;
    for (int i = 0;i<n;i++) {
        sum += min (a[i],  b[i]);
        b [i] = b[i] -  min (a[i] , b[i]);
        if (b[i] > 0) {
            sum += min (a[i+1],  b[i]);
            a[i+1] = a[i+1] - min (a[i+1] ,b[i]);

        }
    }
    cout << sum<< endl ;
}



Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <stdlib.h>

using namespace std;

int main()
{
	int H, N;
	cin >> H >> N;
	vector<int> A(N);

	for (int i = 0; i < N; i++)
		cin >> A[i];

	int MAX = 0, SUM = 0;

	for (int i = 0; i < N; i++)
	{
		SUM += A[i];
		A[i] = 0;
			
	}
	if ( H <= SUM)
		cout << "Yes";
	else
		cout << "No";

}

Measured memory_bytes: 640
#include <iostream>
using ll = long long;
using namespace std;

/* initialize */

/* main */
int main() {
    int n,m;
    cin >> n >> m;
    if (n == 1) n = 14; if (m == 1) m = 14;
    if(n>m) cout << "Alice";
    else if (n==m) cout << "Draw";
    else if (n<m) cout << "Bob";
    return 0;
}

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

#define rep(a,b) for(int a=0; a<b; ++a)

using ll=long long;

template<typename T>
using vec=vector<T>;

int main(void){
	int N; cin>>N;
	vec<ll> a(N); rep(i,N) cin>>a[i];
	sort(a.begin(),a.end());
	int bunbo,bunsi;
	double ans,tmp;
	
	// 分母優先で考えた場合
	int idx,dif=INT_MAX;
	for(int i=1; i<N; ++i){
		if(a[i]-a[i-1]<dif){
			idx=i,dif=a[i]-a[i-1];
		}
	}
	auto va=a;
	bunbo=va[idx]-va[idx-1];
	va.erase(va.begin()+idx),va.erase(va.begin()+idx-1);
	ans=(double)(va[va.size()-2]+va[va.size()-1])/bunbo;
	
	// 分子優先で考えた場合
	bunsi=a[N-1]+a[N-2];
	dif=INT_MAX;
	for(int i=1; i<N-2; ++i){
		if(a[i]-a[i-1]<dif){
			idx=i,dif=a[i]-a[i-1];
		}
	}
	tmp=(double)bunsi/(a[idx]-a[idx-1]);
	
	cout<<fixed<<setprecision(10)<<max(ans,tmp)<<endl;
}


Measured memory_bytes: 3272
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n,m,d = m()

ans = 0

if d == 0:
    ans += (m-1) / n
else:
    ans += (m-1) * (2*(n-d)/(n**2))


print(ans)




Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
int n;
int a[int(1e5+123)];

int f(ll x)
{
	int s = 0;
	for(int i = 0; i < x; i++)
		s+=(a[i] - 1);
	return s;
}

int main()
{
	cin >> n;
	ll mx=100;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int ans = f(n);
	cout << ans;
}

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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b>c+d) cout << "Left" << endl;
    else if(a+b<c+d) cout << "Right" << endl;
    else cout << "Balanced" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

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

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

int main()
{
    IOS;
    ll k,n;
    cin>>k>>n;
    ll a[n];
    repf(i,0,n) cin>>a[i];
    ll ans=k;
    repf(i,0,n-1)
    {
        ans=min(ans,k-abs(a[i+1]-a[i]));
    }
    ans=min(ans,abs(a[0]-a[n-1]));
    cout<<ans<<endl;
}     

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

using namespace std;

void solve()
{
	int n;
	cin >> n;
	bool first = true;
	while(n--)
	{
		if(!first)
		{
			cout << endl;
		}
		first = false;
		char field[9][9];
		char isWrong[9][9];
		for(int i = 0; i < 9; ++i)
		{
			for(int j = 0; j < 9; ++j)
			{
				cin >> field[i][j];
				isWrong[i][j] = ' ';
			}
		}
		for(int i = 0; i < 9; ++i)
		{
			vector<int> count(10);
			bool flag = false;
			for(int j = 0; j < 9; ++j)
			{
				++count[field[i][j] - '0'];
				if(count[field[i][j] - '0'] >= 2)
				{
					flag = true;
				}
			}
			if(flag)
			{
				for(int j = 1; j < 10; ++j)
				{
					if(count[j] >= 2)
					{
						for(int k = 0; k < 9; ++k)
						{
							if(field[i][k] == j + '0')
							{
								isWrong[i][k] = '*';
							}
						}
					}
				}
			}
		}
		
		for(int i = 0; i < 9; ++i)
		{
			vector<int> count(10);
			bool flag = false;
			for(int j = 0; j < 9; ++j)
			{
				++count[field[j][i] - '0'];
				if(count[field[j][i] - '0'] >= 2)
				{
					flag = true;
				}
			}
			if(flag)
			{
				for(int j = 1; j < 10; ++j)
				{
					if(count[j] >= 2)
					{
						for(int k = 0; k < 9; ++k)
						{
							if(field[k][i] == j + '0')
							{
								isWrong[k][i] = '*';
							}
						}
					}
				}
			}
		}

		for(int i = 0; i < 3; ++i)
		{
			for(int j = 0; j < 3; ++j)
			{
				int count[10] = {};
				bool flag = false;
				for(int k = 0; k < 3; ++k)
				{
					for(int l = 0; l < 3; ++l)
					{
						++count[field[3 * i + k][3 * j + l] - '0'];
						if(count[field[3 * i + k][3 * j + l] - '0'] >= 2)
						{
							flag = true;
						}
					}
				}
				if(flag)
				{
					for(int k = 1; k < 10; ++k)
					{
						if(count[k] >= 2)
						{
							for(int l = 0; l < 3; ++l)
							{
								for(int m = 0; m < 3; ++m)
								{
									if(field[3 * i + l][3 * j + m] == k + '0')
									{
										isWrong[3 * i + l][3 * j + m] = '*';
									}
								}
							}
						}
					}
				}
			}
		}
		for(int i = 0; i < 9; ++i)
		{
			for(int j = 0; j < 9; ++j)
			{
				cout << isWrong[i][j] << field[i][j];
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
#define int long long 

int32_t main()
{
    string S;
    cin>>S;
    int n=S.length();
    // RRRRLLLLLRRRRLLLL
    int i=0;
    vector<int>ans(n, 0);
    while(i<n)
    {
        int j=i;
        while(j<n && S[j]=='R') j++;
        int mid=j-1;
        while(j<n && S[j]=='L') j++;

        while(i<j)
        {
            if(abs(mid-i)%2)
            {
                ans[mid+1]++;
            } 
            else ans[mid]++;
            i++;
        }
    }
    for(auto &x: ans) cout<<x<<' ';
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	ll h,w;
	cin >> h >> w;
	
	if (h%3==0 || w%3==0) {
		cout << "0" << endl;
		return 0;
	}

	ll fi = min(h,w);

	ll fi1 = 100000, fi2 = 100000;

	ll a[3]={};
	for(ll i=1;i<h;i++){
		a[0]=i*w;
		a[1]=(w/2) * (h-i);
		a[2]=(w-w/2)*(h-i);
		sort(a,a+3);
		fi1 = min(a[2]-a[0],fi1);
	}

	for(ll i=1;i<w;i++){
		a[0]=i*h;
		a[1]=(h/2) * (w-i);
		a[2]=(h-h/2)*(w-i);
		sort(a,a+3);
		fi2 = min(a[2]-a[0],fi2);
	}
	ll ans = min({fi,fi1,fi2});
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
char s[25][25];
bool vis[25][25];
struct node{
    int x,y,dis;
};
int direction[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
void bfs(int x,int y){
    if(s[x][y]=='#'){
    	return ;
	}
    memset(vis,0,sizeof(vis));
    queue<node>q;
    q.push((node){x,y,0});
    vis[x][y]=1;
    while(!q.empty()){
        node now=q.front();
        q.pop();
        ans=max(ans,now.dis);
        for(int i=0;i<4;++i){
            int temp_x=now.x+direction[i][0]; 
			int temp_y=now.y+direction[i][1];
            if(temp_x<=0){
            	continue;
			}else if(temp_x>n){
				continue;
			}else if(temp_y<=0){
				continue;
			}else if(temp_y>m){
				continue;
			}else if(s[temp_x][temp_y]=='#'){
				continue;
			}else if(vis[temp_x][temp_y]){
				continue;
			}
            q.push((node){temp_x,temp_y,now.dis+1});
            vis[temp_x][temp_y]=1;
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
    	cin>>s[i]+1;
	}
    for(int i=1;i<=n;++i){
    	for(int j=1;j<=m;++j){
    		bfs(i,j);
		}
	}
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, K = lr()
    A = lr()
    vis = [-1]*(N+1)
    dis = [0]*(N+1)
    v = 1
    cnt = 0
    while vis[v] == -1:
        dis[cnt] = v
        vis[v] = cnt
        v = A[v-1]
        cnt += 1
    if K <= vis[v]:
        print(dis[K])
    else:
        print(dis[(K-vis[v])%(cnt-vis[v])+vis[v]])
resolve()

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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)

typedef pair<int, int> P;

const int inf = 1 << 25;

struct edge
{
  int to, cost;
  edge(){}
  edge(int to, int cost):to(to), cost(cost){}
};

vector< vector<edge> > graph;
vector< vector<int> > mincost;

void dijkstra(int s)
{
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  mincost[s][s] = 0;
  while(!que.empty()) {
    int cost, now;
    tie(cost, now) = que.top(); que.pop();
    if(mincost[s][now] < cost) continue;
    for(edge& e : graph[now]) {
      if(e.cost + cost < mincost[s][e.to]) {
	mincost[s][e.to] = e.cost + cost;
	que.push(P(mincost[s][e.to], e.to));
      }
    }
  }
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, R;
  cin >> N >> R;
  graph.resize(N);
  rep(i, R) {
    int s, t, d;
    cin >> s >> t >> d; s--, t--;
    graph[s].emplace_back(t, d);
    graph[t].emplace_back(s, d);
  }

  mincost.resize(N, vector<int>(N, inf));
  int maxdist = 0;
  rep(i, N) dijkstra(i);
  rep(i, N) reps(j, i+1, N) maxdist = max(maxdist, mincost[i][j]);

  //vector<P> ep;
  vector<int> S, T;
  rep(i, N) reps(j, i+1, N) {
    if(mincost[i][j] == maxdist) S.push_back(i), T.push_back(j);//ep.emplace_back(i, j);
  }

  vector<int> ans;
  rep(i, N) {
    bool flag = true;
    //for(auto& p : ep) {
    rep(j, S.size()) {
      //int s, t; tie(s, t) = p;
      if(mincost[S[j]][i] + mincost[i][T[j]] == maxdist) {
	flag = false;
	break;
      }
    }
    if(flag) ans.push_back(i+1);
  }
  
  cout << ans.size() << endl;
  rep(i, ans.size()) cout << ans[i] << endl;
  
  return 0;
}

Measured memory_bytes: 24344
import java.util.HashSet;
import java.util.Set;

public class Main {

	private static void solve() {
		int n = ni();
		int m = ni();
		
		int[] count = new int[m];
		int[] samePair = new int[m];
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < n; i ++) {
			int x = ni();
			count[x % m] ++;
			if (set.contains(x)) {
				set.remove(x);
				samePair[x % m] ++;
			} else {
				set.add(x);
			}
		}
		
		int ret = count[0] / 2;
		count[0] %= 2;
		if (m % 2 == 0) {
			ret += count[m / 2] / 2;
			count[m / 2] %= 2;
		}
		for (int i = 1; i < (m + 1) / 2; i ++) {
			int v = Math.min(count[i], count[m - i]);
			ret += v;
			count[i] -= v;
			count[m - i] -= v;
		}
		for (int i = 0; i < m; i ++) {
			int v = Math.min(samePair[i], count[i] / 2);
			ret +=v;
		}
		System.out.println(ret);
	}

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			@Override
			public void run() {
				long start = System.currentTimeMillis();
				String debug = args.length > 0 ? args[0] : null;
				if (debug != null) {
					try {
						is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
				}
				reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
				solve();
				out.flush();
				tr((System.currentTimeMillis() - start) + "ms");
			}
		}, "", 64000000).start();
	}

	private static java.io.InputStream is = System.in;
	private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
	private static java.util.StringTokenizer tokenizer = null;
	private static java.io.BufferedReader reader;

	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new java.util.StringTokenizer(reader.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	private static double nd() {
		return Double.parseDouble(next());
	}

	private static long nl() {
		return Long.parseLong(next());
	}

	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private static char[] ns() {
		return next().toCharArray();
	}

	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}

	private static int[][] ntable(int n, int m) {
		int[][] table = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[i][j] = ni();
			}
		}
		return table;
	}

	private static int[][] nlist(int n, int m) {
		int[][] table = new int[m][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[j][i] = ni();
			}
		}
		return table;
	}

	private static int ni() {
		return Integer.parseInt(next());
	}

	private static void tr(Object... o) {
		if (is != System.in)
			System.out.println(java.util.Arrays.deepToString(o));
	}
}


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

typedef long long ll;

using namespace std;

ll mem[105][100005];
ll S[105];
ll V[105];

ll max_s;
ll dp(ll n, ll s)
{
    if(n == -1) return 0;
    ll& res = mem[n][s];
    if(res != -1) return res;
    if(s - S[n] >= 0)
        res = max(dp(n-1, s), dp(n-1, s-S[n]) + V[n]);
    else
        res = dp(n-1, s);
    return res;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    memset(mem, -1, sizeof(mem));
    ll n; cin >> n >> max_s;
    for(int i=0; i<n; i++)
        cin >> S[i] >> V[i];
    dp(n-1, max_s);
    cout << mem[n-1][max_s] << endl;
}


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

typedef struct {
  int ch[11];
  int num;
  int time;
  int tnum;
} lg;
int M,T,R,P;
vector<lg> team;

bool asc(lg t1,lg t2);

int main(){
  int i,j,m,t,p;

  for(i=0;i<51;i++){
    lg x;
    team.push_back(x);
  }
  while(1){
    cin >> M >> T >> P >> R;
    if(M==0&&T==0&&P==0&&R==0)break;
    for(i=0;i<=T;i++){
      team[i].num=0;
      team[i].time=0;
      team[i].tnum=i+1;
      for(j=0;j<=P;j++)team[i].ch[j]=0;
    }
    for(i=0;i<R;i++){
      cin >> m >> t >> p >> j;
      if(j!=0)team[t-1].ch[p]++;
      else{
	team[t-1].time+=20*team[t-1].ch[p];
	team[t-1].num++;
	team[t-1].time+=m;
      }
    }

    sort(team.begin(),team.begin()+T,asc);

    for(i=0;i<T;i++){
      if(i==0)cout << team[i].tnum;
      else if(team[i-1].num==team[i].num&&team[i-1].time==team[i].time)cout << "="<<team[i].tnum;
      else cout << ","<<team[i].tnum;
    }
    cout << endl;
  }
  return 0;
}

bool asc(lg t1,lg t2){
  if(t1.num>t2.num)return 1;
  else if(t1.num==t2.num&&t1.time<t2.time)return 1;
  else if(t1.num==t2.num&&t1.time==t2.time&&t1.tnum>t2.tnum)return 1;
  else return 0;
}



Measured memory_bytes: 3156
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
double dist(ll i, ll j)
{
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}

int main()
{
    ll n,i,j,cc=0;
    cin>>n;
    vector<ll>q;
    for(i=0;i<n;i++){
        cin>>j;
        q.pb(j);
    }
    sort(q.begin(),q.end());
    double sum=((q[0]+q[1])*1.0)/2.0;
    for(i=2;i<n;i++){
        sum=((sum+q[i])*1.0)/2.0;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 4992
#include <stdio.h>
int main(){
 
  int x,alph[26]={0},i;
  char ch;
 
  for(i = 0; i < 1200; i++){
 
      scanf("%c",&ch);
       
      if (ch >= 'A' && ch <= 'Z'){
     
    x=ch-'A';
     
    alph[x]++;
     
      } else if (ch >= 'a' && ch <= 'z'){
     
    x=ch-'a';
     
    alph[x]++;
     
      }
       
  }
 
  for(i = 0; i < 26; i++){
 
    printf("%c : %d\n",'a'+i,alph[i]);
 
  }
 
  return 0;
 
}


Measured memory_bytes: 2112
while 1:
	n=input()
	if n==0:break
	p=map(int,raw_input().split())
	sp=p[0]
	ans=[]
	for i in range(n-1):
		if p[i]+1!=p[i+1]:
			if sp!=p[i]:
				ans.append(str(sp)+"-"+str(p[i]))
			else:
				ans.append(str(sp))
			sp=p[i+1]
	else:
		if sp!=p[-1]:
			ans.append(str(sp)+"-"+str(p[-1]))
		else:
			ans.append(str(sp))
	print " ".join(ans)

Measured memory_bytes: 4244
//                      YATIN KWATRA

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll                      long long 
#define ld                      long double
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                      vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                      unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795
// #define node                    Node

using namespace std;

void INPUT() {

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}


void solve()
{ 

        int n;
        n = 5;
        
        vii v(n);
        
        fo(i,0,n-1) cin >> v[i];

        fo(i,0,n-1)
        {
          if(v[i] == 0)
          {
            cout << i+1 << endl;
            return;
          }
        }
    
       
}
int main() {
    
    FIO
    INPUT();
    
    int t;
    t = 1;
 //   cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 3600
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a, b = (int(_) for _ in input().split())
    a_1 = a-1
    b_1 = b-1
    ans = max(a+a-1,b+b-1,a+b)
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3684
program main
	implicit none
    integer::n,i
    real(8)::t
    integer,allocatable::x(:),y(:)
    read(*,*) n
    allocate(x(n))
    allocate(y(n))
    
    read(*,*) x
    y=x
    call heapsort(n,y)
    
    t=(real(y(n/2),kind=8)+real(y(n/2 +1),kind=8))/2.0_8
    
    do i=1,n
    	if(real(x(i),8)<t)then
        	write(*,*) y(n/2 +1)
        else
        	write(*,*) y(n/2)
        end if
    end do
    
    deallocate(x)
    deallocate(y)
    
    
    stop
contains
	subroutine heapsort(n,array)
        implicit none
        integer,intent(in) :: n
        integer,intent(inout) :: array(1:n)
       
        integer ::i,k,j,l
        double precision :: t
       
        if(n.le.0)then
           write(6,*)"Error, at heapsort"; stop
        endif
        if(n.eq.1)return
      
        l=n/2+1
        k=n
        do while(k.ne.1)
           if(l.gt.1)then
              l=l-1
              t=array(L)
           else
              t=array(k)
              array(k)=array(1)
              k=k-1
              if(k.eq.1) then
                 array(1)=t
                 exit
              end if
           end if
           i=l
           j=l+l
           do while(j.le.k)
              if(j.lt.k)then
                 if(array(j).lt.array(j+1))j=j+1
              end if
              if (t.lt.array(j))then
                 array(i)=array(j)
                 i=j
                 j=j+j
              else
                 j=k+1
              endif
           end do
           array(i)=t
        end do
      
        return
    end subroutine heapsort
end program main

Measured memory_bytes: 4864
N = int(input())
S = list(input())
"""
ans = ""
for a in S:
    ans += chr((ord(a) + N - ord("A")) % 26 + ord("A"))

"""
ans = ""
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for a in S:
    ans += alpha[(alpha.index(a) + N) % 26]

print(ans)

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s; cin >> s;
  int n0=0,n1=0;

  for(int i = 0;i<s.size();i++){
    if(s[i]=='0') n0++;
    if(s[i]=='1') n1++;
  }  

  int ans = 2*min(n0,n1);

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


Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#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 repp(i,a,b)  for(ll i=a;i<=(ll)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    cs
    int n;cin>>n;
    vector<int> v(n);
    for(auto &i:v) cin>>i;
    vector<vector<ll>> dp(n,vector<ll>(n));
    rep(i,n) dp[i][i]=v[i];
    repp(i,1,n-1) {
        repp(j,0,n-1-i) {
            dp[j][j+i]=max(v[j]-dp[j+1][j+i],v[j+i]-dp[j][j+i-1]);
        }
    }
    cout<<dp[0][n-1];
}

Measured memory_bytes: 70784
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        final int A=0,C=1,G=2,T=3,mod=1000000007;
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int[][][][] dp=new int[111][4][4][4];
        int ans=0;
        dp[0][0][0][0]=1;
        for(int i=1;i<=n;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    for(int l=0;l<4;l++){
                        for(int m=0;m<4;m++){
                            if(i>2) {
                                if (k == A && l == G && m == C) continue;
                                if (k == A && l == C && m == G) continue;
                                if (k == G && l == A && m == C) continue;
                            }
                            if(i>3) {
                                if (j == A && l == G && m == C) continue;
                                if (j == A && k == G && m == C) continue;
                            }
                            dp[i][k][l][m]+=dp[i-1][j][k][l];
                            dp[i][k][l][m]%=mod;
                        }
                    }
                }
            }
        }
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    ans+=dp[n][i][j][k];
                    ans%=mod;
                }
            }
        }
        out.println(ans);
        out.flush();
    }
}

Measured memory_bytes: 21716
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  string s;
  cin >> s;
  int ok = 1;
  int n = s.size();
  for(int i = 0; i < n; i++) {
    ok &= s[i] == s[n-1-i];
    if(i <= n/2-1) ok &= s[i] == s[n/2-1-i];
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    class UnionFind(private var num: Int) {
        private val parent: IntArray = IntArray(num)
        private val rank: IntArray = IntArray(num)
        private val size: IntArray = IntArray(num)

        init {
            for (i in 0 until num) {
                parent[i] = i
                rank[i] = 1
                size[i] = 1
            }
        }

        fun union(u: Int, v: Int): Int {
            var u = u
            var v = v
            u = root(u)
            v = root(v)
            if (u == v)
                return u
            if (rank[v] < rank[u]) {
                val t = v
                v = u
                u = t
            }
            parent[u] = v
            rank[v] += rank[u]
            rank[u] = -1
            val t = size[u]
            size[u] = t + size[v]
            size[v] = t + size[v]
            return v
        }

        fun root(u: Int): Int {
            var u = u
            while (parent[u] != u)
                u = parent[u]
            return u
        }

        fun size(u: Int): Int {
            return size[root(u)]
        }
    }
    val (n, m, k) = readLine()!!.split(' ').map(String::toInt)
    val union = UnionFind(n)
    val friendNum = IntArray(n)
    val blockNum = IntArray(n)
    for (i in 1..m) {
        val (a, b) = readLine()!!.split(' ').map(String::toInt)
        union.union(a - 1, b - 1)
        friendNum[a - 1]++
        friendNum[b - 1]++
    }
    for (i in 1..k) {
        val (c, d) = readLine()!!.split(' ').map(String::toInt)
        if (union.root(c - 1) == union.root(d - 1)) {
            blockNum[c - 1]++
            blockNum[d - 1]++
        }
    }

    for (i in 0 until n) {
        val size = union.size(i)
        val fn = friendNum[i]
        val bn = blockNum[i]
        print("${size - fn - bn - 1} ")
    }
    println()
}


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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 12;
const int Q = 55;
const int INF = (int) 1e9 + 7;

int n, m, q;
int arr[N];
int a[Q];
int b[Q];
int c[Q];
int d[Q];

int ans = 0;
void f(int i, int x) {
	if (i > n) {
		int sum = 0;
		for (int j = 0; j < q; ++j) {
			if (arr[b[j]] - arr[a[j]] == c[j]) sum += d[j];
		}
		ans = max(sum, ans);
		return;
	}

	for (int j = x; j <= m; ++j) {
		arr[i] = j;
		f(i + 1, j);
	}
}

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	sf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < q; ++i) {
		sf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
	}

	f(1, 1);

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

	return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(void){
  int n,m,i,j,dp[3010][3010]={},fr[3010][3010];
  bool same[3010][3010]={false};
  string s,t;
  cin >> s >> t;
  n=s.size();
  m=t.size();
  for (i=0;i<n;i++) for (j=0;j<m;j++){
    dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
    if (dp[i][j+1]>dp[i+1][j]) fr[i+1][j+1]=1;
    else fr[i+1][j+1]=0;
    if (s[i]==t[j] && dp[i+1][j+1]<dp[i][j]+1){
      dp[i+1][j+1]=dp[i][j]+1;
      fr[i+1][j+1]=2;
    }
  }
  
  vector<int> ss;
  i=n;
  j=m;
  while (i>0 && j>0){
    if (fr[i][j]==2){
      ss.push_back(i-1);
      i--;
      j--;
    }else if (fr[i][j]==1) i--;
    else j--;
  }
  for (i=ss.size()-1;i>=0;i--) cout << s[ss[i]];
  cout << endl;
  return 0;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    bool dis_flg;
    dis_flg = true;
    for(int i=0; i<n; i++){
        cin >> h[i];
    }

    for(int i=1; i<n; i++){
        if(h[i-1] > h[i]){
            cout << "No" << endl;
            return 0;
        }else{
            if(h[i] != h[i-1]){
                h[i] = h[i] - 1;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}




Measured memory_bytes: 3788
W,H,N=map(int,input().split())
ll=[list(map(int,input().split()))for i in range(N)]
wmax=W
hmax=H
wmin=0
hmin=0
for i in range(N):
    if ll[i][2]==1 and ll[i][0]>=wmin:
        wmin=ll[i][0]
    elif ll[i][2]==2 and ll[i][0]<=wmax:
        wmax=ll[i][0]
    elif ll[i][2]==3 and ll[i][1]>=hmin:
        hmin=ll[i][1]
    elif ll[i][2]==4 and ll[i][1]<=hmax:
        hmax=ll[i][1]
ans = (wmax-wmin)*(hmax-hmin)
if wmax-wmin>0 and hmax-hmin>0:
    print((wmax-wmin)*(hmax-hmin))
else:
    print(0)

Measured memory_bytes: 3064
#include<stdio.h>

using namespace std;

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

    int cnt = 0;
    
    for(int i = 0; i < q; i++){
        int key;
        scanf("%d", &key);
        int left = 0;
        int right = n - 1;
        while(left <= right){
            if(s[(left + right) / 2] == key){
                cnt++;
                break;
            }
            else if(s[(left + right) / 2] < key){
                left = (left + right) / 2 + 1;
            }
            else{
                right = (left + right) / 2 - 1;
            }
        }
    }

    printf("%d\n", cnt);
}


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

int f(int x){
	int sum = 0;
	while(0 < x){
		sum += x%10;
		x /= 10;
	}
	return sum;
}

int main(){
	int n;
	cin >> n;
	
	int sum = f(n);
	
	if(n%sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vector <int> a(A, 0);
	for (int ii = 0; ii < A; ++ii){
		cin >> a[ii];
	}
	vector <int> b(B, 0);
	for (int ii = 0; ii < B; ++ii){
		cin >> b[ii];
	}
	vector <int> x(M, 0);
	vector <int> y(M, 0);
	vector <int> c(M, 0);
	for (int ii = 0; ii < M; ++ii){
		cin >> x[ii] >> y[ii] >> c[ii];
		x[ii]--;
		y[ii]--;
	}

	int ans = 1001001001;
	for (int ii = 0; ii < M; ++ii){
		int index1 = x[ii];
		int index2 = y[ii];
		int tmp = a[index1] + b[index2] - c[ii];
		ans = min(ans, tmp); 
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	ans = min(ans, a[0] + b[0]);

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 2176
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000//10^12
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007

using namespace std;

//void型なので返り値は無し　d[]に結果が格納されるので欲しいものをansに
int main(void)
{
	//変数の宣言
	int n;
	static char s[100010][15];
	ll int dp[10];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	int ok,ng;



	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);


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

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	for(i=0;i<5;i++){
		dp[i]=0;
	}

	for(i=0;i<n;i++){
		if(s[i][0]=='M'){
			dp[0]++;
		}else if(s[i][0]=='A'){
			dp[1]++;
		}else if(s[i][0]=='R'){
			dp[2]++;
		}else if(s[i][0]=='C'){
			dp[3]++;
		}else if(s[i][0]=='H'){
			dp[4]++;
		}
	}

	for(i=0;i<5;i++){
		for(j=i+1;j<5;j++){
			for(k=j+1;k<5;k++){
				ans=ans+dp[i]*dp[j]*dp[k];
			}
		}
	}

	//	printf("計算部分終了\n");

	//出力
//	for(i=0;i<5;i++){
//		printf("dp[%d]=%d\n",i,dp[i]);
//	}
	
	printf("%lld",ans);

	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main() {
    int n; cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        mp[x]++;
    }
    int start = 1;
    if (n % 2) {
        start = 2;
        if (mp[0] != 1) {
            cout << 0;
            return 0;
        }
    }
    long long ans = 1;
    long long md = 1e9 + 7;
    for (int i = start; i < n; i+= 2) {
        if (mp[start] != 2) {
            cout << 0;
            return 0;
        }
        ans = (ans * 2) % md;
    }
    cout << ans;
}


Measured memory_bytes: 6528
import fractions
N,M =list(map(int,input().split(" ")))
S = input()
T = input()
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

ans = lcm(N,M)

step_S = ans //M
step_T = ans //N

ind_s = 0
ind_t = 0
while True:

    if ind_s >= N or ind_t >= M:
        break

    if S[ind_s ] != T[ind_t]:
        print(-1)
        exit(0)

    ind_s += step_S
    ind_t += step_T
print(ans)

Measured memory_bytes: 5688