akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()

int main() {
   int a,b;
   cin >> a >> b;
   if(b==1)
   cout << 0 << endl;
   else
   cout << (b-2)/(a-1)+1 << endl;
}

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

int main(){
	int n,k,sum=0;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<k;i++){
		sum=sum+a[i];
	}
	cout<<sum<<endl;
	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

const int MAXN = 1000;
const int MAXS = 10000;
const ll INF = 1e15;
ll dp[MAXN + 5][2 * MAXS + 5];
ll best[MAXN + 5];

auto maxx(auto& a, auto b){a = max(a, b);}

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

  int n;
  cin >> n;
  vi w(n), s(n), v(n);
  rep(i, 0, n) {
    cin >> w[i] >> s[i] >> v[i];
  }
  vi ind(n);
  iota(all(ind), 0);
  sort(all(ind),
       [&](int i, int j) {
	 return s[i] + w[i] < s[j] + w[j];
       });
  auto w2 = w, s2 = s, v2 = v;
  rep(i, 0, n) {
    int i2 = ind[i];
    w[i] = w2[i2], s[i] = s2[i2], v[i] = v2[i2];
  }

  rep(i, 0, MAXN + 1) rep(j, 0, 2 * MAXS + 1)
    dp[i][j] = -1;
  dp[0][0] = 0;
  
  rep(i, 0, n) {
    for (int weight = MAXS; weight >= 0; weight--) {
      maxx(dp[i + 1][weight], dp[i][weight]);
      if (weight <= s[i] and dp[i][weight] != -1) {
	maxx(dp[i + 1][weight + w[i]], dp[i][weight] + v[i]);
	//cout << "Can get: " << dp[i + 1][weight + w[i]] << endl;
      }
    }
    // cout << dp[i + 1][1] << " " << dp[i + 1][2] << " " << dp[i + 1][3] << endl;
  }
  auto res = 0LL;
  rep(i, 0, n + 1) {
    maxx(res, *max_element(all(dp[i])));
  }
  cout << res << '\n';
    
}


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO

    int k;
    cin >> k;

    int x;
    cin >> x;

    if(k * 500 >= x) cout << "Yes\n";
    else cout << "No\n";

}








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

using namespace std;

const int NMAX = 105;
const int VALMAX = 1e5;
const int WMAX = 1e9+5;

int w[NMAX],v[NMAX],dp[NMAX][VALMAX+5];

int main()
{
    int N,i,j,W,k;

    cin>>N>>W;

    for(i = 1 ; i <= N ; ++i)
        cin>>w[i]>>v[i];

    for(i = 0 ; i <= N ; ++i)
        for(j = 1 ; j <= VALMAX ; ++j)
            dp[i][j] = WMAX;

    for(i = 0 ; i <= N ; ++i)
        dp[i][0] = 0;

    for(i = 1 ; i <= N ; ++i)
    {
        for(j = 1 ; j <= VALMAX ; ++j)
        {
            if(j >= v[i])
                dp[i][j] = min(dp[i-1][j-v[i]] + w[i] , dp[i-1][j]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }

    int maxim = 0;
    for(i = 0 ; i <= VALMAX ; ++i)
        if(dp[N][i] <= W)
            maxim = i;

    cout<<maxim;
}


Measured memory_bytes: 41216
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 + 2];

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

        int tmp = 0;
        for (int i = 1; i <= N; i++) {
            tmp += Math.abs(A[i - 1] - A[i]);
        }
        tmp += Math.abs(A[N]);

        for (int i = 1; i <= N; i++) {
            int ans = tmp;
            ans -= Math.abs(A[i] - A[i + 1]);
            ans -= Math.abs(A[i - 1] - A[i]);
            ans += Math.abs(A[i - 1] - A[i + 1]);

            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 63288
import itertools

S = raw_input()

n = len(S)-1
retu = range(n)
ans = 0
for r in range(n+1):
    for c in itertools.combinations(retu, r):
        if not c:
            ans += int(S)
        else:
            ans += int(S[0:c[0]+1])
            for i in range(r-1):
                ans += int(S[c[i]+1:c[i+1]+1])
            ans += int(S[c[r-1]+1:])

print ans





Measured memory_bytes: 2692
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            if(x>=30)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
    
}

Measured memory_bytes: 27480
#include<bits/stdc++.h>
#define N 111111
using namespace std;
int n,l,T,i,V,TT,len,cnt,u,a[N],b[N],c[N],an[N],t;
struct P{
	int x,lx,id;
}p[N];
bool cmp(P a,P b){
	return a.x<b.x;
}
int main(){
	scanf("%d%d%d",&n,&l,&T);
	for(i=1;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].lx),p[i].id=i;
	sort(p+1,p+n+1,cmp);
	for(i=1;i<=n;i++){
		if(p[i].lx==1)b[i]=(p[i].x+T)%l;else b[i]=(p[i].x-T%l+l)%l;
	}
	for(i=2;i<=n;i++)if(p[i].lx!=p[1].lx){
		if(p[1].lx==1)len=(p[i].x-p[1].x+l)%l;
		else len=(p[1].x-p[i].x+l)%l;
		TT=T*2;
		if(TT>=len)cnt++,TT-=len;
		cnt+=TT/l;
		cnt%=n;
	}
	V=b[1];
	sort(b+1,b+n+1);
	if(p[1].lx==1)
	for(i=1;i<=n;i++)if(b[i]==V)u=i;
	if(p[1].lx==2)
		for(i=n;i;i--)if(b[i]==V)u=i;
	for(i=u;i<=n;i++)c[++t]=b[i];
	for(i=1;i<u;i++)c[++t]=b[i];
	if(p[1].lx==1)cnt=n-cnt;c[0]=c[n];
	for(i=1;i<=n;i++)an[p[i].id]=c[(i+cnt)%n];
	for(i=1;i<=n;i++)printf("%d\n",an[i]);
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)

