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

int main(void)
{
  int N;
  cin >> N;
  vector<pair<int, pair<int, int>>> num(N);
  long long int sum = 0;

  for (int i = 0; i < N; i++)
  {
    int a, b;
    cin >> a >> b;
    num[i] = make_pair(-a - b, make_pair(-a, -b));
  }
  sort(num.begin(), num.end());
  for (int i = 0; i < N; i++)
  {
    if (i % 2 == 0)
      sum += (num[i].second).first;
    else
      sum -= (num[i].second).second;
  }
  cout << -sum;
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 7+1e18
#define lld long double
#define eps 0.000001
#define endl '\n'
using namespace std ;

int main()
{
	
 
    lli n,i;
    cin>>n>>i;
    cout<<n-i+1<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    string str;
    cin >> str;
    ll int h[N];
    memset(h, 0, sizeof(h));
    int y = 0;
    char ch_2 = str[0];
    char ch_3 = str[1];
    int FF[N];
    memset(FF, 0, sizeof(FF));
    if(ch_2 == 'A' && ch_3 == 'C'){
        h[0] = 1;
        FF[0] = 1;
    }
    else h[0] = 0;
    for(int i = 1; i < (int)str.size() - 1; ++i){
        char ch = str[i];

        char ch_1 = str[i + 1];

        if(ch == 'A' && ch_1 == 'C'){
            h[i] = h[i - 1] + 1;
            FF[i] ++;
        }
        else h[i] = h[i - 1];
        
    }
    rep(i, Q){
        int l, r;
        cin >> l >> r;
        if (FF[l - 1] == 1) cout << h[r - 2] - h[l - 1] + 1<< endl;
        else cout << h[r - 2] - h[l - 1]<< endl;
    }



}

Measured memory_bytes: 2256
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct data {
	int a, b, c;
} e[10005];
int n, m, p[1005];
inline bool cmp(data d1, data d2) { return d1.c < d2.c; }
int f(int x) {
	if (p[x] == x) return x;
	return (p[x] = f(p[x]));
}
int main() {
	while (scanf("%d%d", &n, &m), n&&m) {
		for (int i = 1; i <= n; i++) p[i] = i;
		for (int i = 1; i <= m; i++) scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].c);
		sort(e + 1, e + m + 1, cmp);
		int cnt = 0;
		for (int i = 1; i <= m; i++) {
			int A = f(e[i].a), B = f(e[i].b);
			if (A == B) continue;
			cnt++;
			p[A] = B;
			if (cnt == n / 2) {
				printf("%d\n", e[i].c);
				break;
			}
		}
	}
}

Measured memory_bytes: 1172
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, k;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	if(n % k == 0) cout << 0 << endl;
	else cout << min(n%k, k-(n%k)) << endl;
	
	return 0;
}

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

int main(){
  vector<ll> dp(200010,0);
  vector<ll> data(200010,0);
  int N; cin >> N;
  int C; int num[N];
  for(int i=0;i<N;i++){
    cin >> num[i];
  }
  for(int i=0;i<N;i++){
    C=num[i];
    if(i==0){
      data[C]=1;
      dp[0]=1;
      continue;
    }
    if(C==num[i-1]){
      dp[i]=dp[i-1];
      continue;
    }
    dp[i]=dp[i-1]+data[C];
    data[C]+=dp[i-1];
    dp[i]%=1000000007;
    data[C]%=1000000007;
  }
  cout << dp[N-1];
}

Measured memory_bytes: 4096
#include <stdio.h>

int main(void){
    //input 
    int N;
    scanf("%d",&N);
    int H[N];
    for(int i=0; i<N; i++)
    scanf("%d",&H[i]);

    //calcu
    int max=0;
    int second=0;

    for(int i = 0; i < N-1; i++){
        if(H[i] >= H[i+1]){
            second++;
        }else if(H[i] < H[i+1] && second > max){
            max = second;
            second = 0; 
        }else{
            second = 0;
        }        
    }

    if(second>=max)
    max = second;
    
    //output
    printf("%d\n",max);
    return 0;

}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
    int S;
    int h;
    int m;
    int s;

    scanf("%d",&S);

    h = S/3600;
    m = S%3600;
    s = m%60;
    m = m/60;

    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



Measured memory_bytes: 2676
#![allow(unused_imports, unused_macros, non_snake_case)]
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

