akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
	
	int arr[3][3];
	 	
	 	for (int i=0 ; i<3 ; i++){
	 		for (int j=0 ; j<3 ; j++){
			 	scanf("%d",&arr[i][j]);
			 }
		 }
	
	int test;
	scanf("%d",&test);
	int angka[test];
	
	for (int k=0 ; k<test ; k++){
		scanf("%d",&angka[k]);
	
	for(int j = 0; j < 3; j++) {
       	for(int l = 0; l < 3; l++) {
            if(angka[k] == arr[j][l]) {
                arr[j][l] = 0;

                }
            }
        }
	}
	                
    if(arr[0][0] == 0 && arr[0][1] == 0 && arr [0][2] == 0){
        printf("Yes");
		}
	else if (arr[1][0] == 0 && arr[1][1] == 0 && arr [1][2] == 0){
		printf("Yes");
		}
	else if (arr[2][0] == 0 && arr[2][1] == 0 && arr [2][2] == 0){
		printf("Yes");
		}
	else if (arr[0][0] == 0 && arr[1][0] == 0 && arr [2][0] == 0){
		printf("Yes");
		}
	else if (arr[0][1] == 0 && arr[1][1] == 0 && arr [2][1] == 0){
		printf("Yes");
		}
	else if (arr[0][2] == 0 && arr[1][2] == 0 && arr [2][2] == 0){
		printf("Yes");
		}
	else if (arr[0][0] == 0 && arr[1][1] == 0 && arr [2][2] == 0){
		printf("Yes");
		}
	else if (arr[2][0] == 0 && arr[1][1] == 0 && arr [0][2] == 0){
		printf("Yes");
		}
		else{
		printf("No");
		}
	
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n),b(n),c(n);
	for(auto&i:a)cin>>i; for(auto&i:b)cin>>i; for(auto&i:c)cin>>i;
	sort(a.begin(),a.end()); sort(b.begin(),b.end()); sort(c.begin(),c.end());
	uint64_t ans=0;
	for(auto&i:b){
		auto aiter=lower_bound(a.begin(),a.end(),i);
		auto citer=upper_bound(c.begin(),c.end(),i);
		ans+=(uint64_t)(aiter-a.begin())*(c.end()-citer);
	}
	cout<<ans<<"\n"s;
}

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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a,b)+min(c,d) << endl;
	return 0;
}

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

signed main(){
    int X,N; cin>>X>>N;
    set<int> P;
    for(int i=0;i<N;i++){
        int p; cin>>p;
        P.insert(p);
    }
    vector<pair<int,int>>A;
    for(int i=-1;i<1000;i++){
        if(P.count(i))continue;
        A.push_back(make_pair(abs(i-X),i));
    }
    sort(A.begin(),A.end());
    cout<<A[0].second<<endl;

}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
const int N = 4001, mod = 998244353;

int n;
vector<bitset<N> > a;
bitset<N> k;

string in;

int sz (bitset<N> &T) {
	for(int i=N;i--;) {
		if(T[i] == 1) return i+1;
	}
	return 0;
}

int val (bitset<N> &T) {
	int R = 0;
	for(int i=N;i--;) {
		R = (2*R + T[i]) % mod;
	}
	return (R + 1) % mod;
}

bool cmp (bitset<N> &A, bitset<N> &B) {
	for(int i=N;i--;) {
		if(A[i] < B[i]) return true;
		if(A[i] > B[i]) return false;
	}
	return false;
}

int main()
{
	cin >> n >> in;
	k = bitset<N>(in);
	for(int i=1;i<=n;i++) {
		cin >> in;
		a.push_back(bitset<N>(in));
	}
	for(int i=1;i<n;i++) {
		if(sz(a[0]) > sz(a[i])) {
			swap(a[0], a[i]);
		}
	}
	while(a.size() > 1) {
		auto &A = a[0], &B = a.back(), T = B;
		int S = sz(A)-1;
		for(int i=N-1;i>=S;i--) {
			if(B[i] == 1) B ^= (A << (i-S));
		}
		swap(A, B);
		if(sz(A) == 0) {
			A = T;
			swap(A, B);
			a.pop_back();
		}
		else {
			a.push_back(T);
		}
	}
	auto T = k;
	int S = sz(a[0])-1;
	for(int i=N-1;i>=S;i--) {
		if(T[i] == 1) T ^= (a[0] << (i-S));
	}
	auto X = k >> S, Y = k^T;
	cout << (val(X) + mod - cmp(k, Y)) % mod << endl;
}


