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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b;
  for (int i = 0 ; i < n ; i++) {
    cin >> a.at(i);
  }
  for (int i = 0 ; i < n ; i++) {
    if (i%2 == 0) {
      b.push_back(a.at(i));
    }
    else {
      b.insert(b.begin(), a.at(i));
    }
  }
  if (n%2 == 1) {
    reverse(b.begin(), b.end());
  }
  for (int i = 0 ; i < n ; i++) {
    cout << b.at(i);
    if (i==n-1) {
      cout << endl;
    }
    else {
      cout << " ";
    }
  }
  return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
#include <utility>
#include <vector>
#include <iomanip>
#define int long long
#define rep(i,n) for(int i=0 ; i < (n) ; ++i)
using namespace std;
double kyori(int a,int b,int c,int d,int r1,int r2){
    double temp =0;
    temp = sqrt((a-c)*(a-c)+(b-d)*(b-d))-(double)r1-(double)r2;
    if(temp>0)return temp;
    return 0;
}
double G[1005][1005];
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int n;
    cin >> n;
    vector<int>x(n+2),y(n+2),r(n+2);
    rep(i,n){
        cin >> x[i] >> y[i] >> r[i];
    }
    x[n] = a,y[n] = b,r[n] = 0;
    x[n+1] = c,y[n+1] = d,r[n+1] = 0;
    rep(i,n+2){
        rep(j,n+2){
            G[i][j] = kyori(x[i],y[i],x[j],y[j],r[i],r[j]);
        }
    }
    rep(k,n+2)rep(i,n+2)rep(j,n+2)G[i][j] = min(G[i][j],G[i][k]+G[k][j]);
    cout << setprecision(10) << G[n][n+1] << endl;
}

Measured memory_bytes: 8192
import itertools
P = 37
print(P**3//(P-1), P+1)
X = [(a, b, c) for a, b, c in itertools.product(range(P), repeat = 3) if c == 1 or (b, c) == (1, 0) or (a, b, c) == (1, 0, 0)]
for x in X:
    print(*[i + 1 for i, y in enumerate(X) if sum(a * b for a, b in zip(x, y)) % P == 0])

Measured memory_bytes: 56668
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)

for h, w in hw:
    h_cnt[h] += 1
    w_cnt[w] += 1

h_mx = max(h_cnt)
w_mx = max(w_cnt)

cnt = h_cnt.count(h_mx) * w_cnt.count(w_mx)
for h, w in hw:
    val = h_cnt[h] + w_cnt[w]
    if val == h_mx + w_mx:
        cnt -= 1

if cnt:
    ans = h_mx + w_mx
else:
    ans = h_mx + w_mx - 1

print(ans)


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

#define int long long

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

struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
  int size(int x){
    return r[find(x)];
  }
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int W, H;
  cin >> W >> H;  

  vector<string> s(H);
  for ( int i = 0; i < H; i++ ) {
    cin >> s[i];    
  }
  
  UnionFind uf((W+1)*(H+1));

  int g;
  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      // cout << i << " " << j << endl;
      if ( s[i][j] == '.' ) {
	for ( int k = 0; k < 4; k++ ) {
	  int ny = i+dy[k], nx = j+dx[k];
	  if ( ny < 0 || ny >= H || nx < 0 || nx >= W ) continue;	  
	  if ( s[ny][nx] == '.' || s[ny][nx] == 't' ) uf.unite(i*W+j, ny*W+nx);	  
	}
      }
      if ( s[i][j] == 't' ) {
	g = i*W+j;	
	for ( int k = 0; k < 4; k++ ) {
	  int ny = i+dy[k], nx = j+dx[k];
	  if ( ny < 0 || ny >= H || nx < 0 || nx >= W ) continue;	  
	  if ( s[ny][nx] == '.' || s[ny][nx] == 't' ) uf.unite(i*W+j, ny*W+nx);	  
	}
      }
    }
  }

  int N;
  cin >> N;
 
  int ans = -1;

  if ( uf.same(0, g) ) ans = 0;  
  
  for ( int i = 0; i < N; i++ ) {
    int x, y;
    cin >> x >> y;
    s[y][x] = '.';    
    if ( ans >= 0 ) continue;
    for ( int k = 0; k < 4; k++ ) {
      int ny = y+dy[k], nx = x+dx[k];
      if ( ny < 0 || ny >= H || nx < 0 || nx >= W ) continue;	  
      if ( s[ny][nx] == '.' || s[ny][nx] == 't' ) uf.unite(y*W+x, ny*W+nx);      
    }

    if ( uf.same(0, g) ) ans = i+1;    
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 19416
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define devugv(v)               for (auto& x: v) cerr << x << " "; cerr << '\n';
#define debugvp(v)              for (auto& x: v) cerr << x.fi << " - " << x.se << '\n';
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long i64; 
typedef vector< int > vi;
typedef vector< i64 > vi64;
typedef pair< int, int > pi;
typedef vector< pair< int, int > > vpi;
typedef vector< vector < int > > vvi;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in.txt", "r", stdin);
#endif

    int n, temp; cin >> n;
    set<int> ss;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        ss.insert(temp);
    }
    if ((int) ss.size() == n) cout << "YES\n";
    else cout << "NO\n";
  
