akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {+0,+1,+0,-1};
const static int ty[] = {-1,+0,+1,+0};
 
static const double EPS = 1e-12;

int W,H;
char stage[1001][1001];
bool visited[1001][1001];

class State{
public:
  int x;
  int y;
  int cost;
  State(int _x,int _y,int _c) : x(_x),y(_y),cost(_c){}

  bool operator <(const State& s) const{
    return cost < s.cost;
  }
  bool operator >(const State& s) const{
    return cost > s.cost;
  }
};

void bfs(){
  priority_queue<State,vector<State>,greater<State> > que;
  que.push(State(0,0,0));
  
  while(!que.empty()){
    State s = que.top();
    que.pop();
    int sx = s.x;
    int sy = s.y;
    if(visited[sy][sx]) continue;

    visited[sy][sx] = true;
    if(stage[sy][sx] == 't') break;
    for(int i=0;i<4;i++){
      int dx = sx + tx[i];
      int dy = sy + ty[i];
      if(dx < 0 || dy < 0 || dx >= W || dy >= H) continue;
      if(visited[dy][dx]) continue;
      if(stage[dy][dx] == '#') continue;
      que.push(State(dx,dy,s.cost+1));
    }
  }
}

void dfs(int sx,int sy){
  visited[sy][sx] = true;
  for(int i=0;i<4;i++){
    int dx = sx + tx[i];
    int dy = sy + ty[i];
    if(dx < 0 || dy < 0 || dx >= W || dy >= H) continue;
    if(visited[dy][dx]) continue;
    if(stage[dy][dx] == '#') continue;
    dfs(dx,dy);
  }
}

bool has_route(int time,const vector<P>& gates,
	       int gx,int gy){

  vector<P> skip;
  for(int i=0;i<time;i++){
    int x = gates[i].first;
    int y = gates[i].second;
    if(stage[y][x] == '.'){
      skip.push_back(gates[i]);
    }
    stage[y][x] = '.';
  }
  memset(visited,false,sizeof(visited));
  bfs();

  for(int i=0;i<time;i++){
    int x = gates[i].first;
    int y = gates[i].second;
    stage[y][x] = '#';
  }

  for(int i=0;i<skip.size();i++){
    int x = skip[i].first;
    int y = skip[i].second;
    stage[y][x] = '.';
  }
  return visited[gy][gx];
}

int main(){

  while(~scanf("%d %d",&W,&H)){

    int gx,gy;
    for(int y=0;y<H;y++){
      string line;
      cin >> line;
      for(int x=0;x<W;x++){
	stage[y][x] = line[x];
	if(line[x] == 't'){
	  gx = x;
	  gy = y;
	}
      }
    }

    vector<P> gates;
    int total_time;
    scanf("%d",&total_time);
    for(int time=0;time<total_time;time++){
      int x,y;
      scanf("%d %d",&x,&y);
      gates.push_back(P(x,y));
    }

    int min_time = 0;
    int max_time = gates.size();
    bool isok = false;
    for(int round=0;round<20;round++){
      int mid = (min_time + max_time) / 2;
      if(has_route(mid,gates,gx,gy)){
	max_time = mid;
	isok = true;
      }
      else{
	min_time = mid+1;
      }
    }

    printf("%d\n",isok ? max_time : -1);
  }
}

Measured memory_bytes: 3300
#include <stdio.h>

int main(void)
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a==b && c==d || a==d && b==c){
		printf("yes\n");
	}
	else{
		printf("no\n");
	}
	return 0;
}



Measured memory_bytes: 2036
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int n;
    scanf("%d",&n);
    int C[510],S[510],F[510];
    int i;
    for(i=1;i<n;i++)
        scanf("%d%d%d",&C[i],&S[i],&F[i]);
    int j,h;
    int sum;
    sum=0;
    for(i=1;i<n;i++)
    {
        sum=S[i]+C[i];
        for(j=1;j<n-i;j++)
        {
            int m;
            if(sum<S[i+j])
                m=S[i+j];
            else
            {
                for(h=1;  ;h++)
                {
                    m=S[i+j]+h*F[i+j];
                    if(m>=sum && m%F[i+j]==0)
                        break;
                }
            }
            sum=C[i+j]+m;
        }
        printf("%d\n",sum);
    }
    if(i==n)
        printf("0\n");
    
}

Measured memory_bytes: 128
n,y=map(int,input().split())
for i in range(n+1):
    for r in range(n+1-i):
        x=n-r-i
        total = 10000*i+5000*r+1000*x
        if total==y and i+r+x==n:
            print(i,r,x)
            exit()