Measured memory_bytes: 1420
#include<iostream>
using  namespace std;
int bubble(int A[],int n)
{
    int i,j,c=0;
    for(i=0;i<n;i++)
    {
     for(j=n-1;j>=i+1;j--)
     {
        if(A[j-1]>A[j])
           {swap(A[j-1],A[j]);
           c++;}
     }}
     return c;
}
int main()
{
    int n,c;
    int A[100];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    c=bubble(A,n);
    for(int i=0;i<n;i++)
    {if(i>0)
        cout<<" ";
        cout<<A[i];
    }
    cout<<endl<<c<<endl;
    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = sz(s);
    vvi dp(n+1, vi(2, 0));
    dp[0][0] = 1;
    rep(i, n) {
        {   // a+b = 0
            if (s[i] == '0') {
                dp[i+1][0] = dp[i][0];
                dp[i+1][1] = dp[i][1];
            } else {
                dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
            }
        }
        {   // a+b = 1
            if (s[i] == '0') {
                dp[i+1][1] += dp[i][1] * 2 % mod;
                dp[i+1][1] %= mod;
            } else {
                dp[i+1][0] += dp[i][0] * 2 % mod;
                dp[i+1][0] %= mod;
                dp[i+1][1] += dp[i][1] * 2 % mod;
                dp[i+1][1] %= mod;
            }
        }
    }
    int ans = (dp[n][0] + dp[n][1]) % mod;
    cout << ans << endl;
}

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


int main(){
    string S;
    cin >> S;
    vector<ll> moji(26,0);

    for(int i = 0; i < S.size(); i++){
        moji[int(S[i] - 'a')] += 1;
        if(moji[int(S[i] - 'a')] == 2){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod=1000000007;
//head

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

    string s, t;
    cin >> s >> t;

    set<string> ans;

    for(int i = 0; i + t.size() - 1 < s.size(); i++) {
        bool ok = true;
        for(int j = 0; j < t.size(); j++) {
            if(!(s[i+j] == t[j] || s[i+j] == '?')) ok = false;
        }
        if(ok) {
            string pos = s;
            for(int j = 0; j < t.size(); j++) {
                pos[i + j] = t[j];
            }
            for(int j = 0; j < pos.size(); j++) if(pos[j] == '?') pos[j] = 'a';
            ans.insert(pos);
        }
    }
    if(ans.size() == 0) {
        cout << "UNRESTORABLE" << endl;
    } else {
        cout << *(ans.begin()) << endl;
    }
    return 0;
}


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

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  vector<int> color(n);
  vector<vector<int>> cnt(3, vector<int>(n, 0));
  for (int i=0; i<n; ++i) {
    if (s.at(i) == 'R') {
      color.at(i) = 0;
      cnt.at(0).at(i)++;
    } else if (s.at(i) == 'G') {
      color.at(i) = 1;
      cnt.at(1).at(i)++;
    } else {
      color.at(i) = 2;
      cnt.at(2).at(i)++;
    }
  }
  for (int i=n-2; i>=0; --i) {
    cnt.at(0).at(i) += cnt.at(0).at(i+1);
    cnt.at(1).at(i) += cnt.at(1).at(i+1);
    cnt.at(2).at(i) += cnt.at(2).at(i+1);
  }
  
  vector<bool> check(3, false);
  long long res = 0;
  int a, b, c;
  for (int i=0; i<n; ++i) {
    a = color.at(i);
    check.at(a) = true;
    for (int j=i+1; j<n; ++j) {
      b = color.at(j);
      if (a != b) {
      	check.at(b) = true;
        for (int k=0; k<3; ++k) if (!check.at(k)) c = k;
        int dif = j - i;
        if (j + dif < n && color.at(j+dif) == c) res += cnt.at(c).at(j) - 1;
        else res += cnt.at(c).at(j);
        check.at(b) = false;
      }
    }
    check.at(a) = false;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3704
str1=input()
ct=0
for i in range(0,3):
    if(str1[i]=='S'):
        ct+=1
if(ct==0):
    print(3)
if(ct==3):
    print(0)
if(ct==2):
    print(1)
if(ct==1):
    if(str1[1]=='S'):
        print(1)
    else:
        print(2)


Measured memory_bytes: 8920
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int x;
  cin >> x;
  if(x==1){
    cout << "Hello World" << endl;
  }else{
    int a,b;
    cin >> a >> b;
	cout << a+b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
  static void Main() {
    var s = "";
    while ((s = Console.ReadLine()) != "0 0") {
      var a = s.Split().Select(int.Parse).ToArray();
      int n = a[0];
      int m = a[1];
      var p = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToArray();
      int sum = 0;
      for (int i = 0; i < n; i++) {
        if ((i + 1) % m == 0) continue;
        sum += p[i];
      }
      Console.WriteLine(sum);
    }
  }
}


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

int main()
{
    int W, H, N; cin >> W >> H >> N;

    auto x1 = 0, x2 = W, y1 = 0, y2 = H;
    for (auto i = 0; i < N; i++)
    {
        int x, y, a; cin >> x >> y >> a;
        if (a == 1) x1 = max(x1, x);
        else if (a == 2) x2 = min(x2, x);
        else if (a == 3) y1 = max(y1, y);
        else y2 = min(y2, y);
    }

    cout << max(0, x2-x1) * max(0, y2-y1) << endl;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var N = parseInt(input[0], 10);

	var valley = toIntAll(tmp);
	var sumValley=0;
	for(var i=0; i<valley.length; i++){
		sumValley += valley[i];
	}

	var tmpSum = 0;
	for(var i=1; i<valley.length; i+=2){
		tmpSum += valley[i];
	}
	tmpMountainZero = sumValley - (2*tmpSum);

	var tmpMountain = [];
	tmpMountain[0] = tmpMountainZero;
	for(var i=1; i<valley.length; i++){
		tmpMountain[i] = (valley[i-1] - (tmpMountain[i-1]/2)) * 2;
	}
	//出力
	console.log('%s', outputDelimiterSpace(tmpMountain));
}
function toIntAll(input){
  var out = []
  for(var i=0; i<input.length; i++){
    out[i] = parseInt(input[i]);
  }
  return out;
}
function outputDelimiterSpace(words){
  var out = words.join(' ');
  out += '\n';
  return out;
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 38196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

const ll inf=1e9+7;

ll mult(ll n,ll m){//n^m%infを求める
    if(m==1){
        return n%inf;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%inf;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%inf;
    }
}

typedef pair<int,int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> ans;
    ans.push_back(2);
    ans.push_back(1);
    FOR(i,2,n+1){
        ans.push_back(ans[i-1]+ans[i-2]);
    }
    cout<<ans[n]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here
    int n;
    cin >> n;
    int a[4][3][10];
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int q=0; q<10; q++){
                a[i][j][q]=0;
            }
        }
    }
    int b,f,r,v;
    for(int i=0; i<n; i++){
        cin >> b >> f >> r >> v;
        a[b-1][f-1][r-1]+=v;
    }
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int q=0; q<10; q++){
                cout << " ";
                cout << a[i][j][q];
            }
            cout << endl;
        }
        if(i<3){
            cout << "####################" << endl;
        }
    }
}



