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

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int n;
	cin >> n;

	int odd[100001];
	int even[100001];
	for(int i=0; i<100001; i++) {
		odd[i] = even[i] = 0;
	}
	
	// 偶奇番目ごとにカウント
	for(int i=0; i<n; i++) {
		int v;
		cin >> v;

		if(i%2) {
			odd[v]++;
		} else {
			even[v]++;
		}
	}
	// 偶奇ごとに一番多い数、2番目に多い数を調べる
	int oddMaxIdx = 0, oddSecIdx = 0;
	int evenMaxIdx = 0, evenSecIdx = 0;
	
	for(int i=1; i<=100000; i++) {
		int oddMax = max(odd[oddMaxIdx], odd[i]);
		if(oddMax == odd[i]) {
			oddSecIdx = oddMaxIdx;
			oddMaxIdx = i;
		} else {
			int oddSec = max(odd[oddSecIdx], odd[i]);
			if(oddSec == odd[i]) {
				oddSecIdx = i;
			}
		}
		
		int evenMax = max(even[evenMaxIdx], even[i]);
		if(evenMax == even[i]) {
			evenSecIdx = evenMaxIdx;
			evenMaxIdx = i;
		} else {
			int evenSec = max(even[evenSecIdx], even[i]);
			if(evenSec == even[i]) {
				evenSecIdx = i;
			}
		}
	}
	
	
	int ret = 0;
	int len = n/2;
	if(oddMaxIdx != evenMaxIdx) {
		ret = (len-odd[oddMaxIdx])+(len-even[evenMaxIdx]);
	} else {
		int comp1 = odd[oddMaxIdx] + even[evenSecIdx];
		int comp2 = odd[oddSecIdx] + even[evenMaxIdx];
		if(comp1 > comp2) {
			ret = (len-odd[oddMaxIdx])+(len-even[evenSecIdx]);
		} else {
			ret = (len-odd[oddSecIdx])+(len-even[evenMaxIdx]);
		}
	}
	cout << ret;

	return 0;
}


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


