akhauriyash/Code-Regression huggingface dataset:
//! Framework <https://github.com/vain0x/procon>

#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::collections::*;

pub struct Scan(Box<dyn Iterator<Item = &'static str>>); // '

impl Scan {
    fn new() -> Self {
        let mut buf = String::new();
        let read_line = move || {
            std::io::stdin().read_line(&mut buf).unwrap();
            Box::leak(buf.split_off(0).into_boxed_str()).split_whitespace()
        };
        Scan(Box::new(std::iter::repeat_with(read_line).flatten()))
    }

    pub fn word<T: std::str::FromStr>(&mut self) -> T {
        self.0.next().unwrap().parse().ok().unwrap()
    }

    pub fn list<T: std::str::FromStr>(&mut self, len: usize) -> Vec<T> {
        std::iter::repeat_with(|| self.word()).take(len).collect()
    }
}

fn main() {
    let mut scan = Scan::new();

    let N = scan.word::<usize>();
    let K = scan.word::<usize>();
    let C = scan.word::<usize>();
    let S = scan.word::<String>().chars().collect::<Vec<_>>();

    // 前から貪欲
    let mut work1 = vec![false; N];
    let mut k1 = 0;
    let mut i = 0;
    while i < N {
        if S[i] == 'o' {
            work1[i] = true;
            k1 += 1;
            i += 1 + C;
        } else {
            i += 1;
        }
    }

    // 後ろから貪欲
    let mut work2 = vec![false; N];
    let mut k2 = 0;
    let mut i = N;
    while i >= 1 {
        i -= 1;

        if S[i] == 'o' {
            work2[i] = true;
            k2 += 1;
            i = i.saturating_sub(C);
        }
    }

    if k1 == K && k2 == K {
        for i in 0..N {
            if work1[i] && work2[i] {
                println!("{}", i + 1);
            }
        }
    }
}


Measured memory_bytes: 3592
n=int(input())
A=list(map(int, input().split()))
q=int(input())
bc=[]
for _ in range(q):
    b,c=map(int, input().split())
    bc.append((b,c))

allsum=sum(A)
cnt={}
for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a]+=1

for b,c in bc:
    if b not in cnt:
        cnt[b] = 0
    if c not in cnt:
        cnt[c] = 0
    allsum += (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] =0
    print(allsum)

Measured memory_bytes: 34856
#include <iostream>
#include <algorithm>