Measured memory_bytes: 3100
import itertools
n,m = map(int,input().split())

a = [[] for i in range(n)]
for i in range(m):
    b = list(map(int,input().split()))
    a[b[0]-1].append(b[1]-1)
    a[b[1]-1].append(b[0]-1)

#print(a)

c = list(itertools.permutations(range(1, n)))
len_c = len(c)

#print(c)
ans = 0
for i in range(len_c):
    now = 0
    check = True
    for j in range(n - 1):
        if not c[i][j] in a[now]:
            check = False
        now = c[i][j]
    if check:
        ans += 1

print(ans)

Measured memory_bytes: 9388
function Main(input) {
	input = input.split("\n");
  var len = parseInt(input[0]);
  var engList = "abcdefghijklmnopqrstuvwxyz".split("");
  var lastList = {};
  for(var i = 0; i < engList.length; i++){
    lastList[engList[i]] = 50;
  }
  var inputList = [];
  for(var i = 1; i <= len; i++){
    var tmp = input[i].split("");
    var tmpList = {};
    for(var j = 0; j < tmp.length; j++){
      if(tmpList[tmp[j]] == null){
         tmpList[tmp[j]] = 1;
         }else{
          tmpList[tmp[j]]++; 
         }
    }
    inputList.push(tmpList);
  }
  for(var i = 0; i < inputList.length ; i++){
    var tmp = inputList[i];
    for(var j = 0; j < engList.length; j++){
      if(tmp[engList[j]] == null){
         lastList[engList[j]] = 0;
         }else{
           lastList[engList[j]] = Math.min(lastList[engList[j]],tmp[engList[j]]);
         }
    }
  }
  var output = "";
  for(var i = 0; i < engList.length; i++){
    var tmp = lastList[engList[i]];
    for(var j = 0; j < tmp; j++){
      output += engList[i];
    }
  }
  console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

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

  string name[100000];
  int time[100000];
  queue<int> Q;
  for(int i=0; i<n; i++){
    cin >> name[i] >> time[i];
    Q.push(i);
  }
  int sum = 0;
  while(! Q.empty()){
    int m = Q.front();
    Q.pop();
    if(time[m]>q){
      Q.push(m);
      time[m] -= q;
      sum += q;
    }
    else{
      sum += time[m];
      cout << name[m] << " " << sum << endl;
    }
  }

}

Measured memory_bytes: 4772
# -*- coding: utf-8 -*-
import sys

def main():
	N, Q = map(int, input().split(" "))
	S = input()
	S = list(S)
	
	Qs = []
	for _ in range(Q):
		l, r = map(int, input().split(" "))
		Qs.append((l, r))
	
	ptn = []
	hit = 0
	flg = False
	for i, val in enumerate(S):
		if val == "A":
			ptn.append(hit)
			if i+1 < len(S) and S[i+1] == "C":
				hit += 1
				ptn.append(hit)
				flg = True
		else:
			if flg == False:
				ptn.append(hit)
			else:
				flg = False
		
	ans = []
	for i, val in enumerate(Qs):
		l, r = val
		if l == r:
			ans.append(0)
			break
			
		tmp = ptn[r-1] - ptn[l-1]
		ans.append(tmp)
	
	
	for i in ans:
		print(i)
	
