akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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 U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

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

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

  int64 n, d, x;
  cin >> n >> d >> x;
  int64 dp[11] = {};
  dp[0] = x;
  vector<vector<int64>> p(d, vector<int64>(n));
  REP(i, d) {
    REP(j, n) {
      cin >> p[i][j];
    }
  }
  array<int64, 112345> dp2;
  REP(i, d-1) {
    FOR(j, i+1, d) {
      REP(k, 112345) {
        dp2[k] = -INF_LL;
      }
      dp2[dp[i]] = 0;
      REP(k, n) {
        for (int64 l = 112344; l >= 0; l--) {
          if (l - p[i][k] >= 0) {
            chmax(dp2[l-p[i][k]], dp2[l] + p[j][k]);
          }
        }
      }
      REP(k, 112345) {
        chmax(dp[j], dp2[k] + k);
      }
    }
  }
  cout << dp[d-1] << endl;
}



Measured memory_bytes: 4036
def main():
    N, Q = map(int, input().split())
    S = input()
    s_list = [str(c) for c in S]
    q_list = [list(map(int, input().split())) for i in range(Q)]

    ac_list = list()
    # get AC start point
    for i, n in enumerate(s_list):
        if n == "A" and i != (len(s_list) - 1):
            if s_list[i + 1] == "C":
                ac_list.append(i + 1)

    # set list
    temp = list()
    pre = 0
    counter = 0
    for s in ac_list:
        for i in range(pre, s):
            temp.append(counter)
        pre = s
        counter += 1

    for i in range(pre, N):
        temp.append(counter)

    # answer Q
    for qs in q_list:
        print(temp[qs[1] - 1] - temp[qs[0] - 1])


if __name__ == '__main__':
    main()


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

int best[67108864];