//{{{ macros missing in 1.15.1
#[macro_use]
mod macros {
    macro_rules! eprint {
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = write!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! eprintln {
        () => { eprintln!(""); };
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = writeln!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! dbg {
        ($val:expr) => {
            match $val {
                tmp => {
                    eprintln!(
                        "[{}:{}] {} = {:#?}",
                        file!(),
                        line!(),
                        stringify!($val),
                        &tmp
                    );
                    tmp
                }
            }
        };
    }
}
//}}}

fn run() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    let n: usize = sc.read();
    println!("{}", (n - 1) / 2);
}

fn main() {
    std::thread::Builder::new()
        .name("run".to_string())
        .stack_size(1024 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap()
}

//{{{ Scanner
pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner { reader: r }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

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


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);

int main() {
  ll n, m; cin >> n >> m;
  vi d(m); REP(i, m) cin >> d[i];
  vvi dp(m, vi(n+1,INF));
  REP(i,m) dp[i][0]=0;
  for(ll i=1;i*d[0]<=n;i++) dp[0][i*d[0]]=i;
  FOR(i,1,m) REP(j,n+1) {
    dp[i][j]=dp[i-1][j];
    if(j>=d[i]) dp[i][j]=min(dp[i][j],dp[i-1][j-d[i]]+1);
    if(j>=d[i]) dp[i][j]=min(dp[i][j],dp[i][j-d[i]]+1);
  }
  cout<<dp[m-1][n]<<endl;
}

Measured memory_bytes: 11008
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n=int(input())
a=list(map(int,input().split()))

ans=0
lo=0
while lo<n:
    hi=lo+1
    while hi<n and a[lo]==a[hi]: hi+=1
    ans+=(hi-lo)//2
    lo=hi
print(ans)


Measured memory_bytes: 38384
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef vector<int> vi;
typedef vector<string> vs;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

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

	while(true) {

		int n;
		cin >> n;
		if(!n) break;

		int b1 = 0, b2 = 0;
		int ans = 0;
		rep(i,0,n) {
			string s;
			cin >> s;
			if(s == "lu") {
				b2 = b1;
				b1 = 1;
			} else if(s == "ru") {
				b2 = b1;
				b1 = 2;
			} else if(s == "ld") {
				b2 = b1;
				b1 = 3;
			} else if(s == "rd") {
				b2 = b1;
				b1 = 4;
			}

			if((b1 == 1 && b2 == 2) || (b1 == 2 && b2 == 1) ||
				 (b1 == 3 && b2 == 4) || (b1 == 4 && b2 == 3))
				 	ans++;
		}
		cout << ans << endl;

	}


	return 0;
}

Measured memory_bytes: 1220
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val N = rd.readInt()
    val S = rd.readString()
    val c = S.toCharArray()

    val change = min(S.count{it == 'R'}, S.count{it == 'W'})

    var l = 0; var r = N-1
    var swap = 0
    while (l < r) {
        while (l<N-1 && c[l] == 'R') l++
        while (0<r && c[r] == 'W') r--
        if (l>=r) break
        c[l] = 'R'
        c[r] = 'W'
        swap++
    }

    val ans = min(change, swap)
    println(ans)
}


//val rd = debug.Reader("abc", "174", "d", "sample-3")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
data class To(val idx: Int, val cost: Long)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 38572
#include <bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define bp __builtin_popcountll
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
int main() 
{
    FAST;
    string s,t;
    cin >> s >> t;
    cout<<t<<s;
}


 

Measured memory_bytes: 256
N = int(input())
K = int(input())
x_li = list(map(int, input().split()))
ans = 0
for i in range(N):
    if x_li[i] > abs(K - x_li[i]):
        ans += 2 * abs(K - x_li[i])
    else:
        ans += 2*x_li[i]

print(ans)

Measured memory_bytes: 9128
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int h,w,k;cin>>h>>w>>k;

    VS s(h);
    REP(i,h){
        cin>>s[i];
    }

    int result = 0;
    int n = h+w;
    REP(bit,(1<<n)){
        VS ss = s;
        REP(i,n){
            if(bit&(1<<i)){
                if(i<h){
                    REP(j,w){
                        ss[i][j] = 'X';
                    }
                }
                else{
                    REP(j,h){
                        ss[j][i-h] = 'X';
                    }
                }
            }
        }
        int t = 0;
        REP(i,h){
            REP(j,w){
                if(ss[i][j] == '#'){
                    t++;
                }
            }
        }
        if(t==k){
            result++;
        }
    }
    cout<<result<<endl;
    
	return;
}

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

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

int graph[101][101];

int main() {
    int n;
    int u,k,v;
    cin >> n;
    for(int i=0;i<n;i++) {
        cin >> u >> k;
        for(int j=0;j<k;j++) {
            cin >> v;
            if(graph[u][v] == 0)
                graph[u][v] = 1;
        }
    }
    
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            cout << graph[i][j] << (j==n ? "\n" : " ");
        }
    }
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007

