akhauriyash/Code-Regression huggingface dataset:
#import heapq
#import itertools
#import math
#import numpy as np
#import sys

#N = int(input())
N, K, Q = list(map(int, input().split()))
A = [int(input()) for _ in range(Q)]
S = [0] * N
for i in A :
    S[i - 1] += 1
for s in S :
    if s > Q - K :
        print('Yes')
    else :
        print('No')


#for i in range(1,N+1) :
#    s = 0
#    for a in A :
#        if i == a :
#            s += 1
#    if s > Q - K :
#        print('Yes')
#    else :
#        print('No')


#T = [list(map(int,input().split())) for _ in range(N)]
#H = [K] * N
#print(A)
#print(H)
#for a in A :
#    for i in range(N) :
#        if i == int(a) :
#            pass
#        else :
#            H[i -1] -= 1
#for h in H :
#    if h > 0 :
#        print('Yes')
#    else :
#        print('No')
#ans = ['Yes' if h > 0 else 'No' for h in H]
#for a
#print(ans)

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n*a, b) << endl;
  return 0;
}


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

int main () {
  int n,k;
  cin>>n>>k;
  vector<int>p(n);
  for (int i=0;i<n;i++){
    cin>>p[i];
  }
  int mx =0;
  int check =0;
  for (int i=0;i<k;i++){
    check += p[i];
    }
  mx =check;
  for (int i=0;i<n-k;i++){
    check =check -p[i]+p[i+k];
    if(mx <check){
     mx  =max(mx,check);
    }
  }
  mx =mx+k;
  double ans = mx;
    ans /=2;
    printf("%.10f\n",ans);
  }


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;

struct graph {
	struct node {vector<int> v; int d = -1;};
	map<int, node> nodes;

	void read_all() {
		int n, id, k, v;
		cin >> n;
		while (n--) {
			cin >> id >> k;
			if (k)
				while (k--) {
					cin >> v;
					nodes[id].v.push_back(v);
				}
			else
				nodes[id].v = {};
		}
	}
	void traverse(int id) {
		nodes[id].d = 0;
		queue<int> q;
		q.push(id);
		while (!q.empty()) {
			node &n = nodes[q.front()];
			q.pop();
			for (int x: n.v) {
				if (nodes[x].d != -1)
					continue;
				else
					nodes[x].d = n.d + 1;
				q.push(x);
			}
		}
	}
	void display_all() {
		for (auto &n: nodes)
			cout << n.first << " " << n.second.d << endl;
	}
};

int main() {
	graph g;
	g.read_all();
	g.traverse(1);
	g.display_all();
}



Measured memory_bytes: 3168
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;
import java.util.*;
 
public class Main {
    Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
    	new Main(); 
    }
 
    public Main() {
    	new aoj0076().doIt();
    }
    class aoj0076{
    	void doIt(){
    		double mapx[] = new double[1001];
    		double mapy[] = new double[1001];
    		mapx[1] = 1;
    		mapy[1] = 0;
    		int rand = 90;
    		for(int i = 2;i < 1001;i++){
    			mapx[i] = (1/Math.sqrt(i-1))*(mapx[i-1]*Math.cos(Math.toRadians(rand)) - mapy[i-1]*Math.sin(Math.toRadians(rand))) + mapx[i-1];
    			mapy[i] = (1/Math.sqrt(i-1))*(mapx[i-1]*Math.sin(Math.toRadians(rand)) + mapy[i-1]*Math.cos(Math.toRadians(rand))) + mapy[i-1];
    		}
    		while(true){
    			int n = sc.nextInt();
    			if(n == -1)break;
    			System.out.printf("%.2f\n",mapx[n]);
    			System.out.printf("%.2f\n",mapy[n]);
    		}
    	}
    }
}

Measured memory_bytes: 26536
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define pb push_back
    #define mk make_pair
    #define ft first
    #define sc second
    #define ppb pop_back
    #define sz size
    #define forn(i,a,n) for(i=a;i<n;i++)
    #define M 1000000007
    #define inf 2e18
    
    int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i])
            ans++;
    }
    cout<<ans;

    return 0;
    } 

Measured memory_bytes: 3780
N = int(input())
A=list(map(int,input().split()))
count_list = [0 for _ in range(N)]
choose_list = [0 for _ in range(N)]
for a in A:
    count_list[a-1] += 1
for i,c in enumerate(count_list):
    choose_list[i] = int(c*(c-1)/2)
sum = sum(choose_list)

