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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,a,b;cin>>n>>a>>b;
  int num,ans=0,hoge;
  for (int i = 1; i <= n; ++i){
  	num=i;
  	hoge=0;
  	while(num>0){
  		hoge+=num%10;
  		num/=10;
  	}
  	//cout<<hoge<<endl;
  	if(hoge>=a && hoge<=b){
  		// cout<<i<<endl;
  		ans+=i;
  	}
  }
  cout<<ans<<endl;
}


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

typedef long long LL;

int n;

void work(){
  scanf("%d",&n);
  int c=0;
  for (int i=1;i<=n;++i){
	int x,y;
	scanf("%d%d",&x,&y);
    x==y?++c:c=0;
	if (c>=3) {puts("Yes");return;}
  }
  puts("No");
}

int main(){
  int T=1;
  for (;T--;) work();
  return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
#define ll  long long  
#define pb push_back
#define fi first
#define se second
using namespace std;
ll mo=1e9+7;
ll i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
 while(tc--)
 {
	ll n,m,x;
	cin>>n>>m>>x;
	ll a[n][m];
	ll c[n];
	ll ans=1e18;
	ll diff;
	for(i=0;i<n;i++)
	{
		cin>>c[i];
	for(j=0;j<m;j++)
	cin>>a[i][j];
    }
   /* for(i=0;i<n;i++)
    cout<<c[i];*/
     for (i = 0; i<(1<<n); i++) {
diff=0;
ll pos[n]={0};
ll val[m]={0};
      for(j=0;j<n;j++)
{
	pos[j]=((i&(1<<j))?1:0);
    diff+=((i&(1<<j))?1:0)*c[j];
}
for(ll y=0;y<n;y++)
for(ll z=0;z<m;z++)
{
	if(pos[y]>0)
val[z]+=a[y][z];
}
ll yo=1;
for(ll z=0;z<m;z++)
if(val[z]<x)
yo=0;
//cout<<diff<<" ";
if(yo==1)
ans=min(ans,abs(diff));
}
if(ans!=1e18)
cout<<ans;
else
cout<<-1;
	cout<<"\n";
 } 
}


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

using namespace std;

#define ll long long

int main()
{
    string str;
    cin >> str;
    ll n = (ll) str.length();
    vector<ll> V1, V2;
    V1.push_back(0);
    for(ll i=0; i<n; i++){
        if(str[i] == '<'){
            V1.push_back(V1.back()+1);
        }
        else V1.push_back(0);
    }
    V2.push_back(0);
    for(ll i=n-1; i>=0; i--){
        if(str[i] == '>') V2.push_back(V2.back()+1);
        else V2.push_back(0);
    }
    reverse(V2.begin(), V2.end());
    ll ans = 0;
    for(ll i=0; i<=n; i++) ans += max(V1[i], V2[i]);
    cout << ans;
}

Measured memory_bytes: 12660
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0]
b = 0
for i in range(N):
    b += A[i]
    B.append(b % M)
B.sort()
ans = 0
k = 1
C = []
for i in range(N):
    if B[i] == B[i + 1]:
        k += 1
    else:
        C.append(k)
        k = 1
C.append(k)
for k in C:
    if k > 1:
        ans += k * (k - 1) // 2
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
 
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define uset unordered_set
#define endl '\n'
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
const int N = 2e5 + 15;
int n, a[N];