int main() {
    string k;
    int n;
    cin >> n;
    cin >> k;
    for(int i=0; i < n; i++) {
        if(i < k.length()) {
            cout << k[i];
        }
    }
    if(n < k.length()) {
        cout << "...";
    }
    cout << "\n";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;

int main(void){
    ll result = 1;
    
    ll A, B;
    cin >> A >> B;
    if(B % A == 0){
        result = A+ B;
    }else{
        result = B - A;
    }
    
    cout << result << endl;
    return 0;
}

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

/*
  ll n , m ;
  cin >> n >> m ;
  ll a , b , c ;
  cin >> a >> b >> c ;
  vector<ll> A(n) ;
  cout << "Yes" << endl ;
  cout << "No"  << endl ;
*/

int main(){
    string s ;
    cin >> s ;
    ll count = 0 ;
    ll ans = 0 ;
    rep(i,3){
      if(s[i] == 'R')count++; 
      else count = 0 ;
      ans = max(ans,count) ;
    } 
    cout << ans << endl ;
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n;
  if(!n) {
    cout << "0" << endl;
  }
  else {
    while(n) {
      if(n%2) {
        s="1"+s;
        n--;
      }
      else {
        s="0"+s;
      }
      n/=-2;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
from collections import Counter
n, p = map(int, input().split())


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


ans = 1
for i in Counter(prime_factorize(p)).most_common():
    if i[1] < n:
        break
    ans *= i[0]**(i[1]//n)
print(ans)


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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int NextPow2(int x)
{
	x--;
	for(int i=1;i<32;i*=2) x|=x>>i;
	return x+1;
}
const int I=numeric_limits<int>::max();
int F(int a,int b){return min(a,b);}

struct SegmentTree{
	int size;
	vi data;
	SegmentTree(int n):size(NextPow2(n)),data(size*2,I){}
	SegmentTree(const vi& a):size(NextPow2(a.size())),data(size*2,I){
		copy(all(a),begin(data)+size);
		peri(i,1,size) data[i]=F(data[i*2],data[i*2+1]);
	}
	int Get(int i){
		return data[size+i];
	}
	void Update(int i,int x){
		data[size+i]=x;
		for(i+=size;i/=2;) data[i]=F(data[i*2],data[i*2+1]);
	}
	int Query(int a,int b,int i,int l,int r){
		if(b<=l || r<=a) return I;
		if(a<=l && r<=b) return data[i];
		return F(Query(a,b,i*2,l,(l+r)/2),Query(a,b,i*2+1,(l+r)/2,r));
	}
	int Query(int a,int b){
		return Query(a,b,1,0,size);
	}
};

struct SegmentTree2D{
	int size;
	vector<SegmentTree> data;
	SegmentTree2D(int h,int w):size(NextPow2(h)),data(size*2,SegmentTree(w)){}
	SegmentTree2D(const vvi& a):size(NextPow2(a.size())),data(size*2,SegmentTree(a[0].size())){
		copy(all(a),begin(data)+size);
		peri(i,1,size) repi(j,1,data[i].data.size())
			data[i].data[j]=F(data[i*2].data[j],data[i*2+1].data[j]);
	}
	int Get(int i,int j){
		return data[size+i].Get(j);
	}
	void Update(int i,int j,int x){
		data[size+i].Update(j,x);
		for(i+=size;i/=2;)
			data[i].Update(j,F(data[i*2].Get(j),data[i*2+1].Get(j)));
	}
	int Query(int a,int b,int c,int d,int i,int to,int bo){
		if(c<=to || bo<=a) return I;
		if(a<=to && bo<=c) return data[i].Query(b,d);
		return F(Query(a,b,c,d,i*2,to,(to+bo)/2),Query(a,b,c,d,i*2+1,(to+bo)/2,bo));
	}
	int Query(int a,int b,int c,int d){
		return Query(a,b,c,d,1,0,size);
	}
};

int main()
{
	for(int r,c,q;scanf("%d%d%d",&r,&c,&q),r|c|q;){
		vvi grid(min(r,c),vi(max(r,c)));
		if(r<=c) rep(i,r) rep(j,c) scanf("%d",&grid[i][j]);
		else     rep(j,r) rep(i,c) scanf("%d",&grid[i][j]);
		
		vi r1(q),c1(q),r2(q),c2(q);
		rep(i,q) scanf("%d%d%d%d",&r1[i],&c1[i],&r2[i],&c2[i]);
		
		if(r>c){
			swap(r,c);
			swap(r1,c1);
			swap(r2,c2);
		}
		
		SegmentTree2D st(grid);
		rep(i,q)
			printf("%d\n",st.Query(r1[i],c1[i],r2[i]+1,c2[i]+1));
	}
	
	return 0;
}

Measured memory_bytes: 39116
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, A[1 << 18], D[1 << 18];
long long S;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= N; i++) S += A[i];
	
	long long base = N * (N + 1LL) / 2LL;
	long long kosuu = S / base;
	if (S % base != 0) {
		cout << "NO" << endl;
		return 0;
	}

	long long t = 0, cnt = 0;
	for (int i = 1; i <= N; i++) D[i] = A[i] - 1LL * i * kosuu;
	for (int i = 2; i <= N; i++) {
		if (D[i] == D[i - 1]) continue;
		if (D[i - 1] < D[i]) { cout << "NO" << endl; return 0; }
		if ((D[i] - D[i - 1]) % N != 0) { cout << "NO" << endl; return 0; }
		long long s = (D[i - 1] - D[i]) / N;
		cnt += s;
		t += 1LL * (N + 2 - i) * s;
	}

	if (kosuu < cnt) { cout << "NO" << endl; return 0; }
	t += 1LL * (kosuu - cnt);
	if (t == A[1]) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
	return 0;
}

Measured memory_bytes: 5176
#b_a,x_a,b_xそれぞれの数を取得し、b_aがあればb_aだけの連結で(b_a)-1個のABが作られる。かつx_a,b_xがあれば両端にABを作ることができる。
#その分x_a.b_xのみで使う予定のものが一つずつ減る。

N = int(input())
S = [input() for i in range(N)]
ab = x_a = b_x = b_a = 0
for s in S:
    ab += s.count('AB')
    if s[-1]=='A' and s[0]=='B':
        b_a += 1
    elif s[-1]=='A':
        x_a += 1
    elif s[0]=='B':
        b_x += 1
        
ans = ab

#b_aが一つでもあれば
if b_a:
    #b_aだけで繋げた時のABの数を追加
    ans += b_a - 1
    if x_a:
        #b_aの左端にx_aをつなげることでできるAB
        ans += 1
        #その代わりにx_aとb_xで使う用のx_aが一つ減る
        x_a -= 1
    if b_x:
        ans += 1
        b_x -= 1
        
#最後に残ったx_aとb_xで作られるABの数を追加する
ans += min(x_a, b_x)
print(ans)

Measured memory_bytes: 3700
#include <cstdio>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>

using namespace std;
bool IsPrime(int num);

int main(){
	long int X;
	long int out;
	
	cin >> X;
	out = X;
	for(;;){
		if(IsPrime(out)==true){
			cout << out;
			break;
		}
		out++;
	}

	return 0;
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

Measured memory_bytes: 256
def f(l):
    sta = True
    for i,j in enumerate(l):
        if sta:
            if j!=0:
                sta=False
                l[i]-=1
        else:
            if j==0:
                break
            else:
                l[i]-=1
    return l



N =int(input())
h =[int(i) for i in input().split()]
m = 0
while h != [0]*N:
    h =f(h)
    m += 1
print(m)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int64_t ans=1,threshold = 1000000000000000000,th_check;
  th_check = threshold;
  vector<int64_t> v(n);
  for(int i=0; i<n; i++){
    cin >> v.at(i);

    if(v.at(i) == 0){
      ans = 0;
      cout << 0 << endl;
      return 0;
    }
  }
  for(auto x: v){
    th_check /= x;
    if(th_check == 0){
      cout << -1 << endl;
      return 0;
    }
    ans *= x;
  }
  if(ans > threshold){
      ans = -1;
    }
  cout << ans << endl;
}

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

int main(){

  long N;
  cin >> N;

  for(int i=1; i<=sqrt(N); i++){
    if((i+1)*(i+1)>N){
      cout << i*i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
k, a, b = map(int, input().split())
if b-a <= 2:
    print(1 + k)
elif a-1+2 > k:
    print(1 + k)
else:
    if (k-a+1)//2 == 1:
        print(b + (k-a+1)%2)
    else:
        print(b + ((k-a+1)//2-1)*(b-a) +  (k-a+1)%2)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

string s,t;
cin >> s >> t;
int cnt = 0;
rep(i,SZ(s)) {
    if(s[i] != t[i]) cnt++;
}
cout << cnt << endl;
return 0;
}

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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    
    int tmp = x;
    x = y;
    y = tmp;

    tmp = x;
    x = z;
    z = tmp;

    cout << ' ' << x << ' ' << y << ' ' << z << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b){
        printf("%d",c);
    }
    else if(b==c){
        printf("%d",a);
    }
    else printf("%d",b);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int n, A[100];

int makeint(int, int);

int main(){
  int i, q, Q;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&Q);
    if(makeint(0 , Q)) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int makeint(int a, int b){
  int rec;
  if(b == 0) return 1;
  if(a >= n) return 0;
  rec = makeint(a + 1 , b) || makeint(a + 1 , b - A[a]);
  
  return rec;
}



Measured memory_bytes: 2104
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int INF = 1 << 30;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
int main() {
	string s;
	cin >> s;
	int fl = 0, ct = 0;
	bool b=0;
	rep(i, s.size()) {
		if (fl == 0) {
			if (s[i] == 'A')++ct;
			if (ct == 2) { b = 0;break; }
			if (s[i] == 'K') { ++fl; ct = 0; }
			if (s[i] != 'A'&&s[i] != 'K') { b = 0; break; }
		}
		else if (fl == 1) {
			if (s[i] == 'I')++fl;
			else { b = 0; break; }
		}
		else if (fl == 2) {
			if (s[i] == 'H')++fl;
			else { b = 0; break; }
		}
		else if (fl == 3) {
			if (s[i] == 'A')++ct;
			if (ct == 2) { b = 0; break; }
			if (s[i] == 'B') { ct = 0; ++fl; }
			if (s[i] != 'A'&&s[i] != 'B') { b = 0; break; }
		}
		else if (fl == 4) {
			if (s[i] == 'A')++ct;
			if (ct == 2) { b = 0; break; }
			if (s[i] == 'R') { ct = 0; ++fl; b = 1; }
			if (s[i] != 'A'&&s[i] != 'R') { b = 0; break; }
		}
		else if (fl == 5) {
			if (s[i] == 'A')++ct;
			else { b = 0; break; }
			if (ct == 2) { b = 0; break; }
			b = 1;
		}
	}
	cout << (b ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
 string S ,T , U;
 cin >> S >> T ;

 int A,B ;
 cin >> A>> B ;
 cin>> U;
 if (U == S) {
    A = A-1 ;
    cout << A<<' '<<B ;
 }
 else {
    B =B-1 ;
    cout <<A <<' '<<B;
 }
       return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W,K;
  cin>>H>>W>>K;
  vector<vector <ll> > dp(H+1, vector<ll>(W,0));
  dp[0][0]=1ll;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      for (int bit = 0; bit < 1<<(W-1); ++bit) {
        bool ok = true;
        for (int k = 0; k < W-2; ++k) {
          if ((bit & (1<<k)) && (bit & (1<<(k+1)))) ok = false;
        }
        if (!ok) continue;
        int nj = j;
        if (bit & (1<<j)) nj = j+1;
        else if (j > 0 && (bit & (1<<(j-1)))) nj = j-1;
        dp[i+1][nj] += dp[i][j];
        dp[i+1][nj] %= MOD;
      }
    }
  }
  cout<<dp[H][K-1]<<endl;
}


Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){


int X;
cin>>X;
vector<int> list;
rep4(i,2,X){
    for(int j=2;(int)pow(i,j)<=X;j++){
        list.push_back((int)pow(i,j));
    }

}
if(list.size()==0){
    cout<<1<<endl;
}
else{
sort(allr(list));
cout<<list[0]<<endl;
}

return 0;
}

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

class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int c = Integer.parseInt(st.nextToken());
        int count = 0;
        for (int i = a; i <= b; i++) {
            if (c % i == 0) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 24256
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_D
  * Structured Program I - Structured Programming
  */
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    //Memory Limit Exceeded
    //    val result = (1 to n).filter(i => i % 3 == 0 || i.toString.contains('3'))
    //      .foldLeft("") { (str, i) => str + s" $i" }
    val result = " " + (1 to n).filter(i => i % 3 == 0 || i.toString.contains('3')).mkString(" ")
    println(result)
  }
}

Measured memory_bytes: 47584
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>'10000000'},'ruby',$0)
n,m=gets.split(" ").map(&:to_i)
@edge=Array.new(n){[]}
@depth=Array.new(n,-1)
m.times{
    a,b=gets.split(" ").map{|k|k.to_i-1}
    @edge[a].<<b
    @edge[b].<<a
}
def check(cur,val)
    @depth[cur]=val
    ok=true
    for i in @edge[cur] do
        if @depth[i]==-1 then
            ok&=check(i,1^val)
        elsif @depth[i]==@depth[cur] then
            return false
        end
    end
    return ok
end
if check(0,0) then
    blk=0
    whi=0
    for i in 0...n do
        blk,whi=blk+@depth[i],whi+1-@depth[i]
    end
    puts blk*whi-m
else
    puts n*(n-1)/2-m
end

Measured memory_bytes: 68292
#include <bits/stdc++.h>
        using namespace std;
        struct point
        {
            unsigned long long x;
            unsigned long long y;

        }Ratio[1010];


        int main(void)
        {
            ios::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            long long N;
            cin>>N;
            for(long long i=0;i<N;i++)
            {
                cin>>Ratio[i].x;
                cin>>Ratio[i].y;
            }
            for(long long i=1;i<N;i++)
            {
               unsigned long long t1,t2;
               if(Ratio[i-1].x%Ratio[i].x==0)
               {
                   t1=Ratio[i-1].x/Ratio[i].x;
               }
               else
               {
                   t1=Ratio[i-1].x/Ratio[i].x+1;
               }
               if(Ratio[i-1].y%Ratio[i].y==0)
               {
                   t2=Ratio[i-1].y/Ratio[i].y;
               }
               else
               {
                   t2=Ratio[i-1].y/Ratio[i].y+1;
               }
               unsigned long long j=max(t1,t2);
               Ratio[i].x=Ratio[i].x*j;
               Ratio[i].y=Ratio[i].y*j;
            }
            cout <<Ratio[N-1].x+Ratio[N-1].y<<endl;
            return 0;
        }


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
long long dis[100005];
long long vis[100005];
long long y[100005];
long long z[100005];
int main()
{
    long long C,N,form=0;
    long long you=0,temp=0,zuo=0,ymax=0,zmax=0;
    scanf("%lld %lld",&N,&C);
    for(int i=1;i<=N;i++)
    {
        scanf("%lld %lld",&dis[i],&vis[i]);
        temp=vis[i]+temp-dis[i]+form;
        form=dis[i];
        if(ymax<temp-dis[i])
            ymax=temp-dis[i];
        y[i+1]=ymax;
        if(you<temp)
            you=temp;
    }
    y[1]=0;
    temp=0;
    form=C;
    for(int i=N;i>0;i--)
    {
        temp=vis[i]+temp-(form-dis[i]);
        if(zmax<temp-(C-dis[i]))
            zmax=temp-(C-dis[i]);
            z[i-1]=zmax;
        if(zuo<temp+y[i])
            zuo=temp+y[i];
        form=dis[i];
    }
    z[N]=0;
    temp=0;
    form=0;
    for(int i=1;i<=N;i++)
    {
        temp=vis[i]+temp-dis[i]+form;
        form=dis[i];
        if(you<temp+z[i])
            you=temp+z[i];
    }
    if(zuo>you)
        printf("%lld\n",zuo);
    else
        printf("%lld\n",you);
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
const int maxn=200000+10;
int fa[maxn],a[maxn];
int find(int u)
{
    return u==fa[u]?u:fa[u]=find(fa[u]);
}
void Union(int x,int y)
{
    fa[find(x)]=fa[find(y)];
}
int main()
{
    int n,m,x,y;
    cin>>n>>m;
    for(int i=1;i<=n;i++) fa[i]=i;
    while(m--)
    {
        cin>>x>>y;
        if(find(x)!=find(y))
            Union(x,y);
    }
    for(int i=1;i<=n;i++) a[find(fa[i])]++;
    sort(a+1,a+n+1);
    cout<<a[n]<<endl;
    return 0;
}


Measured memory_bytes: 7056
import sys

sys.setrecursionlimit(300000)

N = int(input())

memo = [None for _ in range(N + 1)]


def f(n):
    if n == 0:
        return 0
    if memo[n] is not None:
        return memo[n]
    ans = n
    pow = 1
    while pow <= n:
        ans = min(ans, f(n - pow) + 1)
        pow *= 6
    pow = 1
    while pow <= n:
        ans = min(ans, f(n - pow) + 1)
        pow *= 9
    memo[n] = ans
    return ans


print(f(N))

Measured memory_bytes: 89752
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[int(input()) - 1])


Measured memory_bytes: 2940
if __name__ == "__main__":
    x = int(input())
    mask = (1 << 32) - 1
    print(f"{x:032b}")
    print(f"{~x & mask:032b}")
    print(f"{(x << 1) & mask:032b}")
    print(f"{(x >> 1) & mask:032b}")



Measured memory_bytes: 5616
#include <iostream>
#include <algorithm>
 
using ll=long long int;

ll q,h,s,d,n;

int main() {

    std::cin>>q>>h>>s>>d>>n;

    q*=4;
    h*=2;

    s=std::min({q,h,s});

    if(s*2<=d)
        std::cout<<n*s<<std::endl;
    else
        std::cout<<(n/2*d+(n%2)*s)<<std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define  fst first
#define  snd second
typedef pair<int,int> pii;
const ll mod=1e9+7;
const ll N = 2001;
ll a[N];
pii na[N];
ll k;
ll n;
ll res1=0,res2=0;
int bs(int low,int high,int idx){
int ans=n;
int target=na[idx].fst;
while(low<=high){
    int mid=(low+high)/2;
    pii temp=na[mid];
    if(temp.fst>target){
        ans=mid;high=mid-1;
    }
    else if(temp.fst<=target){
        low=mid+1;
    }
}
return ans;
}
int main(){
cin>>n>>k;
for(int i=0;i<n;i++){cin>>a[i];na[i]={a[i],i};}
multiset<ll> s;
for(int i=0;i<n;i++){s.insert(a[i]);auto it=upper_bound(s.begin(),s.end(),a[i]);if(it!=s.end()){ ll val=distance(s.begin(),it);res1+=s.size()-val;}}
sort(na,na+n);
for(int i=0;i<n;i++){
    res2+=n-bs(0,n,i);
}
ll fans=((((k*(k-1))/ (ll)2)%mod*res2)%mod+(k*res1)%mod)%mod;
cout<<fans<<endl;
return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
	int a,b,c,d;
	int x,y;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	x=a+b;
	y=c+d;
	if(x==y) printf("Balanced\n");
	else if(x>y) printf("Left\n");
	else printf("Right\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
const int maxn=8e2+10;
using namespace std;
char a[maxn][maxn];
int stmp[maxn][maxn];
int direction[4][2]={1,0,-1,0,0,1,0,-1};
int n,m,k;
int ans=99999999;
bool check(int x,int y){
    if(x>=0 && x<n && y>=0 && y<m && stmp[x][y]==0 && a[x][y]=='.'){
       return 1;
    }
    return 0;
}
queue<pair<int,int> >po;
int main(){
    cin>>n>>m>>k;
    int sx,sy;
    getchar();
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
            if(a[i][j]=='S'){
                sx=i;
                sy=j;
            }
        }
        getchar();
    }
    stmp[sx][sy]=1;
    po.push(make_pair(sx,sy));
    while(!po.empty()){
        int x=po.front().first;
        int y=po.front().second;
        ans=min(ans,min(min(x,n-x-1),min(y,m-y-1)));
        po.pop();
        for(int i=0;i<4;i++){
            int xx=x+direction[i][0];
            int yy=y+direction[i][1];
            if(check(xx,yy)&&stmp[x][y]<=k){
               stmp[xx][yy]=stmp[x][y]+1;
               po.push(make_pair(xx,yy));
            }
        }
    }
    int anss;
    anss=1+(ans+k-1)/k;
    cout<<anss<<endl;
    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    int a,b;
    cin >> a >> b;
    int c;
    cin >> c;
    if(a+b>=c){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 768
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

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

template<typename has_less>
using ordered_set =
tree<has_less,
	null_type,
	less<has_less>,
	rb_tree_tag,
	tree_order_statistics_node_update>;
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define fast_cin() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define lc (sidx * 2)
#define rc (lc + 1)

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

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

bool bit(int n, int i) { return (n >> i) & 1; }
int ceil(int a, int b) { return ceil(((ld)a) / b); }

int faltu;

const int mod = 1e9+7;
const ll inf = 5e18;
const int N = 2e5 + 100;

int n, m, q;
ll a[N];
ll ans = 0;

int main()
{
	fast_cin();
	srand(time(0));

	cin >> n;
	map <int, int> mp;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		mp[a[i]] ++;
	}
	for(ll num = (1ll << 32); num > 0; num /= 2) {
		for(int i = 1; i <= n; i++) {
			if(num != 2 * a[i] and a[i] <= num and mp[num - a[i]] > 0 and mp[a[i]] > 0) {
				mp[num - a[i]]--;
				mp[a[i]]--;
				ans++;
			} else if(num == 2 * a[i] and mp[num - a[i]] >= 2) {
				mp[a[i]] -= 2;
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 53120
// atcoder/m-solutions2019/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    cout << (n - 2) * 180 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define INFTY 100000
#define SHIRO 0
#define HAI 1
#define KURO 2

int omomi();
 
int A[MAX][MAX],n;

int main(){

  int i,j,hantei;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){

      scanf("%d",&hantei);
      if(hantei == -1) A[i][j] = INFTY;
      else A[i][j] = hantei;

    }
  }

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

  return 0;
}


int omomi()
{

  int sum=0;
  int i,v,u,minv;
  int d[MAX],p[MAX],color[MAX];

  for(i=0;i<n;i++){
    color[i] = SHIRO;
    p[i] = -1;
    d[i] = INFTY;
  }
  d[0] = 0;


  while(1){
    minv = INFTY;
    u = -1;
    for(i=0;i<n;i++){
      if(minv > d[i] && color[i] != KURO){
	u =i;
	minv = d[i];
      }
    }
    if(u==-1)break;
    color[u] = KURO;
    for(v=0;v<n;v++){


      if(color[v] != KURO && A[u][v] != INFTY){
	if(d[v] > A[u][v]){
	  d[v] = A[u][v];
	  p[v] = u;
	  color[v] = HAI;
	}
      }
    }
  }

  for(i=0;i<n;i++){
    if(p[i] != -1) sum += A[i][p[i]];
  }






  return sum;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
#define MAX 10000
#define NIL -1
using namespace std;

int n,pos;
vector<int> pre,in,post;

void rec(int l,int r)
{
    if(l>=r)return;
    int root=pre[pos++];
    int m=distance(in.begin(),find(in.begin(),in.end(),root));
    rec(l,m);
    rec(m+1,r);
    post.push_back(root);
}

void solve()
{
    pos=0;
    rec(0,pre.size());
    for(int i=0;i<n;i++)
    {
        if(i)cout<<" ";
        cout<<post[i];
    }
    cout<<endl;
}

int main()
{
    int k;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>k;
        pre.push_back(k);
    }
    for(int i=0;i<n;i++)
    {
        cin>>k;
        in.push_back(k);
    }

    solve();

 	return 0;
}



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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a <= b){
    if(c <= a){
      cout << c << " " << a << " " << b << endl;
    }else if(b <= c){
      cout << a << " " << b << " " << c << endl;
    }else{
      cout << a << " " << c << " " << b << endl;
    }    
  }else{
    if(c <= b){
      cout << c << " " << b << " " << a << endl;
    }else if(a <= c){
      cout << b << " " << a << " " << c << endl;
    }else{
      cout << b << " " << c << " " << a << endl;
    }
  }
}

Measured memory_bytes: 3096
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e3+5, M = 4e6+5, P = 1e9+7;
int n, m, f[N][N], fac[M], ifac[M], inv[M], ans;
int C(int n, int m) { return 1ll*fac[n]*ifac[n-m]%P*ifac[m]%P; }
int main()
{
    n = read(), m = read(); 
    inv[1] = ifac[0] = fac[0] = 1; 
    for(int i = 2; i <= n*m; ++i) inv[i] = 1ll*(P-P/i)*inv[P%i]%P;
    for(int i = 1; i <= n*m; ++i) fac[i] = 1ll*i*fac[i-1]%P, ifac[i] = 1ll*inv[i]*ifac[i-1]%P;
    f[0][0] = 1;
    for(int i = 1; i <= n; ++i)
        for(int j = 0; j <= i; ++j)
        {
            f[i][j] = f[i-1][j];
            if(j) f[i][j] = (f[i][j]+1ll*f[i][j-1]*(n-j+1)%P*C(n*m-i-(j-1)*(m-1)-1, m-2)%P)%P;
        }
    printf("%d\n", m == 1?1:f[n][n]);
    return 0;
}

Measured memory_bytes: 62720
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = (readLine()!!.split(' ').map(String::toInt).sorted())
    val bList = (readLine()!!.split(' ').map(String::toInt).sorted())
    val cList = (readLine()!!.split(' ').map(String::toInt).sortedDescending())

    var count = 0L
    for (i in 0 until n) {
        val aCount = aList.fastIndexOfLast { it < bList[i] } + 1
        val cCount = cList.fastIndexOfLast { it > bList[i] } + 1
        count += aCount.toLong() * cCount.toLong()
    }
    println(count)
}

inline fun <T> List<T>.fastIndexOfLast(predicate: (T) -> Boolean): Int {
    var left = 0
    var right = size - 1
    while (left < right) {
        val index = ((left + right) / 2)
        if (predicate(this[index])) {
            left = index + 1
        } else {
            right = index
        }
    }
    return if (predicate(this[left])) {
        left
    } else {
        left - 1
    }
}

Measured memory_bytes: 109896
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;
bool C = true;
cin >> S;
int c = (int)(S.length());
for(int i = 0; i < c; i++){
if((i % 2 == 0 && S[i] == 'L') || (i % 2 == 1 && S[i] == 'R')){
  C = false;
  break;
  }
}
  printf(C ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,k;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	if(k<=a)
		printf("%d",k);
	else if(k<=a+b)
		printf("%d",a);
	else
		printf("%d",a-(k-a-b));
}

Measured memory_bytes: 3812
#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)

using ll = long long;
#define INF 1e9

const int mod = 1e9+7;
int H, W;
vector<vector<int>> A, B, diff;
int maxk = 160 * 160;
int dp[85][85][160*160+300] = {0};
int main(){
  cin >> H >> W;
  A.resize(H, vector<int>(W)), B.resize(H, vector<int>(W)), diff.resize(H, vector<int>(W));
  REP(i, H){
    REP(j, W){
      cin >> A[i][j];
    }
  }
  REP(i, H){
    REP(j, W){
      cin >> B[i][j];
      diff[i][j] = abs(A[i][j]-B[i][j]);
    }
  }
  dp[0][0][maxk/2+diff[0][0]] = dp[0][0][maxk/2-diff[0][0]]= 1;
  REP(i, H){
    REP(j, W){
      if(i-1 >= 0){
        REP(k, maxk){
          if(dp[i-1][j][k] == 1){
            dp[i][j][k+diff[i][j]] = dp[i][j][k-diff[i][j]] = 1;
          }
        }
      }
      if(j-1 >= 0){
        REP(k, maxk){
          if(dp[i][j-1][k] == 1){
            dp[i][j][k+diff[i][j]] = dp[i][j][k-diff[i][j]] = 1;
          }
        }
      }
    }
  }
  int ans = INF;
  REP(i, maxk){
    if(dp[H-1][W-1][i] == 1){
      ans = min(ans, abs(i-maxk/2));
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  long long l[87];
  l[0]=2;
  l[1]=1;
  for (int i = 2; i < 87; i++) {
    l[i] = l[i - 1] + l[i - 2];
  }

  cout << l[n] << endl;
  return 0;
}


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

using namespace std;

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

Measured memory_bytes: 3160
#include<stdio.h>
#include<string.h>

#define SIZE 1001

int lcs(char* s1, char* s2){
	int len1, len2;
	int c[SIZE][SIZE];
	int i, j;
	int max=0;

	len1 = strlen(s1);
	len2 = strlen(s2);
	for(i=0;i<=len1;i++)
	    for(j=0;j<=len2;j++) c[i][j]=0;
	    
	for (int i = 0; i < len1; i++){
		for (int j = 0; j < len2; j++){
			if (s1[i] == s2[j]) c[i+1][j+1] = c[i][j] + 1;
			else {
				if (c[i + 1][j] < c[i][j + 1]) c[i+1][j+1] = c[i][j + 1];
				else c[i+1][j+1] = c[i + 1][j];
			}
			if (max < c[i+1][j+1]) max = c[i+1][j+1];
		}
	}

	return max;
}

int main(){
	int i,n,max;
	char s1[SIZE], s2[SIZE];

	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf(" %s%s", s1, s2);
		max = lcs(s1, s2);
		printf("%d\n",max);
	}

	return 0;
}



Measured memory_bytes: 5648
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# 23:39

S = list(sys.stdin.readline().rstrip())

ans = None
for op in itertools.product('+-', repeat=len(S) - 1):
    f = S[0] + op[0] + S[1] + op[1] + S[2] + op[2] + S[3]
    if eval(f) == 7:
        ans = f + '=7'
        break
print(ans)


Measured memory_bytes: 13760
package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func main() {
    sc.Split(bufio.ScanWords)
    defer w.Flush()

    a := nextInt()
    b := nextInt()

    fmt.Fprintln(w, a*b)
}

func nextStr() string {
    sc.Scan()
    s := sc.Text()
    return s
}

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

Measured memory_bytes: 1760
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int t,h,w,n;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool inside(int x,int y){
	if(x>=0 && x<w && y>=0 && y<h)return true;
	else return false;
}

int main(){
	cin>>t;
	rep(p,t){
		cin>>h>>w;
		string dt[h];
		char dir;
		int x,y;
		rep(i,h){
			cin>>dt[i];
			rep(j,w){
				if(dt[i][j]=='^'){x=j;y=i;dir='^';dt[i][j]='.';}
				if(dt[i][j]=='>'){x=j;y=i;dir='>';dt[i][j]='.';}
				if(dt[i][j]=='<'){x=j;y=i;dir='<';dt[i][j]='.';}
				if(dt[i][j]=='v'){x=j;y=i;dir='v';dt[i][j]='.';}
			}
		}
		cin>>n;
		string com;
		cin>>com;
		rep(i,com.size()){
			if(com[i]=='U'){dir='^';if(inside(x,y-1) && dt[y-1][x]=='.')y--;}
			if(com[i]=='D'){dir='v';if(inside(x,y+1) && dt[y+1][x]=='.')y++;}
			if(com[i]=='L'){dir='<';if(inside(x-1,y) && dt[y][x-1]=='.')x--;}
			if(com[i]=='R'){dir='>';if(inside(x+1,y) && dt[y][x+1]=='.')x++;}
			if(com[i]=='S'){
				int mx=x,my=y;
				if(dir=='^')my--;
				if(dir=='v')my++;
				if(dir=='<')mx--;
				if(dir=='>')mx++;
				while(inside(mx,my) &&(dt[my][mx]=='.' || dt[my][mx]=='-')){
					if(dir=='^')my--;
					if(dir=='v')my++;
					if(dir=='<')mx--;
					if(dir=='>')mx++;
				}
				if(inside(mx,my) && dt[my][mx]=='*')dt[my][mx]='.';
			}
		}
		rep(i,h){
			rep(j,w){
				if(i==y && j==x)cout<<dir;
				else cout<<dt[i][j];
			}
			cout<<endl;
		}
	if(p!=t-1)cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

  for (int i = 0; i < n; ++i) {
    vector<int> seq;
    for (int j = 0; j < 8; ++j) {
      char c;
      cin >> c;
      seq.push_back(c - '0');
    }

    int vmax = 0;
    int vmin = 0;

    sort(seq.begin(), seq.end());
    for (int j = 0; j < 8; ++j)
      vmin = vmin * 10 + seq[j];
    sort(seq.rbegin(), seq.rend());
    for (int j = 0; j < 8; ++j)
      vmax = vmax * 10 + seq[j];

    cout << vmax - vmin <<endl;
  }
}


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

int main(){
  string S;
  cin >> S;
  if(S.at(0)==S.at(1) || S.at(1)==S.at(2) || S.at(2)==S.at(3)){
    cout << "Bad" << endl;
  }
  else cout << "Good" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int p = 9;
int q = 5;
while (p != 0 || q != 0) {
p = scan.nextInt();
q = scan.nextInt();
if (p == q && p == 0) {
break;
}
if (p > q) {
System.out.println(q + " " + p);
} else {
System.out.println(p + " " + q);
}

} 

}
}



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

int main(){
  int n;
  cin >> n;
  map<string,int> mp;
  string pre;
  cin >> pre;
  mp[pre]  = 1; 
  string tmp;
  for(int i=0; i<(n-1); i++){
    cin >> tmp;
    if(mp[tmp]==1){cout << "No" << endl; return 0;}
    mp[tmp] = 1;
    if(pre.at(pre.size()-1)!=tmp.at(0)){cout <<"No" << endl; return 0;}
    pre = tmp;
  }
  cout <<  "Yes" << endl; 
}
       

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vector<long long> divisor(long long n) {
    vector<long long> res;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  auto div = divisor(n);
  for (auto r : div) {
    ll m = (n-r)/r;
    if (m && n%m == r)
      ans += m;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a<b)
	cout<<"a < b"<<endl;
	else if(a==b)
	cout<<"a == b"<<endl;
	else
	cout<<"a > b"<<endl;
	return 0;
}


Measured memory_bytes: 3076
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}


struct rmq {
	int seg_n;
	vector<ll> dat;
	void init(int n, ll initial_value = INF){
		seg_n = 1;
		while(seg_n<n) seg_n<<=1;
		dat = vector<ll>(seg_n*2-1, initial_value);
	}

	// v[k] <- a
	void update(int k, ll a){
		k += seg_n - 1;
		dat[k] = a;
		while(k>0){
			k = (k-1)/2;
			dat[k] = min(dat[k*2+1], dat[k*2+2]);
		}
	}

	// min(v[a], v[a+1],..., v[b-1])
	// to use: query(a, b);
	ll rmin(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return INF;
		if(a <= l && r <= b) return dat[k];
		return min(rmin(a, b, k*2+1, l, (l+r)/2), rmin(a, b, k*2+2, (l+r)/2, r));
	}

	ll rmin(int a, int b){
		return rmin(a, b, 0, 0, seg_n);
	}
};


#define N 200010
ll b[2][N], s[2][N], q, n;

int main(){
	cin>>n;
	rep(i, n){
		ll x;
		cin>>x;
		b[0][i] = x?1:0;
		b[1][i] = x?-1:1;
	}
	rep(j, 2) rep(i, n) s[j][i+1] = s[j][i]+b[j][i];
	rmq dp, dp2;
	dp.init(n+10); dp2.init(n+10);
	dp.update(0, s[0][n]);
	dp2.update(0, s[0][n]+s[1][n]);
	cin>>q;
	vector<P> lr(q);
	rep(i, q){
		ll l, r;
		cin>>l>>r; l--;
		lr[i] = P(l, r);
	}
	sort(all(lr));
	rep(i, q){
		ll l = lr[i].fst, r = lr[i].snd;
		ll x = dp.rmin(0, l)+s[1][r]-s[1][l]; ll x2 = x;
		ll y = dp2.rmin(l, r)-s[1][n]+s[1][r];
		//cerr<<dp2.rmin(l, r)<<" "<<s[1][n]<<" "<<s[1][r]<<endl;
		chmin(x, y);
		ll z = dp.rmin(r, r+1);
		if(x<z){
			dp.update(r, x);
			dp2.update(r, x+s[1][n]-s[1][r]);
			//cerr<<"dp: "<<r<<" "<<x<<endl;
			//cerr<<"dp2: "<<r<<" "<<x+s[1][n]-s[1][r]<<endl;
		}
		//cerr<<i<<": "<<l<<" "<<r<<" "<<x-s[0][n]+s[0][r]<<" "<<x2<<" "<<y<<" "<<z<<endl;
	}
	cout<<dp.rmin(0, n+1)<<endl;
	/*cerr<<"dump"<<endl;
	rep(i, n+1){
		cerr<<i<<" "<<dp.rmin(i, i+1)<<" "<<dp2.rmin(i, i+1)<<" "<<dp.rmin(i, i+1)-s[0][n]+s[0][i]<<endl;
	}*/
	return 0;
}


Measured memory_bytes: 17920
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> 
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;

 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
const int N=1e6+5;
vll t;
ll m[N];
bool fun(ll n)
{
	ll i;
	if(n==1 and m[1]==1)
		return true;
	if(m[1] or m[n]>1)
		return false;
	for(i=2;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			if(m[i] or m[n/i])
				return false;
		}
	}
	return true;
}
int main()
{
	fast();
	ll n,i;
	cin>>n;
	ll a[n];
	
	rep(i,n){
		cin>>a[i];
		m[a[i]]++;
	}
	ll ans=0;
	for(i=0;i<n;i++)
	{
		//t.clear();
		if(fun(a[i]))
			ans++;
	}
	cout<<ans;

}

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

int main(){
  int count0=0,count1=0;
  string s;
  cin>>s;
  for(int i=0; i<s.size(); i++){
    if(s[i]=='0') count0++;
    else count1++;
  }
  cout<<2 * min(count0,count1);
}

Measured memory_bytes: 512