akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    
    ll K;
    cin >> K;

    map<string,ll> mp;

    for(ll i = 0; i < s.size(); i++)
    {
        for(ll j = 1; j <= K; j++)
        {
            string tmp;
            for(ll k = 0; k < j; k++)
            {
                if(i+k >= s.size())break;
                tmp.push_back(s[i+k]);
            }
            mp[tmp]++;
        }
    }
    
    ll count = 0;
    for(auto e:mp)
    {
        count++;
        if(count == K)
        {
            cout << e.first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

const ll INF = 1e9;
const long long INFL = 1LL<<60;


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

  if (s[0] != 'A') {
    puts("WA");
    return 0;
  }

  int st = 2;
  int ed = s.size() - 2;

  int idx = -1;

  for (int i = st; i <= ed; i++) {
    if (s[i] == 'C') {
      if (idx == -1) idx = i;
      else {
        puts("WA");
        return 0;
      }
    }
  }

  if (idx == -1) {
    puts("WA");
    return 0;
  }

  for (int i = 1; i < s.size(); i++) {
    if (i == idx) continue;
    if (s[i] < 'a' || 'z' < s[i]) {
      puts("WA");
      return 0;
    }
  }

  puts("AC");

  return 0;
}


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

int main() {
	vector<bool>x( 200000, 1 );
	vector<long long int>prime;
	x[0] = x[1] = 0;
	for( size_t i = 0; i < 200000; i++ ) {
		if( x[i] ) {
			prime.emplace_back( i );
			long long int j = 2;
			while( i*j < 200000 ) {
				x[i*j] = 0;
				j++;
			}
		}
	}
	long long int N, M;
	while( cin >> N >> M, N != -1 && M != -1 ) {
		auto now = upper_bound( prime.begin(), prime.end(), N ) - prime.begin();
		vector<long long int >memo;
		for( size_t i = 0; i < 101; i++ ) {
			for( size_t j = i; j < 101; j++ ) {
				memo.emplace_back( prime[now + i] + prime[now + j] );
			}
		}
		sort( memo.begin(), memo.end() );
		//memo.erase( unique( memo.begin(), memo.end() ), memo.end() );
		cout << memo[M - 1] << endl;
	}
}

Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll INF64 = 1e18;

template <typename T>
string to_string(const vector<T> &v) {
  string ret = "<";
  for (auto it : v) {
    ret += to_string(it) + ", ";
  }
  ret.pop_back(); ret.pop_back();
  ret += ">";
  return ret;
}

void debug_print() { cerr << endl; }

template <typename T, typename ...U>
void debug_print(T t, U... u) {
  cerr << " " << to_string(t);
  debug_print(u...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_print(__VA_ARGS__)
const int N = 1e5 + 5;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  if (c < b)
    ans = (a * c / b) - a * (c / b);
  else ans = (a * (b - 1) / b) - a * ((b - 1) / b); 
  cout << ans << endl; 
  return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    ll s, c;
    cin >> s >> c;

    ll ans = 0;
    {
        ll tmp = min(s, c/2);
        ans += tmp;
        s -= tmp;
        c -= 2*tmp;
    }

    ans += c / 4;
    cout << ans << endl;
}



Measured memory_bytes: 256
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
    return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
    return n = n | (1LL << pos);
}


double calc(double h, double m)
{
    double hh = 0.5 * (h * 60 + m);
    double mm = (0.6 * m);

    double ang = abs(hh - mm);

    if(ang >= 180) ang -= 180;



    ang = (acos(-1.0) * ang) / 180;

    return ang;
}

double calcAngle(double h, double m)
{
    // validate the input
    if (h <0 || m < 0 || h >12 || m > 60)
        assert(1 == 0);

    if (h == 12) h = 0;
    if (m == 60) m = 0;

    double hour_angle = 0.5 * (h * 60 + m);
    double minute_angle = 6 * m;


    double angle = abs(hour_angle - minute_angle);

    angle = min(360 - angle, angle);

    angle = (angle / 180) * pi;
    return angle;
}
int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n >> m >> l >> r)
    {
        double ang = calcAngle(l,r);

//        cout << ang << " " << cos(ang) << endl;

        double c = (n * n) + (m * m) - (2 * n * m * cos(ang));

        printf("%.10f\n", sqrt(c));
    }
}