int main() {
	n = 4;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	sort(a+1, a+1+n);
	if(a[1] == 1 && a[2] == 4 && a[3] == 7 && a[4] == 9)
		return cout << "YES", 0;
	cout << "NO";
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
int main(void) {
	int num_mat, num_row, tmp, min, i, j, k;
	int M[100][100] = {{0}}, r[101];

	scanf("%d", &num_mat);
	if (num_mat < 2) {
		puts("0");
		return 0;
	}

	scanf("%d %d", r, r+1);
	num_row = 2;
	for (i = 1; i < num_mat; i++) {
		scanf("%d %d", &tmp, r+num_row);
		num_row++;
	}
	if (num_mat < 3) {
		printf("%d\n", r[0]*r[1]*r[2]);
		return 0;
	}

	for (i = 0; i < num_row-1; i++) {
		M[1][i] = r[i]*r[i+1]*r[i+2];
	}
	for (i = 2; i < num_mat; i++) {
		for (j = 0; j < num_mat-i; j++) {
			min = INT_MAX;
			for (k = 0; k < i; k++) {
				tmp = M[k][j] + M[i-1-k][1+j+k] + r[j]*r[1+j+k]*r[i+1+j];
				if (min > tmp) {
					min = tmp;
				}
			}
			M[i][j] = min;
		}
	}
	printf("%d\n", M[num_mat-1][0]);
	return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
    FIO
    int k;
    cin>>k;ll ans=0;

    for1(i,k)
    {
        for1(j,k)
        {
            for1(h,k)
            {
                ans+=__gcd(i,__gcd(j,h));
            }
        }
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 3676
from heapq import heappush,heappop,heapify
INF=10**30

def dijkstra(G,s,n):
    que=[(0,s)]
    dist=[INF]*n
    last=[-1]*n
    dist[s]=0
    while que:
        mincost,u=heappop(que)
        if(mincost>dist[u]):
            continue
        for c,v in G[u]:
            if(dist[u]+c<dist[v]):
                dist[v]=dist[u]+c
                last[v]=u
                heappush(que,(dist[v],v))
    return dist,last

dic={}
N,M=map(int,input().split())
G=[[] for i in range(N)]
Edges=[]
for i in range(M):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    G[a].append((c,b))
    G[b].append((c,a))
    Edges.append(tuple(sorted([a,b])))

for i in range(N):
    dist,last=dijkstra(G,i,N)
    for j in range(i):
        now=j
        while(now!=i):
            nex=last[now]
            dic[tuple(sorted([now,nex]))]=1
            now=nex
ans=len(Edges)
for u,v in Edges:
    if (u,v) in dic:
        ans-=1
print(ans)

Measured memory_bytes: 58460
MOD = 10 ** 9 + 7
N, M = map(int, input().split())
dp = [[0, 0] for _ in range(N + 1)]
dp[0][0] = 1
for _ in range(M):
    x = int(input())
    dp[x][1] = 1
for i in range(1, N + 1):
     if dp[i][1] == 0:
         dp[i][0] = (dp[i - 2][0] + dp[i - 1][0]) % MOD
print(dp[N][0])

Measured memory_bytes: 53616
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int &a:A)
        cin >> a;
    vector<vector<int>> dp(N+1, vector<int>(3));
    
    for(int i=0; i<N; i++){
        dp[i+1][0] = gcd(dp[i][0], A[i]);
        dp[i+1][1] = dp[i][0];
        dp[i+1][2] = max(gcd(dp[i][1], A[i]), gcd(dp[i][2], A[i]));
    }
    cout << max(dp[N][1], dp[N][2]) << endl;
    return 0;
}


Measured memory_bytes: 6144
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;

  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
      y=x;
      if(z->key<x->key){
          x=x->left;
      }
      else{
          x=x->right;
      }

  }
  
  z->parent=y;
  
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key<y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
  
}

