akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<ii> ans;
vi adj[222222];

void addedge(int u, int v)
{
	ans.pb(mp(u,v)); adj[u].pb(v); adj[v].pb(u);
}

ll h[222222];
ll sub[222222];

void dfs(int u, int p)
{
	sub[u]=1;
	for(int v:adj[u])
	{
		if(v==p) continue;
		h[v]=h[u]+1;
		dfs(v,u);
		sub[u]+=sub[v];
	}
}

ll ans2[222222];

void dfs2(int u, int p, int n)
{
	for(int v:adj[u])
	{
		if(v==p) continue;
		ans2[v] = ans2[u] + n - 2*sub[v];
		dfs2(v,u,n);
	}
}

ll ori[222222];
bool check(int n)
{
	dfs(0,-1);
	ll ans = 0;
	for(int i=0;i<n;i++) ans+=h[i];
	if(ori[0]!=ans) return false;
	ans2[0] = ans;
	dfs2(0,-1,n);
	for(int i=0;i<n;i++)
	{
		if(ans2[i]!=ori[i]) return false;
	}
	return true;
}

map<ll,int> ma;
int S[222222];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<ii> vec;
	for(int i=0;i<n;i++)
	{
		ll x; cin>>x; vec.pb(mp(x,i)); ori[i]=x; ma[x]=i;
	}
	sort(vec.rbegin(),vec.rend());
	for(int i=0;i<n;i++) S[i]=1;
	for(int i=0;i<n-1;i++)
	{
		ll cur = vec[i].fi; int u = vec[i].se;
		//S[u] is confirmed
		ll newd = cur - (n - 2*S[u]);
		if(ma.find(newd)==ma.end())
		{
			cout<<-1<<'\n'; return 0;
		}
		int v = ma[newd];
		addedge(u,v);
		S[v]+=S[u];
		//cerr<<"ADD "<<u<<' '<<v<<'\n';
	}
	if(check(n))
	{
		for(ii x:ans)
		{
			cout<<x.fi+1<<' '<<x.se+1<<'\n';
		}
	}
	else
	{
		cout<<-1<<'\n';
	}
}


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

int main(void){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<a) cout<<k<<endl;
    else if(k<=a+b) cout<<a<<endl;
    else if(k<=a+b+c) cout<<a-(k-b-a)<<endl;
    else cout<<a-c<<endl;
}



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

typedef long long ll;

int main(){
	int N,K;
	cin >> N >> K;
	vector<ll> a;
	for(int i=0; i<N; i++){int tt; cin >> tt; a.push_back(tt); }

	ll ans = 1e18;
	for(int bit=0; bit<(1<<N); bit++){
		vector<int> cp(N);
		copy(a.begin(),a.end(),cp.begin());
		int t = cp[0]; ll diff=0;
		for(int i=1; i<N; i++){
			if(bit & (1<<i)){
				if(t>=cp[i]){diff += t-cp[i]+1; cp[i]+=t-cp[i]+1;}

			}
			 t = max(t,cp[i]);
		}
		int cnt=0;
		t = cp[0];
		for(int i=1; i<N; i++){
			if(cp[i]>t){cnt++; t=cp[i];}
		}
		if(cnt>=K-1){ ans = min(ans,diff); }
	}

	cout << ans << endl;
}

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

using namespace std;
int i,j,n,m,dp[1005][1005];
const int mod=1e9+7;
char ch;
int calc_modulo(int x)
{
    if(x<mod)return x;
    else return x-mod;
}
int main()
{
    cin>>n>>m;
    dp[1][1]=1;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
    {
        cin>>ch;
        if(ch=='.')
            dp[i][j]=calc_modulo(dp[i][j]+calc_modulo(dp[i-1][j]+dp[i][j-1]));
    }
    cout<<dp[n][m];
    return 0;
}


Measured memory_bytes: 4224
import java.util.Scanner;
class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n ;
    int m;
    n = sc.nextInt();
    m = sc.nextInt();
    double[] A = new double[n];
    int i;
    double sum;
    sum = 0;
    for(i=0; i < n ;i++){
      A[i] = sc.nextDouble();
      sum += A[i];
    }
    double counter = 0;
    double rate = sum /(4 * m);
    for(i=0 ; i<n ; i++){
      if(A[i] >= rate){
        counter++;
      }else{
        continue;
      }
    }
    if(counter >= m){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23380
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#include <cassert>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
#define vi vector<int>
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

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

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

struct s{
  int p,i,r;
};

//比較関数（降順）
bool cmpP(const s &a, const s &b){
  return a.p > b.p;
}

//比較関数（昇順）
bool cmpI(const s &a, const s &b){
  return a.i < b.i;
}

int n,S;
int main()
{

  //cout << fixed << setprecision(10);
  while (cin >> n && n>0){
    int sum=0,M=0,m=1000;
    rep(i,n){
      cin >> S;
      sum += S;
      M = max(S,M);
      m = min(S,m);
    }
    cout << (sum-(M+m))/(n-2) << endl;
  }


  return 0;
}



Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, a, b;
    cin >> n >> a >> b;

    if (n % (a + b) <= a) {
        cout << (n / (a + b)) * a + n % (a + b) << endl;
    } else if (a < n % (a + b)) {
        cout << (n / (a + b)) * a + a << endl;
    }

    return 0;
}

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

