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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int nax = 1e5 + 5;

// ll fact[nax], invfact[nax];

// void pre()
// {
// 	fact[0] = 1;
// 	forn(i, 1, nax)
// 	{
// 		fact[i] = mult(fact[i - 1], i);
// 	}

// 	invfact[nax - 1] = mypow(fact[nax - 1], mod - 2);

// 	ford(i, nax, 1)
// 	{
// 		invfact[i - 1] = mult(invfact[i], i);
// 	}
// }

// ll ncr(ll n, ll r)
// {
// 	if (r > n)
// 		return 0;

// 	ll ans = mult(fact[n], mult(invfact[n - r], invfact[r]));

// 	return ans;
// }

int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	set<ll>S[26];
	while (t--)
	{
		ll n;
		cin >> n;

		string str;
		cin >> str;

		forn(i, 1, n + 1)
		{
			S[str[i - 1] - 'a'].insert(i);
		}

		ll q;
		cin >> q;

		while (q--)
		{
			ll query;
			cin>>query;
			if (query == 1)
			{
				ll idx;
				string x;
				cin >> idx >> x;
				S[str[idx - 1] - 'a'].erase(idx);
				str[idx - 1] = x[0];
				S[str[idx - 1] - 'a'].insert(idx);
			}
			else
			{
				ll l, r, cnt = 0;
				cin >> l >> r;
				forn(i, 0, 26)
				{
					auto L = S[i].lb(l);
					if (L != S[i].end() && (*L <= r))
					{
						++cnt;
					}
				}
				cout << cnt << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 24220
import java.util.*; 
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        String s = sc.next(), t = sc.next();
 
        long l = calc(n, m);
        int x = (int)(l / m);
        int y = (int)(l / n);
 
        boolean bl = true;
        for(int i = 0; i * x < n; i++){
            if(s.charAt(i * x) != t.charAt(i * y)){
                System.out.println(-1);
                bl = false;
                break;
            }
        } 
        if(bl)
            System.out.println(l);
 
    }
    static long calc (int n, int m)
    {
        int a = Math.max(n, m);
        int b = Math.min(n, m);
        int tmp = a;
        while(a % b != 0){
            int c = a;
            a = b;
            b = c % b;
        }
        return (long) n * m / b;
    }
 }




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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  for (ll i = 0; i < s.size(); ++i) {
    cout << "x";
  }
  cout << endl;

  return 0;
}

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

#define MAX   100
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY  1
#define BLACK 2

int n, M[MAX][MAX];

int prim() {
  int d[MAX], p[MAX], color[MAX];
  int u, minv;

  for ( int i = 0; i < n; i++ ) {
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while ( 1 ) {
    minv = INFTY;
    u = -1;
    for ( int i = 0; i < n; i++ ) {
      if ( minv > d[i] && color[i] != BLACK ) {
        u = i;
        minv = d[i];
      }
    }
    if ( u == -1 ) break;
    color[u] = BLACK;
    for ( int v = 0; v < n; v++ ) {
      if ( color[v] != BLACK && M[u][v] != INFTY ) {
        if ( d[v] > M[u][v] ) {
          d[v] = M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }

 int sum = 0;
  for ( int i = 0; i < n; i++ ) {
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }

  return sum;
}


int main() {
  cin >> n;

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      int e;
      cin >> e;
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }

  cout << prim() << endl;

  return 0;
}

Measured memory_bytes: 3092
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

struct edge {
    int from, to;
};

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 1E+05;

int N;

ll dp[MAX_N + 1][2];

vector<edge> G[MAX_N + 1], T[MAX_N + 1];
void makeTree(int s, int prev);
ll paintTree(int s, int j);

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

    cin >> N;

    for (int i = 0; i < N - 1; i++) {
        int s, t;
        cin >> s >> t;
        edge es = { s, t };
        G[s].push_back(es);
        edge et = { t, s };
        G[t].push_back(et);
    }

    makeTree(1, -1);

    memset(dp, -1, sizeof(dp));

    cout << (paintTree(1, 0) + paintTree(1, 1)) % MOD << "\n";

    return 0;
}

ll paintTree(int s, int j)
{
    if (dp[s][j] != -1) {
        return dp[s][j];
    }
    if (T[s].size() == 0) {
        return dp[s][j] = 1;
    }
    ll res = 1;
    for (int i = 0; i < T[s].size(); i++) {
        edge e = T[s][i];
        if (j) {
            res = (res * paintTree(e.to, 0)) % MOD;
        } else {
            res = (res * (paintTree(e.to, 1) + paintTree(e.to, 0)) % MOD) % MOD;
        }
    }
    return dp[s][j] = res;
}

void makeTree(int s, int prev)
{
    for (int i = 0; i < G[s].size(); i++) {
        edge e = G[s][i];
        if (e.to != prev) {
            T[s].push_back(e);
            makeTree(e.to, s);
        }
    }
    return;
}

Measured memory_bytes: 22948
#include<bits/stdc++.h>
#define ll long long
#define w cout 
#define e endl

using namespace std;

int main() {
	int a , b;
	cin >> a >> b;
	int max_1 = b + b - 1;
	int max_2 = a + a - 1;
	int max_3 = a + b ;
	cout << max(max_1 , max(max_2 ,max_3));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,j,k) for(int i=j;i<k;++i)
int main(){
	string str;
	while(true) {
		cin >> str;
		if(str == "#"){
			break;
		}
		
		reverse(str.begin(),str.end());

		vector < int > arr;
		int idx = 0;
		while(idx <  str.size()) {
			if(str[idx] == 'h'){
				idx += 5;
				arr.push_back(0);
			}
			else{
				idx += 4;
				arr.push_back(1);
			}
		}
		int a = arr[0]==0? 0 : 90;
		a *= 1<<20;
		int prev = arr[0];
		int t = 1<<20;
		reps(i,1,arr.size()){
			if(arr[i] == 0) {
				a -= 90 * (t>>i);
			}
			else{
				a += 90 * (t>>i); 			
			}
		}
		int s = __gcd(t,a);
		if(t == s){
			cout << a/s << endl;
		}
		else cout << a/s << "/" << t/s << endl;
	}	
	return 0;
}

Measured memory_bytes: 3136
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toInt() }



    var answer = 1L;
    val MOD = 1000000000L +7L
    val p = PriorityQueue(A)

    if (N % 2 == 1) {
        val head = p.poll()
        if (head != 0) {
            println(0)
            return
        }
    }
    while (!p.isEmpty()) {
        val a = p.poll()
        val b = p.poll()

        if (a != b) {
            println(0)
            return
        }
        answer = answer * 2 % MOD
    }

    println(answer)
}