int main()
{
  string s;
  cin >> s;
  deque<char> ds(s.size());
  for (int i = 0; i < s.size(); i++)
    ds[i] = s[i];
  int q;
  cin >> q;
  int rev = 0;
  for (int i = 0; i < q; i++)
  {
    int type;
    cin >> type;
    if (type == 2)
    {
      int f;
      char c;
      cin >> f >> c;
      f--;
      if (rev) 
        f = 1 - f;
      if (f == 0)
        ds.push_front(c);
      else
        ds.push_back(c);
    }
    else
    {
      rev = 1 - rev;
    }
  }
  if (rev)
    reverse(ds.begin(), ds.end());
  for (auto c : ds)
    cout << c;
  cout << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int read(){
	int sum=0,f=1;
	char s=getchar();
	while (s<'0' or s>'9'){
		if (s=='-')f=-1;
		s=getchar();
	}
	while (s>='0' and s<='9'){
		sum=sum*10+s-'0';
		s=getchar();
	}
	return sum*f;
}
int n;
int main(){
	int a=read(),b=read();
	cout<<a*b<<endl;
		
	return 0;
}



Measured memory_bytes: 3672
while True:
  n = int(input())
  if n == 0:
    break
  a = list(map(int,input().split()))
  s = sum(a)/n
  a.sort()
  ans = 0
  for i in range(n):
    if a[i]>s:
      break
    ans += 1
  print(ans)


Measured memory_bytes: 6608
using System;
using System.Linq;

namespace Recursion___Divide_and_Conquer
{
    class The_Number_of_Inversions
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            Console.WriteLine(MergeSort(A, 0, A.Length));
        }

        static long Merge(int[] A, int left, int mid, int right)
        {
            long c = 0;
            var n1 = mid - left;
            var n2 = right - mid;
            var L = new int[n1 + 1];
            var R = new int[n2 + 1];
            for (int i = 0; i < n1; i++)
                L[i] = A[left + i];
            for (int i = 0; i < n2; i++)
                R[i] = A[mid + i];
            L[n1] = R[n2] = int.MaxValue;
            var p = 0; var q = 0;
            for (int k = left; k < right; k++)
                if (L[p] <= R[q]) A[k] = L[p++];
                else { c += L.Length - 1 - p; A[k] = R[q++]; }
            return c;
        }

        static long MergeSort(int[] A, int left, int right)
        {
            long c = 0;
            if (left + 1 < right)
            {
                var mid = (left + right) / 2;
                c += MergeSort(A, left, mid);
                c += MergeSort(A, mid, right);
                c += Merge(A, left, mid, right);
            }
            return c;
        }
    }
}

