akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
#define int long long

void solve() {
	int h, n; cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    int dp[10010];
    rep(i, 10010) {
        dp[i] = inf;
    }
    dp[0] = 0;
    for(int i = 0; i <= h; ++i) {
        rep(j, n) {
            if(i + a[j] <= h) chmin(dp[i + a[j]], dp[i] + b[j]);
            else chmin(dp[h], dp[i] + b[j]);
        }
    }
    cout << dp[h] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
*/

ll a,b;

void init(){
	cin>>a>>b;
}

int main(void){
	init();
	cout<<max({a+b,a-b,a*b})<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=1;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT32_MAX;

ll i,j,k;
long long euclid(long long x,long long y){
    long long a=max(x,y);
    long long b=min(x,y);
    if(a%b==0)return b;
    else{
        return euclid(b,a%b);
    }
}





int main(){
   ll K;
   cin>>K;
   ll ans=0;
   rep(i,K+1)rep(j,K+1)rep(k,K+1)ans+=euclid(i,euclid(j,k));
   cout<<ans<<endl;

}

Measured memory_bytes: 3636
#include<iostream>
#define ll long long int
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	char a[n][m];
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		cin>>a[i][j];
	}
	ll dp[n][m];
	dp[0][0]=1;
	for(int i=1;i<n;i++)
	{
		if(a[i][0]!='#'&&dp[i-1][0]!=0)
		dp[i][0]=1;
		else
		dp[i][0]=0;
	}
	
	for(int j=1;j<m;j++)
	{
		if(a[0][j]!='#'&&dp[0][j-1]!=0)
		dp[0][j]=1;
		else
		dp[0][j]=0;
	}
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		if(a[i][j]=='#')
    		dp[i][j]=0;
    		
    		
		}
		
	}
	
	ll mod=1000000007;
	
	for(int i=1;i<n;i++)
    {
    	for(int j=1;j<m;j++)
    	{
    		if(a[i][j]!='#')
    		dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
    		
    		//cout<<dp[i][j]<<" ";
    		
		}
		
		//cout<<endl;
	}
	cout<<dp[n-1][m-1];
	
	
	
	
	
}

Measured memory_bytes: 9088
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;
ll level;
struct edge {
	ll to;
};

vector<edge>G[100010];
ll d[100010];

bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b) {
	if (a.second == b.second)return a.first < b.first;
	else return a.second > b.second;
}

void dfs(int root,vector<ll> &c) {
	d[root] = c[level];
	level--;
	for (auto itr = G[root].begin();itr != G[root].end();++itr) {
		//cout << itr->to << endl;
		if (d[itr->to] == 0)dfs(itr->to, c);
	}
	return;
}

