akhauriyash/Code-Regression huggingface dataset:
let n, m, ds = Scanf.scanf "%d %d" @@ fun n m -> Array.(n, m, make_matrix n n (1 lsl 40))
let es = Array.init m @@ fun _ -> Scanf.scanf " %d %d %d" @@ fun a b t -> ds.(a - 1).(b - 1) <- t; ds.(b - 1).(a - 1) <- t; a - 1, b - 1, t
let _ = Array.(iteri (fun i d -> iteri (fun j _ -> if i = j then d.(j) <- 0) d)) ds; for k = 0 to n - 1 do for i = 0 to n - 1 do for j = 0 to n - 1 do ds.(i).(j) <- min ds.(i).(j) @@ ds.(i).(k) + ds.(k).(j) done done done;
  Array.(fold_left (fun r (i, j, t) -> if ds |> to_list |> List.exists (fun s -> s.(i) + t = s.(j)) then r - 1 else r) m es) |> Printf.printf "%d\n"

Measured memory_bytes: 2688
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,l=parseMap(split(readline()))
    apple=[l+i-1 for i in 1:n]
    MIN=100000
    for i in apple
        if abs(i)<abs(MIN)
            MIN=i
        end
    end
    println(sum(apple)-MIN)
end
main()

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

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

const ll MOD=1e9+7;
const int MAX=1e5+100;

set<ll> divisers(ll n) {
  set<ll> res;
  FOR(i,1,(ll)sqrt(n)+1) {
    if (n%i == 0) {
      res.insert(i);
      res.insert(n/i);
    }
  }
  return res;
}

vector<P> factorize(ll n) {
  vector<P> res;
  FOR(i,2,(ll)(sqrt(n))+1) {
    if (n%i==0) {
      ll cnt = 0;
      while (n%i==0) {
        n /= i;
        cnt++;
      }
      res.push_back({i,cnt});
    }
  }
  if (n > 1) res.push_back({n,1});
  return res;
}

int main() {
  ll N;cin>>N;
  set<ll> d = divisers(N);
  vector<P> f = factorize(N);

  // 素数
  if (siz(d)==2) {
    cout<<1<<' '<<1<<endl;
  } else {
    // 最大は約数の数-1だけ
    ll ma = siz(d)-1;
    // 最小は素因数の数
    ll mi = siz(f);
    cout<<mi<<' '<<ma<<endl;
  }

  return 0;
}


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

