akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(N, M);
  map<int, vector<int>> join, del;
  FOR(i, M) {
    GI2(a, b);
    join[a - 1].push_back(i);
    del[b - 1].push_back(i);
  }
  unordered_set<int> now;
  for (int i : join[0]) {
    now.insert(i);
  }
  int ans = 0;
  FOR(i, N - 1) {
    bool f = 0;
    for (int j : del[i + 1]) {
      if (now.count(j))
        f = 1;
    }
    if (f) {
      ans++;
      now.clear();
    }
    for (int j : join[i + 1]) {
      now.insert(j);
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 22908
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        set<char> st;
        rep(i, 0, N) {
                char x;
                cin >> x;
                st.insert(x);
        }
        if (len(st) == 3) {
                cout << "Three" << endl;
        } else {
                cout << "Four" << endl;
        }
}

Measured memory_bytes: 3560
#include <stdio.h>
#include <math.h>


double Square(double a,double b,double c){
      double s=(a+b+c)/2;
      double S=sqrt(s*(s-a)*(s-b)*(s-c));
      return S;
}

int main()
{
  double x1,y1,x2,y2,x3,y3,xp,yp;

  while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF)
    {
      double a=sqrt(pow(x1-x2,2)+pow(y1-y2,2));
      double b=sqrt(pow(x1-x3,2)+pow(y1-y3,2));
      double c=sqrt(pow(x3-x2,2)+pow(y3-y2,2));
      double S1=Square(a,b,c);

      double x=sqrt(pow(x1-xp,2)+pow(y1-yp,2));
      double y=sqrt(pow(x2-xp,2)+pow(y2-yp,2));
      double z=sqrt(pow(x3-xp,2)+pow(y3-yp,2));
      double S2=Square(x,y,a)+Square(x,z,b)+Square(y,z,c);
      if ((float)S1==(float)S2){
        printf("YES\n");
      }else{
        printf("NO\n");
      }

    }
  return 0;
}

Measured memory_bytes: 612
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()
    children = [[] for _ in range(n)]
    for _ in range(n):
        ikc = LI()
        id = ikc[0]
        # k = ikc[1]
        c = ikc[2:]
        children[id] = c

    parent = [-1]*n
    for i, e in enumerate(children):
        for j in e:
            parent[j] = i

    depth = [-1]*n
    root = parent.index(-1)
    depth[root] = 0
    que = collections.deque()
    que.append(root)
    while que:
        c = que.popleft()
        for i in children[c]:
            if depth[i]==-1:
                que.append(i)
                depth[i] = depth[c] + 1

    node_type = ['']*n
    for i in range(n):
        if parent[i]==-1:
            node_type[i] = 'root'
        elif not children[i]:
            node_type[i] = 'leaf'
        else:
            node_type[i] = 'internal node'

    for i in range(n):
        print('node {0}: parent = {1}, depth = {2}, {3}, {4}'.format(i, parent[i], depth[i], node_type[i], children[i]))

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 23900
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define N 200001
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,a[N];
bool check(int m)
{
	// cerr<<m<<endl;
	static map<int,int> s;
	s.clear();
	for(int i=2;i<=n;++i)
	{
		if(a[i-1]>=a[i])
		{
			while(!s.empty() && s.rbegin()->first>a[i])
				s.erase(--s.end());
			for(int j=a[i];~j;--j)
			{
				if(!j)return 0;
				++s[j];
				if(s[j]==m)s.erase(j);
				else break;
			}
		}
	}
	return 1;
}
int main()
{
	re(n);
	bool ok=1;
	for(int i=1;i<=n;++i)re(a[i]),ok&=a[i-1]<a[i];
	if(ok)
	{
		puts("1");
		return 0;
	}
	int l=2,r=n;
	while(l < r)
	{
		int m=l+r>>1;
		if(check(m))r=m;
		else l=m+1;
	}
	printf("%d\n",l);
}
/*
aaaaa aaab aab
*/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MAXN = 2010;

int n, k;

deque< pair<int, pii> > add, rem;

void AddOp(int x1, int x2, int y1, int y2){
  //cout << ' ' << x1 << ' ' << x2 << " : " << y1 << ' ' << y2 << endl;
  add.pb(mp(x1, mp(y1, y2)));
  rem.pb(mp(x2 + 1, mp(y1, y2)));
}

