akhauriyash/Code-Regression huggingface dataset:
icase=0
if icase==0:
    n=int(input())
    ww=set()
    w=[]
    for i in range(n):
        w.append(input())
    ww=set()
    ww.add(w[0])
    yn=""
    for i in range(n-1):
        if w[i][-1]!=w[i+1][0]:
            yn="No"
            print("No")
            break
        if w[i+1] in ww:
            yn="No"
            print("No")
            break
        else:
            ww.add(w[i+1])
    if yn!="No":
        print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

int main(){
	string s;
	cin >> s;

	int a = -1;
	int z = -1;
	rep(i, (int)(s.size())){
		if (s.at(i) == 'A' && a < 0) a = i;
		if (s.at(i) == 'Z') z = i;
	}
	cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

//container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int n;

int main() {
	vector<PII> v;
	REP(_,2){
		cin >> n;
		REP(i,n){
			int a, b;
			cin>>a>>b;
			v.push_back(MP(a,b));
		}
	}
	SORT(v);
	UNIQUE(v);
	REP(i, v.size()){
		cout << v[i].first << ":";
		if(v[i].second<10)cout << 0;
		cout << v[i].second;
		if(i<v.size()-1)cout << " ";
	}
	cout << endl;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  int n, m;
  char q;
  cin >> n >> m;
  int dp[n][n];
  rep(i, n) rep(j, n) dp[i][j] = i == j ? 0 : INF;
  rep(i, m) {
    int a, b, c, d;
    cin >> a >> q >> b >> q >> c >> q >> d;
    a--;
    b--;
    dp[a][b] = c;
    dp[b][a] = d;
  }
  rep(k, n) rep(i, n) rep(j, n) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
  int s, g, V, P;
  cin >> s >> q >> g >> q >> V >> q >> P;
  s--;
  g--;
  cout << V - P - dp[s][g] - dp[g][s] << endl;
  return 0;
}

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

// 素数判定
bool isPrime(int p) {
  if(p == 1) return false;
  else if(p == 2) return true;
  else if(p % 2 == 0) return false;
  
  double x = sqrt(p);
  for(int i = 3; i <= x; i += 2){
    if(p % i == 0) return false;
  }
  return true;
}

int main() {
  int n, i, count = 0;
  cin >> n;
  
  for(i = 7; i <= 55555; i += 5){
    if(isPrime(i)){
      cout << i << endl;
      count++;
    }
    
    if(count == n) break;
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int m, f, r;
    
    while(true){
        cin >> m >> f >> r;
        char result;
        if(m == -1 && f == -1 && r == -1){
            break;
        }
        else if(m == -1 || f == -1 || m+f < 30) result = 'F';
        else if(m+f >= 80) result = 'A';
        else if(m+f >= 65 && m+f < 80) result = 'B';
        else if(m+f >= 50 && m+f < 65) result = 'C';
        else if(m+f >= 30 && m+f < 50){
            if(r >= 50){
                result = 'C';
            }
            else{
                result = 'D';
            }
        }
        cout << result << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3012
#include<stdio.h>

#define N 2000

int solve(int,int);

int a[N],n;

int main(){
  int q,b[N],m,i;
  
  scanf("%d",&n);
  for(i=0 ; i<n ; i++) scanf("%d",&a[i]);
  scanf("%d",&q);
  for(i=0 ; i<q ; i++){
    scanf("%d",&b[i]);
  }

  for(i=0 ; i<q ; i++){
  if(solve(0,b[i])==1) printf("yes\n");
  else if(solve(0,b[i])==0) printf("no\n");
  }
  return 0;
}



int solve(int i,int m){
  int res;
    if(m==0) return 1;

    if(i>=n) return 0;

    res = solve(i + 1,m) || solve(i + 1,m - a[i]);

    return res;
}
    
		       
  



Measured memory_bytes: 2052
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        s += s;
        String p = sc.nextLine();

        if(s.contains(p)) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }
}


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

const int N = 1e5 + 8;

int32_t main(){
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);  
    string s;
    cin >> s;

    s = '!' + s;

    int n = s.size();

    for(int i = 1 ; i <= n ; i++){
        if(i%2 == 1){
            if(s[i] == 'L'){
                cout << "No\n";
                return 0;
            }
        }else{
            if(s[i] == 'R' ){
                cout << "No\n";
                return 0;
            }   
        }
    }

    cout << "Yes\n";
  return 0;
}




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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 505;
int q[N * N];

int main(){
  fastIO;
  int n;
  cin >> n;
  vector<pii> f;
  int x;
  for(int i = 1; i <= n ; i ++ ){
    cin >> x;
    f.push_back(mp(x,i));
  }
  sort(f.begin(), f.end());
  int idx = 1;
  int cnt;
  for(int i = 1; i <= n * n; i ++ )
    q[i] = -1;
  for(auto p : f){
    cnt = p.se - 1;
    while(cnt > 0){
      if(q[idx] == -1){
        q[idx] = p.se;
        idx++;
        --cnt;
      }
      else{
        idx++;
      }
    }
    if(idx > p.fi){
      cout << "No\n";
      return 0;
    }
    else if(idx == p.fi){
      q[idx] = p.se;
      idx ++ ;
    }
    else{
      q[p.fi] = p.se;
    }
  }
  idx = n * n;
  reverse(f.begin(), f.end());
  for(auto p : f){
    cnt = n - p.se;
    while(cnt > 0){
      if(q[idx] == -1){
        q[idx] = p.se;
        idx--;
        --cnt;
      }
      else{
        idx--;
      }
    }
    if(idx < p.fi){
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  for(int i = 1; i <= n * n ; i ++ ){
    cout << q[i] << " ";
  }
  cout << "\n";
  return 0;
}

Measured memory_bytes: 2176
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }

int n,a[N],b[N],c[N]; LL s[N];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n); LL sa=0,sb=0;
	for (int i=1; i<=n; i++)
		sc(a[i]),sc(b[i]),c[++c[0]]=a[i],c[++c[0]]=b[i],sa+=a[i],sb+=b[i];
	sort (c+1,c+c[0]+1);
	for (int i=1; i<=n; i++)
		s[i]=s[i-1]+c[i];
	LL ans=min (sa,sb);
	for (int i=1; i<=n; i++)
	{
		int x=lower_bound (c+1,c+c[0]+1,a[i])-c,y=lower_bound (c+1,c+c[0]+1,b[i])-c;
		if (x> y) swap (x,y),swap (a[i],b[i]);
		if (x> n-2) chkmin (ans,s[n-2]+a[i]+b[i]);
		else if (y> n-1) chkmin (ans,s[n-1]+b[i]);
		else chkmin (ans,s[n]);
	}
	pr(ans);

    return 0;
}

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