#ifdef LOCAL_DEFINE
    cout << "time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
    return 0;
}

Measured memory_bytes: 9600
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [0] + [float("inf")] * 10**5

for i in range(N):
    for j in range(10**5, v[i]-1, -1):
        dp[j] = min(dp[j], dp[j-v[i]] + w[i])

res = 0
for v, e in enumerate(dp):
    if e <= W:
        res = v

print(res)

Measured memory_bytes: 92604
#include <stdio.h>

int main(){
    int i, n;
    long a, max, min, sum = 0;
    scanf("%d\n", &n);
    if(n < 0 || n > 10000) return 0; 
    
    for(i = 1; i <= n; i++){
        scanf("%ld", &a);
        if(a < -1000000 || a > 1000000){
            break;
        }
        if(i == 1){
            max = a;
            min = a;
            sum = a;
        }else if(i > 1){
            if(a > max){max = a;}
            if(a < min){min = a;}
            sum += a;          
        }
    }
    
    printf("%ld %ld %ld\n", min, max, sum);
    return 0;
}

Measured memory_bytes: 600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll x, a, b;
    cin >> x >> a >> b;
    ll da = max(a-x, x-a);
    ll db = max(b-x, x-b);
    if (da<db) {
        cout << "A" << endl;
    }
    else {
        cout << 'B' << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long arr[9],n,A,B,C;
long long dfs(long long l,long long a,long long b,long long c)
{
	long long r1,r2,r3,r4;
    if(l==n)
	    if(a==0||b==0||c==0)
		    return 10000;
        else
            return abs(a-A)+abs(b-B)+abs(c-C);
	r1=dfs(l+1,a+arr[l+1],b,c)+10;
	r2=dfs(l+1,a,b+arr[l+1],c)+10;
	r3=dfs(l+1,a,b,c+arr[l+1])+10;
	r4=dfs(l+1,a,b,c);
	return min(min(r1,r2),min(r3,r4));
}
int main()
{
	long long i;
    scanf("%lld %lld %lld %lld",&n,&A,&B,&C);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&arr[i]);   
    }
    printf("%lld",dfs(0,0,0,0)-30);
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;

#define fi          first
#define se          second
#define pb          push_back
#define INF         INT_MAX
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define dbg(x)      cout<<#x"="<<x<<endl
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     upper_bound(all(x),y)-x.begin()
#define lb(x,y)     lower_bound(all(x),y)-x.begin()
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)

int main(){
  cin.sync_with_stdio(false);
  int n, t, x, y;
  cin >> n;
  int ot = 0,ox = 0,oy = 0;
  bool jd = true;
  rep(i,n){
    cin >> t >> x >> y;
    int ti = t - ot;
    int d = abs(x-ox) + abs(y-oy);
    if(!(d <= ti && t % 2 == d % 2)){
      jd = false;
      break;
    }
  }
  cout << (jd ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
//26

deque<int> q;
int a[200000];
signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,n)scanf("%lld", &a[i]);
	int b = 0;
	if(n%2 == 1)b = 1;
	rep(i,n){
		if(i%2 == b)q.push_back(a[i]);
		else q.push_front(a[i]);
	}
	rep(i,n){
		printf("%lld%c", q.front(), i == n-1 ? '\n' : ' ');
		q.pop_front();
	}
	return 0;
}





Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
int main() {
    int N; cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    vector<long long> s(N+1, 0);
    map<long long, long long> nums;
    
    for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];
    for (int i = 0; i < N+1; ++i) nums[s[i]]++;
    
    long long res = 0;
    for (auto it : nums) {
        long long num = it.second;
        res += num * (num - 1) / 2;
    }
    
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	int x1,x2,y1,y2,x3,y3;
	cin>>x1>>y1>>x2>>y2;
	y3=y2-y1;
	x3=x2-x1;
	cout<<x2-y3<<" "<<y2+x3<<" "<<x1-y3<<" "<<y1+x3<<endl;
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	while (true) {
	    int n = sc.nextInt();
	    if (n == 0) break;
	    int[] s = new int[n];
	    for (int i = 0; i < n; i++) {
		s[i] = sc.nextInt();
	    }
	    Arrays.sort(s);
	    int avg = 0;
	    for (int i = 1; i < n - 1; i++) {
		avg += s[i];
	    }
	    System.out.println(avg/(n-2));
	}
	sc.close();
    }
}



