akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }
    void Union(int x, int y) {
        x = Find(x), y = Find(y);
        if(x == y) return;
        par[x] = par[y];
    }
    int Find(int x) {
        if(par[x]==x) return x;
        else return par[x] = Find(par[x]);
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<P> p(m);
    REP(i,m) {
        cin >> p[i].first >> p[i].second; p[i].first--, p[i].second--;
    }
    int ans = 0, cnt;
    REP(i,m) {
        UnionFind uf(n);
        REP(j,m) {
            if(j != i && !uf.Same(p[j].first, p[j].second)) {
                uf.Union(p[j].first, p[j].second);
            }
        }
        cnt = 0;
        REP(j,n) {
            if(j == uf.par[j]) cnt++;
        }
        if(1<cnt) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

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

cnt_white = 0
for row in s:
    cnt_white += row.count('.')

d = deque([[0, 0]])
dist = [[-1] * w for _ in range(h)]
dist[0][0] = 0
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
goal_flag = False
while d:
    x, y = d.popleft()
    if x == h - 1 and y == w - 1:
        goal_flag = True
        break
    for i in range(4):
        pos_x, pos_y = x + dx[i], y + dy[i]
        if 0 <= pos_x < h and 0 <= pos_y < w and s[pos_x][pos_y] == '.' and dist[pos_x][pos_y] == -1:
            d.append([pos_x, pos_y])
            dist[pos_x][pos_y] = dist[x][y] + 1

if goal_flag:
    print(cnt_white - dist[h-1][w-1] - 1)
else:
    print(-1)

Measured memory_bytes: 72064
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<string> v;
    v.push_back("Sunny");
    v.push_back("Cloudy");
    v.push_back("Rainy");
    string s;
    cin >> s;
    int index = 0;
    for(int i=0; i<3; i++){
        if(v[i]==s){
            index = i;
            break;
        }
    }
    cout << v[(index+1)%3];
    return 0;
}

Measured memory_bytes: 256
c1 = [int(elem) for elem in input().split()]
c2 = [int(elem) for elem in input().split()]
c3 = [int(elem) for elem in input().split()]

x1 = c1[0] - c2[0] == c1[1] - c2[1] == c1[2] - c2[2]
x2 = c1[0] - c3[0] == c1[1] - c3[1] == c1[2] - c3[2]
x3 = c3[0] - c2[0] == c3[1] - c2[1] == c3[2] - c2[2]
x4 = c1[0] - c1[1] == c2[0] - c2[1] == c3[0] - c3[1]
x5 = c1[0] - c1[2] == c2[0] - c2[2] == c3[0] - c3[2]
x6 = c1[2] - c1[1] == c2[2] - c2[1] == c3[2] - c3[1]

if x1 and x2 and x3 and x4 and x5 and x6:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {
	
	ll N, K;
	cin >> N >> K;

	ll h[MAX];
	repn(i, N) cin >> h[i];

	sort(h + 1, h + N + 1);

	ll ans = INF;

	repn(i, N - K + 1) {
		ans = min(ans, h[i + K - 1] - h[i]);
	}

	cout << ans;

	system("PAUSE");
}

Measured memory_bytes: 3320
#include <stdio.h>

#define WIDTH 6
#define HEIGHT 12

enum { YET, ALREADY };

int del( void );
int search( int, int );
int search_body( int, int, char );
void fall( void );

typedef struct {
	char color;
	int state;
} FIELD;

FIELD field[ WIDTH + 2 ][ HEIGHT + 2 ] = {};
const int dx[ 4 ] = { -1, 0, 1, 0 }, dy[ 4 ] = { 0, -1, 0, 1 };

int stack[ WIDTH * HEIGHT ], sp;

int main( void ) {
	int n, x, y, chain;

	for ( scanf( "%d", &n ); n--; printf( "%d\n", chain ) ) {
		for ( y = 1; y < HEIGHT + 1; y++ )
			for ( x = 1; x < WIDTH + 1; x++ ) {
				scanf( " %c", &field[ x ][ y ].color );
				field[ x ][ y ].state = YET;
			}

		for ( chain = 0; del(); chain++ )
			fall();
	}

	return 0;
}

int del( void ) {
	int x, y, del = 0;

	for ( y = 1; y < HEIGHT + 1; y++ )
		for ( x = 1; x < WIDTH + 1; x++ )
			if ( field[ x ][ y ].color != '.' && field[ x ][ y ].color != 'O' && field[ x ][ y ].state == YET ) {
				sp = 0;
				if ( search( x, y ) >= 4 ) {
					while ( sp-- )
						field[ stack[ sp ] / ( HEIGHT + 2 ) ][ stack[ sp ] % ( HEIGHT + 2 ) ].color = '.';

					del++;
				}
			}

	return del;
}

int search( int x, int y ) {
	return search_body( x, y, field[ x ][ y ].color );
}

int search_body( int x, int y, char color ) {
	int i, sum;

	stack[ sp++ ] = x * ( HEIGHT + 2 ) + y;
	field[ x ][ y ].state = ALREADY;

	sum = 0;
	for ( i = 4; i--;  ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ].state == YET )
			if ( field[ nx ][ ny ].color == color )
				sum += search_body( nx, ny, color );
			else if ( field[ nx ][ ny ].color == 'O' )
				stack[ sp++ ] = nx * ( HEIGHT + 2 ) + ny;
	}

	return sum + 1;
}

