akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
int main(){
  double d;
  int a,b,c=0,i,j,sum=0,n;
  scanf("%d",&n);
  for(j=0;j<n;j++){
    scanf("%d",&a);
    if(a<=1 && a%2==0 && a!=2){
      continue;
    }
    if(a==2){
      sum+=1;
    }
    d=sqrt(a)+1;
    for(i=2;i<=d;i++){
      if(a%i==0){
	c=1;
	break;
      }
    }
    if(c==0){
      sum+=1;
    }
    else{
      c=0;
    }    
  }
  printf("%d\n",sum);
  return 0;
}

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

int main(void) { 
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    int x = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'I') x++;
        ans = max(ans, x);
        if(s[i] == 'D') x--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string X;
  cin >> X;
  int N = X.size();
  int cnt = 0;
  int ans = N;
  rep(i, N) {
    if(X[i] == 'S') cnt++;
    else {
      if(cnt) {
        ans -= 2;
        cnt--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		byte W = sc.nextByte();
		byte H = sc.nextByte();
		byte x = sc.nextByte();
		byte y = sc.nextByte();
		byte r = sc.nextByte();
		if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}

}


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

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())
#define mp            make_pair
#define pb            push_back


typedef long long ll;

using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  if(a*b %2 == 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<vector>
#define LL long long 
const int N=1e5+9;
using namespace std;
LL n,m,vis[N],flag,tot,cnt;
vector<int>edge[N];
void addedge(int from,int too)
{
	edge[from].push_back(too); edge[too].push_back(from);  
}
void getclo(int now,int clo)
{
	 vis[now]=clo;
	 if(clo==1) cnt++;
	 int sz=edge[now].size();
	 for(int i=0;i<sz;++i)
	 {
	 	if(!flag) return;
	 	int too=edge[now][i];
	 	if(vis[too]==0)
	 	  getclo(too,3-clo);	
	    else 
		 if(vis[too]==clo)
		  {
		    flag=0;
	        return;
		  }
	 }
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(x,y);
	}
	flag=1;
	getclo(1,1);
	if(!flag) cout<<(n-1)*n/2-m<<endl;
	else cout<<cnt*(n-cnt)-m<<endl;
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r) \
    for (int i = l; i < r; i++) cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int m, n;