Measured memory_bytes: 29328
#include <bits/stdc++.h>
#define Pb push_back
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 7, Mod = 1e9 + 7;
inline int R() { int rt; scanf ( "%d", &rt ); return rt; }
inline int Mop ( int na ) { return na >= Mod ? na - Mod : na; }

int n, m, np, nn;
int x[MAXN], y[MAXN];
struct P { int x, y; P ( int nx = 0, int ny = 0 ) { x = nx, y = ny; } }a[MAXN];
bool Cmpx ( P t1, P t2 ) { return t1.x < t2.x; }
bool Cmpy ( P t1, P t2 ) { return t1.y < t2.y; }
bool Cmp ( P t1, P t2 ) { return t1.x == t2.x ? t1.y > t2.y : t1.x < t2.x; }
map<int, int> hx, hy;
void Pre ()
{
	sort ( a + 1, a + np + 1, Cmpx );
	for ( int i = 1; i <= np; ++i ) if ( a[i].x != a[i - 1].x ) hx[a[i].x] = ++nn;
	nn = 0, sort ( a + 1, a + np + 1, Cmpy );
	for ( int i = 1; i <= np; ++i ) if ( a[i].y != a[i - 1].y ) hy[a[i].y] = ++nn;
	for ( int i = 1; i <= np; ++i ) a[i].x = hx[a[i].x], a[i].y = hy[a[i].y];
	sort ( a + 1, a + np + 1, Cmp );
}

int t[MAXN];
inline int Lbt ( int x ) { return x & -x; }
void Add ( int pos, int val ) { for ( ; pos <= nn; pos += Lbt ( pos ) ) t[pos] = Mop ( t[pos] + val ); }
int Query ( int pos ) { int rt = 0; for ( ; pos; pos -= Lbt ( pos ) ) rt = Mop ( rt + t[pos] ); return rt; }
int Gao ()
{
	Add ( 1, 1 );
	for ( int i = 2; i <= np; ++i )
	{
		if ( a[i].x == a[i - 1].x && a[i].y == a[i - 1].y ) continue;
		Add ( a[i].y, Query ( a[i].y - 1 ) );
	}
	return Query ( nn );
}

int main()
{
	n = R(), m = R();
	for ( int i = 1; i <= n; ++i ) x[i] = R();
	for ( int i = 1; i <= m; ++i ) y[i] = R();
	int nl = 1, nr = 1;
	for ( ; nl <= n; ++nl )
	{
		for ( ; nr <= m && y[nr] < x[nl]; ++nr );
		if ( nr == 1 || nr > m ) continue;
		a[++np] = P ( x[nl] - y[nr - 1] + 1, y[nr] - x[nl] + 1 );
	}
	a[++np] = P ( 1, 1 );
	Pre();
	printf ( "%d\n", Gao() );
	return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>
int main(){
int a, b, s;
char op;
scanf("%d %c %d", &a, &op, &b);
for(;;){
if(op == '?'){
break;
}
switch(op){
case '+':
s = a + b;
break;
case '-':
s = a - b;
break;
case '*':
s = a * b;
break;
case '/':
s = a / b;
break;
case '%':
s = a % b;
break;
}
printf("%d\n", s);
scanf("%d %c %d", &a, &op, &b);
}
return 0;
}

Measured memory_bytes: 1820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main() {
  int n;
  cin>>n;

  int a[100005];
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  sort(a,a+n);
  int num=0,cnt=0;
  for (int i=0; i<n; i++) {
    if (num!=a[i]) {
      num=a[i];
      cnt++;
    }
  }
  cout<<cnt-((n-cnt)%2? 1:0)<<endl;
  return 0;
}

Measured memory_bytes: 640
# coding: utf-8

def areas_calc(strings):
    stack1 = []
    stack2 = []
    total_m = 0
    for i, s in enumerate(strings):
        if s == "\\":
            stack1.append(i)
        elif s == "_":
            continue
        elif s == '/':
            if len(stack1) > 0:
                previous_i = stack1.pop()
                m = i - previous_i
                total_m += m

                while len(stack2) > 0:
                    stacked_i, stacked_m = stack2.pop()
                    if previous_i < stacked_i:
                        m += stacked_m
                    else:
                        stack2.append((stacked_i, stacked_m))
                        stack2.append((previous_i, m))
                        break

                else:
                    stack2.append((previous_i, m))
    print(total_m)
    k = len(stack2)
    for_output = [str(k)] + [str(m) for i, m in stack2]
    print(' '.join(for_output))
    

if __name__ == "__main__":
    areas_calc(input())



Measured memory_bytes: 6204
import java.util.*;
public class Main{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        sc.close();
        char[] c = s.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if(c[i] >= 'A' && c[i] <= 'Z')
            {
                c[i] = Character.toLowerCase(c[i])  ;
            } else if(c[i] >= 'a' && c[i] <= 'z')
            {
                c[i] = Character.toUpperCase(c[i])  ;
            }
        }
        
        System.out.println(String.valueOf(c));
    }
    
    public static void printary(int[] a)
    {
        for ( int i = 0; i < a.length; i++) {
            if(i>0) System.out.print(" ");
            System.out.print(a[i]);
        }
        System.out.println();
    }
}


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