int MaxIntersect(){
  sort(all(add));
  sort(all(rem));

  int ans = 0;
  array<int, MAXN> bal;
  fill(all(bal), 0);

  for(int i = 0;i < MAXN;++i){
    while(!add.empty() && add[0].fi == i){
      auto& e = add[0];
      ++bal[e.se.fi], --bal[e.se.se + 1];
      add.pop_front();
    }

    while(!rem.empty() && rem[0].fi == i){
      auto& e = rem[0];
      --bal[e.se.fi], ++bal[e.se.se + 1];
      rem.pop_front();
    }

    int tot = 0;
    for(int j = 0;j < MAXN;++j){
      tot += bal[j];
      relaxMax(ans, tot);
    }
  }

  return ans;
}

pii Intersect(const pii& a, const pii& b){
  return mp(max(a.fi, b.fi), min(a.se, b.se));
}

void WantBlack(int x, int y){
  x %= (2 * k), y %= (2 * k);

  int sx = x - k + 1,
      sy = y - k + 1;

  for(int dx = -2;dx <= 2;++dx)
    for(int dy = -2;dy <= 2;++dy){
      if((dx + dy) & 1) continue;
      int lx = sx + dx * k, ux = lx + k - 1;
      int ly = sy + dy * k, uy = ly + k - 1;

      auto lrx = Intersect(mp(0, 2 * k - 1), mp(lx, ux));
      auto lry = Intersect(mp(0, 2 * k - 1), mp(ly, uy));
      if(lrx.fi <= lrx.se && lry.fi <= lry.se)
        AddOp(lrx.fi, lrx.se,
              lry.fi, lry.se);
    }
}

int main(){
  scanf("%d%d", &n, &k);

  int x, y;
  char col[10];
  for(int i = 0;i < n;++i){
    scanf("%d%d%s", &x, &y, &col[0]);
    if(col[0] == 'W') x += k;
    WantBlack(x, y);
  }

  cout << MaxIntersect() << '\n';

  return 0;
}


Measured memory_bytes: 11136
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
  public static void main(String[] args) throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int a = Integer.parseInt(line[0]);
    int b = Integer.parseInt(line[1]);
    int c = Integer.parseInt(line[2]);
    String result;
    if(a<b && b<c){
      result = "Yes";
    }else{
      result = "No";
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 24084
N, M = map(int, input().split())
py = []
d = {}
for i in range(M):
    p, y = map(int, input().split())
    py.append([p, y])
    if p not in d:
        d[p] = [y]
    else:
        d[p].append(y)
for key in d.keys():
    d[key].sort()
from bisect import bisect_left
for i in range(M):
    p, y = py[i]
    a = bisect_left(d[p], y)
    ans = '0' * (6 - len(str(p))) + str(p)
    ans += '0' * (6 - len(str(a + 1))) + str(a + 1)
    print(ans)

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int32> a(3);
    int32 sum = 0;
    REP(i,3){
        cin >> a[i];
        sum += a[i];
    }
    ANS(sum - *max_element(ALL(a)));
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory> 
#include <string> 
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>

#define REP(i,n) for(i=0; i < (n); i++)
#define REPONE(i, n) for(i=1; i <= (n); i++)
#define LOOP(n) for(int loopCount=1; loopCount <= (n); loopCount++)
#define ITER(c) __typeof((c).begin())
#define EACH(c,it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define SZ(c) ((int) (c).size())
#define ALL(c) c.begin(), c.end()
#define SUM(c) accumulate(ALL(c), 0)
#define EXIST(c,v) (find(ALL(c), (v)) != (c).end())
#define PB push_back
#define MP make_pair
#define fs first
#define sc second

using namespace std;
static const double EPS = 1e-9;
static const double PI = 3.141592653589793238462643383279;
typedef long long ll;

pair<int, int> toP(char c){
    int x = c - 'A';
    return MP(x/3, x%3);
}

bool isOut(int x, int y){
    return !(0<=x && x<=2 && 0<=y && y<=2);
}

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

int main(){
    double dp[20][3][3];
    int i, j, k, l, n, x, y;
    char c1, c2, c3;
    pair<int, int> st, tar, obs;

    while(scanf("%d\n",&n)){
        if(!n) break;
        scanf("%c %c %c\n",&c1, &c2, &c3);
        st = toP(c1);
        tar = toP(c2);
        obs = toP(c3);
        REP(k,20)REP(i,3)REP(j,3) dp[k][i][j] = 0.0;
        dp[0][st.fs][st.sc] = 1.0;

        REP(k,n)REP(i,3)REP(j,3){
            REP(l,4){
                x = i + dx[l];
                y = j + dy[l];
                if(isOut(x,y) || MP(x,y)==obs){
                    dp[k+1][i][j] += 0.25*dp[k][i][j];
                }
                else{
                    dp[k+1][x][y] += 0.25*dp[k][i][j];
                }
            }
        }
        printf("%.10f\n", dp[n][tar.fs][tar.sc]);
    }

    return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
int main(){
    for(;;){
        int n,k;
        scanf("%d%d",&n,&k);
        if(n==0&&k==0)break;
        vector<int> ns(n);
        for(int i=0;i<n;i++)scanf("%d",&ns[i]);
        set<int> ints;
        sort(ns.begin(),ns.end());
        do{
            int sum=0;
            for(int i=0;i<k;i++){
                if(ns[i]<10) sum=sum*10+ns[i];
                else sum=sum*100+ns[i];
            }
            ints.insert(sum);
        }while(next_permutation(ns.begin(),ns.end()));
        printf("%d\n",ints.size());
    }
}

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


void solve()
{
  string s,t;
  cin>>s>>t;
  int l1=s.length();
  int l2=t.length();
  int count=0;
  for(int i=0;i<s.length();i++)
  {  
    if(s[i]!=t[i])
      count++;
    
      
  
  }
  cout<<count;
  return;
}


int main()
{
solve();
}

Measured memory_bytes: 3852
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

// 入力
int N;
long long W, weight[110], value[110];

// DPテーブル
long long dp[110][100100] = { 0 };

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            // i 番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            // i 番目の品物を選ばない場合
            chmax(dp[i + 1][sum_w], dp[i][sum_w]);
        }
    }

    // 最適値の出力
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<Kanna;I_Love++)cout<<Hashimoto[I_Love]<<(I_Love==Kanna-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<Kanna;I_Love++)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int n,m;
string s[22],sav[22];
pair<string,int> fs[22];
string cs[22];

