akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#define bombNumber 9
#define bombChar '#' 
using namespace std;


// Problem https://atcoder.jp/contests/abc075/tasks/abc075_b

vector<vector<int>> solver(int height,int width,vector<string> givenGrid){
    vector<vector<int>> result(height,vector<int> (width,0));
    // 方向操作用vector作成(2つ) 上→右上→右→右下→下→左下→左→左上
    vector<int> dh = {1,1,0,-1,-1,-1,0,1};
    vector<int> dw = {0,1,1,1,0,-1,-1,-1};
    for(int j=0;j<height;j++){
        for(int k=0;k<width;k++){
            char thisPos;
            int thisPosABomb;
            thisPosABomb = 0;
            thisPos = givenGrid.at(j).at(k);
            if(thisPos == bombChar){
                result.at(j).at(k) = bombNumber;
            }
            else{
                for(int m=0;m<8;m++){
                    int nowH = j+dh.at(m);
                    int nowW = k+dw.at(m);
                    if(nowH < 0 || nowW < 0 || 
                    (height-1) < nowH || (width-1) < nowW){
                        continue;
                    }
                    else{
                          if(givenGrid.at(nowH).at(nowW)==bombChar){
                              thisPosABomb=thisPosABomb+1;
                          }  
                    }
                }
                result.at(j).at(k)=thisPosABomb;
            }
        }
    }
    return result;
}

