akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll n, m;
vector<pair<ll, pair<ll, ll> > > v;

vector<int> uf, usz;
int nc;

void init(int n) {
  vector<int> uf_(n);
  vector<int> usz_(n, 1);
  uf = uf_;
  usz = usz_;
  nc = n;

  for (int i = 0; i < uf.size(); i++) {
    uf[i] = i;
  }
}

int find(int a) {
  return (uf[a] == a) ? a : uf[a] = find(uf[a]);
}

void union_(int a, int b) {
  a = find(a);
  b = find(b);

  if (a != b) {
    if (usz[a] >= usz[b]) {
      swap(a, b);
    }
    uf[a] = b;
    usz[b] += usz[a];
    nc--;
  }
}

int check(int a, int b) {
  return (find(a) == find(b)) ? 1 : 0;
}

int get_size(int a) {
  return usz[find(a)];
}

ll d[100005];

ll check(ll p) {
  clr(d, 0);
  init(n);
  d[n-1] = 1;
  rep(i, 0, v.sz) {
    if(v[i].se.fi==n-1&&v[i].fi == p){
      union_(v[i].se.fi, v[i].se.se);
      d[v[i].se.se] = 1;
    }
    if (v[i].se.fi!=n-1) {
      if (d[v[i].se.fi] == 1) {
        union_(v[i].se.fi, v[i].se.se);
        d[v[i].se.se] = 1;
      }
    }
  }
  if (d[0] == 1)return 1;
  return 0;
}

int main() {
  cin >> n >> m;
  vector<ll> ve;
  rep(i, 0, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    v.pb(mp(c, mp(b, a)));
    if (b == n - 1) {
      ve.pb(c);
    }
  }
  sort(all(v));
  reverse(all(v));
  sort(all(ve));
  if(ve.sz==0){
    cout << -1 << endl;
    return 0;
  }
  ll mx = -1;
  for(int i = ve.sz-1; i >= 0; i--){
    if(check(ve[i])==1){
      mx = max(mx,ve[i]);
    }
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 9000
using System;

class S
{
	static void Main()
	{
		var M = 1000000007;
		var k = Console.ReadLine();
		var d = int.Parse(Console.ReadLine());
		var n = k.Length;

		var dp = new long[n + 1, d, 2];
		dp[0, 0, 0] = 1;

		for (int i = 1; i <= n; i++)
		{
			var c = k[i - 1] - '0';

			for (int x = 0; x <= 9; x++)
				for (int j = 0; j < d; j++)
				{
					dp[i, (j + x) % d, x == c ? 0 : 1] += x <= c ? dp[i - 1, j, 0] : 0;
					dp[i, (j + x) % d, 1] += dp[i - 1, j, 1];
				}

			for (int j = 0; j < d; j++)
				for (int f = 0; f < 2; f++)
					dp[i, j, f] %= M;
		}
		Console.WriteLine((dp[n, 0, 0] + dp[n, 0, 1] + M - 1) % M);
	}
}


Measured memory_bytes: 26080
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if ((h | w) == 0)
                break;
            Set<String> set = new HashSet<String>();
            char[][] d = new char[h][w];
            for (int i = 0; i < h; i++) {
                d[i] = sc.next().toCharArray();
            }
            int max = 0;
            String ans = "";
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    int[] dx = { 0, 1, 1, 1, 0, -1, -1, -1 };
                    int[] dy = { -1, -1, 0, 1, 1, 1, 0, -1 };
                    int x = j;
                    int y = i;
                    for (int k = 0; k < 8; k++) {
                        StringBuilder sb = new StringBuilder();
                        sb.append(d[y][x]);
                        int nx = x;
                        int ny = y;
                        while (true) {
                            nx = nx + dx[k];
                            ny = ny + dy[k];
                            if (nx >= w) {
                                nx = 0;
                            } else if (nx < 0) {
                                nx = w - 1;
                            }
                            if (ny >= h) {
                                ny = 0;
                            } else if (ny < 0) {
                                ny = h - 1;
                            }
                            if (nx == x && ny == y) {
                                break;
                            }
                            sb.append(d[ny][nx]);
                            String str = sb.toString();
                            if (set.contains(str)) {
                                if (str.length() > max) {
                                    max = str.length();
                                    ans = str;
                                } else if (max == str.length()) {
                                    if (str.compareTo(ans) < 0) {
                                        ans = str;
                                    }
                                }
                            } else
                                set.add(str);
                        }
                    }
                }
            }
            System.out.println(ans.equals("") ? 0 : ans);
        }
    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }
}

