akhauriyash/Code-Regression huggingface dataset:
#include<iostream> 
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++) 
 
int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int l_i, r_i;
        cin >> l_i >> r_i;
        ans += (r_i+1 - l_i);
    } 
    cout << ans << endl;
}
 

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

int N;
int store[200007];

int main()
{
    cin >> N;
    int mx = 0, scndmx = 0;
    for (int i = 0; i < N; i++) {
        scanf("%d", &store[i]);

        if (store[i] > mx) {
            scndmx = mx;
            mx = store[i];
        }
        else if (store[i] > scndmx) scndmx = store[i];
    }


    for (int i = 0; i < N; i++) {
        if (store[i] == mx) printf("%d\n", scndmx);
        else printf("%d\n", mx);
    }

}


Measured memory_bytes: 2432
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=a&&a<b)
using namespace std;
int w,h,gy,gx,ans,m[7][7],c[7][7][7][7],dy[]={-1,0,1,0},dx[]={0,-1,0,1};
void dfs(int y,int x,int cy,int cx){
	int cc=c[y][x][cy][cx];
	if(cy==gy&&cx==gx&&ans>cc){
		ans=cc;return;
	}
	rep(d,4){
		int ny=y+dy[d],nx=x+dx[d];
		if(!ck(ny,h)||!ck(nx,w))continue;
		if(!m[ny][nx]&&!(ny==cy&&nx==cx)&&c[ny][nx][cy][cx]>cc)
		c[ny][nx][cy][cx]=cc,dfs(ny,nx,cy,cx);
		if(ny==cy&&nx==cx){
			int nny=ny+dy[d],nnx=nx+dx[d];
			if(ck(nny,h)&&ck(nnx,w)&&!m[nny][nnx]&&c[y][x][nny][nnx]>cc+1)
			c[y][x][nny][nnx]=cc+1,dfs(y,x,nny,nnx);
		}
	}
}
int main(){
	while(cin>>w>>h,w){
		int sy,sx,cy,cx;
		rep(i,h)rep(j,w){
			int &t=m[i][j];cin>>t;
			if(2<=t&&t<=4)(t>2?t>3?(sy=i,sx=j):(gy=i,gx=j):(cy=i,cx=j)),t=0;
		}
		rep(i,h)rep(j,w)rep(k,h)rep(l,w)c[i][j][k][l]=1<<20;
		c[sy][sx][cy][cx]=0;ans=1<<20;dfs(sy,sx,cy,cx);
		cout<<(ans==1<<20?-1:ans)<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Maybe
import Control.Monad
import Data.Function (fix)
import Data.Array (Array, array, (!))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
 
getInts :: IO [Int]
getInts = (map parseInt . BS8.words) <$> BS.getLine 
    where parseInt = fst . fromJust . BS8.readInt

data Tree a = Tree (Tree a) a (Tree a)

instance Functor Tree where
    fmap f (Tree l m r) = Tree (fmap f l) (f m) (fmap f r)

index :: Tree a -> Int -> a
index (Tree _ m _) 0 = m
index (Tree l _ r) n = case (n - 1) `divMod` 2 of
    (q,0) -> index l q
    (q,1) -> index r q

nats :: Tree Int
nats = go 0 1
    where go !n !s = Tree (go l s') n (go r s')
            where l = n + s
                  r = l + s
                  s' = s * 2

memo :: (Int -> a) -> (Int -> a)
memo f = index cached
    where cached = fmap f nats

memo2 :: (Int -> Int -> a) -> (Int -> Int -> a)
memo2 f = memo (\x -> memo (f x))

memo3 :: (Int -> Int -> Int -> a) -> (Int -> Int -> Int -> a)
memo3 f = memo (\x -> memo2 (f x))

solve = (1 `subtract`) . length . group

main :: IO ()
main = do
    str <- getLine
    print (solve str)

Measured memory_bytes: 4988
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    sort(ALL_OF(a));
    vector<ll> imos(n+1, 0);
    REP(i, n) imos[i+1] = imos[i] + a[i];
    
    DSRNG(i, n-1, 0) {
        if (imos[i] * 2 < a[i]) {
            cout << n-i << endl;
            break;
        }
    }
    
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;
    ll ans=0,id;
    int N,M;
    ll A,B,C,W;
    int a[100010];
    bool f=false;
    ll sum=0;
    string S;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>S;
    int siz=S.size();
    REP(i,siz){
        if(i==0||(siz-i)%2==1)continue;
        string a,b;
        a=S.substr(0,(siz-i)/2);
        b=S.substr((siz-i)/2,(siz-i)/2);
        if(a==b){
            cout<<(siz-i);
            break;
        }
    }
    return 0;
}


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

using namespace std;

int main() {

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL);

    int n;
    cin >> n;
    int a[n];

    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a, a+n);

    for(int i = 0; i < n; i++)
        cin >> a[i];
    
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            for(int k = j+1; k < n; k++) {
                if(a[i] + a[j] > a[k] && a[i] != a[j]\
                && a[j] != a[k]) ans++;
            }
        }
    }

    cout << ans << endl;

    
    return 0;

    /*
    9 4 6 1 9 6 10 6 6 8
    
    9 -> 2 tändstickor
    4 -> 1 tändsticka
    6 -> 4 tändstickor
    1 -> 1 tändsticka
    10 -> 1 tändsticka
    8 -> 1 tändsticka   

    2+1+4+1+1+1 = 10


    base -> toal amount of sticks of different length
    exponent -> total frequency of different sticks we have

    10^

    */

}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
int fa[N],cnt;
int find(int x)
{
	return x==fa[x]?x:fa[x]=find(fa[x]);
}
void merge(int u,int v)
{
	int x=find(u),y=find(v);
	if (x==y) return;
	fa[x]=y;
	cnt--;
}