bool check(){
	vector<string>ss;
	FOR(j,0,m){
		string sss="";
		FOR(i,0,n){
			sss.push_back(s[i][j]);
		}
		ss.push_back(sss);
	}
	vector<pair<string,int> >fs;
	FOR(i,0,m){
		fs.push_back({ss[i],i});
	}
	FOR(i,0,m)SORT(fs[i].first);
	SORT(fs);
	int cnt=0;
	bool f=m%2;
	FOR(i,0,m){
		if(i<m-1&&fs[i].first==fs[i+1].first){
			cs[cnt]=ss[fs[i].second];
			cs[m-1-cnt]=ss[fs[i+1].second];
			cnt++;
			i++;
		}
		else {
			if(f){
				cs[m/2]=ss[fs[i].second];
				f=0;
			}
			else return 0;
		}
	}
	FOR(i,0,m){
		string hah=cs[m-1-i];
		REV(hah);
		if(cs[i]!=hah)return 0;
	}
	
	return 1;
	
}

int I_Love_Hashimoto_Kanna() {
  fastio;
  cin>>n>>m;
  FOR(i,0,n){
  	cin>>sav[i];
  	fs[i].first=sav[i];
  	SORT(fs[i].first);
  	fs[i].second=i;
	}
	sort(fs,fs+n);
	bool f=(n%2);
	int cnt=0;
	FOR(i,0,n){
		if(fs[i].first==fs[i+1].first){
			s[cnt]=sav[fs[i].second];
			s[n-1-cnt]=sav[fs[i+1].second];
			cnt+=1;
			i++;
		}
		else {
			if(f){
				f=0;
				s[n/2]=sav[fs[i].second];
			}
			else {
				cout<<"NO\n";
				return 0;
			}
		}
	}
	if(check())cout<<"YES\n";
	else cout<<"NO\n";
	
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a;

int main()
{
	ll n,m;
	string ans="No";
	ll all=0;
	
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		ll tmp;
		cin >> tmp;
		a.push_back(tmp);
		all += tmp;
	}

	sort(a.begin(), a.end(), std::greater<int>());
	
	if (a[m-1] >= (all+(4 * m-1)) / (4 * m)) {
		ans = "Yes";
	}
	else {
		ans = "No";
	}

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


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

typedef long long ll;
typedef pair<int,int> P;

const int INF=1e9;
const int MOD=1e9+7;

vector<int> g[200010];
int ind[200010]={};
ll dp[200010]={};

int main(){
    int N; cin >> N;
    int c[N];
    for(int i=0;i<N;i++){
        cin >> c[i];
    }
    
    for(int i=N-1;i>=0;i--){
        g[c[i]].push_back(i);
    }
    
    dp[0]=1;
    for(int i=0;i<N;i++){
        dp[i+1]+=dp[i];
        dp[i+1]%=MOD;
        int j=g[c[i]].back();
        g[c[i]].pop_back();
        if(g[c[i]].empty()) continue;
        int k=g[c[i]].back();
        //cout << j << " " << k << endl;
        if(k==(j+1)) continue;
        dp[k]+=dp[j];
        dp[k]%=MOD;
    }
    cout << dp[N-1]%MOD << endl;
}

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

int prime[1000001];

int main()
{
	for (int i = 2; i <= 1000000; i++){
		prime[i] = 1;
	}
	for (int i = 2; i * i <= 1000000; i++){
		for (int j = i * i; j <= 1000000; j += i){
			prime[j] = 0;
		}
	}
	for (int i = 1; i <= 1000000; i++){
		prime[i] += prime[i - 1];
	}
	
	int n;
	while (scanf("%d", &n), n){
		int res = 0;
		for (int i = 0; i < n; i++){
			int p, m;
			scanf("%d %d", &p, &m);
			int x = prime[min(p + m, 1000000)] - prime[max(p - m - 1, 0)];
			res += x ? x - 1 : -1;
		}
		printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 5092
N,W = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(N)]

dp = [{} for i in range(N+1)]
dp[0][0] = 0
for i,(w,v) in enumerate(wv):
    for w0,v0 in dp[i].items():
        if w0 in dp[i+1]:
            dp[i+1][w0] = max(dp[i+1][w0], v0)
        else:
            dp[i+1][w0] = v0
        if w0+w > W: continue
        if w0+w in dp[i+1]:
            dp[i+1][w0+w] = max(dp[i+1][w0+w], v0+v)
        else:
            dp[i+1][w0+w] = v0+v
print(max(dp[-1].values()))

Measured memory_bytes: 658328
from collections import deque
s = input()
q = int(input())
reverse_now = 0
first = deque([])
latter = ""
for i in range(q):
    k = list(input().split())
    if k[0] == "1":
        reverse_now = 1 - reverse_now
    else:
        f,c = k[1], k[2]
        if f == "1" and reverse_now == 0:
            first.appendleft(c)
        if f == "1" and reverse_now == 1:
            latter += c
        if f == "2" and reverse_now == 0:
            latter +=  c
        if f == "2" and reverse_now == 1:
            first.appendleft(c)
first = "".join(first)
if reverse_now == 1:
    ans = list(first + s + latter)
    ans.reverse()
    ans = "".join(ans)
else:
    ans = first + s + latter
print(ans)

Measured memory_bytes: 6580
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  string ans("Yes");
  cin >> a >> b >> c;
  
  if(a == b && b == c && c == a || a != b && b != c && c != a){
    ans = "No";
  }
  
  cout << ans << endl;
}

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

#define int long long
//#define uint __int128_t

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N;
int a[404];
int s[404];
int dp[404][404];

int solve(int l,int r){
    if(l==r)return 0;
    if(dp[l][r]!=INF)return dp[l][r];
    int res=INF;
    rep(i,l,r){
        chmin(res,solve(l,i)+s[i+1]-s[l]+solve(i+1,r)+s[r+1]-s[i+1]);
    }
    dp[l][r]=res;
    return res;
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>N;
    rep(i,0,N){
        cin>>a[i];
        s[i+1]=s[i]+a[i];
    }
    rep(i,0,N)rep(j,0,N)dp[i][j]=INF;
    cout<<solve(0,N-1)<<endl;














































































    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<double> a(n);
    double num=0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        num+=a[i];
    }
    num/=n;
    //cout << num << endl;

    int id;
    double nmax=1e9;
    for(int i=0; i<n; i++){
        if(abs(num-a[i])<nmax){
            nmax=abs(num-a[i]);
            id=i;
        }
    }
    cout << id << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    for (int i=0; i<a; i++){
        if(!isdigit(s[i])) {
            out("No");
            return 0;
        }
    }
    if(s.at(a) != '-'){
        out("No");
        return 0;
    }
    for (int i=a+1; i<b+a; i++){
        if(!isdigit(s[i])) {
            out("No");
            return 0;
        }
    }
    out("Yes");
    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        int a,b,c;
		Scanner sc=new Scanner(System.in);
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		if(a<b && b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
    }
}


