akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int check(int src[],int src_max,int dest[],int dest_max){
	int i,j;
	for(i=0;i<dest_max;i++){
		for(j=0;j<src_max;j++){
			if(src[j]==dest[i]){
				break;
			}
		}
		if(j==src_max){
			return 0;
		}
	}
	return 1;
}

int main(void){
	int n,m[100],p[100][100],k,l[100],i,j,bad;
	while(scanf("%d",&n)!=0 && n!=0){
		for(i=0;i<n;i++){
			scanf("%d",&m[i]);
			for(j=0;j<m[i];j++){
				scanf("%d",&p[i][j]);
			}
		}
		scanf("%d",&k);
		for(i=0;i<k;i++){
			scanf("%d",&l[i]);
		}
		bad=0;
		for(i=0;i<n;i++){
			if(check(p[i],m[i],l,k)==1){
				if(bad==0){
					bad=i+1;
				}else{
					bad=-1;
				}
			}
		}
		if(bad==0){
			bad=-1;
		}
		printf("%d\n",bad);
	}
	return 0;
}		
				
				

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n = int(input())
edge = [[] for _ in [0]*n]
for i in range(~-n):
    a, b = map(int, input().split())
    a -= 1;b -= 1
    edge[a] += [[b, i]]
ans = [0] * ~-n

def dfs(now, color):
    count = 1
    for to, i in edge[now]:
        # 親の色と同じとき
        if count == color:
            count += 1
        ans[i] = count
        dfs(to, count)
        count += 1

# 開始根は0番目に
dfs(0, 0)

print(max(ans))
for p in ans:
    print(p)

Measured memory_bytes: 75660
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <math.h>
using namespace std;

/* define const */
int LW[3000000] = {}; 
int RW[3000000] = {}; 
int LE[3000000] = {}; 
int RE[3000000] = {}; 

/* end up defineing const */

int main()
{
  int N;
  string S;
  cin >> N >> S;
  int min = 99999999;
  int west = 0;
  int east = 0;
  for (int i = 0; i < N; i++) {
    if (i) {
      LW[i] = LW[i-1];
      //      LE[i] = LE[i-1];
    }
    if (S[i] == 'W') LW[i]++;
    //    if (S[i] == 'E') LE[i]++;
  }
  for (int i = N-1; i >= 0; i--) {
    if (i != N-1) {
      //      RW[i] = RW[i+1];
      RE[i] = RE[i+1];
    }
    //    if (S[i] == 'W') RW[i]++;
    if (S[i] == 'E') RE[i]++;
  }
  for (int i = 0; i < N; i++) {
    int tmp = 0;
    if (S[i] == 'W') {
      tmp = RE[i] + LW[i] -1;
    }
    else {
      tmp = RE[i] + LW[i] -1;
    }
    if (tmp < min) min = tmp;
  }
  cout << min << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);  
  for(int i=0; i<N; ++i){
    cin >> A[i];
  }
  
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  cout << A[0]-A[N-1] << endl;
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt(),m=nxt();
    vector <int> count;
    count.resize(n+1,0);
    while(m--)
    {
        int u=nxt(),v=nxt();
        count[u]++;
        count[v]++;

    }
    for(int i=1;i<=n;i++)
        cout<<count[i]<<endl;
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

#define PI 3.141592653589793

using namespace std;
int main(int argc, char* argv[])
{
	//ABC168 C
	int a, b, h, m;
	double ax, bx,ay,by;
	double ka, kb;	// 角度
	double ans;
	// A B H M
	//cin >> x >> y >> a >> b >> c;
	// A 時針の長さ B 分針の長さ H時M分 
	// cos x sin y

	cin >> a >> b >> h >> m;

	ka = (360.0 / 60.0 * m) * PI / 180.0;
	kb = ((360.0 / 12.0 * h) + (0.5 * m)) * PI / 180.0;

	ax = a * sin(ka);
	bx = b * sin(kb);
	ay = a * cos(ka);
	by = b * cos(kb);

	ans = sqrt(pow(bx - ax,2.0) + pow(by - ay,2.0));

	printf("%.16f", ans);

	return 0;
}


