akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll N, P, idx[100001] = {}, l[2] = {}, r[2] = {}, ans = 0;
multiset<ll> s;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> P;
		idx[P] = i;
	}
	s.insert(0);
	s.insert(0);
	s.insert(N + 1);
	s.insert(N + 1);
	for (int i = N; i > 0; i--) {
		s.insert(idx[i]);
		auto it = s.find(idx[i]);
		it--;
		l[0] = *it;
		it--;
		l[1] = *it;
		it = s.find(idx[i]);
		it++;
		r[0] = *it;
		it++;
		r[1] = *it;
		ans += i * ((l[0] - l[1]) * (r[0] - idx[i]) + (idx[i] - l[0]) * (r[1] - r[0]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int N;
  cin >> N;
  vector<i64> a(N);
  bool ok = true;
  for(int i = 0;i < N;i++) {
    cin >> a[i];
    if(a[i] % 2 != 0) {
      ok = false;
    }
  }

  if(ok) {
    cout << "second" << endl;
  }
  else{
    cout << "first" << endl;
  }
}


Measured memory_bytes: 1024
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

int isUnder(int T,int A){ // AがT以下で1,それ以外0
    if(A<=T) return 1;
    else return 0;
}

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    int a[3] = {300000,200000,100000};
    Cinii(x,y);
    cout << ((x<=3)? a[x-1]:0) + ((y<=3)? a[y-1]:0 ) + ((x==1&&y==1)?400000:0) << nn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> u(n);
  vector<int> d(n);
  int i,j;
  for(i=0;i<n;i++) cin >> u[i];
  for(i=0;i<n;i++) cin >> d[i];
  int max = 0;
  for(i=0;i<n;i++){
    int uu = 0;
    int dd = 0;
    for(j=0;j<=i;j++) uu += u[j];
    for(j=i;j<n;j++) dd += d[j];
    if(max<uu+dd) max = uu+dd;
  }
  cout << max << "\n";
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>

using namespace std;

int main() {
  int x;
  cin >> x;
  
  bool isprime[1000000];
  for (int i=2; i<1000000; i++) {
    isprime[i] = true;
  }
  for (int i=2; i<1000000; i++) {
    if (isprime[i]) {
      for (int j=i*2; j<1000000; j+=i) {
        isprime[j] = false;
      }
    }
  }
  
  for (int i=x; i<1000000; i++) {
  	if (isprime[i]) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


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


template <typename T>
bool chmin(T& a, T b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

std::vector<int> dp;
int n, k;
std::vector<int> vec(100000+101, 0);
int INF = 1000000002;

int main() {
    std::cin >> n >> k;
    dp.assign(100100, INF);
    for (int i = 0; i < n; i++) {
        std::cin >> vec[i];
    }
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int p = 1; p <= k; p++) {
            chmin(dp[i+p], dp[i]+std::abs(vec[i]-vec[i+p]));
        }
    }
    std::cout << dp[n-1] << std::endl;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(b-a == c-b) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
char tate[1000][500],yoko[500][1000];
char co[1000][1001];
int main(void)
{
	int i,j,c,n,d,dr,dc,cnt,tc,yc,d2;
	scanf("%d %d",&c,&n);
	for(i=0;i<n;i++)	{
		scanf(" %s",co[i]);
	}
//	for(i=0;i<n;i++)	printf("%s\n",co[i]);
	tc=0;
	for(i=0;i<n;i++)	{
		for(j=0;j<n/2;j++)	{
			if(co[i][j]==co[i][n-j-1])	{
				tate[i][j]=0;
			}
			else {
				tate[i][j]=1;
				tc++;
			}
		}
	}
	yc=0;
	for(j=0;j<n;j++)	{
		for(i=0;i<n/2;i++)	{
			if(co[i][j]==co[n-i-1][j])	{
				yoko[i][j]=0;
			}
			else {
				yoko[i][j]=1;
				yc++;
			}
		}
	}
	if(yc==0 && tc==0)	cnt=1;
	else cnt=0;
	for(i=1;i<c;i++)	{
		scanf("%d",&d);
		for(j=0;j<d;j++)	{
			scanf("%d %d",&dr,&dc);
			dr--;	dc--;
//			printf("  %d %d\n",dr,dc);
			if(dc>=n/2)	d2=n-dc-1;
			else d2=dc;
//			printf(" dr=%d d2=%d\n",dr,d2);
			if(tate[dr][d2]==1)	{
				tate[dr][d2]=0;
				tc--;
			}
			else {
				tate[dr][d2]=1;
				tc++;
			}
			if(dr>=n/2)	d2=n-dr-1;
			else d2=dr;
			if(yoko[d2][dc]==1)	{
				yoko[d2][dc]=0;
				yc--;
			}
			else {
				yoko[d2][dc]=1;
				yc++;
			}		
//			printf("tc=%d yc=%d\n",tc,yc);
		}
		if(tc==0 && yc==0)	cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}
	


Measured memory_bytes: 4704
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(x,n) for(int i=x;i<n;i++)
#define REP(y,n) for(int j=y;j<n;j++)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
string shuffle(string S,int h){
  rep(0,h){
    S.pb(S[0]);
    S.erase(S.begin());
  }
  return S;
}
signed main(){
  string S;
  int h;
  while(true){
    cin>>S;
    if(S=="-")break;
    cin>>h;
    int m[h];
    rep(0,h){
      cin>>m[i];
      S=shuffle(S,m[i]);
    }
    cout<<S<<endl;
  }
}



Measured memory_bytes: 3200
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s | da < db = "A"
        | db < da = "B"
 where
  [x, a, b] = fmap read (words s) :: [Int]
  da        = abs (x - a)
  db        = abs (x - b)

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
#include<stdio.h>
long long int min(long long int*);
long long int max(long long int*);
long long int sum(long long int*);
#define FOR for(i=1;i<N;i++)
int N;
main() {
	int i;
	long long int a[10000];
	scanf("%d", &N);
	for (i = 0;i < N;i++) {
		scanf("%lld", &a[i]);

	}

	printf("%lld %lld %lld\n", min(a), max(a), sum(a));
	return 0;

}
long long int min(long long int *KNN) {
	int i;
	long long int kotae = KNN[0];
	FOR{
		if (kotae> KNN[i])
		kotae = KNN[i];
	}
	return kotae;


}

long long int max(long long int *KNN) {
	int i;
	long long int kotae = KNN[0];
	FOR{
		if (kotae < KNN[i]) {
			kotae = KNN[i];
		}
	}
	return kotae;

}

long long int sum(long long int *KNN) {
	int i;
	long long int kotae = KNN[0];
	FOR{
		kotae += KNN[i];
	}
	return kotae;
}


Measured memory_bytes: 2120
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin>>a>>b>>c;
    string ans;
    ans="No";
    if(a<c&&c<b){
        ans="Yes";
    }
    if(a>c&&c>b){
        ans="Yes";
    }cout<<ans;
    
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

const int MAX=510000;
const int mod=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a){
  return modpow(a,mod-2);
}

void init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  rep(i,MAX){
    if(i>1){
      fac[i]=fac[i-1]*i%mod;
      inv[i]=mod-inv[mod%i]*(mod/i)%mod;
      finv[i]=finv[i-1]*inv[i]%mod;
    }
  }
}

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

int main(){
  int N,K;
  cin>>N>>K;
  VI A(N);
  rep(i,N) cin>>A[i];
  sort(all(A));
  ll ans=0;
  ll mod=1e9+7;
  init();
  rep(i,N) (ans+=A[i]*com(i,K-1)%mod)%=mod;
  rep(i,N) (ans+=mod-A[i]*com(N-i-1,K-1)%mod)%=mod;
  cout<<ans<<endl;
}


Measured memory_bytes: 12544
using System;
using System.Web;
using System.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using static System.Math;
 

class P
{
    static void Main()
    {
        Console.WriteLine(Regex.IsMatch(Console.ReadLine(), "^A[a-z]+C[a-z]+$") ? "AC" : "WA");
    }
}


Measured memory_bytes: 15960
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  int K;
  cin >> K;
  if(K%2==0) cout << (K/2)*(K/2) << endl;
  else cout << (K/2)*((K+1)/2) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;

int main() {
	string S;
  in(S);
  int N=sz(S);
  bool a=false,b=false,c=false,d=false;
  
  rep(i,N){
   if(S[i] =='W') b = true;
  if(S[i] =='N' )a = true;
  }
  rep(i,N){
   if(S[i] =='E') c = true;
    if(S[i] == 'S')d= true;
  }
  if(a==d&&b==c) out("Yes");
  else  out("No");
}


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

int main(){
  int num;
  int cnt = 0;
  int index = 1;
  int tmp;
  
  cin >> num;
  
  for(int i = 0; i < num; i++){
    cin >> tmp;
    if(tmp == index){
      index++;
    }else{
      cnt++;
    }
  }
  
  if(index - 1 == num) cout << 0;
  else if(cnt == 0 || cnt == num) cout << -1;
  else cout << cnt;
}

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

using namespace std;

#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using i64 = long long;
using iip = pair<int, int>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }

// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

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

    string s, t;
    while (cin >> s >> t) {
        int ans = 0;
        forn(i, s.size()) {
            ans += s[i] == t[i];
        }
        cout << ans << endl;
    }
}


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

if n%2==1:
    sentou = a.pop(0)
    if sentou!=0:
        print("0")
        exit()
    nxt=2
else:
    nxt=1

ans=1
i=0
while i < len(a):
    if a[i] == nxt and a[i+1] == nxt:
        ans*=2
        ans%=10**9+7
        nxt+=2
        i+=2
    else:
        print("0")
        exit()
print(ans)

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

int main() {
    string S;
    cin >> S;
    reverse(S.begin(),S.end());
    vector<string> t = {"dream","dreamer","erase","eraser"};
    for(int i=0;i<4;i++){
        reverse(t[i].begin(),t[i].end());
    }
    ll N = S.size();
    string substr = "";
    for(int i=0;i<N;i++){
        substr += S[i];
        if(t.size()>7){
            break;
        }
        for(int j=0;j<4;j++){
            if(substr ==t[j]){
                substr ="";
                break;
            }
        }
    }
    if(substr.size()==0){
        cout << "YES" << endl;
    }else{
        cout <<"NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double a;
	cin>>a;
	int ans=100000;
	for(int b=0;b<a;b++)
	{
		double rev=0;
	   ans=ans*1.05;
	   rev=ans%1000;
	   if(rev!=0)
	   ans=ans-rev+1000;
		}
		cout<<ans<<endl;
	}

Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <cmath>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <deque>
#define F first
#define S second
#define MAX_N 32
#define MAX_D 32
#define INF (1<<28)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
typedef pair<double,double> P;
typedef pair<int,P> iP;
typedef pair<int,int> iiP;
typedef pair<iiP,P> PP;
typedef vector<vector<iP> > VViP;
int n,m,s,g;
VViP G;
double mincost[MAX_N][MAX_N][MAX_D]; // mincost[from][to][speed]
int sp[] = {-1,0,+1};

void dijkstra()
{

  deque<PP> deq; // iiPP(iiP(now,pre),P(cost,speed))

  
  deq.push_front(PP(iiP(s,s),P(0,1)));

  mincost[s][s][1] = 0; 
  double ans = INF;  

  
  while(!deq.empty())
    {
      PP p = deq.front(); deq.pop_front();
      int now,pre;
      double cost,speed;
      now = p.F.F, pre = p.F.S;
      cost = p.S.F, speed = p.S.S;

      if(cost >= ans)
	continue;      

      if(now == g && speed == 1)
	{
	  ans = min(ans,cost);	
	  continue;
	}	

      for(int i=0;i<G[now].size();i++)
	{
	  iP ip = G[now][i]; // VViP -> iP(to,P(distance,limit))
	  int to = ip.F;
	  double dis,lim;
	  dis = ip.S.F, lim = ip.S.S;
	  if(pre == to)
	    continue;

	  for(int j=0;j<3;j++)
	    {
	      double new_speed = speed + sp[j];
	      if(new_speed <= 0 || new_speed > lim)
		continue;

	      if(now == s && pre == s && new_speed != 1)
		continue;

	      if(mincost[now][to][(int)new_speed] > cost + (double)dis/new_speed)
		{
		  mincost[now][to][(int)new_speed] = cost + (double)dis/new_speed;

		  /*????????????*/
		  if(mincost[now][to][(int)new_speed] < deq.front().S.F)deq.push_front(PP(iiP(to,now),P(mincost[now][to][(int)new_speed],new_speed)));
		  else 
		    deq.push_back(PP(iiP(to,now),P(mincost[now][to][(int)new_speed],new_speed)));
		}
	    }

	}

    }
  

  if(ans == INF)
    cout << "unreachable" << endl;
  else 
    cout << setiosflags(ios::fixed) << setprecision(5) << ans << endl;
  
}

int main()
{

  while(true)
    {
      cin >> n >> m;
      if(n+m == 0)
	break;
      G.clear();
      G.resize(n+1);
      rep(i,n+1)
	rep(j,n+1)
	  rep(k,31)
	    mincost[i][j][k] = INF;

      cin >> s >> g;
      rep(i,m)
	{
	  int x,y;
	  double d,c;
	  cin >> x >> y >> d >> c;
	  G[x].push_back(iP(y,P(d,c)));
	  G[y].push_back(iP(x,P(d,c)));
	}
      
      dijkstra();
  
    }
  return 0;
}

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

using namespace std;

//Shortcut
#define long long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define X first
#define Y second
#define sz size
#define ft(i , a , b) for (long i = (long)a ; i <= (long)b ; i++)
#define fd(i , a , b) for (long i = (long)a ; i >= (long)b ; i--)
#define lt(i , a , b , c) for (long i = (long)a ; i <= (long)b ; i += (long)c)
#define ld(i , a , b , c) for (long i = (long)a ; i >= (long)b ; i -= (long)c)
#define pll pair <long , long>
#define pls pair <long , string>
#define vtl vector <long>
#define vts vector <string>
#define vtp vector <pll>
#define dql deque <long>
#define mll map <long , long>
#define prio priority_queue<pll , vector<pll > , greater<pll> >
#define pushpq(a , b) push({(long) a , (long) b})

//Variable
const long mxN = 1e5 + 5;
const long base = 311;
const long oo = 1e15;
const long MOD = 1e9 + 7;
const long d4i[4] = {-1 , 0 , 1 , 0} , d4j[4] = {0 , 1 , 0 , -1};
const long d8i[8] = {-1 , -1 , 0 , 1 , 1 , 1 , 0 , -1} , d8j[8] = {0 , 1 , 1 , 1 , 0 , -1 , -1 , -1};

long TestCase;
long n , m , u , v , ans;
vtl adj[mxN] , path;
long dp[mxN];
bool visited[mxN];

void dfs(long x) {
    visited[x] = true;
    ft(i , 0  , adj[x].sz() - 1) {
        if (!visited[adj[x][i]]) dfs(adj[x][i]);
    }
    path.pb(x);
}

void Solve() {
    cin >> n >> m;
    ft(i , 1 , m) {
        cin >> u >> v;
        adj[u].pb(v);
    }
    ft(i , 1 , n) if (!visited[i]) dfs(i);
    reverse(path.begin() , path.end());
    ft(i , 0 , path.sz() - 1) {
        u = path[i];
        ft(j , 0 , adj[u].sz() - 1) {
            v = adj[u][j];
            dp[v] = max(dp[v] , dp[u] + 1);
            ans = max(ans , dp[v]);
        }
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    //cin >> TestCase;
    TestCase = 1;
    while(TestCase--)
        Solve();
    return 0;
}

Measured memory_bytes: 12456
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int a[N];
	int b[N];
	vector<int>as[30];
	vector<int>bs[30];
	long long ass[30];
	long long bss[30];
	int p[30];
	f(i, N){
		a[i] = 0;
		b[i] = 0;
	}
	p[0] = 1;
	ass[0] = 0;
	bss[0] = 0;
	f(i, 29){
		p[i + 1] = 2 * p[i];
		ass[i + 1] = 0;
		bss[i + 1] = 0;
	}
	long long n;
	int k;
	long long x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%lld", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		f(j, 29){
			as[j].push_back((a[i] % p[j + 1]));
			if ((a[i] % p[j + 1]) >= p[j])ass[j]++;
		}
	}
	for (int i = 0; i < n; i++){
		scanf("%d", &b[i]);
		f(j, 29){
			bs[j].push_back((b[i] % p[j + 1]));
			if ((b[i] % p[j + 1]) >= p[j])bss[j]++;
		}
	}
	for (int i = 0; i < 29; i++){
		sort(as[i].begin(), as[i].end());
		bs[i].push_back(-1000000000);
		sort(bs[i].begin(), bs[i].end(),greater<int>());
	}
	k = 0;
	f(i, 29){
		ans = 0;
		ans += ((n - ass[i])*bss[i]);
		ans += ((n - bss[i])*ass[i]);

		if (i > 0){
			x = 0;
			f(j, n){
				while (as[i - 1][j] + bs[i - 1][x] >= p[i])x++;
				ans += x;
			}
		}
		if (ans % 2 == 1)k += p[i];
	}

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


	return 0;
}