Measured memory_bytes: 26192
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef double d;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c;
    cin>>a>>b>>c;

    ll x = a-b;
    c -=x;
    if(c<0){c=0;}
    cout<<c;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int max = 0;
  int sm = 0;
  for(int i = 0; N > i; i++){
    int tmp;
    cin >> tmp;
    if(max < tmp) max = tmp;
    sm += tmp;
  }
  cout << sm - max / 2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int A = scanner.nextInt();
        int B = scanner.nextInt();

        if(B%A == 0){
            System.out.println(A + B);
        }else {
            System.out.println(B - A);
        }
    }
}


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

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll>a(n);
    rep(i,n){
        int at;
        cin>>at;
        a[i]=at-1;
    }
    ll now=0;
    set<ll>s;
    ll before=0;
    for(ll i=0;i<k;i++){
       now=a[now];
       before+=1;
       if(s.count(a[now]))break;
       s.insert(now);
    }
    //nowがループポイント
    ll rp=now;
    ll roop=0;
    for(int i=0;i<n;i++){
        now=a[now];
        roop+=1;
        if(now==rp)break;
    }
    ll ans=0;
    if(k<before){
        for(int i=0;i<k;i++){
           ans=a[ans];
        }
        ans+=1;
        cout<<ans<<endl;
    }
    else{
      k-=before;
      k=k%roop;
      ans=rp;
      for(int i=0;i<k;i++){
         ans=a[ans];
      }
      ans+=1;
      cout<<ans<<endl;
    }
}

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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 1 ; i <= a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second
#define INF 1000000000

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

