akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
  	int n,flag=0;
  string x;	
  cin>>n>>x;
  if(n%2==1)
    flag=1;
   else{
  for(int i=0,j=n/2;i<n/2;i++,j++){
    if(x[i]!=x[j]){
      flag=1; break;
    }
}
   }  
    if(flag==1)
     cout<<"No";
     else
       cout<<"Yes";
}

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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


int main() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    rep(i, n) cin >> a[i];

    rep(i, k, n) {
        if (a[i - k] < a[i])
            prt("Yes");
        else
            prt("No");
    }

    return 0;
}


Measured memory_bytes: 4836
class Student
  attr_accessor("prev", "next", "value")
  
  def initialize
    self.value = 1
  end
end

n, m, q  = gets.split(" ").map(&:to_i)
students = Array.new(n)
(0..n-1).each {|i|
  students[i] = Student.new
}

students[n-1].prev, students[n-1].next = students[n-2], students[0]
(0..n-2).each {|i|
  students[i].prev, students[i].next   = students[i-1], students[i+1]
}

student = students[0]
as = gets.split(" ").map(&:to_i)
as.each {|a|
  if a%2 == 1
    a.times {student = student.prev}
  else
    a.times {student = student.next}
  end
  student.value = 0
  (student.prev).next = student.next
  (student.next).prev = student.prev
  student = student.next
}

qs = gets.split(" ").map(&:to_i)
qs.each {|q|
  p students[q].value
}

Measured memory_bytes: 35436
#include<stdio.h>
int main()
{
    int A, B, C, D;
    scanf("%d %d %d %d", &A,&B,&C,&D);
    if ((A+B)>(C+D)){
        printf("Left\n");
    }
    else if ((A+B)<(C+D)) {
        printf("Right\n");
    }
    else if ((A+B)==(C+D)) {
        printf("Balanced\n");
    }
    return 0;

}

Measured memory_bytes: 1644
import java.util.*;

/**
 * A Main
 *
 * @date 2020.09.19
 * @author 焼き鮭 <yaki-shake@up-tri.me>
 */

public class Main {
  Scanner sc;

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

  public void execute() {
    this.sc = new Scanner(System.in);
    int x = this.sc.nextInt();
    System.out.println(x == 1 ? 0 : 1);
  }
}


Measured memory_bytes: 27100
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <limits.h>
#include <complex>
#include <assert.h>
using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef complex<ld> Point;

void solve() {
	int X;
	cin >> X;
	if (X == 3 || X == 5 || X == 7)cout << "YES" << endl;
	else cout << "NO" << endl;
	return;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int res = 0;
  for (char c : s) {
  	res += (c == '+');
    res -= (c == '-');
  }
  cout << res << '\n';
  return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int c[10001];
	for(int i=0;i<=10000;i++)
		c[i]=0;
	int n=105,n1;
	cin>>n1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				int cal=i*i+j*j+k*k+i*j+j*k+k*i;
				if(cal<=10000){
					c[cal]++;
				}
			}
		}
	}
	for(int i=1;i<=n1;i++)
		cout<<c[i]<<endl;
	return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  stack<int> a;
  string b;
  while(cin >> b){
    if (b =="+"||b =="-"||b=="*"){
        int x = a.top();
        a.pop();
        int y = a.top();
        a.pop();
        if(b == "+") a.push(x+y);
        if(b == "-") a.push(y-x);
        if(b == "*") a.push(x*y);
    } 
    else {
      x = stoi(b);
      a.push(x);
    }
  }
  cout << a.top() << endl;
  return 0;
}


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

int c[26];
char s[101];

int main()
{
	int h,w;
	scanf("%d%d",&h,&w);
	for (int i=1;i<=h;i++)
	{
		scanf("%s",s+1);
		for (int j=1;j<=w;j++)
			c[s[j]-'a']++;
	}
	int c2=0,c1=0;
	for (int i=0;i<26;i++)
	{
		switch (c[i]%4)
		{
		case 1:
			c1++;
			break;
		case 2:
			c2++;
			break;
		case 3:
			c1++,c2++;
			break;
		default:
			break;
		}
	}
	if (h&1&&w&1)
	{
		if (c1==1&&c2<=(h/2)+(w/2)) puts("Yes");
		else puts("No");
	}
	else if (h&1)
	{
		if (!c1&&c2<=w/2) puts("Yes");
		else puts("No");
	}
	else if (w&1)
	{
		if (!c1&&c2<=h/2) puts("Yes");
		else puts("No");
	}
	else
	{
		if (!c1&&!c2) puts("Yes");
		else puts("No");
	}
	return 0;
}


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