public class Test
{
	public static void Main()
	{
		var p = Console.ReadLine().Split(' ').Select(i=>int.Parse(i)).ToArray();
		var a = Console.ReadLine().Split(' ').Select(i=>int.Parse(i)).Concat( new int[1]{p[2]}).Max();
		var b = Console.ReadLine().Split(' ').Select(i=>int.Parse(i)).Concat( new int[1]{p[3]}).Min();
Console.WriteLine((a<b?"No ":"") + "War");
	}
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

int x;
int main(){
  scanf("%d",&x);
  printf("%d\n",48-x);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    #define endl '\n'
    #define pb push_back
    typedef vector<int> vi;
     
    int ing[100005], dp[100005];
    int n, m;
    vi prec[100005], adj[100005];
    vi top;
     
    int f(int v){
      //cout << v << endl;
      if(prec[v].size()==0) return 0;
      if(dp[v]!=-1) return dp[v];
      for(auto u: prec[v]){
        dp[v]=max(dp[v], f(u)+1);
      }
      return dp[v];
    }
    int main(){
      ios_base::sync_with_stdio(0);
      cin.tie(0);
     
      cin >> n >> m;
     
      int a, b;
      for(int i=1; i<=m; i++){
        cin >> a >> b;
        prec[b].pb(a);
      }
      memset(dp, -1, sizeof(dp));
      int ans=-1;
      for(int i=n; i>=1; i--){
        ans=max(ans, f(i));
      }
      cout << ans << endl;
    }

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

#define fi first
#define se second
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 880;
const long long Q = 10100;
const long long mod = 998244353;
const long long MAGIC = 30;

using namespace std;

int n;
int m;
int k;
int d[N][N];
char c[N][N];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

void solve()
{
        cin >> n >> m >> k;
        int x, y;
        for(int i = 1; i <= n; i++){
                for(int j = 1; j <= m; j++){
                        cin >> c[i][j];
                        d[i][j] = 1e9;
                        if(c[i][j] == 'S'){
                                x = i;
                                y = j;
                                d[i][j] = 0;
                        }
                }
        }
        queue < pair < int, int > > q;
        q.push({x, y});
        while(!q.empty()){
                x = q.front().fi;
                y = q.front().se;
                q.pop();
                for(int i = 0; i < 4; i++){
                        int nx = x + dx[i], ny = y + dy[i];
                        if(nx < 1 || ny < 1 || nx > n || ny > m){
                                continue;
                        }
                        if(c[nx][ny] != '#' && d[nx][ny] == 1e9){
                                d[nx][ny] = d[x][y] + 1;
                                q.push({nx, ny});
                        }
                }
        }
        int ans = 1e9;
        for(int i = 1; i <= n; i++){
                for(int j = 1; j <= m; j++){
                        if(d[i][j] <= k){
                                if(i == 1 || j == 1 || i == n || j == m){
                                        ans = 1;
                                }
                                else{
                                        ans = min(ans, (i - 1 - 1) / k + 2);
                                        ans = min(ans, (j - 1 - 1) / k + 2);
                                        ans = min(ans, (n - i - 1) / k + 2);
                                        ans = min(ans, (m - j - 1) / k + 2);
                                }
                        }
                }
        }
        cout << ans << "\n";
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("island.in");
        //fout("island.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int cnt=0;
    int ans=n;
    rep(i,0,n){
        if(s[i]=='S') cnt++;
        else if(cnt>0){
            cnt--;
            ans-=2;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
ll a,b,c,d,e,f,g;

vector<ll> BINGO(9);
for(ll i=0; i<9 ;i++){
  cin >> BINGO[i];
}

cin >> a;
vector<ll> count(9);
for(ll i=0; i<a ;i++){
cin >> b;
for(ll z=0; z<9 ;z++){
  if(b==BINGO[z]){
  count[z]+=1;
}
}
}

if((count[0]==1 && count[1]==1 && count[2]==1) || 
(count[3]==1 && count[4]==1 && count[5]==1)|| 
(count[6]==1 && count[7]==1 && count[8]==1)||
(count[0]==1 && count[3]==1 && count[6]==1)||
(count[1]==1 && count[4]==1 && count[7]==1)||
(count[2]==1 && count[5]==1 && count[8]==1)|| 
(count[0]==1 && count[4]==1 && count[8]==1)|| 
(count[2]==1 && count[4]==1 && count[6]==1)){
  cout << "Yes" << endl; 
}else{
  cout << "No" << endl;
}







}






Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#define endl '\n'
#define ll long long
#define pb push_back
#define pi 3.14159265358979323846264338327950288419716939937510
#define RUN_FAST ios::sync_with_stdio(false);
#define sz 100
using namespace std;

int main()
{
    RUN_FAST;
    char c;
    cin  >> c;
    if (c>='A' && c<='Z') cout << 'A' << endl;
    else cout << 'a' << endl;
    return 0;
}


Measured memory_bytes: 3576
using System;

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int W = int.Parse(s[0]);
            int H = int.Parse(s[1]);
            int x = int.Parse(s[2]);
            int y = int.Parse(s[3]);
            int r = int.Parse(s[4]);

            if (x + r <= W && y + r <= H && x-r>=0 && y-r>=0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 9024
#include<stdio.h>

int main()
{
  int w,a,b;
  
  scanf("%d%d%d",&w,&a,&b);
  
  if(a+w<b)
  {
    printf("%d\n",b-(a+w));
  }
  else if(b+w<a)
  {
    printf("%d\n",a-(b+w));
  }
  else
  {
    printf("0\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
object Main extends App {

  def solve(ns: List[Int]): Int = {
    val r = for (m <- -100 to 100) yield { ns.map(_.toDouble).map(x => math.pow(x - m, 2)).sum.toInt }
    r.min
  }

  val sc = new java.util.Scanner(Console.in)
  val n  = sc.nextInt()
  val ns = List.fill(n)(sc.nextInt())
  println(solve(ns))
}

Measured memory_bytes: 29180
#include<stdio.h>

int main(void)
{
  long int A,B,G,i,j,S;
  long int p[40];
  scanf("%ld%ld",&A,&B);
  
  while(A!=B){
    if(A>B){
      A=A-B;
    }else{
      B=B-A;
    }
  }
  G=A;
  
  if(G!=1){
    p[0]=2;
    i=1;
    while(G!=1){
      p[i]=p[i-1];
      while(G%p[i]!=0&&p[i]<=1000000){
        p[i]++;
      }
      if(p[i]==1000001){
        p[i]=G;
      }
      G=G/p[i];
      i++;
    }
    i=i-1;
    S=2;
    
    for(j=1;j<=i-1;j++){
      if(p[j]!=p[j+1]){
        S++;
      }
    }
  }else{
    S=1;
  }
  
  printf("%ld",S);
  
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
class Main{
    public static void main(String[] args){
    	try{
    		InputStreamReader isr = new InputStreamReader(System.in);
    		BufferedReader br = new BufferedReader(isr);
    		String buf = br.readLine();
    		double r = Double.parseDouble(buf);
        
    		double pi = Math.PI;
        	double S = r * r * pi;
        	double R = 2 * r * pi;
        
        	System.out.printf("%f %f", S, R);
    	}catch (IOException e){
    		System.err.println(e);
        }
    }
}

Measured memory_bytes: 24672
N = int(input())
A_LIST = sorted(list(map(int, input().split(' '))), reverse=True)

n_a = 0
n_b = 0
for i, x in enumerate(A_LIST):
    if i % 2 == 0:
        n_a += x
    else:
        n_b += x
        
print(n_a - n_b)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}

ll const mod =1e9+7;
int main() {
  int N;
  cin >> N;
  vector<ll> a(N),b(N,0),c(N,0);
  rep(i,N) cin >> a[i];
  rep(i,N) {
    b[i]=a[i];
    if (i>0) b[i]+=b[i-1];}
  rep(i,N) {
    c[i]=a[N-1-i];
    if (i>0) c[i]+=c[i-1];}
  reverse(c.begin(),c.end());
  ll ans=LONG_LONG_MAX/100;
  rep(i,N-1) {
    chmin(ans,abs(b[i]-c[i+1]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
import bisect

N = int(input())
S = list(input())

X = []
for i in range(10):
    X.append([])
for i in range(N):
    X[int(S[i])].append(i)

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if len(X[i]) > 0:
                ind = bisect.bisect_left(X[j],X[i][0] + 1)
                if ind < len(X[j]):
                    ind = X[j][ind] + 1
                    ind = bisect.bisect_left(X[k],ind)
                    if ind < len(X[k]):
                        ans += 1
print(ans)
            

Measured memory_bytes: 41328
#include <stdio.h>
#include <math.h>
int main(){
	int a,b,h,m,c,d,t;
	double e,ans;
	scanf("%d%d%d%d",&a,&b,&h,&m);
	c=60*h+m,d=12*m;
	if(c<d)t=c,c=d,d=t;
	e=(c-d)*2*M_PI/720;
	ans=sqrt(a*a+b*b-2*a*b*cos(e));
	printf("%.12lf\n",ans);
	return 0;
}

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

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

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

#define amari(x) ((x) % 1000000007)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

int n;
long a[200000];
long scores[100001];

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

  cin >> n;

  fillLong(a, n*3); 
  
  priority_queue<long, vector<long>, greater<long> > pf;
  priority_queue<long> pb;

  long sf = 0;
  long sb = 0;

  for (int i = 0; i < n; i++) {
    pf.push(a[i]);
    pb.push(a[3 * n - i - 1]);
    sf += a[i];
    sb += a[3 * n - i - 1];
  }

  scores[0] = sf;

  for (int i = n; i < 2 * n; i++) {
    sf += a[i];
    pf.push(a[i]);
    sf -= pf.top(); pf.pop();
    scores[i - n + 1] = sf;
  }

  scores[n] -= sb;

  for (int i = 2 * n - 1; i >= n; i--) {
    sb += a[i];
    pb.push(a[i]);
    sb -= pb.top(); pb.pop();
    scores[i - n] -= sb;
  }

  printf("%ld\n", *max_element(scores, scores + n + 1));

  return 0;
}


Measured memory_bytes: 4340
#include<iostream>
int main()
{
  int x,y;
  int ans[4]={0,300000,200000,100000};
  std::cin>>x>>y;
  if(x==1&&y==1)
    std::cout<<1000000<<std::endl;
  else {
    int tot=0;
    if(x<4) tot+=ans[x];
    if(y<4) tot+=ans[y];
    std::cout<<tot<<std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    if(n%2==1){cout<<0;return 0;}
    n/=2;
    ll ans = 0;
    while(n){
        ans+=n/=5;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int a[114514];
int b[114514];
signed main(){
	int n,m;
	cin>>n>>m;	
	for(int i=0;i<m;i++){
		cin>>a[i];
		cin>>b[i];
	}
	sort(a,a+m);
	sort(b,b+m);
	if(b[0]>=a[m-1]){
		cout<<b[0]-a[m-1]+1<<endl;
	}
	else{
		cout<<0<<endl;
	}		
}			


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d,e;
    cin>>e;
    if (e==25){
       cout<<"Christmas";
    }else if(e==24){
        cout<<"Christmas Eve";
    }else if(e==23){
        cout<<"Christmas Eve Eve";
    }else if(e==22){
        cout<<"Christmas Eve Eve Eve";
    }
}
    
    

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<iterator>
#include<cstdio>
#include<cmath>
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<vector<int> >in(n,vector<int>(3));
  rep(i,n)rep(j,3)cin>>in[i][j];
  rep(j,3){
    map<int,int>out;
	rep(i,n){
	int d=in[i][j];
	  if(out[d]){
		in[out[d]-1][j]=0;
		in[i][j]=0;
	  }else out[d]=i+1;
	}
  }
  rep(i,n){
	int sum=0;
	rep(j,3)sum+=in[i][j];
	cout<<sum<<endl;
  }
}

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

int N;
vector<int> a, b;

void solve()
{
	if(a == b) cout << "0\n";
	else{
		vector<int> c;
		for(int i=1;i<=N;++i)c.push_back(i);
		int x=-1,y=-1;
		int iter = 1;
		do{
			if(c == a) x = iter;
			if(c == b) y = iter;
			iter++;
		}while(next_permutation(c.begin(),c.end()));
		cout << abs(x-y) << '\n';
	}
}

int main()
{
	cin >> N;
	int x;
	for(int i=0;i<N;++i){
		cin >> x;
		a.push_back(x);
	}
	for(int i=0;i<N;++i){
		cin >> x;
		b.push_back(x);
	}
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<set>
#include<string.h>
using namespace std;

int main()
{
    long long r,d;
    long long x;
    cin>>r>>d>>x;
    for(int i=1; i<=10; i++)
    {
        x=r*x-d;
        cout<<x<<endl;

    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <utility>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	map<double, int> m;
	map<double, int> ma;
	int n;
	double t;
	rep(i,3) {
		rep(j,8) {
			cin >> n >> t;
			m.insert(make_pair(t,n));
		}
		auto it = m.begin();
		rep(j,2) {
			cout << (*it).second << " ";
			printf("%.2lf\n", (*it).first);
			++it;
		}
		ma.insert(*it);
		m.clear();
	}
	auto it2 = ma.begin();
	rep(i,2) {
		cout << (*it2).second << " ";
		printf("%.2lf\n", (*it2).first);
		++it2;
	}
	return 0;
}

Measured memory_bytes: 1288
import Control.Applicative

rotate :: (Int,Int) -> (Int,Int)
rotate (x,y) = (-y,x)

main = do
    [x1,y1,x2,y2] <- map read . words <$> getLine
    putStrLn $ pprint (solve x1 y1 x2 y2)

pprint (a,b,c,d) = show(a) ++ " " ++ show(b) ++ " " ++ show(c) ++ " " ++ show(d)

solve x1 y1 x2 y2 = (x3,y3,x4,y4)
     where (dx3,dy3) = rotate (x2-x1,y2-y1)
           x3 = x2 + dx3
           y3 = y2 + dy3
           (dx4,dy4) = rotate (x3-x2,y3-y2)
           x4 = x3 + dx4
           y4 = y3 + dy4

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

int main() {
  int a,b,c,d,L,R;
    cin >> a>>b>>c>>d;
  L=a+b;
    R=c+d;
    if (L>R) {
      cout << "Left" << endl;
    }
    else if (L==R) {
      cout<< "Balanced" << endl;
    }
    else {
      cout<<"Right" << endl;
    }
    }


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

int main(){
    string s;
    cin >> s;
    if(s == "SUN")cout << 7 << endl;
    if(s == "MON")cout << 6 << endl;
    if(s == "TUE")cout << 5 << endl;
    if(s == "WED")cout << 4 << endl;
    if(s == "THU")cout << 3 << endl;
    if(s == "FRI")cout << 2 << endl;
    if(s == "SAT")cout << 1 << endl;
}


Measured memory_bytes: 3536
from collections import Counter, defaultdict
N, M, *X = map(int, open(0).read().split())
c = Counter(X)
dic = defaultdict(int)
nokori = defaultdict(int)
ans = 0
for k in c.keys():
  dic[k%M] += c[k]//2
  nokori[k%M] += c[k]%2
ans = 0
for a in range(M//2+1):
  b = (M-a)%M
  na = nokori[a]
  nb = nokori[b]
  if a==b:
    ans += na//2
    ans += dic[a]
    continue
  if na<nb:
    ans += na
    nb -= na
    ma = dic[a]*2
    ans += min(nb,ma)
    ans += max(0,(ma-nb)//2)
    ans += dic[b]
  else:
    ans += nb
    na -= nb
    mb = dic[b]*2
    ans += min(mb,na)
    ans += max(0,(mb-na)//2)
    ans += dic[a]
print(ans)

Measured memory_bytes: 35292
#!/usr/bin/env python3

def solve(n, a, b):
    if a + b - 1 > n:
        return [ -1 ]
    if a * b < n:
        return [ -1 ]

    # construct in \omega^2
    xs = []
    xs += [ (0, - j) for j in range(b) ]
    for i in range(1, a):
        xs += [ (i, 0) ]
        j = 1
        while j < b and len(xs) + (a - i - 1) < n:
            xs += [ (i, - j) ]
            j += 1

    # coordinate compression
    f = {}
    for x in sorted(xs):
        k = len(f)
        f[x] = k
    return [ f[x] + 1 for x in xs ]


print(*solve(*map(int, input().split())))



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

using namespace std;

int n, k, a[100001], dp[100001];

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (int i = 2; i <= n; i++) {
        dp[i] = 1e9;
        for (int j = 1; j <= k && i-j>0; j++) {
            dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]));
        }
    }

    cout << dp[n];

    return 0;
}

Measured memory_bytes: 1024
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
ppp = get_nums_l()

ans = 0
min_ = 999999999999
max_ = -99999999999
for i,p in enumerate(ppp):

    if p < min_:
        min_ = p
        ans += 1

print(ans)

Measured memory_bytes: 73436
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
    cout << "Left" << endl;
  } else if (A + B == C + D) {
    cout << "Balanced" << endl;
  } else {
    cout << "Right" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#define MAXN 200001
#define int long long

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

int n,a[MAXN],last[MAXN],k;

signed main() {
	read(n),read(k);
	for(int i=1;i<=n;++i) read(a[i]);
	last[1]=1;int now=1;
	while(k) {
		if(last[a[now]]) {
			int times=last[now]+1-last[a[now]];
			k%=times;
			if(k==0) break;
			--k;
			now=a[now];
			while(k!=0) {
				now=a[now];
				--k;
			}
		}
		if(!k) break;
		last[a[now]]=last[now]+1;
		now=a[now];
		--k;
	}
	printf("%lld\n",now);
	return 0;
}

Measured memory_bytes: 6776
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  deque<int> dq;
  FOR(i,1,n+1){
    int a;
    cin >> a;
    if(i%2 == n%2) dq.push_front(a);
    else dq.push_back(a);
  }
  for(auto itr = begin(dq); itr!=end(dq); itr++){
    cout << *itr << " ";
  }
  return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int n,m,x;
	cin>>n>>m>>x;
	int a[101];
	int c=0,d=0;
	for(int i=0;i<m;i++){
		cin>>a[i];
		if(a[i]>x)c++;
		else d++;
	}
	cout<<min(c,d)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double t,x;
  cin>>t>>x;
  cout<<t/x<<endl;
  return 0;
}



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

const int maxn = 20;
int n, m, row[maxn], col[maxn];
bool used[maxn], ans;

string s[20];

void check(int u, bool flag)
{
    if(u == (m + 1) / 2) {
        printf("YES");
        exit(0);
    }

    for(int i = u; i < m; i ++) {
        if(col[i] == -1) {
            for(int j = i + 1; j < m; j ++) {
                if(col[j] >= 0)
                    continue;
                bool f = true;
                for(int k = 0; k < n; k ++) {
                    if(s[k][i] != s[row[k]][j]) {
                        f = false;
                        break;
                    }
                }
                if(f) {
                    col[i] = j;
                    col[j] = i;
                    check(u + 1, flag);
                    col[i] = col[j] = -1;
                }
            }

            if(flag) {
                bool f = true;
                for(int k = 0; k < n; k ++) {
                    if(s[k][i] != s[row[k]][i]) {
                        f = false;
                        break;
                    }
                }
                if(f){
                    col[i] = i;
                    check(u + 1, false);
                    col[i] = -1;
                }
            }
            break;
        }
    }
}

void dfs(int u, int flag)
{
    if(u == (n + 1) / 2) {
        check(0, m & 1);
        return;
    }

    for(int i = u; i < n; i ++) {
        if(row[i] == -1) {
            for(int j = i + 1; j < n; j ++) {
                if(row[j] >= 0)
                    continue;
                row[i] = j;
                row[j] = i;
                dfs(u + 1, flag);
                row[i] = row[j] = -1;
            }
            if(flag) {
                row[i] = i;
                dfs(u + 1, false);
                row[i] = -1;
            }
            break;
        }
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    memset(row, -1, sizeof(row));
    memset(col, -1, sizeof(col));
    for(int i = 0; i < n; i ++)
        cin >> s[i];

    if(n & 1)
        dfs(0, true);
    else
        dfs(0, false);
    printf("NO");
    return 0;
}


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

#define llint long long int
#define MOD 1000000007

using namespace std;

// a^n (mod p)
llint mod_pow(llint a, llint n, llint p)
{
    if (n == 0)
    {
        return 1;
    }
    else if (n % 2 == 0)
    {
        llint d = mod_pow(a, n / 2, p);

        return (d * d) % p;
    }
    else
    {
        return (a * mod_pow(a, n - 1, p)) % p;
    }
}
llint mod_inv(llint a, llint p)
{
    return mod_pow(a, p - 2, p);
}
llint mod_conb(llint a, llint b, llint p)
{
    llint ret = 1;

    for (int i = 0; i < b; i++)
    {
        ret = (ret * (a - i)) % p;
        ret = (ret * mod_inv(b - i, p)) % p;
    }
    return ret;
}
int main()
{
    llint S;

    cin >> S;

    llint ans = 0;

    for (llint k = 1; S - 3 * k >= 0; k++)
    {
        ans = (ans + mod_conb(S - 2 * k - 1, k - 1, MOD)) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long W = sc.nextLong();
    long ans = 0;
    if(H % 3 != 0 && W % 3 != 0) {
      ans = Math.min(H, W);
      for(int i = 1; i < W; i++) {
        long a = H * (long)i;
        long h = H / 2;
        long b = (long)(W - i) * h;
        long c = (long)(W - i) * (H - h);
        long max = a;
        max = Math.max(Math.max(max, b), c);
        long min = a;
        min = Math.min(Math.min(min, b), c);
        ans = Math.min(ans, max - min);
      }
      for(int i = 1; i < H; i++) {
        long a = W * (long)i;
        long h = W / 2;
        long b = (long)(H - i) * h;
        long c = (long)(H - i) * (W - h);
        long max = a;
        max = Math.max(Math.max(max, b), c);
        long min = a;
        min = Math.min(Math.min(min, b), c);
        ans = Math.min(ans, max - min);
      }
    }
    System.out.println(ans);
  }
}

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

int main(){
  ll n,a,b; cin >>n >>a >>b;
  if(a>b){
    cout << 0 << endl;
    return 0;
  }
  if(n==1){
    if(a!=b) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
  }
  ll m = (n-1)*a+b;
  ll M = a+(n-1)*b;
  cout << M-m+1 << endl;
  return 0; 
}

Measured memory_bytes: 3572
s = input()

ans = ''

for i in range(len(s)):
	if s[i] == '0':
		ans += '0'
	elif s[i] == '1':
		ans += '1'
	elif s[i] == 'B':
		if len(s) >= 1:
			ans = ans[:-1]

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	string S; 
	cin >> S; 
	int L = S.size(); 
	long long int sum = 0; 
	long long int count = 0; 
	for(int i = 0; i < L; i++){
		if(S.at(i) == 'W'){sum += i; count += 1;}
	}
	cout << sum - count * (count - 1) / 2 << endl; 
}

Measured memory_bytes: 640
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)

int main() {
	ll n,topCnt=0,a;
	in(n);
	sll cnt;
	rep(i, 0, n) {
		in(a);
		if (a >= 3200) {
			topCnt++;
		}
		else {
			cnt.insert(a/400);
		}
	}

	if (cnt.size() > 0) {
		outs(cnt.size());
	}
	else {
		outs(1);
	}
	outn(topCnt + cnt.size());


}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
ll n,d,t;
ll dir[MAXN],pos[MAXN];
ll a[MAXN],b[MAXN],cnta,cntb;
ll find1(ll l,ll r){
	return upper_bound(b+1,b+1+cntb,r)-lower_bound(b+1,b+1+cntb,l);	
}
ll find2(ll l,ll r){
	return upper_bound(a+1,a+1+cnta,r)-lower_bound(a+1,a+1+cnta,l);	
}
ll ans[MAXN];
int main(){
	SF("%lld%lld%lld",&n,&d,&t);
	t*=2ll;
	for(int i=1;i<=n;i++){
		SF("%lld%lld",&pos[i],&dir[i]);
		if(dir[i]==1)
			a[++cnta]=pos[i];
		else
			b[++cntb]=pos[i];
	}
	ll t1=t/d;
	ll t2=t%d;
	for(int i=1;i<=n;i++){
		if(dir[i]==1){
			ll cnt=t1*cntb;
			ll l=pos[i];
			ll r=(pos[i]+t2)%d;
			if(r<l)
				cnt+=find1(l,d-1)+find1(0,r);
			else
				cnt+=find1(l,r);
			ans[(i+cnt-1)%n+1]=(pos[i]+t/2ll)%d;
		}
		else{
			ll cnt=t1*cnta;
			ll r=pos[i];
			ll l=(pos[i]-t2+d)%d;
			if(r<l)
				cnt+=find2(l,d-1)+find2(0,r);
			else
				cnt+=find2(l,r);
			ans[((i-cnt)%n+n-1)%n+1]=((pos[i]-t/2ll)%d+d)%d;
		}
	}
	for(int i=1;i<=n;i++)
		PF("%lld\n",ans[i]);
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

const int MOD=1e9+7;
int A[50][50], temp[50][50], ans[50][50];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N;
	long long K, cnt=0;
	bool first=true;
	cin>>N>>K;
	for(int i=0;i<N;i++) for(int j=0;j<N;j++) cin>>A[i][j];
	for(int j=0;j<61;j++) {
		if(K&(1LL<<j)) {
			if(first) {
				for(int i=0;i<N;i++) for(int j=0;j<N;j++) ans[i][j]=A[i][j];
				first=false;
			}
			else {
				memset(temp,0,sizeof(temp));
				for(int k=0;k<N;k++) {
					for(int i=0;i<N;i++) {
						for(int j=0;j<N;j++) {
							temp[i][j]=(temp[i][j]+1LL*A[i][k]*ans[k][j])%MOD;
						}
					}
				}
				for(int i=0;i<N;i++) for(int j=0;j<N;j++) ans[i][j]=temp[i][j];
			}
		}
		memset(temp,0,sizeof(temp));
		for(int k=0;k<N;k++) {
			for(int i=0;i<N;i++) {
				for(int j=0;j<N;j++) {
					temp[i][j]=(temp[i][j]+1LL*A[i][k]*A[k][j])%MOD;
				}
			}
		}
		for(int i=0;i<N;i++) for(int j=0;j<N;j++) A[i][j]=temp[i][j];
	}
	for(int i=0;i<N;i++) for(int j=0;j<N;j++) cnt=(cnt+ans[i][j])%MOD;
	cout<<cnt<<'\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    if(A<9&&B<9){
      System.out.println("Yay!");
    }else{
      System.out.println(":(");
    }
  }
}   

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {

    vector<char> s(15, 'o');
    string t;
    cin >> t;
    int n = t.size();
    rep(i, n) s[i] = t[i];
    int c = count(s.begin(), s.end(), 'o');
    string ans = c >= 8 ? "YES" : "NO";
    cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int r, g, b;	cin >> r >> g >> b;

	int num = 100 * r + 10 * g + b;
	if (num % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    static final int A=100001;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n=scan.nextInt();
        int m=scan.nextInt();
        int[]f=new int[A];
        for(int i=0;i<n;++i){
            f[Integer.parseInt(scan.next())]++;
        }
        int[]g=new int[m];
        int[]e=new int[m];
        for(int i=0;i<A;++i)g[i%m]+=f[i];
        for(int i=0;i<A;++i)e[i%m]+=f[i]/2;
        int t=g[0]/2;
        if(m%2==0)t+=g[m/2]/2;
        for(int i=1;2*i<m;++i){
            int u=Math.min(g[i],g[m-i]);
            t+=u+Math.min(e[i],(g[i]-u)/2)+Math.min(e[m-i],(g[m-i]-u)/2);
        }
        System.out.println(t);
    }
}


Measured memory_bytes: 50604
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int A, B, C;	// Aピザ値段, Bピザ値段, ABピザ値段
  int X, Y;		// Aピザ枚数, Bピザ枚数
  cin >> A >> B >> C >> X >> Y;
  long long sum1 = 0;
  sum1 = (A * X) + (B * Y);	// AピザとBピザの値段合計初期値
  // 枚数の最大数ループ
  for(int i = 1; i <= max(X, Y); ++i)
  {
    long long sum2 = 2 * i;	// ABピザの枚数(2枚でAとBが1枚できる)
    long long sum3 = (C * sum2) + (A * max(0, X - i)) + (B * max(0, Y - i));	// AピザBピザの枚数を減らしてABピザに組み替えた合計金額を出す
    sum1 = min(sum1, sum3);	// 最小の値段を蓄積
  }
  cout << sum1 << endl;
  return 0;
}

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

const int MAX_N = 3e5 + 15, MOD = 1e9 + 7;
string s;
int n, ans;
int dp[MAX_N][3][2][2][5];

int _sum (int a, int b) {
	int c = a + b;
	if (MOD <= c)
		c -= MOD;

	return c;
}

int _sub (int a, int b) {
	int c = a - b;
	if (c < 0)
		c += MOD;

	return c;
}

int _mul (int a, int b) {
	int c = 1LL * a * b % MOD;
	return c;
}

int _pow (int a, int b) {
	if (!b)
		return 1;

	int res = _pow(a, b >> 1);
	res = _mul(res, res);

	if (b & 1)
		res = _mul(res, a);
	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> s;
	n = s.size();
	s = '#' + s;

	int num = 0;
	for (int i = 1; i <= n; i++)
		num += s[i] == '?';

	if (s[1] != '0')
		dp[1][2][1][1][0] = 1;
	if (s[1] != '1')
		dp[1][2][0][1][2] = 1;

	for (int i = 1;  i < n; i++)
		for (int j = 0; j < 4; j++) {
			if (s[i + 1] != '1') {
				if (j) dp[i + 1][1][0][0][j - 1] = _sum(dp[i + 1][1][0][0][j - 1], dp[i][0][0][0][j]);
				if (j) dp[i + 1][2][0][1][j - 1] = _sum(dp[i + 1][2][0][1][j - 1], dp[i][0][0][1][j]);

				dp[i + 1][0][0][0][j + 1] = _sum(dp[i + 1][0][0][0][j + 1], dp[i][0][1][0][j]);
				dp[i + 1][2][0][1][j + 1] = _sum(dp[i + 1][2][0][1][j + 1], dp[i][0][1][1][j]);

				dp[i + 1][0][0][0][j + 1] = _sum(dp[i + 1][0][0][0][j + 1], dp[i][1][0][0][j]);
				dp[i + 1][0][0][0][j + 1] = _sum(dp[i + 1][0][0][0][j + 1], dp[i][1][0][1][j]);

				dp[i + 1][1][0][0][j + 1] = _sum(dp[i + 1][1][0][0][j + 1], dp[i][1][1][0][j]);
				dp[i + 1][1][0][0][j + 1] = _sum(dp[i + 1][1][0][0][j + 1], dp[i][1][1][1][j]);

				dp[i + 1][0][0][1][j + 1] = _sum(dp[i + 1][0][0][1][j + 1], dp[i][2][0][1][j]);
				dp[i + 1][1][0][1][j + 1] = _sum(dp[i + 1][1][0][1][j + 1], dp[i][2][1][1][j]);
			}
			if (s[i + 1] != '0' && j) {
				dp[i + 1][0][1][0][j - 1] = _sum(dp[i + 1][0][1][0][j - 1], dp[i][0][0][0][j]);
				dp[i + 1][0][1][0][j - 1] = _sum(dp[i + 1][0][1][0][j - 1], dp[i][0][0][1][j]);

				dp[i + 1][1][1][0][j - 1] = _sum(dp[i + 1][1][1][0][j - 1], dp[i][0][1][0][j]);
				dp[i + 1][1][1][0][j - 1] = _sum(dp[i + 1][1][1][0][j - 1], dp[i][0][1][1][j]);

				dp[i + 1][1][1][0][j - 1] = _sum(dp[i + 1][1][1][0][j - 1], dp[i][1][0][0][j]);
				dp[i + 1][2][1][1][j - 1] = _sum(dp[i + 1][2][1][1][j - 1], dp[i][1][0][1][j]);

				dp[i + 1][1][1][0][j - 1] = _sum(dp[i + 1][1][1][0][j - 1], dp[i][1][1][0][j]);
				dp[i + 1][1][1][0][j - 1] = _sum(dp[i + 1][1][1][0][j - 1], dp[i][1][1][1][j]);

				dp[i + 1][0][1][1][j - 1] = _sum(dp[i + 1][0][1][1][j - 1], dp[i][2][0][1][j]);
				dp[i + 1][1][1][1][j - 1] = _sum(dp[i + 1][1][1][1][j - 1], dp[i][2][1][1][j]);
			}
		}

	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 2; j++)
			for (int t = 0; t < 2; t++)
				for (int k = 1; k < 4; k++)
					ans = _sum(ans, dp[n][i][j][t][k]);

	cout << _sub(_pow(2, num), ans) << "\n";
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  vector<vector<int>> PY(M);
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    vector<int> py = {P[i], Y[i]};
    PY[i] = py;
  }

  sort(PY.begin(), PY.end(),
      [](vector<int> x, vector<int> y) {return (x[0] == y[0]) ? x[1] < y[1] : (x[0] < y[0]);}
  );

  int id = 1, pp = 0;
  map<int, map<int, int>> X;
  for (int i = 0; i < M; i++) {
    int p = PY[i][0];
    int y = PY[i][1];
    if (pp != p) {
      id = 1;
      pp = p;
    }
    X[p][y] = id++;
  }

  for (int i = 0; i < M; i++) {
    int p = P[i];
    int y = X[p][Y[i]];
    printf("%06d%06d\n", p, y);
  }
}

Measured memory_bytes: 21760
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#define f cin
#define NMAX 100010
using namespace std;

//ifstream f("date.in");
long long int n, w;
long long int cost[NMAX], val[NMAX];

long long int dp[100][NMAX];
long long int d2[NMAX], d1[NMAX];

int main() {

    f >> n >> w;
    int total_value = 0;
    for (int i = 0; i < n; ++i) {
        f >> cost[i] >> val[i];
        total_value += val[i];
    }

    for (int i = 1; i <= total_value; ++i) {
        dp[0][i] = w + 1;
    }

    dp[0][val[0]] = cost[0];

    for (int i = 1; i < n; ++i) {
        for (int j = 0; j <= total_value; ++j) {
            dp[i][j] = dp[i - 1][j];
        }
        for (int j = 0; j + val[i] <= total_value; ++j) {
            dp[i][j + val[i]] = min(dp[i][j + val[i]], dp[i - 1][j] + cost[i]);
        }
    }

    //cout << total_value << "\n";

    /*for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= total_value; ++j) {
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }*/

    int c_min = -1;
    for (int i = total_value; i > 0; --i) {
        if (dp[n - 1][i] <= w) {
            cout << i;
            return 0;
        }
    }

    cout << 0;

    return 0;
}


Measured memory_bytes: 78592
import sys
 
n = int(input())
l = []
p = None
 
for i in range(n):
  s = input()
  if s not in l and (p == None or p[-1:] == s[:1]):
    l.append(s)
    p = s
  else:
    print("No")
    sys.exit()
print("Yes")

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

class B {
	int N, M, X, Y;
public:
	void solve()
	{
		int maxX{ -101 }, minY{ 101 };
		int x, y;

		for (int i{ 0 }; i < N; i++)
		{
			cin >> x;
			if (x > maxX) maxX = x;
		}
		for (int i{ 0 }; i < M; i++)
		{
			cin >> y;
			if (y < minY) minY = y;
		}

		if ((maxX < Y) && (maxX < minY) && (X < minY))
			cout << "No War" << endl;
		else cout << "War" << endl;
	}

	B()
	{
		cin >> N >> M >> X >> Y;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int n,b,f,r,v,college[4][3][10]={0};
  cin>>n;
  for(int m=0;m<n;m++){
  cin>>b>>f>>r>>v;
  college[b-1][f-1][r-1]+=v;
  if(college[b-1][f-1][r-1]>9)college[b-1][f-1][r-1]=9;
  if(college[b-1][f-1][r-1]<0)college[b-1][f-1][r-1]=0;
  }
for(int i=0;i<4;i++){
  if(i!=0){
    for(int l=0;l<20;l++)cout<<"#";
    cout<<endl;
  }
    for (int j = 0; j <3 ; j++) {
      for (int k=0;k<10;k++){
        if(college[i][j][k]!=0)cout<<" "<<college[i][j][k];
        else{cout<<" "<<0;}
      }
      cout<<endl;
    }
}
  return 0;
}

Measured memory_bytes: 1164
import bisect

n=int(input())
opens=0
closes=0
ls=[]
rs=[]
for _ in range(n):
  s=input()
  cnt1=0
  cnt2=0
  for i in range(len(s)):
    if s[i]=='(':
      cnt1+=1
    else:
      if cnt1==0:
        cnt2+=1
      else:
        cnt1-=1
  if cnt2==0:
    opens+=cnt1
  elif cnt1==0:
    closes+=cnt2
  else:
    ls.append(cnt2)
    rs.append(cnt1)
ls=sorted(ls)
rs=sorted(rs)
lefts=sum(ls)
rights=sum(rs)
if opens-closes!=lefts-rights:
  print('No')
else:
  flag=False
  if len(ls)==0:
    flag=True
  for a in ls:
    if opens<a or closes<a+(rights-lefts):
      continue
    pos=bisect.bisect_right(rs,a+(rights-lefts))
    if pos!=0:
      flag=True
      break
  for d in rs:
    if opens<d+(lefts-rights) or closes<d:
      continue
    pos=bisect.bisect_right(ls,d+(lefts-rights))
    if pos!=0:
      flag=True
      break
  if flag==True:
    print('Yes')
  else:
    print('No')

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

/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/


using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	string x;
	cin >> x;
	int len = x.length();
	loop(len)
	{
		if (i != len - 1 && x[i] == x[i + 1])
		{
			cout << (i + 1) << " " << (i + 2) << endl;
			return 0;
		}
		if (i != len - 2 && i != len - 1 && x[i] == x[i + 2])
		{
			cout << (i + 1) << " " << (i + 3) << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 512
N = int(input())
A = list(map(int,input().split()))
ans = 1
re = 0

for i in range(2,N,1):
    #print(re)
    if re == 0:
        if A[i-2] >= A[i-1] >= A[i]:
            re = 0
            if A[i-1] == A[i]:
                A[i-1] = A[i-2]
            
        elif A[i-2] <= A[i-1] <= A[i]:
            re = 0
            if A[i-1] == A[i]:
                A[i-1] = A[i-2]
            
        else:
            ans +=1
            re = 1
    else:
        re = 0



print(ans)


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

int prime[100010];
int prime2017[100010];
int sp[100010];

bool isprime(int n)
{
    for(int i=2;i<n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
    }

    return true;
}

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

    for(int i=2;i<100010;i++)prime[i]=1;

    for(int i=2;i<100010;i++)
    {
        if(prime[i]==0)continue;

        if(isprime(i))
        {
            for(int j=i*2;j<100010;j+=i)
            {
                prime[j]=0;
            }

            if(prime[(i+1)/2]==1)prime2017[i]=1;
        }
    }

    for(int i=0;i<100010;i++)sp[i+1]=sp[i]+prime2017[i];

    int q;cin>>q;
    for(int i=0;i<q;i++)
    {
        int l,r;cin>>l>>r;

        cout<<sp[r+1]-sp[l]<<"\n";
    }

    return 0;
}


Measured memory_bytes: 4800
S = list(input())
N = len(S)

ans = 0
for i in range(2**(N-1)):
    p = S[0]
    for j in range(N-1):
        if (i >> j) & 1:
            ans += int(p)
            p = S[j+1]
        else:
            p += S[j+1]
    ans += int(p)

print(ans)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for(ll i = k; i <= n + 1; i++){
        ans = (ans + (n + n - i + 1) * i / 2 % MOD + MOD - (i - 1) * i / 2 % MOD + 1) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632