Measured memory_bytes: 4184
#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define reg register
	#define Rint register int
	#define FOR(i,a,b) for(register int i=(a);i<=(b);++i)
	#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
	#define FORit(templ,arr,i,a,b) for(register templ *i=(arr)+(a);i!=(arr)+(b)+1;++i)
	#define ROFit(templ,arr,i,a,b) for(register templ *i=(arr)+(a);i!=(arr)+(b)-1;--i)
	#define GO(x,p,e,i,v) for(register int i=p[x].head,v;i;i=e[i].link)
	#define MEM(x,v) memset(x,v,sizeof(x))
	#define fir first
	#define sec second
	#define pq priority_queue
	#define PII pair<int,int>
	#define MP make_pair
	typedef long long LL;
	typedef double DB;
	inline int read(){
		int ans=0,f=1;char c=getchar();
		while(c>'9'||c<'0'){ f^=(c=='-'); c=getchar(); }
		for(;c<='9'&&c>='0';c=getchar()) ans=(ans<<1)+(ans<<3)+(c^48); return f?ans:-ans;
	}
	const int mod = 998244353 , N = 100010 , M = 200010;
	inline void inc(int &x,const int &y){ x+=y; if(x>=mod) x-=mod; }
	inline int ksm(int x,LL y){ int res=1; for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod; return res;}
	inline int gcd(int x,int y){ if(x<y) swap(x,y); return y?gcd(y,x%y):x; }
	#define FILE(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
}
using namespace my_std;
#define rsiz(x) (int((x).size()))
int n,m,etot,tot,cnt[2],flag;
LL ans;
queue<int> Q;
struct Edge{
	int link,to;
}e[M];
struct Vertice{
	int head,dep;
}p[N];

inline void add_edge(int u,int v){
	e[++etot] = (Edge){ p[u].head , v };
	return (void)(p[u].head = etot);
}

void dfs(int u,int f){
	++cnt[p[u].dep = (p[f].dep ^ 1)] , ++tot;
	GO(u,p,e,i,v){
		v = e[i].to;
		if(~p[v].dep){
			if(!(p[v].dep ^ p[u].dep)) flag = 1;
			continue;
		}
		else dfs(v,u);
	}
}

inline void work(int S){
	cnt[0] = flag = cnt[1] = tot = 0;
//	dfs(S,0);
//	FOR(i,1,n) printf("%d ",p[i].dep); puts("");
//	printf("%d %d %d %d %d\n",S,cnt[0],cnt[1],tot,flag);
	if(dfs(S,0) , flag) return (void)(ans += 1ll * tot * (tot - 1) / 2);
	return (void)(ans += 1ll * cnt[0] * cnt[1]);
}

int main(){
	n = read() , m = read();
	Rint u,v;
	FOR(i,1,n) p[i].dep = -1;
	FOR(i,1,m) add_edge(u = read(),v = read()) , add_edge(v,u);
	FOR(i,1,m) if(p[i].dep == -1) work(i);
	printf("%lld\n",ans - m);
	return 0;
}

Measured memory_bytes: 3200
N = gets.to_i
A = gets.strip.split.map(&:to_i)
s = 0

s += A[0].abs

for i in 0..N-2

    s += (A[i+1]-A[i]).abs

end

s += A[N-1].abs

if N > 2

for i in 0..N-1

    



        if 1 <= i && i <= N-2
        
            puts s-(A[i+1]-A[i]).abs-(A[i]-A[i-1]).abs+(A[i+1]-A[i-1]).abs

        elsif i == 0

            puts s-A[0].abs-(A[1]-A[0]).abs+A[1].abs 

        elsif i == N-1

            puts s-(A[N-1]-A[N-2]).abs-A[N-1].abs+A[N-2].abs 

        end

end

else N == 2

    puts 2 * A[1].abs

    puts 2 * A[0].abs

end

   




