akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <utility>

int dir[] = {0, -1, 0, 1, 0};

using namespace std;
int main()
{
    while (true) {
        int w, h;
        cin >> w >> h;
        if (w == 0 and h == 0) {
            break;
        }
        vector<vector<int>> tile(h, vector<int>(w));
        vector<vector<int>> check(h, vector<int>(w, 0));
        int starti = 0;
        int startj = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                char c;
                cin >> c;
                if (c == '.') {
                    tile[i][j] = 0;

                } else if (c == '#') {
                    tile[i][j] = -1;
                } else {
                    tile[i][j] = 0;
                    starti = i;
                    startj = j;
                }
            }
        }

        queue<pair<int, int>> q;
        q.push(make_pair(starti, startj));
        while (not q.empty()) {
            const int pi = q.front().first;
            const int pj = q.front().second;
            check[pi][pj] = 1;
            q.pop();
            for (int i = 0; i < 4; i++) {
                const int i_ = pi + dir[i];
                const int j_ = pj + dir[i + 1];
                if (i_ >= 0 and i_ < h and j_ >= 0 and j_ < w and tile[i_][j_] == 0 and check[i_][j_] == 0) {
                    q.push(make_pair(i_, j_));
                }
            }
        }
        int cnt = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (check[i][j] == 1) {
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 6204
#include <iostream>
#include <limits>
#include <algorithm>

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

    int max = std::numeric_limits<int>::min();
    int min = std::numeric_limits<int>::max();
    long long int sum = 0;
    for ( int i = 0; i < n; ++i )
    {
        int a;
        std::cin >> a;

        max = std::max( max, a );
        min = std::min( min, a );
        sum += a;
    }
    std::cout
        << min << " " << max << " " << sum
        << std::endl;

    return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;
typedef long long ll;

int main(){
  double n, t, a;
  cin >> n >> t >> a;
  double ans, h;
  int index =  1, ansi;
  rep(i, n){
    cin >> h;
    if(i == 0){
      ans = h;
      ansi = index;
    }else{
      if(fabs(a - (t - 0.006 * h)) < fabs(a - (t - 0.006 * ans))){
        ans = h;
        ansi = index;
      }
    }
    index++;
  }
  cout << ansi << endl;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};

ll mypow(ll n,ll r){
  ll res = 1;
  while(r){
    if(r & 1)res = res*n%MOD;
    n = n*n%MOD;
    r >>= 1;
  }
  return res;
}

ll oh[2020],reoh[2020];

ll comb(ll n,ll r){
  if(n < r)return 0;
  ll res = oh[n]*reoh[r]%MOD;
  res = res*reoh[n-r]%MOD;
  return res;
}

int main(){

  oh[0] = reoh[0] = 1;
  for(int i = 1;i <= 2010;i++)oh[i] = (oh[i-1]*i)%MOD,reoh[i] = mypow(oh[i],MOD-2);
  
  int n,k;
  cin >> n >> k;
  for(int i = 1;i <= k;i++){
    ll nn = i-1;
    ll res;
    n-k-nn >= 0 ? res = comb(k-1,nn)*comb(n-k-nn+nn+2-1,nn+1)%MOD : res = 0;
    cout << res << endl;
  }




  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
 int a,b;
 char op;
 while(scanf("%d %c %d",&a,&op,&b)!=EOF)
 {
   if(op=='?')break;
   else if(op=='+')printf("%d\n",a+b);
   else if(op=='-')printf("%d\n",a-b);
   else if(op=='*')printf("%d\n",a*b);
   else if(op=='/')printf("%d\n",a/b);
 }

 return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var str = "";
			while (!(str = Console.ReadLine()).StartsWith("0 0"))
			{
				var ns = str.Split(' ');
				int n = int.Parse(ns[0]), s = int.Parse(ns[1]);
				Console.WriteLine(f(n, s, -1));
			}
		}

		static int f(int n, int s, int i)
		{
			if (n == 0)
			{
				return (s == 0) ? 1 : 0;
			}
			int a = 0;
			int l = Math.Min(s, 9);
			for (i = i + 1; i <= l; i++)
			{
				a += f(n - 1, s - i, i);
			}
			return a;
		}
	}
}

Measured memory_bytes: 6276
#include "bits/stdc++.h"
 
using namespace std;
 
#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238
 
typedef pair<int, int> P;
 

void solve(std::string S){
    int n = S.length();
    int ans = 0;
    REP(i,n){
        if(S[i]!=S[n-i-1]) ans++;
    }
    cout<<ans/2<<endl;
}
 
