akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << endl
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  string N;
  cin >> N;
  ll ans = 0;
  rep(i, N.size()) {
    if (N[i] == '1') ans++;
  }
  ANS;
  return 0;
}

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

int main(){
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    while(a>=0&&c>=0){
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout<<"No"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3676
#include <cstdio>
#include <algorithm>

#define MAX_N 100000

int x[MAX_N];
int N,K;

int abs(int x)
{
    return x>0? x : -x;
}

int min(int x, int y)
{
    return x>y ? y : x;
}

int max(int x, int y)
{
    return x<y ? y : x;
}

int main()
{
    scanf(" %d %d", &N, &K);
    for ( int i=0; i<N; i++ ) {
        scanf(" %d", x+i);
    }

    int ret = x[N-1] - x[0] + min(abs(x[N-1]),abs(x[0]));
    for ( int i=0; i<N-K+1; i++ ) {
        int len = min(abs(x[i+K-1]),abs(x[i]));
        if ( x[i+K-1] - x[i] + len < ret ) 
            ret = x[i+K-1] - x[i] + len;
    }

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

}


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

int A[202020], B[202020];
multiset<int> p,m;

int main(){
  int N,Q; cin>>N>>Q;
  ll S=0;
  rep(i,2*N){
    cin>>A[i];
    S+=A[i];
  }

  ll T=0;
  rep(i,2*N){
    cin>>B[i];
    B[i]-=A[i];
    if(i!=0&&i!=2*N-1){
      if(B[i]>0){
        p.insert(B[i]);
        T+=B[i];
      }else{
        m.insert(-B[i]);
      }
    }
  }
  while(Q--){
    ll i,x,y; cin>>i>>x>>y; i--;
    S-=A[i];
    if(i!=0&&i!=2*N-1){
      if(B[i]>0){
        p.erase(p.find(B[i]));
        T-=B[i];
      }else{
        m.erase(m.find(-B[i]));
      }
    }

    A[i]=x;
    S+=A[i];
    B[i]=y-x;
    if(i!=0&&i!=2*N-1){
      if(B[i]>0){
        p.insert(B[i]);
        T+=B[i];
      }else{
        m.insert(-B[i]);
      }
    }

    ll ans;
    if(p.size()%2==0) ans=S+T;
    else ans=S+T-min(*p.begin(),*m.begin());
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 13696
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  string s;cin>>s;
	if(s=="ABC"){
    cout<<"ARC"<<endl;
  }
  else{
    cout<<"ABC"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1000000007;

int h, w;
string s[2000];
int a[2000][2000];
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }
  
  for (int i = 0; i < h; ++i) {
    int st = 0;
    while (st < w) {
      int l = st;
      int r = l;
      while (r < w && s[i][r] == '.') ++r;
      for (int j = l; j < r; ++j) {
        a[i][j] += r - l;
      }
      st = r + 1;
    }
  }
  
  for (int j = 0; j < w; ++j) {
    int st = 0;
    while (st < h) {
      int l = st;
      int r = l;
      while (r < h && s[r][j] == '.') ++r;
      for (int i = l; i < r; ++i) {
        a[i][j] += r - l;
      }
      st = r + 1;
    }
  }
  
  int mx = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      mx = max(mx, a[i][j] - 1);
    }
  }
  cout << mx << endl;
}

Measured memory_bytes: 19968
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int ans = 0;
		HashMap<String, Integer> goods = new HashMap<String, Integer>();

		for (int i = 0; i < N; i++) {
			String S = scan.next();
			if(goods.containsKey(S)) {
				continue;
			}else {
				ans++;
				goods.put(S, 1);
			}
		}

		System.out.println(ans);
		scan.close();
	}
}


Measured memory_bytes: 76948
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <random>

using ll = long long int;
using P = std::pair<ll, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int l[30];
ll c[30],s[400][30],ans[150000];
std::vector<int> v[150000];