Measured memory_bytes: 13588
#include <iostream>

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b;
  if(b/10 == 0)c = b+10*a;
  else if(b/100==0) c = b+ 100*a;
  else c = b+1000*a;
  for(a=1;a<=1100;a++){
    if(a*a==c){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
double ac;
double TLE(){return (double)(clock() - ac) / CLOCKS_PER_SEC;}
void debug_out() { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main(){
 ios::sync_with_stdio(0),cin.tie(0);
 int a[5];
for(int i=0;i<5;i++){
 cin>>a[i];
}
 for(int i=0;i<5;i++){
 	if(a[i]==0){
 		cout<<(i+1)<<endl;
 		break;
 	}
 }
}

Measured memory_bytes: 3560
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<usize>();
    let n = v[0];
    let k = v[1] as u64;
    let div = 1000000007;
    let a = read_vec::<u64>();

    let mut at_count = 0;
    let mut top_count = 0;
    for i in 0..n-1 {
        for j in i+1..n {
            if a[i] > a[j] {
                at_count += 1;
            } else if a[i] < a[j] {
                top_count += 1;
            }
        }
    }

    let ks:u64 = k * (k + 1) / 2;// % 1000000007;
    //println!("{}", ks * at_count % 1000000007);
    let ts:u64 = (k-1) * k / 2;
    //println!("{}", ts * top_count % 1000000007);

    //println!("{} {} {} {}", ks, at_count, ts, top_count);
    let mut ans: u64 = 0;
    for _ in 0..at_count {
        ans += ks;
        ans %= div;
    }
    for _ in 0..top_count {
        ans += ts;
        ans %= div;
        //println!("{}", ans);
    }
    //println!("{} {}", ks, at_count);
    println!("{}", ans);
}


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

import static java.lang.System.in;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] rec = new String[N+1];
        PrintWriter out = new PrintWriter(System.out);
        out.println(0);
        out.flush();
        String s = sc.next();
        rec[0]=rec[N]=s;
        if(s.equals("Vacant")) System.exit(0);
        int lower = 0, upper = N;
        for(int i=0;i<25;i++){
            int mid = (lower+upper)/2;
            out.println(mid);
            out.flush();
            rec[mid]=sc.next();
            if(rec[mid].equals("Vacant")) System.exit(0);
            if(upper-mid<=1) upper=mid;
            else if(mid-lower<=1) lower = mid;
            else{
                if(rec[mid].equals(rec[lower])){
                    if((mid-lower-1)%2==1) lower=mid;
                    else upper=mid;
                } else{
                    if((mid-lower-1)%2==1) upper=mid;
                    else lower=mid;
                }
            }
        }
    }
}


Measured memory_bytes: 23588
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}

//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

