akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
const int MOD = 1e9 + 7;
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 1e5 + 5;

int n, m, x[maxn], y[maxn];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> x[i];
    for(int i = 0; i < m; i++)
        cin >> y[i];
    sort(x, x + n);
    sort(y, y + m);
    int xlensum = 0, ylensum = 0;
    for(int i = 0; i < n; i++)
    {
        xlensum += (i * x[i]) % MOD;
        xlensum -= ((n - 1 - i) * x[i]) % MOD;
        xlensum += MOD;
        xlensum %= MOD;
    }
    for(int i = 0; i < m; i++)
    {
        ylensum += (i * y[i]) % MOD;
        ylensum -= ((m - 1 - i) * y[i]) % MOD;
        ylensum += MOD;
        ylensum %= MOD;
    }
    cout << (xlensum * ylensum) % MOD << "\n";
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> ii;

int main()
{
    // 10010010
    // 10110010101
    char inp[100010];
    scanf("%s", inp);
    int ans = INT_MAX, n = strlen(inp);
    int cnt = 0, cnt2 = 0;
    for (int i = 0; i < n; i++) {
        if (inp[i] == '0' && i % 2 == 1)
            cnt++;
        else if (inp[i] == '1' && i % 2 == 0)
            cnt++;

        if (inp[i] == '0' && i % 2 == 0)
            cnt2++;
        else if (inp[i] == '1' && i % 2 == 1)
            cnt2++;
    }

    ans = min(cnt, cnt2);

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main (void) {
    int A, B, K, x;

    scanf ("%d%d%d", &K, &A, &B);

    x = B / K;

    if (x*K >= A) {
        printf("OK");
    } else {
        printf("NG");
    }

    return 0;
}

Measured memory_bytes: 1684
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
#include <algorithm>
#include <functional>
//#include<stdlib.h>
using namespace std;


int main() {
	int a, b, c;
	cin >> a>>b>>c;
	a -= b; c -= a;
	cout << ((c>=0)?c:0);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [list(map(int, input().split())) for i in range(2)]

dp = [[0 for i in range(2)] for j in range(n)]
dp[0][0] = a[0][0]
dp[0][1] = a[0][0] + a[1][0]

for i in range(n-1):
    dp[i+1][0] = dp[i][0] + a[0][i+1]
    dp[i+1][1] = max(dp[i][1] + a[1][i+1], dp[i+1][0] + a[1][i+1])

print(dp[n-1][1])

Measured memory_bytes: 3064
use std::cmp::min;

fn main() {
    let vec = read_line();
    let n = vec[0];
    let m = vec[1];

    let vec = read_lines(m);
    let mut a = vec![];
    let mut b = vec![];
    let mut c = vec![];
    let mut dist = vec![vec![0; 100]; 100];    
    for v in vec {
        a.push(v[0] - 1);
        b.push(v[1] - 1);
        c.push(v[2]);
    }

    // すべての頂点について辞書をつくる
    for i in 0..n as usize {
        for j in 0..n as usize {
            if i == j {
                dist[i][j] = 0;
            } else {
                dist[i][j] = 100000000; // INF
            }
        }
    }

    // 辞書に移動距離を埋める
    for i in 0..m as usize {
        let idx_ai = a[i] as usize;
        let idx_bi = b[i] as usize;
        dist[idx_ai][idx_bi] = min(dist[idx_ai][idx_bi], c[i]);
        dist[idx_bi][idx_ai] = min(dist[idx_bi][idx_ai], c[i]);
    }

    for k in 0..n as usize {
        for i in 0..n as usize {
            for j in 0..n as usize {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    let mut ans = m;
    for i in 0..m as usize {
        let mut shortest = false;
        for j in 0..n as usize {
            if dist[j][a[i] as usize] + c[i] == dist[j][b[i] as usize] {
                shortest = true;
            }
        }
        if shortest {
            ans -= 1;
        }
    }

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

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

fn read_lines(n : i32) -> Vec<Vec<i32>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim()
            .split_whitespace()
            .map(|e| e.parse().ok().unwrap())
            .collect();
        v2.push(v);
    }
    v2
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  map<int,int> mp;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    mp[a]++;
  }
  for(auto m: mp){
    if(m.second >= 3){
      if(m.second%2){
        mp[m.first] = 1;
      }else{
        mp[m.first] = 2;
      }
    }
  }
  int ans = 0;
  int cnt = 0;
  for(auto m: mp){
    if(m.second == 2){
      cnt++;
    }
    ans++;
  }
  if(cnt%2){
    cout << ans-1 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x);
#define CMIN(m, x)  m = min(m,x);
#define itn int
typedef long long lint;
const int INF = 1e9;
const lint LINF = 1e18;
int main(){
    int n;
    cin >> n;
    lint sum = 0;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);

    REP(i,n)
        cin >> a[i]; 
    REP(i,n)
        cin >> b[i]; 
    REP(i,n)
        cin >> c[i]; 
    
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    
    REP(i,n){
        lint csize = distance(upper_bound(ALL(c),b[i]),c.end());
        lint asize = distance(a.begin(),lower_bound(ALL(a),b[i]));
        sum += csize * asize;
    }
    cout << sum << endl;
    return 0;
   }

Measured memory_bytes: 1536
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  int A[N];
  ll result = 0;
  REP(i,N){
    cin >> A[i];
    result += A[i]-1;
  }

  cout << result << endl;


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int n, m, p;
int dst[10000];

int CWDist ( int s, int e ) { return (e - s + n)%n; }
int CCWDist ( int s, int e ) { return (s - e + n)%n; }

int CWNext ( int i ) { return i == m-1 ? dst[0] : dst[i+1]; }
int CCWNext ( int i ) { return i == 0 ? dst[m-1] : dst[i-1]; }

int CWTurn ( int p, int t, int e ) { return CWDist( p, t ) + CCWDist( t, e ); }
int CCWTurn ( int p, int t, int e ) { return CCWDist( p, t ) + CWDist( t, e ); }

int main() {

    int i, j, s = 0, cwNext, ccwNext, dist, tmp;
    scanf("%d %d %d", &n, &m, &p);
    
    for ( i=0; i<m; ++i ) scanf("%d", &dst[i]);
    for ( i=0; i<m; ++i ) {
	for ( j=i+1; j<m; ++j ) {
	    if ( dst[i] > dst[j] ) {
		tmp = dst[i];
		dst[i] = dst[j];
		dst[j] = tmp;
	    }
	}
    }

    while ( s < m ) {
	if ( dst[s] > p ) break;
	++s;
    }
    
    cwNext  = s == m ? dst[0] : dst[s];
    ccwNext = s == 0 ? dst[m-1] : dst[s-1];

    dist = CCWDist(p, cwNext);
    tmp = CWDist(p, ccwNext);
    if ( tmp < dist ) dist = tmp;

    for ( i=0; i<m; ++i ) {
	tmp = CWTurn(p, dst[i], CWNext(i));
	if ( tmp < dist ) dist = tmp;
	tmp = CCWTurn(p, dst[i], CCWNext(i));
	if ( tmp < dist ) dist = tmp;
    }

    printf("%d\n", 100*dist);
    return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,f,g,r[10000];
    while(cin>>a)
    {
        cin>>b>>c;
        for(d=1;d<=a;d++)
        {
            cin>>r[d];
        }
        g=0;
        for(d=1;d<=a;d++)
        {

            e=1;
            while(1)
            {
                f=((e-1)*r[d])+1;
                if(f<=b)
                {
                    g++;
                }
                if(f>b)
                {
                    break;
                }

              e++;
            }



        }
        cout<<g+c<<endl;



    }



    return 0;
}


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

struct Dice {
 public:
  vector<int> num = vector<int>(6);
  vector<int> tmp = vector<int>(6);

  void Roll(char ch) {
    tmp = num;
    if (ch == 'S') {
      num.at(0) = tmp.at(4);
      num.at(1) = tmp.at(0);
      num.at(2) = tmp.at(2);
      num.at(3) = tmp.at(3);
      num.at(4) = tmp.at(5);
      num.at(5) = tmp.at(1);
    } else if (ch == 'W') {
      num.at(0) = tmp.at(2);
      num.at(1) = tmp.at(1);
      num.at(2) = tmp.at(5);
      num.at(3) = tmp.at(0);
      num.at(4) = tmp.at(4);
      num.at(5) = tmp.at(3);

    } else if (ch == 'N') {
      num.at(0) = tmp.at(1);
      num.at(1) = tmp.at(5);
      num.at(2) = tmp.at(2);
      num.at(3) = tmp.at(3);
      num.at(4) = tmp.at(0);
      num.at(5) = tmp.at(4);

    } else if (ch == 'E') {
      num.at(0) = tmp.at(3);
      num.at(1) = tmp.at(1);
      num.at(2) = tmp.at(0);
      num.at(3) = tmp.at(5);
      num.at(4) = tmp.at(4);
      num.at(5) = tmp.at(2);
    }
  }
  void Print() { cout << num.at(0) << endl; }
  void Print(int n) {
    for (int i = 0; i < n; i++) {
      cout << num.at(i) << " ";
    }
    cout << endl;
  }
};

int main() {
  Dice D;
  for (int i = 0; i < 6; i++) {
    cin >> D.num.at(i);
  }
  string str;
  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    char ch = str.at(i);
    D.Roll(ch);
  }
  D.Print();
}


Measured memory_bytes: 3180
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

int main() {
    deque<char>S;
    SS(string,s);
    rep(i,s.size())S.emplace_back(s[i]);
    bool fb=false;
    SS(ll,Q)
    rep(i,Q){
        SS(int,q)
        if(q==1)if(!fb)fb=true; else fb=false;
        if(q==2){
            SS(int,f);SS(char,c);
            if(fb==false){
               if(f==1)S.push_front(c);
               else S.push_back(c);
            }else{
                if(f==1)S.push_back(c);
                else S.push_front(c);
            }
        }
    }
    ll limit=S.size();
    rep(i,limit){
        if(fb==false){
            cout<<S.front();
            S.pop_front();
        }else{
            cout<<S.back();
            S.pop_back();
        }
    }
}

Measured memory_bytes: 976
n, t = map(int, input().split())
a = [0]
b = [0]
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

dp1 = [[0] * t for _ in range(n+2)]
dp2 = [[0] * t for _ in range(n+2)]

for i in range(n):
    for j in range(t):
        if a[i+1] > j:
            dp1[i+1][j] = dp1[i][j]
        else:
            dp1[i+1][j] = max(dp1[i][j], dp1[i][j-a[i+1]] + b[i+1])

for i in range(n+1, 1, -1):
    for j in range(t):
        if a[i-1] > j:
            dp2[i-1][j] = dp2[i][j]
        else:
            dp2[i-1][j] = max(dp2[i][j], dp2[i][j-a[i-1]] + b[i-1])

ans = 0
for i in range(1, n+1):
    for j in range(t):
        total = b[i] +dp1[i-1][j] + dp2[i+1][t-1-j]
        ans = max(ans, total)
print(ans)

Measured memory_bytes: 178308
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

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



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	int num[200000] = {};
	for (int i = 0; i < N; i++) {
		cin >> num[i];
	}
	for (int i = 1; i < N; i++) {
		if (num[i - 1] == i) {
			swap(num[i - 1], num[i]);
			M++;
		}
	}
	for (int i = N - 1; i > 0; i--) {
		if (num[i] == i + 1) {
			swap(num[i - 1], num[i]);
			M++;
		}
	}
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 1024
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    int n;
    cin>>n;
    vll s(n);
    rep(i,n)cin>>s[i];
    ll ans=0;
    ll num=0;
    sort(all(s));
    for(int i=0;i<n;i++){
        num+=s[i];
    }

    ans=num;

    if(num%10==0){
        rep(i,n){
            if(s[i]%10!=0){
                ans=num-s[i];
                break;
            }
        }
    }

    if(ans%10==0)ans=0;


    cout<<ans<<endl;
    return 0;

}

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

int main()
{
	int n, d;
	cin >> n >> d;
	auto x = vector<vector<long long int>>(n, vector<long long int>(d));
	for(auto&& y : x){
		for(auto&& z : y){
			cin >> z;
		}
	}
	int ans = 0;
	for(auto i = 0; i < n - 1; ++i){
		for(auto j = i + 1; j < n; ++j){
			long long int sum = 0;
			for(auto k = 0; k < d; ++k){
				sum += ((x[i][k] - x[j][k]) * (x[i][k] - x[j][k]));
			}
			bool match = false;
			long long int l, r;
			l = 1;
			r = 10000000;
			while(l <= r){
				long long int m = (l + r) / 2;
				if(m * m == sum){
					match = true;
					break;
				}
				if(m * m < sum){
					l = m + 1;
				}else{
					r = m - 1;
				}
			}
			if(match) ++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# copy
# https://beta.atcoder.jp/contests/arc097/submissions/2509168

N = int(input())
balls = []
for _ in range(2 * N):
    c, a = input().split()
    balls += [(c, int(a))]

# numB[i][b]: 初期状態において、i番目の玉より右にある、1～bが書かれた黒玉の数
numB = [[0] * (N + 1) for _ in range(2 * N)]
numW = [[0] * (N + 1) for _ in range(2 * N)]
for i in reversed(range(1, 2 * N)):
    c, a = balls[i]
    numB[i - 1] = list(numB[i])
    numW[i - 1] = list(numW[i])
    if c == 'B':
        for b in range(a, N + 1):
            numB[i - 1][b] += 1
    else:
        for w in range(a, N + 1):
            numW[i - 1][w] += 1

# costB[b][w]: 黒玉1～b、白玉1～wのうち、初期状態において、黒玉[b+1]より右にある玉の数
costB = [[0] * (N + 1) for _ in range(N + 1)]
costW = [[0] * (N + 1) for _ in range(N + 1)]
for i in reversed(range(2 * N)):
    c, a = balls[i]
    if c == 'B':
        cost = numB[i][a - 1]
        for w in range(N + 1):
            costB[a - 1][w] = cost + numW[i][w]
    else:
        cost = numW[i][a - 1]
        for b in range(N + 1):
            costW[b][a - 1] = cost + numB[i][b]

INF = 10 ** 9 + 7
# dp[b][w]: 黒玉1-b, 白玉1-wまで置いたときの転倒数の最小値
dp = [[INF] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 0
for b in range(N + 1):
    for w in range(N + 1):
        if b > 0:
            dp[b][w] = min(dp[b][w], dp[b - 1][w] + costB[b - 1][w])
        if w > 0:
            dp[b][w] = min(dp[b][w], dp[b][w - 1] + costW[b][w - 1])

print(dp[N][N])

Measured memory_bytes: 284420
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		if(A > B) {
			System.out.println(A + (A-1));
		}else if(A == B) {
			System.out.println(A + B);
		}else {
			System.out.println(B + (B-1));
		}
	}

}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0) break;
			int[] data = new int[26];
			String gomi=sc.nextLine();
			String l=sc.nextLine();
			String[] l2=l.split(" ");
			String line="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			int rem=n;
			boolean flag=true;
			for(int i=0;i<n;++i){
				data[line.indexOf(l2[i])]++;
				rem--;
				int max=max(data),count=0,num=0;
				for(int j=0;j<26;++j){
					if(max<=data[j]+rem){
						count++;
						if(count==1) num=j;
					}
				}
				if(count==1){
					System.out.println(line.charAt(num)+" "+(n-rem));
					i=n;
					flag=false;
				}
			}
			if(flag==true) System.out.println("TIE");
		}
	}
	public static int max(int[] data){
		int num=data[0];
		for(int i=1;i<26;++i){
			num=Integer.max(num, data[i]);
		}
		return num;
	}
}



