akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

int n;
int sums[101] = {0};

int main(){

    while (cin >> n, n) {
        for(int i = 0; i < 100; i++) sums[i] = 0;
        
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 5; j++){
                int tmp;
                cin >> tmp;
                sums[i] += tmp;
            }
        }
        sort(sums,sums+n);
        cout << sums[n-1] << ' ' << sums[0] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1176
#include"bits/stdc++.h"
#include"math.h"
using namespace std;

int main(){
  
  int N, L;
  cin >> N >> L;
  
  vector<int> s(N);
  vector<int> a(N);
    int sum=0;
    for(int i=0; i<N ; i++){
      a.at(i)= L+i;
      sum+=a.at(i);
      s.at(i)= fabs(L+i);}
  
  int x=0;
  
  int c=min(fabs(s.at(0)), fabs(s.at(1)));
  for(int i=0; i<N-1 ; i++){
    c=min(c , s.at(i+1));
  }
  
  for(int i=0; i<N ; i++){
    if(c == fabs(L+i)){
      x = i+1;
  }}
  
  sum=sum-L-x+1;
    cout << sum << endl;
}
  
  
  
  

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

int main(){
    int n;
    cin >>n;
    vector<int> data(n);
    for (int i=0;i<n;i++){
        cin>>data.at(i);
    }
    int result = 0;
    for(int i=0;i<n;i++){
        for(int k=0;k<n&&i!=k;k++){
            result +=data.at(i) * data.at(k);
        }
    }
    cout << result <<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned 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; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));


int main(){
    vector<char> ans;
    while(true){
        int m, f, r;
        cin >> m >> f >> r;
        if(m == -1 and f == -1 and r == -1) break;
        if(m == -1 or f == -1) ans.push_back('F');
        else if(m + f >= 80) ans.push_back('A');
        else if(m + f >= 65) ans.push_back('B');
        else if(m + f >= 50) ans.push_back('C');
        else if(m + f >= 30){
            if(r >= 50) ans.push_back('C');
            else ans.push_back('D');
        }else ans.push_back('F');
    }
    for(char s : ans) cout << s << endl;
}


Measured memory_bytes: 3136
N = int(input())
A = list(map(int, input().split()))

DP_odd = [0, A[0]]
DP_even = [0, max(A[0], A[1])]

for i in range(2, N):
    if (i + 1) % 2 == 1:    
        DP_odd = [max(DP_odd[0] + A[i], DP_even[1]), DP_odd[1] + A[i]]
    else:
        DP_even = [max(DP_even[0] + A[i], DP_odd[0]), max(DP_even[1] + A[i], DP_odd[1])]

if N % 2 == 1:
    ans = DP_odd[0]
else:
    ans = DP_even[1]

print(ans)

Measured memory_bytes: 31624
X, K, D=(map(int, input().split()))
X=abs(X)

        
N=int(X/D)

if N==0:
    if K%2==0:
        print(X)
    else:
        print(D-X)
else:
    if N>K:
        print(X-K*D)
    elif (K-N)%2==0:
        print(X-N*D)
    else:
        print((N+1)*D-X)

Measured memory_bytes: 9084
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 1
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <random>
#include <ctime>

#define MOD 1000000007

const long long INF = 10000000000000000;

using namespace std;