Node treeSeach(Node u,int k){
  while (u!=NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

void inorder(Node u){
  if(u==NIL) return;

  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u==NIL) return;

  printf(" %d",u->key);

  preorder(u->left);
  preorder(u->right);
}
  

int main(){

  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if(com[0]=='f'){
      scanf("%d",&x);
      Node t=treeSeach(root,x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }    
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  
  return 0;
}



Measured memory_bytes: 20488
A = 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
print(A[int(input())-1])

Measured memory_bytes: 3060
// calc で seen の判定と incliment を分けた
// shift 演算子の前で (li) にcast
#include<vector>
#include<map>
#include<iostream>
using namespace std;
#define df 0
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define chmax(a,b) if((a)<(b)) {a=(b);}
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;


li calc(int k,const vector<vector<int>>& ctset,int m,int n){
  int pc=0,i=0,ans=n-1;
  vector<int> seen(m,0);
  if(df)printf("%d:",k);
  while(k){
    if(k%2){
      pc++;
      for(auto x: ctset.at(i)){
	if(df)printf("%d ",x);
	if(not seen.at(x)){
	  seen.at(x)++;
	  ans--;
	}
      }
      if(df)printf("\n");
    }
    k/=2; i++;
  }
  li ret=(pc%2)?-1:1;
  ret*= ((li)1)<<ans;
  if(df)printf("%ld\n",ret);
  return ret;
}

void dfs(int a,const vector<vector<int>>& adj,vector<int>& hgt,
	 vector<int>& par){
  int n=adj.size();
  static int h=0;
  hgt.at(a)=h;
  h++;
  for(int v: adj.at(a)){
    if(par.at(a)==v) continue;
    par.at(v)=a;
    dfs(v,adj,hgt,par);
  }
  h--;
}



auto make_set(int a,int b,const vector<int>& hgt,const vector<int>& par,
	      const map<pair<int,int>,int>& dict){
  int ha=hgt.at(a),hb=hgt.at(b);
  vector<int> st;
  if(ha>hb) {swap(a,b);swap(ha,hb);}
  if(df)printf("between %d %d (dif:%d)\n",a,b,hb-ha);
  auto add_par=[&](int& c){
		 int u=par.at(c),v=c; if(u>v) swap(u,v);
		 pair<int,int> p(u,v);
		 if(df)printf("(%d,%d)",u,v);
		 st.push_back((*dict.find(p)).second);
		 c=par.at(c);
	       };
  
  rep(i,hb-ha){
    add_par(b);
  }
  if(df){printf("%d%d",a,b);cout <<endl;}
  while(par.at(a)!=par.at(b)){
    add_par(a); add_par(b);
    if(df){printf("%d%d",a,b);cout <<endl;}
  }
  if(a!=b){
    add_par(a);
    add_par(b);
  }
  if(df){cout << "done" <<endl;}
  return st;
} 

int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >>n;
  vector<vector<int>> adj(n);
  map<pair<int,int>,int> dict;
  rep(i,n-1){
    int a,b; cin >>a >>b; a--; b--;
    adj.at(a).push_back(b);
    adj.at(b).push_back(a);
    if(a>b)swap(a,b);
    dict[make_pair(a,b)]=i;
  }
  vector<int> hgt(n),par(n,-1);

  dfs(0,adj,hgt,par);
  int m; cin >>m;
  if(df){
    for(int x: hgt) printf("%d ",x);
    printf(":hgt\n");
    for(int x: par) printf("%d ",x);
    printf(":par\n");
  }
  //  vector<pair<int,int>> ctrt(m);
  vector<vector<int>> ctset;
  rep(i,m){
    int a,b; cin >>a >>b; a--; b--;
    auto x=make_set(a,b,hgt,par,dict);
    ctset.push_back(x);
  }
  li ans=0,lim=1<<m;
  if(df)printf("%ld",lim);
  rep(i,lim){
    ans+=calc(i,ctset,n-1,n);
  }

  cout << ans;
}

/// confirm df==0 ///


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
h = [0]+h+[10**9+1]
for i in range(1,n+1):
  if h[i] > h[i+1]+1:
    print("No")
    exit()
  elif h[i] == h[i+1]+1:
    h[i] -= 1
    if h[i-1] > h[i]:
      print("No")
      exit()
  else:
    if h[i-1]  < h[i]:
      h[i] -= 1
print("Yes")
  
    
    


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


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

  int S[10][10] = {{0}};

  for(int i = 0;i < M;i++){
    int k; cin >> k;
    for(int j = 0;j < k;j++){
      int s; cin >> s;
      S[i][s-1] = 1;//電球は0~M-1で,スイッチは0~N-1.
    }
  }



  int p[10];

  for(int i = 0;i < M;i++)cin >> p[i];


  


  int ans = 0;


  for(int i = 0;i < (1 << N);i++){
    vector<int> s;
    for(int j = 0;j < N;j++){
      if((i >> j)&1)s.push_back(1);
      else s.push_back(0);//スイッチの状態を決める.
    }

    bool flag = true;

    for(int i = 0;i < M;i++){
      int parity = 0;
      for(int j = 0;j < N;j++){
        if(S[i][j] == 1 && s[j] == 1)parity++;
      }//ついているスイッチの数を数える.

      parity = parity % 2;
      if(parity != p[i]){
        flag = false;
        break;
      }
    }

    if(!flag)continue;
    else ans++;

  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<int> cnt(n);
    vector<bool> ok(n);
    rep (i, m) {
        int p;
        string s;
        cin >> p >> s;
        p--;
        if (ok[p]) continue;
        if (s == "AC") {
            ok[p] = true;
        } else {
            cnt[p]++;
        }
    }
    int cor = 0, wor = 0;
    rep (i, n) {
        if (!ok[i]) continue;
        wor += cnt[i];
        if (ok[i]) cor++;
    }
    cout << cor << " " << wor << endl;

    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = a; i < (ll)n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= (ll)a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007

template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T, class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<char c = ' ',class T> void write(T a){cout << fixed << setprecision(4) << a << endl;}
template<char c = ' ',class T,class ...Args> void write(T a, Args... args){cout << fixed << setprecision(4) << a << c; write<c>(args...);}
template<class T> void warr(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ull gcd(ull a, ull b){while(true){ull k = a % b;if(k == 0)return b;a = b;b = k;}}
ull comb(ull n, ull m){ull p=1;m=min(m,n-m);for(ull i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int main(void)
{
    int n;
    while(true){
        map<int,int> m;
        read(n);
        if(n==0)break;
        pair<int,int> res(0,0);
        rep(i,n){
            int a;
            read(a);
            int &t=m[a];
            t++;
            res=max(res,pair<int,int>(t,a));
        }
        if(res.first>n/2)write(res.second);
        else write("NO COLOR");
    }
    return 0;
}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;



const int MAXN = (int)1e5+1;
int N, M, state[MAXN];
vector<vector<int>> graph;
vector<vector<int>> in;
vector<int> res;
int dist[MAXN];

bool contains_cycle;

void topo_sort(int a)
{
    state[a] = 1;
    for(int i=0; i<graph[a].size(); i++)
    {

        if(state[graph[a][i]] == 1)
        {
            contains_cycle = true;
            return;
        }

        if(state[graph[a][i]] == 2)
        {
            continue;
        }

        topo_sort(graph[a][i]);
    }
    res.PB(a);
    state[a] = 2;
}

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M;
    graph.resize(N);
    in.resize(N);
    for(int i=0; i<M; i++)
    {
        int x, y;
        cin >> x >> y;
        x--; y--;
        graph[x].PB(y);
        in[y].PB(x);
    }
    for(int i=0; i<N; i++)
    {
        if(!state[i])
        {
            topo_sort(i);
        }
    }
    int ans = 0;
    for(int i=N-1; i>=0; i--)
    {
        int x = res[i];
        for(int j=0; j<in[x].size(); j++)
        {
            dist[x] = max(dist[x], dist[in[x][j]]+1);
        }
        ans = max(ans, dist[x]);
    }
    cout << ans;


    return 0;
}


Measured memory_bytes: 13820
b0=input().split()
N=int(b0[0])
L=int(b0[1])

h0=input().split()
hl=[int(h) for h in h0]

nl=[0 for x in range(N)]
for l in range(L):
  l0=input().split()
  h1=int(l0[0])-1
  h2=int(l0[1])-1
  if hl[h1]>hl[h2]:
    nl[h2]+=1
  elif hl[h1]<hl[h2]:
    nl[h1]+=1
  else:
    nl[h1]+=1
    nl[h2]+=1

A=0
for nn in nl:
  if nn==0:
    A+=1
    
print(A)

Measured memory_bytes: 20848
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    long long N, A, B;
    cin >> N >> A >> B;
    unsigned long long result = 0;
    unsigned long long round = N / (A + B);
    unsigned long long left = N % (A + B);
    result = round * A;
    if(left > A) 
        result += A;
    else
        result += left;
    cout << result << endl;
}

Measured memory_bytes: 256
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

K = ri()
S = rs()

class CombMod:
    def __init__(self, N):
        self.fact = [1]
        self.rfact = [1]
        for i in range(1, N+1):
            self.fact.append(self.fact[i-1]*i % mod)
            self.rfact.append(pow(self.fact[i], mod-2, mod))

    def comb(self, n, k):
        return self.fact[n]*self.rfact[k]*self.rfact[n-k] % mod

N = len(S)
cm = CombMod(K+N)

pows = [1]
pows2 = [1]
p = 1
p2 = 1
for i in range(K+1):
	p = (p * 25) % mod
	p2 = (p2 * 26) % mod
	pows.append(p)
	pows2.append(p2)
#print(pows)
ans = 0
for i in range(K+1):
	#ans += cm.comb(K+N-i-1, N-1) * pow(26, i, mod) * pow(25, K-i, mod)
	ans += cm.comb(K+N-i-1, N-1) * pows2[i] * pows[K-i]
	ans = ans % mod
print(ans)


Measured memory_bytes: 202660
from bisect import bisect
s=input()
n=len(s)
ls=[0]*26
if s == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
if n<26:
  for i in range(n):
    ls[ord(s[i])-97]=i+1
  for i in range(26):
    if ls[i]==0:
      x=i
      break
  print(s+chr(x+97))
else:
  for i in range(n):
    ls[i] = ord(s[i])-97
  if ls[25]>ls[24]:
    print(s[:24]+s[25])
  else:
    tmp = []
    for i in range(24,-1,-1):
      tmp.append(ls[i+1])
      if ls[i+1]>ls[i]:
        tmps = sorted(tmp)
        x = bisect(tmps,ls[i])
        print(s[:i]+chr(tmps[x]+97))
        break

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

const int64 mod = 1e9+7;

using Row = vector<int64>;
using Mat = vector<Row>;

int64 N;
vector<int64> a;

int64 s(vector<int64>& a, int32 l, int32 r){
	return a[r]-a[l];
}

int main(void){
	cin >> N;
	a.resize(N);
	vector<int64> sum(N+1);
	REP(i, N) cin >> a[i];
	REP(i, N) sum[i+1] = sum[i]+a[i];
	Mat dp(N+1, Row(N+1, INF_LL));
	REP(i, N) dp[i][i] = 0;
	REP(i, N) dp[i][i+1] = 0;
	FOR(d, 1, N+1){
		REP(l, N-d+1){
			int32 r = l+d;
			FOR(k, l, r+1){
				chmin(dp[l][r], dp[l][k] + dp[k][r] + s(sum, l, k) + s(sum, k, r));
			}
		}
	}
	cout << dp[0][N] << endl;
}



Measured memory_bytes: 1536
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
       
    int H, W;
 
        while (true) {
            H = scanner.nextInt();
            W = scanner.nextInt();
 
            if (H == 0 && W == 0)
                break;
 
            for (int i = 0; i < H; i++) {
                for (int i2 = 0; i2 < W; i2++) {
                    System.out.print("#");
                }
 
                System.out.println();
            }
 
            System.out.println();
        }
    }

}

Measured memory_bytes: 35072
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

const ll mod = 1e9 + 7;

void solve() {
    ll ans = 1, n, a[100001], i, j, k, cnt[100001];
    fo(i,100001)cnt[i]=0;
    cin>>n;
    fo(i,n)cin>>a[i];
    fo(i,n) {
        if(a[i]==0) {
            ans = (ans * (3ll-cnt[0])) % mod;
        } else {
            ans = (ans * (cnt[a[i]-1]-cnt[a[i]])) % mod;
        }
        cnt[a[i]]++;
    }
    cout<<ans;
}

int main()
{
    fastIO;ll t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
bool notPrime(int x) {
  for(int d = x-1; d>1; --d) if(x%d == 0) return true;
  return false;
}
int main(){
  int n;
  cin >> n;
  int j=2;
  for(int i=0;i<n;++i) {
    if(i) cout << ' ';
    for(j+=5;notPrime(j);j+=5);
    cout << j;
  }
  cout << endl;
  return 0;
}

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

    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine().Select(c=>int.Parse(c.ToString())).ToArray();
            var borrow = false;
            for(var i = N.Count()-1;0<=i;i--)
            {
                if (borrow && 0 < N[i])
                {
                    N[i]--;
                    borrow = false;
                }
                if (i == 0) break;
                if(N[i]==9) continue;
                N[i] = 9;
                borrow = true;
            }
            Console.WriteLine(N.Sum());
        }
    }