Measured memory_bytes: 36388
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    vint a(n);
    deque<int> b;
    rep(i, n) cin >> a[i];
    sort(ALL(a));

    vint ap = a;
    ll t=0;
    b.push_back(a[0]);
    int l=1, r=n-1, c=0;
    while(l<=r){
        if(c%2==0){
            // pr('a');
            int k = b.back();
            t += abs(k - a[r]);
            b.push_back(a[r--]);
            if(l>r) break;
            k = b.front();
            t += abs(k - a[r]);
            b.push_front(a[r--]);
        }else{
           int k = b.back();
            t += abs(k - a[l]);
            b.push_back(a[l++]);
            if(l>r) break;
            k = b.front();
            t += abs(k - a[l]);
            b.push_front(a[l++]);
        }
        c++;
    }
    // while(!b.empty()){
    //     pr(b.front());
    //     b.pop_front();
    // }
    // // pr("");
    ll ans = t;
    reverse(ALL(a));
    t=0;
    b.clear();
    b.push_back(a[0]);
    l=1; r=n-1; c=0;
    while(l<=r){
        if(c%2==0){
            // pr('a');
            int k = b.back();
            t += abs(k - a[r]);
            b.push_back(a[r--]);
            if(l>r) break;
            k = b.front();
            t += abs(k - a[r]);
            b.push_front(a[r--]);
        }else{
           int k = b.back();
            t += abs(k - a[l]);
            b.push_back(a[l++]);
            if(l>r) break;
            k = b.front();
            t += abs(k - a[l]);
            b.push_front(a[l++]);
        }
        c++;
    }
    // while(!b.empty()){
    //     pr(b.front());
    //     b.pop_front();
    // }
    // pr(t);
    pr(max(ans, t));
    return 0;}

Measured memory_bytes: 4576
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <ostream>
using namespace std;
typedef long long ll;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scanlld(n) scanf("%lld",&n)
#define scans(str) scanf("%s",str)
bool vis[1005];
int d[1005];
const int mod=1e9+7;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL
    int m=sqrt(1000+0.5);
    for(int i=2; i<=m; ++i)
        if(!vis[i])
            for(int j=i*i; j<=1005; j+=i)
                vis[j]=1;
    int n;
    scand(n);
    for(int i=2; i<=n; ++i)
    {
        int cnt=i;
        for(int j=2; j<=n; ++j)
            if(!vis[j])
            {
                while(cnt%j==0)
                {
                    cnt/=j;
                    ++d[j];
                }
                if(cnt==1)break;
            }
    }
    int ans=1;
    for(int i=2; i<=n; ++i)
        if(!vis[i])
        {
            ans=(1LL*ans*(d[i]+1))%1000000007;
        }
    printf("%d",ans);
    return 0;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[sc.nextInt() - 1]++;
		}
		sc.close();

		Arrays.sort(a);
		int sum = 0;
		for (int i = 0; i < n - k; i++) {
			sum += a[i];
		}
		System.out.println(sum);
	}
}
	