int main(){
	string s;
	cin >> s;
	int n = (int)s.length();
	for(int i = 0; i<(1<<26); i++){
		best[i] = n+3;
	}
	best[0] = 0;
	int cur = 0;
	int ans = 0;
	for(int i = 0; i<n; i++){
		cur ^= (1<<((int)(s[i]-'a')));
		ans = best[cur]+1;
		for(int j = 0; j<26; j++){
			best[cur] = min(best[cur],best[cur^(1<<j)]+1);
			ans = min(ans,best[cur^(1<<j)]+1);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 262660
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int c[3][3];
    int n = 3;
    rep(i, 0, n){
        rep(j, 0, n){
            cin >> c[i][j];
        }
    }
    bool f = true;
    rep(j, 0, n - 1){
        int tmp = c[0][j + 1] - c[0][j];        
        rep(i, 1, n){
            if(tmp != c[i][j + 1] - c[i][j]) f = false;
        }
    }
    rep(j, 0, n - 1){
        int tmp = c[j + 1][0] - c[j][0];        
        rep(i, 1, n){
            if(tmp != c[j + 1][i] - c[j][i]) f = false;
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int h1, m1, h2, m2, k;
  scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
  
  long start = h1*60 + m1;
  long end = h2*60 + m2;
  printf("%ld\n", end-start-k);
  return 0;
}


Measured memory_bytes: 1732
#include <iostream>

using namespace std;

const int limit = 50;
int N, M;
int a[limit], b[limit];
bool graph[limit][limit];
bool visited[limit];
void dfs(int v) {
	visited[v] = true;
	for (int v2 = 0; v2 < N; ++v2) {
		if (!graph[v][v2]) continue;
		if (visited[v2]) continue;
		dfs(v2);
	}
}
int main(void) {
	cin >> N >> M;
	for (int m = 0; m < M; ++m) {
		cin >> a[m] >> b[m];
		--a[m];
		--b[m];
		graph[a[m]][b[m]] = graph[b[m]][a[m]] = true;
	}
	int ans = 0;
	for (int m = 0; m < M; ++m) {
		graph[a[m]][b[m]] = graph[b[m]][a[m]] = false;
		for (int i = 0; i < N; ++i) {
			visited[i] = false;
		}
		dfs(0);
		for (int i = 0; i < N; ++i) {
			if (!visited[i]) {
				++ans;
				break;
			}
		}
		graph[a[m]][b[m]] = graph[b[m]][a[m]] = true;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let c: Vec<char> = s.trim().chars().collect();

    let mut r = 1;
    for i in 1..c.len() {
        if c[i] != c[i-1] {r += 1};
    }
    
    println!("{}", r-1);
}



Measured memory_bytes: 4352
fn dfs(
    pos: usize,
    pre: usize,
    color: usize,
    edges: &Vec<Vec<usize>>,
    result: &mut Vec<(usize, usize, usize)>,
) {
    let mut next_color = if color == 0 { 1 } else { 0 };
    for &nxt in edges[pos].iter() {
        if nxt == pre {
            continue;
        }
        result.push((pos, nxt, next_color));
        dfs(nxt, pos, next_color, edges, result);
        next_color += 1;
        if next_color == color {
            next_color += 1;
        }
    }
}
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut edges: Vec<Vec<usize>> = vec![vec![]; n];
    let mut degrees: Vec<usize> = vec![0; n];
    let ab: Vec<(usize, usize)> = (0..n - 1)
        .map(|_| {
            let a: usize = sc.read();
            let b: usize = sc.read();
            edges[a - 1].push(b - 1);
            edges[b - 1].push(a - 1);
            degrees[a - 1] += 1;
            degrees[b - 1] += 1;
            if a >= b {
                (b - 1, a - 1)
            } else {
                (a - 1, b - 1)
            }
        })
        .collect();

    let k = degrees.iter().max().unwrap();
    println!("{}", k);
    let mut result = vec![];
    dfs(0, 0, 123456, &edges, &mut result);
    let mut indices = std::collections::HashMap::new();
    for &(a, b, color) in result.iter() {
        if a >= b {
            indices.insert((b, a), color);
        } else {
            indices.insert((a, b), color);
        }
    }
    // println!("{:?}", indices);
    for x in ab.iter() {
        println!("{}", indices.get(x).unwrap() + 1);
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main(){ 
 int N; cin >> N; ll K; cin >> K;
  vector<ll> A(N); for(int i = 0; i < N; i++){ cin >> A[i]; A[i]--;}
  vector<ll> S(N+1,0);
  
  for(int i = 0; i < N; i++){ S[i+1] = (S[i]+A[i])%K;}
  
  map<ll,ll> mp;
  ll ans = 0; queue<int> Q;
  for(int i = 0; i <= N; i++){ 
    
    //次にansにカウントしていく
    ans += mp[S[i]];
    // mpに追加
    mp[S[i]]++;
    Q.push(S[i]);
    if(Q.size() == K){ mp[Q.front()]--; Q.pop();}
  }
  
  cout << ans << endl; return 0;
}
  
  
    
  

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);


int32_t main()
{
    LL n;
    cin >> n;
    n = n % 1000;
    LL ans = (1000 - n) % 1000;
    cout << ans << "\n";
}



Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(500*500)

N =int(input())
H = list(map(int, input().split()))
H.append(0)
#総数Nで、N番目の添字はN-1

#メモ化再帰
#今の場所からゴールまでの最小コストを出す
now = 0
memo = [-1]*N
def func(n,memo):
  if n >= N:
    return 99999999
  if n == N-1:
    memo[N-1] = 0
    return 0
  else:
    if memo[n] != -1:
      return memo[n]
    else:
      min_later = min(func(n+1,memo)+abs(H[n+1]-H[n]), func(n+2,memo)+abs(H[n+2]-H[n]))
      memo[n] = min_later
    return min_later

print(func(now,memo))

Measured memory_bytes: 93664
n = int(input())
lst = list(map(int, input().split()))
a = list()
count = 0
for i in range(n):
    if lst[i] % 2 == 0:
        a.append(lst[i])

for i in range(len(a)):
    if a[i] % 3 == 0 or a[i] % 5 == 0:
        count += 1

if count == len(a):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 9120
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int D = scn.nextInt();
        long[] c = new long[26];
        long[][] s = new long[D][26];
        long sumC = 0;
        int maxNum = 0;

        for(int i=0;i<26;i++){
            c[i]=scn.nextLong();
            sumC += c[i];
        }
        for(int i=0;i<D;i++){
            long max = -3000;
            for(int j=0;j<26;j++){
                s[i][j]=scn.nextLong();
                long tmp = s[i][j];
                long su = tmp - sumC + c[j];
                if(max < su){
                    max = su;
                    maxNum = j;
                }
            }
            System.out.println(maxNum+1);
        }

        scn.close();

    }


}


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

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

    if(S == "ABC"){
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }

}

Measured memory_bytes: 3600
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

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

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;

int n, p[MAXN], cnt[MAXN];

int main() {
	scanf("%d",&n);
	REP(i, n) scanf("%d",&p[i]);
	REP(i, n) cnt[p[i]]++;

  int tot = 0;
  REP(i, MAXN) tot += (cnt[i] > 0);

  if (tot == 1) {
    (2 * p[0] > n && p[0] != n - 1) ? puts("No") : puts("Yes");
    return 0;
  }

  if (tot > 2) {
    puts("No");
    return 0;
  }

  sort(p, p + n);
  int a = p[0];
  int b = p[n - 1];

  if (b - a != 1 || !(cnt[a] + 1 <= b && b <= cnt[a] + cnt[b]/2)) puts("No");
  else puts("Yes");
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define arraySize(A) (sizeof(A)/sizeof(A[0]))
#define FOR(i,n) for(int i=0;i<n;i++)
#define LOOP(n) for(int __loopCountNum=0;__loopCountNum<n;__loopCountNum++)

using namespace std;

int main(){
    char str[200010]={};
    cin >> str;
    int len = strlen(str);
    long long count=0;
    long long wNum=0;
    FOR(i,len){
        if(str[i]=='W'){
            count += i;
            wNum++;
        }
    }
    count -= (wNum*(wNum-1))/2;
    
    cout<<count;
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r, u, l = 0, d = 0, n;
	cin >> r >> u >> n;
	rep(i,n){
		int x, y, a;
		cin >> x >> y >> a;
		if(a == 1){
			chmax(l, x);
		}
		if(a == 2){
			chmin(r, x);
		}
		if(a == 3){
			chmax(d, y);
		}
		if(a == 4){
			chmin(u, y);
		}
	}
	int ans = max(r-l, 0) * max(u-d, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
x=gsmi

c = x.sort[n/2-1,2]

x.each do |xx|
  if xx < c[1]
    puts c[1]
  else
    puts c[0]
  end
end

Measured memory_bytes: 25324
#define DEBUG 1
#include <bits/stdc++.h>
using namespace std;
typedef          char      s8;
typedef unsigned char      u8;
typedef          short    s16;
typedef unsigned short    u16;
typedef          int      s32;
typedef unsigned int      u32;
typedef          long int s64;
typedef unsigned long int u64;
typedef float             f32;
typedef double            f64;
#define rep(_i, _n) for (int _i = 0; _i < (int)(_n); _i++)
#if DEBUG
#define PHERE()			{ cerr << "L" << setw(3) << __LINE__ << ": PHERE" << clock() << endl; }
#define PVAL( _var )	{ cerr << "L" << setw(3) << __LINE__ << ":" << #_var "=" << (_var) << endl; }
#else
#define PHERE()
#define PVAL( _var )
#endif


int main()
{
	//////// 入力 ////////
	int N;
	cin >> N;
	/////////////////////
	
	
	int turi = 1000 - (N%1000);
	if( turi == 1000 ) {
		turi = 0;
	}
	//////// 出力 ////////
	cout << turi;
	/////////////////////
	
	return 0;
}
#if 0
#endif


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/

  v(int) adj[200001];
  int sz[200001]={0};
  int vis[200001]={0};
  int com[200001];
 void dfs(int i,int c){
    if(vis[i]) return;
    com[i]=c;
    sz[c]++;
    vis[i]=true;
    for(auto x:adj[i]){
        dfs(x,c);
    }
}
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
  cin>>n;
  vector<p3> poi;
  rep(i,n){
      int a,b;
      cin>>a>>b;
      a--,b--;
      poi.pb(mk(mk(a,b),i));
  }
  sort(poi.begin(),poi.end());
  stack<int> ys;
  rep(i,n){
      int b=poi[i].fi.se;
      int c=b;
      while(!ys.empty() && ys.top()<b){
          int x=ys.top();
          if(c==b)
            c=x;
          adj[x].pb(b);
          adj[b].pb(x);
          ys.pop();
      }
      ys.push(c);
  }
  int ans[200001]={0};
  rep(i,n){
      dfs(poi[i].fi.se,poi[i].fi.se);
  }
  rep(i,n){
      ans[poi[i].se]=sz[com[poi[i].fi.se]];
  }
  rep(i,n) cout<<ans[i]<<"\n";
  //cout<<endl;
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 1e5+10;


int parent[2*MAX];
int rankb[2*MAX];
 
void init(int x) {
    for(int i = 0; i <= x; i++)
    parent[i] = i,rankb[i] = 0;
}
 
int root(int x) {
    return (parent[x]==x) ? x : parent[x]=root(parent[x]);
}
 
bool same(int x, int y) {
    return root(x) == root(y);
}
 
void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (rankb[x] < rankb[y])
        parent[x] = y;
    else {
        parent[y] = x;
        if (rankb[x] == rankb[y]) rankb[x]++;
    }
}

ll N, H, W;
viii cards;

ll solve() {
    init(2*MAX);
    sort(rALL(cards));
    ll ans = 0;
    FORE (cd, cards) {
        int a = get<0>(cd), r = get<1>(cd), c = get<2>(cd);
        if (!same(r, c+MAX)) {
            ans += a;
            unite(r, c+MAX);
        } else if (!same(0, r)) {
            ans += a;
            unite(0, r);
        }
    }
    return ans;
}

int main() {
    cin >> N >> H >> W;
    REP (i, N) {
        int a, r, c;
        cin >> r >> c >> a;
        cards.PB(MT(a,r,c));
    }
    cout << solve() << endl;
}

Measured memory_bytes: 4852
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    static final int[] R_OFFSETS = { -1, 0, 1, 0 };
    static final int[] C_OFFSETS = { 0, 1, 0, -1 };

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int H = sc.nextInt();
        int W = sc.nextInt();
        char[][] colors = new char[H][W];
        for (int r = 0; r < H; ++r) {
            String line = sc.next();
            for (int c = 0; c < W; ++c) {
                colors[r][c] = line.charAt(c);
            }
        }

        System.out.println(solve(colors));

        sc.close();
    }

    static int solve(char[][] colors) {
        int H = colors.length;
        int W = colors[0].length;

        int[][] distances = new int[H][W];
        for (int r = 0; r < H; ++r) {
            Arrays.fill(distances[r], -1);
        }
        distances[0][0] = 0;

        Queue<Point> queue = new LinkedList<>();
        queue.offer(new Point(0, 0));

        while (!queue.isEmpty()) {
            Point head = queue.poll();
            if (head.r == H - 1 && head.c == W - 1) {
                return Arrays.stream(colors)
                        .mapToInt(row -> (int) IntStream.range(0, W).filter(c -> row[c] == '.').count()).sum()
                        - (distances[H - 1][W - 1] + 1);
            }

            for (int i = 0; i < R_OFFSETS.length; ++i) {
                int adjR = head.r + R_OFFSETS[i];
                int adjC = head.c + C_OFFSETS[i];

                if (adjR >= 0 && adjR < H && adjC >= 0 && adjC < W && colors[adjR][adjC] == '.'
                        && distances[adjR][adjC] == -1) {
                    distances[adjR][adjC] = distances[head.r][head.c] + 1;
                    queue.offer(new Point(adjR, adjC));
                }
            }
        }

        return -1;
    }
}

class Point {
    int r;
    int c;

    Point(int r, int c) {
        this.r = r;
        this.c = c;
    }
}

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

ll a[12345];

void base26(ll p)
{
    ll cnt=0;
    while(p)
    {
        a[++cnt]=p%26;
        p/=26;
    }
}

int main(void)
{
    ll n, cnt=0;
    cin >> n;

    while(n>=(ll)pow(26, cnt))
    {
        n-=(ll)pow(26, cnt);
        cnt++;
    }

    base26(n);

    for(int i=cnt; i>=1; i--)
        cout << (char)(a[i]+97);
    return 0;
}


Measured memory_bytes: 3992
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;
typedef long long LL;
const LL N = 100005;
 
LL ec = 0,to[N << 1],nxt[N << 1],hed[N],deg[N];
LL cnt = 0;
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
	deg[t] ++;
}
 
LL vis[N] = {0},val[N],dis[N];
LL eu[N],ev[N],n;
string s;
 
void solve(){
	queue <LL> q;
	for(LL i = 1;i <= n;i ++) if(deg[i] == 1 && s[i] == 'B') q.push(i);
	while(!q.empty()){
		LL u = q.front(); q.pop();
		vis[u] = 1;
		for(LL i = hed[u];i;i = nxt[i]){
			LL v = to[i];
			if(!vis[v]){
				deg[v] --;
				if(deg[v] == 1 && s[v] == 'B') q.push(v);
			}
		}
//		cout << u << ' ' << id << ' ' << tot << endl;
//		if(tot == 1 && s[id] == 'B') q.push(id);
	}
	memset(deg,0,sizeof(deg));
	memset(hed,0,sizeof(hed)); ec = 0;
	for(LL i = 1;i < n;i ++){
		if(vis[eu[i]] || vis[ev[i]]) continue;
		add_edge(eu[i],ev[i]);
		add_edge(ev[i],eu[i]);
//		cout << eu[i] << ',' << ev[i] << endl;
	}
	for(LL i = 1;i <= n;i ++){
		val[i] = 0;
		if(vis[i]) continue;
		if((s[i] == 'B' && deg[i] % 2 == 1) || (s[i] == 'W' && deg[i] % 2 == 0)){
			val[i] = 2;
			cnt ++;
		}
	}
}
 
LL td = 0;
LL d[N];
void dfs(LL u,LL f){
	d[u] = val[u];
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		dfs(v,u);
		td = max(td,d[u] + d[v]);
		d[u] = max(d[u],d[v] + val[u]);
	}
}
 
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(LL i = 1;i < n;i ++){
		cin >> eu[i] >> ev[i];
		add_edge(eu[i],ev[i]);
		add_edge(ev[i],eu[i]);
//		deg[u] ++; deg[v] ++;
	}
	cin >> s; s = ' ' + s;
	solve();
	LL trt = 1;
	for(LL i = 1;i <= n;i ++) if(!vis[i]) trt = i;
	dfs(trt,0);
