akhauriyash/Code-Regression huggingface dataset:
import numpy as np
from scipy.sparse import csr_matrix, csgraph
N, M = map(int, input().split())
P = tuple(map(lambda n: int(n) - 1, input().split()))
row, column = zip(*tuple(tuple(map(lambda n: int(n) - 1, input().split())) for _ in range(M)))
matrix = csr_matrix((np.ones((M,), dtype=np.int8), (row, column)), dtype=np.int8, shape=(N, N))
connection = csgraph.connected_components(matrix)[1]
print(sum(len(set(connection[list(pair)])) == 1 for pair in enumerate(P)))

Measured memory_bytes: 39000
#include<stdio.h>

#define INF (1<<30)

int adj[100][100],n;

void Dijkstra(void){
	int i,u,v,minCost;
	int c[100],visited[100];
	for(i=0;i<n;i++){
		c[i]=INF;	visited[i]=0;
	}

	c[0]=0;
	while(1){
		minCost=INF;
		for(i=0;i<n;i++){
			if(visited[i]==0 && c[i]<minCost){
				minCost=c[i];
				u=i;
			}
		}if(minCost==INF)break;

		visited[u]=1;
		for(v=0;v<n;v++){
			if(visited[v]==0 && c[v]>c[u]+adj[u][v]){
				c[v]=c[u]+adj[u][v];
			}
		}
	}

	for(i=0;i<n;i++){
		printf("%d %d\n",i,c[i]);
	}
}

int main(){
	int i,j,u,k,v,c;
	scanf("%d",&n);		for(i=0;i<n;i++)for(j=0;j<n;j++)adj[i][j]=INF;

	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++){
			scanf("%d%d",&v,&c);
			adj[u][v]=c;
		}
	}
	Dijkstra();

	return 0;
}



Measured memory_bytes: 2112
N,M = map(int, input().split())
H = list(map(int, input().split()))
P = [1]*N
for i in range(M):
  A,B = map(int, input().split())
  if H[A-1]<=H[B-1]:
    P[A-1]=0
  if H[A-1]>=H[B-1]:
    P[B-1]=0
print(sum(P))

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

using namespace std;

int main()
{
  int n;
  cin>>n;
  vector<int>v(n);
  for(int i=0;i<n;i++)
  {
    cin>>v[i];
  }
  int c=0,f=0;
  for(int i=0;i<n;i++)
  {
    	for(int j=0;j<i;j++)
        {
          if(v[j]<=v[i])
            f=1;
          else{
            f=0;
            break;
          }
          
        }
   		 if(f==1){
            c++;
            f=0;}
  }
  cout<<c+1<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
S = []
for _ in range(n):
    S.append(input())
alpha = [chr(ord('a') + i) for i in range(26)]
summary = [{c: 0 for c in alpha} for _ in range(n)]
for i, s in enumerate(S):
    for c in s:
        summary[i][c] += 1
ans = ''
for al in alpha:
    ans += al * min(summary, key=lambda x: x[al])[al]
print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    double K = sc.nextDouble();

    sc.close();

    double answer = 0.0;

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

      double count = i;
      double j = 0;

      while (count < K) {
        count = count * 2;
        j++;
      }

      answer += Math.pow(0.5,j) / N;

    }

    System.out.println(answer);
 
  }

}

Measured memory_bytes: 23252
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, D = map(int, input().split())
ans = 0
for i in range(N):
    x, y = map(int, input().split())
    if x*x+y*y <= D*D:
        ans += 1
print(ans)

Measured memory_bytes: 9232
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int count = 0;
        int count4 = 0;
        while(count < n){
            count += 4;
            count4++;
        }
        
        String result = "No";
        
        while(count4 > 1 && count != n){
            count4 -= 2;
            count -= 1;
        }
        if(count == n){
            result = "Yes";
        }
        
        System.out.println(result);
        
    }
}


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

using namespace std;

int main(){
    int n; cin >> n;
    while(n--){
        vector<int> v(10);
        for(int i=0; i< 10; i++) cin >> v[i];
        int a=0, b=0;
        bool is = true;
        for(int i=0; i< 10; i++){
            if(v[i] < a && v[i] < b){is = false; break;}
            if(a < b) (b<v[i]?b:a) = v[i];
            else (a<v[i]?a:b) = v[i];
        }
        cout << (is?"YES":"NO") << endl;
    }
}

Measured memory_bytes: 1184
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
int num, count=0;
  scanf("%d", &num);
  if(num >=100){
    count++;
    num-=100;
  }
  if(num>=10){
    count++;
    num -=10;
  }
  if(num>=1){
    count++;
  }
    
  printf("%d", count);
	return 0;
	
}