void fall( void ) {
	int x, y;

	for ( x = WIDTH + 1; x-- > 1;  ) {
		int cnt = 0;

		for ( y = HEIGHT + 1; y-- > 1;  )
			if ( field[ x ][ y ].color == '.' )
				cnt++;
			else {
				field[ x ][ y + cnt ].color = field[ x ][ y ].color;
				field[ x ][ y + cnt ].state = YET;
			}

		for ( ; cnt--; field[ x ][ cnt + 1 ].color = '.' ) ;
	}
}

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

int main(){
  ll N;  cin >> N;
  vector<ll> a(N);
  for(ll i = 0; i < N; i++){
    cin >> a[i];
  }
  
  if(N==1){
    if(a[0] == 0) cout << 0;
    else cout << -1;
    return 0;
  }
  
  ll ans = a[N-1];
  for(ll i = N-2; i >= 0; i--){
    if((a[i] > i)||(a[i] < a[i+1] - 1)) {ans = -1; break;}
    if(a[i] > a[i+1] - 1) {ans += a[i];}
  }
  cout << ans;
}

Measured memory_bytes: 1792
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        ps: [(usize, String); m],
    }
    let mut ac = vec![0; n];
    let mut wa = vec![0; n];
    for (p, s) in ps {
        if s == "AC" {
            ac[p - 1] += 1;
        } else {
            if ac[p - 1] == 0 {
                wa[p - 1] += 1;
            }
        }
    }
    let mut a = 0;
    let mut p = 0;
    for i in 0..n {
        if ac[i] > 0 {
            a += 1;
            p += wa[i];
        }
    }
    println!("{} {}", a, p);
}


Measured memory_bytes: 8444
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
using namespace std;

string s; 
int n,num[30],bit[200010],p[200010];
vector<int> v[30];

inline int sum(int p)
{
	int s=0ll;
	while(p>0){
		s+=bit[p];
		p-=p&(-p);
	}
	return s;
}