//	cout << ec << ';' << cnt << ';' << endl;
	LL ans = ec + cnt - td;
	cout << ans << '\n';
	return 0;
} 

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

int main(){
  
  int n,t,a;
  cin >>n >>t >>a;
  
  vector<int>h(n);
  for(int i=0; i<n; i++)cin >>h[i];
  
  double ans = 10000;
  int anss = 0;
  
  for(int i=0; i<n; i++){
    double w;
    w = abs(a-(t-h[i]*0.006));
    if(ans>w){
      ans = w;
      anss = i+1;
    }
  }
  
  cout <<anss <<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
// #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int INF = 2147483647;
bool is_integer( double x ){
  return std::floor(x)==x;
}
int main(){
 int azei, bzei = 0;
  cin >> azei >> bzei;
  double A = 0.08;
  double B = 0.1; 
  int aHontai,bHontai = 0;
  bHontai = bzei / B;
  int daiichi = bHontai * A;
  if(daiichi  == azei){
    cout << bHontai;
    return 0;
  }
  while(true){
    bHontai +=1;
    int hanteiB = bHontai * B;
    if(hanteiB != bzei){
      cout << -1;
      return 0;
    }
    int hanteiA = bHontai * A;
    if(hanteiA== azei){
      cout << bHontai;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define ll_1e9 (ll)1e9
using namespace std;

const ll MOD = 1e9+7;

template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    

    bool operator!() const{return !x;}

    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }

    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }

    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }

    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }

    modint operator-() const{ return modint(-x); }

    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }


    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }

    modint inv() const{
        ll a = x,b = MOD,u = 1,v = 0;
        while(b){
            ll t = a/b;
            a -= t*b; swap(a,b);
            u -= t*v; swap(u,v);
        }
        u %= MOD;
        if(u < 0) u += MOD;
        return modint(u);
    }

    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }

    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;