Measured memory_bytes: 4068
n = int(input())
ls = list(map(int, input().split()))
l0 = [n for n in ls if n % 2 == 0]
n2 = len([n for n in l0 if n % 4 != 0])
n4 = len([n for n in l0 if n % 4 == 0])
n = n - n2 if n2 % 2 == 0 else n - n2 + 1
if n <= n4 * 2 + 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using pll = pair<long long,long long>;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }


bool isodd(const pll &p) { return (p.first + p.second) & 1; }
bool solve(vector<long long> &a) {
    int N = (int)a.size();
    sort(a.begin(), a.end(), greater<long long>());

    long long x = 0, y = a[0];
    vector<pll> ps;
    for (int i = 0; i < N; ++i) {
        if (a[i] != y) ps.push_back(pll(i-1, y)), y = a[i];
    }
    ps.push_back(pll(N-1, a[N-1]));

    //COUT(ps);
    if (ps.size() == 1) return isodd(ps[0]);
    for (auto p : ps) if (p.first == p.second) return false;
    
    for (int i = 0; i + 1 < ps.size(); ++i) {
        if (ps[i].first < ps[i].second && ps[i+1].first > ps[i+1].second) {
            if (ps[i].first < ps[i+1].second) return isodd(ps[i+1]);
            else if (ps[i].first > ps[i+1].second) return isodd(ps[i]);
            else return isodd(ps[i]) || isodd(ps[i+1]);
        }
    }
    if (ps[0].first > ps[0].second) return isodd(ps[0]);
    else return isodd(ps.back());
}

int main() {
    int N;
    while (cin >> N) {
        vector<long long> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i], --a[i];

        if (solve(a)) cout << "First" << endl;
        else cout << "Second" << endl;
    }
}   


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