signed main()
{
	int n=cnt=read(),m=read();
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		merge(x,y);
	}
	print(cnt-1);

	return 0;
}

Measured memory_bytes: 3984
#include <stdio.h>

int main(){
	int N,K;
	scanf("%d %d",&N,&K);
	if(N%2==1){

	
	if(N/2+1 >= K){
		printf("YES\n");
	}else
		printf("NO\n");
	}else{
	if(N/2 >= K){
		printf("YES\n");
	}else
		printf("NO\n");

	}
}


Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int k;
    cin >> k;
    for(auto&& i : s){
        if(i == s[k - 1]){
            cout << i;
        }else{
            cout << "*";
        }
    }
    cout << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n;
	string s; cin >> n >> s;
	for(char &c : s) c = (c - 'A' + n) % 26 + 'A';
	cout << s << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n,m;
    cin >> n >> m;
    int a[n];
    vector<int> l;
    vector<pair<int,int>> r;
    ll ans = 0;
    rep(i,n){
        cin >> a[i];
        if(0<i){
            if(a[i-1] < a[i]){
                ans += a[i] - a[i-1];
                l.push_back(a[i-1]);
                r.push_back(P(a[i],a[i-1]));
            }else{
                ans += a[i] + m - a[i-1];
                l.push_back(a[i-1]);
                r.push_back(P(a[i]+m,a[i-1]));
            }
        }
    }

    if(m<=2){
        cout << ans << endl;
        return 0;
    }
    if(n==2){
        cout << '1' << endl;
        return 0;
    }

    sort(l.begin(),l.end());
    sort(r.begin(),r.end());

    ll dp[m * 2 + 100] = {};

    ll count = 0;
    ll count1 = 0;
    ll count2 = 0;
    ll sum = 0;
    ll l_ = 0;
    ll r_ = 0;
    srep(i,1,m*2){
        if(i==1){
            while(l[l_]==1){
                count1++;
                l_++;
            }
        }else if(i==2){
            count2 = count1;
            count1 = 0;
            while(l_<n-1 && l[l_]==2){
                count1++;
                l_++;
            }
            while(r_<n-1 && r[r_].first==i){
                count2--;
                r_++;
            }
        }else{
            count += count2;
            count2 = count1;
            count1 = 0;
            sum += count;
            dp[i] = sum;
            while(l_<n-1 && l[l_]==i){
                count1++;
                l_++;
            }
            while(r_<n-1 && r[r_].first==i){
                if(r[r_].second == i-1){
                    count2--;
                }else{
                    count--;
                    sum -= (i-r[r_].second-1);
                }
                r_++;
            }
        }
    }

    ll ans2 = ans;
    srep(i,1,m+1){
        ans2 = min(ans2, ans-dp[i]-dp[i+m]);
    }

    cout << ans2 << endl;
    return 0;
}
 
 


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define pb push_back
#define fi first
#define se second
#define ALL(a) (a.begin(), a.end())
using ll = long long;
template<typename T> void Out(T x) { cout << x << endl; }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x,y,z;
  cin >> x >> y >> z;
  swap(x,y); swap(x, z);
  cout << x  << " " << y << " " << z;

}


Measured memory_bytes: 256
n, m = map(int, input().split())
dist = [-10**18] * n
edge = []
for i in range(m):
    a, b, c = map(int, input().split())
    edge.append((a - 1, b - 1, c))
dist[0] = 0
for i in range(n):
    for i in edge:
        a, b, c = i
        if dist[a] + c > dist[b]:
            dist[b] = dist[a] + c
            updated = True
ans = dist[n - 1]
for i in range(n):
    for i in edge:
        a, b, c = i
        if dist[a] + c > dist[b]:
            dist[b] = dist[a] + c
            updated = True
if ans == dist[n - 1]:
    print(dist[n - 1])
else:
    print("inf")


Measured memory_bytes: 46316
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<string> s(n);

	for(int i=0;i<n;i++)
	{
		cin >> s[i];
		sort(s[i].begin(),s[i].end());
	}

	sort(s.begin(),s.end());

	long long ans=0;

	long long tmp=1;
	for(int i=1;i<n;i++)
	{
		if(s[i-1]==s[i])tmp++;
		else
		{
			ans+=(tmp*(tmp-1)/2);
			tmp=1;
		}
	}

	ans+=(tmp*(tmp-1)/2);




	cout << ans << endl;


}