signed main(){
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

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

    ll minv = 1e12;
    for (int i = 1; i < w; i++)
    {
        if (i != w - 1)
            minv = min(minv, max({i * h, h * ((w - i) / 2), h * ((w - i) - (w - i) / 2)}) - min({i * h, h * ((w - i) / 2), h * ((w - i) - (w - i) / 2)}));
        minv = min(minv, max({i * h, (w - i) * (h / 2), (w - i) * (h - h / 2)}) - min({i * h, (w - i) * (h / 2), (w - i) * (h - h / 2)}));
    }

    swap(h, w);
    for (int i = 1; i < w; i++)
    {
        if (i != w - 1)
            minv = min(minv, max({i * h, h * ((w - i) / 2), h * ((w - i) - (w - i) / 2)}) - min({i * h, h * ((w - i) / 2), h * ((w - i) - (w - i) / 2)}));
        minv = min(minv, max({i * h, (w - i) * (h / 2), (w - i) * (h - h / 2)}) - min({i * h, (w - i) * (h / 2), (w - i) * (h - h / 2)}));
    }
    OP(minv);
    return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

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

fn main(){
    let n: usize = read_as_vec()[0];

    let mut p = read_as_vec::<usize>();

    let mut op = 0;
    for i in 0..n-1{
        if i+1 == p[i]{
            op += 1;
            let tmp = p[i];
            p[i] = p[i+1];
            p[i+1] = tmp;
        }
    }
    if n == p[n-1]{
        op += 1;
    }

    println!("{}", op);
}


Measured memory_bytes: 6396
(defn abc123-B
  [xs]
  (let [X (->> xs
            (map #(int (Math/ceil (/ % 10))))
            (map (partial * 10)))
        Y (->> xs
            (map #(rem % 10))
            (map #(cond (= 0 %) 0
                        :else (- 10 %))))]
    (- (reduce + X) (apply max Y))))
(defn main-abc123-B []
  (let [xs (doall (for [_ (range 5)] (read)))]
    (println (abc123-B xs))))
(main-abc123-B)


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

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (x/d >= k) {
        x -= k*d;
    } else {
        k -= x/d;
        // x -= (x/d)*d;
        x %= d;
        if (k%2==1) x = abs(x-d);
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 3572
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int MAX_V=1100;
const int INF=1<<25;
struct edge{int to,cap,rev;};
vector<edge>G[MAX_V];
int level[MAX_V],iter[MAX_V];
int N,M,B[MAX_V],R[MAX_V];

int yuc(int a,int b)
{
	if(a%b==0)return b;
	return yuc(b,a%b);
}


void add_edge(int from,int to,int cap)
{
	edge ins={to,cap,G[to].size()};
	G[from].push_back(ins);
	ins.to=from;ins.cap=0;ins.rev=G[from].size()-1;
	G[to].push_back(ins);
}

void bfs(int s)
{
	memset(level,-1,sizeof(level));
	queue<int>Q;
	level[s]=0;
	Q.push(s);
	while(!Q.empty())
	{
		int v=Q.front();Q.pop();
		for(int i=0;i<G[v].size();i++)
		{
			edge &e=G[v][i];
			if(e.cap>0&&level[e.to]<0)
			{
				level[e.to]=level[v]+1;
				Q.push(e.to);
			}
		}
	}
}

int dfs(int v,int t,int f)
{
	if(v==t)return f;
	for(int &i=iter[v];i<G[v].size();i++)
	{
		edge &e=G[v][i];
		if(e.cap>0&&level[v]<level[e.to])
		{
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0)
			{
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t)
{
	int flow=0;
	for(;;)
	{
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF))>0)
			flow+=f;
	}
}


int main()
{
	for(;scanf("%d%d",&N,&M),N+M;)
	{
		for(int i=0;i<MAX_V;i++)G[i].clear();
		int s=0,t=N+M+1;
		for(int i=0;i<N;i++)
		{
			scanf("%d",&B[i]);
			add_edge(s,i+1,1);
		}
		for(int i=0;i<M;i++)
		{
			scanf("%d",&R[i]);
			add_edge(N+i+1,t,1);
		}
		for(int i=0;i<N;i++)
			for(int j=0;j<M;j++)
			{
				if(yuc(max(B[i],R[j]),min(B[i],R[j]))!=1)
					add_edge(i+1,j+N+1,1);
			}
		printf("%d\n",max_flow(s,t));
	}
}

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

using namespace std;

typedef long long ll;

constexpr int M = 1000 * 1000 * 1000 + 7;

int a[100000];

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    if (n % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    cout << a[n / 2] - a[n / 2 - 1] << endl;
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<sstream>
#include<iostream>

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> v;
	REP(i,n){
		int d;
		cin>>d;
		if(find(ALL(v),d)==v.end()){
			v.pb(d);
		}
	}
	cout<<v.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
int main(void)
{
	int i,n,x,y,z,r,m;
	while(scanf("%d%d%d",&x,&y,&z), x)
	{
		m = std::min(x*x+y*y, std::min(y*y+z*z,z*z+x*x));

		scanf("%d",&n);
		for(i = 0; i < n; ++i)
		{
			scanf("%d",&r);
			puts( m<4*r*r ? "OK" : "NA" );
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define MOD (ll)(1e9+7)
#define ex(k) (a*(b-n)+(a-b)*(k)-(k)*(k))
using namespace std;

void solve()	{
	int n;
	cin >> n;
	int d[n][2];
	for(int i=0; i<n; i++)	{
		cin >> d[i][0] >> d[i][1];
	}
	for(int i=0; i<n-2; )	{
		if(d[i][0]==d[i][1])	{
			int l=0;
			while(d[i][0]==d[i][1])	{
				l++;
				i++;
			}
			if(l>2)	{cout << "Yes\n"; return;}
		}
		else i++;
	}
	cout << "No\n";
}

int main()	
{
	int t=1;
	//cin >> t;
	for(int i=1; i<=t; i++)	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




// https://imulan.hatenablog.jp/entry/2016/06/14/192955

int dp[2][55][3100];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int n;
    const int mod = 100000;
    while (cin >> n && n) {
        int m, s;
        cin >> m >> s;
        
        fill_n(**dp, 2 * 55 * 3100, 0);
        dp[0][0][0] = 1;
        
        rep3(y, 1, m + 1) { // 数字の候補
            rep(x, n * n + 1) rep(z, s + 1) dp[y % 2][x][z] = dp[(y % 2) ^ 1][x][z];
            
            // これまでx個とった, 合計はz
            rep(x, n * n) rep(z, s) {
                if (z + y <= s) (dp[y % 2][x + 1][z + y] += dp[(y % 2) ^ 1][x][z]) %= mod;
                // (dp[y % 2][x][z] += dp[(y % 2) ^ 1][x][z]) %= mod; // 間違い
            }
            
            if (y == m) {
                cout << dp[y % 2][n * n][s] << endl;
            }
            // cout << endl; rep(i, n * n + 1) { rep(j, s + 1) cout << dp[y % 2][i][j] << " "; cout << endl; }
        }
        
        
    }
}




Measured memory_bytes: 4544
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return b;
    }
    return gcd(b, a % b);
}

int main()
{
    ll R;
    cin >> R;

    string ans;
    if (R < 1200)
    {
        ans = "ABC";
    }
    else if (R < 2800)
    {
        ans = "ARC";
    }
    else
    {
        ans = "AGC";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] S = stdR.readLine().split(" ");
        int N = Integer.parseInt(S[0]);
        int D = Integer.parseInt(S[1]);
        int res = D * 2 + 1;
        System.out.println(N % res == 0 ? N / res : N / res + 1);
    }
}


Measured memory_bytes: 20564
#include <stdio.h>
int main(void){
  int i,x=0,xx=0,max=0;
  char s[100001];
  scanf("%s",&s);
//0
    for(i=0;s[i]!='\0';i++){
      if(i%2==1){
        if(s[i]=='0'){
          xx++;
        }
      }else{
        if(s[i]=='1'){
          xx++;
        }
      }
    }
//1 
    for(i=0;s[i]!='\0';i++){
      if(i%2==1){
        if(s[i]=='1'){
          x++;
        }
      }else{
        if(s[i]=='0'){
          x++;
        }
      }
    }
  if(x>xx)
    max=xx;
  else
    max=x;
  
  printf("%d",max);
  return 0; 
}

Measured memory_bytes: 256
S = input()
tmp1 = int(S[:2])
tmp2 = int(S[2:])
if 0 < tmp1 <= 12 and 0 < tmp2 <= 12:
    print("AMBIGUOUS")
elif (tmp1 == 0 or tmp1 > 12) and 0 < tmp2 <= 12:
    print("YYMM")
elif 0 < tmp1 <= 12 and (tmp2 == 0 or tmp2 > 12):
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
	  FastReader sc = new FastReader();
	  int first = Integer.MIN_VALUE;
	  int second = Integer.MIN_VALUE;
	  int third = Integer.MIN_VALUE;
	  
	  for (int i = 0; i < 3; i++) {
		  int n = sc.nextInt();
		  if (n > first) {
			  third = second;
			  second = first;
			  first = n;
		  } else if (n > second) {
			  third = second;
			  second = n;
		  } else if (n > third) {
			  third = n;
		  }
	  }
	  
	  System.out.println(first*10 + second + third);
	  System.exit(0);
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() { 
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

bool is_prime(ll N) {
    if (N <= 1) return false;
    for (ll i = 2; i*i <= N; i++) {
        if (N % i == 0) {
            return false;
        }
    }
    return true;
}

int main(void)
{
    ll X;
    cin >> X;

    ll ans = X;

    while (!is_prime(ans)) {
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
N,A,B=$<.read.split.map(&:to_i)
MOD=10**9+7

def pow(a,b,mod)
    res = 1
    while 0 < b
        res = res * a % mod if b & 1 == 1
        a = a * a % mod
        b >>= 1
    end
    res
end

def f(a,b,mod)
    i = a
    n = 1
    while i <= b
        n = n*i % mod
        i += 1
    end
    n
end

def inv(a,mod)
    pow(a,mod-2,mod)
end

def comb(a,b,mod)
    (f(a-b+1,a,mod) * inv(f(1,b,mod),mod)) % mod
end

ret = (pow(2,N,MOD) - 1 - comb(N,A,MOD) - comb(N,B,MOD)) % MOD
puts ret

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,a[200005],b[200005],t1,t2;
int ans;
map<int,int> mp;
int main()
{
	scanf("%d",&n);
	fz1(i,n){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	fz1(i,n){
		mp[a[i]]=(i&1);
	}
	fz1(i,n){
		ans+=abs(mp[b[i]]-(i&1));
	}
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int a, b, k;

    cin >> a >> b >> k;
    int m = max(a, b), cont = 0;

    for (int i=m; cont < k; i--) {
        if (a%i == 0 && b%i == 0) cont++;
        if (cont == k) cout << i << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*

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

*/

#include<bits/stdc++.h>
#include<assert.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0);
#define fo(i,s,n) for(int i=s;i<n;i++)
#define mod 1000000007
#define umap unordered_map
#define pb(x) push_back(x)
#define all(x) (x).begin(), (x).end()
#define lb() lower_bound()
#define ub() upper_bound()
#define PI 3.14159265
#define S second
#define F first 
//fill(all(vec), 1);to fill vector with a number
//if (S.count(key)) returns 1 if set or map contain key else return 0
ll nCr(ll n,ll r)
{
	r = min(r,n-r);
	if(r<0)
		 return 0;
	if(r == 0)
		return 1;
	ll ans = 1;
	for(ll i = 1;i<=r;i++)
	{
		ans = ans*(n-i+1)/i;
    }
	return ans;
 		
}


ll logn(int n, int r) 
{ 
     return (n > r - 1) ? 1 + logn(n / r, r) : 0; 
} 


ll power(ll a,ll b) {
	if(b == 1) return a;
	if(b == 0) return 1;
	ll m1 = power(a,b/2);
	if(b%2) return m1*m1*a;
	return m1*m1;
}


bool isprime(ll a)
{
    if(a<=1)
        return false;
    if(a==2||a==3)
        return true;
    if(a%2==0||a%3==0)
        return false;
    for(ll i=5;i*i<=a;i=i+6)
    {
        if(a%i==0||a%(i+2)==0)
            return false;
    }
    return true;

}
/*********************//*********************///*********************///*********************//
ll t;

void solve()
{
    string s;
    cin>>s;
    int ans=0;
    int ma=-1;
    fo(i,0,3)
    {
        if(s[i]=='R')
            ans++;
        else
        {
            ans=0;
        }
        ma=max(ma,ans);
        
    }
    cout<<ma<<endl;
}



int main()
{
    Fast
/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
*/
    //cin>>t;
    t=1;
    for(ll i=1;i<=t;i++)
    {
      solve();
    }

    
    return 0;
}

Measured memory_bytes: 3648
// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll t; cin>>t; while(t--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
bool check(ll mid,vector<ll> v,ll n,ll k){
    if(!mid)
        return false;
    f(i,0,n){
        ll cut=(v[i]-1)/mid;
        k-=cut;
    }
    if(k<0)
        return false;
    return true;
}
int main(){
    TEZ;
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    f(i,0,n)
        cin>>v[i];
    srt(v);
    ll s=0,e=v[n-1]+1;
    ll ans=0;
    while(s<=e){
        ll mid=s+(e-s)/2;
        if(check(mid,v,n,k)){
            ans=mid;
            e=mid-1;
        }else{
            s=mid+1;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 6340
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0);cin.tie(0)
using ll = long long;
using ull = unsigned long long;

int main() {
  fastio;
  int s, w;
  cin >> s >> w;
  if (s <= w) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
  return 0;


  #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<math.h>

int main(){
  
  int i ,a = 0;
  //座標の個数、制限距離、座標の距離
  double N, D, L;
  //X座標、Y座標
  double X[1000000], Y[1000000];
  
   char str[1000000];
   char hub[1000000];
    
   fgets(str, sizeof(str), stdin);
   sscanf(str,"%lf %lf",&N, &D);
  
  for(i = 0; i < N; i++){
     fgets(hub, sizeof(hub), stdin);
     sscanf(hub,"%lf %lf",&X[i], &Y[i]);
    
     L = sqrt(X[i] * X[i] + Y[i] * Y[i]);
       
     if(D >= L){
       
       a += 1;
     
     }
    
  }
    
  printf("%d\n" ,a);
  
  return 0;
  
}

Measured memory_bytes: 5324
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

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

stack<int> st;

int main(void){
	int n,l=0,r=0,i,cnt=0;
	string s;
	cin >> n;
	cin >> s;
	for(i=0; i<n; ++i){
		if(s[i]=='('){
			++l;
			st.push(i);
		}else{
			++r;
			if(!st.empty()){
				st.pop();
				++cnt;
			}
		}
	}
	for(i=cnt; i<r; ++i){
		cout << "(";
	}
	cout << s;
	for(i=cnt; i<l; ++i){
		cout << ")";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
let search (mini, maxi, total) n =
  ((min mini n), (max maxi n), (total + n))

let () =
  let () = ignore (read_line ())
  and data = read_line () in
  let mini, maxi, total = Str.split (Str.regexp " ") data |>
                          List.map int_of_string |>
                          List.fold_left search (max_int, min_int, 0) in
  Printf.printf "%d %d %d\n" mini maxi total

Measured memory_bytes: 4476
using System;
using System.Linq;

namespace AGC019A
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] QHSD = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
            long Q = QHSD[0];
            long H = QHSD[1];
            long S = QHSD[2];
            long D = QHSD[3];
            long N = long.Parse(Console.ReadLine());

            long ans = solve(Q, H, S, D, N);
            Console.WriteLine(ans);
        }

        static long solve(long Q, long H, long S, long D, long N)
        {
            long total = 0;

            long doubles = N / 2;
            long bestDoubleCost = Math.Min(Math.Min(Q * 8, H * 4), Math.Min(S * 2, D));

            total += bestDoubleCost * doubles;

            if (N % 2 == 1)
            {
                long bestSingleCost = Math.Min(Math.Min(Q * 4, H * 2), S);
                total += bestSingleCost;
            }

            return total;
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

vi tail;
const int nax = 2e5+20;
vi a(nax), ans(nax);
vvi adj(nax);
int n,u,v;

// int LIS1(vi &a){
//     vi tail;
//     for(auto x: a){
//         auto it = lower_bound(all(tail), x);
//         if(it==tail.end())
//             tail.push_back(x);
//         else 
//             *it = x;
//     }
//     print(tail);
//     return tail.size();
// }

void dfs(int x, int par){
    int prev = -1;
    auto it = lower_bound(all(tail), a[x]);
    int idx = it - tail.begin();
    if(it==tail.end()){
        tail.push_back(a[x]);
    }
    else{
        prev = *it;
        *it = a[x];
    }

    ans[x] = (int)tail.size();

    for(auto ad: adj[x]){
        if(ad==par) continue;
        dfs(ad, x);
    }

    if(prev==-1)
        tail.pop_back();
    else{
        tail[idx] = prev;
    }
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    fore(i,1,n+1)
        cin>>a[i];
    
    forn(i,n-1){
        cin>>u>>v;
        adj[u].pb(v), adj[v].pb(u);
    }

    dfs(1,-1);

    fore(i,1,n+1)
        cout<<ans[i]<<"\n";

    return 0;
}


Measured memory_bytes: 30100
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void){
	int n,k;
	cin>>n>>k;
	vector<vector<int> > tree(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		tree[a-1].push_back(b-1);
		tree[b-1].push_back(a-1);
	}


	vector<int> mask(n,0);
	queue<int> que;

	mask[0]=1;
	ll ans=k;

	rep(i,tree[0].size()){
		que.push(tree[0][i]);
		mask[tree[0][i]]=1;
		ans*=(k-1-i);
		ans=ans%MAX;
	}
	//cout<<ans<<endl;;
	while(!que.empty()){
		int id=que.front();
		//cout<<"node:"<<id<<endl;
		que.pop();
		//queueに子供をいれる
		//cout<<"child is "<<endl;
		rep(i,tree[id].size()){
			if(mask[tree[id][i]] == 0){
				que.push(tree[id][i]);
				mask[tree[id][i]]=1;
				//cout<<tree[id][i]<<endl;
			}
		}
		ll tmp=1;

		//cout<<"color:"<<k-tree[id].size()<<endl;

		//配色の組み合わせを計算
		rep(i,tree[id].size()-1){
			tmp*=(k-2-i);
			tmp=tmp%MAX;
		}
		
		ans*=tmp;
		ans=ans%MAX;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6904
n=int(input())
a=list(map(int,input().split()))
flag=True
cnt=0
for i in range(n):
	if not flag:
		break
	flag=False
	for j in range(n-1,i,-1):
		if a[j]<a[j-1]:
			a[j],a[j-1]=a[j-1],a[j]
			cnt+=1
			flag=True
print(*a)
print(cnt)


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long n,m;
	cin>>n>>m;
	long long pos;
	cin>>pos;
	long long r[n+5];
	long long c[m+5];
	memset(r,0,sizeof r);
	memset(c,0,sizeof c);
	map<pair<int,int>,int>mp;
	for(int i=0;i<pos;i++)
	{
		long long x,y;
		cin>>x>>y;
		r[x]++;
		c[y]++;
		mp[{x,y}]++;
	}
	int ans=0;
	priority_queue<pair<int,int>>pq,pq1;
	for(int i=1;i<=n;i++)
	{
		pq.push({r[i],i});
	}
	for(int i=1;i<=m;i++)
	{
		pq1.push({c[i],i});
	}
	while(pq.size() && pq1.size())
	{
		pair<int,int>p=pq.top();
		pq.pop();
		pair<int,int>p1=pq1.top();
		pq1.pop();
		/*cout<<p.first<<" "<<p.second<<'\n';
		cout<<p1.first<<" "<<p1.second<<'\n';*/
		int curr_ans=p.first+p1.first;
		if(mp.find({p.second,p1.second})!=mp.end())
		curr_ans--;
		if(curr_ans>=ans)
		ans=curr_ans;
		else
		break;
		if(p.first>p1.first)
		pq.push(p);
		else
		pq1.push(p1);
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 34996
//#pragma comment(linker, "/STACK:102400000,102400000") 
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 4e5 + 5;
const ll mod = 1000;
const double PI = acos(-1.0);
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }

int n, q,cnt;
char val[maxn];
int ch[maxn][30];
int pre[maxn], num[maxn], is[maxn], res[maxn], v[maxn];

char x[100005][30];
int nu[30][30], id[30];
vector<int>p[100005];
map<int, int>hax;

void init()
{
	cnt = 0;
}

void insert(char *x, int len, int id)
{
	int now = 0;
	for (int i = 1; i <= len; i++)
	{
		int k = x[i] - 'a' + 1;
		if (!ch[now][k])
		{
			++cnt;
			ch[now][k] = cnt;
		}
		pre[ch[now][k]] = now;
		now = ch[now][k];
		v[now] = k;
		num[now]++;
	}
	is[now]++;
	hax[id] = now;
}

void cal(int x)
{
	while (x)
	{
		for (int i = 1; i <= 26; i++)
		{
			if (i != v[x] && ch[pre[x]][i])
			{
				nu[i][v[x]] += num[ch[pre[x]][i]];
			}
		}
		nu[v[x]][v[x]] += is[x];
		x = pre[x];
	}
}

void solve()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%s", val + 1);
		insert(val, strlen(val + 1), i);
	}
	scanf("%d", &q);
	for (int i = 1; i <= q; i++)
	{
		int op;
		scanf("%d%s", &op, x[i] + 1);
		p[op].push_back(i);
	}

	for (int i = 1; i <= n; i++)
	{
		memset(nu, 0, sizeof(nu));
		int o = hax[i];
		cal(o);
		for (int j = 0; j < p[i].size(); j++)
		{
			int k = p[i][j];

			for (int g = 1; g <= 26; g++)
			{
				id[g] = x[k][g] - 'a' + 1;
			}
			int f = 0;
			for (int g = 1; g <= 26; g++)
			{
				for (int d = g; d <= 26; d++)
				{
					f += nu[id[g]][id[d]];
				}
			}
			res[k] = f;
		}
	}
	for (int i = 1; i <= q; i++)
	{
		printf("%d\n", res[i]);
	}
}


int main()
{

	solve();
	return 0;
}




Measured memory_bytes: 59904
#define mod 1000000007
char buf[99];sz;
char out[10];osz=10;
int N,A,B;
long p(long a,long b){
	long ret=1;
	while(b)
	{
		if(b&1)ret=ret*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return ret;
}
main()
{
	read(0,buf,99);
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		N=N*10+c-'0';
	}
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		A=A*10+c-'0';
	}
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		B=B*10+c-'0';
	}
	long ans=p(2,N)-1;
	long x=1,y=1;
	for(int i=1;i<=A;i++)
	{
		x=x*(N-i+1)%mod;
		y=y*i%mod;
	}
	ans-=x*p(y,mod-2)%mod;
	for(int i=A+1;i<=B;i++)
	{
		x=x*(N-i+1)%mod;
		y=y*i%mod;
	}
	ans-=x*p(y,mod-2)%mod;
	while(ans<0)ans+=mod;
	do{
		out[--osz]=ans%10+'0';
	}while(ans/=10);
	write(1,out+osz,10-osz);
}


Measured memory_bytes: 128
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors

n=int(input())
ans=0

y=make_divisors(n)
z=make_divisors(n-1)

y.sort()


for i in range(1,len(y)):
    v=n

    while v>=y[i]:
        if v%y[i]==0:
            v=v//y[i]
        else:
            v%=y[i]

    if v==1:
        ans+=1

print(ans+len(z)-1)

Measured memory_bytes: 39152
#include<cstdio>
#include<cstring>
const int N=2e5+7,inf=0x3f3f3f3f;
int dp[N],nxt[N][26],n,x,i,j;char s[N];
int main(){
	for(scanf("%s",s+1),n=strlen(s+1),i=0;i<26;++i)nxt[n][i]=n+1;
	for(memset(dp,inf,sizeof(dp)),dp[n+1]=0,i=n;i>=0;--i){
		for(j=0;j<26;++j)if(dp[i]>dp[x=nxt[i][j]]+1)dp[i]=dp[x]+1;
		if(i)memcpy(nxt[i-1],nxt[i],sizeof(nxt[i])),nxt[i-1][s[i]-'a']=i;
	}
	for(x=0;x<n+1;){
		for(j=0;j<26;++j)if(dp[nxt[x][j]]==dp[x]-1){
			putchar(j+'a');x=nxt[x][j];break;
		}
	}
	return 0*puts("");
}

Measured memory_bytes: 21504
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <ctime>

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define TT int test_cases; cin >> test_cases; while(test_cases--)
#define TT1 int test_cases=1; while(test_cases--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
using namespace std;
typedef long long int ll;

 
int main() {
    
    FAST;
    TT1{
        int n,k;cin>>n>>k;
        vector<int> a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        sort(a.begin(),a.end());
        int sum=0;
        for(int i=0;i<k;i++) sum+=a[i];
        cout<<sum<<"\n";
    }
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int N, Q, c[1009], v[1009], t, x, d;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> c[i];
	cin >> Q;
	int ret = 0;
	for (int i = 0; i < Q; i++) {
		cin >> t >> x >> d; x--;
		if (t == 1) {
			v[x] += d;
		}
		else {
			v[x] -= d;
		}
		if (v[x] < 0 || v[x] > c[x]) {
			ret = x + 1;
			break;
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3108
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long E = sc.nextLong();

		long[] h = {A,B,C,D,E};

		double min=Long.MAX_VALUE;

		for(int i=0;i<5;i++)
			min=Math.min(min,h[i]);

		System.out.println((long)Math.ceil(N/min)+4);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <math.h>
#define T 1
#define F -1
int Prime(int x)
{
  if(x==2) return T;
  if(x<2||x%2==0)return F;
  int i=3;
  while(i<=sqrt(x))
  {
    if(x%i==0)return F;
    i += 2;
  }
  return T;
}
int main()
{
  int cnt=0,n,x;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
  {
    scanf("%d",&x);
    if(Prime(x)==T)cnt+=1;
  }
  printf("%d\n",cnt);
  return 0;
}



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

int main()
{
    string t;
    cin >> t;
    rep(i, t.size()){
        if(t[i] == '?') t[i] = 'D';
    }
    cout << t << endl;
}


Measured memory_bytes: 3748
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << “\t:“;for(const auto& xxx : v){std::cerr << xxx << ” “;}std::cerr << “\n”;}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << ” ” << xxx.second << “\n”;}}

//配るDP

using LL = long long;

int main() {

    int N;
    cin >> N;

    vector<vector<int>> abc(N, vector<int>(3));
    for (int i = 0; i < N; i++) for (int j = 0; j < 3; j++) cin >> abc[i][j];

    vector<vector<int>> dp(N, vector<int>(3, 0));
    for (int i = 0; i < 3; i++)dp[0][i] = abc[0][i];

    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k)dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[i + 1][k]);
            }
        }
    }

    int ans = *max_element(dp[N - 1].begin(), dp[N - 1].end());
    cout << ans << endl;

    return 0;
}































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

int main()
{
	double a,b;
	while(cin >> a >> b)
	{
		     if(a<35.50 && b< 71.00) cout << "AAA";
		else if(a<37.50 && b< 77.00) cout << "AA";
		else if(a<40.00 && b< 83.00) cout << "A";
		else if(a<43.00 && b< 89.00) cout << "B";
		else if(a<50.00 && b<105.00) cout << "C";
		else if(a<55.00 && b<116.00) cout << "D";
		else if(a<70.00 && b<148.00) cout << "E";
		else						 cout << "NA";
		cout << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve(){
    stack<ll> S;
    ll u, d;
    string s;
    while(cin >> s){
        if(s[0] == '+'){
            u = S.top();
            S.pop();
            d = S.top();
            S.pop();
            S.push(d+u);
        }else if(s[0] == '-'){
            u = S.top();
            S.pop();
            d = S.top();
            S.pop();
            S.push(d-u);
        }else if(s[0] == '*'){
            u = S.top();
            S.pop();
            d = S.top();
            S.pop();
            S.push(d*u);
        }else {
            S.push(stoi(s));
        }
    }

    cout << S.top() << "\n";
}


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

    solve();
    return 0;
}



Measured memory_bytes: 3220
A, B, Q = map(int, input().split())

Jinja = []
Tera = []
Ichi = []
for i in range (0, A):
	Jinja.append(int(input()))
for i in range (0, B):
	Tera.append(int(input()))
for i in range (0, Q):
	Ichi.append(int(input()))

import math
import bisect as bi

for i in range (0, Q):
	temp = Ichi[i]
	J = math.inf
	T = math.inf
	JL = bi.bisect_left(Jinja, temp)
	JR = bi.bisect_right(Jinja, temp)
	TL = bi.bisect_left(Tera, temp)
	TR = bi.bisect_right(Tera, temp)
	if JL != JR:
		J = 0
	if TL != TR:
		T = 0
	if JR == 0:
		JW = math.inf
		JE = abs(temp-Jinja[0])
	elif JL == A:
		JW = abs(temp-Jinja[A-1])
		JE = math.inf
	else:
		JW = abs(temp-Jinja[JL-1])
		JE = abs(temp-Jinja[JL])
	if TR == 0:
		TW = math.inf
		TE = abs(temp-Tera[0])	
	elif TL == B:
		TW = abs(temp-Tera[B-1])
		TE = math.inf	
	else:
		TW = abs(temp-Tera[TL-1])
		TE = abs(temp-Tera[TL])
	print(min(J+T, J+TW, J+TE, T+JW, T+JE, max(JW, TW), max(JE, TE), 2*JW+TE, 2*TE+JW, 2*JE+TW, 2*TW+JE))

Measured memory_bytes: 20924
#include <stdio.h>

int main(void){
  int ans = 0;
  char data[4];

  scanf("%s",data);

  for(int i = 0;i < 4;i++){
    if(data[i] == '+')
      ans++;
    else
      ans--;
  }

  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
from heapq import heappop, heappush
 
 
def dijkstra(costs, s, i):
    q = [(0, s)]
    while q:
        c, v = heappop(q)
        if costs[v] >= 0:
            continue
        costs[v] = c
        for link in links[v]:
            u = link[0]
            if costs[u] == -1:
                heappush(q, (c + link[i], u))
 
 
n, m, s, t = map(int, input().split())
links = [[] for _ in range(n+1)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    links[u] += (v, a, b),
    links[v] += (u, a, b),

yen_costs = [-1] * (n+1)
snk_costs = [-1] * (n+1)
dijkstra(yen_costs, s, 1)
dijkstra(snk_costs, t, 2)
ansl = []
ans = 0

for i in range(1, n+1):
    cost = yen_costs[-i]+snk_costs[-i]
    m = 10**15 - cost
    if ans < m:
        ans = m
    ansl.append(ans)
for _ in range(n):
    print(ansl.pop())

Measured memory_bytes: 55716
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;++i)    cin >> a[i];

    sort(a.begin(), a.end());

    int flag = 1;
    for(int i = 0;i < n-1;++i){
        if(a[i] == a[i+1]){
            flag = 0;
            cout << "NO" << endl;
            break;
        }
    }

    if(flag == 1){
        cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

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

int dp[2][5010][2];
int t[10010];

int main(){
	int n;
	cin >> n;
	FOR(i, 1, n) cin >> t[i];
	rep(i, 2) rep(j, n/2+1) rep(k, 2) dp[i][j][k] = 1 << 29;
	dp[0][0][0] = dp[0][0][1] = 0;

	rep(i, n){
		rep(j, n / 2) rep(k, 2) rep(l, 2){
			int x = k == 1;
			dp[i + 1 & 1][j + x][k] = min(dp[i + 1 & 1][j + x][k], dp[i & 1][j][l] + t[i] * (k != l));
		}
		rep(j, n / 2 + 1) rep(k, 2) dp[i & 1][j][k] = 1 << 29;
	}
	cout << min(dp[0][n / 2][0], dp[0][n / 2][1]) << endl;

	return 0;
}

Measured memory_bytes: 1276