if __name__ == "__main__":
	main()
	

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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 1000000000
#define MOD 1000000007

int main(){

    ll n,m;
    cin >> n >> m;

    if(n>=m){
        cout << min(n%m,m-n%m);
    }
    else{
        cout << min(n,m-n);
    }

}




















Measured memory_bytes: 256
#AOTコンパイルテスト
import sys
 
def solve(n):
    return n**3
 
if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
 
    cc = CC('my_module')
    cc.export('solve', '(i8)')(solve)
    cc.compile()
    exit()
    
n=int(input())    
print(solve(n))

Measured memory_bytes: 9080
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		long[] A = new long[N];
		String[] a = new String[N];
		int max = 42;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
			// 二進数を42桁で左側を0で埋める
			a[i] = String.format("%42s", Long.toBinaryString(A[i])).replace(" ", "0");
		}
		sc.close();
		String k = String.format("%42s", Long.toBinaryString(K)).replace(" ", "0");

		long[] c = new long[max];
		int[] b = new int[max];
		for(int i = 0; i < max; i++) {
			if(k.charAt(i) == '1') {
				b[i]++;;
			}
		}
		for(String s : a) {
			for(int i = 0; i < max; i++) {
				if(s.charAt(i) == '1') {
					c[i]++;
				}
			}
		}
		long[][] dp = new long[max + 1][2];
		for(int i = 0; i <= max; i++) {
			dp[i][0] = -1;
			dp[i][1] = -1;
		}
		dp[0][0] = 0;
		for(int i = 0; i < max; i++) {
			long t = (long)Math.pow(2, max - 1 - i);
			long v0 = t * c[i];			// i桁目を0としたときの報酬
			long v1 = t * (N - c[i]);	// i桁目を1としたときの報酬
			if(dp[i][1] != -1) {
				dp[i + 1][1] = dp[i][1] + Math.max(v0, v1);
			}

			if(dp[i][0] != -1) {
				if(b[i] == 1) {
					dp[i + 1][1] = Math.max(dp[i + 1][1], dp[i][0] + v0);
					dp[i + 1][0] = dp[i][0] + v1;
				}else {
					dp[i + 1][0] = dp[i][0] + v0;
				}
			}
		}
		long ans = Math.max(dp[max][0], dp[max][1]);
		System.out.println(ans);
	}
	static void disp(long[] a) {
		for(long i : a) {
			System.out.printf("%d ", i);
		}
		System.out.println();
	}
	static void disp(int[] a) {
		for(long i : a) {
			System.out.printf("%d ", i);
		}
		System.out.println();
	}
}

Measured memory_bytes: 168912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n; cin >> n;
    vector<int> x(n), y(n), h(n);
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i] >> h[i];
    }

    int ans_x, ans_y, ans_h, xxx, yyy, hhh;
    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++){

            vector<int> HH;
            for(int k=0; k<n; k++){
                // 0 の場合は、必ずしも下の式成り立たない
                if(h[k] > 0){
                    HH.push_back(h[k] + abs(x[k] - i) + abs(y[k] - j));
                    xxx = x[k];
                    yyy = y[k];
                    hhh = h[k];
                }
            }

            if(HH.size() == 1){
                cout << xxx << " " << yyy << " " << hhh << endl;
                return 0;
            }

            int count = 0;
            for(int kk=0; kk<HH.size()-1; kk++){
                // 要素数1の場合はどうなるか。
                if(HH[kk] != HH[kk+1]) count++;
            }

            if(count == 0){
                ans_x = i;
                ans_y = j;
                ans_h = HH[0];
                break;
            }

        }
    }

    cout << ans_x << " " << ans_y << " " << ans_h << endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
T = input()

ins = -1#挿入場所(できるだけうしろにして前はAでつめる)
for i in range(0,len(S)-len(T)+1,1):
    
    isOk = True
    for j in range(i,i+len(T),1):
        if not(T[j-i]==S[j] or S[j]=="?"):
            isOk = False
            break
        
    if isOk:
        ins = i

if ins == -1:
    print("UNRESTORABLE")
    exit()

ans = list(S)
for i in range(len(T)):
    ans[ins+i]=T[i]

for i in range(len(ans)):
    if ans[i]=="?":
        ans[i]="a"

print("".join(ans))