void init_fact(vector<mint> &fact){
  rep(i,0,fact.size()){
    mint temp = i;
    if(!i) fact[i] = 1;
    else fact[i] = temp*fact[i-1];
  }
  return;
}

mint comb(ll n,ll k,vector<mint> &fact){
    if(n < k || n < 0 || k < 0) return (mint)0;
    return fact[n] * fact[n-k].inv() * fact[k].inv();
}

int main(){

    ll n,k;
    cin >> n >> k;

    vector<mint> fact(n+10);
    init_fact(fact);


    rep(i,1,k+1){
        cout << comb(n-k+1,i,fact)*comb(k-1,i-1,fact) << endl;
    }
    return 0;

}


Measured memory_bytes: 256
n = int(input())
s = input()
t = set(s)
ans = 0

for i in range(1,n):
    count = 0
    s1 = s[:i]
    s2 = s[i:]
    for i in t:
        if s1.count(i) > 0 and s2.count(i) > 0:
            count += 1
            
    if ans < count:
        ans = count
print(ans)

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

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

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

const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

int main()
{
	faster;

	int n, x, y, left, right;

	cin >> n >> x >> y;

	vector<vector<int> > adjlist(n+1);
	for(int i = 1; i < n; ++i){
		adjlist[i].pb(i+1);
		adjlist[i+1].pb(i);
	}
	adjlist[x].pb(y);
	adjlist[y].pb(x);

	vector<int> res(n, 0);

	for(int i = 1; i <= n; ++i){
		vector<bool> visited(n+1, false);
		queue<int> q;
		int dist = 1;

		q.push(i);
		q.push(-1);
		visited[i] = true;
		while(!q.empty()){
			int cur = q.front();
			q.pop();

			if(cur == -1){
				++dist;
				if(!q.empty())	q.push(-1);
				continue;
			}

			for(auto x: adjlist[cur]){
				if(!visited[x]){
					++res[dist];
					visited[x] = true;
					q.push(x);
				}
			}
		}
	}

	for(int i = 1; i < n; ++i)	cout << res[i]/2 << '\n';

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long n,a[100002],z,zs;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
      cin>>a[i];
    sort(a+1,a+n+1);
    z=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]==a[i-1])z=(z+1)%2;
        else zs+=z,z=1;
    }
    if(z%2)zs++;
    cout<<zs<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int MOD = 1000000007;

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

  string n;
  cin >> n;

  bool fk = false;
  rep(i, 3) {
    if (n[i] == n[i+1]) fk = true;
  }

  cout << (fk ? "Bad" : "Good") << endl;
  
}


