akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int r,c;
bool isin(int x,int y){
	if(x>=0 and x<c and y>=0 and y<r) return true;
	return false;
}
int main() {
	int n;
	cin>>r>>c>>n;
	int x,y;
	cin>>y>>x;
	string a,b;
	cin>>a>>b;
	--x;
	--y;
	int dx=x,dy=y;
	for(int i=0;i<n;i++){
		if(a[i]=='L') dx--;
		
		
		
		
		if(!isin(dx,dy)){
		cout<<"NO";
		return 0;
	}
	if(b[i]=='R' and isin(dx+1,dy)) dx++;
	}
	
	 dx=x,dy=y;
	for(int i=0;i<n;i++){
		if(a[i]=='R') dx++;
		
		if(!isin(dx,dy)){
			cout<<"NO";
			return 0;
		}
		
	if(b[i]=='L' and isin(dx-1,dy)) dx--;
	
	}
		
		 dx=x,dy=y;
	for(int i=0;i<n;i++){
		if(a[i]=='U') dy--;
		
		
		
		
			if(!isin(dx,dy)){
		cout<<"NO";
		return 0;
	}
	if(b[i]=='D' and isin(dx,dy+1)) dy++;
	}

		 dx=x,dy=y;
	for(int i=0;i<n;i++){
		if(a[i]=='D') dy++;
		
		
		
		
		if(!isin(dx,dy)){
		cout<<"NO";
		return 0;
	}
	if(b[i]=='U' and isin(dx,dy-1)) dy--;
	}
	
	cout<<"YES";
}


Measured memory_bytes: 776
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main(void){

    int N; cin>>N;
    vector<int> A(N+2,0);
    ll sum = 0;
    for (int i = 1; i <= N; ++i) {
        cin>>A[i];
        sum += abs(A[i]-A[i-1]);
    }
    sum+=abs(A[N+1]-A[N]);

    for (int i = 1; i <= N; ++i) {
        ll ans = 0;
        ans=abs(A[i+1]-A[i-1])-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1]));
        cout<<sum+ans<<endl;
    }
}

Measured memory_bytes: 1664
// ALDS1_5_D: The Number of Inversions

fn scan<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn scan_vec<T: std::str::FromStr>() -> Vec<T> {
    let s: String = scan();
    s.split_whitespace().map(|a| T::from_str(a).ok().unwrap()).collect()
}

fn merge(a: &mut Vec<i64>, left: usize, mid: usize, right: usize) -> usize {
    let mut l: Vec<i64> = Vec::new();
    let mut r: Vec<i64> = Vec::new();
    for i in left..mid {
        l.push(a[i]);
    }
    for i in mid..right {
        r.push(a[i]);
    }
    l.push(std::i64::MAX);
    r.push(std::i64::MAX);
    let mut i: usize = 0;
    let mut j: usize = 0;
    let mut cnt: usize = 0;
    for k in left..right {
        if l[i] <= r[j] {
            a[k] = l[i];
            i += 1;
        } else {
            a[k] = r[j];
            j += 1;
            cnt += mid - left - i;
        }
    }
    cnt
}

fn merge_sort(a: &mut Vec<i64>, left: usize, right: usize) -> usize {
    let mut cnt: usize = 0;
    if left + 1 < right {
        let mid = (left + right) / 2;
        cnt += merge_sort(a, left, mid);
        cnt += merge_sort(a, mid, right);
        cnt += merge(a, left, mid, right);
    } 
    cnt
}

fn main() {
    let n: usize = scan();
    let mut a: Vec<i64> = scan_vec();
    let ans = merge_sort(&mut a, 0, n);
    println!("{}", ans);
}


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

L_li = []
R_li = []

for i in range(M):
    Li, Ri = list(map(int,input().split()))
    L_li.append(Li)
    R_li.append(Ri)


ans = min(R_li) - max(L_li) + 1
if ans < 0:
    ans = 0
    
    
print(str(int(ans)))

Measured memory_bytes: 56664
import java.util.*;
import java.io.*;
import java.math.BigInteger;
	
class Main {
	static String ReadLn (int maxLg) {
    byte lin[] = new byte [maxLg];
    int lg = 0, car = -1;
    String line = "";
    try {
      while (lg < maxLg) {
        car = System.in.read();
        if ((car < 0) || (car == '\n')) break;
        lin[lg++] += car;
      }
    }
    catch (IOException e) {
      return (null);
    }
    if ((car < 0) && (lg == 0)) 
    	return (null);
    return (new String (lin, 0, lg));
  }
	
	public static void main (String args[]) {
		Main myWork = new Main();
      myWork.Process();
  }
	
	void Process() {
		String input, s1, s2;
		BigInteger a, x;
		int b;
    StringTokenizer line;
    while ((input = Main.ReadLn(255)) != null) {
    	line = new StringTokenizer (input);
    	s1 = line.nextToken();
    	s2 = line.nextToken();
    	a = new BigInteger(s1);
    	b = Integer.parseInt(s2);
    	System.out.println(a.toString(b).length());
    }
	}
}


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