class Bmondai
{
    static void Main()
    {
        var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = line[0];
        var M = line[1];
        var array = new int[M + 1];
        for (int i=0;i<N;++i)
        {
            line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
            for (int j=0;j<line[0];++j) array[line[j+1]]++;
        }
        var ans = array.Count(x => x == N);
        Console.WriteLine(ans);
    }
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, M;
std::string S;
std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
int nxt[100100];

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

  std::cin >> N >> M >> S;

  memset(nxt, -1, sizeof(nxt));
  
  pq.emplace(0, N);

  for(int i=N-1;i>=0;--i){
      if(S[i] == '1'){continue;}

      until(pq.empty()){
          int d, j;
          std::tie(d, j) = pq.top();

          if(j > i + M){
              pq.pop();
              continue;
          }

          // std::cout << i << " -> " << j << ": " << (d + 1) << std::endl;

          pq.emplace(d + 1, i);
          nxt[i] = j;
          break;
      }
  }

  if(nxt[0] == -1){
      std::cout << -1 << std::endl;
      return 0;
  }

  std::vector<int> path;

  int cur = 0;

  while(cur != -1){
      path.emplace_back(cur);
      cur = nxt[cur];
  }

  for(int i=0;i+1<path.size();++i){
      int d = path[i+1] - path[i];
      std::cout << d << " \n"[i + 2 == path.size()];
  }
}


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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let mut v = read_vec::<u64>();
    v.sort();
    let mut cost = 0;
    for i in 1..v.len(){
        cost += v[i as usize] - v[(i-1) as usize];
    }
    println!("{}",cost )
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int n, m;
Graph G;
vector<int> deg;//入次数
int dp[100100];