Measured memory_bytes: 51644
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = 998244353;
const int N = (int)2e5 + 5;
int cnt;
void solve(){
	string s;
	cin>>s;
	rep(i,sz(s))if(i%2==0)cout<<s[i];

}


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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);
//const int INF=(1<<29);

int main(){
  int h,w;
  cin >> h >> w;
  map<char, int> mp;
  REP(i,h*w){
    char a;
    cin >> a;
    mp[a]++;
  }

  int c1,c2,c4;
  if(h%2==1 && w%2 == 1){
    c1 = 1;
    c2 = (h/2)+(w/2);
    c4 = (h/2)*(w/2);
  }else if(h%2==0 && w%2==0){
    c1 = 0;
    c2 = 0;
    c4 = h*w/4;
  }else if(h%2==0){
    c1 = 0;
    c2 = h/2;
    c4 = (h/2)*(w/2);
  }else{
    c1 = 0;
    c2 = w/2;
    c4 = (h/2)*(w/2);
  }
//  cout << c1 << c2 << c4 << endl;
  REP(i,c1){
    for(auto &v: mp){
      if(v.second % 4 == 1 || v.second % 4 == 3){
        v.second--;
        break;
      }
    }
  }

  REP(i,c2){
    bool ok=false;
    for(auto &v: mp){
      if(v.second % 4 == 2){
        v.second-=2;
        ok=true;
        break;
      }
    }
    
    if(ok)continue;

    for(auto &v: mp){
      if(v.second > 0 && v.second % 4 == 0){
        v.second-=2;
        ok=true;
        break;
      }
    }
  }

  REP(i,c4){
    for(auto &v: mp){
      if(v.second > 0 && v.second % 4 == 0){
        v.second-=4;
        break;
      }
    }
  }


  bool ok=true;
  for(auto &v: mp){
    if(v.second != 0){
      ok=false;
      break;
    }
  }

  cout << (ok ? "Yes" : "No" ) << endl;


}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

/*

軽い橋から潤に採用していき、Union-findしていく

各連結成分についてこれらをおぼえておく
・島のコストの和
・保留中の橋の個数

つなぐ時、今つないだ橋のコストが島のコストの和以下だったら
その連携成分は生きになる
その連結成分で保留中の橋は一気に確定になる

*/

class Edge{
	Node node1;
	Node node2;
	long value;
	this(Node node1, Node node2, long value){
		this.node1 = node1, this.node2 = node2;
		this.value = value;
	}
}

class Node{
	long id;
	long value;
	Group group;
	this(long id, long value){
		this.id = id;
		this.value = value;
	}
}

class Group{
	long value;
	long pendingEdgeCount;
	long id;
	Node[] nodes;
	this(Node node){
		this.id = node.id;
		this.nodes = [node];
		this.value = node.value;
	}
	void eat(Group gp){
		if(gp.nodes.length > this.nodes.length) gp.eat(this);
		else{
			foreach(nd; gp.nodes){
				this.nodes ~= nd;
				nd.group = this;
				this.value += nd.value;
			}
			this.pendingEdgeCount += gp.pendingEdgeCount;
		}
	}
}