Measured memory_bytes: 86032
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ld long double
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> k(m);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    k[i]=make_pair(b,a);
  }
  sort(k.begin(),k.end());
  int cnt=0;
  int left=-1;
  rep(i,m){
    if(k[i].second<left)continue;
    else{
      cnt++;
      left=k[i].first;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define sz(x) (int) x.size()
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
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...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<str> vstr;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 7;

//

int32_t main() {
  FAST_IO;
  int n;
  cin >> n;
  int ans = (n + 1) / 2;
  cout << ans << '\n';
  rtn 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int m,f,r;
	int sum;
	
	while(1)
	{
		scanf("%d %d %d",&m,&f,&r);
		
		if(m==-1 && f==-1 && r==-1)
		{
			goto end;
		}
		
		sum = m+f;
		
		if(m==-1 || f==-1)
		{
			printf("F");
		}
		else if(sum>=80)
		{
			printf("A");
		}
		else if(sum>=65 && sum<80)
		{
			printf("B");
		}
		else if(sum>=50 && sum<65)
		{
			printf("C");
		}
		else if(sum>=30 && sum<50)
		{
			if(r>=50)
			{
				printf("C");
			}
			else
			{
				printf("D");
			}
		}
		else if(sum<30)
		{
			printf("F");
		}
		
		printf("\n");
		
	}
	
	end:
	
	return 0;
}

Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[20][20],tmp[20];
ll dp[(1<<16)+10];
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch&15),ch=getchar();
	return x*f;
}
int main()
{
	int n=read();
	for (register int i=1;i<=n;++i)
	  for (register int j=1;j<=n;++j)
	    a[i][j]=read();
	int S=(1<<n)-1;
	for (register int i=0;i<=S;++i)
	{
		int t=i,d=0,p=0;
		while (t)
		{
			d++;
			if (t&1) tmp[++p]=d;
			t>>=1;
		}
		for (register int j=1;j<=p;++j)
		  for (register int k=j+1;k<=p;++k)
		    dp[i]+=a[tmp[j]][tmp[k]];
	}
	for (register int i=0;i<=S;++i)
	  for (register int j=i;j;j=(j-1)&i)
	    dp[i]=max(dp[i],dp[j]+dp[i^j]);
	printf("%lld\n",dp[S]);
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <bitset>
#include <fstream>

#define ll long long
#define scani(x) scanf("%i", &x)
#define scanll(x) scanf("%I64d", &x)
#define scanfl(x) scanf("%f", &x)
#define scanch(x) scanf("%c", &x)
#define scans(x) scanf("%s", x);
#define printi(x) printf("%i", x);
#define printll(x) printf("%I64d", x);
#define printfl(x) printf("%f", x);
#define printch(x) printf("%c", x);
#define prints(x) printf("%s", x);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define INFI (1 << 29)
#define INFL (1LL << 62)
#define sz(x) int(x.size())
#define fi first
#define se second
#define forn(i, n) for(ll i = 0; i < n; i++)
#define for1(i, n) for(ll i = 1; i <= n; i++)
#define ford(i, n) for(ll i = (n - 1); i >= 0; i--)
#define fori(i, n) for(ll i = n; i >= 1; i--)
#define fore(i, l, r) for(ll i = l; i <= r; i++)
#define get_bit(mask, x) (bool)(mask & (1LL << x))
#define set_bit(mask, x) (mask |= (1LL << x))
#define reset_bit(mask, x) (mask &= ~(1LL << x))
#define toggle_bit(mask, x) (mask ^= (1LL << x))

using namespace std;

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

    ll n;

    cin >> n;

    n--;

    cout << ((n * (n + 1)) / 2) << "\n";

    return 0;
}


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