Measured memory_bytes: 61968
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	string S; cin >> S;
	REP(i, S.size()) {
		int tmp = S[i] - 'A' + N;
		tmp %= 26;
		printf("%c", tmp + 'A');
	}
	printf("\n");
}

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


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n), q(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  vector<int> a(n);
  rep(i,n) a[i] = i+1;

  map<vector<int>, int> mp;
  do {
    mp[a] = mp.size();
  } while (next_permutation(a.begin(), a.end()));

  int ans = abs(mp[p] - mp[q]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5248
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.root=[-1]*(n+1)
    self.rank=[0]*(n+1)
  def FindRoot(self,x):
    if self.root[x]<0:
      return x
    else:
      self.root[x]=self.FindRoot(self.root[x])
      return self.root[x]
  def Unite(self,x,y):
    x=self.FindRoot(x)
    y=self.FindRoot(y)
    if x==y:
      return
    else:
      if self.rank[x]>self.rank[y]:
        self.root[x]+=self.root[y]
        self.root[y]=x
      elif self.rank[x]<=self.rank[y]:
        self.root[y]+=self.root[x]
        self.root[x]=y
        if self.rank[x]==self.rank[y]:
          self.rank[y]+=1
  def isSameGroup(self,x,y):
    return self.FindRoot(x)==self.FindRoot(y)
  def Count(self,x):
    return -self.root[self.FindRoot(x)]

n,m=map(int,input().split())
uf=UnionFind(n+1)
for _ in range(m):
  a,b=map(int,input().split())
  uf.Unite(a,b)
s=set()
for i in range(1,n+1):
  s.add(uf.FindRoot(i))
print(len(s)-1)

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

int main() {
	int n;
	int a;
	int min = -1;
	int vt = -1;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;

		if (vt > 0) {
			int x = vt;
			int y = a;

			while (x > 0 && y > 0) {
				if (x >= y) {
					x %= y;
				}
				else {
					y %= x;
				}
			}

			vt = x;
			a = y;

			if (y > 0) vt = a;
		}
		else if (a > 0) vt = a;
	}

	cout << vt;

	getchar(); getchar();
	return 0;
}

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

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define F first 
#define S second
#define int long long
#define endl "\n"

using namespace std;

/*
		TOUGH TIMES DON'T LAST TOUGH PEOPLE DO :)
		COURAGE IS ONE STEP AHEAD OF FEAR :)
*/

const int nax=3e5+5;
vector<int>adj[nax];
const int mod=1e9+7;
const int inf=1e18+7;

int n,m;
int deg[nax];
int P[nax];
int R[nax];

// void dfs(int cur, int p){
// 	if(R[cur] <= R[p]){
// 		R[cur] = R[p]+1;
// 		P[cur] = p;
// 	}
// 	for(auto u:adj[cur]){
// 		if(u!=p)
// 		dfs(u,cur);
// 	}
// }

signed main(){
	fast;
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
// #endif
	cin>>n>>m;
	for(int i=1;i<n+m;i++){
		int a,b;
		cin>>a>>b;
		adj[a].pb(b);
		deg[b]++;
	}
	int node = 0;
	for(int i=1;i<=n;i++){
		if(deg[i] == 0){
			node = i;
			P[node]= 0;
			break;
		}
	}
	R[node] = 0;
	queue<int>q;
	q.push(node);
	while(!q.empty()){
		int cur = q.front();
		q.pop();
		for(int i = 0;i<adj[cur].size();i++){
			deg[adj[cur][i]]--;
			if(deg[adj[cur][i]] == 0){
				P[adj[cur][i]] = cur;
				q.push(adj[cur][i]);
			}
		}
	}
	for(int i=1;i<=n;i++){
		cout<<P[i]<<endl;
	}
	return 0;
}

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

uint64_t iter_lucas(int i, uint64_t a, uint64_t b, int n) {
  if (n == 0) return 2;
  if (n == 1) return 1;
  if (n == i) return b;
  iter_lucas((i+1), b, (a+b), n);
}

uint64_t lucas(int n) {
  return iter_lucas(1, 2, 1, n);
}

int main(){
  int n;
  cin >> n;
  cout << lucas(n) << endl;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

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

   int dp[50] = {0};
   dp[0] = 1;
   for (int i = 1; i <= n; i++) {
      dp[i] = min(dp[i-1] * 2, dp[i-1] + k);
   }

   cout << dp[n] << endl;

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  vector<int> v(5);
  for(int i=0;i<5;i++)
  {
    cin >> v[i];
    if(v[i] == 0) cout << i+1 << endl;
  }
  return 0;
}


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

using namespace std;

map< string, int > cnt;

int main(){
	int n;

	cin >> n;

	while(n--){
		string si;

		cin >> si;
		
		cnt[si]++;
	}

	int best = 0;

	for(auto u: cnt){
		best = max(best, u.second);
	}

	for(auto u: cnt){
		if(u.second == best){
			cout << u.first << endl;
		}
	}

	return 0;
}

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

int main()
{
  vector<int> v(10);
  for (int i = 0; i < 10; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end(), greater<int>());
  for (int i = 0; i < 3; i++) {
    cout << v[i] << endl;
  }
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N+1);
    for (int i = 1; i <= N; i++) cin >> A[i];
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (i%2 == 1 && A[i]%2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>

int main()
{
    int i;

    //標準入力
    int n, S[13], H[13], C[13], D[13], rank;
    char ch[256];
    for( i = 0; i < 13; ++i ) S[i] = H[i] = C[i] = D[i] = 0; //初期化
    scanf("%d", &n);
    for( i = 0; i < n; ++i ){
        scanf("%s%d", ch, &rank);
        switch( ch[0] ){
        case 'S': S[rank-1] = 1; break;
        case 'H': H[rank-1] = 1; break;
        case 'C': C[rank-1] = 1; break;
        case 'D': D[rank-1] = 1; break;
        default: printf("default switch( ch[0] )\n"); break;
        }
    }

    //標準出力
    for( i = 0; i < 13; ++i )
        if( S[i] == 0 ) printf("S %d\n", i+1);
    for( i = 0; i < 13; ++i )
        if( H[i] == 0 ) printf("H %d\n", i+1);
    for( i = 0; i < 13; ++i )
        if( C[i] == 0 ) printf("C %d\n", i+1);
    for( i = 0; i < 13; ++i )
        if( D[i] == 0 ) printf("D %d\n", i+1);

    return 0;
}

Measured memory_bytes: 596
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n = 3;
    yukari<int> bingo(3, akari<int>(3));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            cin >> bingo[i][j];
        }
    cin >> n;
    while (n--)
    {
        int b;
        cin >> b;
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
            {
                if (bingo[i][j] == b)
                {
                    bingo[i][j] = -1;
                }
            }
    }
    bool ok = 0;
    n = 3;
    for (int i = 0; i < n; i++)
    {
        bool res = 1;
        for (int j = 0; j < n; j++)
        {
            if (bingo[i][j] != -1)
            {
                res = 0;
            }
        }
        ok |= res;
    }
    for (int i = 0; i < n; i++)
    {
        bool res = 1;
        for (int j = 0; j < n; j++)
        {
            if (bingo[j][i] != -1)
            {
                res = 0;
            }
        }
        ok |= res;
    }
    if (bingo[1][1] == -1)
    {
        ok |= (bingo[0][0] == -1 && bingo[2][2]) || (bingo[2][0] && bingo[0][2]);
    }
    cout << (ok ? "Yes" : "No") << endl;
}

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


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