void main(){
	long n = read.to!long;
	long m = read.to!long;
	
	Node[] nodes;
	foreach(i; 0 .. n){
		long x = read.to!long;
		nodes ~= new Node(i, x);
	}
	
	foreach(nd; nodes){
		nd.group = new Group(nd);
	}
	
	Edge[] edges;
	foreach(i; 0 .. m){
		long a = read.to!long - 1;
		long b = read.to!long - 1;
		long y = read.to!long;
		
		edges ~= new Edge(nodes[a], nodes[b], y);
	}
	
	edges.sort!"a.value<b.value"();
	
	long edgecount;
	foreach(ed; edges){
		if(ed.node1.group.id != ed.node2.group.id){
			ed.node1.group.eat(ed.node2.group);
		}
		ed.node1.group.pendingEdgeCount += 1;
		if(ed.value <= ed.node1.group.value){
			edgecount += ed.node1.group.pendingEdgeCount;
			ed.node1.group.pendingEdgeCount = 0;
		}
	}
	
	(m - edgecount).writeln;
	
}


Measured memory_bytes: 46328
N, M = map(int, input().split())
A = [int(s) for s in input().split()]
A.sort(reverse=True)
BC = []
for _ in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
BC.sort(key=lambda x: x[1], reverse=True)

num = 0
i = 0
j = 0
ans = 0
while num < N:
    if j >= M:
        ans += sum(A[i:i + N - num])
        break
    if i < N and A[i] >= BC[j][1]:
        ans += A[i]
        num += 1
        i += 1
    elif num + BC[j][0] >= N:
        ans += (N - num) * BC[j][1]
        break
    else:
        ans += BC[j][0] * BC[j][1]
        num += BC[j][0]
        j += 1
print(ans)


Measured memory_bytes: 22508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll len(ll n)
{
    return (1LL << n + 2) - 3;
}

ll rec(ll n, ll x)
{
    ll bur = len(n);
    ll patt = (1LL << n + 1) - 1;
    if (x == bur) return patt;

    ll ans = 0;
    x--;
    if (x > 0)
    {
        ll l = min(x, len(n - 1));
        ans += rec(n - 1, l);
        x -= l;
    }
    if (x > 0)
    {
        ans++;
        x--;
    }
    if (x > 0)
    {
        ll l = min(x, len(n - 1));
        ans += rec(n - 1, l);
        x -= l;
    }
    return ans;
}

int main()
{
    ll n, x; cin >> n >> x;
    //COUT(len(1));
    cout << rec(n, x) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
  int n,l,a[100000],p=0;
  scanf("%d %d",&n,&l);
  for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
  for(int i=1;i<n;i++){
    if(a[i-1]+a[i]>=l){
      printf("Possible\n");
      p=i;
      break;
    }
  }
  if(!p)
    printf("Impossible\n");
  else{
    for(int i=1;i<p;i++)
      printf("%d\n",i);
    for(int i=n-1;i>p;i--)
      printf("%d\n",i);
    printf("%d\n",p);
  }
}

Measured memory_bytes: 1152
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] P = new int[N];

        int sum = 0;
        for (int i = 0; i < N; i++) {
            P[i] = sc.nextInt();
        }

        int min = Integer.MAX_VALUE;
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            if (min >= P[i]) {
                min = P[i];
                cnt++;
            }
        }

        System.out.println(cnt);
        return;
    }

}