inline void add(int p,int v)
{
	while(p<=n){
		bit[p]+=v;
		p+=p&(-p);
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	n=s.size();
	for(int i=1;i<=n;i++){
		num[s[i-1]-'a'+1]++;
		v[s[i-1]-'a'+1].push_back(i);
	}
	int cnt=0,pos=0;
	for(int i=1;i<=26;i++){
		if(num[i]%2==1){
			cnt++;
			pos=v[i][v[i].size()/2];
		}
	}
	int ans=0ll;
	if(cnt>=2){
		cout<<-1<<endl;
		return 0;
	}
	if(cnt==1) p[pos]=n/2+1;
	vector<pair<int,int> > res;
	for(int i=1;i<=26;i++){
		for(int j=0;j<v[i].size()/2;j++){
			res.push_back(make_pair(v[i][j],v[i][v[i].size()-j-1]));
		}
	}
	sort(res.begin(),res.end());
	for(int i=0;i<res.size();i++){
		p[res[i].first]=i+1;
		p[res[i].second]=n-i;
	}
	for(int i=1;i<=n;i++){
		ans+=i-sum(p[i])-1ll;
		add(p[i],1ll);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8712
# UnionFind: https://note.nkmk.me/python-union-find/
n, m, k = map(int, input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        
    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.root[x] > self.root[y]:
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x
        
    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return -self.root[self.find(x)]
    
candidate = [-1] * (n + 1)
f_ship = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    candidate[a] -= 1
    candidate[b] -= 1
    f_ship.unite(a, b)
for _ in range(k):
    c, d = map(int, input().split())
    if f_ship.is_same(c, d):
        candidate[c] -= 1
        candidate[d] -= 1
for i in range(1, n + 1):
    candidate[i] += f_ship.size(i)
print(*candidate[1:])

Measured memory_bytes: 13420
#include <iostream>
#include<string>
#include<vector>
using namespace std;
int main(void){
    // Here your code !
    string s,t;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0')t+=s[i];
        if(s[i]=='1')t+=s[i];
        if(s[i]=='B')if(t.size()!=0)t.pop_back();}
    cout<<t<<endl;
    return 0;
}

Measured memory_bytes: 256
input()
L = list(map(int, input().split()))
m = min(L)
M = max(L)
a = [0]*(M-m+3)
for i in L:
    a[i-m] += 1
    a[i-m+1] += 1
    a[i-m+2] += 1
print(max(a))

Measured memory_bytes: 13964
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main() {
  while (true) {
    uint32_t N;
    cin >> N;
    if (N == 0) break;

    vector<pair<double, string>> seeds;
    for (uint32_t _ = 0; _ < N; _++) {
      string L;
      double P, A, B, C, D, E, F, S, M;
      cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
      double time = (A + B + C + D + E) + (D + E) * (M - 1);
      double efficiency = -(M * F * S - P) / time;
      seeds.push_back({efficiency, L});
    }

    sort(seeds.begin(), seeds.end());

    for (auto iter = seeds.begin(); iter < seeds.end(); iter++) {
      cout << iter->second << endl;
    }
    cout << "#" << endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#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() {
  int n;
  cin >> n;

  vector<int> d(n);
  rep(i, n) cin >> d[i];

  sort(d.begin(), d.end());

  cout << d[n/2] - d[n/2 - 1] << endl;


  return 0;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

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

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int MAXN = 1e5 + 5;

int cnt[MAXN];

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    int n;
    scanf("%d", &n);
    int diff = 0, mn = 1e9, mx = 0;
    for (int i = 0; i < n; i++) {
        int a; scanf("%d", &a);
        cnt[a]++;
        if (cnt[a] == 1) diff++;
        mn = min(mn, a);
        mx = max(mx, a);
    }
    if (mx == mn) {
        if (n == mx + 1)
            puts("Yes");
        else if (mx * 2 <= n)
            puts("Yes");
        else
            puts("No");
    } else if (mn + 1 == mx) {
        //assert(false);
        if (mx - cnt[mn] > 0 && (mx - cnt[mn]) * 2 <= cnt[mx])
            puts("Yes");
        else
            puts("No");
    } else {
        puts("No");
    }
    return 0;
}



Measured memory_bytes: 640
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find_root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
    
    def unite(self, x, y):
        x, y = self.find_root(x), self.find_root(y)
        if(x == y):
            return
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    
    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]
    
    def __str__(self):
        return 'UnionFind(n: {}, root: {}, rnk: {})'.format(self.n, self.root, self.rnk)
    
    def __repr__(self):
        return self.__str__()

inputs = open(0).readlines()
n, m, k = map(int, inputs[0].split())
AB = [tuple(map(int, ab.split())) for ab in inputs[1:m+1]]
CD = [tuple(map(int, cd.split())) for cd in inputs[m+1:]]

uf = UnionFind(n)
friends = [set() for _ in range(n)]
for n0, n1 in AB:
    uf.unite(n0-1, n1-1)
    friends[n0-1].add(n1-1)
    friends[n1-1].add(n0-1)

blocks = [set() for _ in range(n)]
for n0, n1 in CD:
    if uf.is_same_group(n0-1, n1-1):
        blocks[n0-1].add(n1-1)
        blocks[n1-1].add(n0-1)

candidates = []
for i in range(n):
    candidates.append(uf.count(i) - len(friends[i]) - len(blocks[i]) - 1)
print(*candidates)

Measured memory_bytes: 118824
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
main() {
  string ACGT = "ACGT";
  string s; cin>>s; s+="_";//with a sentinel
  int longest=-1, len=0;
  for(int i=0; i<s.size(); ++i) {
    char c = s[i];
    if(ACGT.find(c) == string::npos) {
      longest= max(longest, len);
      len= 0;
    }else ++len;
  }
  cout<< longest <<endl;
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


X, Y = map(int, input().split())

if not (X+Y) % 3 == 0:
    print(0)
else:
    # 2n + m = X
    # n + 2m = Y
    n = (Y - 2*X) // -3
    m = X - (2 * n)
    if n < 0 or m < 0:
        print(0)
    else:
        print(cmb(n+m, n, mod))


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

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var d = Console.ReadLine()
                .Split(' ')
                .GroupBy(x => x)
                .ToList();
            Console.Write(d.OrderByDescending(x => x.Count()).First().Key);
            Console.Write(' ');
            Console.WriteLine(d.OrderByDescending(x => x.Key.Length).First().Key);
        }
    }
}

Measured memory_bytes: 6452
#import math
n = int(input())
l = [0 for i in range(n)]
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x;
            if s <= n:
                l[s-1] += 1
for i in range(n):
    print(l[i])

Measured memory_bytes: 9016
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll N=305;
ll read(){
	ll s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
ll n,a[N],sum,tot,ans;
int main(){
	n=read();
	for(ll i=1;i<=n;i++)a[i]=read();
	for(ll i=3;i<=n;i++)sum^=a[i];
	tot=a[1]+a[2];tot-=sum;
	if(tot<0){puts("-1");return 0;}if(tot&1){puts("-1");return 0;}tot/=2;
	for(ll i=42;i>=0;i--){
		if((tot>>i)&1){
			if((sum>>i&1)){puts("-1");return 0;}
			ans+=(1ll<<i);
			tot-=(1ll<<i);
		}
	}
	if(tot){puts("-1");return 0;}
	if(ans>a[1]){puts("-1");return 0;}
	for(ll i=42;i>=0;i--){
		if((sum>>i&1)&&(ans+(1ll<<i))<=a[1])ans+=(1ll<<i);
	}
	if(ans==0){puts("-1");return 0;}
	cout<<a[1]-ans;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ii {
    int a, b;
    bool operator < (ii o) const {
        return tie(a, b) < tie(o.a, o.b);
    }
};
struct iii {
    int a, b, c;
    bool operator < (iii o) const {
        return tie(a, b, c) < tie(o.a, o.b, o.c);
    }
};

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 200005;

int N, M, par[MAXN], sz[MAXN];

int find(int x) {
    return par[x] == x? x: par[x] = find(par[x]);
}

void merge(int x, int y) {
    int xx = find(x);
    int yy = find(y);
    if (xx == yy) return;
    par[xx] = yy;
    sz[yy] += sz[xx];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        sz[i] = 1;
        par[i] = i;
    }
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        merge(x, y);
    }
    
    int ans = -1;
    for (int i = 1; i <= N; i++) {
        if (par[i] == i) {
            ans = max(ans, sz[i]);
        }
    }
    cout << ans << "\n";
    
}


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

int main()
{
    int N,M; cin>>N>>M;
    string s; cin>>s;
    reverse(s.begin(),s.end());

    vector<int> ans;
    int cur=0;
    while(cur<N){
        int nxt=-1;
        for(int i=min(N,cur+M);i>cur;i--) if(s[i]!='1'){
            nxt=i; break;
        }
        if(nxt==-1){
            cout<<-1<<endl;
            return 0;
        }
        ans.push_back(nxt-cur);
        cur=nxt;
    }
    reverse(ans.begin(),ans.end());
    for(int i:ans) cout<<i<<' '; cout<<endl;
    return 0;
}

Measured memory_bytes: 1144
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
a = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')


def solve(N: int, S: str):
    al = a+a
    ans = []
    for i in range(len(S)):
        ans += al[al.index(S[i])+N]

    print(''.join(ans))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s,t;
  cin>>s>>t;
  vstr ans(0);
  ll sn=sz(s);
  ll tn=sz(t);
  rep(i,sn-tn+1){
    ll k=1;
    string a=s;
    for(int j=0;j<tn;j++){
      if(s[i+j]=='?') {
        a[i+j]=t[j];
        continue;
      }
      if(s[i+j]!=t[j]){
        k=0;
        break;
      }
    }
    if(k){
      rep(j,sn){
        if(a[j]=='?'){
          a[j]='a';
        }
      }
      ans.pb(a);
    }
  }
  if(sz(ans)){
  sort(all(ans));
  COUT(ans[0]);
  }
  else{
    COUT("UNRESTORABLE");
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#define INF 100000000

int n=0,m[101][101];

void MatrixChainOrder(int p[]){
  int i,j,k,l,q;

  for(i=1 ; i<=n ; i++) m[i][i] = 0;
  for(l=2 ; l<=n ;l++){
    for(i=1 ; i<=n-l+1 ;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i ; k<j ; k++){
        q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
        m[i][j] = min(m[i][j],q);
      }
    }
  }
}

int min(int x,int y){
  if(x<=y) return x;
  else return y;
}

int main(){
  int i,r,c,p[101];
  scanf("%d",&n);
  for(i=0 ; i<n ;i++){
    scanf("%d%d",&r,&c);
    if(i==0){
      p[i] = r;
      p[i+1] = c;
    }
    else p[i+1] = c;
  }

  p[n] = c;
  MatrixChainOrder(p);
  printf("%d\n",m[1][n]);

  return 0;
}

Measured memory_bytes: 636
#-*- utf-8 -*-

A, B, C, K = map(int, input().split())

sum_mux = 0

least_A, least_B, least_C = A, B, C
least_K = K

while 0 !=  least_K:
    if 0 != least_A:
        if least_K >= least_A:
            sum_mux += least_A
            least_K -= least_A
            least_A = 0
        else :
            sum_mux += least_K
            least_A -= least_K
            least_K = 0
    elif 0 != least_B:
        if least_K >= least_B:
            sum_mux += 0
            least_K -= least_B
            least_B = 0
        else :
            sum_mux += 0
            least_B -=least_K
            least_K = 0
    else:
        if least_K >= least_C:
            sum_mux -= least_C
            least_K -= least_C
            least_C = 0
        else :
            sum_mux -= least_K
            least_C -=least_K
            least_K = 0

print(sum_mux, flush=True)

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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}