int main() {
  long n,a,ans=0;
  cin >> n >> a;
  vector<long> x(n);
  vector<vector<long>> aaa(n,vector<long>(2500));
  for(long i=0;i<n;i++) cin >> x[i];
  for(long i=0;i<n;i++) {
    for(long j=i;j>0;j--) {
      for(long k=0;k<i*50;k++) {
        aaa[j][x[i]+k]+=aaa[j-1][k];
      }
    }
    aaa[0][x[i]-1]++;
  }
  for(long i=0;i<n;i++) ans+=aaa[i][a*(i+1)-1];
  cout << ans << endl;
}

Measured memory_bytes: 4284
#include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const int MOD=(1e9)+7;
const int mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  double d;
  cin >>n>>d;
  int ans=0;
  d*=d;
  for(int i=0;i<n;i++){
    double x,y;
    cin >>x>>y;
    if(x*x+y*y<=d) ans++;
  }
  cout <<ans<<'\n';
  return (0);
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define ll long long
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 2e5+5, M=2e4+5, oo=0x3f3f3f3f;

ll lcm, n, x, y, a[N], ans;

ll gcd(ll a, ll b)
{
    if(!b)
        return a;
    return gcd(b, a%b);
}

int main()
{
    cin >> n;
    if(n == 1)
    {
        cin >> n;
        cout << n;
        return 0;
    }
    for(int i=0; i<n; i++)
        cin >> a[i];
    lcm = a[0]/gcd(a[0], a[1])*a[1];
    for(int i=2; i<n; i++)
    {
        lcm = a[i]/gcd(a[i], lcm) * lcm;
    }
    for(int i=0; i<n; i++)
    {
        ans+=(lcm/a[i]);
    }
    cout << fixed << setprecision(8) << (1.0*lcm)/(1.00*ans);

    return 0 ;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T> T count_bit(T p){
  if(typeid(p)==typeid(int))return __builtin_popcount(p);
  else if(typeid(p)==typeid(long))return __builtin_popcountl(p);
  else return __builtin_popcountll(p);
}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  int N;
  in(N);
  vector<int> H(N);
  ins(H);
  int cnt=0,now=-1,ans=0;
  rep(i,N){
    if(now>=H[i]){
      cnt++;
    }else{
      chmax(ans,cnt);
      cnt=0;
    }
    now=H[i];
  }
  chmax(ans,cnt);
  out(ans);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}
 