for i in range(N):
    ball = A[i] - 1
    ball_num = count_list[ball] - 1
    print(sum - choose_list[ball] + ball_num*(ball_num-1)//2)


Measured memory_bytes: 26140
object Main {
  var _buf = List[String]()
  def str : String = {
    if (_buf.isEmpty) _buf = io.StdIn.readLine().split(' ').toList
    val res = _buf.head
    _buf = _buf.tail
    return res
  }
  def strs(n:Int) : Array[String] = {
    return new Array[String](n).map(i => str)
  }
  def int : Int = { return str.toInt }
  def long : Long = { return str.toLong }
  def ints(n:Int) : Array[Int] = { return strs(n).map(_.toInt) }
  def longs(n:Int) : Array[Long] = { return strs(n).map(_.toLong) }

  def main(args:Array[String]) = {
    val (n, l) = (int, int)
    val s = strs(n)
    println (s.sorted.mkString(""))
  }
}


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


int n,k, heights[100005];
const int INF = 2000000000;
int main(){
    ios_base::sync_with_stdio(), cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> k;
    int dp[n];
    for(int i = 0; i < n; ++i)
        cin >> heights[i], dp[i] = INF;
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i-1; j >= max(0, i-k); --j){
            dp[i] = min(dp[i], dp[j] + abs(heights[i]-heights[j]));
        }
    }
    cout << dp[n-1];
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


ll dp[55][5010];
int N, P;
int A[55];