Measured memory_bytes: 128
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stderr, stdin, stdout, BufRead, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::{i64, u64, usize};
#[allow(unused_macros)]
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;($($r :tt ) *) =>{let mut s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .expect ("Parse error" ) } ;}
#[allow(unused_macros)]
macro_rules !dbg {($($a :expr ) ,*) =>{writeln !(&mut stderr () ,concat !($(stringify !($a ) ," = {:?}, " ) ,*) ,$($a ) ,*) .unwrap () ;} }
#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(non_snake_case)]
#[allow(dead_code)]
fn main() {
    input! {
        n: usize,
        v: [f64; n],
    }
    let mut v = v;
    v.sort_by_key(|&x| Total(x));
    let mut ans: f64 = (v[0] + v[1]) / 2.0;
    for i in 2..n {
        ans = (ans + v[i]) / 2.0;
    }
    dbg!(ans);
    println!("{:.6}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back

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

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int per(int n) {
  if (n==1) return 1;
  return per(n-1)*n;
}

int main() {
  int n;
  cin >> n;
  vector<int> p(n,0);
  vector<int> q(n,0);
  rep(i,n) cin >> p.at(i);
  rep(i,n) cin >> q.at(i);

  int pc = 0,qc = 0;
  vector<int> v(n,0);
  iota(v.begin(), v.end(), 1);
  FOR(i,0,per(n)) {
    int cp = 0,cq = 0;
    rep(j,n) {
      if(v.at(j) == p.at(j)) cp++;
      if(v.at(j) == q.at(j)) cq++;
    }
    if(cp==n) pc = i;
    if(cq==n) qc = i;
    next_permutation(v.begin(), v.end());
  }

  cout << abs(pc-qc) << endl;
  return 0;
}


Measured memory_bytes: 256
L = int(input())
A = [int(input()) for i in range(L)]

dp = [[0 for _ in range(5)] for _ in range(L)]

# print(dp)

def cost(place,zone):
    if zone == 0 or zone == 4:
        return A[place]
    elif zone == 1 or zone == 3:
        if A[place] == 0:
            return 2
        elif A[place] % 2 == 0:
            return 0
        else:
            return 1
    else:
        if A[place] % 2 == 0:
            return 1
        else:
            return 0

for j in range(5):
    dp[0][j] = cost(0,j)
# print(dp[0])

for i in range(L):
    for j in range(5):
        dp[i][j] = min(dp[i-1][0:j+1])+cost(i,j)
print(min(dp[L-1]))

Measured memory_bytes: 74060
#include <stdio.h>
#define NMAX 10
#define FMAX 3628800
#define min(a, b) ((a) < (b) ? (a) : (b))

int hash(int *a, int asize);
void rev_sort(int l, int r, int *a, int asize);
void bfs(int *a, int asize, char *memo, int depth);
int main (void)
{
  int i, n, fact = 1, res = 9, a[NMAX], b[NMAX];
  char memo1[FMAX], memo2[FMAX];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    fact *= i + 1;
    b[i] = i + 1;
  }
  for (i = 0; i < fact; i++) memo1[i] = memo2[i] = n;
  memo1[hash(a, n)] = memo2[hash(b, n)] = 0;
  bfs(a, n, memo1, 0);
  bfs(b, n, memo2, 0);
  for (i = 0; i < fact; i++) res = min(res, memo1[i] + memo2[i]);
  printf("%d\n", res);
}

int hash(int *a, int asize)
{
  int i, j, res = 0, fact = 1;
  for (i = 0; i < asize; i++) {
    int grade = 0;
    for (j = i + 1; j < asize; j++) if (a[i] < a[j]) grade++;
    res += grade * fact;
    fact *= asize - i;
  }
  return res;
}

void rev_sort(int l, int r, int *a, int asize)
{
  int i;
  for (i = 0; i < asize; i++) {
    int temp;
    if (l + i >= r - i) break;
    temp = a[l+i];
    a[l+i] = a[r-i];
    a[r-i] = temp;
  }
}

void bfs(int *a, int asize, char *memo, int depth)
{
  int i, j;
  if (depth >= 4) return;
  for (i = 0; i < asize; i++) {
    for (j = i + 1; j < asize; j++) {
      int h;
      rev_sort(i, j, a, asize);
      h = hash(a, asize);
      if (memo[h] > depth + 1) {
        memo[h] = depth + 1;
        bfs(a, asize, memo, depth + 1);
      }
      rev_sort(i, j, a, asize);
    }
  }
}


Measured memory_bytes: 8860
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod = 10e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prtd(n, var)  cout << fixed << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl

//----------------------------------------------------------------
ll gcd(ll x, ll y){
  if(x<y){return gcd(y,x);}
  if(y==0 || x==y) {return x;}
  else {return gcd(y, x%y);}
}

ll lcm(ll x, ll y){
  return x*y/gcd(x, y);
}

int main(void) {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  a = a-1;

  ll ans = b-a;
  ans -= b/c - a/c;
  ans -= b/d - a/d;
  ans += b/lcm(c,d) - a/lcm(c,d);

  prt(ans);
}


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

int main(void){
  int m, a[100][100];
  int b[100][100]={0};

  cin >> m;

  for(int i=0; i<m; i++){
    cin >> a[i][0];
    cin >> a[i][1];

    for(int j=2; j<a[i][1]+2; j++){
      cin >> a[i][j];
      b[i][ a[i][j]-1 ] = 1;
    }
  }

  for(int i=0; i<m; i++){
    cout << b[i][0];
    for(int j=1; j<m; j++){
      cout << " " << b[i][j];
    }
    cout << "\n";
  }
  return 0;
}



Measured memory_bytes: 3140
import sys
def input():
    return sys.stdin.readline()[:-1]
def main():
    # dp:=上からi桁目まで払える最小の枚数
    S = list(map(int, '0'+input()))
    l = len(S)
    dp = [[1e18]*2 for _ in range(1001001)]
    dp[0][0]=0
    for i in range(l):
        k = S[i]
        dp[i+1][0] = min(dp[i+1][0], dp[i][0]+k)
        dp[i+1][1] = min(dp[i+1][1], dp[i][0]+k+1)
        dp[i+1][0] = min(dp[i+1][0], dp[i][1]+10-k)
        dp[i+1][1] = min(dp[i+1][1], dp[i][1]+10-k-1)
    print(dp[l][0])

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 214976
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void add(ll& a, ll b){a = (a+b) % MOD;}

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    //cout<<s.find('X')<<endl;
    //cout<<s.find('F')<<endl;
    if(s.find('C')!=string::npos&&s.rfind('F')!=string::npos){
        if(s.find('C')<s.rfind('F')) cout<<"Yes";
        else cout<<"No";
    }
    else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    int N;
    cin>>N;
    vector<tuple<string,int,int>> A;
    for (int i=1; i<=N; i++) {
        string s;
        int p;
        cin>>s>>p;
        p=-p;
        A.emplace_back(s,p,i);
    }
    sort(A.begin(), A.end());
    
    for (int i=0; i<N; i++) {
        cout << get<2>(A[i]) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
const ll mod=1e9+7;
ll b; 
int main() {	
	//freopen("slyar.in", "r", stdin);  
    //freopen("slyar.out", "w", stdout);
    ios::sync_with_stdio(false);
  	cin.tie(0);
    cin>>b;
    while(b!=0)
    {
    	b=2*b;
    	int flag=0;
        for(int n=sqrt(b);n>=1;n--)
		{
			if(b%n==0)
			{
				if((b/n-n+1)/2>0&&(b/n-n+1)%2==0)
				{
				cout<<(b/n-n+1)/2<<" "<<n<<endl;
				break;
				}
				
			}
		}	
    	cin>>b;
    }
	//fclose(stdin);
    //fclose(stdout);
    return 0;
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> k(m,0);
  rep(i,n){
    int y;
    cin >> y;
    rep(i,y){
      int r;
      cin >> r;
      k[r-1]++;
    }
  }
  int ans=0;
  rep(i,m){
    if(k[i]==n)ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string N;
    cin >> N;
    bool j = true;
    int ans = 0;
    
    if (N[0] == '1') {
        reps(i, 1, N.length()) {
            if (N[i] != '0') {
                j = false;
                break;
            }
        }
    }
    else {
        j = false;
    }
    
    if (j) {
        ans = 10;
    }
    else {
        rep(i, N.length()) {
            ans += N[i] - '0';
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  string left;
  string right;
  int size = s.size();
  rep(i, size/2) left += s[i];
  for(int i = size/2; i < size; i++) right += s[i];
  
  int ans = 0;
  while(true) {
  string t = string(1, left.back());
  left.pop_back();
  right = t + right.substr(0, right.size()-1);
  right.pop_back();
  if(left == right) {
    ans = left.size() + right.size();
    cout << ans << endl;
    return 0;
  }
  }
}
  

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int A,B;
  cin >> A >> B;

  if(A == 1) A += 13;
  if(B == 1) B += 13;

  if(A > B) cout << "Alice" << endl;
  else if(A < B) cout << "Bob" << endl;
  else cout << "Draw" << endl;
}



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

int main(){
  int a,b;
  cin>>a>>b;
  string c = to_string(b);
  for (int i=0;i<c.size();i++){
    a*=10;
  }
  int x = a+b;
  double y = sqrt(x);
  
  if (floor(y) == y){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main()
{
int n,d,ans=0;

cin >> n >>d;

ans = n/(d+d+1);

if(n%(d+d+1)) cout << ans+1;
else cout << ans;

return 0;
}

Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
PII p[li];
vector<int> v;

int main(void){
	scanf("%d",&n);
	FOR{
		scanf("%d",&m);
		p[i].fi=m;
		p[i].se=i;
	}
	sort(p+1,p+n+1);
	FOR{
		printf("%lld ",p[i].se);
	}
	return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;
const ll INF = 1LL << 60;


int main() {
    ll a, b, k; cin >> a >> b >> k;
    bool flip = true;
    for(int i = 0; i < k; i++){
        if(flip){
            if(a & 1) a--;
            b += (a / 2);
            a /= 2;
        }else{
            if(b & 1) b--;
            a += (b / 2);
            b /= 2;
        }
        flip = !flip;
    }
    cout << a << ' ' << b << endl;

    return 0;
}


Measured memory_bytes: 3628
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll M =1e9+7;
const int N = 2e5+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)


int main()
{
   
     
        int m=M;
        
        string s,t;
        cin>>s>>t;
        
        int l=s.size(),n=t.size();
        
        rep(i,0,l-n+1)
        {
            int c=0;
            
            rep(j,0,t.size())
            {
                if(s[i+j]!=t[j])
                c++;
            }     
            
            m=min(c,m);
            
            
        }
        
        if(s==t)
        m=0;
        
        prin(m);
        
        
    
    
}

Measured memory_bytes: 3692
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF
 
		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}
 
	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		int total = 0;
		boolean fast = false;
		
		for(int i = 2; i < num.size(); i++){
			total += num.get(1);
			if(num.get(i-1) + num.get(1) - num.get(i) > 0 && fast){
				total -= num.get(1) - (num.get(i) + num.get(1) - (num.get(i-1) + num.get(1)));
			}
			fast = true;
		}
		System.out.println(total);
	}
}

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

int main(){

  int e, y,d;
  char c;
  cin >> e >> y;

  if(e == 0){
    if( y >= 1868 && y <= 1911){
      c = 'M';
      d = y - 1867;
    }
     if( y >= 1912 && y <= 1925){
      c = 'T';
      d = y - 1911;
    }
    if( y >= 1926 && y <= 1988){
      c = 'S';
      d = y - 1925;
    }
    if( y >= 1989 && y <= 2016){
      c = 'H';
      d = y - 1988;
    }
    cout << c << d;
  }

  if(e == 1){
    d = 1867 + y;
    cout << d;
  }  
 if(e == 2){
    d = 1911 + y;
    cout << d;
  }
  if(e == 3){
    d = 1925 + y;
    cout << d;
  } 
 if(e == 4){
    d = 1988 + y;
    cout << d;
 }

    cout << endl;

  

  
  return 0;
}



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

int n, a[101010], b[101010], c[101010];

int main(){
  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  sort(a, a + n);
  sort(b, b + n);
  sort(c, c + n);
  
  long long int res = 0;
  rep(i, n){
    long long int num_A = lower_bound(a, a + n, b[i]) - a;
    long long int num_B = upper_bound(c, c + n, b[i]) - c;
    num_B = n - num_B;
    //cerr << num_A <<" "<< num_B <<endl;
    res += (long)num_A * (long)num_B;
  }
  
  cout << res << endl;   
  return 0;
}


Measured memory_bytes: 1408
num_time = int(raw_input())
x = []
num_z = num_time/3600
num_h = (num_time%3600)/60
num_b = (num_time%3600)%60
x.append(num_z)
x.append(num_h)
x.append(num_b)
x = map(str, x)
print ":".join(x)

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin>>N>>M;
}
//=============================
void func(){}
//=============================
void solve()
{
    //m : black
    int l = M-N+1;
    int r = M+N-1;
    for(int i=l; i<=r;i++){
        cout<<i << ' ' ;
    }
    cout<<endl;
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
int MOD = 1e9 + 7;
const ld E = 1e-9;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#ifndef LOCAL
#define endl "\n"
#endif
#ifndef LONG_LONG_MAX
#define LONG_LONG_MAX LLONG_MAX
#endif
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _read(x) freopen(x, "r", stdin)
#define _write(x) freopen(x, "w", stdout)
#define files(x) _read(x ".in"); _write(x ".out")
#define filesdatsol(x) _read(x ".DAT"); _write(x ".SOL")
#define output _write("output.txt")
#define input _read("input.txt")
#define prev time_prev
#ifndef M_PI
#define M_PI acos(-1)
#endif
#define remove tipa_remove
#define next tipa_next
#define left tipa_left
#define right tipa_right
#define mod % MOD
#define y1 hello_world
unsigned char ccc;
bool _minus = false;
template<typename T>
inline T sqr(T t) {
	return (t * t);
}
inline void read(ll &n) {
	n = 0;
	_minus = false;
	while (true) {
		ccc = getchar();
		if (ccc == ' ' || ccc == '\n')
			break;
		if (ccc == '-') {
			_minus = true;
			continue;
		}
		n = n * 10 + ccc - '0';
	}
	if (_minus)
		n *= -1;
}
inline bool read(int &n) {
	n = 0;
	_minus = false;
	while (true) {
		ccc = getchar();
		if (ccc == ' ' || ccc == '\n') {
			if (ccc == '\n')
				return true;
			break;
		}
		if (ccc == '-') {
			_minus = true;
			continue;
		}
		n = n * 10 + ccc - '0';
	}
	if (_minus)
		n *= -1;
	return false;
}
char wwww[19];
int kkkk;
inline void write(ll y) {
	long long x = y;
	kkkk = 0;
	if (x < 0) {
		putchar('-');
		x *= -1;
	}
	if (!x)
		++kkkk, wwww[kkkk] = '0';
	else
		while (x) {
			++kkkk;
			wwww[kkkk] = char(x % 10 + '0');
			x /= 10;
		}
	for (int i = kkkk; i >= 1; --i)
		putchar(wwww[i]);
}
#ifdef LOCAL
#define DEBUG
#endif
#ifdef DEBUG
#define dbg if(1)
#else
#define dbg if(0)
#endif

const int MAX = 310;
int ar[MAX][MAX];
bool used[MAX];
int u[MAX];

int main() {
	sync;
	srand(time(NULL));
	cout.precision(10);
	cout << fixed;
#ifdef LOCAL
	input;
#else

#endif

	int n, m;
	cin >> n >> m;

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> ar[i][j];
		}
	}

	int ans = 1e9;

	for(int q = 1; q <= m; q++){
		ms(u);
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				if(!used[ar[i][j]]){
					u[ar[i][j]]++;
					break;
				}
			}
		}
		int w = 0;
		for(int i = 1; i <= m; i++){
			if(u[i] > u[w]){
				w = i;
			}
		}
		ans = min(ans, u[w]);
		used[w] = true;
	}

	cout << ans << endl;

}


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