//debug処理
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int k, x;
queue<int>que;
signed main() {
	cin >> k;
	for (int i = 1; i <= 9; i++)que.push(i);
	rep(i, k) {
		x = que.front();
		que.pop();
		if (x % 10 != 0)que.push(x * 10 + (x % 10) - 1);
		que.push(x * 10 + (x % 10));
		if (x % 10 != 9)que.push(x * 10 + (x % 10) + 1);
	}
	cout << x << endl;
	ggr
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod  1000000007
#define pb push_back
#define mk make_pair
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ld long double
#define fi first
#define se second
#define setbits __builtin_popcount
#define inf 1e18
int main()
{
    fastIO;
    ll n,k;
    cin>>n>>k;
    ll r,s,p;
    cin>>r>>s>>p;
    string str,str1;
    cin>>str;
    ll i,ans=0;
    for(i=0;i<k;i++)
    {
        if(str[i]=='r')
        {
            ans+=p;
            str1+='p';
        }
        if(str[i]=='s')
        {
            ans+=r;
            str1+='r';
        }
        if(str[i]=='p')
        {
            ans+=s;
            str1+='s';
        }
    }
    for(i=k;i<str.length();i++)
    {
        if(str[i]=='r')
        {
            if(str1[i-k]=='p')
            {
                str1+='X';
            }
            else
            {
                str1+='p';
                ans+=p;
            }
        }
        if(str[i]=='s')
        {
            if(str1[i-k]=='r')
            {
                str1+='X';
            }
            else
            {
                str1+='r';
                ans+=r;
            }
        }
        if(str[i]=='p')
        {
            if(str1[i-k]=='s')
            {
                str1+='X';
            }
            else
            {
                str1+='s';
                ans+=s;
            }
        }
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 640
from collections import deque

h, w, n = map(int, input().split())
g = ['0'] * h

sx, sy = -1, -1
pos = -1
for i in range(h):
    g[i] = input()
    if pos == -1:
        pos = g[i].find('S')
        if pos != -1:
            sx = i
            sy = pos

book = set()
queue = deque()

ans = 0

Next = [[-1, 0], [1, 0], [0, -1], [0, 1]]

for a in range(1, n + 1):
    book.clear()
    queue.clear()
    queue.append((sx, sy, 0))
    aim = str(a)

    while len(queue):
        t = queue.popleft()
        if (t[0], t[1]) in book:
            continue

        if g[t[0]][t[1]] == aim:
            ans += t[2]
            # print(t[0], ' ', t[1], ' ', aim, ' ', ans)
            sx, sy = t[0], t[1]
            break

        book.add((t[0], t[1]))
        for i in range(4):
            tx = t[0] + Next[i][0]
            ty = t[1] + Next[i][1]
            if 0 <= tx < h and 0 <= ty < w and g[tx][ty] != 'X':
                queue.append((tx, ty, t[2] + 1))

print(ans)





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

int main() {
    int n, m;
    cin >> n >> m;
    bool cnt_a[200200] = {false}, cnt_b[200200] = {false};
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;

        if (a == 1) cnt_a[b] = true;
        if (b == n) cnt_b[a] = true;
    }

    bool can = false;
    for (int i = 1; i <= n; i++) {
        if (cnt_a[i] == true && cnt_b[i] == true) can = true;
    }

    if (can) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

int main(){
	ll k;
	cin >> k;
	vector<ll> num(k,0);
	
	if(k%2==0){
		cout << "-1\n";
		return 0;
	}
	ll i=1;
	ll x=7;
	num[x%k] = 1;
	
	while(x%k!=0){
		x = 10*x + 7;
		x %= k;
		if(num[x]){
			cout << "-1\n";
			return 0;
		}else{
			num[x] = 1;
		}
		i++;
	}
	
	cout << i << endl;
	
	
	return 0;
}

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

int main() {
  int N, W;
  vector<string> vec(N);
  cin >> N >> W;
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < W+1; i++) cout <<"#";
  cout << "#" << endl; //1行目
  
  for (int i = 0; i < N; i++)   cout << "#" << vec.at(i) << "#" << endl;
  
  for (int i = 0; i < W+1; i++) cout <<"#";
  cout << "#" << endl;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

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

    bool flg = true;
    int  len = s.size();
    for (int i = 0; i < len; i++) {
        if (i % 2 == 0) {
            if (s[i] == 'L') {
                flg = false;
                break;
            }
        } else {
            if (s[i] == 'R') {
                flg = false;
                break;
            }
        }
    }

    if (flg == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

//  || s[i] == 'U' || s[i] == 'D')


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

int main() {
	int n,k;
	cin>>n;
	vector<pair<int,int>> v;
	for(int i=1;i<=n;i++){
		int temp;
		cin>>temp;
		v.push_back({temp,i});
	}
	sort(v.begin(),v.end());
	for(auto k : v) cout<<k.second<<" ";
	
	return 0;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
signed main()
{
    int n;
    cin >> n;
    if (n == 2)
    {
        cout << 1 << endl;
        return 0;
    }
    vector<int> divisorn, divisorn1;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            divisorn.pb(i);
    }
    int temp = n - 1;
    for (int i = 2; i * i <= temp; i++)
    {
        if (temp % i == 0)
        {
            divisorn1.pb(i);
            if (temp / i != i)
                divisorn1.pb(temp / i);
        }
    }
    int answer = 0;
    int temp1 = n;
    int temp2 = n - 1;
    for (auto it : divisorn)
    {
        n = temp1;
        while (n % it == 0)
        {
            n /= it;
        }
        if (n % it == 1)
            answer++;
    }
    answer += divisorn1.size();
    answer += 2;
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
 
int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	
 
const ll mod=1e9+7;
const int INF=INT_MAX/2;

int main(){
	ll x;
	cin>>x;
	ll d=100;
	int cnt=0;
	while(d<x){
		d = (ll)(d*1.01);
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}
 

Measured memory_bytes: 3624
// https://agc026.contest.atcoder.jp/tasks/agc026_c
#include <bits/stdc++.h>
using namespace std;
template<class C>constexpr int sz(const C&c){return int(c.size());}
using ll=long long;constexpr const char nl='\n',sp=' ';

seed_seq seq {
  uint64_t(chrono::duration_cast<chrono::nanoseconds>(
    chrono::steady_clock::now().time_since_epoch()).count()
  ),
  uint64_t(__builtin_ia32_rdtsc()),
  uint64_t(uintptr_t(make_unique<char>().get()))
};

mt19937 rng(seq); mt19937_64 rng64(seq);

const size_t RANDOM = uniform_int_distribution<size_t>(
    0, numeric_limits<size_t>::max())(rng64);
struct rand_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);
  }
  template <class T> size_t operator () (const T &x) const {
    return splitmix64(hash<T>()(x) + RANDOM);
  }
  template <class T1, class T2>
  size_t operator () (const pair<T1, T2> &p) const {
    return 31 * operator ()(p.first) + operator ()(p.second);
  }
};

template <class K, class H = rand_hash, class ...Ts>
using uset = unordered_set<K, H, Ts ...>;
template <class K, class V, class H = rand_hash, class ...Ts>
using umap = unordered_map<K, V, H, Ts ...>;

int N;
string S;
umap<pair<string, string>, ll> M;

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // freopen("err.txt", "w", stderr);
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> N >> S;
  for (int i = 0; i < (1 << N); i++) {
    string red, blue;
    for (int j = 0; j < N; j++) {
      if ((i >> j) & 1) red.push_back(S[j]);
      else blue.push_back(S[j]);
    }
    reverse(blue.begin(), blue.end());
    M[make_pair(red, blue)]++;
  }
  ll cnt = 0;
  for (int i = 0; i < (1 << N); i++) {
    string red, blue;
    for (int j = 0; j < N; j++) {
      if ((i >> j) & 1) red.push_back(S[N + j]);
      else blue.push_back(S[N + j]);
    }
    reverse(blue.begin(), blue.end());
    cnt += M[make_pair(blue, red)];
  }
  cout << cnt << nl;
  return 0;
}


Measured memory_bytes: 64512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  string S,T;
  cin >> S >> T;
  reverse(S.begin(),S.end());
  reverse(T.begin(),T.end());
  
  bool can = false;
  for (int i = 0; i < S.size() - T.size() + 1; i++) {
    if (S.at(i) == T.at(0) || S.at(i) == '?') {
      bool can2 = true;
      for (int j = 0; j < T.size(); j++) {
        if (S.at(i+j) != T.at(j) && S.at(i+j) != '?') can2 = false;
      }
      if (can2) {
        for (int j = 0; j < T.size(); j++) S.at(i+j) = T.at(j);
        can = true;
        break;
      }
    }
  }
  
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '?') S.at(i) = 'a';
  }
  
  reverse(S.begin(),S.end());
  
  if (can) cout << S << endl;
  else cout << "UNRESTORABLE" << endl;      
}

