akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

int ans = 0,w,h;
string s[100];

void solve(int x,int y){

  if(s[x][y] == '#') return;
  s[x][y] = '#';
  ans++;

  if(x+1 < h) solve(x+1,y);
  if(y+1 < w) solve(x,y+1);
  if(x-1 >= 0) solve(x-1,y);
  if(y-1 >= 0) solve(x,y-1);
   
  return;
}


int main(){

  while(true){
    cin >> w >> h;
    if(!w && !h) break;

    ans = 0;

    for(int i=0;i<h;i++) cin >> s[i];

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(s[i][j] == '@') solve(i,j);
      }
    }

    cout << ans << endl;
  }
}

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

using namespace std;

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
}


Measured memory_bytes: 3132
import re, copy
import itertools
N= int(input())

pat='(AGC|ACG|GAC|AGAC|AGTC|AGCC|AAGC|ATGC|AGGC)'
repattern = re.compile(pat)

memo={}

for s in itertools.product('ATGC', repeat=3):
  if not repattern.search(''.join(s)):
  	memo[''.join(s)] = 1
  
for _ in range(3,N):
  new_memo={}
  for k,v in memo.items():
    for c in 'ATGC':
      if not repattern.search(k+c):
        new_memo[(k+c)[-3:]] = new_memo.get((k+c)[-3:],0)+v
  memo=new_memo

print(sum(memo.values())%(10**9+7))

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
 
int main(){
    int m, h;
    string str, str1, str2;
 
    while (1){
        cin >> str;
 
        if (str == "-") break;
 
        cin >> m;
 
        for (int i = 0; i < m; i++){
            cin >> h;
 
            str1 = str.substr(0, h);
            str2 = str.substr(h, str.size() - h);
 
            str = str2 + str1;
        }
 
        cout << str << endl;
 
    }
     
    return 0;
}


Measured memory_bytes: 3132
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc144_a.cpp
 * time   : Sat May  2 13:52:46 2020
 * quest  : A - 9x9
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << ((a < 10 && b < 10) ? a * b : -1) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector< int > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] %= M;
    }

    int tot = 0;
    map< int, int > count;
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        tot += A[i];
        tot %= M;

        ans += count[tot];
        if (tot == 0) ans++;
        count[tot]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
  int main()
  {

        string s;
        cin >> s;

     for (int i=0;i<s.size();i++)
     {
         if(s[i]!=',')
            cout << s[i];
         else
            cout << " ";

     }
     cout << "\n";

  }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int sum = 0;

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        for(int i=1;i<n-1;i++) {
            if ((a[i] > a[i-1] && a[i] < a[i+1]) || (a[i] > a[i+1] && a[i] < a[i-1])) {
                sum++;
            }
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 23764
use std::io::*;
use std::str::FromStr;
use std::cmp::{max, min};

fn read<T: FromStr> () -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_vec<T: std::str::FromStr> () -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let N: usize = read();
    let mut B: Vec<usize> = vec![0; N];

    for i in 1..N {
        B[i] = read();
    }

    let mut ans = B[1];
    for i in 1..N {
        ans += std::cmp::min(B[i-1], B[i]);
    }
    ans += B[N-1];
    println!("{}", ans);
}



Measured memory_bytes: 4352
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	int N;
	cin>>N;
	VI A(N);
	REP(i,N)cin>>A[i];
	rSORT(A);
	int sum=0;
	FOR(i,1,N)sum+=A[i];
	if(A[0]<sum)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int a,b;
int main(){
    cin >> a >> b;
    vector<int> c1(a);
    vector<int> c2(b);
    int dp[2][5001];
    memset(dp,0,sizeof(dp));
    REP(i,a){
	cin >> c1[i];
    }
    REP(i,b){
	cin >> c2[i];
    }
    int ans = 0;
    REP(i,b){
	REP(j,a){
	    if(c2[i] == c1[j]){
		dp[0][j+1] = dp[1][j] + 1;
	    }else{
		dp[0][j+1] = dp[0][j];
	    }
	    ans = max(ans,dp[0][j+1]);
	}
	swap(dp[0],dp[1]);
    }
    cout << ans << endl;
    return 0;
}

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

const int INF = 1e9 + 5;

// input
int N, W;
vector<ll> w, v;

vector<map<ll, ll>> m;


void input() {
    cin >> N >> W;
    w = v = vector<ll>(N);
    rep(i, N) cin >> w[i] >> v[i];
}