Measured memory_bytes: 7296
N = int(input())

flag = True
t0 = x0 = y0 = 0
for i in range(N):
    t1, x1, y1 = map(int, input().split())
    t = t1 - t0
    x = x1 - x0
    y = y1 - y0
    if (abs(x) + abs(y)) == 0:
        if t % 2 == 0: pass
    elif t % (abs(x) + abs(y)) != 0:
        flag = False
    t0 = t1
    x0 = x1
    y0 = y1

if flag: print('Yes')
else: print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <string>

int main() {
  int A, B;
  std::string S;
  std::cin >> A >> B >> S;

  auto f = [](int A, int B, std::string S) {
    for (int i = 0; i < A; i++) {
      if (S[i] < '0' || S[i] > '9') {
        return false;
      }
    }

    if (S[A] != '-') {
      return false;
    }

    for (int i = 0; i < B; i++) {
      if (S[A+i+1] < '0' || S[A+i+1] > '9') {
        return false;
      }
    }

    return true;
  };

  std::cout << (f(A, B, S) ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int sum,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10;

	scanf("%d %d %d %d %d %d %d %d %d %d",&s1,&s2,&s3,&s4,&s5,&s6,&s7,&s8,&s9,&s10);

	sum=s1+s2+s3+s4+s5+s6+s7+s8+s9+s10;

	printf("%d\n",sum);

	return 0;
}

Measured memory_bytes: 596
n = int(input())
ds = []
for i in range(n):
  d_1, d_2 = map(int, input().split())
  ds.append((d_1, d_2))
for j in range(n-2):
  if ds[j][0] == ds[j][1] and ds[j+1][0] == ds[j+1][1] and ds[j+2][0] == ds[j+2][1]:
    print("Yes")
    exit()
print("No")

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

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define filename "lynext"
#define freop freopen(filename ".cik","w",stdout);freopen(filename ".gir","r",stdin)
const long long int N = ((long long int)1e5) + 5;
const long long int M = ((long long int)1e3) + 5;
const long long int llinf = (long long int)1e18;
const int inf = INT_MAX;
typedef long long int lli;

lli n;
lli son;
lli arr[N];
lli pref[N];
lli ans;

int main ()
{
	fast;
	//freop;
	cin >> n;
	for (lli i = 1; i <= n; i++)
		cin >> arr[i];
	ans = n;
	sort(arr + 1, arr + n + 1);
	for (lli i = 1; i <= n; i++)
	{
		pref[i] = pref[i - 1] + arr[i];
	}
	for (lli i = 2; i <= n; i++)
	{
		if (arr[i] > pref[i - 1] * 2)
		{
			ans -= (i - 1) - son;
			son = i - 1;
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 1792
from collections import deque

n = int(input())
a = list(map(int, input().split()))

b = deque()
if n % 2 == 0:
    for i in range(n):
        if i % 2 == 0:
            b.append(a[i])
        else:
            b.appendleft(a[i])
else:
    b.appendleft(a[0])
    for i in range(1, n):
        if not i % 2 == 0:
            b.append(a[i])
        else:
            b.appendleft(a[i])

for i in range(len(b)):
    print(b[i], end=" ")


Measured memory_bytes: 25412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15


int main() {
	string s, t;
	cin >> s >> t;
	int ss = s.size();
	int st = t.size();
	sort(all(s));
	sort(all(t));
	reverse(all(t));
	if(s < t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
		
	return 0;
}






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

int main() {
  int x, n;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }

  vector<int> p(n);
  for (int& pi : p) {
    cin >> pi;
  }

  map<int, int> diffs;
  for (int i = 0; i < n; ++i) {
    diffs[p[i]] = abs(p[i] - x);
  }

  int d = 0;
  for (;;) {
    int curr = x - d;
    if (diffs.count(curr) == 0) {
      cout << curr << endl;
      return 0;
    }
    curr = x + d;
    if (diffs.count(curr) == 0) {
      cout << curr << endl;
      return 0;
    }
    ++d;
  }
  // int mindiff = INT_MAX;
  // for (auto& [k, v] : diffs) {
  //   mindiff = min(mindiff, v);
  // }

  // int ret = INT_MAX;
  // for (auto& [k, v] : diffs) {
  //   if (v == mindiff) {
  //     ret = min(ret, k);
  //   }
  // }
  // cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
import sys


A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for _ in range(M)]


ans = 10**9+7

for x,y,c in xyc:
    res = a[x-1] + b[y-1] - c
    ans = min(ans,res)

ans = min(ans,min(a)+min(b))
print(ans)

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

int c[10][10];
int h,w,a,ans;

int main(){

  cin>>h>>w;

  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++)
      cin>>c[i][j];
  }


  for(int k=0;k<10;k++)
    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++)
        if(c[i][j]>c[i][k]+c[k][j])
          c[i][j]=c[i][k]+c[k][j];

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a;
      if(a!=-1) ans+=c[a][1];
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }

ll gcd(ll a, ll b){
        if(b == 0) return a;
        return gcd(b, a % b);
}
// 最小公倍数
ll lcm(ll a, ll b){
        return a / gcd(a, b) * b;
}


int main(int argc, char const *argv[]) {
  ll a,b;
  cin >> a >> b;
  cout << lcm(a,b) << endl;
  return 0;
}


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

int main(){
    int m,f,r;
    while(1){
        cin >> m;
        cin >>f;
        cin >>r;
        if(m == -1 && f == -1 && r == -1) {
            break;
        }
        if(m == -1 || f == -1){
           cout << "F" << endl;
        }else if( m + f >= 80){
            cout << "A" << endl;
        }else if(m + f >= 65 && m + f < 80){
            cout << "B" << endl;
        }else if((m + f >= 50 && m + f < 65) || (m + f >= 30 && m + f < 50 && r >= 50)){
            cout << "C" << endl;
        }else if(m + f >= 30 && m + f < 50){
            cout << "D" << endl;
        }else if(m + f < 30){
            cout << "F" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3104
#include <cmath>
#include <cstdio>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int n; double x[100000], y[100000];
     
    scanf("%d", &n);
     
    for(int i = 0; i < n; i++)
    {
        scanf("%lf", &x[i]);
        scanf("%lf", &y[i]);
    }
     
    pair<double, double> p1[100000], p2[100000];
     
    for(int i = 0; i < n; i++)
    {
        p1[i] = make_pair(x[i], y[i]);
    }
     
    for(int i = 0; i < n; i++)
    {
        p2[i] = make_pair(y[i], x[i]);
    }
     
    sort(p1, p1 + n);
    sort(p2, p2 + n);
     
    double sqr_ans = 100000000.0;
     
    const int loops = 111;
     
    for(int i = 0; i < n - 1; i++)
    {
        int r = min(loops, n - i - 1);
         
        for(int j = 1; j <= r; j++)
        {
            double distance_ = (p1[i + j].first - p1[i].first) * (p1[i + j].first - p1[i].first) + (p1[i + j].second - p1[i].second) * (p1[i + j].second - p1[i].second);
         
            sqr_ans = min(distance_, sqr_ans);
        }
    }
     
    for(int i = 0; i < n - 1; i++)
    {
        int r = min(loops, n - i - 1);
         
        for(int j = 1; j <= r; j++)
        {
            double distance_ = (p2[i + j].first - p2[i].first) * (p2[i + j].first - p2[i].first) + (p2[i + j].second - p2[i].second) * (p2[i + j].second - p2[i].second);
         
            sqr_ans = min(distance_, sqr_ans);
        }
    }
     
    printf("%.9f\n", sqrt(sqr_ans));
     
    return 0;
}

Measured memory_bytes: 7444
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    int n ,k;
    string s;
    
    cin >> n >> k >> s;
    
    s[k-1] = char(int(s[k-1]) + 32);
    
    cout << s << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int a[] = new int[n + 1];

		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
		}

		int ans = 0;
		for (int i = k; i < n; i += (k - 1)) {
			ans++;
		}

		System.out.println(ans + 1);

		sc.close();

	}

}