int main()
{
  int n;
  cin>>n;
  string s1,s2;
  
  cin>>s1>>s2;
  long ans=0;
  bool currpos,lastpos;
  int i;
  if(s1[0]==s2[0])
  {
    ans=3;
    currpos=0;     //position=0 means vertical
	i=1;  
  }
  else{
    ans=6;
    currpos=1;  //horizontal
    i=2;
  }
  lastpos=currpos;
  while(i<n)
  {
	 if(lastpos==0)
     {
       ans=(ans*2)%M;
       if(s1[i]==s2[i])
       {
         i=i+1;
         currpos=0;
       }
       else{ i=i+2;
            currpos=1;}
       
     }
     else
     {
       if(s1[i]!=s2[i])
       {
         ans=(ans*3)%M;
         i=i+2;
         currpos=1;
         
       }
       else
       {
         i=i+1;
         currpos=0;
       }
       
     }
    
    
    lastpos=currpos;
  }
  
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
use itertools::Itertools;
use proconio::{input, marker::Usize1};

fn main() {
    input! {
        n: usize, q: usize,
        c: [Usize1; n],
        query: [(Usize1, Usize1); q]
    }

    let mut right = vec![None; n];
    let mut fw = Fenwick::new(n);

    let query = query.iter().enumerate().sorted_by_key(|(_, (_, r))| r);
    let mut ans = vec![0; q];
    let mut cur = 0;
    for (i, &(l, r)) in query {
        while cur <= r {
            if let Some(old) = right[c[cur]] {
                fw.add(old, -1);
            }
            right[c[cur]] = Some(cur);
            fw.add(cur, 1);
            cur += 1;
        }
        ans[i] = fw.sum(l, r + 1);
    }

    ans.iter().for_each(|it| println!("{}", it));
}

struct Fenwick(Vec<i64>);

impl Fenwick {
    fn new(n: usize) -> Self {
        Self(vec![0; n + 1])
    }
    fn sum(&self, l: usize, mut r: usize) -> i64 {
        if l != 0 {
            return self.sum(0, r) - self.sum(0, l);
        }
        let mut ret = 0;
        while r > 0 {
            ret += self.0[r];
            let ir = r as isize;
            r -= (ir & -ir) as usize;
        }
        ret
    }
    fn add(&mut self, mut i: usize, x: i64) {
        i += 1;
        while i < self.0.len() {
            self.0[i] += x;
            let ii = i as isize;
            i += (ii & -ii) as usize;
        }
    }
}


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

int main()
{
	int N, l, r, res = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> l >> r;
		res += r - l + 1;
	}
	cout << res << endl;
	return 0;
}

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