int main(void) {
	int n;
	cin >> n;
	vector<int>w(n);
	int ans = 10000000;
	for (int i = 0;i < n;i++)cin >> w[i];
	for (int t = 0;t < n;t++) {
		int s1 = 0, s2 = 0;
		for (int i = 0;i < n;i++) {
			if (i <= t)s1 += w[i];
			else s2 += w[i];
		}
		ans = min(ans, abs(s1 - s2));
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int A, B; cin >> A >> B;
  if(A==B){
    cout << "Draw" << endl;
  }
  if(A==1 && B!=1){
    cout << "Alice" << endl;
    return 0;
  }
  if(A!=1 && B==1){
    cout << "Bob" << endl;
    return 0;
  }
  if(A>B){
    cout << "Alice" << endl;
  }
  if(B>A){
    cout << "Bob" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws java.io.IOException {
        Scanner scan = new Scanner(System.in);
        while (true) {
            int n = scan.nextInt();
            if (n == 0)
                break;
            int[] g = new int[7];
            while (n != 0) {
                int age = scan.nextInt();
                if (age >= 60)
                    age = 60;
                g[age / 10]++;

                n--;
            }
            for (int a : g)
                System.out.println(a);
        }
    }
}

Measured memory_bytes: 12000
#include <iostream>
#include <queue>

int main(void)
{
	std::priority_queue<int> height_array;
	int height;
	
	for(int i=0; i<10; i++){
		std::cin >> height;
		height_array.push(height);
	}
	
	for(int i=0; i<3; i++){
		std::cout << height_array.top() << std::endl;
		height_array.pop();
	}
	
	
	return 0;
	
}

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

int H, W;

int main(){
	cin >> H >> W;
	string C[H];
	for(int i=0;i<H;i++){	
		cin >> C[i];
	}
	
	for(int i=0;i<H;i++){
		cout << C[i] << endl;
		cout << C[i] << endl;
    }
    
    return 0;
}


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



int main()
{
    ll i,j,k,l,m,n;

    cin >> n;

    ll L[n+10],R[n+10],ar[n+10];
memset(L,-1,sizeof L);

    for(i = 0 ; i < n ; i++)cin >> ar[i],R[i] = n;

    stack<ll>st;

    for(i = 0 ; i < n ; i++)
    {
        while(!st.empty() && ar[st.top()] >= ar[i])
            st.pop();
       if(!st.empty())L[i] = st.top();
        st.push(i);
    }

    while(!st.empty())st.pop();

    for(i = n-1 ; i >= 0 ; i--)
    {
        while(!st.empty() && ar[st.top()] >= ar[i])st.pop();
        if(!st.empty())R[i] = st.top();
        st.push(i);
    }

     while(!st.empty())st.pop();

     ll ans = 0;
    for(i = 0 ; i < n ; i++)
    {
        ans += ((i-L[i])*(R[i]-i))*ar[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    int N;
    scanf("%d", &N);

    char S[10000];
   
    scanf("%s", S);
     for(int i = 0 ; S[i] != '\0' ; i++){
        S[i] = S[i] + N;
         
        if(S[i] > 90){
            S[i] = S[i] - 26;
        }
    }

    printf("%s",  S);  
    printf("\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 //約数とかが関係してそう
int main() {
  long long A, B, N;
  long long X, Y, Z, C;
  C=0;
  cin >> A >> B >> N;
  X=min(N,B-1);
  Y=0;
  if(B!=1){
  while(X<=N){
  Z=X*A;
  Z/=B;
  Z=Z-Y*A;
  if(C<Z)C=Z;
  //X=Z+B-1;
  X+=B;
  Y++;
  }
  Z=N*A;
  Z/=B;
  Z=Z-Y*A;
  if(C<Z)C=Z;
  cout << C << endl;
  }
  if(B==1)cout << 0 << endl;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



void f(int N, int a, int k, string s, vector<string> &ret){
  const int mask = (1 << N) - 1;
  if(a == mask){
    ret.push_back(s);
    return;
  }

  int j = 0;
  REP(i,N){
    if((a & bit(i)) == 0){
      j = i;
      break;
    }
  }

  int b = ~a & mask;

  for(int t=0; ; t=(t-b)&b){
    if(t & bit(j)){
      string ss(s);

      REP(i,N){
        if(t & bit(i)){
          ss[i] = (char)('a' + k);
        }
      }
      
      f(N, a | t, k+1, ss, ret);
    }
    
    if(t==b) break;
  }
}




int main(){
  int N;

  while(cin >> N){

    vector<string> ans;

    string s(10, ' ');
    f(N, 0, 0, s, ans);
    
    sort(ALL(ans));

    join(cout, ALL(ans), "\n");
  }


  return 0;
}


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

int main(){
    int n;
    cin >> n;
    priority_queue<double,vector<double>,greater<double>> que;
    rp(i,n){
        double v;
        cin >> v;
        que.push(v);
    }
    double ans;
    while(1){
        double a=que.top(); que.pop();
        if(que.empty()){
            ans=a;
            break;
        }
        double b=que.top(); que.pop();
        que.push((a+b)/2.0);
    }
    cout <<fixed<<setprecision(6)<< ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int a,b;
    int ans = 0;
    scanf("%d%d",&a,&b);
    for(int i = 1;i <= 2;i++)
    if(a > b)
    {
        ans += a;
        a--;
    }
    else
    {
        ans += b;
        b--;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


long long f(long long n, long long x){
	if(n == -1){
        return 0;
    }else{
        return n/x+1;
    }
}


int main(){
	long long a, b, x;
	cin >> a >> b >> x;

	cout << f(b, x) - f(a - 1, x) << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int n = sc.nextInt();
			
			long d = sc.nextLong();
			long d2 = d * d;
			
			int count = 0; 
			for(int i = 0 ; i < n ; i++ ) {
				long x = sc.nextLong();
				long y = sc.nextLong();
				
				if ( x * x + y * y <= d2 ) {
					count++;
				}
			}
			
			System.out.println(count);
		}
	}

}

Measured memory_bytes: 59940
# -*- coding: utf-8 -*-
"""
C - Walk on Multiplication Table
https://atcoder.jp/contests/abc144/tasks/abc144_c

"""
import sys


def divisor(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            divisors.add(n // i)
    return divisors


def solve(N):
    ans = float('inf')
    for d in divisor(N):
        q = N // d
        ans = min(ans, d-1 + q-1)
    return ans


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3828
using System;

namespace abc167A
{
  public class MainClass
  {
    public static void Main(string[] args)
    {
      long R = long.Parse(Console.ReadLine());
      if(R < 1200){Console.WriteLine("ABC");}
      else if(R < 2800){Console.WriteLine("ARC");}
      else{Console.WriteLine("AGC");}
    }
  }
}

Measured memory_bytes: 11092
for _ in [0] * int(raw_input()):
  h, m = map(int, raw_input().split(':'))
  x = abs(h*60 - m*11)
  if x>360: x=720-x
  if x<60:
    print 'alert'
  elif 180<=x:
    print 'safe'
  else:
    print 'warning'

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

using namespace std;


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

	int n;
	string s;

	cin >> n;
	cin >> s;

	if(s.length() > n)
	{
		cout << s.substr(0,n) << "..." << '\n';
	}
	else
	{
		cout << s << '\n';
	}
	
	return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<int> freqs(10, 0);
  int score = -1, extra = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &score);
    if (score >= 3200) { ++extra; }
    else { ++freqs[score / 400]; }
  }

  int cnt = 0;
  for (int i = 0; i < 10; ++i) {
    if (freqs[i] > 0) { ++cnt; }
  }
  int ans_min = (cnt == 0) ? 1 : cnt;
  int ans_max = cnt + extra;
  printf("%d %d\n", ans_min, ans_max);
  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;
import java.util.HashMap;

/**
 * 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);
        GreenBin solver = new GreenBin();
        solver.solve(1, in, out);
        out.close();
    }

    static class GreenBin {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            HashMap<String, Integer> set = new HashMap<>();
            for (int i = 0; i < n; i++) {
                char[] chars = in.next().toCharArray();
                Arrays.sort(chars);
                StringBuilder sb = new StringBuilder();
                sb.append(chars);
                set.put(Arrays.toString(chars), set.getOrDefault(Arrays.toString(chars), 0) + 1);
            }

            long result = 0;
            for (String key : set.keySet()) {
                int a = set.get(key);
                result += (long) a * (a - 1) / 2;
            }
            out.println(result);
        }

    }
}



Measured memory_bytes: 69380
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define debug(x) cout << "> x:" << x << endl;
#define len(x) int(x.size())
#define all(x) x.begin(), x.end()
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	if(k==1) cout << 0 << endl;
	else cout << n-k << endl;

}


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

using namespace std;
string S;
bool one;
bool two;

int main() {
  cin >> S;

  if(S[0] == S[S.length()-1]) one = true;
  if(S.length() % 2 == 0) two = true;

  if((one && two) || (!one && !two))cout << "First" <<endl;
  else cout << "Second" <<endl;
}
  
  


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N,M;
    cin >> N >> M;
    string A[N],B[M];
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<M;i++) cin >> B[i];

    for(int i=0;i<N-M+1;i++){
        for(int k=0;k<N-M+1;k++){
            int flg=0;
            for(int j=0;j<M;j++){
                if(A[i+j].substr(k,M) != B[j]) flg++;
            }
            if(flg == 0){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())
while(a >= b and k): # 緑をいじる
    b *= 2
    k -= 1
while(b >= c and k): # 青をいじる
    c *= 2
    k -= 1
print("Yes" if a<b<c else "No")

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

int main() {
  string s; cin >> s;
  int n = s.size();
  
  long long res = 0;
  for (int bit = 0; bit < (1<<(n-1)); bit++) {
    long long tmp = 0;
    for (int i = 0; i < n-1; i++) {
      tmp *= 10;
      tmp += s[i] - '0';
      if (bit & (1<<i)) {
        res += tmp;
        tmp = 0;
      }
    }
    tmp *= 10;
    tmp += s.back() - '0';
    res += tmp;
  }
  cout << res << endl;
}

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

int n, pos;
vector<int> pre, in, post;

void rec(int l,int r){
	if(l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l,m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve(){
	pos = 0;
	rec(0, pre.size());
	for(int i = 0; i < n; i++){
		if(i)cout << " ";
		cout << post[i];
	}
	
	cout << endl;
}


int main(){
	int k;
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> k;
		pre.push_back(k);
	}
	
	for(int i=0; i<n; i++){
		cin >> k;
		in.push_back(k);
	}
	
	solve();
	
	return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main(){
    ll A ,B ,N;
    cin >> A >> B >> N;
    ll x = min(B-1,N);
    cout << (A*x)/B << endl;
}


Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
#include<string>
#include<set>
#include<numeric>
#include<functional>
#include<unordered_map>
#include<cmath>
#include<cstdlib>
#include<cassert>
using namespace std;

int main() {
	string S;
	cin >> S;
	vector<bool> appear(26, false);
	bool ans = true;
	for (char c : S) {
		if (appear[c - 'a']) {
			ans = false;
			break;
		}
		appear[c - 'a'] = true;
	}
	if (ans)
		cout << "yes" << endl;
	else
		cout << "no" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

vector<int> input(int n)
{
	int i;
	vector<int> ret(n);
	for (i = 0; i < n; i++) {
		cin >> ret[i];
	}

	return ret;
}

int main(int argc, char *argv[])
{
	int n;
	int max, min;
	vector<int> array;
	cin >> n;

	array = input(n);

	max = *(max_element(array.begin(), array.end()));
	min = *(min_element(array.begin(), array.end()));

	cout << max - min << endl;
	
	return 0;
}


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

typedef long long ll;

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

  int n;
  cin >> n;

  vector<char> s(n);
  for (int i = 0; i < n; i++){
    cin >> s.at(i);
  }

  int i = 0, num = 0;
  while (i < n){
    if (i < n - 1 && s.at(i) == s.at(i + 1)){
      do {
        i++;
      } while (i < n - 1 && s.at(i) == s.at(i + 1));
    }
    num++;
    i++;
  }

  cout << num << endl;

  return 0;
}


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

int main() {
  int n;
  int num;
  string now, next;
  static string data[10] = {"0111111","0000110","1011011","1001111","1100110",
			    "1101101","1111101","0100111","1111111","1101111"};
  while(1) {
    cin >> n;
    if(n == -1) break;
    now = "0000000";
    for(int i = 0; i < n; i++) {
      cin >> num;
      for(int i = 0; i < 7; i++) {
	if(now[i] == data[num][i]) {
	  cout << "0";
	} else {
	  cout << "1";
	}
      }
      now = data[num];
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=[(a,c)];Y+=c,;X+=a
for i in r(m):a,*b=I();H+=[(a,b)];X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)
h,s,K=g(X);w,t,L=g(Y);j=lambda:[[0]*-~K for i in r(L+1)];V=j();U=j();v=j()
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]-=1
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]-=1
for i in r(L):
 for j in r(K):U[i][j+1]+=U[i][j];V[i+1][j]+=V[i][j]
q=[(h[0],w[0])];v[w[0]][h[0]]=1;a=0
while q:
 x,y=q.pop();a+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in[(-1,0),(1,0),(0,1),(0,-1)]:
  c=x+e;d=y+f
  if 1-v[d][c]and(U[(f>0)+y][x]|e==0)|(V[y][(e>0)+x]|f==0):q+=[(c,d)];v[d][c]=1
print([a,'INF'][a>F])

Measured memory_bytes: 551392
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <limits>
#include <cmath>
#include <numeric>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

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

long long lcm(long long a, long long b)
{
	return a * b / gcd(a, b);
}

int main() {
	long N;
	cin >> N;
	vector<long> A(N);
	for (long i = 0; i < N; ++i) cin >> A.at(i);
	long cur = 1;
	for (long i = 0; i < N; ++i) {
		if (A.at(i) == cur) {
			++cur;
		}
	}
	if (cur - 1 == 0) {
		cout << -1 << endl;
	}
	else {
		cout << N - (cur - 1) << endl;
	}
}

Measured memory_bytes: 1792
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

//============================================================================
int isprime(long x)
{
    long i,n;

    if (x==2)
        return 1;
    if (!(x & 1))
        return 0;
    if (x==1)
        return 0;
	n=sqrt(x);
    for (i=3; i<=n; i+=2){
        if (x == i)
            return 1;
        if (!(x % i))
            return 0;
    }
    return 1;
}
//============================================================================
int main(void)
{
    long i,n,sum; long *Array;

    scanf("%d", &n);
    Array=malloc(sizeof(long)*n);
    for (i=0; i<n; i++)
        scanf("%ld", &Array[i]);
    for (i=sum=0; i<n; i++){
        if (isprime(Array[i])){
            sum++;
            //printf("%d is prime!\n", Array[i]);
        }
    }
    free(Array);
    printf("%d\n", sum);
    return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int> a;
    a.push_back(0);
    for(int i=0; i<n; i++){
        int tmp =0; cin >> tmp;
        a.push_back(tmp);
    }
    a.push_back(0);
    int sum =0;
    for(int i=1; i<n+2; i++){
        sum += abs(a[i]-a[i-1]);
    }
    for(int i=1; i<=n; i++){
        int tmp =0;
        tmp = sum - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1]);
        cout << tmp << endl;
    }
    return 0;
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x; cin>>x;
    int n = 0, i = 0;
    while(n<x){
        i++;
        n+=i;
    }
    print(i);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

int main(){
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
    return 0;
}

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

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

int main(){
  ll n, m;
  cin >> n >> m;
  string s,t;
  cin >> s >> t;

  ll g = gcd(n,m);
  ll res = n / g * m;
  n /= g, m /= g;
  bool ok = true; 
  for (ll i = 0; i < g; i++) {
    if (s[i*n] != t[i*m]) ok = false;
  }
  if (ok) cout << res << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

VI table(100001, 0);
VB prime(100001, false);

bool check(auto a)
{
  if (a < 2) return false;
  else if (a == 2) return true;
  else if (a % 2 == 0) return false;
  double sqrt_a = sqrt(a);
  for (int i = 3; i <= sqrt_a; i += 2) if (a % i == 0) return false;
  return true;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int Q;
  cin >> Q;
  REP2(i, 1, 100001) prime[i] = check(i);
  REP2(i, 1, 100001)
  {
    if (i % 2 == 0)
    {
      table[i] = table[i-1];
      continue;
    }
    if (prime[i] && prime[(i+1)/2]) table[i] = table[i-1] + 1;
    else table[i] = table[i-1];
  }
  REP(query, Q)
  {
    int l, r;
    cin >> l >> r;
    cout << table[r] - table[l-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <chrono>
#include <iostream>
#include <vector>

using namespace std;
using namespace std::chrono;

const int MOD = 1e+9 + 7;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  sort(a.begin(), a.end());
  bool ok = true;
  int val = 1;
  int pos = 0;
  if (n & 1) {
    ok = a[pos++] == 0;
    ++val;
  }
  while (pos + 1 < n) {
    if (!(a[pos] == a[pos + 1] && a[pos] == val))
      ok = false;
    pos += 2;
    val += 2;
  }

  if (!ok) {
    cout << 0 << endl;
    return 0;
  }

  int ans = 1;
  for (int i = 0; i < n / 2; ++i) {
    ans <<= 1;
    if (ans >= MOD)
      ans -= MOD;
  }

  cout << ans << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define en '\n'
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);
const int gf = 1e6 + 9;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	string s;
	cin >> s;
	int k;
	cin >> k;
	set<string>st;
	int n = sz(s);

	zip(i, 0, n)
	{
		string y = "";
		zip(j, i, min(n, i + 5))
		{
			y += s[j];
			st.insert(y);
		}
	}
	int cnt = 0;
	string ans;
	for (string y : st)
	{
		cnt++;
		if (cnt == k)
		{
			ans = y;
			break;
		}
	}
	cout << ans << en;



	return 0;
}




Measured memory_bytes: 4776
import sys
from collections import deque
K = int(input())

visited = [0 for i in range(K)]
q = deque([(1,1)])
while q:
    now,cost = q.popleft()
    if now == 0:
        print(cost)
        sys.exit()
    visited[now] = 1
    v0 = (now*10) % K
    v1 = (now+1) % K
    if not visited[v0]: q.appendleft((v0, cost))
    if not visited[v1]: q.append((v1, cost+1))


Measured memory_bytes: 10996
import java.math.BigInteger;
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigInteger A = new BigInteger(sc.next());
        BigInteger B = new BigInteger(sc.next());
        sc.close();

        BigInteger C = new BigInteger("10");
        if (A.compareTo(C)==-1 && B.compareTo(C)==-1) {
            System.out.println(A.multiply(B));
        } else {
            System.out.println("-1");
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <iomanip>
#include<cmath>
#include<stdio.h>
#include<map>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
#define please return
constexpr auto AC = 0;
using namespace std;
int main() {
	int a, b;
	int ans = 0;
	cin >> a >> b;
	for (;; ans++) {
		if (a <= 0)break;
		a -= b;
	}
	cout << ans << endl;
	please AC;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define int long long
signed main(void){
    int k,a,b; cin>>k>>a>>b;
    int ans = 0;
    //叩きまくる
    ans = k+1;
  
    //cout<<ans<<endl;
    //aまいにする
    k-=(a-1); //cout<<k<<endl;
    if(k%2==1) {k--; chmax(ans, a+1+ k/2*(b-a));}
    else chmax(ans, a+ k/2*(b-a));
    
    cout<<ans<<endl;
}


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

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

ll a, b, c, d;

ll gcd(ll m, ll n) {
  if (n == 0) return m;
  else return gcd(n, m % n);
}

ll lcm(ll m, ll n) {
  return m * n / gcd(m, n);
}

ll solve() {
  a--;
  ll res = b - a;
  res -= b / c - a / c;
  res -= b / d - a / d;
  ll t = lcm(c, d);
  res += b / t - a / t;
  return res;
}

int main() {
  cin >> a >> b >> c >> d;
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N+1);
  rep(i,N)cin >> v[i+1];
  v[0] = -1;
  bool sat = true;
  rep(i,N) if(v[i]+1 < v[i+1]) sat = false;
  ll ans = 0;
  repp(i,1,N+1){
    if(v[i] == 0)continue;
    if(v[i] - v[i-1] == 1)++ans;
    else ans += (ll)v[i];
  }

  if(sat) cout << ans << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n=int(input())
    run=[0]*n
    for i in range(n):
        A=tuple(map(int,input().split()))
        a=0
        for d in range(10):
            a+=A[d]<<d
        run[i]=a
    profit=[tuple(map(int,input().split())) for _ in range(n)]
    ans=-INF
    for i in range(1,1<<10):
        score=0
        for j in range(n):
            score+=profit[j][bin(run[j]&i).count('1')]
        ans=max(ans,score)
    print(ans)
resolve()

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

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
    int N;
    ll count = 0;
    int j = 1;
    IN(N);
    vector<string> s(N);
    REP(i, N) {
        IN(s[i]);
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());
    REP(i, N - 1) {
        if(s[i] == s[i + 1]) {
            count += j;
            j++;
        }
        else {
            j = 1;
        }
    }
    OUT(count);
}

Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

using P=pair<int,int>;
void solve(){
  int n,m;
  cin>>n>>m;
  vector<int>a(n),b(m);
  rep(i,n)cin>>a[i];
  rep(i,m)cin>>b[i];
  vector<P>pos(n*m+5,P{-1,-1});//i行j列について値が決まっているかどうか
  bool ng=false;
  ll ans=1;
  rep(i,n){
    a[i]--;
    if(pos[a[i]].first==-1)pos[a[i]].first=i;
    else ng=true;//2回目はありえない
  }
  rep(i,m){
    b[i]--;
    if(pos[b[i]].second==-1)pos[b[i]].second=i;
    else ng=true;//2回目はありえない
  }
  ll bigger_r=0,bigger_c=0;//行,列について自分より大きいものが既に埋まっている数
  vector<bool>used_r(n),used_c(m);
  for(ll i=n*m-1;i>=0;--i){
    if(pos[i].first!=-1&&!used_r[pos[i].first]){
        used_r[pos[i].first]=true;
        ++bigger_r;
      }
    if(pos[i].second!=-1&&!used_c[pos[i].second]){
        used_c[pos[i].second]=true;
        ++bigger_c;
      }
    if(pos[i].first!=-1&&pos[i].second!=-1){//一意に定まるマス
    }
    else if(pos[i].first==-1&&pos[i].second==-1){//列と行が決まっていない
      ll cul=bigger_c*bigger_r;
      cul-=(n*m-1)-i;
      ans*=cul;
      ans%=mod;
    }
    else if(pos[i].first==-1){//行だけ決まっていない
      ans*=bigger_r;
      ans%=mod;
    }
    else{//列だけ決まっていない
      ans*=bigger_c;
      ans%=mod;
    }
  }
  if(ng)cout<<0;
  else{
    cout<<ans;
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

Measured memory_bytes: 8064
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];
    writeln(N == 1 && M == 1 ? 1 : N == 1 ? M-2 : M == 1 ? N-2 : (N-2) * (M-2));
}

Measured memory_bytes: 256
def main():
    n = int(input())
    while True:
        try:
            num_list = [int(i) for i in input().split()]
            num_list = sorted(num_list)
            a,b,c = num_list[0],num_list[1],num_list[2]
            if (a**2 + b**2) == c**2:
                print("YES")
            else:
                print("NO")
        except EOFError:
            break
    return None

if __name__ == '__main__':
    main()

Measured memory_bytes: 7564
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n , t=0 , mx ;
    cin>>n;
    string s;
    cin>>s;
    mx=t;
    for (int i=0 ; i<n ; ++i)
    {
        if (s[i]=='I')
        {
            t+=1;
            if (t>mx)
            {
                mx=t;
            }
        }
        else
        {
            t-=1;
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 3628
/*Lucky_Glass*/
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	printf("%d\n",min(b,a*n));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#define PATT 4
#define RANK 13
using namespace std;

int main()
{
    bool cards[PATT][RANK] = {};
    int n;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        char ch;
        int num;
        
        cin >> ch >> num;
        switch (ch) {
            case 'S': cards[0][num - 1] = true; break;
            case 'H': cards[1][num - 1] = true; break;
            case 'C': cards[2][num - 1] = true; break;
            case 'D': cards[3][num - 1] = true; break;
        }
    }
    
    for (int i = 0; i < PATT; i++)
        for (int j = 0; j < RANK; j++)
            if (cards[i][j] == false) {
                switch (i) {
                    case 0: cout << "S "; break;
                    case 1: cout << "H "; break;
                    case 2: cout << "C "; break;
                    case 3: cout << "D "; break;
                }
                cout << j + 1 << endl;
            }
}


Measured memory_bytes: 3068
#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("Balanced\n");
    }
    else if(a+b<c+d)
    {
        printf("Right\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    ll k,a,b;
    cin >> k >> a >> b;
    if(a>=b-2||(k-a+1)/2<1){
        cout<<1+k<<endl;
    }else{
        ll cnt = (k-a+1)/2;
        ll add = (k-a+1)%2;
        cout<< a+cnt*(b-a)+add<<endl;
    }
    


    return 0;
}

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

using namespace std;

int main(){
    int n, m; cin >> n >> m;
    int k[10], s[10][10], p[10];
    
    for(int i = 0; i < m; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j];
        }
    }
    
    for(int i = 0; i < m; i++){
        cin >> p[i];
    }
    
    int max = 1;
    for(int i = 0; i < n; i++){
        max *= 2;
    }
    
    int ans = 0;
    
    for(int i = 0; i < max; i++){
        for(int j = 0; j < m; j++){
            int count = 0;
            for(int jj = 0; jj < k[j]; jj++){
                if( (i >> s[j][jj] - 1) & 0x01 == 1 ) count ++;
            }
            
            if(count % 2 != p[j]){
                break;
            }else if(j == m - 1){
                ans ++;
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define true 1
#define false 0
#define N 100
int judge(char *,char *,int kei);
    int main()
{
  int kei,i,j,k[N],g[N],t,m,mini,minim,r,h,w;
  char s,a[N],n[N];
  scanf("%d",&kei);
  for(i=0;i<kei;i++){
    scanf(" %c%d",&a[i],&k[i]);
  }
  for(i=0;i<kei;i++)
    {
    n[i]=a[i];
    g[i]=k[i];
  }
  for(i=0;i<kei;i++)
    {
    for(j=kei-1;j>i;--j){
      if(k[j]<k[j-1]){
	m=a[j-1];
	t=k[j-1];
	a[j-1]=a[j];
	k[j-1]=k[j];
	a[j]=m;
	k[j]=t;
	
      }
    }
  }
  
  for(i=0;i<kei-1;i++)
    {
    mini=g[i];
    minim=n[i];
    r=i;
    for(j=i+1;j<kei;j++)
      {
	if(g[j]<mini)
	  {
      mini=g[j];
    minim=n[j];
    r=j;
	}
      }
      if(i != r){
	h=g[i];
	w=n[i];
	g[i]=g[r];
	n[i]=n[r];
	g[r]=h;
	n[r]=w;
      }
    }
  
  for(i=0;i<kei;++i){
    if(i>0)printf(" ");
    printf("%c%d",a[i],k[i]);
  }
  printf("\n");
  printf("Stable\n");
  for(i=0;i<kei;++i)
    {
    if(i>0)printf(" ");
    printf("%c%d",n[i],g[i]);
  }
  printf("\n");
  if(judge(a,n,kei)==1)printf("Stable\n");
  else printf("Not stable\n");
    return 0;
}

int judge(char x[],char y[],int kei)
{
  int i;
  for(i=0;i<kei;i++)
    {
      if(x[i] != y[i])return false;
    }
  return true;
}
  



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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int e=a*b;
  int f=c*d;
  if(e>f){
  	cout<<e<<endl;
  }else{
  	cout<<f<<endl;
  }
}

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

using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
const ll inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);




int main() {
	string s;
	cin >> s;
	int n = s.size();
	vii nex(n, vi(26));
	vi last(26, n);
	rrep(i, n) {
		rep(j, 26) {
			nex[i][j] = last[j];
		}
		last[s[i] - 'a'] = i;
	}
	vi dp(n + 1, inf);
	dp[n] = 0;
	rrep(i, n) {
		rep(j, 26) {
			chmin(dp[i], dp[nex[i][j]] + 1);
		}
	}
	int len = inf;
	int i;
	rep(j, 26) {
		if (len > dp[last[j]]) {
			len = dp[last[j]];
			i = last[j];
		}
		if (last[j] == n) {
			cout << (char)('a' + j) << endl;
			return 0;
		}
	}
	cout << s[i];
	while (i < n) {
		rep(j, 26) {
			if (dp[nex[i][j]] == dp[i] - 1) {
				cout << (char)('a' + j);
				i = nex[i][j];
				break;
			}
		}
	}
	cout << endl;
}

Measured memory_bytes: 27780