int main(){
	long long N,C,K;
	cin>>N>>C>>K;
	vector<long long> T(N);
	for(int i=0;i<N;i++){
		cin>>T[i];
	}
	int ans=0;
	sort(T.begin(),T.end());
	for(long long i=0;i<N;i++){
		long long tmp=i;
		for(long long j=i+1;j<N;j++){
			//cout<<T[j]<<" "<<T[i]+K<<" "<<endl;
			if(T[j]>T[i]+K){
				//cout<<i<<" to "<<j-1<<endl;
				//i=j-1;
				break;
			}else if(j>=i+C){
				//cout<<i<<" to "<<j-1<<endl;
				//i=j-1;
				break;
			}else{
				tmp=j;
			}			
		}
		i=tmp;
		//cout<<"i="<<i<<endl;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,k;cin >> m >> k;
  if(k>=(1<<m)){
    cout << -1 << endl;
    return 0;
  }
  if(m==0){
    cout << 0 << " " << 0 << endl;
    return 0;
  }
  if(m==1){
    if(k==0){
      cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl;
    }
    else{
      cout << -1 << endl;
    }
    return 0;
  }
  for(int i=0;i<(1<<m);i++){
    if(i!=k){
      cout << i << " ";
    }
  }
  cout << k << " ";
  for(int i=(1<<m)-1;i>=0;i--){
    if(i!=k){
      cout << i << " ";
    }
  }
  cout << k << endl;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pushb push_back
#define popb pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};

intl pow(intl a,intl n){
  intl ans=1;
  Rep(i,n) ans *=a;
  return ans;
}

int main(){
  vec<char> A(6);
  Rep(i,6) cin >>A[i];
  if( A[4]==A[5] && A[2]==A[3]){cout << "Yes";}
  else{cout <<"No";}
}
  

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long s=0,i,j,h,w,n,m,x[100010],y[100010],M=1e9+7,a,b,l=0;
  scanf("%lld %lld",&n,&m);
  for(i=0;i<n;i++)scanf("%lld",&x[i]);
  for(j=0;j<m;j++)scanf("%lld",&y[j]);
  h=(y[m-1]-y[0])%M;
  w=(x[n-1]-x[0])%M;
  for(i=1;i<n;i++){
    a=(x[i]-x[i-1])%M;
    b=(i*(n-i))%M;
    l=(l+(a*b)%M)%M;
  }
  for(i=1;i<m;i++){
    a=(y[i]-y[i-1])%M;
    b=(i*(m-i))%M;
    s=(s+(l*(a*b%M)%M))%M;
  }
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 1664
import Control.Monad
import Control.Applicative
import Data.List

main :: IO()
main = do
  s <- getLine
  putStrLn $ oddString s


oddString :: String -> String
oddString s = f [] s True
    where
      f :: String -> String-> Bool -> String
      f acc   []    _    = reverse acc
      f acc (x:xs) True  = f (x:acc) xs False
      f acc (x:xs) False = f acc xs True


Measured memory_bytes: 6268
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

n = int(input())
a = list(map(int, input().split()))
def med(x):
    cum = [0] * (n+1)
    for i in range(n):
        if a[i] >= x:
            cum[i+1] = cum[i] + 1
        else:
            cum[i+1] = cum[i] - 1
    m = min(cum)
    for i in range(n+1):
        cum[i] -= m - 1
    zb = Bit(max(cum))
    ret = 0
    for j in range(n+1):
        ret += zb.sum(cum[j])
        zb.add(cum[j], 1)
    return ret
b = sorted(a)
l = 0
r = n
while(r - l > 1):
    mid = (l + r + 1) // 2
    if 2 * med(b[mid]) >= n * (n+1) // 2:
        l = mid
    else:
        r = mid
print(b[l])


Measured memory_bytes: 84836
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
  int i,j;
  int m,n,o,u,v;
  while(cin>>m>>n>>o>>u>>v,m||n||o||u||v){
    u--;
    v--;
    int a[8];
    for(i=0;i<m;++i)
      cin>>a[i];
    int b[30][30]={};
    for(i=0;i<o;++i){
      int p,q,r;
      cin>>p>>q>>r;
      p--;
      q--;
      b[p][q]=b[q][p]=r;
    }
    int c[30][1<<8];
    fill(c[0],c[0]+30*(1<<8),-1);
    priority_queue<pair<double,pair<int,int> >,vector<pair<double,pair<int,int> > >,greater<pair<double,pair<int,int> > > > e;
    e.push(make_pair(0,make_pair(u,0)));
    while(!e.empty()){
      double z;
      int x,y;
      z=e.top().first;
      x=e.top().second.first;
      y=e.top().second.second;
      if(x==v)
	break;
      e.pop();
      if(c[x][y]){
	c[x][y]=0;
	for(i=0;i<m;++i){
	  if(!(y&(1<<i))){
	    for(j=0;j<n;++j){
	      if(b[x][j]&&c[j][y|(1<<i)])
		e.push(make_pair(z+(double)b[x][j]/a[i],make_pair(j,y|(1<<i))));
	    }
	  }
	}
      }
    }
    if(e.empty())
      cout<<"Impossible"<<endl;
    else
      cout<<e.top().first<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Where((x, y) => x % 2 == 1 && y % 2 == 0).Count());
    }
}


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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	string S;
	cin >> S;
	int n = S.size();
	int count = 0;
	For(i,1,n){
		if(S[i] != S[i-1]){
			count ++ ;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main (void) {
    int A, B;
    int resp;

    cin >> A >> B;
    resp = (A + B);

    if ((A - B) > resp) {
        resp = (A - B);
    }

    if ((A * B) > resp) {
        resp = (A * B);
    }

    cout << resp << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define max2(a,b) ((a)>(b)?(a):(b))   
#define min2(a,b) ((a)<(b)?(a):(b)) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef pair<ll,ll>     pll;
typedef pair<int,int>   pii;
typedef vector<ll>      vll;
typedef vector<int>      vi;
typedef vector< pll >  vpll;
typedef vector< pii >  vpii;
typedef set<ll>         sll;
typedef set<int>         si;
typedef set< pll >     spll;
typedef set< pii >     spii;
clock_t clk=clock();       

ll i,j,k;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
// #define cerr if(0)cerr

void solve()
{
	int n; cin>>n;
	double arr[n],sum=0.0;
	rep(i,0,n-1)
	{
		cin>>arr[i];
		arr[i]=(1/arr[i]);
		sum+=arr[i];
	}
	sum=(1/sum);
	cout<<fixed<<setprecision(10)<<sum<<'\n';
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	string s;
	cin >> s;
	int a = 0;
	if (s == "SUN")
		a = 7;
	if (s == "MON")
		a = 6;
	if (s == "TUE")
		a = 5;
	if (s == "WED")
		a = 4;
	if (s == "THU")
		a = 3;
	if (s == "FRI")
		a = 2;
	if (s == "SAT")
		a = 1;
	cout << a << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

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

	int h, w;
	cin >> h >> w;
	vector<vector<bool>> grid(h, vector<bool>(w));
	vector<vector<vector<pair<ii, ii>>>> sol(h, vector<vector<pair<ii, ii>>>(w));

	for ( int i = 0 ; i < h ; i++ ){
		for ( int j = 0 ; j < w; j++ ){
			char tmp;
			cin >> tmp;
			grid[i][j] = tmp == '#';
		}
	}
	for ( int i = 0 ; i < h ; i++ ){
		for ( int j = 0 ; j < w ; j++ ){
			bool equal = false;
			pair<ii, ii> p1, p2;

			if ( i > 0 && j > 0 ){
				if ( sol[i-1][j].size() == sol[i][j-1].size() ){
					if ( grid[i][j] && !sol[i-1][j].empty() ){
						equal = true;
						p1 = sol[i-1][j].back();
						p2 = sol[i][j-1].back();
					}else{
						sol[i][j] = sol[i-1][j];
					}
				}else if ( sol[i-1][j].size() > sol[i][j-1].size() ){
					sol[i][j] = sol[i][j-1];
				}else{
					sol[i][j] = sol[i-1][j];
				}
			}else if ( j > 0 ){
				sol[i][j] = sol[i][j-1];
			}else if ( i > 0 ){
				sol[i][j] = sol[i-1][j];
			}

			if ( grid[i][j] ){
				if ( equal ){
					if ( (p1.second.first == i - 1 && p1.second.second == j) || (p1.second.first == i && p1.second.second == j - 1) ){
						sol[i][j] = sol[i-1][j];
						sol[i][j].back() = make_pair(p1.first, ii(i,j));
					}else if ( (p2.second.first - 1 == i && p2.second.second == j) || (p2.second.first == i && p2.second.second == j - 1) ){
						sol[i][j] = sol[i][j-1];
						sol[i][j].back() = make_pair(p2.first, ii(i,j));
					}else{
						sol[i][j] = sol[i-1][j];
						sol[i][j].emplace_back(ii(i,j), ii(i, j));
					}
					equal = false;
				}else if ( sol[i][j].empty() ){
					sol[i][j].emplace_back(ii(i,j), ii(i, j));
				}else{
					pair<ii, ii> p;
					p = sol[i][j].back();
					if ( (p.second.first == i - 1 && p.second.second == j) || (p.second.first == i && p.second.second == j - 1) )
						sol[i][j].back() = make_pair(p.first, ii(i,j));
					else
						sol[i][j].emplace_back(ii(i,j), ii(i, j));
				}

			}
		}
	}

	/*
	for ( auto l : sol ) {
		for ( auto v : l ) {
			cout << v.size() << " ";
		}
		cout << "\n";
	}
	*/

	cout << sol.back().back().size() << "\n";

	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;

  if (n == 1) {
    cout << "Hello World" << endl;
  } else {
    ll a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }

  return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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;}

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;
}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    ll r, d, x; cin >> r >> d >> x;
    REP(i, 0, 10){
        x = r * x - d;
        cout << x << endl;
    }
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size(); i++) cout << xs[i] << (i==xs.size()-1?'\n':' ');
	if(xs.empty()) cout << endl;
	else cout << flush;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

// Z array: Z[i] = maximum n s.t. str[0..n] == str[i..i+n]
template<class It>
std::vector<int> getZarray(It begin, It end) {
	int n = end - begin;
	std::vector<int> Z(n);
	int L, R, k;
	// [L,R] make a window which matches with prefix of s
	L = R = 0;
	for (int i=1; i<n; i++) {
		// if i>R nothing matches so we will calculate.
		// Z[i] using naive way.
		if (i > R) {
			L = R = i;
			// R-L = 0 in starting, so it will start
			// checking from 0'th index. For example,
			// for "ababab" and i = 1, the value of R
			// remains 0 and Z[i] becomes 0. For string
			// "aaaaaa" and i = 1, Z[i] and R become 5
			while (R<n && begin[R-L] == begin[R]) R++;
			Z[i] = R-L;
			R--;
		} else {
			// k = i-L so k corresponds to number which
			// matches in [L,R] interval.
			k = i-L;
			// if Z[k] is less than remaining interval
			// then Z[i] will be equal to Z[k].
			// For example, str = "ababab", i = 3, R = 5
			// and L = 2
			if (Z[k] < R-i+1) Z[i] = Z[k];
			// For example str = "aaaaaa" and i = 2, R is 5,
			// L is 0
			else {
				// else start from R and check manually
				L = i;
				while (R<n && begin[R-L] == begin[R]) R++;
				Z[i] = R-L;
				R--;
			}
		}
	}
	return Z;
}

std::vector<int> occurance(std::string &text, std::string &pattern){
	std::string concat = pattern + "$" + text;
	int np = pattern.size();
	std::vector<int> z = getZarray(concat.begin(), concat.end());
	std::vector<int> idx;

	for(int i=0; i<concat.size()-np-1; i++){
		if(z[i+np+1] >= np) idx.push_back(i);
	}
	return idx;
}

int _main(){
	using namespace std;
	string text = "aababaabaacaabaa";
	string pat = "aab";
	vector<int> oc = occurance(text, pat);
	assert((oc==vector<int>{0, 5, 11}));
	return 0;
}

int main(){
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	for(int i=0; i<N; i++) cin >> A[i];
	for(int i=0; i<N; i++) cin >> B[i];

	vector<bool> idx(N, true);
	for(int k=0; k<32; k++){
		string x, y;
		for(int i=0; i<N; i++) x.push_back(B[i]>>k&1);
		for(int i=0; i<N; i++) y.push_back(A[i]>>k&1);
		for(int i=0; i<N-1; i++) y.push_back(A[i]>>k&1);

		vector<int> v = occurance(y, x);
		vector<bool> bit_idx(N);
		debug(k);
		for(int a: v){
			bit_idx[a] = true;
		}

		for(int i=0; i<N; i++) x[i] = 1-(B[i]>>k&1);
		v = occurance(y, x);
		for(int a: v){
			bit_idx[a] = true;
		}
		for(int i=0; i<N; i++) idx[i] = idx[i] & bit_idx[i];
		debugv(idx);
	}

	for(int k=0; k<N; k++){
		if(idx[k]) cout << k << " " << (A[k]^B[0]) << endl;
	}

	return 0;
}


Measured memory_bytes: 9020
#include<bits/stdc++.h>
#define l1 10000000
#define l2 22500000
using namespace std;
typedef long long ll;
const ll ms=1e9+7;
int f[l2+5];
void pre(){
	int l=1,r=10;
	for (int k=1;k<=7;k++){
		for (int i=l;i<r;i++) f[i]=k;
		l=r; r*=10;
	}
	for (int i=l1;i<=l2;i++) f[i]=8;
}
ll ksm(ll x,ll k){
	ll t=1;
	for (;k;k>>=1){
		if (k&1) t=(t*x)%ms;
		x=(x*x)%ms;
	}
	return t;
}
ll calc1(ll n){
	int l=1,r=1,t=0; ll sum=0;
	while (1){
		while (r<=l2&&sum<n) sum+=f[r++];
		if (sum<n) break;
		if (sum==n) (t+=1)%=ms;
		sum-=f[l++];
		if (l==l1) break;
	}
	return t;
}
ll calc2(ll n){
	ll u=n/8;
	ll ans=u; 
	for (int i=1;i<=u;i++){
		if (n%i==0){
			int len=n/i;
			ll s=9*ksm(10,len-1)%ms;
			(s+=ms-i)%=ms;
			ans+=s; if (ans>=ms) ans-=ms;
		}
	}
	return ans;
}
int main(){
	ll n;
	scanf("%lld",&n);
	pre();
	ll ans=calc1(n)+calc2(n);
	if (ans>=ms) ans-=ms;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 88192
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,q,d[maxn];
struct block{
	int s,t,x;
}b[maxn];
bool operator <(block a,block b){return a.x>b.x;}
priority_queue<block> qw;
bool cmp(block a,block b){
	return a.s<b.s;
}
int main()
{
	n=read(),q=read();
	for(int i=1;i<=n;i++){
		b[i].s=read(),b[i].t=read()-1,b[i].x=read();
		b[i].s=b[i].s-b[i].x;b[i].t=b[i].t-b[i].x;
	}
	sort(b+1,b+1+n,cmp);
	for(int i=1;i<=q;i++)d[i]=read();
	int t=1;
	for(int i=1;i<=q;i++){
		while(b[t].s<=d[i]&&t<=n)qw.push(b[t]),t++;
		if(qw.empty()){
			printf("-1\n");
			continue;
		}
		bool flag=0;
		while(!qw.empty()){
			block u=qw.top();
			//printf("%d %d %d %d\n",u.s,u.t,u.x,d[i]);
			if(u.t<d[i]){qw.pop();continue;}
			flag=1;
			printf("%d\n",u.x);
			break;
		}
		if(!flag)printf("-1\n"); 
	}
	return 0;
}


Measured memory_bytes: 7540
#include<stdio.h>
int main(){

	long long int a,b,x,y;
	while(~scanf("%lld%lld",&a,&b)){
	x=a;
	y=b;
	while(a!=b){
		if(a>b){
			a-=b;
		}
		else{
			b-=a;
		}
	}
	printf("%lld %lld\n",a,x/a*y);
}	
return 0;
	}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



//head



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll u = 0;
  if((a > 0 or b < 0) or (c > 0 or d < 0)) u = INT64_MIN;
  cout << max({u, a*c, b*d, a*d, b*c}) << endl;
}

Measured memory_bytes: 3648
object Main {
  def main(args: Array[String]): Unit = {
    var count = 1
    var vec   = Vector[Int]()
    var flg   = false

    vec = scala.io.StdIn.readInt +: vec
    while(!flg) {
      val calc_num = calc(vec(0))

      if(vec.contains(calc_num)) flg = true
      else                       vec = calc_num +: vec

      count += 1
    }

    println(count)
  }

  def calc(num: Int): Int = {
    if(num%2 == 0) return num/2
    else           return 3*num + 1
  }
}

Measured memory_bytes: 27340
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int main(void){
    int n; cin >> n;
    vector<int> a(n);
    double ans = 0;
    rep(i,n) {
        cin >> a[i];
        ans += 1.0/a[i];
    }ans = 1.0/ans;
    printf("%.10f\n",ans);
}



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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,k;
  cin>>n>>k;

  auto ps=read(n);
  auto cs=read(n);

  for(Int &p:ps) p--;

  const Int INF = 1e18;
  if(k<=n*2){
    Int ans=-INF;
    for(Int i=0;i<n;i++){
      Int cur=i;
      Int res=0;
      for(Int j=0;j<k;j++){
        cur=ps[cur];
        res+=cs[cur];
        chmax(ans,res);
      }
    }
    cout<<ans<<newl;
    return 0;
  }

  Int ans=-INF;
  {
    for(Int i=0;i<n;i++){
      Int cur=i;
      Int res=0;
      for(Int j=0;j<(n*2);j++){
        cur=ps[cur];
        res+=cs[cur];
        chmax(ans,res);
      }
    }
  }

  for(Int i=0;i<n;i++){
    Int stp=k;
    Int res=0;
    Int cur=i;

    vector<Int> used(n,-1);
    Int len=0;
    for(Int j=0;;j++){
      // cout<<cur<<endl;
      if(~used[cur]){
        len=j-used[cur];
        break;
      }
      used[cur]=j;
      cur=ps[cur];
      res+=cs[cur];
      chmax(ans,res);
    }
    // cout<<":"<<len<<endl;

    res=0;
    cur=i;

    assert(stp>=used[cur]);
    stp-=used[cur];
    for(Int j=0;j<used[cur];j++){
      cur=ps[cur];
      res+=cs[cur];
      chmax(ans,res);
    }
    Int pre=cur;

    Int sum=0;
    for(Int j=0;j<len;j++){
      cur=ps[cur];
      sum+=cs[cur];
    }
    assert(cur==pre);

    // cout<<stp<<':'<<len<<endl;
    Int mv=(stp/len-1);
    res+=mv*sum;
    stp-=mv*len;

    for(Int i=0;i<stp;i++){
      cur=ps[cur];
      res+=cs[cur];
      chmax(ans,res);
    }
  }
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3776
// B - Card Game for Two
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vi A(N); rpz(i, N) cin>>A[i];
	sort(allr(A));
	int a = 0, b = 0;
	rpz(i, N){
		if(i%2) b += A[i];
		else a += A[i];
	}
	cout<< a-b <<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long int H, W, D, A, Q, L[100001] = {}, R[100001] = {}, num1[90001] = {}, num2[90001] = {}, ans[100001] = {}, cost[90001] = {};

int main() {
	cin >> H >> W >> D;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> A;
			num1[A] = i;
			num2[A] = j;
		}
	}
	for (int i = 1; i <= D; i++) {
		cost[i] = 0;
		for (int j = i + D; j <= H*W; j += D)cost[j] = cost[j - D] + abs(num1[j - D] - num1[j]) + abs(num2[j - D] - num2[j]);
	}
	cin >> Q;
	for (int i = 1; i <= Q; i++) {
		cin >> L[i] >> R[i];
		ans[i] = cost[R[i]] - cost[L[i]];
	}
	for (int i = 1; i <= Q; i++)cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; string s; cin >> n >> s;
	int ans = 0;
	int l = 0, r = n - 1;
	while (l < r) {
		while (l < n and s[l] == 'R') ++l;
		while (r >= 0 and s[r] == 'W') --r;
		if (l < r) swap(s[l], s[r]), ++ans;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3724
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()

ans = 0
m = INF
r = 1

while r < m:
	m = (N-r)/r
	if (N-r)%r == 0 and r < m:
		ans += m
	r += 1

print(int(ans))

Measured memory_bytes: 10364
s = input()
l = len(s)
for i in range(l-1):
  if s[i] == s[i+1]:
    print(i+1,i+2)
    exit()
for i in range(l-2):
  if s[i] == s[i+2]:
    print(i+1,i+3)
    exit()
print(-1,-1)

Measured memory_bytes: 39536
from collections import defaultdict
S = input()
T = input()

s_to_t = defaultdict(set)
t_to_s = defaultdict(set)

for s, t in zip(S, T):
    s_to_t[s].add(t)
    t_to_s[t].add(s)

for v in s_to_t.values():
    if len(v) > 1:
        print("No")
        exit()
for v in t_to_s.values():
    if len(v) > 1:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 4144
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	X := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		A[i] = nextInt(sc)
		X[A[i]-1] = i
	}
	for i := 0; i < N; i++ {
		fmt.Print(X[i]+1, " ")
	}
	fmt.Println()
}


