akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

// #define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll mod = (1000000007LL);
inline ll Mod(ll a, ll b){return (a%b);}
inline ll poww(ll a, ll b){ll res = 1;while (b > 0){if(b & 1) res = (res * a)%mod;a = (a * a)%mod;b >>= 1;}return res;}
ll gcd (ll a, ll b) { while (b) { a %= b,swap(a, b);}return a;}
void read(vector<int> &w, int n){w.resize(n);for(int i = 0; i < n; i++) cin>>w[i];}
void print(vector<int> &w){for(int i =0; i < sz(w); i++){if(i == sz(w) - 1) cout<<w[i]<<"\n";else cout<<w[i]<<" ";}}
int prodmod(vector<int> w);
int summod(vector<int> w);
///CUIDADO COM MAXN
#define N 300050

int n, m, q, k, v[N], ans;
pii w[N];
string s;

int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n;
	for(int i=1;i<=500;i++){
		if(i*1000 >= n){
			cout<<i*1000-n<<"\n";
			return 0;
		}
	}
}
/*
    CUIDADO COM MAXN, MOD, OVERFLOW 
    >Colocar (>DEFINE INT LONG LONG<) no inicio do template
    >mod = (1e9 + 7), por padrao (NAO ESQUECER DE ALTERAR)
    >NAO ESQUECER DEFINE INT LONG LONG
    > N = 1 ? 
*/
int summod(vector<int> w){int curr=0;for(int i=0;i<sz(w); i++){curr = (curr+w[i])%mod;if(curr<0)curr+=mod;}return curr;}
int prodmod(vector<int> w){int curr = 1;
for(int i = 0; i < sz(w); i++){if(w[i] >= mod) w[i] %= mod;curr = (curr * w[i]) % mod;if(curr < 0) curr += mod;}return curr;}

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

namespace abc127
{
    class C
    {
        static void Main(string[] args)
        {
            var input = Input.IntArray();
            var N = input[0];
            var M = input[1];

            // ゲート
            int L, R, maxL = 1, minR = N;
            for (int i = 0; i < M; i++)
            {
                input = Input.IntArray();
                L = input[0];
                R = input[1];

                if (maxL < L) {
                    maxL = L;
                }
                if (R < minR) {
                    minR = R;
                }
            }

            var res = minR - maxL + 1;
            if (res < 0) {
                res = 0;
            }

            Console.WriteLine(res);

        }

        internal class LR
        {
            public int L;
            public int R;
        }

        /** Input Class */
        internal static class Input
        {
            /** input int */
            public static int Int() => int.Parse(Console.ReadLine());

            /** input str */
            public static string Str() => Console.ReadLine();

            /** input array of int */
            public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            /** input array of string */
            public static string[] StrArray() => Input.Str().Split(' ');

            /** input array of char */
            public static char[] charArray() => Input.Str().ToCharArray();
        }
    }
}


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

object Main {
  def main(args: Array[String]): Unit = {
    val numbers = readLine().map(_.toString.toInt).toList

    var ans: String = numbers.head.toString

    def go(num: List[Int], sumValue: Int, res: String): Boolean = {
      if (num.isEmpty) {
        if (sumValue == 7) {
          ans += res + "=7"
          true
        }
        else false
      } else {
        go(num.tail, sumValue + num.head, Array(res, "+", num.head.toString).mkString("")) ||
          go(num.tail, sumValue - num.head, Array(res, "-", num.head.toString).mkString(""))
      }
    }

    go(numbers.tail, numbers.head, "")
    println(ans)
  }
}


Measured memory_bytes: 25416
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<bool> ac(N, false);
    ll p_i;
    vector<ll> penalty_cnt(N, 0);
    string s_i;
    for (int i = 0; i < M; i++) {
        cin >> p_i >> s_i;
        p_i--;
        if (s_i[0] == 'A') {
            ac[p_i] = true;
        } else {
            if (ac[p_i]) {
                continue; // no penalty
            } else {
                penalty_cnt[p_i]++;
            }
        }
    }
    ll ac_cnt = 0;
    ll p_cnt = 0;
    for (int i = 0; i < N; i++) {
        if (ac[i]) {
            ac_cnt++;
            p_cnt += penalty_cnt[i];
        }
    }
    cout << ac_cnt << " " << p_cnt << endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

typedef vector<long long> V;
typedef vector<V> M;

long long MOD;

V mul(M m, V v) {
  V res(m.size(), 0);
  rep (i, m.size()) rep (j, v.size()) {
    res[i] += m[i][j] * v[j];
    res[i] %= MOD;
  }
  return res;
}

M mul(const M &a, const M &b) {
  M res(a.size(), V(b[0].size(), 0));
  rep (i, a.size()) rep (j, b[0].size()) rep (k, b.size()) {
    res[i][j] += a[i][k] * b[k][j];
    res[i][j] %= MOD;
  }
  return res;
}