int main(void){
	int d,i,j,n=26,k,m=125125;
	ll ansm = -INFLL;
	for(k=0; k<m; ++k){
		for(j=0; j<n; ++j){
			v[k].push_back(j);
		}
		std::random_device seed_gen;
		std::mt19937 engine(seed_gen());
		std::shuffle(v[k].begin(), v[k].end(), engine);
	}
	std::cin >> d;
	for(i=0; i<26; ++i){
		std::cin >> c[i];
	}
	for(i=0; i<d; ++i){
		for(j=0; j<n; ++j){
			std::cin >> s[i][j];
		}
	}
	for(k=0; k<m; ++k){
		for(j=0; j<n; ++j){
			l[j] = -1;
		}
		for(i=0; i<d; ++i){
			ans[k] += s[i][v[k][i%26]];
			l[v[k][i%26]] = i;
			for(j=0; j<n; ++j){
				ans[k] -= c[j]*(i-l[j]);
			}
		}
		ansm = std::max(ansm,ans[k]);
		// std::cout << ans[k] << std::endl;
	}
	for(k=0; k<m; ++k){
		if(ans[k] == ansm){
			for(i=0; i<d; ++i){
				std::cout << v[k][i%26]+1 << std::endl;
			}
			break;
		}
	}
	return 0;
}


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

const int N = 3e5 + 10;
const int mod = 998244353;

int c[N];

int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if (b != 0){
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else{
		x = 1;
		y = 0;
	}
	return d;
}