Measured memory_bytes: 66000
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);++i)
#define pb(x) push_back(x)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
using namespace std;
typedef long long LL;
const int M = 1200000;
const int inf = 0x3f3f3f3f;
bool con[3][3][4222]={0};
string a[3];
void ini(int x,int y){
	int n=SZ(a[x]);
	int m=SZ(a[y]);
	fo(i,0,n-1){
		int u=i,v=0;
		while(u<n && v<m) {
			if(a[x][u]==a[y][v] || a[x][u]=='?' || a[y][v]=='?') {
				++u; ++v;
			}
			else break;
		}
		if(u==n || v==m)
			con[x][y][i] = 1;
	}
}
int cal(int x, int y, int z) {
	int n = SZ(a[x]);
	int m = SZ(a[y]);
	int k = SZ(a[z]);
	int ret = n + m + k;
	fo(i, 0, n-1) {
		if(!con[x][y][i]) continue;
		fo(j, 0, m-1) {
			if(!con[y][z][j]) continue;
			if((i+j)<n && !con[x][z][i+j]) continue;
			int ed = max(n, i+m);
			ed = max(ed, i+j+k);
			ret = min(ret, ed);
		}
		ret = min(ret, max(n+k,i+m+k));
		fo(j, i+m, n-1) {
			if(!con[x][z][j]) continue;
			ret = min(ret, max(n, j+k));
		}
	}
	fo(j, 0, m-1) {
		if(!con[y][z][j]) continue;
		ret = min(ret, n+max(j+k, m));
	}
	return ret;
}
int main() {
	cin>>a[0]>>a[1]>>a[2];
	fo(i,0,2)
		fo(j,0,2){
			if(i!=j)
				ini(i,j);
			//cerr << i << ' ' << j << ":";
			//fo(x, 0, 3)
				//cerr << con[i][j][x] << ' ';
			//cerr << endl;
		}
	int per[3] = {0,1,2};
	int ans = SZ(a[0]) + SZ(a[1]) + SZ(a[2]);
	do{
		int ret = cal(per[0], per[1], per[2]);
		ans = min(ans, ret);
	}while(next_permutation(per, per+3));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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



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

    string S;cin >> S;
    bool ren = false;
    int ans = 0;
    int outp = 0;
    for(int i = 0;i<3;i++){
        if(S.at(i) == 'R'){
            if(!ren) {
                ren = true;
                ans = 1;
                outp = max(outp,ans);
                continue;
            }
            if(ren){
                ans++;
                outp = max(outp,ans);
            }
        }
        else{
            ren = false;
            ans = 0;
            outp = max(outp,ans);
        }
    }
    cout << outp << endl;
}


Measured memory_bytes: 3612
def main():
    K = int(input())
    A, B = (int(x) for x in input().split())
    k = False
    for i in range(A, B + 1):
        if i % K == 0:
            k = True

    if k:
        print("OK")
    else:
        print("NG")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9124
#include <iostream>  
#include <vector>  
#include <string>  
#include <algorithm>  
#include <cstdio>  
#include <cstring>  
#include <ctime>  
#include <cstdlib>  
#include <set>  
#include <map>  
#include <cctype>  
#include <list>  
#include <cmath>  
#include <bitset>  
#include <queue>  
#include <stack>  
#include <sstream>  
#include <functional>  
#include <cassert>  
using namespace std;  
  
#define tmax(a, b) if (b > a) a = b  
#define tmin(a, b) if (b < a) a = b  
char inc() { char _[10]; scanf("%s", _); return _[0]; }  
int ini() { int _; scanf("%d", &_); return _; }  
long long inll() { long long _; scanf("%I64d", &_); return _; }  
double ind() { double _; scanf("%lf", &_); return _; }  
string ins() { string _; cin >> _; return _; }  
int inl(char _[]) { if (!fgets(_, (int)1e8, stdin)) return -1; int i = strlen(_); if (_[i - 1] == '\n') _[--i] = 0; return i; }  
  
