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

const long long INF = (long long) 2e17 ;
const int MAXN = 5005, MAXE = 60006;

int src, snk, nNode, nEdge;
int Q[MAXN], fin[MAXN], pro[MAXN] ;
long long flow[MAXE], cap[MAXE] , dist[MAXN] ;
int Next[MAXE], to[MAXE] ;

inline void init(int _src, int _snk, int _n) {
    src = _src, snk = _snk, nNode = _n, nEdge = 0;
    memset( fin , -1 , sizeof(fin) ) ;
}

inline void add(int u, int v, long long c) {
    to[nEdge] = v, cap[nEdge] = c, flow[nEdge] = 0, Next[nEdge] = fin[u], fin[u] = nEdge++;
    to[nEdge] = u, cap[nEdge] = 0, flow[nEdge] = 0, Next[nEdge] = fin[v], fin[v] = nEdge++;
}

bool bfs() {
    int st, en, i, u, v;
    memset( dist , -1 , sizeof(dist) ) ;
    dist[src] = st = en = 0;
    Q[en++] = src;
    while(st < en) {
        u = Q[st++];
        for(i=fin[u]; i>=0; i=Next[i]) {
            v = to[i];
            if(flow[i] < cap[i] && dist[v]==-1) {
                dist[v] = dist[u]+1;
                Q[en++] = v;
            }
        }
    }
    return dist[snk]!=-1;
}

int dfs(int u, long long fl) {
    if(u==snk) return fl;
    for(int &e=pro[u], v, df; e>=0; e=Next[e]) {
        v = to[e];
        if(flow[e] < cap[e] && dist[v]==dist[u]+1) {
            df = dfs(v, min(cap[e]-flow[e], fl));
            if(df>0) {
                flow[e] += df;
                flow[e^1] -= df;
                return df;
            }
        }
    }
    return 0;
}

long long dinitz() {
    long long ret = 0;
    int df;
    while(bfs()) {
        for(int i=1; i<=nNode; i++) pro[i] = fin[i];
        while(true) {
            df = dfs(src, INF);
            if(df) ret += (long long)df;
            else break;
        }
    }
    return ret;
}

int arr[110] ;