int mod_inverse(int a){
	int x, y, m;
	m = mod;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

int main(){
	int n, a, b, res, ans;
	long long k;
	scanf("%d %d %d %lld",&n,&a,&b,&k);
	c[0] = 1;
	for (int i = 1; i <= n; i++)
		c[i] = 1LL * c[i - 1] * (n - i + 1) % mod * mod_inverse(i) % mod;
	ans = 0;
	for (int i = 0; i <= min(k / a, 1LL * n); i++){
		res = (k - 1LL * a * i) / b;
		if ((k - 1LL * a * i) % b || res > n) continue;
		ans += 1LL * c[i] * c[res] % mod;
		ans %= mod;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 1408
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        ret = dict()
        for i in range(self.n):
            r = self.find(i)
            if r in ret:
                ret[r].append(i)
            else:
                ret[r] = [i]
        return ret

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = in_nn()
    p = in_nl()

    uni = UnionFind(N)
    for i in range(M):
        x, y = in_nn()
        x, y = x - 1, y - 1
        uni.union(x, y)

    ans = 0
    for root, group in uni.all_group_members().items():
        s = set(group)
        for g in group:
            if p[g] - 1 in s:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second

typedef pair<lint, lint> P;
const lint MOD = 1e9+7;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

vector<P> va;
bool seen[MAX];
void dfs(int s){
    seen[s] = true;
    if(!seen[va[s].se]) dfs(va[s].se);
}

int main(){
    int n; cin >> n;
    vector<int> veca, vecb; vector<P> vp;
    rep(i, n){
        int a; cin >> a; veca.push_back(a);
    }
    rep(i, n){
        int b; cin >> b; vecb.push_back(b);
    }
    rep(i, n){
        vp.push_back(make_pair(veca[i], vecb[i]));
    }

    sort(all(vp), [](P const& l, P const& r)->bool{ return l.se < r.se; });

    rep(i, n) va.push_back(make_pair(vp[i].fi, i));
    sort(all(va));

    rep(i, n){
        if(va[i].fi > vp[i].se){
            cout << "No" << endl;
            return 0;
        }
    }

    int cycle = 0;
    rep(i, n){
        if(!seen[i]){
            cycle++;
            dfs(i);
        }
    }
    if(cycle >= 2){
        cout << "Yes" << endl;
        return 0;
    }

    rep(i, n - 1){
        if(va[i+1].fi <= vp[i].se){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 5616
n = gets.to_i
nums = gets.split.map(&:to_i)
sum = 0
1.upto(n - 2) do |i|
  array = nums[i - 1..i + 1]
  if array.max != nums[i] && array.min != nums[i]
    sum += 1
  end
end
puts sum


Measured memory_bytes: 1788
H, W = map(int, input().split())
stage = []
scores = []
for _ in range(H):
    stage.append(list(input()))
    scores.append([float('inf')] * W)
if stage[0][0] == '#':
    scores[0][0] = 1
else:
    scores[0][0] = 0
move = [[0, 1], [1, 0]]
for y in range(H):
    for x in range(W):
        for dx, dy in move:
            nx, ny = x + dx, y + dy
            if H <= ny or W <= nx:
                continue
            if stage[ny][nx] == '#' and stage[y][x] == '.':
                scores[ny][nx] = min(scores[ny][nx], scores[y][x] + 1)
            else:
                scores[ny][nx] = min(scores[ny][nx], scores[y][x])
# print(*scores, sep='\n')
print(scores[-1][-1])

Measured memory_bytes: 9252
//Name: Pankaj Mandrawal (pankaj_m05)
//Problem: OCD
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define INF LLONG_MAX
#define NINF LLONG_MIN
#define mod 10000000009
#define sz(c) int((c).size())
#define sortall(x) sort(all(x))         
#define PI 3.1415926535897932384626     
#define all(c) (c).begin(), (c).end()
#define clr(x) memset(x, 0, sizeof(x))  
#define MAX32 numeric_limits< int >::max() 
#define MIN32 numeric_limits< int >::min()
#define rall(c) (c).rbegin(), (c).rend()
#define deb(x) cerr << #x << " = " << x << endl
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define for1(i, n) for(int i = 1; i <= (int) n; ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = (int)(l); i < (int)(r); ++i)
#define tr(c, it) for(typeof(c).begin() it = c.begin(); it != c.end(); it++)
#define deb2(x, y) cerr << #x << " = " << x << "," << #y << " = " << y << endl

using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vill;
typedef pair < int, int > pi;
typedef unsigned long long int ull;

ll mypow(ll x, ll y) { 
    if (y == 0) 
        return 1; 
    ll p = mypow(x, y / 2) % mod; 
    p = (p * p) % mod; 
    if (!(y & 1)) 
        return p;
    return (p * x) % mod; 
} 

void plssolve() {
	string a, b; cin >> a >> b;
	int x, y; cin >> x >> y;
	string t; cin >> t;
	if(t == a)
		--x;
	else
		--y;
	cout << x << ' ' << y << '\n';	
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    cout << fixed;
    int t = 1;
    //cin >> t;
    while(t--) {
        plssolve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<int>())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> t(5);
    for (int i = 0; i < 5; i++) {
        cin >> t[i];
    }
    SORT(t);
    int min_id = 0;
    Rep(i, 1, 5){
        if(t[i] != t[0]){
            min_id = i-1;
            break;
        }
    }

    if(n <= t[0]) pr(5);
    else pr((n / t[0]) + (n % t[0] ? 1 : 0) + 4);
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    ll a,b;
    cin>>a>>b;
    if(a==1 || b==1){
        cout<<"1"<<endl; return 0;
    }
    if(a%2==0 || b%2==0){
        cout<<a*b/2<<endl; return 0;
    }
    cout<<a*b/2+1<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length(); i += 2) {
			sb.append(s.charAt(i));
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 24904
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

class show {
public:
	show(long _s,long _t,long _c) {
		s = _s;
		t = _t;
		c = _c;
	}
	long s,t,c;
	bool operator<(show& o) {
		if(o.c != c)
			return c < o.c;
		return s < o.s;
	}
};

vector<show> shows;

int main() {
	long n,c;
	cin >> n >> c;
	for(int i = 0;i < n;i++) {
		int ss,tt,cc;
		cin >> ss >> tt >> cc;
		shows.push_back(show(ss,tt,cc));
	}
	sort(shows.begin(),shows.end());
	for(int i = 0;i < n-1;i++) {
		if(shows[i].c == shows[i+1].c && shows[i].t == shows[i+1].s) {
			shows[i+1].s = shows[i].s;
			shows[i].c = -1;
		}
	}
	vector<pair<long,int>> events;
	for(int i = 0;i < n;i++) {
		if(shows[i].c == -1) continue;
		events.push_back(make_pair(shows[i].s-1,1));
		events.push_back(make_pair(shows[i].t,-1));
	}
	sort(events.begin(),events.end());
	int cur = 0,res = 0;
	for(unsigned int i = 0;i < events.size();i++) {
		cur += events[i].second;
		if(i+1 < events.size() && events[i+1].first == events[i].first) continue;
		res = max(res,cur);
	}
	cout << res << endl;
}


Measured memory_bytes: 10736
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void){
  int N;
  vector<string> W;

  cin >> N;
  W.resize(N);
  for(auto& w : W){
    cin >> w;
  }

  char lastCharacter;
  bool isFirst=true;
  bool isFailed = false;

  for (int i = 0; i < N; i++){
    if(isFirst==true){
      isFirst = false;
      lastCharacter = W[i][W[i].size() - 1];
    }
    else{
      if(W[i][0]!=lastCharacter){
        isFailed = true;
      }

      lastCharacter = W[i][W[i].size() - 1];
      for (int j = 0; j < i;j++){
        if(W[i]==W[j]){
          isFailed = true;
        }
      }
    }

    if(isFailed==true){
      cout << "No" << endl;
      return 0 ;
    }
  }

  cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<set>
using namespace std;
set<int> appear[35];
int main()
{
    int n;
    scanf("%d",&n);
    string ss;
    cin>>ss;
    ss="_"+ss;
    for(int i=1;i<(int)ss.length();i++)
        appear[ss[i]-'a'].insert(i);
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int type;
        scanf("%d",&type);
        if(type==1)
        {
            int pos;
            char now;
            scanf("%d%c%c",&pos,&now,&now);
            appear[ss[pos]-'a'].erase(pos);
            appear[now-'a'].insert(pos);
            ss[pos]=now;
        }
        else if(type==2)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            int ans=0;
            for(int i=0;i<26;i++)
            {
                set<int>::iterator find=appear[i].lower_bound(l);
                if(find!=appear[i].end()&&(*find)<=r)
                    ans++;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


Measured memory_bytes: 24216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n, q; cin >> n >> q;
    string s; cin >> s;
    int sn = s.size();
    vector<int> a(sn, 0), sum(sn, 0);
    for(int i=0; i+1<sn; ++i){
        if(s[i]=='A' && s[i+1]=='C'){a[i]++;}
    }
  	//for(int i=0; i<sn; ++i){cout << a[i] << ",";} cout << endl;
    for(int i=0; i+1<sn; ++i){
        sum[i+1] = sum[i] + a[i];
    }
    for(int i=0; i<q; ++i){
        int l, r; cin >> l >> r; l--; r--;
        cout << sum[r] - sum[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 4256
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v){ t = v; }

template<typename T,typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    
    multiset<int> que;
    que.insert(a[0]);
    FOR(i, 1, n)
    {
        auto itr = que.lower_bound(a[i]);
        if(itr == que.begin())
        {
            que.insert(a[i]);
        }
        else
        {
            itr--;
            que.erase(itr);
            que.insert(a[i]);
        }
    }
    cout << que.size() << endl;
}

Measured memory_bytes: 5376
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	n, _ := strconv.Atoi(scanLine(scanner))

	totalMoney := 0.0
	for i := 0; i < n; i++ {
		inputs := strings.Split(scanLine(scanner), " ")
		x, _ := strconv.ParseFloat(inputs[0], 64)

		if inputs[1] == "JPY" {
			totalMoney += x
		} else {
			totalMoney += x * 380000.0
		}
	}
	
	fmt.Println(totalMoney)
}

func scanLine(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
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;};



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

  int a, b, c, n;
  while(true) {
  cin >> a >> b >> c >> n;
  if(!a && !b && !c) break;
  int x[n], y[n], z[n], r[n];
  rep(i, n) {
    cin >> x[i] >> y[i] >> z[i] >> r[i];
    x[i]--; y[i]--; z[i]--;
  }

  int res[a + b + c];
  fill(res, res + a + b + c, 2);

  rep(i, n) {
    int X = x[i], Y = y[i], Z = z[i], R = r[i];
    if(R) {
      res[X] = 1;
      res[Y] = 1;
      res[Z] = 1;
    }
  }

  rep(i, n) {
    int X = x[i], Y = y[i], Z = z[i], R = r[i];
    if(!R) {
      int t = 0;
      if(res[X] == 1) t++;
      if(res[Y] == 1) t++;
      if(res[Z] == 1) t++;
      if(t == 2) {
        if(res[X] != 1) res[X] = 0;
        if(res[Y] != 1) res[Y] = 0;
        if(res[Z] != 1) res[Z] = 0;
      }
    }
  }
  rep(i, a + b + c) cout << res[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};

template< typename T >
T kruskal(Edges< T > &edges, int V) {
  sort(begin(edges), end(edges), [](const edge< T > &a, const edge< T > &b) {
    return (a.cost < b.cost);
  });
  UnionFind tree(V);
  T ret = 0;
  for(auto &e : edges) {
    if(tree.unite(e.src, e.to)) ret += e.cost;
  }
  return (ret);
}







int main(){

  ll n;
  cin >> n;
  ll x,y;
  vector<tuple<ll, ll, int> > xcor;
  vector<tuple<ll, ll, int> > ycor;
  rep(i,n){
    cin >> x >> y;
    xcor.pb(make_tuple(x,y,i));
    ycor.pb(make_tuple(y,x,i));
  }
  sort(xcor.begin(),xcor.end());
  sort(ycor.begin(),ycor.end());
  Edges<ll> edges;
  rep(i,n-1){
    edges.emplace_back(get<2>(xcor[i]),get<2>(xcor[i+1]), get<0>(xcor[i+1])-get<0>(xcor[i]));
    edges.emplace_back(get<2>(ycor[i]),get<2>(ycor[i+1]), get<0>(ycor[i+1])-get<0>(ycor[i]));
  }
  cout << kruskal(edges, n);
  return 0;

}


Measured memory_bytes: 13604
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC095.A
{
    class Program
    {
        static void Main ()
        {
            var sc = new Scanner ();
            var s = sc.Next ();
            int toppingFee = s.Where (val => val == 'o').Count ();
            Console.WriteLine (700 + toppingFee * 100);
        }

    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner ()
        {
            s = new string[0];
            i = 0;
        }

        public string Next ()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine ();
            while (st == "") st = Console.ReadLine ();
            s = st.Split (cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next ();
            i = 0;
            return s[i++];
        }

        public int NextInt ()
        {
            return int.Parse (Next ());
        }
        public int[] ArrayInt (int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt () + add;
            }
            return Array;
        }

        public long NextLong ()
        {
            return long.Parse (Next ());
        }

        public long[] ArrayLong (int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong () + add;
            }
            return Array;
        }

        public double NextDouble ()
        {
            return double.Parse (Next ());
        }

        public double[] ArrayDouble (int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble () + add;
            }
            return Array;
        }

        public decimal NextDecimal ()
        {
            return decimal.Parse (Next ());
        }

        public decimal[] ArrayDecimal (int N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDecimal ();
            }
            return Array;
        }
    }

}

Measured memory_bytes: 11348
// AtCoder Beginner Contest 128 - Problem E: Roadwork (https://atcoder.jp/contests/abc128/tasks/abc128_e) 
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<int, int>;

struct Block {
    ll S, T, X;

    bool operator<(const Block& b) const
    {
        if (X != b.X)
            return X < b.X;

        if (S != b.S)
            return S < b.S;

        return T < b.T;
    }
};

vector<ll> solve(int Q, const vector<ll>& ds, vector<Block>& bs)
{
    sort(bs.begin(), bs.end());
    set<ii> xs;

    for (int i = 0; i < Q; ++i)
        xs.insert(ii(-ds[i], i));

    vector<ll> ans(Q, -1);

    for (auto b : bs)
    {
#ifdef DEBUG
    cout << "-- Block on x = " << b.X << " from " << b.S << " to " << b.T << endl;
    cout << "   shift: " << b.X - b.S << " to " << b.X - b.T + 1<< endl;
#endif
        auto R = b.X - b.S + 1, L = b.X - b.T + 1;

        auto it = xs.lower_bound(ii(L, -1));
        auto jt = xs.lower_bound(ii(R, -1));

#ifdef DEBUG
    cout << "   L = " << L << ", R = " << R << endl;
    cout << "   it = (" << it->first << ", " << it->second << ")" << endl;
    cout << "   jt = (" << jt->first << ", " << jt->second << ")" << endl;
#endif

        for (auto i = it; i != jt; ++i)
        {
#ifdef DEBUG
    cout << "   p = " << i->first << " blocked at " << b.X << endl;
#endif
            ans[i->second] = b.X;
        }

        xs.erase(it, jt);
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, Q;
    cin >> N >> Q;

    vector<Block> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i].S >> xs[i].T >> xs[i].X;

    vector<ll> ds(Q);

    for (int i = 0; i < Q; ++i)
        cin >> ds[i];

    auto ans = solve(Q, ds, xs);

    for (auto x : ans)
        cout << x << '\n';

    return 0;
}


Measured memory_bytes: 20252
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, M, X, Y) = Slice4<long>();
            var xi = Slist();
            var yi = Slist();
            xi.Add(X);
            yi.Add(Y);
            if (xi.Max() < yi.Min())
                WriteLine("No War");
            else
                WriteLine("War");
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 28424
def insertionSort(A,n,g):
  cnt=0
  for i in range(g,n):
    v=A[i]
    j=i-g
    while j>=0 and v<A[j]:
      A[j+g]=A[j]
      j-=g
      cnt+=1
    A[j+g]=v
  return cnt
n=int(input())
A=[int(input()) for _ in range(n)]
cnt_ans=0
G=[]
i=1
while i<=n:
  G.append(i)
  i=i*3+1
G=G[::-1]
m=len(G)
for g in G:
  cnt=insertionSort(A,n,g)
  cnt_ans+=cnt
print(m)
print(*G)
print(cnt_ans)
for i in range(n):
  print(A[i])


Measured memory_bytes: 45520
n=int(input())
S=[[s for s in input().split()] for i in range(n)]
X=[float(s[0]) for s in S]
count =0
for i in range(n):
    if S[i][1]=="JPY":
        count+=float(S[i][0])
    else:
        count+=float(S[i][0])*380000.0
print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define MAX 200009
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in2.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tp, T)
	{
		//cout << "Case #" << tp << ": ";
		int k; cin >> k;
		string s; cin >> s;
		if(s.length() <= k){
			cout << s;
		}
		else cout << s.substr(0, k) + "...";
		cout << '\n';
	}
	return 0;
}


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

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==5 && B==5 && C==7)
    cout<<"YES"<<endl;
  else if(A==5 && B==7 && C==5)
    cout<<"YES"<<endl;
  else if(A==7 && B==5 && C==5)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline().rstrip())