int main(){
    int A,B;
    cin >> A >> B;
    if(A<10&&B<10) cout << A*B << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#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 all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    ll N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> P(N, -Q+K);
    rep(i, Q) { 
        ll A;
        cin >> A;
        A--;
        P[A]++;
    }
    rep(i, N) {
        if(P[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1408
def z_algo(s):
    """文字列sについて、各iについて「SとS[i:|S|]の最長共通接頭辞の長さ」
    を記録した配列をO(|S|)で構築する
    """
    res = [0] * len(s)
    res[0] = len(s)
    i, j = 1, 0
    while i < len(s):
        while i + j < len(s) and s[j] == s[i + j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < len(s) and k + res[k] < j:
            res[i + k] = res[k]
            k += 1
        i, j = i + k, j - k
    return res


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

diff_a = []
diff_b = []
for i in range(n):
    diff_a.append(a[(i + 1) % n] ^ a[i % n])
    diff_b.append(b[(i + 1) % n] ^ b[i % n])

diff_a2b = diff_b + diff_a + diff_a
t = z_algo(diff_a2b)

for i in range(n, 2 * n):
    if t[i] >= n:
        print(i - n, a[i - n] ^ b[0] )


Measured memory_bytes: 128080
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
using namespace std;

#define ll long long
//#define int long long
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

#define dump(x)  cerr << #x << " = " << (x) << endl; 
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 


typedef pair<int, int> P;
struct Point{
	int x, y;
};
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = {1,0,-1,0};



int main(){

	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	sort(a, a + 3, greater<int>());

	cout << a[0]*10+a[1]+a[2] << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int main() {
	int h;
	cin >> h;
	int w;
	cin >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
 
	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }

    for (int i = 0; i < h; i++) {
        if (row[i]) {
            for (int j = 0; j < w; j++) {
                if (col[j]) {
                    cout << a[i][j];
                }
            }
            cout << endl;   
        }
    }
}

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

#include <vector>
#include <algorithm>
/********
*	????????¢?´¢ Binary Search
*********/ 

int main(void)
{
	int n;
	cin >> n;	
	vector<int> strS;
	strS.resize(n);
	
	for(int i = 0; i<n; i++){
		cin >> strS[i];
	}
	
	int q;
	cin >> q;
	vector<int> strT;
	strT.resize(q);
	
	for(int i = 0; i<q; i++){
		cin >> strT[i];
	}
	
	int count = 0 ;	
	for(int j=0; j < q; j++ ){
		bool result = binary_search(strS.begin(), strS.end(), strT[j]);
		if(result)
			count++;
	}

/*	int left  = 0;	//strS[0];
	int right = n;	//strS[(n-1)];
	int middle= (right + left)/2;
	

	for(int j = 0; j<q ; j++){
		if( strS[(middle)] < middle ){
			left = middle;
				if(strT[j] == strS[i]){
					count++;
					break;
				}
			}
		} else if( strS[middle] > middle){
			for(int i =(n/2); i == 0; i--){
				if(strT[j] == strS[i]){
					count++;
					break;
				}
			}
		}
	}
*/
	cout << count << endl;
	
    return 0;
}

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

int N;
ll all;
int A[101010];
// [1,N]
int BIT[202020], sum[101010];

int SUM(int i){
  i+=N+1;
  int s=0;
  while(i>0){
    s+=BIT[i];
    i-=i&-i;
  }
  return s;
}

void ADD(int i){
  i+=N+1;
  while(i<=2*N+2){
    BIT[i]++;
    i+=i&-i;
  }
}

bool f(int X){
  // 中央値をX以下にできるか
  rep(i,N){
    sum[i+1]=sum[i]+(A[i]<=X?1:-1);
  }
  rep(i,202020) BIT[i]=0;

  ADD(0);
  ll res=0;
  for(int i=1;i<=N;i++){
    res+=SUM(sum[i]-1);
    ADD(sum[i]);
  }
  return (res>=all/2+1);
}

int main(){
  cin>>N;
  all=1LL*N*(N+1)/2;
  rep(i,N) cin>>A[i];

  int l=1,r=1e9,ans=0;
  while(l<=r){
    int mid=(l+r)/2;
    if(f(mid)) ans=mid,r=mid-1;
    else l=mid+1;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,b,i,j,v=0,c[100010],ans=0;
    cin >> n >> a >> b;
    for(i=1;i<=n;i++)
    {
        int z=i;
       while(1)
       {
           v+=z%10;
           z=z/10;
           if(z<1)
           {
               break;
           }
       }
        if(v>=a && v<=b)
        {
            ans+=i;
        }
        v=0;       
    }
    cout << ans << endl;

    return 0;

}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

bool ok(vector<int> a, vector<int> b){
    int n = a.size();
    rep(i, n){
        if(a[i] != b[i]) return false;
    }
    return true;
}
int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b = a;
    sort(b.begin(), b.end());

    if(ok(a, b)){
        YES();
        return 0;
    }

    rep(i, n){
        for(int j = i+1; j < n; ++j){
            vector<int> tmp = a;
            swap(tmp[i], tmp[j]);
            if(ok(tmp, b)) {
                YES();
                return 0;
            }
        }
    }
    NO();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	int N, H, W; cin >> N >> H >> W;
	cout << (N - W + 1)*(N - H + 1) << endl;


	



	
	return 0;
}

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

int main()
{
    int n,k,q;
    cin >> n >> k >> q;
    int a[n] = {0};
    int ai;
    for(int i=0; i<q; i++){
        cin >> ai;
        a[ai-1] += 1;
    }
    for(int i=0; i<n; i++){
        if(k-q+a[i]>0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define MAX_N 100005
#define pb push_back
using namespace std;
struct node{
	int y,cost;
	bool operator < (node d) const{
		return cost<d.cost;
	}
}drg[MAX_N];
int n,m,dst[MAX_N];
bool ans;
vector<node> net[MAX_N];
void dfs(int x){
	int sz=net[x].size();
	node y;
	while(sz--){
		y=net[x][sz];
		if(dst[y.y]){
			if(dst[x]+y.cost!=dst[y.y])	ans=true;
			continue;
		}
		dst[y.y]=dst[x]+y.cost;
		dfs(y.y);
	}
}
int main(){
	int i,x;
	node p;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)	drg[i].y=i;
	for(i=0;i<m;i++){
		scanf("%d %d %d",&x,&p.y,&p.cost);
		net[x].pb(p);
		drg[p.y].cost++;
	}
	sort(drg+1,drg+n+1);
	for(i=1;i<=n;i++){
		if(dst[drg[i].y])	continue;
		dst[drg[i].y]=1;
		dfs(drg[i].y);
	}
	printf("%s\n",(ans)?"No":"Yes");
	return 0;
}

Measured memory_bytes: 11520
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		for(int i = 0; i < n; i++){
			int pm,pe,pj;
			cin>>pm>>pe>>pj;
			if(pm==100||pe==100||pj==100||((pm+pe)/2)>=90||((pm+pe+pj)/3)>=80)
				cout<<"A"<<endl;
			else if(((pm+pe+pj)/3)>=70||((((pm+pe+pj)/3)>=50)&&(pm>=80||pe>=80)))
				cout<<"B"<<endl;
			else
				cout<<"C"<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;



int main(){
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int>v(2*n);
  rep(i, 2*n) v[i] = i+1;
  int k;
  rep(i, m){
    scanf("%d", &k);
    vector<int>tmp;
    if(k){
      tmp.insert(tmp.begin(), v.begin(), v.begin()+k);
      v.erase(v.begin(), v.begin()+k);
      v.insert(v.end(), tmp.begin(), tmp.end());
    }else{
      tmp.insert(tmp.begin(), v.begin()+n, v.end());
      v.erase(v.begin()+n, v.end());
      rep(i, n) v.insert(v.begin()+2*i+1, tmp[i]);
    }
  }

  rep(i, v.size()) printf("%d\n", v[i]);
  return 0;
}

Measured memory_bytes: 1216
import sys

input = sys.stdin.readline
H, W, M = map(int, input().split())
h_count = [0]*H
w_count = [0]*W
HW = [tuple(map(int, input().split())) for _ in range(M)]
for h, w in HW:
    h_count[h-1] += 1
    w_count[w-1] += 1
h_max, w_max = 0, 0
hs, ws = [], []
for i in range(H):
    if h_max < h_count[i]:
        h_max = h_count[i]
        hs = [i]
    elif h_max == h_count[i]:
        hs.append(i)
for i in range(W):
    if w_max < w_count[i]:
        w_max = w_count[i]
        ws = [i]
    elif w_max == w_count[i]:
        ws.append(i)

HW = set(HW)
for h in hs:
    for w in ws:
        if (h+1, w+1) not in HW:
            print(h_max+w_max)
            sys.exit()
print(h_max+w_max-1)


Measured memory_bytes: 162844
/*input
2
01
10
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<int> edge[205];
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, n) {
            if (s[j] == '1') edge[i].push_back(j);
        }
    }
    int ans = -2;
    rep(s, n){
        vector<int> d(n, INF);
        d[s] = 0;
        priority_queue<pii, vector<pii>, greater<pii>> que;
        que.push(pii(0, s));
        bool is_ok = true;
        while (!que.empty()) {
            pii p = que.top(); que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for(int i = 0; i < edge[v].size(); i++) {
                int e = edge[v][i];
                if (d[e] == d[v]) {
                    is_ok = false;
                    break;
                }
                if (d[e] > d[v]+1) {
                    d[e] = d[v]+1;
                    que.push(pii(d[e], e));
                }
            }
        }
        if (is_ok) {
            int mx = 0;
            for (int x: d) mx = max(mx, x);
            ans = max(mx, ans);
        }
        is_ok = true;
    }
    cout << ans+1 << endl;
}

Measured memory_bytes: 512
#include <atcoder/scc>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  atcoder::scc_graph G(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    G.add_edge(a, b);
  }
  vector<vector<int>> answer = G.scc();
  int K = answer.size();
  cout << K << endl;
  rep(i, K) {
    cout << answer[i].size();
    for (auto n : answer[i]) {
      cout << " " << n;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 40104
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N, X[505];

pair<int, int> req[505];
int reqa[500*500+5];
int res[500*500+5];
int counts[505];
queue<int> que;

int main() {
    cin >> N; for (int j = 0; j < N; ++j) { cin >> X[j]; --X[j]; }
    fill(reqa, reqa+N*N, 0);
    fill(res, res+N*N, 0);
    fill(counts, counts+N+1, 0);
    for (int j = 0; j < N; ++j) {
        res[X[j]] = reqa[X[j]] = j+1;
        req[j] = make_pair(X[j], j+1);
    }
    sort(req, req+N);

    bool ok = true;
    int idx = 0;
    if (req[0].second == 1) ++idx;
    for (int j = 0; ok && j < N*N; ++j) {
        if (reqa[j] > 0) {
            int num = reqa[j];
            if (++counts[num] < num) {
                ok = false;
            } else {
                for (int n = N-num; n > 0; --n) que.push(num);
            }
        } else if (idx < N) {
            int num = req[idx].second;
            if (counts[num] < num-1) {
                ++counts[num];
                res[j] = num;
            }
            if (counts[num] == num-1) {
                ++idx;
                if (idx < N && req[idx].second == 1) ++idx;
            }
        } else if (que.empty()) {
            ok = false;
        } else {
            res[j] = que.front(); que.pop();
        }
    }

    if (!ok) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        for (int j = 0; j < N*N; ++j) {
            if (j > 0) cout << " ";
            cout << res[j];
        }
        cout << endl;
    }

    return 0;
}


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

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

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

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


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

LL dp[10010];

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

  int M, N;
  cin >> M >> N;
  VL ps(M);
  REP(i,M) cin >> ps[i];
  RSORT(ps);
  VL acc(M+1);
  REP(i,M) acc[i+1] = acc[i] + ps[i];
  
  fill((LL*)dp, dp+10010, INF);
  dp[0] = 0;
  REP(i,N){
	PLL x;
	cin >> x;
	for(int j=M;j>=0;--j){
	  mini(dp[j], dp[max(0ll,j-x.FF)] + x.SS);
	}
  }

  LL ans = 0;
  REP(i,M+1) maxi(ans, acc[i] - dp[i]);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,st,en) for(i=st;i<=en;i++)
#define repv(i,en,st) for(i=en;i>=st;i--)
#define fout cout<<fixed<<setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<int,int> pii;
const int N = 100010;
ll mod = 1e9+7;
ll fmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}

ll dp[N];
ll w[N];
int v[N];
ll INF = 1e17+3;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j,m;
    ll W;
    cin>>n>>W;
    rep(i,1,n)cin>>w[i]>>v[i];
    int num = 1e5;
    rep(i,1,num)dp[i]=INF;
    dp[0]=0;
    int ans = 0;
    rep(i,1,n)
    {
       for(int j=num;j>=v[i];j--)
       {
           dp[j]= min(dp[j],dp[j-v[i]]+w[i]);
           if(dp[j]<=W)ans = max(ans,j);
       }
           
    }
    cout<<ans<<"\n";



            

    
    return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 1;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define MAX 300000
//.....................
ull mod = (int)1e9 + 7;

signed main(void)
{
	int N, K;
	cin >> N >> K;
	rep(i, K) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (N - a - 1 < a) a = N - a - 1;
		if (N - b - 1 < b) b = N - b - 1;
		//dump(a);
		//dump(b);
		int tmp = min(a, b) % 3;
		cout << tmp % 3 + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3112
import java.io.*;
import java.util.*;

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        long from = 2, to = 2;
        for (int i = n - 1; i >= 0; i--) {
            long cur = a[i];
            long minOne = from / cur * cur;
            if (minOne < from) {
                minOne += cur;
            }
            long maxOne = to / cur * cur;
            if (minOne > maxOne) {
                out.println(-1);
                return;
            }
            from = minOne;
            to = maxOne + (cur - 1);
        }
        out.println(from + " " + to);
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}

Measured memory_bytes: 42100
var
	X,i,ans,now:int64;
begin
	read(X);
	i:=1;
	ans:=X+1;
	while i*i<=X do begin
		if X mod i=0 then begin
			now:=i-1+(X div i)-1;
			if ans>now then ans:=now;
		end;
		inc(i);
	end;
	writeln(ans);
end.


Measured memory_bytes: 128
#include<iostream>
#define ll long long
#define P pari<int,int>
#define mk make_pair
const int N = 1e5+10;
using namespace std;
ll a[N],b[N];
int main()
{
    int n;
    cin >> n;
    for(int i=0;i<=n;i++)
    {
        cin >> a[i];
    }
    if(n==0)
    {
        if(a[0] == 1)
        {
            puts("1");
        }
        else
        {
            puts("-1");

        }
        return 0;
    }
    b[n] = a[n];
    for(int i=n-1;i>=0;i--)
    {
        b[i] = b[i+1] + a[i];
    }
    ll ans = 0,temp = 1,flag = 1;
    for(int i=0;i<n;i++)
    {
        ans += temp;
        temp -= a[i];
        if(temp < 0)
            flag = 0;
        if(i==n-1)
            break;
        temp = temp * 2;
        temp = min(temp,b[i+1]);
    }
    if(flag && temp * 2 >=a[n] && temp <= a[n])
        cout << ans + a[n];
    else
        cout << "-1";
    return 0;
}


Measured memory_bytes: 5148
yes="APPROVED"
no="DENIED"
N=int(input())
a=list(map(int,input().split()))
flag=True
for i in a:
    if i%2==1:
        continue
    if not(i%5==0 or i%3==0):
        
        flag=False
        break
if flag:
    print(yes)
else:
    print(no)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define N 5005
#define ll long long
using namespace std;
int n,m;
int st[N],top;
int a[N][205],l[N],r[N];
ll f[N][N];
void add(int x1,int y1,int x2,int y2,int z)
{
    f[x1][y1]+=z;f[x2+1][y2+1]+=z;
    f[x1][y2+1]-=z;f[x2+1][y1]-=z;
}
ll sum[N];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=2;i<=n;i++)
    {
        int tmp;scanf("%d",&tmp);
        sum[i]=sum[i-1]+tmp;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    for(int i=1;i<=m;i++)
    {
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        top=0;
        for(int j=1;j<=n;j++)
        {
            while(top&&a[st[top]][i]<=a[j][i])r[st[top--]]=j;
            st[++top]=j;
        }
        while(top)r[st[top]]=n+1,top--;
        for(int j=n;j>=1;j--)
        {
            while(top&&a[st[top]][i]<a[j][i])l[st[top--]]=j;
            st[++top]=j;
        }
        for(int j=1;j<=n;j++)
        {
            add(l[j]+1,j,j,r[j]-1,a[j][i]);
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            f[i][j]+=-f[i-1][j-1]+f[i-1][j]+f[i][j-1];
            if(j>=i)ans=max(ans,f[i][j]-sum[j]+sum[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = -1001001001001001000;
    ans = max(ans, a*c);
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
typedef pair<int,int> P;
const int MOD = 998244353;
const ll mod = 1e9 + 7;
const int mxN = 1e5 + 9;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    if( n%1000 == 0 ) cout << 0;
    else{
        cout << 1000- (n%1000);
    }



}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
typedef long long ll;

using namespace std;
typedef pair<int, int> pii;

struct UnionFind{
    vector<int> par;
    vector<int> rank;
    UnionFind(int n){
        par = vector<int>(n, -1);
        rank = vector<int>(n, 0);
    }

    int root(int x){
        if(par[x] < 0){
            return x;
        }
        return par[x] = root(par[x]);
    }

    bool isSame(int a, int b){
        return root(a) == root(b);
    }

    int size(int a){
        a = root(a);
        return -par[a];
    }

    bool merge(int a, int b){
        a = root(a);
        b = root(b);
        if(isSame(a, b)){
            return false;
        }
        if(rank[a] < rank[b]){
            swap(a, b);
        }
        if(rank[a] == rank[b]){
            rank[a] ++;
        }
        par[a] += par[b];
        par[b] = a;
        return true;
    }

};

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> as(M);
    vector<int> bs(M);
    rep(i, M){
        cin >> as[i] >> bs[i];
    }
    UnionFind uf(N + 1);
    vector<ll> ansList(M);
    for(int i = M - 1; i >= 0; i --){
        int a = as[i];
        int b = bs[i];
        ll ans = 0;
        ll a_size = uf.size(a);
        ll b_size = uf.size(b);
        if(uf.merge(a, b) == true){
            ans += a_size * b_size;
        }
        ansList[i] = ans;
    }
    ll ans = 0;
    rep(i, ansList.size()){
        ans += ansList[i];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int hituzi = sc.nextInt();
        int ookami = sc.nextInt();
        if(ookami >= hituzi){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
    }
}


Measured memory_bytes: 35852
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
//#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}


int main()
{
	int N, K, R;
	int b, c;
	int count = 0;
	int X[100];

	long long int S;
	long long int min = INF;

	
	scanf("%d", &N);

	for (int i = 0; i < N; i++)
		scanf("%d", &X[i]);

	for (int i = 1; i < 100; i++)
	{
		S = 0;
		for (int j = 0; j < N; j++)
		{
			S += ABS(X[j] - i) * ABS(X[j] - i);

			//printf("%d     \n", S);
		}
		if (S < min)
			min = S;
	}

	printf("%lld", min);
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && a!=c) {
    cout << "Yes" << endl;
  }
  else if(a==c && a!=b) {
    cout << "Yes" << endl;
  }
  else if(b==c && a!=b) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }  
  return 0;
}  

Measured memory_bytes: 256
S=input()
listS=[]
for i in range(len(S)):
    listS.append(S[i])

T=input()
listT=[]
for j in range(len(T)):
    listT.append(T[j])

if len(listS)!=len(listT):
    print("No")
else:
    count=0
    for k in range(len(S)):
        listS.insert(0,listS[len(S)-1])
        del listS[len(S)]
        if listS==listT:
            print("Yes")
            break
        else:
            count+=1
    if count==len(S):        
        print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>

using namespace std;

int main(void) {
  int n;
  cin >> n;
  double x[n];
  char u[n][4];
  double sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> u[i];
    if (strcmp((const char*)u[i], "JPY") == 0) {
      sum += x[i];
    } else {
      sum += (x[i] * 380000);
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 888
import math

def enum_div(n):
    ir=int(n**(0.5))+1
    ret=[]
    for i in range(1,ir):
        if n%i == 0:
            ret.append(i)
            if (i!= 1) & (i*i != n):
                ret.append(n//i)
    return ret

def isPrime(x):
    if x < 2:
        return 0
    elif x == 2:
        return 1
    if x%2 == 0:
        return 0
    ir=int(x**(0.5))+1
    for i  in range(3,ir,2) :
        if x%i == 0:
            return 0
    return 1

a,b=map(int,input().split())
c=math.gcd(a,b)

if isPrime(c)==1:
    print(2)
else:
    icnt=0
    for i in enum_div(c):
        if isPrime(i)==1:
            icnt+=1
    print(icnt+1)

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

red={}
for _ in range(n):
  x,y=map(int,input().split())
  if x in red:
    red[x].append(y)
  else:
    red[x]=[y]
  
blue={}
for _ in range(n):
  x,y=map(int,input().split())
  if x in blue:
    blue[x].append(y)
  else:
    blue[x]=[y]
#print(red,blue)
blueOption=[2*n+1,[]]

cnt=0
for i in range(2*n+1):
  border=2*n-i
  blueOption[0]=border
  if border in blue:
    blueOption[1]+=blue[border]
    blueOption[1].sort()
  #print(redOption))
  
  if border in red:
    redTemp=red[border]
    #print(border,redTemp)
    redTemp.sort(reverse=True)
    for item in redTemp:
      for blueItem in blueOption[1]:
        if item<blueItem:
          cnt+=1
          blueOption[1].remove(blueItem)
          break
print(cnt)
  

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

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double cr = abs(h * 30.0 + m * 0.5 - m * 6.0) * M_PIl / 180.0;
  double c = sqrt(a * a + b * b - 2.0 * a * b * cos(cr));
  cout << fixed << setprecision(20) << c << endl;

  return 0;
}


Measured memory_bytes: 4228
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int S;
	int a, b;
	cin >> S;
	a = S / 100;
	b = S - a * 100;
	if (0 <= a && 0 <= b) {
		if (0 < a&&a < 13) {
			if (0 < b&&b < 13) {
				cout << "AMBIGUOUS";
			}
			else {
				cout << "MMYY";
			}
		}
		else {
			if (0 < b&&b < 13) {
				cout << "YYMM";
			}
			else {
				cout << "NA";
			}
		}
	}
	else {
		cout << "NA";
	}
}


Measured memory_bytes: 256
n, l = (int(i) for i in input().split())
word_list = [input() for i in range(n)]

word_list.sort()
ans = 0

for word in range(n):
    for letter in range(l):
        if ans == 0:
            ans = word_list[word][letter]
        else:
            ans = "{0}{1}".format(ans, word_list[word][letter])

print(ans)

Measured memory_bytes: 3060
H, W = [int(i) for i in input().split()]
A = [list(input()) for _ in range(H)]

def dfs(h, w, count):
    if (h, w) == (H - 1, W - 1):
        return count

    ans = 0
    for nh, nw in [(h + 1, w), (h, w + 1)]:
        if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == "#":
            ans += dfs(nh, nw, count + 1)
    return ans

if dfs(0, 0, 1) == sum(a.count("#") for a in A):
    print("Possible")
else:
    print("Impossible")


Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long power = 1;
		int n = sc.nextInt();
		for(int i = 1; i <= n; i++) {
			power *= i;
			power %= (int)Math.pow(10, 9) + 7;
		}
		System.out.println(power);
	}
}

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    X, K, D = readnums()
    if X > 0:
        if X // D >= K:
            print(X - K * D)
        else:
            a1 = X % D
            a2 = D - X % D
            if (K - X // D) % 2:
                print(a2)
            else:
                print(a1)
    else:
        X = -X
        if X // D >= K:
            print(X - K * D)
        else:
            a1 = X % D
            a2 = D - X % D
            if (K - X // D) % 2:
                print(a2)
            else:
                print(a1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9212
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define Fi first
#define Se second
using namespace std;
static const LL INF = 1LL<<61LL;
typedef pair<int,int> PII;

PII U;
PII R;
int W,H;
int N;
int ans;
int main(){
    U.Fi=1;R.Fi=1;
    U.Se=1;R.Se=2;
    cin>>W>>H;
    cin>>N;
    rep(i,N){
        int a;
        cin>>a;
        if(a==0){
            if(U.Fi<W&&U.Se<H)U.Fi+=1;
            else if(U.Fi==W&&U.Se<H)U.Se+=1;
            else if(U.Se==H)U.Fi-=1;
        }
        else if(a==1){
            if(R.Fi<W-1&&R.Se<H-1)R.Fi+=1;
            else if(R.Fi==W-1&&R.Se<H-1)R.Se+=1;
            else if(R.Se==H-1)R.Fi-=1;
        }
        if((U.Fi==R.Fi&&U.Se+1==R.Se)||(U.Se==R.Se&&U.Fi==R.Fi+1))ans++;
        else if((R.Fi==U.Fi&&R.Se+1==U.Se)||(R.Se==U.Se&&U.Fi==R.Fi+1))ans++;
        //cout<<U.Fi<<" x "<<R.Fi<<endl;
        //cout<<U.Se<<" y "<<R.Se<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1164
fun main(args: Array<String>) {
    val (H, W) = readLine()!!.split(" "). map { it.toInt() }
    val map = Array(H) { IntArray(W) }
    val dp = Array(H) { IntArray(W) }
    dp[0][0] = 1
    for(i in 0 until H) {
        val s = readLine()!!
        for(j in 0 until W) {
            map[i][j] = if (s[j].toString() == "#") 1 else 0
        }
    }
    for (i in 0 until H) {
        for (j in 0 until W) {
            if (map[i][j] == 1) continue
            if (i == 0 && j == 0) continue

            dp[i][j] = ((if (i != 0) dp[i-1][j] else 0) + (if (j != 0) dp[i][j-1] else 0)) % 1000000007
        }
    }
    println(dp[H-1][W-1])
}

Measured memory_bytes: 60504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int n, x; cin >> n >> x;
    int mmin = inf;
    int sum = 0; int num = 0;
    rep(i, n) {
        int a; cin >> a;
        sum += a;
        chmin(mmin, a);
        num++;
    }
    while (sum <= x) { sum += mmin; num++; }
    out(num - 1);
}


Measured memory_bytes: 256
A,V = map(int, input().split())
B,W = map(int, input().split())
T = int(input())
 
if A < B: 
    Ap = A + V*T
    Bp = B + W*T

    if Ap >= Bp:
        print('YES')
    else:
        print('NO')    
else:
    Ap = A + (-V*T)
    Bp = B + (-W*T)

    if Ap <= Bp:
        print('YES')
    else:
        print('NO')    


Measured memory_bytes: 9196