int main() {
    int n,k; cin >> n >> k;
    ll total = 0;
    vector<int>v(n);
    //special moves can kill all monsters, ans = 0
    if(k >= n){
        cout << 0 << endl;
        return 0;
    }
    
    for(int i = 0; i < n; i++){
        int m; cin >> m;
        v[i] = m;
        total+=m;
    }
    if(k == 0){
        cout << total << endl;
        return 0;
    } else{
        total = 0;
    }
    sort(v.rbegin(),v.rend());
    for(int i = k; i < n; i++){
        total += v[i];
    }
    cout << total << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Test int T;cin>>T;while(T--)
#define ls lower_bound
#define up upper_bound
#define bs binary_search
#define S second
#define F first
#define vi vector<int>  
#define pii pair<int,int>
#define vpi vector<pii>
#define vvi vector<vi>
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define m_n(v) *min_element(all(v))
#define m_x(v) *max_element(all(v))
#define ___(a) for(auto &i:a) cin>>i
/* 
#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
*/
int power(int x, int y,int mod){
    int res = 1;
    while (y)
    {
        if (y & 1)
        res = (res*x)%mod;
        y = y>>1;
        x = (x*x)%mod;
    }
    return res;
}
int modInverse(int a, int m){
    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
int binomial(int n,int k){
    int res = 1;
    if ( k > n - k )
        k = n - k;

    for (int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}
/*
vector<int> prime;
void sieve(){
    bool arr[300000]={0};
    prime.pb(2);
    for(int i=3;i<300000;i+=2){
        if(arr[i])continue;
        for(int j=i*i;j<300000;j+=i) arr[j]=1;
        prime.pb(i);
    }
}*/
//const int N=1e18+2;
const int mod = 1e9+7;
const int N= 1e5+9;

int32_t main() {
    IOS;
    string a,b;
    int ans=0;
    cin>>a>>b;
    for(int i=0;i<a.size();i++){
        if(a[i] != b[i]) ans++;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3804
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
void fo (){fflush(stdout);}
using namespace std;
ll fact (int x ){return (x <= 1 ? 1 : 1LL * x * fact (x-1));}
string a [50], b[50] ;
int n , m ;
bool ok (int x , int y )
{
  for (int i = x , ro = 0 ; i - x < m ;ro++ , i++)
  {
    for (int j = y , col = 0 ; j - y < m ;col++ , j++)
    {
      if (a[i][j] != b[ro][col])return false ;
    }
  }
  return  true ;
}
int main ()
{
  cin >> n >> m ;
  for (int i =0 ; i < n ;i++)cin >> a[i];
  for (int i =0 ; i < m ;i++)cin >> b[i];

  for (int i =0 ; i + m <=  n ;i++)
  {
    for (int j =0 ; j + m <=  n ;j++)
    {
      if (ok(i , j ))
      {
        cout <<"Yes\n";
        return 0 ;
      }
    }
  }
  cout <<"No\n";
  //cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

Measured memory_bytes: 256
def euclid(x,y):
    a = max(x,y)
    b = min(x,y)
    
    r =  a % b
    while r != 0:
        a = b
        b = r
        r = a % b

    return b


N,K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

if N == 1:
    if K == A[0]:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
else:
    
    M = max(A)
    G = euclid(A[0],A[1])
    for i in range(1,N):
        G = euclid(A[i],G)
    
    if K % G == 0 and K <= M:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
    
print(ans)

Measured memory_bytes: 14480
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	lint N;
	cin >> N;
	
	lint ans = N;
	lint R = (lint)sqrt(N) + 1;
	for (lint x=1; x<=R; ++x) {
		lint y = N / x;
		if (x * y == N) minUpdate(ans, x + y - 2);
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T C(){T x;cin>>x;return (x);}

template <class T = ll>
T CI(T& t){cin>>t;}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=C();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)

int main(){
  SCIN(s);s[5]=' ';s[13]=' ';COUT(s);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>

using namespace std;
typedef long long li;

vector<li> divisors(li n) {
    vector<li> divisors;
    for (li x = 1; x * x <= n; x++) {
        if (n % x == 0) {
            divisors.push_back(x);
            if (n / x != x) {
                divisors.push_back(n / x);
            }
        }
    }
    return divisors;
}

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

    li n, k;
    cin >> n >> k;

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

    li total = accumulate(xs.begin(), xs.end(), 0LL);

    li ans = 1;
    for (const auto &candidate : divisors(total)) {
        vector<li> negcosts;
        for (int i = 0; i < n; ++i) {
            negcosts.push_back(xs[i] % candidate);
        }
        sort(negcosts.begin(), negcosts.end());
        reverse(negcosts.begin(), negcosts.end());

        li negcost = accumulate(negcosts.begin(), negcosts.end(), 0LL);
        li poscost = 0;
        bool ok = negcost <= k;
        for (int i = 0; i < n; ++i) {
            negcost -= negcosts[i];
            poscost += (candidate - negcosts[i]) % candidate;
            if (negcost <= k && poscost <= k) {
                ok = true;
            }
        }
        if (ok) {
            ans = max(ans, candidate);
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())

D=N()
c=[0]+L()
s=[[0]*27]+[[0]+L() for i in range(D)]

dp=[]
T=[0]
ld=[0]*(27)
for i in range(1,D+1):
    ma=0
    t=0
    for j in range(1,27):
        tmp=s[i][j]+(i-ld[j])*(D-i+1)*c[j]
        if tmp>ma:
            ma=tmp
            t=j
    T.append(t)
    ld[t]=i
        
sc=sum(c)
def point():
    ld=[0]*(27)
    score=-sc*((D+1)*D//2)
    for i in range(1,D+1):
        t=T[i]
        score+=s[i][t]+(i-ld[t])*(D-i+1)*c[t]
        ld[t]=i
    return score

now=point()
import random
for i in range(400000):
    d1,q1=random.randrange(1,D+1),random.randrange(1,27)
    d2,q2=random.randrange(1,D+1),random.randrange(1,27)
    d3,q3=random.randrange(1,D+1),random.randrange(1,27)
    old1=T[d1]
    old2=T[d2]
    old3=T[d3]
    T[d1]=q1
    T[d2]=q2
    T[d3]=q3
    new=point()
    if new>now:
        now=new
    else:
        T[d1]=old1
        T[d2]=old2
        T[d3]=old3
        
for i in T[1:]:
    print(i)

Measured memory_bytes: 100052
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int main(){
  string w;
  cin>>w;
  int n=w.size();
  sort(all(w));
  int count=1;
  char check=w[0];
  rep2(i,1,n){
    if(check==w[i]) count++;
    if(check!=w[i]&&count%2!=0){
      cout<<"No"<<endl;
      return 0;
    }
    if(check!=w[i]&&count%2==0){
      check=w[i];
      count=1;
    }
  }
  if(count%2!=0){
    cout<<"No"<<endl;
    return 0;
  }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define j1 j1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  ll M,K; cin>>M>>K;

  if(K>(1<<M)-1){
    cout<< -1<<"\n";
    return;
  }

  if(M==0){
    cout<< 0 <<" "<<0<<"\n"; return;
  }

  if(M==1){
    if(K==0){
      cout<< 0 <<" "<<1 <<" "<<1 <<" "<<0 <<"\n"; return;
    }
    else{
      cout<< -1<<"\n"; return;
    }
  }

  rep(i,(1<<M)){
    if(i!=K) cout<< i<<" ";
  }
  cout<< K <<" ";

  repr(i,(1<<M)-1,0){
    if(i!=K) cout<< i<<" ";
  }
  cout<< K<<"\n";


}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	string s;
	cin>>s;

	lli cnt=0;

	lli sCnt=0;
	REP(i,0,s.size()){
		if(s.at(i)=='S')sCnt++;
		else{
			if(sCnt>0)sCnt--;
			else cnt++;
		}
	}
	cout<<cnt+sCnt<<endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
 
int main(){
    int N;
    cin >> N;
    int sum = digsum(N);
    if (N%sum == 0) cout << "Yes\n";
    else cout << "No\n";
}


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

void bubbleSort(int A[],int N){
    bool flag = 1;
    int cnt = 0;
    while(flag){
        flag=0;
        for(int j=N-1;j>0;j--){
            if(A[j]<A[j-1]){
                swap(A[j],A[j-1]);
                flag = 1;
                cnt++;
            }
        }
    }
    rep(i,N){
        if(i > 0){
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl << cnt << endl;


}

int main()
 {
    int n;
    cin >> n;
    int A[n];
    rep(i,n){
        cin >> A[i];
    }
    bubbleSort(A,n);

}



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

int main(){
  int m=0,s=0, N,p[12];cin>>N;
  REP(i,N)cin>>p[i],s+=p[i],m=max(m,p[i]);
  cout<<s-(m/2)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
using ll=long long;
using ii=pair<ll,ll>;

ll a,b,c,i,j,l,m,n,ans,tmp,hoge,fuga,piyo;
long long k;
int AC[100000];
int WA[100000];
int main() {
    cin>>n>>m;
    // int WA = 0;
    int nAC = 0;
    for (int i = 0; i < m; i++) {
        int p;
        char S[3] = {0};
        scanf("%d %s", &p, S);
        if (AC[p] == 1) {
            continue;
        } else {
            if (S[0] == 'W') {
                WA[p]++;
            } else {
                nAC++;
                AC[p] = 1;
            }
        }
    }
    int nWA = 0;
    for (int i = 0; i < n + 1; i++) {
        if (AC[i] == 1) {
          nWA += WA[i];
        }
    }
    printf("%d %d", nAC, nWA);
    return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

def solve():
    MOD = 998244353

    N = int(input())
    pts = [tuple(map(int, input().split())) for _ in range(N)]

    iXs = list(range(N))
    iXs.sort(key=lambda iX: pts[iX][0])
    iYs = list(range(N))
    iYs.sort(key=lambda iY: pts[iY][1])
    odrYs = [0]*(N)
    for odrY, iY in enumerate(iYs):
        odrYs[iY] = odrY

    def init(As):
        numPow2 = 2 ** (len(As)-1).bit_length()
        data = [0] * (numPow2+1)
        return data, numPow2
    def addValue(iA, A):
        iA += 1
        while iA <= numPow2:
            data[iA] += A
            iA += iA & -iA
    def getSum(iA):
        iA += 1
        ans = 0
        while iA > 0:
            ans += data[iA]
            iA -= iA & -iA
        return ans

    numPtss = [[0]*(4) for _ in range(N)]

    data, numPow2 = init([0]*N)
    for odr, iX in enumerate(iXs):
        y = odrYs[iX]
        num = getSum(y)
        numPtss[iX][0] = num
        numPtss[iX][1] = odr - num
        addValue(y, 1)

    data, numPow2 = init([0]*N)
    for odr, iX in enumerate(reversed(iXs)):
        y = odrYs[iX]
        num = getSum(y)
        numPtss[iX][2] = num
        numPtss[iX][3] = odr - num
        addValue(y, 1)

    def getPows(base, n, MOD):
        pows = [1] * (n+1)
        for x in range(1, n+1):
            pows[x] = (pows[x-1] * base) % MOD
        return pows

    pow2s = getPows(2, N, MOD)

    ans = 0
    for numPts in numPtss:
        num = pow2s[N-1]
        nums = [pow2s[k] for k in numPts]
        num += (nums[0]-1)*(nums[1])*(nums[2])*(nums[3]-1) % MOD
        num += (nums[0])*(nums[1]-1)*(nums[2]-1)*(nums[3]) % MOD
        num -= (nums[0]-1)*(nums[1]-1)*(nums[2]-1)*(nums[3]-1) % MOD
        ans += num % MOD
        ans %= MOD

    print(ans)


solve()


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

#define pb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vi vector
#define forn(i, l, r) for(int i = l; i <= r; i++)
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define f80 double
#define LOCAL 0
#define endl '\n'

typedef long long int ll;
#define int long long int

const int mod = 1e9 + 7;
const int N = 100005;
const int inf = 2e9;

signed main(){
    IO;
    if(LOCAL){
        freopen("inp.txt", "r", stdin);
    }
    string s, t;
    cin >> s >> t;
    int n = s.size();
    for(int p = 0; p < n; p++){
        bool yes = 1;
        for(int i = 0; i < n; i++){
            if(s[(p + i) % n] != t[i])
                yes = 0;
        }
        if(yes)
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
// #define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}
/*		1. Take all the inputs
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	// int main  or  int32_t main ...
	string s;
	cin >> s;
	if(s[0]=='7' || s[1]=='7' || s[2]=='7')cout << "Yes" << endl;
	else cout << "No" << endl;
}
/*	memset() can be used to set all values as 0 or -1 for integer data types.*/

int main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int t; t = 1;
	// cin >> t;
	while(t--){ solve(); }
	return 0;
}


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

using namespace std;

int n, x, y;
const int bias = 8005;
char str[8010];
int arr[2][8010];
bool can[2][16010];

bool solve(int arr[], int m, int x) {
    int i, j, s = 0;
    memset(can,0,sizeof(can));
    can[0][bias] = 1;
    sort(arr,arr+m);
    for (i=0;i<m;i++) {
        for (j=-s;j<=s;j++) {
            if (can[0][bias+j]) {
                can[1][bias+j+arr[i]]=can[1][bias+j-arr[i]]=1;
            }
        }
        s += arr[i];
        for (j=-s;j<=s;j++) {
            can[0][j+bias]=can[1][j+bias];
            can[1][j+bias]=0;
        }
    }
    return x>=-s&&x<=s&&can[0][x+bias];
}

int main() {
    scanf("%s",str); n = strlen(str);
    scanf("%d%d",&x,&y);
    int i=0;
    for (;str[i]=='F';i++);
    x-=i; int c = 0;
    for (;str[i];c++) {
        i++; int j=i;
        for (;str[i]=='F';i++);
        arr[(c+1)%2][c/2]=i-j;
    }
    if (solve(arr[0],c/2+1,x)&&solve(arr[1],c/2+1,y)) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 384
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect
def main():
    a,b,q=map(int,input().split())
    S=[int(input())for _ in range(a)]
    T=[int(input())for _ in range(b)]

    def dfs(cur,flag1,flag2):
        if flag2==1:
            index_s=bisect(S,cur)
            #print(cur,index_s)
            if index_s>0 and index_s<a:
                if flag1==0:
                    return min(abs(S[index_s-1]-cur),abs(S[index_s]-cur))
                else:
                    return min(dfs(S[index_s-1],0,0)+abs(S[index_s-1]-cur),dfs(S[index_s],0,0)+abs(S[index_s]-cur))
            else:
                if index_s==a:
                    nx=S[-1]
                elif index_s==0:
                    nx=S[0]
                if flag1==1:
                    return dfs(nx,0,0)+abs(nx-cur)
                else:
                    return abs(nx-cur)
        else:
            index_t=bisect(T,cur)
            #print(cur,index_t)
            if index_t>0 and index_t<b:
                if flag1==0:
                    return min(abs(T[index_t-1]-cur),abs(T[index_t]-cur))
                else:
                    return min(dfs(T[index_t-1],0,1)+abs(T[index_t-1]-cur),dfs(T[index_t],0,1)+abs(T[index_t]-cur))
            else:
                if index_t==b:
                    nx=T[-1]
                elif index_t==0:
                    nx=T[0]
                if flag1==1:
                    return dfs(nx,0,1)+abs(nx-cur)
                else:
                    return abs(nx-cur)

    for i in range(q):
        x=int(input())
        print(min(dfs(x,1,1),dfs(x,1,0)))


if __name__=='__main__':
    main()

Measured memory_bytes: 88668
// atcoder 
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int out = 1;
    if (N==1){
        cout << M << endl;
        return 0;
    }
    for (int i=2; i<=M/2; i++){
        if (M%i==0 && M/i >= N){
            out = max(out, i);
        }
        else if (M/i < N) break;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
w = input()
temp_set = {w}
c = w[-1]
ans = "Yes"
for _ in range(n - 1):
    w = input()
    if w[0] != c or w in temp_set:
        ans = "No"
        break
    temp_set.add(w)
    c = w[-1]
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <list>
#include <math.h>

using namespace std;

int main()
{
	int a, b, c, d, e, k;
	std::cin >> a >> b >> c >> d >> e >> k;

	if (e - a > k) {
		std::cout << ":(";

	}
	else {
		std::cout << "Yay!";
	}
	


}

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

vector<int> dat, gannnen;
vector<string> name;

int toInt(int y, int m, int d) {
  return y*10000 + m*100 + d;
}

void make() {
  name.push_back("pre-meiji");
  dat.push_back(toInt(0,0,0));
  gannnen.push_back(0);
  name.push_back("meiji");
  dat.push_back(toInt(1868,9,8));
  gannnen.push_back(1868);
  name.push_back("taisho");
  dat.push_back(toInt(1912,7,30));
  gannnen.push_back(1912);
  name.push_back("showa");
  dat.push_back(toInt(1926,12,25));
  gannnen.push_back(1926);
  name.push_back("heisei");
  dat.push_back(toInt(1989,1,8));
  gannnen.push_back(1989);
}

int getInd(int date) {
  return distance(dat.begin(),upper_bound(dat.begin(), dat.end(), date)) - 1;
}

int main() {
  make();
  int y, m, d;
  while(cin >> y >> m >> d) {
    int i = getInd(toInt(y,m,d));
    if(i)
      cout << name[i] << " " << y-gannnen[i]+1 << " " << m << " " << d << endl;
    else
      cout << name[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
// AOJ 2200: Mr. Rito Post Office
// 2017.12.9

#include <stdio.h>
#include <string.h>

int ll[202][202], ss[202][202];
int dp[1002][202];
int z[1002];

char buf[4000], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int n, m, r, x, y, t, i, j, k, ans;

    while (fgets(p=buf, 15, stdin) && *p != '0') {
		n = getint(), m = getint();

		memset(ll, 0x11, sizeof(ll));
		memset(ss, 0x11, sizeof(ss));
		for (i = 0; i < n; i++) ll[i][i] = ss[i][i] = 0;

		while (m--) {
			fgets(p=buf, 30, stdin);
			x = getint()-1, y = getint()-1, t = getint();
			if (*p == 'L') ll[x][y] = ll[y][x] = t;
			else           ss[x][y] = ss[y][x] = t;
		}
		fgets(p=buf, 10, stdin), r = getint();
		fgets(p=buf, 4000, stdin);
		for (i = 0; i < r; i++) z[i] = getint()-1;

		for (k = 0; k < n; k++) for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
			t = ll[i][k] + ll[k][j];
			if (t < ll[i][j]) ll[i][j] = t;
			t = ss[i][k] + ss[k][j];
			if (t < ss[i][j]) ss[i][j] = t;
		}

		memset(dp, 0x11, sizeof(dp));
		dp[0][z[0]] = 0;

		for (k = 1; k < r; k++) {
			for (i = 0; i < n; i++) {
				for (j = 0; j < n; j++) {
					if (i == j) t = dp[k-1][j] + ll[z[k-1]][z[k]];
					else 		t = dp[k-1][j] + ll[z[k-1]][j] + ss[j][i] + ll[i][z[k]];
					if (t < dp[k][i]) dp[k][i] = t;
				}
			}
		}
		ans = 0x7ffffff;
		for (i = 0; i < n; i++) if (dp[r-1][i] < ans) ans = dp[r-1][i];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2772
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

void bubblesort(int a[],int n){

	for(int i=n-1;i>=0;i--){
		for(int j=0;j<i;j++){
			if(a[j]>a[j+1]) swap(a[j],a[j+1]);
		}
	}

}

/*--- int型オブジェクトの比較関数 ---*/
int int_cmp(const int *a, const int *b)
{
    if (*a < *b)
        return (-1);
    else if (*a > *b)
        return (1);
    return (0);
}

int main()
{
	int n,q;
	int  S[100000],T[100000];
	int c=0;//カウント
	int i=0,j=0;

	cin>>n;
	for(int i=0;i<n;i++) cin>>S[i];

	cin>>q;
	for(int j=0;j<q;j++) cin>>T[j];

	//bubblesort(T,q);
	qsort(T,q,sizeof(int), (int(*)(const void*, const void*))int_cmp);
	//cout<<"test"<<endl;
	/*cout<<"S"<<endl;
	for(int i=0;i<n;i++) cout<<S[i]<<" ";
	cout<<endl;
		cout<<"Q"<<endl;
	for(int i=0;i<q;i++) cout<<T[i]<<" ";
	cout<<endl;*/
	

	while(j<q){
		if(S[i]==T[j]){
			c++;
			i++;
			j++;
		}
		if(S[i]>T[j]) j++;
		if(S[i]<T[j]) i++; 
	}

	cout<<c<<endl;
	
	return 0;
}


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

const int N = 100010;

struct edge {
    int to, next, w;
} e[N * 2];

int head[N], ecnt, dep[N], tot[N], ind[N], val[N], res;

char col[N];

inline void adde(int from, int to, int w) {
    res += w * 2;
    e[++ecnt] = (edge){ to, head[from], w }, head[from] = ecnt;
    e[++ecnt] = (edge){ from, head[to], w }, head[to] = ecnt;
    ind[from]++, ind[to]++;
} 

vector<int> G[N];

void dfs(int u, int f) {
    dep[u] = dep[f] + 1; 
    for (auto v : G[u]) if (v != f) {
        dfs(v, u), tot[u] += tot[v];
    }
}

void build(int u, int f, int t) {
    if (tot[u]) {
        if (t) adde(u, t, dep[u] - dep[t]);
        t = u;
    } 
    for (auto v : G[u]) if (v != f) 
        build(v, u, t);
}

int mx = -1, A[N], B[N];

inline void update(int u, int x) {
    if (A[u] < x) B[u] = A[u], A[u] = x;
    else if (B[u] < x) B[u] = x; 
}

void dfs1(int u, int f) {
    int t = (col[u] == 'B') ^ (ind[u] & 1);
    if (t) val[u] = -1;
    else res++, val[u] = 1;
    A[u] = B[u] = val[u];
    for (int i = head[u]; i; i = e[i].next)
        if (e[i].to != f) {
            dfs1(e[i].to, u);
            mx = max(mx,A[u] + A[e[i].to] + e[i].w);
            A[u] = max(A[u],A[e[i].to] + e[i].w + val[u]);
        }
}

int main() {
    int n; scanf("%d", &n);
    for (int i = 1, a, b; i < n; i++) 
        scanf("%d%d", &a, &b), G[a].push_back(b), G[b].push_back(a);
    scanf("%s", col + 1);
    int rt = -1;
    for (int i = 1; i <= n; i++) if (col[i] == 'W') rt = i, tot[i]++;
    if (rt == -1) return puts("0"), 0;
    dfs(rt, 0), build(rt, 0, 0), dfs1(rt, 0);
    printf("%d\n", res - mx - 1);
    return 0;
}

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

typedef vector<int> vec1;
typedef vector<vector<int>> vec2;
typedef vector<vector<char>> cvec2;
typedef pair<int, int> pairi;

vec1 vecplus(const vec1 &first, const vec1 &second){
  int length = first.size();
  vec1 answer(length);
  rep(i,length){
    answer.at(i) = first.at(i) + second.at(i);
  }
  return answer;
}

vec2 listmake(const int &row, const int &col){
  vec2 list;
  rep(i,row){
    vec1 v(col);
    rep(j,col){
      cin >> v.at(j);
    }
    list.push_back(v);
  }
  return list;
}

int main(){
  int X;
  int now, diff;
  cin >> X;
  vec1 divisors;
  rep(i,X/2+1){
    if(X%(i+1) == 0){
      divisors.push_back(i+1);
    }
  }
  int A, B;
  rep(i,divisors.size()){
    diff = divisors.at(i);
    now = 0;
    bool go = false;
    rep(i,X){
      A = now;
      B = now - diff;
      int C = A*A*A*A*A - B*B*B*B*B;
      if (C == X){
        go = true;
        break;
      }
      if (B > 0 && C > X){
        break;
      }
      now++;
    }
    if(go){
      break;
    }   
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>
int main(void){
  long long a,b,n,k,i;
  scanf("%lld %lld %lld",&a,&b,&n);
  k= floor((long double)a*n/b);
  if(b==1){
    printf("0");
    } else if(n<b) {
      printf("%lld",k);
    }else{
    k= floor((long double)a*(b-1)/b)-floor((long double)(b-1)/b);
          printf("%lld",k);
  }


  return 0;
}

Measured memory_bytes: 2220
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int a,b;
	cin >> a >> b;
	if (a*b %2 == 1){
		cout << "Odd" << endl;
	}
	else
	{
		cout << "Even" << endl;
	}
	
	return 0;
}

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

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

ans = 0
for i, e in enumerate(b):
    rem = e
    if e > a[i]:
        ans += a[i]
        rem = e - a[i]
    else:
        ans += e
        a[i] -= e
        continue

    if rem > a[i + 1]:
        ans += a[i + 1]
        a[i + 1] = 0
    else:
        ans += rem
        a[i + 1] -= rem

print(ans)


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

int main()
{
    int n;
    cin >> n;
    bool flag = false;
    rep(i, n/4 + 1)
        if ((n - 4 * i) % 7 == 0)
        {
            flag = true;
            break;
        }
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}



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

	cout<<"100 100\n";
	REP(i,50) REP(j,100){
		if(i%2==0&&j%2==0&&a!=1){
			a--;
			cout<<'.';
		}
		else cout<<'#';
		if(j==99) cout<<'\n';
	}
	REP(i,100) cout<<'.';
	cout<<'\n';
	REP(i,49) REP(j,100){
		if(i%2==0&&j%2==0&&b!=1){
			b--;
			cout<<'#';
		}
		else cout<<'.';
		if(j==99) cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	vi A(3);
	rep(i,0,3) cin>>A[i];
	sort(all(A));
	int ans;
	ans=A[2]-A[0];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.size(),ans=0;
    for(int i=0,j=n-1;i<j;i++,j--)
        ans+=(s[i]!=s[j]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
while True:
    M,F,R = map(int, input().split());
    if M == -1 and F == -1 and R == -1:
        break;
    if M == -1 or F == -1:
        print("F");
    else:
        sum = M + F;
        if sum >= 80:
            print("A");
        elif sum >= 65:
            print("B");
        elif sum >= 50:
            print("C");
        elif sum >= 30 and R < 50:
            print("D");
        elif sum >= 30 and R >= 50:
            print("C");
        else:
            print("F");


Measured memory_bytes: 5596
/*3.2 hightierra*/
#include <stdio.h>
 
int main(void){
    //変数の定義
    int N,amari;
    scanf("%d",&N);
    //amariにNの１の位を代入
    amari = N % 10;
 
    //amariの値で場合わけ
    switch(amari){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
          printf("hon");
          break;
        case 0:
        case 1:
        case 6:
        case 8:
          printf("pon");
          break;
        case 3:
          printf("bon");
          break;
    }
    return 0;
}

Measured memory_bytes: 1688
from math import sqrt,factorial
n = int(input())
l = []
for i in range(n):
  d = list(map(int,input().split()))
  l.append(d)
x = 2*factorial(n)//n
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    ans += x*sqrt(((l[i][0]-l[j][0])**2 + (l[i][1]-l[j][1])**2))
ans /= factorial(n)
print(ans)

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

void solve(long long N, long long M)
{
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <utility>
#include <iostream>
#include <cmath>
#include <deque>
#include <string>
#include <time.h>

#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef long long ll;
using namespace std;
#define MAXN 228228
#define MOD 1000000007
ll n, x, k, z, m, a[200500], b[200500], ra[200500], rb[200500], pa, pb;
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    reverse(a, a+n);
    ll p = 1;
    for (int i = 0; i + 1 < n; i++) {
        if (a[i] <= a[i+1]) {
            p++;
        } else {
            ans = max(ans, p);
            p = 1;
        }
    }
    ans = max(ans, p);
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>
int main(){
	int n,q,i,j,time=0;
	scanf("%d",&n);
	int s[n];
	for(i=0;i<n;i++)
	scanf("%d",&s[i]);
	scanf("%d",&q);
	int t[q];
	for(i=0;i<q;i++)
	scanf("%d",&t[i]);
	for(i=0;i<q;i++){
		j=0;
		s[n]=t[i];
		while(s[j]!=s[n])
		j++;
		if(j!=n)
		time++;
	}
	printf("%d\n",time);
	return 0;
} 


Measured memory_bytes: 2132
import java.util.*;

class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(true){
			int gu=0, choki=0, pa = 0;
			for(int i=0; i<5; i++){
				int res = in.nextInt();
				if(res == 0) return ;
				else if(res == 1) gu |= (1<<i);
				else if(res == 2) choki |= (1<<i);
				else if(res == 3) pa |= (1<<i);
			}
			int win=0;
			if(Integer.bitCount(gu)>0) win    |= 1;
			if(Integer.bitCount(choki)>0) win |= (1<<1);
			if(Integer.bitCount(pa)>0) win    |= (1<<2);
			if(Integer.bitCount(win) != 2){
				for(int i=0; i<5; i++)
					System.out.println(3);
			}
			else{
				if((win & 1)==0){
					for(int i=0; i<5; i++){
						System.out.println(((choki & (1<<i)) > 0)?1:2);
					}
				}
				if((win & 2)==0){
					for(int i=0; i<5; i++){
						System.out.println(((pa & (1<<i)) > 0)?1:2);
					}
				}
				if((win & 4)==0){
					for(int i=0; i<5; i++){
						System.out.println(((gu & (1<<i)) > 0)?1:2);
					}
				}
			}
		}
	}
	
}

Measured memory_bytes: 12000
S = input()
s = []
roop = True
index = [0]
cnt = 0
for i in S:
    if not(i == "x"):
        s.append(i)
        index.append(0)
    else:
        index[-1] += 1
for i in range(len(s) // 2):
    if s[i] != s[- i - 1]:
        roop = False
if roop:
    for i in range(len(index) // 2):
        if index[i] - index[- i - 1] >= 0:
            cnt += index[i] - index[- i - 1]
        else:
            cnt += index[- i - 1] - index[i]
    print(cnt)
else:
    print(-1)


Measured memory_bytes: 4820
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long n,k,dp[55][5005][55];
int main(){
	cin>>n>>k;
	dp[0][2500][0]=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<=5000;j++)
			for(int k=0;k<=i;k++){
				dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k]*(2*k+1)%mod)%mod;
				dp[i+1][j-(i+1)*2][k+1]=(dp[i+1][j-(i+1)*2][k+1]+dp[i][j][k])%mod;
				if(k)dp[i+1][j+(i+1)*2][k-1]=(dp[i+1][j+(i+1)*2][k-1]+dp[i][j][k]*k*k%mod)%mod;
			}
	if(k+2500>5000)puts("0");
	else printf("%lld",dp[n][k+2500][0]);
	return 0;
}

Measured memory_bytes: 108800
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	double x=0, y=0, a, b, now = 90;
	char c;
	while (cin >> a >> c >> b, a || b) {
		x += a * cos(M_PI * now / 180);
		y += a * sin(M_PI * now / 180);
		now = now - b;
	}
	if (x >= 0) x = floor(x);
	else if (x < 0) x = ceil(x);
	if (y >= 0) y = floor(y);
	else if (y < 0) y = ceil(y);
		cout << x << endl;
		cout << y << endl;
}

Measured memory_bytes: 1288
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <sstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

enum wsdf{RIGHT,DOWNLEFT,DOWN,UPRIGHT};
int out[10][10];
int dx[]={ 1,-1, 0, 1};
int dy[]={ 0, 1, 1,-1};
int d,n;

void solv(){
	int i=1;
	int cx=1,cy=0;
	d=RIGHT;
	out[0][0]=1;
	while(i<n*n){
		++i;
		out[cy][cx]=i;		
		
		if(cy==0 && d==RIGHT)d=DOWNLEFT;
		else if(cy==0 && d==UPRIGHT){
			if(cx==n-1)d=DOWN;
			else d=RIGHT;
		}else if(cx==0 && d==DOWNLEFT){
			if(cy==n-1)d=RIGHT;
			else d=DOWN;
		}else if(cx==0 && d==DOWN)d=UPRIGHT;
		else if(cy==n-1 && d==DOWNLEFT)d=RIGHT;
		else if(cy==n-1 && d==RIGHT)d=UPRIGHT;
		else if(cx==n-1 && d==UPRIGHT)d=DOWN;
		else if(cx==n-1 && d==DOWN)d=DOWNLEFT;
		
		cx+=dx[d];
		cy+=dy[d];
	}
}

main(){
	int c=0;
	while(cin>>n){
		++c;
		if(n==0)break;
		cout<<"Case "<<c<<":"<<endl;
		solv();
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				printf("%3d",out[i][j]);
			}
			puts("");
		}
	}
}

Measured memory_bytes: 0
def prime_t(t):
    i=2
    while i**2<=t:
        if t%i==0:
            return 0
        i+=1
    return 1
d=set([])
n=10**5+1
p=[0]*(10**5+1)
for i in range(2,n):
    if prime_t(i):
        d.add(i)
    if (i in d and (i+1)//2 in d): p[i]=p[i-1]+1
    else: p[i]=p[i-1]

q=int(input())
for i in range(q):
    ans=0
    l,r=map(int,input().split())
    print(p[r]-p[l-1])


Measured memory_bytes: 5068