Measured memory_bytes: 53428
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <fstream>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll long long
#define M 1000000007 
#define MM 998244353
using namespace std;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*ll t,tcitr;
    cin>>t;
    tcitr=0;
    while(tcitr<t)
    {*/
        //cout<<"Case #"<<tcitr+1<<": ";
        ll n,i,j,k;
        cin>>n;
        ll a[n];
        for(i=0;i<n;i++)cin>>a[i];
        ll mx=0,ans=0;
        for(i=0;i<n;i++)
        {
            if(a[i]<mx)
            {
                ans+=(mx-a[i]);
            }
            else mx=a[i];
        }
        cout<<ans<<"\n";
        /*tcitr++;
    }*/
    return 0;
}


Measured memory_bytes: 5216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str1 = sc.nextLine();
		String str2 = sc.nextLine();
		String str3 = sc.nextLine();
		System.out.println(str1.substring(0, 1) + str2.substring(1, 2) + str3.substring(2));
		sc.close();
	}
}

Measured memory_bytes: 21844
# encoding:utf-8
import numpy as np

def main():
	n = int(input())
	m = find_n(n)
	#print(m)
	tmp_st = 1
	if m == -1:
		print("No")
	else:
		ans = np.zeros((m + 1, m))
		for i in range(m):
			tmp_ary = np.array([i for i in range(tmp_st, tmp_st + m - i)])
			tmp_st += m - i
			ans[i, i:] = tmp_ary
			ans[i + 1:, i] = tmp_ary

		print("Yes")
		print(m + 1)
		for i in range(m + 1):
			print(str(m) + " " + " ".join([str(int(x)) for x in ans[i,]]))

			