int main() {
    input();
    m = vector<map<ll, ll>>(N + 1);
    rep(k, N + 1) rep(i, k + 1) rep(j, 3 * i + 1) m[k][i * w[0] + j] = -INF;
    m[0][0] = 0;
    for (int i = 1; i <= N; i++) {
        rep(j, i + 1) rep(k, 3 * j + 1) {
            ll x = j * w[0] + k;
            if (W < x) continue;
            if (m[i - 1].count(x)) m[i][x] = m[i - 1][x];
            ll y = x - w[i - 1];
            if (m[i - 1].count(y)) m[i][x] = max(m[i][x], m[i - 1][y] + v[i - 1]);
        }
    }
    ll ans = 0;
    rep(i, N + 1) rep(j, 3 * i + 1) ans = max(ans, m[N][i * w[0] + j]);
    cout << ans << endl;
}


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

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

  vector<int> a(n);
  for (auto &i : a) cin >> i;

  int ans = 1;
  bool u = false, d = false;
  for (int i = 1; i < n; ++i) {
    if (a[i - 1] < a[i]) u = true;
    if (a[i - 1] > a[i]) d = true;
    if (u && d) {
      u = d = false;
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
long long int vp[60],len[60],sum=0;


int main()
{
    int n;long long int x;
    scanf("%d %lld",&n,&x);
    vp[1]=3;len[1]=5;vp[0]=3;
    for(int i=2;i<=n;i++)
    {
        vp[i]=vp[i-1]*2+1;
    }
    for(int i=2;i<=n;i++)
    {
        len[i]=len[i-1]*2+3;
    }
    while(x>0)
    {
        if(n==1)
        {
            if(x>=5)
            {
                sum+=3;
            }
            else
            {
                sum+=x-1;
            }
            break;
        }
        if(x>=(len[n]-1)/2+1)
            {x-=(len[n]-1)/2+1;
               sum+=vp[n-1]+1;
               n--;

            }
        else
        {
            x--;
            n--;

        }

    }
    printf("%lld",sum);

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main() {
  ll a,b,t,ans=1;
  cin>>a>>b;
  t=min(a,b);
  for(ll i=2;i*i<=t;i++){
    if(a%i==0 && b%i==0) ans++;
    if(a%i==0){
      for(;a%i==0;) a/=i;
    }
    if(b%i==0){
      for(;b%i==0;) b/=i;
    }
    if(a*b==1){
      cout<<ans;
      return 0;
    }
  }
  if(max(a,b)%min(a,b)==0 && min(a,b)!=1) ans++;
  cout<<ans;
}


Measured memory_bytes: 3496
def solve():
    from itertools import permutations
    n,m,R=map(int,input().split())
    r=map(int,input().split())
    d=[[10**18]*n for _ in range(n)]
    for i in range(m):
        a,b,c=map(int,input().split())
        d[a-1][b-1]=c
        d[b-1][a-1]=c
    for i in range(n):
        d[i][i]=0
    for k in range(n):
        for i in range(n):
            for j in range(n):
                t=d[i][k]+d[k][j]
                if t<d[i][j]:
                    d[i][j]=t
    m=10**18
    for e in permutations(r):
        t=0
        for i,j in zip(e,e[1:]):
            t+=d[i-1][j-1]
        if t<m:
            m=t
    print(m)
if __name__=='__main__':
    solve()

Measured memory_bytes: 4648
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long a,b;
    cin>>a>>b;
    if (b%2==1)
    {
    	cout<<"No"<<endl;
    	return 0;
	}
    if (b%a==0)
    {
    	a=b/a;
    	if (a==2 || a==3 || a==4)
    	{
    		cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	else
	{
		a=b/a;
		if (a==2 || a==3)
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
}

Measured memory_bytes: 3640
// <------------- Template -----------------------> //


#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(20);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAX5];

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, y, q, m, k;
string s, t, d;
ll sum = 0;
ll cou = 0;


// <------------- Implement Functions Here ----------> //

ll NCR(ll n, ll r) {
	if (n < r ) return 0;
	if (r == 0) return 1;
	if (r > n / 2) return NCR(n, n - r);
	ll res = 1;
	for (ll k = 1; k <= r; ++k) {
		res *= n - k + 1;
		res /= k;
	}
	return res;
}


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> x >> y;
	vll a(n);
	map<ll, ll> cnt;
	for (ll i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;
	sort(all(a));
	reverse(all(a));
	map<ll, ll> val;
	ld sum=0;
	for (ll i = 0; i < x; i++) val[a[i]]++, sum+=a[i];
	ll ans = 0;
	if(val.size()==1) {
		auto it = *val.begin();
		for(ll i=x;i<=y;i++) {
			ans += NCR(cnt[it.f],i); 
		}
	}
	else {
		ans = 1;
		for (auto it : val) {
			ans *= NCR(cnt[it.f],it.s);
		}
	}
	cout<<(ld)sum/(ld)x;newl;
	cout<<ans;
}

int main() {
	fastio; randomINT;
	//cin>>T;
	while (T--) {
		MAIN();
	}
	return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int A, B;
signed main() {
    cin >> A >> B;
    if (A >= 13) { cout << B << endl; }
    else if (A >= 6) { cout << B / 2 << endl; }
    else { cout << 0 << endl; }
}

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

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

	string ret = "No";
	if(N.find("9") != string::npos)
		ret = "Yes";

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
import math

k=int(input())

ans=0

for l in range(1,k+1):
  for m in range(1,k+1):
    tmp=math.gcd(l,m)
    for n in range(1,k+1):
      gcd=math.gcd(tmp,n)
      ans+=gcd
      
print(ans)

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

int main() {
  int x,y;
  string s;
  cin >> s;
  x = s.size();
  for(int i=2;i<x;i+=2){
    int count = 0;
    y = (x-i)/2;
    for(int j=0;j<y;j++){
      if(s.at(j) == s.at(y+j)){
        count++;
      }
      else {
        break;
      }
    }
    if(count == y){
      cout << x - i << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int mo = 1e9+7,ma=2e5+10;
int n;
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n;
    vector<int> x(n),y(n);
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
        y[i]=x[i];
    }
    sort(begin(y),end(y));
    rep(i,n)
    {
        if(x[i]>=y[n/2])printf("%d\n",y[n/2-1]);
        else printf("%d\n",y[n/2]);
    }
    return 0;
}

Measured memory_bytes: 3840
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
    if A[i-1] + A[i] > x:
        sub = (A[i-1] + A[i]) - x
        if A[i] < sub:
            sub = sub - A[i]
            ans += A[i]
            A[i] = 0
            A[i-1] -= sub
        else:
            A[i] -= sub
        ans += sub
print(ans)


Measured memory_bytes: 14252
n=int(input())
a_list=list(map(int,input().split()))
a_list.sort()
M=a_list[n-1]
m=a_list[0]
d=M/2-m
for i in a_list[:n-1]:
    if abs(M/2-i)<d:
        d=abs(M/2-i)
        m=i
print(M)
print(m)


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

const int N = 50000000;

int main(){
    int k;
    scanf("%d", &k);
    bool f = false;
    int res = 0;
    for (int i = 1; i <= N; ++i){
        res = (res * 10 + 7) % k;
        if (res == 0){
            printf("%d\n", i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 3820
#include <cstdio>

int digsum(int n) {
  int res = 0;
  for (; n; n /= 10) res += n % 10;
  return res;
}

int main() {
  int N, A, B;
  scanf("%d %d %d", &N, &A, &B);

  int res = 0;
  for (int i = 1; i <= N; ++i) {
    int ds = digsum(i);
    if (A <= ds && ds <= B) res += i;
  }

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

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

using namespace std;

double a[55];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%lf", a + i);
	}
	sort(a, a + n);
	double ans = a[0];
	for (int i = 1; i < n; i++){
		ans = (ans + a[i]) / 2.0;
	}
	printf("%.5lf\n", ans);
	return 0;
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int n;cin>>n;
  string str[n];
  int ans=0,ans2=0,ans3=0;
  vector<pair<char,char> >vcc;
  for(int i=0;i<n;i++)cin>>str[i];
  for(int a=0;a<n;a++){
    bool flag2=true;
    for(int i=a;i<a+n;i++){
      for(int j=0;j<n;j++){
	if(str[i%n][j%n]!=str[(j+a)%n][(i-a)%n]){
	  flag2=false;
	}
      }
      if(flag2==false)break;
    }
    if(flag2)ans++;
  }
  for(int a=0;a<n;a++){
    bool flag2=true;
    for(int i=a;i<a+n;i++){
      for(int j=a;j<n+a;j++){
	if(str[i%n][j%n]!=str[j%n][i%n]){
	  flag2=false;
	}
      }
      if(flag2==false)break;
    }
    if(flag2)ans2++;
  }
  for(int a=0;a<n;a++){
    bool flag2=true;
    for(int i=0;i<n;i++){
      for(int j=a;j<a+n;j++){
	if(str[i%n][j%n]!=str[(j-a)%n][(i+a)%n]){
	  flag2=false;
	}
      }
      if(flag2==false)break;
    }
    if(flag2)ans3++;
  }
  int anss=max(ans,ans2);
  anss=max(ans,ans3);
  cout<<anss*n<<endl;
  return 0;
}


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

map<long long ,long long> mp;
const int maxn = 2e5;

int n,m;
long long a[maxn];
long long pre[maxn];
long long cnt[maxn];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		pre[i] = pre[i-1]+a[i];
	}
	long long ans=0;
	for(int i=1; i<=n; i++){
		ans += mp[pre[i]%m];
		//cout<<pre[i]%m<<endl;
		//ans += cnt[ pre[i]%m ];
		if( pre[i]%m==0 )
			ans++;
		mp[ pre[i]%m ]++;
		//cnt[ pre[i]%m ]++;
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 6784
N,K = map(int,input().split())
A = list(map(int,input().split()))
X = dict()
for i in A:
    if i in X:
        X[i] += 1
    else:
        X[i] = 1
Y = [] 
for i in X.keys():
    Y.append(X[i])
Y.sort()
#print(Y)
if len(Y) <= K:
    ans = 0
else:
    ans = sum(Y[:len(Y)-K])
print(ans)

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

int main() {
	long long N;
	cin >> N;
	long long memo = -1;
	for (long long i = 0; i <= N; ++i) {
		if (((i + 1)*i / 2) == N) {
			memo = i;
			break;
		}
	}
	if (-1 == memo) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	cout << memo + 1 << endl;
	vector<vector<int>> Ans(memo + 1);
	for (int i = 0; i < memo + 1; ++i) {
		Ans[i].push_back(memo);
	}
	int l = 0;
	int r = 0;
	for (int i = 0; i < N; ++i) {
		r++;
		if (r == (memo + 1)) {
			l++;
			r = l + 1;
		}
		Ans[l].push_back(i + 1);
		Ans[r].push_back(i + 1);
	}
	for (int i = 0; i < memo + 1; ++i) {
		cout << Ans[i][0];
		for (int j = 0; j < memo; ++j) {
			cout << " " << Ans[i][j + 1];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 4124
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
 int n,m;
 cin>>n>>m;
V<int> g[n];
for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    g[a-1].push_back(b-1);
    g[b-1].push_back(a-1);
}
queue<P> q;
q.emplace(0,0);
V<ll> d(n,-1);
d[0]=0;
while(q.size()){
    int now=q.front().fi,bfo=q.front().se;
    q.pop();
    for(int v:g[now]){
        if(d[v]!=-1)continue;
        else{
            d[v]=now+1;
            q.emplace(v,now);
        }
    }
}
for(int i=0;i<n;i++)if(d[i]==-1){
    cout<<"No"<<"\n";
    return 0;
}
cout<<"Yes"<<"\n";
for(int i=1;i<n;i++){
    cout<<d[i]<<"\n";
}
}


Measured memory_bytes: 11580
ord_A,ord_a=ord('A'),ord('a')
Sss=[input() for _ in range(3)]
iSs=[-1]*3
turn=0
while True:
    iSs[turn]+=1
    if iSs[turn]==len(Sss[turn]):
        print(chr(turn+ord_A))
        break
    turn=ord(Sss[turn][iSs[turn]])-ord_a


Measured memory_bytes: 3060
a, b, c = map(int, input().split())

m = max(a, b, c)
if (a+b+c) % 2 == 3*m % 2:
    print((3*m - (a+b+c)) // 2)
else:
    print((3*(m+1) - (a+b+c)) // 2)


Measured memory_bytes: 9056
# -*- coding: utf-8 -*-
"""
Created on Sun Sep  2 16:39:28 2018
ABC057B
@author: maezawa
"""

n, m = list(map(int, input().split()))

sx = []
sy = []
cx = []
cy = []

for i in range(n):
    sxi, syi = list(map(int, input().split()))
    sx.append(sxi)
    sy.append(syi)
    
for i in range(m):
    cxi, cyi = list(map(int, input().split()))
    cx.append(cxi)
    cy.append(cyi)

for i in range(n):
    l = 10**9
    nj = 0
    for j in range(m):
        lj = abs(sx[i]-cx[j])+abs(sy[i]-cy[j])
        if l > lj:
            l = lj
            nj = j
            #print('({},{}), ({}, {})'.format(sx[i],sy[i],cx[j],cy[j]))
    print(nj+1)
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

long long gcd(long long a, long long b){return (b == 0)? a : gcd(b, a % b);}

long long powmod(long long a, long long x){
    if(x == 0)return 1;
    long long r = powmod(a, x / 2);
    return (x%2)? (r * r % MOD) * a % MOD : r * r % MOD;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n; cin >> n;
	
	map<P, P> mp;
	ll cntz = 0;
	zep(i, 0, n){
		ll a, b; cin >> a >> b;
		if(a == 0 && b == 0){cntz++; continue;}
		
		if(a == 0){
			if(mp.find(P(0, 1)) == mp.end())mp[P(0, 1)] = P(0, 0);
			mp[P(0, 1)] = P(mp[P(0, 1)].first+1, mp[P(0, 1)].second);
		}
		else if(b == 0){
			if(mp.find(P(0, 1)) == mp.end())mp[P(0, 1)] = P(0, 0);
			mp[P(0, 1)] = P(mp[P(0, 1)].first, mp[P(0, 1)].second+1);
		}
		else{
			if(b < 0){a *= -1; b *= -1;}
			
			ll g = gcd(abs(a), abs(b));
			a /= g;
			b /= g;
			
			if(a > 0){
				if(mp.find(P(a, b)) == mp.end())mp[P(a, b)] = P(0, 0);
				mp[P(a, b)] = P(mp[P(a, b)].first+1, mp[P(a, b)].second);
			}
			else{
				ll tmp = a; a = b; b = -tmp;
				if(mp.find(P(a, b)) == mp.end())mp[P(a, b)] = P(0, 0);
				mp[P(a, b)] = P(mp[P(a, b)].first, mp[P(a, b)].second+1);
			}
		}
	}

	ll ans = 1;
	for(auto it = mp.begin(); it != mp.end(); it++){
		auto p = (*it).second;
		ll l = p.first;
		ll r = p.second;
		
		ans *= ((powmod(2, l) + powmod(2, r))%MOD + MOD - 1)%MOD;
		ans %= MOD;
	}
	print((ans+cntz+MOD-1)%MOD)
	return 0;
}

Measured memory_bytes: 19248
// https://atcoder.jp/contests/abc123/tasks/abc123_b
#include <bits/stdc++.h>
using namespace std;

int main(void){
  int time[5] = {0};
  for (int i = 0; i < 5; i++)  cin >> time[i];

  int min_mod = 10;
  for (int i = 0; i < 5; i++)
    if (time[i] % 10 != 0)
      min_mod = min(time[i] % 10, min_mod);  // 最小の余りを保存

  int sum = 0;
  for (int i = 0; i < 5; i++){
    sum += (time[i] + 9) / 10 * 10;
  }
  cout << sum -(10 -min_mod) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>


main()
{
int h,w;
while(1){
	scanf("%d %d",&h,&w);
	if((h|w)==0)break;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			printf("%c",j==0||j==w-1||i==0||i==h-1?'#':'.');
		}
		printf("\n");
	}
	printf("\n");
}
}


Measured memory_bytes: 2584
#include<iostream>
#include<vector>

int insertSort( int data[], int dataNum, int gap ) {
    int cnt = 0;
    for( int i = gap; i < dataNum; i++ ) {
        int edgeVal = data[i];
        int cur = i;
        while( cur - gap >= 0 && data[cur - gap] > edgeVal ) {
            data[cur] = data[cur-gap];
            cur = cur - gap;
            cnt++;
        }
        data[cur] = edgeVal;
    }

    return cnt;
}

std::vector<int> getGaps( int dataNum ) {
    std::vector<int> ret;
    int i = 1;
    while( true ) {
        if( i > dataNum ) {
            break;
        }
        ret.push_back(i);
        i = 3*i + 1;
    }
    return ret;
}

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

    int data[N];
    for( int i = 0; i < N; i++ ) {
        std::cin >> data[i];
    }
    // int N = 10;
    // int data[] = {15,12,8,9,3,2,7,2,11,1};
    std::vector<int> gaps = getGaps(N);

    // Output:1列目
    std::cout << gaps.size() << std::endl;

    // Output:2列目
    for( int i = gaps.size() -1; i >= 0; i-- ) {
        if( i != gaps.size() -1 ) {
            std::cout << " ";
        }
        std::cout << gaps[i];
    }
    std::cout << std::endl;

    // shell sort
    int insCnt = 0;
    for( int i = gaps.size() -1; i >= 0; i-- ) {
        insCnt = insCnt + insertSort(data,N,gaps[i]);
    }
    // Output:3列目
    std::cout << insCnt;
    std::cout << std::endl;

    // Output:4列目
    for(int i = 0; i < sizeof(data)/sizeof(int);i++) {
        std::cout << data[i] << std::endl;
    }
    std::cout << std::endl;
}

// int main() {
//     int N;
//     std::cin >> N;

//     int data[N];
//     for( int i = 0; i < N; i++ ) {
//         std::cin >> data[i];
//     }
// }


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

long long gcd(long long a, long long b) {
    while (b != 0) {
        auto t = b;
        b = a % b;
        a = t;
    }
    return a;
}

int main() {
    int t;
    cin >> t;
    for (long long a, b, c, d; cin >> a >> b >> c >> d; ) {
        if (a < b || d < b) {
            cout << "No\n";
        } else {
            long long g = gcd(b, d);
            auto k = c / g * g + a % g;
            if (k <= c) {
                k += g;
            }
            if (k >= b) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)

#define SZ(x)  (ll)(x.size())
/*
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second*/
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{

    ll n,q,v,sum=0,i,temp,a,b;

    cin>>n;

    map<ll,ll> m;


    for(i=1;i<=n;++i)
    {
        cin>>v;
        ++m[v];
        sum+=v;
    }

    cin>>q;

    while(q--)
    {
        cin>>a>>b;

        sum -= a*m[a];

        sum -= b*m[b];


        m[b] += m[a];
        m[a] = 0;


        sum += b*m[b];
      

        cout<<sum<<"\n";

    }




    return 0;
}

Measured memory_bytes: 9432
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut iter = s.split_whitespace();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();
    if a<b && b<c {
        println!("Yes")
    } else {
        println!("No")
    }
}



Measured memory_bytes: 5032
def main():
    n = int(input())
    inlis = []
    for _ in range(n):
        a = int(input())
        inlis.append(a)
    saidai = max(inlis)
    kosuu = inlis.count(saidai)
    inlis2 = sorted(inlis)
    saidai2 = inlis2[-2]
    for i in range(n):
        if inlis[i] != saidai:
            print(saidai)
        else:
            print(saidai2)

if __name__ == "__main__":
    main()


Measured memory_bytes: 19072
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.begin(), a.end())
using namespace std;
#define m 1000000007

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

    int h, w, H, W;
    cin>>H>>W>>h>>w;
    cout<<H*W-(h*W + w*H - h*w)<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  lvector ER(n,0),WL(n,0);
  string s;cin>>s;
  rep(i,n-1) WL[i+1]+=WL[i]+(s[i]=='W');
  rep(i,n-1) ER[n-1-(i+1)]+=ER[n-1-i]+(s[n-1-i]=='E');
  ll ans=1e9;
  rep(i,n) ans=min(ans,WL[i]+ER[i]);
  print(ans);
  return 0;
}

Measured memory_bytes: 5456
#include<iostream>
#include<string>
using namespace std;
int main(){
	string str;
	int j=1,k=2,joi=0,ioi=0;
	while(cin>>str){
		for(int i=0;i<str.size()-2;i++){
			if(str[i]=='J' && str[i+1]=='O' && str[i+2]=='I'){
				joi++;
			}
			if(str[i]=='I' && str[i+1]=='O' && str[i+2]=='I'){
				ioi++;
			}
		}
		cout<<joi<<endl<<ioi<<endl;
		joi=0;
		ioi=0;


	}


	return 0;
}

Measured memory_bytes: 3072
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int i = 0;
        while(true){
            if((int)Math.pow(B,i)<=A && (int)Math.pow(B,i+1)>A){
                System.out.println(i+1);
                break;
            }
            i++;
        }
    }
}


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

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

typedef tuple<int, int, int> T;

inline ostream& operator<<(ostream& o, const T& v)
{
  return o << get<0>(v) << "," << get<1>(v) << "," << get<2>(v);
}

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("e.1", "r", stdin);

  int N, M;
  cin >> N >> M;
  vector<vector<int>> to = vector<vector<int>>(N + 1, vector<int>());
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    to[u].push_back(v);
  }
  int s, t;
  cin >> s >> t;
  const int SZ = N + 1;
  vector<int> visited = vector<int>(SZ * 3, -1);
  queue<T> q;
  q.push(T(s, 2, 0));
  while (!q.empty()) {
    int v, c, cnt;
    tie(v, c, cnt) = q.front();
    dumpv(v, c, cnt, visited);
    q.pop();
    if (visited[v + SZ * c] != -1)
      continue;
    visited[v + SZ * c] = cnt;
    for (int u : to[v]) {
      if (c == 2)
        q.push(T(u, 0, cnt + 1));
      else
        q.push(T(u, c + 1, cnt));
    }
  }
  cout << visited[t + SZ * 2] << endl;
  return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

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

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


int main() {
  ll N;

  cin>>N;
  ll a[N+1];
  ll ans =0;
  FOR(i,0,N-1){
    cin>>a[i];
  }
  a[N]=-1;

  sort(a,a+N);
  FOR(i,0,N-1){
    if(a[i]!=a[i+1]){
      ans++;
    }else{
      i++;
    }
  }





  cout<<ans<<endl;
  return 0;


 
}
 


Measured memory_bytes: 1024
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin >> s;
    int n = SZ(s);
    string res;
    int ans = 0;
    for(int i = 0, len = 1; i < n - 1; i++, len++){
        if(i & 1){
            int mid = i / 2;
            if(s.substr(0, len / 2) == s.substr(mid + 1, len / 2)){
                if(len > ans){
                    ans = len;
                    res = s.substr(0, len);
                }
            }
        }
    }
    cout << SZ(res);
    return 0;
}
/*
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 256
import math
a,b,h,m = map(int,input().split())
if m==0 and h==0:
	print(a-b)
elif m==0 and h==6:
	print(a+b)
else:
	p=math.pi/2
	x_a= a*math.cos(p-m*2*math.pi/60)
	y_a = a*math.sin(p-m*2*math.pi/60)
	x_b= b*math.cos(p-(h+m/60)*2*math.pi/12)
	y_b = b*math.sin(p-(h+m/60)*2*math.pi/12)
	L = math.sqrt((x_a-x_b)**2+(y_a-y_b)**2)
	print(L)

Measured memory_bytes: 9592
def resolve():
    '''
    code here
    '''
    import collections
    S = [item for item in input()]
    T = [item for item in input()]

    S_cnt = collections.Counter(S)
    T_cnt = collections.Counter(T)


    if sorted(S_cnt.values()) == sorted(T_cnt.values()):
            print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 12408
from _collections import deque
import sys

N,M = map(int,input().split())
T = [ [] for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)
used_1 = [0]*N
used_2 = [0]*N
ans = [0]*N

P = deque([0])
while(len(P)>0):
    c = P.popleft()
    if used_1[c] == 0:
        used_1[c] = 1
        used_2[c] = 1
        for i in T[c]:
            if used_2[i] == 0:
                ans[i] = c+1
                used_2[i] = 1
                P.append(i)
for i in range(N):
    if used_2[i] == 0:
        print("No")
        sys.exit()

print("Yes")
for i in range(1,N):
    print(ans[i])

Measured memory_bytes: 96796
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int mapp[100005];
bool vis[100005];
int flag, num;
int dfs(int i)
{
    if(flag)
    {
        return num;
    }
    vis[i] = 1;
    if(i == 2)
    {
        flag = 1;
        return num;
    }
    ++num;
    if(vis[mapp[i]])
    {
        flag = -1;
        num = -1;
    }
    dfs(mapp[i]);
}
int main()
{
    memset(mapp, 0, sizeof(mapp));
    memset(vis, 0, sizeof(vis));
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
    {
        scanf("%d", &mapp[i]);
    }
    flag = 0;
    num = 0;
    cout << dfs(1) << endl;
    return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), a + n
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MOD(x) ((x) % (1e9 + 7))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const double EPS = 1e-10;
const double PI = acos(-1.0);

inline int to_int(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

inline double vol(double rad, double a, double b) {
	if(a * tan(rad) < b) {
		return (a * a * b) - (a * a * a * tan(rad) / 2.0);
	} else {
		return a * b * b / tan(rad) / 2.0;
	}
}

inline double to_degree(double rad) {
	return rad / PI * 180.0;
}

int main() {
	double a, b, x;
	scanf("%lf %lf %lf", &a, &b, &x);
	double l, r, m;
	l = 0.0;
	r = PI / 2.0;
	int count = 0;
	while(count < 1000000) {
		m = (r + l) / 2.0;
		if(vol(m, a, b) < x) {
			r = m;
		} else {
			l = m;
		}
		count++;
	}
	printf("%.10f\n", to_degree(r));
	return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;


#include <queue>
#include <vector>
#include <functional>
#include <utility>
#include <algorithm>
#include <iterator>

using COST_T = uint32_t;
constexpr uint32_t N_MAX = 50;
constexpr COST_T INF = 10000;//std::numeric_limits<double>::infinity()

#if defined(_MSC_VER) && defined(_DEBUG)
//static_assert(false, "リリースでコンパイルしないと遅いよ！！");
#endif

struct edge {
	uint32_t to;
	COST_T cost;
	edge() {}
	edge(uint32_t to_, COST_T cost_=1)
		:to(to_), cost(cost_) {}
};
std::vector<edge> graph[N_MAX];

//ダイクストラ
COST_T D[N_MAX];
void Dijkstra(uint32_t s)
{
	using P = std::pair<COST_T, uint32_t>;//cost pos
	std::priority_queue<P, std::vector<P>, std::greater<>> que;
	std::fill(std::begin(D), std::end(D), INF);

	D[s] = 0;
	que.emplace(0, s);
	while (!que.empty())
	{
		auto p = que.top(); que.pop();
		const auto& nowpos = p.second;
		const auto& nowcost = p.first;
		if (D[nowpos] < nowcost) { continue; }

		//for (int32_t to = 0; to < N; ++to)
		//{
		//	auto cost = nowcost + graph[nowpos][to];
		//	if (cost < D[to]) {
		//		D[to] = cost;
		//		que.emplace(D[to], to);
		//	}
		//}

		for (const auto& e : graph[nowpos])
		{
			auto cost = nowcost + e.cost;
			if (cost < D[e.to]) {
				D[e.to] = cost;
				que.emplace(cost, e.to);
			}
		}

	}
}

int32_t N,M;
int32_t G[51][2];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M;
	for (int32_t i = 0; i < M; i++)
	{
		int a, b;
		in >> a>> b; --a;--b;
		G[i][0] = a;
		G[i][1] = b;
	}
	int32_t ans = 0;
	for (int32_t i = 0; i < M; i++)
	{
		for (auto& j : graph)
		{
			j.clear();
		}
		for (int32_t j = 0; j < M; j++)
		{
			if (i == j) {
				continue;
			}
			int a = G[j][0];
			int b = G[j][1];
			graph[a].emplace_back(b);
			graph[b].emplace_back(a);
		}
		Dijkstra(0);
		for (int32_t j = 0; j < N; j++)
		{
			if (D[j] == INF) {
				++ans;
				break;
			}
		}
	}
	out << ans << endl;
	return 0;
}
#endif


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};


//-----------------------------------------------------------------------------

int n,mi=INF;

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

	int n;cin>>n;
	REP(i,n) {
		int a;cin>>a;
		int cnt=0;
		while(a%2==0&&a>0) cnt++,a/=2;
		mi=min(mi,cnt);
	}
	cout<<mi<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n,four=0,two=0,j=0;
    scanf("%d",&n);

    int a[n];

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

    for(int i=0;i<n;i++)
    {
        if(a[i]%4==0)
          four++;
        else if(a[i]%2==0)
           two++;
        else j++;
    }

    if(four<j-1)
    {
        printf("No");
        return 0;
    }
    else if((four==j-1)&&two!=0)
     {
         printf("No");
         return 0;
     }
     else
     {
         printf("Yes");
     }
     return 0;

}


Measured memory_bytes: 512
n = STDIN.gets.chomp.to_i

tmp = 0
exist = {}
STDIN.gets.chomp.split(" ").each do |a|
  if exist.fetch(a, nil)
    tmp += 1
  else
    exist[a] = true
  end
end
if tmp % 2 == 0
  puts n - tmp
else
  puts n - tmp - 1
end

Measured memory_bytes: 18820
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();

        int n = nextInt();
        boolean contains = false;
        while (n > 0) {
            int rem = n % 10;
            contains = contains || rem == 7;
            n /= 10;
        }

        System.out.println(contains ? "Yes" : "No");
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


Measured memory_bytes: 32740
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;

int n,m,i,j,k,tmp;
bool s[10][10]={};
bool p[10];
int cnt;

void check(int depth,bool t[]){
  if(depth==m){

    int b[10]={},i,j;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
        if(t[j]){
          if(s[i][j]){
            b[i]++;
          }
        }
      }
    }
    for(i=0;i<n;i++){
      if(b[i]%2!=p[i])return;
    }
    cnt++;
    return;
  }
  else{
    bool n[10];
    for(int i=0;i<m;i++){
      n[i]=t[i];
    }
    check(depth+1,n);
    n[depth]=1;
    check(depth+1,n);
  }
}

int main(void){

  cin>>m>>n;
  for(i=0;i<n;i++){
    cin>>k;
    for(j=0;j<k;j++){
      cin>>tmp;
      s[i][tmp-1]=1;
    }
  }
  for(i=0;i<n;i++){
    cin>>p[i];
  }

  bool t[10]={};
  check(0,t);

  cout<<cnt<<endl;

	return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    rep(i, N) { cin >> x[i]; }

    int sum = 0;
    for (int i = 0; i < N;i++){
        sum += min(x[i], K - x[i]);
    }
    cout << sum * 2;
}

Measured memory_bytes: 256
from collections import deque
S = input()
Q = int(input())
pre = deque()
suf = deque()
rev = False
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        rev = not rev
    else:
        if (not rev and q[1] == '1') or (rev and q[1] == '2'):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if rev:
    S = S[::-1]
    p = list(suf)[::-1]
    s = list(pre)[::-1]
else:
    p = list(pre)
    s = list(suf)
print(''.join(p) + S + ''.join(s))


Measured memory_bytes: 7540