Measured memory_bytes: 5376
N, M, *x = $stdin.read.split(/\s/).map(&:to_i)

x.sort!
distances = []
0.upto(x.size - 2) {|i|
  distances << x[i + 1] - x[i]
}

distances.sort!
distances.pop(N - 1)
puts distances.reduce(0) {|s, d| s + d }


Measured memory_bytes: 22872
#include<stdio.h>
int main(){
  int i,j,n,x;
  char s[101],t[101];
  scanf("%s%s",s,t);
  for(n=0;s[n];n++);
  for(i=0;i<n;i++){x=0;for(j=0;j<n;j++)x+=s[(i+j)%n]==t[j];if(x==n){printf("Yes");return 0;}}
  printf("No");
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int x,y,i,j;
	cin>>x>>y;
	for(i=0;i<=x;i++)
	{
		if(4*i+(x-i)*2==y)
		{
			cout<<"Yes";
			return;
		}
	}
	cout<<"No";
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll mod = 1e9+7;

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

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


void solve(){
  int N;
  cin >> N;
  vector<vector<pi>> edges(N);
  rep(i, N-1){
    int u, v, w;
    cin >> u >> v >> w;
    u--;v--;
    edges[u].emplace_back(make_pair(v, w));
    edges[v].emplace_back(make_pair(u, w));
  }

  vector<int> color(N, -1);
  queue<int> que;
  color[0] = 0;
  que.emplace(0);
  while(!que.empty()){
    int u = que.front(); que.pop();
    for(auto e : edges[u]){
      int v = e.first;
      int w = e.second;
      if(color[v] != -1) continue;
      color[v] = color[u] ^ (w & 1);
      que.emplace(v);
    }
  }

  rep(i, N){
    cout << color[i] << endl;
  }
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 6784
import math
N = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

print(max(math.ceil(N / a),math.ceil(N / b),math.ceil(N / c),math.ceil(N / d),math.ceil(N / e)) + 4)

Measured memory_bytes: 3060
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	string S;
	cin >> S;
	ll N = S.size();
	ll A[N];
	for (ll i = 0; i < N; ++i){
		if (S[i]=='W') A[i] = 1;
		else A[i] = 0;
	}
 
	// 解法
	// REP(i, N) cout << A[i] << endl;
	ll ans = 0;
	ll num_B = 0;
	REP(i,N){
		if (A[i]==0) num_B++;
		else ans += num_B;
	}
	// cout << num_B << endl;
	cout << ans << endl;
	
	
}


Measured memory_bytes: 2180
h,w=map(int,input().split())
d=[list(input())  for i in range(h)]
for i in range(w)[::-1]:
    if not "#" in [d[j][i] for j in range(h)]:
        for j in range(h):del d[j][i]
for i in d:
    if "#" in i:print(*i,sep="")

Measured memory_bytes: 4596
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L[] = new int[N];
		int S = 0;

		for(int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
		}

		Arrays.sort(L);

		for(int i = 0; i < N - 1; i++) {
			S += L[i];
		}

		if(S > L[N - 1])
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n, d;
  cin >> n >> d;

  cout << (n + d * 2) / (d * 2 + 1) << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

# 1 ✕ N
A, B, C, K = list(map(int, input().rstrip().split()))

ans = 0
array = [(A, 1), (B, 0), (C, -1)]

for k, v in array:
    if K > 0:
        n = min(k, K)
        ans += n * v
        K = K - n

print(ans)


Measured memory_bytes: 9192
//WA 7
#include <bits/stdc++.h>
 
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ii pair<int,int>
#define qu queue <int>
#define qmax priority_queue <int>
#define qmin priority_queue <int, vector<int>,greater<int>>

using namespace std;

int solve(int n){
    int ans =0;

    do{
        ans += (n%10);
        n /=10;
    }while(n);

    return ans == 1 ? 10 : ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;

    auto ans = solve(n);

    cout<<ans<<endl;

    return 0;
}

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

int main(){

  int n,m,x,y;

  vector <int> a;

  cin >> n;

  for(int i=0;i<=n;i++){
    a.push_back(i);
    a[i]=i;
  }

  cin >> m;
  for(int i=0;i<m;i++){
    scanf("%d,%d",&x,&y);
    swap(a[x],a[y]);
  }

  for(int i=1;i<=n;i++) cout << a[i] << endl;
}

Measured memory_bytes: 1256
N,M = map(int,input().split())
lis = [None]*M
for i in range(M):
    lis[i] = list(map(int,input().split()))
p = list(map(int,input().split()))
answer = 0

for bit in range(1<<N):
    count =[]
    for i in range(N): #make bit
        mask = 1<<i
        if mask&bit:
            count.append(1)
        else:
            count.append(0)
        #process
    for j in range(M):
        temp = 0
        for k in range(lis[j][0]):
            temp+=count[lis[j][k+1]-1]
        if temp%2 != p[j]:
            break
    else:
        answer+=1
print(answer)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> data(n);
	ff(i, 0, n)cin >> data[i];

	st(data);

	cout << data[data.size() / 2] - data[(data.size() / 2) - 1] << endl;
	return 0;
}