int main() {
  ll l,r;
  cin >> l >> r;

  bool flag = false;
  for(int i = l; i <= r; i++){
    if(i % 2019 == 0){
      flag = true;
      break;
    }
  }

  if(flag){
    cout << 0 << endl;
  }
  else{
    int ans = 2018;
    for(ll i = l; i <= r; i++){
      for(ll j = i+1; j <= r; j++){
        int s;
        s = (i*j) % 2019;
        if(ans > s){
          ans = s;
        }
      }
    }
    cout << ans << endl;
  }

}


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

string s; 
int l, cnt; 

inline int read()
{
    int x = 0, w = 1;
    char c = getchar();
    while(c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
    return x * w;
}

int main()
{
	cin>>s; l = s.size(); 
	cnt = 15 - l; 
	for(int i = 0; i < l; i++) if(s[i] == 'o') cnt++; 
	printf("%s\n", cnt >= 8 ? "YES" : "NO"); 
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include<stdio.h>   

int main(){
    char a;
    scanf("%s",&a);
    int b = a;
    if(b >= 'A' && b <= 'Z'){
        printf("A\n");
    }
    else printf("a\n");

}

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

const int mod = 1e9 + 7;

int n, cnt, x, y, bin[200010];
int col[200010], wei[200010];
int fac[200010], inv[200010];
vector<pair<int, int> > per, all[200010];
bool vis[200010];
vector<int> seq, con[200010];

void dfs(const int &u) {
	vis[u] = 1;
	++cnt;
	++bin[col[u]];
	seq.push_back(col[u]);
	for (int _i = 0; _i < con[u].size(); ++_i) {
		int v = con[u][_i];
		if (!vis[v]) dfs(v);
	}
}

int main() {
	scanf("%d%d%d", &n, &x, &y);
	fac[0] = fac[1] = inv[0] = inv[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fac[i] = (long long)fac[i - 1] * i % mod;
		inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;
	}
	for (int i = 2; i <= n; ++i)
		inv[i] = (long long)inv[i] * inv[i - 1] % mod;
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", col + i, wei + i);
		all[col[i]].push_back(make_pair(wei[i], i));
	}
	for (int i = 1; i <= n; ++i)
		if (all[i].size()) {
			sort(all[i].begin(), all[i].end());
			per.push_back(all[i][0]);
			for (int j = 1; j < all[i].size(); ++j)
				if (all[i][j].first + all[i][0].first <= x) {
					con[all[i][0].second].push_back(all[i][j].second);
					con[all[i][j].second].push_back(all[i][0].second);
				}
		}
	sort(per.begin(), per.end());
	if (per.size()) {
		int id = per[0].second;
		for (int i = 1; i <= n; ++i)
			if (col[i] != col[id] && wei[i] + wei[id] <= y) {
				con[id].push_back(i);
				con[i].push_back(id);
			}
	}
	if (per.size() > 1) {
		int id = per[1].second, min_col = col[per[0].second];
		for (vector<pair<int, int> >::iterator it = all[min_col].begin(); it != all[min_col].end(); ++it)
			if (it->first + wei[id] <= y) {
				con[id].push_back(it->second);
				con[it->second].push_back(id);
			}
	}
	dfs(per[0].second);
	int ans = fac[cnt];
	for (int i = 0; i < seq.size(); ++i) {
		int small = bin[seq[i]];
		bin[seq[i]] = 0;
		ans = (long long)ans * inv[small] % mod;
	}
	printf("%d\n", ans);
}

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



int main (){
    int N;
    cin>>N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++){
        cin>>A.at(i);
    }
    int Checker;
    for(int i=N-1; i>=0; i--){
        Checker=N/(i+1);
      	//cout<<Checker<<' ';
        int Sumofi=0;
        for(int j=2; j<=Checker; j++){
            Sumofi += B.at((i+1)*j-1);
           // Sumofi %= 2;
        }
      	//cout<<Sumofi<<endl;
        if((Sumofi+A.at(i))%2==0){
            B.at(i)=0;
          	
        }
        else{
            B.at(i)=1;
        }
    }
    int Sum=0;
    for(int i=0; i<N; i++){
        Sum+=B.at(i);
    }
    cout<<Sum<<endl;
  	bool Space=false;
    for(int i=0; i<N; i++){
        if(B.at(i)==1){
			if(!Space){
          		Space=true;
        	}
          	else{
            	cout<<' ';
         	}
          	cout<<i+1;
   	 	}
    }
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;    using std::cin;
using std::endl;    using std::vector;
using std::max;     using std::abs;

int main() {

    int n;
    cin >> n;

    vector<int> vx, vy, vh;
    for (int i = 0; i != n; ++i) {

        int x, y, h;
        cin >> x >> y >> h;

        vx.push_back(x);
        vy.push_back(y);
        vh.push_back(h);
    }

    typedef vector<int>::size_type size;

    size count = 0;

    while (vh[count] == 0)
        ++count;

    for (size i = 0; i != 101; ++i) {

        for (size j = 0; j != 101; ++j) {

            int H, Cx = i, Cy = j;
            H = vh[count] + abs(vx[count] - Cx) + abs(vy[count] - Cy);

            size k = 0;
            while (k != n) {

                if (vh[k] != max(H - abs(vx[k] - Cx) - abs(vy[k] - Cy), 0))
                    break;

                ++k;
            }

            if (k == n) {

                cout << Cx << " " << Cy << " " << H << endl;

                return 0;
            }
        }
    }

}


Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,a,cnt=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    while(a%2==0){
      a/=2;
      cnt++;
    }

  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
using namespace std;

int r;
const double PI = 3.14159265358979;
int main() {
	cin >> r;
	cout << 2*PI*r  << endl;
	return 0;
}


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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> x;
    vector<vector<int>> y;
    REP(i, n) {
        cin>>a[i];
        vector<int> x_sub(a[i]), y_sub(a[i]);
        REP(j, a[i]) cin >> x_sub[j] >> y_sub[j];
        x.push_back(x_sub);
        y.push_back(y_sub);
    }

    int ans=0;
    REP(bit, (1<<n)){
        bool ok=true;
        REP(i, n){
            if (bit & (1<<i)) {
                REP(j, a[i]){
                    if (y[i][j]==0 && (bit & (1<<(x[i][j]-1)))) ok=false;
                    if (y[i][j]==1 && !(bit & (1<<(x[i][j]-1)))) ok=false;
                }
            }
            if (ok) continue;
            else break;
        }
        if (ok) ans = max(__builtin_popcount(bit), ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 2000 + 100;
const int MOD = 1000000000 + 7;
const int MAXM = MAXN * MAXN;

int fac[MAXM], inv[MAXM];

int fpow(int x, int p)
{
	int ret = 1;
	for(; p; p >>= 1, x = (long long)x * x % MOD)
		if(p & 1)
			ret = (long long)ret * x % MOD;
	return ret;
}

int get_inv(int x)
{
	return fpow(x, MOD - 2);
}

void init()
{
	fac[0] = 1;
	for(int i = 1; i < MAXM; i++)
		fac[i] = (long long)fac[i - 1] * i % MOD;
	inv[MAXM - 1] = get_inv(fac[MAXM - 1]);
	for(int i = MAXM - 2; i >= 0; i--)
		inv[i] = (long long)inv[i + 1] * (i + 1) % MOD;
}

int get_c(int x, int y)
{
	if(x < 0 || y < 0 || x < y)
		return 0;
	return (long long)fac[x] * inv[y] % MOD * inv[x - y] % MOD;
}

int n, m;
int f[MAXN][MAXN];

int dp(int x, int y)
{
	if(x == 0)
		return 1;
	if(x == y)
		return dp(x, y - 1);
	if(f[x][y] != -1)
		return f[x][y];
	int ret = 0;
	if(y > 0)
		ret = (ret + dp(x, y - 1)) % MOD;
	int A = (m - 1) * (x - 1) + y;
	ret = (ret + (long long)get_c(A + m - 2, A) * dp(x - 1, y)) % MOD;
	// cerr << x << ' ' << y << ' ' << ret << endl;
	return f[x][y] = ret;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;

	if(m == 1)
	{
		cout << 1 << endl;
		return 0;
	}

	init();
	memset(f, -1, sizeof(f));

	int ans = dp(n, n);
	ans = (long long)ans * fac[n] % MOD;
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 52096
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  int K,T;cin >> K >> T;
  int maxa=0;
  repeat(i,T){
    int a;cin >> a;
    maxa = max(maxa,a);
  }
  cout << max(0,2*maxa-K-1) << endl;
  return 0;
}


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

int main(){
  int a,b;
  cin>>a>>b;
  int n=0;
  for (int i=1;i<b-a+1;i++){
    n=n+i;
  }
  cout<<n-b<<endl;
  return 0;
}

    
    

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

signed main() {
  int n;
  cin >> n;
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 26; j++) {
      if (4 * i + 7 * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d",x)
#define ps printf(" "); 
#define plint(x) printf("%lld",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define bg begin()
#define ed end()
#define Set(a, s) memset(a, s, sizeof (a))
#define mod 1000000007
#define tmod(k) if ((k) >= mod) k %= mod;
#define endl '\n'
#define nl printf("\n");
#define fors(i,n) for(int i=0; i<n; i++)
#define fore(i,n) for(int i=n-1; i>=0; i--)
#define forv(i,a,n) for(int i=a; i<n; i++)
#define fora(i,ele) for(auto i: ele)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
typedef pair<int,int> pii;
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");forv(i,30,50){fors(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
const int INF = 0x3f3f3f3f;
float roundoff(float val, float p){ return floor(val*pow(10.0,p)+0.5)/pow(10.0,p);}

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1};
class node{
public:
	int id;
	int prio;
	int prd;
};

class compare{
public:
	bool operator()(node &n1, node &n2){
		if(n1.prio>n2.prio)//ascending
			return true;
		else if(n1.prio==n2.prio){
			return n1.id>n2.id;
		}
		return false;
	}
};
//priority_queue<node, vector<node>, compare> pq;

int main(void) {
    ios_base::sync_with_stdio(true);
    cin.tie(NULL);
    cout.tie(NULL);
    /*#ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #else
    // online submission
    #endif*/
    int n;
    int1(n);
    int sum=0;
    fors(i,n){
        int l,r; int2(l,r);
        sum += r-l+1;
    }
    pint(sum);
    
    return 0;
}



Measured memory_bytes: 256
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)]
x,y = [list(i) for i in zip(*l)]
num = [1] * n
red = ['out'] * n
red[0] = 'in'
for i in range(m):
    if red[x[i]-1] == 'in':
        red[y[i]-1] = 'in'
    num[x[i]-1] -= 1
    num[y[i]-1] += 1
    if num[x[i]-1] == 0:
        red[x[i]-1] = 'out'
print(red.count('in'))

Measured memory_bytes: 35684
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long res = 0;
        long m = 0;
        for (int i = 0; i < n; i++) {
            long a = sc.nextLong();
            m = Math.max(m, a);
            res += m - a;
        }
        System.out.println(res);
        sc.close();
    }
}