int main()
{
	int N,K;
	int *A,*B;
	std::cin >> K >> N;
	A = new int[N + 1];
	B = new int[N];
	for (int i = 0; i < N; i++)
	{
		std::cin >> A[i];
	}
	A[N] = A[0] + K;
	for (int i = 0; i < N; i++)
	{
		B[i] = A[i + 1] - A[i];
	}
	std::sort(B, B+N);
    std::cout << K-B[N-1];
	delete[] A;
	delete[] B;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl;
#define out2(a,b) cout<<a<<" "<<b<<endl;
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

vector< bool > prime_table(int n) {
    vector< bool > prime(n + 1, true);
    if(n >= 0) prime[0] = false;
    if(n >= 1) prime[1] = false;
    for(int i = 2; i * i <= n; i++) {
        if(!prime[i]) continue;
        for(int j = i + i; j <= n; j += i) {
            prime[j] = false;
        }
    }
    return prime;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    vector<bool> pt = prime_table(55555);
    ll cnt=0;
    Vec a;
    REP(i,2,55556){
        if(i%5==1&&pt[i]){
            a.pb(i);
            cnt++;
        }
        if(cnt==n)break;
    }
    vout(a);
    return  0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	string s,u;
	t = 1;
	while(t--) {
	 cin >> s >> u;
	 reverse(u.begin( ), u.end( ));
	 if(s == u)
	  cout << "YES" << endl;
	 else
	  cout << "NO" << endl;
	}
	return 0;
}



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

int main() {
  int a,b;
  cin >> a>>b;
  int x = 1;
  for(int j=0;j<a;j++){
    if(x<b){
      x*=2;
    }else{
      x+=b;
    }
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
while True :
    C = input()
    
    if C == "-" :
        break
    else :
        m = int(input())
        
        for i in range(m) :
            h = int(input())
            c = C[0 : h]
            C = C[h : len(C) + 1]
            C += c
        
        print(C)


Measured memory_bytes: 5592
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MAX_V=114514LL;
const ll MAX = 510000LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
  ll a,b;cin>>a>>b;
  cout<<a*b<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

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

    int n;
    cin >> n;
    map<int, int> mp;
    for(int i = 1; i <= n; ++i){
        int x = i;
        for(int j = 2; j * j <= x; ++j){
            while(x % j == 0){
                x /= j;
                ++mp[j];
            }
        }
        if(x != 1)  ++mp[x];
    }
    modint ans = 1;
    for(auto it : mp){
        ans *= modint(it.second + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 100005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

int main()
{
	string A, B;
	cin >> A >> B;
	for (int i = 0; i < 26; ++i)
	{
		bool ok = true;
		set <char> st;
		for (int j = 0; j < (int) B.size(); ++j)
		{
			if(B[j] - 'a' != i)
				continue;

			st.insert(A[j]);
			if(A[j] != B[j])
			{
				ok = false;
			}
		}
		if(!ok)
		{
			if((int) st.size() > 1)
			{
				cout << "No";
				return 0;
			}
			char ch = *st.begin();
			for (int j = 0; j < (int) A.size(); ++j)
			{
				if(A[j] == ch)
					A[j] = 'a' + i;
				else if(A[j] == 'a' + i)
					A[j] = ch;
			}
		}
		// cout << A << "\n";
	}
	if(A != B)
	{
		cout << "No";
		return 0;	
	}
	cout << "Yes";
}



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

int main() {
    //input
    int n;
    cin >> n;
    double x;
    string u;
    long double sum = 0;
    for(int i = 0;i<n;i++){
        cin >> x >> u;
        if(u == "JPY"){
            sum += x;
        }else{
            sum += x * 380000;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  ll two = 0;
  ll four = 0;
  ll others = 0;
  for (auto i = 0; i < N; i++) {
    ll a;
    cin >> a;
    if (a % 4 == 0) four++;
    else if (a % 2 == 0) two++;
    else others++;
  }
  string res;
  if (four >= others) res = "Yes";
  else if (four + 1 == others && two == 0) res = "Yes";
  else res = "No";

  cout << res << endl;

  return 0;
}


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

int main() {
  int N, i;
cin >> N;
string s;
for (i = 0; i < N; i++) {
  cin >> s;
  
  if (s == "Y"){
    cout << "Four" << endl;
    break;
  }
  
  if (i == (N -1))
    cout << "Three" << endl;
}
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
 
#define X first
#define Y second
 
//#include <boost/unordered_map.hpp>
//using namespace boost;
 
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/
 
using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
//using i128 = i64;
//using u128 = u64;
 
ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}
 
ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

ll gcd(ll a, ll b)
{
	return b ? gcd(b, a%b) : a;
}
 
template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}
 
template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

template<class T>
void print(const T &a)
{
	for (auto x : a) printf("%d ", x); puts("");
}

const int MAXN = 500010;
//const int MAXM = 100010;
const int MAXK = 30;
//const i64 INF = 1000000000000000000LL;
const int INF = 1000000000;
//const int MOD = 998244353;
const int B = 31;
const int MOD = 1000000007;
//const int INV2 = (MOD+1)/2;
const ld pi = 3.1415926535897932384626433;

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

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

int days[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool leap(int y)
{
	return y%4 == 0 && y%100 != 0 || y%400 == 0;
}

int n;
pdd a[MAXN];

void solve()
{
	cin >> n;
	for (int i = 0; i < n; ++ i)
	{
		cin >> a[i].X >> a[i].Y;
	}
	sort(a, a+n);
	ld ans = 0;
	int cnt = 0;
	while (1)
	{
		++ cnt;
		ld ret = 0;
		for (int i = 1; i < n; ++ i)
			ret += sqrt((a[i].X-a[i-1].X)*(a[i].X-a[i-1].X)+(a[i].Y-a[i-1].Y)*(a[i].Y-a[i-1].Y));
		ans += ret;
		if (!next_permutation(a, a+n)) break;
	}
	printf("%.12f\n", (double)(ans/cnt));
}

int main()
{
	
	int T;
	T = 1;
	//scanf("%d", &T);
	while (T --)
	solve();
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[21];
struct node
{
	int x,y;
}b[21][21];
int ans,pd[21];
int hh()
{
	for(int i=1;i<=n;i++)
	if(pd[i])
	for(int j=1;j<=a[i];j++)
	if(pd[b[i][j].x]!=b[i][j].y)
	return 0;
	return 1;
}
void dfs(int x,int y)
{
	if(x==n+1)
	{
		if(y>ans)
		if(hh())
		ans=y;
		return;
	}
	pd[x]=0;
	dfs(x+1,y);
	pd[x]=1;
	dfs(x+1,y+1);
	pd[x]=0;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		for(int j=1;j<=a[i];j++)
		scanf("%d%d",&b[i][j].x,&b[i][j].y);
	}
	dfs(1,0);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
S = input()
s = len(S)
T = input()
t = len(T)

cnt = t
for i in range(s-t+1):
    dif = 0
    for j in range(t):
        if S[i+j] != T[j]:
            dif += 1
    if cnt > dif:
        cnt = dif
print(cnt)


Measured memory_bytes: 9044
h, w = map(int, input().split())
c = []
for i in range(h):
    c.append(input())
thined_c = [0] * (2 * h)
for i in range(2 * h):
    s = ''
    for j in range(w):
        s += c[i // 2][j]
    thined_c[i] = s
for s in thined_c:
    print(s)


Measured memory_bytes: 9088
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using System.Security.Cryptography;
using console=System.Console;
namespace AtCoderTemplate
{
    public class App
    {
        public static void Main()
        {
var p = console.ReadLine().ToCharArray().Select(c=>c-'0').Select((v,i)=>new {v,i});
if(p.All(c=>c.v==1)||p.First(c=>c.v!=1).i>long.Parse(console.ReadLine())-1)
console.WriteLine(1);
else
console.WriteLine(p.First(c=>c.v!=1).v);

        }
    }
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

bool solve(string s) {
    return s[2] == s[3] && s[4] == s[5];
}

int main() {
    string S;
    cin >> S;
    if (solve(S)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main() {
	string s; cin >> s;
	int n = s.size() - 1;
	vector<int> a(s.size());
	for (int i = 0; i < s.size(); i++)
	{
		a.at(i) = s.at(i) - '0';
	}
	int64_t sum = 0;
	for (int bit = 0; bit < (1 << n); bit++) {
		int64_t tmp = a.at(0);
		for (int i = 0; i < n; i++)
		{
			if ((1 << i) & bit) {
				sum += tmp;
				tmp = a.at(i + 1);
			}
			else {
				tmp *= 10;
				tmp += a.at(i+1);
			}
		}
		sum += tmp;
	}
	cout << sum << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}



int main(){
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    //solve(K, N, std::move(A));
    ll ma=0;
    A.push_back(K+A[0]);
    for (long long i = 0; i < N; i++) {
        chmax(ma, A[i+1]-A[i]);
    }
    cout << K-ma << endl;
    return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
 
typedef long long ll;
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++) // no semicoron
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>0;i--)
#define FORD(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
 
using namespace std;
 
int factorialMethod(int k){
    ll sum = 1;
    FOR(i, 1, k+1)
    {
        sum *= i;
    }
    return sum;
}
 
int main(){
    ll N;
    cin >> N;
    vector<int> A (N+1);
    vector<int> B (N+1);
    vector<int> FM (N+1);
 
 
    FOR(i, 0, N+1) B[i] = 0;
 
    FOR(i, 1, N+1){
        cin >> A[i];
        B[A[i]]++;
    }
 
    //FOR(i, 0, N+1) cout << B[i] << endl;
 
    ll sum = 0;
    ll fm;
    ll maxb = 1;
 
    ll nkara;
    ll all = 0;
 
    FOR(i, 1, N+1){
        nkara = (ll)(B[i] - 1) * B[i] / 2;
        all += nkara;
    }
 
    FOR(i, 1, N+1){
        cout << all - (ll)(B[A[i]] - 1) << endl;
    }
    
    /*FOR(i, 1, N+1){
        if(maxb <= B[i]) maxb = B[i];
    }
 
    FOR(j, 1, maxb + 1){
        FM[j] = factorialMethod(B[j])/(2*factorialMethod(B[j] - 2));
    }
 
    FOR(i, 1, N+1){
        //cout << "i: " << i << endl;
        B[A[i]] --;
        FOR(j, 1, N+1){
            if(B[j] != 0){
                //cout << "j: " << j << endl;
                //cout << "B[j]: " << B[j] << endl;
                //fm = factorialMethod(B[j])/(2*factorialMethod(B[j] - 2));
                //cout << "fm: " << fm << endl;
                sum += FM[B[j]];
            }
            //ll fm = 
            
        }
        cout << sum << endl;
        B[A[i]] ++;
        sum = 0;     
    }*/
 
 
 
}

Measured memory_bytes: 4992
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  long long n,a[300005]={},ans=0,x,y;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<62; i++) {
    x=0,y=0;
    for(int j=0; j<n; j++) {
      if((1LL<<i)&a[j]) {
        x++;
      }
      else {
        y++;
      }
    }
    ans=(ans+((1LL<<i)%MOD)*(x*y%MOD))%MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll sumd(ll x) {
  ll ans = 0;
  while (x > 0) {
    ans += x%10;
    x/=10;
  }
  return ans;
}

int main() {
  ll k; cin >> k;
  ll ans = 1;
  ll d = 1;
  REP(i, k) {
    cout << ans << endl;
    if (1.0*(ans+d)/sumd(ans+d) > d) d *= 10;
    ans += d;
  }
  return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//s.find(w[i])==string::npos
//findの使い方

long long int n=1,cnt=0,ans=0,a,b,c,cmp,data,m,h,x,y,txa,txb,tya,tyb,xcmp=0,ycmp=0;

string s,w;

vector<int> z;

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

       cin >> a>> b >>c;
       a-=b;
       rrep(i,0,100000){
           if(a-c<0){
               break;
           }
           a-=c;
       }
       cout << a << endl;
return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF = 1e18L + 5;
int main() {
    ll n,W;
    cin>>n>>W;
    vector<ll> v(n),wt(n);
        ll sum_value=0;
    for(ll i=0;i<n;i++){
        cin>>wt[i]>>v[i];
        sum_value+=v[i];
    }
    vector<ll> dp (sum_value+1,INF);
    dp[0]=0;
    //dp[i]=min weight with total value exactly i;
    for(ll i=0;i<n;i++){
        for(ll value_already=sum_value-v[i]; value_already>=0;value_already--){
            dp[value_already+v[i]]=min(dp[value_already+v[i]],dp[value_already]+wt[i]);
        }
    }
        ll answer =0;
        for(ll i=0;i<=sum_value;i++){
            if(dp[i]<=W){
            answer=max(answer,i);}
        }
        cout<<answer;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int Euclid(int x, int y);

int main(void)
{
    long A,B; /*input var*/
    long lcm; /*least common multiple*/
    
    scanf("%ld %ld",&A,&B);
    lcm = A*B/Euclid(A,B);
    printf("%ld \n",lcm);
    return 0;
}

int Euclid(int x, int y)
{
    if(y==0)    return x;
    else    return Euclid(y,x%y);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
int32_t main(){
    // boost;
    double pie ;
    pie =  3.141592653;
   
    double r;
    cin>>r;
    double ans = 2*pie*r;
    precise(10);
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3784
// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  
  i = 'ABC';
  c = 'ARC';
  
  　if (input[0] === i) {
     console.log(c);
   } else {
     console.log(i);
   }

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29516
'''input
7
3 3 4 5 4 5 3
5 3 4 4 2 3 2
'''
n = input()
arr = map(int,raw_input().split())
arr1 = map(int,raw_input().split())
ss = sum(arr1)
pre = [0]
pre1 = [0]
for i in range(n):
	pre.append(pre[-1]+arr[i])
	pre1.append(pre1[-1]+arr1[i])
ans = -10**30
for i in range(n):
	ans = max(ans,pre[i+1]+ss-pre1[i])
print ans





Measured memory_bytes: 27756
#include <cstdio>
long long N, A, B;
int main()
{
	scanf("%lld%lld%lld", &N, &A, &B);
	if (A > B)
		puts("0");
	else if (N == 1)
		puts(A == B ? "1" : "0");
	else
		printf("%lld\n", (N - 2) * (B - A) + 1);
	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int64_t> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}

	int64_t ans = 0;

	// nが２～４は例外
	if (n == 2) {
		ans = max(a.at(0), a.at(1));
		cout << ans << endl;
		return 0;
	}
	if (n == 3) {
		ans = max(max(a.at(0), a.at(1)), a.at(2));
		cout << ans << endl;
		return 0;
	}
	if (n == 4) {
		ans = max(max(a.at(0) + a.at(2), a.at(0) + a.at(3)), a.at(1) + a.at(3));
		cout << ans << endl;
		return 0;
	}

	// それ以外
	vector<map<int, int64_t>> dp(n);
	map<int, int64_t> dp0;
	dp0[1] = a.at(0);
	dp.at(0) = dp0;
	map<int, int64_t> dp1;
	dp1[1] = max(a.at(0), a.at(1));
	dp.at(1) = dp1;
	map<int, int64_t> dp2;
	dp2[1] = max(dp1.at(1), a.at(2));
	dp2[2] = a.at(0) + a.at(2);
	dp.at(2) = dp2;
	map<int, int64_t> dp3;
	dp3[1] = max(dp2.at(1), a.at(3));
	dp3[2] = max(max(dp2.at(2), a.at(0) + a.at(3)), a.at(1) + a.at(3));
	dp.at(3) = dp3;

	for (int i = 4; i < n; i++) {
		map<int, int64_t> dpi;
		int num = (i + 1) / 2;
		if (i % 2 == 0) {
			// 奇数個の時
			if (i != 4) {
				dpi[num - 1] = max(dp.at(i - 2).at(num - 2) + a.at(i), dp.at(i - 1).at(num - 1));
			} else {
				dpi[num - 1] = max(dp.at(i - 1).at(1), a.at(i));
			}
			dpi[num] = max(dp.at(i - 2).at(num - 1) + a.at(i), dp.at(i - 1).at(num));
			dpi[num + 1] = dp.at(i - 2).at(num) + a.at(i);
			dp.at(i) = dpi;
		} else {
			// 偶数個の時
			dpi[num - 1] = max(dp.at(i - 2).at(num - 2) + a.at(i), dp.at(i - 1).at(num - 1));
			dpi[num] = max(dp.at(i - 2).at(num - 1) + a.at(i), dp.at(i - 1).at(num));
			dp.at(i) = dpi;
		}
	}

	ans = dp.at(n - 1).at(n / 2);
	cout << ans << endl;
}

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

int main () {
    int n, ans = 0; cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++) {
        if (p[i] != i + 1) ans++;
    }
    if (ans <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

    static class CSnukeFestival {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            int[] c = new int[n];
            for (int i = 0; i < n; i++) a[i] = in.nextInt();
            for (int i = 0; i < n; i++) b[i] = in.nextInt();
            for (int i = 0; i < n; i++) c[i] = in.nextInt();
            Arrays.sort(a);
            Arrays.sort(b);
            Arrays.sort(c);
            long sum = 0;

            for (int i = 0; i < n; i++) {
                
                int ng = -1;
                int ok = a.length;
                while (Math.abs(ok - ng) > 1) {
                    int mid = (ok + ng) / 2;
                    if (a[mid] >= b[i]) {
                        ok = mid;
                    } else {
                        ng = mid;
                    }
                   
                }
                long cnta = ok;

                ng = -1;
                ok = c.length;
                while (Math.abs(ok - ng) > 1) {
                    int mid = (ok + ng) / 2;
                    if (c[mid] > b[i]) {
                        ok = mid;
                    } else {
                        ng = mid;
                    }
                }
                
                long cntc = n - 1 - ng;
                sum += cnta * cntc;
            }

            out.println(sum);

        }

    }
}



Measured memory_bytes: 93904
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
vector <int> g[100003];
bool vis[100003];
int n,m;
vector <int> ans;
void dfs(int x){
	for (int i=0;i<g[x].size();i++){
		if (vis[g[x][i]]) continue;
		vis[g[x][i]]=1;
		ans.push_back(g[x][i]);
		dfs(g[x][i]);
		break;
	}
}
int main(){
	cin>>n>>m;
	for (int i=0; i<m; i++) {
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	vis[1]=1;
	ans.push_back(1);
	dfs(1);
	reverse (ans.begin(),ans.end());
	dfs(1);
	cout<<ans.size()<<endl;
	for (int i=0;i<ans.size();i++)
		cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 6904
import sys

lines = sys.stdin.readlines()

N = lines[0]
A = lines[1].strip().split(" ")

print " ".join(A)

for i in range(1, len(A)):
    key = A[i]
    j = i - 1
    while j >= 0 and int(A[j]) > int(key):
        A[j+1] = A[j]
        j -= 1
    A[j+1] = key
    print " ".join(A)

Measured memory_bytes: 6296
#include <iostream>
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 << "Balanced" << endl;
  }
  else{
    cout << "Right"<< endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
// int -> 4byte 2.1 * 10^9
// ll -> 8byte 9.2 * 10^18
// ans * as[i] > 10^18
// as[i] > 10^18 / ans

int main() {
  int n;
  cin >> n;
  ll as[100005];
  rep(i,n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    as[i] = a;
  }
  ll ans = 1;
  rep(i,n) {
    if (as[i] > 1000000000000000000 / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= as[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4364
#include<stdio.h>
#define M 100001
#define NIL -1
 
int height(int);
int parent(int);
int sibling(int);
int degree(int);
int getDepth(int u);
void hairetu(int);
void tree(int a);
void print(int); 

struct Node{ int p, l, r;};
struct Node T[M];

int D[M],H[M];
int n;
int A;

int main(void){
  int i, j, d, v, c, l;
  int t;
  int flag=0;
  
  scanf("%d", &n);
   
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &v, &d, &c);
  
    T[v].p = v;
      
    T[v].l = d;
  
    T[v].r = c;
      
  
  }
  A = 0;
  for(i=n-1;i>0;i--){
    if(T[i].l==A || T[i].r==A){
      A = T[i].p;  
      flag++;
      if(A == 0){
    break;
      }
    else {
      i = n-1;
    }
    }
  }
 
  if(flag == 0){
    A= 0;
  }
   
   
  for(i=0;i<n;i++){
    D[i] = getDepth(i);
  }
  
  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}

int height(int c){
  int l=0;
  int r=0;
  
  if(T[c].l==-1 && T[c].r == -1){
    return 0;
  }
if(T[c].l!=-1 && T[c].r != -1){
    l = height(T[c].l)+1;
    r = height(T[c].r)+1;
    if(l<r){
      return r;
    }
    else return l;
  }
  else if(T[c].l==-1&&T[c].r!=-1){
      return height(T[c].r)+1;
    }
  else if(T[c].l!=-1&&T[c].r==-1){
      return height(T[c].l)+1;
    }
}

int parent(int a){
  int i;
  if(a==A) return -1;
  else {
  for(i=0;i<n;i++){
    if(T[i].l==a || T[i].r == a){
      return T[i].p;
      break;
  }
  }
  }
}
  
int sibling(int b){
  int i;
  if(b==A) return -1;
  else {
    for(i=0;i<n;i++){
      if(T[i].l == b){
    return T[i].r;
      }
      if(T[i].r == b){
    return T[i].l;
      }
    }
  }
}
  int degree(int d){
  if(T[d].l==-1 && T[d].r == -1){
    return 0;
  }
  else if(T[d].l != -1 && T[d].r != -1){
    return 2;
  }
  else if((T[d].l == -1 && T[d].r != -1) || (T[d].l != -1 && T[d].r == -1)){
    return 1;
  }
   
  }
int getDepth(int u){
  int d = 0;
  int i;
  if(u == A) return 0;
  else{
    i = n-1;
    while(1){
      if(u == A) break;
      if(T[i].l == u || T[i].r == u){
    d++;
    u = T[i].p;
      }
      i--;
      if(i<0) i = n-1;
    }
    return d;
  }
    
}

void hairetu(int a){
  int leaf;
    
  if(getDepth(a) == 0){
    printf("root\n");
  }

  else if(T[a].r ==NIL && T[a].l ==NIL){
      printf("leaf\n");
    }
   
 
  else if(T[a].r!=NIL || T[a].l!= NIL){    printf("internal node\n");
  }
}
  void print(int u){
   
    
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",u,parent(u),sibling(u),degree(u),D[u],height(u));
  hairetu(u);
  }

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

int main(){
  int N, M, C;
  cin >> N >> M >> C;
  int B[M];
  for(int i=0; i<M; i++) cin >> B[i];
  int A[N][M];
  for(int i=0; i<N; i++){
    for(int j=0; j<M; j++){
      cin >> A[i][j];
    }
  }
  int ans=0;
  for(int i=0; i<N; i++){
    int num=0;
    for(int j=0; j<M; j++){
      num=num+A[i][j]*B[j];
    }
    if(num+C>0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cstring>

using namespace std;
int main(){
	int h,w;
	int t;
	cin>>t;
	for(int l = 0; l < t; l++){
		char field[21][21];
		memset(field,0,sizeof(field));
		if(l!=0)
			cout<<endl;
		char angle;
		cin>>h>>w;
		int sy,sx;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>field[i][j];
				switch(field[i][j]){
				case '^':
					angle='u';
					sy=i;
					sx=j;
					break;
				case 'v':
					angle='d';
					sy=i;
					sx=j;
					break;
				case '>':
					angle='r';
					sy=i;
					sx=j;
					break;
				case '<':
					angle='l';
					sy=i;
					sx=j;
					break;
				default:
					break;
				}
			}
		}
		int num;
		cin>>num;
		string order;
		cin>>order;
		int cx=sx;
		int cy=sy;
		for(int j = 0; j < order.size(); j++){
			char o=order[j];
			if(o=='U'){
				angle='u';
				int ny=cy-1;
				int nx=cx;
				field[cy][cx]='^';
				if(ny>=0&&nx>=0&&ny<h&&nx<w){
					if(field[ny][nx]=='.'){
						field[cy][cx]='.';
						cy=ny;
						cx=nx;
						field[cy][cx]='^';
					}
				}
			}
			else if(o=='D'){
				angle='d';
				int ny=cy+1;
				int nx=cx;
				field[cy][cx]='v';
				if(ny>=0&&nx>=0&&ny<h&&nx<w){
					if(field[ny][nx]=='.'){
						field[cy][cx]='.';
						cy=ny;
						cx=nx;
						field[cy][cx]='v';
					}
				}
			}
			else if(o=='L'){
				angle='l';
				int ny=cy;
				int nx=cx-1;
				field[cy][cx]='<';
				if(ny>=0&&nx>=0&&ny<h&&nx<w){
					if(field[ny][nx]=='.'){
						field[cy][cx]='.';
						cy=ny;
						cx=nx;
						field[cy][cx]='<';
					}
				}
			}
			else if(o=='R'){
				angle='r';
				int ny=cy;
				int nx=cx+1;
				field[cy][cx]='>';
				if(ny>=0&&nx>=0&&ny<h&&nx<w){
					if(field[ny][nx]=='.'){
						field[cy][cx]='.';
						cy=ny;
						cx=nx;
						field[cy][cx]='>';
					}
				}
			}
			else if(o=='S'){
				if(angle=='r'){
					for(int i = cx+1; i < w; i++){
						if(field[cy][i]=='#')
							break;
						else if(field[cy][i]=='*'){
							field[cy][i]='.';
							break;
						}
					}
				}
				else if(angle=='l'){
					for(int i = cx-1; i >= 0; i--){
						if(field[cy][i]=='#')
							break;
						else if(field[cy][i]=='*'){
							field[cy][i]='.';
							break;
						}
					}
				}
				else if(angle=='u'){
					for(int i = cy-1; i >= 0; i--){
						if(field[i][cx]=='#')
							break;
						else if(field[i][cx]=='*'){
							field[i][cx]='.';
							break;
						}
					}
				}
				else if(angle=='d'){
					for(int i = cy+1; i < h; i++){
						if(field[i][cx]=='#')
							break;
						else if(field[i][cx]=='*'){
							field[i][cx]='.';
							break;
						}
					}
				}
			}
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cout<<field[i][j];
			}
			cout<<endl;
		}
	}

	return 0;
}

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library
//

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int x; cin >> x;
    int ans = 1;
    for(int i = 2; i * i < x; ++i){
        int tmp = 1;
        for(int j = 0; j < 11; ++j){
            if(tmp * i <= x){
                tmp *= i;
            }
            else{
                break;
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n){cin >> h[i];}
  
  int niceView = 1; //西端は常に見られる
  int maxHeight = h.at(0);
  for(int i=1;i<n;i++){
    if(maxHeight <= h.at(i)){
      maxHeight = h.at(i);
      niceView++;
    }
  }
  cout << niceView << endl;
}

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

int main()
{
    int H, W, D;
    int y[99999], x[99999];
    int sum[99999] = {};

    cin >> H >> W >> D;
    for ( int i = 0; i < H; i++ ) {
        for ( int j = 0; j < W; j++ ) {
            int val;
            cin >> val;
            y[val - 1] = i, x[val - 1] = j;
        }
    }

    for ( int i = 0; i < D; i++ ) {
        for ( int j = i + D; j < H * W; j += D ) {
            sum[j] = sum[j - D] + abs(y[j] - y[j - D]) + abs(x[j] - x[j - D]);
        }
    }

    int Q;
    cin >> Q;
    for ( int p = 0; p < Q; p++ ) {
        int l, r;
        cin >> l >> r;
        cout << sum[r - 1] - sum[l - 1] << endl;
    }

    return ( 0 );
}


Measured memory_bytes: 2176
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    for(int i = 0;i < s.size();i++)
    {
        cout << "x";
    }
    cout << "\n";
    
    return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
abs = n.times.map { gets.split.map(&:to_i) }.sort!

ans = 0

abs.each do |a, b|
  if b >= m
    ans += a * m
    m = 0
  else
    ans += a * b
    m -= b
  end

  break if m == 0
end

puts ans


Measured memory_bytes: 12528
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<int, pii>
#define puu pair<ULL, ULL>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

LL a, b, c, d;
LL lcm(LL a, LL b) {
    return a/__gcd(a, b)*b;
}
int main() {
    cin >> a >> b >> c >> d;
    LL l = lcm(c, d);
    printf("%lld\n", b-a+1-(b/c-(a-1)/c)-(b/d-(a-1)/d)+(b/l-(a-1)/l));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

#include<math.h>
using namespace std;



main(){

  int n;
  double xa,ya,xb,yb;
  double ra,rb;
  int out ;
  cin >> n;

  for(int i=0;i<n;i++){
    
    cin >> xa >> ya >> ra >> xb>> yb>>rb;

    double d= sqrt( (xa-xb)*(xa-xb)+(ya-yb)*(ya-yb) );//
    
    if(d<fabs(ra-rb)){//
      out = 2;
      if(ra<rb)out= -2;
          }
    else if(d>(ra+rb))out = 0;//
    else out =1;//
    
    cout << out << endl;
    
  }


  return 0;
}

Measured memory_bytes: 0
import math
def get_div_list(num):
    if num == 1:
        return [1]
    else:
        div_list = []
        div_list.append(1)
        div_list.append(num)
        for i in range(2, math.floor(math.sqrt(num))+ 1):
            if num % i == 0:
                div_list.append(i)
                div_list.append(num // i)
        list(set(div_list))
        div_list.sort(reverse = True)
        return div_list
n = int(input())
a = [int(_) for _ in input().split()]
d = sorted(list(set(get_div_list(a[0])+get_div_list(a[1]))))[::-1]
for i in range(len(d)):
    cnt = 0
    for j in range(n):
        if a[j]%d[i]==0:cnt+=1
    if cnt >= n-1:
        print(d[i])
        break

Measured memory_bytes: 63984
<?php
/*
    Problem URL : http://agc002.contest.atcoder.jp/tasks/agc002_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%d %d", $a, $b);
// echo $a . " " . $b . PHP_EOL;

if ($a <= 0 && $b >= 0) {
    echo "Zero\n";
}

if ($a > 0) {
    echo "Positive\n";
}

if ($b < 0) {
    // echo $b - $a . PHP_EOL;
    if (($b - $a) % 2 === 0)
    {
        echo "Negative\n";
    } else {
        echo "Positive\n";
    }
}


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

constexpr double EPS = 1e-10;
typedef complex<double> Point;
typedef Point Vector;
typedef pair<Point, Point> Segment;
typedef Segment Line;
typedef pair<Point, double> Circle;
typedef vector<Point> Polygon;
double dot(Vector a, Vector b){
	return real(a) * real(b) + imag(a) * imag(b);
}
double cross(Vector a, Vector b){
	return real(a) * imag(b) - imag(a) * real(b);
}
Point project(Line l, Point p){
	Vector base = l.second - l.first;
	base /= abs(base);
	double r = dot(p - l.first, base);
	return l.first + r * base;
}
Point reflect(Line l, Point p){
	return p + (project(l, p) - p) * 2.0;
}
int ccw(Point p0, Point p1, Point p2){
	Vector v = p1 - p0, w = p2 - p0;
	if(cross(v, w) > EPS) return 1; // COUNTER_CLOCKWISE
	if(cross(v, w) < -EPS) return -1; // CLOCKWISE
	if(dot(v, w) < -EPS) return 2; // ONLINE p2 - p0 - p1
	if(norm(v) + EPS < norm(w)) return -2; // ONLINE p0 - p1 - p2
	return 0; // ONLINE p0 - p1 - p2
}
bool isOrthogonal(Vector v1, Vector v2){
	double t = abs(dot(v1, v2));
	return t <= EPS;
}
bool isParallel(Vector v1, Vector v2){
	double t = abs(cross(v1, v2));
	return t <= EPS;
}
bool intersect(Segment s1, Segment s2){
	int t = ccw(s1.first, s1.second, s2.first) * ccw(s1.first, s1.second, s2.second);
	int u = ccw(s2.first, s2.second, s1.first) * ccw(s2.first, s2.second, s1.second);
	return (t == 0 || t == -1 || t == -4) && (u == 0 || u == -1 || u == -4);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin >> q;
	while(q--){
		double x[4], y[4];
		for(int i=0; i<4; ++i) cin >> x[i] >> y[i];
		Point p0(x[0], y[0]), p1(x[1], y[1]), p2(x[2], y[2]), p3(x[3], y[3]);
		if(intersect(Segment(p0, p1), Segment(p2, p3))) cout << 1 << "\n";
		else cout << 0 << "\n";
	}
}


Measured memory_bytes: 3356
#include <iostream>
#include <cstdio>

using namespace std;
int main(void){
    // Your code here!
   int n;
   int wkNum = 0;
   int maxNum = -1000000;
   int minNum = 1000000;
   long sumNum = 0;
   
   cin  >> n ;
   

	
   for (int i=0; i<n; i++) {
       cin >> wkNum;
       sumNum = sumNum + wkNum;
       
       if (wkNum > maxNum) {
          maxNum = wkNum;
       }
       
       if(wkNum < minNum){
          minNum = wkNum;
       }
   }
   printf("%d %d %lld\n", minNum, maxNum, sumNum);
   return 0;
}



Measured memory_bytes: 3224
#include <iostream>

using namespace std;

int main()
{
    int n, m=0, s=0;
    cin>>n;
    int v[n];
    for(int i=0; i<n; i++){
        cin>>v[i];
        if(v[i]>m)
            m=v[i];
        s+=v[i];
    }
    m/=2;
    s-=m;
    cout<<s;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define N	4000

int query(int a, int b) {
	static char s[2];

	printf("? %d %d\n", a, b), fflush(stdout);
	scanf("%s", s);
	return s[0] == 'Y';
}

int ds[N];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (ds[i] > ds[j])
		ds[i] = j;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
	}
}

int main() {
	static int qu[N];
	static char cc[N + 1];
	int n, a, b, i, cnt;

	scanf("%d%d", &a, &b), n = a + b;
	if (a <= b) {
		printf("Impossible\n");
		return 0;
	}
	memset(ds, -1, n * sizeof *ds);
	cnt = 0;
	for (i = 0; i < n; i++)
		if (cnt == 0)
			qu[cnt++] = i;
		else if (!query(qu[cnt - 1], i))
			cnt--;
		else {
			if (!query(i, qu[cnt - 1]))
				cc[find(qu[0])] = '0', cnt = 0;
			else
				join(qu[0], i);
			qu[cnt++] = i;
		}
	cc[find(qu[0])] = '1';
	for (i = 0; i < n; i++)
		if (ds[i] < 0 && !cc[i])
			cc[i] = query(qu[0], i) + '0';
	for (i = 0; i < n; i++)
		cc[i] = cc[find(i)];
	printf("! %s\n", cc);
	return 0;
}


Measured memory_bytes: 3784