akhauriyash/Code-Regression huggingface dataset:
//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib>      // srand,rand


using namespace std;
#define modd 1000000007



typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L,T;
ll A[300005] = {};
ll B[300005] = {};
ll C[100][3005] = {};
bool f, ff;
string S,SS;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset[50];
multiset<ll> llmset;
queue<ll> ql;


struct ST
{
	ll first;
	ll second;
	ll kaisuu;
	

	bool operator<(const ST& another) const
	{
		return first < another.first;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


ll minn, maxx;
double ansa;

ll zettai(ll aa) {

	if (aa < 0) {
		aa *= -1;
	}
	return aa;

}



bool itta[300000];

int main() {
	
	cin >> N;
	

	for (int i = 2; i <= 100000; i++) {
		for (int j = i; j <= 100000; j+=i) {
			A[j]++;
		}

	}

	c = 0;
	for (int i = 1; i <=100000; i++) {
		if (A[i] - 1 >= 3) {
			c++;
		}
		B[i] = c;
	}

	for (int i = 0; i < N; i++) {
		cin >> d;
		cout << B[d] << endl;
	}
	
	//cout << fixed << setprecision(10) << ansa << endl;
	return 0;



}



Measured memory_bytes: 7092
N = int( input())
XYU = [ tuple( input().split()) for _ in range(N)]
U = []
R = []
D = []
L = []
for x, y, u in XYU:
    x, y = int(x), int(y)
    if u == "U":
        U.append((x,y))
    elif u == "D":
        D.append((x,y))
    elif u == "L":
        L.append((x,y))
    else:
        R.append((x,y))
ans = [10**9]
def z(A):
    A.sort()
    n = -10**10
    p = -10**10
    for k, c, a in A:
        if k != n:
            if a == 1:
                n = k
                p = c
                continue
            else:
                continue
        if a == 1:
            p = c
            continue
        if (c - p)*5 < ans[0]:
            ans[0] = (c - p)*5
z([(x,y,1) for x, y in U] + [(x,y,-1) for x, y in D])
z([(y,x,1) for x, y in R] + [(y,x,-1) for x, y in L])
z([(x+y,x-y,1) for x, y in R] + [(x+y,x-y,-1) for x,y in U])
z([(x+y,x-y,1) for x, y in D] + [(x+y,x-y,-1) for x,y in L])
z([(x-y,x+y,1) for x,y in U] + [(x-y,x+y,-1) for x,y in L])
z([(x-y,x+y,1) for x,y in R] + [(x-y,x+y,-1) for x,y in D])
print("SAFE" if ans[0] == 10**9 else ans[0])


Measured memory_bytes: 103048
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        ArrayList<Double> arD = new ArrayList<>();
        
        while(in.hasNextDouble()){
            arD.add(in.nextDouble());
        }
        
        Collections.sort(arD);
        
        System.out.println(arD.get(arD.size() - 1) - arD.get(0));
    }
}



Measured memory_bytes: 27920
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(i64);
    println!("ABC{}", n);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