N = I()
A = [0]
for i in range(1,13):
    A.append(A[-1]+26**i)

ANS = []
for i in range(1,12):
    if N > A[i]:
        continue
    else:
        a = N-A[i-1]-1
        for j in range(i):
            ANS.append(a % 26)
            a = (a - a%26)//26
        break

ANS.reverse()

for i in range(len(ANS)):
    ANS[i] = chr(ANS[i]+97)

print(''.join(ANS))

Measured memory_bytes: 61920
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
#define int long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const int maxn=3005,mod=1e9+7,niyuan=5e8+4;
int n,q,dp[maxn][maxn],a[maxn],ans;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		putchar('-');
		putchar('1');
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}
signed main()
{
	n=read(),q=read();
	int tmp=1;
	for(int i=1;i<=q;++i)
		tmp=tmp*2%mod;
	for(int i=1;i<=n;++i)
		a[i]=read();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			dp[i][j]=tmp*(a[i]>a[j]);
//	for(int i=1;i<=n;++i,cout<<endl)
//		for(int j=1;j<=n;++j)
//			cout<<dp[i][j]<<' ';
	while(q--)
	{
		int x=read(),y=read();
		if(x>y)
			swap(x,y);
		int xi[maxn],yi[maxn],ix[maxn],iy[maxn];
		for(int i=1;i<=n;++i)
			xi[i]=dp[x][i],yi[i]=dp[y][i],ix[i]=dp[i][x],iy[i]=dp[i][y];
		for(int i=1;i<=n;++i)
			if(i!=x&&i!=y)
			{
				dp[i][x]=ix[i]*niyuan%mod+iy[i]*niyuan%mod;
				dp[i][y]=ix[i]*niyuan%mod+iy[i]*niyuan%mod;
				dp[x][i]=xi[i]*niyuan%mod+yi[i]*niyuan%mod;
				dp[y][i]=xi[i]*niyuan%mod+yi[i]*niyuan%mod;
			}
		dp[y][x]=dp[x][y]=xi[y]*niyuan%mod+yi[x]*niyuan%mod;
//		for(int i=1;i<=n;++i,cout<<endl)
//			for(int j=1;j<=n;++j)
//				cout<<dp[i][j]<<' ';
	}
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			ans=(ans+dp[i][j])%mod;
	write(ans);
    return 0;
}


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

