akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <complex>

using namespace std;

const double EPS=1e-9;

typedef complex<double> Point;
struct Line{
	Point pos,dir;
	Line(){}
	Line(Point p,Point d):pos(p),dir(d){}
};
typedef Line Segment;

int Signum(double x)
{
	return abs(x)<EPS?0:x<0?-1:1;
}
double Dot(Point a,Point b)
{
	return real(conj(a)*b);
}
double Cross(Point a,Point b)
{
	return imag(conj(a)*b);
}
double CCW(Point a,Point b,Point c)
{
	Point d1=b-a,d2=c-a;
	double sign=Signum(Cross(d1,d2));
	if(sign)
		return sign;
	if(Dot(d1,d2)<-EPS)
		return -2;
	if(norm(d1)<norm(d2)-EPS)
		return 2;
	return 0;
}

// 直線と線分が重なるとき，線分の端点が直線上にあるときもtrue
bool IntersectLS(Line a,Segment b)
{
	return CCW(a.pos,a.pos+a.dir,b.pos)*CCW(a.pos,a.pos+a.dir,b.pos+b.dir)<=0;
}
bool IntersectSS(Segment a,Segment b)
{
	return IntersectLS(a,b) && IntersectLS(b,a);
}

// aとbが平行でないことが前提
Point IntersectPoint(Line a,Line b)
{
	return a.pos+a.dir*Cross(b.pos-a.pos,b.dir)/Cross(a.dir,b.dir);
}

const char* solve(Line* ls)
{
	Point ps[3];
	for(int i=0;i<3;i++){
		Line l1=ls[i],l2=ls[(i+1)%3];
		if(Signum(Cross(l1.dir,l2.dir))==0)
			return "kyo";
		if(!IntersectSS(l1,l2))
			return "kyo";
		ps[i]=IntersectPoint(l1,l2);
	}
	
	double area=abs(Cross(ps[1]-ps[0],ps[2]-ps[0]))/2;
	if(area<EPS)
		return "kyo";
	if(area<1.0e5-EPS)
		return "syo-kichi";
	if(area<1.0e6-EPS)
		return "kichi";
	if(area<1.9e6-EPS)
		return "chu-kichi";
	return "dai-kichi";
}

