akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self,size):
        self.parent=range(size)
        self.tree_num=size
        self.tree_w=[1]*size
        self.rank=[0]*size

    def findset(self,x):
        if self.parent[x]==x:
            return x
        else:
            self.parent[x]=self.findset(self.parent[x])
            return self.parent[x]

    def unite(self,x,y):
        x=self.findset(x)
        y=self.findset(y)
        if x==y:
            return
        if self.rank[x]<self.rank[y]:
            self.parent[x]=y
            self.tree_num-=1
            self.tree_w[y]+=self.tree_w[x]
        else:
            self.parent[y]=x
            self.tree_num-=1
            self.tree_w[x]+=self.tree_w[y]
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def same(self,x,y):
        if self.findset(x)==self.findset(y):
            return True
        else:
            return False

    def tree_number(self):
        return self.tree_num

    def tree_weight(self,x):
        return self.tree_w[self.findset(x)]

n,m=map(int,raw_input().split())
p=[map(int,raw_input().split()) for _ in xrange(n)]
g=[[] for _ in xrange(m)]
for i in xrange(n):
    for j in p[i][1:]:
        g[j-1].append(i)
uf=UnionFind(n)
for i in xrange(m):
    for j in xrange(len(g[i])):
        uf.unite(g[i][0],g[i][j])
if uf.tree_number()==1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 31912
/*
      author : nishi5451
      created: 11.08.2020 23:18:45
*/

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


