akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    int c[n], s[n], f[n];

    rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];

    rep(i, n)
    {
        int t = 0;
        for (int j = i; j < n - 1; j++)
        {
            if (t < s[j])
                t = s[j];
            else if (t % f[j] == 0)
                ;
            else
                t += f[j] - t % f[j];
            t += c[j];
        }
        OP(t);
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,x;string s;
  map<string, int> M;
  M["AC"]=1;M["WA"]=0;
  cin>>n>>m;
  bool AC[n];int p[n];
  memset(p, 0, sizeof p);
  memset(AC, 0, sizeof AC);
  int pen=0;int ac=0;
  for(int i=0;i<m;i++)
  {
    cin>>x>>s;
    x--;
    if(M[s]==0)
    {
      if(AC[x]==0)p[x]++;
    }
    else AC[x]=1;
  }
  for(int i=0;i<n;i++)
  { if(AC[i])
 	 {pen=pen+p[i];
    ac=ac+AC[i];
  	}
  }
  cout<<ac<<" "<<pen;
}

Measured memory_bytes: 768
program testcase
    integer(8) n
    integer(8) :: i= 0
    integer(8) :: c0 = 0
    integer(8) :: c1 = 0
    integer(8) :: c2 = 0
    integer(8) :: c3 = 0
    character(3) str
    read *, n
    do
        if(i == n)exit
        read *, str
        if(str .eq. "AC")then
            c0 = c0 + 1
        else if(str .eq. "WA")then
            c1 = c1 + 1
        else if(str .eq. "TLE")then
            c2 = c2 + 1
        else if(str .eq. "RE")then
            c3 = c3 + 1
        end if
        i = i + 1
    end do
    print "('AC x ',i0)", c0
    print "('WA x ',i0)", c1
    print "('TLE x ',i0)", c2
    print "('RE x ',i0)", c3
end program

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

int main() {
	
  int a,b,c;
  cin >> a >> b >> c;
  
  int A = max(a,b) - min(a,b) ;
  int B = max(a,c) - min(a,c) ;
  
  if ( A>B) cout << "B" ;
  else cout << "A" ;



}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;



ll pw(ll a, ll b, ll MOD) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
const ll M1 = ll(1e9) + 7;
const ll M2 = ll(1e9) + 9;

struct hsh {

	ll a, b;
	hsh() {a = b = 0;}
	hsh(ll x) {
		a = x % M1;
		b = x % M2;
	}
	hsh(ll A, ll B) {
		a = A % M1;
		b = B % M2;
	}
	hsh operator+(hsh x) {
		return hsh(a + x.a, b + x.b);
	}
	hsh operator-(hsh x) {
		return hsh(a - x.a + M1, b - x.b + M2);
	}
	hsh operator*(hsh x) {
		return hsh(a * x.a % M1, b * x.b % M2);
	}
	ll get() {
		return a * M2 + b;
	}
};

hsh P = 1000003;
hsh BP = hsh(pw(P.a, M1 - 2, M1), pw(P.b, M2 - 2, M2));

int n;
string s;

const int MX = 3000000;

int pos[MX];

hsh hs[MX];

hsh hst[MX];

map<ll, int> mm;

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	cin >> s;
	pos[0] = 0;
	hst[0] = 1;
	int cur = 0;
	for (int i = 0; i < n; ++i) {
		hst[i + 1] = hst[i];
		if (s[i] == '<')
			--cur, hst[i + 1] = hst[i + 1] * BP;
		if (s[i] == '>')
			++cur, hst[i + 1] = hst[i + 1] * P;
		pos[i + 1] = cur;
	}
	hs[n] = 0;
	for (int i = n - 1; i >= 0; --i) {
		if (s[i] == '+') {
			hs[i] = hs[i + 1] + hst[i];
		}
		else if (s[i] == '-') {
			hs[i] = hs[i + 1] - hst[i];
		}
		else {
			hs[i] = hs[i + 1];
		}
	}
	++mm[hs[n].get()];
	ll ans = 0;
	for (int i = n - 1; i >= 0; --i) {
		hsh rq = hs[i] - hs[0] * hst[i];
		ans += mm[rq.get()];
		++mm[hs[i].get()];
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 128020
#include<iostream>
#include<string>
using namespace std;
int n,m;string S;
long long dp[6000][6000];
int main(){
	cin>>n>>S;m=S.size();
	dp[0][0]=1;dp[0][1]=1;
	for(int i=0;i<5900;i++)dp[i][0]=1;
	for(int i=1;i<5900;i++){
		for(int j=1;j<5900;j++){
			if(j*2-2>i)continue;
			if(j*2-2==i)dp[i][j]=dp[i][j-1];
			if(j*2-2<i)dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*2;
			dp[i][j]%=1000000007;
		}
	}
	cout<<dp[n-1][(n-m)/2]<<endl;
	return 0;
}


Measured memory_bytes: 91648
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)
  __gcd(a,b)は最大公約数を取ってくれる、aとb
  の大きい方をNとしたとき、計算量は√N
 */