Measured memory_bytes: 13396
#include <iostream>
using namespace std;
int main(){
  int a,b,n,s,f,i=0;
  cin >> a >> b >> n;
  while(1){
    cin >> s >> f;
    if((a >= s && b <= f) || (s > a && s < b) || (f > a && f < b)){
      cout << '1' << endl;
      break;
    }
    if(++i >= n){
      cout << '0' << endl;
      break;
    }
  }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define ll long long int
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
ll M=1000000007,dp[1005][1005],n,m;
char g[1005][1005];
bool ok(ll i, ll j)
{
    if(i>=0&&i<n&&j>=0&&j<m&&g[i][j]=='.')return true;
    return false;
}
ll f(ll i, ll j)
{
    if(i==n-1&&j==m-1)return 1;
    if(dp[i][j]!=-1)return dp[i][j];
    ll r=0;
    if(ok(i,j+1))
        r+=f(i,j+1);
    if(ok(i+1,j))
        r+=f(i+1,j);
    return dp[i][j]=r%M;
}
int main()
{
    scanf("%lld%lld",&n,&m);
    getchar();
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            scanf("%c",&g[i][j]);
        }
        getchar();
    }
    mem(dp,-1);
    ll ans=f(0,0);
    printf("%lld\n",ans);
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b == c || a+c == b || b+c == a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}