int main(){
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++){
        if (i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    
    cout << "NG" << endl;
    return 0;
    
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  string s, t; cin >> s >> t;
  map<char, set<int>> mp;
  REP(i, s.size()){
    mp[s[i]].insert(i+1);
    mp[s[i]].insert(s.size()+(i+1));
  }
  REP(j, t.size()){
    if(mp[t[j]].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  int ans = 0, pos = 0;
  REP(i, t.size()){
    auto itr = mp[t[i]].upper_bound(pos);
    ans += *itr - pos;
    pos = *itr;
    if(pos > s.size()) pos -= s.size();
  }
  cout << ans << endl;
}

Measured memory_bytes: 9936
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//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 SQ(a) ((a)*(a))
#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,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

//ここから編集
template <typename Monoid>
struct SegmentTree{

  int N;
  vector<Monoid> node;
  Monoid Unit;
  function<Monoid(Monoid, Monoid)> f;

  SegmentTree(vector<Monoid> v, const function<Monoid(Monoid, Monoid)> f, const Monoid &Unit): f(f), Unit(Unit){
    int sz_ = v.size();
    N = 1;
    while(N < sz_) N *= 2;

    node.assign(2*N, Unit);
    for(int i=0; i<sz_; i++) node[i+N-1] = v[i];
    for(int i=N-2; i>=0; i--) node[i] = f(node[2*i+1], node[2*i+2]);
  }

  void update(int k, const Monoid &x) {
    k += N-1;
    node[k] = x;
    while(k > 0){
      k = (k-1)/2;
      node[k] = f(node[2*k+1], node[2*k+2]);
    }
  }

  Monoid query(int a, int b, int k=0, int l = 0, int r=-1){
    if(r < 0) r = N;
    if(r <= a || b <= l) return Unit;
    
    if(a <= l && r <= b) return node[k];
    else{

      Monoid vl = query(a, b, 2*k+1, l, (l+r)/2);
      Monoid vr = query(a, b, 2*k+2, (l+r)/2, r);
      return f(vl, vr);
    }
  }
};

int GCD(int a, int b){
  if(b == 0) return a;
  return GCD(b, a%b);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(5);
  

  int N; cin >> N;
  vector<int> a(N);
  REP(i,N) cin >> a[i];
  function<int(int,int)> op = [&op](int a, int b){ return (b==0)?a:op(b,a%b);};
  SegmentTree<int> seg(a, op, 0);

  int ans = 1;
  for(int i=0; i<N; i++){
    if(i == 0){
      ans = max(ans, seg.query(1, N));
    }else if(i == N-1){
      ans = max(ans, seg.query(0, i));
    }else{
      
      ans = max(ans, GCD(seg.query(0, i), seg.query(i+1, N)));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4968
import java.util.Scanner;
	class Main {
	public static void main(String[] args){
        
		Scanner s = new Scanner(System.in);
		int i,j,k,n,x,count=0;
        boolean sw=false;
        
                  n=s.nextInt();
      			  x=s.nextInt();
        
        if(n==0&&x==0)
            sw=true;
        
        while(sw==false){
            
              for(i=1;i<=n-2;i++)
           		 for(j=i+1;j<=n-1;j++)
            	      for(k=j+1;k<=n;k++)
                         if(i+j+k==x)count++;
                         

                
  			 System.out.println(count);
            
            n=s.nextInt();
      		x=s.nextInt();
            count=0;
            if(n==0&&x==0)
            	sw=true;
        }
	}
}


Measured memory_bytes: 26420
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
 
int main() {
	int n, m;
	std::cin >> n >> m;
 
	std::vector<int> us(m);
	std::vector<int> vs(m);
	std::vector<int> ws(m);
	for (int i = 0; i < m; i++) {
		std::cin >> us[i] >> vs[i] >> ws[i];
		us[i]--;
		vs[i]--;
	}
 
	constexpr long long INF = 1e18;
	std::vector<long long> d(n, -INF);
 
	d[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			d[vs[j]] = std::max(d[vs[j]], d[us[j]] + ws[j]);
		}
	}
	long long ans1 = d[n - 1];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			d[vs[j]] = std::max(d[vs[j]], d[us[j]] + ws[j]);
		}
	}
	long long ans2 = d[n - 1];
	if (ans1 != ans2) {
		std::cout << "inf" << std::endl;
	} else {
		std::cout << ans1 << std::endl;
	}
}

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

int main() {
    int a;
    string s;
    cin >> a >> s;
    if(a>=3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}

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

#define LL long long
#define int long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<LL, LL>
#define pdd pair<double, double>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define length(p1, p2) ((p1.fi-p2.fi)*(p1.fi-p2.fi)+(p1.se-p2.se)*(p1.se-p2.se))
#define ith(state, i) (state & (1 << i))

using namespace std;

constexpr int N = 2e5+9;
constexpr int M = 2e4+9;

//constexpr int INF = 0x3f3f3f3f3f3f3f3f;
int n, k;
int dp[N][64];
int a[N];

signed main() {
    fastio;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i], dp[i][0] = a[i];
    for (int p = 1; p < 64; p++) {
        for (int i = 1; i <= n; i++) {
            dp[i][p] = dp[dp[i][p-1]][p-1];
        }
    }
    int s = 1;
    for (int j = 63; j >= 0; j--) {
        if (k & (1ll << j)) s = dp[s][j];
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 105192
#include <string>
#include<string.h>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<iostream>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fuck(x) cout<<x<<endl
#define mem(a,b) memset(a,b,sizeof a)
#define lowbit(x) (x&-x)
const int MAX=1e5*2+10;
class e
{
    public:
    int u,v,next;
};
e edge[MAX<<1];
int tot;
int head[MAX];
void init()
{
    memset(head,-1,sizeof head);
    tot=0;
}
void add(int u,int v)
{
    edge[tot].u=u;
    edge[tot].v=v;
    edge[tot].next=head[u];
    head[u]=tot++;
}
class node
{
    public:
    int per,u,times;
    node(int per,int u=0,int times=0):per(per),u(u),times(times){}
};
int vis[MAX];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        init();
        memset(vis,0,sizeof vis);
        for(int i=0;i<m;i++)
        {
            int u,v;
            scanf("%d %d",&u,&v);
            add(u,v);
            add(v,u);
        }
        queue<node> Q;
        Q.push(node(-1,1,0));
        int flag=0;
        while(!Q.empty())
        {
            node now=Q.front();
            Q.pop();
            int u=now.u;
            int per=now.per;
            vis[u]=1;
            if(now.times>2)
                continue;
            if(now.times==2 && u==n)
                {flag=1;break;}
            for(int i=head[u];i!=-1;i=edge[i].next)
            {
                int v=edge[i].v;
                if(v==per||vis[v])
                    continue;
                Q.push(node(u,v,now.times+1));
            }
        }
        if(flag)
            puts("POSSIBLE");
        else
            puts("IMPOSSIBLE");
    }
}


Measured memory_bytes: 7680
from sys import stdin
n,m,x,y = map(int,stdin.readline().split())
ans = 'War'
a = map(int,stdin.readline().split())
b  = map(int,stdin.readline().split())
a.sort()
b.sort()
found = 0
for i in xrange(x+1,y+1):
 if max(a) < i and min(b) >= i:
  ans = 'No War'
print ans


Measured memory_bytes: 2568
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
  int n; cin >> n;
  static double x[100], a[100], y;
  int i;

  for( i = 0; i < n; i++ )
    cin >> x[i];

  for( i = 0; i < n; i++ )
    cin >> y, a[ i ] = abs( x[i] - y );

  static double p1, p2, p3, p4;
  for( i = 0; i < n; i++ ) {
    p1 += a[ i ];
    p2 += a[ i ] * a[ i ];
    p3 += a[ i ] * a[ i ] * a[ i ];
    p4  = p4 < a[ i ]?a[ i ] : p4;
  }
  p2 = sqrt( p2 );
  p3 = cbrt( p3 );
  cout  << fixed
        << p1 << endl
        << p2 << endl
        << p3 << endl
        << p4 << endl;

  return 0;
}

Measured memory_bytes: 3464
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int[] arr1 = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int x = arr1[0];
        int n = arr1[1];
        if (n == 0)
        {
            Console.WriteLine(x);
            return;
        }
        int[] arr = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int min = 1000;
        int minVal = 0;
        int[] allArr = new int[141];
        for (int i = -20; i <= 120; i++)
        {
            allArr[i + 20] = i;
        }
        var arrOther = arr.Concat(allArr).GroupBy(v => v).Where(v => v.Count() == 1);
        foreach (var element in arrOther)
        {
            if (Math.Abs(element.Key - x) < min)
            {
                minVal = element.Key;
                min = Math.Abs(element.Key - x);
            }
            else if (Math.Abs(element.Key - x) == min)
            {
                minVal = (element.Key < minVal) ? element.Key : minVal;
            }
        }
        Console.WriteLine(minVal);



    }
}

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

