akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <limits>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <array>
#include <tuple>
#include <utility>
#include <cctype>
#include <typeinfo>
using namespace std;

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define ii(n)    ff(i, n)
#define kk(n)    ff(k, n)
#define mm(n)    ff(m, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define iii(a, b) fff(i, a, b)
#define kkk(a, b) fff(k, a, b)
#define mmm(a, b) fff(m, a, b)
#define xx first
#define yy second
#define bb begin()
#define ee end()
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }

using LL = long long;
using pii = pair<int, int>;


const LL INF = 9223372036854775807LL;
//const int INF = 2147483647;
   




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout << '\n';
    

    int N;
    cin >> N;
    string ox;
    cin >> ox;

    ii (4) {
        vector<int> animals = {i/2, i%2};
        kkk (2, N) {
            bool sheepsame_wolfdiff = (ox[k-1] == 'o');
            animals.append(animals[k-1] 
                                ^ sheepsame_wolfdiff
                                ^ animals[k-2]);
        }

        bool fail = false;
        kk (N) {
            bool here_sheep = bool(animals[k]);
            bool left_sheep = bool(animals[(k-1+N)%N]);
            bool right_sheep = bool(animals[(k+1)%N]);
            bool sheepsame_wolfdiff = (ox[k] == 'o');
            if (here_sheep ^! sheepsame_wolfdiff
            ^! (left_sheep == right_sheep))
                continue;
            else {
                fail = true;
                break;
            }

        }

        if (!fail) {
            kk (N)
                cout << (animals[k] == 1 ? 'S' : 'W');
            cout << '\n';
            return 0;
        }
    }

    cout << "-1\n";

    return 0;
}



Measured memory_bytes: 1360
<?php
$n = (int)trim(fgets(STDIN));

$input = explode(' ', trim(fgets(STDIN)));
$as = [];
$abs = [];
$abs_sum = 0;
$minus = 0;
$zero = 0;
foreach ($input as $v) {
	$tmp = (int)$v;
	if ($tmp === 0) {
		++$zero;
	}elseif ($tmp < 0) {
		++$minus;
	}
	$abs[] = abs($tmp);
	$abs_sum += abs($tmp);
	// echo $abs_sum . PHP_EOL;
}

sort($abs);
// var_dump($abs);
if ($minus % 2 === 1 && $zero === 0) {
	$abs_sum -= ($abs[0] * 2);
}
echo $abs_sum;

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


void solve(long long N, std::vector<long long> A){
    long long k = 0;
    long long c = 1000;
    for(int i = 0; i < N; ++i){
        if(A[i+1] - A[i] > 0){
            long long cnt = 0;
            while(c/A[i] != 0){
                cnt = cnt + c / A[i];
                c = c % A[i];
            }
            k = k + cnt;
        }
        else if(A[i+1] - A[i] == 0){
            continue;
        }
        else{
            c = c + A[i] * k;
            k = 0;
        }
        //cout << "c:" << c << ",k:" << k << endl;
    }
    cout << c + k * A[N - 1] << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 3708
n,k=map(int,input().split())
h=list(map(int, input().split()))
v=[0]*n
for i in range(1,n):
	u = h[i]
	v[i] = min([v[j] + abs(h[j]-u) for j in range(max(0, i-k), i)])
print(v[n-1])

Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
int main(){
  int c[5][5],cnt=0;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>c[i][j];
    }
  }
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      for(int k=0;k<=100;k++){
        if(c[0][0]-i==c[0][1]-j){
          if(c[0][1]-j==c[0][2]-k){
            if(c[1][0]-i==c[1][1]-j){
              if(c[1][1]-j==c[1][2]-k){
                if(c[2][0]-i==c[2][1]-j){
                  if(c[2][1]-j==c[2][2]-k)cnt++;
                }
              }
            }
          }
        }
      }
    }
  }
  if(cnt>0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return(0);
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> h(n);
    REP(i, n) cin >> h[i];

    int cur = 0;
    int ans = 0;
    REP(i, n) 
    {
        if(h[i] >= cur) ans++;

        cur = max(cur, h[i]);
    }
    cout << ans << endl;
    
}   

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using ll = long long;
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<string> s(N);
    const string ab = "AB";
    vector<int> idx_left_candidate, idx_right_candidate, idx_both_candidate;
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        cin >> s[i];
        size_t pos = s[i].find(ab, 0);
        // cout << "pos = " << pos << endl;
        while (pos != string::npos)
        {
            ans++;
            pos = s[i].find(ab, pos + 1);
        }
        bool is_left, is_right;
        is_left = is_right = false;
        if (s[i][0] == 'B')
        {
            // cout << s[i] << ": " << "left" << endl;
            idx_right_candidate.push_back(i);
            is_left = true;
        }
        if (s[i][s[i].size()-1] == 'A')
        {
            // cout << s[i] << ": " << "right" << endl;
            idx_left_candidate.push_back(i);
            is_right = true;
        }
        if (is_left && is_right) {
            idx_both_candidate.push_back(i);
        }
    }
    // debug
    // cout << "ans so far : " << ans << endl;

    int cnt_left, cnt_right, cnt_both;
    cnt_left  = idx_left_candidate.size();
    cnt_right = idx_right_candidate.size();
    cnt_both  = idx_both_candidate.size();
    // ans += max(min(cnt_left - cnt_both, cnt_right), min(cnt_left, cnt_right - cnt_both));
    if (cnt_both > 1) {
        ans += cnt_both - 1;
        cnt_left -= cnt_both - 1;
        cnt_right -= cnt_both - 1;
        cnt_both = 1;
    }
    if (cnt_both == 1) {
        cnt_left--;
        cnt_right--;
        if (cnt_left > 0) {
            ans++;
            cnt_left--;
        }
        if (cnt_right > 0){
            ans++;
            cnt_right--;
        }
    }
    ans += min(cnt_left, cnt_right);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int isuruu(int year) {
	if(year%400==0)return 1;
	if(year%4==0 && year%100!=0)return 1;
	return 0;
}