int n;
int t[10005];
void solve(){
  for(int i=0;i<n;i++){
    cin >> t[i];
  }
  sort(t,t+n);
  unsigned long long wt=0,sum=0;
  for(int i=0;i<n-1;i++){
    wt += t[i];
    sum += wt;
  }
  cout << sum << endl;
}

int main(){
  while (cin >> n) {
    if(n == 0) break;
    solve();
  }
}

Measured memory_bytes: 3072
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_MOD			1000000007								// 除数(10の9乗+7)
#define D_ARRAY_MAX		200000									// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 和 - 取得
int
fGetModSum(
	int piVal1					// <I> 値１
	, int piVal2				// <I> 値２
)
{
	int liSum = piVal1 + piVal2;
	if (liSum >= 0) {
		return liSum % D_MOD;
	}
	else {
		return liSum + D_MOD;
	}
}

// 積 - 取得
int
fGetModMulti(
	int piVal1					// <I> 値１
	, int piVal2				// <I> 値２
)
{
	return (int)((long long)piVal1 * (long long)piVal2 % D_MOD);
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 配列数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列・和 - 取得
	int liSum = 0;
	for (i = 0; i < siACnt; i++) {
		fscanf(szpFpI, "%d", &si1Array[i]);
		liSum = fGetModSum(liSum, si1Array[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 乗算
	int liResult = 0;
	for (i = 0; i < siACnt - 1; i++) {
		liSum = fGetModSum(liSum, -si1Array[i]);
		int liVal = fGetModMulti(liSum, si1Array[i]);
		liResult = fGetModSum(liResult, liVal);
	}

	return liResult;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 2488
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n';

typedef long long ll;

using namespace std;

int main()
{
    string moji;
    cin >> moji;

    for (int i = 0; i < 3; i++)
    {
        if (moji[i] == '1')
        {
            moji[i] = '9';
        }
        else
        {
            moji[i] = '1';
        }
    }
    cout << moji << endl;

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
//#include<Hatsune_Miku>
using namespace std;
int n;
int hmiku[7][831];
int miku[2007][831];
int main(){
   cin>>n;
    for(int i=1;i<=n;++i){cin>>hmiku[1][i];
    }
    for(int i=1;i<=n;++i){ cin>>hmiku[2][i];
    }
    miku[1][1]=hmiku[1][1];miku[2][1]=hmiku[2][1]+hmiku[1][1];
    for(int i=2;i<=n;++i){
        miku[1][i]=miku[1][i-1]+hmiku[1][i];
        miku[2][i]=max(miku[1][i],miku[2][i-1])+hmiku[2][i];
    }
    cout<<miku[2][n]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
   long long n,m,k,p,q;
   cin>>n>>m>>k;
   if(n>k) cout<<n-k<<" "<<m<<endl;
   else
   {
            cout<<0<<" ";
            p=k-n;
            q=m-p;
            if(m>p) cout<<q<<endl;
            else cout<<0<<endl;
   }
}



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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((a == b && b == c) ||(a != b && b != c && c != a))
    cout << "No";
  else cout << "Yes";
}

Measured memory_bytes: 256
//-.-.-.-.-.-.-.-.-.-Make it Work, Make it Right, Make it Fast-.-.-.-.-.-.-.-.-.-.-.-.-.
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pob pop_back
#define pf push_front
#define popb pop_back()
#define popf pop_front()
#define ll long long int
#define llu long long unsigned int 
#define lu long unsigned int 
#define ff first
#define ss second 
#define S size()
#define inf 1e8
#define clr(a) memset(a, 0, sizeof(a))
#define fr(i, x, y) for ( ll i = x; i < y;i++)
#define dc(i, x, y) for ( ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define PI 3.1415926535897932384626433832795
#define pqueue priority_queue<ll>
#define piqueue priority_queue<ll,vll ,greater<ll>>
#define mapcl map<char,ll>
#define mapll map<ll,ll>
#define mapsl map<string,ll>
#define vi vector<ll>
#define vs vector<string>
#define pii pair<ll,ll>
#define vii vector<pii>
using namespace std;
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}  
//----------------------------------------START------------------------------------------
int main()
{
	ll n,k,s;
	cin>>n>>k>>s;
	ll a[n];
	for(int i=0;i<n;i++)
	{
		if(s==1)
		{
			a[i]=s+1;
		}
		else  
		{
			a[i]=s-1;
		}
	}
	if(k!=0){
	for(int i=0;i<k;i++)
	{
		a[i]=s;
	}}
	for(int i=0;i<n;i++)
	{
		cout<<a[i]<<" ";
	}
	
    return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
int a[1000005],n;
for(int i=0;i<1000005;i++)
{
a[i]=0;
}
scanf("%d",&n);
for(int i=1;i<1000005;i++)
{
a[n]++;
if(a[n]==2){printf("%d\n",i); break;}
if(n%2==0){n=n/2;}
else{n=n*3+1;}
}
}

Measured memory_bytes: 4096
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	sqrtN := math.Sqrt(float64(n))
	for i := int(sqrtN); i > 0; i-- {
		if q := n / i; n % i == 0 {
			fmt.Println(i - 1 + q - 1)
			break
		}
	}
}


Measured memory_bytes: 512
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	static PriorityQueue<Edge> pq=new PriorityQueue<>();
	static int n, m;
	static int[] par;
	
	static class Edge implements Comparable<Edge>{
		int u, v, cost;
		Edge(int u, int v, int cost){
			this.u=u;
			this.v=v;
			this.cost=cost;
		}
		public int compareTo(Edge e) {
			return this.cost-e.cost;
		}
	}
	
	static void init(int N) {//初期化
		for(int i=0; i<N; i++) {
			par[i]=i;
		}
	}
	
	static int root(int x) {//親を求める
		if(par[x]==x) {
			return x;
		}
		return par[x]=root(par[x]);
	}
	
	static boolean same(int x, int y) {//判定(同グループかどうか)
		return (root(x)==root(y));
	}
	
	static void unite(int x, int y) {//まとめる
		par[root(x)]=root(y);
	}
	
	static int kraskal() {
		init(n);
		int res=0;
		for(int i=0; i<m; i++) {
			Edge e=pq.poll();
			if(!same(e.u, e.v)) {
				unite(e.u, e.v);
				res+=e.cost;
			}
		}
		return res;
	}
	
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				n=sc.nextInt();
				m=sc.nextInt();
				if(n+m==0) break;
				par=new int[n];
				for(int i=0; i<m; i++) {
					int a=sc.nextInt();
					int b=sc.nextInt();
					int w=sc.nextInt();
					pq.add(new Edge(a, b, w));
				}
				System.out.println(kraskal());
				pq.clear();
			}

		}
	}
}