Measured memory_bytes: 256
s = list(input())
t = list(input())
n = len(s)
m = len(t)
for i in reversed(range(n-m+1)):
    for j in range(m):
        if (s[i+j] != '?' and s[i+j] != t[j]):
            break
    else:
        s[i:i+m] = t
        for k in range(n):
            if(s[k]=='?'):
                s[k] = 'a'
        print(''.join(s))
        exit()
print('UNRESTORABLE')

Measured memory_bytes: 3064
#include <climits>
#include <algorithm>
#include <iostream>

using namespace std;

const int MAX_N = 1 << 17;

int n, dat[2*MAX_N-1];

void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  for(int i=0;i<2*n-1;i++) dat[i] = INT_MAX;
}

void update(int k, int a){
  k += n - 1;
  dat[k] = a;
  while(k > 0){
    k = (k - 1) / 2;
    dat[k] = min(dat[k*2+1], dat[k*2+2]);
  }
}

//min [a, b)
//call query(a, b, 0, 0, n)
int query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return INT_MAX;
  if(a <= l && r <= b) return dat[k];
  else{
    int vl = query(a, b, k*2+1, l, (l+r)/2);
    int vr = query(a, b, k*2+2, (l+r)/2, r);
    return min(vl, vr);
  }
}

main(){
  int m, q;
  cin >> m >> q;
  init(m);
  for(int i=0;i<q;i++){
    int a, b, c;
    cin >> a >> b >> c;
    if(a) cout << query(b, c+1, 0, 0, n) << endl;
    else update(b, c);
  }
}

Measured memory_bytes: 2184
program AGC008A
    implicit none
    integer(8)::x,y
    integer(8)::result=0
    read(5,*)x,y

    result=result+abs(abs(x)-abs(y))

    if(x*y>0 .and. x>y)then
        result=result+2
    else if(x*y<0)then
        result=result+1
    else if(x==0 .and. y<0)then
        result=result+1
    else if(x>0 .and. y==0)then
        result=result+1
    end if

    print'(i0)',result

end program AGC008A

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  int Asize, Bsize;

  Asize=A.size();
  Bsize=B.size();

  if(A.at(Asize-1)==B.at(0) && B.at(Bsize-1)==C.at(0)){
    cout << "YES";
  }
  else{
    cout << "NO";
  }

