akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k := getInt(), getInt()

	a := make([]int, n)
	for i := range a {
		a[i] = getInt()
	}

	minus := 0
	plus := 0
	var ans uint64
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if a[i] > a[j] {
				plus++
			}
			if i < j && a[i] > a[j] {
				minus++
			}
		}
	}

	ans = uint64((k*minus%1000000007 + ((k-1)*k/2%1000000007)*plus)) % 1000000007
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    int n;
    cin >> n;
    int height = 0;
    int count = 0;
    for(int i = 0;i < n;i++){
        int h;
        cin >> h;
        if(height <= h){
            height = h;
            count++;
        }
    }

    cout << count;
}

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

#define ll long long int
#define ld long double
#define clr(arr) memset(arr,0,sizeof(arr))
#define nn '\n'

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
//    cin>>t;
    while(t--)
    {
        ll tk = 1000, x = 0;
        ll n;
        cin>>n;
        ll arr[n];
        for(ll i=0; i<n; i++) cin>>arr[i];
        for(ll i=1; i<n; i++)
        {
            if(arr[i]>arr[i-1])
            {
                ll x = tk/arr[i-1];
                tk -= (x*arr[i-1]);
                tk += (x*arr[i]);
            }
        }
        cout<<tk<<endl;
    }

    return 0;
}




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

#define int int64_t

using namespace std;

int32_t main()
{
    int n, num[2];
    cin >> n >> num[0] >> num[1];
    vector<int> arr(n);
    for (int &i : arr)
        cin >> i;
    reverse(arr.begin(), arr.end());
    int dp[n][2];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 2; j++)
        {
            int val = num[1 - j];
            if (arr.size() > i + 1)
                val = arr[i + 1];
            dp[i][j] = abs(val - arr[0]);
            for (int k = 0; k < i; k++)
                if (j == 0)
                    dp[i][0] = max(dp[i][0], dp[k][1]);
                else
                    dp[i][1] = min(dp[i][1], dp[k][1]);
        }
    cout << dp[n - 1][0];
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();

		if ( S.length() % 2 == 1 ) {
			System.out.println("No");
			return;
		}

		String ans = "Yes";
		for ( int i = 0 ; i < S.length() ; i++ ) {
			if ( i % 2 == 0 ) {
				if ( S.charAt(i) != 'h' ) {
					ans = "No";
					break;
				}
			} else {
				if ( S.charAt(i) != 'i' ) {
					ans = "No";
					break;
				}
			}
		}
		System.out.println(ans);
	}
}


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

typedef long long ll;
typedef vector <int> vi;
typedef pair< int ,int > pii;
typedef istringstream iss;
typedef ostringstream oss;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ln length()
#define rep(i,n) for(int i=0;i<n;i++)
#define fu(i,a,n) for(int i=a;i<=n;i++)
#define fd(i,n,a) for(int i=n;i>=a;i--)
#define all(a)  a.begin(),a.end() 
#define ESP (1e-9)
#define gi(n) scanf("%d",&n)
#define gl(n) cin >> n
#define pi(n) printf("%d",n)
#define pl(n) cout << n
#define ps printf(" ")
#define pn printf("\n")
#define dg(n,s); printf("%s %d",s,n)
#define imax numeric_limits<int>::max()
#define imin numeric_limits<int>::min()
#define lmax numeric_limits<ll>::max()
#define lmin numeric_limits<ll>::min()
 ll n , k , x  ; 