char c[40][40];
bool isInside(int x, int y) {
    return (x >= 0 && x < m && y >= 0 && y < n);
}
int bfs(pair<int, int> source) {
    queue<pair<pair<int, int>, int>> q;
    vector<vector<bool>> visited(m, vector<bool>(n, false));
    visited[source.first][source.second] = true;
    q.push({source, 0});
    int ans = INT_MIN;
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        ans = max(ans, p.second);

        int x = p.first.first, y = p.first.second;
        for (int i = 0; i < 4; i++) {
            int tx = x + dx[i];
            int ty = y + dy[i];

            if (isInside(tx, ty) && !visited[tx][ty] && c[tx][ty] == '.') {
                q.push({{tx, ty}, p.second + 1});
                visited[tx][ty] = true;
            }
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> m >> n;

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            cin >> c[i][j];
        }
    }
    int ans = INT_MIN;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (c[i][j] == '.') {
                ans = max(ans, bfs({i, j}));
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   string S;
   cin >> N >> S;
   long long cnt[3]={0,0,0};
   for(int i = 0 ; i < N; i++){
      if(S[i]=='R') cnt[0]++;
      if(S[i]=='G') cnt[1]++;
      if(S[i]=='B') cnt[2]++;
   }
   long long ans=cnt[0]*cnt[1]*cnt[2];
   for(int i = 0 ; i < N ; i ++){
      for(int d = 1; i+d+d< N; d++){
         if(S[i]!=S[i+d]&&S[i]!=S[i+d+d]&&S[i+d]!=S[i+d+d]) ans--;
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int h, w, i, j;
	while(1){
		scanf("%d %d", &h, &w);
		if(h || w){
			for(i = 0; i < h; i++){
				for(j = 0; j < w; j++){
					if((i + j) % 2){
						printf(".");
					}else{
						printf("#");
					}
				}
				printf("\n");
			}
			printf("\n");
		}else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 572
/* ex6_2
   moka223711 */

#include <stdio.h>
#include <string.h>
#define SIZE 101 // 文字数制限が100なので配列の大きさは100+1

int main(void){
    char str[SIZE];
    int len;
    scanf("%s", str);
    // strlenは文字列の長さを返す
    len = strlen(str);
    
    // 文字列の最初の文字str[0]
    // 文字列の長さから最初の文字と最後の文字を抜いたlen-2
    // 文字列の最後の文字str[len-1] をそれぞれ出力
    printf("%c%d%c", str[0], len-2, str[len-1]);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
 
int main() {
    ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll x = 0;
	int a, d[100001] = {};
	for (int i = 0 ; i < n ; i++) {
		cin >> a;
		d[a]++;
		x += a;
	}
	int q;
	cin >> q;
	int b, c;
	for (int i = 0 ; i < q ; i++) {
		cin >> b >> c;
		x += 1ll * (c - b) * d[b];
		cout << x << endl;
		d[c] += d[b];
        d[b] = 0;
	}
}

Measured memory_bytes: 4016
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int x,y;
    cin>>x>>y;
    for(int i=0;i<=x;i++){
        if(y==i*2+(x-i)*4){
            cout<<"Yes\n";
            return;
        }
    }
    cout<<"No\n";
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long

int main() {
  string s ;
  cin >> s ;
  int half = (s.size()-1)/2;
  int ans = 0;
  
 
  while(half>=1 ){
   rep(i,half){
    if(s.at(i) != s.at(half+i)){
      half --;
      break;
    }
    if(i == half-1){
      ans = half*2;
      half = 0 ;
    }
   }
  }
   cout << ans ;   
 
}


Measured memory_bytes: 256
function Main(input) {
    input = input.split(' ').map(n => parseInt(n, 16));
    x = input[0];
    y = input[1];
    if(x == y) {
        console.log('=');
    } else if(x < y) {
        console.log('<');
    } else {
        console.log('>');
    }
    
    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] adj = new int[n+1][];
        for (int i = 0; i < n; i++) {
            int u = in.nextInt();
            int k = in.nextInt();
            adj[u] = new int[k];
            for (int j = 0; j < k; j++) {
                adj[u][j] = in.nextInt();
            }
        }
        in.close();
        int[] d = bfs(adj, n);
        for (int i = 1; i <= n; i++) {
            System.out.println(i + " " + d[i]);
        }
    }

    private static int[] bfs(int[][] adj, int n) {
        Queue<Integer> queue = new LinkedList<>();
        HashSet<Integer> visited = new HashSet<>();
        queue.offer(1);
        int[] d = new int[n+1];
        Arrays.fill(d, -1);
        d[1] = 0;
        visited.add(1);
        while (!queue.isEmpty()) {
            int v = queue.poll();
            int[] neighbors = adj[v];
            for (int i : neighbors) {
                if (!visited.contains(i)) {
                    visited.add(i);
                    queue.offer(i);
                    if (d[i] < 0) {
                        d[i] = d[v] + 1;
                    } else if (d[v] + 1 < d[i]) {
                        d[i] = d[v] + 1;
                    }
                }
            }
        }
        return d;
    }
}



Measured memory_bytes: 28292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] data = new int[N+1];

		data[0] = 0;
		for (int i = 1; i <= N; i++) {
			int a = sc.nextInt();
			data[a] = i;
		}
		for (int i = 1; i <= N; i++) {
			System.out.print(data[i]+" ");
		}
	}
}

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

int main() {
  int n,i;
  cin >> n;
  i = 1;
  while(i <= n){
    i = i*2;
  }
  cout << i/2 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N_MAX 100
#define W_MAX 10000
using namespace std;
int dp[N_MAX+1][W_MAX+1];
int v[N_MAX+1],w[N_MAX+1];
int N,W;

int solve(){
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(j>=w[i]){
                dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
            }
            else dp[i+1][j]=dp[i][j];
        }
    }
    
    return dp[N][W];
}
int main(){
    
    
    cin>>N>>W;
    for(int i=0;i<N;i++) cin>>v[i]>>w[i];
    
    cout<<solve()<<endl;
    
    return 0;
}