Measured memory_bytes: 640
def main():
    Rec = 0
    Dia = 0
    while True:
        try:
            a,b,c = map(int,input().split(","))
            if a == b:
                Dia += 1
            elif a != b and c > a and c > b:
                Rec += 1
        except EOFError:
            break
    print(Rec)
    print(Dia)

if __name__ == '__main__':
    main()


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

using ll = long long;
ll n;
ll m;
ll dp[305][305][305];
const ll MOD = 1e9+7;

vector<pair<int, int>> v[305];

bool check(int r, int g, int b) 
{
	int k = max({r, b, g});
	for(auto pp: v[k]) 
	{
    	int ct = 0;
    	int l = pp.first;
    	if (r >= l) ct++;
    	if (g >= l) ct++;
    	if (b >= l) ct++;
    
    	if (ct != pp.second) return false;
	}
	return true;
}
 
int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0); 

	cin>>n>>m;
	for (int i=0;i<m;++i)
	{
		int l,r,x;
		cin>>l>>r>>x;
		v[r].push_back({l,x});
	}  
	dp[0][0][0]=1;
	ll ret=0;
	for (int r=0;r<=n;++r)
	{
		for (int g=0;g<=n;++g)
		{
			for (int b=0;b<=n;++b)
			{
				ll c=dp[r][g][b];
				if (!c) continue;
				
				if (!check(r,g,b))
				{
					dp[r][g][b]=0;
					continue;
				}
				
				int k=max({r,g,b}) + 1;
				if (k-1 == n)
				{
					ret+=dp[r][g][b];
					ret%=MOD;
				}
				dp[k][g][b]+=dp[r][g][b] % MOD;
				dp[r][k][b]+=dp[r][g][b] % MOD;
				dp[r][g][k]+=dp[r][g][b] % MOD;
				
			}
		}
	}
	cout<<ret;
 
}

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