int main()
{
    int i,n,x;
    cin >> n;
    S[0] = true;
    int sum = 0,rs=0;
    for(i=0;i<n;i++)
    {
        cin >> x;
        sum += x;
        S|=(S<<x);
    }
    rs = (sum+1)/2;
    for(i=rs;i<=sum;i++)
    {
        if(S[i])
            break;
    }
    cout << i << endl;
return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>

int main()
{
  int a,b,c;
  int tmp;
  int r;
  scanf("%d%d%d",&a,&b,&c);
  if(a<b){
    tmp=a;
    a=b;
    b=tmp;
  }
  r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  tmp=c%b;
  if(tmp==0){
    printf("YES");
  }
  else{
    printf("NO");
  }
  return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define for_each(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = __INT_MAX__;               // 2^31 - 1
const long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    int n;
    cin >> n;
    vi x, y, h;
    rep(i, n) {
        int a, b, c;
        cin >> a >> b >> c;
        x.push_back(a);
        y.push_back(b);
        h.push_back(c);
    }
    int ax, ay, ah;
    auto f = [](int x1, int x2, int y1, int y2, int h) {
        return h + abs(x1 - x2) + abs(y1 - y2);
    };
    rep(xn, 101) {
        rep(yn, 101) {
            bool ok = true;
            int idx = 0;
            while (h[idx] == 0)
                idx++;
            int h_condidate = f(xn, x[idx], yn, y[idx], h[idx]);
            rep(i, n) {
                if (max(0, h_condidate - abs(xn - x[i]) - abs(yn - y[i])) != h[i])
                    ok = false;
            }
            if (ok)
                ax = xn, ay = yn, ah = h_condidate;
        }
    }
    cout << ax << ' ' << ay << ' ' << ah << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	var S string
	fmt.Scan(&S)
	s:=[]byte(S)
	y:=1
	for x:=1;x<N;x++{
		if (s[x]!=s[x-1]){
			y+=1
		}
	}
	fmt.Print(y)
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
a.sort()
#print(a)
i = 0 # a[-i-1] 
big = 0
small = 0
while True:
    #print(i)
    if i+2 > n: break
    if a[-i-1] == a[-i-2]:
        if big == 0:
            big = a[-i-1]
            #print("b",big)
        else:
            small = a[-i-1]
            #print("s",small)
            break
        i += 2
    else: i += 1
    
print(big*small)

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

using namespace std;

#define MAX 200
#define INF 1000002
typedef pair<int, int> pii;

int H, W, N;
int X1[MAX], X2[MAX], Y1[MAX], Y2[MAX];
bool fld[MAX*6][MAX*6];

int compress(int *x1, int *x2)
{
    vector<int> xs;
    for (int i = 0; i < N; i++) {
        for (int d = -1; d <= 1; d++) {
            int tx1 = x1[i] + d, tx2 = x2[i] + d;
            xs.push_back(tx1);
            xs.push_back(tx2);
        }
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());

    for (int i = 0; i < N; i++) {
        x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
        x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
    }
    return xs.size();
}

int solve()
{
    W = compress(X1, X2);
    H = compress(Y1, Y2);
    
    memset(fld, 0, sizeof(fld));
    for (int i = 0; i < N; i++) {
        for (int y = Y1[i]; y <= Y2[i]; y++) {
            for (int x = X1[i]; x <= X2[i]; x++) {
                fld[y][x] = 1;
            }
        }
    }
    
    const int dx[] = {-1, 0, 1, 0};
    const int dy[] = {0, -1, 0, 1};
    
    int res = 0;
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (fld[y][x]) continue;            
            res++;

            queue<pii> Q;
            Q.push(pii(x, y));
            while (!Q.empty()) {
                pii p = Q.front(); Q.pop();
                int sx = p.first, sy = p.second;

                for (int i = 0; i < 4; i++) {
                    int tx = sx + dx[i], ty = sy + dy[i];
                    if (tx < 0 || W <= tx || ty < 0 || H <= ty || fld[ty][tx]) {
                        continue;
                    }

                    Q.push(pii(tx, ty));
                    fld[ty][tx] = 1;
                }

            }
        }

    }
    return res;
}

int main()
{
    while (cin >> N, N) {
        H = W = INF;
        int x[2], y[2];
        for (int i = 0; i < N; i++) {
            cin >> x[0] >> y[0] >> x[1] >> y[1];
            for (int j = 0; j < 2; j++) {
                x[j] = x[j] * 2 + 1;
                y[j] = y[j] * 2 + 1;
            }
            int dj[] = {1, 0, 0, -1}, dk[] = {0, -1, 1, 0};
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k < 2; k++) {
                    int l = j * 2 + k, m = i * 4 + l;
                    int nj = j + dj[l];
                    int nk = k + dk[l];
                    X1[m] = x[j];  Y1[m] = y[k];
                    X2[m] = x[nj]; Y2[m] = y[nk];
                    if (X1[m] > X2[m]) swap(X1[m], X2[m]);
                    if (Y1[m] > Y2[m]) swap(Y1[m], Y2[m]);
                }
            }                        
        }
        N *= 4;
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 2652
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};