int main(){
    cin >> n >> m;
    G.resize(n);
    deg.assign(n,0);
    rep(i,m){
        int x, y; cin >> x >> y;
        --x, --y;
        G[x].pb(y);
        deg[y]++;
    }
    //bfsでトポロジカルソートをしながらDP
    queue<int> q;
    rep(i,n) if(deg[i] == 0) q.push(i);

    while(!q.empty()){
        int v = q.front(); q.pop();
        for(auto nv : G[v]){
            deg[nv]--;//delete edge
            if(deg[nv]==0){
                q.push(nv);
                chmax(dp[nv], dp[v]+1);
            }
        }
    }
    int ans = 0;
    rep(v,n) chmax(ans, dp[v]);
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include <bits/stdc++.h>
//1000000000000223
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, k ;
int main()
{
    IO
    cin>>n>>k;
    if(k>= (1<<n) || (n==1 && k==1))
        return cout<<-1, 0 ;
    if(n==1)
        return cout<<"0 0 1 1" , 0;
    cout<<k<<" ";
    for(int i=0; i<(1<<n); i++)
        if(i!=k)
            cout<<i<<" ";
    cout<<k<<" ";
    for(int i=(1<<n)-1; i>=0; i--)
        if(i!=k)
            cout<<i<<" ";
    return 0;
}


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

int main(){
    int n, m;
    long long A[101][101], B[101], C[101];
    cin >> n >> m;

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

    for(int i=1; i<=n; i++){
        C[i] = 0;
        for(int j=1; j<=m; j++){
            C[i] += A[i][j] * B[j];
        }
    }

    for(int i=1; i<=n; i++){
            cout << C[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3168
#include<stdio.h>

int main(){

  int A, B;
  
  scanf("%d %d", &A, &B);

  if(A>=13){
    printf("%d\n", B);
  }else if(A>=6){
    printf("%d\n",B/2);
  } else{
    printf("0\n");
  }

}
    


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long N,h,n,w;
int main()
{
	scanf("%I64d",&N);
	for(h=1;h<=3500;h++)
	{
		for(n=1;n<=3500;n++)
		{
			long long k=4*h*n-N*(n+h),c=N*h*n;
			if(k!=0&&k>0&&c%k==0)
			{
				printf("%I64d %I64d %I64d",h,n,c/k);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

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

int main() {
	vt n, s = 0;
	cin >> n;
	vector<vt> b(n - 1), a(n, -1);
	rep(i, n - 1) cin >> b.at(i);
	a.at(0) = b.at(0);
	reps(i, 1, n - 1) {
		a.at(i) = min(b.at(i - 1), b.at(i));
	}
	a.at(n - 1) = b.at(n - 2);
	rep(i, n) s += a.at(i);
	cout << s;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        int a;
        int b;
        Scanner input = new Scanner(System.in);
        a = input.nextInt();
            //Scanner op = new Scanner(System.in);
        b = input.nextInt();
            if (a < b) {
                System.out.println("a < b");
            }
            if (a == b) {
                System.out.println("a == b");
            }
            if (a > b) {
                System.out.println("a > b");
            }
    }

}


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

int main() {
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
		cout<<"Yes"<<endl;
	}
	else{
            cout<<"No"<<endl;
        }
}

Measured memory_bytes: 3092
N = int(input())
S = [input() for _ in range(N)]

import sys
import copy

ans = 0
adj_list = [[]for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if int(S[i][j]):
            adj_list[i].append(j)
            adj_list[j].append(i)


for kk in range(N):
    q = []
    visited = [False] * N
    cnt = 1
    visited[kk] = True
    q.append(kk)
    VC = 1
    while VC < N:
        nextv = copy.copy(q)
        q = []
        nextv = list(set(nextv))
        #子の要素同士の連結チェック
        L = len(nextv)
        for i in range(L):
            if not(visited[nextv[i]]):
                visited[nextv[i]] = True
                VC += 1
            for j in range(i+1,L):
                if (int(S[nextv[i]][nextv[j]])):
                    print(-1)
                    sys.exit()
        
        for nv in nextv:
            for v in adj_list[nv]:
                if not(visited[v]):
                    q.append(v)
    
        cnt += 1
    
    ans = max(ans,cnt-1)
        
#
print(ans)


Measured memory_bytes: 48220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T> T in(){T x;cin>>x;return x;}
// long long a = in<long long>();
template<class T> vector<T> inarr(int s,int e, T init){
	vector<T> v;T x;
	for(int i=0;i<s;++i)v.push_back(init);
	for(int i=s;i<e;++i){cin>>x;v.push_back(x);}
	return v;
}
// vi P = inarr<int>(0,N,0);
// vi P = inarr<int>(1,N+1,INT_MAX);
// vs P = inarr<string>(0,N,"");
template<class T>void outarr(int s,int e,vector<T> &V){
	for(int i=s;i<e;i++)cout<<V[i]<<(i<e-1?" ":"\n");
}
// outarr<int>(0,V.size(),V);
// outarr<ll>(0,V.size(),V);

// #define MAX 1'000'000'000
ll N,A,B;

ll solve(){
	ll ans = 0L;
	if(A == 0) return 0L;

	ll c = A+B;
	ll d = N/c;
	// cout<<c<<" "<<d<<"\n";//
	ans += d*A;
	N -= d*c;
	// cout<<N<<"\n";//

	if(N < A){
		ans += N;
	}
	else{
		ans += A;
	}

	return ans;
}

int main(){
	cin>>N>>A>>B;
	cout<< solve() <<endl;
	// printf("%f\n",solve());
	// solve();
}


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

int main() {
 int n,L,s=0;cin>>n; int l[n];for(int i=0 ;i<n;i++) cin>>l[i];sort(l,l+n);
  
  
 
    
  for(int i=0;i<n-1;i++){
    s+=l[i];
  }
   
  
  if(l[n-1]<s)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}




Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
pos=[]
nega=[]

for i in range(n):
    if a[i]>=0:
        pos.append(a[i])
    else:
        nega.append(a[i])
if len(pos)==0:
    if len(nega)%2==0:
        print(abs(sum(a)))
    else:
        print(abs(sum(a))+max(a)*2)
elif len(nega)==0:
    print(sum(a))
elif len(nega)%2==0:
    print(sum(pos)-sum(nega))
else:
    if min(pos)>-max(nega):
        print(sum(pos)-sum(nega)+max(nega)*2)
    else:
        print(sum(pos)-sum(nega)-min(pos)*2)

Measured memory_bytes: 14464
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123
typedef pair<ll, ll> P;



//initialization here
//
const int maxn = 1e5+10;

//
//initialization finish


// your function is here
//

//
// your function finished



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//
	int n = 3;

	int c[3][3];
	rep(i, n)rep(j, n) cin >> c[i][j];

	rep(i, 2)
	{
		int sa[3];
		rep(j, 3)
		{
			sa[j] = c[i + 1][j] - c[i][j];
		}
		if (sa[0] != sa[1] || sa[1] != sa[2])
		{
			No; return 0;
		}
	}

	rep(i, 2)
	{
		int sa[3];
		rep(j, 3)
		{
			sa[j] = c[j][i + 1] - c[j][i];
		}
		if (sa[0] != sa[1] || sa[1] != sa[2])
		{
			No; return 0;
		}
	}

	Yes;
	//
	// your code finished


	return 0;
}

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

int mod = 1e9+7;
long long int func(int n){
  long long int tmp = 1;
  for(int i=1; i<=n; i++){
    tmp *= i;
    tmp %= mod;
  }
  return tmp;
}

int main() {

  int n, m; cin >> n >> m;
  if( abs(n-m) >= 2 ){
    cout << 0 << endl;
    return 0;
  }

  long long int cn = func(n);
  long long int cm = func(m);
  long long int ans = (cn * cm)%mod;
  if( n == m ){
    cout << (ans*2)%mod << endl;
  }else{
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] h = new int[N + 1];
            Arrays.fill(h, 0);
            for (int i = 0; i < N; i++) {
                h[i] = in.nextInt();
            }

            int count = 0;
            for (int i = 0; i < N; i++) {
                if (h[i] > h[i + 1]) {
                    count += h[i] - h[i + 1];
                }
            }
            out.println(count);
        }

    }
}



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

int main() {
  int N; cin >> N;
  string S; cin >> S;
  int leftCheck[N], rightCheck[N];
  leftCheck[0] = 0; rightCheck[N-1] = 0;
  for (int i = 1; i < N; i++) {
    leftCheck[i] = leftCheck[i-1] + (S[i-1] == 'W');
    rightCheck[N-1-i] = rightCheck[N-i] + (S[N-i] == 'E');
  }
  int minCount = N;
  for (int i = 0; i < N; i++) {
    minCount = min(minCount, leftCheck[i] + rightCheck[i]);
  }
  cout << minCount << endl;
}


Measured memory_bytes: 3076
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

//#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    int L,R,d;
    cin>>L>>R>>d;

    int c=0;
    for(int i=L;i<=R;i++){
        if(i%d==0) c++;
    }

    cout<<c<<endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N,M;
  	cin >> N;
  	string a, check;
  	vector<string> vec1(N);
  	for(int i = 0; i< vec1.size(); i++){
    	cin >> a;
      	vec1.at(i) = a;
    }
	cin >> M;
    vector<string> vec2(M);
  	for(int i = 0; i< vec2.size(); i++){
    	cin >> a;
      	vec2.at(i) = a;
    }
    int max = 0;
  	for(int i = 0; i < vec1.size(); i++){
        int count = 0;
    	check = vec1.at(i);
      	for(int j = 0; j < vec1.size(); j++){
        	if(check == vec1.at(j)){
            	count++;
            }
        }
      	for(int k = 0; k < vec2.size(); k++){
        	if(check == vec2.at(k)){
            	count--;
            }
        }
        if(max < count){
        	max = count;
        }
    }
    if(max > 0){
    	cout << max << endl;
    }else{
    	cout << 0 << endl;
    }
}


Measured memory_bytes: 256
main :: IO()
main = do
    x:y:xs <- map read . words <$> getLine
    putStrLn $ anata $ watashi x y

watashi :: Int -> Int -> Bool
watashi x y =   if x `mod` 2 == 0 then True -- divでなくmod
                else if y `mod` 2 == 0 then True
                else False

anata :: Bool -> String
anata True = "Even"
anata False = "Odd"

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    int ans = INT_MAX;
    for(int i=0;i<(1<<n);i++){
        vector<int> temp(m,0);
        bool ok = true;
        int cost = 0;
        for(int j=0;j<13;j++){
            if(i&(1<<j)){
                for(int k=0;k<m;k++){
                    temp[k]+=a[j][k];
                }
                cost+=c[j];
            }
        }
        for(int k=0;k<m;k++){
            if(temp[k]<x){
                ok = false;
                break;
            }
        }
        if(ok){
            ans = min(ans,cost);
        }

    }
    if(ans==INT_MAX){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3664
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

int main()
{
    ll a,b,m;
    cin >> a >> b >> m;
    vector<ll> A(a),B(b);
    ll min_a=INF;
    ll min_b=INF;
    rep(i,a){
        cin >> A[i];
        min_a=min(min_a,A[i]);
    }
    rep(i,b){
        cin >> B[i];
        min_b=min(min_b,B[i]);
    }
    vector<ll> x(m),y(m),c(m);
    ll ans=INF;
    rep(i,m){
        cin >> x[i] >> y[i] >> c[i];
        x[i]--;
        y[i]--;
        ans=min(ans,A[x[i]]+B[y[i]]-c[i]);
    }
    ans=min(ans,min_a+min_b);
    cout << ans << endl;
    return 0;
} 


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

int topa (char a){
  if(a == 'o'){
    return 1;
  }
  else return 0;

}

int topb (char b){
  if(b == 'o'){
    return 1;
  }
  else return 0;

}
int topc (char c){
  if(c == 'o'){
    return 1;
  }
  else return 0;

}

int main(){
  char a, b, c;
  cin >> a >> b >> c;
  cout <<topa(a)*100 + topb(b)*100 + topc(c)*100 + 700<<endl;
}

Measured memory_bytes: 256
import numpy as np
n = input().split()
N = int(n[0])
M = int(n[1])

num_list = []
pr_list = []
for i in range(N):
    a = input().split()
    num_list.append(int(a[1]))
    pr_list.append(int(a[0]))

x = np.argsort(np.array(pr_list))

tmp = 0
for i in range(100000):
    key = int(num_list[x[i]])
    if M - key > 0:
        tmp += int(pr_list[x[i]])*key
        M -= key
    else:
        if i == 0:
            tmp = int(pr_list[x[i]])*M
            break
        tmp += int(pr_list[x[i]])*M
        break

print(str(tmp))



Measured memory_bytes: 21608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int l[N], r[N];
    int ans = 0;
    rep(i ,N) {
        cin >> l[i] >> r[i];
        ans += r[i] - l[i] + 1;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int ans1 = a * b;
		int ans2 = (a * 2) + (b * 2);
		System.out.println(ans1 + " " + ans2);
	}
}

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

//ライブラリ始まり

//定数
//円周率
const double pi = 3.1415926535897932384;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数
//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}
//to_char
char to_char(int i){
  if (i == 0) {
    return '0';
  }
  if (i == 1) {
    return '1';
  } 
  if (i == 2) {
    return '2';
  } 
  if (i == 3) {
    return '3';
  }
  if (i == 4) {
    return '4';
  } 
  if (i == 5) {
    return '5';
  } 
  if (i == 6) {
    return '6';
  }
  if (i == 7) {
    return '7';
  } 
  if (i == 8) {
    return '8';
  } 
  if (i == 9) {
    return '9';
  }
  return ' ';  
}
//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false; // 1や0,-1は素数ではない
  }
  if (x == 2) {
    return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false; // 割れたら素数じゃない
    }
  }
  return true;
}