Measured memory_bytes: 59624
n,k= map(int,input().split())
rclass = [0]*(k)
for i in range(k):
    rclass[i] = int(n/k)
if n%k  != 0:
    for i in range(1,n%k+1):
        rclass[i] += 1
import math
def Comb(a,b):
    if a>= b:
        return int(math.factorial(a)/(math.factorial(b)*math.factorial(a-b)))
    else:
        return 0
def ans(lis,inte):
    return max(0,lis[inte])*max(0,lis[inte]-1)*max(0,lis[inte]-2)+Comb(lis[inte],2)*6+lis[inte]
print(ans(rclass,0) if k%2 == 1 else ans(rclass,int(k/2))+ans(rclass,0))

Measured memory_bytes: 5844
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define MOD 1000000007
const int mxn = 2e5 + 1;
int vis[mxn];
vector<vector<int>> adj(mxn);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    map<ll,ll> m,d,c;
    for(int i = 1; i<=n; i++){
        cin>>a[i];
        m[i] = a[i];        
    }
    ll kk = k;
    ll steps = 0;
    bool dup = false;
    ll i = 1;
    while(kk && !dup){
        steps++;
        if(d[i] == 1){
            dup = true;
            continue;
        }
        d[i] = 1;
        c[i] = steps;
        i = m[i];
        kk--;
    }
    if(kk){
    ll r = (k - c[i])%(steps - c[i]);
    while(r>=0){
        i = m[i];
        r--;
    }
    }
    cout<<i;
    
}