def find_n(m):
	i = 1
	while True:
		if m == i * (i + 1) / 2:
			return i
		elif i * (i + 1) / 2 > m:
			return -1
		i += 1

if __name__ == '__main__':
	main()

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

int cnt;
void solve(int p, int s) {
	if (!s)cnt++;
	if (!s || !p)return;
	for (int i = p; i >= 1; i--) {
		for (int j = s / (i*i); j > 0; j--)solve(i - 1, s - i*i*j);
	}
}
int main() {
	int n;
	while (scanf("%d", &n), n) {
		cnt = 0;
		solve(17, n);
		printf("%d\n", cnt);
	}
}

Measured memory_bytes: 3144
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int MOD=2019;
char s[N];
int dp[N],cnt[MOD],len;
int main(){
    scanf("%s",s+1);
    len=strlen(s+1);
    int p=1;
    for(int i=len;i>=1;i--){
        dp[i]=((s[i]-'0')*p+dp[i+1])%MOD;
        p=p*10%MOD;
    }
    ll res=0;
    for(int i=len;i>=1;i--){
        if(dp[i]==0) res++;
        res+=cnt[dp[i]];
        cnt[dp[i]]++;
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 4696
n = int(input())
s = []
p = [0] * 101
d = {}
for i in range(n):
    a,b = input().split()
    b = int(b)
    s.append(a)
    p[b] = i+1
    if a in list(d.keys()):
        d[a].append(b)
        continue
    d[a] = [b]
s = sorted(set(s))
for i in s:
    c = sorted(d[i],reverse=True)
    for j in c:
        print(p[j])


Measured memory_bytes: 9032
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll a,b,k;
  cin >> k >> a >> b;
  if(b-a<=2){
    cout << k+1<<endl;
  }else{
    if(k<=a){
      cout << k+1<<endl;
    }else{
      k -= a-1;
      ll ans = a+(k/2)*(b-a);
      if(k%2==1) ans++;
      cout << ans << endl;
    }
  }
}


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

int main() {
    string s;
    int n, k;
    
    cin >> n >> k >> s;
    
    s[k - 1] = s[k - 1] + ('a' - 'A');
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,l;
    scanf("%d",&n);
    int a[n+3],prime[1000],b[1000005],d[1005];
    for(i=1;i<=1000000;i++){
        b[i]=0;
    }
    for(i=1;i<=1000;i++){
        d[i]=1;
    }
    for(i=2;i<=sqrt(1000);i++){
        for(j=2*i;j<=1000;j+=i){
            d[j]=0;
        }
    }
    l=0;
    for(i=2;i<=1000;i++){
        if(d[i]==1){
           prime[l]=i;
           l++;
        }
    }
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    int mx=0;
    for(i=1;i<=n;i++){
        int k=a[i];
        for(j=0;j<l;j++){
            int e=0;
            while(k%prime[j]==0){
               e=1;
               k/=prime[j];
            }
            if(e==1){
               b[prime[j]]++;
               mx=max(mx,b[prime[j]]);
            }
        }
        if(k!=1){
           b[k]++;
           mx=max(mx,b[k]);
        }
    }
    if(mx<=1)
      printf("pairwise coprime\n");
    else if(mx<n)
      printf("setwise coprime\n");
    else
      printf("not coprime\n");
    return 0;
}


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

using namespace std;

int main() {
    string S;

    cin >> S;

    int ans = 0;

    for (int i = 0, j = S.length() - 1; i < j; i++, j--) {
        if (S[i] != S[j]) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}


signed main()
{
    showoff;
    int n,ans = 0;
    cin >> n;
    vector<int>v(n+5);
    FOR(i,1,n+1)cin >> v[i];
    sort(v.begin()+1,v.begin()+n+1);
    FOR(i,1,n+1){
        FOR(j,i+1,n+1){
            int k = lower_bound(v.begin()+1,v.begin()+n+1,v[i]+v[j])-v.begin()-1;
            ans += max(0LL,k-j);
        }
    }
    cout << ans;
    return 0;

}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ....s

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

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


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,t; cin >> n >> t;
    vector<ll> h(n);
    for(ll i=0;i<n;i++){
        cin >> h[i];
    }
    ll sta=0;
    ll tern=0;
    ll res=2e9;
    for(ll i=0;i<n;i++){
        sta+=h[i];
        tern=max(tern,h[i]);
        if(sta>t){
            printf("1\n");
        }
        else{
            res=min(res,(t-sta)/tern+2);
            printf("%d\n",res);
        }
    }
}



Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,h,ans=0,com=0;
    vector<lli> vec;
    lli i,j;
    cin>>n;
    rep(i,0,n){
        cin>>h;
        if(h-com>=0){
            ans+=h-com;
        }
        com=h;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
s = str(input())
d = s.split()
n = int(d[0])
k = int(d[1]) 
ps = str(input())
p = ps.split()
l = []
ans = 0
for i in p:
	i = int(i)
	l += [i]
l.sort()
for j in l[0:k]:
	ans += j
print(ans)

Measured memory_bytes: 62412
#encoding:utf-8
def sort array #バブルソートを用いる。小さい数値を後ろに追いやる
 j = 0
 while j < 4 
  i = 0
  while i < 4
   if array[i] < array[i+1]
    array[i],array[i+1] = array[i+1],array[i] #多重代入を利用して入れ替える
   end
   i += 1
  end
  j += 1
 end

 i = 0
 while i < 5
  if i != 4
   print "#{array[i]} "
   i += 1
  else
   print array[i]
   i += 1
  end
 end
end

numbers = gets.split
numbers.length.times do |i|
 numbers[i] = numbers[i].to_i
end

puts sort numbers

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

int main() {
    //H,Wを入力
    int H, W;
    cin >> H >> W;
    char c[200][200];
    //C_i,jを入力
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            cin >> c[i][j];
        }
    }
    //D_i,jをセット
    for(int i=1; i<=2*H; i++){
        for(int j=1; j<=W; j++){
            cout << c[(i+1)/2][j];
        }
        cout << endl;
    }
}


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