int main(){
	int N;
	cin>>N;
	int i,j;
	vector<double>P(N+1);//Probabilities
	vector<vector<double>>DP(N+1,vector<double>(N+1,0));
	for(i=1;i<=N;i++){
		cin>>P[i];
	}
	DP[0][0]=1;
	for(i=1;i<=N;i++){
		DP[i][0]=1;
		for(j=1;j<=N;j++){
			DP[i][j]=(DP[i-1][j-1]*P[i])+(DP[i-1][j]*(1-P[i]));
		}
	}
	cout.precision(10);
	cout<<DP[N][(N+1)/2];
	return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;

int main() {
   int n; cin>>n;
   string s; cin>>s;
   string a,b;
   int ans=0;
   rep(i,2,n-1){
      a=s.substr(0,i);
      b=s.substr(i,n-i);
      char bucket1[26],bucket2[26];
      rep(i,0,26){
         bucket1[i]=0;
         bucket2[i]=0;
      }
      rep(i,0,a.size()){
         bucket1[a[i]-'a']++;
      }
      rep(i,0,b.size()){
         bucket2[b[i]-'a']++;
      }
      int cnt=0;
      rep(i,0,26){
         if(bucket1[i]&&bucket2[i]){
            cnt++;
         }
      }
      ans=max(ans,cnt);
   }
   cout<<ans<<endl;
}


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

ll j = 1000000000000000000;

int main(){
  ll n;
  cin >> n;
  ll now = 1;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  if( count(a.begin(),a.end(),0) > 0 ){
    cout << 0 << endl;
    return 0;
  }
  rep(i,n){  
    if( a.at(i) > j/now ){
      cout << -1 << endl;
      return 0;
    }
    now *= a.at(i);
  }
  cout << now << endl;

  return 0;
}


Measured memory_bytes: 4000
num = int(input())
wr = str(input())

r_num = wr.count("R")
i_counts = [r_num]
rw_count = r_num
wr_count = 0
for i in range(num):
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

ans = min(i_counts)

print(ans)

Measured memory_bytes: 84456
<?php
    $input = trim(fgets(STDIN));
    
    $cnt = 0;
    $max = 0;

    

    foreach(str_split($input) as $a){
        if(strcmp($a,'A')==0 || strcmp($a,'T')==0 || strcmp($a,'C')==0 || strcmp($a,'G')==0){
            $cnt++;
        }else{
            $cnt=0;
        }
        
        if($cnt > $max){
            $max = $cnt;
        }
    }

    echo $max;
?>

Measured memory_bytes: 3700
#include<iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int max=0;
    int min=1000;
    int tmp;
    for (int i=0;i<N;i++){
        cin>>tmp;
        if (tmp>max) max=tmp;
        if (tmp<min) min=tmp;
    }
    cout << max-min << endl;
    return 0;

}