int main(){

    int x;
    cin >> x;
    if(x >= 400 && x <= 599) cout << 8 << endl;
    else if(x >= 600 && x <= 799) cout << 7 << endl;
    else if(x >= 800 && x <= 999) cout << 6 << endl;
    else if(x >= 1000 && x <= 1199) cout << 5 << endl;
    else if( x >= 1200 && x <= 1399) cout << 4 << endl;
    else if( x >= 1400 && x <= 1599) cout << 3 << endl;
    else if(x >= 1600 && x <= 1799) cout << 2 << endl;
    else if(x >= 1800 && x <= 1999) cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
int n;
long long ans = 0;
int main() {
	cin >> n;
	for(int i = 1;i <= n;i ++) {
		if(i % 3 && i % 5) ans += i;
	}
	cout << ans << "\n";
	return 0;
} 

Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cassert>
#include <iostream>
using std::cin; using std::cout; using std::endl;
#include <algorithm>
using std::sort;
#include <vector>
using std::vector;
#include <map>
using std::map;
#include <set>
using std::set;
#include <queue>
using std::queue; using std::priority_queue;
#include <utility>
using std::pair;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
#define pass printf("%s : Line.%d\n", __FUNCTION__, __LINE__);

bool chmin(int &a, const int &b) { return a > b ? a = b, true : false; }
bool chmax(int &a, const int &b) { return a < b ? a = b, true : false; }
bool chmin(LL &a, const LL &b) { return a > b ? a = b, true : false; }
bool chmax(LL &a, const LL &b) { return a < b ? a = b, true : false; }
int readint() {
	int a = 0, po = 1; char c = getchar();
	while(isspace(c)) c = getchar();
	if(c == '-') po = -1, c = getchar();
	while(isdigit(c)) a = a*10 + c - '0', c = getchar();
	return a * po;
}
LL readLL() {
	LL a = 0, po = 1; char c = getchar();
	while(isspace(c)) c = getchar();
	if(c == '-') po = -1, c = getchar();
	while(isdigit(c)) a = a*10 + c - '0', c = getchar();
	return a * po;
}

const int maxN = 100000 + 5;
int n, k;
LL x[maxN], ans;

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i) scanf("%lld", &x[i]);
	std::sort(x + 1, x + n + 1);
	ans = 0x3f3f3f3f3f3f3f3f;
	for(int i = 1; i <= n && i + k - 1 <= n; ++i) {
		int j = i + k - 1;
		LL val = 0;
		if(x[j] <= 0) val = -x[i];
		else if(x[i] >= 0) val = x[j];
		else val = std::min(x[j]*2 - x[i], -x[i] * 2 + x[j]);
		chmin(ans, val);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
vector<int> mx = {1,0,-1,0} ;
vector<int> my = {0, 1, 0, -1} ;


int main () {
    int h, w ;
    cin >> h >> w ;
    int sx, sy, gx, gy ;
    cin >> sx >> sy ;
    cin >> gx >> gy ;
    sx--; sy-- ; gx--; gy-- ;
    vector<string> g (h) ;
    rep(i, h) cin >> g[i] ;
    vector<vector<ll>> list (h, vector<ll> (w, INF)) ;
    deque<P> deq ; 
    deq.emplace_front(sx, sy) ;
    list[sx][sy] = 0 ;
    while(!deq.empty()){
        P f = deq.front() ;
        int fx = f.first ;
        int fy = f.second ;
        int d = list[fx][fy] ;
        deq.pop_front() ;
        rep(i, 4){
            int px = mx[i] ;
            int py = my[i] ;
            int nx = fx + px ;
            int ny = fy + py ;
            if(nx < 0 || ny < 0 || nx > h - 1 || ny > w - 1) continue ;
            if(list[nx][ny] <= d) continue ;
            if(g[nx][ny] == '#') continue ;
            list[nx][ny] = d ;
            deq.emplace_front(nx, ny) ;
        }
        for(int i = -2 ; i <= 2 ; i++){
            for(int j = -2; j <= 2 ; j++){
                int nx = fx + i ;
                int ny = fy + j ; 
                int nd = d + 1 ;
                if(nx < 0 || ny < 0 || nx > h - 1 || ny > w - 1) continue ;
                if(list[nx][ny] <= nd) continue ;
                if(g[nx][ny] == '#') continue ;
                list[nx][ny] = nd ;
                deq.emplace_back(nx, ny) ;
            }
        }
    }
    if(list[gx][gy] > 1e15){
        cout << -1 << endl ;
    }
    else {
        cout << list[gx][gy] << endl ;
    }
}

Measured memory_bytes: 13308
mod=10**9+7
n,k=map(int,input().split())
cnt=[0]*k
for i in range(k,0,-1):
	cnt[i-1]=pow(k//i,n,mod)
	for j in range(i*2,k+1,i):
		cnt[i-1]-=cnt[j-1]
	cnt[i-1]%=mod
ans=0
for i in range(k):
	ans+=cnt[i]*(i+1)%mod
print(ans%mod)

Measured memory_bytes: 11188
n = int(input())
Number = [[0]*10 for l in range(10)]

for i in range(1,n+1):
    s = str(i)
    j = int(s[0])
    k = int(s[-1])
    Number[j][k] += 1
count = 0
for i in range(10):
    for j in range(10):
        count += Number[i][j] *Number[j][i]
print(count)

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

int main()
{
  string a,b;
  cin>>a>>b;
  int cnt=0;
  for(int i=0;i<a.size();i++)
  {
    if(a[i]!=b[i]) cnt++;
  }
  
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3892
import heapq
def E():
    X, Y, A, B, C = map(int, input().split())
    reds = []
    heapq.heapify(reds)
    for n in input().split():
        heapq.heappush(reds, int(n))
    greens = []
    heapq.heapify(greens)
    for n in input().split():
        heapq.heappush(greens, int(n))
    colorless = []
    heapq.heapify(colorless)
    for n in input().split():
        heapq.heappush(colorless, -int(n))
    
    redx = heapq.nlargest(X, reds)
    greeny = heapq.nlargest(Y, greens)
    colorless_val = 0
    while True:
        if not colorless:
            break
        cur = abs(heapq.heappop(colorless))
        if redx and cur > redx[-1]:
            if greeny and redx[-1] > greeny[-1]:
                greeny.pop()
            else:
                redx.pop()
            colorless_val += cur
        elif greeny and cur > greeny[-1]:
            if redx and greeny[-1] > redx[-1]:
                redx.pop()
            else:
                greeny.pop()
            colorless_val += cur
        else:
            break
    print(sum(redx)+sum(greeny)+colorless_val)

E()

Measured memory_bytes: 25904
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))

memo = 10**5
for i in range(n):
    if abs((t-h[i]*0.006)-a) < memo:
        ans = i+1
        memo = abs((t-h[i]*0.006)-a)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

vi step(100010,1),dp(100010,0);
int n,m;

void solve(){
    dp[0] = 1;
    dp[1] += step[1];
    rep(i,2,n+1){
        if(!step[i]){dp[i] = 0;}
        else{dp[i] = dp[i-1] + dp[i-2];}
        dp[i]%=MOD;
    }
}


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    cin>>n>>m;
    
    int a;
    rep(i,0,m){
        cin>>a;
        step[a]=0;
    }
    solve();
    cout<<dp[n]%MOD<<endl;
}

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

