akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	static class Node {
		int id = -1;
		Node p = NIL;
		Node lc = NIL;
		Node rs = NIL;
		int depth = -1;
	}
	static Node NIL = new Node();
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		Node[] tree = new Node[n];
		for (int i = 0; i < n; i ++) {
			tree[i] = new Node();
		}

		for (int i = 0; i < n; i ++) {
			int id = scanner.nextInt();
			Node u = tree[id];
			u.id = id;
			
			int k = scanner.nextInt();
			if (k == 0) continue;
			
			Node v =  tree[scanner.nextInt()];
			u.lc = v;
			v.p = u;
			for (int j = 1; j < k; j ++) {
				Node w = tree[scanner.nextInt()];
				v.rs = w;
				w.p = u;
				v = w;
			}
		}

		scanner.close();
		
		for (Node u: tree) {
			System.out.print("node ");
			System.out.print(u.id);
			System.out.print(": parent = ");
			System.out.print(u.p.id);
			System.out.print(", depth = ");
			System.out.print(getDepth(u));
			System.out.print(", ");
			System.out.print((u.p == NIL) ? "root": ((u.lc != NIL) ? "internal node": "leaf"));
			System.out.print(", [");
			printChildren(u);
			System.out.println("]");
		}
	}
	
	static int getDepth(Node u) {
		u.depth = (u.p != NIL) ? ((u.p.depth != - 1) ? u.p.depth + 1: getDepth(u.p) + 1): 0;
		return u.depth;
	}
	
	static void printChildren(Node u) {
		if (u.lc == NIL) return;
		
		System.out.print(u.lc.id);
		for (Node v = u.lc.rs; v != NIL; v = v.rs) {
			System.out.print(", " + v.id);
		}
	}
} 



Measured memory_bytes: 141572
N, M = map(int, input().split())
energy = [[int(_) for _ in input().split()] for _ in range(N)]
energy.sort(key=lambda x: x[0])
Res = 0

for i in energy:
    if M - i[1] > 0:
        M -= i[1]
        Res += i[0] * i[1]
    elif M == i[1]:
        Res += i[0] * i[1]
        break
    else:
        Res += i[0] * M
        break

print(Res)

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

template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
int dp[1234567][3];


int main(){
  string s;cin>>s;
  while(s.back()=='0')s.pop_back();
  int n=s.size();
  dp[0][1]=1,dp[0][2]=1e9;
  for(int i=0;i<n;i++){
    int a=s[i]-'0';
    dp[i+1][0]=dp[i][0]+a;
    dp[i+1][1]=min({dp[i][0]+a+1,dp[i][1]+9-a,dp[i][2]+a+1});
    dp[i+1][2]=min({dp[i][1]+10-a,dp[i][1]+a+1,dp[i][2]+a});
  }
  cout<<min({dp[n][0],dp[n][1]+1,dp[n][2]})<<endl;
}


Measured memory_bytes: 13572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  //map<string,int> s;
  //map<string,int> s{};
  //string res;
  vector<int> a;
  cin >> n >> m;
  int tmp,res;
  res = 0;
  for(int i = 0;i < m; i++){
    cin >> tmp;
    res += tmp;
    
  }
  //cout << res << " " << n << endl;
  if (res > n){
    cout << -1;
  }else{
    cout << n-res;
  }
}

Measured memory_bytes: 3636
macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };

    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