print(-1,-1,-1)
                

Measured memory_bytes: 40428
maxn=int(raw_input())
data1=maxn*[0]
data2=maxn*[0]
for n in range(maxn):
 inp=raw_input()
 data1[n]=int(inp.split(' ')[0])
 data2[n]=int(inp.split(' ')[1])
print max(data1)+min(data2)

Measured memory_bytes: 12164
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int N,M;
int main() {
while(1){
	cin >> N >> M;
	if(N==0&&M==0)return 0;
	vector<int> in;
	for(int i=0;i<N;i++){
		int a;
		cin >> a;
		in.push_back(a);
	}
	in.push_back(0);
	vector<int> p;
	for(int i=0;i<in.size();i++){
		for(int j=i;j<in.size();j++){
			p.push_back(in[i]+in[j]);
		}
	}
	int s=0,t=p.size()-1;
	sort(p.begin(),p.end());
	int ret=0;
	while(s<=t){
		int v=p[s]+p[t];
		if(v<=M){
			ret=max(ret,v);
			s++;
		}
		else{
			t--;
		}
	}
	cout << ret << endl;
}
}

Measured memory_bytes: 5040
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;

#define rep(i,n) for (int i = 0; i < (n); ++i)

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){

int n;cin>>n;
vector<int> n1(n/2+1,-1),n2(n/2+1,-1);
rep(i,n){
  int num;cin>>num;
  if(i%2==0){
    n1[i/2]=num;
  }
  else n2[i/2]=num;
}

if(n%2==0){
rep(i,n/2+1){
  if(n2[i]==-1)continue;
  //cout<<n2[n/2-1-i];
  printf("%d ",n2[n/2-1-i]);
}
rep(i,n/2+1){
  if(n1[i]==-1)continue;
  //cout<<n1[i];
 printf("%d ",n1[i]); 
}
}
else{
rep(i,n/2+1){
  if(n1[i]==-1)continue;
  //cout<<n1[n/2+1-i];
  printf("%d ",n1[n/2-i]);
}
rep(i,n/2+1){
  if(n2[i]==-1)continue;
  printf("%d ",n2[i]); 
}
}
  return 0;
}

Measured memory_bytes: 2944
n=int(input())
xu=[]
for i in range(n):
    xu1=input().split()
    xu.append(xu1)
BTC=[]
JPY=[]
for j in xu:
    if j[1]=='BTC':
        BTC.append(float(j[0]))
    else:
        JPY.append(int(j[0]))
print(380000.0*sum(BTC)+sum(JPY))

Measured memory_bytes: 3064
#include <cstdio>

using namespace std;
int n,tmp,Ans = 0;
int main(){
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; i++){
        scanf("%d",&tmp);
        if(tmp % 2 && i % 2) Ans++;
    }
    printf("%d",Ans);
    return 0;
}

Measured memory_bytes: 1680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll par[160005],c[160005];
ll a[160005],b[160005];
void init(int x){
  for(int i=0;i<x;i++){
    par[i]=i;
    c[i]=1;
  }
}
ll root(int x){
  if(par[x]==x){
    return x;
  }
  return par[x]=root(par[x]);
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y){
    return;
  }
  par[x]=y;
  c[y]+=c[x];
  b[y]+=b[x];
}