template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}
 
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif
 
const int N = 100005;
 
int k, dp[N][15];
int tot[N];
 
int getDP(int i, int d) {
    if (d < 0 || d > 9) {
        return 0;
    }
    return dp[i][d];
}
 
int main() {
    
    scanf("%d", &k);
    
    for (int i = 1; i <= k; i++) {
        for (int d = 0; d < 10; d++) {
            dp[i][d] = min(2 * k, i == 1 ? 1 : getDP(i - 1, d - 1) + getDP(i - 1, d) + getDP(i - 1, d + 1));
            debug(i, d, dp[i][d]);
            tot[i] += dp[i][d];
        }
        tot[i] += tot[i - 1] - dp[i][0];
        tot[i] = min(tot[i], 2 * k);
        debug(i, tot[i]);
    }
    
    int start = 0;
    int sum = 0;
    for (int i = 1; i <= k; i++) {
        for (int d = 1; d < 10; d++) {
            sum += dp[i][d];
        }
        if (sum >= k) {
            start = i;
            break;
        }
    }
    debug(start);
    string number;
    int rem = k;
    dp[start][0] = tot[start - 1];
    int mini = 0;
    int maxi = 9;
    for (int i = start; i >= 1; i--) {
        for (int d = mini; d <= maxi; d++) {
            debug(i, d, dp[i][d], rem);
            if (dp[i][d] >= rem) {
                mini = max(0, d - 1);
                maxi = min(9, d + 1);
                if (number.empty() && d == 0) {
                    break;
                }
                number += (char)(d + '0');
                break;
            } else {
                rem -= dp[i][d];
            }
        }
    }
    
    if (number.empty()) number = "0";
    
    printf("%s\n", number.c_str());
    
    return 0;
}

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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    int n;
    cin>>n;
    n=n%10;
    if(n==2 || n==4 || n==7 || n==5 || n==9) cout<<"hon\n";
    if(n==1 || n==0 || n==6 || n==8) cout<<"pon\n";
    if(n==3) cout<<"bon\n";
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define mk(a,b) make_pair(a,b)
#define pii pair<int,int>
using namespace std;
inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=(X<<3)+(X<<1)+c-'0',c=getchar();
    return X*w;
}
typedef long long ll;
const int N = 1e5+5;
int a[N];
int main(){
    int n,m,k,x;
    n=read();
    for(int i=1;i<=n;i++){
        a[i]=read();
    }
    int tmp=a[1];
    for(int i=2;i<=n;i++){
        tmp=__gcd(tmp,a[i]);
    }
    cout<<tmp;
}

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

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

    int N,M;

    while(cin>>N>>M,N|M){
        vector<int> h(N),w(M),h_c,w_c;

        for(auto &t:h) cin>>t;
        for(auto &t:w) cin>>t;

        for(int i=0; i<h.size(); i++){
            int sum=0;
            for(int j=i;j<h.size();j++){
                sum += h[j];
                h_c.push_back(sum);
            }
        }

        for(int i=0; i<w.size(); i++){
            int sum=0;
            for(int j=i;j<w.size();j++){
                sum += w[j];
                w_c.push_back(sum);
            }
        }

        sort(h_c.begin(),h_c.end());
        sort(w_c.begin(),w_c.end());

        int sum=0;

        for(auto t:h_c){
            sum += distance(lower_bound(w_c.begin(),w_c.end(),t),upper_bound(w_c.begin(),w_c.end(),t));
        }

        cout << sum << endl;
    }
}