Measured memory_bytes: 41924
using System;
using System.Linq;

namespace EDPC
{
    class B
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);

            input = Console.ReadLine().Split(' ');

            // initialize
            int[] h = new int[N];
            for (int i = 0; i < N; i++)
            {
                h[i] = int.Parse(input[i]);
            }

            /*
            long H = int.MaxValue;
            long[] dp = new long[N];
            for (int i = 0; i < N; i++)
            {
                dp[i] = H;
            }
             */

            var dp = Enumerable.Repeat(int.MaxValue, N).ToArray();

            // Main processing
            dp[0] = 0;
            for (int i = 1; i < N; i++)
            {
                for (int j = 1; j <= K; j++)
                {
                    if (j <= i)
                    {
                        dp[i] = Math.Min(dp[i], dp[i - j] + Math.Abs(h[i] - h[i - j]));
                    }
                }
            }
            Console.WriteLine(dp[N - 1]);
        }
    }
}


Measured memory_bytes: 19680
#include <iostream>
#include <algorithm>
using namespace	std;
int main(){

  int a,b,c;

  cin>>a>>b;
  if(a<b) swap(a,b);
  while(a%b!=0){
    c=a%b;
    a=b;
    b=c;
  }
  cout<<b<<endl;

}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int,int>
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    // #endif
  int n; cin>>n;
  ll sum=0;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      for(int k=1;k<=n;k++)
        sum+=__gcd(k,(__gcd(i,j)));
  cout<<sum<<"\n";
  return 0;
}

Measured memory_bytes: 3692
#!ruby -na
f=->n,m,a,b{s=a/m*n*~-n/2+b/m*n
x=b%m-m*y=(b%m+n*a%=m)/m
s+=y>0?f[y,a,m,x%a]+y*=n+x/a:0}
p f[*$F.map(&:to_i)]if$.>1

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

int N, D;
vector<int> C;
vector<vector<int>> S;