return 0;  
}

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


int main(){
    ll n; cin>>n;
    if(n%10==7) cout<<"Yes"<<endl;
    else if((n/10)%10==7) cout<<"Yes"<<endl;
    else if(n/100==7) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
n, a, b = [int(x) for x in input().strip().split()]
if (a + b) % 2 == 0:
    print((b - a) // 2)
else:
    if a - 1 <= n - b:
        ans = a - 1
        b -= ans
        if b % 2 == 0:
            ans += 1
            b -= 1
        ans += (b - 1) // 2
    else:
        ans = n - b
        a += ans
        if (n - a) % 2 == 1:
            ans += 1
            a += 1
        ans += (n - a) // 2
    print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int h,w;
    cin >> h >> w;
    char s[h+2][w+2];
    for(int i=0;i<h+2;i++){
        if(i==0 || i==h+1){
            for(int j=0;j<w+2;j++) s[i][j]='.';
        }else{
            for(int j=0;j<w+2;j++){
                if(j==0 || j==w+1){
                    s[i][j]='.';
                }else{
                    cin >> s[i][j];
                }
            }
        }
    }

    /*for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            cout << s[i][j];
        }
        cout << endl;
    }*/

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(s[i][j]=='#'){
                if(s[i+1][j]=='.' && s[i-1][j]=='.' && s[i][j+1]=='.' && s[i][j-1]=='.'){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    
    cout << "Yes" << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
long long a[1000005],b[1000005];
int main()
{
	long long n,A,B;
	cin>>n>>A>>B;
	long long m=A-B;
	for(int i=1;i<=n;++i) cin>>a[i];
	long long l=1,r=1000000000;
	while(l<r)
	{
		long long mid=(l+r)/2;
		long long q=mid;
		for(int i=1;i<=n;++i)
		{
			b[i]=a[i];
			b[i]-=mid*B;
			if(b[i]>0)
			{
				long long a1=b[i]/m;
				long long a2=b[i]%m;
				if(a2!=0) a2=1;
				q-=a1+a2;
			}
		}
		if(q<0) l=mid+1;
		else r=mid;
	 } 
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define line cout<<"\n"
#define ci std ::cin
#define co std ::cout
#define sf(n) scanf("%d",&n);
#define sff(n,m) scanf("%d%d",&n,&m);
#define pf(n) printf("%d",n);
#define n_line printf("\n");
#define cas(n) printf("Case %d: ",n++);
#define task return
#define loop(x,n)  for(int x = 0 ; x < n ; x++)
#define constloop(x,a,n) for(int x = a ; x < n ; x++)
#define revloop(x,a,n)  for(int x = a ; x >= n ; x--)
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define pi acos(-1)
#define mx 10000000
ll P[mx+5],cnt=1;
bool nP[mx+5];
void sieve(void)
{
    P[0]=2;
    nP[0]=true;
    nP[1]=true;
    for(ll i=3 ; i<=mx ; i+=2)
    {
        if(nP[i]==true)
            continue;
        for(ll j=i+i ; j<=mx ; j+=i)
            nP[j]=true;
        P[cnt++]=i;
    }
}
void solve()
{
    //Code here
 	ll n;
 	cin>>n;
 	ll A[200000+5];
 	for(int i=0 ; i<n ; i++)
 	{
 		cin>>A[i];
 	}
 	ll sum=0;
 	for(int i=0 ;  i<n-1 ; i++)
 	{
 		if(A[i+1]<A[i])
 		{
 			sum+=A[i]-A[i+1];
 			A[i+1]=A[i];
 		}
 	}
 	cout<<sum;
 	line;
}
int main()
{
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	/*ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);*/
	solve();
	return 0;
}

Measured memory_bytes: 5180
$ans = 0

def dfs(a_array, a, b, c, d, n, m, q)
  haire = []
  a_array.size.times do |i|
    haire.push(a_array[i])
  end
  if a_array.size== n
    num = 0
    q.times do |i|
      if a_array[b[i] - 1] - a_array[a[i] - 1] == c[i]
        num += d[i]
      end
    end
    hai = [$ans, num]
    $ans = hai.max
  else
    num = 1
    if haire.size != 0
      num = haire[haire.size - 1]
    end
    for i in num..m do
        haire << i
        dfs(haire, a, b, c, d, n, m, q)
        haire.pop
    end
  end
end

n, m, q = gets.split(" ").map!{|i| i.to_i}

a = []
b = []
c = []
d = []
q.times do |i|
  hai = gets.split(" ").map!{|i| i.to_i}
  a << hai[0].to_i
  b << hai[1].to_i
  c << hai[2].to_i
  d << hai[3].to_i
end

a_array = []
dfs(a_array, a, b, c, d, n, m, q)

puts $ans

Measured memory_bytes: 14636
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int n;
int a[101];
int main()
{
	cin >> n;
	REP(i, 0, n) cin >> a[i];

	sort(a, a + n);
	reverse(a, a + n);

	int alice = 0;
	int bob = 0;
	REP(i, 0, n) {
		if (i % 2 == 0) alice += a[i];
		else bob += a[i];
	}
	cout << alice - bob << endl;
	return 0;
}

Measured memory_bytes: 256
# from sys import stdin
import sys
global cnt1


def bts(A, cnt, max):
    # print(A)
    if cnt == max:
        global cnt1
        cnt1 = cnt1+1
        if cnt1 == K:
            print(A)
            sys.exit()
        return
    cnt = cnt+1
    if A % 10 == 0:
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)
    elif A % 10 == 9:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
    else:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)


K = int(input())
# print(K)
N = 9
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# global cnt1
cnt1 = 0
for k in range(1, 11):
    for i in range(len(A)):
        bts(A[i], 1, k)
# print(cnt1)


Measured memory_bytes: 3188
import java.util.*;
public class Main {
	Scanner stdin=new Scanner(System.in);
	int w,h;
	int[][] field;
	int[] dx={-1,-1,-1,0,0,1,1,1};
	int[] dy={-1,0,1,1,-1,-1,0,1};
	
	int count;
	
	
	
	
	public void Solve(){
		h=1;
		while(true){
			
			
			count=0;
			w=stdin.nextInt();
			h=stdin.nextInt();
			if(w==0&&h==0) break;
			field=new int[h][w];
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					field[i][j]=stdin.nextInt();
				}
			}
			
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					if(field[i][j]==1){
						dfs(i,j);
						count++;
					}
					
				}
			}
			System.out.println(count);
		}
		
		
		
	}
	
	public void dfs(int x,int y){
		//System.out.println(x+","+y);
		field[x][y]=0;
		for(int i=0;i<8;i++){
			int xx=x+dx[i];
			int yy=y+dy[i];
			if(xx>=0&&xx<h&&yy>=0&&yy<w){
				if(field[xx][yy]==1) dfs(xx,yy);
			}
		}
	}
	
	
	public static void main(String args[]){
		Main m =new Main();
		m.Solve();
		
	}
}