M pow(const M &m, long long k) {
  if (k == 0) {
    M res(m.size(), V(m.size(), 0));
    rep (i, m.size()) res[i][i] = 1;
    return res;
  }
  M a = pow(m, k / 2);
  a = mul(a, a);
  if (k % 2 == 1) a = mul(a, m);
  return a;
}

int main() {
  while (true) {
    int n, a, b, c, t;
    cin >> n >> MOD >> a >> b >> c >> t;
    if (n == 0) break;
    M m(n, V(n, 0));
    rep (i, n - 1) m[i + 1][i] = a;
    rep (i, n) m[i][i] = b;
    rep (i, n - 1) m[i][i + 1] = c;
    m = pow(m, t);
    V v(n);
    rep (i, n) cin >> v[i];
    v = mul(m, v);
    rep (i, v.size()) cout << v[i] << (i == (int)v.size() - 1 ? "\n" : " ");
  }
}

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

struct Edge {
  set<int> edge;
  // bool is_visited = false;
};

bool is_visited[51];

void dfs(int root, const vector<Edge>& g) {
  is_visited[root] = true;
  for (auto i : g[root].edge) {
    if (is_visited[i]) continue;
    dfs(i, g);
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<P> edges;
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    edges.push_back(make_pair(a - 1, b - 1));
  }
  auto check = [=]() {
    bool res = true;
    for (int i = 0; i < N; ++i) res &= is_visited[i];
    return !res;
  };
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    vector<Edge> graph(N);
    for (int i = 0; i < N; ++i) is_visited[i] = false;
    for (int j = 0; j < M; ++j) {
      if (i == j) continue;
      int a = edges[j].first;
      int b = edges[j].second;
      graph[a].edge.insert(b);
      graph[b].edge.insert(a);
    }
    dfs(edges[(i + 1) % M].first, graph);
    if (check()) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))

ansList = []
ans = 0
for i in range(n-1):
  if h[i] >= h[i+1]:
    ansList.append(h[i])
    ans = max(len(ansList),ans)
  else:
    ansList = []
print(ans)

Measured memory_bytes: 15020
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=stdIn.nextInt();
		int m=stdIn.nextInt();
		int l=stdIn.nextInt();
		int a[][]=new int[n][m];
		int b[][]=new int[m][l];
		int i,j,k;
		for(i=0;i<n;i++)
			for(j=0;j<m;j++)
				a[i][j]=stdIn.nextInt();
		for(i=0;i<m;i++)
			for(j=0;j<l;j++)
				b[i][j]=stdIn.nextInt();
		for(i=0;i<n;i++){
			for(j=0;j<l;j++){
				long c=0;
				if(j>0)
					System.out.print(" ");
				for(k=0;k<m;k++)
					c+=a[i][k]*b[k][j];
				System.out.print(c);
			}
			System.out.println("");
		}
		
	}
}

Measured memory_bytes: 53360
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string s = Console.ReadLine();
		int[]B = new int[N];
		int[,]A = new int[N,N];
		string aaa = "abcdefghijklmnopqrstuvwxyz";
		for(var i=0;i<N;i++){
			B[i] = aaa.IndexOf(s.Substring(i,1));
		}
		for(var i=0;i<N;i++){
			for(var j=i+1;j<N;j++){
				if(B[i]==B[j]){
					A[i,j] = 1;
				}
			}
		}
		int ans = 0;
		int[,]X = new int[N,N*2+1];
		for(var i=0;i<N-1-ans*2;i++){
			for(var j=i+ans+1;j<N-ans;j++){
				if(X[i,j-i+N]==1){
					continue;
				}
				int a1 = Math.Min(j-i,N-j);
				for(var k=0;k<a1;k++){
					if(A[i+k,j+k]==1){
						ans = Math.Max(ans,k+1);
					} else {
						for(var l=k;l>=1;l--){
							X[i+l,j-i+N] = 1;
                        }
						break;
                    }
				}
			}
		}
		Console.WriteLine(ans);
	}
}


Measured memory_bytes: 305624
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
const ll MOD=1e9+7;
ll dp[3000][3000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    string s;
    cin>>N>>s;
    dp[0][0]=1;
    rep(i,1,N){
        rep(j,0,i+1){
            if(s[i-1]=='<'&&j>=1) {
                dp[i][j]+=dp[i][j-1]+dp[i-1][j-1];
                dp[i][j]%=MOD;
            }
            if(s[i-1]=='>'){
                if(j>=1) dp[i][j]+=dp[i][j-1]-dp[i-1][j-1];
                dp[i][j]+=dp[i-1][i-1];
                dp[i][j]=(dp[i][j]%MOD+MOD)%MOD;
            }
        }
    }
    cout <<dp[N-1][N-1]<<"\n";
}

Measured memory_bytes: 68864
#include<iostream>
using namespace std;
int main()
{
    int n,m,i,a[100],s=0,j=0;
    double min;
    cin >> n >> m;
    for(i=0;i<n;i++){
        cin >> a[i];
        s+=a[i];
    }
    min=s/(4.0*m);
    for(i=0;i<n;i++){
        if(a[i]>=min)j++;
        if(j==m){
    cout << "Yes";
    return 0;
        }
    }
    cout << "No";
    return 0;
}

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