//ここから書き始める
int main(){
	string s ;
	cin >> s;
	if(s[0] == 'S') cout << "Cloudy"<<endl;
	else if (s[0] == 'R' ) cout <<"Sunny"<<endl;
	else cout << "Rainy"<<endl;
}


Measured memory_bytes: 256
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N, K = i2nn()
    V = i2nn()
    n = 0
    for i in range(min(N+1, K+1)):
        for j in range(min(N+1-i, K+1-i)):
            k = K - i - j
            w = V[0:i] + V[N-j:N]
            w.sort()
            t = 0
            for u in w:
                if u < 0 and k > 0:
                    k -= 1
                    continue
                t += u
            if n < t:
                n = t
    print(n)

main()


Measured memory_bytes: 40432
import java.util.Scanner;


// 145_a
public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int r = scan.nextInt();

        //        HashMap<String, Integer> map = new HashMap<>();
        //        map.put("SUN", 7);
        //        map.put("MON", 6);
        //        map.put("TUE", 5);
        //        map.put("WED", 4);
        //        map.put("THU", 3);
        //        map.put("FRI", 2);
        //        map.put("SAT", 1);

        System.out.println(r * r);

    }

}


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

int main() {
  int n;
  cin >> n;
  vector<LL> a(n);
  vector<LL> b(n);
  for (int i = 0; i < n; i ++) cin >> a.at(i);
  for (int i = 0; i < n; i ++) cin >> b.at(i);

  int cnt = 0;
  LL sum_rem = 0;
  LL sum_short = 0;
  pair<LL, LL> rem[n];
  for (int i = 0; i < n; i ++) {
    if (a.at(i) - b.at(i) < 0) {
      cnt ++;
      sum_short += b.at(i) - a.at(i);
    } else {
      rem[i].first = a.at(i) - b.at(i);
      rem[i].second = i;
      sum_rem += a.at(i) - b.at(i);
    }
  }

  if (sum_short > sum_rem) {
    cout << "-1" << endl;
    return 0;
  } else {
    sort(rem, rem + n);
    reverse(rem, rem + n);
    int i = 0;
    while (sum_short > 0) {
      sum_short -= rem[i].first;
      i ++;
      cnt ++;
    }
  }

  cout << cnt << endl;
}


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

#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'

using namespace std;