Measured memory_bytes: 888
n, q = map(int, input().split())

p = [i for i in range(n)]
rank = [0 for i in range(n)]

def makeSet(x):
 p[x] = x
 rank[x] = 0

def union(x, y):
 link(findSet(x), findSet(y))

def link(x, y):
 if rank[x] > rank[y]:
  p[y] = x
 else:
  p[x] = y
  if rank[x] == rank[y]:
   rank[y] = rank[y] + 1

def findSet(x):
 if x != p[x]:
  p[x] = findSet(p[x])
 return p[x]


def unite(x, y):
 union(x, y)

def same(x, y):
 x = findSet(x)
 y = findSet(y)

 if x == y:
  return 1
 else :
  return 0


output = []

for i in range(q):
 com, x, y = map(int, input().split())

 if com == 0:
  unite(x, y)
 else :
  output.append(same(x,y))

for ans in output:
 print(ans)


Measured memory_bytes: 7120
I,*U=N,*D=9**9,
P,*L='x+y,',
M,*R='x-y,',
for t in[*open(0)][1:]:*z,u=t.split();exec(u+'+=[*map(int,z)],')
for*A,S in(D,U,'x,y,'),(L,R,'y,x,'),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
 n=I
 for x,y,r in eval('sorted((%sQ)for Q,P in enumerate(A)for x,y in P)'%S):
  if r:n,p=x,y
  elif x==n:N=min(N,y-p)