#define eb emplace_back
#define INF 1LL<<62
#define FLT_INF pow(10.0, 16)

using ll = long long;
using vll = vector<ll>;
using ull = unsigned long long;
using int2 = pair<int, int>;

template <typename A> string to_string(const A& v);
string to_string(const string& s) { return '"'+ s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B> string to_string(const pair<A, B>& p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A> string to_string(const A& v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename T>
void sort(vector<T>& val) {
  sort(val.begin(), val.end());
}

template <typename T>
void sort_b(vector<T>& val) {
  sort(val.begin(), val.end(), greater<T>());
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...);
#endif

#define COMMON_MOD 998244353
#define PI 3.14159265

// sort(a.begin(), a.end(), less<ll>()); greater<ll>()
// cout<<fixed<<setprecision(20)<<(s/kl)*2;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;

  vector<string> s_lst(n);
  ll b_start_count = 0;
  ll a_end_count = 0;
  ll b_start_a_end_count = 0;
  ll ab_count = 0;
  for (int i = 0; i < n; i++) {
    cin >> s_lst[i];
    if (s_lst[i][0] == 'B' && s_lst[i][s_lst[i].size() - 1] == 'A') {
      b_start_a_end_count++;
    } else if (s_lst[i][0] == 'B') {
      b_start_count++;
    } else if (s_lst[i][s_lst[i].size() - 1] == 'A') {
      a_end_count++;
    }
    for (int j = 0; j < s_lst[i].size() - 1; j++) {
      if (s_lst[i][j] == 'A' && s_lst[i][j + 1] == 'B') {
        ab_count++;
      }
    }
  }
  debug(s_lst);
  debug(ab_count, a_end_count, b_start_count, b_start_a_end_count);

  if (b_start_a_end_count > 0) {
    ab_count += (b_start_a_end_count - 1);
    if (a_end_count > 0) {
      a_end_count--;
      ab_count++;
    }
    if (b_start_count > 0) {
      b_start_count--;
      ab_count++;
    }
  }

  ab_count += min(b_start_count, a_end_count);

  cout << ab_count;
  cout << endl;
  return 0;
}


Measured memory_bytes: 768
#include<stdio.h>

int main(){
	
int A,B,C;
int n,i;
	
A=0;
B=1;
scanf("%d",&n);
for(i=0;i<n;i++){
		
C=B+A;
A=B;
B=C;
}
printf("%d\n",B);
return 0;
}

Measured memory_bytes: 1852
import scala.io.StdIn._

object Main extends App {
  val Array(n, m, x) = readLine.split(" ").map(_.toInt)

  val books = Range(0, n).map { _ =>
    val line = readLine.split(" ").map(_.toInt)
    line.head -> line.tail
  }

  val patterns = Range(0, Math.pow(2, n).toInt).map { patternInt =>
    val booksToBuy = books.zipWithIndex
      .filter { case (_, idx) => ((1 << idx) & patternInt) > 0 }
      .map { case (book, _) => book }

    val initial = (0, Array.fill(m)(0).toSeq)
    booksToBuy.foldLeft(initial) {
      case ((totalCost, totalEffects), (cost, effects)) =>
        (
          totalCost + cost,
          Range(0, m).map(i => totalEffects(i) + effects(i))
        )
    }
  }

  val satisfiedWithEffects = patterns.filter { case (_, effects) => effects.forall(_ >= x) }

  if (satisfiedWithEffects.nonEmpty) {
    val (minCost, _) = satisfiedWithEffects.minBy { case (cost, _) => cost }
    println(minCost)
  } else {
    println(-1)
  }
}



Measured memory_bytes: 58656
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin >> S;
  vector<int> X(4);
  for(int i=0;i<4;i++){
    X.at(i)=S.at(i)-'0';
  }
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
    bitset<3> s(tmp);
    int x=X.at(0);
    for(int i=0;i<3;i++){
      if(s.test(i)){
        x+=X.at(i+1);
      }else{
        x-=X.at(i+1);
      }
    }
    if(x==7){
      for(int i=0;i<3;i++){
        cout << X.at(i);
        if(s.test(i)){
          cout << "+";
        }else{
          cout << "-";
        }
      }
      cout << X.at(3) << "=7" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000;

//main関数
int main() {
    
    //入力
    long N;
    cin>>N;
    vector<long> a(N);
    for(int i=0;i<N;i++){
        cin>>a.at(i);
    }
    
    
    //計算
    
    long ans=0;
    for(int i=0;i<N;i++){
        ans+=(a.at(i)-1);
    }
    
    //出力
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

const ll maxl = (1<<21)+5, mod = 1e9+7;
ll dp[21][maxl], mask[21];
int n;

int solve(int idx, int bitmask)
{
	if(idx == n) return (__builtin_popcount(bitmask)==n);
	
	if(dp[idx][bitmask]!=-1)return dp[idx][bitmask];
	
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(!(bitmask & (1 << i)) && ((1 << i) & mask[idx]))
			ans = (ans + solve(idx+1, bitmask | (1<<i)))%mod; 
	}
	return dp[idx][bitmask] = ans;
}

int main()
{
    ios;
	cin>>n;
	
	memset(mask, 0, sizeof(mask));
	memset(dp, -1, sizeof(dp));
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			int x;
			cin>>x;
			if(x) mask[i] |= (1<<j);
		}
		
	cout<<solve(0,0)<<endl;
	// for(int i=0;i<21;i++)
	// 	{
	// 		for(int j=0;j<maxl;j++)
	// 			cout<<dp[i][j]<<" ";
			
	// 		cout<<endl;
	// 	}
	
	return 0;
}

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

int main()
{
  	int a,b,c,cnt = 0;

 	cin >> a >> b >> c;
  
    for(int i = a;a <= b;a++){
      if(c % a == 0)
        	cnt++;
    }
  
 	cout << cnt << endl;
}


Measured memory_bytes: 3104
process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  const S = lines[1].split(" ");
  const T = lines[3].split(" ");
  const C = SinT(S, T);
  console.log(C.length);
});