int main()
{
   ll a,b ,c,k;
   cin>>a>>b>>c>>k;
   
   ll sum=0;
   
   if(a>=k)
   {
       sum+=k;
       k=0;
   }
   else
   {
       sum+=a;
       k-=a;
   }
   
   if(b>=k)
     k=0;
   else  
     k-=b;
     
    if(k>0) 
      sum-=k;
     
   
   
   
   cout<<sum;
   
     
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    int sum = 0;
    rep(i,n-1){
        if(i%2)sum += a[i];
        else sum -= a[i];
    }
    sum *= 2;
    int t = 2*a[n-1] - sum;
    t /= 2;
    rep(i,n){
        if(i)cout << " ";
        cout << t;
        t = a[i]*2-t;
    }
    cout << endl;
}


Measured memory_bytes: 2048
A=int(input())
B=int(input())
C=int(input())
X=int(input())
cnt=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            
            if i*500+j*100+k*50==X:
                
                cnt+=1
print(cnt)

Measured memory_bytes: 3060
from math import factorial

N, M = map(int, input().split())
if abs(N - M) > 1:
	print(0)
	exit()
INF = 1000000007

if abs(N - M) == 0:
	print(((factorial(N) ** 2) * 2) % INF)
else:
	print((factorial(N) % INF) * (factorial(M) % INF) % INF)


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

