akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
data = []
data << [0, 0, 0]
n.times do
    t, x, y = gets.strip.split.map(&:to_i)
    data << [t, x, y]
end

def is_reachable t1, x1, y1, t2, x2, y2
    # 次の地点までのマンハッタン距離
    d = (x2 - x1).abs + (y2 - y1).abs
    # かけたい時間
    t = t2 - t1
    # 最短ルートで行っても間に合わない
    return false if t < d

    # 余裕がある時、行ったり来たりで調整できるか？
    return (d - t) % 2 == 0
end

reachable = true
for i in (0...n)
    t1, x1, y1 = data[i]
    t2, x2, y2 = data[i + 1]
    unless is_reachable(t1, x1, y1, t2, x2, y2)
        reachable = false
        break
    end
end

if reachable
    puts 'Yes'
else
    puts 'No'
end


Measured memory_bytes: 9596
n = gets.to_i
ans = Array.new

for k in 1..11111 do
    isbreak = false
    x = 5*k + 1
    for i in 2 .. x - 1 do
        if x % i == 0
            isbreak = true
            break
        end
    
    end
    next if isbreak
    ans << x
    if ans.size == n
        puts ans.join(" ")
        exit
    end
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int s,sum=1;
  cin >> s;
  if(s==1||s==2){cout << 4 << endl;}
  else{while(s!=4){
    if(s%2==0){
      s=s/2;
    }
    else{
      s=3*s+1;
    }
           sum++;
  } 
      
  cout << sum+3 << endl;
      }
}

Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))
m = float("INF")
for i in range(N - K + 1):
    if x[i + K - 1] * x[i] < 0:
        m = min(m, x[i + K - 1] - x[i] + min(abs(x[i + K - 1]), abs(x[i])))
    else:
        m = min(m, max(abs(x[i + K - 1]), abs(x[i])))
print(m)


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int h, w;
  cin >> h >> w;

  int g[10][10];
  for (int y = 0; y < 10; y++) {
    for (int x = 0; x < 10; x++) {
      cin >> g[y][x];
    }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }

  int wall[h][w];
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cin >> wall[y][x];
    }
  }

  ll ans = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (wall[y][x] != -1)
        ans += g[wall[y][x]][1];
    }
  }

  cout << ans << endl;
}


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

using namespace std;


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

  int a,b;

  cin>>a;
  cin>>b;

   if(a==2 && b==3 || a==3 && b==2)
    cout<<"1"<<endl;
   else if(a==1 && b==3 ||a==3 && b==1)
    cout<<"2"<<endl;

    else if(a==1 && b==2 ||a==2 && b==1)
    cout<<"3"<<endl;


return 0;   }



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[]D = new int[N];
		var list = new List<int>[N];
		for(var i=0;i<N;i++){
			list[i] = new List<int>();
			D[i] = -1;
		}
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			int a1 = int.Parse(str2[0]);
			int a2 = int.Parse(str2[1]);
			list[a1-1].Add(a2-1);
			list[a2-1].Add(a1-1);
		}
		var listA = new List<int>();
		listA.Add(0);
		while(listA.Count>0){
			var listB = new List<int>(listA);
			listA.Clear();
			for(var i=0;i<listB.Count;i++){
				int a3 = listB[i];
				for(var j=0;j<list[a3].Count;j++){
					int a4 = list[a3][j];
					if(D[a4]==-1 && a4!=0){
						D[a4] = a3+1;
						listA.Add(a4);
					}
				}
			}
		}
		Console.WriteLine("Yes");
		for(var i=1;i<N;i++){
			Console.WriteLine(D[i]);
		}
	}
}

Measured memory_bytes: 35248
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

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

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

ll upper(ll n,ll m){return (n+m-1)/m;};
ll rounding(ll n){return (long double)n+0.5;};