Measured memory_bytes: 65668
#include<bits/stdc++.h>
using namespace std;
#define l long
#define ll long long
#define nitro ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define PI 3.141592653589793238
int main()
{
    nitro
    ll int n,m,s=0;cin>>n>>m;
    ll int a[m];
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    if(n-s>=0) cout<<n-s;
    else cout<<"-1";
    return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int N,n[8];
string s;

int main(){
	cin>>N;
	while(cin>>s){
		for(int i=0;i<8;i++)n[i]=s[i]-'0';
		sort(n,n+8);
		int M=0,m=0;
		for(int i=0;i<8;i++){
			M+=n[i]*pow(10,i);
			m+=n[7-i]*pow(10,i);
		}
		cout<<M-m<<endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
	while(1){
		int n;
		scanf(" %d", &n);
		if(n==0) break;
	
		string s;
		int d[6]={1,2,3,4,5,6};
		long ans=1;
		
		for(int i=0; i<n; ++i){
			cin >> s;
			
			int tmp;
			if(s=="North"){
				tmp=d[0];
				d[0]=d[1];
				d[1]=d[5];
				d[5]=d[4];
				d[4]=tmp;
				
				ans+=d[0];
			}
			else if(s=="East"){
				tmp=d[0];
				d[0]=d[3];
				d[3]=d[5];
				d[5]=d[2];
				d[2]=tmp;
				
				ans+=d[0];
			}
			else if(s=="West"){
				tmp=d[0];
				d[0]=d[2];
				d[2]=d[5];
				d[5]=d[3];
				d[3]=tmp;
				
				ans+=d[0];				
			}
			else if(s=="South"){
				tmp=d[0];
				d[0]=d[4];
				d[4]=d[5];
				d[5]=d[1];
				d[1]=tmp;
				
				ans+=d[0];
			}
			else if(s=="Right"){
				tmp=d[1];
				d[1]=d[2];
				d[2]=d[4];
				d[4]=d[3];
				d[3]=tmp;
				
				ans+=d[0];
			}
			else if(s=="Left"){
				tmp=d[1];
				d[1]=d[3];
				d[3]=d[4];
				d[4]=d[2];
				d[2]=tmp;
				
				ans+=d[0];
			}
			
			//printf("now:%d\n", d[0]);
		}
		
		printf("%ld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1248
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long P = 10^^9+7;
long[10^^5*2+10] F, RF;

void init()
{
    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long comb(N)(N n, N k)
{
    auto n_b = F[n];    // n!
    auto nk_b = RF[n-k]; // 1 / (n-k)!
    auto k_b = RF[k];    // 1 / k!

    auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!

    return (n_b * nk_b_k_b) % P;  // n! / (n-k)!k!
}

void main()
{
    init();
    auto nmk = readln.split.to!(long[]);
    auto N = nmk[0];
    auto M = nmk[1];
    auto K = nmk[2];

    long r;
    foreach (long d; 1..N) {
        auto x = (((N-d)*M^^2)%P*d)%P;
        if (K == 2) {
            r = (r+x)%P;
        } else {
            auto y = comb(N*M-2, K-2);
            r = (r + (x*y)%P)%P;
        }
    }
    foreach (long d; 1..M) {
        auto x = (((M-d)*N^^2)%P*d)%P;
        if (K == 2) {
            r = (r+x)%P;
        } else {
            auto y = comb(N*M-2, K-2);
            r = (r + (x*y)%P)%P;
        }
    }
    writeln(r);
}

Measured memory_bytes: 3452
#include <iostream>
int main(){
    int r, d, x;
    std::cin >> r >> d >> x;
    for(int i=0; i<10; ++i){
        int ans,tmp;
        if(i == 0) tmp = x;
        ans = r * tmp - d;
        std::cout << ans << std::endl;
        tmp = ans;
    }
    return 0;
}

Measured memory_bytes: 256
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,x,t=map(int,input().split())

print(celi(n,x)*t)

Measured memory_bytes: 68192
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='A'){
      for(int j=s.size()-1;j>=0;j--){
        if(s.at(j)=='Z'){
          cout << j-i+1 << endl;
          return 0;
         }
      }
    }
  }
}

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

long gcd(long a, long d){ // この問題の答えは全てのT[i]で割り切れる最小公倍数
 if(d==0){return a;}  // a*b=gcd(a, b)*lcm(a, b)という公式を使う
  return gcd(d, a%d);   // gcdはa, dの最大公約数を求める関数
}

long lcm(long a, long d){ // lcmはa, dの最小公倍数を求める関数
 return a/gcd(a, d)*d; // 上記のa*b=gcd(a, b)*lcm(a, b)を変形した式
}

int main(){
long N;
  cin>>N;
  
  long a;
  cin>>a;
  for(long i=1; i<N; i++){
   long d;
    cin>>d;
    a=lcm(a, d); // 初期値をaとして、入力される全ての数値との最小公倍数を算出する
  }
  
  cout<<a;
}

Measured memory_bytes: 256
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
 
#define int long long
#define F first
#define S second
#define sz(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int >
#define E cout << '\n'

#ifdef LOCAL
#define cerr cout
#else
#endif
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int mod = 1e9 + 7;
const int N = 4e5 + 5;

inline int add(int x, int y, int mod = mod) {
   if (x >= mod) x %= mod;
   if (y >= mod) y %= mod;
   x  += y;
   return (x >= mod ? x - mod : x);
} 
inline int mul(int x, int y, int mod = mod) {
  if (x >= mod) x %= mod;
  if (y >= mod) y %= mod;
  return (x*y) % mod;
}
inline int sub(int x, int y, int mod = mod) {
  x -= y;
  if (x + mod <= 0) {
    x %= mod;
  }
  return (x < 0 ? x+mod : x);
}
int po(int x, int n, int mod = mod) {
  int res = 1;
  for (;n > 0;) {
    if (n & 1) {
      res = mul(res, x, mod);
    }
    x = mul(x, x, mod);
    n /= 2;
  }
  return res;
}

int get(vector<int> &v, int val) {
  int n = v.size()-1, ok = (1LL<<val)%mod;
  int x = 0, y = 0, ans = 0;
  for (int &i: v)x += (i==1), y += (i==0);
  for (int &i: v) {
    x -= i==1;
    y -= i==0;
    if (i == 0)
      ans = add(ans, mul(x, ok));
    else 
      ans = add(ans, mul(y, ok));
  }
  return ans;
}
 
inline void solve() {
   int n, x, ans(0);
   cin >> n;
   vector<int>v(n);
   for (int &x: v) cin >> x;
   for (int i = 0; i < 60; ++i) {
    vector<int> tmp;
    for (int &x: v)
      tmp.push_back(((1LL<<i)&x)>0);
    ans = add(ans, get(tmp, i));
   }
   cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL); 
  //int t = 1;cin >> t; while(t--)
  solve();
  E;
  return 0;
}

Measured memory_bytes: 10892
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
#include <set>

typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


/*
 * 最大公約数計算
 */
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll R;
	cin >> R;
	
		cout << 2 * 3.14159265358979323846 * R << endl;

	

	return 0;

}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string date;
    cin >> date;
    string ans = count(ALL(date), '9') > 0 ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;

template <typename T>
void __dump__(std::ostream &os, const T &first) {
    os << first;
}
template <typename First, typename... Rest>
void __dump__(std::ostream &os, const First &first, const Rest &... rest) {
    os << first << ", ";
    __dump__(os, rest...);
}
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)