void Read() {
  N = 26;
  cin >> D;
  C.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  S.resize(D);
  for (int i = 0; i < D; i++) {
    S[i].resize(N);
    for (int j = 0; j < N; j++) {
      cin >> S[i][j];
    }
  }
}

int ans_score = 0;
vector<int> ans;

void Write() {
  for (auto i : ans) {
    cout << i + 1 << "\n";
  }
  exit(0);
}

int Arithmetic(int n) {
  return n * (n - 1) / 2;
}

vector<set<int>> BuildOcc(vector<int> a) {
  vector<set<int>> occ(N);
  for (int i = 0; i < D; i++) {
    occ[a[i]].insert(i);
  }
  for (int i = 0; i < N; i++) {
    occ[i].insert(-1);
    occ[i].insert(D);
  }
  return occ;
}

int Evaluate(vector<int> a) {
  vector<int> last(N, -1);
  int score = 0;
  for (int i = 0; i < D; i++) {
    score += S[i][a[i]];
    last[a[i]] = i;
    for (int j = 0; j < 26; j++) {
      score -= C[j] * (i - last[j]);
    }
  }
  return score;
}

int Evaluate(int init_score, const vector<int> &a, const vector<set<int>> &occ, int d, int q) {
  if (a[d] == q) return init_score;
  const set<int> &cur = occ[a[d]];
  auto pos = cur.lower_bound(d);
  int lst = *prev(pos);
  int nxt = *next(pos);

  int score = init_score;
  score += C[a[d]] * (Arithmetic(nxt - d) + Arithmetic(d - lst) - Arithmetic(nxt - lst));

  pos = occ[q].upper_bound(d);
  lst = *prev(pos);
  nxt = *pos;
  score -= C[q] * (Arithmetic(nxt - d) + Arithmetic(d - lst) - Arithmetic(nxt - lst));

  score -= S[d][a[d]];
  score += S[d][q];

  return score;
}

void Change(int &init_score, vector<int> &a, vector<set<int>> &occ, int d, int q) {
  int new_score = Evaluate(init_score, a, occ, d, q);
  init_score = new_score;
  occ[a[d]].erase(d);
  a[d] = q;
  occ[a[d]].insert(d);
}

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

  Read();
  vector<int> a(D);
  for (int i = 0; i < D; i++) {
    cin >> a[i];
    a[i]--;
  }
  int score = Evaluate(a);
  auto occ = BuildOcc(a);
  int M;
  cin >> M;
  while (M--) {
    int d, q;
    cin >> d >> q;
    d--, q--;
    Change(score, a, occ, d, q);
    cout << score << "\n";
  }
}


Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<string> s(N);

    for (int i = 0; i < N; i++)
    {
        string si;
        cin >> si;
        sort(si.begin(), si.end());
        s[i] = si;
    }

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

    long long int a = 1;
    long long int ans = 0;

    // cout << " " << endl;
    string base = s[0];
    for (int i = 1; i < N; i++)
    {
        // cout << "i: " << i << endl;
        // cout << a << endl;
        // cout << s[i] << endl;
        if (i == N - 1)
        {
            if (s[i] == base)
            {
                a++;
            }
            if (a >= 2)
            {
                ans += a * (a - 1) / 2;
            }
        }
        else if (s[i] != base)
        {
            base = s[i];
            if (a >= 2)
            {
                ans += a * (a - 1) / 2;
            }
            a = 1;
        }
        else
        {
            a++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5760
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, K);
    IN(ll, A);
    IN(ll, B);
    bool ok = false;
    for (ll i = A; i <= B; ++i)
    {
        ok |= i % K == 0;
    }
    YES(ok, "OK", "NG");
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC085 {
	class ABC085_A {
		static void Main(string[] args) {
			var input = Console.ReadLine();
			Console.WriteLine("2018/01/"+input.Split('/').Last());
		}
	}
}


Measured memory_bytes: 11220
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c=INTM()
    ans=[]
    for i in range(c):
        ai=a+i
        bi=b-i
        if a<=ai and ai<=b:
            ans.append(ai)
        if a<=bi and bi<=b:
            ans.append(bi)
    ans=sorted(set(ans))
    for i in ans:
        print(i)
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String input = scanner.nextLine();
		Double r = Double.parseDouble(input); 
		double x = Math.PI;
		System.out.printf("%.5f",r*r*x);
		System.out.print(" ");
		System.out.printf("%.5f",2*r*x);
	}
}

Measured memory_bytes: 26388
using System;