int main() {
  int n; cin >> n;
  vector<long long> l(max(2, n + 1));
  l.at(0) = 2;
  l.at(1) = 1;
  for (int i = 2; i <= n; i++) {
    l.at(i) = l.at(i - 2) + l.at(i - 1);
  }
  cout << l.at(n) << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let n: i32 = read(&mut s).unwrap();
    let mut counter: i32 = 0;

    let mut matrix: [[i32; 9]; 9] = [[0; 9]; 9];
    if n < 10 {
        println!("{}", n);
        return;
    }

    for i in 1..n + 1 {
        let ii = i.to_string();
        let ilen = ii.len() - 1;

        let first: usize = ii.chars().nth(0).unwrap() as usize - 48;
        let last: usize = ii.chars().nth(ilen).unwrap() as usize - 48;

        if last == 0 {
            continue;
        }
        matrix[first - 1][last - 1] += 1;
    }

    //println!("{:?}", matrix);
    for i in 0..9 {
        for j in 0..9 {
            if i == j {
                counter += matrix[i][j] * matrix[j][i];
            } else if matrix[i][j] > 0 && matrix[j][i] > 0 {
                counter += matrix[i][j] * matrix[j][i];
            }
        }
    }
    println!("{}", counter);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int n,m;
    cin>>n>>m;
    ll by=pow(2,m);
    cout<<(1900*m+100*(n-m))*by<<endl;

//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int a,b;
    cin>a>b;
    if(a>12)cout<b<endl;
    else if(a>5)cout<b/2<endl;
    else cout<0<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;



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

  long long a;
  map<long long, long long> a_frq_dict;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    if(a_frq_dict.find(a) == a_frq_dict.end()){
      a_frq_dict[a] = 1;
    }else{
      a_frq_dict[a]++;
    }
  }

  int ans = 0;
  for(auto a_frq: a_frq_dict){
    if(a_frq.first < a_frq.second) {
      ans += a_frq.second - a_frq.first;
    }else if(a_frq.first > a_frq.second){
      ans += a_frq.second;
    }
  }

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 6272
use std::io::Read;
use std::str::{self, FromStr};

/// readerをラップして、いい感じにトークンを読みます。
pub struct Scanner<R: Read>(R);

impl<R: Read> Scanner<R> {
    /// readerからScannerを作ります。
    /// # Examples
    ///
    /// ```
    /// use tkio::Scanner;
    ///
    /// let stdin = std::io::stdin();
    /// let mut sc = Scanner::new(stdin.lock());
    /// ```
    pub fn new(reader: R) -> Self {
        Self(reader)
    }

    /// ひとつ読みます。
    ///
    /// # Panics
    /// パースできなかったらお手上げです。
    ///
    /// # Examples
    ///
    /// ```
    /// use tkio::Scanner;
    ///
    /// let input = "4 3";
    /// let mut sc = Scanner::new(input.as_bytes());
    ///
    /// let (n, m): (i32, i32) = (sc.read(), sc.read());
    /// assert_eq!((n, m), (4, 3));
    /// ```
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();

        unsafe { str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }

    /// n個読んでVecで返します。
    ///
    /// # Examples
    ///
    /// ```
    /// use tkio::Scanner;
    ///
    /// let input = "\
    /// 5
    /// 1 2 3 4 5
    /// ";
    /// let mut sc = Scanner::new(input.as_bytes());
    ///
    /// let n: usize = sc.read();
    /// assert_eq!(n, 5);
    ///
    /// let v: Vec<i32> = sc.vec(n);
    /// assert_eq!(v, vec![1, 2, 3, 4, 5]);
    /// ```
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    /// Stringをひとつ読んでVec\<char\>で返します。
    ///
    /// # Examples
    ///
    /// ```
    /// use tkio::Scanner;
    ///
    /// let input = ".#..#";
    /// let mut sc = Scanner::new(input.as_bytes());
    ///
    /// let v = sc.chars();
    /// assert_eq!(v, vec!['.', '#', '.', '.', '#']);
    /// ```
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

use std::io::{self, Write};

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());

    solve(&mut sc, &mut out);

    out.flush().ok().unwrap();
}

fn solve(sc: &mut Scanner<io::StdinLock>, out: &mut io::BufWriter<io::StdoutLock>) {
    let (N, A, B): (u32, u32, u32) = (sc.read(), sc.read(), sc.read());

    let ans: u32 = (1..=N)
        .filter(|&i| {
            let mut i = i;
            let mut sum = 0;
            while i > 0 {
                sum += i % 10;
                i /= 10;
            }
            sum >= A && sum <= B
        })
        .sum();

    println!("{}", ans);
}


Measured memory_bytes: 2112
def find(base, indexes):
    n = len(indexes)
    ng = -1
    ok = n

    while ok - ng > 1:
        mid = (ok + ng) // 2
        if indexes[mid] > base:
            ok = mid
        else:
            ng = mid

    return indexes[0] if ok == n else indexes[ok]