signed main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		vector<vector<int>>masu(b + 1, vector<int>(a));
		vector<vector<int>>suberikata(b + 1, vector<int>(a));
		for (int c = 0; c < b; c++) {
			for (int d = 0; d < a; d++) {
				cin >> masu[c][d];
			}
		}
		for (int e = 0; e < a; e++) {
			if (masu[0][e] ==0)suberikata[0][e]++;
		}
		for (int f = 0; f < b-1; f++) {
			for (int g = 0; g < a; g++) {
				switch (masu[f][g]) {
				case 0:
					suberikata[f + 1][g] += suberikata[f][g];
					if (g > 0&&masu[f+1][g-1]!=2)suberikata[f + 1][g - 1] += suberikata[f][g];
					if (g < a - 1 && masu[f + 1][g + 1] != 2)suberikata[f + 1][g + 1] += suberikata[f][g];
					break;     
				case 2:suberikata[f + 2][g] += suberikata[f][g]; break;
				}
			}
		}
		int s = 0;
		for (int x = 0; x < a; x++) {
			if (masu[b - 1][x] != 1) { s += suberikata[b - 1][x]; }
		}
		for (int x = 0; x < a; x++) {
			s += suberikata[b][x]; 
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please



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

	
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	int MA = F / (100 * A);
	int MB = F / (100 * B);

	double noudo = 0;
	pair<int, int> saidai = make_pair(100 * A, 0);
	rep(i, MA + 1) {
		rep(ii, MB + 1) {
			int omosa = 100 * (A * i + B * ii);
			if (omosa > F) continue;

			int youkai = omosa * E / 100;
			int MD = min((F - omosa) / D, youkai / D);
			rep(iii, MD + 1) {
				int omosa2 = omosa + D * iii;
				int iiii = min((F - omosa2) / C, (youkai - iii * D) / C);
				double noudo2 = 1.0 * (iii * D + iiii * C) / (omosa + iii * D + iiii * C);
				if (noudo < noudo2) {
					noudo = noudo2;
					saidai = make_pair(omosa + iii * D + iiii * C, iii * D + iiii * C);
				}
			}
		}
	}

	cosp(saidai.first);
	co(saidai.second);

	Would you please return 0;
}

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

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  while(true){
    if(A > B){
      cout << "NG" << endl;
      break;
    }
    if(A % K == 0){
      cout << "OK" << endl;
      break;
    }
    A++;
  }
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
    
       
int main(){
  int n;
  string s;
  map<ll,int> mp;
  cin >> n;
  ll ans = 0;
  rep(i,n){
    ll tmp;
    cin >> tmp;
    mp[tmp]++;
    ans += tmp;
  }
  int q;
  cin >> q;
  rep(i,q){
    ll a,b;
    cin >> a >> b;
    ans += mp[a]*(b-a);
    mp[b] += mp[a];
    mp[a] = 0;
    cout << ans << endl;

  }
 
  
  return 0;
}