namespace AtCoder20170211 {
	class Program {
		static void Main(string[] args) {
			var cards = Console.ReadLine().Split(' ');

			var alice = Convert.ToInt32(cards[0]);
			var bob = Convert.ToInt32(cards[1]);

			if(alice > bob) {
				if(bob == 1) {
					Console.WriteLine("Bob");
				}
				else {
					Console.WriteLine("Alice");
				}
			}
			else if(alice < bob) {
				if (alice == 1) {
					Console.WriteLine("Alice");
				}
				else {
					Console.WriteLine("Bob");
				}
			}
			else {
				Console.WriteLine("Draw");
			}
		}
		
	}
}


Measured memory_bytes: 11220
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    D = int(input().strip())
    # C[i]: コンテストiの低下量にかかる係数
    C = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    # S[d, i]: d日目にコンテストiを開催したときの増加量
    S = np.empty((D, 26), dtype=np.int32)
    for i in range(D):
        s = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
        S[i, :] = s[:]
    # T[d]: d日目に開催されるコンテストの種類
    T = np.array([int(input().strip()) for i in range(D)], dtype=np.int32)
    T -= 1
    # M: 変更クエリの数
    M = int(input().strip())
    # DQ[i]: d[i] 日目のコンテストを q[i] に変更する
    DQ = np.empty((M, 2), dtype=np.int32)
    for i in range(M):
        dq = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
        DQ[i, :] = dq[:]
    DQ -= 1
    return D, C, S, T, M, DQ