int main(void) {
	int now,to;
	int found=0;
	while(1) {
		scanf("%d %d",&now,&to);
		if(now==0 && to==0)break;
		if(found)puts("");
		found=0;
		for(;now<=to;now++) {
			if(isuruu(now)) {
				printf("%d\n",now);
				found=1;
			}
		}
		if(found==0)printf("NA\n");
		found=1;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int n,a[222222],res;
long long ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) a[i]-=i;
	sort(a+1,a+n+1);
	res=a[(n+1)/2];
	for (int i=1;i<=n;i++) ans+=(long long)(abs(res-a[i]));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=min(a,b);i>=1;i--){
		if(a%i==0 && b%i==0) c--;
		if(c==0){
			printf("%d\n",i);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    vector<P> pqr;
    rep (i, a) { int p; cin >> p; pqr.emplace_back(p, 0); }
    rep (i, b) { int p; cin >> p; pqr.emplace_back(p, 1); }
    rep (i, c) { int p; cin >> p; pqr.emplace_back(p, 2); }
    sort(all(pqr)); reverse(all(pqr));
    int count_a = 0, count_b = 0, count_all = 0;
    int i = 0;
    ll ans = 0;
    while (count_all < x + y) {
        P xx = pqr[i];
        if (xx.second == 2) {
            count_all++;
            ans += xx.first;
        } else if (xx.second == 0 && count_a < x) {
            count_all++; count_a++;
            ans += xx.first;
        } else if (xx.second == 1 && count_b < y) {
            count_all++; count_b++;
            ans += xx.first;
        }
        i++;
    }
    eprintf("%d %d %d\n", count_a, count_b, count_all);
    cout << ans << "\n";
    return 0;
}

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

/*typedefs*/
typedef vector<int> vi;
typedef map<string,int> msi;
typedef complex<double> point;
typedef  long long ll;


#define all(v)			((v).begin()), ((v).end())
#define SIZE(v)			((int)((v).size()))
#define LOG(x)			log((double)x)
#define TOLOWER(x)          transform(all(x),x.begin(),::tolower)
#define TOUPPER(x)          transform(all(x),x.begin(),::toupper)
#define ROUND(x,m)			(round((double)x/m)*m)
#define DIGITS(x)			(floor(log10((double)x))+1)
#define READSTR(x)			getline(cin,x)
#define sort_g(a,b)              sort(a, b, greater<int>());
#define X real()
#define Y imag()
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define length(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)
#define rotateO(p,ang)          ((p)*exp(point(0,ang)))
#define rotateA(p,ang,about)  (rotateO(vec(about,p),ang)+about)
#define reflectO(v,m)  (conj((v)/(m))*(m))
#define IOS() ios_base::sync_with_stdio(0);cin.tie(NULL);
#define REP(i, n) for (int i = 0; i < n; i++)
#define FILE_INPUT() 	freopen( "input.txt", "r", stdin)
#define FILE_OUTPUT()   freopen( "output.txt", "w", stdout)

bool myCmp(pair<int,int> &p1 , pair<int,int>&p2)
{
    return p1.first > p2.first;
}


unsigned long long
choose(unsigned long long n, unsigned long long k) {
    if (k > n) {
        return 0;
    }
    unsigned long long r = 1;
    for (unsigned long long d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
ll  OO = 10e12;
int main() {
    IOS();
    ll h;
    cin>>h;
    ll t = log2(h);
    for(ll i = 0 ; i <= t ; ++i)
        h|=(1ul<<i);
    cout<<h<<endl;

    return 0;
}


Measured memory_bytes: 512
//




#include <bits/stdc++.h>
using namespace std;


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back()
#define pf push_front
#define ppf pop_front()
#define ff first
#define ss second
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=j; i--)
#define pll pair<ll,ll>
#define plb pair<ll,bool>
#define psl pair<string,ll>
#define psb pair<string,bool>
#define srt(v) sort((v).begin(),(v).end())
#define ub(v,val) upper_bound((v).begin(),(v).end(),(val))-(v).begin()
#define lb(v,val) lower_bound((v).begin(),(v).end(),(val))-(v).begin()


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;
const ll mod = (ll) 1e9  +  7;




ll ncr(ll n,ll r) {
    ll val=1,i,j,p=2;
    rfr(i,n-r+1,n+1) {
        val*=i;
        while(val%p==0 && p<=r) {
            val/=p;
            p+=1;
        }
    }
    if(p<r) {
        fr(i,p,r+1) val/=i;
    }
    return val;
}




ll fun(ll n,ll w,ll wt[],ll val[],ll ind,vector <vector <ll> > &dp) {
    if(ind>=n || w<=0) return 0;
    if(dp[ind][w]!=-1) return dp[ind][w];
    if(w<wt[ind]) return dp[ind][w]=fun(n,w,wt,val,ind+1,dp);
    else return dp[ind][w]=max(fun(n,w,wt,val,ind+1,dp),val[ind]+fun(n,w-wt[ind],wt,val,ind+1,dp));
}




void cazz() {
    ll t=1,i=0,j,n;
    //cin>>t;
    while(t--) {
        ll w;
        cin>>n>>w;
        ll wt[n],val[n];
        fr(i,0,n) cin>>wt[i]>>val[i];
        vector <vector <ll> > dp(n+1,vector <ll> (w+1,-1));
        cout<<fun(n,w,wt,val,0,dp)<<"\n";
    }
}




int main() {
    spdio;
	cazz();
	return 0;
}


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

void solve(long long N, std::vector<long long> H){
  long long count = 0;
  long long mymax = 0;

  REP(i, N-1) {
    if(H[i] >= H[i+1]) {
      count++;
      mymax = max(mymax, count);
    }
    else {
      count = 0;
    }
  }

  cout << mymax << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> H(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&H[i]);
  }
    solve(N, std::move(H));
    return 0;
}


Measured memory_bytes: 1024
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    n = int(input())
    p = np.array(read().split(), np.int32)
    r = float('inf')
    for i1 in range(101):
        r = min(r, sum((p - i1)**2))
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 27316
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

A = LIR(3)
n = I()
B = IR(n)

for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = 0

for i in range(3):
    if A[0][i] == A[1][i] == A[2][i] == 0:
        print("Yes")
        exit()

for i in range(3):
    if A[i][0] == A[i][1] == A[i][2] == 0:
        print("Yes")
        exit()

if A[0][0] == A[1][1] == A[2][2] == 0:
    print("Yes")
    exit()

if A[2][0] == A[1][1] == A[0][2] == 0:
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 63340
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int x[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a;
	cin>>a;
	if(a[1]=='B')cout<<"ARC";
	else cout<<"ABC";
	cout<<endl; 
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }



void solve() {
    LL n,k;
    cin >> n >> k;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    VI imos(n+1);
    REP(j,0,k) {
        REP(i,0,n+1) imos[i] = 0;
        REP(i,0,n) {
            imos[max(0LL,i-a[i])]++;
            imos[min(n,i+a[i] + 1)]--;
        }
        REP(i,1,n+1) imos[i] += imos[i-1];
        REP(i,0,n) a[i] = imos[i];
        bool done = true;
        REP(i,0,n) if (a[i] < n) {
            done = false;
            break;
        }
        if (done) break;
    }
    REP(i,0,n) cout << a[i] << " ";
    cout << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

typedef long long ll;

const int MAX_N=1e5;

int N;
vector<int> G[MAX_N];
ll A[MAX_N];

ll dp[MAX_N];
bool ok;

void dfs(int v,int par){
	int chi=0;
	REP(i,(int)G[v].size()){
		if (G[v][i]!=par){
			chi++;
		}
	}
	if (chi==0){
		dp[v]=A[v];
		return;
	}
	ll sum=0,ma=-1;
	REP(i,(int)G[v].size()){
		if (G[v][i]!=par){
			dfs(G[v][i],v);
			sum+=dp[G[v][i]];
			ma=max(ma,dp[G[v][i]]);
		}
	}
	ll x,y;
	x=sum-A[v];
	y=A[v]-x;
	if (A[v]<(sum+1)/2 || sum<A[v]) ok=false;
	if (y<ma-(sum-ma)) ok=false;
	dp[v]=y;
}

void solve(){
	if (N==2){
		if (A[0]==A[1]){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
		return;
	}
	int s=0;
	REP(i,N){
		if (G[i].size()>=2){
			s=i;
			break;
		}
	}
	ok=true;
	dfs(s,-1);
	if (ok && dp[s]==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

}

int main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	REP(i,N-1){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	solve();
	return 0;
}


Measured memory_bytes: 14080
n = int(input())
arr = list(map(int, input().split()))
ai = max(arr)
aj = 0
min_aj = float('inf')
for i in arr:
    if i == ai:
        continue
    if abs((ai - i) - i) < min_aj:
        min_aj = abs((ai - i) - i)
        aj = i
print(ai,aj)

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

const int maxn = 110;
int h, w, n;
int a[10010], c[maxn][maxn];

int main() {
	ios::sync_with_stdio(false);
	cin >> h >> w >> n;
	int nowr = 1, nowc = 1;
	bool turn = true;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		for (int j = 1; j <= a[i]; j++) {
			c[nowr][nowc] = i;
			if (turn) {
				nowc++;
				if (nowc == w + 1) {
					nowr++;
					nowc--;
					turn = false;
				}
			} else {
				nowc--;
				if (nowc == 0) {
					nowr++;
					nowc++;
					turn = true;
				}
			}
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (j > 1) cout << " ";
			cout << c[i][j];
		}
		cout << endl;
	}
	return 0;
}

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

int main()
{
 int n,m,x;
  cin>>n>>m>>x;
  vector<int> v(n+1);
  for(int i=0;i<m;i++)
  {
    int t;
    cin>>t;
    v[t]=1;
  }
  int cur=x+1,cost=0,cost2=0;
  while(cur<=n)
  {cost+=v[cur];cur++;}
  cur=x-1;
  while(cur>=0)
  {cost2+=v[cur];cur--;}
  cout<<min(cost,cost2)<<"\n";    
  
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef pair<ll,ll> pll;
const ll inf = 99999999999;
const int nax = 2e6 + 7;
int n , m;
vector< pair< ll , pair< ll , ll > >  > edges;
int main(){
	dhoom;
	int v , e , s;
	cin >> v >> e >> s;
	for(int i = 0 ; i < e ; i++){
			int u , x , w;
			cin >> u >> x >> w;
			edges.push_back({u , {x, w}});
	}
	ll dis[v];
	for(int i = 0 ; i < v ; i++)
		dis[i] = inf;
	dis[s] = 0;
	for(int i = 0 ; i < v - 1; i++){
		for(int j = 0 ; j < e ; j++){
			ll x = edges[j].first;
			ll y = edges[j].second.first;
			ll wt = edges[j].second.second;
			if(dis[x] < inf)
				dis[y] = min(dis[y] , dis[x] + wt);
		}
	}
	for(int j = 0 ; j < e ; j++){
		ll x = edges[j].first;
		ll y = edges[j].second.first;
		ll wt = edges[j].second.second;
		if(dis[x]!= inf && dis[x] + wt < dis[y])
			return cout << "NEGATIVE CYCLE\n",0;
	}
	for(int i = 0 ; i < v ;i++){
		if(dis[i] == inf)
				cout << "INF" << endl;
	    else 
				cout << dis[i] << endl;
		
	}
    return 0;
}




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

void solve()
{

    long long int N,i,Y,Z,ans=0;
    cin>>N;

     for(i=1;i<=sqrt(N);i++)
     {
        if(N%i==0)
        Y=i;
        Z=N/Y;
        ans=(Y-1+Z-1);
     }
    cout<<ans<<endl;

}

int main ()
{
    solve();

    return 0;
}


Measured memory_bytes: 384
import sys, math, re
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

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

    for i in range(n):
        if s[i] == 'C':
            for j in range(i+1, n):
                if s[j] == 'F':
                    print('Yes')
                    return

    print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9884
n,m = map(int,input().split())

ans = 0
clear = 0

chk = [0]*(n+1)

for i in range(m):
    p,s = input().split()
    p = int(p)
    if chk[p] >=0:
        if s=="WA":
            chk[p]+=1
        elif s =="AC":
            ans += chk[p]
            chk[p]=-1
            clear+=1

print(str(clear)+" "+str(ans))

Measured memory_bytes: 51812
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int[] c = new int[m];
		for (int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
			int b = sc.nextInt();
			int x = 0;
			for (int j = 0; j < b; j++) {
				x |= (1 << sc.nextInt() - 1);
			}
			c[i] = x;
		}

		long[] dp = new long[1 << n];
		Arrays.fill(dp, Long.MAX_VALUE);
		dp[0] = 0;
		for (int i = 0; i < (1 << n); i++) {
			for (int j = 0; j < m; j++) {
				int t = i | c[j];
				if (dp[i] != Long.MAX_VALUE) {
					dp[t] = Math.min(dp[t], dp[i] + a[j]);
				}
			}
		}

		if (dp[(1 << n) - 1] == Long.MAX_VALUE) {
			System.out.println(-1);
			return;
		}

		System.out.println(dp[(1 << n) - 1]);
	}
}


Measured memory_bytes: 32576
#include "bits/stdc++.h"

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;

int main() {
	speed;
	int a, b;
	int sum, dif, prd;
	cin >> a >> b;
	sum = a + b;
	dif = a - b;
	prd = a * b;
	int ans = max(sum, max(dif, prd));
	c(ans);
	return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

s = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                s += 1
    
print(s)

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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define llong long long

int main(){
	int x,t;
	cin>>x>>t;
	if(x>t){
		cout<<x-t<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}

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

int main() {
	
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    
    long long n,m,k,count=0,ans=0,sum=0,l,r,i,j,x,y;
    cin>>n;
    long long a[n],b[1000006]={0};
    
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    sort(a,a+n);
   for(i=n-1;i>=0;i--)
   {
       b[a[i]]--;
       k=a[i];count=0;
       for(j=1;j<=sqrt(k);j++)
       {
           if(k%j==0)
           {
              if(b[j]>0 || b[k/j]>0)
              count=1;
           }
       }
       if(count==0)
       ans++;
       b[a[i]]++;
   }
   cout<<ans;
    
    
	return 0;
}

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

int main()
{
       string str;
       cin >> str;
       int n = str.length();
       if(n%2==0)
       {
           cout << "No" << endl;
           return 0;
       }
       for(int i=0;i<n/2;i++)
       {
           if(str[i]!=str[n-1-i])
           {
               cout << "No" << endl;
               return 0;
           }
       }
       int m = n/2;
       for(int i=0;i<m/2;i++)
       {
           if(str[i]!=str[m-1-i])
           {
               cout << "No" << endl;
               return 0;
           }
       }
       int x = (n+m)/2;
       for(int i=m+2;i<x;i++)
       {
           if(str[i]!=str[n-1-i])
           {
               cout << "No" << endl;
               return 0;
           }
       }
       cout << "Yes" << endl;
       return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main(){
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;
    vector<int> xa, ya;
    int n = (int) s.size();
    int flag = 0;
    int flag2 = 0;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'T') {
            if(flag2 == 0) flag2 = 2;
            if(flag == 0 && cnt > 0) {
                xa.push_back(cnt);
            }
            else if(flag == 1 && cnt > 0)ya.push_back(cnt);
            cnt = 0;
            flag = (flag + 1) % 2;
        }
        else {
            if(flag2 == 0) flag2 = 1;
            cnt++;
        }
    }
    if(cnt > 0 && flag == 0) xa.push_back(cnt);
    else if(cnt > 0 && flag == 1) ya.push_back(cnt);
    vector<vector<bool>> xt(17000, vector<bool>((int)xa.size() + 1, false)), yt(17000, vector<bool>((int)ya.size() + 1, false));
    xt[8010][0] = true, yt[8010][0] = true;
    for(int i = 0; i < (int)xa.size(); i++){
        for(int j = 0; j < 17000; j++){
            if(xt[j][i] == false) continue;
            xt[j + xa[i]][i + 1] = xt[j + xa[i]][i + 1] || xt[j][i];
            if(flag2 == 1 && i == 0) continue;
            xt[j - xa[i]][i + 1] = xt[j - xa[i]][i + 1] || xt[j][i];
        }
    }
    for(int i = 0; i < (int)ya.size(); i++){
        for(int j = 0; j < 17000; j++){
            if(yt[j][i] == false) continue;
            yt[j + ya[i]][i + 1] = yt[j + ya[i]][i + 1] || yt[j][i];
            yt[j - ya[i]][i + 1] = yt[j - ya[i]][i + 1] || yt[j][i];
        }
    }
    bool fx = false, fy = false;
    for(int i = 0; i < 17000; i++){
        if(xt[i][(int)xa.size()] && i - 8010 == x) fx = true;
        if(yt[i][(int)ya.size()] && i - 8010 == y) fy = true;
    }
    if(fx && fy) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 13456
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n; long double d; cin>>n>>d;
  int ans=0;
  for(int i=0;i<n;i++){
    long double a,b, dis; cin>>a>>b;
    dis= sqrt(a*a+b*b);
    if(dis<=d)
      ans++;
  }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 3804
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
 
#pragma comment(linker, "/STACK:336777216")  
 
using namespace std;
 
const int MAXN = 200000 + 10;

int N;
long long a[MAXN], A[MAXN];

int GetMax()
{
	int i = 0;
	for (int j = 0; j < N; j ++)
		if (A[j] > A[i])
			i = j;
	return i;
}

void Work()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i ++)
	{
		scanf("%lld", &a[i]);
		A[i] = a[i];
	}

	long long MX = A[0], MN = A[0], rev = 0;
	for (int i = 0; i < N; i ++)
	{
		MX = max(MX, a[i]);
		MN = min(MN, a[i]);
	}
	if (MN < 0 && MN < -MX)
	{
		rev = 1;
		for (int i = 0; i < N; i ++) A[i] = -a[N - 1 - i];
	}

	vector < pair <int, int> > ans;
	for (int i = 1; i < N; i ++)
	{
		while (A[i] < A[i - 1])
		{
			int pos = GetMax();
			A[i] += A[pos];
			ans.emplace_back(pos, i);
		}
	}

	printf("%d\n", (int) ans.size());
	for (auto it: ans)
	{
		if (rev)
			printf("%d %d\n", N - it.first, N - it.second);
		else
			printf("%d %d\n", it.first + 1, it.second + 1);
	}
}
 
int main()
{
	Work();
	return 0;
}

Measured memory_bytes: 256
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

N = int(input())

Ans = num2alpha(N)
ans = Ans.lower()
print(ans)

Measured memory_bytes: 9116
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

L=input()
n=len(L)
dp1=[0]*(n+1); dp2=[0]*(n+1)
dp2[0]=1

for i in range(n):
    if L[i] == "1":
        dp1[i+1] = (dp1[i]*3 + dp2[i]) % mod
        dp2[i+1] = dp2[i]*2 % mod
    else:
        dp2[i+1] = dp2[i] % mod
        dp1[i+1] = dp1[i]*3 % mod
print((dp1[n] + dp2[n])%mod)

Measured memory_bytes: 41456
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [0 for i in range(N)]
    for i in range(N):
        B[A[i]-1] = i + 1
    for i in range(N):
        print(B[i],end = " ")
    print()

if __name__ == "__main__":
    main()

Measured memory_bytes: 13876
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
int i,j,k,m,n,x,y,tot,ans;
int a[N],b[N],ver[N],nxt[N],head[N],edge[N]; 
void add(int x,int y,int w)
{
	ver[++tot]=y,edge[tot]=w,nxt[tot]=head[x],head[x]=tot;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	k=(n-1)/2;
	for(int i=1;i<=k;i++)
	{
		ans+=a[i*2]-a[i*2-1];
	}
	b[1]=a[n]-ans;
	b[n]=2*a[n]-b[1];
	for(int i=2;i<=n-1;i++)
	{
		b[i]=2*a[i-1]-b[i-1];
	}
	for(int i=1;i<=n;i++) printf("%d ",b[i]);
}

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

num = 0
for i in range(1, N+1):
    divisors = {}
    if i % 2 == 0:
        continue
    for j in range(3, i+1):
        if j % 2 == 0:
            continue
        if i % j == 0:
            if j in divisors.keys():
                divisors[j] += 1
            else:
                divisors[j] = 1
    if sum(divisors.values()) + 1 == 8:
        num += 1

print(num)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    for (int i = 0; i <= 100000; i++){
        if (i/10 == b && (i*8)/100 == a){
            printf("%d",i);
            return 0;
        }
    }
    printf("-1");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

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

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;

  int x = N/1.08;
  for (; x <= N/1.08+200; x++) {
    if (N == int(x*1.08)) {
      cout << x << endl;
      return 0;
    }
  }
  cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

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

Measured memory_bytes: 256
readline()
a=map(x->parse(Int,x),split(readline()))
b=map(x->parse(Int,x),split(readline()))
t=sum(b)-sum(a)
x=y=0
for (u,v)=zip(a,b)
	if u>v
		x+=u-v
	else
		y+=div(v-u+1,2)
	end
end
println(t<x||t<y ? "No" : "Yes")


Measured memory_bytes: 167364
#include<cstdio>
#include<algorithm>
using namespace std;
struct point{
    int x, ck, num;
    bool operator <(const point &p)const{
        return x!=p.x?x<p.x:ck>p.ck;
    }
}w[101000];
int T, n, L;
int Calc(point a, point b){
    if(a.ck==b.ck)return 0;
    int chk = 1;
    if(a.ck==2)swap(a,b), chk = -1;
    int d = (b.x-a.x+L)%L;
    if(2*T < d)return 0;
    return (((2*T-d)/L+1) % n * chk + n)%n;
}
int Res[101000];
int main(){
    int i;
    scanf("%d%d%d",&n,&L,&T);
    for(i=0;i<n;i++){
        scanf("%d%d",&w[i].x,&w[i].ck);
        w[i].num = i;
    }
    int s = 0, pv = 0;
    for(i=0;i<n;i++){
        s = (s + Calc(w[0],w[i]))%n;
    }
    for(i=0;i<n;i++){
        if(w[i].ck==1)w[i].x = (w[i].x + T)%L;
        else w[i].x = (w[i].x + L - T%L) % L;
    }
    sort(w,w+n);
    for(i=0;i<n;i++){
        if(!w[i].num)pv = i;
    }
    for(i=0;i<n;i++){
        Res[(i-pv+s+n)%n] = w[i].x;
    }
    for(i=0;i<n;i++)printf("%d\n",Res[i]);
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll D, G;
vector<ll> p(11, 0);
vector<ll> c(11, 0);
vector<ll> v;
vector<vector<ll>> dp(20, vector<ll>(10010, -1));
 
int main(void){
	
	cin >> D >> G;
	for(int i = 0; i < D; ++i) cin >> p[i] >> c[i];
	
	ll sum = 0;
	for(int i = 0; i < D; ++i) sum += p[i], v.push_back(sum);
    
    dp[0][0] = 0;
    for(int i = 0; i < D; ++i){
        for(int j = 0; j <= v[i]; ++j){
            if(~dp[i][j]){
                for(int q = 0; q <= p[i]; ++q){
                    ll point = q * 100 * (i + 1) + (q == p[i] ? c[i] : 0);
                    dp[i + 1][j + q] = max(dp[i + 1][j + q], dp[i][j] + point);
                }
            }
        }
    }
    for(int i = 0; i <= v.back(); ++i) if(dp[D][i] >= G){ cout << i << endl; break; }
    
	return 0;
}

Measured memory_bytes: 1920
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	int N,M;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		N = nextInt();
		M = nextInt();

		out.println(N==M?"Yes":"No");
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}

	long lcm(long m, long n) {
	        return m * n / gcd(m, n);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

struct edge{
    int to, cost;
};

struct node{
    int n, cost;
    bool operator < (const node& n) const {
        return cost < n.cost;
    }
    
    bool operator > (const node& n) const {
        return cost > n.cost;
    }
};

int N, M;
int cost[200010];
int came[200010];
vector<edge> G[200010];

void add_edge(int a, int b, int c){
    G[a].push_back(edge{b, c});
    G[b].push_back(edge{a, c});
}

void dijkstra(int s){
    for(int i = 1; i <= N; i++) cost[i] = inf;

    cost[s] = 0;
    
    priority_queue<node, vector<node>, greater<node>> pq;
    pq.push(node{s, 0});

    while(!pq.empty()){
        node n = pq.top();
        pq.pop();

        if(cost[n.n] < n.cost) continue;

        for(auto& e : G[n.n]){
            if(cost[e.to] > e.cost + n.cost){
                cost[e.to] = e.cost + n.cost;
                came[e.to] = n.n;
                pq.push(node{e.to, cost[e.to]});
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M;
    for(int i = 0; i < M; ++i){
        int A, B;
        cin >> A >> B;
        add_edge(A, B, 1);
    }
    dijkstra(1);
    cout << "Yes" << endl;
    for(int i = 2; i <= N; ++i) cout << came[i] << endl;
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

const int mod = 1e9 + 7;
int dp[101010][2];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i, n) {
        {   // a+bのi桁目が0
            if (s[i] == '0') {
                dp[i+1][0] = dp[i][0];
                dp[i+1][1] = dp[i][1];
            }
            else {
                // 未満の方へいく
                dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
            }
        }
        {   // a+bのi桁目が1
            if (s[i] == '0') {
                (dp[i+1][1] += dp[i][1] * 2 % mod) %= mod;
            }
            else {
                (dp[i+1][0] += dp[i][0] * 2 % mod) %= mod;
                (dp[i+1][1] += dp[i][1] * 2 % mod) %= mod;
            }
        }
    }

    int ans = dp[n][0]+dp[n][1];
    cout << ans%mod << endl;

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
using namespace std;
typedef vector<vector<int> > VVI;
typedef vector<vector<bool> > VVB;

int w, h, cnt;

void labeling(VVI& map, VVB& visited, int x, int y) {
    visited[x][y] = true;
    for (int i = -1; i <= 1; ++i) {
        for (int j = -1; j <= 1; ++j) {
            if (x+i < 0 || h <= x+i || y+j < 0 || w <= y+j)
                continue;
            if (!visited[x+i][y+j] && map[x+i][y+j])
                labeling(map, visited, x+i, y+j);
        }
    }
}

int main(int argc, char *argv[])
{
    while (cin >> w >> h, w | h) {
        VVI map(h, vector<int>(w));
        VVB visited(h, vector<bool>(w, false));
        cnt = 0;
        for (int i = 0; i < h; ++i)
            for (int j = 0; j < w; ++j)
                cin >> map[i][j];
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if (!visited[i][j] && map[i][j]) {
                    cnt++;
                    labeling(map, visited, i, j);
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1516
program main
  implicit none
  integer :: n, i, j
  logical :: can
  read (*, *) n
  can = .false.
  do i = 1, 9
    do j = 1, 9
      if (i * j == n) can = .true.
    end do
  end do
  if (can) then
    write (*, "(a)") "Yes"
  else
    write (*, "(a)") "No"
  end if
end program main


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

ll N, M, V, P;
bool C(int mid, const vector<ll> &A) {
    // debug(mid);
    if (mid <= P - 1) {
        return true;
    } else if (A[mid] + M < A[P - 1]) {
        return false;
    } else {
        ll sum = 0;
        for (int i = P - 1; i < mid; i++) {
            sum += A[mid] + M - A[i];
        }
        for (int i = mid + 1; i < N; i++) {
            sum += M;
        }
        // cout << mid << ": " << sum << endl;
        return sum >= M * (V - P);
    }
}

int main() {
    cin >> N >> M >> V >> P;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end(), greater<ll>());
    int ng = N;
    int ok = 0;
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (C(mid, A)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok + 1 << endl;
}


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

int gcd(int x, int y){

	int r;
	if (x < y)
		swap(x, y);

	while (y > 0)
	{
		r = x%y;
		x = y;
		y = r;
	}

	return x;

}

int main(){

	int x, y;
	cin >> x >> y;
	
	cout<<gcd(x, y)<<endl;

	return 0;
}

Measured memory_bytes: 1164
n = int(input())
taste_list = list(map(int, input().split())) 
taste_sum = 0
for i in range(n):
  for j in range(n):
    taste = taste_list[i]*taste_list[j]
    taste_sum += taste
for i in range(len(taste_list)):
  taste_sum -= taste_list[i]**2
print(int(taste_sum/2))

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

using ll=long long;

ll check(bool isLeft,multiset<pair<int,int>> lr,multiset<pair<int,int>> rl){
    ll res=0;
    int pos=0;
    int non=0;
    while(!lr.empty()){
        if(isLeft){
                isLeft=!isLeft;
            pair<int,int> to=*rl.begin();
            
            if(to.first>=pos){
                if(non){
                    return res+abs(pos);
                }
                non++;
                continue;
            }
            res+=pos-to.first;
            pos=to.first;
            lr.erase(lr.find(make_pair(to.second,to.first)));
            rl.erase(rl.find(to));
        }
        else{
            isLeft=!isLeft;
            pair<int,int> to=*(--lr.end());

            if(to.first<=pos){
                if(non){
                    return res+abs(pos);
                }
                non++;
                continue;
            }
            res+=to.first-pos;
            pos=to.first;
            lr.erase(lr.find(to));
            rl.erase(rl.find(make_pair(to.second,to.first)));
        }
    }
    
    return res+abs(pos);
}
int main(){
    int n;
    cin>>n;
    vector<int> l(n),r(n);
    for(int i=0;i<n;i++){
        cin>>l[i]>>r[i];
    }

    multiset<pair<int,int>> lr,rl;
    
    for(int i=0;i<n;i++){
        lr.insert(make_pair(l[i],r[i]));
        rl.insert(make_pair(r[i],l[i]));
    }
    
    ll res=check(0,lr,rl);
    
    res=max(res,check(1,lr,rl));
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 19840