akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

int main() {
	string a, b; cin >> a >> b;
	int n = max(SZ(a), SZ(b));
	for(int i=0; i<n; i++) {
		if(i < SZ(a)) printf("%c", a[i]);
		if(i < SZ(b)) printf("%c", b[i]);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for (int i = 0; i < tx - sx; i++)
    {
        cout << 'R';
    }
    for (int i = 0; i < ty - sy; i++)
    {
        cout << 'U';
    }
    for (int i = 0; i < tx - sx; i++)
    {
        cout << 'L';
    }
    for (int i = 0; i < ty - sy; i++)
    {
        cout << 'D';
    }
    cout << 'D';
    for (int i = 0; i < tx - sx + 1; i++)
    {
        cout << 'R';
    }
    for (int i = 0; i < ty - sy + 1; i++)
    {
        cout << 'U';
    }
    cout << 'L';
    cout << 'U';
    for (int i = 0; i < tx - sx + 1; i++)
    {
        cout << 'L';
    }
    for (int i = 0; i < ty - sy + 1; i++)
    {
        cout << 'D';
    }
    cout<<'R';
    return 0;
}

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

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

  if (N%1000==0) {
    cout << 0 << endl;
  }
  else{
    int A=0;
    A=N/1000;
    cout <<1000*(A+1)-N<< endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long int;
using namespace std;
ll mod=1e9+7;


int main() {
  int s;
  cin >> s;
  s=s%10;
  if(s==3){cout << "bon" << endl;}
  else if(s==0 || s==1 || s==6 || s==8){cout << "pon" << endl;}
  else {cout << "hon" << endl;}
}

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


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

    pair<int, int> M[5];
    for (auto &m: M) {
        int t;
        cin >> t;
        int res = t % 10 == 0? 0 : 10 - (t % 10);
        m = make_pair(res, t);
    }
    sort(M, M + 5);

    int res = 0;
    for (int i = 0; i < 5; ++i) {
       res += M[i].second;
       if (i < 4) {
           res += M[i].first;
       }
    }

    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
using System;using System.Linq;
class A{static void Main(){
int n=int.Parse(Console.ReadLine());
  long []a=Console.ReadLine().Split().Select(long.Parse).ToArray();
  for(int i=0;;i++){
  for(int j=0;j<a.Length;j++){
  if(a[j]%2==1){Console.WriteLine(i);return;}
  a[j]/=2;
  }
    
  }



}}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
 #define all(v) (v).begin(),(v).end()
 using ll = long long;
using Graph = vector<vector<int>>;
const int MAX = 510000;
const int MOD = 1000000007;
 
 
 
int main(){
ll n;
  cin>>n;
  ll t=0;
  ll s=-1;
  rep(i,n){
  ll a,b;
    cin>>a>>b;
   
  t=t+a*b;
    s=s+b;
  }
 s=s+t/9;
  if(t%9==0) s--;
  cout<<s;

}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

int N;
vector<char> v;
void dfs(int count,char c_lim){
    if(count==0){
        for(char c:v){
            printf("%c",c);
        }
        printf("\n");
    }else{
        for(char c='a';c<=c_lim;++c){
            v.push_back(c);
            dfs(count-1,max(char(c+1),c_lim));
            v.pop_back();
        }
    }
}


int main(){
    cin>>N;
    dfs(N,'a');
}

Measured memory_bytes: 1536
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [x, y] = [int(input_raw[0]), int(input_raw[1])]
    X = abs(abs(y) - abs(x))
    if y == 0:
        if x > 0:
            X += 1
    elif x == 0:
        if y < 0:
            X += 1
    elif (abs(x) == x) != (abs(y) == y):
        X += 1
    else:
        if y < x:
            X+= 2

    print X

if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
alice, bob = gets.chomp.split.map(&:to_i)

if (alice == 1 && bob != 1) 
  puts 'Alice'
elsif (alice != 1 && bob == 1)
  puts 'Bob'
elsif (alice > bob)
  puts 'Alice'
elsif (alice < bob)
  puts 'Bob'
else
  puts 'Draw'
end

Measured memory_bytes: 1788
#include <stdio.h>

int main(){
  int x,y,d;
  scanf("%d%d",&x,&y);
  if(x<y){
    d=x;
    x=y;
    y=d;
  }
  while(y>0){
    d=x%y;
    x=y;
    y=d;

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

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

int main() {
  string s;
  cin >> s;
  bool flag=true;
  if(s[0] != s[2]) {
    flag=false;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
def resolve():
  h, w = map(int, input().split())
  a = []
  for i in range(h):
    s = input()
    if '#' in s:
      a.append(s)
  h = len(a)
  blk_clm = set()  # '#' を含む列
  for i in range(h):
    for j in range(w):
      if a[i][j] == '#':
        blk_clm.add(j)

  for i in range(h):
    for j in range(w):
      if j in blk_clm:
        print(a[i][j], end='')
    print('')

  return

if __name__ == "__main__":
  resolve()


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

int main() {
  string s,t,u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(s==u){
    a--;
  }
  if(t==u){
    b--;
  }
  cout << a << " " << b;
}


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

int n, m, k;

int power(int m, int n) {
  int p = 1;
  for (int i = 0; i < n; i++) {
    p *= m;
  }
  return p;
}

int dfs(int depth, int sum) {
  if (depth == n) {
    return (sum - k > 0) ? sum - k : 1;
  }
  int res = 0;
  for (int i = 1; i <= m; i++) {
    res += dfs(depth + 1, sum + i);
  }
  return res;
}

int main() {
  while (true) {
    cin >> n >> m >> k;
    if (!n && !m && !k) return 0;
    int base = power(m, n);
    printf("%.8f\n", dfs(0, 0) / (double) base);
  }
}



Measured memory_bytes: 3124
const main = () => {
  const ab = getParams()
      , a = ab[0]
      , b = ab[1];
  console.log(solve(a, b));
};

const getParams = () =>
  getStdin().split(' ').map(Number);

const getStdin = () =>
  require('fs').readFileSync('/dev/stdin', 'utf8');

const solve = (a, b) =>
  a * b % 2 === 1 ? 'Odd' : 'Even';

main();


Measured memory_bytes: 21064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "No\n"; return;}

const double PI = 3.1415926535;

void solve() {
    int k, n;
    cin >> k >> n;
    int sum = 0;
    loop(i, n) {
        int x; cin >> x;
        sum += x;
    }
    cout << max(-1ll, k - sum);
}

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

Measured memory_bytes: 3612
N = int(input())
word = []
flag = 1
for i in range(N):
  st = input()
  if i > 0 :
    if final != st[0]:
      flag = 0
    elif st in word:
      flag = 0
    else:
      final = st[-1]
      word += [st]
  else:
    final = st[-1]
    word += [st]
if flag:
  print("Yes")
else :
  print("No")

Measured memory_bytes: 3064
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int H, W, D;
    cin >> H >> W >> D;

    int N = H * W;

    vvi A(H, vi(W));
    vector<pair<ll, ll>> pos(N);

    rep(i, H)
    {
        rep(j, W)
        {
            cin >> A[i][j];
            A[i][j]--;
            pos[A[i][j]] = make_pair(i, j);
        }
    }

    vvll cost(D, vll(N / D + 1));
    rep(d, D)
    {
        rep(i, N / D)
        {
            int next = (i + 1) * D + d;
            if (next >= N) break;

            auto p = pos[i * D + d];
            auto q = pos[next];

            cost[d][i + 1] = cost[d][i] + abs(p.first - q.first) + abs(p.second - q.second);
        }
    }

    int Q;
    cin >> Q;

    rep(_, Q)
    {
        int L, R;
        cin >> L >> R;
        L--;
        R--;

        int d = L % D;
        int l = L / D;
        int r = R / D;

        cout << cost[d][r] - cost[d][l] << endl;
    }
       
    return 0;
}

Measured memory_bytes: 9632
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
int N;
int A[20];
int x[20][20];
int y[20][20];


//1bit毎にフラグがたっているか確認する。
int counter(int x) {
	if (x == 0)return 0;
	return counter(x>>1) + (x&1);
}

void solve() {
	cin >> N;
	for (int i = 0; i < N;++i) {
		cin >> A[i];
		for (int j = 0; j < A[i];++j) {
			cin >> x[i][j] >> y[i][j];
		}
	}
	int ans = 0;
	//あらゆるパターン（正直者か否か）を網羅してくれる。bit全探索
	for (int bits = 0; bits < (1 << N);++bits) {
		//それぞれ確認していく
		bool ok = true;
		for (int i = 0; i < N;++i) {
			//正直者でなければ確認しない
			if (!(bits&(1<<i)))continue;
			//正直者であるならば、言っていることが全て正しくなければならない
			for (int j = 0; j < A[i];++j) {
				if ((bits & 1<<(x[i][j]-1)) ^ (y[i][j]<<(x[i][j]-1)))ok = false;
			}
		}
		if (ok) ans = max(ans, counter(bits));
	}
	cout << ans << endl;
}

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




Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
int main(void) {
  int n, a;
  int m1, m2;
  vector<int> v;
  m1 = m2 = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    v.push_back(a);
    if (m1 < a) {
      m2 = m1;
      m1 = a;
    } else if (m2 < a)
      m2 = a;
  }
  for (int i = 0; i < n; i++)
    printf("%d\n", v[i] == m1 ? m2 : m1);
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), c(n);
    rep(i, n) cin >> a[i];
    copy(a.begin(), a.end(), c.begin());
    sort(c.begin(), c.end(), greater<int>());

    rep(i, n) {
        if(a[i] == c[0]) {
            cout << c[1] << endl;
            continue;
        }
        cout << c[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 4780
import java.io.*; 
import java.util.*; 

public class Main{ 
	
	static class FastReader{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

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

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

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

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

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	}
  
	public static void main(String[] args) 
	{ 
		FastReader sc = new FastReader(); 
		long a = sc.nextLong();
      	long b = sc.nextLong();
      	System.out.println( (a+b)%2==0 ? (a+b)/2 : "IMPOSSIBLE" );
	} 
} 


Measured memory_bytes: 21716
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
 
int main()
{
    string S; cin >> S;
    int N = S.size();
    int a[N+1];
    for (int i = 0; i < N+1; i++)
    {
        a[i] = 0;
    }
    for (int i = 0; i < N; i++)
    {
        if(S[i] == '<') a[i+1] = a[i] + 1;
    }
    for (int i = 0; i < N-1; i++)
    {
        if(S[N-1-i] == '>'){
            if(S[N-2-i] == '<') a[N-1-i] = max(a[N-1-i],a[N-i]+1);
            else a[N-1-i] = a[N-i] + 1;
        }
    }
    if(S[0] == '>') a[0] = a[1] + 1;
    ll ans = 0;
    for (int i = 0; i < N+1; i++)
    {
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2820
package main

import (
	"bufio"
	"fmt"
	"os"
	"regexp"
	"strconv"
)

func solve() {
	s := next()
	r := regexp.MustCompile(`^(eraser|erase|dreamer|dream)+$`)
	if r.MatchString(s) {
		println("YES")
	} else {
		println("NO")
	}
	return
}

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, scBufSize), scBufSize)

	solve()
}

// --- template ---

const scBufSize = 1 * 1024 * 1024 // 1MB

var (
	in  = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func println(a ...interface{}) {
	fmt.Fprintln(out, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(out, format, a...)
}

func next() string {
	in.Scan()
	return in.Text()
}

func nextInt() int {
	s := next()
	i, e := strconv.Atoi(s)
	if e != nil {
		fmt.Println(e)
	}
	return i
}

func nextInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = nextInt()
	}
	return res
}

func unique(list []int) []int {
	m := make(map[int]bool)
	uniq := make([]int, 0)
	for _, e := range list {
		if !m[e] {
			m[e] = true
			uniq = append(uniq, e)
		}
	}
	return uniq
}


Measured memory_bytes: 896
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define deb(x) cout << #x << ' ' << x << '\n'
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define per(i,ini) for(int i=ini;i>=0;i--)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 1e5+2;


int main()
{
	int n;
	scn(n);

	int d = n % 10;

	if(d == 2 || d == 4 || d == 5 || d == 7 || d == 9)
	cout << "hon";
	else if(d == 3)
	cout << "bon";
	else
	cout << "pon";

	return 0;	
}

Measured memory_bytes: 3712
/*input
3 2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<'('<<P.F<<','<<P.S<<')';
    return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        
        b>>=1;
    }
    return res;
}

int a[maxn];
int main(){
    IOS;
    int n,k;
    cin>>n>>k;
    int rem=n;
    REP(i,k-1) a[i]=1,rem--;
    a[k-1]=rem;
    sort(a,a+k);
    cout<<a[k-1]-a[0]<<'\n';
    return 0;
}


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

int res[5];

void digits(int x) {
  res[0] = x / 10000;
  x -= res[0] * 10000;
  res[1] = x / 1000;
  x -= res[1] * 1000;
  res[2] = x / 100;
  x -= res[2] * 100;
  res[3] = x / 10;
  x -= res[3] * 10;
  res[4] = x;
}

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

  int count = 0;
  for (int i = a; i <= b; i++) {
    digits(i);
    if (res[0] == res[4] && res[1] == res[3]) count++;
  }
  cout << count << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> l(n);
  rep(i, n){
    cin >> l[i];
  }
  sort(l.begin(), l.end());

  int cnt = 0;
  rep(i, n){
    for (int j = i; j < n; j++){
      if (i == j || l[i] == l[j]) continue;
      for (int k = j; k < n; k++){
        if (i == k || l[i] == l[k] || j == k || l[j] == l[k]) continue;
        if (l[i] + l[j] > l[k]) {
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}


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

int main() {
	int a,b;
	char op;
	while(1){
		cin>>a>>op>>b;
		if(op=='+')
			cout<<a+b<<endl;
		else if(op=='-')
			cout<<a-b<<endl;
		else if(op=='*')
			cout<<a*b<<endl;
		else if(op=='/')
			cout<<a/b<<endl;
		else if(op=='?')
			break;
		
	}
		
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
int n,m;
int a[1005],b[1005],c[1005];
int dp[10000];
int fullmask=0;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	REP(i,m){
		cin>>a[i]>>b[i];
		REP(j,b[i]){
			int x;cin>>x;c[i]|=1<<(x-1);
		}
	}
	REP(i,9999) dp[i]=1e9;
	dp[0]=0;
	fullmask=1<<n;--fullmask;--n;
	REP(i,m){
		for (int mask=0;mask<fullmask;++mask) dp[mask|c[i]]=min(dp[mask|c[i]],dp[mask]+a[i]);
	}
	if (dp[fullmask]<1e9) cout<<dp[fullmask];
	else cout<<-1;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

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

        int[] b = new int[M];
        for (int j = 0; j < M; j++) {
            b[j] = sc.nextInt();
        }

        int[][] a = new int[N][M];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        int ans = 0;
        for (int i = 0; i < N; i++) {
            int tmp = 0;
            for (int j = 0; j < M; j++) {
                tmp += a[i][j]*b[j];
            }
            tmp += C;
            if(tmp > 0){
                ans++;
            }
        }

        out.println(ans);
    }
}


Measured memory_bytes: 23120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    sonic();
    int n, k, ans=0;
    cin >> n >> k;
    int A[n];
    rep(i, n){
        int l;
        cin >> l;
        A[i] = l;
    }
    sort(A, A+n);
    rep(j, k) ans += A[n - j - 1];
    cout << ans << "\n";
}



Measured memory_bytes: 256
// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;


// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz


	int n;
	cin >> n;
	int ans = (n/500)*1000;
	n%=500;
	cout << ans+(n-n%5);

	return 0;
}  


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void)
{
    int H, W;
    cin >> H >> W;
    
    vector<vector<char>> grid(H, vector<char>(W));
    vector<vector<int>> is_show(H, vector<int>(W, 1));
    
    for(int i = 0; i < H;i++)
    {
        bool all_white = true;
        
        for(int j = 0;j < W;j++)
        {
            cin >> grid[i][j];
            
            if(grid[i][j] == '#')
            {
                all_white = false;
            }
        }
        
        if(all_white)
        {
            for(int j = 0;j < W;j++)
            {
                is_show[i][j] = 0;
            }
        }
    }
    
    for(int i = 0; i < W;i++)
    {
        bool all_white = true;
        
        for(int j = 0;j < H;j++)
        {
            if(grid[j][i] == '#')
            {
                all_white = false;
            }
        }
        
        if(all_white)
        {
            for(int j = 0;j < H;j++)
            {
                is_show[j][i] = 0;
            }
        }
    }
    
    for(int i = 0;i < H;i++)
    {
        bool is_output = false;
        for(int j = 0;j < W;j++)
        {
            if(is_show[i][j] == 1)
            {
                cout << grid[i][j];
                is_output = true;
            }
        }
        
        if(is_output)
        {
            cout << endl;
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    char strChar = str.charAt(0);
    int code = (int)strChar;
    char out = (char)(code+1);
    
    System.out.println(out);

  }
}


Measured memory_bytes: 20948
#include<iostream>

int main(){
    long long int a, b, n;
    std::cin >> a >> b >> n;
    if(a-n < 0){
        if(b-(n-a) > 0)
            b -= n-a;
        else
            b = 0;
        a=0;
    }else 
        a-=n;
    std::cout << a << " " << b << "\n";
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string a;
    int n;
    char l;
    map<string,int>mp;
    cin>>n;
    bool ok=1;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        if(mp[a]) ok=0;
        mp[a]++;
        if(i!=1 && a[0]!=l)
            ok=0;
        l=a.back();
    }
    if(ok) cout<<"Yes\n"; else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n,m,d[100];
  string s[100];
  while(cin>>n>>m&&n){
    int a=0;
    for(int i=0;i<n;i++)cin>>s[i]>>d[i];
    for(int i=0;i<m;i++){
      string t;
      cin>>t;
      for(int k=0;k<n;k++){
      bool f=1;
    for(int j=0;j<t.size();j++)if(s[k][j]!='*'&&s[k][j]!=t[j])f=0;
    if(f)a+=d[k];    
      }
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
/*
  AUTHOR:SOURABH
  CREATED:22:03:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t,n,i,sum;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n;
        vll a(n),b(n+1);
        fn(i,n)
        {
            cin>>a[i];
            b[a[i]]++;
        }
        sum=0;
        fs(i,1,n+1)
        {
            sum=sum+(b[i]*(b[i]-1))/2;
        }
        fn(i,n)
        {
            cout<<sum-b[a[i]]+1<<"\n";
        }
    }
    return 0;
}











































Measured memory_bytes: 5760
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())

    A = [0]*N
    A[0] = 1
    B = [1]*N
    for q in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        if A[x] == 1:
            A[y] = 1
        B[x] -= 1
        B[y] += 1
        if B[x] == 0:
            A[x] = 0

    ans = 0
    for i in range(N):
        if A[i] == 1 and B[i] != 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

const int INF = numeric_limits<int>::max();
const int MAXN = 3e5 + 1;
const int MOD = 1e9 + 7;
const double res = 1e-9;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
#if(DEBUG_LEVEL > 0)
    freopen("../input.txt", "r", stdin);
    freopen("../out.txt", "w", stdout);
#endif
    int n, x;
    cin >> n >> x;
    int now = 0, ans = 1;
    while(n--) {
        int k;
        cin >> k;
        now += k;
        ans += now <= x;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define pii pair<ll,ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(ll i=a;i<=(ll)b;++i)
#define per(i,a,b) for(ll i=a;i>=(ll)b;--i)
#define ll long long
#define lowbit(x) ((x)&(-x))

int main()
{
    int n;cin>>n;
    ll ans=0;
    ans+=n/500*1000;
    n%=500;
    ans+=n/5*5;
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll cnt , sum , c ;
int const N = 100 , m = 1e6+6 , OO = 0x3f3f3f3f;
int main(){
 int a , b , c  ;
 cin >> a >> b >> c ;
 (a+b >= c  ) ? cout << "Yes"<<endl : cout << "No" <<endl;

}




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

namespace abc145
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc145A();
        }

        public static void solve_abc145B()
        {

        }

        public static void solve_abc145A()
        {
            int r = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine(r * r);
        }
    }
}


Measured memory_bytes: 11348
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	int n,t;
	cin >> n>>t;
	int maxx = 9999;
	int a, b;
	for (int i = 1; i <= n; i++) {
		cin >> a >> b;
		if (b <= t) {
			maxx = min(a, maxx);
		}
	}
	if (maxx == 9999)cout << "TLE" << endl;
	else cout << maxx << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    string s,t;
    cin>>s>>t;
    s+=s;
    if((int)s.find(t)>-1||s==t) cout<<"Yes"<<endl;
    else  cout<<"No"<<endl;

    return 0;
}


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

int N;
bool ans = false;

int main() {
  scanf("%d", &N);
  rep(i,10) rep(j,10) if (i * j == N) ans = true;
  if (ans) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n, l, r;
    while (cin >> n >> l >> r and n and l and r) {
        vector<int> a(n);
        rep(i, n) cin >> a[i];
        int ans = 0;
        for (int x=l; x<=r; ++x) {
            bool ok = false;
            rep(i, n) {
                if (x%a[i] == 0) {
                    if (i%2 == 0) ans++;
                    ok = true;
                    break;
                }
            }
            if (!ok) {
                if (n%2 == 0) ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3004
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <ctime>
#include <cstdlib>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 51;
ll f[2][N][N*N];
int n , A , x;

int main(){
    scanf("%d%d",&n,&A);
    int c = 0;
    f[c][0][0] = 1;
    rep(i,0,n){
        scanf("%d",&x);
        c ^= 1;
        memset(f[c] , 0 , sizeof(f[c]));
        rep(j,0,i+1) for(int k=0;k<=2500;++k) if(f[c^1][j][k])
            f[c][j][k] += f[c^1][j][k] ,
            f[c][j+1][k+x] += f[c^1][j][k];
    }
    ll ans = 0;
    rep(i,1,n+1) ans += f[c][i][i*A];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2304
#include <cstdio>
#include<iostream>
#include<string>

using namespace std;
   
int main(void){

	string inp;

	while(cin>>inp){
			 if((inp[0]=='o'&&inp[1]=='o'&&inp[2]=='o')||(inp[3]=='o'&&inp[4]=='o'&&inp[5]=='o')||(inp[6]=='o'&&inp[7]=='o'&&inp[8]=='o')||(inp[0]=='o'&&inp[3]=='o'&&inp[6]=='o')||(inp[1]=='o'&&inp[4]=='o'&&inp[7]=='o')||(inp[2]=='o'&&inp[5]=='o'&&inp[8]=='o')||(inp[0]=='o'&&inp[4]=='o'&&inp[8]=='o')||(inp[2]=='o'&&inp[4]=='o'&&inp[6]=='o')) cout<<"o"<<endl;
		else if((inp[0]=='x'&&inp[1]=='x'&&inp[2]=='x')||(inp[3]=='x'&&inp[4]=='x'&&inp[5]=='x')||(inp[6]=='x'&&inp[7]=='x'&&inp[8]=='x')||(inp[0]=='x'&&inp[3]=='x'&&inp[6]=='x')||(inp[1]=='x'&&inp[4]=='x'&&inp[7]=='x')||(inp[2]=='x'&&inp[5]=='x'&&inp[8]=='x')||(inp[0]=='x'&&inp[4]=='x'&&inp[8]=='x')||(inp[2]=='x'&&inp[4]=='x'&&inp[6]=='x')) cout<<"x"<<endl;
		else cout<<"d"<<endl;
	}

    return 0;
}

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

bool jg(const vector <int >& x, const vector <int >& y) {
    for (int Z = -100; Z <= 100; ++Z) {
        bool ans = true;
        for (int i = 0; i < x.size(); ++i) {
            if (x[i] >= Z) ans = false;
        }
        for (int i = 0; i < y.size(); ++i) {
            if (y[i] < Z) ans = false;
        }
        if (ans) return false;
    }
    return true;
}
int main() {
    int N, M; cin >> N >> M;
    vector <int> x(N + 1), y(M + 1);
    cin >> x[0] >> y[0];
    for (int i = 0; i < N; ++i) {
        cin >> x[i + 1];
    }
    for (int i = 0; i < M; ++i) {
        cin >> y[i + 1];

    }
    if (jg(x, y)) {
        cout << "War" << endl;
    }
    else {
        cout << "No War" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  string op = "+";
  V<> a(n);
  for (int i = 0; i < n; ++i) {
    if (i) {
      char c; cin >> c;
      op += c;
    }
    cin >> a[i];
    if (op[i] == '-') a[i] = -a[i];
  }

  constexpr lint inf = 9e18;
  V<lint> dp(10, -inf);
  dp[0] = a[0];
  for (int i = 1; i < n; ++i) {
    V<lint> ndp(10, -inf);
    for (int x = 0; x < 10; ++x) {
      for (int y = 0; y <= min(x + (op[i - 1] == '-'), 9); ++y) {
        ndp[y] = max(ndp[y], dp[x] + (y & 1 ? -a[i] : a[i]));
      }
    }
    swap(dp, ndp);
  }

  cout << *max_element(begin(dp), end(dp)) << '\n';
}

Measured memory_bytes: 896
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
//priority_queue< int,vector<int>,greater<int> >
struct edge { int to; llint a, b; };

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	whei(int) s(h, hei(int)(w));
	hei(int) a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}
	int x = 0;
	for (int j = 0; j < w;j+=2) {
		rep(i, 0, h) {
			if (!a[x])x++;
			s[i][j] = x + 1;
			a[x]--;
	    }
		if (j+1 == w)break;
		for (int i = h-1; i >= 0; i--) {
			if (!a[x])x++;
			s[i][j+1] = x + 1;
			a[x]--;
		}
	}
	rep(i, 0, h) {
		rep(j, 0, w) {
			cout << s[i][j];
			if (j != w - 1)cout << " ";
			else cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void makegraph(int x,vector<vec> &v){rep(i,x-1){int a=in(),b=in();v[a].pb(b);v[b].pb(a);}}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=924844033;
#define N 355050

ll n,m,k;
ll a[N];
ll x[N];
main(){
    n=in();
    m=in();
    rep(i,m)a[i]=in();
    n--;
    sort(a,a+m);
    rep(i,m-1){
        x[i]=a[i+1]-a[i];
    }
    sort(x,x+m-1);
    ll ans=0;
    rep(i,m-1-n){
        ans+=x[i];
    }
    cout<<ans;
}

Measured memory_bytes: 3072
#pragma GCC optimize("Ofast")
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)	
using namespace std;
int s;
map<int,bool>m;
int main()
{
	cin>>s;
	m[s]=true;
	for (int i=1;;i++)
	{
		if (s%2==0)
		   s=s/2;
		else
		   s=3*s+1;
		
		if (!m[s])
		   m[s]=true;
		else
		{
			cout<<i+1<<endl;
			return 0;
		}
	}
    return 0;
}

Measured memory_bytes: 256
def rr(): return input().rstrip()
def rri(): return int(rr())
def rrl(): return list(map(int, rr().split()))
def rrt(): return tuple(map(int, rr().split()))
from collections import defaultdict
def mus(d=lambda: 0): return defaultdict(lambda: defaultdict(d))
def dd0(d=lambda: 0): return defaultdict(d)
def ms(x, y, d=0): return [[0]*y for i in range(x)]
def ar(x, d=0): return [d]*x
def ppm(m, n=0, x=0, y=0): print("\n".join(("\t".join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))
def ppa(a, n): print("\t".join(map(str, a[0:n])))
def ppl(a=0, x=[1]): x[0]=a or (x[0]+1); print("-"+"- -"*14+"-# "+str(x[0]-2)+" #-"+"- -"*14+"-")
def fltn(a): (i for sub in a for i in sub)
def yn(x): return "YES" if x else "NO"
from itertools import accumulate
from itertools import groupby
def grp(x): return ((i, sum(1 for _ in g)) for i, g in groupby(x))
import math
#def rnar(): return (*rrl(), rrl())
#def rn(): return (*rrl(),)
def dpp(a, b=""): print(")#| {} |#(o) ? {} ? (".format(a, b))

def read():
    n, w = rrl()
    l = [rrt() for _ in range(n)]

    return n, w, l

def solve(n, w, l):
    dp = ms(w+1, n+1)

    for wi in range(1, w+1):
        for ii in range(1, n+1):
            if l[ii-1][0] > wi:
                dp[wi][ii] = dp[wi][ii-1]
            else:
                dp[wi][ii] = max(
                        dp[wi][ii-1],
                        dp[wi-l[ii-1][0]][ii-1] + l[ii-1][1],
                        )
    #ppm(dp, w+1, n+1)

    ans = dp[w][n]
    return ans

if __name__ == "__main__":
    #test_count = rri()
    test_count = 1
    for _ in range(test_count):
        input_data = read()
        result = solve(*input_data)
        print(result)


Measured memory_bytes: 130524
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#define ld long double 
#define ll long long 
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	ll a[n];
	ll i=0;
	ll p=1;
	ld m=1;
	for(i=0;i<n;i++)
	{
		
		cin>>a[i];	
	
	}
	
	for(i=0;i<n;i++)
	{
		
	    p=p*a[i];
	    m=m*a[i];
			
    
	}
	 
	ll k= pow(10,18);
	if(m>k) 
	{
		
		cout<<"-1"<<endl;
		
	}
	
	
	else 
	{
		
		cout<<p<<endl;
		
	}
	

	

	return 0;
	
}

Measured memory_bytes: 4404
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<math.h>
#include <iomanip>

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

using namespace std;

const int INF = 1000;

int N, M;

int d[100];

int A[100][100];

vector< pair<int, int> > V;

int main()
{
	cin >> N;

	rep(i, N) {
		int x, y;
		cin >> x >> y;
		V.push_back(make_pair(x, y));
	}

	double sum = 0;

	vector<int> v;
	rep(i, N)v.push_back(i);

	do {

		rep(i, N - 1) {
			double x = V[v[i]].first - V[v[i + 1]].first;
			double y = V[v[i]].second - V[v[i + 1]].second;

			sum += sqrt(x * x + y * y);
		}

	} while (next_permutation(v.begin(), v.end()));

	rep(i, N) sum /= (i + 1);
	cout << fixed << setprecision(10) << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define lli long long int
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}

int main() {
	lli n, sum = 0;
  cin >> n;
  for(lli i = 1; i <= n; i++){
  	for(lli j = 1; j <= n; j++){
    	for(lli k = 1; k <= n; k++) {
        	sum += gcd(i, gcd(j , k));
        }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3228
open Printf
open Scanf

let read_int _ = scanf " %d " (fun x -> x)

let next u =
  let rec next' = function
    | [] -> (true,[])
    | x::xs -> let (c,u') = next' xs in
      if c
      then if x < 3 then (false,(x+1)::u') else (true,0::u')
      else (false,x::u') in
  let (c,u') = next' u in
  if c then None else Some u'

let calc lu a b c =
  let (a',b',c',k') = List.fold_left (fun (a,b,c,k) (l,v) ->
      match v with
      | 0 -> (a+l,b,  c,  k+1)
      | 1 -> (a,  b+l,c,  k+1)
      | 2 -> (a,  b,  c+l,k+1)
      | _ -> (a,  b,  c,  k  )
    ) (0,0,0,0) lu in
  if a' = 0 || b' = 0 || c' = 0
  then max_int
  else abs (a-a') + abs(b-b') + abs(c-c') + 10*(k'-3)

let f l ini a b c =
  let rec f' u accum =
    let accum' = min (calc (List.combine l u) a b c) accum in
    match next u with
    | None -> accum'
    | Some u' -> f' u' accum' in
  f' ini max_int

let () =
  let n,a,b,c = scanf " %d %d %d %d " (fun n a b c -> (n,a,b,c)) in
  let l = Array.(init n read_int |> to_list) in
  let ini = Array.(make n 0 |> to_list) in
  printf "%d\n" @@ f l ini a b c


Measured memory_bytes: 2560