const int MOD = 1e9 + 7;
const int N = 510;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n, x;
	cin >> n >> x;
	int ans = 0;
	while(n--) {
		ll a, b;
		cin >> a >> b;
		if (sqrt(a * a + b * b) <= x)
			ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3676
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

string S, T;

int main() {
	cin >> S >> T;
	if (S == T.substr(0, S.size())) printf("Yes");
	else printf("No");
}

Measured memory_bytes: 3764
#include <iostream>
using namespace std;
int main(void){
	int k,i,temp = 7,t = 0;
	cin >> k;
	
	for (i=1;i<=1000000;i++) {
		if (temp%k==0) {
			t = 1;
			cout << i << '\n';
          break;
		}
		temp = (temp*10+7)%k;
	}
	if (t == 0) {
		cout << "-1" << '\n';
	}
}


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

int main(){
  int N,K,R,S,P,ans;
  string T,A;
  cin>>N>>K;
  cin>>R>>S>>P;
  cin>>T;
  ans = 0;
  for(int i=0;i<T.size();i++){
    if(T.at(i)=='r'){
      A.push_back('p');
      ans+=P;
    }else if(T.at(i)=='s'){
      A.push_back('r');
      ans+=R;
    }else if(T.at(i)=='p'){
      A.push_back('s');
      ans+=S;
    }
  }
  for(int i=K;i<A.size();i++){
    if(A.at(i-K)==A.at(i)){
      if(A.at(i)=='r'){
        ans-=R;
        A.at(i)='x';
      }else if(A.at(i)=='s'){
        ans-=S;
        A.at(i)='x';
      }else if(A.at(i)=='p'){
        ans-=P;
        A.at(i)='x';
      }
    }
  }
  cout<<ans;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

string s;
int gx,gy;
vector<int> nums, A, B;

bool dp(int s,int t,vector<int> &n){
    set<int> now;
    now.insert(s);
    for(auto& x:n){
        set<int> nxt;
        for(auto itr:now){
            nxt.insert(itr+x);
            nxt.insert(itr-x);
        }
        swap(now,nxt);
    }
    return (now.find(t)!=now.end());
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s>>gx>>gy;
    s+='T';
    int cnt=0;
    rep(i,s.size()){
        if(s[i]=='T'){
            nums.push_back(cnt);
            cnt=0;
        }else{
            cnt++;
        }
    }
    
    rep(i,nums.size()){
        if(i%2==0){
            A.push_back(nums[i]);
        }else{
            B.push_back(nums[i]);
        }
    }
    
    int s=A[0];
    A.erase(A.begin());
    if(dp(s,gx,A)&&dp(0,gy,B)){
        cout1("Yes");
    }else{
        cout1("No");
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

int main() {
  int a, b, c, x;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  scanf("%d", &x);
  int way_cnt = 0;
  for (int i = 0; i <= a; i++) {
  	for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        int sum = 500*i + 100*j + 50*k;
        if (sum != x) continue;
        way_cnt++;
      }
    }
  }
  std::cout << way_cnt << '\n';
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

import static java.lang.Math.floor;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int h = (int)floor(a/3600);
        int m = (int)floor(a%3600 /60);
        int s = a%60;
        System.out.print(h+":"+m+":"+s);
        System.out.println();
    }
}


Measured memory_bytes: 26396
N=int(input())
I=[]
for i in range(N):
    I.append(input())
a=0
b=0
c=0
d=0
for i in range(N):
    if I[i]=='AC':
        a+=1
    if I[i]=='WA':
        b+=1
    if I[i]=='TLE':
        c+=1
    if I[i]=='RE':
        d+=1
print('AC x '+str(a))
print('WA x '+str(b))
print('TLE x '+str(c))
print('RE x '+str(d))

Measured memory_bytes: 16272
#include<iostream>
using namespace std;
unsigned long long Lucas[87]={2,1};
unsigned long long L(int n){
    if(Lucas[n]!=0)return Lucas[n];
    return Lucas[n]=L(n-1)+L(n-2);
}
int main(){
    int n;cin>>n;
    cout<<L(n)<<endl;
    return 0;
}

Measured memory_bytes: 256
a=[list(map(int,input().split()))for i in range(3)]
cnt=[0,0,0,0]
for i in range(3):
    cnt[a[i][0]-1]+=1
    cnt[a[i][1]-1]+=1
for i in range(4):
    if cnt[i]==3:
        print("NO")
        exit()
print("YES")


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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){

  char si;
  string s = "1974";
  rep(i,4){
    cin >> si;
    rep(j,s.size()){
      if(s[j] == si) s[j] = 'x';
    }
  }

  if(s == "xxxx") cout << "YES" << endl;
  else cout << "NO" << endl;



  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462
int main(){
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
	return 0;
}

Measured memory_bytes: 1180
def judge(a, b, s):
    num = [str(i) for i in range(10)]
    for i in range(a+b+1):
        if (s[i] in num and i != a)  or (s[a] == "-" and i == a):
            continue
        else:
            return "No"

    return "Yes"
            

A, B = map(int,input().split())
S = input()
ans  = judge(A, B, S)
print(ans)


Measured memory_bytes: 3060
program zero_one_matrix
  implicit none
  integer :: h, w, a, b, x(1000,1000) = 0, i, j
  read(*,*) h, w, a, b
  if (a == 0) a = w
  if (b == 0) b = h
  x(1:b,1:a) = 1
  x(b+1:h,a+1:w) = 1
  do i = 1, h
    do j = 1, w
      write(*,'(i0)',advance='no') x(i,j)
    end do
    write(*,*)
  end do
end program zero_one_matrix

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
  int N;
  cin>>N;
  vector<int64_t>T(N);
  for(int i=0;i<N;i++){
    cin>>T[i];
  }
  int64_t a=1;
  for(int i=0;i<N;i++){
   a=a/__gcd(a,T[i])*T[i];
  }
  cout<<a<<endl;
  return 0;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,a,b,c,l[8],f[8];
int dfs(int x){
    int aa=0,bb=0,cc=0,ans=0,d[4]={};
    if(x==n){
        for(int i=0;i<n;i++){
            if(f[i]==0){
                aa+=l[i];
                d[0]++;
            }
            else if(f[i]==1){
                bb+=l[i];
                d[1]++;
            }
            else if(f[i]==2){
                cc+=l[i];
                d[2]++;
            }
        }
        ans+=abs(a-aa);
        ans+=abs(bb-b);
        ans+=abs(cc-c);
        for(int i=0;i<3;i++){
            if(d[i]==0){
                return 10000;
            }
            else{
                ans+=10*(d[i]-1);
            }
        }
        return ans;
    }
    ans=10000;
    for(int i=0;i<4;i++){
        f[x]=i;
        ans=min(ans,dfs(x+1));
    }
    return ans;
}
int main(){
    scanf("%d %d %d %d",&n,&a,&b,&c);
    for(int i=0;i<n;i++){
        scanf("%d",&l[i]);
    }
    printf("%d\n",dfs(0));
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
 
            int D = int.Parse(s[0]);
            int N = int.Parse(s[1]);
            int ans; 
            if (D == 0)
            {
                ans = N;
                if (ans == 100)
                {
                    ans += 1;
                }
            }
            else if (D == 1)
            {
                ans = N * 100;
                if (ans == 100*100)
                {
                    ans += 100;
                }
            }
            else 
            {
                ans = N * 100 * 100;
                if (ans == 100*100*100)
                {
                    ans += 10000;
                }
            }

            Console.WriteLine(ans);
            Console.ReadLine();


        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
	int i;
	string s;
	cin>>s;
	for(i=0;i<s.size();i+=2){	//〇.size()　・・・　入力した文字数を取得する
		if(s[i]=='L'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	for(i=1;i<s.size();i+=2){
		if(s[i]=='R'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2e5;
int n,cnt,hd[N],v[N],nxt[N],w[N];
long long d[N];
void dfs(int u,int fa){
    for(int i=hd[u];i;i=nxt[i])
    if(v[i]!=fa){
        d[v[i]]=d[u]+w[i];
        dfs(v[i],u);
    }
}
int main(){
    cin>>n;
    for(int i=1,x,y,z;i<n;i++){
		cin>>x>>y>>z;
		v[++cnt]=y;
		nxt[cnt]=hd[x];
		w[cnt]=z;
		hd[x]=cnt;
		v[++cnt]=x;
		nxt[cnt]=hd[y];
		w[cnt]=z;
		hd[y]=cnt;
	}
    dfs(1,0);
    for(int i=1;i<=n;i++){
        int op=d[i]&1;
        cout<<op<<endl;
    }
}

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

using namespace std;

#define vec vector
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    string s;
    int k;

    cin >> s >> k;

    int n = (int)s.size();

    vec< vec< vec< int > > > dp(n, vec< vec< int > >(n, vec< int >(k + 1, 0)));

    for(int l = n - 1;l >= 0;l--) {
        for(int r = l;r < n;r++) {
            if(l == r) {
                for(int q = 0;q <= k;q++) {
                    dp[l][r][q] = 1;
                }
                continue;
            }
            for(int q = 0;q <= k;q++) {
                dp[l][r][q] = max(dp[l + 1][r][q], dp[l][r - 1][q]);
                if(q) dp[l][r][q] = max(dp[l][r][q], dp[l][r][q - 1]);
                int add = !(s[l] == s[r]);
                if(q >= add) {
                    dp[l][r][q] = max(dp[l][r][q], dp[l + 1][r - 1][q - add] + 2);
                }
            }
        }
    }

    cout << dp[0][n - 1][k] << "\n";

    return 0;
}


Measured memory_bytes: 109568
#include <stdio.h>
#include <string.h>
int main(void){
    char s[100020] ;
    scanf ("%s",s) ;
    for (int i=0; i<strlen(s); i++) {
        if (i%2==0){
            printf("%c",s[i]) ;
        }
    }
    return 0 ;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin>>N>>M;
}
void solve() {
  ;
  cout<<(M>=N ? "unsafe" : "safe")<<endl;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int ans=0,num[100],a,b,c;
    string s;
    memset(num,0,sizeof(num));
    for(int i=1;i<=n;i++)
    {
        stringstream ss;
        ss<<i;
        ss>>s;
        a=s[0]-'0';
        b=i%10;
        c=a*10+b;
        num[c]++;
    }
    for(int i=11;i<=100;i++)
    {
        if(i%10==0)
            continue;
        if(i%10==i/10)
            ans+=num[i]*num[i];
        else
        {
            int j=(i%10)*10+i/10;
            ans+=2*num[i]*num[j];
            num[i]=0;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int board[8][8]={{}};
  string buf;
  int i,j,k;
  char cs[]={'.','o','x'};
  for(i=0;i<8;i++){
    cin>>buf;
    for(j=0;j<8;j++){
      if(buf[j]=='.') board[j][i]=0;
      if(buf[j]=='o') board[j][i]=1;
      if(buf[j]=='x') board[j][i]=2;
    }
  }
  int f=1;
  int ax[]={ 1, 1, 1, 0, 0,-1,-1,-1};
  int ay[]={ 0, 1,-1, 1,-1,-1, 1, 0};
  while(f!=0){
    f=0;
    int x,y,bx,by,m=0,c,s;
    for(j=0;j<8;j++){
      for(i=0;i<8;i++){
	c=0;s=0;
	x=i;
	y=j;
	if(board[x][y]!=0) continue;
	for(k=0;k<8;k++){
	  s=0;
	  x=i;
	  y=j;
	  //cout << x+ax[k];
	  while(0<=x+ax[k]&&x+ax[k]<8&&
		0<=y+ay[k]&&y+ay[k]<8){
	    //cout << board[x+ax[k]][y+ay[k]];
	    if(board[x+ax[k]][y+ay[k]]==2){
	      s++;
	      //cout << s << endl;
	      x+=ax[k];y+=ay[k];
	    }
	    else if(board[x+ax[k]][y+ay[k]]==1) {
	      c+=s;
	      break;
	    }else break;
	    
	  }	  
	}
	if(m<c){
	  bx=i;
	  by=j;
	  m=c;
	}
      }
    }
    
    //cout << m << " "<<bx << " " << by<< endl;
    if(m!=0){
      for(k=0;k<8;k++){
	s=0;
	x=bx;
	y=by;
	while(0<=x+ax[k]&&x+ax[k]<8&&
	      0<=y+ay[k]&&y+ay[k]<8){
	  if(board[x+ax[k]][y+ay[k]]==2){
	    s++;
	    x+=ax[k];y+=ay[k];
	  }else if(board[x+ax[k]][y+ay[k]]==1) {
	    for(int a=0;a<=s;a++) board[bx+ax[k]*a][by+ay[k]*a]=1;
	    break;
	  }else break;
	  
	}
      }
      f=1;
    }
    m=0;
    for(j=7;j>=0;j--){
      for(i=7;i>=0;i--){
	c=0;s=0;
	x=i;
	y=j;
	
	if(board[x][y]!=0) continue;
	for(k=0;k<8;k++){
	  s=0;
	  x=i;
	  y=j;
	  while(0<=x+ax[k]&&x+ax[k]<8&&
		0<=y+ay[k]&&y+ay[k]<8){
	    if(board[x+ax[k]][y+ay[k]]==1){
	      s++;
	      //cout << s << endl;
	      x+=ax[k];y+=ay[k];
	    }
	    else if(board[x+ax[k]][y+ay[k]]==2) {
	      c+=s;
	      break;
	    }else break;
	  }
	}
	if(m<c){
	  bx=i;
	  by=j;
	  m=c;
	}
      }
    }
    if(m!=0){
      for(k=0;k<8;k++){
	s=0;
	x=bx;
	y=by;
	while(0<=x+ax[k]&&x+ax[k]<8&&
	      0<=y+ay[k]&&y+ay[k]<8){
	  if(board[x+ax[k]][y+ay[k]]==1){
	    s++;
	    x+=ax[k];y+=ay[k];
	  }else if(board[x+ax[k]][y+ay[k]]==2) {
	    for(int a=0;a<=s;a++) board[bx+ax[k]*a][by+ay[k]*a]=2;
	    break;
	  }else break;
	  
	}
      }
      f=1;
    }
    //cout << m << " "<<bx << " " << by<< endl;
    //f*=0;
  }
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      cout << cs[board[j][i]];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1180
let n = Int(readLine()!)!
let a = readLine()!.split(separator:" ").map{Int($0)! % mod}
let mod = 1000000007
var s = 0, s1 = 0
for i in 0..<n-1 {
  s1 += a[n-i-1]
  s1 %= mod
  s += a[n-2-i] * s1
  s %= mod
}
print(s)


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

struct edge{ int to,cost; };
const int N = 2e5+10;
vector< edge > G[N];

struct TreeDP{
  vector<int> d; //始点(n/2とする)から最も遠い距離
  vector<int> dp; //各点から最も遠い距離
  void init(int n){
    d.resize(n+1); dp.resize(n+1);
  }

  void dfs1(int u,int par){
    for(auto e : G[u]){
      if(e.to == par) continue;
      dfs1(e.to,u);
      d[u] = max(d[u],d[e.to] + e.cost);
    }
  }

  int dfs2(int u,int d_par,int par){
    vector< pair<int,int> > d_child;
    d_child.push_back({0,-1}); //番兵
    for(auto e : G[u]){
      if(e.to == par) d_child.push_back({d_par + e.cost,e.to});
      else d_child.push_back({e.cost + d[e.to],e.to});
    }
    sort(d_child.rbegin(),d_child.rend());

    int res = d_child[0].first + d_child[1].first;
    for(auto e : G[u]){
      if(e.to == par) continue;
      
      if(d_child[0].second != e.to) {
        res = max(res,dfs2(e.to,d_child[0].first,u));
      }
      else {
        res = max(res,dfs2(e.to,d_child[1].first,u));
      }
    }
    return dp[u] = res;
  }
}Tree;

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n-1; i++){
    int s,t,w; cin >> s >> t >> w;
    G[s].push_back({t,w});
    G[t].push_back({s,w});
  }

  Tree.init(n);
  Tree.dfs1(n/2,-1);
  int ans = Tree.dfs2(n/2,0,-1);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 24692
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/**@author: Sayed Sohan*/
/**status : */
/**url: */
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define FOR(i,x,n) for(ll i=(x);i<(n);i++)
#define IFOR(i,n,x) for(ll i=(n-1);i>=(x);i--)
#define REP(i,n) for(ll i=0;i<n;i++)
#define IREP(i,n) for(ll i = n-1;i>=0;i--)
#define cas(c,x)  cout<<"Case "<<c++<<": "<<x<<NL;
#define clr(arr,value) memset(arr,value,sizeof(arr))
#define MOD 1000000007
#define PI acos(-1.0)
#define rtod 180/PI
#define DIF if(0)
#define PB push_back
#define MP make_pair
#define SP " "
#define NL "\n"
#define DE cout<<"HERE"<<endl;
#define F first
#define S second
#define INF 1e18
#define Pause system("pause")
#define __FAST_IO ios_base::sync_with_stdio(0);
#define clr2V(x,sz) for(int iii=0;iii<=sz;iii++) x[iii].clear();
#define NUM1(x) __builtin_popcount(x)
#define MAX 100010/** can increase another 0 */

//** your code goes from here



int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    ll i,j,k,arr[MAX],l,m,n,x,y,coun,sum,ans,T,check;
    vector<ll> v;
    string s;
	
  cin>>n>>m;
  
  x = min(n,m);
  
	if(n==x){
      for(i=0;i<m;i++) cout<<n;
      cout<<NL;
    }
  else{
    for(i=0;i<n;i++) cout<<m;
    cout<<NL;
  }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N, M, P, D[10101];
int hidari[10101], migi[10101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> P;
    rep(i, 0, M) cin >> D[i];
    D[M] = P;
    sort(D, D + M + 1);

    int st = 0;
    rep(i, 0, M + 1) if (D[i] == P) st = i;

    rep(i, 1, M + 1) hidari[i] = ((D[st] - D[(st - i + M + 1) % (M + 1)] + N) % N) * 100;
    rep(i, 1, M + 1) migi[i] = ((D[(st + i) % (M + 1)] - D[st] + N) % N) * 100;

    int ans = inf;
    rep(i, 0, M + 1) chmin(ans, hidari[i] * 2 + migi[M - i]);
    rep(i, 0, M + 1) chmin(ans, migi[i] * 2 + hidari[M - i]);
    cout << ans << endl;
}



Measured memory_bytes: 3340
import java.util.Scanner;
import java.lang.Math;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	while (scan.hasNext()) {
	    String input = scan.nextLine();
	    String[] inputs = input.split(" ");
	    int height = Integer.parseInt(inputs[0]);
	    int width = Integer.parseInt(inputs[1]);
	    if (height == 0 && width == 0) {
		break;
	    }
	    for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
		    System.out.print("#");
		}
		System.out.println();
	    }
	    System.out.println();
	}
    }
}

Measured memory_bytes: 33840
#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxn 100010

using namespace std;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int n, A, B, C, type[Maxn], step[Maxn];
char ch[2];
bool vis[10][10][10][Maxn], flag;

void output() {
    cout << "Yes" << endl;
    for(int i = 1; i <= n; ++i) {
        if(step[i] == 1) printf("A\n");
        if(step[i] == 2) printf("B\n");
        if(step[i] == 3) printf("C\n");
    }
}

void dfs(int a, int b, int c, int x) {
    // cout << a << " " << b << " " << c << " " << x << endl;
    if(vis[a][b][c][x] || flag) return;
    if(x == n + 1) {
        flag = 1;
        output();
        return;
    }
    if(type[x] == 1) {
        if(a > 0) step[x] = 2, dfs(a - 1, b + 1, c, x + 1);
        if(b > 0) step[x] = 1, dfs(a + 1, b - 1, c, x + 1);
        if(!a && !b || !flag) vis[a][b][c][x] = 1;
    }
    if(type[x] == 2) {
        if(a > 0) step[x] = 3, dfs(a - 1, b, c + 1, x + 1);
        if(c > 0) step[x] = 1, dfs(a + 1, b, c - 1, x + 1);
        if(!a && !c || !flag) vis[a][b][c][x] = 1;
    }
    if(type[x] == 3) {
        if(b > 0) step[x] = 3, dfs(a, b - 1, c + 1, x + 1);
        if(c > 0) step[x] = 2, dfs(a, b + 1, c - 1, x + 1);
        if(!b && !c || !flag) vis[a][b][c][x] = 1;
    }
}

int main() {
    n = read();
    A = read(); B = read(); C = read();
    if(A > 3) A = 3;
    if(B > 3) B = 3;
    if(C > 3) C = 3;
    if(!A && !B && !C) {
        cout << "No" << endl;
        return 0;
    }
    for(int i = 1; i <= n; ++i) {
        scanf(" %s", ch + 1);
        if(ch[1] == 'A' && ch[2] == 'B') type[i] = 1;
        if(ch[1] == 'A' && ch[2] == 'C') type[i] = 2;
        if(ch[1] == 'B' && ch[2] == 'C') type[i] = 3;
    }
    dfs(A, B, C, 1);
    if(!flag) cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 14124
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class DAOrorBProblem {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll a, b; cin >> a >> b;
      ll tmp = a;
      vector<int> va, vb;
      while(tmp>0) {
        va.push_back(tmp%2);
        tmp /= 2;
      }
      tmp = b;
      while(tmp>0) {
        vb.push_back(tmp%2);
        tmp /= 2;
      }
      reverse(all(va));
      reverse(all(vb));
      for(auto e: va) {
        cerr << e;
      }
      cerr << endl;
      for(auto e: vb) {
        cerr << e;
      }
      cerr << endl;

      if (a==b) {
        cout << 1 << endl;
        return;
      }
      for(int k=61; k>=0; k--) {
        ll t = 1LL<<k;
        //debug(t);
        if (b < t) continue;
        if (a >= t && b >= t) {
          a -= t;
          b -= t;
          continue;
        }
        if (b >= t && a < t) {
          ll c = t|a;
          ll d = t*2-1;
          debug(t);
          debug(a, b, c, d);
          bool find = false;
          for(int p=k-1; p>=0; p--) {
            ll r = 1LL<<p;
            if (b&r) {
              find = true;
            }
            if (find) {
              b |= r;
            }
          }
          debug(a, b, c, d);

          ll ret = -1;
          if (b >= c) {
            ret = d-a+1;
          } else {
            ret = d-c+1 + b-a+1;
          }
          cout << ret << endl;
          return;
        }



      }
    }
};

signed main() {
  DAOrorBProblem solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000009;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[]={-1,-2,1,-2,2,-1,2,1},ddy[]={-2,-1,-2,1,-1,2,1,2};

ll a[303],d[303][303];
int n,k;
ll go(int N,int K)
{
	if(N==n+1)return 0;
	ll &ret=d[N][K];
	if(~ret)return ret;
	ret=INF;
	fup(i,0,K,1)
	{
		int next=N+i+1;
		if(next>n+1)break;
		if(a[next]>a[N])ret=min(ret,go(next,K-i)+a[next]-a[N]);
		else ret=min(ret,go(next,K-i));
	}
	return ret;
}
int main(){
	MEM_1(d);
	scanf("%d%d",&n,&k);
	if(n==k)return !printf("0");
	fup(i,1,n,1)scanf("%lld",a+i);
	printf("%lld",go(0,k));
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793


   
int main(){
   int n;
   cin >> n;
   if(n%1000==0)cout << 0 << endl;
   else cout << 1000-n%1000 << endl;
}

Measured memory_bytes: 3620
x1, y1, x2, y2 = map(int, input().split())
x3 = x2 + y1 - y2
y3 = y2 - x1 + x2
x4 = x1 + x3 - x2
y4 = y1 + y3 - y2
print(x3, y3, x4, y4)

Measured memory_bytes: 3060
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list
def summarize_list(l):
  sl=l

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res

def main():
  s=S()
  k=I()

  if len(s)==1:
    return k//2

  l=summarize_list(s)

  if len(l)==1:
    return (l[0][1]*k)//2

  ans=0
  bf=False
  
  if l[0][0]==l[-1][0] and (l[0][1]//2+l[-1][1]//2!=(l[0][1]+l[-1][1])//2):
    bf=True

  _ans=0
  for x in l:
    _ans+=x[1]//2
  ans+=_ans*k

  if bf:
    ans+=k-1

  return ans

# main()
print(main())


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

int main() {
	int n;
	string s;
	cin >> n >> s;
	vector<int> w(n + 1);
	for (int i = 0; i < n; i++)
		if (s[i] == '#')
			w[i + 1] = w[i] + 1;
		else
			w[i + 1] = w[i];
	int ans = 2e5;
	for (int i = 0; i <= n; i++)
		ans = min(ans, w[i] + n - i - (w[n] - w[i]));
	cout << ans << endl;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> start(n + 1), end(n + 1);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        start[a].push_back(i);
        end[b].push_back(i);
    }
    unordered_set<int> s, f;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int fg = 0;
        for (auto x: end[i]) {
            if (f.find(x) == f.end()) {
                fg = 1;
                break;
            }
        }
        if (fg) {
            ans++;
            for (auto x: s) {
                f.insert(x);
            }
            s.clear();
        }
        for (auto x: start[i]) {
            s.insert(x);
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 15916
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define REPB(i,n) for(long long i=((n)-1);i>=0;i--)
#define REPB1(i,n) for(long long i=(n);i>0;i--)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();ite++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
typedef long long ll;
typedef pair<int,int> pii;
//---------------------
#define MAXN 50
//---------------------
int dx[]={0,1,1,1,0,-1,-1,-1};
int dy[]={-1,-1,0,1,1,1,0,-1};
string s[50];
int num[50][50];
int h,w;

void addnum(int x,int y){
	if(x<0||y<0||x>=h||y>=w) return;
	num[x][y]+=1;
}

int setbomb(int x,int y){
	REP(i,8) addnum(x+dx[i],y+dy[i]);
}

int main(){
  	memset(num,0,sizeof(num));
	cin>>h>>w;
	REP(i,h) cin>>s[i];
	
	REP(i,h){
		REP(j,w){
			char c=s[i][j];
			if(c=='#') setbomb(i,j);	  
		}
	}
	REP(i,h){
		REP(j,w){
			char c=s[i][j];
			if(c=='#') cout<<'#';
			else cout<<num[i][j];
		}
		cout<<endl;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n){ cin >> x[i]; }
  ll ans=longinf;  
  rep(i,101){
    ll tmp=0;
    rep(j,n){
      tmp += (x[j]-i)*(x[j]-i);
    }
    ans = min(ans,tmp);
  }

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

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  rep(i, n) {
    if (i == 0)
      h[i]--;
    else if (h[i - 1] <= h[i] - 1)
      h[i]--;
    else if (h[i - 1] > h[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 640
A,B,M = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

def calc_money(x, y, c):
  return A_list[x-1] + B_list[y-1] - c

money = 10**7
for i in range(M):
  x, y, c = map(int, input().split())
  tmp_money = calc_money(x, y, c)
  if tmp_money < money:
    money=tmp_money
print(min(money,min(A_list)+ min(B_list)))



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

int main() 
{
    int A,B;
    cin >> A >> B;
    if (A%3==0 || B%3==0 || (A+B)%3==0) {
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
}

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

namespace abc090b
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split();
            var a = int.Parse(ab[0]);
            var b = int.Parse(ab[1]);
            var palindromic = 0;
            for (var i = a; i <= b; ++i) {
                var s = i.ToString();
                if (s.SequenceEqual(s.Reverse()))
                    palindromic++;
            }
            Console.WriteLine(palindromic);
        }
    }
}


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

int main() {
  string a;
  cin>>a;
  int b,c,d,e;
  c=103;
  d=101;
  e=0;
  b=a.size();
  for(int i=0;i<b;i++){
    if(a.at(i)=='C'){
      c=i;
    }
    else if(a.at(i)=='F'){
      d=i;
    }
    if(c<d&&d<101){
      e++;
    }
  }
  if(e>0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

int main() {
	 int N;
	 cin >> N;
	 long long a=2, b=1, ans=0;
	 if (N==1){
	     cout << 1 << endl;
	     return 0;
	 }
	 for (int i=1; i<N; i++){
	     ans=a+b;
	     a=b;
	     b=ans;
	 }
	 cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inv_num_valtype int

//比較関数
int compare(inv_num_valtype a, inv_num_valtype b){
	return a - b;
}

//昇順
int inv_num_sub(inv_num_valtype *origin, int left, int right, inv_num_valtype *tmp){
	int ans = 0;
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		ans += inv_num_sub(origin, left, half, tmp);
		ans += inv_num_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				ans += k - i;
				k++;
			}
		}
	}
	return ans;
}

//i < j && a[i] > a[j] となる組(i, j)の数
//effect: sortされる
int inv_num(inv_num_valtype *origin, int N){
	inv_num_valtype *tmp = (inv_num_valtype *)malloc(sizeof(inv_num_valtype) * N);
	return inv_num_sub(origin, 0, N, tmp);
}

int main(){
	int N, i;
	scanf("%lld", &N);
	int *p = (int *)malloc(sizeof(int) * N);
	int N1 = (N + 1) / 2, N2 = N / 2;
	int *p_even = (int *)malloc(sizeof(int) * N1);
	int *p_odd = (int *)malloc(sizeof(int) * N2);
	for(i = 0; i < N; i++){
		scanf("%lld", &p[i]);
		p[i]--;
		if(i % 2 == 0){
			p_even[i / 2] = p[i];
		}
		else{
			p_odd[i / 2] = p[i];
		}
	}
	for(i = 0; i < N; i++){
		if(i % 2 != p[i] % 2){
			printf("No\n");
			return 0;
		}
	}
	int p_inv_num = inv_num(p, N);
	if(p_inv_num % 3 != 0){
		printf("No\n");
		return 0;
	}
	if(p_inv_num / 3 != inv_num(p_even, N1) + inv_num(p_odd, N2)){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 9600
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair <int, int> pr;
priority_queue <pr> qua;
char s[105], t[105];
bool flg;

int main() {
	scanf("%s %s", s, t);
	int l = strlen(s);
	for(int i = 0; i < l; i++) {
		if(t[i] == s[0]) {
			flg = 1;
			for(int j = i, k = 0; j < l, k <= l - 1 - i; j++, k++) {
				if(s[k] != t[j]) {
					flg = 0; break;
				}
			}
			for(int j = 0, k = l - i; j < i, k < l; j++, k++) {
				if(s[k] != t[j]) {
					flg = 0; break;
				}
			}
		}
		if(flg) break;
	}
	if(flg) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
S = [input() for i in range(N)]

ctr = Counter()
ans = 0
for s in S:
    a = "".join(sorted(list(s)))#1文字ずつのリストにしてソートして文字列に戻している
    #print(a)
    if a in ctr:
        ans += ctr[a]#個数を数えている
        #print(ctr)
    ctr[a] += 1
print(ans)



Measured memory_bytes: 74328