Measured memory_bytes: 256
import math

N,H=map(int,input().split())
AB=[]
for i in range(N):
    AB.append(list(map(int, input().split())))

ki=0  #切る力の最大を取得
for i in range(N):
    ki = max(ki,AB[i][0])

nage=[]
for i in range(N):
    if AB[i][1] > ki:
        nage.append(AB[i][1])
nage.sort(reverse=True)

count=0
i=0
if nage!=[]:
    while H>0 and i<=len(nage)-1:
        H-=nage[i]
        count+=1
        i+=1

if H<=0:
    print(count)
else:
    print(count+math.ceil(H/ki))

Measured memory_bytes: 28580
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = (10**5)*2+5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

Num,K=map(int,input().split())

ans=0
for i in range(min(Num+1,K+1)):
    ans+=(cmb(Num,i,mod)*cmb(Num-1,i,mod))%mod
print(ans%mod)

Measured memory_bytes: 81008
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

ll powmod(ll x, ll y)
{
    ll res = 1;
    for (ll i=0; i<y; ++i)
    {
        res = res * x % mod;
    }

    return res;
}

int main()
{
    ll n;
    cin >> n;
    ll ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n);
    ans %= mod;
    ans = (ans+mod) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 3612
S = input()
T = input()
lens = len(S)
lent = len(T)
ans = lent
for i in range(lens-lent+1):
    s = S[i:i+lent]
    count = 0
    for j in range(lent):
        if s[j] != T[j]:
            count+= 1
    ans = min(ans, count)
print(ans)