typedef pair<int, int> pii;  
typedef pair<char, char> pcc;  
typedef long long LL;  
const int inf = 0x3f3f3f3f;  
const LL lnf = 0x3f3f3f3f3f3f3f3f;  
const double pi = 3.14159265358979323846;  
const double eps = 1e-8;  
const int mod = 100007;  
const int maxn = 200+ 10;  

  
int main() {  
    int CAS = 0;  
    //std::ios::sync_with_stdio(0);  
    //std::cin.tie(0);  
#ifdef NIGHT_13  
    freopen("in.txt", "r", stdin);  
   // freopen("out.txt", "w", stdout);  
    int time_night_13 = clock();  
#endif // NIGHT_13  
  
	int x, a, b;
	while (scanf("%d%d%d", &x, &a, &b) != EOF) {
		int st = -a, ed = -a + b;
		if (ed <= 0) puts("delicious");
		else if (ed <= x) puts("safe");
		else puts("dangerous");
	}
  
#ifdef NIGHT_13  
    fprintf(stderr, "\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");  
    fprintf(stderr, "\t   Time: %d ms", (int)clock() - time_night_13);  
    fprintf(stderr, "\n...........................................\n\n");  
#endif // NIGHT_13  
    return 0;  
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long a,b,l,n;
string s;
int main() {
	
  cin >> n;
  
  int a[n];
  
  for (int i=0; i<n; i++){
    	cin >> a[i];
  	}
  
  int l=0,k=0;

  for (int i=0; i<n; i++){
  	  if (a[i]!=l+1){
        l--;
        k++;
      }

      l++;
  }
  
  if (k==n)
    cout << -1 << endl;
  else
    cout << k << endl;
    
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(){
  int A, B; cin >> A >> B;
  int ans = A - B;
  if(ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N;
  cin >>N;
  int tokutenA=0;
  int tokutenB=0;
  for(int i=0;i<N;i++){
    vector<string> s(2);
    cin>>s.at(0)>>s.at(1);
    string t[2];
    t[0]=s.at(0);
    t[1]=s.at(1);
    sort(s.begin(),s.end());
    if(s.at(0)==t[0]){
      if(s.at(0)==t[1]){
        tokutenA++;
        tokutenB++;
      }else{        
        tokutenB+=3;
      }
    }else{
        tokutenA+=3;
    } 
  }
  cout<<tokutenA<<" "<<tokutenB<<endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

int main()
{
    int n, m;
    rep(i, 3)
    {
        int a, b, c;
        cin >> a >> b >> c;
        if (!i)
        {
            n = abs(a - b);
            m = abs(b - c);
        }
        else
        {
            if ((n != abs(a - b)) || m != abs(b - c))
            {
                cout << "No" << endl;
                return (0);
            }
        }
    }

    cout << "Yes" << endl;
    return (0);
}


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

namespace test
{
    class Program
    {
        static List<int>[] to;
        static List<int>[] rto;
        static bool[] reach1;
        static bool[] reachN;
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var M = input[1];
            var P = input[2];
            var edge = new int[M][];
            to = new List<int>[N].Select(l => l = new List<int>()).ToArray();
            rto = new List<int>[N].Select(l => l = new List<int>()).ToArray();
            reach1 = new bool[N];
            reachN = new bool[N];
            for (int i = 0; i < M; i++)
            {
                input = ReadArrayInt();
                var A = --input[0];
                var B = --input[1];
                var C = -(input[2] - P);
                edge[i] = new int[3];
                edge[i][0] = A;
                edge[i][1] = B;
                edge[i][2] = C;
                to[A].Add(B);
                rto[B].Add(A);
            }
            Dfs1(0);
            DfsN(N - 1);
            var D = Enumerable.Repeat((long)int.MaxValue, N).ToArray();
            D[0] = 0;
            for (int i = 0; i < N; i++)
            {
                var update = false;
                for (int j = 0; j < M; j++)
                {
                    var from = edge[j][0];
                    var to = edge[j][1];
                    var cost = edge[j][2];
                    if (!reach1[from] || !reachN[to]) continue;
                    if (D[from] != int.MaxValue && D[from] + cost < D[to])
                    {
                        D[to] = D[from] + cost;
                        update = true;
                    }
                }
                if (!update) break;
                if (i == N - 1)
                {
                    Console.WriteLine(-1);
                    Console.ReadLine();
                    return;
                }
            }

            Console.WriteLine(Math.Max(-D[N - 1], 0));
            Console.ReadLine();
        }

        static void Dfs1(int v)
        {
            if (reach1[v]) return;
            reach1[v] = true;
            foreach(var u in to[v])
            {
                Dfs1(u);
            }
        }
        static void DfsN(int v)
        {
            if (reachN[v]) return;
            reachN[v] = true;
            foreach (var u in rto[v])
            {
                DfsN(u);
            }
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 16468
import math

A ,B ,H ,M =map(int,input().split())

dighour:float = 30*H + M*0.5
digmin:float =  M * 6
length:float = 0

deg = abs(dighour-digmin)
length = math.sqrt(A**2 + B**2 - (2 * A * B * math.cos(math.radians(deg))))

'''
if dighour > digmin and abs(dighour - digmin) <= 180:
    length = math.sqrt((A **2 + B **2) - ((2*A*B) * math.cos(math.radians(abs(dighour-digmin)))))
elif dighour > digmin and abs(dighour - digmin) > 180:
    length = math.sqrt((A **2 + B **2) - ((2*A*B) * math.cos(math.radians(360 - abs(dighour-digmin)))))
elif dighour < digmin and abs(digmin - dighour) <= 180:
    length = math.sqrt((A **2 + B **2) - ((2*A*B) * math.cos(math.radians((abs(digmin-dighour))))))
elif dighour < digmin and abs(digmin - dighour) > 180:
    length = math.sqrt((A **2 + B **2) - ((2*A*B) * math.cos(math.radians((360 - abs(digmin-dighour))))))
'''

print(length)

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 入れない品物の最小値をa[k]とするとW-a[k]+1以上W以下に収めるだけでいい
// コーナー) 全部入る場合,

int n, W, a[200];
ll dp[202][20202], res, bas;

signed main() {
	cin >> n >> W;
	rep(i,n) {
		cin >> a[i];
		if (a[i]>W) i--, n--;
	}
	if (accumulate(a,a+n,0)<=W) return cout << 1 << ln, 0;
	sort(a,a+n);
	rep(k,n) {
		if (k!=0) bas += a[k-1];
		if (bas>W) break;
		int l = max(0,W-a[k]+1), r = W;
		zero(dp);
		dp[k+1][bas] = 1;
		reps(i,k+1,n) rept(j,20000) {
			(dp[i+1][j] += dp[i][j]) %= mod;
			if (j+a[i]<=W) (dp[i+1][j+a[i]] += dp[i][j]) %= mod;
		}
		repst(i,l,r) (res += dp[n][i]) %= mod;
	}
	cout << res << ln;
}


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

int main() {
    int N;
    cin >> N;
    vector<ll> a(3*N);
    rep(i, 3*N) cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll sum = 0;
    rep(i, N) {
        sum += a[2*i + 1];
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long MOD = 998244353;

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

    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    for (int i = 0; i < h; i++)
        cin >> v[i];
    vector<vector<int> > ans(h, vector<int>(w, INT_MAX));
    ans[h - 1][w - 1] = 0;
    for (int c = w - 1; c > 0; c--) {
        for (int i = h - 1, j = c; i >= 0 && j < w; i--, j++) {
            if (j > 0) ans[i][j - 1] = min(ans[i][j - 1], ans[i][j] + ((v[i][j] == v[i][j - 1]) ? 0 : 1));
            if (i > 0) ans[i - 1][j] = min(ans[i - 1][j], ans[i][j] + ((v[i][j] == v[i - 1][j]) ? 0 : 1));
        }
    }
    for (int r = h - 1; r > 0; r--) {
        for (int i = r, j = 0; i >= 0 && j < w; i--, j++) {
            if (j > 0) ans[i][j - 1] = min(ans[i][j - 1], ans[i][j] + ((v[i][j] == v[i][j - 1]) ? 0 : 1));
            if (i > 0) ans[i - 1][j] = min(ans[i - 1][j], ans[i][j] + ((v[i][j] == v[i - 1][j]) ? 0 : 1));
        }
    }

    if (ans[0][0] % 2 == 0) {
        ans[0][0] /= 2;
        if (v[0][0] == '#')
            ans[0][0]++;
    } else
        ans[0][0] = (ans[0][0] + 1) / 2;
    cout << ans[0][0];
}

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

typedef pair <int, int> pii;

const int MAXN = 1e5 + 5;

int N;
pii p[MAXN];

bool cmp(const pii &l, const pii &r) {
	return l.first + l.second > r.first + r.second;
}

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%d%d", &p[i].first, &p[i].second);
	
	sort(p, p + N, cmp);
	
	long long ans = 0;
	for (int i = 0; i < N; i++)
		if (i % 2)
			ans -= p[i].second;
		else
			ans += p[i].first;
	
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 1024
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = [1];
  var dp = new Array(N + 1).fill(100007);
  dp[0] = 0;
  for(var i = 1; i <= 9; i++){
    var six = Math.pow(6,i);
    if(six <= N){
      list.push(six);
    }
    var nine = Math.pow(9,i);
    if(nine <= N){
      list.push(nine);
    }
  }
  list.sort(function(a,b){
  	return a - b;
  });
  for(var i = 0; i < list.length; i++){
    for(var j = list[i]; j <= N; j++){
      dp[j] = Math.min(dp[j],dp[j - list[i]] + 1);
    }
    
    //myerr(dp);
  }
  //myerr(list);
  
  myout(dp[N]);
}

Measured memory_bytes: 9548
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;cin>>n;
  ll ans=0;
  ll a,b;cin>>a>>b;
  for(int i=1;i<n;i++){
    ll c,d;cin>>c>>d;
    ll e,f;
    if(a%c==0)e=a/c;else e=a/c+1;
    if(b%d==0)f=b/d;else f=b/d+1;
    a=c*max(e,f);
    b=d*max(e,f);
    //cout<<a<<" "<<b<<endl;
  }
  cout<<a+b<<endl;
  return 0;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())
ans = 0
if X == 1:
    ans += 300000
elif X == 2:
    ans += 200000
elif X == 3:
    ans += 100000

if Y == 1:
    ans += 300000
elif Y == 2:
    ans += 200000
elif Y == 3:
    ans += 100000

if X == 1 and Y == 1:
    ans += 400000

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    string s; cin >> s;
    int k; cin >> k;
    char num= '1';
    rep(i,k)if(s[i] != '1'){num =s[i];break;}
    cout << num << endl;
}




Measured memory_bytes: 256
import sys,itertools
from collections import deque

input = sys.stdin.readline


def _main():
    IN = input()
    area = 0
    all_area_stack = deque([])
    local_spot_stack = deque([])
    for i, op in enumerate(IN):
        if(op == '\\'):
            all_area_stack.append(i)
        elif(op == '/' and len(all_area_stack) > 0):
            i_p = all_area_stack.pop()
            area += (i - i_p)
            local_area = i - i_p
            while(len(local_spot_stack) > 0 and local_spot_stack[-1][0] > i_p):
                top_i, top_area = local_spot_stack.pop()
                local_area += top_area
            local_spot_stack.append((i, local_area))
    
    spots = [str(spot[1]) for spot in local_spot_stack]
    str_spots = ' '.join(spots)
    print(area)
    if(len(local_spot_stack) > 0):
        print('{} {}'.format(len(local_spot_stack), str_spots))
    else:
        print(0)





if __name__ == "__main__":
    _main()


Measured memory_bytes: 6620
<?php
fscanf(STDIN, "%d %d", $n, $k);
$j = $n - $k;
while ($n--) {
	fscanf(STDIN, "%d", $h[]);
}
sort($h);
$x = PHP_INT_MAX;
for ($i = 0; $i <= $j; $i++) {
	$v = $h[$i+$k-1] - $h[$i];
	if ($v < $x) $x = $v;
}
echo $x;

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

int b[65];
int main() {
    int n;
    cin >> n;
    int ct = 0;
    long long mo = 1000000007;
    for(int i=0;i<n;i++)
    {
        long long x;
        cin >> x;
        int ct = 0;
        while(x)
        {
            b[ct] += (x % 2);
            x /= 2;
            ct++;
        }
            
    }
    
    long long ans = 0;
    long long temp = 1;
    for(int i=0;i<=60;i++)
    {
        ans = (ans + (((b[i] * (n - b[i] + mo))%mo)*temp)%mo)%mo;
        temp = (temp * 2) % mo;
    }
    cout << ans;
    
	return 0;
}


Measured memory_bytes: 256
n, q = gets.chomp.split.map(&:to_i)
p = [] * n
h = Hash.new(0)
n.times do
  l = gets.chomp.split
  p << [l[0], l[1].to_i]
end

ela = 0
while !p.empty?
  p_name, time = p.shift

  change = [time, q].min
  ela += change

  if change == time
    h[p_name] = ela
  else
    p << [p_name, time - q]
  end
end
h.keys.each{|key| puts "#{key} #{h[key]}"}


Measured memory_bytes: 16840
n = input()
k = int(input())

# dp[i桁まで][非0個数][未満フラグ]
dp = [[[0]*2 for _ in range(k+1)] for _ in range(len(n)+1)]
dp[0][0][0] = 1

for i in range(len(n)):
    x = int(n[i])
    for j in range(k):
        dp[i+1][j+1][1] += dp[i][j][1]*9
        dp[i+1][j][1] += dp[i][j][1]
        if x>0:
            dp[i+1][j][1] += dp[i][j][0]
            dp[i+1][j+1][1] += dp[i][j][0]*(x-1)
            dp[i+1][j+1][0] += dp[i][j][0]
        else:
            dp[i+1][j][0] += dp[i][j][0]
    dp[i+1][k][1] += dp[i][k][1]
    dp[i+1][k][x>0] += dp[i][k][0]

print(sum(dp[len(n)][k]))

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

string s;

int main(){
	cin>>s;
  cout<<s.substr(0,s.size()-8)<<endl;
	return 0;
}


Measured memory_bytes: 256
n, m = [int(item) for item in input().split()]
edge = [[0]*n for _ in range(n)]
for i in range(m):
    a, b = [int(item) for item in input().split()]
    edge[a-1][b-1] = 1
    edge[b-1][a-1] = 1

ans = 0
order = 0
pre = [-1]*n
low = [-1]*n
def dfs(node, prev):
    global order, ans
    pre[node] = order
    low[node] = order
    order += 1
    for to in range(n):
        if to == prev or edge[node][to] == 0:
            continue
        if pre[to] == -1:
            ret = dfs(to, node)
            low[node] = min(low[node], ret)
        else:
            low[node] = min(low[node], pre[to])
        if pre[node] < low[to]:
            ans += 1
    return low[node]
    
dfs(0, -1)
print(ans)

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

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

int main(){
    int n;
    cin >> n;
    vector<long long> v(n);
    long long  ans=1;
    for(int i=0; i<n; i++){
        cin >> v[i];
        ans = lcm(ans,v[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int H[] = new int[9999];
    int W[] = new int[9999];
    int i=0;

    H[0]=1;
    W[0]=1;
    do{
      H[i] = scanner.nextInt();
      W[i] = scanner.nextInt();
      i++;
    }while((!(H[i-1]==0&&W[i-1]==0)));

    for (int j=0;j<i-1;j++){
      for(int k=0;k<H[j];k++){
        for(int l=0;l<W[j];l++){
          if(k==0||k==H[j]-1)System.out.print("#");
          else if(l==0||l==W[j]-1)System.out.print("#");
          else System.out.print(".");
        }
        System.out.print("\n");
      }
      System.out.print("\n");
    }

  }
}



Measured memory_bytes: 36968
// ??????: http://d.hatena.ne.jp/simezi_tan/20140920/1411169324

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);++i)
#define rep2(i,a,b) for (int i=(a);i<(b);++i)
#define rrep(i,n) for (int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;--i)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) cout<<(#_v)<<":";for(auto(_x):(_v)){cout<<" "<<(_x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

// 14:30-15:00

// N, E, S, W
const int dx[4] = {-1, 0,  1,  0};
const int dy[4] = { 0, 1,  0, -1};

int w, h;
int a[30][30];
int c[4];
int d[30][30][4]; // d[i][j][k] = (i, j):pos, k:dir

bool inside(int x, int y) {
    return 0 <= x && x < h && 0 <= y && y < w;
}

int dijkstra() {
    using State = tuple<int, int, int, int>; // cost, i, j, k
    priority_queue<State, vector<State>, greater<State>> pq;
    rep(i, h) rep(j, w) rep(k, 4) d[i][j][k] = inf;
    d[0][0][1] = 0;
    pq.push(State(0, 0, 0, 1));

    while (!pq.empty()) {
        int cost, i, j, k;
        tie(cost, i, j, k) = pq.top(); pq.pop();
        if (d[i][j][k] < cost) continue;
        rep(nk, 4) {
            int ni = i + dx[nk], nj = j + dy[nk];
            if (!inside(ni, nj)) continue;
            int ncost = c[(nk - k + 4) % 4];
            if (a[i][j] != 4 && nk == (k + a[i][j]) % 4) {
                ncost = 0;
            }
            if (d[ni][nj][nk] > cost + ncost) {
                d[ni][nj][nk] = cost + ncost;
                pq.push(State(cost + ncost, ni, nj, nk));
            }
        }
    }

    int ret = inf;
    rep(k, 4) chmin(ret, d[h-1][w-1][k]);
    return ret;
}

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

    int testcase = 0;
    while (cin >> w >> h, w) {
        rep(i, h) rep(j, w) cin >> a[i][j];
        rep(i, 4) cin >> c[i];
        cout << dijkstra() << endl;
    }
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int A, B, C, X, ans = 0;
    cin >> A >> B >> C >> X;
    rep(i, A + 1) {
        rep(j, B + 1) {
            rep(k, C + 1) {
                if (500 * i + 100 * j + 50 * k == X) ans++;
            }
        }
    }
    cout << ans << "\n";
}

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

int main(){
  
int M;
int N;
cin >> M >> N ;
vector < vector <int> > seiseki(M,vector<int>(N));
vector <int> sum(M);
int maxpoint=0;

for (int i=0;i<M;i++){
    for (int j=0;j<N;j++){
        cin >> seiseki.at(i).at(j);
    }
}
  
for (int i=0;i<M;i++){
    for (int j=0;j<N;j++){
        if (seiseki.at(i).at(j) == 1){sum.at(i)++;}
    }
}

maxpoint = 0;
for (int i=0;i<M;i++){
    if ((sum.at(i))> maxpoint){
        maxpoint=sum.at(i);
    }
}
  
cout << maxpoint << endl;
return 0;

}




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

int main() {
  const unsigned long long MOD = 1000000007;
  unsigned N, X, Y, Z;
  std::cin >> N >> X >> Y >> Z;
  unsigned mask = (1u << (X + Y + Z - 1)) | (1u << (Y + Z - 1)) | (1u << (Z - 1));
  std::vector<std::vector<unsigned long long>> dp(N + 1, std::vector<unsigned long long>(1u << (X + Y + Z), 0));
  dp[0][0] = 1;
  unsigned HOGE = X + Y + Z - 1;
  for (unsigned i = 0; i < N; ++i) {
    unsigned j = 0;
    for (unsigned k = 0; k <= (X + Y + Z); ++k) {
      for (; j < 1u << k; ++j) {
        for (unsigned l = 0; l < 10; ++l) {
          if (l + k > HOGE) {
            unsigned x = ((1u << (l + k)) + j) >> (l + k - HOGE);
            if ((x & mask) != mask || !(j & 1u << (l + k - HOGE - 1))) {
              dp[i + 1][x] += dp[i][j];
              dp[i + 1][x] %= MOD;
            }
          } else {
            unsigned x = (1u << (l + k)) + j;
            if ((x & mask) != mask) {
              dp[i + 1][x] += dp[i][j];
              dp[i + 1][x] %= MOD;
            }
          }
        }
      }
    }
  }
  unsigned long long ans = 0;
  for (unsigned i = 0; i < 1u << (X + Y + Z); ++i) {
    ans += dp[N][i];
    ans %= MOD;
  }
  unsigned long long all = 1;
  for (unsigned i = 0; i < N; ++i) {
    all *= 10;
    all %= MOD;
  }
  std::cout << (all >= ans ? all - ans : all + MOD - ans) << std::endl;
  return 0;
}

Measured memory_bytes: 43392
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    a = LI()
    ans = sum([(a[i+1]-a[i])%m for i in range(n-1)])
    s = [0]*(2*m)
    f = [0]*(2*m)
    x = a[0]-1
    for i in range(1,n):
        y = a[i]-1
        if y < x:
            y += m
        if x+1 >= y:
            x = a[i]-1
            continue
        s[x+2] += 1
        s[y+1] -= 1
        f[y+1] -= y-x-1
        x = a[i]-1
    for i in range(2*m-1):
        s[i+1] += s[i]
        f[i+1] += f[i]+s[i+1]
    f = [f[i]+f[i+m] for i in range(m)]
    print(ans-max(f))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 54612
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = -1;
#ifndef LOCAL
#define cerr if(0)cout
#endif
 
int32_t main() 
{
	IAMSPEED
	int x,y; cin >> x >> y;
	FOR(i,0,100) {
		FOR(j,0,100) {
			if(i*2 + j*4 == y && i+j == x) {
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
}


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

typedef long long s64;

int q;
int a, b, c, d;

int main()
{
	cin >> q;
	while (q--)
	{
		cin >> a >> b;
		cin >> c >> d;

		int k = (max(a, b) - 1) / (min(a, b) + 1) + 1;

		int l = 0, r = a + b;
		while (l <= r)
		{
			int mid = l + r >> 1;
			int vA = a - mid / (k + 1) * k - mid % (k + 1);
			int vB = b - mid / (k + 1);
			if (vB <= (s64)vA * k)
				l = mid + 1;
			else
				r = mid - 1;
		}

		int vA = a - l / (k + 1) * k - l % (k + 1);
		int vB = b - l / (k + 1);
		int s = l + 1 + vB - vA * k;

		int p = min(d, l + 0);
		int q = max(c, l + 1);
		for (int i = c; i <= p; ++i)
			putchar((i - 0) % (k + 1) ? 'A' : 'B');
		for (int i = q; i <= d; ++i)
			putchar((i - s) % (k + 1) ? 'B' : 'A');
		putchar('\n');
	}

	return 0;
}

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

int main() {
  ll l,r;
  cin>>l>>r;
  ////////
  ll ans=0,m=10000;
  
  if(l-r>=2018){
    ans=0;
  }
  else{
    for(int i = l ; i <= (r) ; i ++ ){
      for(int j = i+1 ; j <= (r) ; j ++ ){
         ll c=(i%2019)*(j%2019);
         c=c%2019;
         m=min(m,c);
        if(m==0) break;
      }
      if(m==0) break;
    }
     ans=m; 
  }
  cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

string s;
int l;

void init()
{
	cin >> s;
	l = s.length();
}

int calc(int pos)
{
	int res = 0;
	reps(i, pos, pos+3) {
		res *= 10;
		res += s[i] - '0';
	}
	return res;
}

void solve()
{
	int mi = 100000;
	rep(i, l-2) {
		mi = min(mi, abs(calc(i) - 753));
	}
	cout << mi << endl;
}




Measured memory_bytes: 256
def main():
    a = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    x = [[0]*3 for _ in range(3)]
    b =[]
    for _ in range(n):
        b.append(int(input()))
    for i in range(3):
        for j in range(3):
            if a[i][j] in b:
                x[i][j] = 1
    
    for i in range(3):
        c = 1
        for j in range(3):
            c *= x[i][j]
        if c == 1:
            print("Yes")
            return
    for i in range(3):
        c = 1
        for j in range(3):
            c *= x[j][i]
        if c == 1:
            print("Yes")
            return
    c = 1
    for i in range(3):
        c *= x[i][i] 
    if(c):
        print("Yes")
        return
    if(x[0][2]*x[1][1]*x[2][0]):
        print("Yes")
        return
    print("No")
    

    
    

if __name__ == "__main__":
    main()

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

typedef long long ll;
typedef pair<int,int>P;

P func(int n){
        int a=n%10,b;
        while(n){
                b=n;
                n/=10;
        }
        return P(a,b);
}

int main(){
        int n;
        cin>>n;
        map<P,int>mp;
        for(int i=1;i<=n;i++){
                mp[func(i)]++;
        }
        ll ans=0;
        for(int i=1;i<=n;i++){
                P p=func(i);
                P q(p.second,p.first);
                ans+=mp[q];
        }
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <atcoder/all>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define REP2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define rall(hoge) (hoge).rbegin(), (hoge).rend()
#define en '\n'
using Edge = pair<ll, ll>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x) { cout << x << '\n'; }
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;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return x / gcd(x,y)*y ;}
// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)

const int MAX_A = 300005;
int op(int a,int b) { return max(a,b);}
int e() { return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    segtree<int,op,e> dp(MAX_A);
    rep(i,n) {
        int x = a[i];
        int l = x-k, r = x+k+1;
        l = max(l,0);
        r = min(r,MAX_A);
        int now = dp.prod(l,r) + 1;
        dp.set(x, now);
    }
    int res = dp.prod(0,MAX_A);
    print(res);
    return 0;
}


Measured memory_bytes: 9828
#include <stdio.h>

/*  選択ソート(0オリジン) */
int selectionSort(int A[], int N) {
    int i, j, t, sw =0, minj;
    for(i=0;i<N-1;i++) {
        minj = i;
        for(j=i;j<N;j++) {
            if(A[j]<A[minj]) minj = j;
        }
        t=A[i]; A[i]=A[minj]; A[minj]=t;
        if(i!=minj) sw++;
    }
    return sw;
}

int main(void) {
    int A[100], N, i, sw;

    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = selectionSort(A,N);

    for(i=0;i<N;i++) {
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",sw);

    return 0;
}


Measured memory_bytes: 2116
#include<stdio.h>
int main(void)
{
	int n,k,a[51],i,j,l,sum;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(a[i]<a[j]){
				l=a[i];
				a[i]=a[j];
				a[j]=l;
			}
		}
	}
	for(i=0;i<k;i++){
	//printf("a=%d\n",a[i]);
		sum+=a[i];
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
using namespace std;
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include<stack>

#define MOD1e9 1000000007
#define INT_MAX       2147483647
#define INT_MIN     (-2147483647 - 1)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(c) for(int i = 0; i <(c); ++i)
#define rrep(n) for(int i = (n) ; i >=0 ; --i)
#define fora(i, s, c) for(int i = (s); i < (c); ++i)
#define forr(i, s, c) for(int i = (s); i > (c); --i)
#define endl "\n"
#define ret(n) return n
#define pb push_back
#define eb emplace_back
#define ff first;
#define ss second;
#define mp make_pair;
#define all(p) p.begin(),p.end()
#define mid(s,e) (s+(e-s)/2)
//Typedefs
typedef long long ll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef priority_queue<int> pqint;
typedef priority_queue<ll> pqll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<long> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
//Testcase start
#define tcs() int testcases; cin >> testcases; while(testcases--)

int main()
{
	int K, A, B;
	cin >> K >> A >> B;
	bool ans = false;
	for(int i = A; i<=B; ++i)
		if (i % K == 0)
		{
			ans = true;
			break;
		}
	if (ans)
		cout << "OK";
	else
		cout << "NG";

	ret(0);
}

Measured memory_bytes: 3128