Measured memory_bytes: 43148
n = int(input())
s = list(map(int, input().split()))


def cost(t):
    res = 0
    sum = 0
    for y in s:
        sum += y
        if sum * t <= 0:
            res += abs(sum - t)
            sum = t
        t *= -1
    return res


print(min(cost(1), cost(-1)))


Measured memory_bytes: 14332
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

inline set<long long> factorize(const long long n) {
    set<long long> factors;
    long long i = 2;
    long long j = n;
    while (i * i <= n && j != 1) {
        long long cnt = 0;
        while (j % i == 0) {
            ++cnt;
            j /= i;
        }
        if (cnt > 0)
            factors.insert(i);
        ++i;
    }
    if (j > 1)
        factors.insert(j);
    return factors;
}

// n以下の素数列挙
inline vector<long long> prime_numbers(long long n) {
    vector<long long> primes;
    for (long long i = 2; i <= n; ++i) {
        bool is_prime = true;
        for (int j = 0; j < primes.size(); ++j) {
            if (primes[j] * primes[j] > i)
                break;
            if (i % primes[j] == 0) {
                is_prime = false;
                break;
            }
        }
        if (is_prime)
            primes.push_back(i);
    }
    return primes;
}

int main() {
    int n, k, s; cin >> n >> k >> s;
    auto fact = factorize(s);
    auto primes = prime_numbers(n);
    int t = 1;
    for (auto p: primes) {
        if (fact.count(p) == 0) {
            t = p;
            break;
        }
    }
    for (int i = 0; i < k; ++i) {
        cout << s << " ";
    }
    for (int i = 0; i < n - k; ++i) {
        cout << t << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }



int main()
{
	int n;
	ll ans, tmp, s;
	vll a;

	cin >> n;
	a.resize(n);
	REP(i, n)
		cin >> a[i];

	s = a[0];
	tmp = 0;
	if (s <= 0)
	{
		tmp += (1 - s);
		s = 1;
	}
	REP1O(i, n)
	{
		if (!(s + a[i]) || (s ^ (s + a[i])) >= 0)
		{
			if (s > 0)
			{
				tmp += 1LL + s + a[i];
				s = -1;
			}
			else
			{
				tmp += 1LL - (s + a[i]);
				s = 1;
			}
		}
		else
			s += a[i];
	}

	ans = tmp;

	s = a[0];
	tmp = 0;
	if (s >= 0)
	{
		tmp += 1LL + s;
		s = -1;
	}
	REP1O(i, n)
	{
		if (!(s + a[i]) || (s ^ (s + a[i])) >= 0)
		{
			if (s > 0)
			{
				tmp += 1LL + s + a[i];
				s = -1;
			}
			else
			{
				tmp += 1LL - (s + a[i]);
				s = 1;
			}
		}
		else
			s += a[i];
	}

	chmin(ans, tmp);

	cout << ans << endl;

}


Measured memory_bytes: 1024
import sys

input = sys.stdin.readline


def main():
    s = int(input())

    a = set([s])
    i = s
    while True:
        if i % 2 == 0:
            i = i // 2
        else:
            i = 3 * i + 1
        
        if i in a:
            ans = len(a) + 1
            break
        else:
            a.add(i)

    print(ans)


if __name__ == "__main__":
    main()


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

int main(void){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++) cin >> vec.at(i);

    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    int a=0,b=0;
    for(int i=0;i<vec.size();i++){
        //cout << vec.at(i) << endl;
        if(i%2==0) a+=vec.at(i);
        else b+=vec.at(i);
    }
    cout << a-b << endl;
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())