int n, m;
vector<int> x, y;

int calc(vector<int> x) {
    int n = x.size();
    int S = 0;
    for (int i = 1; i < (int)x.size(); ++i) {
        int w = x[i] - x[i-1];
        int s = w * i % MOD * (n - i) % MOD;
        S += s;
        S %= MOD;
    }
    return S;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(cin >> n >> m){
        x.resize(n);
        y.resize(m);
        rep(i, n) cin >> x[i];
        rep(i, m) cin >> y[i];
        sort(all(x));
        sort(all(y));
        x.erase(unique(all(x)), x.end());
        y.erase(unique(all(y)), y.end());

        n = x.size();
        m = y.size();
        auto sx = calc(x);
        auto sy = calc(y);
        cout << sx*sy % MOD << endl;
    }
}


Measured memory_bytes: 2672
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}

int main(){
  ll h,ans=0;
  cin>>h;
  /*
  ll t=pow(2,h/2+1)-1;
  cout<<t<<endl;
*/

  while(h>0){
  ans+=1;
    h/=2;
  }
  ll r=pow(2,ans)-1;
  cout<<r<<endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			long n = sc.nextLong();
			long sum = 0;
			long cur=0;
			
			for(int i=1;sum<n;i++) {
				sum += i;
				cur = i;
			}
			
			for(int i=1;i<=cur;i++) {
				if(i!=sum-n) {
					System.out.println(i);
				}
			}
			
	    }
		
		
	}
	


Measured memory_bytes: 37304
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
typedef pair< int, int > ii;
typedef vector< ii > vii;