long long binpow(long long a, long long b) {
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}


void solve()
{
	int x, y;
	cin >> x >> y;

	if ( y % 2 == 0 && (4 * x >= y) && (y >= 2 * x) )
	{
		cout << "Yes\n";
		return;
	}

	cout << "No\n";
}



int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


	int t = 1;
	//cin >> t;


	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int l[205];
int main()
{
	int n,i,ans=0;
	cin>>n;
	for(i=1;i<=2*n;i++)
		cin>>l[i];
	sort(l+1,l+2*n+1);
	for(i=1;i<=2*n;i+=2)
		ans+=l[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
i = 1
while N // (10**i) > 0: 
    i += 1
 
ans = 0    
if i % 2 == 0:
    for j in range(i//2):
        ans += 9*(10**(2*j))
else:
    for j in range(i//2):
        ans += 9*(10**(2*j))
    ans += (N-10**(2*(i//2))+1)

print(ans)

Measured memory_bytes: 3060
//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
const ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 500010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}

bool ok(int I, int J, vector<vector<char>> C, int h, int w, int k){
  int cnt = 0;
  rep(i, h)rep(j, w){
    if((I>>i)&1 || (J>>j)&1) continue;
    if(C[i][j] == '#') cnt++;
  }
  return cnt == k;
}

void solve(){
  int K;
  cin >> K;
  int ans = 0;
  for(int i = 1; i <= K; i++){
    for(int j = 1; j <= K; j++){
      for(int k = 1; k <= K; k++){
        ans += gcd(gcd(i, j), k);
      }
    }
  }
  cout << ans << endl;
}


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


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	for(int i = 0; i < 8; i++){
			int res = n / 1000;
			for(int j = 0; j < 3; j++){
					if((i >> j) % 2 == 0){
							res += n / int(pow(10, 2-j)) % 10;
					}else{
							res -= n / int(pow(10, 2-j)) % 10;
					}
			}
			if(res == 7){
					for(int j = 0; j < 4; j++){
							cout << (n / int(pow(10, 3-j))) % 10;
							if(j != 3){
									if((i >> j) % 2 == 0)cout << "+";
									else cout << "-";
							}
					}
					cout << "=7" << endl;
					return 0;
			}
	}
	return 0;
}


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

    int max, min;

    void run(){
	while(sc.hasNext()){
	    max = sc.nextInt();
	    min = sc.nextInt();
	    System.out.println(max-min);
	}
    }
}

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

int main() {
  int N, l, r;
  cin >> N;
  
  int count = 0;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    count += r - l +1;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
function cal(mon,num,i,A,N)
#for i in 1:N
#println(mon)
  if i == N
    mon += num*A[i]
    num = 0
  #elseif A[i] == maximum(A[i:N])
  #   mon += num*A[i]
  #   num = 0
  #   println(mon)
  #   exit()
  else
#    if i == 1
#      num += div(mon,A[i])
#      mon -= num*A[i]
#else
    if A[i] > A[i+1]
      mon += num*A[i]
      num = 0
    elseif A[i] < A[i+1]
      num += div(mon,A[i])
      mon -= div(mon,A[i])*A[i]
    end
  end
return num,mon
end

parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N = parseInt(readline())
A = parseMap(split(readline()))
mon=1000 ; num=0
#if A[1] == maximum(A)
#  println(1000)
#  exit()
#end
for i in 1:N
  num,mon=cal(mon,num,i,A,N)
end
println(mon)
end
main()


Measured memory_bytes: 164716
#include <bits/stdc++.h>
#include <map>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    map<int,int> mp;
    int Count = 0;
    for(int i : A){
        if(mp.count(i)) mp.at(i)++;
        else mp[i] = 1;
    }
    for(auto i : mp){
        int first = i.first;
        int second = i.second;
        if(second < first) Count += second;
        else Count += second - first;
    }
    cout << Count << endl;
}

Measured memory_bytes: 5120
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST

warshallFloyd1 :: V.Vector [(Int, Int64)] -> UArray (Int, Int) Int64
warshallFloyd1 !graph = runSTUArray $ do
  let n = V.length graph
  !arr <- newArray ((0,0),(n-1,n-1)) (10^9+1)
  forM_ [0..n-1] $ \a -> do
    forM_ (graph V.! a) $ \(b,c) -> do
      writeArray arr (a,b) c
      writeArray arr (b,a) c
  forM_ [0..n-1] $ \a -> do
    writeArray arr (a,a) 0
  forM_ [0..n-1] $ \k -> do
    forM_ [0..n-1] $ \i -> do
      forM_ [0..n-1] $ \j -> do
        a_ij <- readArray arr (i,j)
        a_ik <- readArray arr (i,k)
        a_kj <- readArray arr (k,j)
        writeArray arr (i,j) $! min a_ij (a_ik + a_kj)
  return arr

warshallFloyd2 :: Int -> Int -> UArray (Int, Int) Int64 -> UArray (Int, Int) Int
warshallFloyd2 !n !l !graph = runSTUArray $ do
  !arr <- newArray ((0,0),(n-1,n-1)) (10^9+1)
  forM_ [0..n-1] $ \a -> do
    forM_ [0..n-1] $ \b -> do
      let v = graph ! (a,b)
      when (v <= fromIntegral l) $ do
        writeArray arr (a,b) 1
  forM_ [0..n-1] $ \a -> do
    writeArray arr (a,a) 0
  forM_ [0..n-1] $ \k -> do
    forM_ [0..n-1] $ \i -> do
      forM_ [0..n-1] $ \j -> do
        a_ij <- readArray arr (i,j)
        a_ik <- readArray arr (i,k)
        a_kj <- readArray arr (k,j)
        writeArray arr (i,j) $! min a_ij (a_ik + a_kj)
  return arr

main = do
  [n,m,l] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM m $ do
    [a,b,c] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (a-1,b-1,fromIntegral c)
  let graph :: V.Vector [(Int, Int64)]
      graph = V.create $ do
        g <- VM.replicate n []
        U.forM_ edges $ \(a,b,c) -> do
          VM.modify g ((b,c) :) a
        return g
  let w1 = warshallFloyd1 graph
      w2 = warshallFloyd2 n l w1
  q <- readLn
  queries <- U.replicateM q $ do
    [s,t] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (s,t)
  U.forM_ queries $ \(s,t) -> do
    let d = w2 ! (s-1,t-1)
    print $ if d > 10^9 then -1 else d - 1


Measured memory_bytes: 8444
from itertools import combinations
n,m,x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ans = 10**9
for i in range(1,n+1):
  for j in combinations(ca, i):
    s = [0]*(m+1)
    for k in j:
      for a in range(m+1):
        s[a] += k[a]
    if min(s[1:]) >= x:
      ans = min(ans, s[0])
if ans == 10**9:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 9204
#include <stdio.h>

#define INF 1010101010

int N, M, L;
int Q;
int s[512 * 512], t[512 * 512];

int kyori[512][512];

int kaisu[512][512];

int main(void) {
	int i, j, k;
	if (scanf("%d%d%d", &N, &M, &L) != 3) return 1;
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= N; j++) {
			kyori[i][j] = INF;
			kaisu[i][j] = INF;
		}
		kyori[i][i] = 0;
		kaisu[i][i] = 0;
	}
	for (i = 0; i < M; i++) {
		int A, B, C;
		if (scanf("%d%d%d", &A, &B, &C) != 3) return 1;
		kyori[A][B] = kyori[B][A] = C;
	}
	if (scanf("%d", &Q) != 1) return 1;
	for (i = 0; i < Q; i++) {
		if (scanf("%d%d", &s[i], &t[i]) != 2) return 1;
	}

	for (k = 1; k <= N; k++) {
		for (i = 1; i <= N; i++) {
			for (j = 1; j <= N; j++) {
				if (kyori[i][j] > kyori[i][k] + kyori[k][j]) {
					kyori[i][j] = kyori[i][k] + kyori[k][j];
				}
			}
		}
	}

	for (i = 1; i <= N; i++) {
		for (j = 1; j <= N; j++) {
			if (i != j && kyori[i][j] <= L) kaisu[i][j] = 1;
		}
	}

	for (k = 1; k <= N; k++) {
		for (i = 1; i <= N; i++) {
			for (j = 1; j <= N; j++) {
				if (kaisu[i][j] > kaisu[i][k] + kaisu[k][j]) {
					kaisu[i][j] = kaisu[i][k] + kaisu[k][j];
				}
			}
		}
	}

	for (i = 0; i < Q; i++) {
		printf("%d\n", kaisu[s[i]][t[i]] >= INF ? -1 : kaisu[s[i]][t[i]] - 1);
	}

	return 0;
}


Measured memory_bytes: 3456
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import qualified Data.IntSet as IS
import qualified Data.Vector.Unboxed as V
main=mapM_(print.solve).analyze.map(map (fst.fromJust.B.readInt).B.words).B.lines=<<B.getContents
analyze ([n,m]:cs)=(n,m,as):analyze bs where (as,bs)=splitAt n cs
analyze _=[]
solve::(Int,Int,[[Int]])->Int
solve (n,m,as)=fst$foldr f (n,(as,IS.empty)) [2..m] where
  f _ (r,(as,s)) = (min r k,(map (dropWhile (flip IS.member t)) as,t))where
    c=V.accum (+)(V.replicate (m+1) 0)$map (\a->(head a,1)) as
    j=V.maxIndex c
    k=c V.! j
    t=IS.insert j s

Measured memory_bytes: 10364
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            out.println(in.next().indexOf("AC") != -1 ? "Yes" : "No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 22996
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // long longの1次元の型に vll という別名をつける
using vvll = vector<vll>; // long longの2次元の型に vvll という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pll という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------


int main() {
   ll ans=0,n;
   cin>>n;
   
   rep2(a,1,1000+1){
       rep2(b,a,1000000){
           if(n-a*b>0){
               
               if(a==b)ans++;
               else ans+=2;
           }
       }
   }
   cout<<ans<<endl;
    
}



Measured memory_bytes: 3636
import numpy as np
n, m = (int(i) for i in input().split())
a = [0]*n
b = [0]*n
for j in range(n):
    a[j], b[j] = (int(i) for i in input().split())
price = 0
for i in np.argsort(a):
    num = min(m, b[i])
    price = price + num * a[i]
    m = m - num
    if m == 0:
        break
print(price)


Measured memory_bytes: 21480
#include<stdio.h>
int main(void)
{	int i,sum=0,n,v[20]={},c[20]={};
	scanf("%d",&n);
	for(i=0;i<n;i++){scanf("%d",&v[i]);}
	for(i=0;i<n;i++){scanf("%d",&c[i]);}
	for(i=0;i<n;i++)
	{	if(v[i]>c[i])
			sum+=v[i]-c[i];
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 128
//
//  main.cpp
//  A
//
//  Created by 黄道煜 on 2018/7/21.
//  Copyright © 2018年 黄道煜. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

int a[5];

int main()
{
    scanf("%d%d%d", &a[1], &a[2], &a[3]);
    sort(a+1, a+4);
    printf("%d\n", a[3]-a[1]);
}


Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,c=parseMap(split(readline()))
    if c-(a+b)>=0 && 4*a*b<(c-(a+b))^2
        println("Yes")
    else
        println("No")
    end
end
main()

Measured memory_bytes: 165952
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const ull MOD = 998244353;
const int MSIZE = 100007;
const double Pi = 3.14159265358979323146;

int main(){
  int a, b; cin >> a >> b;
  cout << a * b << endl;

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define eb emplace_back
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

const int MAXN = 200055;
const int MAXM = 200055;

struct SEG {
	SEG() { init(); }
	ll dmx[MAXN*4], du[MAXN*4];

	void init() { fill(dmx, dmx+MAXN*4, -INFLL); }
	void cal(int i) {
		dmx[i] = max(dmx[i<<1] + du[i<<1], dmx[i<<1|1] + du[i<<1|1]);
		if(dmx[i] < -INFLL) dmx[i] = -INFLL;
	}
	void upd(int i, int s, int e, int p, int q, int r) {
		if(q < p || e < p || q < s) return;
		if(p <= s && e <= q) {
			du[i] += r;
			return;
		}
		int m = (s+e) >> 1;
		upd(i<<1, s, m, p, q, r);
		upd(i<<1|1, m+1, e, p, q, r);
		cal(i);
	}
	void upd(int i, int s, int e, int x, ll r) {
		if(s == e) {
			dmx[i] = r;
			return;
		}
		int m = (s+e) >> 1;
		if(x <= m) upd(i<<1, s, m, x, r);
		else upd(i<<1|1, m+1, e, x, r);
		cal(i);
	}
	ll get(int i, int s, int e, int p, int q) {
		if(q < p || e < p || q < s) return -INFLL;
		if(p <= s && e <= q) return max(dmx[i] + du[i], -INFLL);
		int m = (s+e) >> 1;
		return max(max(get(i<<1, s, m, p, q), get(i<<1|1, m+1, e, p, q)) + du[i], -INFLL);
	}
} seg;

vector<int> EVI[MAXN], EVO[MAXN];
ll dp[MAXN];

int A[MAXM], B[MAXM], C[MAXM];

ll Sum;
int N, M;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> M;
	for(int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i] >> C[i];
		EVI[A[i]].eb(i);
		EVO[B[i]].eb(i);
	}

	for(int i = 1; i <= N; i++) {
		for(int v : EVI[i]) {
			Sum += C[v];
			seg.upd(1, 1, N, A[v], B[v], -C[v]);
		}
		dp[i] = max(0ll, seg.get(1, 1, N, 1, i)) + Sum;
		seg.upd(1, 1, N, i, dp[i]);
		for(int v : EVO[i]) {
			Sum -= C[v];
			seg.upd(1, 1, N, A[v], B[v], C[v]);
		}
	}

	cout << *max_element(dp, dp+N+1) << endl;
	return 0;
}

Measured memory_bytes: 37248
#include<cstdio>
#include<vector>
#define big (1<<25)
#define maxAs(a,b) if((a)<(b)){(a)=(b);}
#define minAs(a,b) if((a)>(b)){(a)=(b);}
//cleared!
using namespace std;
//joi2016-ho-1
//Just odd industry???????????????????????????
int main(void){
    long long int N=0,M=0,K=0,i=0,j=0,x=0,gen=0,thmax=0,thmin=0;
    vector<int> A;//?????¬???????????§??????
    vector<long long int> cost;
    scanf("%lld %lld %lld",&N,&M,&K);
    for(i=0;i<N;i++){
        scanf("%lld",&x);
        A.push_back(x);
    }
    cost.push_back(0);
    for(i=1;i<=N;i++){
        gen=big;thmax=0;thmin=big;
        gen*=big;thmin*=big;
        for(j=1;j<=M;j++){
            if(i-j<0){break;}
            maxAs(thmax,A[i-j]);
            minAs(thmin,A[i-j]);
            minAs(gen,cost[i-j]+K+j*(thmax-thmin));
        }
        cost.push_back(gen);
    }
    printf("%lld\n",cost[N]);
    return 0;
}

Measured memory_bytes: 2952
# N < 10000
N = int(input())

# len(s) < 10

count = 0
a, b, ba = 0, 0, 0
for i in range(N):
    s = input().rstrip()
    count += s.count("AB")

    if s[-1] == 'A':
        if s[0] == 'B':
            ba += 1
        else:
            a += 1
    elif s[0] == 'B':
        b += 1

#e = int(input())
#print("*A=",a, ", B*=",b, "B*A=",ba, ",AB=", count, ",expected=", e)

if ba > 1:
    count += ba - 1
    ba = 1

if a + b > 0:
    #count += max(min(a + ba, b),min (a, b + ba))
    count += min(a,b) + ba
print(count)


Measured memory_bytes: 3064