Measured memory_bytes: 9496
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			var b = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			var c = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			Array.Sort(a);
			Array.Sort(b);
			Array.Sort(c);

			long ans = 0;
			for (int i = 0; i < n; i++) {
				long sizeB = b[i];
				int cntA;
				{
					int ok = -1;
					int ng = n;
					while (ng - ok > 1) {
						int mid = (ok + ng) / 2;
						if (a[mid] < b[i]) {
							ok = mid;
						} else {
							ng = mid;
						}
					}

					cntA = ok + 1;
				}

				int cntC;
				{
					int ng = -1;
					int ok = n;
					while (ok - ng > 1) {
						int mid = (ok + ng) / 2;
						if (c[mid] > b[i]) {
							ok = mid;
						} else {
							ng = mid;
						}
					}

					cntC = n - ok;
				}

				ans += (long)cntA * cntC;
			}

			Console.WriteLine(ans);
		}
	}
}

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

int main (){
	int N,cont=0,max=0,min=0,ex=0;
	int a[200];
	cin>>N;
	for(int t=0;t<N;t++)cin>>a[t];

	bool co[30];
	fill(co,co+30,false);

	for(int t=0;t<N;t++){
		if((a[t]/400)>=8){
			ex++;
			continue;
		}
		co[(a[t]/400)]=true;
	}

	for(int t=0;t<=7;t++){
		if(co[t])cont++;
	}

	if(cont==0){
		min=1;
	}else{
		min=cont;
	}
	max=cont+ex;

	cout<<min<<" "<<max<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>
#include <bitset>
#include <numeric>

using namespace std;
typedef long long ll;
ll MOD = 1000000007;

struct edge
{
    int to;
    int cost;
};

#define MAX_V 200010 * 3
vector<edge> E[MAX_V];
int d[MAX_V];

void dijkstra(int s, int V)
{
    using P = pair<int, int>;
    priority_queue<P, vector<P>, greater<P>> queue;
    fill(d, d + V, 1e+9);
    d[s] = 0;
    queue.push(P(0, s));

    while (!queue.empty())
    {
        P p = queue.top();
        queue.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;

        for (int i = 0; i < E[v].size(); i++)
        {
            edge e = E[v][i];
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                queue.push(P(d[e.to], e.to));
            }
        }
    }
}