Measured memory_bytes: 9060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{

	/*
	 * ????????°???????????¨?????????????????????
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// ??????????????°
		int set = Integer.parseInt(br.readLine());
		// ?????¬?????????????????????????????????
		Player isono = new Player("Isono-kun");
		Player nakajima = new Player("Nakajima-kun");

		// ??????????????????????????????????????????????´?
		for (int cnt = 0; cnt < set; cnt++)
			isono.getGesture().add(Action.valueOf(br.readLine()));
		for (int cnt = 0; cnt < set; cnt++)
			nakajima.getGesture().add(Action.valueOf(br.readLine()));

		// ????????????????????????????????????
		for (int turn = 0; turn < set; turn++) {
			// ???????????\????????????2???????????????
			for (int chance = 0; chance < 2; chance++) {
				Player p1 = chance == 0 ? isono : nakajima;
				Player p2 = chance == 0 ? nakajima : isono;

				switch (p2.getGesture().get(turn)) {
				case kougekida:
					// p2????????????0??§???????????¢
					if (p2.getForce() == 0 && !(p1.getGesture().get(turn) == Action.kougekida)) {
						System.out.println(p1.getPlayerName());
						return;
					}
					// ????????¨??????????????¢???????????¨
					if (p1.getGesture().get(turn) == Action.kougekida) {
						if (p1.getForce() > p2.getForce()) {
							System.out.println(p1.getPlayerName());
							return;
						}
					}
					break;

				case tameru:
					if (p1.getGesture().get(turn) == Action.kougekida && p1.getForce() > 0) {
						System.out.println(p1.getPlayerName());
						return;
					}
					break;

				case mamoru:
					if (p1.getGesture().get(turn) == Action.kougekida && p1.getForce() >= 5) {
						System.out.println(p1.getPlayerName());
						return;
					}
					break;
				}
			}
			// ???????????¢?????¨??£?????´??????????????????0?????????
			if (isono.getGesture().get(turn) == Action.kougekida)
				isono.setForce(0);
			if (nakajima.getGesture().get(turn) == Action.kougekida)
				nakajima.setForce(0);
			// ?????????
			if (isono.getGesture().get(turn) == Action.tameru)
				isono.setForce(isono.getForce() + 1);
			if (nakajima.getGesture().get(turn) == Action.tameru)
				nakajima.setForce(nakajima.getForce() + 1);
		}
		System.out.println("Hikiwake-kun");
	}// ?????????????????????????????????
}// ??????????????????????????????

enum Action {
	kougekida, tameru, mamoru
}// Action?????????????????????

/**
 * ?????¬??????????????¶???
 *
 * @author ?????????????????§???
 */
class Player {
	private int force = 0;
	private String PlayerName;
	private List<Action> gesture = new ArrayList<Action>();

	public List<Action> getGesture() {
		return gesture;
	}

	public String getPlayerName() {
		return PlayerName;
	}

	public int getForce() {
		return force;
	}

	public void setForce(int force) {
		this.force = force;
	}

	Player(String name) {
		this.PlayerName = name;
	}
}// Player?????????????????????

Measured memory_bytes: 24508
#include<bits/stdc++.h>
#define int long long
using namespace std;
int N;
int p[214514],memo[214514];
vector<int> ve[214514];
int saiki(int u){
	if(memo[u]!=-1)
		return memo[u];
	if(ve[u].empty()){
		memo[u]=0;
		return 0;
	}
	vector<int> gr;
	for(auto x:ve[u])
		gr.push_back(saiki(x));
	sort(begin(gr),end(gr));
	int v=-1;
	for(auto x:gr){
		if(x-v>1)
			break;
		v=x;
	}
	memo[u]=v+1;
	return v+1;
}
signed main(){
	int i,j;
	cin>>N;
	fill(memo,memo+N,-1);
	for(i=0;i<N;i++){
		cin>>p[i];
		p[i]--;
		ve[p[i]].push_back(i);
	}
	int q[214514]={};
	int u=0;
	while(!q[u]){
		q[u]=1;
		u=p[u];
	}
	fill(q,q+N,0);
	while(!q[u]){
		q[u]=1;
		u=p[u];
	}
	for(i=0;i<N;i++)
		if(!q[i])
			saiki(i);
	vector<int> gr;
	int aaa;
	for(auto x:ve[u])
		if(memo[x]!=-1)
			gr.push_back(memo[x]);
		else
			aaa=x;
	sort(begin(gr),end(gr));
	int v=-1;
	for(i=0;i<gr.size();i++){
		if(gr[i]-v>1)
			break;
		v=gr[i];
	}
	v++;
	int w=v;
	for(;i<gr.size();i++){
		if(gr[i]-w>1)
			break;
		w=gr[i];
	}
	w++;
	int hoge[214514];
	copy(memo,memo+N,hoge);
	memo[u]=v;
	if(saiki(aaa)!=v){
		cout<<"POSSIBLE"<<endl;
		return 0;
	}
	copy(hoge,hoge+N,memo);
	memo[u]=w;
	if(saiki(aaa)==v){
		cout<<"POSSIBLE"<<endl;
		return 0;
	}
	cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 33024
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std ;

int n , m ;
int res;

int main ()
{
	int i ;
	res=-1;
	scanf("%d%d",&n,&m);
	int t=m/n+1;
	for ( i=t ; i>=1 ; i-- ) 
	{
		if ( m%i==0 ) 
		{
			if ( m>=i*n ) 
			{
				res=max(res,i);
				break;
			}
		}
	}
	printf("%d\n",res);
	return 0 ;
}

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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
  string s;
  cin >> s;
  int ans = 0;
  char c = 'R';

  if (s[0] == c && s[1] != c)
    ans = 1;
  else if (s[0] == c && s[1] == c)
  {
    if (s[2] == c)
      ans = 3;
    else
      ans = 2;
  }
  else if (s[1] == c)
  {
    if (s[2] == c)
      ans = 2;
    else
      ans = 1;
  }
  else if (s[2] == c)
    ans = 1;
  else
    ans = 0;
  cout << ans << endl;

}


Measured memory_bytes: 3720
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 9999999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int n , r , c;
int main(){
fcin;
	cin>>n>>r;
	while(n>0){
		n/=r;
		c++;
	}
	cout<<c<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  string s;
  cin>>s;
  int n=s.size();
  int64_t ans=0;
  for(int p=0;p<(1<<n-1);p++){
    int64_t r=0,sum=0;
    for(int i=0;i<n-1;i++){
      string t=s.substr(r,i-r+1);
      if((p>>i)&1){sum+=stoll(t);r=i+1;}
     // cout<<t<<endl;
    }
    sum+=stoll(s.substr(r));
    ans+=sum;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3604
n = int(input())
a = list(map(int, input().split()))
l = {}
r = {}
for i in range(n):
    if i+1+a[i] in l:
        l[i+1+a[i]] += 1
    else:
        l[i+1+a[i]] = 1
        
    if i+1-a[i] in r:
        r[i+1-a[i]] += 1
    else:
        r[i+1-a[i]] = 1

c = 0
for i in range(2, n):
    if i in l and i in r:
        c += l[i]*r[i]
print(c)

Measured memory_bytes: 56908
#include <bits/stdc++.h>
#define DIM 100007
#define INF 1000000007
using namespace std;

long long n,w,v,W,d[107][DIM];

int main()
{
    cin>>n>>W;
    for(int i = 1; i <= n; ++i)
    {
        cin>>w>>v;
        for(int j = 1; j <= W; ++j)
        {
            d[i][j] = d[i-1][j];
            if(j>=w) d[i][j] = max(d[i][j],d[i-1][j-w]+v);
        }
    }
    cout<<d[n][W];
    return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	vector<int> ans(n + 1, 0);
	for(int x = 1; x <= 100; x++)
	{
		for(int y = 1; y <= 100; y++)
		{
			for(int z = 1; z <= 100; z++)
			{
				int cur = x * x + y * y + z * z + x * y + y * z + z * x;
				if(cur <= n)
					ans[cur]++;
			}
		}
	}
	for(int i = 1; i <= n; i++)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	int s, ba;
	cin >> s;
	ba = s;

	map<int, int> m;
	m[ba]++;

	int i = 2;
	while (true) {
		if (ba % 2 == 0) {
			ba = ba / 2;
		}
		else {
			ba = ba * 3 + 1;
		}
		m[ba]++;
		if (m[ba] == 2) {
			COUT(i);
			return 0;
		}
		i++;
	}




	return 0;
}


Measured memory_bytes: 256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()

l=[0,0,0]

mod=10**9+7

ans=1
for i in a:
  l_cnt=l.count(i)
  ans*=l_cnt
  ans%=mod
  for j in range(3):
    if l[j]==i:
      l[j]+=1
      break

print(ans)

Measured memory_bytes: 20656
#include <iostream>
using namespace std;
int citys[500*500]={0};
int main()
{
    int N,M,Q,p,q,i,j,L,R,cnt;

    cin>>N>>M>>Q;
    for(i=0;i<M;i++)
    {
        cin>>L>>R;
        citys[(L-1)*500+R-1]++;
    }
    for(i=0;i<N;i++)
    {
        cnt=0;
        for(j=0;j<N;j++)
        {
            cnt = citys[i*500+j]+cnt;
            citys[i*500+j] = cnt;
        }
    }

    for(i=0;i<Q;i++)
    {
        cin>>p>>q;
        cnt=0;
        for(j=p-1;j<q;j++)
        {
            cnt = cnt+citys[j*500+q-1];
        }
        cout<<cnt<<endl;
    }
    return 0;
}



Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>
long int pwl(int n){
	long int t = 1;
	for(int i = 0; i < n; i++){
		t *= 10;
	}
	return t;
}


int main(){
	long int n, jpy = 0, btc = 0;
	//long double btc = 0;
	std::string str, v, jb;
	std::cin >> n;
	for(int i = 0; i < n; i++){
		std::cin >> v >> jb;
		if(jb == "JPY"){
			jpy += std::stoi(v);
		}else{
			//btc += std::stoi(v);
			int dot;
			for(int j = 0; j < v.size(); j++){
				if(v[j] == '.'){
					dot = j;
				}
			}
			for(int j = 0; j < v.size(); j++){
				if(j < dot){
					btc += (v[j] - '0') * pwl(9 - j + dot - 2);
				}else if(j == dot){
					
				}else{
					btc += (v[j] - '0') * pwl(9 - j + dot - 1);
				}
			}
		}
	}
	//std::cout << jpy << " " << btc << std::endl;
	std::cout << (double)jpy + (double)btc * 0.0038 << std::endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF=1e9+7,MAXN=1e5+1,MAXM=2e5+5;
int N,M;
int f[MAXM],t[MAXM];
int fs[MAXN];
inline int findset(int x){
	return fs[x]==x?x:fs[x]=findset(fs[x]);
}
LL ans,siz[MAXN],as[MAXN];
int main(){
	scanf("%d%d",&N,&M);
	ans=(LL)N*(N-1)/2;
	for(int i=1;i<=N;i++){
		fs[i]=i;
		siz[i]=1;
	}
	for(int i=1;i<=M;i++){
		scanf("%d%d",f+i,t+i);
	}
	for(int i=M;i>=1;i--){
		int ii=findset(f[i]),jj=findset(t[i]);
		as[i]=ans;
		if(ii!=jj){
			ans-=siz[ii]*siz[jj];
			siz[ii]+=siz[jj];
			fs[jj]=ii;
		}
	}
	for(int i=1;i<=M;i++){
		printf("%lld\n",as[i]);
	}
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int sum1=0;
  sort(a,a+n,greater<int>());
  for(int i=0;i<n;i+=2){
    sum1+=a[i];
  }
  int sum2=0;
  for(int i=1;i<n;i+=2){
    sum2+=a[i];
  }
  cout<<sum1-sum2<<endl;
  return 0;
}

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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

using namespace std;
const int N=1e6, mod= 1e9+7;
ll p[N],w[N],v[N],vec[ (1<<21)+1 ];

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	ll a,b,res=1;
	cin>>a>>b; 
	a=__gcd(a,b);
	
	for(ll i=2;i*i<=a;i++){
		if( a%i==0 ){
			while( a%i==0 ){
				a/=i;
			}
			res++;
		}
	}
	if(a>1)res++;
	cout<<res;
	
    yogeshk972();
}



Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc[1000];
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;

int main(){
    cin>>s>>sa>>sb;
    //n=int('a')-int('A');
    C char(s[0]+n)<<char(sa[0]+n)<<char(sb[0]+n) E;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    int n, m;
    cin >> n >> m;
    vector<P> v(n);

    for(int i=0; i<n; i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());

    ll ans = 0;
    ll cnt = m;
    for(int i=0; i<v.size(); i++){
        if(cnt - v[i].second > 0){
            ans += v[i].first * v[i].second;
            cnt -= v[i].second;
        }
        else {
            ans += v[i].first * cnt;
            break;
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        string S = RString();
        int N = S.Length;
        int ans = N;
        for (int i = 0; i < N-1; i++)
        {
            if (S[i] != S[i + 1])
            {
                int v = Max(i + 1, N - 1 - i);
                ans = Min(ans, v);
            }
        }
        WriteLine(ans);
    }
}

class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[0], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[0], typeof(T4));
        return (r1, r2, r3, r4);
    }
}

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

#define N 1000
#define max(a,b) ( a > b ? a : b )

int main(void)
{
    int iii, i, j, m, n;
    char x[N], y[N];
    int table[N+1][N+1];
    int num;
    scanf( "%d", &num );

    for( iii=0; iii<num; ++iii ) {
        scanf( "%s", x );
        scanf( "%s", y );

        m = strlen(x);
        n = strlen(y);

        for( i=0; i<=m; ++i )
            for( j=0; j<=n; ++j )
                table[i][j] = 0;

        for( i=1; i<=m; ++i )
            for( j=1; j<=n; ++j )
                if ( x[i-1] == y[j-1] )
                    table[i][j] = table[i-1][j-1] + 1;
                else
                    table[i][j] = max( table[i][j-1], table[i-1][j] );

        printf( "%d\n", table[m][n] );
    }

    return 0;
}



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

/*int solve(vector<int> v, int i){
if(i>=v.size()-1)return 0;
//if(i>v.size)return v[i-2];
if(dp[i])return dp[i];
else
        if((i+2)<v.size())
             dp[i]=min(abs(v[i]-v[i+1])+solve(v,i+1),abs(v[i]-v[i+2])+solve(v,i+2));
        else dp[i]=abs(v[i]-v[i+1]);

return dp[i];
}*/
int main(){
int n,k;
cin>>n>>k;
vector <int> v(n);
vector<int>dp(n,1e9);
dp[0]=0;
for(auto & it : v)cin>>it;
if(v.size()==1)return 0;
else if(v.size()==2)cout<<abs(v[0]-v[1])<<endl;
else{
        for(int i=0;i<n;i++){
            for(int j=i+1;j<=i+k;j++){
                if(j<n){
                    dp[j]=min(dp[j],dp[i]+abs(v[i]-v[j]));
                }
            }
        }
        cout<<dp[n-1]<<endl;
}

return 0;}


Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		char[][] s=new char[100][40];
		for(int i = 0; i<50; i++){
			Arrays.fill(s[i],'#');
		}
		for(int i = 50; i<100; i++){
			Arrays.fill(s[i],'.');
		}
		for(int i = 0; i<a-1; i++){
			s[(i/20)*2][(i%20)*2]='.';
		}
		for(int i = 0; i<b-1; i++){
			s[99-(i/20)*2][(i%20)*2]='#';
		}
		System.out.println(100+" "+40);
		for(int i = 0; i<100; i++){
			for(int j = 0; j<40; j++){
				System.out.print(s[i][j]);
			}	
			System.out.println();
		}
	}
}


Measured memory_bytes: 25684