Measured memory_bytes: 51692
n = io.read("*n", "*l")
s = io.read()
k = io.read("*n")
a = string.sub(s, k, k)
dst = "";
for i = 1, n do
  if(string.sub(s, i, i) == a) then dst = dst .. a else dst = dst .. "*" end
end
print(dst)


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

using namespace std;


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

    map<long,int> mp;

    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin>>tmp;

        mp[tmp]++;
    }

    int ans=0;

    for(auto itr=mp.begin();itr!=mp.end();itr++){
        if(itr->second%2){
            ans++;
        }
    }
    
    cout<<ans<<endl;


}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <queue>

//#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int, int> P;
#define int long long

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

template<class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int INF = 1LL << 60;
const int MAX_N = 110;
const int MAX_V = 100100; // vの最大値 * N
int dp[MAX_N][MAX_V]; //  i-1 番目までの品物から価値が sum_v 以上を達成するように選んだときの、重さの総和 sum_w の最小値
int weights[MAX_N], values[MAX_N];

signed main() {
    int N, W; cin >> N >> W;
    for (int i = 0; i < N; i++) {
        cin >> weights[i] >> values[i];
    }

    // 初期化
    for (int i = 0; i < MAX_N; i++) {
        for (int j = 0; j < MAX_V; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int v = 0; v < MAX_V; v++) {
            // i 番目の品物を選ぶ場合
            if (v - values[i] >= 0) {
                chmin(dp[i + 1][v], dp[i][v - values[i]] + weights[i]);
            }

            // i 番目の品物を選ばない場合
            chmin(dp[i + 1][v], dp[i][v]);
        }
    }

    int ans = 0;
    for (int v = 0; v < MAX_V; v++) {
        // W以下を満たす価値の総和の最大値
        if (dp[N][v] <= W) {
            ans = v;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 86272
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    ans = 0
    for i in range(n):
        a,b = f()
        ans += b- a+1
    
    print(ans)

solve()


Measured memory_bytes: 3060
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
    fun main(args: Array<String>) {
        val (n, m) = longList()
        when {
            n >= 3 && m >= 3 -> {
                val count = (n - 2) * (m - 2)
                println(count.toString())
            }
            else -> {
                if (n == 2L || m == 2L) {
                    println("0")
                } else if (n == 1L && m == 1L) {
                    println("1")
                } else if (n == 1L) {
                    println("${m - 2L}")
                } else if (m == 1L) {
                    println("${n - 2L}")
                }
            }
        }
    }


Measured memory_bytes: 37896
from collections import deque
s = deque(input())
q = int(input())
state = 0
for i in range(q):
    query = input().split()
    if query[0] =="1":
        state +=1
    else:
        if (int(query[1])+state)%2 == 1:
            s.appendleft(query[2])
        else:
            s.append(query[2])
if state%2 == 1:
    s.reverse()
print("".join(s))

Measured memory_bytes: 8428
#include <stdio.h>
typedef long long ll;

ll n;
char s[20];

void dfs(ll a, char c) {
  if(a == n) {
    printf("%s\n", s);
    return;
  }
  ll i;
  for(i = 'a'; i <= c; ++i) {
    s[a] = i;
    dfs(a + 1, c);
  }
  s[a] = c + 1;
  dfs(a + 1, c + 1);
}

int main(void) {
  scanf("%lld", &n);
  s[0] = 'a', s[n] = 0;
  dfs(1, 'a');
  return 0;
}

Measured memory_bytes: 1408
/*
 * AOJ 0118: Property Distribution
 * 题意：m＊n矩阵中，共3种植物。相邻的同种植物块可合并，问合并后共多少块区域。
 * 类型：DFS＋记忆化搜索（／BFS／并查集）
 * 算法：从某点出发，向上下左右4个方向查询，若为同种植物则继续递归，经过的点需要记忆化。
 */

#include <cstdio>
#include <iostream>

using namespace std;


// char mat[100][100];
// int dirs[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
// int m, n, res;

// void dfs(int x, int y) {
//   char t = mat[x][y];
// 	mat[x][y] = '.';  //标记，标记过的就是一个连通区域了
// 	int xx, yy;
// 	for (int i = 0; i < 4; i++) {
// 		xx = x + dirs[i][0];
// 		yy = y + dirs[i][1];
// 		if (xx >= 0 && xx < m && yy >= 0 && yy < n && mat[xx][yy] == t) {
// 			dfs(xx, yy);
// 		}
// 	}
// }

// void solve() {
// 	res = 0;
// 	for (int i = 0; i < m; i++) cin >> mat[i];
// 	for (int i = 0; i < m; i++) {
// 		for (int j = 0; j < n; j++) {
//       if (mat[i][j] != '.') {
//         res++;
//         dfs(i, j);
//       }
// 		}
// 	}
// }

// int main() {
// 	while (cin >> n >> m && m > 0 && n > 0) {
// 		solve();
// 		cout << res << endl;
// 	}
// 	return 0;
// }




char mat[102][102];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int m, n;
int ans;

void dfs(int x, int y) {
  char t = mat[x][y];
  mat[x][y] = '.';
  for (int i = 0; i < 4; ++i) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (xx >= 0 && xx < m && yy >= 0 && yy < n && mat[xx][yy] == t) {
      dfs(xx, yy);
    }
  }
}

void solve() {
  ans = 0;
  for (int i = 0; i < m; ++i) {
    cin >> mat[i];
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      if (mat[i][j] != '.') {
        ++ans;
        dfs(i, j);
      }
    }
  }
}

int main() {
  while (cin >> m >> n && n > 0 && m > 0) {
    solve();
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3568
#include<cstdio>
typedef long long ll;
const int N=203,K=60;
int n,k;ll a[N],f[K];char s[N];
inline void Insert(ll a){
	for(int j=K-1;~j;j--)if(a>>j&1)
	  if(f[j])a^=f[j];
	  else{f[j]=a;return;}
}
inline bool Find(ll a){
	for(int j=K-1;~j;j--)if(a>>j&1)
	  if(f[j])a^=f[j];
	  else return 0;
	return 1;
}
int main(){
	int T;scanf("%d",&T);for(;T--;){
	k=0;
	for(int i=0;i<K;i++)f[i]=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%lld",a+i);
	scanf("%s",s+1);
	for(int i=n;i;i--){
	  if(s[i]=='0')Insert(a[i]);
	  if(s[i]=='1'&&!Find(a[i])){puts("1");goto Brk;}
	}
	puts("0");
	Brk:;
	}return 0;
}

Measured memory_bytes: 1648
def main():
    h, w = [int(e) for e in input().split()]
    s = [input() for i in range(h)]

    ans = ''
    for hi in range(1, h + 1):
        for wi in range(1, w + 1):
            c = convert(s, hi, wi)
            ans += c

        ans += '\n'

    print(ans, end='')


def convert(s, hi, wi):
    if s[hi - 1][wi - 1] == '#':
        return '#'

    count = 0
    for dh in [-1, 0, 1]:
        for dw in [-1, 0, 1]:
            hp = hi + dh
            wp = wi + dw
            if hp < 1 or hp > len(s) or wp < 1 or wp > len(s[0]) or s[hp - 1][wp - 1] == '.':
                continue
            if s[hp - 1][wp - 1] == '#':
                count += 1

    return str(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41328
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int a,b,c;
int main()
{
int ans=0;
	cin>>a>>b>>c;
 for(int i=a;i<=b;i++){
 if(c%i==0) ans++;
}
cout<<ans<<endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int main(){

    int N;
    cin>>N;

    int sum=0;

    for(int i=0;i<N;i++){
        int lx,rx;
        cin>>lx>>rx;
        sum+=rx-lx+1;
    }

    cout<<sum;
}


Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    string a;
    sf(n);
    cin>>a;
    if(n%2==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        bool flag = false;
        for(i=0,j=n/2;i<n/2;i++,j++)
        {
            if(a[i]!=a[j])
            {
                flag = true;
                break;
            }
        }
        if(flag)
        {
            cout<<"No"<<endl;
        }
        else cout<<"Yes"<<endl;
    }
    return 0;
}



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

int main(){
    ll h,w;
    cin >> h >> w;
    if(h==1||w==1){
        cout << 1 << endl;
    }else if(h%2==0){
        cout << h*w/2 << endl;
    }else{
        cout << h/2*w + (w+1)/2 << endl;
    }
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int L;
int tw[22];
vint u, v, w;
signed main() {
    tw[0] = 1;
    for (int i = 1; i < 22; i++)tw[i] = tw[i - 1] * 2;
    cin >> L;

    int N = 1;
    for (int i = 0; i < 20; i++) {
        if (tw[i + 1] > L)break;

        N++;
        u.push_back(i + 1);
        v.push_back(i);
        w.push_back(tw[i]);

        u.push_back(i + 1);
        v.push_back(i);
        w.push_back(0);
    }
    int cur = tw[N - 1];
    L -= cur;

    for (int i = 0; i <= 20; i++) {
        if (L % 2 == 1) {
            u.push_back(N - 1);
            v.push_back(i);
            w.push_back(cur);
            cur += tw[i];
        }
        L /= 2;
    }


    cout << N << endl;
    cout << u.size() << endl;
    for (int i = 0; i < u.size(); i++) {
        cout << N - u[i] << " " << N - v[i] << " " << w[i] << endl;
    }
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
cs = [0]*9
for a in A:
    if a >= 3200:
        cs[8] += 1
    else:
        cs[a//400] += 1

fixed = 0
for i in range(8):
    if cs[i]: fixed += 1

if fixed:
    print(fixed, fixed + cs[8])
else:
    print(1, cs[8])

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
    int n,t;
    scanf("%d",&n);
    t=n%10;
    if(t==2||t==4||t==5||t==7||t==9) printf("hon");
    if(t==0||t==1||t==6||t==8) printf("pon");
     if(t==3) printf("bon");
     return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define eps 0.000001
#define ll long long
#define INF 1e18
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define uint unsigned int

const int N = 200000+5;

int h[N];
ll a[N];
ll f[N];
void upd(int x, ll val)
{
	while( x < N)
	{
		f[x] = max(f[x],val);
		x += x&(-x);
	}
}

ll get(int x)
{
	ll ans = 0;
	while(x > 0)
	{
		ans = max(ans,f[x]);
		x -= (x)&(-x);
	}
	return ans;
}

main()
{ 
	SPEED;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for(int i = 0; i<n; i++)
	{
		cin >> h[i];
	}
	for(int i = 0; i<n; i++)
	{
		cin >> a[i];
	}
	ll mx = 0;
	for(int i = 0; i<n; i++)
	{
		ll v = get(h[i]);
		upd(h[i],v+a[i]);
		mx = max(mx, v + a[i]);
	}
	cout << mx << endl;
}

Measured memory_bytes: 4224
#include <stdio.h>
    int main(){
    	int n;
      	scanf("%d" , &n);	
      	char a[10000];
      	scanf("%s" , a);
      	int i = 0;	
      if(n%2==1){
      	  printf("No");
          return 0;
        	
      }
      for( i = 0 ; i < n/2 ; i++){
        	if(a[i] != a[n/2 + i]){
            	printf("No");
              	return 0;
        	}
        }
        printf("Yes");
              	       
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
    return;
}
int gdc(int a, int b) {
    int r;
    if (a < b)
        swap(&a, &b);
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main() {
    int a,b;
    scan2Int(a,b);
    if (a > 9 || b > 9) {
        printInt(-1);
        return 0;
    }
    printInt(a*b);
    return 0;
}

Measured memory_bytes: 3784
#define _USE_MATH_DEFINES
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;

int main() {
	
	int n;
	string w[105];

	cin >> n;

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

		if (s[s.size() - 1] != t[0]) {
			cout << "No" << endl;
			return 0;
		}
		for (int j = 0; j < n; j++)
		{
			if (i != j) {
				if (w[i] == w[j]) {
					cout << "No" << endl;
					return 0;
				}
			}

		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
W = [input() for i in range(N)]
sW = list(set(W))

if len(W) != len(sW):
    print('No')
else:
    for i in range(N):
        if i == N-1:
            print('Yes')
            break
        if W[i][-1] is not W[i+1][0]:
            print('No')
            break


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


int main() {
	int n, m, l; cin >> n >> m >> l;
	long long sp[n + 1][n + 1], G[n + 1][n + 1];
	for(int i = 0 ; i <= n ;i ++){
		for(int j = 0 ; j <= n ; j ++){
			sp[i][j] = 1e18;
			G[i][j] = 1e18;
		}
	}
	for(int i = 0 ; i <= n ; i ++ ){
		sp[i][i] = 0;
	}
	for(int i = 0 ; i < m ; i ++ ) {
		int x, y, z; cin >> x >> y >> z;
		sp[x][y] = z , sp[y][x] = z;
	}
	
	for(int k = 1; k <= n ;k ++) {
		for(int i = 1; i <= n ;i ++ ){ 
			for(int j = 1 ; j <= n ;j ++) {
				sp[i][j] = min(sp[i][j], sp[i][k] + sp[k][j]);
			}
		}
	}
	
	for(int i = 0 ; i <= n ;i ++ ) {
		for(int j = 0 ;j <= n ; j ++ ) {
			if(sp[i][j] <= l) G[i][j] = 1;
		}
	}
	
	for(int k = 1 ; k <= n ;k ++ ){
		for(int i = 1; i <= n ;i ++){
			for(int j = 1; j <= n ; j ++){
				G[i][j] = min(G[i][j] , G[i][k] + G[k][j]);
			}
		}
	}
	
	int q; cin >> q;
	while(q--){
		int a , b; cin >> a >> b;
		cout << (G[a][b] == 1e18 ? -1 : G[a][b] - 1) << '\n';
	} 
}


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

int main() {
  int K;
  cin >>K;
  int ans=0;
  cin >>ans;
  for (int i = 1; i < K+1; i++) {
    for (int j = 1; j < K+1; j++) {
      for (int t = 1; t < K+1; t++) {
        
        
      ans+=   __gcd(t,__gcd(i, j) );
}
 
}
 
}
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
int fun(int arr[],int n,int k)
{
  vector<int>dp(n,0);
  dp[0]=0;
  dp[1]=abs(arr[0]-arr[1]);
  for(int i=2;i<n;i++)
  {
     int ans = INT_MAX;
     for(int j=1;j<=i&&j<=k;j++)
     {
        ans=min(ans,dp[i-j]+abs(arr[i-j]-arr[i]));
     }
     dp[i]=ans;
  }  
  return dp[n-1];
}
int main()
{
  int n,k;
  cin >>n>>k;
  int *arr = new int[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  cout<<fun(arr,n,k);
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
using namespace std;
int n,m,d,k,q,l,r,x[100001],y[100001],sum[100001];
int dist(int a,int b)
{
	return abs(x[a]-x[b])+abs(y[a]-y[b]);
}
int main()
{
	scanf("%d%d%d",&n,&m,&d);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			scanf("%d",&k);
			x[k]=i;
			y[k]=j;
		}
	for (int i=d+1;i<=n*m;i++)sum[i]=sum[i-d]+dist(i-d,i); 
	scanf("%d",&q);
	for (int i=1;i<=q;i++)
	{
		scanf("%d%d",&l,&r);
		printf("%d\n",sum[r]-sum[l]);
	}
}

Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	vector<int> cnt(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
		cnt.at(i) = vec.at(i) % 4;
	}
	int A = 0;
	int B = 0;
	for(int i = 0;i < N;i++) {
		if(cnt.at(i) == 0) {
			A++;
		}
		else if(cnt.at(i) == 2) {
			B++;
		}
	}
	if(N / 2 <= A) {
		cout << "Yes" << endl;
	}
	else {
		N = N - A * 2;
		if(N <= B && B != 1) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}


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

int main() {
    ll n;
    cin>>n;
    ll num[n];
    for (int i = 0; i < n; ++i) {
        cin>>num[i];
    }
    ll count=n;
    sort(num,num+n);
    ll now=num[0];
    for (int j = 0; j < n-1; ++j) {
        //cout<<now<<endl;
        if(num[j+1]>now*2)count=n-j-1;
        now+=num[j+1];
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e19;
/*ll power(ll x,ll y,ll m)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%m;
        x=(x*x)%m;
        y=y/2;
    }
    return res;
}*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,m,i,x;
    set<ll>s;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>m;
        s.insert(m);
    }
    if(s.size()==n)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 9600
N,M = map(int,input().split(" "))
pathway = [[] for i in range(N)]
for i in range(M):
    A,B = map(int,input().split(" "))
    pathway[A-1].append(B-1)
    pathway[B-1].append(A-1)
visit = [0 for i in range(N)]
guide = [-1 for i in range(N)]
point = [0]
while True:
    next_point = []
    for i in point:
        for j in pathway[i]:
            if visit[j]==0:
                guide[j] = i
                visit[j] = 1
                next_point.append(j)
    point = next_point
    if len(point) == 0:
        break
print("Yes")
for i in range(1,N):
    print(guide[i]+1)


Measured memory_bytes: 107228
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;

char s[maxn];int len;
void solve(){
	int yu1 = 0,yu2 = 0;
	for(int i = 1;i<=len;i++){
		yu1 = (yu1*10 + s[i]-'0')%9;
		yu2 = (yu2 + s[i]-'0')%9; 
	}
	if(yu1 == 0 && yu2 == 0) cout<<"Yes\n";
	else cout<<"No\n";
}
int main(){
	// debug;
	ios;

	cin>>(s+1);
	len = strlen(s+1);
	solve();
	
	return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  cin >> N;
  cout << N*N*N << endl;
  return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> syu;
    for(int i = 1; i < n; i++){
        int count = 0;
        string x = s.substr(0,i);
        string y = s.substr(i);
        //初期化チェック
        vector<char> str;
        vector<char> str2;
        for(int o = 0; o < x.length(); o++){
            str.push_back(x[o]);          
        }
        for(int p = 0; p < y.length(); p++){
            str2.push_back(y[p]);          
        } 
        sort(str.begin(), str.end());
        str.erase(unique(str.begin(), str.end()), str.end());
        sort(str2.begin(), str2.end());
        str2.erase(unique(str2.begin(), str2.end()), str2.end());

        
        for(int k=0; k < str.size(); k++){
            for(int l=0; l < str2.size();l++){
                if(str[k] == str2[l]){
                    count++;
                    break;
                }
            }
        }
        syu.push_back(count);      
    }
    sort(syu.begin(), syu.end(),greater<int>());
    cout << syu.at(0) << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int count=0;
    for(int i=a;i<=b;i++)
    {
        if(c%i==0)
        {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3096
#include <stdio.h>
#define MAX 1400
int H,W;

int C[MAX][MAX];
int dp[MAX][MAX];
int min(int a,int b){
  if(a<b)return a;
  else return b;
}
int max(int a,int b){
  if(a<b)return b;
  else return a;
}
int largest(){
  int i,j;
  int maxwidth=0;
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      dp[i][j]=(C[i][j]+1)%2;
      maxwidth|=dp[i][j];
    }
  }
  for(i=1;i<H;i++){
    for(j=1;j<W;j++){
      if(C[i][j])dp[i][j]=0;
      else{
	dp[i][j]=min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+1;
	maxwidth=max(maxwidth,dp[i][j]);
      }
    }
  }
  return maxwidth*maxwidth;
}
int main(){
  int i,j;
  scanf("%d %d",&H,&W);
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      scanf("%d",&C[i][j]);
    }
  }
  printf("%d\n",largest());
  return 0;
}

Measured memory_bytes: 15912
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,q;cin>>n>>q;
	vector<vector<int> > a(n);
	for(int i = 0; i < q; i++){
		int p;
		cin>>p;
		if(p==0){
			int t,x;
			cin>>t>>x;
			a[t].push_back(x);
		}else if(p==1){
			int t;
			cin>>t;
			if(a[t].size()==0){
				cout << endl;
				continue;
			}
			for(int j = 0; j < a[t].size(); j++){
				cout << a[t][j] << (j!=a[t].size()-1?" ":"");
			}printf("\n");
		}else{
			int t;
			cin>>t;
			a[t].clear();
		}
	}

	return 0;
}


Measured memory_bytes: 5884
#include <bits/stdc++.h>
using namespace std;
#define EQ(x, y) (abs(x - y) < 1e-9)
typedef long long ll;

const int N = 2e5 + 10;
pair<vector<int>, ll> g[N];
bool vis[N];

void dfs(int node, ll inc){
	vis[node] = true;
	g[node].second += inc;
	for (auto x : g[node].first){
		if (!vis[x])
			dfs(x, g[node].second);
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;

	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n - 1; ++i){
		int from, to;
		cin >> from >> to;
		g[from].first.push_back(to);
		g[to].first.push_back(from);
	}

	for (int i = 0; i < q; ++i){
		int p, x;
		cin >> p >> x;
		g[p].second += x;
	}

	dfs(1, 0);

	for (int i = 1; i <= n; ++i)
		cout << g[i].second << ' ';
	cout << '\n';

#ifdef local
	cout << setprecision(3) << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
	return 0;
}

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

using namespace std;

int dp[100001][3];
int dfs(vector<vector<int>>& arr,int index,int t)
{
  
  if(index >= (int)arr.size())
    return 0;
  
  if(dp[index][t] != -1)
    return dp[index][t];
  
  if(index == 0)
    return dp[index][t] = max(arr[index][0]+dfs(arr,index+1,0),max(arr[index][1]+dfs(arr,index+1,1),arr[index][2]+dfs(arr,index+1,2)));
  
  if(t==0)
    return dp[index][t] = max(arr[index][1]+dfs(arr,index+1,1),arr[index][2]+dfs(arr,index+1,2));
  
  else if(t==1)
    return dp[index][t] = max(arr[index][0]+dfs(arr,index+1,0),arr[index][2]+dfs(arr,index+1,2));
  
  else
    return dp[index][t] = max(arr[index][0]+dfs(arr,index+1,0),arr[index][1]+dfs(arr,index+1,1));
  
}

int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  vector<vector<int>> arr;
  for(int i=0;i<n;i++)
  {
    vector<int> v;
    for(int j=0;j<3;j++)
    {
      int x;
      cin>>x;
      v.push_back(x);
    }
    arr.push_back(v);
  }
  memset(dp,-1,sizeof(dp));
  int ans = dfs(arr,0,0);
  cout<<ans<<endl;
    
}

Measured memory_bytes: 17748
import sys
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
if s%(n*(n+1)//2)!=0:
  print('NO')
  sys.exit()
else:
  x=s//(n*(n+1)//2)
d=[]
for i in range(n-1):
  d.append(a[i+1]-a[i])
d.append(a[0]-a[n-1])
for i in range(n):
  d[i]-=x
  if d[i]%n!=0 or d[i]>0:
    print('NO')
    sys.exit()
print('YES')

Measured memory_bytes: 14436
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	string buffer;

	while ( cin >> buffer )
	{
		for ( unsigned i = 0; i < buffer.length(); i++ )
		{
			if ( buffer[i] == ',' )
			{
				buffer[i] = ' ';
			}
		}

		int num;
		double weight, height;

		istringstream( buffer ) >> num >> weight >> height;

		if ( 25 <= weight / pow( height, 2 ) )
		{
			cout << num << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;

template<typename T>
bool chmin(T &a,T b){
    if(b<a){
        a=b;
        return true;
    }
    return false;
}
int main(){
    int N;cin>>N;
    vector<int> a(N);
    vector<int> u(31);
    int x=0;
    REP(i, N){
        cin >> a[i];
        x^=a[i];
        u[__builtin_popcount(a[i]^(a[i]-1))]++;
    }
    int ans=0;
    for(int i=29;i>=0;--i){
        if(x>>i&1&&u[i+1]){
            x^=(1<<(i+1))-1;
            ans++;
        }
    }
    if(x) cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    long N = 1_000_000_007L;
    Scanner scanner = new Scanner(System.in);
    String str = scanner.next();

    long[][] d = new long[str.length() + 1][4];
    d[0][0] = 1;
    for (int i = 1; i <= str.length(); i++) {
      char ch = str.charAt(i - 1);

      int n = ch == '?' ? 3 : 1;
      d[i][0] = d[i - 1][0] * n % N;
      d[i][1] = d[i - 1][1] * n % N;
      d[i][2] = d[i - 1][2] * n % N;
      d[i][3] = d[i - 1][3] * n % N;
      int a = 0, b = 0, c = 0;
      if (ch == 'A' || ch == '?') a = 1;
      if (ch == 'B' || ch == '?') b = 1;
      if (ch == 'C' || ch == '?') c = 1;
      d[i][1] += a * d[i - 1][0];
      d[i][2] += b * d[i - 1][1];
      d[i][3] += c * d[i - 1][2];

      for (int j = 0; j < 4; j++) d[i][j] %= N;
    }

    System.out.println(d[str.length()][3]);
  }
}


Measured memory_bytes: 30908