akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

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

    LL ans = 1333333333333333;

    for(int i = 0; i < n; i++){
        vector<LL> b;
        for(int j = 0; j < n; j++){
            if(a[j] >= a[i]){
                vector<LL> t;
                bool flag = true;
                for(; j < n; j++){
                    if(a[j] < a[i]){
                        sort(t.begin(),t.end());
                        for(int l = 0; k+l <= t.size(); l++){
                            b.push_back(t[l]);
                        }
                        
                        flag = false;
                        break;
                    }
                    t.push_back(a[j]);
                }
                if(flag){
                    sort(t.begin(),t.end());
                    for(int l = 0; k+l <= (int)t.size(); l++){
                        b.push_back(t[l]);
                    }
                }
            }
        }
        sort(b.begin(),b.end());
        if(b.size() >= q){
            ans = min(ans,b[q-1] - b[0]);
        }
    }
    

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

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

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

}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

struct team_data {
    int id;
    int solved;
    int time;
    map<int, int> wrong;
};

int main() {
    int M, T, P, R;
    while(cin >> M >> T >> P >> R, M) {
        vector<team_data> v(T);
        for(int i=0; i<v.size(); ++i) {
            v[i].id = i+1;
        }

        for(int i=0; i<R; ++i) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            if(j == 0) { // correct
                v[t-1].time += m + v[t-1].wrong[p];
                v[t-1].solved++;
            } else { // wrong
                v[t-1].wrong[p] += 20;
            }
        }
        sort(v.begin(), v.end(), [](auto const& t1, auto const& t2) {
            return t1.id > t2.id;
        });
        stable_sort(v.begin(), v.end(), [](auto const& t1, auto const& t2) {
            if(t1.solved == t2.solved) {
                return t1.time < t2.time;
            } else {
                return t1.solved > t2.solved;
            }
        });

        for(int i=0; i<v.size(); ++i) {
            cout << v[i].id;
            if(i != v.size()-1) {
                if(v[i].solved == v[i+1].solved && v[i].time == v[i+1].time) {
                    cout << '=';
                } else {
                    cout << ',';
                }
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3172
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    LL n;
    LL k;
    LL ans;
    cin >> n >> k;
    ans=n;
    if(n>k){
        ans=k;
        if(n%k==0){
            ans=0;
            n=k;
        }else{
            ans=n%k;
            n=n%k;
        }
    }

    //cout << ans << " " << k << " " << n << endl;
    if(ans>k-n){
        ans=k-n;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//#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;
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 n,m;cin>>n>>m;
  ll count=0;
  if(n%2==1){
    while(true){
      cout<<count+1<<" "<<n-1-count<<endl;
      count++;
      if(count==m)break;
    }
    return 0;
  }
  /*while(true){
    cout<<count+1<<" "<<n-1-count<<endl;
    count++;
    if(count==m)break;
  }*/
  ll k=n/2;
  ll i=0,j=0;
  while(true){
    cout<<i+1<<" "<<k-i<<endl;
    i++;
    if(i+j==m)break;
    cout<<k+1+j<<" "<<n-j-1<<endl;
    j++;
    if(i+j==m)break;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;

bool possible(int t,int x,int y){
    if(abs(x)+abs(y) > t) return false;
    if((t-abs(x)+abs(y))%2==0) return true;
    return false;
}

int main() {
    int n;
    cin >> n;
    int t[n+1],x[n+1],y[n+1];
    t[0]=0;
    x[0]=0;
    y[0]=0;
    for(int i=1;i<=n;i++) cin >> t[i] >> x[i] >> y[i];
    bool yes=true;
    for(int i=0;i<n;i++){
        if(!possible(t[i+1]-t[i],x[i+1]-x[i],y[i+1]-y[i])) yes=false;
    }
    if(yes) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  
  if ((a == b) && (b == c) && (c == a))
    cout << "No" << endl;
  else if ((a != b) && (b != c) && (c != a))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  
  return 0;
}


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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,b,a)     for(int i=b;i>=a;i--)

int n;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    if(n%111==0)
        cout<<n;
    else
        cout<<(n/111+1)*111;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

int n;
int a[55];

int main() {
	cin >> n;
	int mi = INF, ma  =-INF, imi, ima;
	for (int i = 1; i <= n; i++) {
		cin >> a[i]; 
		if (ma <= a[i]) {
			ma = a[i];
			ima = i;
		}
		if (mi > a[i]) {
			mi = a[i];
			imi = i;
		}
	}

	bool flag = (abs(ma) >= abs(mi));

	if (mi >= 0&& ma >=0) {//前から累積和
		cout << n - 1 << endl;
		for (int i = 1; i < n; i++) {
			cout << i << " " << i + 1 << endl;
		}
	}
	else if (ma <= 0&&mi <= 0) {//後ろから累積和
		cout << n - 1 << endl;
		for (int i = n; i > 1; i--) {
			cout << i << " " << i - 1 << endl;
		}
	}
	else {
		cout << 2 * n - 1 << endl;
		if (flag) {
			for (int i = 1; i <= n; i++) {
				cout << ima << " " << i << endl;
			}
			for (int i = 1; i < n; i++) {
				cout << i << " " << i + 1 << endl;
			}
		}
		else {
			for (int i = 1; i <= n; i++) {
				cout << imi << " " << i << endl;
			}
			for (int i = n; i > 1; i--) {
				cout << i << " " << i - 1 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>


ll sub(string s, int k)
{
	//cerr<<"["<<s<<"]"<<k<<endl;
	if (k==0) return 1;
	if (s=="") return 0;
	string _9=string(s.length()-1,'9');
	string s1=s.substr(1);
	
	if (s[0]=='0') return sub(s1,k);
	ll ret=0;
	if (s[0]>'1') ret+=(s[0]-'0'-1)*sub(_9,k-1);
	ret+=sub(_9,k);
	ret+=sub(s1,k-1);
	return ret;
}

int main(int argc, char *argv[])
{
	string n;
	int k;
	ll ret=0;

	cin >> n>>k;
	
	ret=sub(n,k);

	cout<<ret<<endl;
	return 0;
}


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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


int main(){
  int n,k,q;
  cin>>n>>k>>q;
  vector<int> a(q);
  rep(i,q)cin>>a[i];
  vector<int> p(n);
  rep(i,n){
  p[i]=k-q;
  }
  rep(i,q){p[a[i]-1]++;}
  rep(i,n){
  if(p[i]>0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
    Int a,b,c,x,y;cin >> a >> b >> c >> x >> y;
    Int ans = 0;
    //cout << " start" << endl;
    if((a+b)>=(2*c)){
        if(x<=y){
            ans+= 2*c*x;
            y-=x;
            x = 0;
        }else{
            ans+=2*c*y;
            x-=y;
            y = 0;
            //cout << "bin " << endl;
        }
    }
    if(2*c<=a) {ans+=2*c*x;x=0;}
    if(2*c<=b) {ans+=2*c*y;y=0;}
    ans+=x*a;
    ans+=y*b;
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define      fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define      debug       printf("\n<<CameHere>>\n")
#define      mem(x,y)    memset(x, y, sizeof(x))
#define      all(qz)     qz.begin(),qz.end()
#define      rall(qz)    qz.rbegin(),qz.rend()
#define      inf         1000000000000000000
#define      mod         1000000007
#define      Sqr(x)      ((x)*(x))
#define      ll          long long
#define      mk          make_pair
#define      pb          push_back
#define      pi          acos(-1.0)
#define      cos(a)      cos(a*pi/180)
#define      sin(a)      sin(a*pi/180)
#define      tan(a)      tan(a*pi/180)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
/*---------AL ASAD NUR RIYAD------------*/


int main()
{
    fastt

    string s;
    cin>>s;
    ll cnt=0;
    for(ll i=0;i<s.size();i++){
        cnt+=s[i]-'0';
    }
    if(cnt%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}
























Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  for(int i=0; i<N; i++){
    string color;
    cin >> color;
    if(color== "Y"){
      cout << "Four" << endl;
      break;
    }
    else if (i==N-1)
      cout << "Three" <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,k;
	cin>>a>>b>>k;
	vector<int> v;
	for(int i=min(a,b);i>=1;i--)
		if(a%i==0&&b%i==0)
			v.push_back(i);
	cout<<v[k-1]<<endl;
	return 0;
}


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

#define N 3
#define L 32
#define H 362897

struct depth{
  int dep, key;
};

int ans[N][N] = {
  {1, 2, 3},
  {4, 5, 6},
  {7, 8, 0}
};

int min = L;
struct depth h[H];

int hash1(int k){
    return k % H;
}

int hash2(int k){
    return 1 + k%(H-1);
}

int hash(int k, int i){
    return (hash1(k) + i*hash2(k))%H;
}



void dfs(int p[N][N], int n){
    int i, j, i0, j0;
    int a = 0;
    int b = 1;
    int f = 0;
    int tmp[N][N];

    for(i = 0 ; i<N ; i++){
        for(j=0 ; j<N ; j++){
            if( ans[i][j] != p[i][j] ){f++;}
            if( p[i][j] == 0 ){
                i0 = i;
                j0 = j;
            }
            a += p[i][j] * b;
            b *= 10;
        }
    }

    if( f == 0 ){
        if( min >= n ){
            min = n;
        }
        return;
    }

    if(n > min) return;
    i = 0;
    while(1){
        b = hash(a, i);
        if(h[b].key == 0){
            h[b].key = a;
            h[b].dep = n;
            break;
        }
        else if(h[b].key == a){
            if(h[b].dep>n){
                h[b].dep = n;
                break;
            }
            else return;
        }
        i++;
    }

    if(i0 > 0 && i0 < N){
        memcpy(tmp, p, sizeof(int)*N*N);
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0-1][j0];
        tmp[i0-1][j0] = f;
        dfs(tmp, n+1);
      }
    if(j0>0 && j0<N){
        memcpy(tmp, p, sizeof(int)*N*N);
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0][j0-1];
        tmp[i0][j0-1] = f;
        dfs(tmp, n+1);
      }

    if(i0>=0 && i0<N-1){
        memcpy(tmp, p, sizeof(int)*N*N);
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0+1][j0];
        tmp[i0+1][j0] = f;
        dfs(tmp, n+1);
      }
    if(j0>=0 && j0<N-1){
        memcpy(tmp, p, sizeof(int)*N*N);
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0][j0+1];
        tmp[i0][j0+1] = f;
        dfs(tmp, n+1);
      }

}
int main(){
  int i, j;
  int p[N][N];

  for(i=0 ; i<N ; i++){
    for(j=0 ; j<N ; j++){
      scanf("%d", &p[i][j]);
    }
  }
  dfs(p, 0);

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

  return 0;
}



Measured memory_bytes: 4700
from math import sqrt
from itertools import permutations as per
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
kumi = per(range(N))
ans = []
leng = 0
for p in kumi:
    cnt = 0
    for i in range(1, len(p)):
        cnt += sqrt((xy[p[i-1]][0] - xy[p[i]][0])**2 + (xy[p[i-1]][1] - xy[p[i]][1])**2)
    ans.append(cnt)
    leng += 1
print(sum(ans) / leng)

Measured memory_bytes: 43756
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;
typedef long long ll;

int n;
int a[1 << 18];

struct solver{
    int i, j;
    solver() : i(-1), j(-1) {}
    void insert(int k){
        if(k == -1 or k == i or k == j)return;
        if(i == -1){ i = k; return; }
        if(a[i] >= a[k]){
            if(j == -1)j = k;
            else if(a[j] < a[k])j = k;
        } else {
            j = i;
            i = k;
        }
    }
    int get(){
        int res = 0;
        if(i != -1)res += a[i];
        if(j != -1)res += a[j];
        return res;
    }
};

solver ss[1 << 18];

int main(){

    cin >> n;
    int sz = 1 << n;
    int ans = 0;
    solver use;
    rep(i, sz){
        cin >> a[i];
        if(i == 0){
            ss[i].insert(i); 
            continue; 
        }
        solver use;
        use.insert(i);
        rep(j, n){
            if((1 << j) & i){
                use.insert(ss[(1 << j) ^ i].i);
                use.insert(ss[(1 << j) ^ i].j);
            }
        }
        chmax(ans, use.get());
        ss[i] = use;
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
char ans[3];
cin >> ans;
REP(i,3) {
  if(ans[i]=='1') {
    ans[i] = '9';
  } else {
    ans[i] = '1';
  }
}
cout << ans << endl;
return 0;
}


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

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

Measured memory_bytes: 256
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const [N, K] = nextIntArray()
    const p = nextIntArray()
    p.sort((a,b) => a-b)
    let ans = 0
    for(let i = 0; i<K; i++){
        ans += p[i]
    }
    console.log(ans)
}
Main()


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

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static void main(String[] args){
        int N = in.i();
        char[] S = in.s().toCharArray();
        int[][] dp = new int[N+1][N+1];
        int max = 0;
        for(int i = 1; i < N+1; i++)
            for(int j = 1; j < N+1; j++)
                if(i != j && S[i-1] == S[j-1])
                    if((dp[i][j] = dp[i-1][j-1] + 1) > max && Math.abs(i-j+1) > dp[i][j])
                        max = dp[i][j];
        out.println(max);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 167244
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a % 2 == 0 || b % 2 == 0){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

use std::cmp;

fn main() {
    input!{
        n: usize,
        k: usize,
        x: [i64; n],
    }
    let mut mint:i64 = 10i64.pow(8)*3;
    for i in 0..n-k+1 {
        let ref l = x[i];
        let ref r = x[i+k-1];
        if l*r >=0 {
            mint = cmp::min( mint, cmp::max(l.abs(), r.abs()))
        } else {
            mint = cmp::min (mint, cmp::min(r*2-l, r-l*2));
        }
    }
    println!("{}",mint);
}

Measured memory_bytes: 4352
// Problem : E - Flatten
// Contest : AtCoder - AtCoder Beginner Contest 152
// URL : https://atcoder.jp/contests/abc152/tasks/abc152_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 1000000

int spf[N+5];

void sieve(){
    for(int i=2;i<=N;i++) spf[i] = i;
    for(int i=4;i<=N;i+=2) spf[i] = 2;
    for(int i=3;i*i<=N;i+=2){
        if(spf[i] == i){
            for(int j=i*i;j<=N;j+=i){
                if(spf[j] == j) spf[j] = i;
            }
        }
    }
}

int binpow(int x,int y){
    x %= mod;
    int res = 1;
    while(y){
        if(y&1) res = (res*x)%mod;
        x = (x*x)%mod;
        y = y/2;
    }
    return res;
}
 
int inv(int a){
    return binpow(a,mod-2);
}

//Solution

void solve(){
    sieve();
    int n;
    cin>>n;
    vi a(n);
    for(int &i : a) cin>>i;
    if(n == 1){
        cout<<1<<endl;
        return;
    }
    unordered_map<int,int> m;
    for(int i=0;i<n;i++){
        int x = a[i];
        unordered_map<int,int> tmp;
        while(x > 1){
            tmp[spf[x]]++;
            x /= spf[x];
        }
        for(auto [p,v] : tmp) m[p] = max(m[p],v);
    }
    int lcm = 1;
    for(auto [p,v] : m) lcm = (lcm*binpow(p,v))%mod;
    int ans = 0;
    for(int i=0;i<n;i++) ans = (ans+(lcm*inv(a[i]))%mod)%mod;
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int x; cin >> x;
	for (int i = 1; ; i++) {
		long long now = (long long)(i + 1) * i / 2;
		if (now >= x) {
			cout << i << "\n";
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int r, d, x;

int main() {
	scanf("%d %d %d", &r, &d, &x);
	for(int i = 1; i <= 10; i++) {
		int ans = r * x - d;
		printf("%d\n", ans);
		x = ans;
	}
	return 0;
}

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


int main() {
  long D,G;
  cin >> D >> G;
  long P[11];
  long C[11];
  for (int i = 0; i < D; i ++) {
    cin >> P[i] >> C[i];
  }
  long ans = 10000;
  for (int i = 0; i < (1 << D); i++) {
    long only_all = 0;
    long count_solve = 0;
    long max_part = 0;
    for (long j = 1; j <= D; j++) {
      if ((i >> (D - j)) & 1) {
        only_all += (100*j*P[j-1] + C[j-1]);
        count_solve += P[j-1];
      }
      else 
        max_part = j;
    }
    if (only_all >= G) {      
      //cout << count_solve << endl;
      //cout << only_all << endl;
    }
    else {
      long k = 0;
      while ((only_all < G) && (k < P[max_part - 1])) {
        only_all += max_part*100;
        count_solve += 1;
        k++;
      }
      if (only_all < G) continue;
      //cout << count_solve << endl;
      //cout << only_all << endl;
    }
    ans = min(count_solve,ans);
  } 
  
  cout << ans << endl;
}


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

#define ll long long

int main(){
    int n;
    string s;
    cin >> n >> s;

    int x=0, ans =0;
    for(int i=0; i<n; ++i){
        if(s[i] =='I')
            x++;
        else
            x--;

        ans = max(ans, x);
    }
    cout << ans;
}


Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;

int t = 1;
int n;
int a[105][105];

vector<int> d;
vector<int> f;
vector<int> g;
vector<int> color;

void visit(int u){
  color[u] = GRAY;
  d[u] = t++;

  for(int i = 0; i < n; i++){
    if(a[u][i] == 0) continue;
    if(color[i] == WHITE) visit(i);
  }

    color[u] = BLACK;
    f[u] = t++;
}

void dfs(){
  for(int i = 0; i < n; i++) color[i] = WHITE;

  for(int i = 0; i < n; i++){
    if(color[i] == WHITE) visit(i);
  }
}

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

  d.resize(n+5);
  f.resize(n+5);
  g.resize(n+5);
  color.resize(n+5);

  for(int i = 0; i < n; i++){
    cin >> u >> k;
    u--;

    for(int j = 0; j < k; j++){
      cin >> v;
      v--;
      a[u][v] = 1;
    }
    
  }

  dfs();

  for(int i = 0; i < n; i++){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }

  return 0;

}



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

int main(void){
  
  long long N;
  cin >> N;
  vector<long long> A(N + 1);
  vector<long long> B(N);
  for(long long i = 0; i < N + 1; i++){
    cin >> A[i];
  }
  for(long long i = 0; i < N; i++){
    cin >> B[i];
  }
  long long count = 0;
  for(long long i = N; i > 0; i--){
    if(A[i] > B[i - 1]){
      count += B[i - 1];
      //cout << count << endl;
    }
    else{
     count += A[i];
      //cout << count << ",";
     if(A[i - 1] > (B[i - 1] - A[i])){
       count += B[i - 1] - A[i];
       A[i - 1] = A[i - 1] - B[i - 1] + A[i];
     }
     else{
       count += A[i - 1];
       A[i - 1] = 0;
     }
      //cout << count << endl;
   }
  }
  
  cout << count;
 return 0;
  
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {

		int a, b;

		cin >> a >> b;

		if (a > b) {
			cout << "a > b" << endl;
		}
		else if (a < b) {
			cout << "a < b" << endl;
		}
		else {
			cout << "a == b" << endl;
		}

		return 0;

	}






/*if文で条件分岐について*/

  /* 

  　　　● まずはイメージを掴もう

	 　 if文を英語で言うと「もし～なら○○する」です。

     　 そう、普段の生活で使用しています。
	 　 例えば、警報が発令されたら家から出ない。好きな人が出来たらデートに誘う。仕事が残っていると残業する。などがある!!

	    これを、プログラムの書き方で書くと、こんな感じ～

	    if(警報発令){
             家から出ない
	    }

		書き方は
		if(条件){
		     動かしたい命令
		}


		● 2通りの条件とき

		例：ジェットコースターに乗れるのは身長は140cm以上で乗れる。その条件を満たしていないとは乗れない

		if(身長は140cm以上){
		　　　ジェットコースターに乗れる
		}
		else{
		　　　ジェットコースターに乗れない
		}

		書き方は
		if(条件){
		動かしたい命令
		}
		else{
		条件を満たさないときの命令
		}

		※ 重要：ifの条件を満たさないときはelseを使って別の命令をする。


		● 3通りの条件とき

		信号機は青色で道路を渡る、黄色で道路を急いで渡る、赤色は道路を渡らない

		これを、プログラムの書き方で書くと、こんな感じ～

		if(青色){
		　　　道路を渡る
		}
		else if(黄色) {
		      道路を急いで渡る
		}
		else{
		      道路を渡らない
		}

		※ 重要　elseの後にifを付けて3通りにする　else␣if(条件)の形を作る。

  */


  /*　重要

  　　　● 条件には不等号を使う

	      ・　a < b　  (aはbより大きい)
	　　　・　a > b　  (aはbより小さい)
	　　　・　a <= b　（aはb以上）
	　　　・　a >= b　（aはb以下）
	　　　・　a == b　（aはb等しい）
	　　　・  a != b　（aはb等しくない）

  */






Measured memory_bytes: 3092
#include<cstdio>
#include<algorithm>
int main(){
  int j=1,x,da[3][100001],fun[3][2];
  scanf("%d",&x);
  fun[0][0] = fun[1][0] = fun[2][0] = 0;
  for(int i=1;i<=x;i++){
    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);
    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];
    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];
    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];
    j^=1;
  }
  j^=1;
  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));
  
  return 0;
}


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

bool judgePrimeNumber( int a )
{
    if( a == 1 )
        return false;
    for( int i = 2; i <= sqrt(a); i++ )
        if( a % i == 0 )
            return false;
    return true;
}

int main()
{
    int a, d, n;

    while( cin >> a >> d >> n )
    {
        if( a + d + n == 0 )
            break;

        int cnt = 0;
        while( cnt != n )
        {
            if( judgePrimeNumber(a) )
                cnt++;
            a += d;
        }

        cout << a - d << endl;

    }
    return 0;
}



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

int main() {
    long long k;
    cin >> k;
    long long a[50];
    for (int i = 0; i < k % 50; i++) {
        a[i] = k / 50 + 100 - k % 50;
    }
    for (int i = k % 50; i < 50; i++) {
        a[i] = k / 50 + 49 - k % 50;
    }
    cout << 50 << '\n';
    for (auto i : a) {
        cout << i << ' ';
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define st string
#define con continue
#define br break
#define rt return 0
#define fr first
#define sec second
using namespace std;
int main(){
//ll tc; cin>>tc; while(tc--){
ll n,m,mn=INT_MAX,i,x,j,a=0,t,k,b=-1,mx=-1,cnt=0,c=0; 
 st s,str; char strn;
cin>>n; //a=n; n-=1; 
ll ara[n+1],bra[n+1],taj[n+1];
memset(ara,0,sizeof(ara));
//for(i=1;i<=n;i++) cin>>ara[i]; 
  for(i=1;i<=n;i++)
   {  
     for(j=i;j<=n;j+=i)
      {
        ara[j]++;
      }
      
   }      
   for(i=1;i<=n;i++) 
        a+=(i*ara[i]);  

        
     cout<<a<<endl;
    
 
    rt;
}

Measured memory_bytes: 81748
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string a,b;
    while(cin>>a>>b){
        int ans = 0;
        reverse(a.begin(),a.end());
        for(int i=0;i<b.size();++i){
            a+="0";
        }
        reverse(a.begin(),a.end());
        for(int i=0;i<a.size();++i){
            int count=0;
            for(int j=0;j+i<a.size()&&j<b.size();++j){
                if(a[i+j]==b[j]){
                    ++count;
                }else{
                    ans=max(ans,count);
                    count=0;
                }
            }
            ans=max(ans,count);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  if(x<=599) cout << 8 << endl;
  else if(x<=799) cout << 7 << endl;
  else if(x<=999) cout << 6 << endl;
  else if(x<=1199) cout << 5 << endl;
  else if(x<=1399) cout << 4 << endl;
  else if(x<=1599) cout << 3 << endl;
  else if(x<=1799) cout << 2 << endl;
  else if(x<=1999) cout << 1 << endl;
}
  


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

char a[100007], b[100007];
int len;

bool judge() {
	for(int i = 0; i < len; i++)
		if(b[i] != a[len - 1 - i]) 
			return false;
	return true;
}
int main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin >> a;
	strcpy(b, a);
	len = strlen(a);
	for(int i = 0; i < len; i++)
		switch(b[i]) {
			case 'b': a[i] = 'd'; break;
			case 'd': a[i] = 'b'; break;
			case 'p': a[i] = 'q'; break;
			case 'q': a[i] = 'p'; break;
		}
	
	cout << (judge() ? "Yes\n" : "No\n");
	
	return 0;
}


Measured memory_bytes: 384
def check(s1,s2):
    l1 = s1.split('"')
    l2 = s2.split('"')
    if len(l1) != len(l2):
        return "DIFFERENT"
    close = 0
    for i in range(len(l1)):
        if l1[i] != l2[i]:
            if i % 2 == 0: return "DIFFERENT"
            else : close += 1
    if close == 1: return "CLOSE"
    if close == 0: return "IDENTICAL"
    return "DIFFERENT"

if __name__ == '__main__':
    while True:
        s1 = input()
        if s1 == ".": break
        s2 = input()
        print(check(s1,s2))


Measured memory_bytes: 5576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        int a = Integer.parseInt(br.readLine());
        int b = Integer.parseInt(br.readLine());
        System.out.println(problem087a(x, a, b));
    }

    private static int problem087a(int x, int a, int b) {
        return (x - a) % b;
    }
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

int main(){
	cin>>N;
	LL ans=0;
	LL ma=0;
	REP(i,N){
		LL a;
		cin>>a;
		ma=max(ma,a);
		ans+=a;
	}
	cout<<ans-ma/2<<endl;
}

Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	string s; cin >> s;
	int ans = 0;
	rep(i, 3) {
		if (s[i] == '1') ans++;
	}

	cout << ans << endl;
}

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

typedef long long ll;
#define reg register
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)

char IO;
int rd(){
	int s=0,f=0;
	while(!isdigit(IO=getchar())) if(IO=='-') f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(isdigit(IO=getchar()));
	return f?-s:s;
}

const int N=5e5+10;


int n,a[N];
int s[N],s1[N];

int main(){
	rep(i,1,n=rd()) a[i]=rd(),s[i]=max(a[i],s[i-1]);
	drep(i,n,1) s1[i]=max(a[i],s1[i+1]);
	rep(i,1,n) {
		printf("%d\n",max(s[i-1],s1[i+1]));
	}
	;
}


















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

#define int long long

signed main(){
    string odd = "RUD";
    string even = "LUD";
    
    string s;
    cin >> s;
    
    for(int i = 0; i < s.length(); i+=2){
        int cnt = 0;
        for(int j = 0; j < odd.length(); j++){
            if(s[i] == odd[j])cnt++;
        }
        
        if(!cnt){
            cout << "No\n"; return 0;
        }
    }
    swap(odd, even);
    for(int i = 1; i < s.length(); i+=2){
        int cnt = 0;
        for(int j = 0; j < odd.length(); j++){
            if(s[i] == odd[j])cnt++;
        }
        
        if(!cnt){
            cout << "No\n"; return 0;
        }
    }
    
    cout << "Yes\n";
    
}




Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include <algorithm>  
using namespace std;


int main() {
  int n;
  cin >> n;
  int temp;
  int ans;
  cin >> ans;
  for(int i=1; i < n; i++) {
   	cin >> temp;
    ans = __gcd(ans, temp);
  }
  cout << ans;
  return 0;
}

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

if N > M:
    print(0)
    exit(0)

X = list(map(int, input().split()))
X.sort()

gap = []
for i in range(M-1):
    gap.append(X[i+1] - X[i])

gap.sort()

ans = sum(gap)
for i in range(N-1):
    ans -= gap[-1-i]

print(ans)

Measured memory_bytes: 13968
#include "bits/stdc++.h"

using namespace std;

bool judge(const vector<vector<bool>>& picture) {
    int H = picture.size();
    int W = picture.front().size();
}

void Main() {
    int H, W;
    cin >> H >> W;
    vector<vector<bool>> picture(H, vector<bool>(W, false));
    for (int i = 0; i < H; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < W; ++j) {
            picture[i][j] = (s[j] == '#');
        }
    }

    bool ans = true;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (picture[i][j]) {
                bool ip1 = (i < H - 1) && picture[i + 1][j];
                bool im1 = (i > 0) && picture[i - 1][j];
                bool jp1 = (j < W - 1) && picture[i][j + 1];
                bool jm1 = (j > 0) && picture[i][j - 1];
                if (ip1 || im1 || jp1 || jm1) {
                    continue;
                }
                else {
                    ans = false;
                    break;
                }
            }
        }
        if (!ans) {
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3584
//****** @author mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fast_pow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}



void solve() {
   ll a,b;cin>>a>>b;
   ll gc=__gcd(a,b);
   ll lcm=(a*b)/gc;
  // if(lcm%2==1)lcm*=2;
   cout<<lcm<<endl;

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

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int N,M,A[10001],i,sum = 0,ans;

    scanf("%d %d",&N,&M);
    for(i = 0;i < M;i++){
        scanf("%d",&A[i]);
        sum += A[i];
    }

    ans = N - sum;
    if(ans < 0) printf("-1\n");
    else printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1736
#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)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

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

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}

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

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

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

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,cmp,cmpp,m,h,w,sx,sy,tx,ty,dx,dy,sum=0,pos;

string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

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


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

using namespace std;

using ll = long long;

int main() {
    ll N, K;
    cin >> N >> K;

    std::vector<ll> A(N);
    std::for_each(A.begin(), A.end(), [](auto &x) { cin >> x; });
    
    const auto count = [&K](const auto num) {
        return num % (K - 1) == 0 ? num / (K - 1) : num / (K - 1) + 1;
    };

    cout << count(N - 1) << endl;

    return 0;
}


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

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

using namespace __gnu_pbds;  // or pb_ds;

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#ifndef DEBUG
#define endl "\n"
#endif
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

template <typename T, typename B = null_type>
using oset =
    tree<T, B, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order / order_of_key

const ld eps = 1e-12;

/*-----------------END TEMPLATE-----------------*/

vi vals;
vi valsR;

int(((((((((((((((main)))))))))))))))() {
  FASTIO;
  ll n;
  cin >> n;
  int total = 0;
  while (n > 0) {
    total += n % 10;
    n /= 10;
  }
  if (total == 1) {
    total = 10;
  }
  cout << total << endl;
}

/*
100000
 11111
988889

*/

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n; ll p; in(n),in(p);
  string s; in(s);
  reverse(s.begin(), s.end());
  
  if (p == 2 or p == 5) {
    ll ans = 0;
    loop(i,0,n) {
      ll d = s[i]-'0';
      if (d%p==0) {
        ans += n-i;
      }
    }
    print(ans);
    return 0;
  }
  
  ll rem = 0;
  ll ten = 1;
  vector<ll> C(p+1, 0);
  C[rem]++;
  loop(i,0,n) {
    ll d = s[i]-'0';
    rem = (rem + (d * ten)) % p;
    C[rem]++;
    ten = (ten * 10) % p;
  }
  
  ll ans = 0;
  loop(i,0,p) {
    ans += (C[i]*(C[i]-1)) / 2;
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
//#include <functional>


int main(){
    int64_t A,B;
    std::cin >> A >> B;

    int64_t res = (A + B);
    if(res % 2 != 0){
        std::cout << "IMPOSSIBLE";
    }
    else{
        std::cout << res / 2;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] array = new int[n][2];
        int[][] arrayC = new int[m][2];
        for (int i=0; i<n; i++) {
            array[i][0] = sc.nextInt();
            array[i][1] = sc.nextInt();
        }
        for (int i=0; i<m; i++) {
            arrayC[i][0] = sc.nextInt();
            arrayC[i][1] = sc.nextInt();
        }
        for (int i=0; i<n; i++) {
            int x = array[i][0];
            int y = array[i][1];
            double min = Math.pow(10,8)*2;
            int minP = 0;
            for (int j=0; j<m; j++) {
                if (min > Math.abs(arrayC[j][0] - x) + Math.abs(arrayC[j][1]-y)) {
                    min = Math.abs(arrayC[j][0] - x) + Math.abs(arrayC[j][1]-y);
                    minP = j;
                }
            }
            System.out.println(minP +1);
        }

    }
}

Measured memory_bytes: 21716
N = int(input())
c = input()
rlist = []
wlist = []
for i in range(N):
    if c[i] == 'R':
        rlist.append(i)
    else:
        wlist.append(i)

cnt = 0
if len(rlist) == 0:
    print(0)
    exit()
for i in range(len(wlist)):
    if wlist[i] < rlist[-cnt - 1]:
        cnt += 1
    else:
        break
print(cnt)

Measured memory_bytes: 17420
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N, W;
  cin >> N >> W;

  vector<vector<int>> dp(N + 10, vector<int>(111111, INF));
  dp.at(0).at(0) = 0;
  for (int i = 0; i < N; i++)
  {
    int w, v;
    cin >> w >> v;
    
    for (int j = 0; j < dp.at(0).size(); j++)
    {
      if (j + v < dp.at(0).size())
        chmin(dp.at(i + 1).at(j + v), dp.at(i).at(j) + w);

      chmin(dp.at(i + 1).at(j), dp.at(i).at(j));
    }
  }
  
  int ans = -INF;
  for (int i = 0; i < dp.at(0).size(); i++)
  {
    if (dp.at(N).at(i) <= W) ans = i;
  }

  cout << ans << endl;
}

Measured memory_bytes: 97024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int a[110];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,k;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		sort(a,a+n,cmp);
		int sum=0;
		for(int i=0;i<k;i++)
			sum+=a[i];
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 256
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut cnt: Vec<u64> = vec![0; 200020];
    let mut choose: Vec<u64> = vec![0; 200020];
    for i in 0..n {
        cnt[a[i]] += 1;
    }
    for i in 0..200005 {
        if cnt[i] > 0 {
            choose[i] = cnt[i] * (cnt[i] - 1) / 2;
        }
    }
    for i in 0..200005 {
        choose[i + 1] += choose[i];
    }

    let mut out = Vec::new();
    for i in 0..n {
        writeln!(out, "{}", choose[200005] - (cnt[a[i]] - 1)).ok();
    }

    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 19472