s = input()
t = input()

s_set = set(s)
t_set = set(t)

if t_set.issubset(s_set) is False:
    print(-1)
    exit(0)

s_indxes = [[] for _ in range(26)]

for i in range(len(s)):
    c = s[i]
    idx = ord(c) - ord("a")
    s_indxes[idx].append(i)

base = -1
loop = 0
for i in range(len(t)):
    c = t[i]
    idx = ord(c) - ord("a")
    n_base = find(base, s_indxes[idx])

    if n_base <= base:
        loop += 1

    base = n_base

print(loop * len(s) + base + 1)


Measured memory_bytes: 13436
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a*b==0:
    return a if b==0 else b
  else:
    while b:
      a,b=b,a%b
  return a

B=[0]*(n+5)
C=[0]*(n+5)

for i in range(n):
  B[i+1]=gcd(B[i],A[i])
  C[i+1]=gcd(C[i],A[n-i-1])
po=0
for i in range(n):
  po=max(po,gcd(B[i],C[n-1-i]))
print(po)

Measured memory_bytes: 14400
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
typedef long long ll;
using namespace std;

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

    ll s[8][n];
    fill(s[0], s[8], 0);
    for (int i = 0; i < n; i++) {
        ll x, y, z;
        cin >> x >> y >> z;

        for (int j = 0 ; j < 8; j++) {
            if (j >= 4) s[j][i] -= x;
            else s[j][i] += x;

            if (j%4 == 2 || j%4 == 3) s[j][i] -= y;
            else s[j][i] += y;

            if (j%2 == 1) s[j][i] -= z;
            else s[j][i] += z;
        }
    }

    ll ans = 0LL;
    for (int i = 0; i < 8; i++) {
        sort(s[i], s[i]+n, greater<ll>());
        ll sum = 0LL;
        for (int j = 0; j < m; j++) {
            sum += s[i][j];
        }
        ans = max(ans, sum);
    }

    cout << ans << endl;
    return 0;
}

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