class Program {
  static void Main() {
    int n = int.Parse(Console.ReadLine());
    int ans = 0;
    for (int i = 105; i <= n; i += 2) {
      int cnt = 0;
      for (int j = 1; j <= i; j += 2) {
        if (i % j == 0) cnt++;
      }
      if (cnt == 8) ans++;
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13140
#include <stdio.h>

int main(void)
{
	int i,j,count;
	int data,number[4000];
	long long int uriage[4000],tanka[4000],kosu[4000];
	
	
	while(1)
	{
		for(i=0;i<4000;i++)	//初期
		{
			number[i]=0;
			uriage[i]=0;
		}
		count=0;
		
		scanf("%d",&data);
		if(data!=0)
		{
			for(i=0;i<data;i++)
			{
				scanf("%d %lld %lld",&number[i],&tanka[i],&kosu[i]);
				uriage[i]=tanka[i]*kosu[i];
				for(j=0;j<i;j++)	//既に同じIDがあるか
				{
					if(number[i]==number[j])	//あったら上にあるものに足して下にあるものを消す
					{
						uriage[j]+=uriage[i];
						uriage[i]=0;
					}
				}
			}
		
		for(i=0;i<data;i++)
		{
			if(uriage[i]>=1000000)
			{
				printf("%d\n",number[i]);
				count++;
			}
		}
		if(count==0)
			printf("NA\n");
		
		}
		
		if(data==0)
			break;
	}
	return 0;
}

Measured memory_bytes: 680
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a;
	set<int> s;
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>a;
		s.insert(a);
	}
	if (s.size()==n) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 9600
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            for (var i = N; i <= 999; ++i)
            {
                if (i.ToString().Distinct().Count() == 1)
                {
                    WriteLine(i);
                    return;
                }
            }
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 28204
a,b,c,d = gets.chars.map(&:to_i)
pm = ["+","-"]
0.upto(7) do |i|
  st = "#{a}"
  st << pm[i[0]] << "#{b}"
  st << pm[i[1]] << "#{c}"
  st << pm[i[2]] << "#{d}"
  if eval(st) == 7
    st << "=7"
    puts st
    break
  end
end

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

void quick(char s[][13], int left, int right){
  int pl = left, pr = right;
  char x[13];  sprintf(x, "%s", s[(left+right)/2]);
  do{
    while(strcmp(s[pl], x) < 0)  pl++;
    while(strcmp(s[pr], x) > 0)  pr--;
    if(pl <= pr){
      char t[13];  sprintf(t, "%s", s[pl]);
      sprintf(s[pl], "%s", s[pr]);
      sprintf(s[pr], "%s", t);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(s, pl, right);
  if(pr > left)   quick(s, left, pr);
}

int main(){
  int n;  scanf("%d", &n);
  char s[100005][13], march[] = "MARCH";
  for(int i=1; i<=n; i++)  scanf("%s", s[i]);
  quick(s, 1, n);

  long idx = 1, num[5] = {0};
  while(idx <= n){
    int same = 1;
    for(int i=0; i<5; i++)
      if(s[idx][0] == march[i]){
	num[i]++;
	break;
      }
    while(strcmp(s[idx], s[idx+same])==0)  same++;
    idx = idx + same;
  }

  long ans = 0;
  for(int i=0; i<3; i++)
    for(int j=i+1; j<4; j++)
      for(int k=j+1; k<5; k++){
	ans += num[i] * num[j] * num[k];
      }

  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 2968
n = int(input())
x, y = [0] * n, [0] * n
for i in range(n):
  x[i], y[i] = list(map(int, input().split()))

dis = 0
import itertools
import math
for per in itertools.permutations(range(n)):
  first = True
  for i in per:
    if not first:
      dis += math.sqrt((x[i] - x[previ]) ** 2 + (y[i] - y[previ]) ** 2)
    previ = i
    first = False

print(dis / math.factorial(n))


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int main() {
    int N;
    scanf("%d", &N);

    int t[N+1], x[N+1], y[N+1];
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    for (int i=1; i < N+1; i++) {
        scanf("%d %d %d", &t[i], &x[i], &y[i]);
    }

    for (int i = 0; i < N; i++) {
        int time = t[i+1] - t[i];
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1]- y[i]);

        if (time < dist || time % 2 != dist % 2) {
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1280
import java.io.*;

public class Main {

    public static void main(String[] arg) throws NumberFormatException, IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        String revLine;

        // ab = gcd * lcm
        while ((line = in.readLine()) != null) {
            revLine = "";
            for (int i = line.length() - 1; i >= 0; i--) {
                revLine = revLine + line.charAt(i);
            }
            System.out.println(revLine);
        }
    }
}

Measured memory_bytes: 16860
using System;
using System.Collections.Generic;
using System.Linq;

namespace at
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            Console.WriteLine((int.Parse(str[0])*int.Parse(str[1]))/2);
        }
    }
}


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

int main() {
  long long N;
  cin>>N;
  for(long long i=0;i<=N;i++){
    if(i*10800/10000==N){
      cout<<i<< endl;
      return 0;
    }
  }
  cout<<":("<< endl;
  
  
}


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

int main() {
	int N;
	cin >> N;
	int sum = 0, MAX = 0;
	for (int i = 0; i < N; i++) {
		int L;
		cin >> L;
		sum += L;
		MAX = max(MAX, L);
	}
	cout << (MAX < sum - MAX ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) a[i]--;
  vector<int> idx(n);
  rep(i,n) idx[a[i]]=i;
  
  set<int>st;
  ll ans = 0;
  for(int p=n-1;p>=0;p--){
    int i = idx[p];
    ll c = 0;
    {
      //calc c;
      st.insert(i);
      vector<int> l(2,-1);
      vector<int> r(2,n);
      {
        // calc l
        auto it = st.find(i);
        rep(j,2){
          if(it == st.begin())break;
          --it;
          l[j] = *it;
        }
      }
      {
        // calc r
        auto it = st.find(i);
        rep(j,2){
          ++it;
          if(it == st.end())break;
          r[j] = *it;
        }
      }
      vector<int> ls(2);
      vector<int> rs(2);
      ls[0] = i-l[0];
      ls[1] = l[0]-l[1];
      rs[0] = r[0]-i;
      rs[1] = r[1]-r[0];
      c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
    }
    ans += c*(p+1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8720
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P  = pair<int, int>;
int main() {
    long double a, b, h, m;
    cin >> a >> b >> h >> m;
    long double th = abs(h * 60 - m * 11) / 360 * M_PI, thr;
    //th = h/12+m/60/12-m/60
    //thr = th / 180.0 * M_PI;
    cout << setprecision(20) << sqrt(a * a + b * b - 2.0 * a * b * cosl(th));
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> X(H+1);
  for(int i=1; i<=H; i++) {
    cin >> X[i];
  }
  for(int i=0; i<H+2; i++) {
    if(i==0 || i==H+1) {
      for(int j=0; j<W+2; j++) {
        cout << "#";
      }
      cout << endl;
    }
    else {
      cout << "#" << X[i] << "#" << endl;
    }
  }
  return 0;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

int main(){
int N, K;
cin >> N >> K;
int cnt = 0;
REP(i, N) {
    int h;
    cin >> h;
    if(K <= h)  cnt++;
}
 print(cnt);
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pill;

int first[100005];
ll fact[100005];
ll ifact[100005];
const int MOD = 1000000007;

ll choose(int n, int k) {
  if(k > n) return 0;
  ll ret = fact[n];
  ret *= ifact[k];
  ret %= MOD;
  ret *= ifact[n-k];
  ret %= MOD;
  return ret;
}

ll modpow(ll b, ll e, ll m) {
  ll r = 1;
  while(e) {
    if(e%2) {
      r*=b;
      r%=m;
    }
    e/=2;
    b*=b;
    b%=m;
  }
  return r;
}

void solve() {
  int n;
  cin >> n;
  fact[0] = 1;
  for(int i = 1; i <= n+1; i++) {
    fact[i] = i * fact[i-1];
    fact[i] %= MOD;
  }
  ifact[n+1] = modpow(fact[n+1], MOD-2, MOD);
  for(int i = n; i >= 0; i--) {
    ifact[i] = (i+1) * ifact[i+1];
    ifact[i] %= MOD;
  }
  int a = -1;
  int b = -1;
  for(int i = 1; i <= n+1; i++) {
    int t;
    cin >> t;
    if(first[t] > 0) {
      a = first[t];
      b = i;
      break;
    }
    else {
      first[t] = i;
    }
  }
  for(int i = 1; i <= n+1; i++) {
    ll ret = choose(n+1, i);
    ret -= choose(a+n-b, i-1);
    ret %= MOD;
    ret += MOD;
    ret %= MOD;
    cout << ret << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 3200
# -*- coding: utf-8 -*-

import itertools

def main():

    s = [int(x) for x in input().split(' ')]
    n = s[0]
    m = s[1]
    x = s[2]

    iters = []
    ran = range(n)
    for i in range(n):
        comb = list(itertools.combinations(ran, i+1))
        iters.extend(comb)

    books = []
    for j in range(n):
        l = [int(x) for x in input().split(' ')]
        books.append(l)

    sum_list = []
    for comb in iters:
        flag = False
        budget = []
        score_list = [0 for x in range(m)]
        for index in comb:
            book = books[index]
            budget.append(book[0])
            book_score = book[1:]
            for i, bs in enumerate(book_score):
                score_list[i] += bs
            flags = [True if y >= x else False for y in score_list]
            flag = all(flags)
        if flag:
            sum_list.append(sum(budget))
    if len(sum_list) == 0:
        print(-1)
    else:
        print(min(sum_list))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9516
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String t = scanner.next();
        if (s.equals(t.substring(0, t.length() - 1))) {
            if (s.length() + 1 == t.length()) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");

        /*
        long a = scanner.nextInt();
        long b = scanner.nextInt();
        long c = scanner.nextInt();
        long k = scanner.nextInt();
        if (a + b >= k) {
            System.out.println(a);
        }else {
            System.out.println(a - (k - (a + b)));
        }

         */
    }
}


Measured memory_bytes: 35524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n,k;
    double temp,shift;
    double ans = 0;
    cin >> n >> k;
    int count;
    for(int i = 1; i < n+1; i++){
        temp = (double)i;
        count = 0;
        while(temp < k){
            count += 1;
            temp *= 2.0;
        }
        shift = 1 << count;
      //cout << shift << endl;
        ans += (1.0/n) / shift;
    }
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

#include <vector>
using namespace std;

/* Union-Find-Tree */
/* 必ず要素数をコンストラクタに入れること */
template <class T = long long>
class Union_Find {
  using size_type = std::size_t;
  using _Tp = T;
public:

  vector<_Tp> par;
  vector<_Tp> rnk;

  // 親の根を返す。値の変更は認めない。
  const _Tp & operator[] (size_type child) {
    return find(child);
  }

  Union_Find (_Tp n) {
    par.resize(n), rnk.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rnk[i] = 0;
    }
  }

  // 木の根を求める
  _Tp find(_Tp x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }

  // xとyの属する集合を併合
  void merge(_Tp x, _Tp y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rnk[x] < rnk[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rnk[x] == rnk[y]) rnk[x]++;
    }
  }

  // xとyが同じ集合に属するか否か
  bool same(_Tp x, _Tp y) {
    return find(x) == find(y);
  }
};


int main() {
  int n,k,l;
  cin >> n >> k >> l;
  Union_Find<long long> uf_road(n+1), uf_train(n+1);

  int r,s;
  rep(i,k) {
    cin >> r >> s;
    uf_road.merge(r, s);
  }

  rep(i,l) {
    cin >> r >> s;
    uf_train.merge(r, s);
  }

  vector<pair<int,int> > com;
  map<pair<int,int>, int> mp;

  for (int i = 1; i <= n; ++i) {
    int a, b;
    a = uf_road.find(i);
    b = uf_train.find(i);
    com.push_back(make_pair(a,b));
    mp[make_pair(a,b)] += 1;
  }

  for (int i = 0; i < n; ++i) {
    cout << mp[com[i]] << " ";
  }

  END;
}


Measured memory_bytes: 19568
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    if (s.charAt(s.length()-1)=='3') {
      System.out.println("bon");
    }else if(s.charAt(s.length()-1)=='0'||s.charAt(s.length()-1)=='1'||s.charAt(s.length()-1)=='6'||s.charAt(s.length()-1)=='8'){
      System.out.println("pon");
    }else{
      System.out.println("hon");
    }
  }
}


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

struct Sieve {
	int n;
	vector<int> f, primes;
	Sieve(int n = 1) :n(n), f(n + 1) {
		f[0] = f[1] = -1;
		for (ll i = 2; i <= n; i++) {
			if (f[i]) {
				continue;
			}
			primes.push_back(i);
			f[i] = i;
			for (ll j = i * i; j <= n; j += i) {
				if (!f[j]) {
					f[j] = i;
				}
			}
		}
	}

	bool isPrime(int x) {
		return f[x] == x;
	}

	vector<int> factorList(int x) {
		vector<int> res;
		while (x != 1) {
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}

	vector<P> factor(int x) {
		vector<int> fl = factorList(x);
		if (fl.size() == 0) {
			return {};
		}
		vector<P> res(1, P(fl[0], 0));
		for (int p : fl) {
			if (res.back().first == p) {
				res.back().second++;
			}
			else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};

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

	Sieve sieve(1e5+100);
	int ans = 0;
	rep(i, sieve.primes.size()) {
		if (sieve.primes[i] < X) {
			continue;
		}
		else {
			ans = sieve.primes[i];
			break;
		}
	}


	cout << ans << endl;
}

Measured memory_bytes: 768
while true
    n = STDIN.gets.to_i
    exit 0 if n==0
    num = Hash.new
    num["t"] = 1
    num["b"] = 6
    num["s"] = 2
    num["n"] = 5
    num["e"] = 3
    num["w"] = 4
    total = num["t"]
    for i in 0..n-1 do
        str = STDIN.gets.chomp
        if str=="North" then
            tmp=num["t"]
            num["t"]=num["s"]
            num["s"]=num["b"]
            num["b"]=num["n"]
            num["n"]=tmp
        elsif str=="East" then
            tmp=num["t"]
            num["t"]=num["w"]
            num["w"]=num["b"]
            num["b"]=num["e"]
            num["e"]=tmp
        elsif str=="West" then
            tmp=num["t"]
            num["t"]=num["e"]
            num["e"]=num["b"]
            num["b"]=num["w"]
            num["w"]=tmp
        elsif str=="South" then
            tmp=num["t"]
            num["t"]=num["n"]
            num["n"]=num["b"]
            num["b"]=num["s"]
            num["s"]=tmp
        elsif str=="Right" then
            tmp=num["n"]
            num["n"]=num["w"]
            num["w"]=num["s"]
            num["s"]=num["e"]
            num["e"]=tmp
        elsif str=="Left" then
            tmp=num["n"]
            num["n"]=num["e"]
            num["e"]=num["s"]
            num["s"]=num["w"]
            num["w"]=tmp
        end
        total = total + num["t"]
    end
    print total,"\n"
end

Measured memory_bytes: 6112