Measured memory_bytes: 59404
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000

/*
  A,B,Cに分けて議論したくなるが、ele1は~以降、ele2は~以降、ele3は~以降、というようには議論できないことに気がつく。
  配列的に処理するためには、やはり、10^9の配列を考えるしかない。
  P以上の合計を持つ組み合わせがK個存在する、時のPを求めたい。
  （これが求まれば、あとは、K程度の計算量で答えを導ける）
  ポイント
  ・P以上の合計を持つ組がK個以上存在するか否かを判定する関数。
  ・２分探索で境界を見つける。
    （ある点をピンポイントで見つけたい時は２分探索、例えば、10^12オーダーの中からであっても、40回くらいで見つけられる）
*/

void merge_sort(long *t1, int left, int right){    //アドレスが渡される
    if(left==right){
        ;
    }
    else{
        int n2=(right-left+1)/2;
        int n3=right-left+1-n2;
        int i=0,j=0,k=0;

        merge_sort(t1,left,left+n2-1);
        merge_sort(t1,left+n2,right);

        long t2[n2];
        long t3[n3];
        for(i=0;i<n2;i++){
          t2[i]=t1[left+i];
        }
        for(i=0;i<n3;i++){
          t3[i]=t1[left+n2+i];
        }

        for(i=0;i<n2+n3;i++){
            if(k==n3 || (j<n2 && t2[j]<t3[k])){
                t1[left+i]=t2[j];
                j++;
            }
            else{
                t1[left+i]=t3[k];
                k++;
            }
        }
    }
}

//XY+Kオーダー
bool solve(long P, int K, long *A, long *B, long *C, int X, int Y, int Z){
  int count=0;
  rrep(i,X){
    rrep(j,Y){
      rrep(k,Z){
        if(A[i]+B[j]+C[k]<P){
          break;
        }
        count++;
        if(count>=K){
          return true;
        }
      }
    }
  }
  return false;
}