print(N%I*5or'SAFE')

Measured memory_bytes: 72464
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   double l;
   cin >> l;
   cout << fixed << setprecision(15)<<(l/3)*(l/3)*(l/3) << endl;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;


int main() {

	int a[6];
	int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;

	for (int i = 0; i < 6; i++) {
		cin >> a[i];
		if (a[i] == 1) {
			cnt1++;
		}
		else if (a[i] == 2) {
			cnt2++;
		}
		else if (a[i] == 3) {
			cnt3++;
		}
		else if (a[i] == 4) {
			cnt4++;
		}
	}
	if ((cnt1 % 2 != 0 && cnt2 % 2 != 0 && cnt3 % 2 != 0 && cnt4 % 2 != 0) || 
		(cnt1 % 2 != 0 && cnt2 % 2 != 0 && cnt3 % 2 != 0) ||
		(cnt1 % 2 != 0 && cnt2 % 2 != 0 && cnt4 % 2 != 0) ||
		(cnt2 % 2 != 0 && cnt3 % 2 != 0 && cnt4 % 2 != 0) ||
		(cnt1 % 2 != 0 && cnt3 % 2 != 0 && cnt4 % 2 != 0)){

		cout << "NO" << endl;

	}
	else {
		cout << "YES" << endl;
	}

	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) {
		//code
		Scanner in=new Scanner(System.in);
		int sum=0;
      	String s=in.nextLine();
      char ch[]=s.toCharArray();
      for(int i=0;i<s.length();i++)
      {
        	sum=sum+(int)(ch[i]-'0');
      }
      if(sum%9==0)
      {
        	System.out.println("Yes");
      }
      else
      {
        	System.out.println("No");
      }
}
}


Measured memory_bytes: 41380
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int k;
	cin >> k;
	bool ch[k] = {};
	int mo = 7 % k;
	int now = 0;
	while(!ch[mo]){
		ch[mo] = true;
		now ++;
		mo = (mo* 10 + 7) % k;
	}
	if (ch[0]) cout << now << endl;
	else cout << "-1" << endl;
	
	//cout << ans << endl;
}

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

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

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

#define fast_io                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)