int main()
{
	for(;;){
		Line ls[3];
		for(int i=0;i<3;i++){
			int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			ls[i]=Line(Point(x1,y1),Point(x2-x1,y2-y1));
		}
		if(feof(stdin))
			break;
		puts(solve(ls));
	}
	
	return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)n;i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1001001001; const long long INFLL=1001001001001001001ll;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
    #ifdef int
        cerr<<"\x1b[7m"<<"'int' is defined as 'long long' !!!!"<<"\x1b[m"<<endl;
    #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int N,M;
    cin>>N>>M;
    vector<string> a(N),b(M);
    REP(i,N) cin>>a[i];
    REP(i,M) cin>>b[i];
    REP(i,N-M+1) {
        REP(j,N-M+1) {
            bool f=false;
            REP(k,M) {
                REP(l,M) {
                    if(a[i+k][j+l]!=b[k][l]) {f=true; goto next;}
                }
            }
            next:
            if(!f) {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

bool isPrime(int x)
{
    if (x == 2)
        return true;
    if (x < 2 || x % 2 == 0)
        return false;
    
    for (int i = 3; i <= sqrt(x); i += 2)
        if (x % i == 0)
            return false;

    return true;
}

int main()
{
    int n;
    cin >> n;
    int x;
    int count = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> x;
        if(isPrime(x))
            count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,m,x;
int main()
{
    scanf("%d%d",&n,&m);
    int ans1=0,ans2=0;
    for (int i=1;i<=n;i++) {
        scanf("%d",&x);
        ans1=(ans1+1LL*(2*i-n-1)*x%mod)%mod;
    }
    for (int i=1;i<=m;i++) {
        scanf("%d",&x);
        ans2=(ans2+1LL*(2*i-m-1)*x%mod)%mod;
    }
    printf("%d\n",1LL*ans1*ans2%mod);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N;
string S;

bool solve() {
  if (N % 2 == 1) {
    return false;
  }

  for (int i = 0; i < N / 2; ++i) {
    if (S[i] != S[N / 2 + i]) {
      return false;
    }
  }

  return true;
}

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

  cout << (solve() ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
#define all(c) begin(c),end(c)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const long double pi = acos(-1.0);
typedef complex<ld> cd;

void solve(int k, vector<vector<int> > &ans, int r)
{
    if (k == 2)
    {
        ans[0].push_back(1);
        ans[1].push_back(1);
        return;
    }
    for (int j = r; j > r - k + 1; j--) ans[k - 1].push_back(j);
    for (int j = r; j > r - k + 1; j--) ans[k - 2 - (r - j)].push_back(j);
    solve(k - 1, ans, r - k + 1);
}


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

    int n;
    cin >> n;
    for (int k = 1; k <= 4000; k++)
    {
        if (k * (k + 1) == 2 * n)
        {
            cout << "Yes\n";
            cout << k + 1 << "\n";
            vector<vector<int> > ans(k + 1);
            solve(k + 1, ans, n);
            rep(i, ans.size())
            {
                cout << ans[i].size() << " ";
                rep(j, ans[i].size())
                {
                    cout << ans[i][j] << " ";
                }
                cout << "\n";
            }
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 2304
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


class Combination(object):

    def __init__(self, N, mod):
        fac, finv, inv = [0]*(N+1), [0]*(N+1), [0]*(N+1)
        fac[:2] = 1, 1
        finv[:2] = 1, 1
        inv[1] = 1
        for i in range(2, N+1):
            fac[i] = fac[i-1]*i % mod
            inv[i] = -inv[mod % i]*(mod//i) % mod
            finv[i] = finv[i-1]*inv[i] % mod
        self.N = N
        self.MOD = mod
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def __call__(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return self.fac[n] * (self.finv[k]*self.finv[n-k] % self.MOD) % self.MOD


def div(a, b):
    return (a * pow(b, MOD-2, MOD)) % MOD


def solve(n: int, k: int):

    cmb = Combination(2*n, MOD)
    if n - 1 <= k:
        print(cmb(2*n-1, n))
        return
    else:
        b = 0
        for i in range(k+1):
            b += cmb(n-1, i)*cmb(n, i)
            b %= MOD
        print(b % MOD)
        return
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(n, k)


if __name__ == '__main__':
    main()


Measured memory_bytes: 50596
#include <stdio.h>

int	main(void)
{
	int	distance;
	int	time;
	int	speed;

	scanf("%d", &distance);
	scanf("%d", &time);
	scanf("%d", &speed);

	if (distance <= speed * time)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 2088
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const ll inf = (ll) (1e18) + 7;

const int N = 5020;
const int M = 1e9 + 7;

int mul(int a, int b) {
  return (a * (ll) b) % M;
}

void add(int &a, int b) {
  a += b;
  if (a < 0) a += M;
  if (a >= M) a -= M;
}

int pw(int a, int n) {
  int ret = 1;
  while (n) {
    if (n % 2 == 0) {
      a = mul(a, a);
      n /= 2;
    } else {
      ret = mul(ret, a);
      n--;
    }
  }
  return ret;
}

int inv(int x) {
  return pw(x, M - 2);
}

vector <int> g[N];
bool u[N];

vector <int> verts;

void dfs(int v) {
  verts.push_back(v);
  u[v] = true;
  for (int to : g[v]) {
    if (!u[to]) {
      dfs(to);
    }
  }
}

int dp[N][N];

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> p(n);
  vector <int> in(n);
  int opt = 1;
  for (int i= 0; i < n; i++) {
    cin >> p[i];
    if (p[i] != -1) p[i]--;
    if (p[i] != -1) {
      in[p[i]]++;
      g[i].push_back(p[i]);
      g[p[i]].push_back(i);
    }
    if (p[i] == -1) {
      opt = mul(opt, n - 1);
    }
  }
  vector <int> dp(n + 1);
  dp[0] = 1;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!u[i]) {
      vector <int> ndp(n + 1);
      verts.clear();
      dfs(i);
      int paths = 0;
      bool cyc = false;
      for (int v : verts) {
        int x = v;
        vector <char> vis(n);
        bool bad = false;
        while (x != -1) {
          if (vis[x]) {
            cyc = true;
            bad = true;
            break;
          }
          vis[x] = true;
          x = p[x];
        }
        if (!bad) {
          paths++;
        }
      }
      if (cyc) add(ans, 1);
      for (int j = n - 1; j >= 0; j--) {
        add(dp[j + 1], mul(dp[j], paths));
      }
    }
  }
  int ok = inv(n - 1);
  int fact = 1;
  for (int i = 1; i <= n; i++) {
    add(ans, mul(fact, mul(pw(ok, i), dp[i])));
    fact = mul(fact, i);
  }
  for (int i = 0; i < n; i++) {
    if (p[i] == -1) {
      add(ans, -ok);
    }
  }
  int ret = n;
  add(ret, -ans);
  cout << mul(ret, opt) << endl;
}


Measured memory_bytes: 4012
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
import math
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())

    for i in range(int(math.sqrt(n)), 0, -1):
        if n % i == 0:
            print(i + (n // i) - 2)
            break


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    string ans = "";
    for(int i = 0; i < n; i++){
        ans += s[i];
        ans += t[i];
    }

    cout << ans << endl;

    return 0;

}


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

int main() {
  int N;
  int M;
  cin >> N >> M;
  
  int Sn =N*(N-1)/2;
  int Sm =M*(M-1)/2;
  
  if (N>=2){
    if (M>=2){
      cout << Sn+Sm <<endl;
    }
    else{
      cout << Sn <<endl;
    }
  }
  
  else if(M>=2){
      cout << Sm <<endl;
    }
  else{
      cout << 0 <<endl;
    }
}

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

typedef long long ll;

const int MOD = 1000000007;

int N, M, Q, L[200009], R[200009], X[509][509], C[509][509];

int main() {
    cin >> N >> M >> Q;
    for (int i = 1; i <= M; i++) {
        cin >> L[i] >> R[i];
        X[L[i]][R[i]]++;
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            C[i][j] = C[i][j-1] + X[i][j];
        }
    }

    for (int i = 1; i <= Q; i++) {
        int p, q;
        cin >> p >> q;
        int sum = 0;
        for (int j = p; j <= q; j++) sum += C[j][q] - C[j][p-1];
        cout << sum << endl;
    }
}


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

stack<char> st;
string s;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>s;
    for(int i=0;i<s.size();++i)
    {
        if(st.empty()||!(st.top()=='S'&&s[i]=='T')) st.push(s[i]);
        else st.pop();
    }
    cout<<st.size();
    return 0;
}

Measured memory_bytes: 720
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    vector<int> v,ans;
    int maxi,tot,x;
    void solve()
    {
        cin>>n>>k;
        fo(i,0,k)
        {
            cin>>x;
            v.pb(x);
        }
        sort(v.begin(),v.end());
        fo(i,1,k)
        {
            ans.pb(v[i]-v[i-1]);
        }

        ans.pb(n-v[k-1]+v[0]);
        // sort(ans.begin(),ans.end());
        for(auto x:ans)
        {
            maxi=max(x,maxi);
            tot+=x;
        }
        cout<<tot-maxi<<endl;
 
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
    
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 4848
import Data.List  -- sortBy, group
import Data.Ord   -- comparing

modes ls = map fst . takeWhile ((>= frq) . snd) $ svls
  where vls = map valLen . group . sort $ ls     -- list of value-length pairs
        valLen ls = (head ls, length ls)
        svls = sortBy (flip $ comparing snd) vls -- sorted vls
        frq = snd (head svls)                    -- max frequency

main = do
  s <- getContents               -- get all input
  let ls :: [Int]
      ls = map read . lines $ s  -- break it into a list
      ms = modes ls
  putStr . unlines . map show $ ms

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,Y;
    cin >> N >> Y;
    Y/=1000;
    for(int i = 0; i <= N; i++) {
        for(int j = 0; i+j <= N; j++) {
            int k = N-i-j;
            if(i*10+j*5+k == Y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N;
int A[1010][1010];

int id[1010][1010];
int getID(int a,int b){
  if(a>b) swap(a,b);
  return id[a][b];
}

const int MAXV=1001*1001;

vector<int> g[MAXV];
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];

int dfs(int now){
  if(visited[now]){
    if(!calculated[now]) return -1;
    return dp[now];
  }

  visited[now]=true;
  int res=0;
  for(auto nex:g[now]){
    int val=dfs(nex);
    if(val==-1) return -1;
    res=max(res,val+1);
  }

  calculated[now]=true;
  return dp[now]=res;
}

int findLongestPath(int n){
  int res=0;
  for(int i=1;i<=n;i++){
    int val=dfs(i);
    if(val==-1) return -1;
    res=max(res,val);
  }
  return res;
}

int main(){
  cin>>N;
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N-1;j++){
      cin>>A[i][j];
    }
  }

  int cnt=1;
  for(int i=1;i<=N;i++){
    for(int j=i+1;j<=N;j++){
      id[i][j]=cnt++;
    }
  }
  cnt--;

  for(int i=1;i<=N;i++){
    for(int j=1;j+1<=N-1;j++){
      int a=i,b=A[i][j],c=i,d=A[i][j+1];
      g[getID(a,b)].push_back(getID(c,d));
    }
  }

  int ans=findLongestPath(cnt);
  if(ans==-1) cout<<-1<<endl; 
  else cout<<ans+1<<endl;

  return 0;
}


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

int main() {
    long long ans = 0;
    int N;
    int MAX = 100001;
    cin >> N;
    vector<long long> L(MAX, 0);
    for(int i = 0; i < N; i++) {
        long long a;
        cin >> a;
        L[a]++;
    }
    for(int i = 0; i < MAX; i++) {
        ans += i * L[i];
    }
    // cout << ans << endl;
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++) {
        long long b, c;
        cin >> b >> c;
        ans += (c - b) * L[b];
        L[c] += L[b];
        L[b] = 0;
        cout << ans << endl;
    }
}

Measured memory_bytes: 4048
#!/usr/bin/env python3
import sys
from itertools import groupby


def solve(S: str):
    MS = [len(list(g)) for k, g in groupby(S)]
    res = 0
    N = len(MS)
    for i, c in enumerate(MS):
        res += (c // 3) * 2
        c %= 3

        if c == 0:
            continue

        if i == N-1:
            res += 1
            break

        if c == 2:
            res += 2
            MS[i+1] -= 1
            continue

        if c == 1:
            res += 1
            continue
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 53744
#include <stdio.h>
int main(){

    int i, x, y, tmp;


    for(i=1;;i++){
        scanf("%d %d", &x, &y);
        if (x==0 && y==0){
            break;
        }
        if (x <= y) {
            printf("%d %d\n", x, y);
        }
        if(x>y){
            tmp = x;
            x = y;
            y = tmp;
        printf("%d %d\n", x, y);
        }
    }

return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

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

	while(true) {
		int h,w;
		cin>>h>>w;
		if(h==0) break;
		int ma[h][w][h][w],fld[h][w];
		REP(i,h) REP(j,w) cin>>fld[i][j];
		// [l,r], [u,d]
		REP(l,w) {
			FOR(r,l,w) {
				REP(u,h) {
					FOR(d,u,h) {
						int MA=0;
						FOR(x,l,r+1) FOR(y,u,d+1) MA=max(MA,fld[y][x]);
						ma[u][r][d][l]=MA;
						//printf("u,r,d,l = %d %d %d %d ma = %d\n",u,r,d,l,ma[u][r][d][l]);
					}
				}
			}
		}
		int ans=0;
		FOR(r,2,w) {
			FOR(l,0,r-1) {
				FOR(d,2,h) {
					FOR(u,0,d-1) {
						//printf("in r,l,d,u = %d %d %d %d ",r,l,d,u);
						int MI=INF;
						FOR(x,l,r+1) MI=min(MI,min(fld[u][x],fld[d][x]));
						FOR(y,u,d+1) MI=min(MI,min(fld[y][l],fld[y][r]));
						//printf("mi = %d ma = %d\n",MI,ma[u+1][r-1][d-1][l+1]);
						if(MI<=ma[u+1][r-1][d-1][l+1]) continue;
						int sum=0;
						FOR(x,l+1,r) {
							FOR(y,u+1,d) {
								sum+=MI-fld[y][x];
							}
						}
						ans=max(ans,sum);
					}
				}
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define FOR(i, N) for (long i = 0; i < (N); i++)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    cin >> H >> W;
    int C_h, C_w, D_h, D_w;
    cin >> C_h >> C_w;
    cin >> D_h >> D_w;

    vector<string> S(H);
    FOR(h, H) {
        cin >> S[h];
    }

    vector<vector<long>> A(H);

    FOR(h, H) {
        FOR(w, W) {
            A[h].push_back(MOD);
        }
    }

    queue<pair<int, int>> A_que;
    queue<pair<int, int>> B_que;

    A_que.push(make_pair(C_h - 1, C_w - 1));
    long ans = 0;
    while (!B_que.empty() || !A_que.empty()) {
        while (!A_que.empty()) {
            pair<int, int> p = A_que.front();
            int x = p.first;
            int y = p.second;
            A[x][y] = ans;
            A_que.pop();
            for (int i = -1; i < 2; i++) {
                for (int j = -1; j < 2; j++) {
                    if (abs(i + j) == 1) {
                        if (x + i < 0 || x + i >= H || y + j < 0 || y + j >= W) {
                            continue;
                        }
                        if (S[x + i][y + j] == '#') {
                            continue;
                        }
                        if (A[x + i][y + j] != MOD) {
                            continue;
                        }
                        A_que.push(make_pair(x + i, y + j));
                        A[x + i][y + j] = ans;
                    }
                }
            }
            for (int i = -2; i < 3; i++) {
                for (int j = -2; j < 3; j++) {
                    if (x + i < 0 || x + i >= H || y + j < 0 || y + j >= W) {
                        continue;
                    }
                    if (S[x + i][y + j] == '#') {
                        continue;
                    }
                    if (A[x + i][y + j] != MOD) {
                        continue;
                    }
                    if (abs(i) + abs(j) > 1) {
                        B_que.push(make_pair(x + i, y + j));
                    }
                }
            }
        }
        while (!B_que.empty()) {
            pair<int, int> q = B_que.front();
            int x = q.first;
            int y = q.second;
            B_que.pop();
            if (A[x][y] != MOD) {
                continue;
            }
            A_que.push(make_pair(x, y));
        }
        ans += 1;
    }

    if (A[D_h - 1][D_w - 1] == MOD) {
        cout << -1 << endl;
    } else {
        cout << A[D_h - 1][D_w - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 13376
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		TreeMap<Integer, Integer>map = new TreeMap<Integer, Integer>();

		for (int i=0; i<n; i++){
			int a = sc.nextInt();
			if (map.containsKey(a)){
				map.put(a, map.get(a)+1);
			} else {
				map.put(a, 1);
			}
		}
		int max = map.lastKey();
		boolean[] b = new boolean[max+1];
		for (int i=0; i<max+1; i++){
			b[i] = true;
		}
		for (int key : map.keySet()){
			if (b[key] == false){
				continue;
			}
			for (int i = 2; i*key <= max; i++){
				b[i*key] = false;
			}
		}
		int ans = 0;
		for (int key : map.keySet()){
			if (map.get(key) == 1 && b[key] == true){
				ans++;
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 71680
import sys
import numpy as np

N, K = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = np.zeros(N, dtype=int)
h = np.array(h)

for i in range(1, N):
  start = max(0, i-K)
  dp[i] = min(dp[start:i] + np.abs(h[start:i]-h[i]))
print(dp[N-1])

Measured memory_bytes: 22912
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
const int INF = (int)1e9;
typedef pair<int, int> P;
int manhattan(P a, P b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}
int dp[5][1000];
int main() {
  ios::sync_with_stdio(false);
  while(true) {
    int X, Y; cin >> X >> Y;
    if(X == 0 && Y == 0) break;
    P sp, gp;
    vector<vector<P>> mp(5);
    REP(i,Y) {
      string F; cin >> F;
      REP(j,X) {
        if(F[j] == 'S') {
          sp = P(i, j);
        }
        if(F[j] == 'G') {
          gp = P(i, j);
        }
        if(isdigit(F[j])) {
          int id = F[j] - '0';
          mp[id - 1].push_back(P(i, j));
        }
      }
    }
    P ans(INF, INF);
    REP(i,5) {
      REP(j,5) REP(k,1000) dp[j][k] = INF;
      int begin = (i + 1) % 5;
      REP(k, mp[begin].size()) {
        dp[begin][k] = manhattan(sp, mp[begin][k]);
      }
      for(int j = 2; j <= 4; ++j) {
        int prev = (i + j - 1) % 5;
        int next = (i + j) % 5;
        REP(k, mp[prev].size()) {
          REP(l, mp[next].size()) {
            int d = dp[prev][k] + manhattan(mp[prev][k], mp[next][l]);
            dp[next][l] = min(dp[next][l], d);
          }
        }
      }
      int end = (i + 4) % 5;
      REP(k, mp[end].size()) {
        ans = min(ans, make_pair(dp[end][k] + manhattan(mp[end][k], gp), i));
      }
    }
    if(ans.first == INF) {
      cout << "NA" << endl;
    }
    else {
      cout << ans.second + 1 << ' ' << ans.first << endl;
    }
  }
}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, M;
  cin >> N >> M;
  vector<int> road(N, 0);
  int r;
  
  for (int i = 0; i < 2*M ; i++) {
    cin >> r;
    road.at(r-1)++;
  }
  
    for (int i = 0; i < N; i++) {
    cout << road.at(i) << endl;
  }
  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
//string S, T;
int ans;

signed main(){
  cin >> N;
  vi A, B;
  rep(i,N){
    int a; cin >> a;
    if(i%2 == 0 ) A.push_back(a);
    else B.push_back(a);
  }
  
  if(N%2 == 0){
    for(int i = B.size()-1; i>= 0; i--){ cout << B[i] << " ";}
    rep(i, A.size()){
      cout << A[i];
      if(i != A.size()-1) cout << " ";
    }
  }
  else{
    for(int i = A.size()-1; i>= 0; i--){ cout << A[i] << " ";}
    rep(i, B.size()){
      cout << B[i];
      if(i != B.size()-1) cout << " ";
    }
  }
  cout << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;

    int N;
    cin >> N;
    priority_queue<int> PQ;
    rep(i, N)
    {
        int a;
        cin >> a;
        PQ.push(a);
    }

    int alice_point = 0;
    int bob_point = 0;

    rep(i, N)
    {
        int point = PQ.top();
        PQ.pop();
        if(i % 2 == 0)
            alice_point += point;
        else
            bob_point += point;
    }

    cout << alice_point - bob_point << endl;
}

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

class Solver {
    Scanner sc = new Scanner();

    long min = long.MaxValue;
    public void Solve() {
        int H = sc.nextInt();
        int W = sc.nextInt();

        Sub(H, W);
        Sub(W, H);

        WriteLine(min);

    }

    void Sub(long H, long W) {
        var arr = new long[3];
        for (int i = 1; i < H; i++) {
            long h = H - i;
            arr[0] = i * W;
            arr[1] = h * (W / 2);
            arr[2] = h * (W - (W / 2));
            min = Math.Min(min, Math.Abs(arr.Max() - arr.Min()));

            arr[1] = h / 2 * W;
            arr[2] = (h - (h / 2)) * W;
            min = Math.Min(min, Math.Abs(arr.Max() - arr.Min()));
        }
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {


        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

Measured memory_bytes: 17352
import sys
from math import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
vvv = na()
list.sort(vvv)
for i in range(n-1):
    m = (vvv[0]+vvv[1])/2
    vvv.append(m)
    vvv.pop(0)
    vvv.pop(0)
    list.sort(vvv)
print(vvv[0])





Measured memory_bytes: 38384
import math

N = int(input())
s = int(math.sqrt(2*N))
if s*(s+1) != 2*N:
    print('No')
else: 
    print('Yes')
    print(s+1)
    a = []
    for i in range(1, s+1):
        n0 = 1 + s*(i-1) - (i-2)*(i-2+1)//2
        a.append(n0)
    w = a[-1] + 1 ; a.extend((w, w))  #;print(a); print()

    for i in range(s+1):
        nL = []
        for k in range(i):
            nL.append(a[k]+(i-k-1))
            #print('i, k, a[k]+(i-k)', i, k, a[k]+(i-k-1))
        nL = nL + list(range(a[i], a[i+1]))
            #print('+', list(range(a[i], a[i+1])))  ;print()
        print(s, *nL)

Measured memory_bytes: 9200
#include <iostream>
using namespace std;
void ABC50(void);
void ABC52(void);
void ABC53(void);
void ABC54(void);
void ABC55(void);
void ABC56(void);
void ABC57(void);
void ABC58(void);
void ABC59(void);

int main(void){
    ABC54();
    return 0;
}

void ABC54(void){
    int a,b;
    cin>>a>>b;
    if(a==1)a=14;
    if(b==1)b=14;
    if(a>b)cout<<"Alice"<<endl;
    else if(b>a)cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int W, a, b;
  cin >> W >> a >> b;
  if(b<=a+W && a<=b+W) cout << 0 << endl;
  else if(a>b+W){
    cout << a-b-W << endl;
  }
  else{
    cout << b-a-W << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import Counter


class Factorize:
    def __init__(self):
        self.primes = Counter()

    def add_target(self, n):
        for i in range(2, int(n**0.5)+1):
            while n%i==0:
                self.primes[i] += 1
                n //= i
            if not n:
                break
        if n>1:
            self.primes[n] += 1
    
    def get_result(self):
        return dict(self.primes)


N = int(input())
f = Factorize()
f.add_target(N)

d = f.get_result()
ans = 0
for i in d.values():
    for j in range(i+1):
        if j*(j+1)//2>i:
            j-=1
            break
    ans += j
print(ans)


Measured memory_bytes: 9640
#include<iostream>
using namespace std;
char t[200000],d[200000];
int n,q;
string s;

int simulate(int x){
	for(int i=0;i<q;i++){
		if(s[x]==t[i]){
			if(d[i]=='L') x--;
			else x++;
			if(x<0 || n<=x) break;
		}
	}
	return x;
}

int main(){
	cin >> n >> q;
	cin >> s;
	for(int i=0;i<q;i++) cin >> t[i] >> d[i];

	int left=-1,right=n;
	while(left+1<right){
		int mid=(left+right)/2;
		int p=simulate(mid);
		if(p==-1) left=mid;
		else right=mid;
	}
	int l=left;
	left=-1,right=n;
	while(left+1<right){
		int mid=(left+right)/2;
		int p=simulate(mid);
		if(p==n) right=mid;
		else left=mid;
	}
	int r=right;
	cout << n-((l+1)+(n-r)) << endl;
	return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
vector<long long> vv;
bool isPrime(long long  n)
{
  if (n == 1)
  {
    return false;
  }
  long i = 2;
  while (i*i <= n)
  {
      if (n % i == 0)
      {
          return false;
      }
      i += 1;
  }
  return true;
}
long long  gcd(long long a, long long b){
	if (a == 0)
		return b;
	return gcd(b%a, a);
} 

int main(){ 
	
	string a,b; cin>>a>>b;
	cout<<b+a<<"\n";
	
	
	
	
	
	
	
	
}


Measured memory_bytes: 256
// abc155_b
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int n,a;
  bool ok=true;
  cin>>n;
  rep(i,n){
    cin>>a;
    if (a%2==0&&!(a%3==0||a%5==0)) {
      ok=false;
    }
  }
  if (ok) cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
  return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    c = list()
    for i in range(3):
        c.append(list(map(int, input().split())))

    tmp = list()
    for i in range(3):
        tmp.append([c[i][0]-c[0][0], c[i][1]-c[0][1], c[i][2]-c[0][2]])
    for i in range(3):
        if tmp[i][0] == tmp[i][1] == tmp[i][2]:
            continue
        else:
            print('No')
            exit()

    tmp = list()
    for i in range(3):
        tmp.append([c[0][i]-c[0][0], c[1][i]-c[1][0], c[2][i]-c[2][0]])
    for i in range(3):
        if tmp[i][0] == tmp[i][1] == tmp[i][2]:
            continue
        else:
            print('No')
            exit()

    print('Yes')


Measured memory_bytes: 3064
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int n, m, k;

int read() {
  if (scanf("%d%d%d", &n, &m, &k) < 3) {
    return false;
  }
  return true;
}

void solve() {
  for (int a = 0; a <= n; a++) {
    for (int b = 0; b <= m; b++) {
      if (a * (m - b) + b * (n - a) == k) {
        printf("Yes\n");
        return;
      }
    }
  }
  printf("No\n");
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
(defun main ()
  (let* ((x (read-line))
         (abcd (map 'list #'parse-integer (map 'list #'string x)))
         (ops (list '+ '-))
         (z nil))
    (dolist (op1 ops)
      (if z (return))
      (dolist (op2 ops)
        (if z (return))
        (dolist (op3 ops)
          (when (= 7 (funcall (symbol-function op3) (funcall (symbol-function op2) (funcall (symbol-function op1) (first abcd) (second abcd)) (third abcd)) (fourth abcd)))
            (format t "~a~a~a~a~a~a~a=7~%" (first abcd) op1 (second abcd) op2 (third abcd) op3 (fourth abcd))
            (setf z t)
            (return)))))))
(main)


Measured memory_bytes: 11492
#include<iostream>
using namespace std;
int main()
{
    int N, max = 0, min = 1000000000;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++)
        cin >> A[i];
    for(int i = 0; i < N; i++)
    {
        if(max < A[i])
            max = A[i];
        if(min > A[i])
            min = A[i];
    }
    cout << max - min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	string s; cin >> s;
	int cnt = 0;
	rep(i, n - 2)
	{
		if (s.substr(i, 3) == "ABC")++cnt;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include  "bits/stdc++.h"
using namespace std;
 
#define IOS         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define mem(a,v)    memset((a), (v), sizeof (a))
#define mp(a , b)   make_pair(a , b)
#define eb(a)       emplace_back(a)
#define anal         '\n'
#define mod 1000000007

typedef long long ll;



int main(){
     
 IOS;
 

 // # #-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
   
   int n;
   cin >> n;
   string s;
   cin >> s;  
   if(s.length() <= n){
   	  cout << s ;
   	  return 0;
   }

   for(int i = 0; i < n; i++){
   	  cout << s[i];
   }
   cout << "...";
return  0 ;      
}        





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

int main() {
  int K, A, B, x;
  cin >> K >> A >> B;
  x = B - K*(B/K);
  
  if (x <= (B - A)) {
    cout << "OK" << endl;
  }
  else {
    cout << "NG" << endl;
  }
  
}


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

int gcd(long long x, long long y){
  if (x > y) return gcd(y, x);
  if (y % x == 0) return x;
  return gcd(y % x, x);
}

int main(){
  long long N, X;
  cin >> N >> X;
  long long x[N], ans;
  for (int i = 0; i < N; i++){
    cin >> x[i];
    if (i == 0)
      ans = abs(X - x[i]);
    else
      ans = gcd(abs(X - x[i]), ans);
  }
  cout << ans << endl;
  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine();
        var digit = int.Parse(l.Split(' ')[0]);
        var num = int.Parse(l.Split(' ')[1]);
        //line.Split(' ');
        var flag = true;

        if(num == 0)
        {
            if(digit == 1)
            {
                Console.WriteLine(0);
            }
            else
            {
                var s = "1";
                for(var i = 2; i < digit + 1; i++)
                {
                    s += "0";
                }
                Console.WriteLine(s);
            }
            return;
        }


        var dict = new Dictionary<int, int>();
        for(var i = 0; i < num; i++)
        {
            var line = Console.ReadLine();
            var digitPlace = int.Parse(line.Split(' ')[0]);
            var digitNum = int.Parse(line.Split(' ')[1]);

            if (!dict.ContainsKey(digitPlace))
            {
                dict.Add(digitPlace, digitNum);
            }
            else
            {
                if(dict[digitPlace] != digitNum)
                {
                    flag = false;
                    break;
                }
            }
        }
        var str = "";

        if (flag)
        {
            for(var i = 1; i < digit + 1; i++)
            {
                if(i == 1 && dict.ContainsKey(1) && dict[1] == 0 && digit != 1)
                {
                    Console.WriteLine(-1);
                    break;
                }

                if (dict.ContainsKey(i))
                {
                    str += dict[i];
                }
                else
                {
                    if(i == 1)
                    {
                        str += "1";
                    }
                    else
                    {
                        str += "0";
                    }
                }
            }

            Console.WriteLine(str);
        }
        else
        {
            Console.WriteLine(-1);
        }

        //Console.ReadKey();
    }
}



Measured memory_bytes: 13152
s=input()
t=input()

ans=1000
for i in range(len(s)-len(t)+1):
  a=s[i:len(t)+i]
  num=0
  for i,j in zip(t,a):
    if i!=j:
      num+=1
  ans=min(ans,num)

print(ans)
    
    

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

int main() {
  ll  A, B, C, K;
  cin >> A >> B >> C >> K;

  if(K < A) cout << K << endl;
  else{
    if(K <= A + B) cout << A << endl;
    else{
      if(K <= A+B+C) cout << A * 2 - K + B << endl;
      else cout << A - C << endl;
    }
  }

}


Measured memory_bytes: 3636
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <tuple> 
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;


const int INF = 1e8;

typedef int Weight;
typedef int Flow;

const double EPS = 1e-6;

struct Edge {
	int src, dest, rev;
	Flow cap;
	Weight cost;
	bool operator < (const Edge &rhs) const {
		return cost > rhs.cost;
	}
	Edge(int s, int d) : src(s), dest(d) { ; }
	Edge(int s, int d, int c) : src(s), dest(d), cost(c) { ; }
	Edge(int s, int d, int r, Flow cp, Weight cst) : src(s), dest(d), rev(r), cap(cp), cost(cst) { ; }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, Flow cap) {
	g[src].push_back(Edge(src, dest, (int)g[dest].size(), cap, 0));
	g[dest].push_back(Edge(dest, src, (int)g[src].size() - 1, 0, 0));
}

Flow dfs(Graph &g, vector<bool> &used, int v, int t, Flow f) {
	if (v == t) return f;
	used[v] = true;
	for (Edge& e : g[v]) {
		if (!used[e.dest] && e.cap > EPS) {
			Flow d = dfs(g, used, e.dest, t, min(f, e.cap));
			if (d > EPS) {
				e.cap -= d;
				g[e.dest][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

Flow ford_fulkerson(Graph &g, int s, int t) {
	Flow flow = 0;
	for (;;) {
		vector<bool> used(g.size(), false);
		Flow f = dfs(g, used, s, t, INF);
		if (abs(f) < EPS) return flow;
		flow += f;
	}
}

int main() {
	ll V, E;
	cin >> V >> E;
	Graph g(V + 2);
	for (int i = 0;i<E;i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		add_edge(g, a, b, c);
		g[a].push_back(Edge(a, b, c));
	}
	cout << ford_fulkerson(g, 0, V - 1) << endl;
	return 0;
}

Measured memory_bytes: 3192