int main () {
	cin >> n >> k  ;
	ll ans = 0 ; 
	for ( int i = 0 ; i  < n ; i ++ ){
		   cin >> x ;
		   if ( x <= 0 )   ans -= 2 * x ; 
		   else if ( x >= k )   ans += 2* ( x - k ) ;
		   else  {
		        if (  x <= k / 2 )   ans += 2 * ( x ) ;
				else                 ans += 2 * ( k  - x ) ; 	
		   }  
	} 
	cout << ans ; 
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
ll N;

int main()
{
	int n, k;
	cin >> n >> k;
	int cnt = 0;
	int m[101] = {0};

	rep(ki, k) {
		int di;
		cin >> di;
		rep (dii, di) {
			int a;
			cin >> a;
			m[a] = 1;
		}
	}

	rep(ni, n) {
		if (m[ni + 1] == 0) cnt++;
	}
	cout << cnt << endl;

	return 0;
}


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

int main(){
  int N;
  int A,B;
  cin>>N;
  if (N==1){
    cout<<"Hello World";
  }
  else{
    cin>>A>>B;
    cout<<A+B;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define nyan "(=^･ω･^=)"
using namespace std;

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
//using ll = long long;
//using P = pair<int,int>;

int N, Q;
vector<int> edges[202020];

void dfs(int v, int p, vector<long long> & num){
    
    for (int j : edges[v]){
        if (j != p){
            num[j] += num[v];
            dfs(j, v, num);
        }
    }
}


int main(){
    cin >> N >> Q;
    
    // input of a graph
    
    for (int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        
        a--, b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    
    vector<long long> num(202020);
    
    // preparation for the imos
    for (int i = 0; i < Q; i++){
        long long p, x;
        cin >> p >> x;
        p--;
        
        num[p] += x;
    }
    
    dfs(0, -1, num);
    
    for (int i = 0; i < N; i++){
        if (i == N-1) cout << num[i] << endl;
        else cout << num[i] << " ";
    }
}

Measured memory_bytes: 27392
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;


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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF;
    string str;
    cin>>a>>b;
    ll sum=b;
    rep(i,a-1){
        sum*=(b-1);
    }
    cout<<sum<<endl;
    return 0;
}


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

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int N;
    cin >> N;
    if (N < 1000) {
        cout << "ABC" << endl;
    }
    else {
        cout << "ABD" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define eb emplace_back
typedef long long ll;
auto const inf = numeric_limits<ll>::max()/4;

using Weight = ll;
using Capacity = int;
struct Edge {
    int src, dst; Weight weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

pair<vector<Weight>, bool> spfa(const Graph &g, int s){
    const Weight inf = numeric_limits<Weight>::max()/4;
    const int n = g.size(); queue<int> q;
    vector<Weight> dist(n, inf); vector<int> inQ(n);
    vector<int> count(n);
    dist[s] = 0; q.emplace(s); inQ[s] = true; ++count[s];
    bool negCycle = false;
    for(int i = 0; q.size(); i++){
        int v = q.front(); q.pop(); inQ[v] = false;
        for(auto &e : g[v]){
            if(dist[v] != inf && dist[e.dst] > dist[v] + e.weight){
                dist[e.dst] = dist[v] + e.weight;
                if(!inQ[e.dst]){
                    q.emplace(e.dst); inQ[e.dst] = true; ++count[e.dst];
                    if(count[e.dst] >= n){ negCycle = true; goto END; }
                }
            }
        }
    }
 END:;
    return make_pair(dist, !negCycle);
}

int main(){
    int V,E,r;
    while(cin >> V >> E >> r){
        Graph g(V);
        rep(i,E){
            int a,b,c;
            cin >> a >> b >> c;
            g[a].eb(a,b,c);
        }
        bool ok;
        vector<Weight> dist;
        tie(dist, ok) = spfa(g,r);
        if(ok){
            for(int i = 0; i < (int)dist.size(); i++){
                if(dist[i] == inf) cout << "INF";
                else cout << dist[i];
                cout << endl;
            }
        } else {
            cout << "NEGATIVE CYCLE" << endl;
        }
    }
}

Measured memory_bytes: 19228
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	void set(int arg_from,int arg_to,int arg_id){
		from = arg_from;
		to = arg_to;
		id = arg_id;
	}
	int from,to,id;
};

struct Data{
	Data(int arg_node_id,int arg_total_cost){
		node_id = arg_node_id;
		total_cost = arg_total_cost;
	}
	bool operator<(const struct Data &arg) const{
		return total_cost > arg.total_cost;
	}
	int node_id,total_cost;
};

bool check[1000][1000];
Info info[10000];
int N,M,start,goal,min_dist[1000],rev_min_dist[1000];
vector<int> V[1000],rev_V[1000];


void func(){

	scanf("%d %d",&start,&goal);
	start--;
	goal--;

	for(int i = 0; i < N; i++){
		V[i].clear();
		rev_V[i].clear();
		for(int k = 0; k < N; k++)check[i][k] = false;
	}

	scanf("%d",&M);

	int tmp_from,tmp_to,index = 0;

	for(int loop = 0; loop < M; loop++){
		scanf("%d %d",&tmp_from,&tmp_to);
		tmp_from--;
		tmp_to--;
		if(check[tmp_from][tmp_to] == false){
			check[tmp_from][tmp_to] = true;
			info[index].set(tmp_from,tmp_to,loop+1);
			V[tmp_from].push_back(tmp_to);
			rev_V[tmp_to].push_back(tmp_from);
			index++;
		}
	}

	for(int i = 0; i < N; i++)min_dist[i] = BIG_NUM;

	min_dist[start] = 0;

	priority_queue<Data> Q;
	Q.push(Data(start,0));

	int minimum1 = BIG_NUM;

	while(!Q.empty()){

		if(Q.top().node_id == goal){
			minimum1 = min(minimum1,Q.top().total_cost);
			Q.pop();
		}else if(Q.top().total_cost > min_dist[Q.top().node_id]){
			Q.pop();
		}else{

			for(int i = 0; i < V[Q.top().node_id].size(); i++){

				if(min_dist[V[Q.top().node_id][i]] > Q.top().total_cost+1){
					min_dist[V[Q.top().node_id][i]] = Q.top().total_cost+1;
					Q.push(Data(V[Q.top().node_id][i],min_dist[V[Q.top().node_id][i]]));
				}
			}
			Q.pop();
		}
	}

	for(int i = 0; i < N; i++)rev_min_dist[i] = BIG_NUM;
	rev_min_dist[goal] = 0;
	Q.push(Data(goal,0));

	while(!Q.empty()){

		if(Q.top().node_id == start){
			Q.pop();
		}else if(Q.top().total_cost > rev_min_dist[Q.top().node_id]){
			Q.pop();
		}else{

			for(int i = 0; i < rev_V[Q.top().node_id].size(); i++){

				if(rev_min_dist[rev_V[Q.top().node_id][i]] > Q.top().total_cost+1){
					rev_min_dist[rev_V[Q.top().node_id][i]] = Q.top().total_cost+1;
					Q.push(Data(rev_V[Q.top().node_id][i],Q.top().total_cost+1));
				}
			}
			Q.pop();
		}
	}

	int minimum2 = BIG_NUM,road_id;
	for(int i = 0; i < index; i++){
		if(min_dist[info[i].from] > min_dist[info[i].to]){
			if(min_dist[info[i].to]+rev_min_dist[info[i].from]+1 < minimum2){
				minimum2 = min_dist[info[i].to]+rev_min_dist[info[i].from]+1;
				road_id = info[i].id;
			}
		}
	}

	if(minimum1 <= minimum2){
		printf("%d %d\n",minimum1,0);
	}else{
		printf("%d %d\n",minimum2,road_id);
	}
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 4580
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

signed main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    cin >> a[0];
    rep(n-1){
        cin >> a[i+1];
        a[i+1] += a[i];
    }
    if(n == 2){
        cout << abs(2*a[0] - a[1]);
        return 0;
    }
    ll tmp, ans  = abs(2*a[0] - a[n-1]);
    reppp(i, 1, n-2){
        tmp = abs(2*a[i] - a[n-1]);
        if(tmp < ans) ans = tmp;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;


	public class Main {
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int[] a = new int[n];
			
			for(int i=0;i<n;i++) {
				a[i]=sc.nextInt();
			}
			
			long h = 0;
			long w = 0;
			int count = 0;
			
			Arrays.sort(a);
			
			for(int i=n-1;i>=1&&count<2;i--) {
				if(a[i]==a[i-1]) {
					count++;
					i--;
					if(h==0) {
						h = a[i];
					}else {
						w = a[i];
					}
				}
			}
			
			long ret = h*w;
			
			System.out.println(ret);
		}
		
	}


Measured memory_bytes: 50856
#include<stdio.h>
#define M 10000

int parent(int n){
  return n/2;
}
int left(int n){
  return n*2;
}
int right(int n){
  return n*2+1;
}

int main(){
  int A[M+1];
  int h;
  int i;
  
  scanf("%d",&h);
  for(i=1;i<=h;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=h;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=h)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=h)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2112
def factorial(n):
    a = 1
    for i in range(1, n + 1):
        a *= i
    return a

def nCr(n,r):
    if r > n:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

def nC2(n):
    if n < 2:
        return 0
    else:
        return n * (n-1) // 2


####
N = int(input())
sorted_dic = {}
for i in range(N):
    s = "".join(sorted(input()))
    v = 0
    if s in sorted_dic:
        v = sorted_dic[s]
    sorted_dic[s] = v + 1

ans = 0
for k in sorted_dic:
    v = sorted_dic[k]
    #print(k,v,factorial(v),factorial(2), factorial(v - 2), nCr(v, 2))
    ans = ans + nC2(v)

print(ans)

Measured memory_bytes: 17852
#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() {
  string s;
  cin >> s;

  int ans = 1e9;
  rep(si, s.size()) {
    string t = s;
    while (true) {
      bool same = true;
      rep(ti, t.size()) {
        if (t[ti] != s[si]) same = false;
      }
      if (same) break;
      string tp = "";
      rep(ti, t.size() - 1) {
        if (t[ti] == s[si]) tp += t[ti];
        else tp += t[ti + 1];
      }
      t = tp;
    }
    ans = min(ans, (int)(s.size() - t.size()));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;


int main()
{
   FAST/**/
   
   ll a,b;
   cin>>a>>b;
   
   ll g = __gcd(a,b);
   cout<<(a/g)*b;
   
   return 0;        
}  
   

Measured memory_bytes: 256
import java.util.*

class SumBit(private val size: Int){
    private val mArray = IntArray(size){0}
    fun sumAt(index:Int): Int {
        var sum = 0
        var idx = index
        while(idx >= 0){
            sum += mArray[idx]
            idx -= (idx + 1) and idx.inv()
        }
        return sum
    }
    fun incrementAt(index:Int) {
        var idx = index
        while (idx < size){
            mArray[idx]++
            idx += (idx + 1) and idx.inv()
        }
    }
}
fun main(args:Array<String>):Unit {
    val str = readLine()!!.trim()
    var k = readLine()!!.trim().toInt()
    val queues = Array(26){PriorityQueue<Int>()}
    for ((queue, c) in queues.zip('a' .. 'z')) {
        for (i in 0 until str.length){
            if (str[i] == c) queue.add(i)
        }
    }
    val res = StringBuilder()
    val bit = SumBit(str.length)
    loop@while(res.length < str.length) {
        for (i in 0 until 26){
            if (queues[i].isNotEmpty() && queues[i].peek() - bit.sumAt(queues[i].peek()) <= k) {
                k -= queues[i].peek() - bit.sumAt(queues[i].peek())
                res.append('a'.plus(i))
                bit.incrementAt(queues[i].poll())
                continue@loop
            }
        }
    }
    println(res.toString())
}


Measured memory_bytes: 41276
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
    int key;
    struct node *prev;
    struct node *next;
} Node;
 
Node *nil;
void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->prev = nil;
    nil->next = nil;
}

void insert(int key)
{
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

Node* listSearch(int key) {
    Node *cur = nil->next;
    while(cur != nil && cur->key != key)
        cur = cur->next;
    return cur;
}
 
void deleteNode(Node *t)
{
    if(t == nil)
        return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}
 
void deleteFirst()
{
    deleteNode(nil->next);
}
 
void deleteLast()
{
    deleteNode(nil->prev);
}
 
void deleteKey(int key)
{
    deleteNode(listSearch(key));
}
 
void printList()
{
    Node *cur = nil->next;
    int isf = 0;
    while(1) {
        if(cur == nil) {
            break;
        }else {
            if(isf++ > 0)
                printf(" ");
            printf("%d", cur->key);
            cur = cur->next;
        }
    }
    printf("\n");
}
 
int main()
{   
    int i, n;
    int key;
    char com[15];
    scanf("%d", &n);
 
    init();
 
    for(i = 0; i < n; i++) {
        scanf("%s %d", com, &key);
        if (com[0] == 'i') {
            insert(key);
        }
        else if(com[0] == 'd') {
            if(com[6] == 'F')
                deleteFirst();
            else if(com[6] == 'L')
                deleteLast();
            else
                deleteKey(key);
        }
    }
 
    printList();
 
    return 0;
}

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

int n, m, res = 1e9;
int table[10000010];

int main(){
	int i, j, k, a, s;
	scanf("%d %d", &n, &m); m /= 100; table[0] = 1;
	for(i = 1; i <= n; i++){
        scanf("%d %d", &a, &s); s /= 100;
        for(j = m - 1; j >= 0; j--){
            if(table[j]){
                for(k = 1; k < a; k++){
                    if(!table[j + k * i]) table[j + k * i] = table[j] + k;
                    else table[j + k * i] = min(table[j + k * i], table[j] + k);
                    if(j + k * i >= m) res = min(res, table[j + k * i] - 1);
                }
                if(!table[j + k * i + s]) table[j + k * i + s] = table[j] + k;
                else table[j + k * i + s] = min(table[j + k * i + s], table[j] + k);
                if(j + k * i + s >= m) res = min(res, table[j + k * i + s] - 1);
            }
        }
	}
	printf("%d", res);
	return 0;
}


Measured memory_bytes: 384
using System;

class Example
{
    static void Main()
    {
        int size = int.Parse(Console.ReadLine());
        string[] n = Console.ReadLine().Split(' ');
        int[] nums = new int[size];
        for (int i = 0; i < size; i++)
        {
            nums[i] = int.Parse(n[i]);
        }
        int temp, count = 0;
        for (int a = 1; a < size; a++)
        {
            for (int b = size - 1; b >= a; b--)
            {
                if (nums[b - 1] > nums[b])
                {
                    temp = nums[b - 1];
                    nums[b - 1] = nums[b];
                    nums[b] = temp;
                    count++;
                }
            }
        }
        for(int i = 0; i < size - 1; i++)
            Console.Write(nums[i] + " ");
        Console.WriteLine(nums[size - 1]);
        Console.WriteLine(count);
    }
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;
  int cur = 0;
  for (int i = 0; i < 1e7; ++i) {
    cur = (cur * 10 + 7) % n;
    if (cur == 0) {
      cout << i + 1 << endl;
      return;
    }
  }
  cout << -1 << endl;
}

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

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 3656
s = input()
s_len = len(s)
s = int(s)
s_1 = '1'
s_0 = '0'

for i in range(0,s_len-1):
    if i%2==0:
        s_1 = s_1 + '0'
    else:
        s_1 = s_1 + '1'

for i in range(0,s_len-1):
    if i%2==0:
        s_0 = s_0 + '1'
    else:
        s_0 = s_0 + '0'

s_1 = int(s_1)
s_0 = int(s_0)

s_1_1 = str(s+s_1)
s_0_1 = str(s+s_0)

count_1=0
count_0=0
for i in s_1_1:
    if int(i)==1:
        count_1+=1
for i in s_0_1:
    if int(i)==1:
        count_0+=1
 
print(min(count_0,count_1))

Measured memory_bytes: 3504
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int count;

		while (sc.hasNext()) {
			n = sc.nextInt();
			count = 0;
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					for (int k = 0; k < 10; k++) {
						for (int l = 0; l < 10; l++) {
							if (i + j + k + l == n) {
								count++;
							}
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 12000
import java.util.*;

public class Main{
	
	static int[] Revers(int[] Numbers , int n){
		
		for(int i = 0; i < n/2 ; i++){
			int t = Numbers[i];
			Numbers[i] = Numbers[n - i -1];
			Numbers[n - i - 1]= t;
		}
		return Numbers;
	}
	
	static int[] Input(){
		Scanner scanner = new Scanner(System.in);		
		int n 			= scanner.nextInt();
		int[] Numbers	= new int[n];
		for(int i = 0; i < n ; i++){
			Numbers[i] = scanner.nextInt();
		}
		scanner.close();
		return Revers(Numbers, n);
		
	}
	
	public static void main(String[] args) {
		int[] RN = Input();
		for(int i = 0 ; i < (RN.length-1) ; i++){
			System.out.print(RN[i] + " ");			
		}
		System.out.println(RN[RN.length-1]);
	}

}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    long long a, b, k;
    cin >> a >> b >> k;

    cout << max(a - k, 0LL) << " " << max(b - max(k - a, 0LL), 0LL) << "\n";

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	ll ans = k;
	rep(i, n-1){
		ans *= (k-1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
X=list(map(int,input().split()))
M=max(X)
X.remove(M)
m=min([abs(2*x-M) for x in X])
if (M+m)//2 in X:
    m=(M+m)//2
else:
    m=(M-m)//2
print(M,m)

Measured memory_bytes: 14428
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const double PI = 3.14159265358979;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

static const int bn = 32;

ll n, m;
ll c[51][51] = {};
bool v[51] = {};

ll ma[51] = { };
ll mb[51] = { };

ll total = 0;
bool allvisited() {
	repe(i, 1, n) {
		if (!v[i]) {
			return false;
		}
	}
	return true;
}
bool allV = false;
void dfs(int k) {
	repe(i, 1, n) {
		if (k != i && c[k][i] && !v[i]) {
			v[i] = true;
			dfs(i);
			//v[i] = false;
		}
	}
}

int main() {
	cin >> n >> m;

	rep(i, 0, m) {
		ll a, b; cin >> a >> b;
		ma[i] = a;
		mb[i] = b;
		c[a][b] = 1;
		c[b][a] = 1;
	}

	rep(i, 0, m) {
		//cout << "!" << ma[i] << " " << mb[i] << endl;
		repe(i, 1, n)v[i] = false;
		c[ma[i]][mb[i]] = 0;
		c[mb[i]][ma[i]] = 0;
		allV = false;
		v[1] = true;
		dfs(1);
		if (!allvisited()) {
			total++;
		}
		c[ma[i]][mb[i]] = 1;
		c[mb[i]][ma[i]] = 1;
	}

	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	int S,h,m,s;
	
	scanf("%d",&S);
	
	h=S/3600;
	m=(S-3600*h)/60;
	s=S-(3600*h+60*m);
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}	

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#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 FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  int a, b;
  cin >> a >> b;
  if(a + b == 15) cout << "+";
  else if(a * b == 15) cout << "*";
  else cout << "x";
}

Measured memory_bytes: 256
import Data.List (foldl', find)
import Data.Bits (shiftL, (.|.), testBit)

main = do
  _ <- getLine  
  a <- map read . words <$> getLine
  let f = foldl' (\a x -> a .|. shiftL a x) 1 a :: Integer
  let s = sum a

  let (Just ans) = find (\x -> testBit f x) [(s + 1) `div` 2 ..]
  print ans



Measured memory_bytes: 4348
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn main() {
    input! {
        x: isize,
    }
    for a in 0..=1000isize {
        for b in -1000..=1000isize {
            if a.pow(5) - b.pow(5) == x {
                println!("{} {}", a, b);
                return;
            }
        }
    }
}


Measured memory_bytes: 2140
#include<iostream>
using namespace std;
int checksort(int arr[],int n)
{
	for(int i = 0;i < n - 1;i++)if(arr[i] > arr[i+1])return 0;
	return 1;
}
int main()
{
	int n;cin >> n;
	int arr[n];
	for(int i = 0;i < n;i++)cin >> arr[i];
	int i = 0;int j = n - 1,check = 0;
	int temp;
	for(int i = 0;i < n;i++)
	{
		for(int j = n - 1;j >= 0;j--)
		{
			if(!checksort(arr,n)){
				temp = arr[i];
				arr[i] = arr[j];
				arr[j] = temp;
				if(!checksort(arr,n))
				{
					temp = arr[i];
				arr[i] = arr[j];
				arr[j] = temp;
				}
			}
			else 
			{
				check = 1;
				break;
			}
		}
		if(check == 1)break;
	}
	if(check == 1)cout << "YES";
	else cout << "NO";
	return 0;
}

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

int main(void){
    int n;
    int x[100];
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>x[i];
    }

    int ans_=1,max=-1,test=0;
    for(;ans_<101;++ans_){
        test=0;

        for(int i=0;i<n;++i){
            test+=(x[i]-ans_)*(x[i]-ans_);
        }

        if(max==-1||test<max){
            max=test;
        }
    }

    cout<<max;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    int ans;
    int tmp = N;
    int cnt = 0;
    while (tmp > 0) {
        tmp /= 10;
        cnt++;
    }

    if (cnt == 1) ans += N;
    else if (cnt == 2) ans = 9;
    else if (cnt == 3) ans = 9 + N - 100 + 1;
    else if (cnt == 4) ans = 9 + 900;
    else if (cnt == 5) ans = 9 + 900 + N - 10000 + 1;
    else if (cnt == 6) ans = 9 + 900 + 90000;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import kotlin.math.abs

fun main(args: Array<String>) {
    var (x, k, d) = readLine()!!.toString().split(' ').map { abs(it.toLong()) }
    var ans = 0L
    if (k >= x / d) {
        k -= x / d
        x -= x / d * d
        k %= 2
    }
    println(abs(x - d * k))
}

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

int main(){
    int n;
    cin >> n;
    double ans = 0;
    for(int i=0; i<n; i++){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY") ans += x;
        else ans += x * 380000.0;
    }
    cout << fixed << setprecision(10) << ans << endl;
}

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

int fibo(int num){
    if(num < 3) return 1;
    int o = 1;
    int oo = 1;
    for(int n=2; n<num; n++){
        int res = o + oo;
        oo = o % 1000000007;
        o = res % 1000000007;
    }
    return o;
}

int main(){
    int N,M;
    cin >> N >> M;
    if(M == 0){
        int res = fibo(N+1);
        cout << res << endl;
        return 0;
    }
    int a[M];
    for(int m=0; m<M; m++){
        cin >> a[m];
    }
    int fl = 0;
    vector<int> vec;
    vec.reserve(N+1);
    vec.push_back(a[0]);
    for(int m=1; m<M; m++){
        if(a[m]-a[m-1] == 1) fl = 1;
        vec.push_back(a[m]-a[m-1]-1);
    }
    vec.push_back(N-a[M-1]);
    if(fl == 1){
        cout << "0" << endl;
        return 0;
    }
    else{
        long long res = 1;
        for(int n=0; n<vec.size(); n++){
            int atai = fibo(vec[n]);
            atai %= 1000000007;
            res *= atai;
            res %= 1000000007;
        }
        cout << res << endl;
    }
}


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

using namespace std;

int A, B, C, X, Y;

int main(){
	scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);
	C *= 2;
	bool ok = (C < (A + B));
	int res = 0;
	if(ok){
		int k = min(X, Y);
		res += k * C;
		X -= k, Y -= k;
	}
	int val = (C < A) ? C : A;
	res += X * val;
	val = (C < B) ? C : B;
	res += Y * val;
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,m;
    cin>>n>>m;
    int ans=0;
    int tle=0;
    int x=1;
    rep(i,m){
        tle+=1900;
        x*=2;
    }
    n-=m;
    ans+=n*x*100;
    ans+=tle*x;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
p = [(int(i)+1)/2 for i in input().split()]
ansi = sum(p[0:k-1])
ans = 0
for i in range(k-1,n):
    a1 = p[i-k+1]
    if ansi + p[i] >= ans:
        ans = ansi + p[i]
    ansi = ansi - a1 + p[i]
print(ans)

Measured memory_bytes: 23524
import sys
from io import StringIO
import unittest


def resolve():
    # get input
    a, b, c = input().split()

    work = ""

    work = b
    b = a
    a = work

    work = c
    c = a
    a = work

    print(a + " " + b + " " + c)




class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1 2 3"""
        output = """3 1 2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """100 100 100"""
        output = """100 100 100"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """41 59 31"""
        output = """31 41 59"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 6440
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String[] X = new String[3];
		X[0] = sc.next();
		X[1] = sc.next();
		X[2] = sc.next();

		sc.close();

		int turn = 0;
		int[] idx = new int[3];

		char ans;
		while (true) {
			if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			}

			char c = X[turn].charAt(idx[turn]++);
			turn = (char) (c - 'a');
		}

		out.println(ans);

	}

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


Measured memory_bytes: 21844
#include<stdio.h>

int main() {

	int n, a[100],i,j;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	for (i = n-1;i>=0;i--) {
		if (i > 0) printf("%d ", a[i]);
		else printf("%d", a[j]);
	}
	printf("\n");

	return 0;


}



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

// #include<iostream>
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) 
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) 
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) 
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) 
#define forrc(i,l,r) for (int i= (int)(r); i>= (int)(l); --i)

#define pb push_back
#define fi first
#define se second
#define mp make_pair

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


#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)


#define present(c,x) ((c).find(x) != (c).end())


#define cpresent(c,x) (find(all(c),x) != (c).end())

#define sz(a) int((a).size())


 using namespace std;


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
typedef long long ll;
typedef unsigned long long int ull;
int main(){
  int x;
  cin >> x;
  int flag=0,jl;
  forc(i,-118,119){
    forc(j,-119,118){
      if(pow(i,5)-pow(j,5)==x){
        flag=1;
        jl=j;
        break;
      }
    }
    if(flag==1){
      cout << i << " " << jl << endl;
      break;
    }
  }
}

Measured memory_bytes: 4024
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int H1 = sc.nextInt();
		int M1 = sc.nextInt();
		int H2 = sc.nextInt();
		int M2 = sc.nextInt();
		int K = sc.nextInt();
		int span = (H2 * 60 + M2) - K;
		System.out.print(span - (H1 * 60 + M1));
	}
}

Measured memory_bytes: 35740
n = int(input())

A = list(map(int, input().split()))

q = int(input())

for _ in range(q):
    
    b, m, e = map(int, input().split())

    list_rotate = [None] * (e - b)
    
    for k in range(e - b):

        index = ((k + (e - m))) % (e - b)

        list_rotate[index] = A[b + k]

    A = A[:b] + list_rotate + A[e:]


print(*A)



Measured memory_bytes: 5832
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  int h, w, m, ans = 0, th = 0, tw = 0; cin >> h >> w >> m;
  v1i bh(h, 0), bw(w, 0), mh, mw; set<pii> b;
  rep(i, m){
    int ih, iw; cin >> ih >> iw; ih--; iw--;
    bh[ih]++; bw[iw]++; b.insert({ih, iw});
  }
  rep(i, h) th = max(th, bh[i]);
  rep(i, w) tw = max(tw, bw[i]);
  rep(i, h) if(th == bh[i]) mh.push_back(i);
  rep(i, w) if(tw == bw[i]) mw.push_back(i);
  ans = th + tw;
  long tc = (long)mh.size() * (long)mw.size();
  if(tc <= (long)m){
    ans--; bool tb = 0;
    rep(i, mh.size()){
      rep(j, mw.size()){
        pii tpi = {mh[i], mw[j]};
        if(!b.count(tpi)){
          ans++; tb = 1; break;
        }
      }
      if(tb) break;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int Partition(int A[], int p, int r) {
  int x = A[r];
  int i = p - 1;

  for (int j = p; j < r; j++) {
    if (A[j] <= x) {
      i++;
      int swap = A[i]; A[i] = A[j]; A[j] = swap;
    }
  }
  int swap = A[i + 1]; A[i + 1] = A[r]; A[r] = swap;

  return i + 1;
}

int main() {
  int n; cin >> n;
  int A[100000]; for (int i = 0; i < n; i++) cin >> A[i];

  int q = Partition(A, 0, n - 1);

  for (int i = 0; i < n; i++) {
    if (i == q)cout << "[" << A[i] << "]";
    else cout << A[i];

    if (i == n - 1)cout << endl;
    else cout << " ";
  }
}


Measured memory_bytes: 3480
/*
  AOJ 2515
  Title:Seishun 18 Kippu 2013
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

int N,T;
char st_time[6],st_name[51],ar_time[6],ar_name[50];
char station[10][51];
int  stay[10];
int timediff(char t1[],char t2[])
{
        int h1,h2,m1,m2;

        sscanf(t1,"%d:%d",&h1,&m1);
        sscanf(t2,"%d:%d",&h2,&m2);
        return((h2-h1)*60+(m2-m1));
}
main()
{
        int i,diff,cnt;

        scanf("%d %d",&N,&T);

        scanf("%s %s %s %s",st_time,st_name,ar_time,ar_name);
        if(N==1)
                printf("0\n");   
        else
        {
                for(i=1,cnt=0;i<N;i++)
                {
                        scanf("%s %s",st_time,st_name);
                        diff=timediff(ar_time,st_time);
                        if(diff>=T)
                        {
                                strcpy(&station[cnt][0],st_name);
                                stay[cnt]=diff;
                                cnt++;
                        }
                        scanf("%s %s",ar_time,ar_name);
                }
                printf("%d\n",cnt);
                for(i=0;i<cnt;i++)
                {
                        printf("%s %d\n",&station[i][0],stay[i]);
                }
        }
        return(0);
}

Measured memory_bytes: 624
#include <stdio.h>

#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define STR(i,str) for(int i=0;(str)[i];i++)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX3(a,b,c) ((a)>(b)?(a)>(c)?(a):(c):(b)>(c)?(b):(c))
#define MIN3(a,b,c) ((a)<(b)?(a)<(c)?(a):(c):(b)<(c)?(b):(c))
#define RNG(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define RNG3(a,b,c) ((a)>(b)?(b)>(c)?(a)-(c):(c)>(a)?(c)-(b):(a)-(b):(b)>(c)?(c)>(a)?(b)-(a):(b)-(c):(c)-(a))
#define MAXS(a,b) {if((a)<(b))(a)=(b);}
#define MINS(a,b) {if((a)>(b))(a)=(b);}



int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d\n", b + (b - a));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;


//xor和と加算和が等しいという条件を満たす部分列を数え上げる
// x xor y = x + y ↔︎ 二進数におけるどの桁を見てもビットが立っているのは高々一方のみ
int main(){
   ll n;
   cin >> n;
   vector<int> a(n);
   rep(i,n) cin >> a.at(i);

   //尺取法
   ll res=0;
   int right=0;
   int sum=0;
   for(int left=0; left<n; left++){
       while(right<n && (sum ^ a[right])==(sum + a[right])){
           sum += a[right];
           ++right;
       }
       res += right - left;
       if(right==left) right++;
       else sum -= a[left];
   }
   cout << res << endl;

}

Measured memory_bytes: 4028
n = int(input())
s = input()
r = g = b = 0
for i in range(n):
    if s[i] == "R": r += 1
    elif s[i] == "G": g += 1
    else: b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]: continue
        k = 2*j-i
        if k >= n: continue
        if s[k] not in (s[i],s[j]): ans -= 1
print(ans)

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

int f(int x, int y, int z) {
    return pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x;
}

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

    int num = 0;

    for (int i = 1; i < n; i++) {

        if (pow(i, 2) + 2 * i + 3 > n) {
            num = i - 1;
            break;
        }
    }

    vector<int> a(n, 0);
    for (int w = num; 1 <= w; w--) {
        for (int y = w; 1 <= y; y--) {
            for (int x = y; 1 <= x; x--) {
                int u = f(x, y, w);
                if (u <= n) {
                    if (x == y && y == w) {
                        a.at(u - 1)++;
                    } else if (x != y && y != w) {
                        a.at(u - 1) += 6;
                    } else {
                        a.at(u - 1) += 3;
                    }
                }
            }
        }
    }

    for (auto x : a) {
        cout << x << endl;
    }
}


Measured memory_bytes: 3512
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<stack>
#include<queue>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
#define int long long
using namespace std;
signed main(){
    string s; cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
MOD_N = 10 ** 9 + 7

def main
  n, k = gets.chop.split.map(&:to_i)
  arr = gets.chop.split.map(&:to_i)
  index = make_index(arr)
  res = 0
  index.each do |n1, n2|
    c = (n1 + n2) * k * (k + 1) / 2 - n1 * k
    res += c
    res = res % MOD_N
  end
  puts res
end

def make_index(arr)
  arr.map.with_index do |a, i|
    [small_before(arr, a, i), small_after(arr, a, i)]
  end
end

def small_after(arr, a, i)
  c = 0
  (i+1).upto(arr.size - 1) do |j|
    c += 1 if arr[j] < a
  end
  return c
end

def small_before(arr, a, i)
  c = 0
  0.upto(i - 1) do |j|
    c += 1 if arr[j] < a
  end
  return c
end

if __FILE__ == $0
  main
end

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int N,K,i,j,tmp,a,b,c;
c=0;
 
tmp=0;
b=1000000000;
cin>>N>>K;
a=N-K+1;
int A[N];
for(i=0;i<N;i++){
cin>>A[i];
 
}
sort(A, A + N);
for(i=0;i<a;i++){
c=abs(A[i]-A[i+K-1]);
 
if(c<b){
b=c;
}
}
 
cout<<b<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int H, W;
int my[] = {1, 0, -1, 0};
int mx[] = {0, 1, 0, -1};

void step(int &y, int &x, int my, int mx){
  y += my; x += mx;
  if(y >= H) y = H - 1;
  if(x >= W) x = W - 1;
  if(y < 0) y = 0;
  if(x < 0) x = 0;
}

int main() {
  while(cin >>W >>H && H){
    int y = 0, x = 0, d = 0;
    string s;
    while(cin >>s && s != "STOP"){
      if(s == "FORWARD"){
        int n; cin >>n;
        REP(i, n) step(y, x, my[d], mx[d]);
      }
      if(s == "BACKWARD"){
        int n; cin >>n;
        REP(i, n) step(y, x, -my[d], -mx[d]);
      }
      if(s == "LEFT") d = (d - 1 + 4) % 4;
      if(s == "RIGHT") d = (d + 1) % 4;
    }
    cout <<x + 1 <<" " <<y + 1 <<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;
LL MOD;
static const size_t MAX_N = 2000001;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL ans = 0;
		int n = -1, p;
		cin >> n >> p;
		if (n < 0) return 0;
		string s;
		cin >> s;
		if (p == 2 || p == 5) {
			for (int i = 0; i < n; ++i) {
				if (((s[i] - '0') % p) == 0) {
					ans += i + 1;
				}
			}
		} else {
			int dp[10000] = {1};
			MOD = p;
			modll d = 1, x = 0;
			for (int i = n - 1; i >= 0; --i) {
				x += d * (s[i] - '0');
				ans += dp[x];
				dp[x] += 1;
				d *= 10;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 644