int main()
{
    int N, M, S, T;
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        for (int j = 0; j < 3; j++)
        {
            edge e = {(b + N * (j + 1)) % (N * 3), 1};
            E[a + N * j].push_back(e);
        }
    }
    cin >> S >> T;
    dijkstra(S - 1, N * 3);
    if (d[T - 1] == 1e+9)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << d[T - 1] / 3 << endl;
    }

}


Measured memory_bytes: 25216
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main() {
    int N, K, r = 1;
    cin >> N >> K;
    vector<int> A(N);
    for (int j=0; j < N; ++j) {
        cin >> A[j];
    }
    N -= K;
    while (N > 0) {
        N -= K-1;
        r += 1;
    }
    cout << r << endl;
}

Measured memory_bytes: 640
N, M = map(int, input().split(" "))

AB = []
for _ in range(N):
    a, b = input().split(" ")
    AB.append([int(a), int(b)])

# Aをkeyにしてソート
AB = sorted(AB, key=lambda x: x[0])

# 先頭からM本選ぶ
i = 0 # 店のインデックス
c = 0 # 現在の本数
p = 0 # 合計の値段
while c < M:
    a, b = AB[i]
    if c + b > M:
        d = (M - c) # 足りない本数
        c += d
        p += a * d
    else:
        c += b 
        p += a * b
    i += 1