Measured memory_bytes: 30168
#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(50, vector<ll>(50, INF));

int main() {
	ll a, b;
	char c;
	cin >> a >> c >> b;
	if (c == '+') cout << a + b << endl;
	else cout << a - b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int h[n],a[n];
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  a[0] = 0;
  a[1] = abs(h[1]-h[0]);
  for(int i=2; i<n; i++){
    a[i] = min(abs(h[i-2]-h[i])+a[i-2],abs(h[i-1]-h[i])+a[i-1]);
  }
  cout << a[n-1] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)
using Graph = vector<vector<int>>;
ll n,m,l,a,b,c,x,y; 
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin>>n;
  ll arr[n];
  fr(i,n){
    cin>>a;
    arr[i]=a;
  }
  sort(arr,arr+n);
  fr(i,n){
    if(i%2==0) b+=arr[n-1-i];
    else c+=arr[n-1-i];
  }
  cout<<b-c;
}  

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define ALL(v) (v).begin(), (v).end()

typedef pair<int, int> P;

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

    REP(cx, 101) REP(cy, 101) {
        int ha;
        bool hantei = true;
        REP(i, n) {
            if(h[i] > 0) {
               ha = h[i] + abs(cx - x[i]) + abs(cy - y[i]);
               break; 
            }
        }
        //cout << "ha=" << ha << endl;
        REP(i, n) {
            int tmp = ha - abs(cx - x[i]) - abs(cy - y[i]);
            tmp = max(tmp, 0);
            if(tmp != h[i]) hantei = false;
        }
        if(hantei) {
            cout << cx << " " << cy << " " << ha << endl;
            return 0;
        }
    }

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> V(110000, 0);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    V.at(A)++;
  }
  int K = 0;
  for (int i = 0; i < 110000; i++) {
    if (V.at(i) > 0) K++;
  }
  if (K % 2 == 0) cout << K - 1 << endl;
  else cout << K << endl;
}

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