struct edge{int from, to,cost;};

// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));

string S,T;

int main()
{
    cin>>S>>T;
    int s,t;
    s=S.size();
    
    // cout<<T.substr(0,s)<<endl;
    if( S==T.substr(0,s)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;

}




Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s,p;
    cin >> s >> p;
    s+=s;
    bool exist=false;
    for(int li=0;li<s.size();li++){
        if(li+p.size()-1>=s.size()){
            continue;
        }
        bool judge=true;
        for(int i=0;i<p.size();i++){
            if(s.at(li+i)!=p.at(i)){
                judge=false;
                break;
            }
        }
        if(judge){
            exist=true;
        }
    }
    if(exist){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_20181006
{
    class Program
    {
        static void Main(string[] args)
        {
            var nt = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = nt[0];
            var t = nt[1];
            var tmpc = 1001;
            foreach (var _ in Enumerable.Range(0, n))
            {
                var ct = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if (ct[1] <= t)
                {
                    tmpc = Math.Min(tmpc, ct[0]);
                }
            }
            if (tmpc == 1001)
            {
                Console.WriteLine("TLE");
            }
            else
            {
                Console.WriteLine(tmpc);
            }
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int a,b;
  cin>>a>>b;
  vector<int>vec(a);
  for(int i=0;i<a;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int count=1;
  int c=vec.at(0);
  for(int j=1;j<a;j++){
    int d=vec.at(j);
    if(d!=c){
      count++;
      c=d;
    }
  }
  if(count<=b){
    cout<<0<<endl;
  }
  else{
    vector<int>vec2(count);
    int e=vec.at(0);
    int y=1;
    int m=0;
    vec2.at(0)=1;
    for(int k=1;k<a;k++){
      int f=vec.at(k);
      if(f==e){
        y++;
        if(k==a-1){
          vec2.at(m)=y;
        }
      }
      else {
        e=f;
        vec2.at(m)=y;
        m++;
        y=1;
        if(k==a-1){
          vec2.at(m)=y;
        }
      }
    }
   sort(vec2.begin(),vec2.end());
    int x=0;
    for(int n=0;n<count-b;n++){
      x+=vec2.at(n);
    }
    cout<<x<<endl;
  }
}

Measured memory_bytes: 1792
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int D;
  cin >> D;
  vector<int64_t> C(26);
  rep(i, 26) cin >> C[i];
  vector<vector<int64_t>> S(D, vector<int64_t>(26));
  rep(i, D) { rep(j, 26) cin >> S[i][j]; }
  vector<int> T(D);
  rep(i, D) cin >> T[i];

  vector<int> Last(26, 0);
  int64_t answer = 0;
  rep(i, D) {
    int idx = T[i] - 1;
    Last[idx] = i + 1;
    int64_t down = 0;
    rep(j, 26) { down += C[j] * (i + 1 - Last[j]); }
    answer += S[i][idx] - down;
    cout << answer << endl;
  }
  return 0;
}


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

int n, m, p;
int a[5000], b[5000], c[5000], d[2501];
const int INF = 2000000000;

void sp(){
	for (int i = 1; i <= n; i++)
		d[i] = INF;

	d[1] = 0;

	for (int j = 0; j < n; j++) {
		for (int i = 0; i < m; i++) {			
			if (d[a[i]] != INF)
				d[b[i]] = min(d[b[i]], d[a[i]] - c[i] + p);
		}
	}

	for (int j = 0; j < n; j++) {
		for (int i = 0; i < m; i++) {
			if (d[a[i]] != INF && d[b[i]] > d[a[i]] - c[i] + p)
				d[b[i]] = -INF;
		}
	}
}

int main()
{
	cin >> n >> m >> p;

	for (int i = 0; i < m; i++)
		cin >> a[i] >> b[i] >> c[i];

	sp();

	if (d[n] == -INF)
		cout << -1 << endl;
	else
		cout << max(0, -d[n]) << endl;

	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
 
int main(void){
 
int i,j,w,h,x = 1;
char b[52][52];
 
scanf("%d %d",&h,&w);
 
for(j = 1; j <= w; j++){
 for(i = 1; i <= h; i++){
scanf("%s",&b[i][j]);
 }
}
 
for(j = 1; j <= w; j++){
 for(i = 1; i <= h; i++){
if(b[i][j] == '#'){
if(b[i-1][j] == '#' || b[i+1][j] == '#' || b[i][j-1] == '#' || b[i][j+1] == '#') {}
else {x = 0; }
}
}
}
 
if(x == 1) printf("Yes");
else printf("No");
 
return 0;
}

Measured memory_bytes: 256
s=gets.strip.codepoints
zero="0".codepoints[0]
one="1".codepoints[0]
ze_c=0
on_c=0
for i in 0..s.size-1
    ze_c+=1 if s[i]==zero
    on_c+=1 if s[i]==one
end
puts [ze_c,on_c].min*2


Measured memory_bytes: 2812
/************************************************************LET US BREAK BAD!****************************************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vi vector<int>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vvi vector< vector<int> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<ll, ll>, ll > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define pi pair<int, int>
#define ppi pair<pair<int, int>, int>
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}

int main(){
    //#ifndef ONLINE_JUDGE
    //    freopen("../input.txt", "r", stdin);
    //    freopen("../output.txt", "w", stdout);
    //#endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll n, x, T;
        cin>>n>>x>>T;
        cout<<((n+x-1)/x)*T<<endl;    
    }
return 0;
}


Measured memory_bytes: 3648
n = input()
a = []
b = []
l = []
for _ in xrange(n):
    t = input()
    if _%2 == 0:
        a.append(t)
    else:
        b.append(t)
    l.append(t)
a = sorted(a)
b = sorted(b)
l = sorted(l)
c = 0
i = 0
for k,m in enumerate(l):
    if i < len(a) and m == a[i]:
        i += 1
        if k%2 == 1:
            c += 1
    else:
        if k%2 == 0:
            c += 1
print c/2

Measured memory_bytes: 7792
#include <stdio.h>
#include <stdlib.h>
void swap(int *x, int *y){
    int tmp;
    tmp = *x;
    *x = *y;
    *y = tmp;
}
int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    swap(&a, &b);
    swap(&a, &c);
    printf("%d %d %d", a, b, c);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
num = list(map(int, input().split()))

q = int(input())
for _ in range(q):
    start, end = map(int, input().split())
    tmp = num[start:end]
    tmp = tmp[::-1]
    num[start:end] = tmp

print(' '.join(str(n) for n in num))



Measured memory_bytes: 5644
#include <iostream>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 100005;
int pri[5005],cnt,n;
bool notpri[MAXN];
inline void init()
{
	for(int i=2;i<=2300;++i){
		if(!notpri[i])pri[++cnt]=i;
		for(int j=1;j<=cnt && pri[j]*i<=2300;++j){
			notpri[pri[j]*i]=true;
			if(i%pri[j]==0)break;
		}
	}
}
typedef long long ll;
ll a[MAXN],val[MAXN],rev[MAXN];
inline ll pow(int x,int k)
{
	if(k==0)return 1;
	else if(k==1)return x;
	else if(k==2)return x*x;
}
int ans=0;
map<ll,int>size;
map<ll,bool>used;
int cnt1=0;
int main()
{
	init();
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld",a+i);
		val[i]=rev[i]=1;
		for(int j=1;j<=cnt;++j){
			if(a[i]%pri[j])continue;
			int t=0;
			while(a[i]%pri[j]==0){
				++t;
				a[i]/=pri[j];
			}
			t%=3;
			val[i]*=pow(pri[j],t);
			rev[i]*=pow(pri[j],(3-t)%3);
		}		
		if(a[i]!=1){
			ll t;
			if(pow(t=(ll)sqrt(a[i]),2)==a[i]){
				val[i]*=a[i];
				rev[i]*=t;
			}else{
				val[i]*=a[i];
				rev[i]*=a[i]*a[i];
			}
		}
		if(val[i]==1)cnt1=true;
		size[val[i]]+=1;
	}	
	for(int i=1;i<=n;++i){
		if(val[i] != rev[i] && !used[val[i]] && size[val[i]]>=size[rev[i]])ans+=size[val[i]],used[val[i]]=true,used[rev[i]]=true;
	}
	cout<<ans+cnt1<<endl;
	return 0;
}


Measured memory_bytes: 27648
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
	long long n,m,ans=0,summ=0;
	cin>>n>>m;
	vector<long long> a1,a2,b1,b2,c1,c2,sum;
	for(long long i=0;i<n;i++){
		long long a,b,c;
		cin>>a>>b>>c;
		a1.push_back(a);
		b1.push_back(b);
		c1.push_back(c);
		a2.push_back(-a);
		b2.push_back(-b);
		c2.push_back(-c);
		sum.push_back(0);
	}
	for(int i=0;i<2;i++){
		vector<long long> a;
		if(i)a=a2;
		else a=a1;
		for(int j=0;j<2;j++){
			vector<long long> b;
			if(j) b=b2;
			else b=b1;
			for(int k=0;k<2;k++){
				vector<long long>c;
				if(k)c=c2;
				else c=c1;
				for(int l=0;l<n;++l){
					sum[l]=a[l]+b[l]+c[l];
				}
				sort(sum.begin(),sum.end());
				summ=0;
				for(int i=0;i<m;i++)summ+=sum[n-1-i];
				ans=max(ans,summ);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    int res = 0;
    string t = s;
    t += s;
    int ed = 0, mid = 0;
    int l = 1, r = 1;
    for(int i=1; i<s.size(); i++) {
        if(s[i] == s[0]) l++;
        else break;
    }
    if(l!=s.size()) for(int i=s.size()-2; i>=0; i--) {
        if(s[i]==s[s.size()-1]) r++;
        else break;
    } else {
        if(l%2) {res += (l/2) * (K/2);
        res += (l/2 + 1) * (K/2);
        if(K%2) res += l/2;}
        else res += (l/2) * K;
        
        cout << res << endl;
        return 0;
    }

    if(s[0] == s[s.size()-1]) ed = l+r;
    char prev = s[l];
    int cnt = 0;
    bool con = false;
    for(int i=l+1; i<s.size()-r; i++) {
        if(s[i] == prev) {
            if(con) cnt++;
            else {
                con = true;
                cnt = 2;
            }
        } else {
            if(con) {
                mid += cnt/2;
                con = false;
                cnt = 0;
            }
        }
        prev = s[i];
    }
    if(con) mid += cnt/2;
    //cout << ed << " " << mid << " " << l << " " << r << endl;

    if(ed != 0) {
    res += mid * K;
    res += (ed/2) * (K-1);
    res += (l/2) + (r/2);
    } else {
        res += (mid + (l/2) + (r/2)) * K;
    }

    cout << res << endl;
    
    return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;

using namespace std;

int main(){
    ll n, s;
    cin >> n >> s;
    vector<ll> w(n);
    vector<ll> v(n);
    for(ll i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }

    ll dp[n+1][100001+2];
    for(ll i = 0; i <= n; i++){
        for(ll j = 0; j <= 100001+1; j++){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j <= 100001+1; j++){
            if(v[i] <= j){
                dp[i+1][j] = min(dp[i][j-v[i]]+w[i],dp[i][j]);
            } else{
                dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            }
        }
    }

    ll ans = 0;
    for(ll j = 0; j <= 100001+1; j++){
        if(dp[n][j] <= s){
            ans = j;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

set<char> st;

int main() {
    cin >> n;
    REP(i,n) {
        cin >> c;
        st.insert(c);
    }
    cout << (st.size()==3?"Three":"Four") << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <cmath>
#include <cstring>
using namespace std;

#define pi acos(-1)

int to_int(string s){
    int number = 0;
    for(int i=0;i<s.size();i++){
        number *= 10;
        number += s[i] - '0';
    }
    return number;
}

string to_str(int n){
    string s;
    while(n!=0){
        s += n % 10 + 48;
        n /= 10;
    }
    reverse(s.begin(),s.end());
    return s;
}

bool isLeapYear(int year)
{
    if(((year % 4 == 0 ) && (year % 100 != 0)) || (year % 400 == 0))
        return true;
    else
        return false;
}

bool isPrime(int n)
{
    if (n == 2)
        return true;
    if ((n & 1)==0)
        return false;
    for (int i = 3; i*i <= n;i+=2) {
        if (n%i == 0)
            return false;
    }

    return true;
}

bool isPalindrome(string s)
{
    for(int i=0,j=s.size()-1 ; i< s.size()/2 && j >= s.size()/2;i++,j--){
            if(s[i] == s[j])
                continue;
            else{
                return false;
            }
        }
    return true;
}

/*#define row 5001
#define col 10000

int arr[row][col];

void fib()
{
    arr[0][0] = 0;
    arr[1][0] = 1;
    for(int i=2;i<row;i++){
        for(int j=0;j<col;j++){
            if(arr[i-1][j] + arr[i-2][j] == 0)
                continue;
            arr[i][j] += arr[i-1][j] + arr[i-2][j];
            if(arr[i][j] > 9){
                arr[i][j+1] = arr[i][j]/10;
                arr[i][j] %= 10;
            }
        }
    }
}*/

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

    string st =s;
    string tt = t;
    sort(st.begin(),st.end());
    sort(tt.begin(),tt.end());

    if(st != tt)
    {
        cout << "No" << endl;
        return 0;
    }

    for(int i=0;i<s.size();i++){
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
        st = s;
        s[0] = st[st.size()-1];
        for(int k=1;k<st.size();k++)
            s[k] = st[k-1];
    }

    cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "vector"
#include "string"
#include "map"
#include "algorithm"
#include "functional"
#include "set"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007; 

long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

struct Node {
	int l;
	int r;
	int bottom = 0;
	int up;
};

void Search(vector<long long int>&dp1, vector<long long int>& dp2, vector<vector<int>>&edge, vector<Node> &node, int n = M - 1) {
	if (edge[n].empty()) {
		dp1[n] = power(2, node[n].up - node[n].bottom, MOD);
		dp2[n] = dp1[n];
		dp2[n] += power(2, node[n].r - node[n].l + 1, MOD) + MOD - 2;
		dp2[n] %= MOD;
		return;
	}
	dp1[n] = 1;
	dp2[n] = 1;
	int w = node[n].r - node[n].l + 1;
	for (auto i : edge[n]) {
		if (dp1[i] == -1)Search(dp1, dp2, edge, node, i);
		dp1[n] *= dp1[i];
		dp1[n] %= MOD;
		dp2[n] *= (dp1[i] + dp2[i]) % MOD;
		dp2[n] %= MOD;
		/*if(node[i].r!=node[i].l)*/w -= node[i].r - node[i].l + 1;
	}
	dp2[n] *= power(2, w, MOD);
	dp2[n] %= MOD;
	dp2[n] += dp1[n] * (power(2, node[n].up - node[n].bottom, MOD) - 2);
	dp2[n] %= MOD;
	dp1[n] *= power(2, node[n].up - node[n].bottom, MOD);
	dp1[n] %= MOD;
	return;
}

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

	cin >> N;
	vector<int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	set<int>s;
	for (auto i : v)s.insert(i);
	vector<Node>node;
	for (auto i : s) {
		L = -1;
		for (int j = 0; j < N; j++) {
			if (v[j] >= i) {
				if (L == -1)L = j;
			}
			else {
				if (L != -1) {
					Node n;
					n.l = L;
					n.r = j - 1;
					L = -1;
					n.up = MOD;
					for (int k = n.l; k <= n.r; k++) {
						n.up = min(n.up, v[k]);
					}
					if (n.up == i)	node.push_back(n);
				}
			}
		}
		if (L != -1) {
			Node n;
			n.l = L;
			n.r = N - 1;
			n.up = MOD;
			for (int k = n.l; k <= n.r; k++) {
				n.up = min(n.up, v[k]);
			}
			if (n.up == i)	node.push_back(n);
		}
	}
	M = node.size();
	//cout << M << endl;
	vector<vector<int>>edge(M);
	reverse(node.begin(), node.end());
	for (int i = 0; i < M; i++) {
		for (int j = i + 1; j < M; j++) {
			if (node[i].l >= node[j].l&&node[i].r <= node[j].r) {
				edge[j].push_back(i);
				node[i].bottom = node[j].up;
				break;
			}
		}
	}
	vector<long long int>dp1(M, -1);
	vector<long long int>dp2(M, -1);
	Search(dp1, dp2, edge, node);
	cout << dp2.back() << endl;
	return 0;
}

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


int main(){
	int c = 0 ;
	string s , t ;
	cin >> s >> t ;
	if( s[0] == t[0]) c++ ;
	if( s[1] == t[1]) c++ ;
	if( s[2] == t[2]) c++ ;
	cout << c << endl ;

	return 0 ;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int x,y,i,t;
    for(i=1;i<=10000;i++){
        scanf("%d %d",&x,&y);
        if(x>y){
            t=x;
            x=y;
            y=t;
        }
        if(x==0 && y==0)
        break;
        printf("%d %d\n",x,y);
        x=0;
        y=0;
    }
return 0;
}


Measured memory_bytes: 2068
#include "bits/stdc++.h"
using namespace std;
#define PB push_back
#define MP make_pair
#define ALL(a)  (a).begin(),(a).end()
#define REP(i,n) for(int i=0;i<(n);i++)
int d[100][100];
int main(){
    int n,m;
    int a[1000],b[1000],c[1000];
    cin>>n>>m;
    REP(i,n)REP(j,n)d[i][j]=1e9;
    REP(i,n)d[i][i]=0;
    REP(i,m){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
        d[a[i]][b[i]]=d[b[i]][a[i]]=c[i];
    }
    REP(k,n)
        REP(i,n)
            REP(j,n)
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);

    int cnt=0;
    REP(i,m)if(d[a[i]][b[i]]<c[i])cnt++;
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

char s[20];

int main(){
	scanf("%s" , s);
	for(int i = 0 ; i < 12 ; ++i){
		printf("%c" , s[i]);
		if(i == 3) printf(" ");
	}
	printf("\n");
	return 0;
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define endl "\n";
#define p push_back
typedef long long ll;

int main()
{IOS
ll n,i,j,k=0,sum=0,count=0,f=0,d=0,z=0;
string s;
string q;
cin>>s;
cin>>q;
for(i=0;i<s.length();i++)
{if(s[i]!=q[i])
{count++;}}

cout<<count;




return 0;
}


Measured memory_bytes: 3832
import math

def main():
    a, b, angle = map(int, input().split())
    calc(a, b, angle)

def calc(a, b, angle):
    rad = math.radians(angle)
    S = a * b * math.sin(rad) / 2
    c = math.sqrt(math.pow(a, 2) + math.pow(b, 2) - (2 * a * b * math.cos(rad)))
    L = a + b + c
    h = S * 2 / a
    print(format(S, '.8f'))
    print(format(L, '.8f'))
    print(format(h, '.8f'))

if __name__ == '__main__':
    main()



Measured memory_bytes: 5720
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define INF 2147483647

int min(int a,int b){
    if(a<b){
        return a;
    }
    else{
        return b;
    }
}


int main(void){
    int n,k,i,val,val1,val2,val3;
    scanf("%d %d",&n,&k);
    int l_c = 0,r_c = 0,c_c=0;
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i] < 0){
            l_c++;
        }
        else if(a[i] > 0){
            r_c++;
        }
        else{
            c_c++;
        }
    }
    k = k-c_c;
    val = INF;
    if(k==0){
        printf("0\n");
    }
    else if(k==1){
        printf("%d\n", min(a[n-r_c],abs(a[l_c-1])));
    }
    else{
    for(i=1;i<=k;i++){
        if(r_c>=i && l_c>=k-i){
            val1 = a[n-r_c+i-1]*2 + abs(a[l_c-k+i]);
            val2 = abs(a[l_c-k+i])*2 + a[n-r_c+i-1];
            val1 = min(val1,val2);
            val = min(val,val1);
        }
    }
    if(k<=r_c){
        val2 = a[n-r_c+k-1];
    }
    else{
        val2 =INF;
    }
    if(k<=l_c){
        val3 = abs(a[l_c-k]);
    }
    else{
        val3 = INF;
    }
    val = min(min(val2,val3),val);
    printf("%d\n",val);

    }

    
    return 0;
}

Measured memory_bytes: 512
import java.util.*;
class Main{

     public static void main(String []args){
      Scanner scan = new Scanner(System.in);
      int m = scan.nextInt() ;
      int n = scan.nextInt() ;
       String s = scan.next();
      char arr[] = s.toCharArray();
      //for(int i = 0 ; i < m+n+1 ; i++){
       //   arr[i] = scan.next().charAt(0);
      //}
      int count = 0 ; 
      if(arr[m] == '-'){
          for(int i = 0 ; i<m+n+1 ; i++){
              if(i == m){
                  continue ;
              }
              if(arr[i]>='0' && arr[i]<='9'){
                  count++;
              }
          }
        	//System.out.println(count);
           if(count == m+n){
                System.out.println("Yes");
             }else{
            System.out.println("No");
             }
      
      }else{
          System.out.println("No");
      }   
    }
}

Measured memory_bytes: 22868