int main(){
    int a,b;
    cin >> a >> b;
    cout << a*b << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <stdio.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
// O(log N)　keyのある場所を返す。なかったら-1を返す
int search(int key, vector<int> a){
  int right = a.size();
  int left = 0;
  while(right >= left){
    int middle = left + (right - left) / 2;
    if(a[middle] == key) return middle; //keyが入ってる場所を返す
    else if(a[middle] > key) right = middle - 1;
    else if(a[middle] < key) left = middle + 1;
  }
  //なければ-1を返す
  return -1;
}
// O(N^2) babble sort
int main(){
  char w,x,y,z;
  cin >> w >> x >> y >> z;
  int a = int(w - '0');
  int b = int(x - '0');
  int c = int(y - '0');
  int d = int(z - '0');
  for(int i = -1; i < 2; i += 2){
    for(int j = -1; j < 2; j += 2){
      for(int k = -1; k < 2; k += 2){
        if(a + b*i + c*j + d*k == 7){
          cout << a;
          if(i == 1){
            cout << "+" << b;
          }else{
            cout << "-" << b;
          }
          if(j == 1){
            cout << "+" << c;
          }else{
            cout << "-" << c;
          }
          if(k == 1){
            cout << "+" << d;
          }else{
            cout << "-" << d;
          }
          cout << "=7" << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}

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

int main(){
    int num[10];
    num[1] = 2, num[2] = 5, num[3] = 5, num[4] = 4, num[5] = 5;
    num[6] = 6, num[7] = 3, num[8] = 7, num[9] = 6;
    int N, M;
    cin >> N >> M;
    int A[M];
    rep(i, M){
        cin >> A[i];
    }
    long long dp[N+1];
    dp[0] = 0;
    rep2(i, 1, N+1){
        long long ans = -10000000000;
        rep(j, M){
            int k = i - num[A[j]];
            if(k >= 0){
                ans = max(ans, dp[k]+1);
            }
        }
        dp[i] = ans;
    }
    sort(A, A+M, greater<int>());
    long long n = dp[N];
    long long x = N;
    int res[n];
    while(n > 0){
        rep(i, M){
            if(dp[x-num[A[i]]] == n-1){
                x -= num[A[i]];
                n--;
                res[n] = A[i];
                break;
            }
        }
    }
    for(int i = dp[N]-1; i >= 0; i--){
        cout << res[i];
    }
}

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

int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>>vec(h,vector<char>(w));
    vector<vector<int>>vek(h,vector<int>(w,0));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>vec[i][j];
            if(vec[i][j]=='#'){
                if(i!=0){
                    vek[i-1][j]++;
                    if(j!=0){
                        vek[i-1][j-1]++;
                    }
                    if(j!=w-1){
                        vek[i-1][j+1]++;
                    }
                }
                if(i!=h-1){
                    vek[i+1][j]++;
                    if(j!=0){
                        vek[i+1][j-1]++;
                    }
                    if(j!=w-1){
                        vek[i+1][j+1]++;
                    }
                }
                if(j!=0){
                    vek[i][j-1]++;
                }
                if(j!=w-1){
                    vek[i][j+1]++;
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(vec[i][j]=='#'){
                cout<<'#';
            }
            else{
                cout<<vek[i][j];
            }
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
N,A,B = map(int, input().split())
roop = N//(A+B)
remainder = N % (A+B) 

if A==0:
  print(0)
elif A>=N:
  print(N)
elif N>A and N<=A+B:
  print(A)
elif N>A and N>A+B and A>=remainder:
  out = roop * A + remainder
  print(out)
elif N>A and N>A+B and A<remainder:
  out = roop * A + A
  print(out)
  

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

char a, b, c, d;
int main(){
    scanf(" %c%c%c%c", &a, &b, &c, &d);
    if((a==b&&c==d&&c!=a)||(a==c&&b==d&&c!=d)||(a==d&&c==b&&c!=a))cout<<"Yes";
    else cout<<"No";

    cout<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()

int
main(int argc, char** argv)
{
	int x;
	int b;

	while (scanf("%d", &x) != EOF)
	{
		b = 1;
		while (x != 0)
		{
			if ((x & 1) != 0)
				printf("%d%c", b, x != 1 ? ' ' : '\n');

			x >>= 1;
			b <<= 1;
		}
	}

	return 0;
}

Measured memory_bytes: 596
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        var tmp = ReadIntArray();
        int n = tmp[0], i = tmp[1];
        WriteLine(n-i+1);
    }
}


Measured memory_bytes: 13268
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var h = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var dp = new int[nk[0]];

            dp[0] = 0;
            dp[1] = Abs(h[1] - h[0]);

            for (int i = 2; i < dp.Count(); i++)
            {
                int cmin = int.MaxValue;
                for (int j = i - 1; j >= 0 && (i - j) <= nk[1]; j--)
                {
                    cmin = Min(dp[j] + Abs(h[i] - h[j]), cmin);
                }
                dp[i] = cmin;
            }

            Console.WriteLine(dp.Last());

        }
    }
}


Measured memory_bytes: 20192
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      int D, G;
      cin >> D >> G;
      vector<int> quiz (D);
      vector<int> comp (D);
      for(int i = 0;i < D;i++){
          cin >> quiz.at(i) >> comp.at(i);
      }
      int ans = INF;
      for(int i = 0;i < pow(2,D);i++){
          bitset<10> bs (i);
          int score = 0;
          int solve = 0;
          int maxscorequiz = -1;
          for(int j = 0;j < D;j++){
              if(bs[j] == true){
//                  cout << j << " solve ";
                  score += comp[j] + quiz[j] * (j+1) * 100;
                  solve += quiz[j];
//                  cout << quiz[j] << " ";
              }
              else{
//                  cout << j << " dont solve ";
                  maxscorequiz = j;
              }
          }
//          cout << "score = " << score << " maxscorequiz = " << maxscorequiz << " ";
          if(score < G && maxscorequiz != -1){
              solve += ((G-score)+(maxscorequiz+1)*100-1)/((maxscorequiz+1)*100);
//              cout << "solve += " << ((G-score)+(maxscorequiz+1)*100-1)/((maxscorequiz+1)*100);
              if(((G-score)+(maxscorequiz+1)*100-1)/((maxscorequiz+1)*100) >= quiz.at(maxscorequiz)){
//                  cout << " cannot complete +solve = " << ((G-score)+(maxscorequiz+1)*100-1)/((maxscorequiz+1)*100) << endl;
                  continue;
              }
          }
          ans = min(solve,ans);
//          cout << " can solve " << solve << endl;
      }
      cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
int main(){
	long int n,m;
	cin>>n>>m;
	long int ans=0;
	if(m>=n*2){
		m-=(n*2);
		ans+=n;
		ans+=(m/4);
	}
	else{
		ans+=(m/2);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
def solve(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2):
	if xb2<xa1 or xb1>xa2 or yb2<ya1 or yb1>ya2:
		print("NO")
	else:
		print("YES")


while True:
	try:
		xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2=map(float,input().split())
		solve(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2)
	except EOFError:
		break

Measured memory_bytes: 7484
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1e9+7;

int h,w,a,b;
long long ret;
int fac[maxn];

void exgcd(int a, int b, int &g, int &x, int &y) {
	if (b == 0) g = a, x = 1, y = 0;
	else exgcd(b,a%b,g,y,x), y -= a/b*x;
}

int inv(int a) {
	int g,x,y;
	exgcd(a, mod, g, x, y);
	return (x+mod) % mod;
}

int C(int n,int m) {
	return (long long)fac[n] * inv(fac[m]) % mod * inv(fac[n-m]) % mod;
}

int f(int n, int m) {
	return C(n+m-2, n-1);
}

int main() {
	fac[0] = 1;
	for (int i = 1; i <= maxn; i++) fac[i] = (long long)fac[i-1]*i%mod;
	scanf("%d%d%d%d",&h,&w,&a,&b);
	for (int i = 1; i <= h-a; i++) {
		ret = (ret + (long long)f(i,b) * f(h-i+1,w-b))%mod;
	}
	printf("%d\n",ret);
	return 0;
}

Measured memory_bytes: 4576
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define ll long long

using namespace std;


const ll mod = 998244353;
const int MAXN = 305;
ll dp[MAXN][MAXN][MAXN];
ll S1[MAXN][MAXN][MAXN];
ll S2[MAXN][MAXN][MAXN];

int main() {
	string s;
	cin >> s;
	int k;
	cin >> k;
	k = min(k, MAXN - 1);
	vector<int> arr;
	int now = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			arr.push_back(now);
			now = 0;
		}
		else
			now++;
	}
	arr.push_back(now);
	//for (auto elem : arr)
	//	cerr << elem << "/";
	//cerr << endl;
	int n = arr.size();
	dp[n][0][0] = 1;
	S1[n][0][0] = 1;
	for (int fr = 0; fr < MAXN; fr++) {
		S2[n][fr][0] = dp[n][fr][0];
	}
	for (int used = 0; used < MAXN; used++) {
		S2[n][0][used] = dp[n][0][used];
	}
	for (int fr = 1; fr < MAXN; fr++) {
		for (int used = 1; used < MAXN; used++) {
			S2[n][fr][used] = (S2[n][fr - 1][used - 1] + dp[n][fr][used]) % mod;
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		int x = arr[i];
		for (int fr = 0; fr < MAXN; fr++) {
			for (int used = 0; used < MAXN; used++) {
				/*
				for (int val = 0; val < MAXN; val++) {
					int fr2 = fr + x - val;
					int used2 = used + max(0, x - val);
					if (fr2 >= 0 && fr2 < MAXN && used2 >= 0 && used2 < MAXN) {
						dp[i][fr2][used2] += dp[i + 1][fr][used];
						dp[i][fr2][used2] %= mod;
					}
				}
				*/

				/*
				for (int val = 0; val < x; val++) {
					int fr2 = fr - (x - val);
					int used2 = used - (x - val);
					if (fr2 >= 0 && used2 >= 0) {
						dp[i][fr][used] += dp[i + 1][fr2][used2];
						dp[i][fr][used] %= mod;
					}
				}
				*/
				dp[i][fr][used] += S2[i + 1][fr][used];
				dp[i][fr][used] %= mod;
				if (fr > x && used > x) {
					dp[i][fr][used] -= S2[i + 1][fr - x - 1][used - x - 1];
					dp[i][fr][used] = (dp[i][fr][used] % mod + mod) % mod;
				}


				dp[i][fr][used] += S1[i + 1][fr][used];
				dp[i][fr][used] %= mod;

				dp[i][fr][used] -= dp[i + 1][fr][used];
				dp[i][fr][used] = (dp[i][fr][used] % mod + mod) % mod;
			}
		}

		for (int used = 0; used < MAXN; used++) {
			S1[i][MAXN - 1][used] = dp[i][MAXN - 1][used];
			for (int f1 = MAXN - 2; f1 >= 0; f1--) {
				S1[i][f1][used] = (S1[i][f1 + 1][used] + dp[i][f1][used]) % mod;
			}
		}
		for (int fr = 0; fr < MAXN; fr++) {
			S2[i][fr][0] = dp[i][fr][0];
		}
		for (int used = 0; used < MAXN; used++) {
			S2[i][0][used] = dp[i][0][used];
		}
		for (int fr = 1; fr < MAXN; fr++) {
			for (int used = 1; used < MAXN; used++) {
				S2[i][fr][used] = (S2[i][fr - 1][used - 1] + dp[i][fr][used]) % mod;
			}
		}

	}
	ll ans = 0;
	for (int i = 0; i <= k; i++) {
		ans += dp[0][0][i];
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 658204
using System;

namespace abc164_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);
            int d = int.Parse(str[3]);
            int turnA = 0;
            int turnB = 0;
            while (a > 0)
            {
                turnA++;
                a = a - d;
            }
            while (c > 0)
            {
                turnB++;
                c = c - b;
            }
            if (turnB <= turnA)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 27496
N = int(input())
A = list(map(int,input().split()))
S = 0
for i,a in enumerate(A):
    if i != 0:
        if A[i-1] > A[i]:
            S += ( A[i-1] - A[i] )
            A[i] = A[i-1]
print(S)

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

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    vector<int> arr(n);
    int sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        sum+=arr[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(arr[i]*4*m>=sum)ans++;
    }
    if(ans>=m){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return(0);
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  int Now=1;
  for(int i=0; i<N; i++){
    if(A.at(i)==Now){
      Now++;
    }
  }
  if(Now==1){
    cout << -1 << endl;
  }
  else{
    cout << N-Now+1 << endl;
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define powerof2 ()
#define mp make_pair
#define pi acos(-1)
using ll = long long;
const ll M = 1000000007;
const ll M1= 998244353;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
ll power(ll x,ll y){
	if(y==0)
		return 1;
	ll res=power(x,y/2);
	res=(res*res);
	if(y&1)
		res=(res*x);
	return res;
}
 
ll powermod(ll x,ll y,ll mod){
	if(y==0)
		return 1;
	ll res=powermod(x,y/2,mod);
	res=(res*res)%mod;
	if(y&1)
		res=(res*x)%mod;
	return res;
}
/*ll binarysearch(ll va)
{
	ll n=1;
	ll l=va+1,u=n;
	ll st=num.order_of_key(va);
	while(l+1<u)
	{
		m=(l+u)/2;
		ll in=num.order_of_key(m);
		if(in-st==m-va)
		{
			l=m;
		}
		else
		{
            u=m;
		}
	}
	if(num1.find(l)==num1.end())
		return l;
	return u;
}*/
void solve(){
	int l,r,d;
	cin>>l>>r>>d;
	int ans=0;
	for(int i=l;i<=r;i++){
		if(i%d==0) ans++;
	}
	cout<<ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
 
    for(int i=1;i<=t;i++)
    {//cout<<"Case #"<<i<<": ";
    solve();}
    return 0;
}


Measured memory_bytes: 3656
use proconio::input;

fn main() {
  input! {
    _n: usize,
    k: usize,
    s: String,
  }
  let s = s.chars().collect::<Vec<char>>();
  let k = 2 * k + 1;
  let mut stack: Vec<usize> = vec![];
  
  if s[0] == '0' {
    stack.push(0);
  }
  
  let mut count = 0;
  let mut last = s[0];
  for c in s {
    if c == last {
      count += 1;
    } else {
      last = c;
      stack.push(count);
      count = 1;
    }
  }

  if count > 0 {
    stack.push(count);
  }

  let mut max = 0;
  let mut total = 0;
  let mut index = 0;
  let mut left = 0;
  let mut right = 0;
  while index < stack.len() {
    let next_left = index;
    let next_right = std::cmp::min(index + k, stack.len());

    while right < next_right {
      total += stack[right];
      right += 1;
    }
    
    while left < next_left {
      total -= stack[left];
      left += 1;
    }

    max = std::cmp::max(max, total);
    index += 2;
  }

  println!("{}", max);
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;
const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	while (true) {
		ll n; cin >> n;
		if (n == 0) break;

		vl low(n), high(n);
		REP(i, n) cin >> low[i] >> high[i];

		using vvvl = vector<vvl>;
		vvvl dp(2 * n + 1, vvl(1 << (2 * n), vl(10, -1)));
		dp[0][0][0] = 1;
		REP(i, 2 * n) REP(j, 1 << (2 * n)) REP(k, 10) if (dp[i][j][k] != -1) {
			REP(k_next, 10) { // k : next digit
				ll j_next = 0;
				if (i == 0) {
					if (k_next != 0 && low[0]/10 <= k_next && k_next <= high[0]/10) j_next |= 1 << 0;
					if (               low[0]    <= k_next && k_next <= high[0])    j_next |= 1 << 1;
				} else {
					REP(l, 2 * n - 1) if ((j >> l) & 1) { // l : ?????????index
						if (l % 2 == 0) {
							if (k == high[l / 2] / 10 && k_next > high[(l + 1) / 2] % 10) continue;
							if (k == low[l / 2] / 10  && low[(l + 1) / 2] % 10 > k_next) continue;
							j_next |= 1 << (l + 1);
						} else {
							if (k_next != 0 && low[(l + 1) / 2] / 10 <= k_next && k_next <= high[(l + 1) / 2] / 10) {
								j_next |= 1 << (l + 1);
							}
							if (low[(l + 2) / 2] <= k_next && k_next <= high[(l + 2) / 2]) {
								j_next |= 1 << (l + 2);
							}
						}
					}
				}
				dp[i + 1][j_next][k_next] = max(0ll, dp[i + 1][j_next][k_next]) + dp[i][j][k];
			}
		}
		ll ans = 0;
		FOR(i, 1, 2 * n + 1) FOR(j, 1 << (2 * n - 1), 1 << (2 * n)) REP(k, 10) if(dp[i][j][k] != -1) ans += dp[i][j][k];
		cout << ans << endl;
	}

	return 0;
}

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

double myRound(double x){
	int minusFlg = 0;

	if(x < 0){
		minusFlg = 1;
		x = fabs(x);
	}

	x += 0.0005;
	x *= 1000;
	x = floor(x);
	x /= 1000;

	return x * pow(-1,minusFlg);
}

int main(void){
	double a,b,c,d,e,f;

	while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f) != EOF){
		double q = a * e - b * d;
		double x = (c * e - b * f) / q;
		double y = (a * f - c * d) / q;

		printf("%.3lf %.3lf\n",myRound(x),myRound(y));
	}

	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String word = s.nextLine();
        int a =0;
        a=Integer.parseInt(word.charAt(word.length()-1)+"");
        if(a==2||a==4||a==5||a==7||a==9) System.out.println("hon");
        else if(a==0||a==1||a==6||a==8) System.out.println("pon");
        else System.out.println("bon");


    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for (ll i=0;i<N;i++)
#define REP(i,N) for (ll i=1;i<=N;i++)
 
ll N,M,A,B,C,D,ANS;
string S,T,U;
double n,m,a,b,c,ans;
 
int main() {
	cin>>A>>B>>C>>D;
  cout<<(A==C?0:1)<<endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;

const int N_MAX = 300;
const int M_MAX = 300;

vector< vector<int> > A(N_MAX, vector<int>(M_MAX, -1));
bool done[M_MAX] = {};

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || '9' < c) break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    int N, M;

    gc(N);
    gc(M);

    REP(i, N)
    {
        REP(j, M)
        {
            int tmp;
            gc(tmp);
            tmp--;

            A[i][j] = tmp;
        }
    }

    int ans = 301;
    REP(x, M)
    {
        int cnt[M_MAX] = {};

        REP(i, N)
        {
            REP(j, M)
            {
                if (!done[A[i][j]])
                {
                    cnt[A[i][j]]++;
                    break;
                 }
            }
        }

        int mx = -1;
        int mxidx = 0;
        REP(i, M)
        {
            if (!done[i] && mx < cnt[i] && cnt[i] != 0)
            {
                mxidx = i;
                mx = cnt[i];
            }
        }

        if (mx == -1) break;

        ans = min(ans, mx);
        done[mxidx] = true;
    }


    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n;
int main(void){
    
    cin>>n;
    cout<<(n-2LL)*180LL<<endl;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;
  int n = s.size();
  int ans = n;
  rep(i, n-1) {
    if(s[i] != s[i+1]) {
      chmin(ans, max(i+1, n-i-1));
    }
  }
  cout << ans << endl;

  return 0;
}


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


using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)




int main() {

    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll r=0,l=0,ans=0,now=0;
    while(r < n) {
        if((a[r] + now) == (a[r] ^ now)) {
            now = now^a[r];
            r++;
            ans += r-l;
        } else {
            now = now^a[l];
            l++;
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

signed main () {
    ll x,k,d;cin >> x >> k >> d;
    x = abs(x);
    ll ans;
    if (x/d >= k) {
        ans = abs(x - d*k);
    } else {
        if((k - x/d)%2==0)ans=x%d;
        else ans=abs(x%d-d);
    }
    cout << ans << endl;
}//https://atcoder.jp/contests/abc175/tasks/abc175_c

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

using ll = long long int;
constexpr ll INF = 1LL<<60;

void chmin(ll &a, ll b){
    a = min(a,b);
}
void chmax(ll &a, ll b){
    a = max(a,b);
}

bool solve(){
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), dp(n+1,INF);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    dp[0] = 0;
    for(int i=0;i<n;i++){
        ll mi = INF, ma = 0;
        for(int j=i+1;j<=min(n,i+m);j++){
            chmin(mi, a[j-1]);
            chmax(ma, a[j-1]);
            chmin(dp[j], dp[i]+k+(ma-mi)*(j-i));
        }
    }
    cout << dp[n] << endl;
    return true;
}

int main(){
    solve();
    return 0;
}



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

int main(){
  
  int a,b,x;
  cin >> a >> b >> x;
  
  if( a<= x && x-a <= b ){
  
    cout << "YES" << endl;
  
  }
  
  else{
    
    cout << "NO" << endl;
    
  }
  
}
  


Measured memory_bytes: 256
#include <stdio.h>

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

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

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

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

int main() {
    int x, y;

    scanf("%d %d", &x, &y);

    if(x < y) {
        printf("%d\n", x);
    }
    else if(x % y == 0) {
        printf("-1\n");
    }
    else {
        printf("%.0f\n", lcm(x, y) - x);
    }

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
int main(){
  int a,b;
  std::string str,rts;
  std::cin>>a >>b;
  for(int i=0;i<a;i++){
    str += '0'+b;
  }
  for(int i=0;i<b;i++){
    rts += '0'+a;
  }
  if(str >= rts ){
    std::cout<<rts;
  }
  else{
    std::cout<<str;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	long long a, b, c, k;
	cin >> a >> b >> c >> k;

	if(k % 2 == 0){
		cout << a - b << endl;
	}else{
		cout << -a + b << endl;
	}
}


Measured memory_bytes: 256
n = int(input())
pt = 0
px = 0
py = 0
tmp = []
can = True

for i in range(n):
    tmp = list(map(int, input().split()))
    t = tmp[0]
    x = tmp[1]
    y = tmp[2]
    dist = abs(x-px) + abs(y-py)
    if dist > t-pt or (px+py+t-pt)%2 != (x+y)%2:
        can = False
        break

if can:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
    int a = 0, b = 0, c = 0, d = 0, e = 0,f=0, min = 0, ma = 0, ans = 0, ansb = 0, counter = 0,countb, crowdy[101] = {},  bu = 0;
	int reset = 0,w=0;
	char hairetu[200] = {};
	int number[10000000] = {}, price[10000] = {}, sort[100000] = {}, kisu[10000] = { 100000 }, gusu[10000] = { 100000 };
	using namespace std;
	int x = 0, y = 0, z = 0, play[200] = {}, acount = 0, bcount = 0;
	std::string toki, tokit, fun,funt;

	
	int main()
	{
		bool okada = true;
		cin >> a;
		for (int i = 0; i < a; i++) {
			cin >> price[i];
			ans += price[i];
		}

		for (int j = 0; j < a; j++) {
			if (ma < price[j]) {
				ma = price[j];
			}
		}
		cout << ans - ma / 2 << endl;




	}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;

void main(){
	int W;
	int dp[5000+1] = 99999999;
	int[] w = [200, 300, 500, 1000, 1200, 1500];
	int[] v = [380, 550, 850, 1520, 1870, 2244];
	dp[0] = 0;
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j+w[i] <= 5000; j++) {
			dp[j+w[i]] = min(dp[j+w[i]], dp[j] + v[i]);
		}
	}
	while (readf("%d\n", &W) && W) {
		writeln(dp[W]);
	}
}

Measured memory_bytes: 1008
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}

#define STR_MAX 20000
#define BUF_MAX (STR_MAX+50)

enum type {
    TYPE_DOWN = '\\',
    TYPE_UP = '/',
    TYPE_FLAT = '_'
};

struct rect {
    int depth;
    int left;
};

struct stack {
    void *s;
    int idx;
};

static struct rect stack[BUF_MAX];
static int sidx;

struct rect peek(void) { return stack[sidx-1]; }
int is_empty(void) { return !sidx; }

void push(struct rect r) { stack[sidx++] = r; }
struct rect pop(void) { return stack[--sidx]; }


struct pair {
    int depth;
    int area;
};

static struct pair pstack[BUF_MAX];
static int pidx;
struct pair pair_pop(void) {return pstack[--pidx];}
void pair_push(struct pair p) { pstack[pidx++] = p; }
struct pair pair_peek(void) { return pstack[pidx-1]; }
int is_pair_empty(void) { return !pidx; }


int main(void) {
    static char str[BUF_MAX];
    get_str(str, BUF_MAX);
    int len = strlen(str);

    int right;
    int depth = 0;
    int sum = 0;
    for(right = 0; right < len; right++) {
        switch(str[right]) {
            case TYPE_DOWN:
                {
                    struct rect r = {depth, right};
                    push(r);
                    depth++;
                }
                break;
            case TYPE_UP:
                {
                    depth--;
                    if(is_empty()) {
                        pair_push((struct pair){depth, 0});
                        break;
                    }
                    struct rect r = pop();
                    int newarea = 0;
                    while(!is_pair_empty()) {
                        struct pair p = pair_peek();
                        // if p is higher, break;
                        if(p.depth <= depth) break;
                        newarea += p.area;
                        pair_pop();
                    }
                    if(r.depth == depth) {
                        sum += (right - r.left);
                        newarea += right-r.left;
                    }
                    pair_push((struct pair){depth, newarea});
                }
                break;
            case TYPE_FLAT:
                break;
            default:
                break;
        }
    }
    printf("%d\n", sum);
    int i;

    int cnt = 0;
    for(i = 0; i < pidx; i++) cnt += !!(pstack[i].area);
    printf("%d", cnt);
    for(i = 0; i < pidx; i++) {
        if(pstack[i].area) printf(" %d", pstack[i].area);
    }
    putchar('\n');
    return 0;
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    string s, t;
    cin >> s >> t;
    sort(ALL(s));
    sort(ALL(t), greater<char>());

    vstr a;
    a.pb(s);
    a.pb(t);
    sort(ALL(a));
    if (a[0] == s && s != t)
    {
        Yes;
    }
    else
    {
        No;
    }
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
while 1:
    n=int(input())
    if n==0:break
    p=list(map(int,input().split()))
    j=list(map(int,input().split()))
    j.sort()
    sump=sum(p)
    sarary=sump*n
    for i in range(n-1):
        sump+=j.pop()
        n-=1
        sara_check=sump*n
        sarary=max(sarary,sara_check)
    print(sarary)


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

int a[5010];
int n,K,x;

bool dp[5010][5010];

inline bool check(int now)
{
	memset(dp,false,sizeof dp);
		dp[0][0]=true;
		for(int i=1;i<=n;i++)
		for(int j=0;j<=K;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(i!=now&&j-a[i]>=0)
				dp[i][j]|=dp[i-1][j-a[i]];
		}
		bool ok=0;
		for(int sum=max(0,K-a[now]);sum<K;sum++)
		{
			ok|=dp[n][sum];
		}
		return ok;
}

int main()
{
	cin>>n>>K;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	int ans=0;
	int l=0,r=n+1;
	while(l+1<r)
	{
		int mid=(l+r)/2;
		if(check(mid))	r=mid;
		else l=mid;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 24832
#include<iostream>
#include<algorithm>
#include<string>


int main() {

	std::string str;
	std::cin>> str;

	auto&& it = std::begin(str);
	size_t count_{ 0 };
	while (it != std::end(str)) {
		//std::cout << *it << " ";
		it = std::find_if_not(it, std::end(str), [&](auto x) { return *it == x; });
		count_++;
	}

	std::cout << count_ -1 <<"\n";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,X,Y;
  cin>>N;
  cin>>K;
  cin>>X;
  cin>>Y;
  int en;
  if(N>K){
    en=X*K+Y*(N-K);
  }
  else{
    en=X*N;
  }
    
  cout<<en<<endl;
}

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

using namespace std;

int main(){

    int a, b;
    cin >> a;
    cin >> b;

    if(b%a == 0){
        cout << a+b << endl;
    }else{
        cout << b-a << endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 20;
int main()
{
  int n,i,res=0;
  int p[N_MAX];
  cin >> n;
  for(i=0;i<n;i++)
    cin >> p[i];
  for(i=1;i<n-1;i++)
    if((p[i]-p[i-1])*(p[i+1]-p[i])>0)
      res++;
  cout << res << endl;
  return 0;
}

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

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);

        String s=sc.next();

        boolean pld=true;
        int l=s.length();
        for(int i=0;i<l/2;i++){
            if(s.charAt(i)!=s.charAt(l-1-i))pld=false;
        }
        for(int i=0;i<(l-1)/4;i++){
            if(s.charAt(i)!=s.charAt((l-1)/2-1-i))pld=false;
        }
        for(int i=(l+3)/2;i<(l-(l+3)/2)/2;i++){
            if(s.charAt(i)!=s.charAt(l-1-i))pld=false;
        }
        if(pld){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  string S;
  int K;
  cin>>S>>K;
  int L=S.size();
  FOR(i,0,L){
    if(S[i]=='a'){
      continue;
    }
    int num='z'-S[i]+1;
    if(num<=K){
      K-=num;
      S[i]='a';
    }
  }
  if(K==0){
    cout<<S<<endl;
  }else{
    K%=26;
    S[L-1]+=K;
    cout<<S<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  
  char c;
  cin >> c;
  bool sub1 = c == 'a';
  bool sub2 = c == 'e';
  bool sub3 = c == 'i';
  bool sub4 = c == 'o';
  bool sub5 = c == 'u';
  if(sub1 || sub2 || sub3 || sub4 || sub5) cout << "vowel" << endl;
  else cout << "consonant" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
	rep(q,0,100100){
		int a,b; cin>>a>>b;
		if(a==0 && b==0)return 0;
		rep(i,0,a){
			bool ok=i%2==0;
			rep(j,0,b){
				if(ok)cout<<'#';
				else cout<<'.';
				ok=!ok;
			}
			cout<<endl;
		}
		cout<<endl;
	}


	return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007



              
int main()
{
  ios::sync_with_stdio(0);
    cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
      
    int t;
    t=1;
     //  cin>>t;
    while(t--){
        	unsigned int n;
        	string s,s1,s2;
        	cin>>n;
        	cin>>s;
        	if(s.size()<=n)
        	cout<<s;
        	else if (s.length()>n){
        		s1=s.substr(0,n);
        		s2="...";
        		s1=s1.append(s2);
        		cout<<s1;
        	}

       


             }
             cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast


        
    string str;
    cin>>str;

    ll n;
    cin>>n;

    map<int,int> m;
    forn(i,0,str.sze)
    {
        m[str[i]-'a']++;
    }

    if(m.sze == 1)
    {
        cout<<((n*((ll)str.sze))/2);
        return 0;
    }

    if(str[0] == str[str.sze-1])
    {
        ll a = 0;
        int i = 0;
        for(; i < str.sze; i++)
        {
            if(str[i] != str[0]) break; 
        }

        a = i;

        ll b = 0;

        int j = str.sze-1;
        for(; j >= i; j--)
        {
            if(str[j] != str[0]) break;
        }

        b = str.sze-1-j;

        ll c = 0;

        for(; i < j; i++)
        {
            if(str[i] == str[i+1])
            {
                str[i+1] = '0';
                c++;
            }
        }

        ll total = a/2 + b/2 + ((a+b)/2)*(n-1) + n*c;
        cout<<total;

    }
    else
    {
        string s = str;
        ll total = 0;
        forn(i,0,s.sze-1)
        {
            if(s[i] == s[i+1])
            {
                s[i+1] = '0';
                total++;
            }
        }

        cout<<n*total;           
    }









    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int n,m;
int a[200010];
int main(){
	cin>>n>>m;
	for(int i=0;i<=n;i++)a[i]=0;
	for(int i=0;i<m;i++){
		int c,d;cin>>c>>d;
		if(c==1)a[d]++;
		if(d==n)a[c]+=10;
	}
	bool ok=false;
	for(int i=1;i<=n;i++){
		if(a[i]>=11)ok=true;
	}
	if(ok)cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}


Measured memory_bytes: 1024
//#define TASK "sqrtrev"

// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse4.2,avx2")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("unroll-all-loops")

#include <bits/stdc++.h>

// #include <ext/rope>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
using namespace std;

//template<class T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//
//template<class K, class T>
//using ordered_map = tree<K, T, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define pb push_back
#define pii pair<int, int>
#define len(x) (long long)x.size()
#define int long long
#define umap unordered_map

typedef long long ll;
typedef long double ld;


const int INF = (int)numeric_limits<int>::max() >> 1;
const long long MAXN = (long long)2e5;
const long long MOD = (long long)1e9 + 7;
const long double EPS = (long double)1e-12;


// char _buf_[(int)1e8];
// size_t _p_ = 0;

// inline void *operator new(size_t _n_) {
//    _p_ += _n_;
//    return _buf_ + _p_ - _n_;
// }
// inline void operator delete(void*) {};

ll power(ll x, ll n, ll mod = 1e9 + 7) {
    if (n == 0) return 1ll;
    if (n & 1ll) return power(x, n - 1ll, mod) * x % mod;
    ll tmp = power(x, n >> 1ll, mod);
    return (tmp * tmp) % mod;
}

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

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

template<typename A, typename B>
bool cmax(A &a, const B &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename A, typename B>
bool cmin(A &a, const B &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
#ifndef LOCAL
    #ifdef TASK
    freopen(TASK".in", "r", stdin);
    freopen(TASK".out", "w", stdout);
#endif
#endif
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(924653523);
    mt19937 rnd(42);
    // == SOLUTION == //
    int a, b;
    cin >> a >> b;
    cout << a + b / 2 << "\n";
}











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

int main() {
    int H, W; cin >> H >> W;
    vector<string> grids(H+2);
    for (int i = 1; i <= H; i++) {
        string S; cin >> S;
        grids[i] = "." + S + ".";
    }
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (grids[i][j] == '#') {
                cout << '#';
            } else {
                int a = 0;
                for (int s : {-1, 0, +1}) {
                    for (int t : {-1, 0, +1}) {
                        a += (int)(grids[i+s][j+t] == '#');
                    }
                }
                cout << a;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
W, a, b = map(int, input().split())
A = [a,a+W]
B = [b,b+W]
if A[0] <= B[0] <= A[1] or A[0] <= B[1] <= A[1] or B[0] <= A[0] <= B[1] or B[0] <= A[1] <= B[1]:
    print(0)
    exit()
print(max(B[0]-A[1],A[0]-B[1]))

Measured memory_bytes: 3064