typedef long long ll;
const int N = 1000006;
int a[N];
bool prim[N];
int vstd[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	
	for(int i=0;i<n;i++){
		vstd[a[i]]++;
		if(vstd[a[i]] > 1)continue;
		for(int j=2*a[i];j<N;j+=a[i]){
			prim[j] = true;
		}
	}
	
	int ans = 0;
	for(int i=0;i<n;i++){
		if(!prim[a[i]] && vstd[a[i]] == 1)ans++;
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 9280
import java.util.Scanner;

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

		int intInput1 = scan.nextInt();
		int intInput2 = scan.nextInt();
		int intInput3 = scan.nextInt();
		int intSub = 0;
		if(intInput1 > intInput2){
			intSub = intInput1;
			intInput1 = intInput2;
			intInput2 = intSub;
			if(intInput2 > intInput3){
				intSub = intInput2;
				intInput2 = intInput3;
				intInput3 = intSub;
			}
		}else if(intInput2 > intInput3){
			intSub = intInput2;
			intInput2 = intInput3;
			intInput3 = intSub;
		}
		if(intInput1 > intInput2){
			intSub = intInput1;
			intInput1 = intInput2;
			intInput2 = intSub;
			if(intInput2 > intInput3){
				intSub = intInput2;
				intInput2 = intInput3;
				intInput3 =intInput2;
			}
		}
		System.out.println(intInput1 + " " + intInput2 + " " + intInput3);
	}
}

Measured memory_bytes: 17352
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			if(n==0) return ;
			int xs[] = new int[n], ys[] = new int[n];
			xs[0] = ys[0] = 1;
			for(int i=1; i<n; i++){
				int pre = in.nextInt();
				int dir = in.nextInt();
				xs[i] = xs[pre] + (dir==0?-1:dir==2?1:0);
				ys[i] = ys[pre] + (dir==1?-1:dir==3?1:0);
			}
			Arrays.sort(xs);
			Arrays.sort(ys);
			System.out.printf("%d %d\n", xs[n-1] - xs[0] + 1, ys[n-1] - ys[0] + 1);
		}
	}
}

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

