akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

            if(B/K*K>=A){
                System.out.println("OK");
            }else{
                System.out.println("NG");
            }         
	}
}


Measured memory_bytes: 35600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    set<char> se;
    rep(i,n){
        char a;
        cin >> a;
        se.insert(a);
    }
    if(se.size()==4){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }
}

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

int main() {

    ll n , t ,q  , j , k ;

    string s ;

    cin >> n ;
    ll ans = 0 ;


    for(ll i=1;i<=n;i++) {
        for(j=1;j<=n;j++) {
            for(k=1;k<=n;k++) {
                ans+= __gcd(__gcd(i,j),k) ;
            }
        }
    }
    cout << ans << endl ;

    return 0 ;
}


Measured memory_bytes: 3628
n,k = map(int,input().split())
v = list(map(int,input().split()))
ans = 0
for i in range(min(n+1,k+1)):
    for j in range(min(n+1-i,k+1-i)):
        g = []
        x = 0
        while x < i:
            g.append(v[x])
            x += 1
        y = 0
        z = -1
        while y < j:
            g.append(v[z])
            y += 1
            z -= 1
        g.sort()
        x = k - i - j
        for z in range(min(len(g),x)):
            if g[z] < 0:
                g[z] = 0
            else:
                break
        ans = max(ans,sum(g))
print(ans)

Measured memory_bytes: 9188
S = gets.chomp
T = gets.chomp
sl = S.size
tl = T.size

if sl < tl
	puts "UNRESTORABLE"
	exit
end

x = []
(sl-tl+1).times{|i|
	str = S.dup
	sbs = str[i,tl]
	if (0...tl).all?{|j|sbs[j] == T[j] || sbs[j] == '?'}
		str[i,tl] = T
		x << str.gsub('?', 'a')
	end
}
puts x.empty? ? "UNRESTORABLE" : x.sort[0]

Measured memory_bytes: 1788
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

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

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

const int N=201;

class FordFulkerson{
  public:
  int source,sink,n;
  int cap[201][201];
  bool seen[201];
  int dfs(int u,int flow){
    seen[u]=1;
    if(u==sink){
      return flow;
    }
    for(int i=0;i<n;i++){
      if(cap[u][i]>0&&seen[i]==0){
	int val=dfs(i,min(flow,cap[u][i]));
	if(val){
	  cap[u][i]-=val;
	  cap[i][u]+=val;
	  return val;
	}
      }
    }
    return 0;
  }

  void addEdge(int u,int v,int w){
    cap[u][v]+=w;
  }

  void run(){
    int fl=1;
    int total=0;
    while(fl){
      memset(seen,0,sizeof(seen));
      fl=dfs(source,1e9);
      total+=fl;
    }
    cout<<total<<"\n";
  }
  
};

void solve(){
  FordFulkerson ff;
  cin>>ff.n;
  ff.source=0;ff.sink=ff.n-1;
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    int x,y,w;
    cin>>x>>y>>w;
    ff.addEdge(x,y,w);
  }
  ff.run();
  
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}



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

#define N 1000003

void insert(char *);
void find(char *);
int hash1(int);
int hash2(int);
int hash(char *, int);

int im;
char dict[N][13];

int main()
{
  int n, i;
  char str[13];
  
  scanf("%d", &n);
  for(i=0; i<N; i++)
    {
      strcpy(dict[i], "\0");
    }

  for(i=0; i<n; i++)
    {
      scanf("%s", str);
      
      if(strcmp(str, "insert") == 0)
	{
	  scanf("%s", str);
	  insert(str);
	}
      else if(strcmp(str, "find") == 0)
	{
	  scanf("%s", str);
	  find(str);
	}
    }
  return 0;
}