@njit
def satisfaction(d, C, S, T, last):
    """満足度の変化を求める
    """
    v = 0
    # 増加分: S[d, i]
    p = T[d]
    v += S[d, p]
    last[p] = d
    # 低下分: sum(C[i] * (d-last[d, i]))
    for i in range(26):
        v -= C[i] * (d - last[i])
    return v


@njit
def change_schedule(D, C, S, T, d, q, cumsat):
    """d日目のコンテストをqに変更する
    """
    p = T[d]
    dp1, dq1 = -1, -1
    dp3, dq3 = D, D
    for i in range(0, d):
        if T[i] == p: 
            dp1 = i
        if T[i] == q:
            dq1 = i
    for i in range(D-1, d, -1):
        if T[i] == p:
            dp3 = i
        if T[i] == q:
            dq3 = i
    cumsat = cumsat - S[d, p] + S[d, q] - C[p] * (dp3-d) * (d-dp1) + C[q] * (dq3-d) * (d-dq1)
    return cumsat

@njit
def solve(D, C, S, T, M, DQ):
    # 最後にコンテストiを開催した日、未開催ならlast[i] = 0
    last = -np.ones(26, dtype=np.int32)
    # cumsat: d日目の満足度
    cumsat = 0
    # sat: d日目の満足度の増加量
    for d in range(D):
        sat = satisfaction(d, C, S, T, last)
        cumsat += sat
    for i in range(M):
        d, q = DQ[i]
        cumsat = change_schedule(D, C, S, T, d, q, cumsat)
        T[d] = q
        print(cumsat)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 115624