#define endl '\n'
constexpr int N = 101;
int out[N];

int main() {
  fast_io;
  vector<pair<string, int>> x;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string ct;
    int p;
    cin >> ct >> p;
    p = -p;
    x.PB({ct, p});
    out[-p] = i + 1;
  }
  sort(ALL(x));
  for (auto v : x) {
    cout << out[-v.S] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=105;
const int mod=1000000007;

int n,m,up,ans;
int dp[N][N*N];

int main(){
	int i,j,k;
	scanf("%d%d",&n,&m);
	ans=1ll*m*(m+1)/2%mod;
	for (i=2;i<=n;i++) ans=1ll*ans*(m+1)%mod;
	ans=1ll*ans*n%mod;
	dp[n+1][0]=1;
	for (i=n;i>=1;i--){
		for (j=0;j<=up;j++)
			for (k=0;k<=m;k++){
				if (k<=i) dp[i][(j+k)/i+j]=(dp[i][(j+k)/i+j]+dp[i+1][j])%mod;
				else dp[i][j]=(dp[i][j]+dp[i+1][j])%mod;
			}
		up+=(up+min(i,m))/i;
	}
	for (i=0;i<=up;i++) ans=(ans-1ll*dp[1][i]*i%mod)%mod;
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 2560
a = int(input())

mt = [1,2,3,4,5,6,7,8,9, \
     4,6,8,10,12,14,16,18,\
     9,12,15,18,21,24,27,\
     16,20,24,28,32,36,\
     25,30,35,40,45,\
     36,42,48,54,\
     49,56,63, \
     64,72, \
     81]

if a in mt:
  print("Yes")
else:
  print("No")

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

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999
#define P(x)           printf("%d\n", (x));

typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for(int &a : A) cin >> a;
	VSORT(A);

	int cost = accumulate(A.begin(), --A.end(), A.back() / 2);

	cout << cost << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  ll n;
  cin>>n;
  vvll table(n,vll(10));
  rep(i,n) rep(j,10)cin>>table[i][j];
  vvll p(n,vll (11));
  rep(i,n) rep(j,11) cin>>p[i][j];
  ll ans=0;
  ans-=INF;
  for(int bit=1;bit<(1<<10);bit++){
    ll cu=0;
    vll pp(10);
    rep(i,10){
      if(bit&(1<<i)) pp[i]=1;
    }
    rep(i,n){
      ll k=0;
      rep(j,10){
        if(pp[j]&&table[i][j]){
          k++;
        }
      }
      cu+=p[i][k];
    }
    ans=max(ans,cu);
  }
  COUT(ans);
}


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

namespace Aojx
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            double[] pos = { 0, 0 };
            double rad = Math.PI / 2;

            while (true)
            {
                var row = Console.ReadLine().Split(',').Select(e => int.Parse(e)).ToArray();
                if (row[0] == 0 && row[1] == 0)
                {
                    break;
                }
                pos[0] += row[0] * Math.Cos(rad);
                pos[1] += row[0] * Math.Sin(rad);
                rad -= row[1] * Math.PI / 180;
            }

            pos[0] = pos[0] - (pos[0] % 1);
            pos[1] = pos[1] - (pos[1] % 1);

            Console.WriteLine("{0}\n{1}",
                pos[0], pos[1]);

        }
    }
}

Measured memory_bytes: 5984
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<string> vo,ve;
    vo.reserve(n/2+1);
    ve.reserve(n/2+1);

    REP(i,n) {
        string x; cin >> x;
        if (i % 2 == 0) ve.push_back(x);
        else vo.push_back(x);
    }
    reverse(ALL(vo));
    vector<string> v(vo);
    v.reserve(n);
    v.insert(v.end(),ALL(ve));
    if (n % 2 == 1) reverse(ALL(v));

    string ans = "";
    REP(i,n-1) {
        ans += v[i] + " ";
    }
    ans += v[n-1];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 17776
#include<iostream>
#include<stdio.h>
using namespace std;
int n;
int A[50];
int solve(int i,int m){
	if(m==0)return 1;
	if(i>=n)return 0;
	int res=solve(i+1,m)||solve(i+1,m-A[i]);
	return res;
} 


int main(){
	int q,m,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&m);
		if(solve(0,m))cout<<"yes"<<endl;
		else
		cout<<"no"<<endl; 
	}
	return 0;
}


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


Measured memory_bytes: 128
import sys
from math import ceil

sys.setrecursionlimit(100000)
A, B, C = list(map(int, input().split()))