//ライブラリ終わり
  
//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N;
  cin >> N;
  vector<ll> M(N, 0);
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      M.at(j - 1)++;
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += M.at(i) * (i + 1);
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 81400
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
if N > 10000:
    A = A[5050:] + A[:5050]
    B = B[5050:] + B[:5050]
ans = -1

D = [0] * N
L = [i-1 for i in range(N)]
R = [i+1 for i in range(N)]

def calc():
    i = 0
    c = 0
    ans = 0
    while c < N:
        while i < N:
            if B[i] == A[i]:
                if D[i] == 0:
                    c += 1
                    D[i] = 1
                if L[i] >= 0: R[L[i]] = R[i]
                if R[i] < N: L[R[i]] = L[i]
            if B[i] > A[i] and B[i] >= max(B[i-1], B[(i+1)%N]):
                k = - (-(B[i] - max(B[i-1], B[(i+1)%N], A[i])) // (B[i-1] + B[(i+1)%N]))
                B[i] -= (B[i-1] + B[(i+1)%N]) * k
                ans += k
                if k <= 0:
                    return -1
            i = R[i]
        i = N-1
        while i >= 0:
            if B[i] == A[i]:
                if D[i] == 0:
                    c += 1
                    D[i] = 1
                if L[i] >= 0: R[L[i]] = R[i]
                if R[i] < N: L[R[i]] = L[i]
            if B[i] > A[i] and B[i] >= max(B[i-1], B[(i+1)%N]):
                k = - (-(B[i] - max(B[i-1], B[(i+1)%N], A[i])) // (B[i-1] + B[(i+1)%N]))
                B[i] -= (B[i-1] + B[(i+1)%N]) * k
                ans += k
                if k <= 0:
                    return -1
            i = L[i]
    return ans

print(calc())

Measured memory_bytes: 121172
#include <stdio.h>
int main() {
  int N, i, j, ans;
  scanf("%d", &N);
  ans = 0;
  int d[N];
  for(i = 0; i < N; ++i){
  	scanf("%d", &d[i]);
  }
  for(i = 0; i < N; ++i){
    for(j = i + 1; j < N; ++j){
      ans += d[i] * d[j];
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#import copy
# 最大値が2つ以上あるものと1つしかないもので場合分けをする
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
if b[-1] == b[-2]:
  for i in range(n):
    print(b[-1])
else:
  p = a.index(b[-1])
  for i in range(n):
    if i == p:
      print(b[-2])
    else:
      print(b[-1])
#deepcopy is so slow!!
# ex_a = []
# for i in range(n):
#   ex_a = copy.deepcopy(a)
#   ex_a[i] = -1
#   print(max(ex_a))

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

int main()
{
  int N;
  int d[110];

  cin >> N;
  for(int i = 0;i<N;++i)cin >>d[i];
  set<int> a;
  for(int i = 0; i<N; ++i)a.insert(d[i]);
  cout << a.size() <<endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int f(int n) {
    int res = 0;
    while(n != 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    if (n % f(n) == 0 ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

using namespace std;

const int INF = 1000000009;

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

  vector<vector<int>> f(n, vector<int>(10, 0));
  vector<vector<int>> p(n, vector<int>(11, 0));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> p[i][j];
    }
  }

  int ans = -INF;
  for (int bit = 1; bit < (1 << 10); bit++) {
    int prof = 0;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if (f[i][j] == 1 && f[i][j] == ((bit >> j) & 1)) {
          cnt++;
        }
      }
      prof += p[i][cnt];
    }
    ans = max(ans, prof);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


n,m=map(int,input().split())

mlis=make_divisors(m)

I=1
for i in mlis:
    if m<i*n:
        break
    else:
        I=i
    
print(I)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
/*2進数配列+1*/
vector<int> twoadd(vector<int> v, int N){
    v[N-1]+=1;
    int ind = N-1;
    int j=N-1;
    for(j=N-1;j>=1;j--){
        if(v[j]>1){
            v[j-1]+=1;
            v[j]=0;
        }
    }
    return v;
}
/*フィボナッチ*/
long long fibonatti(long long d){
    long long count = 0;
    long long f1 = 1;
    long long f2 = 1;/*ここを変える*/
    long long temp;
    if(d == 1){
        count = f1;
    }else if(d == 2){
        count = f2;
    }else if(d==0){
        count = 1;
    }else{
        for(int i=0;i<d-2;i++){
            temp = f1+f2;
            f1 = f2;
            f2 = temp;
        }
        count = temp;
    }
    return count;
}

/*ここから*/
int main() {
    int A,P;
    cin >> A >> P;
    int ans,piece;
    piece = A*3+P;
    ans = piece/2;
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	cin>>n;
	int s=0,ans=0;
	for(int i=1;i<=n;i++){
		char c;
		c=getchar();
		while(c!='D'&&c!='I') c=getchar();
		if(c=='D') s--;
		else s++;
		ans=max(ans,s);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <cassert>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define endl '\12'
#define eb emplace_back
#define SZ(a) int32_t(a.size())
#define ALL(x) (x).begin(),(x).end()
#define trav(a,x) for (auto& a: x)
#define LOG(FMT...) fprintf(stderr, FMT)
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
constexpr int mod = 1e9+7;
constexpr int Erica = 998244353;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ex_gcd(ll a, ll b, ll& x, ll& y){if(!b){x=1;y=0;return a;}ll ret=ex_gcd(b,a%b,y,x);y-=a/b*x;return ret;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
int norm(int x) { return x >= mod ? (x - mod) : x; }
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
inline ll get_inv(ll a) { ll x, y; ex_gcd(a, mod, x, y); return norm(x + mod);}
template<class T>inline void umin(T &x, T y) {x = x > y ? y : x;}
template<class T>inline void umax(T &x, T y) {x = x < y ? y : x;}
template<class T>inline void dec(T &x, T y) {x -= y; if(x < 0) x += mod;}
template<class T>inline void add(T &x, T y) {x += y; if(x >= mod) x -= mod;}
const double PI = acos(-1.0);
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr ull base=2333, P_1=19260817, P_2=999998639;
constexpr int maxn = 1e6+10; // remember to calculate. if tle, check maxn first.
int n;
int main()
{
    cin >> n;
    cout << (n >= 30 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, M;
  cin >> N >> M;
  
int number =0;
  
  vector<int> vec(M*2);
  
 
   for(int j=1; j<N+1; j++){
     for(int i=0; i<M*2; i++){
    cin >> vec. at(i);
    if(vec. at(i) ==j)
      number++;
    }
    cout << number << endl;  
     number = 0;
  }
}



Measured memory_bytes: 3576
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String[] sl = str.split(" ");
        int R = Integer.parseInt(sl[0]);
        int G = Integer.parseInt(sl[1]);
        int B = Integer.parseInt(sl[2]);
        int N = Integer.parseInt(sl[3]);
        int ans = 0;
        for (int r=0;r<=N;r+=R){
            for (int g=0;g<=N-r;g+=G){
                if ((N-(r+g))%B==0){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21328
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int k, n;
  cin >> k >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mx = 0;
  for (int i = 1; i < n; i++) {
    mx = max(mx, a[i] - a[i - 1]);
  }
  mx = max(mx, k - a[n - 1] + a[0]);
  cout << k - mx << endl;
  return 0;
}

Measured memory_bytes: 1024
//https://beta.atcoder.jp/contests/abc112/tasks/abc112_d
#include<bits/stdc++.h>

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

LL n,m;

LL ret = 1;
int main() {
    cin>>n>>m;
    for(LL i=1;i*i<=m;i++){
        if(m%i==0){
            if(n<=m/i)chmax(ret,i);
            if(n<=i)chmax(ret,m/i);
        }
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		int n=Integer.parseInt(br.readLine());
		StringTokenizer st=new StringTokenizer(br.readLine());
		int[] in=new int[n];
		for(int i=0;i<n;i++)in[i]=Integer.parseInt(st.nextToken());
		
		int count=0;
		for(int i=0;i<n-1;i++){
			int mini=i;
			for(int j=i+1;j<n;j++){
				if(in[mini]>in[j]){
					mini=j;
				}
				}
			if(mini!=i){
				count++;
			int tmp=in[i];
			in[i]=in[mini];
			in[mini]=tmp;}
		}
		StringBuilder stb=new StringBuilder(Integer.toString(in[0]));
		for(int i=1;i<n;i++)stb.append(" "+in[i]);
		System.out.println(stb+"\r\n"+count);
		
	}

}

Measured memory_bytes: 16884
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		long I=sc.nextLong();
		long O=sc.nextLong();
		long T=sc.nextLong();
		long J=sc.nextLong();
		long L=sc.nextLong();
		long S=sc.nextLong();
		long Z=sc.nextLong();
		long ans=0;
		long tmp=0;
		if(I>0) {
			ans+=((I-1)/2)*2;
			//pl("I"+((I-1)/2)*2);
		}
		ans+=O;
		if(J>0) {
			ans+=((J-1)/2)*2;
			//pl("J"+((J-1)/2)*2);
		}
		if(L>0) {
			ans+=((L-1)/2)*2;
			//pl("L"+((L-1)/2)*2);
		}
		if(I>0 && J>0 && L>0) {
			ans+=3;
		}

		tmp+=I/2*2;
		tmp+=O;
		tmp+=J/2*2;
		tmp+=L/2*2;
		pl(Math.max(ans,tmp));
		//ウソっぽいのだが、これがなんで違うのかわからないので取りあえず投げる
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

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

typedef long long ll;
typedef long double ld;

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll x, a, b;
    string ans;

    cin >> x >> a >> b;

    if((-1) * a + b <= 0)
        ans = "delicious";
    else if((-1) * a + b <= x)
        ans = "safe";
    else
        ans = "dangerous";
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
string S[200];
int cost[200][200];

signed main(){
    cin >> N;
    rep(i, N) cin >> S[i];

    rep(i, N){
        rep(j, N){
            cost[i][j] = 1e9;
            if(S[i][j] == '1') cost[i][j] = 1;
        }
        cost[i][i] = 0;
    }
    rep(i, N){
        rep(j, N){
            rep(k, N){
                cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
            }
        }
    }
    
    rep(i, N){
        rep(j, N){
            if(S[i][j] == '1' && cost[0][i]%2 == cost[0][j]%2){
                cout << -1 << endl;
                exit(0);
            }
        }
    }

    int ans = 2;
    rep(i, N){
        rep(j, N){
            ans = max(ans, cost[i][j]+1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3804
//15
#include<iostream>
#include<queue>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
  for(int w,h;cin>>w>>h,w|h;){
    bool wall[64][64];
    fill_n(&wall[0][0],64*64,true);
    for(int y=1;y<=2*h-1;y++){
      for(int x=y%2+1;x<2*w;x+=2){
	int w;
	cin>>w;
	wall[y][x]=w;
      }
    }
    queue<pair<pair<int,int>,int> > que;
    que.push(make_pair(make_pair(1,1),1));
    bool pass[64][64]={};
    while(!que.empty()&&(que.front().first.first!=h*2-1||que.front().first.second!=w*2-1)){
      pair<int,int> point=que.front().first;
      if(!pass[point.first][point.second]){
	for(int i=0;i<4;i++){
	  int dx[]={0,1,0,-1};
	  int dy[]={1,0,-1,0};
	  if(!wall[point.first+dy[i]][point.second+dx[i]]){
	    que.push(make_pair(make_pair(point.first+dy[i]*2,point.second+dx[i]*2),que.front().second+1));
	  }
	}
	pass[point.first][point.second]=true;
      }
      que.pop();
    }
    cout<<((que.empty())?0:que.front().second)<<endl;
    }
  return 0;
}
      
      

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

int main() {
  string s;
  int c = 0;
  cin >> s;
  s += '0';
  vector<int>data(s.size()-1);
  for(int i = 0;i < s.size()-1;i++){
    data.at(i) = 0;
  }
  for(int i = 0;i < s.size()-1;i++){
    c++;
    if(s.at(i) != s.at(i+1) && s.at(i) == 'R'){
      if(c%2 == 0){
        data.at(i) += c/2;
        data.at(i+1) += c/2;
      }
      else{
        data.at(i) += c/2+1;
        data.at(i+1) += c/2;
      }
      c = 0;
    }
    else if(s.at(i) != s.at(i+1)){
      if(c%2 == 0){
        data.at(i-c+1) += c/2;
        data.at(i-c) += c/2;
      }
      else{
        data.at(i-c+1) += c/2+1;
        data.at(i-c) += c/2;
      }
      c = 0;
    }
  }
  for(int i = 0;i < s.size()-1;i++){
    cout << data.at(i) << " ";
  }
  cout << "" << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt();
		int trainCost = a * n;

		if (trainCost < b) {
			System.out.println(a*n);
		} else {
			System.out.println(b);
		}



	}

}

Measured memory_bytes: 23124