long binary(long N, int K, long *A, long *B, long *C, int X, int Y, int Z){
  long lb=-1;
  long ub=N;

  //解の存在範囲が２個になるまで、繰り返す。
  while(ub-lb>1){
    long mid=(ub+lb)/2;
    if(solve(mid, K, A, B, C, X, Y, Z)){
      lb=mid;
    }
    else{
      ub=mid;
    }
  }
  //この時点で、ub-lb==1
  //a[lb] <= k <= a[ub]となる
  return lb;
}


int main(){
  char buf[20000];
  int X,Y,Z,K;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d %d %d", &X, &Y, &Z, &K);

  long *A=(long *)malloc(sizeof(long)*X);
  rep(i,X){
    scanf("%ld",&A[i]);
  }
  long *B=(long *)malloc(sizeof(long)*Y);
  rep(i,Y){
    scanf("%ld",&B[i]);
  }
  long *C=(long *)malloc(sizeof(long)*Z);
  rep(i,Z){
    scanf("%ld",&C[i]);
  }

  merge_sort(A, 0, X-1);
  merge_sort(B, 0, Y-1);
  merge_sort(C, 0, Z-1);

  long N=A[X-1]+B[Y-1]+C[Z-1]+1;
  long P=binary(N, K, A, B, C, X, Y, Z);

  long *ans=(long *)malloc(sizeof(long)*K);
  int n=0;
  rrep(i,X){
    rrep(j,Y){
      rrep(k,Z){
        if(A[i]+B[j]+C[k]<=P){
          break;
        }
        ans[n]=A[i]+B[j]+C[k];
        n++;
      }
    }
  }

  srep(i,n,K){
    ans[i]=P;
  }

  merge_sort(ans, 0, K-1);

  rrep(i,K){
    printf("%ld\n", ans[i]);
  }

  return 0;


}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(void) {
	int x = 0;
	int h = 0, m = 0, s = 0;
	cin >> x;
	if (x >= 3600) {
		h = (int)(x / 3600);
		m = (int)((x % 3600) / 60);
	}
	else {
		m = (int)(x / 60);
	}

	s = x % 60;

	cout << h << ":" << m << ":" << s << endl;

}