int A, B;
char S[12];

int main()
{
	scanf("%d%d", &A, &B);
	scanf("%s", S);

	for (int i = 0; i < A; ++i) {
		if (!('0' <= S[i] && S[i] <= '9')){
			printf("%s", "No");
			return 0;
		}
	}
	if (S[A] != '-') {
		printf("%s", "No");
		return 0;
	}
	for (int i = A+1; i <= A+B; ++i) {
		if (!('0' <= S[i] && S[i] <= '9')) {
			printf("%s", "No");
			return 0;
		}
	}
	printf("%s", "Yes");
}


Measured memory_bytes: 256
from sys import stdin


def main():
    _ = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    Bs = [int(x) for x in stdin.readline().rstrip().split()]
    result = 0
    for i, b in enumerate(Bs):
        min_ = min(As[i], b)
        result += min_
        As[i] -= min_
        b -= min_

        min_ = min(As[i + 1], b)
        result += min_
        As[i + 1] -= min_
    print(result)


if __name__ == "__main__":
    main()


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  cout << 0 << endl;

  string H;
  cin >> H;

  int lb = 0, ub = (N+1)/2;
  while(ub-lb>1){
	int m = (lb + ub) / 2;
	cout << m*2 << endl;
	string S;
	cin >> S;
	if(S[0] == H[0]){
	  lb = m;
	}
	else if(S[0] == 'V'){
	  return 0;
	}
	else{
	  ub = m;
	}
  }

  cout << ub*2-1 << endl;
  cin >> H;

  return 0;
}