using namespace std;



int n,w;
int t,temp;
long long int maximum(long long int a,long long int b)
{
	if(a<b)return b;
	return a;
}

 long long int KnapSack(vector<int>&wg,vector<int>&val)
{
	
	long long int a[w+1][n+1];

	for(int i=0;i<=w;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i==0 || j==0)a[i][j]=0;
			else 
				{
					if(wg[j-1]<=i)a[i][j]=maximum(val[j-1]+a[i-wg[j-1]][j-1], a[i][j-1]);
			         else a[i][j]=a[i][j-1];
			    }

		}
	}
	return a[w][n];
}
int main()
{
	#ifdef patil
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    cin>>n>>w;
   vector<int>val,wg;

   for(int i=0;i<n;i++)
   {
    cin>>t>>temp;
    wg.push_back(t);
    val.push_back(temp);
   	
   }
   

   cout<<KnapSack(wg,val);


	return 0;

}

Measured memory_bytes: 82384
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

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

int main()
{
	for(int i=1;i<=5;++i)
		if(read()==0)
			printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 3016
#include <stdio.h>
#include <stdlib.h>

#define N (3*100000)

int main() {
  int H, W, M, h[N], w[N], rsum[N] = {0}, csum[N] = {0}, rsummax = 0, csummax = 0, ncsummaxarg = 0, nrsummaxarg = 0, nbomb = 0;
  scanf("%d%d%d", &H, &W, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &h[i], &w[i]);
    h[i]--;
    w[i]--;
    rsum[h[i]]++;
    csum[w[i]]++;
    if (rsummax < rsum[h[i]]) {
      rsummax = rsum[h[i]];
    }
    if (csummax < csum[w[i]]) {
      csummax = csum[w[i]];
    }
  }
  for (int i = 0; i < H; i++) {
    if (rsum[i] == rsummax) {
      nrsummaxarg++;
    }
  }
  for (int i = 0; i < W; i++) {
    if (csum[i] == csummax) {
      ncsummaxarg++;
    }
  }
  for (int i = 0; i < M; i++) {
    if (rsum[h[i]] == rsummax && csum[w[i]] == csummax) {
      nbomb++;
    }
  }
  if (nrsummaxarg*ncsummaxarg == nbomb) {
    printf("%d\n", rsummax+csummax-1);
  } else {
    printf("%d\n", rsummax+csummax);
  }
  return 0;
}

Measured memory_bytes: 6840
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	int n;
	string s;
	list<string> str;
	cin >> n;
	rep (i,n) {
		cin >> s;
		str.push_back(s);
	}
	str.sort();;
	str.unique();
	int ans;
	ans = str.size();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 16100
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

ll N,M,b,c;
vector<ll> A;
vector<pair<ll,ll> > BC;

int main(){
    cin >> N >> M;
    A.assign(N,0);
    REP(i,N) cin >> A[i];
    REP(i,M){
        cin >> b >> c;
        BC.push_back(make_pair(c,b));
    }
    sort(A.begin(),A.end());
    sort(BC.rbegin(),BC.rend());
    int a = 0;
    REP(i,M){
        ll num = BC[i].first;
        ll idx = BC[i].second;
        REP(j,idx){
            A[a] = max(A[a],num);
            ++a;
            if(a>=N) goto ANS;
        }
    }
ANS:
    ll ans = 0;
    REP(i,N) ans += A[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3188
#include<stdio.h>
#define N 100

int main(){
  int h,i,j,v,a[N],n;
  
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf(" %d",&a[i]);
    if(a[i]<0 || a[i]>1000)break;
  }

  for(i=1; i<=n-1; i++){
    for(h=0; h<n-1; h++){
      printf("%d ",a[h]);
    }
    printf("%d\n",a[h]);
    
    v=a[i];
    j=i-1;
    while(j>=0 && a[j]>v){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
  }
  for(h=0; h<n-1; h++){
      printf("%d ",a[h]);
    }
    printf("%d\n",a[h]);

  return 0;
}



Measured memory_bytes: 2056