Measured memory_bytes: 19912
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	void run() {

		for (;;) {

			int n = Integer.valueOf(sc.nextLine());

			if (n == 0)

				break;

			int m = Integer.valueOf(sc.nextLine()) - 1;

			int g = Integer.valueOf(sc.nextLine()) - 1;

			int d = Integer.valueOf(sc.nextLine());

			int[][] map = new int[n][d + 1];

			boolean[][] nSwap = new boolean[n + 2][d + 1];

			for (int i = 0; i < n; i++)

				map[i][0] = i;

			for (int i = 1; i < d + 1; i++) {

				String buffer = sc.nextLine();

				for (int j = 0; j < n; j++)

					map[j][i] = map[j][i - 1];

				for (int j = 0; j < n - 1; j++) {

					if (buffer.charAt(j) == '1') {

						map[j][i] = map[j + 1][i - 1];

						map[j + 1][i] = map[j][i - 1];

						nSwap[j][i] = nSwap[j + 1][i] = nSwap[j + 2][i] = true;

					}

				}

			}

			if (map[g][d] == m) {

				System.out.println("0");

				continue;

			}

			boolean c = false;

			for (int i = 1; i < d + 1 && !c; i++) {

				for (int p = 0; p < n - 1 && !c; p++) {

					if (map[p][i] == map[g][d]) {

						if (map[p + 1][i] == m && !nSwap[p+1][i]) {

							System.out.println(i+" "+(p+1));

							c=true;

							break;

						}

						continue;

					}

					if (map[p][i] == m) {

						if (map[p + 1][i] == map[g][d] && !nSwap[p+1][i]) {

							System.out.println(i+" "+(p+1));

							c=true;

							break;

						}

						continue;

					}

				}

			}

			if (c)

				continue;

			System.out.println("1");

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        long[] A = cin.arrayLong();
        long[] B = cin.arrayLong();

        long sum = 0;
        for (int i = 0; i < N; i++)
        {
            long tmp1 = Math.Min(A[i], B[i]);
            A[i] -= tmp1;
            B[i] -= tmp1;
            sum += tmp1;

            long tmp2 = Math.Min(A[i + 1], B[i]);
            A[i + 1] -= tmp2;
            B[i] -= tmp2;
            sum += tmp2;
        }

        Console.WriteLine(sum);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



Measured memory_bytes: 31196
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N, T;
    cin >> N >> T;
    
    vector<int> t;
    for( int i = 0; i < N; ++i ){
        int tmp;
        cin >> tmp;
        t.push_back(tmp);
    }
    
    
    int ans = T;
    for( int i = 0; i < N-1; ++i ){
        ans += T;
        int loss = t[i+1] - (t[i]+T);
        if( loss < 0 ) ans += loss;
    }
    
    
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 1400
def main():
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    T = [int(input()) for i in range(D)]
    contest_last_opened = [0]*26  # コンテストiを前回開催した日
    score = 0
    for d, t in enumerate(T, start=1):
        get_score = S[d-1][t-1]
        score += get_score
        contest_last_opened[t-1] = d
        loss_score = 0
        for i in range(26):
            ld = contest_last_opened[i]
            loss_score += C[i]*(d-ld)
        score -= loss_score
        print(score)


if __name__ == '__main__':
    main()


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


int findArea(int n, int m) {
	return (n*m);
}

int main()
{
	int A;
	int B;
	int C;
	int D;
	int firstArea;
	int secondArea;

	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;

	firstArea = findArea(A,B);
	secondArea = findArea(C, D);

	if (firstArea > secondArea) {
		cout << firstArea << endl;
	}
	else if (firstArea < secondArea) {
		cout << secondArea << endl;
	}
	else {
		cout << secondArea << endl;
	}

}

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

if 400 <= X <= 599:
    print("8")
if 600 <= X <= 799:
    print("7")
if 800 <= X <= 999:
    print("6")
if 1000 <= X <= 1199:
    print("5")
if 1200 <= X <= 1399:
    print("4")
if 1400 <= X <= 1599:
    print("3")
if 1600 <= X <= 1799:
    print("2")
if 1800 <= X <= 1999:
    print("1")

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(){

  map <int, int> cnt;
  int ans = 0;
  for (int i = 0; i < 3; i++){
    int a; cin >> a;
    if (cnt[a] == 0){
      ans++;
    }
    cnt[a]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def c(s, n):
    s = list(s)
    for i in range(len(s)):
        if s[i] in alphabets:
            s[i] = alphabets[(alphabets.index(s[i]) + n) % 26]
    return ''.join(s)
def is_right(s):
    words = '.'.join(s.split(' ')).split('.')
    return 'the' in words or 'this' in words or 'that' in words
alphabets = 'abcdefghijklmnopqrstuvwxyz'
while True:
    try:
        line = input()
        if line == '*':
            break
    except:
        break
    for i in range(26):
        if is_right(c(line, i)):
            print(c(line, i))
            break

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

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

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

tuple<ll,int> term(const string& s,int i)
{
	ll x=s[i++]-'0';
	while(i<s.size() && s[i]=='*'){
		i++;
		x*=s[i++]-'0';
	}
	return mt(x,i);
}
ll expr(const string& s)
{
	ll x; int i;
	tie(x,i)=term(s,0);
	while(i<s.size() && s[i]=='+'){
		i++;
		ll y; tie(y,i)=term(s,i);
		x+=y;
	}
	return x;
}

ll calc(const string& s)
{
	stack<ll> st;
	char op;
	for(int i=0;i<s.size();i++){
		if(isdigit(s[i])){
			st.push(s[i]-'0');
			if(st.size()==2){
				ll b=st.top(); st.pop();
				ll a=st.top(); st.pop();
				st.push(op=='+'?a+b:a*b);
			}
		}
		else
			op=s[i];
	}
	return st.top();
}

int main()
{
	for(string s;cin>>s && s!="#";){
		ll ans; cin>>ans;
		
		ll infix=expr(s);
		ll left=calc(s);
		
		if(infix==ans && left==ans)
			cout<<'U'<<endl;
		else if(infix==ans)
			cout<<'M'<<endl;
		else if(left==ans)
			cout<<'L'<<endl;
		else
			cout<<'I'<<endl;
	}
}

Measured memory_bytes: 1212
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(0,n):
    ans+=b[i]
for i in range(0,n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    vector<int>r(n,1e8);
    REP(i,m){
        int a,b;cin>>a>>b;a--;b--;
        r[a]=min(r[a],b);
    }
    int curr=1e8,ans=0;
    REP(i,n){
        curr=min(r[i],curr);
        if(i==curr){ans++;curr=r[i];}
    }cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    if (A == 0) {
        cout << 0 << endl;
        return 0;
    }
    long long last = N % (A + B);
    long long ans = (N / (A + B)) * A;
    if (last < A) {
        ans += last;
    }
    else {
        ans += A;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#define maxn 200009
using namespace std;
int n;
int C[maxn], V[maxn], D[maxn];
bool cmp(int x, int y){
	return x > y;
}

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> V[i];
	for(int i = 1; i <= n; i++)
		cin >> C[i];
		
	for(int i = 1; i <= n; i++){
		D[i] = V[i] - C[i];
	}
	
	sort(D + 1, D + 1 + n, cmp);
	
	int sum = 0;
	for(int i =1 ; i <= n; i++){
		if(D[i] > 0)
			sum += D[i];
		else
			break;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using p = pair<int, int>;

int n, m;
vector<vector<p>> v;
vector<p> mom[2];
vector<int> ans;

void solve();
bool ch(int x, bool y, int z);

int main() {
  while(1) {
    cin >> n;
    if(n == 0) break;
    cin >> m;
    for(int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      mom[0].push_back({x, y});
      mom[1].push_back({x, y});
    }
    reverse(mom[1].begin(), mom[1].end());
    for(int i = 0; i < n; ++i) {
      vector<p> dum;
      cin >> m;
      for(int j = 0; j < m; ++j) {
        int x, y;
        cin >> x >> y;
        dum.push_back({x, y});
      }
      v.push_back(dum);
    }
    solve();
    for(int i = 0; i < ans.size(); ++i)
      cout << ans[i] + 1 << endl;
    cout << "+++++" << endl;
    mom[0].erase(mom[0].begin(), mom[0].end());
    v.erase(v.begin(), v.end());
    ans.erase(ans.begin(), ans.end());
  }
  return 0;
}
void solve() {
  m = mom[0].size();
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < 2; ++j)
      if(ch(i, 0, j) || ch(i, 1, j)) {
        ans.push_back(i);
        break;
      }
}

bool ch(int x, bool y, int z) {
  bool nowans = 0;
  if(z == 0) z = -1;
  if(v[x].size() != m) return 0;
  for(int i = 1; i < m; ++i) {
    p nv, nm;
    nv = {(v[x][i].fi - v[x][i - 1].fi) * z,
          (v[x][i].se - v[x][i - 1].se) * z};
    nm = {mom[y][i].fi - mom[y][i - 1].fi,
          mom[y][i].se - mom[y][i - 1].se};
    if(nv != nm) break;
    if(i == m - 1) nowans = 1;
  }

  for(int i = 1; i < m; ++i) {
    p nv, nm;
    nv = {(v[x][i].se - v[x][i - 1].se) * z,
          -(v[x][i].fi - v[x][i - 1].fi) * z};
    nm = {mom[y][i].fi - mom[y][i - 1].fi,
          mom[y][i].se - mom[y][i - 1].se};
    if(nv != nm) break;
    if(i == m - 1) nowans = -1;
  }
  return nowans;
}


Measured memory_bytes: 3112
n = int(input())
dp = [10**6] * (n+1)
dp[0] = 0
for i in range(1,n+1):
  c = 1
  d = 1
  dp[i] = min(dp[i],dp[i-1]+1)
  while True:
    if i - 6**c >= 0:
      dp[i] = min(dp[i],dp[i-6**c]+1)
    else:
      break
    c += 1
  while True:
    if i - 9**d >= 0:
      dp[i] = min(dp[i],dp[i-9**d]+1)
    else:
      break
    d += 1
print(dp[n])

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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	cout<<(n>=30?"Yes":"No");
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	ll n,m,d;
	cin >>n >> m >>d;
	/*
	ll w=1LL;
	
	ll pj=n, su=m, as=0;
	rep(i,(int)pow(pj, su)){
		vector<int> vi(su);
		for(int j=0, wki=i; j<su; j++, wki/=pj){
			vi[su-1-j] = wki%pj;
		}
		int c=0;
		rep(j, m-1) if(abs(vi[j] - vi[j+1])==d) c++, as++;
		//for(auto x :vi) printf("%d ",x); printf(" ::%d\n", c);
	}
	rep(i,m) w*=n;
	
	dbg(as, w, double(as)/w);
	*/
	ll sa = n -d;
	double z = sa * 2.0 / (n * n);
	double ans =z * (m-1);
	if(d==0) ans /=2.0;
	printf("%.14f\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s) {
		ll a=0,z=INF;
		REP(i, s.size()) if(s[i]=='A') {a=i;break;}
		REPR(i, s.size()) if(s[i]=='Z') {z=i;break;}
		ll ans=z-a+1;
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 720
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        n %= 1000;
        if(n != 0)
            n = 1000 - n;
        WriteLine(n);
        ReadLine();
    }
}


Measured memory_bytes: 17620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int dir(int x1, int y1, int x2, int y2){
    return abs(x1-x2)+abs(y1-y2);
}

int main(){
    int n;
    cin>>n;
    
    bool f = true;
    int t = 0;
    int x = 0, y=0;
    rep(i,n){
        int a,b,c;
        cin>>a>>b>>c;
        
        int d = dir(x,y,b,c);
        if(d<=(a-t) && (a-t-d)%2==0)continue;
        f = false;
    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

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

    int mi=10000,ma=0;
    for(int i=0;i<N;i++){
        int tmp;
        cin>>tmp;
        mi=min(tmp,mi);
        ma=max(tmp,ma);
    }

    cout<<ma-mi<<endl;

    return 0;
}

Measured memory_bytes: 256
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------
from math import gcd, ceil
 
def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi
 
 
def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans
 
def lcm(a, b): return a * b // gcd(a, b)
 
 
def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

s = input()
t = input()

S = len(s)
T = len(t)
ans = int(1e9)
for i in range(S - T + 1):
    mn = T
    for j, k in enumerate(range(T)):
        if s[i+k] == t[j]:
            mn -= 1
    ans = min(mn, ans)


print(ans)


Measured memory_bytes: 73292
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

/*---------------------------------------------------*/

bool binary_search(int data[],int size,int target){
  int l=0,r=size;
  while(r-l>0){
    int mid=(l+r)/2;
    if(data[mid]==target)return true;
    else if(target<data[mid])r=mid;
    else l=mid+1;
			 
  }
  return false;
}

int main(){
  int n,q,s[100005],t;
  cin>>n;
  rep(i,n)cin>>s[i];
  sort(s,s+n);
  cin>>q;
  int ans=0;
  rep(i,q){
    cin>>t;
    if(binary_search(s,n,t))ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3420
//“ In order to be irreplaceable, one must always be different”
#include <bits/stdc++.h>
using namespace std;
# define ll long long
#define endl "\n"
# define pi 3.14159265359
#define mod 1000000007
# define str string
# define vll vector<ll>
# define vstr vector<str>
# define vchar vector<char>
# define pb push_back
# define mll map<ll,ll>
#define mchar map<char, ll>
# define mstr map<str,ll>
# define vp vector< pair<ll,ll> >
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
# define r(x,y) for(int x=y;x>=0;x--)
# define loop(x,y,z) for(int x=y;x<z;x++)
ll power(ll a , ll b){ll res=1;for(ll i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll gcd(ll a, ll b){
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}
void print(vll a){
    for(int i=0;i<a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
vll inp(int n){
    vll a;
    ll x;
    f(i,n){
        cin>>x;
        a.pb(x);
    }
    return a;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    str s;
    cin>>s;
    str s1="ABC";
    if(s==s1){
        cout<<"ARC";
    }
    else{
        cout<<"ABC";
    }
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

int finish(int isCan) {
	if(isCan) puts("Yes");
	else puts("No");
	return 0;
}
const int MAX_N = 5e2 + 10;

int H, W, h, w;
int Nr[MAX_N][MAX_N];

int main() {
	cin >> H >> W >> h >> w;
	if(H%h == 0 && W%w == 0) return finish(0);

	bool flag = false;
	if(H%h == 0) {
		flag = true;
		swap(H, W);
		swap(h, w);
	}

	int BIG = 10000;
	finish(1);
	for(int j=0; j<W; j++) {
		for(int k=0; k*h<H; k++) {
			for(int i=0; k*h+i<H && i<h; i++) {
				if(i+1 == h) Nr[k*h+i][j] = -h-BIG;
				else if(i == 0) Nr[k*h+i][j] = 1+BIG;
				else Nr[k*h+i][j] = 1;
			}
		}
	}
	if(flag) {
		for(int i=0; i<W; i++) {
			for(int j=0; j<H; j++) printf("%d ", Nr[j][i]);
			puts("");
		}
	} else {
		for(int i=0; i<H; i++) {
			for(int j=0; j<W; j++) printf("%d ", Nr[i][j]);
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int a,b,c,d,e,ans = 0;
  cin >> a >> b >> c >> d >> e;
  if((a-1)%10 > (b-1)%10) swap(a,b);
  if((c-1)%10 > (d-1)%10) swap(c,d);
  if((a-1)%10 > (c-1)%10) swap(a,c);
  if((a-1)%10 > (e-1)%10) swap(a,e);
  ans += ((e+9)/10)*10;
  ans += ((d+9)/10)*10;
  ans += ((c+9)/10)*10;
  ans += ((b+9)/10)*10;
  ans += a;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// AOJ 0539: Pizza
// 2017.9.1 bal4u@uu
// 2018.1.2

#include <stdio.h>
#include <stdlib.h>

#define getchar_unlocked()  getchar()

int N;
int d[100002];
int k[10002];

int cmp(int *a, int *b) { return *a - *b; }

int in()
{
	int n, c;

	while ((c = getchar_unlocked()) < '0');
	n = 0;
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int bsrch(int l, int x)
{
	int m, r = N;
    while (l < r) {
        m = (l + r) >> 1;
        if (d[m] < x) l = m + 1; else r = m;
    }
	return l;
}

int main()
{
	int D, M, i, j, t, ans;

	while (D = in()) {
		N = in();
		M = in();

		d[0] = 0; for (i = 1; i < N; i++) d[i] = in();
		qsort(d, N, sizeof(int), cmp);
		d[N] = D;

		for (i = 0; i < M; i++) k[i] = in();
		qsort(k, M, sizeof(int), cmp);
		k[M] = -1;

		ans = 0, j = 0;
		i = 0; while (!k[i]) i++; 
		while (i < M) {
			if (d[j] < k[i]) j = bsrch(j, k[i]);
			if (k[i] != d[j]) {
				t = k[i]-d[j-1];
				if (d[j]-k[i] < t) t= d[j]-k[i];
				ans += t;
			}
			i++;
		}
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2460
// Ho-kago Tea Time

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

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

const int MAXN = (int) 2e5;

int X0, X1, Y0, Y1;

struct point
{
	int x, y;

	inline bool operator < (const point &rhs) const { return this->x < rhs.x; }

	point() { }
	point(int _x, int _y): x(_x), y(_y) { }
};

vector<point> P;

inline void input()
{
	X0 = read<int>(), Y0 = read<int>(), X1 = read<int>(), Y1 = read<int>();
	if(X0 > X1) swap(X0, X1), swap(Y0, Y1);
	for(int n = read<int>(); n--; )
	{
		int x = read<int>(), y = read<int>();
		if(X0 <= x && x <= X1 && min(Y0, Y1) <= y && y <= max(Y0, Y1)) P.emplace_back(x, y);
	}
	sort(ALL(P));
}

inline int get_LIS()
{
	static int seq[MAXN + 5], len;

	len = 0;
	for(auto i : P)
	{
		int p = lower_bound(seq + 1, seq + len + 1, i.y) - seq;
		seq[p] = i.y;
		chkmax(len, p);
	}
	return len;
}

inline void solve()
{
	if(Y0 > Y1) for(int i = 0; i < SZ(P); ++i) P[i].y *= -1;

	const double PI = acos(-1), delta = 5 * PI - 20;
	int m = get_LIS();

	double ans = (abs(X0 - X1) + abs(Y0 - Y1)) * 100.0;
	ans += m * delta;
	if(m == abs(X0 - X1) + 1 || m == abs(Y0 - Y1) + 1) ans += 5 * PI;
	printf("%.11lf\n", ans);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 2672