Measured memory_bytes: 1168
h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
b = [list(map(int,input().split())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        a[i][j] = abs(a[i][j] - b[i][j])

base = 2**12800 - 1
dp = [[0] * (w+1) for _ in range(h+1)]
dp[1][1] = (2**6400 >> a[0][0])|(2**6400 << a[0][0])&base
for i in range(1,h+1):
    for j in range(1,w+1):
        if(i==1)&(j==1):
            dp[1][1] = (2**6400 >> a[0][0])|(2**6400 << a[0][0])&base
            continue

        dp[i][j] = ((dp[i-1][j] >> a[i-1][j-1])|(dp[i-1][j] << a[i-1][j-1])|
                    (dp[i][j-1] >> a[i-1][j-1])|(dp[i][j-1] << a[i-1][j-1]))&base

ans = 6400
ans_bit = dp[-1][-1]
for i in range(6300,6500):
    if((ans_bit >> i)&1 == 1):
        ans = min(ans, abs(6400-i))

print(ans)

Measured memory_bytes: 52700
kai = [1]

s = 1
for i in range(1,51):
    s *= i
    kai.append(s)

n,a,b = map(int,input().split())

vl = list(map(int,input().split()))
vl = sorted(vl)
member = vl[-a:]
ans = sum(vl[-a:]) / len(vl[-a:])
v = vl[-a]
m = vl.count(v)
k = member.count(v)
if member[0] == member[-1]:
    print(ans)
    ans2 = 0
    for i in range(a, min(b, m)+1):
        ans2 += kai[m] // (kai[i] * kai[m-i])
    print(ans2)

else:
    print(ans)
    print(kai[m]//(kai[k] * kai[m-k]))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
  	cin>>a>>b;
  	int ans=0;
  	int eat=0;
  	for(int i=0;i<a;i++){
      ans+=b+i;
    }
  	if(b>=0){
      ans-=b;
      cout<<ans<<endl;
    }else if(abs(b)<a){
      cout<<ans<<endl;
    }else{
      ans-=b+a-1;
      cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
while True:
  try:
   w=float(input())
   if w<=48:
    judge='light fly'
   elif 48<=w<=51:
    judge='fly'
   elif 51<=w<=54:
    judge='bantam'
   elif 54<=w<=57:
    judge='feather'
   elif 57<=w<=60:
    judge='light'
   elif 60<=w<=64:
    judge='light welter'
   elif 64<=w<=69:
    judge='welter'
   elif 69<=w<=75:
    judge='light middle'
   elif 75<=w<=81:
    judge='middle'
   elif 81<=w<=91:
    judge='light heavy'
   else:
    judge='heavy'  
   print(judge)
  except EOFError:
   break

Measured memory_bytes: 7424
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

void Main(){
    ll H, N, a;
    sll(H);
    sll(N);
    ll s = 0;
    rep(i, N){
        sll(a);
        s += a;
    }

    if(s>=H){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;

    }


}

int main(){
    Main();
}

Measured memory_bytes: 3148
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <assert.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp

//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
//const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
const int MAX=1e5+5;
//const ll MAXN=2e8;
//const int MAX_N=MAX;
//const ll MOD=1e15+37;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
void open()
{
//    freopen("1009.in","r",stdin);
    freopen("out.txt","w",stdout);
}
int n;
int a[MAX],b[MAX],c[MAX];
int pre[MAX];
ll an;
int lo;
ll sum;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=0;i<n;i++)scanf("%d",&b[i]);
    for(int i=0;i<n;i++)scanf("%d",&c[i]);
    sort(a,a+n);sort(b,b+n);sort(c,c+n);
    lo=0;
    for(int i=0;i<n;i++)
    {
        while(lo<n&&a[lo]<b[i])++lo;
        pre[i]=lo;
    }
    lo=0;
    for(int i=0;i<n;i++)
    {
        while(lo<n&&b[lo]<c[i])
        {
            sum+=pre[lo];
            ++lo;
        }
        an+=sum;
    }
    printf("%lld\n",an);



}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll MAX=105;
vector<ll> conn[MAX];
vector<pii> edge;
queue<ll> bfs;
ll n,chk[MAX],k,mdep[MAX],fin1=MAX,fin2=MAX;
pii build(ll x){
    ll t,color=0,val=1;
    bfs.push(x); chk[x]=x;
    while(!bfs.empty()){
        ll r=bfs.size();
        mdep[color]=0;
        for(ll i=0;i<r;i++){
            t=bfs.front();
            bfs.pop(); chk[t]=x;
            ll next=0;
            for(ll i=0;i<conn[t].size();i++) if(chk[conn[t][i]]!=x) {
                bfs.push(conn[t][i]);
                next++;
            }
            mdep[color]=max(mdep[color],next);
        }
        color++;
    }
    for(ll i=0;i<color-1;i++) val*=mdep[i];
    return make_pair(color,val);
}
pii build2(ll x,ll y){
    ll t,color=0,val=1,code=x*120+y;
    bfs.push(x); chk[x]=code;
    bfs.push(y); chk[y]=code;
    while(!bfs.empty()){
        ll r=bfs.size();
        mdep[color]=0;
        for(ll i=0;i<r;i++){
            t=bfs.front();
            bfs.pop(); chk[t]=code;
            ll next=0;
            for(ll i=0;i<conn[t].size();i++) if(chk[conn[t][i]]!=code) {
                bfs.push(conn[t][i]);
                next++;
            }
            mdep[color]=max(mdep[color],next);
        }
        color++;
    }
    for(ll i=0;i<color-1;i++) val*=mdep[i];
    return make_pair(color,val*2);
}
int main(){
    scanf("%lld",&n);
    for(ll i=0;i<n-1;i++){
        ll t1,t2;
        scanf("%lld%lld",&t1,&t2);
        conn[t1].push_back(t2);
        conn[t2].push_back(t1);
        edge.push_back(make_pair(t1,t2));
    }
    for(ll i=1;i<=n;i++){
        pii tmp=build(i);
        if(tmp.first<fin1) fin1=tmp.first,fin2=tmp.second;
        else if(tmp.first==fin1) fin2=min(tmp.second,fin2);
        //printf("%lld%d\n",tmp.first,tmp.second);
    }
    for(ll i=0;i<n-1;i++){
        pii tmp=build2(edge[i].first,edge[i].second);
        if(tmp.first<fin1) fin1=tmp.first,fin2=tmp.second;
        else if(tmp.first==fin1) fin2=min(tmp.second,fin2);
        //printf("%lld%d\n",tmp.first,tmp.second);
    }
    printf("%lld %lld\n",fin1,fin2);
    /*
    k=dnode(1);
    k=depth(k);
    if(k)
    */
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <set>

using namespace std;

#define ALL(n) n.begin(), n.end()
#define mp make_pair

int main(){
    int n;
    while (cin >> n) {
	set< pair<int, pair<int, pair<int, int> > > > s;
	for (int i = 0; i < 10; i++)
	    for (int j = 0; j < 10; j++)
		for (int k = 0; k < 10; k++)
		    for (int l = 0; l < 10; l++)
			if (i+j+k+l == n)
			    s.insert(mp(i, mp(j, mp(k, l))));
			    
	cout << s.size() << endl;
    }

    return 0;
}

Measured memory_bytes: 1232
import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = in.nextInt();

		}
		int q = in.nextInt();
		for (int i = 0; i < q; i++) {

			if(solve(c,0,in.nextInt())) {
				System.out.println("yes");
			}else{
				System.out.println("no");
			};

		}

		in.close();
	}

	private static boolean solve(int[] c,int i, int m) {
		boolean res;
	   if (m == 0) {
	     return true;
	   }
	   if (i == c.length) {
	     return false;
	   }
	   res = solve(c,i + 1, m) || solve(c,i + 1, m - c[i]);
	   return res;
	}
}



Measured memory_bytes: 26720
def prime(n):
  l = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(n)]
  l[0] = l[1] = False
  l[2] = l[3] = l[5] = True
  sqrt = n**(1/2)
  for s in range(3,n,2):
    if s>=sqrt:
      return l
    for s in range(s**2,n,s): 
      l[s]=False

