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

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// AC
public class Main{

	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	int INF=1<<28;
	double EPS=1e-12;

	int n, m;
	int p, q, r;
	int[] x, y;

	void run(){
		try{
			for(;;){
				n=Integer.parseInt(br.readLine());
				if(n==0){
					break;
				}
				m=Integer.parseInt(br.readLine());
				String[] ss=br.readLine().split(" ");
				p=Integer.parseInt(ss[0]);
				q=Integer.parseInt(ss[1]);
				r=Integer.parseInt(ss[2]);
				x=new int[m];
				y=new int[m];
				for(int i=0; i<m; i++){
					ss=br.readLine().split(" ");
					x[i]=Integer.parseInt(ss[0]);
					y[i]=Integer.parseInt(ss[1]);
				}
				solve();
			}
		}catch(IOException e){
		}
	}

	long[] cards=new long[20000];
	long[] a=new long[20000];
	long[] b=new long[20000];
	long[] c=new long[20000];
	
	void solve(){
		// long[] cards=new long[20000];
		int nCards=0;
		cards[nCards++]=hoge(1, n+1);
		// long[] a=new long[20000];
		// long[] b=new long[20000];
		// long[] c=new long[20000];
		for(int k=0; k<m; k++){
			int ai=0, bi=0, ci=0;
			int left=0, right=0;
			for(int i=0; i<nCards; i++){
				int offset=(int)cards[i];
				int len=(int)(cards[i]>>>32);
				right+=len;
				boolean xCut=left<x[k]&&x[k]<right;
				boolean yCut=left<y[k]&&y[k]<right;
				if(xCut&&yCut){
					a[ai++]=hoge(offset, offset+x[k]-left);
					b[bi++]=hoge(offset+x[k]-left, offset+y[k]-left);
					c[ci++]=hoge(offset+y[k]-left, offset+len);
				}else if(xCut){
					a[ai++]=hoge(offset, offset+x[k]-left);
					b[bi++]=hoge(offset+x[k]-left, offset+len);
				}else if(yCut){
					b[bi++]=hoge(offset, offset+y[k]-left);
					c[ci++]=hoge(offset+y[k]-left, offset+len);
				}else{
					if(right<=x[k]){
						a[ai++]=cards[i];
					}else if(right<=y[k]){
						b[bi++]=cards[i];
					}else{
						c[ci++]=cards[i];
					}
				}
				left=right;
			}
			nCards=0;
			for(int i=0; i<ci; i++){
				cards[nCards++]=c[i];
			}
			for(int i=0; i<bi; i++){
				cards[nCards++]=b[i];
			}
			for(int i=0; i<ai; i++){
				cards[nCards++]=a[i];
			}
		}
		p--;
		q--;
		// [p, q]ªrÈº=[p, q+1)ªrÈº
		int ans=0;
		q++;
		int left=0, right=0;
		for(int k=0; k<nCards; k++){
			int offset=(int)cards[k];
			int len=(int)(cards[k]>>>32);
			right+=len;
			if(left<=q&&p<=right){
				int min=max(left, p)-left+offset;
				int max=min(right, q)-left+offset;
				// [i, j)ÅrÈºÌàÌÍH=[i, j)År+1¢ÌàÌÍH
				max=min(max, r+1);
				ans+=max(max-min, 0);
			}
			left=right;
		}
		println(ans+"");
	}

	long hoge(long left, long right){
		long offset=left;
		long len=right-left;
		return (len<<32)|offset;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
		System.out.close();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int n; cin >> n;
	int sum = 0;
	vector<int> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			sum += s[i] * s[j];
		}
	}
	cout << sum << endl;
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (a + b > c + d) {
        cout << "Left" << endl;
    } else if (a + b == c + d) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int n, query; cin >> n >> query;
  vector<priority_queue<int>> v(1010);

  for (int i = 0; i < query; ++i) {
    int op; cin >> op;
    if (op == 0) {
      int t, x; cin >> t >> x;
      v[t].push(x);
    } else if (op == 1) {
      int t; cin >> t;
      if (v[t].empty()) {
        continue;
      } else {
        cout << v[t].top() << '\n';
      }
    } else {
      int t; cin >> t;
      if (v[t].empty()) {
        continue;
      } else {
        v[t].pop();
      }
    }
  }

  return 0;
}