int main(void) {
	cin >> N >> P;
	rep(i, N) cin >> A[i];

	dp[0][0] = 1;
	rep(i, N) rep(j, 5010) {
		if(dp[i][j] == 0) continue;
		dp[i + 1][j + A[i]] += dp[i][j];
		dp[i + 1][j] += dp[i][j];
	}
	ll ans = 0;
	rep(i, 5010) if(i % 2 == P) ans += dp[N][i];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
row, collumn = list(map(int, input().split()))
A = []
for _ in range(row):
    line = list(map(int, input().split()))
    A.append(line)

b = []
for _ in range(collumn):
    b.append(int(input()))

# けいさん
for r in range(row):
    sum = 0
    for c in range(collumn):
        sum += A[r][c] * b[c]
    print(sum)


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

#define PI (atan(1.0)*4.0)

int main(){
	int n;
	while( cin >> n, n!=-1 ){
		double x = 1.0, y = 0.0;
		double theta = PI/2.0;
		for( int i=1; i<n; i++ ){
			x += cos(theta);
			y += sin(theta);
			theta = PI/2.0 + atan2( y, x );
		}
		cout << x << endl;
		cout << y << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string S;
int p,ch[1<<8];
ll bnf();

ll getNum(){
  ll res=0;
  while(isdigit(S[p])) res=res*10+S[p++]-'0';
  return res;
}

ll get(ll &a,ll b,char c){
  if(c=='+')a+=b;
  if(c=='-')a-=b;
  if(c=='*')a*=b;
  return a;
}

ll calc(int c){
  ll res,t;
  if(S[p]=='(') p++,res=bnf(),p++;
  else res=getNum();
  while(p<S.size()&&S[p]!=')'&&ch[S[p]]>c)t=S[p++],get(res,calc(ch[t]),t);
  return res;
}

ll bnf(){
  ll res=calc(-1),t;
  while(p<S.size()&&S[p]!=')')t=S[p++],get(res,calc(ch[t]),t);
  return res;
}

int main(){
  cin>>S; 
  ll res=bnf();
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      for(int k=0;k<3;k++) {
	ch['+']=i,ch['-']=j,ch['*']=k;
	p=0;
	res=max(res,bnf());
      }
  
  cout<<res<<endl;
  return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b;
	cin >> a >>b;
	if(a+b==15) puts("+");
	else if(a*b==15) puts("*");
	else puts("x");
	return 0;
}


Measured memory_bytes: 256
/*
* @Author: Kabid
* @Date:   2020-04-29 14:50:32
* @Last Modified by:   Kabid
* @Last Modified time: 2020-05-13 14:18:23
*/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define  in(x) scanf("%d",&x);
#define out(x) printf("%d",x);
#define  ins(x)  scanf("%s",x);
#define outs(x) printf("%s",x);
#define lin puts("");
#define _ putchar(' ');

int t;       //test cases
int i,j;	 //iterators
ll  n,k,p,f,c,s;   //variables
string q;
char h;
int main(){
	cin>>n>>k;
	cout<<(n*(n-1))/2+k*(k-1)/2<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (ll)1e9+7
#define LLINF (ll)1e30
// #define int ll
using namespace std;
const int MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[100010][3],dp[100010][3];
    cin>>n;
    rep(i,n) cin>>a[i][0]>>a[i][1]>>a[i][2];
    rep(i,n)rep(j,3) dp[i][j]=-LLINF;
    rep(i,3) dp[0][i]=a[0][i];
    rep2(i,1,n)rep(j,3){
            ll b=-LLINF;
            rep(l,3){
                if(j != l) b=max(b,dp[i-1][l]);
            }
            dp[i][j]=b+a[i][j];
    }
    ll ans=max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>

using namespace std;

typedef long long ll;

const ll q = 10000000000 + 7;

int main() {
	
	string a, b, c;
	a = "Sunny";
	b = "Cloudy";
	c = "Rainy";

	string s;
	cin >> s;
	if (s == a) {
		cout << b;
	}
	else if (s == b) {
		cout << c;
	}
	else {
		cout << a;
	}
	cout << endl;

	return 0;
}

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

int main()
{
    string a;
    cin >> a;
    if(a[2]==a[3]&&a[4]==a[5])
    {
    cout << "Yes"<< endl;
    }
    else
    {
    cout << "No"<< endl;
        
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


a,b = list(map(int, input().split()))
ans = (b-1) // (a-1) + int((b-1)%(a-1)!=0)
print(ans)

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

int main() {
    ll K, N;
    cin >> K >> N;
    ll d = -1;
    vector<ll> A(N);
    rep(i, N){
        cin >> A[i];
    }
    rep(i, N){
        ll dis;
        if(i+1 == N){
            dis = (K-A[N-1]) + A[0];
        }
        else{
            dis = A[i+1] - A[i];
        }
        d = max(d, dis);
    }
    cout << K - d;
}

Measured memory_bytes: 1792
from collections import deque
s=input()
s_list=list(s)
length=len(s)
K=int(input())
o=[]
x=deque(sorted(set(s)))

while len(o) < K:
    letter=x.popleft()
    X=[i for i , x in enumerate(s_list) if x==letter]
    for i in X:
        for j in range(i+1,length+1):
            if not s[i:j] in o:
                o.append(s[i:j])
            if j-1-i == 5:
                break

o.sort()
print(o[K-1])


Measured memory_bytes: 9556
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int K, N;
	cin >> K >> N;
	cat mod = 998244353;
	vector< vector<cat> > cnt_pair(K/2+1, vector<cat>(N+1, 0));
	cnt_pair[0][0] = 1;
	for(int i = 0; i < K/2; i++) {
		cnt_pair[i+1] = cnt_pair[i];
		cat sum = 0;
		for(int j = 0; j <= N; j++) {
			cnt_pair[i+1][j] += 2 * sum;
			if(cnt_pair[i+1][j] >= mod) cnt_pair[i+1][j] -= mod;
			if(cnt_pair[i+1][j] >= mod) cnt_pair[i+1][j] -= mod;
			sum += cnt_pair[i][j];
			if(sum >= mod) sum -= mod;
		}
	}
	vector< vector<cat> > cnt_free(K+1, vector<cat>(N+1, 0));
	cnt_free[0][0] = 1;
	for(int i = 0; i < K; i++) {
		cat sum = 0;
		for(int j = 0; j <= N; j++) {
			sum += cnt_free[i][j];
			if(sum >= mod) sum -= mod;
			cnt_free[i+1][j] += sum;
			if(cnt_free[i+1][j] >= mod) cnt_free[i+1][j] -= mod;
		}
	}
	for(int k = 2; k <= 2*K; k++) {
		cat ans = 0;
		int num_pairs = 0, num_free = 0;
		for(int i = 1; i <= K; i++) {
			int i2 = k-i;
			if(i2 <= 0 || i2 > K) num_free++;
			else if(i2 > i) num_pairs++;
		}
		for(int i = 0; i < (k%2 == 0 ? 2 : 1); i++)
			for(int j = 0; j <= N-i; j++)
				ans = (ans + cnt_pair[num_pairs][j] * cnt_free[num_free][N-i-j]) % mod;
		if(ans < 0) ans += mod;
		cout << ans << "\n";
	}
	return 0;
}

// look at my code
// my code is amazing


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  priority_queue<int> X;
  int x = 0;
  X.push(0);
  for (int i = 0; i < N; i++) {
    if (S[i] == 'I') {
      x++;
      X.push(x);
    }
    else if (S[i] == 'D') {
      x--;
      X.push(x);
    }
  }
  cout << X.top() << endl;
}


Measured memory_bytes: 256
use std::collections::BTreeMap;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let a: Vec<usize> = sc.vec(n);

    if (1..n).all(|i| a[i - 1] < a[i]) {
        println!("1");
        return;
    }

    let mut ok = n;
    let mut ng = 0;
    while ok - ng > 1 {
        let x = (ok + ng) / 2;
        if solve(&a, x) {
            ok = x;
        } else {
            ng = x;
        }
    }
    println!("{}", ok + 1);
}

fn solve(a: &Vec<usize>, x: usize) -> bool {
    let n = a.len();
    let mut state = State {
        map: BTreeMap::new(),
        color: x,
    };

    let mut start = 0;
    for i in 1..n {
        if a[i] <= a[i - 1] {
            state.increment(a[i]);
            start = i + 1;
            break;
        }
    }

    for i in start..n {
        if a[i] <= a[i - 1] {
            state.resize(a[i]);
            if !state.increment(a[i]) {
                return false;
            }
        }
    }
    true
}

struct State {
    map: BTreeMap<usize, usize>,
    color: usize,
}

impl State {
    fn increment(&mut self, index: usize) -> bool {
        if let Some(&v) = self.map.get(&index) {
            if v == self.color {
                self.map.remove(&index);
                if index == 1 {
                    false
                } else {
                    self.increment(index - 1)
                }
            } else {
                *self.map.get_mut(&index).unwrap() += 1;
                true
            }
        } else {
            self.map.insert(index, 1);
            true
        }
    }

    fn resize(&mut self, s: usize) {
        while let Some(&key) = self.map.keys().next_back() {
            if key > s {
                self.map.remove(&key);
            } else {
                break;
            }
        }
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n;
  string s,t;
  cin>>n>>s>>t;
  for(int i=n;i>0;i--){
    if(s.substr(n-i,i)==t.substr(0,i)){
      cout<<n+(n-i);
      return 0;
    }
  }
  cout<<n+n;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
const int MAXN = 2e5+5;
const int ROOT = 1;
std::vector<int> G[MAXN];
bool seen[MAXN];
int C[MAXN];
int a, b, p, x;
int N, Q;

void dfs(int cur) {
  seen[cur] = true;
  for (auto nxt: G[cur]) {
    if (seen[nxt]) continue;
    C[nxt] += C[cur];
    dfs(nxt);
  }
}

void init() {
  for (int i = 1; i <= N; ++i) {
    C[i] = 0;
    G[i].clear();
    seen[i] = false;
  }
}

int main() {
  scanf(" %d%d", &N, &Q);
  init();
  for (int i = 1; i < N; ++i) {
    scanf(" %d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int q = 0; q < Q; ++q) {
    scanf(" %d%d", &p, &x);
    C[p] += x;
  }
  dfs(ROOT);
  for (int i = 1; i <= N; ++i) {
    printf("%d%c", C[i], (i == N) ? '\n' : ' ');
  }
  return 0;
}

Measured memory_bytes: 20608
#include <iostream>

bool month_like(int num) {
    return 0 < num && num < 13;
}

int main() {
    std::string yymm, ans;
    int yy, mm;
    bool y_ok, m_ok;
    std::cin >> yymm;
    yy = std::stoi(yymm.substr(0, 2));
    mm = std::stoi(yymm.substr(2, 2));
    
    if (month_like(yy) && month_like(mm)) {
        ans = "AMBIGUOUS";
    } else if (month_like(yy) && !month_like(mm)) {
        ans = "MMYY";
    } else if (!month_like(yy) && month_like(mm)) {
        ans = "YYMM";
    } else {
        ans = "NA";
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n, r[200000], i, rmin, profit;

  scanf("%d", &n);

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

  rmin = r[0];
  profit = r[1] - r[0];
  for (i = 1; i < n; i++) {
    if ( profit < r[i] - rmin){
      profit = r[i] - rmin;
    }
    if ( rmin > r[i]) {
      rmin = r[i];
    }
  }

  printf("%d\n", profit);

  return 0;
}


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

struct item{int value, weight;};
int n, w;
vector<item> items;
vector<vector<int>> dp_table;
void dp() {
    dp_table.resize(n+1, vector<int>(w+1,0));
    rep(i, n+1) {
        rep(j, w+1) {
            if (i == 0 || j == 0) continue;
            dp_table[i][j] = dp_table[i-1][j];
            if (j-items[i].weight >= 0) {
                // dp_table[i][j] = max(dp_table[i-1][j-items[i].weight]+items[i].value, dp_table[i][j]);
                dp_table[i][j] = max(dp_table[i][j-items[i].weight]+items[i].value, dp_table[i][j]);
            }
            // printf("%d ", dp_table[i][j]);
        }
        // printf("\n");
    }
}

int main() {
    cin >> n;
    cin >> w;
    items.resize(n+1);
    rep(i, n+1) {
        if (i == 0) continue;
        cin >> items[i].value;
        cin >> items[i].weight;
    }
    dp();
    cout << dp_table[n][w] << endl;
}


Measured memory_bytes: 6824
s = input()
t = input()
if len(s) < len(t):
  print("UNRESTORABLE")
  exit()

start = -1
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j] != "?" and s[i+j] != t[j]:
      break
  else:
    start = i

if start == -1:
  print("UNRESTORABLE")
else:
  ans_list = list(s)
  for i in range(len(ans_list)):
    if start <= i < start+len(t):
      ans_list[i] = t[i-start]
    elif ans_list[i] == "?":
      ans_list[i] = "a"
  print("".join(ans_list))
    
    


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

int main() {
  string S, T;
  cin >> S >> T;
  int n=S.size();
  
  string ans="No"; 
  for(int i=0; i<n; i++){
    if(S==T)ans="Yes";
    S=S+S.at(0);
    S.erase(0,1);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main()
  {
     int a,b,c;
   scanf("%d%d%d",&a,&b,&c);
     a=a+b+c; 
     b=a-b-c;
     c=a-b-c;    
     a=a-b-c;
   printf("%d %d %d",a,b,c);
     return 0;
  }

Measured memory_bytes: 128
//
//  main.cpp
//  Empty_Test_Keep_Empty
//
//  Created by Davidia on 2018-09-26.
//  Copyright © 2018 Davidia. All rights reserved.
//

#include <bits/stdc++.h>
/*
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
*/
using namespace std;

#define MAXN 100
#define INF 1000000001 // watch it
#define MAXV 100000

typedef long long  ll;
typedef pair<int,int> vw;



int dp[MAXV+5][MAXN+5];
vw items[MAXN+5];


int process(int v, int p){
    if (v <= 0) {
        return 0;
    }
    if (p < 0){
        return INF;
    }
    if (dp[v][p] != 0){
        return dp[v][p];
    }
    int best = min(process(v, p-1), process(v-items[p].first, p-1) + items[p].second);
    return dp[v][p] = best;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,W; cin >> n >> W;
    for (int i = 0; i < n; i++){
        cin >> items[i].second >> items[i].first;
    }
    
    int l = 1, r = 100002;
    int best_so_far = r;
    while (l <= r){
        int mid = (l+r)/2;
        if (process(mid, n) <= W){
            best_so_far = mid;
            l = mid+1;
        }
        else{
            r = mid-1;
        }
    }
    
    cout << best_so_far << '\n';
    
    
    
    return 0;
}






Measured memory_bytes: 41088
#!/usr/bin/env python3
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()
ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))

print(ans)


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

typedef long long LL;

const int N=1000,M=5000,INF=(1<<30)-1;

int n,x[N+9];
struct side{
  int y,next;
}e[N+9];
int lin[N+9],cs;

void Ins(int x,int y){e[++cs].y=y;e[cs].next=lin[x];lin[x]=cs;}

void into(){
  scanf("%d",&n);
  for (int i=2;i<=n;++i){
  	int x;
  	scanf("%d",&x);
  	Ins(x,i);
  }
  for (int i=1;i<=n;++i)
    scanf("%d",&x[i]);
}

int dp[N+9],dp0[M+9];

void Dfs_dp(int k,int fa){
  for (int i=lin[k];i;i=e[i].next)
    if (e[i].y^fa) Dfs_dp(e[i].y,k);
  dp[k]=INF;
  for (int i=0;i<=x[k];++i) dp0[i]=INF;
  dp0[0]=0;
  for (int i=lin[k];i;i=e[i].next)
    if (e[i].y^fa)
	  for (int j=x[k];j>=0;--j){
	  	int t=INF;
	  	if (j>=x[e[i].y]) t=min(t,dp0[j-x[e[i].y]]+dp[e[i].y]);
	  	if (j>=dp[e[i].y]) t=min(t,dp0[j-dp[e[i].y]]+x[e[i].y]);
	  	dp0[j]=t;
      }
  for (int i=0;i<=x[k];++i) dp[k]=min(dp[k],dp0[i]);
}

void work(){
  Dfs_dp(1,0);
}

void outo(){
  puts(dp[1]==INF?"IMPOSSIBLE":"POSSIBLE");
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> d(N);
	for (auto &x : d) {
		cin >> x;
	}
	sort(d.begin(), d.end());
	int ans = d[N / 2] - d[N / 2 - 1];
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
    int H, W;
    scanf("%d%d",&H, &W);
    while(!(H==0 && W == 0)){
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if((i + j) % 2 == 0){
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d%d",&H, &W);
    }
}

Measured memory_bytes: 2604
/*bismillah ->                                                                                                         << Suirkhanov Meyirlan >>
  GL HF


                                                                                                                      42

    bless my code =)
                                                                                                            NEVER FOLLOW YOUR RULES :D HAHAHAHA
*/


///scanf ("%d%d", &x, &y);
///printf("%d", &a)

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define pii pair < int , int >
#define pll pair < ll, ll >
#define pb push_back
#define pf psuh_front
#define mp make_pair
#define fi first
#define se second
#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define eb emplace_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll N = 2 * 1e3 + 7;
const ld pi = 3.14159265359;
const int INF = 1e20 + 7;
const double eps = 1e-9;

const int xi[4] = {-1, 0, +1, 0};
const int yj[4] = {0, +1, 0, -1};
const int xxi[4] = {+1, 0, -1, 0};
const int yyj[4] = {0, -1, 0, +1};

set < char > st;

string s;

int ans;

int main(){

  //freopen("bridge.in", "r", stdin);
  //freopen("bridge.out", "w", stdout);

  fast
  randoperation;

  ///           ||
  ///start here \/

  cin >> s;

  st.insert(s.begin(), s.end());

  if(st.size() == 1){
    cout << 0;
    return 0;
  }

  for(int i = s.size() - 2; i >= 0; i--){
    if(s[i] != s[i + 1]){
      ans++;
      s[i + 1] = s[i];
    }
  }

  cout << ans;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
int x,y,z,w,q;
cin>>x>>y>>z>>w>>q;
if(y>=x&&z>=x){
if(w>=q){cout<<x+q-50<<endl;} 
else if(q>=w){cout<<x+w-50<<endl;}
}

else if(x>=y&&z>=y){
if(w>=q){cout<<y+q-50<<endl;} 
else if(q>=w){cout<<y+w-50<<endl;}
}

else if(x>=z&&y>=z){
if(w>=q){cout<<z+q-50<<endl;} 
else if(q>=w){cout<<z+w-50<<endl;}
}

return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<long long int>
#define vi  vector<int>
#define vpi vector<pair<int,int>>
#define prec fixed<<setprecision(12)
#define set(x) __builtin_popcount(x)
#define ffs(x) __builtin_ffs(x)
#define clz(x) __builtin_clz(x)
#define inf 1000000007
#define linf 1000000000000000007
#define a(v) v.begin(),v.end()
void fast(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
}


int main(){
	fast;
    int n;
    cin >> n;
    cout << prec << 2*M_PI*n;
    
}


Measured memory_bytes: 3788
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sn = new Scanner(System.in);
        
        int n = sn.nextInt();
        int m = sn.nextInt();
        int tmp = 0;
        int cnt = 0;
        int all = 0;
        double num = 0.0;
        double cal = 0.0;
        Integer[] array = new Integer[n];
        
        cal = (double) 1 / (4 * m);
        
        // 各商品の票数を取得し、総督票数を求める
        for(int i = 0; i < n; i++) {
            array[i] = sn.nextInt();
            all += array[i];
        }

        // 人気商品として選択できる最低得票数を求める
        num = (double) (all * cal);
        
        // 
        for(int i = 0; i < array.length; i++) {
            if(array[i] >= num){
                cnt++;
            }
        }
        
        if(cnt >= m) {
            System.out.print("Yes");
            return;
        }
        
        System.out.print("No");
    }
}


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

int main()
{
   
   int N,K,X,Y,i,money;
   cin>>N>>K>>X>>Y;
   money=0;
   for(i=1;i<=N;i++){
       if(i<=K){
           money+=X;
       }
       else{
           money+=Y;
       }
           
   }
   
   cout<<money<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=1,mod=1e9+7,v;cin>>n;
  lvector A(n),T(3,0);rep(i,n) cin>>A[i];
  if(A[0]!=0) {print(0);return 0;}
  ans*=3;T[0]=1;
  for(ll i=1;i<n;++i) {
    v=0;
    rep(j,3) if(T[j]==A[i]) v++;
    ans=(ans*v)%mod;
    rep(j,3) if(T[j]==A[i]) {T[j]++;break;}
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

ll dp[13];

int main() {
    string s; cin >> s;
    int n = s.size();
    vint mo(n);
    mo[n-1] = 1;
    for (int i = n-2; i >= 0; i--) {
        mo[i] = (mo[i+1]*10)%13;
    }
    dp[0] = 1;
    for (int i = n-1; i >= 0; i--) {
        ll next_dp[13];
        rep(i,13) next_dp[i] = 0;
        if (s[i] != '?') {
            int x = (s[i] - '0')*mo[i]%13;
            rep(j,13) {
                next_dp[(j+x)%13] += dp[j];
            }
        }
        else {
            rep(j,13) {
                rep(k,10) {
                    int x = k*mo[i]%13;
                    next_dp[(j+x)%13] += dp[j];
                }
            }
        }
        rep(i,13) next_dp[i] %= mod;
        swap(dp,next_dp);
    }
    cout << dp[5] << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <queue>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

const std::vector<std::pair<int, int>>
    dxys{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

void solve() {
    int h, w, k, sx, sy, gx, gy;
    std::cin >> h >> w >> k >>
        sx >> sy >> gx >> gy;
    --sx, --sy, --gx, --gy;

    std::vector<std::string> grid(h);
    for (auto& s : grid) std::cin >> s;

    auto dist = vec(h, vec(w, -1));
    dist[sx][sy] = 0;
    std::queue<std::pair<int, int>> que;
    que.emplace(sx, sy);

    while (!que.empty()) {
        auto [x, y] = que.front();
        que.pop();

        for (auto [dx, dy] : dxys) {
            for (int d = 1; d <= k; ++d) {
                auto nx = x + dx * d,
                     ny = y + dy * d;

                if (nx < 0 || h <= nx ||
                    ny < 0 || w <= ny ||
                    grid[nx][ny] != '.' ||
                    (dist[nx][ny] != -1 &&
                     dist[nx][ny] <= dist[x][y])) break;

                if (dist[nx][ny] == -1) {
                    dist[nx][ny] = dist[x][y] + 1;
                    que.emplace(nx, ny);
                }
            }
        }
    }

    std::cout << dist[gx][gy] << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 12136
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();
		boolean boo = false;
		while(true) {
			boo = isPrime(x);
			if(boo) {
				System.out.println(x);
				break;
			}
			x++;
		}
//		System.out.println(b);
	}

	private static boolean isPrime(int b) {
//		if(b%2 == 0) { return false; }
//		double sq = Math.sqrt(b);
//		for(int c=3;c<sq;c+=2) {
//			if(b%c==0) {
//				return false;
//			}
//		}
		for(int c=2;c<b;c++) {
			if(b%c==0) {
				return false;
			}
		}

		return true;
	}
}


Measured memory_bytes: 21972
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;



int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main()
{
    int n,m,sum=0,i;
    cin>>n>>m;
    int arr[m];
    for(i=0;i<m;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    if(sum<=n)
        cout<<n-sum<<endl;
    else
        cout<<"-1"<<endl;
   return 0;
}


Measured memory_bytes: 3624
//Author: AnandRaj anand873
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test(t) int t;cin>>t;while(t--)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define rforn(i,b,a) for(int i=b-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl;

const int MOD = 1e9+7,MAX = 1e6+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
//////////////////Sieve////////////////////

int main()
{
	fastio
	int a,b;
	cin>>a>>b;
	set<int> S={1,2,3};
	S.erase(a);
	S.erase(b);
	cout<<*S.begin()<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define M 100005
char s[M],t[M];
int nxt[30][M],pre[30];
int main(){
	cin>>s+1>>t+1;
	int l1=strlen(s+1),l2=strlen(t+1);
	for(int i=l1*2;i>l1;--i)pre[s[i-l1]-'a']=i-l1;
	for(int i=l1;i>=0;--i){
		for(int j=0;j<26;++j)nxt[j][i]=pre[j];
		if(i)pre[s[i]-'a']=i;
	}
	int id=1,p=0;
	long long ans=0;
	while(id<=l2){
		int q=nxt[t[id]-'a'][p];
		if(!q){
			puts("-1");
			return 0;
		}
		if(p>=q){
			ans+=q+l1-p;
			p=q;
			++id;
		}else {
			ans+=q-p;
			p=q;
			++id;
		}
	}
	printf("%lld",ans);
	return 0;
}

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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	int a,b;
	cin >> a >> b;
	rep(i,a){
		rep(j,b){
			string s;
			cin >> s;
			if(s == "snuke"){
				cout <<  (char)('A'+j)  << i+1 << endl;
			}
		}

	}
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second 
#define ll long long 
#define _for(i,j,k) for(int i=j;i<k;i++)
#define endl  '\n'
#define inf 1<<29
const int mod=1e9+7;
const int MAX=1e6+5;
ll a[MAX]; 
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	ll k,n,sum=0;
	cin>>k>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll Max=-1;
	for(int i=1;i<n;i++)
	{
		sum+=a[i]-a[i-1];
		Max=max(Max,a[i]-a[i-1]);
	}
	sum+=k-a[n-1]+a[0];
	Max=max(Max,k-a[n-1]+a[0]);
	cout<<sum-Max;	
}

Measured memory_bytes: 1792
N = int(input())

def f(s, mx):
    if len(s) == N:
        print(s)
    else:
        for c in range(ord('a'), ord(mx) + 1):
            f(s + chr(c), chr(ord(mx) + 1) if c == ord(mx) else mx)
    
f("", 'a')


Measured memory_bytes: 9152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map> 
using namespace std;

#define LL long long
#define MOD (1000000007)

//126
struct Node {
	unsigned int connect;
	unsigned int weight;
};

int main() {
	LL N;

	scanf("%lld", &N);

	static vector<Node> node[100010];
	static char color[100010];

	for (int i = 0; i < N - 1; i++) {
		unsigned int u, v, w;

		scanf("%d %d %d", &u, &v, &w);

		Node n1;
		n1.connect = v;
		n1.weight = w;
		node[u].push_back(n1);

		Node n2;
		n2.connect = u;
		n2.weight = w;
		node[v].push_back(n2);
	}

	for (int i = 0; i <= N; i++) {
		color[i] = -1;
	}

	std::queue<unsigned int> q;

	color[1] = 0;
	q.push(1);

	//���D��T��
	while (q.size() > 0) {
		unsigned int index = q.front();
		q.pop();

		char c = color[index];

		for (auto item : node[index]) {
			if (color[item.connect] < 0) {
				//�܂��ʂ��Ă��Ȃ��m�[�h
				color[item.connect] = item.weight % 2 == 0 ? c : 1 - c;
				q.push(item.connect);
			}
		}
	}

	for (int i = 1; i <= N; i++) {
		printf("%d\n", color[i]);
	}

	return 0;
}

Measured memory_bytes: 6528
def resolve():
    X = int(input())
    max_num = 200
    for A in range(max_num):
        for B in range(max_num):
            if X == A**5 - B**5:
                print(A, B)
                return
            elif X == A**5 + B**5:
                print(A, -B)
                return

resolve()

Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;

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

int main(){
    char s[4];
    rep(i,4){
        cin>>s[i];
    }
    sort(s,s+4);
    if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
//using
using namespace std;
/*using vi = vector <int>;
using vs = vector <string>;
using vc = vector <char>;*/
//vector<vector<char> > hyou(N, vector<char>(N));
//define
#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
//グローバル変数宣言
int a=0,b=0,c=0,d=0;

signed main(){
    cin>>a>>b;
    if(b<10){c=a*10+b;}
    else if(b==100){c=a*1000+b;}
    else{c=a*100+b;}

        for(int i=4;i<317;i++){
            if(c==i*i)d=1;
        }
    if (d==1)
    {
        print("Yes")
    }else {print("No")}
    
}


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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

/////////////////////////////////////////////////////

ll N;
char S[202020];

ll i, j, k;

int main(){
    scanf("%s",S);
    N = strlen(S);
    rep(i,0,N){
        j *= 10;
        (j += (S[i] - '0'))%=9;
    }
    if(j==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int n;
vector<vector<int>> adjacencyList;
enum state {New, Working, Done};
vector<state> status;
vector<int> startTime;
vector<int> endTime;
int t = 0;

vector<vector<int>> GetAdjacencyList(int n)
{
	vector<vector<int>> adjacencyList(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			int v;
			cin >> v;
			adjacencyList[u][--v] = 1;
		}
	}
	return adjacencyList;
}

void DFS(int node)
{
	status[node] = Working;
	startTime[node] = ++t;
	for (int i = 0; i < n; i++) {
		if (adjacencyList[node][i] && status[i] == New) DFS(i);
	}
	status[node] = Done;
	endTime[node] = ++t;
}

int main()
{
	cin >> n;
	adjacencyList = GetAdjacencyList(n);
	status = vector<state>(n);
	startTime = vector<int>(n);
	endTime = vector<int>(n);
	for (int i = 0; i < n; i++) {
		if (status[i] != Done) DFS(i);
	}
	for (int i = 0; i < n; i++) cout << i + 1 << " " << startTime[i] << " " << endTime[i] << endl;
}



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

using namespace std;

int main() {
	string S;
	cin >> S;
	vector<int> cnt(2);

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '0') {
			cnt[0]++;
		}
		else {
			cnt[1]++;
		}
	}

	cout << min(cnt[0], cnt[1]) * 2 << endl;

	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner

import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val seqBuf = ArrayBuffer.empty[Int]
    for (i <- 0 until n) {
      val elem = sc.nextInt()
      seqBuf.append(elem)
    }
    (n, seqBuf.toVector)
  }

  // 長さlengthの半開区間の部分半開区間の数
  def numSubsection(length: Long): Long = length * (length + 1) / 2

  // 半開区間[left, right)の部分半開区間の数
  def numSubsection(left: Int, right: Int): Long = numSubsection(right - left)


  /**
    * 次のようなリストlistを返す
    * list(l) = max{r | satisfies(l, r)} (l=0,1,...,n-1)
    *
    * @param satisfies satisfies(l,r) ならば satisfies(l+1, r), satisfies(l, r-1)
    * @param n         >0
    */

  def maxRightSatisfies(satisfies: (Int, Int) => Boolean, n: Int): Vector[Int] = {
    val buf: ArrayBuffer[Int] = ArrayBuffer.fill(n)(0)
    // buf(l) = max{r | [l, r) satisfies the condition} となるように計算する
    var r = 0
    for (l <- 0 until n) {
      while (r <= n && satisfies(l, r)) {
        r = r + 1
      }
      buf(l) = r - 1
    }

    buf.toVector
  }

  def solve(n: Int, seq: Vector[Int]): Long = {
    // comulativeSum(k) = seq(0) + seq(1) + ... + seq(k-1)
    val cumulativeSum: Vector[Long] = seq.scanLeft(0: Long)(_ + _)
    val cumulativeXor: Vector[Long] = seq.scanLeft(0: Long)(_ ^ _)

    // seqの[left, right)の項の通常の和を求める
    // seq(left) + ... + seq(right-1) = (seq(0) + ... + seq(right-1)) - (seq(0) + ... + seq(left-1))
    def partialSum(left: Int, right: Int): Long = cumulativeSum(right) - cumulativeSum(left)

    // seqの[left, right)の項のXORの和を求める
    // XOR(^)の逆演算はXOR(^)
    def partialXor(left: Int, right: Int): Long = cumulativeXor(right) ^ cumulativeXor(left)

    // [right, left)の項の通常和 = [right, left)の項のXOR和
    val satisfies = (left: Int, right: Int) => partialSum(left, right) == partialXor(left, right)

    // maxRightList(l) = max{r | satisfies(l, r)}
    val maxRightList = maxRightSatisfies(satisfies, n)

    (0 until n).map(l => numSubsection(l, maxRightList(l))).sum - (1 until n).map(l => numSubsection(l, maxRightList(l - 1))).sum
  }

  def main(args: Array[String]): Unit = {
    val (n, seq) = read()
    println(solve(n, seq))
  }
}

Measured memory_bytes: 93340
#include <bits/stdc++.h>
const int M = 1e9 + 7;
using namespace std;
int main() {
    long long n, m, ans = 1; cin >> n >> m;
    if (abs(m - n) > 1) {cout << "0\n"; return 0;}
    for (int i = 1; i <= n; i++) ans = ans * i % M;
    for (int i = 1; i <= m; i++) ans = ans * i % M;
    cout << (n != m ? ans : ans * 2 % M) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)

using namespace std;

void solve(int N, string S) {
  vector<int> cnt(3, 0);
  REP(i, N) {
    if (S[i] == 'R')
      cnt[0]++;
    if (S[i] == 'G')
      cnt[1]++;
    if (S[i] == 'B')
      cnt[2]++;
  }
  long long ans(1);
  REP(i, 3)
    ans *= cnt[i];
    
  REP(j, N) {
    REP(i, j) {
      const int k = j + (j - i);
      if (k >= N || S[i] == S[j] || S[i] == S[k] || S[j] == S[k])
	continue;
      ans--;
    }
  }
  cout << ans << endl;
}

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

  string S;
  cin >> S;

  solve(N, S);
  return 0;
}


Measured memory_bytes: 3636