S=100001
l=prime(S)
cd=[3]+[i for i in range(5,S,4) if l[i] and l[(i+1)//2]]
size=len(cd)
m=[0 for _ in range(S)]
p=0
for i in range(S):
  if p<size and i>=cd[p]:
    p+=1
  m[i]=p

for _ in range(int(input())):
  a,b=map(int,input().split())
  print(m[b]-m[a-1])



Measured memory_bytes: 5144
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main() {
    string s(20,'A');
    cin>>s;
    for(int i=19;i>=0;i--){
        if(s[i]!='A')cout<<s[i];
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3020
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define pb(s) push_back(s)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }
int main() {
  ll N;
  cin >>N;
  vl a(3*N);
  rep(i,3*N) {
    cin >>a.at(i);
  }
  
  sort(all(a));
  
  ll sum=0;
  repl(i,1,N+1) {
    sum +=a.at(3*N-i*2);
  }
  cout<<sum<<endl;
}
  

Measured memory_bytes: 2560
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int NN=300000 +13;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
int n,len;
int a[NN]={};
int t[NN]={};
bool l[NN]={},r[NN]={};
int main(){
//	freopen("test.in","r",stdin);
	int n=read(),len=read();
	LL ans=0;
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	for(int i=1;i<=n;++i){
		t[i]=read();
		ans+=t[i]/(2*len)*2;
		t[i]%=2*len;
		if(t[i]==0){
			ans-=2;
			t[i]+=2*len;
		}
	}
	for(int i=1;i<=n;++i){
		l[i]=(t[i]<=2*(len-a[i]));
		r[i]=(t[i]<=2*a[i]);
		if(!l[i]&&!r[i]){
			ans+=2;
		}
		else{
			ans+=1;
		}
	}
	ans+=1;
	int more=0;
	int i=1;
	int lcnt=0;
	bool fl=0;
	for(;i<=n;++i){
		if(l[i]||r[i]){
			if(l[i]&&!r[i]){

				//if((i==n)&&(more<0)&&((-more)&1)){
			//		fl=1;
			//	}
				more++;
			}
			else if(l[i]&&r[i]){
				if(more>0){
					lcnt+=more;
					more=0;
				}
				--more;
			}
			else{
				break;
			}
		}
		else{
			if(i==n)fl=1;
		}
	}
	int mid=0;
	if(more<0)mid=-more;
	if(more>0)
		lcnt+=more;
	more=0;
	int rcnt=0;
	for(;i<=n;++i){
		if(l[i]||r[i]){
			if(l[i]&&r[i]){
				if(i==n){
					if(more<0)fl=1;
				}
				more++;
			}
			else if(!l[i]&&r[i]){
				if(i==n)fl=1;
				if(more>0){
					rcnt+=more;
					more=0;
				}
				--more;
			}
			else{
				break;
			}
		}
		else{
			if(i==n)fl=1;
		}
	}
	if(more>0){
		rcnt+=more;
	}
	if(more<0)fl=1;
	mid=rcnt+mid;
	if(mid&1){
		mid=1;
	}
	else{
		mid=0;
		fl=1;
	}
	rcnt=max(0,-more);
	ans+=(rcnt+lcnt+mid-1);
	if(fl==1)ans+=2;
	printf("%lld\n",(LL)ans*len);
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rloop(i,a,b) for(ll i=a;i>b;i--)
const int inf=1e9+7;



int main()
{

ll n,k;
cin>>n>>k;
ll a[n];

loop(i,0,n)
{
	cin>>a[i];
}

bool dp[k+1];
dp[0]=false;
loop(i,1,k+1)
{
	bool flag=false;
	loop(j,0,n)
	{
		if(i==a[j])
		flag=true;
		else if(i-a[j]>0)
		flag+=!(dp[i-a[j]]==true);
		
		if(flag)break;
	}
	
	dp[i]=flag;

	
}
	
	if(dp[k])cout<<"First";
	else cout<<"Second";	
	
	
}

Measured memory_bytes: 384
import sys
input=sys.stdin.readline
while True:
	rr=[]
	h,w=map(int,input().split())
	if h==w==0:
		break
	else:
		for i in range(h):
			r=input().rstrip()
			rr.append(r)
		s=input().rstrip()
		ans=0
		now=[0,0]
		for i in range(len(s)):
			for j in range(h):
				for k in range(w):
					if rr[j][k]==s[i]:
						ans+=abs(now[0]-j)+abs(now[1]-k)
						now=[j,k]
		print(ans+len(s))



Measured memory_bytes: 5628
#設定
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

def DFS(G, XOR, visit, node):
	for i in G.graph[node]:
		if visit[i] != "Yes":
			visit[i] = "Yes"
			DFS(G, XOR, visit, i)
			XOR[node] ^= XOR[i] + 1

#処理内容
def main():
	N = int(input())
	G = Graph()
	for i in range(N - 1):
		x, y = getlist()
		x -= 1
		y -= 1
		G.add_edge(x, y)
		G.add_edge(y, x)

	#計算
	XOR = [0] * N
	visit = ["No"] * N
	visit[0] = "Yes"
	DFS(G, XOR, visit, 0)
	if XOR[0] == 0:
		print("Bob")
	else:
		print("Alice")
	

if __name__ == '__main__':
	main()

Measured memory_bytes: 119992
n = gets.to_s.to_i
a = gets.to_s.split.map{|t| t.to_i }.sort
n = a.size

m = a[-1] / 2

x = a[0,n-1].bsearch{ |t| t >= m }
x = a[0,n-1].bsearch{ |t| t >= m+1 } if a[-1].odd?
y = a[0,n-1].reverse.bsearch{ |t| t <= m }

# if a[-1].odd?
#   y = a[0,n-1].reverse.bsearch{ |t| t <= m+1 }
# end

# p [x, y, a[-1] - x, y]
# if a[-1].odd?
# p x
# p y

if (x && y && x-m <= m-y) || !y
  puts "#{a[-1]} #{x}"
else
  puts "#{a[-1]} #{y}"
end

Measured memory_bytes: 10120
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      String output = "second";
      for(int i = 0; i < N; i++){
        if(nextInt() % 2 == 1){
          output = "first";
          break;
        }
      }
      myout(output);
	}
	//Method addition frame start


  
	//Method addition frame end
}


Measured memory_bytes: 43888
n, m, k = map(int, input().split())
flg = False
for i in range(n+1):
  for j in range(m+1):
    total = (n-i)*j + i*(m-j)
    if total == k:
      flg = True
      break
if flg:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    REP(i, s.size()){
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,a[2001];
long long s=0;

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
}

int bina(int l,int x)
{
    int kq=l,r=n,mid;
    while (l<=r)
    {
        mid=(l+r)/2;
        if (a[mid]<=x)
        {
            l=mid+1;
            kq=mid;
        }
        else r=mid-1;
    }
    return kq;
}

void process()
{
    for (int i=1;i<n;++i)
    {
        for (int j=i+1;j<=n;++j)
        {
            int vt=bina(j,a[i]+a[j]-1);
            while (a[vt]==a[vt+1])
                vt++;
            s+=vt-j;
        }
    }
    cout<<s;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i,j,n,v,k;
    scanf("%d",&n);
    int A[n];
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    for(i=0;i<n-1;i++) printf("%d ",A[i]);
    printf("%d\n",A[n-1]);
    for(i=1;i<=n-1;i++){
        v = A[i];
        j = i-1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }
        for(k=0;k<n-1;k++) printf("%d ",A[k]);
            printf("%d\n",A[n-1]);
    }
    return 0;
}




Measured memory_bytes: 2044
main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  print (case (n,m) of
    (1,1) -> 1
    (1,n) -> max 0 (n-2)
    (n,1) -> max 0 (n-2)
    (n,m) -> (n-2) * (m-2))

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

const int maxnodes = 101;

int nodes = maxnodes, src, dest;
int dist[maxnodes], q[maxnodes], work[maxnodes];

struct Edge {
  int to, rev;
  int f, cap;
};

vector<Edge> g[maxnodes];

// Adds bidirectional edge
void addEdge(int s, int t, int cap){
  Edge a = {t, (int) g[t].size(), 0, cap};
  Edge b = {s, (int) g[s].size(), 0, 0};
  g[s].push_back(a);
  g[t].push_back(b);
}

bool dinic_bfs() {
  fill(dist, dist + nodes, -1);
  dist[src] = 0;
  int qt = 0;
  q[qt++] = src;
  for (int qh = 0; qh < qt; qh++) {
    int u = q[qh];
    for (int j = 0; j < (int) g[u].size(); j++) {
      Edge &e = g[u][j];
      int v = e.to;
      if (dist[v] < 0 && e.f < e.cap) {
        dist[v] = dist[u] + 1;
        q[qt++] = v;
      }
    }
  }
  return dist[dest] >= 0;
}

int dinic_dfs(int u, int f) {
  if (u == dest)
    return f;
  for (int &i = work[u]; i < (int) g[u].size(); i++) {
    Edge &e = g[u][i];
    if (e.cap <= e.f) continue;
    int v = e.to;
    if (dist[v] == dist[u] + 1) {
      int df = dinic_dfs(v, min(f, e.cap - e.f));
      if (df > 0) {
        e.f += df;
        g[v][e.rev].f -= df;
        return df;
      }
    }
  }
  return 0;
}

int maxFlow(int _src, int _dest) {
  src = _src;
  dest = _dest;
  int result = 0;
  while (dinic_bfs()) {
    fill(work, work + nodes, 0);
    while (int delta = dinic_dfs(src, INT_MAX))
      result += delta;
  }
  return result;
}

int main() {
    int n, m;
    cin >> n >> m;
    nodes = n;
    int s, d, c;
    for (int i = 0; i < m; i++) {
        cin >> s >> d >> c;
        addEdge(s, d, c);
    }
    cout << maxFlow(0, n - 1) << endl;
}


Measured memory_bytes: 3176