using namespace std;

int main(){
    int n,S;
    while(cin >> n >> S, n){
        vector<int> r(n);
        for(int i = 0 ; i < n ; i++){
            cin >> r[i];
        }
        sort(r.begin(),r.end());
        int res = 0;
        for(int i = 0 ; i < n-1 ; i++){
	    res += n-(upper_bound(r.begin()+i+1,r.end(),S-r[i])-r.begin());
	}
	cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1252
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	vector<int> b(3);
	for (auto& v : b)
	{
		cin >> v;
	}
	ALL(sort, b);
	print(b[0]+b[1]);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define emp emplace

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 100010, MOD = 1000 * 1000 * 1000 + 7;
int pd[N][2];
vector<int> g[N];
int n;

int p[N];

void dfs(int u, int last)
{
	p[u] = last;
	for (int v : g[u])
	{
		if (v == last) continue;
		dfs(v, u);
	}
}

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

int solve(int u, int c)
{
	int& ret = pd[u][c];
	if (ret != -1)
		return ret;
	ret = 0;
	if (c == 0)
	{	
		int cur = 1;
		for (int v : g[u])
		{
			if (v == p[u]) continue;
			cur = mul(cur, solve(v, 0));
		}
		ret += cur;
		cur = 1;
		for (int v : g[u])
		{
			if (v == p[u]) continue;
			cur = mul(cur, solve(v, 1));
		}
		ret += cur;
		ret %= MOD;
	}
	else
	{
		int cur = 1;
		for (int v : g[u])
		{
			if (v == p[u]) continue;
			cur = mul(cur, solve(v, 0));
		}
		ret += cur;
	}
	return ret;
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n-1; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1, 0);
	memset(pd, -1, sizeof(pd));
	printf("%d\n", solve(1, 0));
	return 0;
}



Measured memory_bytes: 13824
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);
    static int nextInt () {return Integer.parseInt(sc.next());}

    public static void main(String[] args) {
        int N = nextInt();
        int M = nextInt();
        int[][] prefYears = new int[M][2];
        Map<Integer, List<Integer>> prefectureToYears = new HashMap<>();

        for (int i = 0; i < M; i++) {
            int p = nextInt();
            int y = nextInt();
            prefYears[i] = new int[] {p, y};
            if (!prefectureToYears.containsKey(p)) {
                prefectureToYears.put(p, new ArrayList<>());
            }
            List<Integer> ys = prefectureToYears.get(p);
            ys.add(y);
            prefectureToYears.put(p, ys);
        }

        for (Integer p : prefectureToYears.keySet()) {
            List<Integer> ys = prefectureToYears.get(p);
            Collections.sort(ys);
        }

        // 二重for文なので一見NxMに見えるが、高々M個までしかいかない。
        // なぜならこのfor文が舐める数は市の数に一致し、それはMなので。
        Map<Integer, Integer> yearToPosi = new HashMap<>();
        for (List<Integer> years : prefectureToYears.values()) {
            for (int i = 0; i < years.size(); i++) {
                yearToPosi.put(years.get(i), i+1);
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < M; i++) {
            int p = prefYears[i][0];
            int y = prefYears[i][1];
            sb.append(String.format("%06d%06d", p, yearToPosi.get(y)) );
            sb.append(System.getProperty("line.separator"));
        }
        System.out.println(sb);
    }
}


Measured memory_bytes: 123460
x, k, d = map(int, input().split())

cur = abs(x)  # 座標を正にしてしまいます
rem = k  # 残りの移動回数です