Measured memory_bytes: 6984
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

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

	map<int, int> mp_even, mp_odd;
	for (int i = 0; i < n; i++) {
		if (i & 1) mp_odd[v[i]]++;
		else mp_even[v[i]]++;
	}

	auto comp = [](auto &l, auto &r) {return l.second > r.second; };
	vector<pair<int, int>> top2_odd(2), top2_even(2);
	partial_sort_copy(mp_odd.begin(), mp_odd.end(), top2_odd.begin(), top2_odd.end(), comp);
	partial_sort_copy(mp_even.begin(), mp_even.end(), top2_even.begin(), top2_even.end(), comp);

	if (top2_odd[0].first != top2_even[0].first) cout << n - (top2_odd[0].second + top2_even[0].second) << "\n";
	else cout << n - max(top2_odd[0].second + top2_even[1].second, top2_odd[1].second + top2_even[0].second) << "\n";

	return 0;
}

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

int main(){
    int N, X;
    cin >> N >> X;
    int L[N];
    for(int i = 0; i < N; i++)
        cin >> L[i];
    int ans = 0, dis = 0;
    
    for(int i = 0; i < N; i++){
        if(dis > X)
            break;
        ans++;
        dis += L[i];
    }
    if(dis <= X)
        ans++;
    cout << ans << "\n";
    return 0;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N, A, B;
    cin >> N >> A >> B;
    cout << ((B - A) % 2 == 0 ? "Alice" : "Borys") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

int MAX=100000;
vector<int> x(MAX,0);//関係分け
vector<vector<int>> frien(MAX,vector<int>(0));

int cnt=1;


void dfs(int i){
    if(x[i]) return;
    x[i]=cnt;
    for(auto a : frien[i]) dfs(a);
    return;
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,m,k;
    cin>>n>>m>>k;
    int f,g;
    vector<P> enemy(k);
    rep(i,m){
        cin>>f>>g;
        f --;
        g --;
        frien[f].push_back(g);
        frien[g].push_back(f);
    }
    rep(i,k){
        cin>>f>>g;
        f --;
        g --;
        enemy[i]=P(f,g);
    }
    
    rep(i,n){
        if(x[i]) continue;
        dfs(i);
        cnt ++; 
    }
    vector<int> w(n);
    rep(i,n) w[i]=x[i];
    sort(all(w));//数えるた
    vector<int> z(cnt+1,0);
    REP(i,1,cnt+1){
        f=upper_bound(all(w),i)-lower_bound(all(w),i);
        z[i]=f;
    }
    
    rep(i,n){
        w[i]=z[x[i]]-1-frien[i].size();
    }//x:組み合わせ、w:人数
    rep(i,k){
        f=enemy[i].first;
        g=enemy[i].second;
        if(x[f]==x[g]) {w[f] --;w[g] --;}
    }
    //すでにfriend

    rep(i,n) cout<<w[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 8320
#include <iostream>

using namespace std;

string s;
int main()
{
    cin >> s;
    if(s[0] == s[1] && s[0] == s[2] && s[0] == s[3]) {
        cout << "No";
    }else if(s[0] == s[1] && s[2] == s[3]) {
        cout << "Yes";
    } else if (s[0] == s[2] && s[1] == s[3]) {
        cout << "Yes";
    } else if (s[0] == s[3] && s[1] == s[2]) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=n/(a+b)*a;
    ll tmp=n%(a+b);
    if(tmp<=a)ans+=tmp;
    else ans+=a;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#%%
def o(x, w):
    if x == 0:
        return w
    else:
        return x

h, w = map(int, input().split())
a = [[] for _ in range(h)]
for i in range(h):
    a[i] = list(map(int, input().split()))

b = []
for i in range(h):
    if i%2 == 0:
        tmp = a[i]
    else:
        tmp = a[i][::-1]
    for j in range(w):
        b.append(tmp[j])

#print(b)

l1 = []
l2 = []
for i in range(len(b)-1):
    if b[i]%2 == 1:
        b[i] -=1
        b[i+1] += 1
        if ((i+0)//w) % 2 == 1:
            l1.append(((i)//w) * w - i%w + w - 1)
        else:
            l1.append(i)
        j = i+1
        if ((j+0)//w) % 2 == 1:
            l2.append(((j)//w) * w - j%w + w - 1)
        else:
            l2.append(j)

#print(b)
#print(l1)
#print(l2)

print(len(l1))
for i in range(len(l1)):
    y1 = l1[i]//w+1
    x1 = l1[i]%w+1
    y2 = l2[i]//w+1
    x2 = l2[i]%w+1
    print(y1, x1, y2, x2)

Measured memory_bytes: 19844
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;


int main(){
    int a, b, k, cnt = 0;
    int A[100];
    cin >> a >> b >> k;
    for (int i = 1; i <= 100; i++) {
        if (a%i == 0 && b%i == 0) {
            cnt++;
            A[cnt] = i;
        }
    }
    cout << A[cnt-k+1] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;
public class Main {





public static void main(String[] args)
{
	Scanner sc=new Scanner(System.in);
char a=sc.next().charAt(0);
char b=sc.next().charAt(0);
char c=sc.next().charAt(0);
String aa=""+a;
String bb=""+b;
String cc=""+c;
System.out.println(aa.toUpperCase()+bb.toUpperCase()+cc.toUpperCase());
}

}

class pair{
	int x,y;
	pair(int x,int y){
		this.x=x;
		this.y=y;
	}
}


Measured memory_bytes: 39836
package main

import (
	"fmt"
	"math"
	"strings"
	"strconv"
)

func main() {
	var a, b float64
	var x, y float64
	x = 0
	y = 0
	var now float64
	now = 90
	var info string
	for {
		fmt.Scan(&info)
		infos := strings.Split(info, ",")
		a_int, _ := strconv.Atoi(infos[0])
		b_int, _ := strconv.Atoi(infos[1])
		a = float64(a_int)
		b = float64(b_int)
		// println(a, b)
		if a == 0 && b == 0 {
			break
		}
		x += math.Cos(now*math.Pi/180)*a
		y += math.Sin(now*math.Pi/180)*a
		now -= b
	}
	fmt.Printf("%d\n%d\n", int(x), int(y))
}


Measured memory_bytes: 1108
#!/usr/bin/ruby
n,m=gets.split.map &:to_i
a,b,c=$<.map{|e|e.split.map &:to_i}.transpose
d=n.times.map{|i|[1<<30]*i+[0]+[1<<30]*(n-i-1)}
m.times{|i|
	d[a[i]-1][b[i]-1]=d[b[i]-1][a[i]-1]=c[i]
}
n.times{|k|n.times{|i|n.times{|j|
	d[i][j]=[d[i][j],d[i][k]+d[k][j]].min
}}}
p m.times.count{|i|
	n.times.all?{|s|
		d[s][a[i]-1]+c[i]!=d[s][b[i]-1]
	}
}

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

int main() {
  int n, i, ans = 1;
  cin >> n;
  vector<string> w(n);
  map<string, int> cnt;
  for (i = 0; i < n; i++) {
    cin >> w[i];
    cnt[w[i]]++;
  }
  for (auto p : cnt) {
    if (p.second > 1) {
      ans = 0;
      break;
    }
  }
  if (ans == 1) {
    for (i = 0; i < n - 1; i++) {
      if (w[i][w[i].size() - 1] != w[i + 1][0]) {
        ans = 0;
        break;
      }
    }
  }
  if (ans) {
    cout << "Yes"
         << "\n";
  } else {
    cout << "No"
         << "\n";
  }
  return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

int n;
int las[N];
long long A, B;
long long a[N], f[N], sum[N];

template <typename T> inline void read(T &x) {
	x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
}

int main() {
	read(n), read(A), read(B);
	if(A < B) swap(A, B);
	a[0] = -1e18;
	for(int i = 1; i <= n; ++i) {
		read(a[i]);
		if(i > 1 && a[i] - a[i - 2] < B) {
			/* 每隔一个一定要大于较小的数 B */
			puts("0");
			return 0;
		}
	}
	int p(0);
	for(int i = 1; i <= n; ++i) {
		while(p < i && a[i] - a[p + 1] >= A) ++p;
		las[i] = (a[i] - a[i - 1] >= B ? las[i - 1] : i);
		if(las[i - 1] == 0) {
			++f[i];
		} if(p >= las[i - 1] - 1) {
			f[i] = (f[i] + sum[p] - sum[max(0, las[i - 1] - 2)] + mod) % mod;
		}
		sum[i] = (f[i] + sum[i - 1]) % mod;
	}
	long long ans = 0;
	if(las[n] == 0) ++ans;
	ans = (ans + sum[n] - sum[max(0, las[n] - 2)]+ mod) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using ll = long long;

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  cout << t * ((n + x - 1) / x) << endl;
  return 0;
}

Measured memory_bytes: 3620
const N: usize = 55;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a: Vec<usize> = sc.vec(n);
    let b: Vec<usize> = sc.vec(n);

    if required(60, &vec![], &a, &b) {
        println!("-1");
        return;
    }

    let mut current = vec![];
    for i in (1..N).rev() {
        if required(i, &current, &a, &b) {
            current.push(i);
        }
    }

    let ans = current.into_iter().map(|c| 1 << c).sum::<usize>();
    println!("{}", ans);
}

fn required(k: usize, current: &Vec<usize>, a: &Vec<usize>, b: &Vec<usize>) -> bool {
    let mut graph = vec![vec![false; N]; N];
    for i in 0..N {
        graph[i][i] = true;
    }

    for &c in current.iter() {
        for i in 0..N {
            graph[i][i % c] = true;
        }
    }

    for t in 1..k {
        for i in 0..N {
            graph[i][i % t] = true;
        }
    }

    for k in 0..N {
        for i in 0..N {
            for j in 0..N {
                graph[i][j] |= graph[i][k] && graph[k][j];
            }
        }
    }

    (0..a.len()).any(|i| !graph[a[i]][b[i]])
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    string T;
    cin >> S >> T;
    if (S.find(T) != std::string::npos)
    {
        for (int k = 0; k < S.length(); k++)
        {
            if (S[k] == '?')
                S[k] = 'a';
        }
        cout << S << endl;
        return 0;
    }
    for (int i = S.length() - 1; i >= 0; i--)
    {
        bool flag = true;
        for (int j = 0; j < T.length(); j++)
        {
            if (!(S[i - j] == T[T.length() - 1 - j] || S[i - j] == '?'))
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            for (int j = 0; j < T.length(); j++)
            {
                S[i - j] = T[T.length() - 1 - j];
            }
            for (int k = 0; k < S.length(); k++)
            {
                if (S[k] == '?')
                    S[k] = 'a';
            }
            cout << S << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;
#define int long long

const int NMAX = 3 * 1e2 + 5;
int dist[NMAX][NMAX];

signed main(){
	ios_base::sync_with_stdio(false);
	for(int i=0; i<NMAX; i++)
		for(int j=0; j<NMAX; j++)
			dist[i][j] = LLONG_MAX/2;
	
	int n, m, l;
	cin >> n >> m >> l;	

	for(int i=0; i<m; i++){
		int a, b, c;
		cin >> a >> b >> c;
		dist[a][b] = min(dist[a][b], c);
		dist[b][a] = min(dist[b][a], c);
	}

	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(i == j) continue;
				if(dist[i][j] > dist[i][k] + dist[k][j])
					dist[i][j] = dist[i][k] + dist[k][j];
			}
		}
	}

	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++){
			if(dist[i][j] <= l){
				dist[i][j] = 1;
			}else{
				dist[i][j] = LLONG_MAX/2;
			}
		}


	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(i == j) continue;
				if(dist[i][j] > dist[i][k] + dist[k][j])
						dist[i][j] = dist[i][k] + dist[k][j];
			}
		}
	}

	int q;
	cin >> q;

	while(q--){
		int s, t;
		cin >> s >> t;
		if(dist[s][t] != LLONG_MAX/2)
			cout << (dist[s][t]-1) << endl;
		else
			cout << -1 << endl;
	}

	dbg(dist[5][2]);

	return 0;
}

/*
3 -> 0
4 -> 0
5 -> 1
6 -> 1
*/

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,m,a,i;
    cin >> n >> m;
    vector<int> broken(n+1);
    for(i=0;i<m;i++){
        cin >> a;
        broken[a]=1;
    }
    vector<int> dp(n+2);
    dp[n]=1;
    const int MOD = 1000000007;
    for(i=n-1;i>=0;i--){
        if(broken[i]) continue;
        dp[i] = (dp[i+1]+dp[i+2])%MOD;
    }
    cout << dp[0] << endl;

}

Measured memory_bytes: 1024
s=input()
a=s[:2]
b=s[2:]
na=int(a)
nb=int(b)
if na>12 or na==0:
    if nb>12 or nb==0:
        print('NA')
    else:
        print('YYMM')
else:
    if nb>12 or nb==0:
        print('MMYY')
    else:
        print('AMBIGUOUS')

Measured memory_bytes: 3060
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,m = inpm()

if n==m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 30808
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {
    string s,t;
    cin>>s>>t;
    map<char,char> m;
    set<int> se;
    rep(i,s.size()){
        if(m.find(s[i])==m.end()){
            if(se.count(t[i])==0){
                m[s[i]]=t[i];
                se.insert(t[i]);
            } else {
                fin("No");
                return 0;
            }
        } else if(m[s[i]]==t[i]){
            continue;
        } else {
            fin("No");
            return 0;
        }
    }
    fin("Yes");
}


Measured memory_bytes: 776
#include <iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a > 0) {
		cout << "Positive" << endl;
	} else if (a <= 0 && 0 <= b) {
		cout << "Zero" << endl;
	} else {
		int c = b-a;
		if (c % 2 == 0) {
			cout << "Negative" << endl;
		} else {
			cout << "Positive" << endl;
		}
	}
	return 0;
}

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

const vector<int> dy({0, 0, 1, -1});
const vector<int> dx({1, -1, 0, 0});

struct P {
  int y;
  int x;
};

// 01-BFS
int main() {

  const int INF = 1e9;

  int H, W;
  cin >> H >> W;

  int sx, sy, ex, ey;
  cin >> sy >> sx >> ey >> ex;
  --sx, --sy, --ex, --ey;

  vector<string> maps(H);

  vector<vector<int>> dist(H, vector<int>(W, INF));

  rep(i, 0, H) { cin >> maps[i]; }

  dist[sy][sx] = 0;

  deque<P> q;
  q.emplace_back(P({sy, sx}));

  while (!q.empty()) {

    int y = q.front().y;
    int x = q.front().x;
    q.pop_front();

    int d = dist[y][x];

    // コスト０
    // ４方向
    rep(i, 0, 4) {

      int ny = y + dy[i];
      int nx = x + dx[i];

      if (ny < 0 || H <= ny || nx < 0 || W <= nx)
        continue;
      if (maps[ny][nx] == '#')
        continue;
      if (dist[ny][nx] <= d)
        continue;

      dist[ny][nx] = d;
      q.emplace_front(P({ny, nx}));
    }

    // コスト１
    // 中心５ｘ５エリア
    for (int i = -2; i <= 2; ++i) {
      for (int j = -2; j <= 2; ++j) {

        int ny = y + i;
        int nx = x + j;

        if (ny < 0 || H <= ny || nx < 0 || W <= nx)
          continue;
        if (maps[ny][nx] == '#')
          continue;
        if (dist[ny][nx] <= d + 1)
          continue;

        dist[ny][nx] = d + 1;
        q.emplace_back(P({ny, nx}));
      }
    }
  }

  int ans = dist[ey][ex];
  if (ans == INF) {
    ans = -1;
  }

  cout << ans << endl;
  getchar();
}

Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    int n;
    cin >> n;
    vll a(n);
    cin >> a;
    ll now = a[0];
    ll ans = 0;
    REP(i,n){
        if (now > a[i]) {
            ans += now - a[i];
        } else {
            now = a[i];
        }
    }
    cout << ans << endl;
}

int main() {
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



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


int main(){
  string S, T;
  cin >> S >> T;

  for(auto& t : T){
    if(S.find(t) == string::npos){
      cout << -1 << endl;
      return 0;
    }
  }

  int N = S.size();
  vector<vector<int>> pos(26);
  for(int ii=0; ii<N; ii++){
    pos[S[ii]-'a'].push_back(ii);
  }

  vector<map<char, pair<int, int>>> dict(N);
  for(int ii=0; ii<N; ii++){
    for(int jj=0; jj<26; jj++){
      if(pos[jj].size()==0) continue;
      auto it = lower_bound(pos[jj].begin(), pos[jj].end(), ii+1);
      int index = (it==pos[jj].end()) ? pos[jj][0] : *it;
      int score = (ii < index) ? index-ii : N-ii+index;
      dict[ii]['a'+jj] = {index, score};
    }
  }

  /*
  for(int ii=0; ii<N; ii++){
    for(int score=1; score<N+1; score++){
      int index = ii+score;
      if(index >= N) index -= N;
      if(dict[ii].find(S[index]) != dict[ii].end()) continue;
      dict[ii][S[index]] = {index, score};
    }
  }
  */

  /*
  for(int ii=0; ii<N; ii++){
    cout << S[ii];
    for(auto d : dict[ii]){
      cout << "(" << d.first << ": " << d.second.first << ", " << d.second.second << ") ";
    }
    cout << endl;
  }
  */

  long long int ans = 0;
  auto t = T.begin();
  int index = S.find_first_of(*t);
  ans += index+1;
  while(t+1 != T.end()){
    ans += dict[index][*(t+1)].second;
    index = dict[index][*(t+1)].first;
    t++;
  }
  cout << ans << endl;
 
  return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  
  int num = (N - 1) * (N - 2) / 2;
  if (K > num) {
    cout << -1 << endl;
    return 0;
  }
  cout << N * (N - 1) / 2 - K << endl;
  
  // スターを作る
  for (int i = 1; i < N; i++) {
    cout << i << " " << N << endl;
  }
  
  if (num - K == 0) return 0;
  
  // K個になるよう調整
  int cnt = 0;
  for (int i = 1; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      cout << i << " " << j << endl;
      cnt++;
      if (cnt == num - K) return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int m = 0,n = 0,l = 0;
		if(x >= a) {
			m = x - a;
			n = m / b;
			l = m - (n * b);
		System.out.println(l);
		}else if(m == b) {
			System.out.println(0);
		}
	}
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int main() {
  int c[3][3];
  rep(i, 3) rep(j, 3) cin >> c[i][j];

  string res = "No";
  rep(k, 101) rep(m, 101) rep(n, 101) {
    int a[3], b[3];
    a[0] = k, a[1] = m, a[2] = n;
    b[0] = c[0][0] - a[0], b[1] = c[1][1] - a[1], b[2] = c[2][2] - a[2];
    int cnt = 0;
    rep(i, 3) rep(j, 3) {
      if (c[i][j] != a[i] + b[j]) continue;
      cnt++;
    }
    if (cnt == 9) {
      res = "Yes";
      goto RES;
    }
  }

RES:
  cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

 
#define MAX 101

void reVisit(int);
void dfs(void);

int Adj[MAX][MAX];
int D[MAX];
int F[MAX];
int n, time;

int main()
{
  int i, j;
  int u, v, k;
 
  scanf("%d", &n);
  for(i = 1; i <= n; i++)
    {
      for(j = 1; j <= n; j++)
    {
      Adj[i][j] = 0;
    }
    }
  for(i = 1; i <= n; i++)
    {
      scanf("%d %d", &u, &k);
      for(j = 1; j <= k; j++)
    {
      scanf("%d", &v);
      Adj[u][v] = 1;
    }
    }
 
  dfs();
 
  for(i = 1; i <= n; i++)
    {
      printf("%d %d %d\n", i, D[i], F[i]);
    }
 
 return 0;
}
 
void dfs()
{
  int i;
 
  time = 0;
 
  for(i = 0; i < n; i++)
    {
      D[i] = 0;
      F[i] = 0;
    }
 
  for(i = 1; i <= n; i++)
    {
      if(D[i] == 0)
    reVisit(i);
    }
}
 
void reVisit(int u)
{
  int i, j;
 
  D[u] = ++time;
 
 
  for(i = 1; i <= n; i++)
    {
      if(Adj[u][i] == 1 && D[i] == 0)
    {
      reVisit(i);
    }
    }
 
  F[u] = ++time;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  ll ans = 0;
  if (a < 0) {
    ans += abs(a)*c + d + b*e;
  } else {
    ans += (b-a)*e;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3108
# 1.input
n = int(input())
a = list(map(int, input().split()))

#2. choose maximum number as a_i and remove
ai = max(a)
a.remove(ai)

# 3. choose the nearest number from (a_i/2) as a_j
abs_dist = [abs(a_temp-(ai/2)) for a_temp in a]
chosen_temp = min(abs_dist)
aj = a[abs_dist.index(chosen_temp)]

print("{} {}".format(ai, aj))

Measured memory_bytes: 14060
def to_int(A):
    return int(A[1])

def bubble_sort(N, A):
    for i in range(N):
        for j in range(i+1, N)[::-1]:
            if to_int(A[j]) < to_int(A[j-1]):
                aj = A[j]
                A[j] = A[j-1]
                A[j-1] = aj
    return A

def selection_sort(N, A):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if to_int(A[j]) < to_int(A[minj]):
                minj = j
        a = A[i]
        A[i] = A[minj]
        A[minj] = a
    return A

def is_stable(bubble, selection):
    if bubble == selection:
        return "Stable"
    else:
        return "Not stable"

if __name__ == "__main__":
    N = int(input())
    A = input().split(" ")
    bubble = bubble_sort(N, A[:])
    selection = selection_sort(N, A[:])
    print(" ".join(bubble))
    print("Stable")
    print(" ".join(selection))
    print(is_stable(bubble, selection))



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define sz(v)           (int)v.size()
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f;








void sol()
{   
    cin>>n>>a;
    
    
    
    
    cout<< ceil(n*1.0/a) <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 3816
#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);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << 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};

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr 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);}
inline void Yes(){cout << "Yes" << endl;}
inline void No(){cout << "No" << endl;}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){cout << "YES" << endl;}
inline void NO(){cout << "NO" << endl;}
inline 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 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(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;


vector<pint> key;
vector<int> dp;
int main(){
    
    int n, m;
    scanf("%d%d", &n, &m);
    key.resize(m);
    dp.resize(1<<n, INF);
    rep(i, m){
        int a, b;
        scanf("%d%d", &a, &b);  
        key[i].second = a;
        key[i].first = 0;
        rep(j, b){
            int c; scanf("%d", &c); --c;
            key[i].first |= 1<<c;
        }
    } 

    dp[0] = 0;
    rep(patt, 1<<n){
        rep(i, m){
            dp[ patt|key[i].first ] = min(dp[ patt|key[i].first ] , dp[patt] + key[i].second); 
        }
    }
    int ans = dp.back();
    if(ans == INF) ans = -1;
    ppp(ans);
    
    
    
    return 0;
}


Measured memory_bytes: 256
#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 F first
#define S second
#define INF 1 << 30

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

int n, cum[1024][1024];
char s[1024][1024];

int main(){
  while(scanf("%d", &n) && n){
    memset(cum, 0, sizeof(cum));
    rep(i, n){
      scanf("%s", s[i]);
      rep(j, n){
	if(s[i][j] != '.') continue;
	cum[i+1][j+1] = min(cum[i][j], min(cum[i][j+1], cum[i+1][j])) + 1;
      }
    }

    int res = 0;
    rep(i, n+1) rep(j, n+1)
      res = max(res, cum[i][j]);

    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 6300
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200000+10
int n,ans=0,k,tot=0,pos=1,a[MAXN];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if(!a[x])tot++;
		a[x]++;
	}
	sort(a+1,a+n+1);
	for(;!a[pos];pos++);
	for(int i=pos;i<=n;i++)
		if(i-pos+1<=tot-k)ans+=a[i];
		else break;
	printf("%d\n",ans);	
	return 0;
}

Measured memory_bytes: 1024
N=input()
S=raw_input()

L=[]

for i,x in enumerate(S):
		if x=="B": n=1
		elif x=="W": n=-1
		if i%2==1: n*=-1
		L.append(n)


mod=10**9+7

if sum(L)!=0:
	print 0
	quit()

ans=1
t=0
for x in L:
	if x==-1:
		ans*=t
		ans%=mod
	t+=x


for n in range(1,N+1):
	ans*=n
	ans%=mod

print ans


Measured memory_bytes: 46952
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    string S, T;

    cin >> S >> T;

    if (S.size() + 1 == T.size()) {
        for (int i = 0; i < S.size(); i++) {
            if (S[i] != T[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624