void insert(char *str)
{
  int i=0;

  while(strcmp(dict[hash(str, i)], "\0") != 0)
    {
      i++;
    }
  strcpy(dict[hash(str, i)], str);
  im = i;
  //printf("%d\n", hash(str, i));
}
void find(char *str)
{
  int i=0;

  while(1)
    {
      if(strcmp(dict[hash(str, i)], "\0") == 0)
	{
	  printf("no\n");
	  break;
	}
      else if(strcmp(dict[hash(str, i)], str) == 0)
	{
	  printf("yes\n");
	  break;
	}
      i++;
    }
}
int hash1(int k)
{
  return k % N;
}
int hash2(int k)
{
  return 1 + k%(N-1);
}
int hash(char *str, int i)
{
  int j, k=0, n=1;
  for(j=0; str[j]!='\0'; j++)
    {
      if(str[j] == 'A')
	{
	  k += n*0;
	}
      else if(str[j] == 'C')
	{
	  k += n*1;
	}
      else if(str[j] == 'G')
	{
	  k += n*2;
	}
      else if(str[j] == 'T')
	{
	  k += n*3;
	}
      n *= 4;
    }
  //printf("%d\n", k);
  
  return (hash1(k) + i*hash2(k))%N;
}

Measured memory_bytes: 13296
#include <iostream>
using namespace std;
 
int main() {
    int N;
    long double x[4],y[4];
    cin>>N;
    while(N--){
        for(int i=0;i<4;i++) cin>>x[i]>>y[i];
        long double y1=y[1]-y[0]; long double x1=x[1]-x[0];
        long double y2=y[3]-y[2]; long double x2=x[3]-x[2];
        if(y1*x2==y2*x1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n;
    cin >> n;
    int p[n];
    rep(i, n) cin >> p[i];
    int ans = 0;
    int mn = 1000000;
    rep(i, n){
        if (mn >= p[i]){
            mn = p[i];
            ans++;
        }
    }
    cout << ans << endl;
}

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

if N < 105:
    print(0)
else:
    ans = 1
    for i in range(107, N+1, 1):
        count = 0
        if i % 2 ==0:
            continue
        for j in range(3, i, 2):
            if i % j == 0:
                count += 1
            if count > 6:
                break
        if count == 6:
            ans += 1
    print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
  int n;
  cin >> n;
  double ans = 0.0;
  while (n--) {
    int a;
    cin >> a;
    ans += 1. / a;
  }
  cout << fixed << setprecision(10) << 1. / ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer a = scanner.nextInt();
        Integer b = scanner.nextInt();
        Integer c = scanner.nextInt();
        System.out.println(Math.max(c-(a-b),0));
    }
}


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

int main(void){
  int N;
  cin >> N;
  vector<int> Q(N);
  int min = N;
  int count = 0;
  for (int i = 0; i < N; i++){
   	cin >> Q[i];
    if(Q[i] <= min){
      min = Q[i];
      count++;
    }
  }
  
  cout << count << endl;
 return 0; 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a>0) cout<<"Positive"<<endl;
    else if(b>0) cout<<"Zero"<<endl;
    else if((a-b+1)%2==0) cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
}


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



int main()
{
	int n;
	int d[100][100];
	cin >> n;
	for(int i = 0; i< n; i++)
		for (int j = 0; j < n; j++)
			cin >> d[i][j];

	int sl = -100000;
	for (int p = 0; p < n; p++)
	{
		for (int q = 0; q <= p; q++)
		{
			vector<int> a = vector<int>(100, 0);
			for (int r = q; r <= p; r++)
			{
				for (int t = 0; t < n; t++)
				{
					a[t] += d[r][t];
				}
			}


			vector<int> s = vector<int>(1, 0);
			bool f = true;
			bool plus = false;
			for (int i = 0; i < n; i++)
			{
				if (a[i] >= 0)
				{
					if (!f)
						f = true;
					if (!plus)
						plus = true;
					s[0] += a[i];
				}
				else if (s[0] > abs(a[i]))
				{
					if (f)
					{
						s.push_back(s[0]);
						f = false;
					}
					s[0] += a[i];
				}
				else
				{
					s[0] = 0;
				}

			}
			if (!plus)
			{
				int max = a[0];
				for (int i = 1; i < n; i++)
				{
					if (max < a[i])
						max = a[i];
				}
				if (sl < max)
					sl = max;
				continue;
			}
			for (int i = 1; i < s.size(); i++)
			{
				if (s[i] > s[0])
					s[0] = s[i];
			}
			if (sl < s[0])
				sl = s[0];
		}
	}
	cout << sl << endl;

	return 0;
}

Measured memory_bytes: 3192
n = gets.to_i
v = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

arr = []

v.each_with_index do |a,idx|
  num = a - c[idx]
  arr << num
end

max = 0

arr.each do |a|
  if a > 0
    max += a
  end
end

p max