int main(void){
    int H,W;
    cin >> H >> W;
    vector<vector<int>> answer(H,vector<int> (W,0)); 
    vector<string> S;
    S.clear();
    for(int j=0;j<H;j++){
        string s1;
        cin >> s1;
        S.push_back(s1);
    }
    answer=solver(H,W,S);
    for(int j=0;j<H;j++){
        for(int k=0;k<W;k++){
            int answerInt;
            answerInt = answer.at(j).at(k);
            if(answerInt == bombNumber){
                cout << bombChar ;
            }
            else{
                cout << answerInt;
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
const Int MOD = 1e9+7;
Int dp[3][3][314514];
void add(Int &a,Int b){a+=b;a%=MOD;};

signed main(){
  string s;
  cin>>s;
  Int n=s.size();
  
  memset(dp,0,sizeof(dp));
  dp[0][0][0]=1;
  for(Int i=0;i<n;i++){
    for(Int j=0;j<3;j++){
      for(Int k=0;k<3;k++){
	// cout<<i<<":"<<j<<" "<<k<<":"<<dp[j][k][i]<<endl;
	// s[i] == '0' || s[i] == '?'
	if(s[i]!='1') add(dp[j][(k%2)+1][i+1],dp[j][k][i]);
      }
      // s[i] == '1' || s[i] == '?'
      if(s[i]!='0'){
	Int k;
	k = 0; 
	add(dp[min(2LL,j+1)][0][i+1],dp[j][k][i]);
	k = 1;
	add(dp[j][0][i+1],dp[j][k][i]);	  
	k = 2;	
	add(dp[j][k-1][i+1],dp[j][k][i]);
      }
    }    
    // cout<<endl;
  }
  
  Int ans=dp[1][0][n];
  for(Int i=0;i<3;i++) add(ans,dp[2][i][n]);
  cout<<ans<<endl;
  return 0;
}


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

vector<int> solve(int t, string num, vector<int> ret, int i, int k){
  if(i == -1) return ret;
  bool f = false, g = false;
  vector<int> r1, r2;
  if(ret[0] != -1 && ret[0] + k*10*(num[i]-'0') <= t){
    ret[ret.size()-1] += k*10*(num[i]-'0');
    ret[0] += k*10*(num[i]-'0');
    r1 = solve(t,num,ret,i-1,k*10);
    ret[ret.size()-1] -= k*10*(num[i]-'0');
    ret[0] -= k*10*(num[i]-'0');
    f = (r1[0] != -1);
  }
  if(ret[0] != -1 && ret[0] + (num[i]-'0') <= t){
    ret.push_back(num[i]-'0');
    ret[0] += (num[i]-'0');
    r2 = solve(t,num,ret,i-1,1);
    ret.pop_back();
    ret[0] -= (num[i]-'0');
    g = (r2[0] != -1);
  }
  if(f && g){
    if(r1[0] == r2[0]){
      vector<int> r(2,-1);
      r[0] = r1[0];
      return (r);
    }else{
      return max(r1,r2);
    }
  }
  if(f) return r1;
  if(g) return r2;
  vector<int> r(1,-1);
  return r;
}

int main(){
  int t;
  string num;
  while(cin >> t >> num, t){
    int n = num.length();
    vector<int> init(1,num[n-1]-'0');
    init.push_back(num[n-1]-'0');
    vector<int> ans = solve(t,num,init,n-2,1);
    if(ans[0] == -1) cout << "error" << endl;
    else if(ans[1] == -1) cout << "rejected" << endl;
    else{
      cout << ans[0];
      for(int i = ans.size()-1; i > 0; --i)
        cout << " " << ans[i];
      cout << endl;
    }
  }
  return 0;
}



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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};

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

int main() {
    ll Q,H,S,D,N;
    cin>>Q>>H>>S>>D>>N;
    ll best1=S;
    best1=min(S,min(Q*4,H*2));
    ll best2=min(D,2*best1);
    if(N%2==0) cout<<N/2*best2<<endl;
    else cout<<(N-1)/2*best2+best1<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func main() {
	sc := NewScanner()
	N, M := sc.nextInt(), sc.nextInt()
	set := make(map[int][]int)
	for i := 0; i < M; i++ {
		a, b := sc.nextInt(), sc.nextInt()
		set[a] = append(set[a], b)
		set[b] = append(set[b], a)
	}
	var count int
	var search func(next int, seen []int)
	search = func(current int, seen []int) {
		seen = append(seen, current)
		if len(seen) == N {
			count++
			return
		}
		for _, next := range set[current] {
			flg := false
			for _, v := range seen {
				if next == v {
					flg = true
				}
			}
			if flg {
				continue
			}
			nseen := make([]int, len(seen))
			copy(nseen, seen)
			// fmt.Println(next, nseen)
			search(next, nseen)
		}
	}
	search(1, []int{})
	fmt.Println(count)
}


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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  ll x; cin >> x;
  ll ans = x/11*2;
  x -= ans/2*11;
  ans += (x+5)/6;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main(){
   int h,w;
   cin>>h>>w;
   vector<vector<char>> a(h,vector<char>(w));
   vector<vector<char>> b(h,vector<char>(w));
   
   for(int i=0;i<h;i++){
       for(int j=0;j<w;j++)cin>>a[i][j];
   }

   int k=0;
   for(int i=0;i<h;i++){
       bool flag=true;
       for(int j=0;j<w;j++){
           if(a[i][j]=='#')flag=false;
       }
       
       if(!flag){
           for(int j=0;j<w;j++)b[k][j]=a[i][j];
           k++;
       }
   }
   
   int l=0;
   for(int j=0;j<w;j++){
       bool flag=true;
       for(int i=0;i<k;i++){
           if(b[i][j]=='#')flag=false;
       }
       
       if(!flag){
           for(int i=0;i<k;i++)b[i][l]=b[i][j];
           l++;
       }
   }
     
   for(int i=0;i<k;i++){
       for(int j=0;j<l;j++)cout<<b[i][j];
       cout<<endl;
   }
   

}

   


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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

const int dx[4] = {0,  0, 1, -1};
const int dy[4] = {1, -1, 0,  0};

const int N = 100001;
int a[N];
int main() {
	ios_base::sync_with_stdio(0);
	int x;
	cin >> x;
	if (x < 1200)
		cout << "ABC";
	else
		cout << "ARC";
  	return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

s = list(STR())
flag = True
if s.count('N') and not s.count('S'):
    flag = False
if s.count('E') and not s.count('W'):
    flag = False
if not s.count('N') and s.count('S'):
    flag = False
if not s.count('E') and s.count('W'):
    flag = False
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 59736
//
// Created by kuroneko on 2019-07-06.
//

using namespace std;

#include <iostream>
#include <vector>
#include <cmath>
#include <string>

typedef long long ll;
int INF = 1000000007;

int main() {
    int N, K; cin >> N >> K;
    vector<int> v(N);
    int ans = -1e9;
    for (int i = 0; i < N; i++) cin >> v[i];

    for (int a = 0; a <= min(N, K); a++) {
        for (int b = 0; b <= min(N, K) - a; b++) {
            vector<int> tmp;
            for (int i = 0; i < a; i++) tmp.push_back(v[i]);
            for (int i = 0; i < b; i++) tmp.push_back(v[N-1-i]);

            sort(tmp.begin(), tmp.end());
            int sum = 0;
            for (int i = 0; i < tmp.size(); i++) sum += tmp[i];
            for (int i = 0; i < min(K - a - b, int(tmp.size())); i++) {
                if (tmp[i] < 0) sum -= tmp[i];
            }

            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

//2*p + 1

const int MAXN = 1e5 + 10;
int a[MAXN];

int _lcm(int x,int y){
    return (x*y)/__gcd(x,y);
}

void solve(){
    int n,m; cin>>n>>m;

    FOR(i,1,n) cin>>a[i];
    FOR(i,1,n) a[i]/=2;

    set<int> check;
    FOR(i,1,n){
        int x = a[i];
        int cnt = 0;
        while(x%2 == 0){
            cnt++; x/=2;
        }
        check.insert(cnt);
    }

    int lcm = a[1];
    bool flag = true;

    FOR(i,2,n) {
        lcm = _lcm(lcm,a[i]);
        if(lcm > m){
            flag = false; break;
        }
    }

    if(check.size() > 1) flag = false;

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

    int ans = m/lcm;
    ans -= m/(2*lcm);

    cout<<ans<<endl;
}

signed main(){

   FastRead;    

    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 1024
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: i32,
    }

    // 分子はN以下の奇数
    let n: i32 = if N % 2 == 0 { N / 2 } else { (N - 1) / 2 + 1 };

    let ans: f32 = 1.0 * n as f32 / N as f32;
    println!("{}", ans);
}


Measured memory_bytes: 2216
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())



void init() {

}

void input() {

}

bool chk(int a) {
  int k = a%10;
  while(a) {
    if (a%10 != k) return false;
    a /= 10;
  }
  return true;
}

void solve() {
  int n;
  cin >> n;
  FOR(i, 111, 1000) {
    if (i >= n && chk(i)) {
      cout << i << endl;
      return;
    }
  }
}

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


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>

int main() {
    int count[26] = {};
    char ch;

    while (scanf("%c", &ch) != EOF) {
        if (isalpha(ch)) {
            ch = tolower(ch);
            count[ch - 'a']++;
        }
    }
    for (int i = 0; i < 26; i++) {
        printf("%c : %d\n", i + 'a', count[i]);
    }
    return 0;
}


Measured memory_bytes: 2588
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    ll h,n;
    cin>>h>>n;
    ll a;
    ll sum=0;
    rep(i,n){
        cin>>a;
        sum+=a;
    }
    if(h<=sum){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    }


Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main() {
	int a, b ,c, i;
	int x = 0;
	cin >> a >> b >> c;
	for (i = a; i <= b; i++) 
		if (c % i == 0)
			x++;
		cout << x << endl;	
	return 0;
}


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

main(){
	int n,ans,tmp,k;
	int a[100010];
	
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	
	ans = tmp = 0;
	k = a[1];
	for(int i=2;i<=n;i++){
		if(a[i] <= k){
			k = a[i];
			tmp++;
		}
		else{
			k = a[i];
			ans = max(ans,tmp);
			tmp = 0;
		}
	}
	cout<<max(ans,tmp)<<endl;
} 

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        var xys = new KeyValuePair<int, int>[n];
        for (int i = 0; i < xys.Length; ++i)
        {
            var list = Console.ReadLine().Split(' ');
            xys[i] = new KeyValuePair<int, int>(
                int.Parse(list[0]),
                int.Parse(list[1])
            );
        }

        var diffs = new Dictionary<KeyValuePair<long, long>, int>();
        for (int i = 0; i < xys.Length; ++i)
        {
            var a = xys[i];
            for (int j = i + 1; j < xys.Length; ++j)
            {
                var b = xys[j];

                var x = (long)a.Key - b.Key;
                var y = (long)a.Value - b.Value;

                var t = new KeyValuePair<long, long>(x, y);
                int c;
                if (!diffs.TryGetValue(t, out c))
                    c = 0;
                diffs[t] = ++c;

                var u = new KeyValuePair<long, long>(- x, - y);
                if (!diffs.TryGetValue(u, out c))
                    c = 0;
                diffs[u] = ++c;
            }
        }

      var ans = n;
      foreach (var c in diffs.Values)
      {
          var a = n - c;
          if (ans > a)
              ans = a;
      }
        Console.WriteLine(ans);
    }

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 17336
/* ***********************************************
Author        :pkwv
Created Time  :2017年10月22日 星期日 20时04分47秒
File Name     :A.cc
************************************************ */

#include <algorithm>
#include <bitset>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <unordered_map>
#include <vector>

using namespace std;

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
  string s;
	while (std::cin >> s) {
		bool ok{false};
		for (int i = 1; i < s.size(); ++ i) {
			if (s[i - 1] == 'A' && s[i] == 'C') {
				ok = true;
			}
		}
		printf("%s\n", ok ? "Yes" : "No");
	}
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 11;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	fread(cn, 1, cm, stdin);
	int N = getint(), W = getint();

	ll dp[100001] = {};
	rep(i, N) {
		int w = getint();
		int v = getint();
		for (int j = W; j >= w; j--) {
			dp[j] = max(dp[j], dp[j - w] + v);
		}
	}

	printf("%lld", dp[W]);

	Would you please return 0;
}

Measured memory_bytes: 896
# 2019-11-18 23:58:23(JST)
import sys
# import collections
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def primeFactorize(n):
    from math import floor, sqrt
    res = set()
    before = n
    while n % 2 == 0:
        n //= 2
    if n < before:
        res.add(2)
    if n == 1:
        return res
    for i in range(3, floor(sqrt(n))+1, 2):
        before = n
        while n % i == 0:
            n //= i
        if n < before:
            res.add(i)
        if n == 1:
            return res
    res.add(n)
    return res

def main():
    a, b = [int(x) for x in sys.stdin.readline().split()]
    ans = len(primeFactorize(a) & primeFactorize(b)) + 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#E
from math import gcd
N=int(input())

mod=1000000007
ans=1
P=dict()
M=dict()
zero=0
zero1=0
zero2=0
for i in range(N):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif a==0 and b!=0:
        zero1+=1
    elif a!=0 and b==0:
        zero2+=1
    elif (a>0 and b<0) or (a<0 and b>0):
        GCD=gcd(abs(a),abs(b))
        a=abs(a)//GCD
        b=abs(b)//GCD
        s=str(a)+"/"+str(b)
        P[s]=P.get(s,0)+1
        
    else:
        GCD=gcd(abs(a),abs(b))
        a=abs(a)//GCD
        b=abs(b)//GCD
        s=str(b)+"/"+str(a)
        M[s]=M.get(s,0)+1

P["0/0"]=zero1
M["0/0"]=zero2
for v,cnt_p in P.items():
    if v in M:
        cnt_m=M[v]
        ans*=(2**cnt_p+2**cnt_m-1)
        M.pop(v)
    else:
        ans*=2**cnt_p
    ans%=mod
    
for v,cnt_m in M.items():
    ans*=2**cnt_m
    ans%=mod

ans-=1
ans+=zero
ans%=mod
print(ans)

Measured memory_bytes: 134872
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
#define abs(x,y) max(x,y)-min(x,y)
using namespace std;
long long i[10000000];
long long u[1111111];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0;
  string s;
  cin >>s;
  for(int n=0;n<s.size();n++){
    if(s[n]=='N') d++;
    else{
      if(s[n]=='W') e++;
      else{
	if(s[n]=='S') f++;
	else g++;
      }
    }
  }
  if(d>0){
    if(f>0){
      if(e>0){
	if(g>0) cout <<"Yes\n";
	else cout <<"No\n";
      }
      else{
	if(g>0) cout <<"No\n";
	else cout <<"Yes\n";
      }
    }
    else cout <<"No\n";
  }
  else{
    if(f>0) cout <<"No\n";
    else{
      if(e>0){
	if(g>0) cout <<"Yes\n";
	else cout <<"No\n";
      }
      else{
	if(g>0) cout <<"No\n";
	else cout <<"Yes\n";
      }
    }
  }
  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=200010;
vi v;
int a[N];
int main()
{
	int n,x;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[i]=x;
		v.pb(x);
	}
	sort(v.begin(),v.end());
	x=v[n-1];
	x=x/2;
	int y=v[n-1]-x,z=v[0];
	for(int i=0;i<n-1;i++)
	{
		if(min(abs(x-z),abs(y-z))>min(abs(x-v[i]),abs(y-v[i])))
			z=v[i];
	}
	cout<<v[n-1]<<" "<<z;
	return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
long long ans=0;
int main(){
    int k;
    cin>>k;
    for(int i=1;i<=k;i++)
        for(int j=1;j<=k;j++)
            for(int l=1;l<=k;l++)
                ans+=(__gcd(l,__gcd(i,j)));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3604
L = input()
dp1 = [0, 1]
dp2 = [0, 2]
for i in range(1, len(L)):
	if L[i] == '0':
		newdp1 = dp1[-1] * 3
		newdp2 = dp2[-1] 
		dp1.append(newdp1%1000000007)
		dp2.append(newdp2%1000000007)
	else:
		newdp1 = dp1[-1] * 3 + dp2[-1]
		newdp2 = dp2[-1] * 2
		dp1.append(newdp1%1000000007)
		dp2.append(newdp2%1000000007)
print((dp1[-1]+dp2[-1])%1000000007)


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

int q;
std::string str, b, e;

int solve(int m) {
	int cnt = 0;
	while (1) {
		str = std::to_string(m);
		if (str.size() == 1)
			break;
		b.clear();
		e = str;
		int l, r, max = 0;
		for (int i = 0; i < str.size() - 1; ++i) {
			b += str[i];
			e.erase(e.begin());
			l = std::stoi(b);
			r = std::stoi(e);
			max = std::max(max, l*r);
			m = max;
		}
		++cnt;
	}
	return cnt;
}

int main() {
	std::cin >> q;
	int n;
	for (int i = 0; i < q; ++i) {
		std::cin >> n;
		std::cout << solve(n) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3268
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A_sorted = sorted(A, reverse=True)
max_numbers = A_sorted[:M]
A_sum = sum(A)
for i in max_numbers:
    if i < A_sum / (4 * M):
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
ll a[200060],b[300000];
vector<ll>v;
map<ll,ll>mp,mp1;
int main()
{
    IO;
    ll i, j, m, k, l, g=0, mod,t,kk=0,tc, n,mn=INT_MAX;
           cin>>k>>n>>m;
           m/=k; m*=k;
           if(m>=n)cout<<"OK"<<endl;
           else cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int mod = 1e9 + 7;

long long f[100010];
int n, k;

long long pow_mod(long long x, long long y) {
    long long ret = 1, now = x;
    while(y > 0) {
        if(y % 2 == 1) {
            ret *= now;
            ret %= mod;
        }
        now *= now;
        now %= mod;
        y /= 2;
    }
    return ret % mod;
}

long long cal(int x) {
    long long cnt, now = k / x;
    cnt = pow_mod(now, n);
    //if(x == 1) printf("****%d\n", cnt);
    for(int i = 2; ;i++) {
        if(x * i > k) break;
        cnt -= f[x * i];
    }
    return cnt;
}

int main() {
    scanf("%d%d", &n, &k);
    long long ans = 0;
    for(int i = k; i >= 1; i--) {
        f[i] = cal(i);
        //printf("%d %d\n", i, f[i]);
        f[i] %= mod;
        f[i] += mod;
        f[i] %= mod;
        ans += f[i] * i;
        ans %= mod;
        ans += mod;
        ans %= mod;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 2496
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// cout << fixed << setprecision(10);
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

struct UnionFind {
	vector<int> par, rank, cnt;
	UnionFind(int n) : par(n), rank(n, 0), cnt(n, 1){
		for(int i=0; i<n; ++i) par[i] = i;
	}
 
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
 
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
 
		if (rank[x] < rank[y]) swap(x, y);
 
		par[y] = x;
		cnt[x] += cnt[y];
		if (rank[x] == rank[y]) rank[x]++;
	}
 
	bool same(int x, int y) {
		return find(x) == find(y);
	}
 
	int size(int x) {
		return cnt[find(x)];
	}
};


int main(){
	long long H,W; cin >> H >> W;
	if (H % 3 == 0 || W % 3 == 0){
		cout << 0 << endl;
		return 0;
	}
	long long a1,a2,a3,mn = H*W;
	for (long long w = 1; w < W; w++){
		a1 = w*H;
		a2 = (W-w)*(H/2);
		a3 = H*W - a1 - a2;
		long long tmp = max(a1,max(a2,a3)) - min(a1,min(a2,a3));
		mn = min(mn,tmp);

		a2 = ((W-w)/2)*H;
		a3 = H*W - a1 - a2;
		tmp = max(a1,max(a2,a3)) - min(a1,min(a2,a3));
		mn = min(mn,tmp);
	}
	for (long long h = 1; h < H; h++){
		a1 = h*W;
		a2 = (H-h)*(W/2);
		a3 = H*W - a1 - a2;
		long long tmp = max(a1,max(a2,a3)) - min(a1,min(a2,a3));
		mn = min(mn,tmp);

		a2 = ((H-h)/2)*W;
		a3 = H*W - a1 - a2;
		tmp = max(a1,max(a2,a3)) - min(a1,min(a2,a3));
		mn = min(mn,tmp);
	}
	cout << mn << endl;
} 


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

typedef pair<int,int> P;

int main(){
    int n;
    cin>>n;
    vector<P> data;
    for(int i=0; i<n; i++) {
        int a, v;
        cin>>a>>v;
        data.push_back(P(-v,a));
    }
    sort(data.begin(),data.end());
    cout<<data[0].second<<" "<<-data[0].first<<endl;
}

Measured memory_bytes: 1204
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long l, r;
	cin >> l >> r;
	long long a = (l*r) % 2019;
	if (r-l+1>=2019) {
		cout << "0" << endl;
	}
	else {
		for (long long i = l; i <= r; i++) {
			for (long long j = i + 1; j <= r; j++) {
				a = min(a, (i*j) % 2019);
			}
		}
		cout << a << endl;
	}

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define N 100005
#define rep(i, l, r) for(int i=l; i<=r; ++i)
using namespace std;
int t;
int x, m;
ll n;
int pos[N];
int f[N];
int main(){
	scanf("%lld%d%d", &n, &x, &m);
	ll ans=0;
	if(n<=m){
		rep(i, 1, n){
			f[i]=x;
			ans+=x;
			x=1ll*x*x%m;
		}
		printf("%lld", ans);
	}
	else{
		rep(i, 1, m+1){
			f[i]=x;
			if(pos[x]){
				rep(j, 1, pos[x]) ans+=f[j];
				rep(j, pos[x]+1, i) ans+=1ll*f[j]*((n-pos[x]+i-j)/(i-pos[x]));
				printf("%lld", ans);
				break;
			}
			pos[x]=i;
			x=1ll*x*x%m;
		}	
	}
	
	return 0;
}
	

Measured memory_bytes: 2320
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

bool cmp(const string& lhs,const string& rhs)
{
	int lsize=lhs.size();
	int rsize=rhs.size();
	if(lsize!=rsize)
		return lsize<rsize;
	
	for(int i=0;i<lsize;i++)
		if(lhs[i]!=rhs[i])
			return lhs[i]-'0'<rhs[i]-'0';
	return false;
}

int main()
{
	const int cost[]={0,2,5,5,4,5,6,3,7,6};
	const string num[]={"0","1","2","3","4","5","6","7","8","9"};

	int N,M;
	int A[10]={};

	cin >> N >> M;
	for(int i=1;i<=M;i++)
		cin >> A[i];
	
	sort(A+1,A+M+1,greater<int>());

	string dp[10010]={};
	for(int i=0;i<=N;i++)
		dp[i]="";
	for(int i=1;i<=N;i++)
	{
		for(int j=1;j<=M;j++)
		{
			if(i-cost[A[j]]<0)
				continue;
			if(dp[i-cost[A[j]]]=="" && i-cost[A[j]]!=0)
				continue;
			string nxt1=dp[i-cost[A[j]]]+num[A[j]];
			string nxt2=num[A[j]]+dp[i-cost[A[j]]];
			if(cmp(dp[i],nxt1))
				dp[i]=nxt1;
			if(cmp(dp[i],nxt2))
				dp[i]=nxt2;
		}
	}
	
	cout << dp[N] << endl;
	return 0;
}



Measured memory_bytes: 38016
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;
using boost::math::gcd;
using boost::math::lcm;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){cin.tie(nullptr);ios::sync_with_stdio(false);}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

template<class T> void show_(const T& t) {cout<<t;}
template<class T> void show_(const vector<T>& v) {cout<<joined(v);}
void show_(bool b) {cout<<(b?"Yes":"No");}
void show_(double d) {cout<<fixed<<setprecision(12)<<d;}
template<class T, class... TS> void show_(const T& t, TS... ts) {show_(t);cout<<' ';show_(ts...);}
template<class T> void show(const T& t) {show_(t);cout<<LN;}
template<class T, class... TS> void show(const T& t, TS... ts) {show_(t, ts...);cout<<LN;}

int main() {
    int N;
    cin >> N;
    auto as = scan<vector<int>>(N);
    int k = 1;
    for (int a : as) {
        if (a == k) {
            k++;
        }
    }
    if (k == 1) {
        show(-1);
    } else {
        show(N - k + 1);
    }
}


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

int main() {
  int n;
  cin >> n;
  while (n) {
    if (n % 10 == 7) {
      cout << "Yes\n";
      return 0;
    }
    n /= 10;
  }
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 3132
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int coin[] = {10, 50, 100, 500};

int main()
{
    bool first = true;

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        if(first)
            first = false;
        else
            cout << endl;

        vector<int> a(4);
        int sum = 0;
        for(int i=0; i<4; ++i){
            cin >> a[i];
            sum += a[i] * coin[i];
        }

        sum -= n;
        vector<int> b(4);
        for(int i=3; i>=0; --i){
            b[i] = sum / coin[i];
            sum %= coin[i];
        }

        for(int i=0; i<4; ++i){
            int ret = max(0, a[i] - b[i]);
            if(ret > 0)
                cout << coin[i] << ' ' << ret << endl;
        }
    }
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	/*int N, A, B;
	cin >> N >> A >> B;
	cout << min(N * A, B);*/


	/*int N, D;
	cin >> N >> D;
	int x[15][15];
	int ans = 0;
	rep(i, N)rep(j, D)cin >> x[i + 1][j + 1];
	for (int i = 1; i < N; i++) {
		for (int j = i + 1; j <= N; j++) {
			double d = 0;
			for (int k = 1; k <= D; k++) {
				d += pow(x[i][k] - x[j][k], 2);
			}
			d = sqrt(d);
			if (d == floor(d))ans++;
		}
	}
	cout << ans;*/


	ll L, R;
	cin >> L >> R;
	ll ans = 1e10;
	if (R / 3 - L / 3 >= 1 && R / 673 - L / 673 >= 1) {
		ans = 0;
		cout << ans;
		return 0;
	}
	if (ans != 0) {
		for (int i = L % 2019; i < R % 2019; i++) {
			for (int j = i + 1; j <= R % 2019; j++) {
				ll x = (i * j) % 2019;
				if (ans > x)ans = x;
				if (ans == 0)break;
			}
		}
		cout << ans;
	}


	/*int N;
	cin >> N;
	ll a[100005];
	rep(i, N)cin >> a[i + 1];
	ll ans[100005];
	for (int i = 1; i <= N - 2; i++) {

	}*/
	return 0;
}

Measured memory_bytes: 256
import os, sys, re, math

(N, M) = [int(n) for n in input().split()]

stores = []
for i in range(N):
    stores.append([int(n) for n in input().split()])

stores = sorted(stores, key=lambda x: x[0])
total = 0
for (price, stock) in stores:
    total += price * min(stock, M)
    M -= stock
    if M <= 0:
        break

print(total)


Measured memory_bytes: 23772
import math
def choose(n,k):
    return math.factorial(n)//(math.factorial(n-k)*math.factorial(k))
mod = 10**9 +7
N,M,K = map(int,input().split())
ans = 0
memo = choose(N*M-2,K-2)
memo %= mod
#まずはX軸について、総和を考える
d = 1
while d < M:
    ans += d*memo*(M-d)*N*N
    d += 1
    ans %= mod

#Y軸について、総和を考える
d = 1
while d < N:
    ans += d*memo*(N-d)*M*M
    d += 1
    ans %= mod

print(ans)


Measured memory_bytes: 101944
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
unsigned long long a[110000];
int main()
{
    unsigned long long  n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    unsigned long long  max1=2,min1=2;
    for(int i=n;i>=1;i--)
    {
        if(max1<a[i])
        {
            cout<<"-1"<<endl;
            return 0;
        }
        if(min1%a[i]==0)
            min1=min1/a[i]*a[i];
        else
            min1=(min1/a[i]+1)*a[i];
        max1=max1/a[i]*a[i]+a[i]-1;
        if(min1>max1)
        {
            cout<<"-1"<<endl;
            return 0;
        }
    }
    cout<<min1<<" "<<max1<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
	int X, Y, Z, K, S,ans=0;
	cin >> K >> S;
	for(int X=0;X<=K;X++)
		for (int Y = 0; Y <= K; Y++)
		{
			Z = S - X - Y;
			if (Z >= 0&&Z<=K)
				ans++;
		}
	cout << ans << endl;
	return 0;


}	

Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

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

    priority_queue<double, vector<double>, greater<double> > pq;

    for(int i = 0; i < n; ++i) {
        double v = 0.0;
        cin >> v;

        pq.push(v);
    }

    while(pq.size() > 1) {
        double x = pq.top();
        pq.pop();
        double y = pq.top();
        pq.pop();

        pq.push((x + y) / 2.);
    }

    cout << pq.top() << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		int count = 0;
		for (int i = 2; i <= 55555; i++) {
			if (i % 5 == 1 && isPrime(i)) {
				if (count != 0) {
					sb.append(" ");
				}
				sb.append(i);
				count++;
				if (count >= n) {
					break;
				}
			}
		}
		System.out.println(sb);
	}
	
	static boolean isPrime(int x) {
		for (int i = 2; i * i <= x; i++) {
			if (x % i == 0) {
				return false;
			}
		}
		return true;
	}
}


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

long long getMax(long long x, long long y){
	if(x >= y)
		return x;
		
	return y;
}

long long getMax2(long long* arr){
	long long val = 0ll;
	for(int i = 0; i < 4; i++)
		val = getMax(val,arr[i]);
	
	return val;
}

int main() {
	// your code goes here
	int r,c,k,x,y;
	cin >> r >> c >> k;
	long long dp[r+1][c+1][4];
	long long prev_dp[c+1][4];
	long long new_dp[c+1][4];
	int grid[r+1][c+1];
	for(int i = 0; i <= r; i++){
		for(int j = 0; j <= c; j++){
			grid[i][j] = 0;
		}
	}
	
	for(int i = 0; i <= c; i++){
		for(int j = 0; j < 4; j++){
			prev_dp[i][j] = 0ll;
			new_dp[i][j] = 0ll;
		}
	}
	
	int v;
	
	for(int i = 0; i < k; i++){
		cin >> x >> y >> v;
		grid[x][y] = v;
	}
	
	for(int row = 1; row <= r; row++){
		for(int col = 1; col <= c; col++){
			new_dp[col][0] = getMax(new_dp[col-1][0],getMax2(prev_dp[col]));
			if(grid[row][col]){
				for(int taken = 0; taken < 3; taken++){
					new_dp[col][taken+1] = getMax(new_dp[col-1][taken],getMax2(prev_dp[col]))+grid[row][col];
				}
			}
			for(int taken = 0; taken < 4; taken++){
				new_dp[col][taken] = getMax(new_dp[col][taken],new_dp[col-1][taken]);
			}
		}
		
		for(int i = 0; i <= c; i++){
			for(int j = 0; j < 4; j++){
				prev_dp[i][j] = new_dp[i][j];
				new_dp[i][j] = 0ll;
			}
		}
	}
	
	cout << getMax2(prev_dp[c]) << '\n';
	return 0;
}

Measured memory_bytes: 38928
N=int(input())
n=int(N**0.5)
l=[]
for i in range(1,n+1):
  ll=[]
  if N%i==0:
    ll.append(i)
    ll.append(int(N/i))
    l.append(ll)
mins=10**12
for j in range(len(l)):
  s=l[j][0]-1+l[j][1]-1
  if s<mins:
    mins=s
print(mins)

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

int main() {
    vector<int> L(4);
    string s;
    cin >> s;
    for (int i = 0; i < 4; i++)
    {
        L[i] = (int)(s[i] - '0');
    }

    for (int tmp = 0; tmp < (1 << 3); tmp++) {
        bitset<3> b(tmp);
        int sum = L[0];
        string res = "";
        res += to_string(L[0]);

        for (int i = 0; i < 3; i++) {
            if (b.test(i)) {
                sum += L[i + 1];
                res += "+" + to_string(L[i + 1]);
            }
            else
            {
                sum -= L[i + 1];
                res += "-" + to_string(L[i+1]);
            }
        }
        if (sum == 7) {
            cout << res << "=7" << endl;
            break;
        }
    }
}

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

int main(int argc, char** argv)
{
	/*
	問題文
英大文字からなる文字列 S が与えられます。S の部分文字列 (注記を参照) であるような最も長い ACGT 文字列 の長さを求めてください。
ここで、ACGT 文字列とは A, C, G, T 以外の文字を含まない文字列です。

注記
文字列T の部分文字列とは、T の先頭と末尾から0 文字以上を取り去って得られる文字列です。
例えば、ATCODER の部分文字列には TCO, AT, CODER, ATCODER,  (空文字列) が含まれ、AC は含まれません。
	*/

	// input = 文字列
	string S;
	cin >> S;

	// S の最大の長さを教えてくださいます？
	// 変数にしなくても構いませんわ
	// ただ計算量を見積もりたいだけです//
	
	/*
	制約S は長さ 1 以上 10 以下の文字列である。
	S の各文字は英大文字である。
	*/
	// ありがとう
	// これなら O(n^2) でも余裕ですわね
    //  その通りですわ
	int ans=0;
	int b = ans;
	std::set<char> acgtm = { 'A', 'C', 'G', 'T' };
	// タイが曲がっていてよ、だった
	// https://dic.nicovideo.jp/a/%E5%B0%8F%E7%AC%A0%E5%8E%9F%E7%A5%A5%E5%AD%90
	for (int i = 0; i < S.length(); i++) {
		if (acgtm.find(S[i]) != acgtm.end()) {
			ans++;
			b = max(b, ans);
		} else {
			ans = 0;
		}
		//for (int j = 0; j < 4; j++) {
		//	if (S[i] == acgt[j]) {
		//		ans++;
		//		b = max(b, ans);
		//		break;
		//	}
		//	if (j == 3) {
		//		ans = 0;
		//	}
		//}
	}
	// std::max と衝突しますことよ
	
	
	// はやくしてくださいます？
	// output = 部分文字列の長さ
	std::cout << b << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>

using namespace std;

int n;
vector<int>a;

int main(){
  cin>>n;
  a.resize(n);
  int max_a=0;
  int max_ind=0;
  for(int i= 0;i<n;i++){
    cin>>a.at(i);
    if(max_a<a.at(i)){
      max_a=a.at(i);
      max_ind=i;
    }
  }
  int second_max=0;
  for(int i=0;i<n;i++){
  	if(i==max_ind)continue;
    if(second_max<a.at(i)){
      second_max=a.at(i);
    }
  }
  for(int i=0;i<n;i++){
  	if(i==max_ind)cout <<second_max<<endl;
    else cout <<max_a<<endl;
  }
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;
typedef pair<int, int> pii;

int main(){
    int N;
    cin >> N;
    vector<bool> sl(N, 0);
    vector<pii> rs;
    vector<pii> bs;
    rep(i, N){
        int x, y;
        cin >> x >> y;
        pii p = {x, y};
        rs.push_back(p);
    }

    rep(i, N){
        int x, y;
        cin >> x >> y;
        pii p = {x, y};
        bs.push_back(p);
    }
    sort(rs.begin(), rs.end());
    reverse(rs.begin(), rs.end());
    sort(bs.begin(), bs.end());
    reverse(bs.begin(), bs.end());
    int ans = 0;
    rep(j, rs.size()){
        pii r = rs[j];
        int bIndex = -1;
        int tmp = 1e9;
        rep(i, bs.size()) {
            if (sl[i]) {
                continue;
            }
            pii b = bs[i];
            if(r.first >= b.first) {
                break;
            }
            if(r.second < b.second && b.second < tmp) {
                tmp = b.second;
                bIndex = i;
            }
        }
        if(bIndex != -1) {
            sl[bIndex] = true;
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> L(2 * N);
  for (int i = 0; i < 2 * N; i++)
    cin >> L.at(i);
  sort(L.begin(), L.end());
  int ans = 0;
  for (int i = 0; i < 2 * N; i += 2)
    ans += L.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
//19234567892927;
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	int n,bi,i,j,b,ans=-mod;cin>>n;
	vector<int> mise(n);
	vector<array<int,11>> rieki(n);
	for(i=0;i<n;i++){
		int a=0;
		for(j=0;j<10;j++){
			int x;cin>>x;
			if(x==1){a+=(1<<j);}
		}
		mise[i]=a;
	}
	for(i=0;i<n;i++){for(j=0;j<=10;j++){cin>>rieki[i][j];}}
	for(bi=1;bi<1024;bi++){
		int gen=0;
		for(i=0;i<n;i++){
			int kab=0;
			for(j=0;j<10;j++){
				if((bi&mise[i]&(1<<j))!=0){kab++;}
			}
			gen+=rieki[i][kab];
		}
		maxeq(ans,gen);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())

s_list = []
for i in range(n):
    s_list.append(input())

# print(s_list.count("AC"))

# print(s_list)

print("AC x {0}".format(s_list.count("AC")))
print("WA x {0}".format(s_list.count("WA")))
print("TLE x {0}".format(s_list.count("TLE"))) 
print("RE x {0}".format(s_list.count("RE")))

# print("AC x {0}".format(”AC” in s_list))
# print("WA x {0}".format(”WA” in s_list))
# print("TLE x {0}".format(”TLE” in s_list)) 
# print("RE x {0}".format(”RE” in s_list))

Measured memory_bytes: 16284
n1, n2, n3, n4= list(map(int, input().split()))
cand = [n1,n2,n3,n4]
result=[0,0,0,0]
for i in cand:
  if i == 1:
    result[0]=1
  elif i == 9:
    result[1]=1
  elif i == 7:
    result[2]=1
  elif i == 4:
    result[3]=1
    
if result == [1,1,1,1]:
  print("YES")
else:
  print("NO")

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

typedef long long ll;

ll gcd(ll x, ll y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    rep(i, N) cin >> x[i];
    int ans = abs(X - x[0]);
    rep(i, N) ans = gcd(ans, abs(X - x[i]));
    cout << ans << "\n";
}

Measured memory_bytes: 640