Measured memory_bytes: 4144
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

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

  std::vector<int> A_arr(N);
  for(int i = 0; i < N; i++){
    std::cin >> A_arr[i];
    A_arr[i] *= -1;
  }

  std::vector<int> current_arr;
  for(int i = 0; i < N; i++){
    auto change_it = std::upper_bound(current_arr.begin(), current_arr.end(), A_arr[i]);
    if(change_it == current_arr.end()){
      current_arr.push_back(A_arr[i]);
    }else{
      *change_it = A_arr[i];
    }
  }
  std::cout << current_arr.size() << std::endl;

  return 0;
}



Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string S;
  cin >> S;
  long long ans = 0;
  long long cntB = 0;
  for (char c : S)
  {
    if (c == 'B')
      cntB++;
    else
      ans += cntB;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

#define NOT_YET -1
#define CAT 1
#define RABBIT 0

int memo[500][500+1];

bool is_cat(string &s, int b, int e){
    if(memo[b][e] != NOT_YET)
        return memo[b][e];
    
    if(e - b == 0) return true;
    
    if(s[b] == 'm' && s[e-1] == 'w'){
        bool ret = false;
        for(int i=b; i<e; i++){
            if(s[i] == 'e')
                ret |= is_cat(s, b+1, i) && is_cat(s, i+1, e-1);
        }
        return memo[b][e] = ret;
    }else{
        return memo[b][e] = false;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(memo, -1, sizeof(memo));
    
    string s;
    cin >> s;
    cout << (is_cat(s, 0, s.size()) ? "Cat" : "Rabbit") << endl;
    
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    string s[n];
    long ans = 0;
    unordered_map<string, long> mp;
    for (int i = 0; i < n; i++) {
        char str_s[11];
        cin >> str_s;
        sort(str_s, str_s + 10);
        s[i] = string(str_s);
    }
    for (int i = 0; i < n; i++) {
        mp[s[i]]++;
    }
    for (auto p: mp) {
        long x = p.second;
        ans += x * (x - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11428
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;

int main() {
        int a, b, k;
        scanf("%d%d%d", &a, &b, &k);
        for (int i = a; i <= b; i ++) {
                if (i - a < k || b - i < k) {
                        printf("%d\n", i);
                }
        }
        return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  string s; 
  cin >> s;

  int ans = 0;
  REP(i, s.size()){
    if(s[i] == '1') ans++;
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
    string s;
    cin >> s;
    rep(i,s.size()) {
        if(s[i]==',') s[i] = ' ';
    }
    cout << s << endl;
    return 0;
}

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

int main() {
	int i, N, M, aa, bb, a[51]={0};
	scanf("%d%d", &N, &M);
	for (i=0; i < M ;i++) {
		scanf("%d%d", &aa, &bb);
		a[aa]++;
		a[bb]++;
	}
	for (i=1; i <= N ;i++) {
		printf("%d\n", a[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int k, x;
  cin >> k >> x;
  int L = max(-1000000, x - k + 1);
  int R = min(1000000, k + x - 1);
  for (int k = L; k <= R; ++k) {
    cout << k << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io::{self, BufRead};

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let line = lines.next().unwrap().unwrap();
  let vs: Vec<i64> = line.split(' ').map(|x| x.parse().unwrap()).collect();
  let n = vs[0];
  let k = vs[1];
  let line = lines.next().unwrap().unwrap();
  let mut hs: Vec<i64> = line.split(' ').map(|x| x.parse().unwrap()).collect();
  hs.sort();
  let ans = if n <= k {
    0
  } else {
    hs.iter().take((n - k) as usize).sum::<i64>()
  };
  println!("{}", ans);
}

Measured memory_bytes: 10492
import bisect
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
Q = [-a[0]]
for i in range(1,n):
    if a[i] <= -Q[-1]:
        Q.append(-a[i])
    else:
        j = bisect.bisect_right(Q,-a[i])###right
        #print(a,Q,i,j)
        Q[j] = -a[i]
    #print(i,Q)
print(len(Q))


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

#define ll              long long int
#define ull             unsigned long long int
#define pii             pair < int, int>
#define pll             pair < ll, ll>
#define sc              scanf
#define scin(x)         sc("%d",&(x))
#define scln(x)         sc("%lld",&(x))
#define pf              printf
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define mp              make_pair
#define db              double
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define vi              vector< int >
#define vl              vector< ll >
#define vii             vector<vector< int > >
#define vll             vector<vector< ll > >
#define DBG             pf("HI\n")
#define MOD             1000000007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define RUN_CASE(t,T)   for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)         printf("Case %d: ",t)
#define CASEL(t)        printf("Case %d:\n",t)
#define intlimit        2147483648
#define longlimit       9223372036854775808
#define infinity        (1<<28)
#define gcd(a, b)       __gcd(a,b)
#define lcm(a, b)       ((a)*(b)/gcd(a,b))
#define mx              123456789

using namespace std;

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fx[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

ll dp[100];

ll lucas(ll n)
{
    if(n==0)
        return 2;
    else if(n==1) return 1;
    else if(dp[n]==0)
        dp[n] = lucas(n-1)+lucas(n-2);
    return dp[n];
}

int main()
{
    ll n;
    scln(n);
    pf("%lld\n",lucas(n));
    return 0;
}


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

int main() {
  long long N;
  cin >> N;
  int m = INFINITY;
  for(long long i=1; i<=sqrt(N)+1; i++) {
    if(N%i==0) {
      int x = max(log10(i)+1,log10(N/i)+1);
      m = min(m,x); 
    }
    else continue;
  }
  cout << m << endl;
}

Measured memory_bytes: 3864
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a,b;
    cin >> a >> b;

	int i,s;
	for (s=1, i=0; s<b; i++) {
		s--;
		s+=a;
	}

    // 出力
    cout << i << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from random import randint
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def count_v(last_d, C, S, t, d):
    ret = S[t - 1]
    last_d[t - 1] = d
    for i in range(len(last_d)):
        ret -= C[i] * (d - last_d[i])
    return ret


def count_v_virtual(last_d, C, S, t, d):
    ret = S[t]
    tmp = last_d[t]
    last_d[t] = d
    for i in range(len(last_d)):
        ret -= C[i] * (d - last_d[i])
    last_d[t] = tmp
    return ret


def get_diff_score(T, d, q, C, D, Ss):
    diff = 0
    original_t = T[d - 1]
    last_d_q = 0
    last_d_ori = 0
    for i in range(d):
        if T[i] == q:
            last_d_q = i + 1
        if T[i] == original_t and i < d - 1:
            last_d_ori = i + 1
    # print(d, q, original_t, last_d_q, last_d_ori)
    for i in range(d - 1, D):
        if T[i] == q:
            break
        diff += C[q - 1] * (d - last_d_q)
    # print(diff, C[q - 1])
    T[d - 1] = q
    for i in range(d - 1, D):
        if T[i] == original_t:
            break
        diff -= C[original_t - 1] * (d - last_d_ori)
    # print(C[original_t - 1], diff)
    diff += Ss[d - 1][q - 1] - Ss[d - 1][original_t - 1]
    return diff


def main():
    D = int(input())
    C = inpl()
    Ss = [inpl() for _ in range(D)]
    T = []
    last_d = [-1] * len(C)
    Contest = 26

    for d in range(D):
        tmp_t, tmp_v = -1, -float('inf')
        for i in range(Contest):
            tmp_score = count_v_virtual(last_d, C, Ss[d], i, d)
            if tmp_score > tmp_v:
                tmp_v = tmp_score
                tmp_t = i
        last_d[tmp_t] = d
        T.append(tmp_t + 1)

    Cs = [i + 1 for i, c in enumerate(C)]
    Cs.sort(key=lambda x: C[x - 1])

    for _ in range(1000):
        d, q = randint(1, D), randint(1, Contest)
        ori_q = T[d - 1]
        diff = get_diff_score(T, d, q, C, D, Ss)
        if diff < 0:
            T[d - 1] = ori_q

    for t in T:
        print(t)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 78636
#include<bits/stdc++.h>
const int N=1e6+9;
using namespace std;
int read(int &x){
    int dat=0,oko=1;char chc=getchar();
    while(chc<'0'||chc>'9'){if(chc=='-')oko=-1;chc=getchar();}
    while(chc>='0'&&chc<='9'){dat=dat*10+chc-'0',chc=getchar();}
    x=dat*oko;return x;
}int n;
int main(){
    read(n);
    printf("%d\n",(n-1)>>1);
    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ervb
//
//  Created by Kanak Gautam on 21/04/20.
//  Copyright © 2020 Kanak Gautam. All rights reserved.
//
 
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 1000000007
using namespace std;
typedef long long int lli;
typedef long double ld;
priority_queue <lli, vector<lli>, greater<lli> > ti;
vector <lli> p[300005],f(200005,0),b(200005,0),a(200005,0);
map <pair<lli,lli>,lli> mp;
set<pair<lli, lli> > s;
set<lli> st;
map<lli,lli> np,v;
queue<lli> q;
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
lli bpow(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
lli fact(lli i)
{
    f[0]=1;
    for(lli k=1;k<=i;k++)
    {
        (f[k]=f[k-1]*k)%=mod;
    }
    return f[i];
}
lli isprime(lli n)
{
    if(n==1)
        return 0;
    for(lli i=2;i<=sqrt(n);i++)
        if(n%i==0)
            return 0;
    return 1;
}
bool cmp(lli i,lli j)
{
    return p[i].size()<p[j].size();
}
 
/*void sieve()
{
    for(lli i=2;i<=5000000;i++)
    {
        if(b[i]==0)
        {
        for(lli j=2;i*j<=5000000;j++)
        {
            b[i*j]=1;
        }
        }
    }
}*/
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    lli n;cin>>n;
    if(n>=30)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 15092
#include<iostream>
using namespace std;
int main(){
    int N,x,a[100],tmp,sum=0,l;
    cin>>N>>x;
    for(int i=0;i<N;i++)cin>>a[i];
    for(int k=1;k<=N-1;k++){
        for(int i=0;i<N-k;i++){
            if(a[i]>a[i+1]){
                tmp=a[i];
                a[i]=a[i+1];
                a[i+1]=tmp;
            }
        }  
    }
    for(l=0;x>=0&&l<N;l++){
        x-=a[l];
        sum++;
    }
    if(x==0&&l==N);
    else sum--;
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int64_t max_val = 0;
    bool success = true;
    for (int i = 0; i < n; i++)
    {
        int64_t h;
        cin >> h;
        if (max_val - 2 >= h)
        {
            success = false;
            break;
        }
        max_val = max(max_val, h);
    }
    cout << (success ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
/*------U Have To DO It------*/
/* BY-> RicoProg */
/*        ___ 
           __|__|
          |  |___       */
#include <bits/stdc++.h>
using namespace std;
 
 
//---------------------------------------------------MACROS----------------------------------------------------------
#define ll long long
#define beg(i ,n) for(ll i=0;i<n;i++)
#define beg1(i ,n) for(ll i=1;i<n;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back 
#define mp make_pair
#define nl "\n" 
#define vec(v , n) vector<ll> v(n)
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define pll pair<ll , ll>
#define mii map<int , int>
#define mll map<ll , ll>
#define msi map<string , int>
#define mci map<char , int>
#define f1 first
#define f2 second
 
//---------------------------------------------------GLOBAL----------------------------------------------------------
const ll MOD = 998244353 ;
const ll MAX = 1e5 + 7;
//---------------------------------------------------FUNCTIONS-------------------------------------------------------

void solve(){
	ll n , k ;
	vector<ll> dp(100001 , 1e18) ;
	cin >> n >> k ;
	vector<ll> ar(n) ;
	beg(i , n) cin >> ar[i] ;
	dp[0] = 0 ;
	beg1(i , n){
		beg1(j , k+1){
			if( i-j >=0 )	dp[i] = min(dp[i] , dp[i-j]+abs(ar[i]-ar[i-j])) ;
		}
	}
	cout << dp[n-1] ;
}
 
//---------------------------------------------------DRIVER----------------------------------------------------------
int main()
{
    fast ;
    int t=1 ;
    //cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}	

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;
const ll INF = 1 << 29;

int main() {
	int N;
	cin >> N;
	VI p(N);
	VB b(N,true);
	int count = 0;
	REP(i, N) {
		cin >> p[i];
		if (p[i] == i + 1) {
			b[i] = false;
			count++;
		}
	}
	for (int i = 0; i < N - 1; i++) {
		if ((!b[i]) && (!b[i + 1])) {
			count--;
			i ++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 640
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y
from collections import Counter

def main():
    n = II()
    ss = [IS() for _ in range(n)]
    c = Counter(ss)
    print(len(c))

if __name__ == '__main__':
    main()

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

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

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int ans = n % 1000;

            // 出力
            if (ans == 0) {
                out.println(0);
            } else {
                out.println(1000 - ans);
            }

        }

    }
}



Measured memory_bytes: 35644
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <string>

using namespace std;

// stringをintに
// string a = "123";
// stoi(a)
//
// intをstringに
// int a = 123;
// to_string(a)
//
// charをintに
// char a = '1';
// (int)a - 48 // asciiコードを値にする

// 配列Aにcinする
//int main() {
//  int N;
//  cin >> N;
//  vector<int> A(N);
//  for (int i = 0; i < N; i++) {
//    cin >> A.at(i);
//  }
//  return 0;
//}

// 標準入出力
int main() {
	int A, B;
	cin >> A >> B;
  int sum = A + B;
  int sub = A - B;
  int mul = A * B;
  if (sum >= sub && sum >= mul) {
    cout << sum << endl;
  } else if (sub >= sum && sub >= mul) {
    cout << sub << endl;
  } else if (mul >= sum && mul >= sum) {
    cout << mul << endl;
  }
  return 0;
}

// 文字列を1文字ずつループ
//int main() {
//  string str;
//  cin >> str;
//  int sum = 0;
//  for(int i = 0; i < (int)str.size(); ++i){
//    char ch = str[i];
//
//    if (ch == '1') {
//      sum++;
//    }
//  }
//  cout << sum << endl;
//  return 0;
//}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using Graph = vector<set<int>>;

void dfs(int v, const Graph &G, vector<bool> &seen, set<int> &friends) {
    seen[v] = true;

    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(next_v, G, seen, friends);
    }

    friends.insert(v);
}

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

    Graph G(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].insert(b-1);
        G[b-1].insert(a-1);
    }
    
    
    vector<bool> seen(n, 0);
    vector<set<int>> friendship;
    for (int i = 0; i < n; i++) {
	set<int> friends;
	dfs(i, G, seen, friends);
	friendship.push_back(friends);
    }

    int max = 0;
    for (auto f : friendship) {
	int num = f.size();
	if (max < num) {
	    max = num;
	}
    }
    cout << max << endl;
    return 0;
}



Measured memory_bytes: 84484
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long int li;
typedef long long ll;
typedef long double ld;

int main()
{
	FastIO;
	int n, k = 0;
	string s;
	cin >> n >> s;
	vector<int> w;
	vector<int> r;
	for (int i = 0; i < n; i++)
		if (s[i] == 'W')
			w.push_back(i);
		else
			r.push_back(i);
	sort(w.begin(), w.end());
	sort(r.rbegin(), r.rend());
	if (w.size())
	{
		if (w.size() >= r.size())
		{
			for (int i = 0; i < r.size(); i++)
				if (w[i] < r[i])
					k++;
		}
		else
		{
			for (int i = 0; i < w.size(); i++)
				if (w[i] < r[i])
					k++;
		}
		cout << k << "\n";
	}
	else
		cout << "0\n";
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

void input() {
	int n = ri();
	std::vector<int> c(26);
	for (auto &i : c) i = ri();
	std::vector<std::vector<int> > val(n, std::vector<int>(26));
	for (auto &i : val) for (auto &j : i) j = ri();
	
	std::vector<int> all(n);
	for (auto &i : all) i = ri() - 1;
	
	auto score = [&] (const std::vector<int> &all) {
		int last[26];
		for (auto &i : last) i = -1;
		int res = 0;
		for (int i = 0; i < n; i++) {
			int cur = all[i];
			last[cur] = i;
			for (int j = 0; j < 26; j++) res -= c[j] * (i - last[j]);
			res += val[i][cur];
			printf("%d\n", res);
		}
	};
	
	score(all);
}

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


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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int n;
    cin>>n;
    for(int i=1;i<10;i++){
        if(n%i==0 && n/i<10){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 2e5 + 10;
set<int> a[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    a[x].insert(y);
    a[y].insert(x);
  }
  bool found = false;
  for (int i = 1; i < n - 1; ++i) {
    if (a[0].count(i) && a[n - 1].count(i)) {
      found = true;
      break;
    }
  }
  puts(found ? "POSSIBLE" : "IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 28416
#include <iostream>

int main()
{
    int A, B, K;
    std::cin >> K >> A >> B;

    for (int i=A; i<=B; ++i)
    {
        if (i % K == 0)
        {
            std::cout << "OK" << std::endl;
            return 0;
        }
    }

    std::cout << "NG" << std::endl;
}


Measured memory_bytes: 3616
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=input()
res=0
for i in n:
    a=int(i)
    res+=a
if res%9==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 73272
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin >> n >> m;
  if(n==m) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

int r,c,n;

class P {
public:
  int x,y;
  bool onEdge() {
    return y == 0 || y == c || x == 0 || x == r;
  }
  int d() {
    if(y == 0) {
      return x;
    } else if(x == r) {
      return r+y;
    } else if(y == c) {
      return 2*r + c - x;
    } else if(x == 0) {
      return 2*r + 2*c - y;
    }
  }
};

int main () {
  priority_queue<pair<int, int>> q;

  scanf("%d %d %d", &r, &c, &n);
  rep(i,n) {
    P p1, p2;
    scanf("%d %d %d %d", &p1.x, &p1.y, &p2.x, &p2.y);
    if(p1.onEdge() && p2.onEdge()) {
      q.push(make_pair(p1.d(), i));
      q.push(make_pair(p2.d(), i));
    }
  }

  stack<int> s;
  vector<int> used(n, 0);
  while(!q.empty()) {
    int i = q.top().second; q.pop();
    if(used[i]) {
      if(s.top() != i) {
        printf("NO\n");
        return 0;
      }
      s.pop();
    } else {
      used[i] = 1;
      s.push(i);
    }
  }

  printf("YES\n");
  return 0;
}


Measured memory_bytes: 3444
n=input()


if n=='SUN':
    ans = 7
elif n=='MON':
    ans = 6
elif n=='TUE':
    ans = 5
elif n=='WED':
    ans = 4
elif n=='THU':
    ans = 3
elif n=='FRI':
    ans = 2
elif n=='SAT':
    ans = 1

print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int n,m;
long long k;
long long ans;
int main() {
	priority_queue <long long> pq;
	cin>>n>>m;
	for(int i=1;i<=n;i++) {
		scanf("%lld",&k);
		pq.push(k);
	}
	for(int i=1;i<=m;i++) {
		k=pq.top();
		k/=2;
		pq.pop();
		pq.push(k);
	}
	for(int i=1;i<=n;i++) {
		ans+=pq.top();
		pq.pop();
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#define llint long long int

using namespace std;

llint N;
llint T[105];

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

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++) cin >> T[i];
	
	llint ans = 1;
	for(int i = 0; i < N; i++){
		ans = ans / gcd(ans, T[i]) * T[i];
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
int main(){
    int n,i,sx=0,sy=0,step,ex,ey,old=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        int steps = 0;
        scanf("%d%d%d",&step,&ex,&ey);
        steps+=abs(ex-sx);
        steps+=abs(ey-sy);
        if(steps>step-old){
            printf("No\n");
            return 0;
        }
        else if(steps<step-old){
            if((step-old-steps)%2!=0){
                printf("No\n");
                return 0;
            }
        }
        old=step;
        sx=ex;
        sy=ey;
    }
    printf("Yes\n");
    return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}
#define MOD 1000000007
template<int mod>
struct ModInt{
	int x;
	ModInt():x(0){}
	ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}
	ModInt &operator^=(long long p){
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator-()const{return ModInt(-x);}
	ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
	ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
	ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
	ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
	ModInt operator^(long long p)const{return ModInt(*this)^=p;}
	bool operator==(const ModInt &p)const{return x==p.x;}
	bool operator!=(const ModInt &p)const{return x!=p.x;}
	explicit operator int() const { return x; }						   // added by QCFium
	ModInt operator=(const int p) {x = p; return ModInt(*this);} // added by QCFium
	ModInt inverse()const{
		int a=x,b=mod,u=1,v=0,t;
		while(b>0){
			t=a/b;
			a-=t*b;
			std::swap(a,b);
			u-=t*v;
			std::swap(u,v);
		}
		return ModInt(u);
	}
	friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
		return os<<p.x;
	}
	friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
		long long x;
		is>>x;
		a=ModInt<mod>(x);
		return (is);
	}
};
typedef ModInt<MOD> mint;

struct MComb {
	std::vector<mint> fact;
	std::vector<mint> inversed;
	MComb(int n) { // O(n+log(mod))
		fact = std::vector<mint>(n+1,1);
		for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*mint(i);
		inversed = std::vector<mint>(n+1);
		inversed[n] = fact[n] ^ (MOD-2);
		for (int i = n - 1; i >= 0; i--) inversed[i]=inversed[i+1]*mint(i+1);
	}
	mint ncr(int n, int r) {
		return (fact[n] * inversed[r] * inversed[n-r]);
	}
	mint npr(int n, int r) {
		return (fact[n] * inversed[n-r]);
	}
	mint nhr(int n, int r) {
		assert(n+r-1 < (int)fact.size());
		return ncr(n+r-1, r);
	}
};


int main() {
	int n = ri(), k = ri();
	MComb com(2 * n + 1);
	mint res = 0;
	for (int i = 0; i < n; i++) {
		if (i > k) break;
		int m = n - i;
		res += com.ncr(n, i) * com.ncr(m - 1 + i, i);
	}
	std::cout << res << std::endl;
	return 0;
}


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

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

using namespace std;

struct UnionFind {
  vector<int> parent;
  UnionFind (int n) { parent.assign(n, -1); }
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (parent[y] < parent[x]) swap(x, y);
    if (parent[x] == parent[y]) --parent[x];
    parent[y] = x;
    return true;
  }
};

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n) break;
    UnionFind uf(n*4);
    REP(i,n){
      uf.merge(i*4,i*4+3);
      uf.merge(i*4+1,i*4+2);
    }
    map<int,map<int,int>> m;
    vector<tuple<int,int,string>> f;
    REP(i,n){
      int x,y;
      string d;
      cin>>x>>y>>d;
      m[x][y] = i*2+1;
      if(d=="x")
        m[x+1][y] = i*2+2;
      else
        m[x][y+1] = i*2+2;
      f.emplace_back(x,y,d);
    }
    REP(i,n){
      int x,y;
      string d;
      tie(x,y,d) = f[i];
      int l=m[x-1][y];
      if (l != 0) {
        int j = (l-1)/2;
        int s = (l-1)-2*j;
        uf.merge(i*4,j*4+s*2);
        uf.merge(i*4+1,j*4+s*2+1);
      }
      l=m[x][y-1];
      if (l != 0) {
        int j = (l-1)/2;
        int s = (l-1)-2*j;
        uf.merge(i*4,j*4+s*2);
        uf.merge(i*4+1,j*4+s*2+1);
      }
      if(d=="x"){
        l=m[x+1][y-1];
        if (l != 0) {
          int j = (l-1)/2;
          int s = (l-1)-2*j;
          uf.merge(i*4+2,j*4+s*2);
          uf.merge(i*4+3,j*4+s*2+1);
        }
      }else{
        l=m[x-1][y+1];
        if (l != 0) {
          int j = (l-1)/2;
          int s = (l-1)-2*j;
          uf.merge(i*4+2,j*4+s*2);
          uf.merge(i*4+3,j*4+s*2+1);
        }
      }
    }
    bool ok = true;
    REP(i,n) {
      if (uf.root(i*4)==uf.root(i*4+1)) ok = false;
    }
    if(ok)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 11892
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  return *(long *)a - *(long *)b;
}

int main(){
   int i,n;
   long a[200001];
    
   scanf("%d",&n);
   for (i=0;i<n;i++) scanf("%ld",&a[i]);
   qsort(a,n,sizeof(long),asc);

   for (i=1;i<n;i++) 
      if (a[i-1]==a[i]) {
         puts("NO");
         return 0;
   }
   puts("YES");
   return 0;
}


Measured memory_bytes: 3324
#include "iostream"
#include "random"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"
#include "queue"
#include "list"
#include "set"
#include "climits"
#include "iomanip"

using namespace std;
using ll = long long int;

const long long int MOD = 1000000007;

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

	int N, M;

	cin >> N >> M;
	vector<vector<long long int>>dp(N, vector<long long int>(M));
	vector<int>v(N);
	for (int i = 0; i < N; i++)cin >> v[i];
	vector<int>w(N);
	for (int i = 0; i < N; i++)cin >> w[i];
	if (w[0]) {
		for (int i = v[0]; i < M; i += w[0])dp[0][i] = 1;
	}
	else {
		dp[0][v[0]] = 1;
	}
	for (int i = 1; i < M; i++) {
		dp[0][i] += dp[0][i - 1];
		dp[0][i] %= MOD;
	}
	for (int i = 1; i < N; i++) {
		if (w[i]) {
			for (int j = v[i]; j < M; j += w[i]) {
				if (j)dp[i][j] = dp[i - 1][j - 1];
			}
		}
		else {
			dp[i][v[i]] = dp[i - 1][v[i] - 1];
		}
		for (int j = 1; j < M; j++) {
			dp[i][j] += dp[i][j - 1];
			dp[i][j] %= MOD;
		}
	}
	cout << dp.back().back() << endl;
}


Measured memory_bytes: 198580
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m, sum = 0;
    cin >> n;
    string s[n];
    for (int i = 0; i < n; i++) cin >> s[i];
    cin >> m;
    string t[m];
    for (int i = 0; i < m; i++) cin >> t[i];
    for (int i = 0; i < n; i++)
    {
        int r = 0;
        for (int j = 0; j < n; j++)
            if (s[i] == s[j]) r++;
        for (int j = 0; j < m; j++)
            if (s[i] == t[j]) r--;
        sum = max(sum, r);
    }
    cout << sum;
}

Measured memory_bytes: 3604
#include <iostream>
#include <set>

using namespace std;
int main()
{
  int s;
  cin >> s;
  set<int> num_set;
  num_set.insert(s);

  auto func = [](int n)
  {
    if (n%2 == 0) {
      return n/2;
    }
    return 3*n+1;
  };

  int next = func(s);
  while(num_set.count(next) == 0)
  {
      num_set.insert(next);
      next = func(next);
  }
  cout << num_set.size()+1 << endl;
  return 0;
}

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

int main()
{
	int N;
	int A[100005];
	int maxv = 0;	
	cin >> N;
	for ( int i = 0; i < N; i++ ) {
		cin >> A[i];
		maxv = max(A[i], maxv);
	}
	int ans = -1, close = maxv;
	for ( int i = 0; i < N; i++ ) {
		int val = min(abs(maxv / 2 - A[i]), abs((maxv - 1) / 2 - A[i]));
		if ( close > val ) {
			close = val;
			ans = A[i];
		}
	}

	cout << maxv << " " << ans << endl;

	return (0);
}


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

int main(){
  vector<vector<int>> c(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> c.at(i).at(j);
    }
  }
  
  vector<int> a3_2(3),a2_1(3),a1_3(3),b3_2(3),b2_1(3),b1_3(3);
  for(int i=0;i<3;i++){
    a3_2.at(i) = c.at(2).at(i) - c.at(1).at(i);
    a2_1.at(i) = c.at(1).at(i) - c.at(0).at(i);
    a1_3.at(i) = c.at(0).at(i) - c.at(2).at(i);
    b3_2.at(i) = c.at(i).at(2) - c.at(i).at(1);
    b2_1.at(i) = c.at(i).at(1) - c.at(i).at(0);
    b1_3.at(i) = c.at(i).at(0) - c.at(i).at(2);
  }
  
  if(a3_2.at(0)==a3_2.at(1)&&a3_2.at(1)==a3_2.at(2)&&a3_2.at(2)==a3_2.at(0)&&a2_1.at(0)==a2_1.at(1)&&a2_1.at(1)==a2_1.at(2)&&a2_1.at(2)==a2_1.at(0)&&a1_3.at(0)==a1_3.at(1)&&a1_3.at(1)==a1_3.at(2)&&a1_3.at(2)==a1_3.at(0)&&b3_2.at(0)==b3_2.at(1)&&b3_2.at(1)==b3_2.at(2)&&b3_2.at(2)==b3_2.at(0)&&b2_1.at(0)==b2_1.at(1)&&b2_1.at(1)==b2_1.at(2)&&b2_1.at(2)==b2_1.at(0)&&b1_3.at(0)==b1_3.at(1)&&b1_3.at(1)==b1_3.at(2)&&b1_3.at(2)==b1_3.at(0)){
    cout << "Yes" << "\n";
  }else{
    cout << "No" << "\n";
  }
}
    
  

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

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

int main()
{
    int r;
    cin >> r;
    OP(r * r);

    return 0;
}

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

vector<int>solve(vector<int>vec){
    vector<int>r;
    map<int,int>m;
    for(int i=0;i<vec.size();i++)
        m[vec[i]]++;
    for(int i=0;i<vec.size();i++)
        r.push_back(m[vec[i]]);
    return r;
}
int main(){
    int n,t,suc;
    while(cin>>n,n){
        vector<int>las,cur;
        while(n--){
            cin>>t;
            las.push_back(t);
        }
        t=0;
        while(1){
            cur=solve(las);
            suc=1;
            for(int i=0;i<cur.size();i++){
                if(cur[i]!=las[i]){
                    suc=0;
                    break;
                }
            }
            if(suc==1&&cur.size())break;
            for(int i=0;i<cur.size();i++)
                las[i]=cur[i];
            t++;
        }
        cout<<t<<endl;
        for(int i=0;i<cur.size()-1;i++)
            cout<<cur[i]<<" ";
        cout<<cur[cur.size()-1]<<endl;
    }
}

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

int	main() {
	string s, t;
	cin >>s >>t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	vector<string> S;
	S.push_back(s);
	S.push_back(t);
	sort(S.begin(), S.end());
	if (t!=S.at(0))
		cout <<"Yes" <<endl;
	else
		cout <<"No" <<endl;
	return 0;
};


Measured memory_bytes: 256
// SeeAlso: https://atcoder.jp/contests/abc129/tasks/abc129_b

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int N;
int W[MAX];

int main() {
    int sum = 0;  
    cin >> N;
    REP(i, N) {
        cin >> W[i];
        sum += W[i];
    } 

    int s1 = 0;
    int av = sum / 2;
    int m = av;
    int ans = 0;
    REP(i, N) {
        if (m < (abs(av-s1-W[i]))) {
            ans = abs(sum-s1-s1);
            break;
        }
        s1 += W[i];
        m = abs(av-s1);
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 256
def read_input():
    a, b, c = map(int, input().split())
    return a, b, c


def submit():
    a, b, c = read_input()

    if a == b:
        print(c)
    elif a == c:
        print(b)
    else:
        print(a)


if __name__ == '__main__':
    submit()

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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#define co(n) cout << (n) << endl;
#define cn(n) cin >> n;
#define all(x) (x).begin(), (x).end()

int main(){
  ll a,b;
  cin >> a >> b;
  if (a>b)swap(a,b);
  ll ans = a*b;
  while(true){
    if (a%b){
      ll t = a%b;
      a = b;
      b = t;
    }else{
      break;
    }
  }
  cout << ans/b << endl;
}

Measured memory_bytes: 256