int main()
{
	int a,b,c,num1,num2,GCD,LCM;

	while(cin >> a >> b){

	//????????????
	if(b < a){
		num1 = a;
		a = b;
		b = num1;
	}
	num1 = a; num2 = b;
	//????????????????????????????????????????????§??¬?´???°????±???????
	while((b%a)!=0){
		c = b%a;
		b = a;
		a = c;
	}
	
	GCD = a;
	
	//????°???¬?????°????±???????
	
	LCM = (num1 / GCD) * num2;
	
	//???????????¨?????????
	cout << GCD << " " << LCM << endl;
	
	}
	
	return 0;
}

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

char buf[12];

int main() {

	int N,A,B;

	scanf("%d %d %d",&N,&A,&B);

	int i,j;

	int ans=0;

	for(i=1;i<=N;i++){
		memset(buf,'\0',sizeof(buf));
		sprintf(buf, "%d", i);
		int cnt=0;
		for(j=0;j<strlen(buf);j++){
		cnt+=buf[j]-'0';
		}
		if(A<=cnt&&cnt<=B){
		ans+=i;
		}
	}

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

	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {

	var H, A int
	fmt.Scanf("%d %d", &H, &A)

	var count int
	count = 1
	for {
		if H <= A {
			break
		} else {
			H = H - A
			count++
		}
	}

	fmt.Println(count)

}


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

using namespace std;

void swap(int *dat, int i, int j){

  int tmp = dat[i];
  dat[i] = dat[j];
  dat[j] = tmp;

}

void quicksort(int *dat, int first, int last){
  
  int p = dat[first];
  int i = first;
  int j = last;


  while(1){ 
    while( (dat[i] < p) && (i < last) ){
      i++;
    }

    while( (p < dat[j]) && (j > first) ){
      j--;
    }
 
    if(i >= j){
      break;
    }
    
    swap(dat, i, j);
    i++;
    j--;
        
  }
  

  if( first < i - 1 ){
    quicksort(dat, first, i - 1);
  }
  if(j + 1 < last){
    quicksort(dat, j + 1, last);
  }

}

void launch_quick(int *dat, int num){
  
  quicksort(dat, 0, num-1);

}

int main(){

  int N, A, B;
  int P[101] = {0};
  int cntA = 0;
  int cntAB = 0;
  int cntB = 0;
  
  cin >> N >> A >> B;

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

  launch_quick(P, N);

  for(int i = 0; i < N; i++){
    if(P[i] <= A){
      cntA++;
    }
    else if(P[i] <= B){
      cntAB++;
    }
    else{
      cntB++;
    }
  }

  cout << min(cntA, min(cntAB, cntB)) << "\n";
  
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        //入力


        //実証

        //出力


        int N = int.Parse(Console.ReadLine());

        string s = Console.ReadLine();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = int.Parse(s.Split(' ')[i]);
        }

        //ソートを続けるかどうかのフラグ
        bool flag = true;
        int counter = 0;  //カウンタ

        for (int i = 0; flag; i++) {
            flag = false;
            for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int kari = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = kari;
                    flag = true;
                    counter++;
                }
            }

        }

        Console.WriteLine(string.Join(" ", A));
        Console.WriteLine(counter);
    }
}


Measured memory_bytes: 17948
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

const long double PI = acos(-1);

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

ld a,b,h,m;
cin >> a >> b >> h >> m;

h += m/60;
h /= 12, m/= 60;
h *= 2*PI, m *= 2*PI;
ld ax = a*cos(h), ay = a*sin(h), bx = b*cos(m), by = b*sin(m);
cout << fixed << setprecision(12) << sqrt((ax-bx)*(ax-bx) + (ay-by)*(ay-by)) << endl;
return 0;
}

Measured memory_bytes: 4156
N = int(input())
X = input()
bin_X = int(X, 2)
cnt = 0
for i in X:
    if i == '1':
        cnt += 1


def bit_count(bits):
    cnt = 0
    while bits:
        bits = bits & (bits - 1)
        bits >> 1
        cnt += 1
    return cnt


def pop_counter(n):
    return n % bit_count(n)


ans = 0
xp = bin_X % (cnt + 1)
if cnt != 1:
    xm = bin_X % (cnt - 1)
else:
    xm = 0
for n, i in enumerate(X):
    if i == '0':
        tmp = xp + pow(2, N - n - 1, cnt + 1)
        tmp %= cnt + 1
    elif cnt != 1:
        tmp = xm - pow(2,N-n-1,cnt-1)
        tmp %= cnt -1
    else:
        print(0)
        continue
    ans = 1
    while tmp != 0:
        tmp = pop_counter(tmp)
        ans += 1
    print(ans)