int main() {
    int n, e, u, v, c, i;
    long long p = 0 ;
    scanf("%d" , &n ) ;
    for( int i = 1 ; i <= n ; i++ ) scanf("%d" , &arr[i] ) ;
    int s = n+n+2 , t = s + 1 ;
    init( s , t , n+n+5 ) ;
    for( int i = 1 ; i <= n ; i++ ) {
        p += max( 0 , arr[i] ) ;
        add( i , n+i , INF ) ;
        add( s , i , max(0 , arr[i] ) ) ;
        add( n+i , t , max( 0 , -arr[i] ) ) ;
        for( int j = 1 ; j <= n ; j++ ) {
            if( i % j == 0 ) {
                add( i , j + n , INF ) ;
            }
        }
    }
    printf("%lld\n" , p - dinitz() ) ;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

#define DATA_M 50

int main(void)
{
    int a[DATA_M];
    int num[DATA_M];
    int i,j;
    double w,h;
    double bmi;

    i = 0;
    while (scanf("%d,%lf,%lf", &a[i], &w, &h) != EOF)
    {
        bmi = w / (h * h);
        if (bmi >= 25){
            num[i] = a[i];
            i++;
        }
    }
    for (j = 0; j < i; j++){
        printf("%d\n", num[j]);
    }

    return (0);
}


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

using namespace std;
typedef long long ll;

#define f(i,n) for(int i=0; i < (n); i++)
#define fi(n) for(int i=0; i < (n); i++)
#define fsi(start, n) for(int i=(start); i < (n); i++)
#define fj(n) for(int j=0; j < (n); j++)

#define sv(v)for(auto x: v)cout << x << " ";cout << endl;

int main()
{
    int t;
    cin >> t;
    map<string, int> votes;
    while(t--) {
        string s;
        cin >> s;
        votes[s]++;
    }

    int max = -1;
    vector<string> results;

    for(auto p: votes) {
        if(p.second > max) {
            max = p.second;
            results.clear();
            results.push_back(p.first);
        }
        else if (p.second == max)
            results.push_back(p.first);
//        cout << p.first << " " << p.second << endl;
    }

    sort(results.begin(), results.end());
    
    for(auto s: results)
        cout << s << endl;

    return 0;
}


Measured memory_bytes: 26868
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int dirx[] = {1, 0, -1, 0};
int diry[] = {0, 1, 0, -1};

void solve() {
	int h, w, ch, cw, dh, dw;
	cin >> h >> w >> ch >> cw >> dh >> dw;
	ch--; cw--; dh--; dw--;
	
	vvi a(h, vi(w));
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++) {
			char c;
			cin >> c;
			
			if(c == '.') a[i][j] = 0;
			else a[i][j] = 1;
		}	
		
	vvi dp(h, vi(w, inf));
	priority_queue<pair<int, ii>> q;
	dp[ch][cw] = 0;
	q.push({dp[ch][cw], {ch, cw}});
	while(!q.empty()) {
		int x = q.top().ss.ff, y = q.top().ss.ss; q.pop();
		
		if(x == dh && y == dw) break;
		
		for(int i = 0; i < 4; i++) {
			int nx = x + dirx[i], ny = y + diry[i];
			if(not in(nx, 0, h) or not in(ny, 0, w) or a[nx][ny]) continue;
			if(dp[nx][ny] > dp[x][y]) {
				dp[nx][ny] = dp[x][y];
				q.push({-dp[nx][ny], {nx, ny}});
			}
		}
		
		for(int i = -2; i <= 2; i++) {
			for(int j = -2; j <= 2; j++) {
				int nx = x + i, ny = y + j;
				if(not in(nx, 0, h) or not in(ny, 0, w) or a[nx][ny]) continue;
				if(dp[nx][ny] > dp[x][y] + 1) {
					dp[nx][ny] = dp[x][y] + 1;
					q.push({-dp[nx][ny], {nx, ny}});
				}
			}
		}
	}
	
	cout << (dp[dh][dw] == inf ? -1 : dp[dh][dw]) << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 11416
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N,C;
ll x[100010];
ll v[100010];
ll le[100010];
ll ri[100010];
ll maxr[100010];
ll maxl[100010];

int main() {
    cin >> N >> C;
    rep(i,N) cin >> x[i+1] >> v[i+1];
    x[N+1] = C;
    ll ans = 0;
    repi(i,1,N+1){
        ri[i] = ri[i-1]-(x[i]-x[i-1])+v[i];
        maxr[i] = max(maxr[i-1],ri[i]);
        ans = max(ans,ri[i]);
    }
    repi(i,1,N+1){
        le[i] = le[i-1]+(x[N-i+1]-x[N-i+2])+v[N-i+1];
        maxl[i] = max(maxl[i-1],le[i]);
        ans = max(ans,le[i]);
    }
    repi(i,1,N+1){
        ll temp = ri[i]-x[i]+maxl[N-i];
        ans = max(ans,temp);
    }
    repi(i,1,N+1){
        ll temp = le[i]-(C-x[N-i+1])+maxr[N-i];
        ans = max(ans,temp);
    }
    cout << ans << endl;
   
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll N,X,M; cin >> N >> X >> M;


  if(N==1){
    cout << X << endl;
    return 0;
  }
  vector<ll> nxt(M,0);
  for(ll i=0;i<M;i++){
    nxt[i] = i*i%M;
  }

  vector<ll> cnt(M+10,0);
  vector<ll> sum(M+10,0);
  vector<ll> res(M+10,-1);
  ll now = X;
  cnt[X]++;
  sum[1] = X;
  res[0]=X;
  ll l=-1,r=-1;
  for(ll i=1;i<=M;i++){
    res[i] = now = nxt[now];
    if(cnt[now]!=0 && r==-1){
      r = i;
    }
    cnt[now]++;
    sum[i+1] = sum[i]+now;
  }
  rep(i,M+1){
    if(res[i]==res[r] && l==-1){
      l = i;
    }
  }
  ll ans=0;
  if(r==-1){
    ans = sum[N];
  }
  else{
    ll lng = r-l;
    ll tim = (N-l)/lng;
    ans = sum[l];
    ans += tim*(sum[r]-sum[l]);
    for(ll i=0;l+lng*tim+i<N;i++){
      ans += res[l+i];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int x, a, b;

int main() {
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}
}

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

int main() {
    string S;
    cin >> S;
    bool A = S[0] == 'A';
    int Cs = S.find("C");
    int Ce = S.rfind("C");
    bool C1    = (Cs == Ce);
    bool C2    = (Cs >= 2) && (Cs <= S.size() - 2);
    bool C     = (C1 && C2);
    bool small = true;
    for(int i=1;i<S.size();i++){
        if (i == Cs) continue;
        if(!islower(S[i]))small = false;
    }
    if(A&&C&&small){
      cout << "AC" << endl;
    } else {
      cout << "WA" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n;
    cin>>n;

    ll sum = 0;
    ll sub = 0;
    vector<ll> arr;
    for(int i = 0; i < n; i++){
       ll t; cin>>t;
       sum+=t;
       arr.push_back(t);
       if((i+1)%2 == 0) sub+=2*t;
    }
    
    ll m = sum - sub;
    cout<<m<<" ";
    for(int i = 1; i < n; i++){
        m = 2LL*arr[i-1] - m;
        cout<<m<<" ";
    }
}


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


int R, C, W, S;
vector<string> V;

int main() {
  while(cin >> R && R) {
    V.clear();
    cin >> C;
    cin >> W;
    cin >> S;
    cin.ignore();
    string line;
    while(getline(cin, line) && line != "?") {
      if(line == "") line = ".";
      for(int i = 0; i < line.size(); i += W) {
        V.push_back(line.substr(i, W));
        V.back().resize(W, '.');
      }
    }

    while(V.size() % (R*C) != 0) V.push_back(string(W, '.'));

    for(int k = 0; k < V.size(); k += R*C) {
      for(int i = 0; i < R; ++i) {
        for(int j = 0; j < C; ++j) {
          if(j) cout << string(S, '.');
          cout << V[k + i + j * R];
        }
        cout << endl;
      }
      cout << "#" << endl;
    }
    cout << "?" << endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n; cin>>n;
	int a[100], b[100], c[100];
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=1; i<=n; i++) cin>>b[i];
	for(int i=1; i<n; i++) cin>>c[i];
	int ans=0;
	for(int i=0; i<n; i++){
		ans+=b[a[i]];
		if(i>0 && a[i-1]+1==a[i]) ans+=c[a[i-1]];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n,h=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(n)]
c=max([a[0] for a in ab])
d=[b[1] for b in ab if b[1]>c]
d.sort()
ans=0
while len(d)>0:
    h-=d.pop()
    ans+=1
    if h<=0:
        print(ans)
        exit()
f=(h+c-1)//c
print(ans+f)

Measured memory_bytes: 28396
def examA():
    def bfs_grid(h, w, s, maze):
        distance = [[inf] * w for _ in range(h)]

        def bfsg():
            queue = deque()
            if maze[s[0]][s[1]]=="#":
                queue.append((s, 1))
                distance[s[0]][s[1]] = 1
            else:
                queue.append((s,0))
                distance[s[0]][s[1]] = 0
            while len(queue):
                [y, x],st = queue.popleft()
                for i in range(2):
                    nx, ny = x + [1, 0][i], y + [0, 1][i]
                    if (0 <= nx < w and 0 <= ny < h):
                        cur = deepcopy(distance[y][x])
                        if st==0 and maze[ny][nx]=='#':
                            cur += 1
                        if distance[ny][nx] <= cur:
                            continue
                        if maze[ny][nx]=='#':
                            queue.append(((ny, nx),1))
                        else:
                            queue.append(((ny, nx), 0))
                        distance[ny][nx] = cur
            return distance

        return bfsg()
    H, W = LI()
    S = [SI()for _ in range(H)]
    L = bfs_grid(H,W,[0,0],S)
    ans = L[-1][-1]
    #print(L)
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examA()

"""

"""

Measured memory_bytes: 47976
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n;
    cin >> n;

    int dsum[112345];

    int n_ = n;
    int tmp = 0;
    while (n_ >= 1)
        tmp += n_ % 10, n_ /= 10;

    fill(dsum, dsum + n + 1, INT_MAX);

    priority_queue<P, vector<P>, greater<P>> q;

    dsum[1] = 1;
    q.push(make_pair(1, 1));

    while (q.size())
    {
        P p = q.top();
        q.pop();

        if (p.first > dsum[p.second])
            continue;

        for (int i = 0; i <= 9; i++)
        {
            int ne = (p.second * 10 + i) % n;
            if (dsum[ne] > p.first + i)
            {
                dsum[ne] = p.first + i;
                q.push(make_pair(dsum[ne], ne));
            }
        }
    }

    cout << dsum[0] << endl;

    return 0;
}

Measured memory_bytes: 2804
def prime(x):
  for i in range(2,int(x**0.5)+1):
    if x%i==0:
      return False
  return True

pri = [0]*(100000+1)
for j in range(2,100000+1):
    if prime(j):
        pri[j] = 1

c = [0]*(100000+1)
for i in range(2,100000+1):
    if pri[i]==1 and pri[(i+1)//2]==1:
        c[i] = c[i-1]+1
    else:
        c[i] = c[i-1]

q = int(input())
for _ in range(q):
    l,r = map(int, input().split())
    print(c[r]-c[l-1])

Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[105][100005];
ll value[105];
ll weight[105];
int main()
{
    int n,w;
    cin>>n>>w;
    for(int i=0;i<n;i++)
    {
        cin>>weight[i]>>value[i];
    }
    
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(j>=weight[i-1])
            {
                memo[i][j]=max(memo[i-1][j],value[i-1]+memo[i-1][j-weight[i-1]]);
            }
            
            else
            {
                memo[i][j]=memo[i-1][j];
            }
        }
    }
    
    printf("%lld\n",memo[n][w]);
}

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

int main(){
  int a,m[101][101],b,c,d;
  cin >> a;
  for(int i=1;i<=a;i++){
    for(int j=1;j<=a;j++){
      m[i][j]=0;
    }
  }
  for(int i=1;i<=a;i++){
    cin >> b >> c;
    for(int j=0;j<c;j++){
      cin >> d;
      m[i][d]=1;
    }
  }
  for(int i=1;i<=a;i++){
    for(int j=1;j<=a;j++){
      cout << m[i][j];
      if(j!=a)cout<< " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int left[n+1]={},right[n+1]={};
    for(int i=0; i<n; i++){
        left[i+1] = GCD(a[i],left[i]);
        //cout << right[i] << endl;
    }
    //cout << endl;
    for(int i=n-1; i>=0; i--){
        right[i] = GCD(a[i],right[i+1]);
    }
    /*
    for(int i=0; i<n+1; i++){
        cout << left[i] << endl;
    }
    cout << endl;
    */
    int res=0;
    for(int i=0; i<n; i++){
        int c=GCD(left[i],right[i+1]);
        res = max(res,c);
    }
    cout << res << endl;
}


Measured memory_bytes: 1408
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
ans=0
1.upto(N) do|i|
  ans+=i unless (i%3).zero? or (i%5).zero?
end
puts ans

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int C[30];

int main()
{
    string S;
    cin >> S;
    REP(i, S.length())
    {
        C[S[i] - 'A']++;
    }

    int t = 0;
    bool e = true;
    REP(i, 28)
    {
        if (C[i] > 0)
        {
            if (C[i] != 2)
                e = false;
            t++;
        }
    }

    if (e && t == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll num = x / d;
    if(num >= k){
        cout << x - d * k << endl;
    }else{
        x %= d;
        k -= num;
        if(k&1) cout << d - x << endl;
        else cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
    { for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
    { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
    { cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    vector<int> X(n), Y(n);
    rep(i, n) cin >> X[i] >> Y[i];
    vector<int> P(n);
    rep(i, n) P[i] = i;
    double sum = 0;
    int co = 1;
    REP(i, 1, n) co *= i;
    do {
        double dist = 0;
        rep(i, n - 1) {
            dist += sqrt(pow(X[P[i]] - X[P[i + 1]], 2) + pow(Y[P[i]] - Y[P[i + 1]], 2));
        }
        sum += dist;
    } while(next_permutation(all(P)));
    double ans = sum / co;
    cout << fixed << setprecision(10) << ans << endl;
}

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


Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

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

    sort(v.begin(), v.end(), greater<int>());

    cout << accumulate(v.begin()+K, v.end(), 0) << endl;
}

Measured memory_bytes: 1024
a, b, c, d = map(int,input().split())

"""
case1
a b c d   →0

case2
a c b d  → b-c

case3
a c d b → d-c

case4
c a 

start →開始時刻のmax
end →終了時刻のmin



"""
starttime = max(a,c)
endtime  = min(b,d)

if starttime < endtime:
    result  = endtime - starttime
else:
    result = 0




"""
if b<=c :
    result = 0
else:  ## c < b 
    if b < d:  ## c < b < d
        result  = b - c
    else:  ## c < d <= b
        result  = d -c
"""



print(result)



Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>

using namespace std;

int a[3000][2],i=0;

int main(){
    while(1){
        cin >>a[i][0] >>a[i][1];
        if(a[i][0] == 0 && a[i][1] == 0)break;
        sort(a[i],a[i]+2);
        i++;
    }
    for(int j=0;j<i;j++){
        cout << a[j][0] << " " << a[j][1] << endl;
    }
}


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

int main(){
    int N, minNum=1e9, ans=0;
    cin >> N;
    vector<int> a(N);
    
    for(int i=0; i<N; i++){
	cin >> a[i];
    }


    for(int i=0; i<N; i++){
	if(minNum>a[i])
	    ans++;
	minNum = min(a[i], minNum);
    }
    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>

using namespace std;

#define N_MAX 2000



int n,k;
vector<int> nx[N_MAX];


int dfs(int k, int s,int p){
	if(k == 0) return 1;
	k--;
	
	int c = 1;
	for(vector<int>::iterator it = nx[s].begin();it != nx[s].end();++it){
		if(*it != p) c += dfs(k, *it, s);
	}
	return c;
}
int main(){
	scanf("%d %d", &n, &k);
	for(int i = 0;i < n-1;i++){
		int a,b;
		scanf("%d %d", &a, &b);
		a--; b--;
		nx[a].push_back(b);
		nx[b].push_back(a);
	}
	int m = 1;
	for(int i = 0;i < n;i++){
		m = max(m, dfs(k/2, i,-1));
	}
	for(int i = 0;i < n;i++){
		for(vector<int>::iterator it = nx[i].begin();it != nx[i].end();++it){
			int j = *it;
			int mm = dfs((k-1)/2,i,j)+dfs((k-1)/2,j,i);
			m = max(m, mm);
		}
	}
	printf("%d\n", n-m);
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<vector>
using namespace std;

bool dp[2000*2000/2+1];
int a[2000];

int main() {
	int n;
	int sum = 0;
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	int max = 0;
	vector<int> v;
	for(int i=0;i<=sum/2;i++) dp[i] = false;
	v.push_back(0);
	dp[0] = true;
	for(int i=0;i<n;i++) {
		int l = v.size();
		for(int j=0;j<l;j++) {
			int k = v[j] + a[i];
			if(k <= sum/2 && !dp[k]) {
				dp[k] = true;
				v.push_back(k);
				if(k > max) max = k;
			}
		}
	}
	printf("%d\n", sum - max);
	return 0;
}


Measured memory_bytes: 7664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

constexpr int MOD = 1e9+7;

constexpr int COMB_MAX = 200010;
ll fac[COMB_MAX], finv[COMB_MAX], inv[COMB_MAX];

void initComb(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COMB_MAX; i ++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll sum(int n){
    return (ll)n * (n+1) / 2 % MOD;
}

int main(void){
    Cin(int, h, w, k);
    initComb();
    
    ll ans = 0;
    For(i, h) For(j, w){
        ans = (ans + (sum(i) + sum(h-i-1)) % MOD * w % MOD) % MOD;
        ans = (ans + (sum(j) + sum(w-j-1)) % MOD * h % MOD) % MOD;
    }
    if(ans % 2 == 0) ans /= 2;
    else ans = (ans + MOD) / 2;
    
    Cout(comb(w*h-2, k-2) * ans % MOD);
}


Measured memory_bytes: 4992
N,M = map(int,input().split())
S = [list(map(int,input().split())) for _ in range(N)]
C = [list(map(int,input().split())) for _ in range(M)]

for i in range(N):
  mind = 10**9
  ans = 0
  for j in range(M):
    MD = abs(C[j][0] - S[i][0]) + abs(C[j][1] - S[i][1])
    if MD < mind:
      mind = MD
      ans = j+1
  print(ans)

Measured memory_bytes: 3064
# 数値→アルファベット
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
n=num2alpha(int(input()))
n=str(n.lower())
print(n)

Measured memory_bytes: 9100
#include<stdio.h>
int d[100000];
int main()
{
	int num;
	scanf("%d",&num);
	for(int i=0;i<num;i++)
	{
		int z;
		scanf("%d",&z);
		z--;
		d[i]=z;
	}
	int c=0;
	for(int i=0;i<num;i++)
	{
		if(d[d[i]]==i)c++;
	}
	printf("%d\n",c/2);
}

Measured memory_bytes: 512
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    s = input()
    n = len(s)

    ans = len(s)
    current_number = s[0]
    for k, c in enumerate(s):
        if c != current_number:
            ans = min(ans, max(k, n - k))
            current_number = c
    print(ans)

if __name__=="__main__":
    solve()


Measured memory_bytes: 40176
s = input()
t = input()
s = sorted(s)
t = sorted(t,reverse=True)
S = [ord(s[i]) for i in range(len(s))]
T = [ord(t[i]) for i in range(len(t))]
l = 0
if len(S) < len(T):
  for i in range(len(S)):
    if S[i] < T[i]:
      print('Yes')
      break
    elif S[i] >T[i]:
      print('No')
      break
    else:
      l += 1
  if l == len(S):
    print('Yes') 
else:
  for i in range(len(T)):
    if S[i] < T[i]:
      print('Yes')
      break
    elif S[i] >T[i]:
      print('No')
      break
    else:
      l += 1
  if l == len(T):
    print('No')
      

Measured memory_bytes: 38384
#include<cstdio>
#define rep(i,a) for(int i=0;i<(a);++i)

typedef long long ll;

const int MAX_N = 1000;

int N, A[MAX_N];
ll dp[MAX_N][21];

int main()
{
	scanf( "%d", &N );
	rep( i, N )
		scanf( "%d", A+i );

	dp[0][0] = 1;
	rep( i, N-1 ) rep( j, 21 )
	{
		if( j+A[i] <= 20 )
			dp[i+1][j+A[i]] += dp[i][j];
		if( i && j-A[i] >= 0 )
			dp[i+1][j-A[i]] += dp[i][j];
	}

	printf( "%lld\n", dp[N-1][A[N-1]] );

	return 0;
}

Measured memory_bytes: 1052
#include <iostream>
using namespace std;
int main(void){
    int a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,a6,b6,a7,b7;
    cin>>a1>>b1>>a2>>b2>>a3>>b3>>a4>>b4>>a5>>b5>>a6>>b6>>a7>>b7;
       cout<<a1-b1<<endl;
    cout<<a2-b2<<endl;
    cout<<a3-b3<<endl;
    cout<<a4-b4<<endl;
    cout<<a5-b5<<endl;
    cout<<a6-b6<<endl;
    cout<<a7-b7<<endl;
    
    
}


Measured memory_bytes: 3096
#include<iostream>
#include<cmath>
#include<algorithm>
#include <iomanip>
using namespace std;

int main(){
	int n,y;
	cin>>n>>y;
	y /= 1000;
	bool flag = false;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			int tmp = y - i*10 -j*5;
			if(tmp < 0) continue;
			if(tmp + i + j == n){
				cout<<i<<" "<<j<<" "<<tmp<<endl;
				goto out;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
	out:
	return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line)
});
 
reader.on('close', () => {
 
  var n = lines[1].split(' ')
  for (var k in n) n[k] = parseInt(n[k])
 
  var r = 0
 
  for (var i = 1; i < n.length - 1; i++) {
    var ary = [
      n[i - 1],
      n[i],
      n[i + 1]
    ].sort((a, b) => {
      if (a < b) return -1
      if (a > b) return 1
      return 0
    })
    if (ary.filter(x => x === n[i]).length > 1) continue
    if (ary[1] === n[i]) r++
  }
 
  console.log(r)
 
});

Measured memory_bytes: 7628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  vector<int> vec(N);
  for(int i =0; i < N;i++){
    cin >> vec.at(i);}
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int suma = 0;
  int sumb = 0;
  for(int i = 0;i < N; i = i + 2){
    suma += vec.at(i);}
  for(int i = 1;i < N; i = i + 2){
    sumb += vec.at(i);}
  cout << suma - sumb << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

    string S;
    cin >> S;
    ll AC = 0;
    ll ans = 0;
    ll i = 0;

    if(S.size() == 1){
        cout << 0 << endl;
        return 0;
    }

    while(i+1 < S.size()){
        if(S[i] == 'A'){
            AC++;
          if(i+2 < S.size()){
            if(S[i+1] == 'B' && S[i+2] == 'A'){
              AC = 0;
            }
            else if(S[i+1] == 'B' && S[i+2] == 'B'){
              AC = 0;
            }
          }
          else if(S[i+1] == 'C'){
            AC = 0;
          }
        }
        else if(S[i] == 'B' && S[i+1] == 'C'){
            ans += AC;
            i++;
        }
        else if(AC > 0 && S[i] != 'A'){
            AC = 0;
        }
      else AC == 0;
        i++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,mx=0;
    scanf("%d%d",&n,&m);
    map<int,int>mp;
    priority_queue<int>q;
    mp[0]=0;
    for(int i=0;i<n;i++){
        int w,v;
        scanf("%d%d",&w,&v);
        if(w>m||v==0) continue;
        for(map<int,int>::iterator it = mp.begin(); it!=mp.end();++it){
            int d = it->first;
            if(1ll*d+1ll*w<=m)  q.push(d+w);
        }
        while(!q.empty()){
            int d = q.top();q.pop();
            mp[d] = max(mp[d],mp[d-w]+v);
            mx = max(mx,mp[d]);
        }
    }
    mp.clear();
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=String.valueOf(n);
        char[] ch=s.toCharArray();
        for(int i=0;i<s.length();i++){
            if(ch[i]=='1'){
                ch[i]='9';
            }
            else{
                ch[i]='1';
            }
        }
        s=String.valueOf(ch);
        System.out.println(s);
    }
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int head(int x) { return x < 10 ? x : head(x / 10); }
int tail(int x) { return x % 10; }

int cnt[10][10];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	ll ans = 0;
	rep(i, 1, n + 1)
		cnt[head(i)][tail(i)]++;
	rep(i, 1, n + 1)
		ans += cnt[tail(i)][head(i)];
	die(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
char s[N];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s+1);
    int r=0;
    for(int i=1;i<=n;i++)
        if(s[i]=='R') r++;
    int ans=0;
    for(int i=1;i<=n;i++)
        if(i<=r) ans+=s[i]!='R';
    else ans+=s[i]!='W';
    printf("%d\n",ans/2);
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N;
    cin >> N;

    vector<pair<i64,i64>> ba(N);
    rep(i,0,N){
        i64 A,B;
        cin >> A >> B;
        ba[i]=make_pair(B,A);
    }

    sort(begin(ba),end(ba));
    i64 prev=0,remain=0;
    rep(i,0,N){
        i64 t=ba[i].first,r=ba[i].second;

        remain+=t-prev;
        prev=t;

        if(remain<r){
            cout << "No" << endl;
            return;
        }

        remain-=r;
    }

    cout << "Yes" << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 3456
wall = "#"*20
L = [[[str(0) for i in range(10)] for i in range(3)]
 for i in range(4)]

N = int(input())
for i in range(N) :
    tou,kai,ban,dx = map(int,input().split())
    L[tou-1][kai-1][ban-1] = str(int(L[tou-1][kai-1][ban-1]) + dx)

for i in range(12) :
    info = " "+" ".join(L[i//3][i%3])
    print(info)
    if i % 3 == 2 and i != 11 :
        print(wall)



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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
n=I()
As=LI()
Bs=LI()
Cs=LI()
satis=Bs[As[0]-1]
for i in range(1,n):
    satis+=Bs[As[i]-1]
    if As[i]==As[i-1]+1:
        satis+=Cs[As[i-1]-1]
print(satis)
        

Measured memory_bytes: 38384
<?php
fscanf(STDIN,"%d %d",$L,$R);
$lastCalc = false;
if($R-$L>=2019){
  //$R-$Lが2019以上なら間に2019の倍数を含むので最小剰余は必ず0
  $result = 0;
}elseif($R*($R-1)<2019){
  //$L*$Rが2019以上でない場合、最小剰余は$L*($L+1)
  //$result = (($L%2019)*(($L+1)%2019))%2019;
  //一時的に0にし総当りループを抜けた後に計算させる
  $result = 0;
  $lastCalc = true;
}else{
  //1組目を初期値にする
  $result = (($L%2019)*(($L+1)%2019))%2019;
}
//総当り
for($i=$L;$i<=$R-1;$i++){
  if($result === 0){
    break;
  }
  for($j=$i+1;$j<=$R;$j++){
    if($result === 0){
      break;
    }
    //最小値更新
    if($result > (($i%2019)*($j%2019))%2019){
      $result = (($i%2019)*($j%2019))%2019;
    }
  }
}
//if文を1行で書くと{}を省略できる
if($lastCalc) $result = $L*($L+1);
echo $result;


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vp arm(n);
    rep(i, n) {
        int x, l;
        cin >> x >> l;
        arm[i] = P(x+l, x-l);
    }
    sort(arm.begin(), arm.end());
    int cnt = 0;
    int now = 0;
    rep(i, n) {
        if (i == 0) {
            cnt++;
            now = arm[0].fi;
        }
        else if (now <= arm[i].se) {
            cnt++;
            now = arm[i].fi;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using namespace std;

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;
using vs=vector<string>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N; cin >>N;
  ll X=0,x=0,ans=LONG_MAX;
  vll a(N);
  for (ll i=0;i<N;i++) {
    cin >>a[i];
    X+=a[i];
  }
  for (ll i=0;i<N-1;i++) {
    x+=a[i];
    ans=min(ans,abs(X-2*x));
  }
  cout <<ans <<'\n';
  return 0;
}


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


int main(){
    int N;
    cin >> N;
    ll x = 1, y = 1;
    for (int i = 0; i < N; i++) {
        int T, A;
        cin >> T >> A;
        if (x % T != 0) x += T - (x % T);
        if (y % A != 0) y += A - (y % A);
        if (x/T*A > y) y = x/T*A;
        else x = y/A*T;
    }
    cout << x+y << endl;
    return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint dp[101][8];
int main() {
	int H, W , K;
	cin >> H >> W >> K;

	vector<mint> memo(W);
	memo[0] = 1;
	mint x = 0;//引く
	mint y = 1;//惹かない
	for (int n = 1;n<W;++n) {
		memo[n] = x + y;
		mint tmp = x;
		x = y;
		y = tmp + y;
	}

	dp[0][0] = 1;
	for (int n = 0;n<H;++n) {
		for (int m = 0;m<W;++m) {
			if (0 != m) {
				dp[n + 1][m - 1] += dp[n][m]*memo[m-1]*memo[W-m-1];
			}
			dp[n + 1][m] += dp[n][m]*memo[m]*memo[W-1-m];
			if (W - 1!= m) {
				dp[n + 1][m + 1] += dp[n][m]*memo[m]*memo[W-m-2];
			}
		}
	}
	cout << dp[H][K-1]<<endl;
	return 0;
}


Measured memory_bytes: 3604
main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  print $ f as 0 1000

f :: Integral p => [p] -> p -> p -> p
f (a : []) stock money = money + stock * a
f (a : b : xs) stock money
  | a > b =
    let m = money + stock * a
        (s, m') = m `divMod` b
     in f (b : xs) s m'
  | otherwise =
    let (s, m') = money `divMod` a
     in f (b : xs) (stock + s) m'


Measured memory_bytes: 4296
#include <cstdio>
using namespace std;
const int N = 1e6 + 5, Mod = 1e9 + 7;
int ml(int x, int y) { return 1ll * x * y % Mod; }
int dc(int x, int y) { return (x - y < 0) ? (x - y + Mod) : (x - y); }
int ad(int x, int y) { return (x + y > Mod) ? (x + y - Mod) : (x + y); }
int n, f[N], fac[N], inv[N];
int ksm(int x, int y) {
	int ret = 1;
	for (; y; y >>= 1, x = ml(x, x))
		if (y & 1) ret = ml(ret, x);
	return ret;
}
void Prepare() {
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) fac[i] = ml(fac[i - 1], i);
	inv[n] = ksm(fac[n], Mod - 2);
	for (int i = n - 1; i >= 0; --i) inv[i] = ml(inv[i + 1], i + 1);
}
int binom(int u, int d) {
	if (u < 0 || d < 0) return 0;
	if (u < d) return 0;
	return ml(fac[u], ml(inv[d], inv[u - d]));
}
int main() {
	scanf("%d", &n);
	Prepare();
	for (int i = 1; i <= n - 1; ++i)
		f[i] = ml(binom(i - 1, n - i - 1), ml(fac[i], fac[n - i - 1]));
	for (int i = n - 1; i >= 1; --i) f[i] = dc(f[i], f[i - 1]);
	int ans = 0;
	for (int i = 1; i <= n - 1; ++i) ans = ad(ans, ml(f[i], i));
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 14920
#include <stdio.h>

long GCD(long a, long b){
  long dividend, divisor;
  if (a >= b) {
    dividend = a;
    divisor = b;
  } else {
    dividend = b;
    divisor = a;
  }
  long remainder;
  while (1) {
    if (divisor == 1) {
      return 1;
    }
    remainder = dividend % divisor;
    if (remainder == 0) {
      break;
    } else {
      dividend = divisor;
      divisor = remainder;
    }
  }
  return divisor;
}

int main(void) {

  long x;
  scanf("%ld", &x);
  long ans = 360*x/GCD(360,x)/x;
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 1728
#include<iostream>
using namespace std;
int N_MAX = 102;
int main()
{
  int n,x,i,t,res;
  bool f[N_MAX];
  fill(f,f+N_MAX,0);
  cin >> x >> n;
  for(i=0;i<n;i++){
    cin >> t;
    f[t]=1;
  }
  if(f[x]==0){
    res=x;
  }else{
    for(i=1;i<N_MAX;i++){
      if(f[x-i]==0){
        res=x-i;
        break;
      }
      if(f[x+i]==0){
        res=x+i;
        break;
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3156
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int L;
int n = 1, m, l = 0;

vector <pair<int,int>> g[N];
void ae(int v, int u, int c) {
	assert(v < u);
	g[v].pb({u, c});
	++m;
}

void add() {
	if (n > 1) ae(1, n, l);
	else if (0) {
		++n;
		ae(n - 1, n, 0);
		if (l) ae(1, n, l);
	}
	++l;
}
void mult() {
	ae(n, n + 1, 0);
	ae(n, n + 1, l);
	++n;
	l <<= 1;
}
int main() {
	#ifdef wws
		freopen ("in.txt", "r", stdin);
	#endif
	cin >> L;
	// L--;
	vector <int> a;
	int tmp = L;
	while (tmp) {
		a.pb(tmp & 1);
		tmp >>= 1;
	}
	reverse(all(a));
	rep(i, 0, sz(a) - 1) {
		if (a[i]) add();
		if (i + 1 < sz(a)) mult();
	}
	cerr << l << nl << nl;
	// assert(n <= 20);
	cout << n << ' ' << m << nl;
	rep(i, 1, n) {
		for (auto to : g[i]) cout << i << ' ' << to.f << ' ' << to.s << nl;
	}
	ioi
}


Measured memory_bytes: 11904
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=(0);(i)<(n);++i)
#define ll long long
#define INF 1000000000

int main()
{
	int n,a,k,dp[100010];
	cin >> n >> k;

	int high[n+1];

	REP(i,n){
		cin >> a;
		high[i] = a;
	}

	REP(i,100010)dp[i]=INF;

	dp[0]=0; dp[1]=abs(high[1]-high[0]);

	for(int i=2;i<n;++i){
		for(int j=i-1;j>=0 && i-j<=k;--j){
			dp[i] = min(dp[i],dp[j]+abs(high[i]-high[j]));
		}
	}

	cout << dp[n-1] << endl;

	return 0;
}

Measured memory_bytes: 1024