Measured memory_bytes: 852
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	s := make([]int, M)
	c := make([]int, M)
	for i := range s {
		fmt.Scan(&s[i])
		s[i]--
		fmt.Scan(&c[i])
	}
	// fmt.Println("N", N, "M", M, "s", s, "c", c)
	var nmin, nmax int
	if N == 1 {
		nmin, nmax = 0, 9
	} else if N == 2 {
		nmin, nmax = 10, 99
	} else {
		nmin, nmax = 100, 999
	}
	ans := -1
	for i := nmin; i <= nmax; i++ {
		nstr := strconv.Itoa(i)
		// fmt.Printf("%d - %s\n", i, nstr)
		ok := true
		for j := 0; j < M; j++ {
			if s[j] < len(nstr) && nstr[s[j]] == '0'+byte(c[j]) {
				continue
			} else {
				ok = false
			}
		}
		if ok && ans == -1 {
			ans = i
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main(void) {
  string s;
  int n, q;
  cin >> n >> q;
  cin >> s;
  vector<int> v(n);
  v[0] = 0;
  for (int i = 0; i + 1 < s.size(); i++) {
    if (s[i] == 'A' and s[i + 1] == 'C')
      v[i + 1] = v[i] + 1;
    else
      v[i + 1] = v[i];
  }
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << v[r - 1] - v[l - 1] << endl;
  }
  return 0;
}


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

// 8 3 4
// bbbrrrrb
// bbbrrrr  8/(3+4) * 3
//        b min(8%(3+4),3)

int main() {
  long n, a, b;
  std::cin >> n >> a >> b;
  std::cout << ((n / (a + b)) * a) + (std::min(n % (a + b), a)) << std::endl;
}


Measured memory_bytes: 256
function main(input) {
  const strList = input.split("\n").filter(v => v != "");
  strList.pop();
  const ans = strList
    .map(str => {
      return sumChar(str);
    })
    .join("\n");
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

function sumChar(str) {
  const chars = str.split("");
  const sum = chars.reduce((memo, value) => {
    memo += Number(value);
    return memo;
  }, 0);
  return sum;
}



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

int main(){
  int n;
  int sum = 0;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum ^= a[i];
  }
  for(int i = 0; i < n; i++){
    cout << (sum^a[i]) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4028
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#include<iomanip>
#include<deque>
#include<utility>
#include<functional>
#include<sstream>
#include<ctime>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define P 1000000007
#define debug(x) cerr<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int dp[55][11];
char s[3][55];
map<char, int> mp;
int calc(int c1, int c2)
{
    return c1 * 3 + c2;
}
int main()
{
    int n,i,j,k,l,m,t;
    cin >> n;
    scanf("%s", s[1] + 1);
    scanf("%s", s[2] + 1);
    if(s[1][1]==s[2][1])
    {
        for (j = 0; j<3; j++)
            dp[1][calc(j, j)] = 1;
    }
    else
    {
        for (j = 0; j<3; j++)
            for(k=0;k<3;k++)
                if(j!=k)
                    dp[1][calc(j, k)] = 1;
    }
    for (i = 2; i <= n; i++)
    {
        for(j=0;j<3;j++)
            for(k=0;k<3;k++)
                if (t=dp[i - 1][calc(j, k)])
                {
                    if (s[1][i] == s[2][i])
                    {
                        for (l = 0; l < 3; l++)
                            if (l != j&&l != k)
                                dp[i][calc(l, l)] = (dp[i][calc(l, l)] + t)%P;
                    }
                    else
                    {
                        for (l = 0; l < 3; l++)
                            for (m = 0; m < 3; m++)
                                if(l != m)
                                    if((s[1][i-1]!=s[1][i])^(l==j))
                                        if ((s[2][i - 1] != s[2][i]) ^ (m == k))
                                            dp[i][calc(l, m)] = (dp[i][calc(l, m)] + t)%P;
                    }
                }
    }
    int ans = 0;
    for (j = 0; j < 3; j++)
        for (k = 0; k < 3; k++)
            ans = (ans + dp[n][calc(j, k)]) % P;
    cout << ans << endl;
    return 0;
}
// davidlee1999WTK 2017/
// ios::sync_with_stdio(false);
//#pragma comment(linker, "/STACK:102400000,102400000") compiler c++,not g++
//#include<bits/stdc++.h>
/*

*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if(v <= w)cout << "NO" << endl;
    else if((ld)abs(a - b) / (v - w) <= t)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
//const ll MOD = 1000000007;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> P;
typedef pair<ll,ll> PLL;
double rad(double a) {return a * 180 / PI;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//dpTable
int dp[100050];

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep (i,N) cin >> A.at(i);
    ll kabu = 0,moneynow = 1000;
    for (int i = 0; i < N - 1; i++) {
        if (i >= 1 && A.at(i) > A.at(i - 1)) {
            moneynow += kabu * A.at(i);
            kabu = 0;
        }
        if (A.at(i) < A.at(i + 1)) {
            kabu = moneynow / A.at(i);
            moneynow = moneynow - kabu * A.at(i);
        }
    }
    if (kabu != 0) moneynow += A.at(N - 1) * kabu;
    cout << moneynow << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N;
string s;
long long ans;
map <string, int>mp;

int main(){
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> s;
		sort(s.begin(), s.end());
		ans += mp[s]++;
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD=1000000007;

ll ans=0;

string a;
int n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>a;
    n=a.size(); reverse(a.begin(),a.end());

    ll abc=0;
    ll bc=0;
    ll c=0;

    ll p=1;
    for(int i=0;i<n;i++) {
        if(a[i]=='C') {
            c+=p;c%=MOD;
            continue;
        }
        if(a[i]=='B') {
            bc+=c;bc%=MOD;
            continue;
        }
        if(a[i]=='A') {
            abc+=bc;abc%=MOD;
            continue;
        }
        /// a[i] == '?'
        ll abc_nou=0;
        ll bc_nou=0;
        ll c_nou=0;
        c_nou=3*c+p;
        bc_nou=3*bc+c;
        abc_nou=3*abc+bc;
        c=c_nou%MOD;
        bc=bc_nou%MOD;
        abc=abc_nou%MOD;
        p*=3; p%=MOD;
    }
    cout<<abc<<"\n";
    return 0;
}
/**

**/


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long N,i,sumA,sumB;
    cin>>N;
    long long A[N],B[N];
    sumA=0;sumB=0;
    for(i=0;i<N;i++){
        cin>>A[i];
        sumA+=A[i];
    }
    for(i=0;i<N;i++){
        cin>>B[i];
        sumB+=B[i];
    }
    if(sumA<sumB){
        cout<<-1<<endl;
        return 0;
    }
    for(i=0;i<N;i++){
        A[i]-=B[i];
    }
    sort(A,A+N);
    long long ans=0,d=0;
    for(i=0;i<N;i++){
        if(A[i]>-1&&d+A[i]<sumA-sumB+1){
            ans++;
            d+=A[i];
        }
    }
    ans=N-ans;
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
def main():
    _ = int(input())
    S = input()
    aw = S.count('.')
    ab = S.count('#')
    w = S.count('.')
    b = 0
    ans = float('INF')
    for s in S:
        if s == '.':
            w -= 1
        if s == '#':
            b += 1
        ans = min(aw, ab, w + b, ans)
    print(ans)


main()


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

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

  if (1 <= A && 1 <= B && 9 >= A && 9 >= B) {
    cout << A * B << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        while(true){
            int n = sc.nextInt();
            if(n == 0) break;

            int[] s = new int[n];

            for(int i = 0; i < n; i++){
                s[i] = sc.nextInt();
            }

            int min = s[0];
            int max = s[0];

            for(int j = 1; j < n; j++){
                min = Math.min(min, s[j]);
                max = Math.max(max, s[j]);
            }

            int sum = 0;

            for(int k = 0; k < n; k++){
                sum += s[k];
            }

            int ave = (sum - min - max) / (n - 2);

            System.out.println(ave);

        }

    }
}


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

#ifdef HELTHAZAR
#define dbg(x) cerr << #x << " " << x << endl
#define dbg2(x, y) cerr << #x << " " << x << " " << #y << " " << y << endl
#define dbg3(x, y, z) cerr << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z << endl
#else
#define dbg(x) ;
#define dbg2(x, y) ;
#define dbg3(x, y, z) ;
#endif

#define rep(i, from, to) for (int i = from; i < int(to); i++)
#define repn(i, from, to) for (int i = from; i <= int(to); i++)
#define repr(i, from, to) for (int i = int(from); i >= to; i--)
#define trav(a, x) for (auto& a: x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

typedef long long ll;
typedef double dbl;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<ll> vll;

const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int MAXN = 1e5 + 1;

void solve() {
	int n;
	cin >> n;
	vi a(n);
	trav(x, a) cin >> x;

	vii last(20);
	ll cnt = 0;
	rep(i, 0, n) {
		int l = 0;
		rep(j, 0, 20) {
			if (a[i] & (1 << j)) {
				if (sz(last[j]) >= 1) l = max(l, last[j][sz(last[j]) - 1] + 1);
				last[j].pb(i);
			}
			else {
				if (sz(last[j]) >= 2) l = max(l, last[j][sz(last[j]) - 2] + 1);
			}
		}
		cnt += i - l + 1;
	}
	
	cout << cnt;
}

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

	solve();
}


Measured memory_bytes: 9032
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	ll n, k, a[100000], cnt[41];
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<n; i++){
		for(int j=40; 0<=j; j--){
			if(((1LL<<j) & a[i])==0){
				cnt[j]++;
			}
		}
	}
	ll total=0;
	for(int i=40; 0<=i; i--){
		if((total | (1LL << i)) <=k && n-cnt[i] <= cnt[i]){
			total |= 1LL << i;
		}
	}
	ll ans=0;
	for(int i=0; i<n; i++){
		ans+=total^a[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024