#include<cstdio>
using namespace std;
int main()
{
	long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	if (a+b>=c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
}

Measured memory_bytes: 128
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread!ulong();
    ulong X = A.reduce!"a^b"();
    auto ans = new ulong[](N);
    foreach (i; 0 .. N)
    {
        ans[i] = X ^ A[i];
    }
    ans.arywrite();
}


Measured memory_bytes: 15912
import sys
sys.setrecursionlimit(10000000)

N, M, X = map(int, input().split())

ans = 10000000000000

hon = []


def dfs(cost, now, nextt):
    global N, M, X, ans, hon
    okcnt = 0
    for i in range(M):
        if now[i] >= X:
            okcnt += 1

    if okcnt == M:
        ans = min(cost, ans)

    if nextt >= N:
        return

    temp = now.copy()
    temp2 = now.copy()
    for j in range(M):
        temp[j] += hon[nextt][j + 1]

    dfs(cost + hon[nextt][0], temp, nextt + 1)
    dfs(cost, temp2, nextt + 1)


for i in range(N):
    c = list(map(int, input().split()))

    hon.append(c)

li = [0] * M

dfs(0, li, 0)

if ans == 10000000000000:
    print(-1)
else:
    print(ans)

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

using namespace std;
using ll = long long int;
using vec = vector<int>;

#define rep(n) for(int i = 0; i < (n); ++i)
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)

const int INF = 2147483647;
const ll  MOD = 1000000007;

// abc147c HonestOrUnkind2
// 正直者・嘘つきをそれぞれ完全に決めつけて，証言と整合しているかを確認する

// 何人いるか
int n;

// pair<int, bool> 証言
// i人がj回発言するので2次元配列
vector<vector<pair<int, bool>>> v;