Measured memory_bytes: 9472
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N, M;
  while(cin>>N>>M, N){
	VI h(N+1, 0), w(M+1, 0);
	REP(i,N){
	  int x; cin >> x;
	  h[i+1] = h[i] + x;
	}
	REP(i,M){
	  int x; cin >> x;
	  w[i+1] = w[i] + x;
	}
	LL ans = 0;
	map<int,int> szx, szy;
	for(int i=0;i<=M;++i)
	  for(int j=0;j<i;++j)
		szx[w[i]-w[j]]++;
	
	for(int i=0;i<=N;++i)
	  for(int j=0;j<i;++j){
		ans += szx[h[i]-h[j]];
	  }
	
	cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 19052
#include <iostream>
#include <cstdio>

using namespace std;
#define long long long

int const N = 1e5 + 10;

int n, total;
//long w[110], v[110], f[110][N];
long w[110], v[110], f[N];

int main()
{
//    freopen("tam.inp", "r", stdin);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n >> total;
    for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i];

//    for (int i = 1; i <= n; ++i)
//        for (int j = 1; j <= total; ++j) {
//            f[i][j] = f[i - 1][j];
//            if (w[i] <= j) f[i][j] = max(f[i][j], f[i - 1][j - w[i]] + v[i]);
//        }
//    cout << f[n][total];

    for (int i = 1; i <= n; ++i)
        for (int j = total; j; --j)
            if (w[i] <= j) f[j] = max(f[j], f[j - w[i]] + v[i]);
    cout << f[total];

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void)
{
	int n,m;
	while(cin >> n >> m){
		if(n==0&&m==0) break;
		int member[1001]={0};
		int count_n=0;
		int first = n;
		while(count_n != n){
			int count_m = 0;
			int i = first;
			while(1){
				if( member[i%n] == 0){
					count_m++;
				}
				if(count_m==m) break;
				i++;
			}
			member[i%n] = 1;
			first = i%n;
			count_n++;
		}
		cout << first+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#
# File    : A.rb
# Author  : Kazune Takahashi
# Created : 2019-3-24 20:58:56
# Powered by Visual Studio Code
#

b = gets.chomp
if b == 'A'
  puts 'T'
elsif b == 'T'
  puts 'A'
elsif b == 'C'
  puts 'G'
else
  puts 'C'
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cstring>
#include <map>
#include <stack>
using namespace std;

int dp[1010][8];
int N;
string S;

int enc(char c){
	return string("JOI").find(c);
}
int dfs(int day,int prev){
	if( day >= N ) return 1;
	if( dp[day][prev] != -1 ) return dp[day][prev];
	int ans = 0;
	for(int i = 0 ; i < 8 ; i++){
		if( (i & prev) && (i & (1<<enc(S[day])) ) ){
			ans += dfs(day+1,i);
			ans %= 10007;
			
		}
	}
	return dp[day][prev] = ans;
}
int main(){
	memset(dp,-1,sizeof(dp));
	cin >> N; cin >> S;
	cout << dfs(0,1) << endl;
	
}

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

int main(){       
  int A, B;
  cin >> A >> B;
  int sum = 0;

  for(int i = 0; i < 2; i++){
    if(A > B)
      sum += A--;
    else
      sum += B--;
  }

  cout << sum << endl;
  return 0;
  
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long N,k;
cin >> N >> k;
cout << (k%2==0?(((N+k/2)/k)*((N+k/2)/k)*((N+k/2)/k)):0)+(N/k)*(N/k)*(N/k) << endl;
return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
n -= 2
r = a[0]
i = 1
while n-2 >= 0:
    r += a[i]*2
    i += 1
    n -= 2
if n==1:
    r += a[i]
print(r)

Measured memory_bytes: 31316
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())
void no(){
  cout << -1 << endl;
  exit(0);
}

int main(){
  ll K; cin >> K;
  vector<ll> a(K);
  REP(i,K) cin >> a[i];
  ll maxi = 2, mini = 2;
  IREP(i,K){
    // t = mini以上で最小のa[i]の倍数
    ll t = (mini+a[i]-1)/a[i]*a[i];
    if(t>maxi) no();
    //  u = maxi以下で最大のa[i]の倍数+a[i]-1
    ll u = (maxi+1+a[i]-1)/a[i]*a[i]-1;
    maxi = u;
    mini = t;
  }
  cout << mini << " " << maxi << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

//二次元累積和
struct cumulative_sum_2d {
    using lint = long long int;
    int sz;
    vector<vector<lint>> data;
    vector<vector<lint>> sum;
    cumulative_sum_2d(const int _sz) : sz(_sz) {
        data.assign(sz, vector<lint>(sz));
        sum.assign(sz + 1, vector<lint>(sz + 1));
    }
    vector<lint> &operator[](const int k) {
        return data[k];
    }
    void build() {
        for (int i = 0; i < sz; i++)
            for (int j = 0; j < sz; j++)
                sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + data[i][j];
    }
    //[a,b)×[c,d)の和を計算
    lint query(const int a, const int b, const int c, const int d) const {
        return sum[b][d] - sum[b][c] - sum[a][d] + sum[a][c];
    }
};

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

lint h, w, k;
vector<string> s;

int main() {
    cin >> h >> w >> k;
    s.resize(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    lint ans = INT_MAX;
    cumulative_sum_2d cum(1000);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '1') {
                cum[i][j]++;
            }
        }
    }
    cum.build();
    for (int i = 0; i < (1 << (h - 1)); i++) {
        bitset<10> b(i);
        vector<int> cut;
        cut.push_back(0);
        for (int j = 0; j < h - 1; j++) {
            if (b[j]) {
                cut.push_back(j + 1);
            }
        }
        cut.push_back(h);
        lint cand = b.count() - 1;
        lint left = 0;
        bool hoge = true;
        vector<int> bdry;
        while (left < w) {
            lint ok = left, no = w + 1;
            while (abs(ok - no) > 1) {
                lint mid = (ok + no) / 2;
                bool flag = true;
                for (int j = 0; j < (int)(cut.size()) - 1; j++) {
                    if (cum.query(cut[j], cut[j + 1], left, mid) > k) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    ok = mid;
                } else {
                    no = mid;
                }
            }
            if (ok == left) {
                hoge = false;
                break;
            } else {
                left = ok;
                bdry.push_back(ok);
                cand++;
            }
        }
        if (hoge) {
            chmin(ans, cand);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 16000
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int wide, tall, field[16][16], memo[16][16];

int skiing(int x, int y, bool ok)
{
	if( x < 0 || x >= wide || field[y][x] == 1 || field[y][x] == 2 && ok == true )
	{
		return 0;
	}
	else if( y >= tall - 1 )
	{
		return 1;
	}

	if( memo[y][x] != -1 )
	{
		return memo[y][x];
	}

	if( field[y][x] == 2 )
	{
		return memo[y][x] = skiing(x, y+2, false);
	}
	else
	{
		return memo[y][x] = skiing(x-1, y+1, true) + skiing(x, y+1, false) + skiing(x+1, y+1, true);
	}
}

int main()
{
	int cnt;
	while( cin >> wide >> tall )
	{
		if( wide == 0 && tall == 0 )
		{
			break;
		}

		memset(memo, -1, sizeof(memo));

		for(int i = 0; i < tall; i++)
		{
			for(int j = 0; j < wide; j++)
			{
				cin >> field[i][j];
			}
		}
		cnt = 0;
		for(int i = 0; i < wide; i++)
		{
			cnt += skiing(i, 0, false);
		}

		cout << cnt << endl;
	}
}

Measured memory_bytes: 1160
#include <cstdio>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>

using namespace std;

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

	if(A>=K){
		cout << A-K << " " << B;
	}else{
		if(B-(K-A)>0){
			cout << "0 " << B-(K-A);
		}else{
			cout << "0 0";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, q; scanf("%d%d", &n, &q);
	std::vector<std::vector<int>> g(n);
	for(int i = 0; i < n - 1; i++) {
		int a, b; scanf("%d%d", &a, &b);

		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}

	std::vector<i64> latte(n, 0);
	for(int i = 0; i < q; i++) {
		int p; i64 x; scanf("%d%lld", &p, &x);

		latte[p - 1] += x;
	}
	
	i64 tmp = 0;
	std::vector<i64> ans(n, 0);
	std::function<void (int, int)> solve = [&](int v, int par) {
		tmp += latte[v];
		ans[v] = tmp;
		for(auto e: g[v]) {
			if(e == par) continue;
			solve(e, v);
		}
		tmp -= latte[v];
		
	};
	solve(0, -1);

	for(auto v: ans) printf("%d ", v);
	printf("\n");
	return 0;
}


Measured memory_bytes: 32128
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include <ctime>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	string N;
	cin >> N;
	int sum = 0;
	rep(i, N.size()) {
		int num = N[i] - '0';
		sum += num;
		sum = sum % 9;
	}
	if (sum % 9 == 0)cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
#define BUG cout << "acdsfas" << endl
#define int long long

struct point {
    int w, s, v;
    bool operator < (const point &b) const {
        return w + s < b.w + b.s;
    }
};

const int N = 1e3 + 15;
const int M = 2e4 + 15;
int n, m, dp[2][M];
point a[N];

// dp[bit][weight] = max_cost

main() {
    scanf("%lld", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%lld %lld %lld", &a[i].w, &a[i].s, &a[i].v);
    sort(a + 1, a + 1 + n);
    for(int i = 1; i <= n; ++i) {
        int bit = i & 1;
        memcpy(dp[bit], dp[bit ^ 1], sizeof(dp[bit]));
        for(int j = min(a[i].s, M - 1 - a[i].w); j >= 0; --j)
            dp[bit][j + a[i].w] = max(dp[bit][j + a[i].w], dp[bit ^ 1][j] + a[i].v);
    }
    printf("%lld\n", *max_element(dp[n & 1], dp[n & 1] + M));
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s;
	cin >> s;
	
	vector<int> index;
	int n = s.size();
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if( s[i] != s[n - i - 1] ) ans++;
	}
	
	cout << ans / 2 << endl;
	
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int T=1;
    //cin >> T;
    while(T--){
        ll n,a,b,c;
        cin>>n;
        ll dp[n][3];
        rep(i,n) dp[i][2]=dp[i][1]=dp[1][0]=0;
        cin>>a>>b>>c;
        dp[0][0]=a;
        dp[0][1]=b;
        dp[0][2]=c;
        rep_a(i,1,n){
            cin>>a>>b>>c;
            dp[i][0]=a+max(dp[i-1][1], dp[i-1][2]);
            dp[i][1]=b+max(dp[i-1][0], dp[i-1][2]);
            dp[i][2]=c+max(dp[i-1][1], dp[i-1][0]);
        }
        cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<el;
    }

    return 0;
}

Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {

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

		String mes = stdIn.next();
		int n = stdIn.nextInt();
		int cnt = 0;
		for(int i=0;i<n;i++){
			StringBuffer input = new StringBuffer();
			input.append(stdIn.next());
			input.append(input);
			if(input.toString().contains(mes)){
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

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

int main() {
  int n, k;
  string s;

  cin >> n >> k;
  cin >> s;

  for (int i = 0; i < n; i++) {
    if (i == (k - 1)) {
      s[i] = tolower(s[i]);
    }
  }
  cout << s << endl;
}

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

int n;
void dfs(string s, int depth, int used) {
  
  if(depth == n) {
    printf("%s\n", s.c_str());
    return;
  }
  for(int i = 0; i < used + 1; ++i) {
    char c = 'a' + i;
    string tmp(1, c);
    if(i == used) dfs(s + tmp , depth + 1, used + 1);
    else dfs(s + tmp , depth + 1, used);
  }  
}

int main(){
  cin >> n;
  dfs("", 0, 0);
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);
#define openfile freopen("input.txt", "r" ,stdin); freopen("output.txt", "w", stdout); 
#define FOR(n) for(int i(0);i<n;++i)
#define ASC(i,a,b) for(int i(a); i <=b; ++i)
#define DESC(i,a,b) for(int i(a);i>=b;i--)
#define WL(t) while(t--)
#define SZ(a) int((a).size())
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define BB begin()
#define EE end()
#define all(c) c.BB, c.EE
#define present(container, element) (container.find(element) != container.end())
// ^^for set,map etc
#define cpresent(container, element) (find(all(container), element) != container.end())
// for vector,array etc
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef map<char,int> mci;
typedef pair<int, int> pii;
typedef map<int,pii> ipii;
const float INF = numeric_limits<float>::infinity();
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
const LL big=998244353;

#ifdef _DEBUG
freopen(input.txt,"r",stdin);
freopen(output.txt,"w",stdout);
#endif

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	cout << max(0,b+c-a);
}

Measured memory_bytes: 256
N=int(input())
nlist = list(map(int, input().split()))
nnlist = sorted(nlist)
kei = 0
l = 0
for i in range(l,N-2):
    for j in range(i,N-1):
        for k in range(j,N):
            if nnlist[i]!=nnlist[j]:
                if nnlist[i]!=nnlist[k]:
                    if nnlist[j]!=nnlist[k]:
                        if nnlist[i]+nnlist[j]>nnlist[k]:
                            kei = kei+1
print(kei)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N);
    ll X = 0;
    for(auto& x:A){
        cin >> x;
        X ^= x;
    }
    ll ans = 0;
    int M = 60;
    for(int i=0;i<M;i++) if(X>>i&1){
        ans += 1LL<<i;
        for(int j=0;j<N;j++) if(A[j]>>i&1) A[j] ^= 1LL<<i;
    }

    int r = 0;
    for(int i=M-1;i>=0;i--){
        bool ok = false;
        for(int j=r;j<N;j++) if(A[j]>>i&1){
            swap(A[j],A[r]);
            ok = true;
            break;
        }
        if(ok){
            for(int j=0;j<N;j++) if(j!=r && (A[j]>>i&1)) A[j] ^= A[r];
            r++;
        }
    }
    ans += 2*accumulate(A.begin(),A.end(),0LL,[](ll a,ll b){return a^b;});
    cout << ans << "\n";
}

Measured memory_bytes: 3956
import fractions

N = int(input())
A = list(map(int, input().split()))

gcd = fractions.gcd(A[0], A[1])
ag = {A[0], A[1]}

for d in A[2:]:
    gc = fractions.gcd(gcd, d)
    ag2 = set()
    for c in ag:
        ag2.add(fractions.gcd(c, d))
    ag = ag2
    ag.add(gcd)
    gcd = gc

print(max(ag))

Measured memory_bytes: 16124
//69行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

//Simple Array Input
#define SAI int n;cin >> n;vi a(n);ain(a)
//Simple Graph Input
#define SGI(m) for(int i=0;i<m;i++){int a,b;cin >> a >> b;g[--a].pb(--b);g[b].pb(a);}
//Simple Tree Input
#define STI SGI(n-1)

typedef long long ll;
typedef long long integer;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){
    for(int i=0;i<a.size();i++)cout << a[i] << (i < a.size()-1 ? ' ' : '\n');
}
///////////////////////////////////////////////////////////
int main(int argc, char const *argv[])
{
	cin.tie(0);ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);

	int n,k;cin >> n >> k;
	vector<int> a(n);
	rep(i,n){
		cin >> a[i];
		a[i]--;
	}
	vector<ll> c(n+1,0);
	rep(i,n){
		c[i+1] = (c[i] + a[i]) % k;
	}
	map<ll,vector<int>> M;
	rep(i,n+1){
	    M[c[i]].push_back(i);
	}
	ll ans = 0;
	for(auto i : M){
	   auto v = i.second;
	   if(v.size() <= 1)continue;

	   for(int j = 0;j < v.size();j++){
	      ans += (ll)(lower_bound(all(v),v[j] + k) - v.begin() - (j + 1));
	   }
	}
	cout << ans << '\n';
	return 0;
}

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

string S;
vector<vector<int>> color;

void hantei(int i){
  if(S[i]=='R'){
    color[0][i]++;
  }
  else if(S[i]=='G'){
    color[1][i]++;
  }
  else if(S[i]=='B'){
    color[2][i]++;
  }
}

int main(){
  int N;
  cin >> N >> S;
  vector<vector<int>> c(3,vector<int>(N,0));
  color=c;
  ll ans=0;
  hantei(0);
  for(int i=0;i<N;i++){
    color[0][i]=color[0][i-1];
    color[1][i]=color[1][i-1];
    color[2][i]=color[2][i-1];
    hantei(i);
  }
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(S[i]==S[j]){
        continue;
      }
      if((S[i]=='R' && S[j]=='G') || (S[i]=='G' && S[j]=='R')){
        ans+=color[2][N-1]-color[2][j];
        if(i+2*(j-i)<N && S[i+2*(j-i)]=='B'){
          ans--;
        }
      }
      else if((S[i]=='G' && S[j]=='B') || (S[i]=='B' && S[j]=='G')){
        ans+=color[0][N-1]-color[0][j];
        if(i+2*(j-i)<N && S[i+2*(j-i)]=='R'){
          ans--;
        }
      }
      else if((S[i]=='B' && S[j]=='R') || (S[i]=='R' && S[j]=='B')){
        ans+=color[1][N-1]-color[1][j];
        if(i+2*(j-i)<N && S[i+2*(j-i)]=='G'){
          ans--;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++){
    cin >> A[i];
  }
  int m = 0;
  int d = 1;
  while (d <= n){
    d = d * 3 + 1;
    m++;
  }
  vector<int> g(m);
  g[m - 1] = 1;
  for (int i = m - 2; i >= 0; i--){
    g[i] = g[i + 1] * 3 + 1;
  }
  cout << m << endl;
  int cnt = 0;
  for (int i = 0; i < m; i++){
    cout << g[i];
    if (i < m - 1){
      cout << ' ';
    }
    for (int j = g[i]; j < n; j++){
      int v = A[j];
      int k = j - g[i];
      while (k >= 0 && A[k] > v){
        A[k + g[i]] = A[k];
        k = k - g[i];
        cnt++;
      }
      A[k + g[i]] = v;
    }
  }
  cout << endl;
  cout << cnt << endl;
  for (int i = 0; i < n; i++){
    cout << A[i] << endl;
  }
}


Measured memory_bytes: 6704
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    S = LI()
    q = I()
    T = LI()

    cnt = 0
    for i in T:
        if i in S:
            cnt += 1
    
    print(cnt)

if __name__ == '__main__':
    resolve()


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
            int a = line[0], b = line[1], c = line[2];

            Console.WriteLine(a * b / 2);
        }
    }
}


Measured memory_bytes: 13268
import sys

N, M = map(int, input().split())
A = [list(input()) for i in range(N)]
B = [list(input()) for i in range(M)]

for k in range(N-M+1):
    for i in range(N-M+1):
        a = [A[j+k][i:i+M] for j in range(M)]
        if a == B:
            print('Yes')
            sys.exit()

print('No')

Measured memory_bytes: 3064