function SinT(S, T) {
  const ret = [];
  T.forEach((e) => {
    S.includes(e) && ret.push(e);
  });
  return ret;
}



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

int main() {
    long long n,c;
    cin >> n >> c;
    vector<long long> x(n + 1), v(n + 1);
    for(int i = 0; i < n; i++)
    {
        cin >> x.at(i + 1) >> v.at(i + 1);
    }

    long long sum_v = 0;
    vector<long long> max_sum(n + 1);
    long long maximum = 0;
    for(int i = 1; i <= n; i++)
    {
        sum_v += v.at(i);
        maximum = max(maximum, (sum_v - x.at(i)));

        max_sum.at(i) = maximum;
    }
    long long ans = max_sum.at(n);
    sum_v = 0;
    for(int i = n; i >= 1; i--)
    {
        sum_v += v.at(i);
        ans = max(ans, (sum_v - (c - x.at(i)) * 2 + max_sum.at(i - 1)));
    }
    
    vector<long long> max_sum2(n + 1);
    sum_v = 0;
    maximum = 0;
    for(int i = n; i >= 1; i--)
    {
        sum_v += v.at(i);
        maximum = max(maximum, (sum_v - (c - x.at(i))));

        max_sum2.at(i) = maximum;
    }
    ans = max(ans, max_sum2.at(1));
    sum_v = 0;
    for(int i = 1; i < n; i++)
    {
        sum_v += v.at(i);
        ans = max(ans, (sum_v - x.at(i) * 2 + max_sum2.at(i + 1)));
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <stdio.h>
int ans[4], test[4];
int in(int n) {
	int i;
	for(i = 0; i < 4; ++ i) if(ans[i] == n) return 1;
	return 0;
}
int main() {
	int N, M;
	int i, hit, brow;
	int ten[4] = {1, 10, 100, 1000};
	for(;;) {
		scanf("%d %d", &N, &M);
		if(N == 0 && M == 0) break;
		hit = brow = 0;
		for(i = 0; i < 4; ++ i) {
			ans[i] = N / ten[i] % 10;
			test[i] = M / ten[i] % 10;
		}
		for(i = 0; i < 4; ++ i) {
			if(in(test[i])) {
				if(ans[i] == test[i]) hit ++;
				else brow ++;
			}
		}
		printf("%d %d\n", hit, brow);
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		boolean[][] F = new boolean[N][10];
		int[][] P = new int[N][11];
		
		for(int i = 0;i < N;++i)
			for(int j = 0;j < 10;++j)
				F[i][j] = sc.nextInt() == 1;
		for(int i = 0;i < N;++i)
			for(int j = 0;j < 11;++j)
				P[i][j] = sc.nextInt();
		
		int max = Integer.MIN_VALUE;
		for(int i = 1;i < 1024;++i) {
			boolean[] isOpen = new boolean[10];
			for(int j = 0;j < 10;++j)
				isOpen[j] = (i>>>j)%2 == 1;
			int[] duplicate = new int[N];
			for(int j = 0;j < N;++j)
				for(int k = 0;k < 10;++k)
					if(isOpen[k] && F[j][k])
						++duplicate[j];
			int score = 0;
			for(int j = 0;j < N;++j)
				score += P[j][duplicate[j]];
			if(score > max)
				max = score;
		}
		System.out.println(max);
		sc.close();
	}
}

Measured memory_bytes: 26064
function parseInt(x) parse(Int, x) end
parseMap(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
	n, m = parseMap(split(readline()))
	x = [Int64[] for i in 1:n]
	for i in 1:m
		a, b = parseMap(split(readline()))
		push!(x[a], b)
		push!(x[b], a)
	end
	flg = 0
	for i in 2:n-1
		if 1 in x[i] && n in x[i]
			print("POSSIBLE")
			flg = 1
			break
		end
	end
	if flg == 0
		print("IMPOSSIBLE")
	end
end

main()

Measured memory_bytes: 172432
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;



int main() {
  	long long N;
  	cin >> N;
  	vector<long long> A(N);
  	for(long long i; i<N; i++){
      cin >> A[i];
    }
  	map<long,long> uss;
  	for(long long i; i<N; i++){
    	uss[(A[i])]++;
	}
  	for(long long i; i<N; i++){
      if (uss[(A[i])]>=2){
        cout << "NO" << endl;
        return 0;
      }
    }
  	cout << "YES" << endl;
}


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

typedef long long LL;

int main() {
    LL N;
    cin >> N;
    LL sum = 0, x;
    LL s[N];
    for (LL i = 0; i < N; i++) {
        cin >> s[i];
        sum += s[i];
    }
    sort(s, s + N);
    LL i = 0;
    while (sum % 10 == 0)
    {
        if (s[i] % 10 != 0) {
            sum -= s[i];
        }
        i++;
        if (i == N)
        {
            sum = 0;
            break;
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int32_t find_len(vector<uint32_t> &nums, uint32_t start, uint32_t len) {
  int32_t end = -1;
  int32_t index = start;
  int32_t remain = len;
  while (remain > 0 && index < nums.size()) {
    remain -= nums[index];
    index++;
  }

  if (remain == 0) {
    end = index;
  }

  return end;
}
int32_t main() {
  while (true) {
    uint32_t n;
    cin >> n;

    if (n == 0) break;

    vector<uint32_t> nums;
    for (uint32_t _ = 0; _ < n; _++) {
      string str;
      cin >> str;
      nums.push_back(str.size());
    }

    for (uint32_t i = 0; i < nums.size(); i++) {
      int32_t index = find_len(nums, i, 5);
      if (index == -1) continue;
      index = find_len(nums, index, 7);
      if (index == -1) continue;
      index = find_len(nums, index, 5);
      if (index == -1) continue;
      index = find_len(nums, index, 7);
      if (index == -1) continue;
      index = find_len(nums, index, 7);
      if (index == -1) continue;
      cout << i + 1 << endl;
      break;
    }
  }

  return 0;
}

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

int main() {
    int N; cin >> N;
    int mx = -1, mn = 2020;
    for(int i = 0; i < N; ++i) {
        int x; cin >> x;
        mx = max(mx, x);
        mn = min(mn, x);
    }
    cout << (mx - mn + 1) / 2 << '\n';
    return 0;
}



Measured memory_bytes: 3100
package main

import "fmt"

func main() {
	var n, h, w, a, b, ans int
	fmt.Scan(&n, &h, &w)
	for i := 0; i < n; i++ {
		fmt.Scan(&a, &b)
		if a >= h && b >= w {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<cstdio>
int ans,w=1e9;
char o[5],lst;
int main(){
	while(w!=1){
		printf("? %d\n",w),fflush(stdout),scanf("%s",o);
		if(*o=='Y'){
			printf("? %d\n",w-1),fflush(stdout),scanf("%s",o);
			if(*o=='N'||lst=='N')break;
		}
		lst=*o;
		w/=10;
	}
	if(w==1e9){printf("! %d\n",w),fflush(stdout);return 0;}
	if(w==1){
		for(int i=1;i<10;++i){
			printf("? %d0\n",i),fflush(stdout),scanf("%s",o);
			if(*o=='Y'){printf("! %d\n",i),fflush(stdout);return 0;}
		}
	}else{
		for(int i=1;i<10;++i){
			printf("? %d\n",i),fflush(stdout),scanf("%s",o);
			if(*o=='N')break;
			ans=i*w;
		}
		for(w/=10;w;w/=10){
			int l=0,r=9,s=0;
			while(l<=r){
				const int mid=l+r>>1;
				printf("? %lld\n",(ans+mid*w+w)*10LL-1);
				fflush(stdout),scanf("%s",o);
				if(*o=='N')l=mid+1;else r=(s=mid)-1;
			}
			ans+=s*w;
		}
	}
	printf("! %d\n",ans),fflush(stdout);
	return 0;
}

Measured memory_bytes: 504