fn main() {
    let (a, b, c) = scan!(String, String, String);
    if a.chars().last() == b.chars().next() && b.chars().last() == c.chars().next() {
        println!("YES")
    } else {
        println!("NO")
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


int acc[1024][1001];


int main()
{
	while (1)
	{
		int H, W;
		
		cin >> H >> W;
		if (!H && !W) break;
		rep(i, W) acc[0][i] = 0;
		rep(i, H)
		{
			string line;
			cin >> line;
			rep(c, W)
			{
				if (i > 0) acc[i][c] = acc[i - 1][c];
				if (line[c] == '*') acc[i][c] = 0;
				else acc[i][c]++;
			}
		}
		int ans = 0;
		rep(r, H)
		{
			acc[r][W] = 0;
			stack<pair<int, int> > stk;
			for (int c=0; c<=W; c++)
			{
				int len = 0;
				const int cur = acc[r][c];
				while (!stk.empty() && stk.top().first >= cur)
				{
					len += stk.top().second;
					const int area = len * stk.top().first;
					ans = max(ans, area);
					stk.pop();
				}
				len++;
				stk.push(mp(cur, len));
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

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

using namespace std;

const long long MOD = 1000000007;
const long long MAX = 2000000;
long long gcd(long long a, long long b) {
    return b != 0 ? gcd(b, a % b) : a;
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
long long extgcd(long long a, long long b, long long &x, long long &y) {
    long long g = a; x = 1; y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}

int main() {
    long long a,b;
    cin>>a>>b;
    cout<<lcm(a,b)<<endl;








}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin >> n;
    ll a[n];
    F0R(i,n) cin >> a[i];
    ll l[n],r[n];
    ll lk = 0;
    ll rk = 0;
    F0R(i,n){
      l[i] = __gcd(a[i],lk);
      lk = l[i];
      r[n-1-i] = __gcd(a[n-1-i],rk);
      rk = r[n-1-i];
    }
    ll ans = 1;
    F0R(i,n){
      if(i == 0){
        if(ans < r[1])
          ans =r[1];
      }
      else if(i == n-1){
        if(ans < l[n-2])
          ans = l[n-2];
      }
      else {
        if(ans < __gcd(l[i-1],r[i+1]))
          ans = __gcd(l[i-1],r[i+1]);
      }
    }

    cout << ans << endl;


    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  rep(i, n) std::cin >> a[i];

  int current = 0;
  rep(i, n) {
    current = a[current] - 1;
    if (current == 1) {
      std::cout << i + 1 << std::endl;
      return 0;
    }
  }

  std::cout << -1 << std::endl;
  return 0;
}


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

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

  vector<int> a(N);
  rep(i,0,N-1) cin >> a[i];

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

  if (a[N-1] == 0)
    cout << "Yes" << endl;
  else if (N % 3 == 0)
  {
    if (a[0] == 0 && a[N / 3 - 1] == 0 && a[N / 3] == a[N - 1])
      cout << "Yes" << endl;
    else if (a[0] == a[N / 3 - 1] && a[N / 3] == a[2 * N / 3 - 1] && a[2 * N / 3] == a[N - 1] && (a[0] ^ a[N / 3] ^ a[2 * N / 3]) == 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3784
# coding: utf-8
# Your code here!
N=int(input())

ans=0
if N%2==0:
    for i in range(18):
        ans+=N//(10*10**i)
    for i in range(100):
        for j in range(100):
            ans+=N//(50*5**i*10**j)-N//(100*5**i*10**j)
    print(ans)
    
    
else:
    print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }

    ll a;
    string b;
    cin >> a >> b;

    string bintstr = b.substr(0, b.find('.'));
    ll bint = stoll(bintstr);

    ll ans = a*bint;

    string bdecstr = b.substr(b.find('.')+1);
    ll bdec = stoll(bdecstr);

    ans += a*bdec/100LL;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3668
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n;
  cin >> n;
  pair<ll,ll> x[n];
  ll temp1,temp2;
  for(int i=0;i<n;i++){
    cin >> temp1 >> temp2;
    x[i] = make_pair(temp1+temp2,temp1-temp2);
  }
  sort(x,x+n);
  ll ans = 1;
  ll ref = x[0].first;
  for(int i=1;i<n;i++){
    if(ref <= x[i].second){
      ref = x[i].first;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
n=int(input())
p=list(map(int, input().split()))
i=0
ans=1
flag=0
k=1e18
while(n>i):
	if(p[i]==0):
		flag=1
	i+=1
if(flag==1):
	print(0)
else:
	flag=0
	i=0			
	while(n>i):
		ans*=p[i]
		if(ans>k):
			flag=1
			break
		i+=1		
	if( flag==1):
		print(-1)
	else:
		print(ans)
		


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000


typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int N = 23;
const int MAX = (1 << 21);
const int MOD = 1e9+7;

int n;
int dp[MAX][N];

bool arr[N][N];

int solve(int pairs, int idx){
	if(idx == n && pairs != (1 << n)-1)
		return 0;
	if(idx == n){
	    return 1;
	}
	int & cur = dp[pairs][idx];
	if(~cur)
		return cur;
	cur = 0;
	lp(i, n)
	    if(arr[idx][i] && ((pairs & (1 << i)) == 0))
	        (cur += solve(pairs | (1 << i), idx+1)) %= MOD;
	return cur = cur % MOD;
}

int main()
{
	clr(dp, -1);
    cin >> n;
    lp(i, n)
        lp(j, n)
    	    cin >> arr[i][j];
    cout << solve(0, 0);
    return 0;
}

Measured memory_bytes: 188672
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>

using namespace std;

using ll = long long;

int main()
{
    int N;
    cin >> N;
    vector<ll> v(N + 2, 0);
    for (int i = 1; i <= N; i++) {
        scanf("%lld", &v[i]);
    }
    int res = 0;
    map<ll, int> mp; mp[0] = 0;
    for (int i = 1; i <= N; i++) {
        v[i] += v[i - 1];
        if (!mp.count(v[i])) {
            mp[v[i]] = i;
        } else {
            res = max(res, i - mp[v[i]]);
        }
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 16804
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void Solver(int A,int B,int C)
    {
        int sevenCount = 0;
        int fiveCount = 0;
        if(A == 5)
            fiveCount++;
        if(B == 5)
            fiveCount++;
        if(C == 5)
            fiveCount++;
        if(A == 7)
            sevenCount++;
        if(B == 7)
            sevenCount++;
        if(C == 7)
            sevenCount++;

        if(fiveCount == 2 && sevenCount == 1)
            System.out.println("YES");
        else
            System.out.println("NO");

    }
    public static void main(String[] args) throws IOException {
        Scanner input = new Scanner(System.in);

        Solver(input.nextInt(),input.nextInt(),input.nextInt());
    }
}


Measured memory_bytes: 21332
# ソートかけてどちらも同じだとYES

c1 = list(input())
c2 = list(input())

# print(c1)
# print(c2)

c1_str = ''.join(c1)
# c2_str = ''.join(c2)

c2_str_reverse = c2[2] + c2[1] + c2[0]

if c1_str == c2_str_reverse:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 9024
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

int vs[100];
int cs[100];

int main(void) {
  int n;
  cin >> n;
  REP(i, n) {
    cin >> vs[i];
  }
  REP(i, n) {
    cin >> cs[i];
  }
  int res = 0;
  REP(i, n) {
    if(vs[i] - cs[i] > 0) {
      res += vs[i] - cs[i];
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
N = int(input())
A = [*map(int, input().split())]

for i in range(N):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
// const ll m=1LL<<32;

int main(){

  ll n,m;
  while(cin>>n>>m){
    if(n==m&&m==0)break;
    ll c[m];rep(i,0,m)cin>>c[i];
    ll x[n];rep(i,0,n)cin>>x[i];
    ll dp[n+1][256];
    rep(i,0,n+1)rep(j,0,256)dp[i][j]=INF;
    dp[0][128]=0;
    rep(i,1,n+1){
      rep(j,0,m){
        rep(k,0,256){
          if(dp[i-1][k]!=INF){
            ll p=k+c[j];
            if(p<0)p=0;
            if(p>255)p=255;
            ll num=abs(p-x[i-1]);
            chmin(dp[i][p],dp[i-1][k]+num*num);
          }
        }
      }
    }
    ll ans=INF;
    rep(i,0,256){
      chmin(ans,dp[n][i]);
    }

    out(ans);
  }




  return 0;
}



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

using namespace std;

int n, ans[10050], v;

int main() {
    cin >> n;

    for (int i = 1; i <= 105; ++i)
        for (int j = 1; j <= 105; ++j)
            for (int k = 1; k <= 105; ++k) {
                v = i*i + j*j + k*k + i*j + j*k + k*i;

                if (v < 10050)
                    ++ans[v];
            }

    for (int i = 1; i <= n; ++i)
        cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3592
#
#    ------------------------------------------------
#           ____          _     Generatered using
#          / ___|        | |
#         | |    __ _  __| | ___ _ __  ______ _
#         | |   / _` |/ _` |/ _ \ '_ \|_  / _` |
#         | |__| (_| | (_| |  __/ | | |/ / (_| |
#          \____\____|\____|\___|_| |_/___\____|
#
#      GNU Affero General Public License v3.0
#    ------------------------------------------------
#    Author   : prophet
#    Created  : 2020-07-05 22:26:03.150631
#    UUID     : SX0X0QCtQizbJCbK
#    ------------------------------------------------
#
production = True

import sys, math, collections

def input(input_format = 0, multi = 0):

    if multi > 0: return [input(input_format) for i in range(multi)]
    else:
        next_line = sys.stdin.readline()[:-1]

        if input_format >= 10:
            use_list = False
            input_format = int(str(input_format)[-1])
        else: use_list = True

        if input_format == 0: formatted_input = [next_line]
        elif input_format == 1: formatted_input = list(map(int, next_line.split()))
        elif input_format == 2: formatted_input = list(map(float, next_line.split()))
        elif input_format == 3: formatted_input = list(next_line)
        elif input_format == 4: formatted_input = list(map(int, list(next_line)))
        elif input_format == 5: formatted_input = next_line.split()
        else: formatted_input = [next_line]

        return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format = 0, newline = True):

    formatted_output = ""

    if output_format == 0: formatted_output = str(output_line)
    elif output_format == 1: formatted_output = " ".join(map(str, output_line))
    elif output_format == 2: formatted_output = "\n".join(map(str, output_line))

    print(formatted_output, end = "\n" if newline else "")

def log(*args):
    if not production:
        print("$$$", end = "")
        print(*args)

enu = enumerate

ter = lambda a, b, c: b if a else c

def mapl(iterable, format = 0):
    
    if format == 0: return list(map(int, iterable))
    elif format == 1: return list(map(str, iterable))
    elif format == 2: return list(map(list, iterable))
#
#   >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#


def solve():

    n = input(11)

    b = math.ceil((n) / 1000) * 1000

    log(b)
    out(b - n)
    return


#for i in range(input(11)): solve()
solve()

#
#   >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#


Measured memory_bytes: 65520
while(True):
    n,x = [int(i) for i in input().split()]
    if(n == 0 and x == 0):
        break
    t = 0
    for i in range(1,n + 1):
        for j in range(1,n + 1):
            for k in range(1,n + 1):
                if(i < j < k and i + j + k == x):
                    t += 1
    print(t)

Measured memory_bytes: 7716
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}

// map<ll, list<ll>> m;
map<ll, ll> m;

bool isPrime(ll n) {
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;

        }
    }
    return true;
}

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    // cin >> t;
    while(t--) {
        ll x, q;
        cin >> x;
        string s="";
        while(x) {
            if(x%26==0) {
                q=26;
                x--;
            }
            else {
                q=x%26;
            }
            s+=(char)((q)+'a'-1);
            x/=26;
        }
        reverse(s.begin(), s.end());
        cout << s << endl;
    }
}


Measured memory_bytes: 3072
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#define MAX 110

void initialize(void);
int isEmpty(void);
int isFull(void);
void push(int);
int pop(void);

int s[MAX];
int top;

int main(){
  char c[100];
  int a,b;
  
  while(scanf("%s",c)!=EOF){
    
    if(c[0] == '+'||c[0] == '*'||c[0] == '-'){
      a = pop();
      b = pop();
      
      switch(c[0]){
      case '+':
	push(a+b);
	break;
      case '-':
	push(b-a);
	break;
      case '*':
	push(a*b);
	break;
      default :
	break;
      }
    }else{
      push(atoi(c));
    }
  }

  printf("%d\n",s[top]);
  return 0;
}

void initialize(){
  top = 0;
}
int isEmpty(){
  if(top == 0) return 1;
  return 0;
}
int isFull(){
  if(top >= MAX - 1) return 1;
  return 0;
}
void push(int x){
  if(isFull()){
    printf("stack overflow!");
    exit(1);
  }
  top++;
  s[top] = x;
}
int pop(){
  if(isEmpty()){
    printf("stack underflow!");
    exit(2);
  }
  top--;
  return s[top+1];
}

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

int main()
{
  	int i,n;
  	double sum = 0.0,mx = 0.0;;
  
 	cin >> n;
  	
  	vector<int> x(n),y(n);
    vector<double> m(n);
  
  	for(i = 0;i < n;i++)
      cin >> x.at(i);
  	for(i = 0;i < n;i++)
      cin >> y.at(i);
  
  	for(i = 0;i < n;i++){
      m.at(i) = abs(x.at(i) - y.at(i));
      sum += m.at(i);
      mx = max(mx,m.at(i));
    }
  	cout << fixed << setprecision(8) << sum << endl;
  
    sum = 0.0;
  	for(i = 0;i < n;i++)
      sum += pow(m.at(i),2.0);
  
  	cout << fixed << setprecision(8) << sqrt(sum) << endl;
  
    sum = 0.0;
  	for(i = 0;i < n;i++)
      sum += pow(m.at(i),3.0);
  
  	cout << fixed << setprecision(8) << cbrt(sum) << endl;
  
  	cout << fixed << setprecision(8) << mx << endl;


}


Measured memory_bytes: 3492
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int ara[n];
    for(int i=0;i<n;i++){
        scanf("%d",&ara[i]);
            }
    double d=0;
    for(int k=0;k<n;k++){
        d=(double)(d+(double) 1/ara[k]);
    }
    d=(double)1/d;
    printf("%lf\n",d);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    if(K == 1){cout << N*N*N << endl;return 0;}
    if(K % 2 == 1){
        N /= K;
        cout << N*N*N << endl;
        return 0;
    }
    else{
        ll A = K/2;
        ll cnt = N,B;
      	B = N / A;
      	B = (B + 1) / 2;
        N /= K;
        cout << B*B*B+N*N*N << endl;
    }
}

Measured memory_bytes: 256
def main():
    N = int(input())
    D, X = map(int, input().split())
    A = []
    for _ in range(N):
        A.append(int(input()))
    count = X
    for i in range(N):
        count += (D-1)//A[i] + 1
    return count

if __name__ == '__main__':
    print(main())


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

//#define int int64_t

//#define CHOOSE(a) CHOOSE2 a
//#define CHOOSE2(a0,a1,a2,a3,x,...) x
//#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
//#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
//#define REP3(i, n) REP2(i, 0, n)
//#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)

#define rep(i, n) for(int i = 0; i < n; i++)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

//using VV = vector<vector<int>>;
//using V = vector<int>;
//using P = pair<int, int>;
//using IP = pair<int, P>;

typedef complex<double> P;
typedef vector<P> L;
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
bool operator == (const L& a, const L& b) {
	if (a.size() != b.size()) return false;
	rep(i, a.size()) if (a[i] != b[i]) return false;
	return true;
}
P rs[] = { P(1, 0), P(0, 1), P(-1, 0), P(0, -1) };
L rotate(L line, int idx) {
	L ret = line;
	for (auto& x : ret) {
		x *= rs[idx];
	}
	return ret;
};
L move(L line) {
	P sub = *min_element(all(line));
	L ret = line;
	for (auto& x : ret) {
		x -= sub;
	}
	return ret;
};
L input() {
	int m; cin >> m;
	L l(m);
	rep(i, m) {
		int x, y; cin >> x >> y;
		l[i] = P(y, x);
	}
	return l;
};
bool equal(L l1, L l2) {
	L l22 = l2;
	reverse(all(l22));
	rep(i, 4) {
		if (move(l1) == move(rotate(l2, i)) || move(l1) == move(rotate(l22, i))) return true;
	}
	return false;
};

signed main() {
	int n;
	while (cin >> n && n) {
		vector<L> lines(n - 1);
		L line;

		line = input();
		stringstream ss;
		rep(i, n) {
			if (equal(line, input())) {
				ss << i + 1 << endl;
			}
		}
		ss << "+++++" << endl;
		cout << ss.str();
	}
}

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

int main(int argc, char const *argv[]) {

    for (int i = 0; i < 50; i++) {
        int m, f, r;
        char grade;
        cin >> m >> f >> r;

        if (m == -1 && f == -1 && r == -1) {
            break;
        } else {
            if (m == -1 || f == -1) {
                grade = 'F';
            } else if (m + f >= 80) {
                grade = 'A';
            } else if (65 <= m + f && m + f < 80) {
                grade = 'B';
            } else if (50 <= m + f && m + f < 65) {
                grade = 'C';
            } else if (30 <= m + f && m + f < 50) {
                if (r >= 50) {
                    grade = 'C';
                } else {
                    grade = 'D';
                }
            } else {
                grade = 'F';
            }
            cout << grade <<endl;
        }    
    }
    return 0;
}



Measured memory_bytes: 3084
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll K, S, ANS=0;
    scanf("%lld %lld", &K, &S);
    rep(x, 0, K+1){
        rep(y, 0, K+1){
            ll z = S -x-y;
            if(z>=0 && z<=K) ANS++;
        }
    }
    printf("%lld\n", ANS);
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, D;
    scanf("%d %d", &N, &D);
    int X[N][D];
    REP(int, j, 0, N){
        REP(int, i, 0, D) scanf("%d", &X[j][i]);
    }
    int ans = 0;
    int Dis1, Dis2;
    REP(int, k, 0, N-1){
        REP(int, j, k+1, N){
            Dis1 = 0;
            REP(int, i, 0, D){
                Dis1 += (X[k][i]-X[j][i]) * (X[k][i]-X[j][i]);
            }
            Dis2 = sqrt(Dis1);
            if ( Dis1 == Dis2 * Dis2 ) ans += 1;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
# -*- utf8 -*-

arg = gets.chomp

arg = arg.split(" ")

k = arg[0].to_i
s = arg[1].to_i

numPettern = 0

if k*3 == s
    puts 1
    exit
end

(0..k).each do |x|
    if x + k + k < s
        next
    end
    if x == s
        numPettern+=1
        next
    end
    (0..k).each do |y|
        if x+y+k < s
            # p "break"
            next
        end
        if x+y > s
            break
        end
        if x+y == s
            numPettern+=1
            break
        end
        z = s - x - y
        # print x.to_s + "+" + y.to_s + "+" + z.to_s + " = " + (x+y+z).to_s
        if z <= s
            numPettern+=1
            # print "  OK\n"
        end
        # (0..k).each do |z|
        #     if x+y+z > s
        #         break
        #     end
        #     print x.to_s + "+" + y.to_s + "+" + z.to_s + " = " + (x+y+z).to_s
        #     if x + y + z == s
        #       numPettern+=1
        #       print " OK!!"
        #       break
        #     end
        #     print "\n"
        # end
    end
end

puts numPettern

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

using namespace std;

const int MAX_N = 1e4;  
const int MAX_M = 9;  

struct mynum {
    int x[MAX_M + 1] = {};
    bool ok = false;
};

int N, M;
int a[MAX_M + 1];
int match[] = {0,2,5,5,4,5,6,3,7,6};
mynum dp[MAX_N + 1]; // dp[j]はj本のマッチで作れる最大値

bool comp_num(mynum a, mynum b){
    int suma = accumulate(begin(a.x) , end(a.x), 0);
    int sumb = accumulate(begin(b.x) , end(b.x), 0);

    if(suma < sumb){
        return true;
    } else if(suma > sumb){
        return false;
    } else{
        for(int i=9; i>=1; i--){
            if(a.x[i] < b.x[i]) return true;
            if(a.x[i] > b.x[i]) return false;
        }
        return false;
    }
}

void print_num(mynum a) {
    for(int i=9; i>=1; i--){
        for(int j=0; j<a.x[i]; j++){
            cout << i;
        }
    }
    cout << endl;
}

int main()
{

    cin >> N >> M;
    for(int i=0; i<M; i++) cin >> a[i];
    dp[0].ok = true;
    for(int i=0; i<M; i++){
        int num = a[i];
        int w = match[num];
        for(int j=0; j<=N; j++){
            for(int k=1; w*k <= j; k++){
                if(dp[j - w*k].ok){
                    mynum temp = dp[j - w*k];
                    temp.x[num] += k;
                    if(comp_num(dp[j] ,temp)) dp[j] = temp;
                }
            }
        }
    }



    print_num(dp[N]);    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define fi first
#define se second
#define SET(p,k) memset(p, k, sizeof(p));
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

int x, y;
string s;
bool t = 1;
bitset<16005> dpx[8005][2], dpy[8005][2];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
 
	cin >> s >> x >> y;

    x += 8001;
    y += 8001;

    dpx[0][1][8001] = 1;

    dpy[0][0][8001] = 1;
    dpy[0][1][8001] = 1;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'T') {
            t = !t;

            for (int j = 1; j <= 16002; j++) {
                dpx[i+1][0][j] = dpx[i+1][1][j] = (dpx[i][1][j] || dpx[i][0][j]);
                dpy[i+1][0][j] = dpy[i+1][1][j] = (dpy[i][1][j] || dpy[i][0][j]);
            }

            continue;
        }

        for (int j = 1; j <= 16002; j++) {
            if (t) {
                dpx[i+1][0][j] = dpx[i][0][j+1];
                dpx[i+1][1][j] = dpx[i][1][j-1];

                dpy[i+1][0][j] = dpy[i][0][j];
                dpy[i+1][1][j] = dpy[i][1][j];
            } else {
                dpx[i+1][0][j] = dpx[i][0][j];
                dpx[i+1][1][j] = dpx[i][1][j];

                dpy[i+1][0][j] = dpy[i][0][j+1];
                dpy[i+1][1][j] = dpy[i][1][j-1];
            }
        }
    }

    if ((dpx[s.size()][0][x] || dpx[s.size()][1][x]) && 
        (dpy[s.size()][0][y] || dpy[s.size()][1][y]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 63104
s = int(input())
x = [0,10**9]
y = [0,1]
tmp = 10**9
x3 = 0
if s % tmp != 0:
    x3 = tmp - (s % tmp)

y3 = (s + x3) // tmp

print(0,0,10**9,1,x3,y3)


Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 200005
#define FH 400005
#define inf INT32_MAX
#define MOD 1000000007LL

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;


inline void solve()
{
	int n, m;
	cin >> n >> m;
	vector<pr> arr(n);
	fore(i, 0, n)
		cin >> arr[i].first >> arr[i].second;
	sort(arr.begin(), arr.end());
	int j = 0;
	int otv = 0;
	priority_queue<pr> q;
	fr(i, m, 0)
	{
		while (j < n && arr[j].first == m - i)
		{
			q.push({ arr[j].second, arr[j].first });
			j++;
		}
		if (q.size())
		{
			otv += q.top().first;
			q.pop();
		}
	}
	cout << otv;
}



int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}

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

using namespace std;

using lint = long long;
using ldouble = long double;

vector<int> W;
vector<vector<int>> dp;

bool rec(int L, int R) {
    auto& ret = dp[L][R];
    if (ret >= 0) return ret;

    if (L == R) return ret = 1;
    if ((R - L) & 1) return ret = 0;

    for (int i = L + 1; i < R; i += 2) {
        if (abs(W[L] - W[i]) > 1) continue;
        if (rec(L + 1, i) && rec(i + 1, R)) return ret = 1;
    }
    return ret = 0;
}

bool solve() {
    int N;
    cin >> N;
    if (N == 0) return false;

    W.resize(N);
    for (auto& w : W) cin >> w;

    dp = vector<vector<int>>(N + 1, vector<int>(N + 1, -1));

    vector<int> ans(N + 1, 0);
    for (int i = 0; i < N; ++i) {
        ans[i + 1] = max(ans[i], ans[i + 1]);
        for (int len = 2; i + len <= N; ++len) {
            if (rec(i, i + len)) {
                ans[i + len] = max(ans[i + len], ans[i] + len);
            }
        }
    }

    cout << ans[N] << endl;
    return true;
}

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



Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <climits>
using namespace std;

#define MIN(X,Y) (((X)>(Y))?(Y):(X))

int main () {
	int N, tmp;
	vector <int> v;
	cin >> N;
	v.push_back (INT_MAX);
	for (int i=0; i<N-1; i++) {
		cin >> tmp;
		v.push_back (tmp);
	}
	v.push_back (INT_MAX);
	int ans = 0;
	for (int i=0; i<N; i++)
		ans += MIN (v.at(i), v.at(i+1));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int N,A,B,C,D,check=0;
  cin >> N >> A >> B >> C >> D;
  A--,B--,C--,D--;
  string S;
  cin >> S;
  for(int i=A;i<D;i++) if(i+1<N && S[i]=='#' && S[i+1]=='#') check=1;
  if(C>D){
    int check2=0;
    for(int i=B-1;i<D;i++) if(S[i]=='.' && S[i+1]=='.' && S[i+2]=='.' && i+2<N) check2=1;
    if(check2==0) check=1;
  }
  if(check==1) cout << "No" << endl;
  else cout << "Yes" << endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << endl;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, pair<vector<T>&, int> v) {
	while (v.second--) {
		T a;
		v.first.push_back(is >> a, a);
	}
	return (is);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

int N, M;
int dp[305][305][305] = {}; // i masume 2 tsu noiro no idx
vector<Pi> v[305];
int main() {
	cin >> N >> M;

	dp[0][0][0] = 1;
	for (int i = 0; i < M; i++) {
		int l, r, x;
		cin >> l >> r >> x;
		v[r].emplace_back(l, x);
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= N; k++) {
				int li[3][3] = {{i+1, j, k}, {i+1, i, k}, {i+1, i, j}};
				for (int l = 0; l < 3; l++) {
					bool flag = true;
					for (auto &u : v[i+1]) {
						int cnt = 0;
						for (int m = 0; m < 3; m++) {
							cnt += (int)(u.first <= li[l][m]);
						}
						flag &= cnt == u.second;
					}
					if (flag) (dp[li[l][0]][li[l][1]][li[l][2]] += dp[i][j][k]) %= mod;
				}
			}
		}
	}
	ll sum = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			(sum += dp[N][i][j]) %= mod;
		}
	}
	cout << sum << endl;
	return (0);
}

Measured memory_bytes: 110464
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    rep(i, 0, 5)
    {
        int a;
        cin >> a;
        if (a == 0)
            cout << i + 1;
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)

string putstr(int cnt, char c) {
    string res = "";
    rep(i, cnt) res += c;
    return res;
}

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

    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx, dy = ty - sy;
    cout << putstr(dy, 'U') << putstr(dx, 'R') << putstr(dy, 'D') << putstr(dx, 'L');
    cout << 'L';
    cout << putstr(dy + 1, 'U') << putstr(dx + 1, 'R');
    cout << 'D' << 'R';
    cout << putstr(dy + 1, 'D') << putstr(dx + 1, 'L');
    cout << 'U' << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;

ll N, K;
ll A[2000];
ll th[2000];
ll th_right[2000];
ll ans=0;
ll mod = 1000000007;

int main()
{
    cin>>N>>K;
    rep(i, N) cin>>A[i];
    rep(i, N){
        rep(j, N){
            if(A[i]>A[j]){
                th[i]++;
                if(i<j) th_right[i]++;
            }
        }
    }
    rep(i, N){
        // cout<<th[i]<<" "<<th_right[i]<<endl;
        ans += (th_right[i] * K) % mod;
        ans %= mod;
        ans += (th[i] * (((K * (K-1)) / 2) % mod)) % mod;
        ans %= mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
S=list(input())
N=len(S)
ans=[0 for i in range(N)]
a=1
s=1
for i in range(1,N):
  if S[i-1]=="R" and S[i]=="L":
    f=i
  if S[i-1]=="L" and S[i]=="R" or i==N-1:
    if i==N-1:
      a+=1
    if (a)%2==0:
      ans[f-1] = a//2
      ans[f]   = a//2
    else:
      if (f-s)%2==0:
        ans[f-1] = a//2+1
        ans[f]   = a//2
      else:
        ans[f-1] = a//2
        ans[f]   = a//2+1 
    a=0
    s=i+1
  a+=1
    
for i in range(N):
  print(ans[i],end=" ")

    
  

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

using namespace std;

//#define local
#ifdef local

template<class T>
void _E(T x) { cerr << x; }

void _E(double x) { cerr << fixed << setprecision(6) << x; }

void _E(string s) { cerr << "\"" << s << "\""; }

template<class A, class B>
void _E(pair<A, B> x) {
    cerr << '(';
    _E(x.first);
    cerr << ", ";
    _E(x.second);
    cerr << ")";
}

template<class T>
void _E(vector<T> x) {
    cerr << "[";
    for (auto it = x.begin(); it != x.end(); ++it) {
        if (it != x.begin()) cerr << ", ";
        _E(*it);
    }
    cerr << "]";
}

void ERR() {}

template<class A, class... B>
void ERR(A x, B... y) {
    _E(x);
    cerr << (sizeof...(y) ? ", " : " ");
    ERR(y...);
}

#define debug(x...) do { cerr << "{ "#x" } -> { "; ERR(x); cerr << "}" << endl; } while(false)
#else
#define debug(...) 114514.1919810
#endif
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db long double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define endl "\n"
#define ls ch[now][0]
#define rs ch[now][1]
const ll mod = 998244353;
const ll maxn = 2e5 + 10;


ll qpow(ll a, ll b) {
    ll ret = 1;
    for (; b; a = a * a % mod, b >>= 1) {
        if (b & 1) {
            ret = ret * a % mod;
        }
    }
    return ret;
}

vector<ll> f(maxn), invf(maxn);

ll inv(ll a) {
    return qpow(a, mod - 2);
}

void prework() {
    f[0] = 1;
    _rep(i, 1, maxn - 1) {
        f[i] = f[i - 1] * i % mod;
    }
    invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
    for (ll i = maxn - 2; i >= 0; i--) {
        invf[i] = invf[i + 1] * (i + 1) % mod;
    }

}

ll C(ll n, ll m) {
    if (n > m || m < 0)return 0;
    if (n == 0 || m == n) return 1;
    ll res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
    return res;
}

vector<ll> G[maxn];


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    string s;
    cin >> n;
    cin >> s;
    

    s = '.' + s;
    vector<ll> prew(s.size() + 2), sufr(s.size() + 2);

    _rep(i, 1, n+1) {
        prew[i] = prew[i - 1] + (s[i] == 'W');
    }
    for (ll i = n; i >= 0; i--) {
        sufr[i] = sufr[i + 1] + (s[i] == 'R');
    }
    ll res = oo;
    debug(prew);
    debug(sufr);
    _rep(i, 0, n+1){
        ll needswap = min(prew[i], sufr[i+1]);
        res = min(res, needswap + (prew[i] - needswap + sufr[i+1] - needswap));
    }
    cout << res << endl;

}

Measured memory_bytes: 14384
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 void call(int n)
 {
   int i=1;
   do
   {
     int x=i;
     if(x%3==0) cout<<" "<<i;
     else
     {
       do
       {
         if(x%10==3)
         {
           cout<<" "<<i;
           break;
         }
         x/=10;         
       }while(x);    
     }    
   }while((++i)<=n);   
   cout<<endl; 
 }
 
 int main()
 {
   int n;
   cin>>n;
   call(n);
   //while(1);
   return 0;
 }
 

Measured memory_bytes: 3084
N,A,B = map(int, input().split())
dim = abs(B-A)

if dim % 2 == 0:
  print(int(dim//2))
elif dim % 2 == 1:
  dimAN = N - A
  dimBN = N - B
  dimB1 = B - 1
  dimA1 = A - 1
  
  result = min(dimA1,dimBN)+1+(dim-1) // 2
  print(result)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int max = a;
    if (max < b)max = b;
    if (max < c)max = c;
    printf("%d\n", a*b*c / max / 2);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (1 <= a && a <= 9 && 1 <= b && b <= 9)
        cout << a * b << '\n';
    else
        cout << "-1\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#define INF 1000
using namespace std;

int n,m,type[3];
vector<int> G[101];
vector<int> step[101][3];
bool used[101];
int dp[101];

void bfs(int v,int st){
	queue<int> que[151];
	que[0].push(v);
	for(int i=0;i<type[st];i++){
		memset(used,false,sizeof(used));
		while(que[i].size()){
			int now=que[i].front();
			que[i].pop();
			for(int j=0;j<G[now].size();j++){
				int nw=G[now][j];
				if(!used[nw]){
					used[nw]=true;
					que[i+1].push(nw);
				}
			}
		}
	}
	while(que[type[st]].size()){
		step[v][st].push_back(que[type[st]].front());
		que[type[st]].pop();
	}
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<3;i++){
		scanf("%d",&type[i]);
	}
	for(int i=0;i<m;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		G[f].push_back(t);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			bfs(i,j);
		}
	}
	for(int i=0;i<n;i++){
		dp[i]=INF;
	}
	dp[n-1]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int lr=0;
			for(int k=0;k<3;k++){
				int rr=INF;
				for(int l=0;l<step[j][k].size();l++){
					rr=min(rr,dp[step[j][k][l]]+1);
				}
				lr=max(lr,rr);
			}
			dp[j]=min(dp[j],lr);
		}
	}
	
	memset(used,false,sizeof(used));
	if(dp[0]>=INF)printf("IMPOSSIBLE\n");
	else printf("%d\n",dp[0]);
	return 0;
}

Measured memory_bytes: 2940