#define int long long
#define double long double
int gcd(int x,int y){
    if(y==0)return x;
    x=x%y;
    gcd(y,x);
}
main()
{
    int n,m;
    cin>>n>>m;
    vector<int>a(m);
    int sum=0;
    rep(i,m) {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    if(n>=m){
        cout<<0<<endl;
    }else{
    vector<int>b(m-1);
    for(int i=0;i<m-1;i++){
        b[i]=a[i+1]-a[i];
        sum+=b[i];
    }
    sort(b.rbegin(),b.rend());
    if(n==1){
    cout<<sum<<endl;
    }else{
        rep(i,n-1){
        sum-=b[i];
    }
    cout<<sum<<endl;
    }
    }
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include <stdlib.h>
using namespace std;

int main(void) {
	char n[4];
	int m = 0;
	cin >> n;
	for (int i = 0; i < 3; i++) {
		if (n[i] == '1')m++;
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	ll ans=0;
	rep(i,s.size()/2){
		if(s[i]!=s[s.size()-1-i])ans++;
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#define DEBUG false
using namespace std;

struct P{
  vector<int> v;
  unsigned int i; // TõðJn·éindex
  bool f;         // ¯¶ index ð2xA±ÅTõ·éÆ«true
};
stack< P > st;

void pr( P p ){
  for( unsigned int i=0;i<p.v.size();i++ ){
    cout << p.v[i] << " ";
    if( i%4==3 ) cout << endl;
  }
  if( p.v.size()%4 != 0 )  cout << endl;
}
// p.v[i] p.v[j] ðíÅ«êÎíµAstack ÉÇÁ 
bool erase( P p,bool f, unsigned int i, unsigned int j ){
  if( f && j<p.v.size() && p.v[i]==p.v[j] ){
    P q = p; q.f=true;
    q.v.erase( q.v.begin() + j );
    q.v.erase( q.v.begin() + i );
    st.push( q );
    return true;
  }
  return false;
}

int main(){
  int n;
  P p;

  cin >> n;
  for( int loop=0;loop<n;loop++ ){
    while( !st.empty() ) st.pop();
    p.v.clear();
    for( int i=0,j;i<20;i++ ){ cin >> j; p.v.push_back( j ); }
    p.i = 0; p.f=false;  st.push( p );

    int ans=20;
    while( !st.empty() ){
      p=st.top(); st.pop();

      if( ans > (int)p.v.size() ){
	ans = p.v.size();
	if( ans==0 ) break;
	if( DEBUG ){ cout<<"ans="<<ans<<" i="<<p.i<<endl;pr( p );}
      }
      unsigned int i = p.i;
      bool f = false;
      f=erase( p,i%4!=3,i,i+1 ) || f;
      f=erase( p,i%4!=3,i,i+5 ) || f;
      f=erase( p,i%4!=0,i,i+3 ) || f;
      f=erase( p,true  ,i,i+4 ) || f;
      if( DEBUG && f ){
	cout << "p.i="<<p.i << endl;
	pr( p );
      }

      p.i++;
      if( p.i<p.v.size() ){
	st.push( p );
      }else if( p.f ){ // i=0 -> size ÅêxÅàíðsÁ½
	p.f=false; p.i=0; st.push( p );
      }
    }
    cout << ans << endl;
    
    if( DEBUG )    break;
  }
  return 0;
}

Measured memory_bytes: 912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxx = 2e5 + 7;
const ll mode = 1e9 + 7;

ll fac[maxx + 5], inv[maxx + 5];

ll qwr(ll x, int y) {
	ll res = 1;
	while(y) {
		if(y & 1) res = res * x % mode;
		y >>= 1;
		x = x * x % mode;
	}
	return res;
}

ll solve(int n, int m) {
	return fac[n] * inv[n - m] % mode * inv[m] % mode;
}


int main() {
	ll res = 1;
	fac[0] = 1;
	for(ll i = 1; i <= maxx; i++) fac[i] = fac[i - 1] * i % mode;
	inv[maxx] = qwr(fac[maxx], mode - 2);
	inv[0] = 1;
	for(ll i = maxx - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % mode;
	int n, m;
	cin >> n >> m;
	int t = m;
	for(int i = 2; i * i <= m; i++) {
		if(!(t % i)) {
			int cnt = 0;
			while(!(t % i)) t /= i, cnt++;
			res = res * solve(n + cnt - 1, n - 1) % mode;
		}
	}
	if(t > 1) res = res * solve(n, n - 1) % mode;
	cout << res << endl;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

const int N = 100010;

int n, m, k;
int a[N], b[N], c[N], ans = 0x3f3f3f3f, ma = 0x3f3f3f3f, mb = 0x3f3f3f3f;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	
	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i) 
	{
		cin >> a[i];
		ma = min(ma, a[i]);
	}
	for (int i = 1; i <= m; ++i) 
	{
		cin >> b[i];
		mb = min(mb, b[i]);
	}
	for (int t = 1, l, r, s; t <= k; ++t) 
	{
		cin >> l >> r >> s;
		ans = min(ans, a[l] + b[r] - s);
	}
	
	ans = min(ans, ma + mb);
	
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
int a,b=0,c=0;
string s;
signed main()
{
	cin>>a;
	cin>>s;
	rep(i,a){
		if(s[i]=='R'){
			b++;
		}else{
			c++;
		}
	}
	if(b>c){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
N = int(input())

dp = [[0]*3 for i in range(N+1)]

for i in range(1, N+1):
  acitivities = list(map(int, input().split()))
  for j in range(3):
    for k in range(3):
      if j == k :
        continue
      dp[i][j] = max(dp[i][j], dp[i-1][k]+acitivities[j])

print(max(dp[N]))

Measured memory_bytes: 22824
#include<stdio.h>
int main()
{
	int A,B;
	scanf("%d%d",&A,&B);
	if (A!=1 && B!=1)
	printf("1\n");
	else if (A!=2 && B!=2)
	printf("2\n");
	else
	printf("3\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const ll INF=2e15;
const double PI=acos(-1);


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

    int n;
    cin >> n;
    string x;
    cin >> x;
    int cnt=0;
    rep(i,n) {
        if (x[i]=='1') ++cnt;
    }
    vector<int> pre(n);
    repr(i,1,n) {
        int j=i;
        while (j>0) {
            bitset<20> bit(j);
            int c=0;
            rep(k,20) {
                if (bit[k]==1) ++c;
            }
            j=j%c;
            ++pre[i];
        }
    }
    vector<int> pp(n+1);
    pp[0]=1;
    rep(i,n) pp[i+1]=(pp[i]*2)%(cnt+1);
    ll ap=0;
    invrep(i,n) {
        if (x[i]=='1') ap=(ap+pp[n-1-i])%(cnt+1);
    }
    vector<int> pm(n+1);
    ll am=0;
    if (cnt>1) {
        pm[0]=1;
        rep(i,n) pm[i+1]=(pm[i]*2)%(cnt-1);
        invrep(i,n) {
            if (x[i]=='1') am=(am+pm[n-1-i])%(cnt-1);
        }
    }
    rep(i,n) {
        if (x[i]=='0') {
            ll a=(ap+pp[n-1-i])%(cnt+1);
            cout << pre[a]+1 << endl;
        } else {
            if (cnt==1) cout << 0 << endl;
            else {
                ll a=(am-pm[n-1-i]+cnt-1)%(cnt-1);
                cout << pre[a]+1 << endl; 
            }
        }
    }

    return 0;
}


Measured memory_bytes: 6048
#include <stdio.h>
int main(void){
  int i,judge=0;
  char s[100];
  int co[26];
  for(i=0;i<26;i++) co[i]=0;
  scanf("%s",s);
  for(i=0;s[i]!=0;i++){
    if(s[i]=='a') co[0]++;
    if(s[i]=='b') co[1]++;
    if(s[i]=='c') co[2]++;
    if(s[i]=='d') co[3]++;
    if(s[i]=='e') co[4]++;
    if(s[i]=='f') co[5]++;
    if(s[i]=='g') co[6]++;
    if(s[i]=='h') co[7]++;
    if(s[i]=='i') co[8]++;
    if(s[i]=='j') co[9]++;
    if(s[i]=='k') co[10]++;
    if(s[i]=='l') co[11]++;
    if(s[i]=='m') co[12]++;
    if(s[i]=='n') co[13]++;
    if(s[i]=='o') co[14]++;
    if(s[i]=='p') co[15]++;
    if(s[i]=='q') co[16]++;
    if(s[i]=='r') co[17]++;
    if(s[i]=='s') co[18]++;
    if(s[i]=='t') co[19]++;
    if(s[i]=='u') co[20]++;
    if(s[i]=='v') co[21]++;
    if(s[i]=='w') co[22]++;
    if(s[i]=='x') co[23]++;
    if(s[i]=='y') co[24]++;
    if(s[i]=='z') co[25]++;
  }
  for(i=0;i<26;i++){
    if(co[i]%2){
      judge=1;
      break;
    }
  }
  if(judge==0) printf("Yes\n");
  else printf("No\n");
  return(0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
#define pi 3.1415926535897
int gcd(int a, int b) {
	if (b != 0) return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int a; cin >> a;
	cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    long a,b ,k;
    cin >> a >> b >> k;
    if(2 * k > b - a) {
        for (int i = a; i <= b; ++i) {
            cout << i << endl;

        }
    } else {
        for (int i = a; i < a + k ; ++i) {
            cout << i << endl;
        }
        for (int i = b-k+1; i <= b ; ++i) {
            cout << i << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[200010];
int main() {
	ll n;
	cin>>n;
	ll sum=0;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	ll sum1=0;
	ll ans=INF;
	for(ll i=0;i<n-1;i++){
		sum1+=a[i];
		ll sum3=sum-sum1;
		ans=min(ans,abs(sum3-sum1));
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1792
MOD=10**9+7
N=int(input())
alist=list(map(int,input().split()))

slist=[0]*N
sum_a=0
for i in reversed(range(N)):
  sum_a+=alist[i]
  slist[i]=sum_a  
#print(slist)

answer=0
for i in range(N-1):
  answer+=alist[i]*slist[i+1]
  answer%=MOD
  
print(answer)

Measured memory_bytes: 94068
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int main() {
    int a[3][3];

    cin >> a[0][0] >> a[0][1] >> a[1][1];

    a[2][0] = a[0][0] + a[0][1] - a[1][1];
    a[2][2] = a[0][1] + a[1][1] - a[2][0];
    a[1][2] = a[0][0] + a[0][1] - a[2][2];
    a[2][1] = a[0][0] + a[2][2] - a[0][1];
    a[1][0] = a[0][1] + a[2][1] - a[1][2];
    a[0][2] = a[1][1] + a[2][1] - a[0][0];


    REP(i,3){
        REP(j,3) cout << a[i][j] << " ";
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
s = input()
k = int(input())


l = list(s)
alphabet = sorted(list(set(l)))

num = 0
for a in alphabet:
    cand = []
    n = s.count(a)
    l = list(s)
    for i in range(n):
        ind = l.index(a)
        for j in range(k):
            cand.append(s[ind+i: ind+j+1+i])
        l.remove(a)
    cand = list(set(cand))
    if len(cand) >= k:
        break
    else:
        num += len(cand)
print(sorted(cand)[k-num-1])


Measured memory_bytes: 4432
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line;
      MyList list = new MyList();

      for(int i=0; i<n; i++) {
        line = br.readLine().split(" ");
        switch( line[0] ) {
          case "insert" :
            list.insertFirst( Integer.parseInt(line[1]) );
            break;
          case "delete" :
            list.delete( Integer.parseInt(line[1]) );
            break;
          case "deleteFirst" :
            list.deleteFirst();
            break;
          case "deleteLast" :
            list.deleteLast();
            break;
          default :
            System.out.println("n:" + i + " is failed.");
        }
      }

      System.out.println (list.getAllElements() );
    }
  }
}

class Node {
  Node next,prev;
  int key;

  public Node(int key) {
    this.key = key;
  }
}

class MyList {
  Node nil;
  Node current;
  int size;
  int position;

  public MyList() {
    nil = new Node(0);
    nil.next = nil.prev = nil;
    size = 0;
    position = 0;
  }

  public String getAllElements() {
    StringBuilder buf = new StringBuilder(size*2);

    if(size > 0){
      current = nil.next;
      for(int i=0; i<size; i++){
        buf.append(current.key).append(" ");
        current = current.next;
      }
    }
    buf.setLength(buf.length()-1);

    return buf.toString();
  }
  public void insertFirst(int x) {
    if(size == 0) {
      current = new Node(x);
      nil.next = current;
      nil.prev = current;
      current.prev = nil;
      current.next = nil;
      size++;
    }
    else {
      Node add = new Node(x);
      
      current.prev.next = add;
      add.prev = current.prev;

      add.next = current;
      current.prev = add;

      current = add;
      size++;
    }
  }
  public void deleteFirst() {
    current = nil.next;
    nil.next = current.next;
    current.next.prev = current.prev;
    current = current.next;
    size--;
  }
  public void deleteLast() {
    current = nil.prev;
    nil.prev = current.prev;
    current.prev.next = current.next;
    current = nil.next;
    size--;
  }
  public void delete(int x) {
    Node target = findFirst(x);
    if(target == nil) current = current.next;
    else if( target == nil.prev ) deleteLast();
    else {
      current.prev.next = target.next;
      current.next.prev = target.prev;
      current = nil.next;
      size--;
    }
  }
  private Node findFirst(int x) {
    current = nil.next;
    while(current != nil) {
      if(current.key == x) break;
      current = current.next;
    }

    return current;
  }
}


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

int main(void){
    int n;
    cin >> n;
    vector<int> l;
    rep(i,n){
        int x;
        cin >> x;
        l.push_back(x);
    }
    sort(l.begin(),l.end());
    int ans = 0;
    for(int i=0;i<=n-3;i++){
        for(int j=i+1;j<=n-2;j++){
            for(int z=j+1;z<=n-1;z++){
                if(l[z]<l[i]+l[j]){
                    if((l[i] < l[j]+l[z])&&(l[j]<l[i]+l[z])){
                        ans++;
                    }
                }
                else{
                    break;
                }
            }
        }
    }
    
    cout << ans <<endl;
    
    
    
    return 0;
    
}



















































Measured memory_bytes: 256
a, b, c, d = gets.chomp.chars.map(&:to_i)
op = ['+','-']

op.each do |i|
  op.each do |j|
    op.each do |k|
      if eval "#{a}#{i}#{b}#{j}#{c}#{k}#{d}==7"
        puts "#{a}#{i}#{b}#{j}#{c}#{k}#{d}=7"
        exit
      end
    end
  end
end

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



int main() {
	int n; cin >> n;
	int b[100];
	for (int i = 0; i < n - 1; i++) cin >> b[i];



	int ans = b[0] + b[n - 2];
	for (int i = 1; i < n - 1; i++) {
		ans += min(b[i - 1], b[i]);
	}
	cout << ans << endl;

	return 0;
}



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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll a, b, c;

	cin >> a >> b >> c;

	cout << min(c, a + b + 1) + b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    vector<long long> v;
    long double sum=0.0;
    long long i,j,k,l,n=0,m=0,x,y;
    cin>>n>>k;
    for(i=1;i<=n;i++){
        x=i;
        y=1;
        long long cnt=0;
        while(x<k){
            x=x*2;
            cnt++;
            y=y*2;
        }
        y=y*n;
        sum=sum+((long double)1/y);
    }
    cout<<setprecision(18)<<fixed<<sum<<endl;
}

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

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

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;
  int ans=1;
  REP(i,N-1){
    if(s[i] != s[i+1])ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int M;
    int D;

    scanf("%d %d\n",&M,&D);

    int i;
    int count;
    int ten,one;
    count = 0;
    
    for(i=22;i<=D;i++){
        ten = i%10;
        one = (i-ten)/10;
        if(ten>=2 && one>=2){
            if(ten*one <= M){
                count++;
            }
        }
    }
    
     printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 128
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W = map(int, readline().split())
    A = [list(map(int, readline().split())) for _ in range(H)]

    odd = []

    for i in range(H):
        for j in range(W):
            if i % 2 == 1:
                j = W - j - 1
            if A[i][j] % 2 == 1:
                odd.append((i + 1, j + 1))

    ans = []
    for (x, y), (z, w) in zip(*[iter(odd)] * 2):
        tmp = []
        tmp.append((x, y))
        while (x, y) != (z, w):
            if x % 2 == 1:
                if y == W:
                    x += 1
                else:
                    y += 1
            else:
                if y == 1:
                    x += 1
                else:
                    y -= 1
            tmp.append((x, y))

        for i in range(len(tmp) - 1):
            ans.append((tmp[i][0], tmp[i][1], tmp[i + 1][0], tmp[i + 1][1]))

    print(len(ans))
    for row in ans:
        print(*row)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 50044
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>

int compare_int(const void* a, const void* b) { return *(int*) a - *(int*) b; }

int n, s[100], ans;
long long int dp[100][1000];

long long int func(int a, int sum) {
	if (a == n-1)
		return sum == ans ? 1 : 0;
	long long int cnt = 0;
	if (sum - s[a + 1] >= 0) {
		if (!dp[a + 1][sum - s[a + 1]]) {
			dp[a + 1][sum - s[a + 1]] = func(a + 1, sum - s[a + 1]);
		}
		cnt += dp[a + 1][sum - s[a + 1]];
	}
	if (sum + s[a + 1] <= 20) {
		if (!dp[a + 1][sum + s[a + 1]]) {
			dp[a + 1][sum + s[a + 1]] = func(a + 1, sum + s[a + 1]);
		}
		cnt += dp[a + 1][sum + s[a + 1]];
	}
	return cnt;
}

int main() {
	scanf("%d", &n);
	n--;
	for (int i = 0; n > i; i++) {
		scanf("%d", &s[i]);
	}
	scanf("%d", &ans);
	printf("%lld\n", func(0, s[0]));
	return 0;
}

Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
	int m, f, r;
	scanf("%d%d%d", &m, &f, &r);
	while (m!=-1 || f!=-1 || r!=-1)
	{
		if (m==-1 || f==-1 )
		{
			printf("F\n");
		} else if (m+f>=80)
		{
			printf("A\n");
		} else if (m+f<80 && m+f>=65)
		{
			printf("B\n");
		} else if (m+f<65 && m+f>=50)
		{
			printf("C\n");
		} else if (m+f<50 && m+f>=30)
		{
			if (r>=50)
			{
				printf("C\n");
			} else printf("D\n");
		} else printf("F\n");
		scanf("%d%d%d", &m, &f, &r);
	}
	return 0;
}

Measured memory_bytes: 584
n = int(input())
s = input()

slimes = []
cur = 0
peek = 0
for i in range(n):
    if s[cur] == s[i]:
        peek = i
    else:
        slimes.append(s[cur])
        cur = i
        peek = i

slimes.append(s[cur])
print(len(slimes))


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int n, l; cin >> n >> l;
    string s;
    vector<string> S(n);
    string min = ""; rep(i, l) min += "z";
    rep(i, n){
        cin >> S[i];
        // min = (min > s) ? s : min;
    }
    sort(all(S));
    rep(i, n){
        cout << S[i];
    }
    // cout << min << endl;
    // string s1, s2;
    // s1 = "aaabb";
    // s2 = "aaaba";
    // if(s1 > s2) cout << "yes" << endl;
    return 0;
}

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

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { if(&o == &cerr) { o << '{'; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; } else { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); } return o; }
#ifdef DEBUG
#define dump(...) (cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
#else
#define dump(...) (0)
#endif
/// }}}--- ///

ll N;
ll C;

bool ask(ll n) {
  if(n < 1 || n > 1e18) {
    // dump(N, n);
    assert(0);
  }
  C++;
  if(C > 64) {
    // dump(N, n, "over");
    assert(0);
  }
  // return (n <= N && to_string(n) <= to_string(N) ||
  //     n > N && to_string(n) > to_string(N));
  cout << "? " << n << endl;
  char y; cin >> y;
  return y == 'Y';
}

void out(ll x) {
  // if(x != N) {
    // dump(x);
    // dump(N);
  // }
  cout << "! " << x << endl;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  dump("start");
  // ll T = 0;
  // random_device rnd;
  // mt19937 mt(rnd());
  // uniform_int_distribution<> rand(1, 1e9);
  // for(N = 1; N <= 1e8; N--,N *= 10) {
    // N = rand(mt);
    // if(++T%1000==1)dump(T, N);
    // N++;
    C = 0;
    ll b = 1; for(int i = 0; i < 9; i++) b *= 10;
    ll c = b - 1;
    ll now = 0;
    int all9 = 1;
    ll k = 1;
    int cnt = 0;
    while(1) {
      if(cnt == 9 && now != 1e8) {
        out(now);
        goto end;
      }
      if(cnt == 9) {
        out(ask(9e8) ? 1e8 : 1e9);
        goto end;
      }
      int ok = 9, ng = cnt ? -1 : 0;
      while(ok - ng > 1) {
        ll mid = (ok + ng) >> 1;
        if(ask((now * 10 + mid) * b + c)) {
          ok = mid;
        } else {
          ng = mid;
        }
      }
      if(ok == 0) {
        if(all9) {
          if(!ask(k)) {
            out(now);
            goto end;
          }
        } else {
          if(ask(k-1)) {
            out(now);
            goto end;
          }
        }
      }
      all9 &= ok == 9;
      now = now * 10 + ok;
      k *= 10;
      cnt++;
    }
end:;
  // }
  // dump("finish");
}



Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> a(3);
  for(int i = 0;i < 3;i++) {
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  cout << a.at(0) + a.at(1) + a.at(2) * 10 << endl;
}

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

long long modnum = 1000000007;

long long unrelated(int index, bool ber){
    long long ber_e = (ber == true);
    long long ber_ne = (ber == false);
    while(index > 0){
        long long new_ber_e = ber_ne;
        long long new_ber_ne = (ber_e + ber_ne) % modnum;
        
        ber_e = new_ber_e;
        ber_ne = new_ber_ne;
        index--;
    }
    return (ber_e + ber_ne) % modnum;
}

int main(){
    int H, W, K;
    std::cin >> H >> W >> K;
    
    std::vector< std::vector< long long > > cnt(H+1, std::vector< long long >(W, 0));
    cnt[0][0] = 1;
    for(int i=1; i<W; i++){
        cnt[0][i] = 0;
    }
    
    for(int i=1; i<=H; i++){
        for(int j=0; j<W; j++){
            long long cur = 0;
            long long tmp;
            if(j != 0){
                tmp = (unrelated(j-1, true) * unrelated(W - j - 2, false)) % modnum;
                tmp = (tmp * cnt[i-1][j-1]) % modnum;
                cur = (cur + tmp) % modnum;
            }
            
            tmp = (unrelated(j-1, false) * unrelated(W - j - 2, false)) % modnum;
            tmp = (tmp * cnt[i-1][j]) % modnum;
            cur = (cur + tmp) % modnum;
            
            if(j != W-1){
                tmp = (unrelated(j-1, false) * unrelated(W - j - 2, true)) % modnum;
                tmp = (tmp * cnt[i-1][j+1]) % modnum;
                cur = (cur + tmp) % modnum;
            }
            cnt[i][j] = cur;
        }
    }
    
    std::cout << cnt[H][K-1] << std::endl;;
    
    return 0;
    
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j;
	long int height;
	long int a, b, c;
	long int flg = 0;
	long int h[100000] = {0};
	
	scanf("%ld%ld%ld", &a, &b, &c);
	
	if(a < b + c) {
		printf("%ld\n", b + c - a);
	} else {
		printf("%ld\n",0);
	}
	
	
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector <int> d(N);
  for (int i = 0; i < N; i++) {
	  cin >> d[i];
	}
  sort(d.begin(), d.end());
  cout << d[N / 2] - d[N / 2 - 1] << endl;
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;
int dp[1111][1111];
int w[1111],v[1111];
int main(){
  int W,N;
  int c = 1;
  while(1){
    cin >> W;
    if(!W)break;
    cin >> N;
    for(int i=0;i<N;i++){
      scanf("%d,%d",&v[i],&w[i]);
    }
    memset( dp , 0 , sizeof(dp) );
    for(int i=0;i<N;i++){
      for(int j=0;j<=W;j++){
	if(j<w[i]){
	  dp[i + 1][j] = dp[i][j];
	}else {
	  dp[i + 1][j] = max( dp[i][j] , dp[i][j - w[i]] + v[i] );
	}
      }
    }
    int ret=0,value=0;
    for(int i=0;i<=W;i++){
      if(value<dp[N][i]){
	ret = i;
	value = dp[N][i];
      }
    }
    cout << "Case " << c++ << ":" <<  endl;
    cout << dp[N][W] << endl;
    cout << ret << endl;
  }
}

Measured memory_bytes: 6080
N,X,Y=map(int,input().split())
X,Y=X-1,Y-1
d=[0]*N
for i in range(N-1):
  for j in range(i+1,N):
    a=min(abs(j-i),abs(X-i)+1+abs(j-Y))
    d[a]+=1
for i in range(1,N):
  print(d[i])

Measured memory_bytes: 9336
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f[509];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	for(c=1; c<=a; c++) cin>>f[c];
	for(c=1; c<=a; c++){
		for(d=1; d<=a; d++){
			swap(f[c],f[d]);
			for(e=2; e<=a; e++){
				if(f[e]<f[e-1]) break;
			}
			if(e==a+1){
				cout<<"YES";
				return 0;
			}
			swap(f[c],f[d]);
		}
	}
	cout<<"NO";
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 4) {
    if(s[i]=='+') ans++;
    else ans--;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
//#include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ...

#define pi 3.14159265358979323846
#define rep(i, n) for (int i = 0; i < n; i++)
using  ll = long long;
using ld = long double;
using Byte = unsigned char;
using namespace std;

//string ans = "Yes";
int ans = 0;
string Big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

string SetAns() {
	char L;
	cin >> L;
	rep(i, 26) {
		if (Big[i] == L) return "A";
	}

	return "a";
}

int main() {
	cout << SetAns() << endl;
	return 0;
}


Measured memory_bytes: 3128
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                String S = sc.next();
                int[] num = new int[4];
                for (int i = 0; i < S.length(); i++) {
                        switch (S.charAt(i)) {
                                case 'K':num[0]++;break;
                                case 'U':num[1]++;break;
                                case 'P':num[2]++;break;
                                case 'C':num[3]++;break;
                        }
                }
                int ans = 1 << 30;
                for (int i = 0; i < 4; i++) {
                        ans = Math.min(num[i], ans);
                }
                System.out.println(ans);
        }
}

Measured memory_bytes: 26120
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
    
#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void)
{
    
    int  number1, number2;
    long long answer2 = 0; int answer1;
    int temp;
    int i;
    long long answer2array[1000] = {1};
    int answer1array[1000] = {0};
    int counter = 0;
    
    while(cin >> number1 >> number2)
    {
        /*?????§??¬?´???°???????±???????*/
        int x = 0, y = 0, x2 = 0, x1 = 0;
        if(number1 > number2)
        {
            x = number1;
            y = number2;
            x1 = x;
            x2  = y;
        }
        else
        {
            x = number2;
            y = number1;
            x1 = x;
            x2 = y;
            
        }
        while(x % y)
        {
            temp = (x % y);
            x = y;
            y = temp;
        }
        answer1 = y;
        /*????°???¬?????°????±???????*/
        for(i = 1;i<=x2;i++)
        {
            if((x1*i)%x2 == 0)
            {
                answer2 = (long long)(x1*i);
                break;
            }
        }
        
        answer2array[counter] = answer2;
        answer1array[counter] = answer1;
        counter++;
        }
        REP(i, counter)
    cout << answer1array[i] << " " << answer2array[i] << endl;
    return 0;
    

    }

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, b) for(int i = 0; i < b; i++)
#define repr(i, b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    int n; cin >> n;
    vector<char> s(n);
    stack<int> st;
    for(int i = 0; i < n; i++) {
        cin >> s[i];
        if(s[i] == 'R') {
            st.push(i);
        }
    }
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        if(st.empty()) break;
        if(!st.empty() && i > st.top()) {
            break;
        }
        if(s[i] == 'W') {
            if(!st.empty()) {
                st.pop();
                cnt++;
            }
        }
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 4360
local n = io.read("n")

local function pow_mod(x, y)
	local result = 1
	for i = 1, y do
		result = (result * x) % 1000000007
	end
	return result
end

local out = pow_mod(10, n)
out = (out - pow_mod(9, n)) % 1000000007
out = (out - pow_mod(9, n)) % 1000000007
out = (out + pow_mod(8, n)) % 1000000007
print(out < 0 and out + 1000000007 or out)


Measured memory_bytes: 2796
n=int(input())
xy=[tuple(map(int,input().split())) for _ in range(n)]
import numpy as np
e=(1,0)
xyz=[]
k=0
for x,y in xy:
  if x==0 and y==0:continue
  k+=1
  l=np.linalg.norm((x,y))
  z=np.inner((x/l,y/l),e)
  theta = np.rad2deg(np.arccos(z))
  if y<0:
    theta=360-theta
  xyz.append((x,y,theta))
xyz.sort(key=lambda x:x[2])


tx,ty=0,0
c=[(0,0)]
for x,y,z in xyz:
  tx+=x
  ty+=y
  c.append((tx,ty))
for x,y,z in xyz:
  tx+=x
  ty+=y
  c.append((tx,ty))

ans=0
for i in range(k):
  for j in range(k):
    x=c[i+j+1][0]-c[i][0]
    y=c[i+j+1][1]-c[i][1]
    ans=max(ans,(x**2+y**2)**0.5)
print(ans)


Measured memory_bytes: 27152
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void prnt(vector<int> b){
	for(int i=0;i<b.size();i++){
		cout<<b[i]<<endl;
	}
	return;
}
void ok(vector<int>& b,vector<int>& ans,int* bo){
	//prnt(b);
	//cout<<"size="<<b.size()<<endl;
	if(b.size()==1&&b[0]==1){
		//cout<<"hoge\n";
		ans.push_back(1);
		*bo=1;
		return;
	}
	for(int i=b.size()-1;i>=0;i--){
		if(b[i]==i+1){
			//cout<<"ho\n";
			b.erase(b.begin()+i);
			ans.push_back(i+1);
			ok(b,ans,bo);
			if(*bo==1) return;
			ans.pop_back();
			b.insert(b.begin()+i,i+1);
			break;
		}
	}
	return ;
}

int main(){
	int n;
	cin>>n;
	vector<int> b(n,0);
	vector<int> ans;
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	int bo=0;
	ok(b,ans,&bo);
	//cout<<"bo="<<bo<<endl;
	if(bo==1){
		for(int i=0;i<ans.size();i++){
			cout<<ans[ans.size()-i-1]<<endl;
		}
	}else{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		dPA();

	}

	private static void dPA() {
		Scanner scanner = null;
		int numDay = 0;

		try {
			scanner = new Scanner(System.in);
			numDay = scanner.nextInt();
			int[][] dayArray = new int[numDay][3];
			int[][] koufukuArray = new int[numDay + 1][3];

			for (int i = 0; i < numDay; i++) {
				dayArray[i][0] = scanner.nextInt();
				dayArray[i][1] = scanner.nextInt();
				dayArray[i][2] = scanner.nextInt();
			}

			for (int i = 0; i < numDay; i++) {

				for (int j = 0; j < 3; j++) {
					for (int k = 0; k < 3; k++) {
						if (j == k) {
							continue;
						}
						if (i != 0) {
							koufukuArray[i][j] = Math.max(koufukuArray[i - 1][k] + dayArray[i][j], koufukuArray[i][j]);
						} else {
							koufukuArray[i][j] = dayArray[i][j];
						}

					}
				}
			}

			int koufuku = 0;
			for (int i = 0; i < 3; i++) {
				koufuku = Math.max(koufuku, koufukuArray[numDay - 1][i]);
			}

			System.out.println(koufuku);
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 103808
# -*- coding: utf-8 -*-
import collections
s = (input())

"""
n = len(s)
ans = 0
for i in range(n-4):
    for j in range(i+4,n+1):
        if int(s[i:j]) % 2019 == 0:
            ans += 1
print(ans)
"""

n = len(s)
ans = 0
l = 0
#r = l
num = int(s)

tmp = [0 for _ in range(n+1)]
ten = [0 for _ in range(n)]
tmp1 = 0
val = 1
for i in range(0,n):
    ten[i] = val
    tmp1 += (int(s[n-i-1]) * val)
    tmp[i+1] = tmp1 % 2019
    val = (val * 10) % 2019
#print(tmp)

c = collections.Counter(tmp)
#print(c)
for i in range(0, 2020):
    a = c[i]
    if a > 0:
        ans += ((a * (a - 1)) // 2)
print(ans)


Measured memory_bytes: 97460
#include <iostream>
#include <vector>
#include <string>
//#include <fstream>

using namespace std;

bool dfs (int row, int col, char p, vector <string> d, vector <vector <bool> >& used )
{
	// order up right down left
	const int dir[][2] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };
	int size = d.size();
	int len  = d[0].size();
	int k;

	if (used[row][col] ){
		return false;
	} // end if

	used[row][col] = true;

	for (k = 0; k < 4; ++k){
		int nrow = row + dir[k][0];
		int ncol = col + dir[k][1];
		if (nrow < 0 || nrow >= size || ncol < 0 || ncol >= len ){
			continue;
		} // end if
		if (!used[nrow][ncol] && d[nrow][ncol] == p ){
			if (dfs (nrow, ncol, p, d, used )){
				return true;
			} // end if
		} // end if
	} // end for

	return false;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.property", "r", stdin );

	string str = "";
	int h, w;

	while (1){
		cin >> h;
		cin >> w;
		
		if (h == 0 && w == 0 ){
			break;
		} // end if
		
		vector <string> d (h, string (w, ' ') );

		int i,j;

		for (i = 0; i < h; ++i){
			cin >> str;
			for (j = 0; j < w; ++j){
				d[i][j] = str[j];
			} // end for
		} // end for

		vector <vector <bool> > used (h, vector <bool> (w, false ) ); 

		int res = 0;
		
		for (i = 0; i < h; ++i){
			for (j = 0; j < w; ++j){
				if (!used[i][j] ){
					dfs (i, j, d[i][j], d, used );
					++res;
				} // end if
			} // end for
		} // end for

		cout << res << endl;	
	} // end loop
		
	return 0;
}

Measured memory_bytes: 4176
use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        a: usize,
        b: usize
    }

    let mut ans = 0;

    if a > b {
        for i in 0..a {
            ans += b * usize::pow(10, i as u32);
        }
    } else {
        for i in 0..b {
            ans += a * usize::pow(10, i as u32);
        }
    }

    println!("{}", ans);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 8572
#include<stdio.h>
int main()
{
	int a,b,c,d,s1,s2;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	s1=a*b;
	s2=c*d;
	if(s1>=s2)
	  printf("%d\n",s1);
	else
	  printf("%d\n",s2);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
char x[100010],y[100010];
int main()
{
	scanf("%s%s",x+1,y+1);
	int a = strlen(x+1);
	for(int i=1;i<=a;i++)
	{
		if(x[i]!=y[i])
		{
			printf("No");
			return 0;
		}
	}
	printf("Yes");
}

Measured memory_bytes: 1740