// 整数bitに対応する「決め打ち」が正しいか判定する
bool judge(const int& n , const int& bit) {
    // i人目の証言を確認していく
    for(int i = 0; i < n; ++i) {
        // i自体が嘘つきなら破綻するので無視
        if(!(bit & (1 << i))) continue;

        for(auto xy : v[i]) {
            // 嘘つきと証言しているが，i人目が正直者なら破綻
            if(xy.second == 0 && (bit & (1 << xy.first))) return false;

            if(xy.second == 1 && !(bit & (1 << xy.first))) return false;
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    v.resize(n);

    for(int i = 0; i < n; ++i) {
        int a; cin >> a;
        v[i].resize(a);
        for(int j = 0; j < a; ++j) {
            cin >> v[i][j].first >> v[i][j].second;
            // インデックスと人とを対応させる
            --v[i][j].first;
        }
    }

    int ans = 0;
    // 全組み合わせを決め打ちで検証していく
    for(int bit = 0; bit < (1 << n); ++bit) {
        if(judge(n, bit)) {
            int count = 0;
            for(int i = 0; i < n; ++i) {
                if(bit & (1 << i)) ++count;
            }
            ans = max(ans, count);
        }
    }

    cout << ans;
}

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

int main() {
    vector<vector<int>> A(3, vector<int>(3));
    vector<vector<int>> check(3, vector<int>(3, -1));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int b;
        cin >> b;
        for (int j = 0; j < 3; j++) {
            if (b < 0) break;
            for (int k = 0; k < 3; k++) {
                if (A[j][k] == b) {
                    check[j][k] = 0;
                    b = -1;
                    break;
                }
            }
        }
    }
    bool answer = false;
    for (int i = 0; i < 3; i++) {
        if ((check[i][0] + check[i][1] + check[i][2] == 0) or (check[0][i] + check[1][i] + check[2][i] == 0)) {
            answer = true;
            break;
        }
    }
    if (not answer) {
        int count = 0;
        for (int i = 0; i < 3; i++) {
            if (check[i][i] == 0) count++;
        }
        if (count == 3) answer = true;
    }
    if (not answer) {
        if (check[0][2] + check[1][1] + check[2][0] == 0) answer = true;
    }
    if (answer) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

const int M = 1e18+7;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n , c;
    cin >> n >> c;
    vector<vector<int>> dp(n+1 , vector<int>(c+1 , 0)); int v[n+1] , w[n+1];
    for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= c; j++) {
            if(j-w[i] >= 0) dp[i][j] = max(dp[i][j] , v[i] + dp[i-1][j-w[i]]);
            dp[i][j] = max(dp[i][j] , dp[i-1][j]);
        }
    }
    cout << dp[n][c] << "\n";

    return 0;
}

Measured memory_bytes: 80256
import sys
input = sys.stdin.readline

n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*3 for _ in range(n)]
for i in range(3):
    dp[0][i] = abc[0][i]
for i in range(1, n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i][j] = max(dp[i][j], dp[i-1][k]+abc[i][j])
print(max(dp[-1]))

Measured memory_bytes: 71344
import sys
from fractions import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    N, M, *A = map(int, read().split())
    A = list({a // 2 for a in A})

    power = 1
    while all(a % 2 == 0 for a in A):
        A = [a // 2 for a in A]
        power *= 2

    if any(a % 2 == 0 for a in A):
        print(0)
        return

    l = 1
    for a in A:
        l = lcm(l, a)
        if l > M:
            print(0)
            return

    l *= power
    ans = (M + l) // (2 * l)
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 16108
S = input()
x, y = map(int, input().split())

a = [0, 1]

fs = S.split("T")
f_num = [len(f) for f in fs]

dir_lst = [[], []]

for i in range(len(f_num)):
    dir_lst[i%2].append(f_num[i])
    

x_lst = dir_lst[0].copy()
y_lst = dir_lst[1].copy()

nowx = x_lst.pop(0)
x_lst.sort()
while x_lst != []:
    if nowx > x:
        nowx -= x_lst.pop()
    else:
        nowx += x_lst.pop()

y_lst.sort()
nowy = 0
while y_lst != []:
    if nowy > y:
        nowy -= y_lst.pop()
    else:
        nowy += y_lst.pop()

if nowx == x and nowy == y:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3316