print(p)

Measured memory_bytes: 22044
N = int(input())
A = list(map(int,input().split(" ")))
inc = 0
dec = 0
s = 1
for i in range(N-1):
    inc += A[i] < A[i+1]
    dec += A[i] > A[i+1]
    if inc and dec:
        s += 1
        inc = 0
        dec = 0
print(s)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  long now = 1000, k = 0;
  for (int i = 0; i + 1 < N; i++) {
    if (A.at(i + 1) <= A.at(i)) now += k * A.at(i), k = 0;
    else k += now / A.at(i), now %= A.at(i);
  }
  cout << now + k * A.at(N - 1) << "\n";
}

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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> inline constexpr auto square(T x) { return (x) * (x); }

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

const int MOD = 1000000007;
const int INF = INT_MAX;

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

	VI P(n);
	rbf(p, P) {
		cin >> p;
	}

	VI san(3, 0);
	int ans = 0;
	rng(i, 1, n - 1) {
		rep(j, 3) san[j] = P[i - 1 + j];
		sort(All(san));
		if (san[1] == P[i]) ans++;
	}

	COL(ans);

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(){
    int q, i, j;
    char str[1001], p[1001];

    scanf("%s %d", str, &q);
    int len = strlen(str);

    for(i = 0; i < q; i++){
        char odr[8];
        int begin, end;
        scanf("%s %d %d", odr, &begin, &end);

        if(strcmp(odr, "print") == 0){
            for(j = begin; j <= end; j++){
                printf("%c", str[j]);
            }
            putchar('\n');
        }
        else if(strcmp(odr, "reverse") == 0){
            for(j = 0; j <= (end - begin) / 2; j++){
                char tmp = str[begin + j];
                str[begin + j] = str[end - j];
                str[end - j] = tmp;
            }
            // printf("%s", str);
        }
        else if(strcmp(odr, "replace") == 0){
            scanf("%s\n", p);
            for(j = 0; j < end - begin + 1; j++){
                str[begin + j] = p[j];
            }
            // printf("%s\n", str);
        }
    }
}