void solve(){
	int n, k; cin>>n>>k;
	vector< int > v(n);
	for(int &i : v) cin>>i;
	sort(v.begin(), v.end());
	int ans = 0;
	for(int i = 0; i<k; i++){
		ans += v[i];
	}
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



Measured memory_bytes: 3640
function Main(input) {
    var K = parseInt(input[0], 10);
    var S = input[1];
    
    if (S.length > K) {
        console.log(`${S.substring(0, K)}...`);
    } else {
        console.log(S);
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 29636
/**
 *    author:  tesnik      
**/
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    if (((a == b) && (a != c)) || ((b == c) && (b != a)) || ((a == c) && (a != b))) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
const lli INF = 1e18L + 5;
const int MOD = 1000000007;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int H, W;
    cin >> H >> W;
    vector<vector<lli>> dp(H+1,vector<lli> (W+1,0));

    dp[1][1] = 1;
    for(int i = 1; i <= H ; ++i){
        for(int j = 1 ; j <= W ; ++j){
            char a; cin >> a;
            if(i == 1 && j == 1) continue;
            if(a == '.') dp[i][j] = (dp[i-1][j]%MOD + dp[i][j-1]%MOD) % MOD;
            else dp[i][j] = 0;
        }
    }
    cout << dp[H][W] << '\n';
    return 0;
}

Measured memory_bytes: 8192
INF = 10**10
 
def main():
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
 
    dp = [INF]*n
    dp[0] = 0
 
    for i in range(1,n):
        from_ = max(i-k, 0)
        dp[i] = min(d + abs(hs[i]-h) for d, h in zip(dp[from_:i], hs[from_:i]))
    print(dp[-1])
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 13976
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int n, k;
	cin >> n >> k;
    vector<int> p(n), cum(n+1);
    rep(i,n) {
        cin >> p[i];
        cum[i+1] = cum[i] + p[i];
    }
    int sum = 0;
    rep(i,n-k+1) sum = max(sum, cum[i+k] - cum[i]);
    double ans = sum + k;
    ans /= 2;
    printf("%.10f\n", ans);
    // cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int n , i , k , j;
    cin >> n >> k;
    long long int a[n] , dp[n];
    for(i = 0 ; i < n ; i++){
        cin >> a[i];
        dp[i] = 1e12;
    }
    dp[0] = 0;
    for(i = 1 ; i < n ; i++){
        for(j = i - 1 ; j >= max(0LL , i - k) ; j--){
            dp[i] = min(dp[i] , abs(a[i] - a[j]) + dp[j]);
        }
    }
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1792
while (line = gets)
  x1, y1, x2, y2, xq, yq = line.chomp.split(",").map{|s| s.to_f}

  vx = x2 - x1
  vy = y2 - y1

  m00 = vx
  m01 = vy
  w0 = xq * vx + yq * vy
  m10 = vy
  m11 = -vx
  w1 = vy * (2 * x1 - xq) - vx * (2 * y1 - yq)

  if m00.abs < m01.abs
    t = m00; m00 = m10; m10 = t
    t = m01; m01 = m11; m11 = t
    t = w0; w0 = w1; w1 = t
  end

  m01 /= m00; w0 /= m00; m00 = 1.0
  m11 -= m01 * m10; w1 -= w0 * m10; m10 = 0.0

  y = w1 / m11
  x = w0 - m01 * y

  printf("%.6f %.6f\n", x, y)
end

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

#define ll long long int

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    ll m = s.length();
    ll n = t.length();
    string ans = "";
    vector<vector<ll>> dp = vector<vector<ll>>(m + 1, vector<ll>(n + 1, 0));
    for (ll i = 1; i <= m; i++)
    {
        char chm = s.at(i - 1);
        for (ll j = 1; j <= n; j++)
        {
            char chn = t.at(j - 1);
            ll up = dp[i - 1][j];
            ll left = dp[i][j - 1];
            if (chn == chm)
            {
                dp[i][j] = dp[i - 1][j - 1] +1;                   
            }
            else
            {
                dp[i][j] = max(up, left);
            }
        }
    }
    ll x = dp[m][n];
    ll i = m;
    ll j = n;
    while (x != 0) {
        ll u = dp[i - 1][j];
        ll l = dp[i][j - 1];
        if (u != x && l != x) {
            ans = s.at(i - 1) + ans;
            i--;
            x = dp[i][j];
        }
        else if (l == x) {
            j--;
            x = dp[i][j];
        } else {
            i--;
            x = dp[i][j];
        }
    } 
    cout << ans;
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#include <limits>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define lli long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define um unordered_map
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define mem(data_structure, val) memset(data_structure, val, sizeof(data_structure))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl "\n"
const ll mod = 1e9+7;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 
um<pii, int, hash_pair> map_with_pair{};
priority_queue <int, vector<int>, greater<int> > pq_desc; // decreasing order

lli minCost(int n, lli *h) {
	lli cost[n];
	cost[0] = 0;
	cost[1] = abs(h[0]-h[1]);
	Fo(i, 2, n) {
		cost[i] = min(cost[i-1]+abs(h[i-1]-h[i]), cost[i-2]+abs(h[i-2]-h[i]));
	}
	return cost[n-1];
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	lli h[n];
	fo(i, n) cin >> h[i];

	lli ans = minCost(n, h);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
n = int(input())                                                                          
ls_s = list(map(int,input().split()))                                                     
q = int(input())                                                                          
ls_t = list(map(int,input().split()))                                                     
                                                                                          
ls_ch = []                                                                                
cnt = 0                                                                                   
for i in range(n):                                                                        
    flag = 0                                                                              
    for j in range(len(ls_ch)):                                                           
        if ls_s[i] == ls_ch[j]:                                                           
            flag = 1                                                                      
            break                                                                         
    if flag == 1:                                                                         
        continue                                                                          
    for j in range(q):                                                                    
        if ls_s[i] == ls_t[j]:                                                            
            cnt += 1                                                                      
            ls_ch.append(ls_s[i])                                                         
            break                                                                         
                                                                                          
print(cnt)  


Measured memory_bytes: 6552
def main():
    height, width = map(int, input().split())
    grid = [list(input()) for _ in range(height)]
    dp = [[float("inf") for _ in range(width)] for _ in range(height)]
    if grid[0][0] == "#":
        dp[0][0] = 1
    else:
        dp[0][0] = 0
    delta = [[0, 1], [1, 0]]
    for i in range(height):
        for j in range(width):
            for dx, dy in delta:
                if i + dy >= height or j + dx >= width:
                    continue
                else:
                    add = 0
                    if grid[i][j] == "." and grid[i + dy][j + dx] == "#":
                        add = 1
                    dp[i + dy][j + dx] = min(dp[i + dy][j + dx], dp[i][j] + add)
    print(dp[-1][-1])


if __name__ == '__main__':
    main()



Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

ll c[10][10];
int main(void){
    ll n;
    cin >> n;

    ll count = 0;

    rep(i, 1, n + 1){
        string tmp = to_string(i);
        c[int(tmp[0]) - int('0')][int(tmp[tmp.size() - 1]) - int('0')]++;
    }

    rep(i, 0, 10){
        rep(j, 0, 10){
            count += c[i][j] * c[j][i];
        }
    }


    cout << count << endl;
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(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 RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int MAX = 10001;

struct init{
    init(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
} init;

int y;
int m;
int d;
char l;


void input(){
  std::cin >> y >> l >> m >> l >> d;
}


int main(int argc, char const *argv[]) {
  input();
  if (m >= 5) {
    std::cout << "TBD" << '\n';
  } else {
    std::cout << "Heisei" << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
def resolve():
    I = input()
    L = [int(c) for c in I]
    # bit全探索
    # https://qiita.com/gogotealove/items/11f9e83218926211083a#%E4%BE%8B%E9%A1%8C-1
    for i in range(2 ** 3):
        val=L[0]
        ans=[]
        for j in range(3):  # このループが一番のポイント
            if ((i >> j) & 1):
                val+=L[j+1]
                ans.append('+')
            else:
                val-=L[j+1]
                ans.append('-')
                # 順に右にシフトさせ最下位bitのチェックを行う
        if val==7:
            for k in range(3):
                print('{}{}'.format(L[k],ans[k]),end='')
            print('{}=7'.format(L[3]))
            break





resolve()

Measured memory_bytes: 38256
sx, sy, tx, ty = [int(x) for x in input().split()]
dx=tx-sx
dy=ty-sy
print('R'*dx+'U'*dy+'L'*dx+'D'*(dy+1)+'R'*(dx+1)+'U'*(dy+1)+'L'+'U'+'L'*(dx+1)+'D'*(dy+1)+'R')


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<set>
#include<stack>
#include<queue>
#include<sstream>
#include<iomanip>

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}

template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", ";
	return out << "}" << endl;
}

#define N 30
double d[N+1][N][N];
// -time, from, current, speed
struct elem{
	double t;
	int f,c,s;
	elem(){};
	elem(double time, int from, int cur, int sp){
		t = time; f = from; c = cur; s = sp;
	}
	bool operator<(const elem r) const{ return mk(mk(t, f),mk(c,s)) < mk(mk(r.t,r.f), mk(r.c,r.s)); }
};
ostream &operator<<(ostream &out, const elem &e){
	return out << "{" << e.t << ", " << e.f << ", " << e.c << ", " << e.s << "}";
}


#define INF (1e12)
int main(){
	int n, m, s, g;
	while(cin >> n >> m, n){
		cin >> s >> g;
		s--; g--;
		fill(d[0][0], d[0][0] + (N+1) * N * N, INF);
		vector<pair<int,double> > e[N+2][N];// e[c][x] : from x at vert c : (to, time) list
		rep(i, m){
			int x, y, di, c;
			cin >> x >> y >> di >> c;
			x--; y--;
			reps(j,1,c+1){
				double time = di / (double) j;
				e[j][x].pb(mk(y, time));
				e[j][y].pb(mk(x, time));
			}
		}
		priority_queue<elem> q;
		q.push(elem(-0.0, -1, s, 0));//initial state
		while(!q.empty()){
			elem el = q.top();
			double dst = - el.t;
			int from = el.f, cur = el.c, sp = el.s;
			q.pop();
			if(from>=0){
				if(d[sp][cur][from] < INF) continue;
//				if(d[sp][cur][from] < dst) continue;
				d[sp][cur][from] = dst;
			}
//			cout << el << endl;
//			if(sp == 1 && cur == g) break;
			rep(i,3){
				int ci = sp - 1 + i;
				if(ci<1 || ci > N) continue;
				rep(j, e[ci][cur].size()){
					pair<int, double> p = e[ci][cur][j];
					int to = p.fs;
					if (from == to) continue;
					double tmp = dst + p.sc;
					q.push(elem(-tmp, cur, to, ci));
				}
			}
		}
/*		reps(i, 1, N+1){
			cout << "v : " << i << endl;
			rep(j, n) cout << d[i][j] << ", ";
			cout << endl;
		}
*/
		double ans = INF;
		rep(i,n) ans = min(ans, d[1][g][i]);
		if(ans >= INF) cout << "unreachable" << endl;
		else cout <<fixed << setprecision(10)<< ans << endl;
	}
	return 0;
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

vector<string> a, b;

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    int n, m;

    cin >> n >>m;

    for(int i = 0; i < n; ++i){
        string c;
        cin >> c;
        a.push_back(c);
    }

    for(int i = 0; i < m; ++i){
        string c;
        cin >> c;
        b.push_back(c);
    }

    for(int x = 0; x <= n - m; ++x){
        for(int y = 0; y <= n - m; ++y){
            bool found = true;
            for(int i = 0; i < m; ++i){
                for(int j = 0; j < m; ++j){
                    if(a[x + i][y + j] != b[i][j]){
                        found = false;
                        break;
                    }
                }
            }
            if(found){
                cout << "Yes";
                return 0;
            }
        }
    }

    cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<set>
#define lowbit(x) ((x)&(-x))
using namespace std;
const int maxn = 2e5+5;
const int mod = 1e9+7;
int add(int x,int y) {
	x+=y; return x>=mod?x-mod:x;
}
int sub(int x,int y) {
	x-=y; return x<0?x+mod:x;
}
int bit[maxn];
int n,m;
int ha[maxn],cnt;
int gsum(int x) { int sm=0; for(;x;x-=lowbit(x))sm=add(sm,bit[x]); return sm; }
void adds(int x,int d) { for(;x<=cnt;x+=lowbit(x)) bit[x]=add(bit[x],d); }
struct node{
	int x,y;
}z[maxn]; int tot;

int gid(int x) {
	return lower_bound(ha+1,ha+1+cnt,x)-ha;
}
bool cmp(node aa,node bb) {
	if(aa.x!=bb.x)return aa.x < bb.x;
	return aa.y>bb.y;
}
set<int>se;
int a[maxn],b[maxn];
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=m;i++) scanf("%d",&b[i]),se.insert(b[i]);
	for(int i=1;i<=n;i++) {
		if(a[i]<=b[1]||a[i]>=b[m]||se.count(a[i])) continue;
		int pr = (lower_bound(b+1,b+1+m,a[i])-b); int pl = pr-1;
		z[++tot] = (node) {a[i] - b[pl] , b[pr] - a[i] };
		ha[++cnt] = b[pr]-a[i];
	}
	sort(z+1,z+1+tot,cmp);
	sort(ha+1,ha+1+cnt);
	cnt = unique(ha+1,ha+1+cnt)-ha-1;
	int ans = 1;
	for(int i=1;i<=tot;i++) {
		if(z[i].x==z[i-1].x&&z[i].y==z[i-1].y) continue;
		int ff = add(gsum(gid(z[i].y)-1),1);
		ans = add(ans,ff);
		adds(gid(z[i].y),ff);
	}
	printf("%d",ans);
}

Measured memory_bytes: 8192
n, k = map(int, input().split())
d = []
a = set()
for _ in range(k):
    d.append(int(input()))
    for p in list(map(int, input().split())):
        a.add(p)

a_all = set(i+1 for i in range(n))

print(len(set(a_all)-set(a)))

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
int ans = 1;
for(int i = 2;i < x;i++){
int hoge = i*i;
  while(hoge <= x){
    ans = max(ans,hoge);

    hoge *= i;


  }
} 
cout<< ans <<endl;
}

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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String[] tmpArray = br.readLine().split(" ");
			
			int oldRate = Integer.parseInt(tmpArray[0]);
			int newRate = Integer.parseInt(tmpArray[1]);
			int sum = Integer.parseInt(tmpArray[2]);
			
			if(oldRate == 0 && newRate == 0 && sum == 0){
				break;
			}
			
			int newSumMax = 0;
			for(int i = 1; i <= sum - 1 ; i++){
				for(int j = 1; j <= sum - 1; j++){
					if(addTax(i, oldRate) + addTax(j, oldRate) == sum){
						int tmpNewSum = addTax(i, newRate) + addTax(j, newRate);
						if(newSumMax < tmpNewSum){
							newSumMax = tmpNewSum;
						}
					}
				}
			}
			
			System.out.println(newSumMax);
		}
	}
	
	static int addTax(int price, int rate){
		return price * (100 + rate) / 100;
	}

}

Measured memory_bytes: 25256
D, G = list(map(int, input().split()))
prob = [list(map(int, input().split())) for i in range(D)]

min_count = 1e9

for mask in range(1<<D):
    count = 0
    score = 0
    rest = -1
    for i in range(D):
        if((mask>>i) & 1):
            score += prob[i][0]*100*(i+1) + prob[i][1]
            count += prob[i][0]
        else:
            rest = i

    for i in range(prob[rest][0]):
        if (score < G):
            score += (rest+1)*100
            count += 1
        else:
            min_count = min(min_count, count)
            break

print(min_count)

Measured memory_bytes: 40688