Measured memory_bytes: 256
def caesar(s, n):
    ns = []
    for ch in s:
        # A - Z
        if ('A' <= ch and ch <= 'Z'):
            ns.append(chr((ord(ch) - ord('A') + n) % 26 + ord('A')))
        # a - z
        elif ('a' <= ch and ch <= 'z'):
            ns.append(chr((ord(ch) - ord('a') + n) % 26 + ord('a')))
        # 0 - 9
        elif ('0' <= ch and ch <= '9'):
            ns.append(chr((ord(ch) - ord('0') - n) % 10 + ord('0')))
        # no change for other characters
        else:
            ns.append(ch)
    return "".join(ns)
a = int(input())
b = input()
result = caesar(b, a)
print(result)

Measured memory_bytes: 3188
// abc177_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int D, T, S;
  cin >> D >> T >> S;
  if (D <= T * S) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
  int n[101]={0};
  int a,max=0;
  while(cin >>a) n[a]++;
  for(int i=1; i<101; i++) if(max<n[i]) max = n[i];
  for(int i=1; i<101; i++) if(n[i] == max) cout <<i<<endl;
  return 0;
}

Measured memory_bytes: 1160
N, M = gets.split.map(&:to_i)
s = []
c = []
str = Hash.new
M.times do |i|
  s[i], c[i] = gets.split.map(&:to_i)
  if str[s[i]-1].nil?
    str[s[i]-1] = []
  end
  str[s[i]-1] << c[i]
end

# puts "#{str}"

ans = []
ans = ans.fill('0',0..N-1)
if N>=2
  ans[0] = '1'
end

str.each do |key, val|
  if key==0 and val.first==0 and N>=2
    puts -1
    exit
  else
    val.uniq!
    if val.size >= 2
      puts -1
      exit
    else
      ans[key] = val.first.to_s
    end
  end
end
puts "#{ans.inject(:+)}"

Measured memory_bytes: 1788
#include <iostream>
#include <vector>

using namespace std;

int main() {
    const int INF = 1145141919;
    int n, m;
    cin >> n >> m;

    vector<int> dp(1 << n, INF);
    dp[0] = 0;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        int can = 0;
        for (int j = 0; j < b; j++) {
            int c;
            cin >> c;
            can |= 1 << (c - 1);
        }

        for (int j = 0; j < 1 << n; j++) {
            dp[j | can] = min(dp[j | can], dp[j] + a);
        }
    }

    cout << (dp[(1 << n) - 1] == INF ? -1 : dp[(1 << n) - 1]) << endl;
    return 0;
}

Measured memory_bytes: 256