if A * 7 >= C:
    print(ceil(C/A))
    exit()

cur = C
count = 0
count_i = 0
while cur > 0:
    count += 1
    count_i += 1
    if count_i == 7:
        count_i = 0
        cur -= B
    cur -= A

print(count)


Measured memory_bytes: 5664
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var n,a;
var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  n = next();
  a = nexts(n);
  if(n & 1)return solveodd();
  return solveeven();
}
function solveeven(){
  var dp = xArray(0,n+1,2,2);
  for(var i = 0; i < n; i++){
    dp[i+1][0][1] = dp[i][0][0] + a[i];
    dp[i+1][0][0] = dp[i][0][1];
    dp[i+1][1][0] = Math.max(dp[i][0][0], dp[i][1][1]);
    dp[i+1][1][1] = dp[i][1][0] + a[i];
  }
  return Math.max(dp[n][0][0], dp[n][1][1]);
}

function solveodd(){
  var dp = xArray(0,n+1,3,2);
  for(var i = 0; i < n; i++){
    dp[i+1][0][1] = dp[i][0][0] + a[i];
    dp[i+1][0][0] = dp[i][0][1];
    dp[i+1][1][0] = Math.max(dp[i][0][0], dp[i][1][1]);
    dp[i+1][1][1] = dp[i][1][0] + a[i];
    dp[i+1][2][0] = Math.max(dp[i][1][0], dp[i][2][1]);
    dp[i+1][2][1] = dp[i][2][0] + a[i];
  }
  return Math.max(dp[n][1][0], dp[n][2][1]);
}

Measured memory_bytes: 147712
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

s = input()
for i in range(len(s)):
    if (i+1) % 2 != 0:
        print(s[i], end='')


Measured memory_bytes: 46680
import java.util.*;
import java.math.*;
class Main {
    //
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        c -=a+b;
      	if(c<0){
          System.out.println("No");
          return;
        }
        long an = 4*a*b;
        long cn = c*c;
        if(an<cn){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
    
}



Measured memory_bytes: 23764
N, M = map(int, input().split())
A = list(map(int, input().split()))
total, count = 0, 0
for i in range(N):
    total += A[i]
for i in range(N):
    if(A[i] >= total/(M*4)):
        count+=1

if(count>=M):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <numeric>
#include <ctime>
using namespace std;

const int MAX_N = 20001;
typedef pair<int, int> P;

// input
int n, x[MAX_N], y[MAX_N];
char dir[MAX_N];

int futon[MAX_N];
bool used[MAX_N];
map<P, int> m;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};
bool ans;

void dfs(int pos, int k){
	if( ans == false ) return ;
	
	int x1 = x[pos], y1 = y[pos], x2, y2;
	used[pos] = true;
	futon[pos] = k;
	int next = (k + 1) % 2;
	if( dir[pos] == 'x' ){
		x2 = x1 + 1, y2 = y1;
	}else{
		x2 = x1, y2 = y1 + 1;
	}
	
	for(int i=0 ; i < 4 ; i++ ){
		int mx = x1 + dx[i], my = y1 + dy[i];
		if( mx == x2 && my == y2 ) continue;
		
		if( m.count(P(mx,my)) ){
			int id = m[P(mx,my)];
			if( used[id] ){
				if( futon[id] == futon[pos] ){
					ans = false;
				}
			}else{
				dfs(id, next);
			}
		}
	}
	for(int i=0 ; i < 4 ; i++ ){
		int mx = x2 + dx[i], my = y2 + dy[i];
		if( mx == x1 && my == y1 ) continue;
		
		if( m.count(P(mx,my)) ){
			int id = m[P(mx,my)];
			if( used[id] ){
				if( futon[id] == futon[pos] ){
					ans = false;
				}
			}else{
				dfs(id, next);
			}
		}
	}
}

int main(){
	while( cin >> n, n ){
		fill(used, used + MAX_N, false);
		fill(futon, futon+MAX_N, -1);
		m.clear();
		ans = true;
		
		for(int i = 0 ; i < n ; i++ ){
			cin >> x[i] >> y[i] >> dir[i];
			if( dir[i] == 'x' ){
				m[ P(x[i], y[i]) ] = i;
				m[ P(x[i]+1, y[i]) ] = i;
			}else{
				m[ P(x[i], y[i]) ] = i;
				m[ P(x[i], y[i]+1) ] = i;
			}
		}
		for(int i = 0 ; i < n ; i++ ){
			if( used[i] ) continue;
			dfs(i, 0);		
		}
		if( ans ){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 6148