Measured memory_bytes: 2120
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <math.h>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define CIN(s) int (s);cin>>(s);
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; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
//ここから
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    V vec(n);
    rep(i,n)cin>>vec[i];
    reverse(all(vec));
    ll k_max=2;
    ll k_min=2;
    if(vec[0]!=2){
        cout<<-1<<endl;
        return 0;
    }
    rep3(i,0,n-1){
        k_max+=vec[i]-1;
        k_max=(k_max/vec[i+1])*vec[i+1];
        if(k_min%vec[i+1]!=0){
            k_min=((k_min/vec[i+1])+1)*vec[i+1];
            if(k_min>k_max){
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    k_max+=vec[n-1]-1;
    cout<<k_min<<" "<<k_max<<endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll            long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll           vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)               
#define forr(i,s,n)    for(auto i=s;i>=n;--i) 
const li mx = 1e6;
void solve() 
{
    int x;
    cin>>x;
    cout<<((x>=30)?"Yes":"No")<<endl;
}
int main() {
    ioS
    int t;
    // cin>>t;
    // while(t--)
        solve();
    return 0;
}

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

int main() {
  map<string, int> week;
  week["SUN"] = 7;
  week["MON"] = 6;
  week["TUE"] = 5;
  week["WED"] = 4;
  week["THU"] = 3;
  week["FRI"] = 2;
  week["SAT"] = 1;
  string S;
  cin >> S;
  cout << week[S] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> h(N);
    for(int i = 0; i < N; i++)cin >> h[i];
    vector<ll> dp(N);
    for (int i = 0; i < N; i++) dp[i] = 1000000000;
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < N; i++) {
      chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
      chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin >> N;
  for(int i = 0; 7 * i <= N; i++){
    if((N - 7 * i) % 4 == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
	int a=in.nextInt();
	int b=in.nextInt();
	int c=in.nextInt();
	if(a<b && b<c)
		System.out.println("Yes");
	else
		System.out.println("No");
	}
}

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

int main(){
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, m) cin >> b.at(i);
    int cnt = 0;

    rep(i, n){
        int a;
        int ans = c;
        rep(j, m){
            cin >> a;
            ans += a * b.at(j);
        }
        if(ans>0) cnt+=1;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3600
s=input()
q=int(input())
l=[]
for c in range(q):
    i=input().split()
    if i==["1"]:
        l.append([1,0,0])
    else:
        l.append([2,int(i[1]),i[2]])
d=0
for c in range(1,q+1):
    if l[-c][0]==1:
        d=d+1
    else:
        l[-c][1]+=d%2
a=""
for c in range(1,q+1):
    if l[-c][0]==2 and l[-c][1]%2==1:
        a=a+l[-c][2]
if d%2==0:
    a=a+s
else:
    a=a+s[::-1]
for c in range(q):
    if l[c][0]==2 and l[c][1]%2==0:
        a=a+l[c][2]
print(a)

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

char s[200001][11];//入力受け取り
char results[200001][11];//結果表示用

int compare_char(const void* left, const void* right) {
    char *left_char = (char *)left;
    char *right_char = (char *)right;
 
    return strcmp(left_char,right_char);
}

int main(void){
  int n, i, j, match=0, count=0, result=0, max=0;
  int c[200001] = {0};//出現回数
  char tmp[11];
  
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%10s", &s[i]);
  }
  
  qsort(s,n,sizeof(s[0]),compare_char);
  
  count=1;
  for(i=1;i<n;i++){
    if(strcmp(s[i], s[i-1])==0){
      //same
      count++;
    }else{
      //different
      strcpy(results[result], s[i-1]);
      c[result] = count;
      if(count > max) max = count;
      result++;
      count=1;
    }
  }
  strcpy(results[result], s[n-1]);
  c[result] = count;
  if(count > max) max = count;
  result++;
    
  for(i=0;i<result;i++) if(c[i] >= max) printf("%s\n", results[i]);
  
  return 0;
}

Measured memory_bytes: 7164
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n) cin >> a[i];
  int now = a[0];
  rep(i,n-1) now^=a[i+1];
  rep(i,n){
    int ans = now^a[i];
    cout << ans << " ";
  }
  return 0;
}


Measured memory_bytes: 3912
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

string s;

int main() {
  cin >> s;
  string ans;
  auto N = s.size();
  rep(i, N) {
    if (s.at(i) == '0') {
      ans.push_back('0');
    } else if (s.at(i) == '1') {
      ans.push_back('1');
    } else {
      if (ans.size() > 0) {
        ans.pop_back();
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a,b,c;
	
	while(scanf("%d %d %d",&a,&b,&c) !=EOF)
	{
		if(a == -1 && b == -1 && c == -1)
		{
			break;
		}
		
		if((a == -1 || b == -1) && c == -1)
		{
			printf("F\n");
		}
		else
		{
			int sum = 0, k = 0;
			if(a >= 0)
			{
				sum += a;
			}
			if(b >= 0)
			{
				sum += b;
			}
			if(sum >= 80)
			{
				printf("A\n");
			}
			else if(sum >= 65 && sum < 80)
			{
				printf("B\n");
			}
			else if((sum >= 50 && sum < 65) || c >= 50)
			{
				printf("C\n");
			}
			else if(sum >= 30 && sum < 50)
			{
				printf("D\n");
			}
			else
			{
				printf("F\n");
			}
		}
	}
	return 0;
 } 


Measured memory_bytes: 2600
N = int(input())
S = list(input())
L = [chr(ord("A")+i) for i in range(26)]
X = ""
for i in S:
    a = L.index(i) + N
    if a >= 26:
        a = a - 26
        X += L[a]
    else:
        X +=  L[a]
print(X)


Measured memory_bytes: 9248