int main(){
  int h,w;cin >> h >> w;
  vector<string> s(h);
  init(h*w);
  for(int i=0;i<h;i++){
    cin >> s[i];
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        b[i*w+j]=1;
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i!=h-1){
        if(s[i][j]!=s[i+1][j]){
          unite(i*w+j,(i+1)*w+j);
        }
      }
      if(j!=w-1){
        if(s[i][j]!=s[i][j+1]){
          unite(i*w+j,i*w+j+1);
        }
      }
    }
  }
  ll ans=0;
  for(int i=0;i<h*w;i++){
    if(root(i)==i){
      ans+=b[i]*(c[i]-b[i]);
    }
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define MOD 1000000007

int n,m;
set<int> g[125252];

int sm[125252];
vector<int> eds[125252];

int main(){
  scanf("%d",&n);
  REP(i,n){
    scanf("%d",&m);
    while(m--){
      int x;
      scanf("%d",&x);
      g[i].insert(x-1);
    }
  }
  set<int> rm;
  REP(i,n)if(g[i].count(i)){
    rm.insert(i);
  }
  REP(i,n)if(!rm.count(i)){
    set<int>::iterator it = g[i].begin();
    while(it != g[i].end()){
      if(rm.count(*it)){
        g[i].erase(it++);
      }else{
        it++;
      }
    }
  }
  REP(i,n)if(!rm.count(i) && g[i].count(i+1)){
    sm[i+1]++;
  }
  REP(i,n+1)sm[i+1]+=sm[i];
  REP(i,n)if(!rm.count(i)){
    set<int>::iterator it = g[i].begin();
    while(it != g[i].end()){
      int x = *it; it++;
      int y = i;
      if(x==y+1)continue;
      assert(x<y);
      if(y-x == sm[y]-sm[x]){
        eds[x].push_back(y);
      }
    }
  }
  priority_queue<int> Q;
  int ans = rm.size();
  REP(i,n){
    for(int x : eds[i]){
      Q.push(-x);
    }
    if(Q.size() && -Q.top() == i){
      ans++;
      while(Q.size())Q.pop();
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 16804
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define ll long long 
int main(){
    char ch; int s=0;
    ch=getchar();
    while (ch<'0'||ch>'9') ch=getchar();
    while (ch>='0'&&ch<='9'){
        s+=ch-'0'; ch=getchar();
    }
    if (s%9) cout<<"No";
    else cout<<"Yes";
}

Measured memory_bytes: 3640
from collections import Counter

N = int(input())
lst = [int(x) for x in input().split()]
dic = dict(Counter(lst))

ret = 0
for k, v in dic.items():
    ret += v * (v - 1) // 2


for x in lst:
    n = dic[x]
    if n == 1:
        print(ret)
    else:
        print(ret - (n * (n - 1) // 2) + ((n - 1) * (n - 2) // 2))


Measured memory_bytes: 26900
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

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

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int N, K, h, ans=0;
int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N >> K;
    REP(i,N)
    {
        cin >> h;
        if (h>=K) ans++;
    }
    cout<<ans<<endl;
  
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[200000],b[200000]={0};
  int ans=0;
  rep(i,n) cin>>a[i];
  int prev;
  repn(i,n-1){
    if(a[i]>i){cout<<-1<<endl;return 0;}
    if(i==n-1){prev=a[i];ans+=a[i];}
    else{
      if(prev-1 >a[i]){cout<<-1<<endl;return 0;}
      else if(prev-1 == a[i]){
	prev=a[i];
      }else{
	prev=a[i];
	ans+=a[i];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
int a,b,c,d;ll ans;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	d=min(b,c);ans+=d*2;b-=d;c-=d;
	if(b)ans+=b;else ans+=min(a,c);
	if(c>min(a,c))ans++;printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 256
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;

int main()
{
    int n, d;

    cin >> n>>d;

    int x[10][10];
    int kyori2;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }

    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            kyori2 = 0;
            bool ok = false;
            for (int k = 0; k < d; k++) {
                kyori2+= (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            int x = 0;
            while (x*x<=kyori2) {
                if (x * x == kyori2)ok = true;
                x++;
            }
            if (ok)ans++;
           
        }
    }
    cout << ans << endl;
}



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

int main() {
  string a, b;
  cin >> a >> b;
  
  sort(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<char>());
  cout << (a < b ? "Yes" : "No") << endl;  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <complex>
using namespace std;

typedef complex<double> Point;

#define X real()
#define Y imag()
#define PI 3.1415926535

Point ans;
Point v = Point(0, 1);

int main() {
  while (1) {
    int a, b;
    scanf("%d,%d", &a, &b);
    if (a == 0 && b == 0) break;
    ans += double(a) * v;

    double t = double(-b)*PI/180;
    v *= Point(cos(t), sin(t));
  }

  printf("%d\n", int(ans.X));
  printf("%d\n", int(ans.Y));
}

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

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    int res = -1;
    for (int i = 0; i <= 1000000; i++) {
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            res = i;
            break;
        }
    }

    cout << res << endl;
}


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

int main() {
  long long n;
  cin>>n;
  vector<long long>a(n);
  for(long long i=0;i<n;i++){
    cin>>a.at(i);
    if(a.at(i)==0){
      cout<<"0"<< endl;
      return 0;
    }
  }
  long long sum=a.at(0);
  for(long long i=1;i<n;i++){
    if(sum>1000000000000000000||1000000000000000001/sum<a.at(i)){
      cout<<"-1"<< endl;
      return 0;
    }
    sum*=a.at(i);
  }
  if(sum>1000000000000000000){
    cout<<"-1"<< endl;
    return 0;
  }
  
  cout<<sum<< endl;
}
  


Measured memory_bytes: 4032
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
vector<int> a[nax];
int n , md[nax], ct[3];
vector<int> node[2];
void dfs (int nod,  int pa, int lv) {
    ct[lv % 2] ++;
    node[lv % 2].emplace_back(nod);
    for (int i : a[nod]) {
        if (i != pa) dfs(i, nod, lv + 1);
    }
}
vector<int> laz[3];
int col[nax];
int ptr3;
int c[3];
void reCol3 () {
    for (int i = 1 ;i  <= n ; ++ i) {
        if (col[i] == 0) {
            col[i] = laz[0][ptr3 ++];
        }
    }
}

int main () {
    scanf("%d", &n);
    for (int i = 1 ; i < n ; ++ i) {
        int u, v;
        scanf("%d %d", &u, &v);
        a[u].emplace_back(v);
        a[v].emplace_back(u);
    }
    for (int i = 1 ; i <= n; ++ i) {
        laz[i % 3].emplace_back(i);
    }
    c[0] = n / 3 ;
    c[1] = n / 3 + (n % 3 > 0);
    c[2] = n / 3 + (n % 3 > 1);
    dfs(1, 0, 0);
    if (max(ct[0], ct[1]) >= c[1] + c[2]) {
        int toCol = ct[0] >= ct[1] ? 0 : 1;
        for (int i = 0 ;i < (int)laz[1].size() ; ++ i) {
            col[node[toCol][i]] = laz[1][i];
        }
        for (int i = 0 ; i < (int) laz[2].size() ; ++ i) {
            col[node[toCol][i + (laz[1].size())]] = laz[2][i];
        }
        reCol3();
        for (int i = 1 ; i <= n ; ++ i) {
            printf("%d ", col[i]);
        }
    }
    else if (max(ct[0], ct[1]) >= c[1] && min(ct[0], ct[1]) >= c[2]) {
        int maxCol = ct[0] >= ct[1] ? 0 : 1;
        int minCol = (maxCol ^ 1);
        for (int i = 0 ; i < (int) laz[1].size() ; ++ i) {
            col[node[maxCol][i]] = laz[1][i];
        }
        for (int i = 0 ; i < (int) laz[2].size() ; ++ i)
            col[node[minCol][i]] = laz[2][i];
        reCol3();
        for (int i = 1 ; i <= n ; ++ i)
            printf("%d ", col[i]);
    }
    else throw;
}
/*
    Good Luck
        -Lucina
*/


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

int mod =1000000007;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back

template<typename T, typename U>
inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U>
inline void amax(T &x, U y) { if(x < y) x = y; }

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;

int main(){
	int n,k;
	cin>>n>>k;
	vi h(n);
	for(auto & ht:h)
	cin>>ht ;
	vi cost(n,mod);
	cost[0]=0;
	cost[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;++i){
		for(int j=(i>=k?i-k:0);j<i;++j)
		amin(cost[i],abs(h[i]-h[j])+cost[j]);
	}
	cout<<cost[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
#define pl pair<ll,ll>
#define pi pair<int,int>
#define pll pair< ll, pair<ll,ll> > 
#define pii pair< int, pair<int,int> >
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll l,t,T,x,y,z,n;
    cin>>n;
    ll a[n+5];
    rep(i,1,n) cin>>a[i];
    x = 0,y=0;
    rep(i,1,n){
    	x+=a[i];
    	x%=N;
	}
	rep(i,1,n){
		x= (x - a[i] + N)%N;
		y+=x*a[i];
		y%=N;
	}
	cout<<y;
}

Measured memory_bytes: 5200
s=int(input())
a=s//3
b=s//5
c=s//15
d=s*(s+1)
d=d//2
a=a*(a+1)*3
a=a//2
b=b*(b+1)*5
b=b//2
c=c*(c+1)*15
c=c//2
e=d-a-b+c
print(e)

Measured memory_bytes: 9192
#include <iostream>
#include<vector>
#define MAX 1000000
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int N,M;
    vector<int> w,h;
    int p=0;
    //int x[MAX]={0};
    while((cin>>N>>M)&&N)
    {
        int tt=0;
        w.resize(M);
        h.resize(N);
        for(int i=0;i<N;i++)
        {
            cin>>h[i];
        }

        for(int j=0;j<M;j++)
        {
            cin>>w[j];
        }
        map<int,int> x;
        for(int i=0;i<N;i++)
        {
            p=0;
            for(int j=i;j<N;j++)
            {
                p+=h[j];
                x[p]++;
            }
        }
        for(int i=0;i<M;i++)
        {
            p=0;
            for(int j=i;j<M;j++)
            {
                p+=w[j];
                tt+=x[p];
            }
        }
        cout<<tt<<endl;
    }
    return 0;
}



Measured memory_bytes: 21008
(let ((s (read-line)))
  (cond ((or (string= s "SSR")
             (string= s "SRS")
             (string= s "RSS")
             (string= s "RSR"))
         (format t "1~%"))
        ((or (string= s "SRR")
             (string= s "RRS"))
         (format t "2~%"))
        ((string= s "RRR")
         (format t "3~%"))
        (t
         (format t "0~%"))))


Measured memory_bytes: 23596
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))//なるべくこれを使う
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MODi 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll mod_pow(ll x,ll n,ll mod){ll res=1;while(n>0){
if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}
using Graph=vector<vector<P> >;
ll nCr(ll n,ll k,ll MOD_=1000000007){
    ll size=k;
    ll ans=1;
    vector<ll>fact_inv,inv;
    fact_inv.resize(size+5);
    inv.resize(size+5);
    fact_inv[0]=fact_inv[1]=1;
    inv[1]=1;
    for(int i=2;i<size+5;i++){
        inv[i]=MOD_-inv[MOD_%i]*(MOD_/i)%MOD_;
        fact_inv[i]=fact_inv[i-1]*inv[i]%MOD_;
    }
    for(int i=n;i>=n-k+1;i--){
        ans*=i;ans%=MOD_;
    }
    return ans*fact_inv[k]%MOD_;
}

int main(){
    ll x,y;cin>>x>>y;
    if((x+y)%3!=0||(2*y-x)/3<0){cout<<0<<endl;return 0;}
    ll n=(x+y)/3,r=(2*y-x)/3;
    cout<<nCr(n,r)<<endl;
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}
VL a(70, 1), p(70, 1);
ll solve(ll n, ll k) {
  if(n == 0) return k <= 0 ? 0 : 1;
  else if(k <= 1 + a[n-1]) return solve(n-1, k-1);
  else return p[n-1] + 1 + solve(n-1, k-2-a[n-1]);
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  ll x;
  cin >> n >> x;
  rep(i, 60) {
    a[i+1] = 2 * a[i] + 3;
    p[i+1] = 2 * p[i] + 1;
  }
  ll ans = solve(n, x);
  out(ans);
  return 0;
}


Measured memory_bytes: 256
// ABC162-D RGB Triplets

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

signed main() {
    int n, a, b, pos1, pos2;
    long long dp[3][4000] = {}, ans = 0;
    string s;

    cin >> n;
    cin >> s;

    ans = 0;
    for(int i=0 ;i<n ;i++ ) {
        if(s[i] == 'R') {
            dp[0][i] = 1;
        } 
        else if(s[i] == 'B') {
            dp[1][i] = 1;
        }
        else {
            dp[2][i] = 1;
        }

        if(i > 0) {
            for(int j=0 ;j<3 ;j++ ) {
                dp[j][i] += dp[j][i-1];
            }
        }
    }

    for(int i=1 ;i<n-1 ;i++ ) {  
        if(s[i] == 'R') {
            a = 1;
            b = 2;
        }
        else if(s[i] == 'B') {
            a = 0;
            b = 2;
        }
        else {
            a = 0;
            b = 1;
        }

        ans += dp[a][i-1] * (dp[b][n-1] - dp[b][i]) + dp[b][i-1] * (dp[a][n-1] - dp[a][i]);
        pos1 = i-1;
        pos2 = i+1;   

        while(pos1 >= 0 && pos2 <= n-1) {
            if(s[pos1] != s[i] && s[i] != s[pos2] && s[pos1] != s[pos2]) {
                ans --;
            }

            pos1 --;
            pos2 ++;
        }
    }

    cout << ans << endl;

    return (0);
}

Measured memory_bytes: 3736
S = input()
F = int(S) // 100
B = int(S) % 100
if (F <= 12 and F > 0) and (B <= 12 and B > 0):
  print("AMBIGUOUS")
elif F <= 12 and F > 0:
  print("MMYY")
elif B <= 12 and B > 0:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
#define NDEBUG

#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <tuple>
#include <vector>

using namespace std;
using tii = tuple<int, int>;

#ifdef NDEBUG
#  define debug(...)
#else
#  include "debug.hh"
#endif

int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
  string s;
  cin >> s;
  for (char & c: s) {
    if (c == '1') c = '9';
    else if (c == '9') c = '1';
  }
  cout << s << endl;
  return 0;
}


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

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

    int N, A;
    cin >> N >> A;

    int L = A;
    int R = A + N - 1;

    int eat;
    if (R <= 0) eat = R;
    else if (L >= 0) eat = L;
    else eat = 0;

    int answer = (R+L)*(R-L+1)/2 - eat;

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    int n;
    cin>>n;
    vector<ll>a(n+1),b(n);
    for(int i=0;i<n+1;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];

    ll ans = 0, rem = a[n];
    for(int i=n-1;i>=0;i--)
    {
        if( rem > 0 )
        {
            ans += min(rem,b[i]);
            b[i] = max(0ll,b[i]-rem);
        }
        ans += min(a[i],b[i]);
        rem = max(0ll, a[i]-b[i]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { //WOOOOOOO AtCoder is HELPING!!!!!!!!!!
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		long curGCD = input.nextLong();
		for (int i = 1; i < N; i++) {
			long prev = curGCD;
			long x = input.nextLong();
			curGCD = GCD(prev,x);
		}
		System.out.println(curGCD);
	}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.max(a, b)%Math.min(a, b),Math.min(a, b));
	}
}

Measured memory_bytes: 49028
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    cout << max({A1, A2, A3}) - min({A1, A2, A3}) << endl;
    return 0;
}


Measured memory_bytes: 256
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

for ai in a:
  if ai % 2 == 0:
    if ai%3!=0 and ai%5!=0:
      print('DENIED')
      exit()
print("APPROVED")

Measured memory_bytes: 3060
#include <numeric>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
vector<int> adj[2000];

int n;
string s;

struct res { int s, t, k; };

res dfs(int i, int p) {
    vector<int> ss, ts;
    int K = 0;
    for (int j : adj[i]) {
        if (j == p) continue;
        res r = dfs(j, i);
        ss.push_back(r.s + r.k);
        ts.push_back(r.t + r.k);
        K += r.k;
    }
    int K1 = s[i] == '1' ? K+1 : K;
    if (ss.empty()) return {0, 0, K1};
    int j = max_element(ts.begin(), ts.end()) - ts.begin();
    int S = 0;
    for (int k = 0; k < ss.size(); k++) {
        if (k != j) S += min(ts[j], ss[k]);
    }
    if (ts[j] <= S) return { accumulate(ss.begin(), ss.end(), 0),
                            accumulate(ts.begin(), ts.end(), 0) % 2, K1 };
    else
        return { accumulate(ss.begin(), ss.end(), 0),
                ts[j] - S, K1 };
}

int main() {
    cin >> n >> s;
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    int ans = 1<<30;
    for (int i = 0; i < n; i++) {
        auto r = dfs(i, -1);
        if (r.t == 0) ans = min(ans, r.s/2);
    }
    cout << (ans < 1<<30 ? ans : -1) << endl;
}


Measured memory_bytes: 768
use proconio::input;

fn main() {
    input! {
        x: i64,
    }

    for a in -1000i64..=1000 {
        for b in -1000i64..=1000 {
            if a.pow(5) - b.pow(5) == x {
                println!("{} {}", a, b);
                return;
            }
        }
    }
    panic!();
}


Measured memory_bytes: 2116
N, K = gets.split.map(&:to_i)
p = gets.split.map { |i| (i.to_i + 1) / 2.0 }

tmp = max = p[0...K].inject(:+)

(N - K).times do |i|
  tmp = tmp - p[i] + p[K + i]
  max = tmp if max < tmp
end

puts max

Measured memory_bytes: 14980
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cstdio>
#include <queue>

using namespace std;

#define int long long

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

    signed n;
    vector<int> v;

    cin >> n;

    v.resize(n);

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

    sort(v.begin(), v.end(),greater<int>());

    bool isAlice = true;

    int alice = 0, bob = 0;

    for (int i = 0; i < n; ++i)
    {
        if (isAlice)
        {
            alice += v[i];
        }
        else
        {
            bob += v[i];
        }

        isAlice = !isAlice;
    }

    cout << alice - bob << endl;
}

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

signed main(){
    int N;cin>>N;
    vint A(N);rep(i,N)cin>>A[i];
    sort(all(A));
    int sum=accumulate(all(A),0ll);

    for(int i=N-1;i>=0;i--){
        sum-=A[i];
        if(sum*2<A[i]){
            cout<<N-i<<endl;
            return 0;
        }
    }
    return 0;
}


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


int main(){

    string s;
    cin >> s;

    int c = 1;
    for(int i = 1; i < 4; i++){
        if(s[0] == s[i]){
            c++;
        }
    }

    if(c != 2){
        cout << "No" << endl;
        return 0;
    }

    if(s[0] == s[1]){
        if(s[2] != s[3]){
            cout << "No" << endl;
            return 0;
        }
    }
    else{
        c = 1;
        for(int i = 2; i < 4; i++){
            if(s[1] == s[i]){
                c++;
            }
        }

        if(c != 2){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
from math import gcd


def factorization(n):
    arr, temp = [], n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr


A, B = map(int, input().split())
n_gcd = gcd(A, B)

fac = factorization(n_gcd)
ans = 0
if fac[0][0] != 1:
    ans += 1

ans += len(fac)
print(ans)

Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 1000005
#define in(x)  cin>>x
#define o(x)  cout<<x
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define frm(i,a,n) for(ll i=n;i>=a;i--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS],tem[AS];
ll board[500][500];
int main()
{
    fast;
   in(n>>x>>y);
   o((n+x-1)/x*y);
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

const long long MAX = 5e5+100;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll f(int n, int k){
    return fac[n] * finv[n - k] % MOD;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    COMinit();
    ll n, m; cin >> n >> m;

    ll a[n + 1];
    rep(k, 0, n){
        a[k] = COM(n, k) * f(m, k) % MOD * f(m - k, n - k) % MOD * f(m - k, n - k) % MOD;
    }

    ll ans = 0;
    rep(k, 0, n){
        if(k % 2 == 0){
            ans += a[k];
        }else{
            ans += MOD - a[k];
        }
        ans %= MOD;
    }
    print(ans)

    return 0;
}

Measured memory_bytes: 19276
#include <stdio.h>

int n, m, d, p, r[11];

int main()
{
    while(true)
    {
        scanf("%d", &n);
        scanf("%d", &m);
        
        if(n == 0 && m == 0) { break; }
        
        for(int i = 0; i < 11; i++)
        {
            r[i] = 0;
        }
        
        while(n--)
        {
            scanf("%d", &d);
            scanf("%d", &p);
            
            r[p] += d;
        }
        
        for(int i = 10; i >= 0; i--)
        {
            if(m >= r[i])
            {
                m -= r[i];
                
                r[i] = 0;
            }
            else
            {
                r[i] -= m;
                
                break;
            }
        }
        
        int sum = 0;
        
        for(int i = 0; i <= 10; i++)
        {
            sum += i * r[i];
        }
        
        printf("%d\n", sum);
    }
    
    return 0;
}

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

int main() {
  int n;
  vector<int> d1(n);
  vector<int> d2(n);
  cin >> n;
  int count = 0;
  string ans = "No";
  rep(i,n) {
    cin >> d1[i] >> d2[i];
    if (d1[i] == d2[i]) {
      count++;
    } else {
      count = 0;
    }
    if (count >= 3) {
      ans = "Yes";
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3880
#include <iostream>
#include <algorithm>
#include<cstring>
using namespace std;
int dis[10];
int check(int n);
int main()
{
     int n,k;
     cin >> n >> k;
     memset(dis,0,sizeof(dis));
     int x;
     for(int i = 0;i < k;i++)
        {
         cin >> x;
         dis[x] = 1;
        }
     for(int i = n; ;i++)
        {
         if(check(i))
            {
             cout << i <<endl;
             break;
            }
        }
     return 0;
}
int check(int n)
{
     while(n)
        {
         int yushu = n%10;


         if(dis[yushu])
            {
            return 0;
         }
         n /= 10;
         }
    return 1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define stp setprecision(15)
#define eps 0.000001
#define endl '\n'
#define mod2 998244353
#define ll lli

using namespace std ;

#define N 200000+5 

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main() 
{
/////////////////////////////////////
    
    fastio;
 
/////////////////////////////////////    

    lli n;
    cin>>n;

    lli a[n];
    loopl(i,0,n) cin>>a[i];

    multiset<lli> s;
    s.insert(a[0]);

    loopl(i,1,n)
    {
        auto it = s.lb(a[i]);
        if(it == s.begin())
            s.insert(a[i]);

        else
        {
            it--;
            s.erase(it);
            s.insert(a[i]);
        }
    }

    cout<<s.size()<<endl;

}



Measured memory_bytes: 5760
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}

 
int32_t main()
{
    IOS
   
        
        int n,k;
        cin>>n>>k;
        int a[n];
        for(int i=0;i<n;++i)
            cin>>a[i];
        int dp[k+1];
        dp[0]=0;
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=k;++i)
        {
            int check=0;
            for(int j=0;j<n;++j)
            {
                if(i-a[j]>=0)
                {
                    if(dp[i-a[j]]==0)
                        {
                            check=1;
                            break;
                        }
                }
            }
            if(check)
            {
                dp[i]=1;
            }
           // cout<<dp[i]<<" "<<i<<endl;

        }
        if(dp[k])
        {
            cout<<"First";
        }
        else
        {
            cout<<"Second";
        }


 
 
 
}

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

int main(){
  int N;
  cin >> N;
  vector<int>s(N);
  for(int i = 0; N > i ; i++){
   cin >> s.at(i);
  }
  for(int i = 0; N > i ; i++){
   for( int j = i+1 ; N > j ; j++){
     if( s.at(j) > s.at(i) ){
      int tmp = s.at(i);
       s.at(i) = s.at(j);
       s.at(j) = tmp;
      }  
    }
  }
  
  int sum1 = 0,sum2 = 0;
  for( int i = 0; N > i ; i += 2 ){
    sum1 += s.at(i);
  }
  for ( int i = 1; N > i ; i +=2 ){
    sum2 += s.at(i);
  }
  cout << sum1 - sum2 << endl;
}

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

void solve(int n){
  int ans[100050] = {};
  for(int i = 1; i <= 100; i++){
    for(int j = 1; j <= 100; j++){
      for(int k = 1; k <= 100; k++){
        int l = i * i + j * j + k * k + i * j + j * k + k * i;
        ans[l-1]++;
      }
    }
  }
  for(int i = 0; i < n; i++){
    cout << ans[i] << endl;
  }
}

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

Measured memory_bytes: 4032
#include <cstdio>
#include <deque>

int main()
{
	char s[100001];
	int q;
	scanf("%s%d", s, &q);
	std::deque<char> deque;
	for (char* p = s; *p; ++p)
	{
		deque.push_back(*p);
	}
	int dir = 0;
	while (q--)
	{
		int t;
		scanf("%d", &t);
		if (t == 1)
		{
			dir ^= 1;
		}
		else
		{
			int f, c;
			scanf("%d %c", &f, &c);
			if ((dir ^ (f - 1)) == 0)
			{
				deque.push_front(c);
			}
			else
			{
				deque.push_back(c);
			}
		}
	}

	if (dir == 0)
	{
		for (char c : deque)
		{
			printf("%c", c);
		}
	}
	else
	{
		for (auto it = deque.rbegin(); it != deque.rend(); ++it)
		{
			printf("%c", *it);
		}
	}
	putchar('\n');
	return 0;
}


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

int main() {
  int x;
  cin >> x;
  if (x<1200) {
    cout << "ABC" << endl;
  } else {
    cout << "ARC" << endl;
  }
  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Integer[][] array = new Integer[m][m];
		int n = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int a = n+b+c;
		if(a>=22)
			System.out.println("bust");
		else
			System.out.println("win");
	}
}

Measured memory_bytes: 23892
#include<stdio.h>
int main(void)
{
	int a,h,m1,m,s;
	scanf("%d",&a);
	h=a/3600;
	m1=a-h*3600;
	m=m1/60;
	s=m1-m*60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


Measured memory_bytes: 2112
import java.awt.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = i;
        }

        Point[] order = new Point[m];

        for (int i = 0; i < m; i++) {
            order[i] = new Point(scanner.nextInt() - 1, scanner.nextInt() - 1);
        }

        int ans = 0;

        for (int i = 0; i < m; i++) {
            int[] copied = new int[n];
            System.arraycopy(array, 0, copied, 0, n);
            for (int j = 0; j < m; j++) {
                if (i == j) {
                    continue;
                }
                union(copied, order[j].x, order[j].y);
            }
            int v = find(copied, 0);
            for (int j = 1; j < n; j++) {
                if (v != find(copied, j)) {
                    ans++;
                    break;
                }
            }
        }

        System.out.println(ans);
    }

    public static int find(int[] tree,int idx) {
        if(tree[idx]==idx) return idx;
        else return tree[idx] = find(tree,tree[idx]);
    }

    //union idx2 tree to idx1 tree O(a(N))
    public static void union(int[] tree,int idx1,int idx2) {
        int root1 = find(tree,idx1);
        int root2 = find(tree,idx2);
        tree[root2] = root1;
    }
}

Measured memory_bytes: 35312
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 2010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

int n, m, a[MAXN], b[MAXN];
ll dp[MAXN][MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,m) cin >> b[i];
    FOR(i,0,n) dp[i][0] = 1;
    FOR(i,0,m) dp[0][i] = 1;
    FOR(i,1,n)
        FOR(j,1,m) {
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + MODBASE) % MODBASE;
            if (a[i] == b[j]) dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MODBASE;
        }
    cout << dp[n][m];
    return 0;
}

Measured memory_bytes: 31744
#include<iostream>
using namespace std;
int main()
{
	int i,ans=0,j,n,l1,r1;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>l1>>r1;
		j=r1-l1+1;
		ans+=j;	
	}	
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256