Measured memory_bytes: 1788
#include <stdio.h>

void function(int a[][2],int *n);

int main(){
	
	int n,x;
	int a[100][2];
	
	int t;
	for(t=0;t<100;t++){
		do{
			printf("");
			scanf("%d %d",&n,&x);
		}while( !( (n>=3 && n<=100) || (n==0 && x==0) ) );
		if(n==0 && x==0)break;
		a[t][0]=n;
		a[t][1]=x;
	}
	
	
	function(a,&t);
	
	return 0;
}

void function(int a[][2],int *n){
	int s,t,u;
	int d;
	
	
	for(d=0;d<*n;d++){
		int c=0;
		for(s=1;s<=a[d][0]-2;s++){
			for(t=s+1;t<=a[d][0]-1;t++){
				for(u=t+1;u<=a[d][0];u++){
					if(s+t+u==a[d][1])c++;
				}
			}
		}
		printf("%d\n",c);
	}
	
	
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

#define N	100*1000+5
int pre[N], suf[N];
vi v;
void solve(){
	int n;
	cin>>n;
	v.pb(0);
	rep(i,0,n){
		int t;
		cin>>t;
		v.pb(t);
	}
	v.pb(0);
	rep(i,1,n+1){
		pre[i] = pre[i-1] + abs(v[i]-v[i-1]);
		suf[n+1-i] = suf[n+2-i] + abs(v[n+1-i]-v[n+2-i]);
	}
	rep(i,1,n+1)
		cout<<pre[i-1]+suf[i+1]+abs(v[i+1]-v[i-1])<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
     t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 2552
#include <stdio.h>

int main(void)
{
    int x, y;
    char op;
    while (1) {
        scanf("%d %c %d", &x, &op, &y);
        if (op == '?') {
            break;
        } else if (op == '+') {
            printf("%d\n", x + y);
        } else if (op == '-') {
            printf("%d\n", x - y);
        } else if (op == '*') {
            printf("%d\n", x * y);
        } else if (op == '/') {
            printf("%d\n", x / y);
        }
    }
    return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui H{}, W{}; std::cin >> H >> W;
  ui h{}, w{}; std::cin >> h >> w;

  cout << (H - h) * (W - w) << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

using ll = long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n) for(ll i=0;i<(n);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//static const ll MOD = 1000000007;
//static const ll INF = 1000000000000000000;
//#define PI 3.14159265359

int main() {
    // input
    ll N;
    cin >> N;
    Vec A(N), B(N);
    rep(i, N) {
        cin >> A[i] >> B[i];
    }

    //process
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    ll ans = 0;
    if (N % 2 == 0) {
        ll center = N / 2 - 1;
        double center_A = (double) (A[center] + A[center + 1]) / 2;
        double center_B = (double) (B[center] + B[center + 1]) / 2;
        ans = (center_B - center_A + 0.5) * 2;
    } else {
        ll center = N / 2;
        ans = B[center] - A[center] + 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int n, d, x; cin >> n >> d >> x;
    int choco = x;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        int j = 0;
        while (j * a + 1 <= d) {
            choco++;
            j++;
        }
    }
    cout << choco << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val c = new Array[String](2*N + 1)
  val a = new Array[Int](2*N + 1)

  for(i <- 1 to 2*N) {
    val x, y = in.next()
    c(i) = x; a(i) = y.toInt
  }


  //
  val wi = new Array[Int](N+1)
  val bi = new Array[Int](N+1)

  for(i <- 1 to 2*N) {
    if(c(i) == "W")
      wi(a(i)) = i
    else
      bi(a(i)) = i
  }


  val memow = Array.ofDim[Int](N+1, 2*N+1)
  val memob = Array.ofDim[Int](N+1, 2*N+1)

  for(i <- 1 to N) {
    memow(i)(wi(i)) += 1
    if(i == 1) {
      for(k <- 2 to 2*N)
        memow(i)(k) += memow(i)(k-1)
    }
    else {
      for(k <- 2 to 2*N)
        memow(i)(k) += memow(i)(k-1)
      for(k <- 1 to 2*N)
        memow(i)(k) += memow(i-1)(k)
    }
  }


  for(i <- 1 to N) {
    memob(i)(bi(i)) += 1
    if(i == 1) {
      for(k <- 2 to 2*N)
        memob(i)(k) += memob(i)(k-1)
    }
    else {
      for(k <- 2 to 2*N)
        memob(i)(k) += memob(i)(k-1)
      for(k <- 1 to 2*N)
        memob(i)(k) += memob(i-1)(k)
    }
  }


  val dp = Array.ofDim[Int](N+1, N+1)

  dp(0)(0) = 0

  for(x <- 1 to N) {
    val now = (bi(x) - 1) - (memob(x-1)(bi(x) - 1))
    dp(0)(x) = dp(0)(x-1) + now
  }

  for(y <- 1 to N) {
    val now = (wi(y) - 1) - (memow(y-1)(wi(y) - 1))
    dp(y)(0) = dp(y-1)(0) + now
  }

  for(y <- 1 to N; x <- 1 to N) {
    val a = dp(y)(x-1) + (bi(x) - 1) - (memob(x-1)(bi(x)-1)) - (memow(y)(bi(x)-1))
    val b = dp(y-1)(x) + (wi(y) - 1) - (memow(y-1)(wi(y)-1)) - (memob(x)(wi(y)-1))

    dp(y)(x) = Math.min(a, b)
  }

  // dp.foreach{ x => println(x.deep) }
  println(dp(N)(N))
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 154976
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e12;
const ll inf=1e18;
const ll ms=10000000;
fast;
ll n,m,ans;
void solve()
{
    cin>>n>>m;
    cout<<n*m/__gcd(n,m)<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	string s, t;
	cin >> s >> t;

	if (s == t.substr(0, sz(t) - 1)) {
		out("Yes");
	}
	else {
		out("No");
	}

	return 0;
}

Measured memory_bytes: 3656
seta = set([1,3,5,7,8,10,12])
setb = set([4,6,9,11])
setc = set([2])
 
a,b = map(int, input().split())
 
if (a in seta and b in seta) or (a in setb and b in setb) or (a in setc and b in setc):
  print('Yes')
else:
  print('No')

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

int main()
{
    long long int a , b , temp=-1;
    scanf("%lld%lld",&a,&b);
    if(a<b)
      swap(a,b);
    while((a%b)!=0)
    {
        temp=a%b;
        a=b;
        b=temp;
    }
    if(temp!=(-1))
      printf("%lld\n",temp);
    else if(a%b==0)
      printf("%lld\n",b);
    return 0;
}



Measured memory_bytes: 3236
def main():
    n ,m = map(int, input().split(' '))
    inf = 10**9
    bit_dp = [inf for _ in range(2**(n))]
    bit_dp[0] = 0
    for i in range(m):
        a, b = map(int, input().split(' '))
        c = list(map(int, input().split(' ')))
        bit_n = 0
        for i in c:
            bit_n |= 1 << i-1
        for i in range(2**(n)):
            bit_dp[i|bit_n] = min(bit_dp[i|bit_n], bit_dp[i] + a)
    if bit_dp[-1] >= inf:
        print(-1)
    else:
        print(bit_dp[-1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define int long long
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	/*cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);*/

	bool flag = false;
	cout << "? " << 1000000000 << endl;
	char c;
	cin >> c;
	if (c == 'Y') flag = true;
	if (flag) {
		int check = 999999999;
		while (true) {
			cout << "? " << check << endl;
			char d;
			cin >> d;
			if (d == 'N') {
				cout << "! " << check + 1 << endl;
				return 0;
			}
			else if (d == 'Y'&&check == 9) {
				cout << "! " << 1 << endl;
				return 0;
			}
			check /= 10;
		}
	}
	else {
		int dig = 9;
		int check = 100000000;
		while (true) {
			cout << "? " << check << endl;
			char d;
			cin >> d;
			if (d == 'Y') break;
			else dig--;
			check /= 10;
		}
		int ok = 1;
		rep(_, dig - 1) ok *= 10;
		int ng = ok * 10;
		while (ng - ok > 1) {
			int mid = (ok + ng) / 2;
			cout << "? " << mid * 10 << endl;
			char d;
			cin >> d;
			if (d == 'N') ok = mid;
			else ng = mid;
		}
		cout << "! " << ng << endl;
	}
}

Measured memory_bytes: 596
function bomb(){
   var obj={};
   var min=-1;
   var start=[];
   yx.forEach(function(v,i){
      v.forEach(function(value,j){
         if(value==2)start=[i,j];
      });
   });
   var ary=[[start,6,0]];
   while(true){
      if(ary.length==0)break;
      var v=ary.shift();
      var y=v[0][0];
      var x=v[0][1];
      var power=v[1];
      var cnt=v[2];
      if(obj.hasOwnProperty(y+","+x+","+power))continue;
      obj[y+","+x+","+power]=true; 
      if(yx[y][x]==3){
         min=cnt;
         break;
      }
      if(power==1)continue;
      var dy=[-1,0,0,1];
      var dx=[0,-1,1,0];
      for(var i=0;i<4;i++){
         var Y=y+dy[i];
         var X=x+dx[i];
         if(Y<0 || X<0 || Y>=h || X>=w || yx[Y][X]==0)continue;
         if(yx[Y][X]==1 || yx[Y][X]==3)ary.push([[Y,X],power-1,cnt+1]);
         else if(yx[Y][X]==4)ary.push([[Y,X],6,cnt+1]);
     }   
   }
   return min;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var wh=arr.shift().split(" ").map(Number);
   if(wh.join(" ")=="0 0")break;
   var w=wh[0];
   var h=wh[1];
   var yx=[];
   for(var i=0;i<h;i++)yx.push(arr.shift().split(" ").map(Number));
   console.log(bomb());
}

Measured memory_bytes: 17816
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

int n,k,c;
string s;
vector<int> p;
int co[200005];

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

  cin >> s;

  for(int i = 0; i < n; i++) {
    if(s[i] == 'o') p.push_back(i + 1);
  }

  

  int l = 0, r = p.size() - 1;
  int tmp = k;
  int x = -200005;
  while(l < p.size() && tmp > 0) {
    if(p[l] > x + c) {
      x = p[l];
      tmp--;
      co[x]++;
    }
    l++;
  }
  x = 400005;
  tmp = k;
  while(r >= 0 && tmp > 0) {
    if(p[r] < x - c) {
      x = p[r];
      tmp--;
      co[x]++;
    }
    r--;
  }
  //   cout << l <<"   "<<r << endl;
  int mo = 0;
  int i = 0;
  x = -200005;
  while(i <= r) {
    if(p[i] > x + c) {
      x = p[i];
      mo++;
    }
    i++;
  }
 
  i = l;
  while(i < p.size()) {
    if(p[i] > x + c) {
      x = p[i];
      mo++;
    }
    i++;
  }
  // cout << mo << endl;

  vector<int> ans;
  for(int i = 0; i < 200005; i++) if(co[i] == 2) ans.push_back(i);

  if(ans.size() + mo <= k) {
    for(int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
  }
  else return 0;

  
  
}
  


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

int n;
int memo[45][100000], used[45][100000];
int solve(int d, int m){
	if(d == 0 && m == 0)return 1;
	if(memo[d][m])return memo[d][m];
	if(used[d][m])return memo[d][m] = 2;
	used[d][m] = 1;
	
	int res = 2;
	for(int i = 0;i < 10;i++)if(d-i >= 0){
		res = solve(d-i, (m*10+i)%n);
		if(res == 1)break;
	}
	return memo[d][m] = res;
}

int main(){
	scanf("%d", &n);
	int lim = 0, m = n;
	while(0 < m){
		lim += m%10;
		m /= 10;
	}
	for(int ans = 1;ans < lim;ans++){
		int res = solve(ans, 0);
		if(res == 1){
			printf("%d\n", ans);
			return 0;
		}
	}
	printf("%d\n", lim);
	return 0;
}

Measured memory_bytes: 35072
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct Permutation {
  vector<mint> fact, ifact;
  Permutation(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[n-k];
  }
} p(100005);

vector<int> g[100005];
int n,k;
mint dfs(int u = 0, int pv = -1){
  if(g[u].size()>k) return 0;

  int ni = k - 1;
  if(pv != -1) --ni;
  int ki = g[u].size();
  if(pv != -1) --ki;

  mint res = p(ni,ki);
  for(int v:g[u]){
    if(v != pv) res *= dfs(v,u);
  }
  if(u==0) res *= k;
  return res;
}
int main() {
  cin >> n >> k;
  rep(i,n-1){
    int u,v;
    cin >> u >> v;
    --u; --v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  cout << dfs() << endl;
}


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


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

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


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll n, k;
	cin >>n >>k;
	
	if(k==0){cout <<n*n <<"\n"; return 0;}
	ll ans = 0;
	rep2(i, k+1, n+1){
		ans += n / i * (i-k);
		if(n%i >=k) ans += n%i +1 -k;
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int

def solve(N: int, A: int, B: int, K: int):
    N_max = 3*10**5
# 元テーブル
    g1 = [1, 1]
# 逆元テーブル
    g2 = [1, 1]
# 逆元テーブル計算用テーブル
    inv = [0, 1]

    for i in range(2, N_max+1):
        g1.append((g1[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD//i)) % MOD)
        g2.append((g2[-1] * inv[-1]) % MOD)

    ans = 0
    for x in range(N+1):
        if (K-A*x)%B==0:
            y = (K-A*x)//B
            if y<0 or y>N:
                continue
            ans += g1[N]*g2[x]*g2[N-x] * g1[N]*g2[y]*g2[N-y]
            ans %= MOD
    print(ans)

    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, A, B, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39088
#include <stdio.h>
#include <math.h>
struct person{
    double ban;
    double h;
    double w;
    double bmi;
};
typedef struct person P ;
int main(){
    while (1) {
        int n,i,memo;
        double result;
        scanf("%d",&n);
        if(n==0)break;
        P data[n+1];
        for(i=0;i<n;i++){
            scanf("%lf %lf %lf",&data[i].ban,&data[i].h,&data[i].w);
            data[i].bmi=data[i].w/((data[i].h/100)*(data[i].h/100));
            if(i==0){
                result=fabs(data[i].bmi-22);
                memo=data[i].ban;
            }
            if(result>fabs(data[i].bmi-22)){
                result=fabs(data[i].bmi-22);
                memo=data[i].ban;
            }else if(result==fabs(data[i].bmi-22)){
                if(memo>data[i].ban)memo=data[i].ban;
            }
        }
        printf("%d\n",memo);
    }
    return 0;
}

Measured memory_bytes: 664
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;

int ans;
signed main(){

    string s;
    cin>>s;
    int co=0;
    rep(i,s.size()){
        if(s[i]=='o')co++;
    }
    if(co+15-s.size()>=8)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int X,max=0;
    scanf("%d",&X);
    while(X>=5){
        if(X>=500){
            X-=500;
            max+=1000;
        }else{
            X-=5;
            max+=5;
        }
    }
    printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define LL long long
#define R register
int n,k,ans,p;
int map[12][6]={
    {4,2,0,9,7},
    {1,10,8,6,4},
    {9,7,5,3,1},
    {6,4,2,0,9},
    {3,1,10,8,6},
    {0,9,7,5,3},
    {8,6,4,2,0},
    {5,3,1,10,8},
    {2,0,9,7,5},
    {10,8,6,4,2},
    {7,5,3,1,10}};
int main()
{
    scanf("%d%d",&n,&k);
	n-=2;
    p=n%11;
	n/=11;
    ans=n*5;
    for(int i=0;i<p;i++)
    	for(int j=0;j<5;j++)
    		if(map[i][j]==k)ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

map<PII, int> mp;
void solve(int h, int w) {
    int n = h * h + w * w;
    pair<PII, int> ans = MP(MP(INF, INF), INF);
    FORE(el, mp) {
        if (MP(h, w) == el.first) continue;
        if (n > el.second) continue;
        if (n == el.second && h >= el.first.first) continue;
        if (el.second < ans.second) {
            ans = el;
        } else if (el.second == ans.second && ans.first.first > el.first.first) {
            ans = el;
        }
    }

    cout << ans.first.first << " " << ans.first.second << endl;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    REP(h, 150) FOR(w, h + 1, 150) {
        mp[MP(h + 1, w + 1)] = pow(h + 1, 2) + pow(w + 1, 2);
    }
    while (cin >> n >> m, n && m) {
        solve(n, m);
        //return 0;
    }
}

Measured memory_bytes: 3768
import bisect
import sys
readline = sys.stdin.buffer.readline


def main():
    n = int(readline())
    a = list(map(int,readline().rsplit()))
    b = list(map(int,readline().rsplit()))
    c = list(map(int,readline().rsplit()))
    a.sort()
    c.sort()
    ans = 0
    for i in b:
        d = bisect.bisect_left(a, i)
        e = len(c) - bisect.bisect_right(c, i)
        ans += d * e
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 71516
use std::io;
use std::io::Read;

fn main() {
    loop {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();

        let H: i32 = iter.next().unwrap().parse().unwrap();
        let W: i32 = iter.next().unwrap().parse().unwrap();

        if H == 0 && W == 0 {
            break;
        }

        for i in 0..H {
            for j in 0..W {
                if (i + j) % 2 == 0 {
                    print!("#");
                } else {
                    print!(".");
                }
            }
            println!("");
        }
        println!("");
    }
}


Measured memory_bytes: 5028
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}

using namespace std;
#pragma endregion
signed main() {
	int N,r=0,b=0;
	string s;
	cin >> N >> s;
	rep(i, N) {
		if (s[i] == 'R')
			r ++;
		else
			b++;
	}
	if (r > b)
		cout << "Yes" << endl;
	else
		cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
const double PI = 3.14159265358979323846;
const ll MOD = 1000000007;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
    int n, k;
	cin >> n >> k;
    ll ans = 0;

    FOR(i, k, n+2){
        //ans += (i*n -i*(i-1) + 1) % MOD;
        ans = (ans + i*n -i*(i-1) + 1) % MOD;
        //cout << ans << endl;
    }
    cout << ans << endl;
}


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

int main() {
    int h, w, m;
    cin >> h >> w >> m;
    set<pair<int, int>> s;
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        s.insert({a, b});
    }
    int mxH = 0, mxW = 0;
    map<int, int> mph, mpw;
    for(auto [u, v] : s) {
        mxH = max(mxH, ++mph[u]);
        mxW = max(mxW, ++mpw[v]);
    }
    set<int> hmax, wmax;
    for(auto u : mph) {
        if(mxH == u.second) hmax.insert(u.first);
    }
    for(auto v : mpw) {
        if(mxW == v.second) wmax.insert(v.first);
    }
    int ans = mxH + mxW - 1;
    for(auto u : hmax) {
        for(auto v : wmax) {
            if(s.find({u, v}) == s.end()) {
                ans++;
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 73876
#include <stdio.h>
main(){
  int n,kazu,card[4][13]={0},i,j,k;
  char mark;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&mark,&kazu);
    if(mark=='S'){
      card[0][kazu-1]=1;
    }
    else if(mark=='H'){
      card[1][kazu-1]=1;
    }
    else if(mark=='C'){
      card[2][kazu-1]=1;
    }
    else if(mark=='D'){
      card[3][kazu-1]=1;
    }
  }
  for(j=0;j<4;j++){
    for(i=1;i<14;i++){
      if(card[j][i-1]!=1 && j==0){
	printf("S %d\n",i);
      }
      else if(card[j][i-1]!=1 && j==1){
	printf("H %d\n",i);
      }
      else if(card[j][i-1]!=1 && j==2){
	printf("C %d\n",i);
      }
      else if(card[j][i-1]!=1 && j==3){
	printf("D %d\n",i);
      }
    }
  }
  return 0;
}

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

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n+1);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    a[n] = a[0]+k;
    int maxi = 0;
    for(int i=0;i<n;i++){
        maxi = max(maxi, a[i+1]-a[i]);
    }
    cout << k - maxi << endl;
    return 0;
}


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

vector<vector<int>> G;

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

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

  G.resize(n);
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  for (int i = 0; i < m; i++) {
    int a,b;
    cin >> a >> b;
    a--, b--;

    G[a].push_back(b);
    G[b].push_back(a);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int maxv = h[i];
    bool flag = true;
    for(auto it : G[i]) {
      if(h[it] >= maxv) {
        flag = false;
        break;
      }
    }
    if(flag) ans++;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 8744
A = input()
B = int(input())
C = ""
for i in range(B):
    D = input().split()
    if D[0] == "1":
        C,A = A,C
    else:
        if D[1] == "1":
            C += D[2]
        else:
            A += D[2]
C = C[::-1]
print(C+A)

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

using namespace std;

int main() {
    int N;
    cin >> N;
    int max_count = 0;
    int max_count_index = -1;
    for (int i = 1; i <= N; i++) {
        int tmp = i;
        int count = 0;
        while (tmp > 0) {
            if (tmp % 2 == 0) {
                count++;
                tmp /= 2;
            } else {
                break;
            }
        }
        if (count >= max_count) {
            max_count = count;
            max_count_index = i;
        }
    }

    cout << max_count_index << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(void)
{
	int a[100][100]={0};/*??????????????????*/
	int b[100]={0};	/*????????????????????????*/
	int c[100]={0};/*????????¨??????????????????????????????*/
	int n,m;
	int i,j;

	scanf("%d %d", &n, &m);


	for(i=0;i<n;i++){		/*?????????????????????*/
		for(j=0;j<m;j++){
		scanf("%d", &a[i][j]);
		}
	}
	for(i=0;i<m;i++){		/*???????????????????????????*/
		scanf("%d", &b[i]);
		}

	for(i=0;i<n;i++){		/*????????¨???????????????????????¬???????????£?????£??\*/
		for(j=0;j<m;j++){
		c[i] += a[i][j]*b[j];
		}
		printf("%d\n", c[i]);
	}
	return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
  int n;

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

  vector<int> costs(n, 0);
  for (int i = n-1; i >= 0; --i) {
    if (i < n-1) {
      int costA = costs[i+1] + abs(heights[i] - heights[i+1]);
      if (i < n-2) {
        int costB = costs[i+2] + abs(heights[i] - heights[i+2]);
        if (costA < costB) {
          costs[i] = costA;
        } else {
          costs[i] = costB;
        }
      } else {
          costs[i] = costA;
      }
    }
  }

  cout << costs[0] << endl;
  return 0;
}


Measured memory_bytes: 4048
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353
def make_trie(str_set):
    """
    :param collections.Iterable[str] str_set:
    :rtype: dict of dict
    """
    trie = {}
    for s in str_set:
        node = trie
        for c in s:
            if c not in node:
                node[c] = {}
            node = node[c]
    return trie


N, L = list(map(int, sys.stdin.buffer.readline().split()))
S = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(N)]

trie = make_trie(S)


# # grundy[i]: 深さ L - i の grundy 数
# grundy = [0] * L
# grundy[0] = 1
# for i in range(1, L):
#     gs = [0]
#     for j in range(i):
#         g = 0
#         for k in range(j, i):
#             g ^= grundy[k]
#         gs.append(g)
#     g = 0
#     while g in gs:
#         g += 1
#     grundy[i] = g
# print(grundy) # lsb
# [1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, 32]

# @debug
def grundy(i):
    # 深さ i の grundy 数
    # L - i の最下位ビット
    ret = 1
    while (L - i + 1) & ret == 0:
        ret <<= 1
    return ret


g = 0
stack = [(trie, 0)]
while stack:
    nodes, depth = stack.pop()
    if depth < L and len(nodes) == 1:
        g ^= grundy(depth + 1)
    for children in nodes.values():
        stack.append((children, depth + 1))

if g == 0:
    print('Bob')
else:
    print('Alice')


Measured memory_bytes: 34932
from collections import Counter
import sys
input = sys.stdin.buffer.readline
ans = {}

def main():
    n = int(input())
    for i in range(n):
        dic = {}
        for a in input().strip():
            if a in dic:
                dic[a] += 1
            else:
                dic[a] = 1
        dic2 = tuple(sorted(dic.items()))
        #print(dic2)
        tmp = ""
        for k, v in dic2:
            tmp += str(k) + str(v)
        if tmp in ans:
            ans[tmp] += 1
        else:
            ans[tmp] = 1
    su = 0
    for vv in ans.values():
        su += vv * (vv -1) // 2
    print(su)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20048
N = int(input())
S = input()
a0 = 0; a1 = 0; a2 = 0
P = [0]*N
for i, c in enumerate(S):
    if c == 'J':
        a0 += 1
    elif c == 'O':
        a1 += a0
    else:
        a2 += a1
    P[i] = a0

b0 = 0; b1 = 0; b2 = 0
Q = [0]*N
for i, c in enumerate(reversed(S)):
    if c == 'I':
        b0 += 1
    elif c == 'O':
        b1 += b0
    else:
        b2 += b1
    Q[-1-i] = b0

res = max(a1, b1)
for i in range(N):
    res = max(res, P[i] * Q[i])
print(res + a2)



Measured memory_bytes: 10432