bool inG(ll x,ll n){return 0<=x && 0<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

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

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  string s;
  cin>>s;

  int ans=1000;

  REP(i,2,s.size()) ans=min(ans,abs(753-stoi(s.substr(i-2,3))));

  cout<<ans<<endl;

  return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 15

struct node{
  int key;
  struct node *prev, *next;
};

typedef struct node * Nodepointer;

void insert(int);
void delete(int);
void deleteFirst();
void deleteLast();
Nodepointer find(int);
void print(void);

Nodepointer head;
int cnt = 0;

int main(){
  int n, x;
  int i;
  char com[LEN];

  head = (Nodepointer)malloc(sizeof(struct node));
  head -> next = head;
  head -> prev = head;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf(" %s", com);
    if(strcmp(com, "insert") == 0){
      scanf(" %d", &x);
      //printf("%d\n", x);
      insert(x);
      //printf("%d\n", x);
    }
    else if(strcmp(com, "delete") == 0){
      scanf(" %d", &x);
      delete(x);
    }
    else if(strcmp(com, "deleteFirst") == 0) deleteFirst();
    else if(strcmp(com, "deleteLast") == 0) deleteLast();
  }

  print();
  
  return 0;
}

//末尾のノードのnextはhead
//head -> prev は末尾のノード

void insert(int x){
  Nodepointer newnode;
  newnode = (Nodepointer)malloc(sizeof(struct node));
  newnode -> key = x;
  newnode -> next = head -> next;
  head -> next -> prev = newnode;
  //printf("debug\n");
  head -> next = newnode;
  newnode -> prev = head;
  cnt++;
}

void delete(int x){
  Nodepointer delnode;
  if((delnode = find(x)) != NULL){
    if(delnode == head) return;
    //printf("debug\n");
    delnode -> prev -> next = delnode -> next;
    delnode -> next -> prev = delnode -> prev;
    free(delnode);
    cnt--;
  }
  else return;
}

void deleteFirst(){
  Nodepointer delnode;
  delnode = head -> next;
  if(delnode == head) return;
  delnode -> prev -> next = delnode -> next;
  delnode -> next -> prev = delnode -> prev;
  //printf("debug\n");
  free(delnode);
  cnt--;
}

void deleteLast(){
  Nodepointer delnode;
  delnode = head -> prev;
  if(delnode == head) return;
  delnode -> prev -> next = delnode -> next;
  delnode -> next -> prev = delnode -> prev;
  //printf("debug\n");
  free(delnode);
  cnt--;
}

Nodepointer find(int x){
  Nodepointer p;
  for(p = head->next; p != head; p = p -> next){
    if(p -> key == x) return p;
  }
  return NULL;
}

void print(){
  Nodepointer p;
  //printf("debug\n");
  for(p = head->next ;p->next != head; p = p->next ){
    printf("%d ", p -> key);
  }
  printf("%d\n", p -> key);
}



Measured memory_bytes: 33048
#include<iostream>
using namespace std;
int main(){
  int k,s,cnt=0;
  cin >> k >> s;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      if(s-x-y>=0&&s-x-y<=k) cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7;
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }

int main(){
  ll A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  
  if(A+B<=C*2){
    cout<<A*X+B*Y<<endl;
  }
  
  else{
   if(X>Y){
     cout<<min(Y*C*2+(X-Y)*A,X*C*2)<<endl;
  }
  
    else{
cout<<min(X*C*2+(Y-X)*B,Y*C*2)<<endl;
}
  }
}
    

Measured memory_bytes: 256
// In The Name Of God
#include <iostream>
#include <string.h>
#include <algorithm>
#include <set>
#include <vector>
#include <climits>
#include <map>
#include <queue>
#include <math.h>
#include <iomanip>