cnt = min(cur // d, k)  # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt

# 0 % 2 = 0なので、残り回数の場合分けをする必要はないのですが、一応
if rem > 0:
    if rem % 2 == 1:
        cur = cur - d

ans = abs(cur)
print(ans)

Measured memory_bytes: 9044
#include <iostream>

using namespace std;

int main(){
	int N; cin >> N;
	int contador = 0;
	char oracion[N+1];
	for(int i = 0; i < N; i++){
		cin >> oracion[i];
	}
	for(int i = 0; i < N-2; i++){
		if(oracion[i] == 'A' && oracion[i+1] == 'B' && oracion[i+2] == 'C') contador++;
	}
	cout << contador;
	return 0;
}

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

#define ASC(a) a.begin(), a.end()		// 昇順ソート 例：sort(ASC(a));
#define DESC(a) a.rbegin(), a.rend()	// 降順ソート 例:sort(DESC(a));
#define rep(i, n) for(int i = 0; i < n; ++i)
//#define rep(i, a, n) for(int i = a; i < n; ++i)
#define Rep(i, n) for(int i = 1; i < n; ++i)
#define In(a) rep(i, n) cin>>a[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;
#define only_unique(vec) vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
#define souwa(vec) accumulate(ASC(vec), 0)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vii;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };


// ────────────────────────────────────────────────────
int  main() {
	while (1) {
		int t; cin >> t;
		if (!t) break;

		int n; cin >> n;
		vii h(n);
		int def = 0;
		rep(i, n) {
			cin >> h[i].first >> h[i].second;
			def += h[i].second - h[i].first;
		}
		if (t <= def) cout << "OK" << endl;
		else cout << t - def << endl;
	}
}



Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    string s,t;

    cin >> s >> t;

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

    if(s < t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = input()
ac = Counter(map(int, input().split()))

w, h = 0, 0
for i in sorted(ac.keys(), reverse=True):
    if ac[i] == 1:
        continue
    if w:
        h = i
        break
    if ac[i] >= 4:
        w = h = i
        break
    w = i

print(w * h)


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

li n;
li a[5];

inline li divup(li x, li y) {
	return (x + y - 1) / y;
}

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

	li mi = 1ll << 50;
	rep(i, 5) {
		mi = min(mi, a[i]);
	}
	li group_num = divup(n, mi);
	cout << group_num + 4 << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        Pattern space = Pattern.compile(" ");
        int n = Integer.parseInt(stdin.readLine());
        int[] a = new int[n - 1];
        int[] b = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            int[] line = space.splitAsStream(stdin.readLine()).mapToInt(Integer::parseInt).toArray();
            a[i] = line[0] - 1;
            b[i] = line[1] - 1;
        }

        List< List<Integer>> nexts = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            nexts.add(new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            nexts.get(a[i]).add(b[i]);
            nexts.get(b[i]).add(a[i]);
        }

        Map<Integer, Map<Integer, Integer>> colors = new HashMap<>();
        int[] used = new int[n];
        int[] parent = new int[n];
        Arrays.fill(parent, -1);
        Deque<Integer> stack = new ArrayDeque<>();
        stack.add(0);
        while (!stack.isEmpty()) {
            int current = stack.removeFirst();
            int color = 1;
            for (int next : nexts.get(current)) {
                if (parent[current] == next) continue;

                if (used[current] == color) color++;
                used[next] = color;
                parent[next] = current;
                stack.addLast(next);

                int x = Math.min(current, next);
                int y = Math.max(current, next);
                colors.computeIfAbsent(x, unused -> new HashMap<>()).put(y, color);
                color++;
            }
        }

        int max = 0;
        for (int i = 0; i < n - 1; i++) {
            max = Math.max(max, colors.get(a[i]).get(b[i]));
        }

        stdout.println(max);
        for (int i = 0; i < n - 1; i++) {
            stdout.println(colors.get(a[i]).get(b[i]));
        }
    }


    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 76612
#include<bits/stdc++.h>
using namespace std;
#define sz 100005
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

int main()
{
    faster_io
    int n,x,y;
    int mx1,mx2;

    mx1 = mx2 = -1;

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

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

    for(int i=0;i<n;i++){
        if(a[i]==mx1) cout<<mx2<<endl;
        else cout<<mx1<<endl;
    }



    return 0;
}





Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
// #define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

ll N;
std::unordered_set<ll> paper;

int main(){
	FAST;
	
	cin >> N;
	rep(i,N) {
		ll r;
		cin >> r;
		auto it = paper.find(r);
		if (it == paper.end()) {
			paper.insert(r);
		}
		else {
			paper.erase(it);
		}
	}

	cout << paper.size() << LF;

	return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

int main(){
  ll a,b;
  cin >> a >> b;
  //どちらか0なら, 絶対正
  if(a<=0 && 0<=b){
    cout << "Zero" << endl;
    return 0;
    }
  if(0 < a){
    cout << "Positive" << endl;
  }else if(b < 0){
    if((b-a)%2==0) cout << "Negative" << endl;
    else cout << "Positive" << endl;
  }
}

Measured memory_bytes: 256