int main(){
    int x,n;
    int m = 1000000;
    int ans = 0;
    cin >> x >> n;
    vector<int> a(n);
    for(int i = 0;i<n;i++){
        cin >> a.at(i);
    }
    bool aru = false;
    for(int i = 0;i<=101;i++){
        aru = false;
        for(int j:a){
            if(i == j) aru = true;
        }
        if(!aru){
            if(m > (i-x)*(i-x)){
                ans = i;
                m = (i-x)*(i-x);
            }

        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>

#define S_HOUR (60 * 60)
#define S_MINUTE (60)

int main(void)
{
    int s_input;
    std::cin >> s_input;

    std::cout << s_input / S_HOUR << ":"
        << (s_input % S_HOUR) / S_MINUTE << ":"
        << s_input % S_MINUTE
        << std::endl;
    
    return 0;
}



Measured memory_bytes: 3116
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;

ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	ll y[302][302] = {};
	ll y2[302][302] = {};
//bool comp(
//
//	st pll &a, const pll &b) {
//	return a.first < b.first;
//}
//std::vector<int> enum_div(int n)//nの約数を列挙
//{
//	std::vector<int> ret;
//	for (int i = 1; i*i <= n; ++i)
//	{
//		if (n%i == 0)
//		{
//			ret.push_back(i);
//			if (i != 1 && i*i != n)
//			{
//				ret.push_back(n / i);
//			}
//		}
//	}
//	return ret;
//}
ll kansuu(int num)
{
	ll x[100] = {};
	ll answer = 0;
	ll b;
	ll tmp = 0;
	b = num;
	for (int j = 0; j < 15; j++)
	{
		x[j] = 0;
	}
	for (int j = 1; j <= a; j++)
	{
		if (b % 2 == 1)
		{
			x[j] = 1;
			tmp++;
		}
		b /= 2;
	}
	for (int i = 1; i <= a; i++)
	{
		if (x[i]==1)
		{
			for (int k = 1; k <= y[i][0]; k++)
			{
				if (x[y[i][k]]==y2[i][k])
				{

				}
				else
				{
					return 0;
				}
			}
		}
	}
	//for (int j = 0; j < a; j++)
	//{
	//	cout << x[j] << endl;
	//}
	//cout << endl;


	return tmp;
}

template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}
int main()
{
	priority_queue<int> q;
	string s = {};
	ll x[100005] = {};
	cin >> a;
	for (int i = 1; i <= a; i++)
	{
		cin >> y[i][0];
		for (int j = 1; j <= y[i][0]; j++)
		{
			cin >> y[i][j];
			cin >> y2[i][j];
		}

	}

	for (int i = 0; i < pow(2, a); i++)
	{
		ans=max(kansuu(i),ans);
	}




	cout << ans << endl;

	//cout<<factorial<10><<endl;

	//cin >> a >> b;
	//for (int i = 0; i < a; i++)
	//{
	//	cin >> s[i];
	//	if (s[i] >= b)
	//	{
	//		ans++;
	//	}
	//}

	//cout << ans << endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}


Measured memory_bytes: 384
from math import factorial
from itertools import combinations
N = int(input())
LIM = factorial(N)
pls = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
ans = 0
for x, y, z in combinations(pls, 3):
  if LIM%((x**4)*(y**4)*(z**2))==0:
    ans += 1
  if LIM%((y**4)*(z**4)*(x**2))==0:
    ans += 1
  if LIM%((z**4)*(x**4)*(y**2))==0:
    ans += 1
for x, y in combinations(pls,2):
  if LIM%((x**14)*(y**4))==0:
    ans += 1
  if LIM%((y**14)*(x**4))==0:
    ans += 1
  if LIM%((x**24)*(y**2))==0:
    ans += 1
  if LIM%((y**24)*(x**2))==0:
    ans += 1
for x in pls:
  if LIM%(x**74)==0:
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

struct edge {
  int to;
  ll cost;
  edge(int t, ll c): to(t), cost(c) {};
};

using P = pair<ll, int>;

vector<ll> d;
vector<int> par;
void dijkstra(int s, int N, vector<vector<edge>>& G) {
  priority_queue<P, vector<P>, greater<P>> que;
  d = vector<ll>(N, longinf);
  par = vector<int>(N, -1);
  d[s] = 0;
  que.push(P(0, s));

  while(!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;

    for(int i=0; i<(int)G[v].size(); i++) {
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
        par[e.to] = v;
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  int ch, dh, cw, dw;
  cin >> ch >> cw >> dh >> dw;
  ch--; dh--; cw--; dw--;
  vector<string> S(h); rep(i, h) cin >> S[i];
  vector<vector<edge>> G(h*w);
  rep(i, h) rep(j, w) {
    if(S[i][j] == '.') {
      for(int di=-2; di<=2; di++) {
        for(int dj=-2; dj<=2; dj++) {
          if(di==0 && dj==0) continue;
          int nx = i+di, ny = j+dj;
          if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
          if(S[nx][ny] == '#') continue;
          if(abs(di)+abs(dj)==1) {
            G[i*w+j].push_back({nx*w+ny, 0});
          } else {
            G[i*w+j].push_back({nx*w+ny, 1});
          }
        }
      }
    }
  }
  dijkstra(ch*w+cw, h*w, G);
  cout << (d[dh*w+dw]==longinf ? -1LL : d[dh*w+dw]) << endk;
  return 0;
}


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

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] cost=new int[N];
		for(int i=0; i<N; i++) {
			cost[i]=sc.nextInt();
		}
		Arrays.sort(cost);
		int price=0;
		for(int i=0; i<N; i++) {
			if(i==N-1) {
				price+=(cost[i]/2);
			}
			else {
				price+=cost[i];
			}
		}
		System.out.println(price);
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
  
#define MP make_pair
#define PB push_back
#define MAX_N 1100000
#define SIZE 1200
#define X first
#define Y second
  
const int STX = 600, STY = 600;

typedef pair<int, int> Pii;
typedef pair<int, Pii> P;
  
int id[SIZE][SIZE];
bool is_prime[MAX_N+1];
vector<Pii> coord;

void Sieve() {
  fill(is_prime, is_prime+MAX_N+1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i=2; i*i<=MAX_N; i++)
    if(is_prime[i])
      for(int j=i*i; j<=MAX_N; j+=i)
	is_prime[j] = false;
}

void MakeMap() {
  int x = STX, y = STY;
  int cnt = 0;
  
  coord.PB(MP(0, 0)); // no use
  cnt ++;
  coord.PB(MP(x, y)); // cnt = 1
  
  fill(id[0], id[0]+SIZE*SIZE+1, -1);
  
  const int dx[] = {0,-1,0,1};
  const int dy[] = {-1,0,1,0};
  
  int a = 0; x = STX+1; y = STY+1;
  while(cnt <= MAX_N) {
    a += 2;
    for(int turn=0; turn<4; turn++) {
      for(int i=0; i<a; i++) {
	x += dx[turn], y += dy[turn];
	coord.PB(MP(x, y));
	id[y][x] = ++ cnt;
      }
    }
    x++, y++;
  }
}

int dp[MAX_N+1];

int main() {
  
  Sieve();
  MakeMap();
  
  int m, n;

  while(cin >> m >> n && (m|n)) {
    
    fill(dp, dp+MAX_N+1, -1);
    dp[n] = is_prime[n];
    Pii ans(dp[n], n);
    
    queue<P> que;
    que.push(P(dp[n], coord[n]));
    while(!que.empty()) {
      P now = que.front(); que.pop();
      int tmpid = id[now.second.Y][now.second.X];
      if(now.first < dp[tmpid]) continue;
      
      int noid = id[now.second.Y][now.second.X];
      
      for(int i=-1; i<=1; i++) {
	Pii nex = MP(now.second.X+i, now.second.Y+1);
	if(nex.X < 0 || SIZE <= nex.X || nex.Y < 0 || SIZE <= nex.Y) continue;
	int neid = id[nex.Y][nex.X];
	if(neid <= m) {
	  if(dp[neid] < dp[noid] + is_prime[neid]) {
	    dp[neid] = dp[noid] + is_prime[neid];
	    if(is_prime[neid]) ans = max(ans, MP(dp[neid], neid));
	    que.push(P(dp[neid], nex));
	  }
	}
      }

    }
    
    if(ans.first == 0) cout << "0 0" << endl;
    else cout << ans.first << ' ' << ans.second << endl;
  }
  return 0;
}

Measured memory_bytes: 25844
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int N, M; cin >> N >> M;
    vector<int> H(N+1); for(int i=1; i<=N; i++) cin >> H[i];

    vector<vector<int> > T(N+1);
    vector<bool> can(N+1);
    for(int i=1; i<=N; i++) can[i] = true;
    
    REP(i, M){
        int A, B; cin >> A >> B;
        T[A].push_back(B);
        T[B].push_back(A);
    }

    for(int i=1; i<=N; i++){
        for(int j=0; j<T[i].size(); j++){
            if( H[i] <= H[T[i][j]] ) can[i] = false;
        }
    }

    int cnt=0;
    for(int i=1; i<=N; i++){
        if(can[i] == true) cnt++;
    }

    cout << cnt << endl;

}

Measured memory_bytes: 11980
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////





int main() {

	char c;
	cin >> c;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') { cout << "vowel"; }
	else { cout << "consonant"; }


	system("PAUSE");
}

Measured memory_bytes: 504
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    return buf
}

fn main() {
  let line = gets();
  let n = line.trim().parse::<usize>().unwrap();
  let mut a = vec![vec![0; n]; n];
  for i in 0..n {
    let line = gets();
    let x: Vec<i64> = line.trim().split_whitespace().map(|n| n.parse::<i64>().unwrap()).collect();
    for j in 0..n {
      a[i][j] = x[j];
    }
  }

  for k in 0..n {
    for i in 0..n {
      for j in 0..n {
        if a[i][k] + a[k][j] < a[i][j] {
          println!("-1");
          return;
        }
      }
    }
  }

  let mut flag = vec![vec![1; n]; n];
  for k in 0..n {
    for i in 0..n {
      for j in 0..n {
        if (i == j) || (j == k) || (k == i) {
          continue;
        }
        if a[i][k] + a[k][j] == a[i][j] {
          flag[i][j] = 0
        }
      }
    }
  }

  let mut ans = 0;
  for i in 0..n {
    for j in (i+1)..n {
      ans += a[i][j] * flag[i][j]
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 6396
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR2(i, s, n) for (int i = (s); i < (int)(n); i++)
char maze[110][110];
int dp[110][110];

int main() {
  int H, W;
  cin >> H >> W;
  FOR(i, H) FOR(j, W) cin >> maze[i][j];

  FOR(i, H) FOR(j, W) dp[i][j] = 10000;

  if (maze[0][0] == '#')
    dp[0][0] = 1;
  else
    dp[0][0] = 0;

  FOR(i, H) FOR(j, W) {
    if (i - 1 >= 0) {
      if (maze[i][j] == '#' && maze[i - 1][j] == '.')
        dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
      else
        dp[i][j] = min(dp[i][j], dp[i - 1][j]);
    }
    if (j - 1 >= 0) {
      if (maze[i][j] == '#' && maze[i][j - 1] == '.')
        dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
      else
        dp[i][j] = min(dp[i][j], dp[i][j - 1]);
    }
  }

  /*
  FOR(i, H) {
    FOR(j, W) { cout << dp[i][j] << ' '; }
    cout << endl;
  }
  */

  cout << dp[H - 1][W - 1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int N, A, B;
int main(int argc, char const *argv[]) {
  scanf("%d\n", &N);
  if(N==2){
    scanf("%d\n", &A);
    scanf("%d\n", &B);
    printf("%d\n", A+B);
  } else{
    printf("Hello World\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, l, r, z = 0;
    cin >> n;
    while (n--) cin >> l >> r, z += r - l + 1;
    cout << z;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define LL long long;
#define ULL unsigned long long;
using namespace std;

string str;

int main() {
	cin>>str;
	reverse(str.begin(), str.end());
	cout<<(regex_replace(str, regex("maerd|remaerd|esare|resare"), "").empty()?"YES":"NO")<<endl;
}


Measured memory_bytes: 512
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final int result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int s = sc.nextInt();

        sc.close();
        return new TestCase(s);
    }

    public static int process(TestCase testCase) {
        int s = testCase.s;
        Set<Integer> appeared = new HashSet<>();
        int count = 1;

        while (!appeared.contains(s)) {
            count++;
            appeared.add(s);

            boolean isOdd = (s % 2) != 0;
            if (isOdd) {
                s = handleOdd(s);
            } else {
                s = handleEven(s);
            }
        }
        return count;
    }

    private static int handleOdd(int s) {
        return 3 * s + 1;
    }

    private static int handleEven(int s) {
        return s / 2;
    }

    private static void output(int result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int s;

        public TestCase(int s) {
            this.s = s;
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> data(N);
  for (int i = 0; i < N; i++) cin >> data.at(i);
  
  int sum = 0;
  for (int i = 0; i < N-1; i++) {
    for (int k = i+1; k < N; k++) {
      sum += data.at(i)*data.at(k);
    }
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		string s = Console.ReadLine();	
      	string ans = "";
      	
      	if(s == "AAA" || s == "BBB"){
          ans = "No";
        }
      	else{
          ans = "Yes";
        }
      	
		Console.WriteLine(ans);
	}
}

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


ll b[200010],w[200010];


int main(){
    ll N;cin>>N;
    string s;cin>>s;
    rep(i,1,N){
        if(s.at(i-1)=='#')b[i]++;
        b[i]+=b[i-1];
    }
    for(int i=N-2;i>=0;i--){
        if(s.at(i+1)=='.')w[i]++;
        w[i]+=w[i+1];
    }
    ll MIN=99999999999999;
    rep(i,0,N){
        MIN=min(MIN,b[i]+w[i]);
    }
    cout<<MIN<<endl;
}







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

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
typedef double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265


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

    int n;
    cin >> n;
    int v;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> v;
        ans += (v - 1);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
 
using namespace std;
 
int main(){
        int N,K,now;
        double c=1,d=0;
        cin>>N>>K;
        for(int i=1;i<=N;i++){
                now=i;
                while(now<K){
                        now*=2;
                        c/=2;
                }
                d+=c/N;
                c=1;
        }
        cout<<setprecision(12)<<d;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	s := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&s[i])
	}

	dx := []int{1, -1, 0, 0}
	dy := []int{0, 0, 1, -1}
	success := true
	for y := 0; success && y < h; y++ {
		for x := 0; success && x < w; x++ {
			if s[y][x] == '#' {
				tmp := false
				for i := 0; i < 4; i++ {
					nx := x + dx[i]
					ny := y + dy[i]
					if 0 <= nx && nx < w && 0 <= ny && ny < h && s[ny][nx] == '#' {
						tmp = true
					}
				}
				success = tmp
			}
		}
	}

	if success {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n;
int a[N];
ll f[N];
int ans;
int mx;
ll calc (ll a, ll b, ll c) {
    if (a % 2 == 0) return 0;
    return b * c;
}
int main () {
	ll a, b, c;
	cin >> a >> b >> c;
	cout << min(calc(a, b, c), min(calc(b, a, c), calc(c, a, b)));
	return Accepted;
}

// Coded By OB

Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int zt[8010],ztx[8010],zty[8010];
int n,x,y,nx,ny,l,sx,sy;
string s;
int main()
{
	cin>>s;
	l=s.size();
	
	for(int i=0;i<l;i++)
	if(s[i]=='T')n++;
	else zt[n]++;
	
	for(int i=1;i<=n;i++)
	if(i%2)zty[ny++]=zt[i];
	else ztx[nx++]=zt[i];
	
	cin>>x>>y;
	sort(ztx,ztx+nx);
	sort(zty,zty+ny);
	sx=zt[0];
	for(int i=nx-1;i>=0;i--)
	//for(int i=0;i<nx;i++)
	if(sx>=x)sx-=ztx[i];
	else sx+=ztx[i];
	
	for(int i=ny-1;i>=0;i--)
	//for(int i=0;i<ny;i++)
	if(sy>=y)sy-=zty[i];
	else sy+=zty[i];
	//cout<<sx<<sy;
	if(x==sx&&y==sy)
	cout<<"Yes";
	else cout<<"No";
	return 0;
} 

Measured memory_bytes: 256
from itertools import accumulate
N, W = map(int, input().split())
Item = [[] for i in range(4)]
for i in range(N):
    wi, vi = map(int, input().split())
    if i == 0:
        Item[0].append(vi)
        w_base = wi
    else:
        Item[wi - w_base].append(vi)

w0, w1, w2, w3 = Item
w0 = [0] + list(accumulate(sorted(w0, reverse=True)))
w1 = [0] + list(accumulate(sorted(w1, reverse=True)))
w2 = [0] + list(accumulate(sorted(w2, reverse=True)))
w3 = [0] + list(accumulate(sorted(w3, reverse=True)))

ans = 0
for i in range(len(w0)):
    for j in range(len(w1)):
        for k in range(len(w2)):
            tmp_weight = w_base * i + (w_base + 1) * j + (w_base + 2) * k
            if tmp_weight > W:
                continue
            tmp_ans = w0[i] + w1[j] + w2[k] + w3[min((W - tmp_weight) // (w_base + 3), len(w3) - 1)]
            ans = max(ans, tmp_ans)

print(ans)


Measured memory_bytes: 40560
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <tuple>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P; 
typedef tuple<ll,ll,ll> T;

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> v(N);
	for(int i=0;i<M;i++){
		ll a,b;
		cin >> a >> b;
		v[a-1]++;
		v[b-1]++;
	}
	bool ok=true;
	for(int i=0;i<N;i++){
		if(v[i]%2!=0){
			ok=false;
		}
	}
	if(ok)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	int a;
  	cin>>a;
  	
  	for(int i=a;;i++){
      	bool flag=true;
    	for(int j=2;j*j<=i;j++){
        	if(i%j==0) flag=false;
        }
      if(flag){
      	cout<<i<<endl;
        break;
      }
    }
}

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

int main(int argc, char const *argv[])
{
	char A[100],B[100],C[100],base[100];
	int N;
	int i,j;
	int change_num=0;
	int num=0;
	scanf("%d%s%s%s",&N,A,B,C);

	for(i=0;i<N;i++)
	{
		for(j=0;j<2;j++)
		{
			if(A[i]==B[i]||A[i]==C[i])
			{
				base[i]=A[i];
			}
			else if(B[i]==C[i])
			{
				base[i]=B[i];
			}
			else
			{
				base[i]=A[i];
			}
		}
	}
	for(i=0;i<N;i++)
	{
		if(A[i]!=base[i])
		{
			change_num++;
		}
		if(B[i]!=base[i])
		{
			change_num++;
		}
		if(C[i]!=base[i])
		{
			change_num++;
		}
	}
	printf("%d\n",change_num);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0;i < N;i++) cin >> vec.at(i);
int M;
cin >> M;
vector<pair<int,int>> pa(M);

for (int i = 0;i < M;i++) cin >> pa.at(i).first >> pa.at(i).second;

for (int i = 0;i < M;i++) {
    int ans = 0;
    for (int j = 0;j < N;j++) {
        if (j+1 == pa.at(i).first) {
            ans += pa.at(i).second;
        }
        else {
            ans += vec.at(j);
        }
    }
    cout << ans << endl;
}


return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h,w;
	cin>>h>>w;
	vector<vector<char>> a(h,vector<char>(w));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	vector<vector<int>> nways(h,vector<int>(w));
	nways[0][0]=1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i==j&&i==0)continue;
			int d1=(i-1>=0&&(a[i-1][j]!='#'))?nways[i-1][j]:0;
			int d2=(j-1>=0&&(a[i][j-1]!='#'))?nways[i][j-1]:0;
			nways[i][j]=add(d1,d2);
		}
	}
	cout<<nways[h-1][w-1]<<endl;
}


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

struct edge{
	int a, b, w;
	edge(int a, int b, int w): a(a), b(b), w(w) {}
	bool operator<(const edge &e) const{	return w < e.w;	}
};

int rank[101], par[101];

int init(int n){
	for(int i = 0; i <= n; ++i){
		rank[i] = 0;
		par[i] = i;
	}
}

int find(int x){
	return x != par[x] ? par[x] = find(par[x]) : x;
}

bool unite(int x, int y){
	x = find(x);
	y = find(y);
	if( x == y ) return false;
	
	if( rank[x] < rank[y] ){
		par[x] = y;
	}
	else{
		par[y] = x;
		if( rank[x] == rank[y] ) ++rank[x];
	}

	return true;
}

int main(){
	int n, m, a, b, w;
	int INF = 1e9;

	while( scanf("%d%d", &n, &m), n != 0 ){
		vector<edge> e;
		e.reserve(m);
		
		for(int i = 0; i < m; ++i){
			scanf("%d%d%d", &a, &b, &w);
			e.push_back( edge(a, b, w) );
		}
		sort(e.begin(), e.end());

		int ans = INF;
		for(int i = 0; i < m; ++i){
			init(n);
			int trees = n;

			for(int j = i; j < m; ++j){
				if( unite(e[j].a, e[j].b) ){
					if( --trees == 1 ){
						ans = min(ans, e[j].w - e[i].w);
					}
				}
			}
		}

		printf("%d\n", ans != INF ? ans : -1);
	}
}

Measured memory_bytes: 1092
#include <stdio.h>
    #include <stdlib.h>

    int main()
    {
        long long  a,b,sum;
        sum = 0;
        scanf("%lld %lld",&a,&b);
        if(2*a<=b)
        {
            sum += a;
            b = b - a*2;
            sum += b/4;
        }
        else
        {
            sum += b/2;
        }
        printf("%lld\n",sum);
        return 0;
    }


Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var n, m, c int
	var b []int
	var a [][]int

	fmt.Scan(&n, &m, &c)
	for i := 0; i < m; i++ {
		var tmp int
		fmt.Scan(&tmp)
		b = append(b, tmp)
	}

	a = make([][]int, n)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			var tmp int
			fmt.Scan(&tmp)
			a[i] = append(a[i], tmp)
		}
	}

	var res int
	for i := range a {
		sum := 0
		for j := 0; j < m; j++ {
			sum += a[i][j] * b[j]
		}
		sum += c
		if sum > 0 {
			res++
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 512