#define sqr(A) ((A) * (A))
#define F first
#define S second
#define MP make_pair
#define BSZ  __builtin_popcount
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e2 + 20;
int a[N], b[N], n, ans;

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int sz = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] == a[i - 1])
			sz++;
		else {
			ans += sz / 2;
			sz = 1;
		}
	}
	if (sz > 1)
		ans += sz / 2;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    for( int i = 0; i < 12; ++i ){
        cout << s[i];
        if( i == 3 ){
            cout << " ";
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import scala.io.Source

object Main{
  def main(args: Array[String]){
    val lines = for{
      in <- Source.stdin.getLines
    }yield if(isPrime(in.toInt)) in else -1

    println(lines.filter(_ != -1).length)
  }

  def isPrime(n: Int): Boolean = (2 to Math.sqrt(n).toInt).forall(n % _ != 0)
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;cin>>s;

  bool no = (count(s.begin(), s.end(), 'N') == 0) && (count(s.begin(), s.end(), 'S') > 0);
  no = no || (count(s.begin(), s.end(), 'S') == 0) && (count(s.begin(), s.end(), 'N') > 0);
  no = no || (count(s.begin(), s.end(), 'W') == 0) && (count(s.begin(), s.end(), 'E') > 0);
  no = no || (count(s.begin(), s.end(), 'E') == 0) && (count(s.begin(), s.end(), 'W') > 0);

  if (no){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanNum = new Scanner(System.in);
		int S = scanNum.nextInt();
		int h = S/3600;
		int m = (S%3600)/60;
		int s = (S%3600)%60;
		System.out.println(h+":"+m+":"+s);
	}
}

Measured memory_bytes: 17360
//
// Created by Abhishek Bansal on 9/01/2020.
//
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll m = 1e9+7;
long long moduloMultiplication(long long a,
                               long long b,
                               long long mod)
{
    long long res = 0; // Initialize result

    // Update a if it is more than
    // or equal to mod
    a %= mod;

    while (b)
    {
        // If b is odd, add a with result
        if (b & 1)
            res = (res + a) % mod;

        // Here we assume that doing 2*a
        // doesn't cause overflow
        a = (2 * a) % mod;

        b >>= 1; // b = b / 2
    }

    return res;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

    ll n; cin >> n;ll a[n+1], su[n+1];su[0]=0;
    for(ll i=1;i<=n;i++) {cin >> a[i];su[i] = su[i-1] + a[i];}
    ll ans = 0;
    for(ll i=1;i<n;i++) {
        ans += moduloMultiplication(a[i], su[n]-su[i], m);
    }
    cout << ans%m;

//    string s, t; cin >> s >> t;
//    for(int i=0;i<s.length();i++) {
//        if (t[0] == s[i]) {
//
//        }
//    }

    return 0;
}

Measured memory_bytes: 6712
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
	
def main():
	N, K = map(int, input().split())
	X = input().split(" ")
	X = [int(s) for s in X]
	
	left_val = bisect_left(X, 0)
	start = 0
	if left_val - K >= 0:
		start = left_val - K
		
	ans = -1
	while True:
		end = start + (K-1)
		#print(end)
		if end >= len(X):
			break
		
		tmp = X[end] - X[start]
		tmp2 = min(abs(X[start] - 0), abs(X[end] - 0))
		
		if ans == -1 or ans > tmp + tmp2:
			ans = tmp + tmp2
			
		start += 1
		
	print(ans)
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 14872
import java.util.*;
import java.util.Map.Entry;
 
 
 
public class Main{
	
	public int num;
	public int vol;
 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd(long a, long b) {
		if (b == 0) {
			return a;			
		}
		return gcd(b, a % b);
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 long n=0,s=0,e=0,w=0;
	 
	 String S=sc.next();
	 char[] c=S.toCharArray();
	 
	 for(int i=0;i<S.length();i++) {
		 if(c[i]=='N') {
			 n++;
		 }else if(c[i]=='S') {
			 s++;
		 }else if(c[i]=='E') {
			 e++;
		 }else if(c[i]=='W') {
			 w++;
		 }
	 }
	
	 if((Math.min(n,s)!=0&&Math.min(e, w)!=0)||(Math.min(n,s)!=0&&e==0&&w==0)||(Math.min(e,w)!=0&&n==0&&s==0)) {
		 System.out.println("Yes");
	 }else {
		 System.out.println("No");
	 }

	
	
    
}
}


Measured memory_bytes: 24020
def fermat_binom(n,k,p):
  if k > n:
    return 0
  num = 1
  for i in range(n,n-k,-1):
    num = (num*i)%p
  denom = 1
  for i in range(1,k+1):
    denom = (denom*i)%p
  return (num * pow(denom,p-2,p))%p

if __name__ == '__main__':
  n, a, b = map(int, input().split())
  mod = 1000000007 
  k = pow(2, n, mod)
  r = k- 1- fermat_binom(n, a, mod) - fermat_binom(n, b, mod)
  r = (r%mod+mod)%mod
  print(max(r, 0))

Measured memory_bytes: 3064
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int N; scanf("%d",&N);
    ll ans=0;
    vec A(N+1);A[0]=0;
    rep(i,N){
        scanf("%lld",&A[i+1]);
        if(A[i]==1 && A[i+1]>0){
            A[i+1]--;ans++;
        }
        ans+=A[i+1]/2;
        A[i+1]=A[i+1]%2;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; cin >> n;
  vector<int> x(n), y(n); REP(i, n) cin >> x[i] >> y[i];
  vector<int> root(n);
  iota(ALL(root), 0);
  double ans = 0;
  long long pat = 1;
  FOR(i, 1, n + 1) pat *= i;
  do {
    double dist = 0;
    FOR(i, 1, n) {
      long long tmp_x = x[root[i - 1]] - x[root[i]], tmp_y = y[root[i - 1]] - y[root[i]];
      dist += sqrt(tmp_x * tmp_x + tmp_y * tmp_y);
    }
    ans += dist / pat;
  } while (next_permutation(ALL(root)));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int n, i, j, flag;
char S[201];
int main(){
  scanf("%s", S);
  while(S[n]){n++;}
  i=(n>>1)-1;
  while(1){
    flag=1;
    for(j=0; j<i; j++){
      if(S[j] != S[j+i]){flag=0; break;}
    }
    if(flag){break;}
    i--;
  }
  printf("%d\n", i*2);
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

const int nmax = 40, abmax = 10, inf = 1e6;

int a[nmax], b[nmax], c[nmax];
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];

int main() {
   int n, ma, mb;
   cin >> n >> ma >> mb;

   rep (i, n) {
      cin >> a[i] >> b[i] >> c[i];
   }

   for (int i = 0; i <= n; i++) {
      for (int ca = 0; ca <= nmax*abmax; ca++) {
         for (int cb = 0; cb <= nmax*abmax; cb++) {
            dp[i][ca][cb] = inf;
         }
      }
   }

   dp[0][0][0] = 0;
   for (int i = 0; i < n; i++) {
      for (int ca = 0; ca <= nmax*abmax; ca++) {
         for (int cb = 0; cb <= nmax*abmax; cb++) {
            if (dp[i][ca][cb] == inf) continue;
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb]);
            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
         }
      }
   }

   int ans = inf;
   for (int ca = 1; ca <= nmax*abmax; ca++) {
      for (int cb = 1; cb <= nmax*abmax; cb++) {
         if (ca*mb==cb*ma) ans = min(ans, dp[n][ca][cb]);
      }
   }

   if (ans == inf) ans = -1;
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 25984
#include<bits/stdc++.h> 
using namespace std; 
int main()
{ 
    int n,k; 
    scanf("%d %d", &n, &k); 
    int count=1; 
    while(n/k!=0){
         n=n/k;
         count++; 
        } 
      printf("%d\n",count);
     return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

vector<int> sieve_of_eratosthenes(int n = 200010) {
  vector<bool> is_prime(n+1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 0; i <= n; ++i) if (is_prime[i]) {
    for (int j = i+i; j <= n; j+=i) is_prime[j] = false;
  }
  vector<int> primes;
  for (int i = 2; i <= n; ++i) if (is_prime[i]) primes.push_back(i);
  return primes;
}

map<long long, int> prime_factorize(long long n, const vector<int> &primes) {
  map<long long, int> prime_factor;
  for (int p : primes) {
    if (n < (long long) p * p) break;
    while (n % p == 0) {
      prime_factor[p] += 1;
      n /= p;
    }
  }
  if (n != 1) prime_factor[n] += 1;
  return prime_factor;
}

struct RuntimeModComb {
private:
  unsigned int N;
  long long MOD;

public:
  vector<long long> fac;
  vector<long long> inv;
  vector<long long> ifac;

  RuntimeModComb(unsigned int N, long long MOD) : N(N), MOD(MOD), fac(), inv(), ifac() {
    fac.resize(N), inv.resize(N), ifac.resize(N);
    fac[0] = fac[1] = inv[1] = ifac[0] = ifac[1] = 1;
    for (size_t i = 2; i <= N; ++i) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
      ifac[i] = ifac[i-1] * inv[i] % MOD;
    }
  }
  long long comb(unsigned int n, unsigned int k) const {
    if (n < 0 || k < 0 || k > n) return 0;
    return (fac[n] * ifac[k] % MOD) * ifac[n-k] % MOD;
  }
};

int main() {
  int n, m; cin>>n>>m;
  auto primes = sieve_of_eratosthenes();
  auto prime_factor = prime_factorize(m, primes);

  RuntimeModComb mc(200010, MOD);
  long long ans = 1;
  for (auto x: prime_factor) {
    ans = (ans * mc.comb(x.second + n - 1, x.second)) % MOD;
  }
  print(ans);

  return 0;
}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

const long long int llinf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

#define Endl endl
#define pr(x) cout << x << endl
#define FOR(i,a,b) for(int i = a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define atcoder int(1e9) +7;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
#define all(x) x.begin,x.end();

char c[110][110];

int main() {

	int h, w;
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> c[i][j];
		}
	}

	rep(i, h) {
		rep(k ,2){
			rep(j, w) {
				cout << c[i][j];
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
from collections import Counter


def main():
    """
    blue: a, a, d
    red:  a, b, c

    a: 2-1= 1
    b,c: 0-1=-1
    d: 1-0=1
    """
    N = int(input())
    S = [input() for _ in range(N)]
    M = int(input())
    T = [input() for _ in range(M)]

    b = Counter(S)
    r = Counter(T)
    b_r = b - r

    ans = 0
    for word, count in b_r.most_common():
        ans = max(ans, count)
        break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3436
S = input()
a,b = int(S[:2]), int(S[2:])
if (a > 12 or a == 0 )and b <= 12 and b > 0:
  print('YYMM')
elif a <= 12 and (b > 12 or b == 0) and a > 0:
  print('MMYY')
elif a <= 12 and b <= 12 and a > 0  and b > 0:
  print('AMBIGUOUS')
else:
  print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    int sum = 0;
    int x = n;
    while(n){
        sum += n % 10;
        n /= 10;
    }
    if (x % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
n = gets.to_i
a = gets.split.map(&:to_i)
b = a.dup
(1..a.length-1).each { |idx| b[idx] = b[idx-1] + b[idx] }
bl = b.last
t = 0
max_from_top = 1
a.each.with_index do |ai, idx|
  if idx == a.length - 1
    if max_from_top < ai
      puts '-1'
      exit 0
    end
    t += ai
    break
  else
    nn = [bl - b[idx] + ai, max_from_top].min
    t += nn
    max_from_top = (nn - ai) * 2
    if max_from_top <= 0
      puts '-1'
      exit 0
    end
  end
end
puts t

Measured memory_bytes: 21476
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
#重み付き隣接リスト(weight-first)
n,m = map(int,readline().split())
g = [[] for i in range(n)]
for i in range(m):
    x,y = map(int,readline().split())
    x,y = x-1,y-1
    w = 1
    g[x].append((w,y))
    g[y].append((w,x))

#ダイクストラ法通常版
#O(ElogV)
import heapq
def dijkstra_heap(s,edge): #s:始点,g:グラフ
    #始点sから各頂点への最短距離
    d = [float("inf")] * len(edge)
    used = [True] * len(edge) #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]: #既に最小距離が確定しているなら
            continue
        v = minedge[1] #vに頂点を代入
        d[v] = minedge[0] #その頂点のコストに重みを代入
        used[v] = False #vには最小距離が入っていることが証明できる(ヒープキューを使用しているため)
        for e in edge[v]: #頂点vから伸びている辺の先をヒープキューに入れてく
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v],e[1]))
    return d #回しきったらreturn(たどり着けなかった頂点はinf.)

dist = dijkstra_heap(0,g)[-1]
print("POSSIBLE" if dist == 2 else "IMPOSSIBLE") 

Measured memory_bytes: 115376
#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>;

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

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

    int ans = N;
    while(ans > 0){
        ans = ans - 1000;
    }

    cout << abs(ans) << endl;

    return 0;
}

Measured memory_bytes: 3620
fn main() {
    let (n,m) = {
        let s = rv::<usize>();
        (s[0],s[1])
    };
    let mut c = vec![true;n];
    let mut g = vec![vec![];n];
    for _ in 0..m {
        let s = rv::<usize>();
        let (l,r,d) = (s[0]-1,s[1]-1,s[2]as i32);
        g[l].push((r,d));
        c[r]=false;
    }
    let mut a = vec![-1;n];
    let mut r = true;
    for i in 0..n { if r && c[i] {
        a[i]=0;
        r = f(i,&g,&mut a);
    }}
    r = r && a.into_iter().all(|a|a>=0);
    println!("{}",if r {"Yes"} else {"No"});
}
fn f(v:usize, g:&Vec<Vec<(usize,i32)>>, a: &mut Vec<i32>) -> bool {
    for &(u,d) in &g[v] {
        let d=a[v]+d;
        if a[u]<0 {
            a[u]=d;
            if d>1000000000 || !f(u,g,a) {
                return false;
            }
        }
        else if a[u]!=d {
            return false;
        }
    }
    true
}
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

Measured memory_bytes: 20732
import sys
sys.setrecursionlimit(1000000)
 
H,W = map(int,input().split())
S = [input() for i in range(H)]

L = [[0 for i in range(W)] for j in range(H)]
R = [[0 for i in range(W+1)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            L[i][j] = L[i][j-1] + 1
        else:
            L[i][j] = 0
            
        if S[i][W-1-j] == ".":
            R[i][W-1-j] = R[i][W-1-j+1] + 1
        else:
            R[i][W-1-j] = 0
        
U = [[0 for i in range(W)] for j in range(H)]
D = [[0 for i in range(W)] for j in range(H+1)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            U[i][j] = U[i-1][j] + 1
        else:
            U[i][j] = 0
           
        if S[H-1-i][j] == ".":
            D[H-1-i][j] = D[H-1-i+1][j] + 1
        else:
            D[H-1-i][j] = 0
        
        
ans = 0

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
            
print(ans)

Measured memory_bytes: 185988
loop do
  n, m = gets.split.map(&:to_i)
  break if n==0 and m==0
  es = Array.new(n+1){[]}
  m.times{
    a, b = gets.split.map(&:to_i)
    es[a] << b
    es[b] << a
  }
  if m>=n or es.any?{|a| a.size>2}
    puts "no"
    next
  end
  visited = Array.new(n+1){false}
  dfs = ->x{
    es[x].each{|y|
      if not visited[y]
        visited[y] = true
        dfs[y]
      end
    }
  }
  (1..n).each{|i|
    if es[i].size==0
      visited[i] = true
    elsif es[i].size==1
      visited[i] = true
      dfs[i]
    end
  }
  visited[0] = true
  if visited.all?
    puts "yes"
  else
    puts "no"
  end
end


Measured memory_bytes: 23852
#include <cmath>
#include <queue>
#include <vector>
#include <iostream>
#include <functional>

using namespace std;

int main()
{
	int V, E, S, T;

	cin >> V >> E;

	vector<int> X(V), Y(X);

	vector<vector<pair<int, double> > > G(V, vector<pair<int, double> >());

	for (int i = 0; i < V; i++)
	{
		scanf("%d", &X[i]);
		scanf("%d", &Y[i]);
	}
	
	for (int i = 0; i < E; i++)
	{
		scanf("%d", &S);
		scanf("%d", &T);

		G[S - 1].push_back(make_pair(T - 1, 100000.0 - sqrt((X[T - 1] - X[S - 1]) * (X[T - 1] - X[S - 1]) + (Y[T - 1] - Y[S - 1]) * (Y[T - 1] - Y[S - 1]))));
		G[T - 1].push_back(make_pair(S - 1, 100000.0 - sqrt((X[T - 1] - X[S - 1]) * (X[T - 1] - X[S - 1]) + (Y[T - 1] - Y[S - 1]) * (Y[T - 1] - Y[S - 1]))));
	}

	vector<bool> u(V, false);

	double res = 0.0; int C = 0;

	for (int p = 0; p < V; p++)
	{
		if (u[p]) { continue; }

		priority_queue<pair<double, int>, vector<pair<double, int> >, greater<pair<double, int> > > que;

		que.push(make_pair(0.0, p)); C++;

		while (!que.empty())
		{
			pair<double, int> r = que.top(); que.pop();

			int v = r.second;

			if (u[v]) { continue; }

			res += r.first; u[v] = true;

			for (int i = 0; i < G[v].size(); i++)
			{
				if (!u[G[v][i].first])
				{
					que.push(make_pair(G[v][i].second, G[v][i].first));
				}
			}
		}
	}

	double ret = 0.0;

	for (int i = 0; i < V; i++)
	{
		for (int j = 0; j < G[i].size(); j++)
		{
			ret += G[i][j].second;
		}
	}

	ret = ret / 2 - res;

	printf("%.9f\n", 100000.0 * (E - V + C) - ret);

	return 0;
}

Measured memory_bytes: 5132
n = int(input())
s = list(input())
l = []
for i in range(len(s)):
    x = set(s[:i])
    y = set(s[i:])
    li = list((x & y))
    for i in li:
        if li.count(i) >= 2:
            while True:
                if li.count(i) == 1:
                    break
                else :
                    li.remove(i)
    l.append(len(li))
print(max(l))

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

using namespace std;

const int N = 1234567;

int n, m;
pair<int, int> pr[N];
int fen[N];

void fadd(int i, int foo) {
  while (i < N) {
    fen[i] += foo;
    i += i & -i;
  }
}

int fget(int i) {
  int ret = 0;
  while (i > 0) {
    ret += fen[i];
    i -= i & -i;
  }
  return ret;
}

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int l, r; scanf("%d %d", &l, &r);
    pr[i] = make_pair(l, r);
  }
  sort(pr, pr + n, [&](const pair<int, int> a, const pair<int, int> b) {
    return a.second - a.first < b.second - b.first;
  });
  for (int d = 1, j = 0; d <= m; d++) {
    while (j < n && pr[j].second - pr[j].first + 1 < d) {
      fadd(pr[j].first, 1);
      fadd(pr[j].second + 1, -1);
      j++;
    }
    int ans = n - j;
    for (int i = 0; (long long) i * d <= m; i++) {
      ans += fget(i * d);
    }  
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }
    UnionFind uf(N);
    int x, y;
    for (int i = 0; i < M; i++) {
        cin >> x >> y;
        uf.unionSet(x - 1, y - 1);
    }
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (uf.findSet(i, p[i] - 1)) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

ll combination(ll x, ll y) {
  y = min(y, x - y);
  vi a, b;
  for (ll i = 0; i < y; i++) a.push_back(x - i);
  for (ll i = 0; i < y; i++) b.push_back(i + 1);
  for (ll i = 0; i < y; i++) {
    for (ll j = 0; j < y; j++) {
      ll k = __gcd(a[i], b[j]);
      a[i] /= k;
      b[j] /= k;
    }
  }
  ll ret = 1;
  for (auto i: a) ret *= i;
  for (auto i: b) ret /= i;
  return ret;
}

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  vi v(N);
  for (ll i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  ll x = 0;
  for (ll i = 0; i < A; i++) {
    x += v[i];
  }

  unordered_map<ll, ll> m1;
  for (auto i: v) {
    m1[i] += 1;
  }

  ll ret = 0;

  for (ll i = A; i <= B; i++) {
    vi v2;
    for (ll k = 0; k < i; k++) {
      v2.push_back(v[k]);
    }
    ll sum = 0;
    for (auto j: v2) sum += j;
    if (x * v2.size() != sum * A) {
      break;
    }
    unordered_map<ll, ll> m2;
    for (auto j: v2) m2[j] += 1;
    ll j = 1;
    for (auto p: m2) {
      j *= combination(m1[p.first], p.second);
    }
    ret += j;
  }
  cout << fixed << setprecision(10);
  cout << (double)x / A << endl;
  cout << ret << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.buffer.readline
    M = int(input())
    ans = 0
    dc_sum = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print(ans - 1 + dc_sum//9 - 1)
    else:
        print(ans - 1 + dc_sum//9)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42748
use std::cmp;
use std::io;

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

const SPLIT_DELIMITER: char = ' ';
#[allow(dead_code)]
fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

fn main() {
    let mut l: usize;
    let mut r: usize;
    let mut ans = 9999999;
    input!(l, r);
    let q = r-l;
    l = l % 2019;
    r = r % 2019;

    if q>2019 {
        l += 2019;
        r = r + 2019 + 2019;
    }

    for i in l..r {
        for j in i + 1..r + 1 {
            ans = cmp::min(ans, (i * j) % 2019);
        }
    }
    p(ans);
}

Measured memory_bytes: 4352
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll n,m,s; cin>>n>>m>>s;
  struct Train {
    ll s, c, d;
    Train(ll s,ll c,ll d):s(s),c(c),d(d){}
    bool operator>(const Train& x) const {return d>x.d;}
  };
  vector<Train> graph[n];
  for (int i = 0; i < m; i++) {
    ll u,v,a,b; cin>>u>>v>>a>>b; u--; v--;
    graph[u].emplace_back(v,a,b);
    graph[v].emplace_back(u,a,b);
  }
  for (int i = 0; i < n; i++) {
    int c,d; cin>>c>>d;
    graph[i].emplace_back(i,-c,d);
  }
  constexpr ll MAX = 200;
  constexpr ll INF = 1e18;
  vector<array<ll, MAX+1>> dp(n);
  for (auto& arr:dp) arr.fill(INF);
  dp[0][min(s,MAX)] = 0;
  priority_queue<Train, vector<Train>, greater<>> qs;
  qs.emplace(0,s,0);
  while (not qs.empty()) {
    auto [s,c,d] = qs.top(); qs.pop();
    if (d > dp[s][min(c,MAX)]) continue;
    for (auto t:graph[s]) {
      if (c-t.c<0) continue;
      if (d+t.d >= dp[t.s][min(c-t.c,MAX)]) continue;
      dp[t.s][min(c-t.c,MAX)] = d+t.d;
      qs.emplace(t.s, c-t.c, d+t.d);
    }
  }
  for (int i = 1; i < n; i++) {
    cout << *min_element(dp[i].begin(), dp[i].end()) << '\n';
  }

  return 0;
}


Measured memory_bytes: 3876
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>K>>N;
  int a[N];
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int ans=a[N-1]-a[0];
  for(int i=1;i<N;i++){
    ans=min(ans,K-(a[i]-a[i-1]));
  }
  cout<<ans<<endl;
}


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

int main(){

    int i,n,x;
    cin>> n;
    std::vector<int> v;
    map<int,int> mp;
    for(i = 0;i < (n - 1);i++){
        cin>> x;
        v.push_back(x);
        mp[v[i]] = 0;
    }
    for(i = 0;i  <(n-1);i++){
        if((i + 2) > v[i])
            mp[v[i]]++;
    }
    i =  0;
    for(i = 1;i<= n;i++){
        cout<<mp[i]<<endl;
        //i++;
    }
/*
    for (int j = i + 1; j <= n; j++)
    {
        cout<<"0\n";
    }
    */
}

Measured memory_bytes: 13480
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    string s;
    cin >> s;
    bool yes = false;
    for (auto c : s) {
        yes |= c == '7';
    }
    cout << (yes ? "Yes" : "No");
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  ll x;
  cin >> N >> x;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<vector<ll>> C(N, vector<ll>(N, longinf));
  rep(i, N) rep(d, N) {
    if(d) C[i][(i+d)%N] = min(C[i][(i+d-1)%N], C[i][(i+d)%N]);
    else  C[i][i] = A[i];
  }
  rep(j, N) rep(d, N) {
    if(d) C[(j+N-d)%N][j] = min(C[(j+N-d+1)%N][j], C[(j+N-d)%N][j]);
  }
  ll mn = longinf;
  rep(d, N) {
    ll tmp = x * d;
    rep(j, N) {
      tmp += C[(j+N-d)%N][j];
    }
    mn = min(tmp, mn);
  }
  cout << mn << endl;
  return 0;
}


Measured memory_bytes: 31744
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = str(input())

c = 0
for i in range(len(N)):
    c += int(N[i])
    c %= 9

if c == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 68700
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long X, Y;
    long long Z;
    long long N, D;
    cin >> N >> D;
    D=D*D;
    long long count=0;
    for(int i=0;i<N;i++){
        cin >> X >> Y;
        Z=(X*X)+(Y*Y);
        if(D>=Z)count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>

using namespace std;
 
int main() {

    char ch;
    int counter[26] = {0};

    // while ( (ch=getchar()) == 1)
    // while (scanf("%c", &ch)==1)
    // while ( scanf("%c", &ch) != EOF )
    // while ( cin >> ch )

    while (scanf("%c", &ch) != -1)
    {
        if ( 'A'<=ch && ch<='Z' )
        {
            counter[ch - 'A']++;
        }
        else if ( 'a'<=ch && ch<='z' )
        {
            counter[ch - 'a']++;
        }
    }

    for ( int i=0; i< sizeof(counter)/sizeof(int); i++)
    {
        printf("%c : %d\n", (int)'a'+i, counter[i]);
    }
    return 0;
}


Measured memory_bytes: 3228