cnt = 0
A, B, C = sorted([A, B, C])

while A < C:
    A += 2
    cnt += 1
if (A > C):
    A -= 2
    cnt -= 1

while B < C:
    B += 2
    cnt += 1
if (B > C):
    B -= 2
    cnt -= 1

if (A == C and B == C):
    print(cnt)
elif (A == C and B != C) or (A != C and B == C):
    print(cnt + 2)
else:
    print(cnt + 1)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp> 
boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;

/************ Use when precision need to set to some value **************/
// std::cout << std::setprecision(12);
// std::cout << std::fixed;
/*******************************************/
int max(int a,int b){
	if(a > b)return a;
	else return b;
}

int min(int a, int b){
	if(a < b)return a;
	else return b;
}
/*		0. Go to main function first.
		1. Take all the inputs................................................
		2. Check Once whether the graph given is directed or undirected.......
		3. Tree can also be undirected.
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	double d;
	cin >> d;
	double ans = d*d*d;
	cout << ans/27 << endl;
}
/*
	memset() can be used to set all values as 0 or -1 for integer data types.
	It will not work if we use it to set as other values.
	The reason is memset works byte by byte.
*/

int main(){
	IO;

	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif // ONLINE_JUDGE

	std::cout << std::setprecision(12);
	std::cout << std::fixed;

	int t;
	// cin >> t;
	t = 1;
	while(t--){
		solve();
	}
	return 0;
}

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

int main(){
    int N; cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) cin >> v[i];

    vector<int> v_sort = v;
    sort(v.begin(), v.end());

    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if(v[i]!=v_sort[i]) cnt++;
        if(cnt>2) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
typedef long long ll;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n&1){
        cout << "No";
    }
    else{
        for(int i=0;i<n/2;i++){
            if(s[i]!=s[i+n/2]){
                cout << "No";
                return 0;
            }
        }
        cout << "Yes";
    }
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST

solve :: Int -> Int -> [(Int,Int,String)] -> Int
solve n k xycs = answer where
  _cell :: VU.Vector Int
  _cell = VU.create $ do
    vec <- VUM.replicate (k*k) 0
    forM_ (map (absPt k) xycs) $ \(x,y,t) -> VUM.modify vec (+ t) (enc x y)
    return vec
  
  enc :: Int -> Int -> Int
  enc x y = x*k + y
  cell x y = _cell VU.! (enc x y)

  bars0 = [sum [cell i j | i <- [0..k-1]] | j <- [0..k-1]]
  val0 = sum bars0

  starts = unfoldr f (0, val0, bars0) where
    f (i, val, bars) | i == k = Nothing
                     | otherwise = Just ((val, bars), (i+1, val', bars'))
      where
      bars' = map g (zip [0..] bars) where
        g (j,x) = x - 2 * cell i j
      val' = val - sum [2 * cell i j | j <- [0..k-1]]

  calcV (val, bars) = maximum (map abs (scanl' (-) val (map (* 2) bars)))

  answerXX = (n + (maximum (map calcV starts))) `div` 2

  answer = answerXX

absPt k (x,y,c) =
  let (dx, mx) = divMod x k
      (dy, my) = divMod y k
      t | (head c == 'B') `xor` (dx `mod` 2 == 1) `xor` (dy `mod` 2 == 1) =  1
        | otherwise                                                       = -1
  in (mx, my, t)

xor :: Bool -> Bool -> Bool
xor x y = ((not x) && y) || (x && not y)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_k]:remLines1 = remLines0
      n = readBInt bs_n
      k = readBInt bs_k
      xycs = map (\[x1,x2,x3] -> (readBInt x1,readBInt x2,B.unpack x3)) remLines1
  in solve n k xycs

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 11260
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String w = input.readLine();
		String t;
		int num = 0;

		while (!(t = input.readLine()).equals("END_OF_TEXT")) {
			t = t.toLowerCase();
			Scanner scan = new Scanner(t);
			while (scan.hasNext()) {
				String str = scan.next();
				if (str.equals(w))
					num++;
			}

		}

		System.out.println(num);
	}
}

Measured memory_bytes: 18864