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

using namespace std;

const int N = 36;

struct Card {
    char suit;
    int value;
};

void bubbleSort(Card a[], int n) {
    for (int i = 0; i < n; i++) {
        for (int j = n - 1; j > i; j--) {
            if (a[j].value < a[j - 1].value)
                swap(a[j], a[j - 1]);
        }
    }
}

void selectionSort(Card a[], int n) {
    for (int i = 0; i < n; i++) {
        int minIndex = i;
        for (int j = i + 1; j < n; j++) {
            if (a[j].value < a[minIndex].value)
                minIndex = j;
        }
        swap(a[minIndex], a[i]);
    }
}

bool isSame(Card a[], Card b[], int n) {
    for (int i = 0; i < n; i++) {
        if (a[i].suit != b[i].suit)
            return false;
    }
    return true;
}

void output(Card a[], int n) {
    for (int i = 0; i < n; i++) {
        if (i > 0)
            cout << " ";
        cout << a[i].suit << a[i].value;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    Card cards1[N];
    Card cards2[N];
    for (int i = 0; i < n; i++) {
        cin >> cards1[i].suit >> cards1[i].value;
        cards2[i].suit = cards1[i].suit;
        cards2[i].value = cards1[i].value;
    }

    bubbleSort(cards1, n);
    selectionSort(cards2, n);
    bool isStable = isSame(cards1, cards2, n);
    
    output(cards1, n);
    cout << "Stable" << endl;
    output(cards2, n);
    if (isStable)
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;

    return 0;
}



Measured memory_bytes: 3100
A,B=map(int,input().split())
if A%2==0:
    set1={i for i in range((25*A)//2,(25*A+25)//2+1)}
    set2={i for i in range(10*B,10*B+10)}
    ans=set1.intersection(set2)
    if len(ans)>0:
        print(min(ans))
    else:
        print(-1)
else:
    set1={i for i in range((25*A)//2+1,(25*A+25)//2)}
    set2={i for i in range(10*B,10*B+10)}
    ans=set1.intersection(set2)
    if len(ans)>0:
        print(min(ans))
    else:
        print(-1)


Measured memory_bytes: 38384
#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

typedef pair<xy_t, bool> dat;

namespace std{
	bool operator < (const xy_t &a, const xy_t &b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a)*b);
}

int ccw(xy_t a, xy_t b, xy_t c){
	b -= a; c -= a;
	if(cross(b, c) > 0) return 1;
	if(cross(b, c) < 0) return -1;
	if(dot(b, c) < 0) return +2;
	if(norm(b) < norm(c) ) return -2;
	return 0;
}

bool intersectSS(const line &s, const line &t){
	return ccw(s.first, s.second, t.first) * ccw(s.first, s.second, t.second) <= 0 &&
		ccw(t.first, t.second, s.first) * ccw(t.first, t.second, s.second) <= 0;
}

xy_t crosspoint(const line &l, const line &m){
	double a = cross(l.second - l.first, m.second - m.first);
	double b = cross(l.second - l.first, l.second - m.first);
	if(abs(a) < EPS && abs(b) < EPS) return m.first;
	if(abs(a) < EPS) assert(false);
	return m.first + b / a * (m.second - m.first);
}

line lines[200];

int main(){
	int n;
	double x1, y1, x2, y2;
	while(cin >> n && n){
		int ans = 1;
		for(int i = 0; i < n; i++){
			vector<xy_t> ps;
			ans++;
			cin >> x1 >> y1 >> x2 >> y2;
			lines[i] = line(xy_t(x1, y1), xy_t(x2, y2));
			for(int j = 0; j < i; j++){
				if(intersectSS(lines[i], lines[j])){
					xy_t p = crosspoint(lines[i], lines[j]);
		//			cout << p << endl;
					if(abs(abs(imag(p)) - 100.0) < EPS || abs(abs(real(p)) - 100.0) < EPS) continue;
					bool ok = true;
					for(int k = 0; k < (int)ps.size(); k++){
						if(abs(ps[k] - p) < EPS){
							ok = false;
							break;
						}
					}
					if(ok) ps.push_back(p);
				}
			}
			ans += ps.size();
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;

int gcd(int a, int b) {
	return !b ? a : gcd(b, a % b);
}

void solve() {
	int a, b;
	cin >> a >> b;
	cout << a / gcd(a, b) * b;
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>


int n, c[200002], colorlastp[200002], lastsame[200002], t;

int main()
{
    unsigned long long dp[200002];
    memset(colorlastp, -1, sizeof(colorlastp));
    memset(lastsame, -1, sizeof(lastsame));
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &t);
        c[i] = t;
        if (colorlastp[t] != -1)
            lastsame[i] = colorlastp[t];
        colorlastp[t] = i;
    }
    dp[0] = 1;
    for (int i = 1; i < n; i++)
    {
        dp[i] = dp[i-1];
        if (c[i-1] != c[i] && lastsame[i] != -1)
            dp[i] = (dp[i] + dp[lastsame[i]]) % 1000000007;
    }
    printf("%llu", dp[n-1]);
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, now;;
  cin >> N;
  now = 0;
  vector<pair<int, int>> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i).second >> A.at(i).first;
  }
  sort(A.begin(), A.end());
  bool jud = true;
  for(int i=0;i<N;i++){
    now += A.at(i).second;
    if(A.at(i).first < now){
      jud = false;
      cout << "No" << endl;
      break;
    }
  }
  if(jud) cout<<"Yes"<<endl;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N, K = map(int, input().split())

    have = [0 for i in range(N)]
    for _ in range(K):
        D = int(input())
        A = list(map(int, input().split()))
        for a in A:
            have[a - 1] = 1

    print(N - sum(have))


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9988
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int h, w;
 cin >> h >> w;

 string board[50];

 for (int i = 0; i < h; ++i) cin >> board[i];

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

 for (int i = 0; i < h; ++i) {
 for (int j = 0; j < w; ++j) {
 if (board[i][j] == '#') continue;

 int num = 0;
 for (int d = 0; d < 8; ++ d) {
 const int ni = i + dy[d];
 const int nj = j + dx[d];

 if (ni < 0 or h <= ni) continue;
 if (nj < 0 or w <= nj) continue;
 if (board[ni][nj] == '#') num++;
 }

 board[i][j] = char(num + '0');

 }
 }

 for (int i = 0; i < h; ++i) cout << board[i] << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include <fstream>
#include<unordered_set>
#include<stack>
#include <map>
#include<unordered_map>
#include<time.h>
#include <chrono>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
using namespace std;
#define MAX 1000001 
#define M 998244353
ll inverse(ll n)
{
	ll modu = M;
	ll m = modu;
	ll a = 0, b = 1;
	if (modu == 1)
		return 0;
	while (n > 1)
	{
		ll quo = n / modu;
		ll temp = modu;
		modu = n % modu, n = temp;
		temp = a;
		a = b - (quo * a);
		b = temp;
	}
	if (b < 0)
		b += m;
	return b;
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll a, b;
	cin >> a >> b;

	cout << (a*b)/gcd(a, b);
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
N = int(readline())
A = list(map(int,readline().split()))
total = sum(A)
B = [0] * N
for i in range(N):
    B[i] = total-A[i]
ans = 0 
for i in range(N):
    ans += A[i]*B[i]
print((ans//2)%MOD)

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

int main(){
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int maxX = -999;
  int minY = 999;
  for(int i = 0; i < N; i++){
    int x ;
    cin >> x;
    maxX = max(maxX, x);
  }
  for(int i = 0; i < M; i++){
    int y ; 
    cin >> y;
    minY = min(minY, y);
  }
  if(X < Y && X < maxX && maxX < minY && minY <= Y){
    cout << "No War" << endl;
  }
  else{
    cout << "War" << endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef complex<ull> pt;
#define x real()
#define y imag()

#define endl "\n"

const int N = 2e5+10;
const int MOD = 1e9+7;


ll fpow(ll a, ll b) {
  a %= MOD;
  if(b == 0)
   return 1;
  ll ret = fpow(a*a, b/2);
  if (b&1)
   ret *= a;
  return ret % MOD;
}

int gcd(ll a, ll b)
{

    if(b == 0) {
            return a;
    }
    else {
        return gcd(b, a % b);
    }
}

ll n,m,k;
string s,t;

bool vis[4];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//cin >> n;
	
	cin >> n >>m;
	cout << (n*m)/gcd(n,m);
	
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
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()
def LS(): return list(input())
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(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
V = LI()
C = LI()
ans = 0
for i in range(n):
    ans += max(V[i]-C[i], 0)
print(ans)

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

int main() {
    string str;
    cin >> str;

    int x = -1, y = -1;
    for (int i = 0; i < str.size(); i++) {
        if (i > 0 && str[i] == str[i-1]) x = i, y = i+1;
        if (i > 1 && str[i] == str[i-2]) x = i-1, y = i+1;
    }

    cout << x << " " << y << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>

bool x[5][5];
bool used[5];

bool check(){
    for(int i=1;i<=4;++i){
        if(!used[i])
            return false;
    }
    return true;
}

bool dfs(int y){
    used[y]=1;

    if(check()){
        used[y]=0;
        return 1;
    }

    bool res=0;
    for(int i=1;i<=4;++i){
        if(x[y][i]&&!used[i])
            res|=dfs(i);
    }
    used[y]=0;

    return res;
}

int main() {

    for(int i=0;i<3;++i){
        int a,b;
        std::cin>>a>>b;
        x[a][b]=x[b][a]=1;
    }

    bool ans=0;

    for(int i=1;i<=4;++i)
        ans|=dfs(i);

    if(ans)
        std::cout<<"YES"<<std::endl;
    else
        std::cout<<"NO"<<std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> p(n),q(n),ans;
  for(int i=0;i<n;i++)cin>>p.at(i);
  for(int i=0;i<n;i++)cin>>q.at(i);
  for(int i=1;i<=n;i++)ans.push_back(i);
  int cnt=0;
  int a,b;
  do{
    cnt++;
    bool ok1=true,ok2=true;
    for(int i=0;i<n;i++)if(ans.at(i)!=p.at(i))ok1=false;
    for(int i=0;i<n;i++)if(ans.at(i)!=q.at(i))ok2=false;
    if(ok1)a=cnt;
    if(ok2)b=cnt;
  }while(next_permutation(ans.begin(),ans.end()));
  cout<<abs(a-b)<<endl;
  return 0;
}

Measured memory_bytes: 256
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}



signed main() {
	int N;
	cin >> N;
  	int n;
	int ans = 0;
	REP (i,N) {
		cin >> n;
		ans += n - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
double S,L,r;
int main(){
    cin>>r;
    S=r*r*3.14159265358979323846264338;
    L=2.0*r*3.14159265358979323846264338;
    printf("%f %f",S,L);
    return 0;
}

Measured memory_bytes: 1232
num,total=[int(str) for str in input().split()]

#if total>10000*num or total<1000*num or total%1000!=0:
#    print("-1 -1 -1")


total_cal=[]
num_10000=0
num_5000=0
num_1000=0
limit=20

if num<limit:
    pass
else:
    for num_cal in range(num,limit,-1):
        #print('total:',total)
        #print(num_cal)
        ave=total/num_cal
        diff=[abs(10000-ave),abs(5000-ave),abs(1000-ave)]
        if diff.index(min(diff))==0:
            total-=10000
            num_10000 += 1
        elif diff.index(min(diff))==1:
            total-=5000
            num_5000 += 1
        else:
            total-=1000
            num_1000 += 1

    num=limit
    #print(num)
    #print(total)

for i in range(num+1):
    for j in range(num+1):
        for k in range(num+1):
            total_cal.append({"nums":[i,j,k],'total':10000*i+5000*j+1000*k})

nums=[x["nums"] for x in total_cal if x['total']==total and sum(x['nums'])==num]


if total_cal!=0 and nums==[]:
    print("-1 -1 -1")
else:
    nums = [x + y for (x, y) in zip(nums[0], [num_10000, num_5000, num_1000])]
    print('{num_10000} {num_5000} {num_1000}'.format(num_10000=nums[0],num_5000=nums[1],num_1000=nums[2]))


Measured memory_bytes: 44764
#include<stdio.h>
#define N 100

int main(){
  int M[N][N];
  int n, u, k, v, i, j;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    for(j= 0; j < n; j++) M[i][j] = 0;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i = 0; i < n; i++){
    for(j= 0; j < n; j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2044
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll a, b, k;
  scanf("%lld%lld%lld", &a, &b, &k);
  ll num = MIN(a, b);
  while (k)
  {
    if (a % num == 0 && b % num == 0)
    {
      k--;
    }
    num--;
  }
  printf("%lld\n", num + 1);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
 int A,B,C;
  cin >> A >> B >> C;
  string ans = "No";
  if(A==B||B==C||C==A){
    ans = "Yes";
    if(A==B && B==C){
    ans = "No";
    }
  }
  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 brep(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<n;i++)
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
#define MOD 1e9+7

int main(void){
    char a[3];
    rep(i,3){
        cin >> a[i];
        if(a[i]=='1')a[i]='9';
        else a[i] ='1';
    }
    rep(i,3){
        cout << a[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RF(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
/*----------------------------------------------------------------------*/

const int N = 3005;
lll dp[N][N]; ll arr[N];
bool visited[N][N];
int n;

lll solve(int s, int e, int turn) {
	if(s > e) return {0, 0};
	if(visited[s][e]) return dp[s][e];

	lll ret; lll r1 = solve(s+1, e, 1-turn);
	lll r2 = solve(s, e-1, 1-turn);

	if(turn == 0) {
		r1.first += arr[s];
		r2.first += arr[e];
		lll tmp = r1;
		if(r2.first > tmp.first || (r2.first == tmp.first && r2.second < tmp.second)) tmp = r2;
		ret = tmp; 
	} else {
		r1.second += arr[s];
		r2.second += arr[e];
		lll tmp = r1;
		if(r2.second > tmp.second || (r2.second == tmp.second && r2.first < tmp.first)) tmp = r2;
		ret = tmp;
	}

	visited[s][e]=true;
	return dp[s][e] = ret;
}

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

    cin>>n;
    F(i, 0, n) {
    	cin>>arr[i];
    }

    memset(visited, false, sizeof(visited));

    lll ans = solve(0, n-1, 0);
    cout<<ans.first-ans.second;

    return 0;
}/*

*/


Measured memory_bytes: 150016
#include<stdio.h>
#include<math.h>
#include <iostream>
using namespace std;
#define  LL long long

const int maxn = 1e5+55;

LL a[maxn],b[maxn];
LL x[maxn],v[maxn];
LL sum[maxn];
int main()
{
	LL n,c;
	cin>>n>>c;
	for(int i=1;i<=n;i++)
		cin>>x[i]>>v[i];

	for(LL i=1;i<=n;i++)
		a[i]=a[i-1]+v[i]-(x[i]-x[i-1]);
	x[n+1]=c;

	for(LL i=n;i>=1;i--)
		b[i]=b[i+1]+v[i]-(x[i+1]-x[i]);
	a[0]=b[n+1]=-1231231222231323;

	for(LL i=1;i<=n;i++)
		a[i]=max(a[i-1],a[i]);

	for(LL i=n;i>=1;i--)
		b[i]=max(b[i],b[i+1]);
	a[0]=a[n+1]=0;
	LL ans=0;
	for(LL i=1;i<=n;i++){
		ans=max(ans,-x[i]+a[i]+b[i+1]); //顺时针，再折回
		ans=max(ans,a[i]);//顺时针，不折回
		ans=max(ans,b[i]);//逆时针，不折回
		ans=max(ans,-(c-x[i])+b[i]+a[i-1]);//逆时针 再折回
	}
	cout<<ans<<endl;




}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
const int MAX=1e5;

vector< int > G[MAX];
int N;
bool visited[MAX];
int prenum[MAX],parent[MAX],lowest[MAX],timer;

void dfs(int current,int prev){
    prenum[current]=lowest[current]=timer;
    timer++;

    visited[current]=true;

    int next;

    REP(i,G[current].size()){
        next=G[current][i];
        if(!visited[next]){
            parent[next]=current;
            dfs(next,current);
            lowest[current]=min(lowest[current],lowest[next]);
        }else if(next!=prev){
            lowest[current]=min(lowest[current],prenum[next]);
        }
    }
}

void art_points(){
    REP(i,N) visited[i]=false;
    timer=1;
    dfs(0,-1);
    set< int > ap;
    int np=0;
    FOR(i,1,N){
        int p=parent[i];
        if(p==0) np++;
        else if(prenum[p]<=lowest[i]) ap.insert(p);
    }
    if(np>1) ap.insert(0);
    for(auto&& it:ap) printf("%d\n",it);
}

int main(){
    int m;
    scanf("%d%d",&N,&m);

    REP(i,m){
        int s,t;
        scanf("%d%d",&s,&t);
        G[s].push_back(t);
        G[t].push_back(s);
    }
    art_points();

    return 0;
}




Measured memory_bytes: 7116
N=int(input())
a=list(map(int,input().split()))
for i in range(N):
  if i!=0:
    a[i]=a[i]+a[i-1]
ans=10**10
for i in range(N-1):
  ans=min(ans,abs(a[i]+a[i]-a[N-1]))
print(ans)

Measured memory_bytes: 30488
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    string a;
    scan(a);

    int[] cnt = new int[](26);
    foreach (ai ; a) {
        cnt[ai - 'a']++;
    }

    long ans = 1L * a.length * (a.length + 1) / 2 - a.length + 1;

    foreach (i ; 0 .. 26) {
        ans -= 1L * cnt[i] * (cnt[i] - 1) / 2;
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    int a, b;
    cin >> a >> b;
    //int ans = ceil((b - 1) * 1.0 / (a - 1));
    int ans = (b - 1 + a - 2) / (a - 1);
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
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 perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,m;cin >> n >>m;
    vvpl g(n);
    rep(i,m){
        ll a,b,c;cin >> a >>b >>c;a--;b--;
        g[a].pb({b,c});
        g[b].pb({a,c});
    }
    rep(i,n-1){
        g[i+1].pb({i,0});
    }
    vl d(n,INF/10);
    pqueue(pl) que;
    que.push({0,0});
    d[0]=0;
    while(!que.empty()){
        pl p=que.top();
        que.pop();
        ll v=p.se;
        if(d[v]<p.fi)continue;
        rep(i,g[v].size()){
            pl ed=g[v][i];
            if(d[ed.fi]>d[v]+ed.se){
                //prev[ed.fi]=v;
                d[ed.fi]=d[v]+ed.se;
                que.push({d[ed.fi],ed.fi});
            }
        }
    }
    if(d[n-1]==INF/10)cout << -1 <<endl;
    else cout << d[n-1] <<endl;
}

Measured memory_bytes: 12536
#include <bits/stdc++.h>
using namespace std;
#define all(arr) arr.begin(), arr.end() 
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
int n, arr[2005];
ll ans=0;

int main(){
	IOS
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	sort(arr, arr+n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				if(arr[k]<arr[i]+arr[j]){
					ans++;
				}
			}
		}
	}	
	cout << ans << '\n';
}


Measured memory_bytes: 3680
fun main(args: Array<String>) {
    val size = readLine()!!.toInt()
    val hp = readLine()!!.split(' ').map(String::toInt)
    val last = hp.reduce(::gcd)
    println(last)
}

fun gcd(a: Int, b: Int): Int {
    if(a < b) return gcd(b, a)
    if(b == 0) return a
    return gcd(b, a % b)
}

Measured memory_bytes: 51916
#include <algorithm>
#include <iostream>
#include <vector>

int main()
{
    const int mod = 1000000007;

    int n;
    std::cin >> n;

    long long power = 1;

    for (int i = 0; i < n; i++) {
        power *= (i + 1);
        power %= mod;
    }

    std::cout << power << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

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(){
	int n, m;
	while(cin >> n >> m, m){
		char buf[20], buf2[20];
		map<int, int> memo;
		memo[n] = 0;
		
		int cnt = 0;
		
		while(1){
			sprintf(buf, "%0*d", m, n);
			sort(buf, buf + m);
			strcpy(buf2, buf);
			reverse(buf2, buf2 + m);
			
			int a, b;
			sscanf(buf, "%d", &a);
			sscanf(buf2, "%d", &b);
			
			n = b - a;
			cnt++;
			if(memo.count(n)){
				cout << memo[n] << " " << n << " " << cnt - memo[n] << endl;
				break;
			}
			memo[n] = cnt;
		}
	}
	return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10, MOD = 998244353;

vector<pair<ll, ll>> vec;
vector<ll> pref;
ll dp[SIZE];

ll get_sum(int l, int r) {
	if (l < 0) l = 0;
	if (r < 0) r = -1;

	return pref[r + 1] - pref[l];
}

int main()
{
	fastInp;

	int n;
	cin >> n;
	bool p2 = 0, p3 = 0;
	bool fl = 0;
	for (int i = 0; i < n; ++i) {
		int d1, d2;
		cin >> d1 >> d2;

		if (p2 && p3 && d1 == d2) {
			fl = 1;
		}

		p3 = p2;
		p2 = (d1 == d2);
	}

	if (fl) {
		cout << "Yes\n";
	} 
	else {
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <set>
using ll = long long;
int MOD=1e9+7;
using namespace std;
int main(){
    int n;
    cin >> n;
    set<int> st;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        st.insert(x);
    }
    cout<<st.size()<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();

   int[] a = new int[N];
   for(int i=0;i<N;i++) a[i] =sc.nextInt();
   
   boolean flg=true;
   int count =0;
   while(flg)
   {
     for(int i=0;i<N;i++) 
     {
       if(a[i]%2==1) 
       {
         flg =false;
         break;
       }
       else a[i]/=2;
     }
     if(!flg) break;
     count++;
   }
   System.out.println(count);
 }
}

Measured memory_bytes: 22996
input_front = input().split(" ")
input_back = input().split(" ")
n, x = int(input_front[0]), int(input_front[2])


def problemB(n, x):
    masu_list = [0] * (n+1)
    adder = input_back

    for i in adder:
        masu_list[int(i)] = 1
    front = sum(masu_list[:x])
    back = sum(masu_list[x+1:])

    if front <= back:
        return print(front)

    else:
        return print(back)


problemB(n, x)

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

using namespace std;

#define ll long long int

int main() 
{
    ll n,w,v,i,j,k;
    cin>>n>>w;
    ll dp[n+5][w+5];
    pair<ll,ll> p[n+5];
    for(i=1;i<=n;i++)
    {
        cin>>j>>v;
        p[i]={j,v};
    }
    sort(p+1,p+n+1);
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
            else if((p[i].first)<=j)
                dp[i][j]=max((p[i].second)+dp[i-1][j-(p[i].first)],dp[i-1][j]);
            else 
                dp[i][j]=dp[i-1][j];
        }
    }
    i=1;
    j=w;
    cout<<dp[n][w]<<"\n";
    return 0;
}

Measured memory_bytes: 81024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, m;
int a[110];

int main() {
    cin >> n >> m;
    rep(i, n) cin >> a[i];

    rep(i, n) a[i] *= 4 * m;
    int sum = 0;
    rep(i, n) sum += a[i];

    int cnt = 0;
    rep(i, n) {
        if (a[i] >= sum / (4 * m)) cnt++;
    }
    if (cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
# C - Green Bin

from collections import defaultdict

d = defaultdict(int)
n = int(input())

for _ in range(n):
    s = sorted(input())
    s = ''.join(s)
    d[s] += 1

ans = 0
for i in d.values():
    ans += i*(i-1)//2

print(ans)

Measured memory_bytes: 18236
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = list(zip(b, a))
 
a.sort()
b.sort()
for i in range(n):
  if a[i] > b[i]:
    print('No')
    exit()

ptr, pos = {}, {}
for i in range(n):
  if i > 0 and a[i] <= b[i - 1]:
    print('Yes')
    exit()
  ptr[l[i][1]] = l[i][0]
  pos[b[i]] = i

sta, now, cnt = a[0], a[0], 1
while True:
  now = a[pos[ptr[now]]]
  if now == sta:
    break
  cnt += 1
if cnt == n:
  print('No')
else:
  print('Yes')


Measured memory_bytes: 37380
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
    int w=-1, d=-1;
    int tmp;
    int ans;
    vector<int> hw(21),hd(21);
    for(;;){
        ans = 0;
        cin >> w >> d;
        if(w==0)break;
        for(int i=0; i< 21; i++){
            hw[i] = 0;
            hd[i] = 0;
        }
        for(int i=0; i<w ; i++){
            cin >> tmp;
            hw[tmp]++;
        }
        for(int i=0; i<d ; i++){
            cin >> tmp;
            hd[tmp]++;
        }
        for(int i=1; i<21; i++){
            ans += i*max(hd[i],hw[i]);
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3072
n = int(input())
s = input()

nums = []
for i in range(1, len(s)):
  x = s[:i]
  y = s[i:]
  x_letters = set(x)
  y_letters = set(y)
  num = 0
  for letter in x_letters:
    if letter in y_letters:
      num += 1
  nums.append(num)

print(max(nums))

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

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
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...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//省略
using vi  = vector<int>;
using vii = vector<vector<int>>;
using vl  = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
    ll N;
    cin>>N;
    vl S(pow(2,N));
    REP(i,pow(2,N)) cin>>S[i];
    sort(ALL(S),greater<ll>());

    multiset<ll> st_no_used;
    multiset<ll,greater<ll>> st_used;

    st_used.insert(S[0]);
    REP2(i,1,pow(2,N)){
        st_no_used.insert(S[i]);
    }

    

    while(!st_no_used.empty()){
        vl input;
        for(auto itr=st_used.begin();itr!=st_used.end();itr++){
            ll x=*itr;
            auto itr2=st_no_used.lower_bound(x);
            if(itr2==st_no_used.begin()){
                cout<<"No"<<endl;
                return 0;
            }
            itr2--;
            input.emplace_back(*itr2);
            st_no_used.erase(itr2);
        }
        REP(i,input.size()){
            st_used.insert(input[i]);
        }
    }

    cout<<"Yes"<<endl;

}

Measured memory_bytes: 19020
open System

[<EntryPoint>]
let main argv =
    let abx = stdin.ReadLine().Split() |> Array.map int
    let a = abx.[0]
    let b = abx.[1]
    let x = abx.[2]
    if a <= x && x <= a + b then "YES" else "NO"
    |> stdout.WriteLine
    0


Measured memory_bytes: 11220
#include<stdio.h>
#include<stdlib.h>
#define N 101
#define MAX 2001
#define BLACK -1
#define WHITE 0

int main(){
  int i,j,n,x,min2,sum=0;
  int a[N][N];
  int min[N];
  int color[N];
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&a[i][j]);
      if(a[i][j]==-1)
	a[i][j]=MAX;
    }
  }

  for(i=0;i<n;i++){
    min[i]=MAX;
    color[i]=WHITE;
  }
  min[0]=0;
  
  while(1){
    min2=MAX;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && min[i]<min2){
	min2=min[i];
	x=i;
      }
    }
    if(min2==MAX)
      break;
    
    color[x]=BLACK;
    
    for(j=0;j<n;j++){
      if(color[j]!=BLACK && a[x][j]<min[j]){
	min[j]=a[x][j];
      }
    }
  }
  
  for(i=0;i<n;i++){
    sum+=min[i];
  }
  
  printf("%d\n",sum);
  return 0;
}
  


Measured memory_bytes: 2040
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    
    int ans = 0;
    for (int i = 1; i <= n/2; ++i) {
        if (n-i != i) ans++;
    }

    cout << ans << endl;
    return 0;
}

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

int is_succeed(vector<int> Scores, int X)
{
    bool result = true;
    rep(i, Scores.size())
    {
        if (Scores.at(i) < X)
        {
            result = false;
            break;
        }
    }

    return result;
}

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

    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    rep(i, N)
    {
        cin >> C.at(i);
        rep(j, M) cin >> A.at(i).at(j);
    }

    int ans = 1e9;
    for (int i = 0; i < (1 << N); i++)
    {
        vector<int> Scores(M, 0);
        int cost = 0;

        bitset<12> bit(i);
        rep(j, N)
        {
            if (bit.test(j))
            {
                cost += C.at(j);
                rep(k, M)
                {
                    Scores.at(k) += A.at(j).at(k);
                }
            }
        }

        if (is_succeed(Scores, X))
        {
            ans = min(ans, cost);
        }
    }

    if (ans == 1e9)
    {
        ans = -1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m, a, sum = 0;
	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		cin >> a;
		sum += a;
	}
	if (n < sum) {
		cout << -1 << endl;
	} else {
		cout << n - sum << endl;
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


int N;
vector<vector<ll>> a;
vector<ll> memo(1<<18, 0);
vector<bool> flg(1<<18, false);

ll rec(int S){
    if(flg[S]) return memo[S];


    ll tmp = 0;
    rep(i, N) repr(j, i+1, N) if(S&1<<i && S&1<<j) tmp += a[i][j];

    for(int T=(S-1)&S; T>0; T=(T-1)&S){
        chmax(tmp, rec(T)+rec(S^T));
    }

    flg[S] = true;
    return memo[S] = tmp;
}

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

    cin >> N;
    a.resize(N, vector<ll>(N, 0));
    rep(i, N) rep(j, N) cin >> a[i][j];

    cout << rec((1<<N)-1) << endl;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << ", "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << ", "; cerr << "\n"; }
#define dbm(map) cerr << #map << ":"; for (auto p : map) cerr << "(" << p.first << ", " << p.second << "), "; cerr << "\n";
#define YN(f) cout << (f ? "YES" : "NO") << "\n"
#define Yn(f) cout << (f ? "Yes" : "No") << "\n"
#define yn(f) cout << (f ? "yes" : "no") << "\n"
using ll = long long;
using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vb = vector<bool>;
using vvi = vector<vi>; using vvl = vector<vl>; using vvb = vector<vb>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using vpii = vector<pii>; using vpll = vector<pll>;
using ti3 = tuple<int, int, int>; using tl3 = tuple<ll, ll, ll>;
using mii = map<int, int>; using mil = map<int, ll>; using mli = map<ll, int>; using mll = map<ll, ll>;

int main() {
	int n; cin >> n;
	vi dp(n + 1); dp[0] = dp[1] = 1;
	rep2(i, 2, n + 1) dp[i] = dp[i - 1] + dp[i - 2];
	// dbv(dp);
	cout << dp[n] << endl;
}


Measured memory_bytes: 3104
# 前からカウント
s = input()

# 確か文字列は操作時に毎回文字列を作り直すはずだからTLE対策に数字の配列に直しておく
s_int = [1 if c == "A" else 2 if c == "B" else 3 for c in s ]

s_len = len(s_int)

write_count = 0

s_pointer = 0

a_count = 0

while (s_pointer + 1 < s_len):
    # AAAAABC→5回変換可、BCを一番左にもっていった状態と等しい
    if s_int[s_pointer] == 1:
        a_count += 1
    elif s_int[s_pointer] == 2 and s_int[s_pointer + 1] == 3:
        # BCで変換個数を確定し、一個余分にポインタを動かす
        write_count += a_count
        s_pointer += 1
    else:
        # 連鎖が途切れた
        a_count = 0
    s_pointer += 1

print(write_count)

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/*(._.)*/
int main(){
	ll MAX = 1e10;
	int ans = 0;
	int N;
	cin >> N;
	vector<ll> C(100005);
	C[0] = -1e10;
	vector<ll> A(N);
	int nowl;
	REP(i,N){
	    cin >> A[i];
	    A[i]++;
	}

	REP(i,N){
		auto It = upper_bound(ALL(C), -A[i]);
		auto dist = It - C.begin();
		//cout << dist << endl;
		C[dist] = -A[i];
	}

	REP(i,100002){
	    if ((C[i] != 0)) ans++;
	}

	cout << ans - 1 << "\n";


    return 0;
}


Measured memory_bytes: 1792