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

#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384


int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}    //最大公約数
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}     //最小公倍数
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} //コンビネーション
int nHr(int a,int b){return nCr(a+b-1,b);}       // 重複組み合わせ
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}  //階乗
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} // a~bまでの階乗
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}   //数字の各位の和
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}  // b進数の各位の和？
int sankaku(int x){return ((1+x)*x)/2;} //三角数 xまでの和

//以下long long ver
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}

//double
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}


typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) ; for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

 
/*CODE START HERE*/
int main() {
  int s;
  cin >> s;
  int a_n = s;
  int n = 1;
  forn(i,1000000){
    if (  a_n == 1 || a_n == 2 ||a_n == 4){
      break ;
    }
    if ( a_n%2==1){
      a_n = 3*a_n+1;
    }else if ( a_n%2==0){
      a_n/=2;
    }
    n++;
  }
  cout << n+3 << endl;
}

Measured memory_bytes: 3620
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextLong()
    val b = sc.nextLong()
    val c = sc.nextLong()
    val x = sc.nextLong()
    val y = sc.nextLong()
    println(problem095c(a, b, c, x, y))
}

fun problem095c(a: Long, b: Long, c: Long, x: Long, y: Long): Long {
    val min = Math.min(x, y)

    fun normal(): Long {
        val maxPrice = if (min == x) b else a
        return c * min * 2 + ((x - min) + (y - min)) * maxPrice
    }

    fun noSeparate(): Long {
        return a * x + b * y
    }

    fun allSeparate(): Long {
        return c * Math.max(x, y) * 2
    }

    return listOf(normal(), noSeparate(), allSeparate()).min()!!
}


Measured memory_bytes: 36044
#[allow(unused_imports)]
use std::cmp::{max, min};

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    // from kenkoooooo
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

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

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

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: i64 = sc.read();
    let k: i64 = sc.read();
    if n % k == 0 {
        println!("0");
    } else {
        println!("1");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{
  int offset = 0;
  int num = 0;
  int q;cin>>q;
  vector<int> vec;
  multiset<int> sl,sr;
  int tot = 0;
  for (int i = 0; i < q; i++)
  {
    int x;cin>>x;
    if(x == 1)
    {
      int a,b;cin>>a>>b;
      offset += b;
      sl.insert(a);
      sr.insert(a);
      auto itl = sl.end(); itl--;
      auto itr = sr.begin();
      int l = *itl;
      int r = *itr;
      if(l > r)
      {
        tot += l - r;
        sl.erase(itl); sl.insert(r);
        sr.erase(itr); sr.insert(l);
      }
    }
    else
    {
      int l = *sl.rbegin();
      cout<<l<<" "<< tot + offset<<endl;
    }
  }
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 22284
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]


n = ni()
m = [[0]*10 for _ in range(10)]
for i in range(1, n+1):
    i = str(i)
    f, e = int(i[0]), int(i[-1])
    m[f][e] += 1
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += m[i][j]*m[j][i]
print(ans)



Measured memory_bytes: 3064
#include <stdio.h>

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

	while(scanf("%d %d", &a, &b) != EOF){
		cnt = 0;
		a = a+b;
		while(a != 0){
			a = a / 10;
			cnt++;
		}
		printf("%d\n", cnt);
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t a,b,c;cin>>a>>b>>c;
  if(c-a-b>0&&4*a*b<(c-a-b)*(c-a-b))cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define desync ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define inf 1000000000 // 1e9
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

int32_t main(){
    desync;
    int n;
    cin >> n;
    int h[n],dp[n];
    frr(i,n) cin >> h[i];

    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int A, B, C;

int main(void) {
	cin >> A >> B >> C;

	int tmp = 10 * A + B+C;

	int tmp2 = A + 10 * B + C;
	int ans;
	if (tmp > tmp2)
	{
		ans = tmp;
	}
	else { ans = tmp2; }

	int tmp3 = 10*C + A + B;

	if (ans < tmp3) { ans = tmp3; }

	cout << ans << endl;
	//system("pause");
	return 0;
}

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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

struct App {
    // input
    n: usize,
    adj: Vec<Vec<bool>>,
    // intermediate variables
    col: Vec<i32>,
    fail: bool,
}

impl App {
    fn input() -> App {
        let n: usize = read();
        let m: usize = read();
        let mut adj: Vec<Vec<bool>> = vec![vec![false; n]; n];
        for _ in 0..m {
            let a = read::<usize>() - 1;
            let b = read::<usize>() - 1;
            adj[a][b] = true;
            adj[b][a] = true;
        }
        return App {
            n: n, adj: adj,
            col: vec![-1; n],
            fail: false
        };
    }

    fn solve(&mut self) {
        let mut ts: Vec<(usize, usize)> = Vec::new();

        for v in 0..self.n {
            if self.col[v] != -1 {
                continue;
            }

            let (a, b) = self.dfs(v, 0);
            ts.push((a, b));
        }

        if self.fail {
            println!("-1");
            return;
        }

        let mut crr: Vec<bool> = vec![false; self.n + 1];
        crr[0] = true;
        for &(a, b) in ts.iter() {
            let mut nxt: Vec<bool> = vec![false; self.n + 1];
            for i in 0..self.n {
                if crr[i] {
                    nxt[i + a] = true;
                    nxt[i + b] = true;
                }
            }
            crr = nxt;
        }

        let mut ans = 1000000000;
        for i in 0..self.n {
            if crr[i] {
                let a = i as i64;
                let b = (self.n - i) as i64;
                ans = std::cmp::min(ans, a * (a - 1) / 2 + b * (b - 1) / 2);
            }
        }
        println!("{}", ans);
    }

    fn dfs(&mut self, v: usize, c: i32) -> (usize, usize) {
        if self.col[v] != -1 {
            if self.col[v] != c {
                self.fail = true;
            }
            return (0, 0);
        }
        self.col[v] = c;
        // println!("{}: {}", v, c);

        let mut a = 0;
        let mut b = 0;

        if c == 0 {
            a += 1;
        } else {
            b += 1;
        }

        for w in 0..self.n {
            if v == w || self.adj[v][w] {
                continue;
            }
            let (da, db) = self.dfs(w, 1 - c);
            a += da;
            b += db;
        }

        return (a, b);
    }
}

fn main() {
    let mut app = App::input();
    app.solve();

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


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

bool is_prime[10001];
int prime[10001];
int main() {
	memset(is_prime, 1, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	int p = 0;
	for (int i = 2; i <= 10000; i++) {
		if (is_prime[i]) {
			prime[++p] = prime[p - 1] + i;
			for (int j = i * 2; j <= 10000; j += i)is_prime[j] = false;
		}
	}
	map<int, int>mp;
	for (int i = 0; i < p; i++) {
		for (int j = i + 1; j < p&&prime[j] - prime[i] <= 10000; j++) {
			mp[prime[j] - prime[i]]++;
		}
	}
	int n;
	while (scanf("%d", &n), n)printf("%d\n", mp[n]);
}

Measured memory_bytes: 3368
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

class S {
public:
    int l;
    char *a;
    char c(int i) {
        return a[i%l];
    }
};

vector<int> p;
char s_[500004], t_[500004];

int kmp(S t, int tc, S s, int sc, int o = 0) {
    int tn = t.l*tc;
    if (p.size() < tn)
        p.resize(tn);

    for (int i = 1, k = 0; i < tn; ++i) {
        while (k && t.c(k) != t.c(i))
            k = p[k - 1];
        if (t.c(k) == t.c(i))
            k++;
        p[i] = k;
    }

    int sn = s.l*sc;
    for (int i = 0, k = 0; i < sn; ++i) {
        while (k && t.c(k) != s.c(i))
            k = p[k - 1];
        if (t.c(k) == s.c(i))
            k++;
        if (k == tn) {
            if (i - k + 1 >= o)
                return i - k + 1;
            k = p[k - 1];
        }
    }

    return -1;
}

int fp(char *a, int l) {
    S s, t;
    s.a = a;
    s.l = l;

    t.a = a;
    t.l = l;

    return kmp(t, 1, s, 2, 1);
}

int main() {
    p.push_back(0);

    S s, t;
    scanf("%s", s_);
    s.a = s_;
    s.l = strlen(s_);
    scanf("%s", t_);
    t.a = t_;
    t.l = strlen(t_);

    int sp = fp(s.a, s.l);
    int tp = fp(t.a, t.l);

    if (sp == tp && ((t.l < s.l && kmp(t, 1, s, 1) != -1) || (t.l > s.l && kmp(s, 1, t, 1) != -1) || (t.l == s.l && kmp(t, 1, s, 2) != -1))) {
        printf("-1\n");
        return 0;
    }

    int l2 = 1;
    for (; ; l2*=2) {
        int sc = (l2*t.l+s.l-1+s.l-1)/s.l;
        if (kmp(t, l2, s, sc) == -1)
            break;
    }

    int l1 = l2/2;
    l2--;
    while (l1 < l2) {
        int tc = (l1 + l2)/2;
        int sc = (tc*t.l+s.l-1+s.l-1)/s.l;
        if (kmp(t, tc, s, sc) == -1) {
            l2 = tc-1;
        } else {
            if (l2 == l1+1) {
                sc = (l2*t.l+s.l-1+s.l-1)/s.l;
                if (kmp(t, l2, s, sc) == -1)
                    l2--;
                else
                    l1++;
            } else
                l1 = tc;
        }
    }

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

    return 0;
}


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

using namespace std;

#define roop(i, n) for(int i = 0;i < n;i++)
#define ll long long int

int main(void){

    int n;
    cin >> n;
    vector<int> a(n);
    roop(i, n) cin >> a[i];

    int mi = a[0];
    int ma = a[0];
    ll total = 0;

    for(int i = 0;i < n;i++){
        mi = min(mi, a[i]);
        ma = max(ma, a[i]);
        total += a[i];
    }

    cout << mi << " " << ma << " " << total << endl;

    return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;

vector<int> g[650];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	for(int i=0;i<m;i++){
		int x,y; cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
	}
	vector<double> dp(n);
	dp[n-1]=0;
	for(int i=n-2;i>=0;i--){
		double now=0;
		for(int p:g[i]){
			now+=dp[p];
		}
		now/=g[i].size();
		dp[i]=now+1;
	}
	double ans=dp[0];
	for(int i=0;i<n-1;i++){
		if(g[i].size()==1)continue;
		int nu=g[i][0];
		for(int p:g[i]){
			if(dp[nu]<dp[p])nu=p;
		}

		double now=[&]{
			vector<double> dp(n);
			dp[n-1]=0;
			for(int j=n-2;j>=0;j--){
				double now=0;
				for(int p:g[j]){
					if(i==j&&p==nu)continue;
					now+=dp[p];
				}
				int deg=g[j].size();
				if(i==j)deg--;
				now/=deg;
				dp[j]=now+1;
			}
			return dp[0];
		}();
		ans=min(ans,now);
	}
	printf("%.8f\n", ans);
}

Measured memory_bytes: 1408
#define rep(i,n) for (int i=0;i<n;i++)
#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const long long INF = 9223372036854775809;

int main(){
  string S;
  cin >> S;
  bool torf=true;
  
  rep(i,S.size()){
    if(i%2==0){
      if(S.at(i)=='L')
        torf=false;
      
    }
    if(i%2==1){
      
      if(S.at(i)=='R')
        torf=false;
      }
      
  }
  
  if(torf==true)
  cout << "Yes" << endl;
  else
    cout << "No" << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int bubbleSort(int *num,int n) {
	int cnt = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - 1; j++) {
			if (num[j] > num[j + 1]) {
				swap(num[j], num[j + 1]);
				cnt++;
			}
		}

		
	}
	for (int i = 0; i < n; i++) {
		
		cout << num[i];
		if(i!=n-1)
			cout << " ";
	}
		
	return cnt;
}

int main() {
	int ans = 0;
	int n;
	int tmp;
	int *num;
	cin >> n;
	num = new int[n];
	for (int i = 0; i < n; i++) {
		cin>>num[i];
	}
	
	ans=bubbleSort(num,n);

	cout << endl<<ans << endl;

	return 0;
}



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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main()
{
	int n,m,c;cin >> n >> m >> c;
	vector<int> kazu(c);
	REP(i,c)cin >> kazu[i];
	
	vector<vector<int> > v(c);
	
	REP(i,n){
		int a,b;cin >> a >> b;
		a--;
		v[a].PB(b);
	}
	
	vector<int> ret;
	
	ll ans = 0;
	REP(i,c){
		sort(ALL(v[i]),greater<int>());
		REP(j,min(kazu[i],(int)v[i].size())){
			ret.PB(v[i][j]);
		}
	}
	
	sort(ALL(ret),greater<int>());

	REP(i,min(m,(int)ret.size()))ans += ret[i];
	
	cout << ans << endl;
	
	return 0;
}


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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int Maxn = 1000 + 100, Maxm = 2e5 + 100;

int N, M;
int fl[2][Maxn][Maxn];
int Vis[2][Maxn];
vector <int> G[Maxn];

inline void dfs1 (int x, int s)
{
	if (fl[0][s][x]) return ;
	fl[0][s][x] = 1;
	for (int i = 0; i < G[x].size(); ++i) dfs1 (G[x][i], s);
}

inline void dfs2 (int x, int col, int op)
{
	if (Vis[op][x]) return ;
	Vis[op][x] = col;
	for (int i = 0; i < G[x].size(); ++i) dfs2 (G[x][i], col, op);
}

pii E[Maxm];

inline void Solve ()
{
	for (int i = 1; i <= N; ++i) dfs1 (i, i);

	for (int x = 1; x <= N; ++x)
	{
		if (!G[x].size()) continue;
		memset (Vis, 0, sizeof Vis);
		Vis[0][x] = Vis[1][x] = -1;
		for (int i = 0; i < G[x].size(); ++i) dfs2 (G[x][i], i + 1, 0);
		for (int i = G[x].size() - 1; i >= 0; --i) dfs2 (G[x][i], i + 1, 1);
		for (int i = 0; i < G[x].size(); ++i)
			if (Vis[0][G[x][i]] == Vis[1][G[x][i]]) fl[1][x][G[x][i]] = 0;
			else fl[1][x][G[x][i]] = 1;
	}

	for (int i = 1; i <= M; ++i)
		if (fl[0][E[i].y][E[i].x] == fl[1][E[i].x][E[i].y]) puts("same");
		else puts("diff");
}

inline void Input ()
{
	N = read<int>(), M = read<int>();
	for (int i = 1; i <= M; ++i)
	{
		int x = read<int>(), y = read<int>();
		E[i] = mp (x, y);
		G[x].pb (y);
	}
}

int main()
{

#ifdef hk_cnyali
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}


Measured memory_bytes: 13312
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INF = (int) 1e9;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.00001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	const int MAXV = 100000;
	int N, W;
	cin >> N >> W;
	vector<ll> dp(MAXV + 1, 1e18);
	dp[0] = 0;
	for (int k = 0; k < N; k++) {
		int w, v;
		cin >> w >> v;
		for (int i = MAXV; i >= v; i--) {
			if (dp[i - v] != -1) dp[i] = min(dp[i], dp[i - v] + w);
		}
	}
	int v = -1;
	for (int i = 0; i <= MAXV; i++) {
		if (dp[i] <= W) v = i;
	}
	cout << v << endl;
	return 0;
}


Measured memory_bytes: 1024
import numpy as np
import math
N = int(input())
s = [int(input()) for _ in range(N)]
sn=np.array(s)
sa=sn.argsort()
x=0
for i in range(N):
  if i %2 != sa[i] %2:
    x+=1
print(math.ceil(x/2))
  

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

using namespace std;
typedef long long ll;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a.begin(), a.end());
    int ma = *--a.end() + 1;
    vector<bool> sieve(ma);
    for (auto e : a) sieve[e] = 1;
    for (int i = 0; i < a.size(); i++) {
        if (!sieve[a[i]]) continue;
        if (i < n - 1 && a[i] == a[i + 1]) sieve[a[i]] = 0;
        for (int m = 2; m * a[i] < ma; m++) sieve[m * a[i]] = 0;
    }
    int ans = 0;
    for (auto e : a) ans += sieve[e];
    printf("%d\n", ans);
}


Measured memory_bytes: 4296
input = input()
splitedinput = input.split(" ")
num1 = int(splitedinput[0])
num2 = int(splitedinput[1])
if num1 < num2:
  num3 = int(num2) - int(num1)
elif int(num2) < int(num1):
  num3 = int(num1) - int(num2)
elif num2 == num1:
  num3 = 0
if num3 >= 2:
  toadd = max(num1, num2)
  result = toadd * 2
  result = int(result) - 1
  print(result)
else:
  result = num1 + num2
  print(result)
  


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

int main(){
	int n,a[10],t;
	while(cin >> n,n){
		for(int i = 0;i < 10;i++) a[i] = 0;
		for(int i = 0;i < n;i++){
			cin >> t;
			a[t]++;
		}
		for(int i = 0;i < 10;i++){
			if(a[i] == 0) cout << "-" << endl;
			else {
				for(int j = 0;j < a[i];j++) cout << "*";
				cout << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
using namespace std;
const int N = 1000000;


int main() {
   int a,b,c,d; cin >> a >> b >> c >> d;

   print(c + b - d);
   print(d - a + c);
   print(a + b - d);
   print(b - a + c);
}

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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif
    vector<pair<int, int> > vp;
    int n;
    scanf("%d", &n);
    vp.resize(n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &vp[i].first, &vp[i].second);
    }
    sort(vp.begin(), vp.end());
    double avg = 0;
    int cnt = 0;
    do {
        double cur = 0;
        for (int i = 1; i < vp.size(); i++) {
            int dx = vp[i].first - vp[i - 1].first;
            int dy = vp[i].second - vp[i - 1].second;
            cur += sqrt(1ll * dx * dx + 1ll * dy * dy);
        }
        avg += cur;
        cnt++;
    } while (next_permutation(vp.begin(), vp.end()));
    avg /= cnt;
    printf("%.10lf\n", avg);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int main(void)
{
	int p,i,j,n,sum,ki;
	while(1) {
		cin >> n;
		if(n==-1) break;
		sum=1150;
		for(i=10;i<=n;i++) {
			if(i>10 && i<=20) sum+=125;
			if(i>20 && i<=30) sum+=140;
			if(i>30) sum+=160;
		}
		ki=4280;
		cout << ki-sum <<endl;
	}
	exit(0);
}

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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 3e5 + 7;
vector <vi > adj;
bool vis[N];
int a[3005];
int dp[3005][3005][3];

int help(int s, int e, int player) {
	if (s > e) return 0;

	if (dp[s][e][player] != -1) return dp[s][e][player];

	if (player == 1) {
		int op1 = a[s] + help(s + 1, e, 2);
		int op2 = a[e] + help(s, e - 1, 2);
		return dp[s][e][player] = max(op1, op2);
	}

	int op1 = help(s + 1, e, 1) - a[s];
	int op2 = help(s, e - 1, 1) - a[e];
	return dp[s][e][player] = min(op1, op2);

}

void solve()
{
	int n;
	cin >> n;
	mset(dp, -1);
	loop(i, 0, n) cin >> a[i];
	cout << help(0, n - 1, 1) ;
	return;

}

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


	cout << setprecision(9) << fixed;

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


	return 0;
}

Measured memory_bytes: 212096
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;

int main()
{
  int n, r;
  cin >> n >> r;
  int ans = 0;
  if (n >= 10)
    ans = r;
  else
    ans = r + 100 * (10 - n);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

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

    ll ans = 0;
    for(int b=K+1; b<=N; b++){
        int r = N%b;
        ans += (b-K)*(N/b) + max(r+1-K, 0);
        if(K == 0) ans--;
    }

    
    cout << ans << endl;
}

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

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> pena(N,0);
    vector<ll> ok(N,0);
    ll res1=0;
    ll res2=0;
    for (int i = 0; i < M; ++i)
    {
        ll p;
        string status;
        cin >> p >> status;
        --p;
        if(status=="AC"){
            if(!ok[p]){
                ++res1;
                res2+=pena[p];
                ok[p]=true;
            }
        }
        else pena[p]++;
    }
    cout<<res1<<" "<<res2;
    return 0;
}

Measured memory_bytes: 4824
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 20:57:46 2019

@author: Yamazaki Kenichi
"""
import sys

N,K = map(int,input().split())
S = input()

T = []
a,b = 0,0
if S[0] == '0':
    T.append(0)
for c in S:
    if c =='1':
        if a > 0:
            a += 1
        else:
            a = 1
            T.append(b)
            b = 0
    else:
        if b > 0:
            b += 1
        else:
            b = 1
            T.append(a)
            a = 0
T.extend([max(a,b),0,0])
if K*2+3 >= len(T):
    print(sum(T))
    sys.exit()
    
m,tmp = sum(T[1:K*2+2]),sum(T[1:K*2+2])
for i in range(0,len(T)-(K*2+3),2):
#    print(i)
#    print(m,tmp,T[i+1],T[i+2],T[i+K*2+2],T[i+K*2+3])
    tmp = tmp-T[i+1]-T[i+2]+T[i+K*2+2]+T[i+K*2+3]
    m = max(m,tmp)
print(m)


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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    int m =  max(A, max(B, C));

    if( m == A ) cout << A*10 + B + C << endl;
    else if( m == B ) cout << B*10 + A + C << endl;
    else if( m == C ) cout << C*10 + A + B << endl;

    return 0;
}


Measured memory_bytes: 256
x,k,d=map(int,input().split())
# x,k,d=1000000000000000,1000000000000000,1000000000000000

if abs(x) >= k * d:
    print(abs(x) - (k * d))

else:
    if (abs(x)//d)%2==1:
        if k%2==0:
            print(abs(abs(x)%d-d))

        else:
            print(abs(abs(x)%d))

        
    elif (abs(x)//d)%2==0:
        if k%2==0:
            print(abs(abs(x)%d))
        else:
            print(abs(abs(x)%d-d))




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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long 

using namespace std;

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

	return gcd(b%a,a);
}

int32_t main()
{
	fio;
	int k;
	cin>>k;
	int sum=0;
	for(int a=1;a<=k;a++)
	{
		for(int b=1;b<=k;b++)
		{
			for(int c=1;c<=k;c++)
			{
				sum+=gcd(gcd(a,b),c);
			}
		}
	}

	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3656
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    ans = 0
    if "RRR" in s:
        print(3)
    elif "RR" in s:
        print(2)
    elif "R" in s:
        print(1)
    else:
        print(0)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 67224
#include<bits/stdc++.h>
using namespace std;
#define nw '\n'

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

		string S;
		cin>>S;
		
		if(S=="RRR")
		cout<<"3"<<nw;
		else if(S=="RSR" || S=="RSS" || S=="SRS" || S=="SSR")
		cout<<"1"<<nw;
		
		else if(S=="SRR" || S=="RRS")
		cout<<"2"<<nw;
		else
		cout<<"0"<<nw;
		

	return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int q;
    cin >> q;
    while (q--) {
        ll n,a,b,c,d;
        cin >> n >> a >> b >> c >> d;
        ll ans = INT64_MAX;
        map<ll,ll> mp;
        set<ll> st;
        mp[n] = 0;
        st.insert(n);
        while (!st.empty()) {
            auto it = prev(st.end());
            for (int i = -5;i < 6;++i) if (*it+i >= 0 && *it+i < n+6) {
                ll s = mp[*it]+d*abs(i),t = *it+i;
                if (t%2 == 0 && (mp[t/2] == 0 || mp[t/2] > s+a)) {
                    mp[t/2] = s+a;
                    if (t/2) st.insert(t/2);
                }
                if (t%3 == 0 && (mp[t/3] == 0 || mp[t/3] > s+b)) {
                    mp[t/3] = s+b;
                    if (t/3) st.insert(t/3);
                }
                if (t%5 == 0 && (mp[t/5] == 0 || mp[t/5] > s+c)) {
                    mp[t/5] = s+c;
                    if (t/5) st.insert(t/5);
                }
                if (t < (INT64_MAX-s)/d) ans = min(ans,s+t*d);
            }
            st.erase(it);
        }
        cout << ans << newl;
    }
}

Measured memory_bytes: 7412
def main():
    n, m = map(int, input().split())
    ans = -1
    if m != 0:
        lst = [None]*m
        for i in range(m):
            s, c = map(int, input().split())
            lst[i] = [s, c]
    for i in range(1000):
        f = True
        if len(str(i)) != n:
            f = False
            continue
        if m != 0:
            for v in lst:
                if str(i)[v[0]-1] != str(v[1]):
                    f = False
        if f:
            ans = i
            break
    if ans != -1:
        print(ans)
    else:
        print("-1")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define lld unsigned long long int
#define MAX 100000
using namespace std;
struct r{
    int p, index;
    char name[50];
}restaurants[MAX];

int n, aux;

bool ord(r a, r b){
    aux = strcmp(a.name, b.name);
    if(aux<0)return true;
    if(aux>0)return false;
    if(a.p>b.p)return true;
    return false;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> restaurants[i].name >> restaurants[i].p;
        restaurants[i].index = i+1;
    }
    sort(restaurants, restaurants+n, ord);
    for(int i = 0; i < n; i++){
        printf("%d\n", restaurants[i].index);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  string str;
  int m=0;
  vi v;
  v = {-1};
  cin >> str;
  rep(i,str.size()){
    if(str[i]=='A'||str[i]=='T'||str[i]=='C'||str[i]=='G'){

    }else{
      v.push_back(i);
    }
  }
  v.push_back(str.size());
  switch (v.size()) {
    case 1:
      cout << str.size() << endl;
      return 0;
    default:
    rep(i,v.size()-1){
      m = max(m,v[i+1]-v[i]);
    }
    cout << m-1 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
h,w,K=map(int,input().split())
g=[[] for i in range(h)]
for i in range(h):
  s=input()
  g[i].append(s)

t=[[0 for i in range(w)] for j in range(h)]
c=0
for i in range(h):
  for j in range(w):
    t[i][j]=g[i][0][j]
    if g[i][0][j]=='#':
      c+=1
black=[]
for i in range(h):
  l=0
  for j in range(w):
    if t[i][j]=='#':
      l+=1
  black.append(t)
for i in range(w):
  l=0
  for j in range(h):
    if t[j][i]=='#':
      l+=1
  black.append(l)
ans=0
for i in range(2**(h+w)):
  count=0
  i=format(i,'b').rjust(h+w,'0')
  
  hl=[]
  wl=[]
  for j in range(h):
    if i[j]=='1':
      hl.append(j)
  for k in range(h,h+w):
    if i[k]=='1':
      wl.append(k-h)
  for i in range(h):
    for j in range(w):
      if i not in hl and j not in wl and t[i][j]=='#':
        count+=1

  if count==K:
    ans+=1
print(ans)

Measured memory_bytes: 9164
#include<stdio.h>
#define max(x,y) (x<y)?y:x
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
int N, M;
char B[514][514];
int E[514];
int dp[2][1<<22];
void mode1(void){
    int ans = 0;
    rep(i,1<<N){
        rep(j,M) E[j]=0;
        int cnt = 0;
        rep(j,N){
            if(i>>j&1){
                cnt++;
                rep(k,M){
                    if(B[j][k]=='1')E[k]=!E[k];
                }
            }
        }
        int flag=1;
        rep(j,M) if(E[j])flag=0;
        if(flag) ans=max(ans,cnt);
    }
    printf("%d\n",ans);
}
void mode2() {
    rep(i, 1 << M)dp[0][i] = -1;
    dp[0][0] = 0;
    int k = 1;
    rep(i, N) {
        int W = 0;
        int d = 1;
        rep(j, M) { //入力を2進数に変換
            W += d * (B[i][M - j - 1] == '1');
            d *= 2;
        }
        rep(j, 1 << M)dp[k][j] = dp[!k][j];
        rep(j, 1 << M) {
            if (dp[!k][j] >= 0) {
                int x = j^W; //101^110=011
                dp[k][x] = max(dp[!k][x], dp[!k][j] + 1);
            }
        }
        //rep(j,1<<M) printf("%2d ",dp[k][j]); puts("");
        k = !k;
    }
    printf("%d\n",dp[!k][0]);
}
int main(void){
    while (1) {
        scanf("%d%d",&N,&M);
        if (N == 0 && M == 0)return 0;
        rep(i, N) scanf("%s",B[i]);
        if (N < M)
            mode1();
        else
            mode2();
    }
    return 0;
}
/*
 wiの排他的論理和をとると0になる
 0 -1 -1 -1 -1 -1  1 -1
 0 -1 -1  2 -1  1  1 -1
 3 -1 -1  2 -1  2  2 -1
 3 -1 -1  3 -1  3  4 -1
 */



Measured memory_bytes: 34756
#include <iostream>

using namespace std;
int a[100], b[100];

int main()
{
  int p, q;

  while(cin>>p>>q){
    for(int i = 0; i < 100; i++){
      if(p == 0){
	q = i;
	break;
      }

      p *= 10;
      a[i] = p/q;
      b[i] = p;
      p %= q;
    }

    if(p == 0){
      for(int i = 0; i < q; i++) cout << a[i];
      cout << endl;
    } else {
      for(p = 0; p < 99; p++){
	bool f = true;
	for(q = p+1; q < 100 && f; q++)
	  if(b[p] == b[q]) f = false;

	if(!f) break;
      }

      q--;
      for(int i = 0; i < q; i++) cout << a[i];
      cout << endl;
      for(int i = 0; i < p; i++) cout << " ";
      for(int i = p; i < q; i++) cout << "^";
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 0
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt() // A= +1
	b := nextInt() // B=  0
	c := nextInt() // C= -1
	k := nextInt()

	if a+b >= k {
		if a >= k {
			fmt.Println(k)
		} else {
			fmt.Println(a)
		}

	} else {
		fmt.Println(a - (k - a - b))
	}
	a = c

}


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

class Test
{
    static void Main()
    {
        int[] dd = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int W = dd[0];
        int H = dd[1];
        int x = dd[2];
        int y = dd[3];
        int r = dd[4];

        if (r <= x && x <= W - r && r <= y && y <= H - r) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}


Measured memory_bytes: 20476
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string s;
  cin >> s;
  string t(s);
  int l = 0, r = 0;
  for(char c: s) {
    if(c == '(')
      l++;
    else
      r++;
    if(r > l) {
      t = string("(") + t;
      l++;
    }
  }
  fi(0, l - r)
    t += ")";
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
import math
from functools import reduce

K=int(input())
sum=0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for a in range(1,K+1,1):
	for b in range(1,K+1,1):
		for c in range(1,K+1,1):
			sum+=gcd(a,b,c)
print(sum)

Measured memory_bytes: 69320
n = int(input())
lis = list(map(int,input().split()))
minus,plus = [],[]
for num in lis:
    if num >= 0:
        plus.append(num)
    elif num < 0:
        minus.append(num)
plus.sort()
minus.sort(reverse=True)
ans = []
if len(plus) == 0:
    now = minus.pop(0)
    for num in minus:
        ans.append([now,num])
        now -= num
    print(now)
elif len(minus) == 0:
    now = plus.pop(0)
    last_num = plus.pop(0)
    for num in plus:
        ans.append([now,num])
        now -= num
    ans.append([last_num,now])
    last_num -= now
    print(last_num)
else:
    now = minus.pop(0)
    last_num = plus.pop(0)
    for num in plus:
        ans.append([now,num])
        now -= num
    for num in minus:
        ans.append([last_num,num])
        last_num -= num
    ans.append([last_num,now])
    last_num -= now
    print(last_num)
for i in range(n-1):
    print(*ans[i])

Measured memory_bytes: 23224
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

struct data{
	int l,r;
	data(){}
	data(int ll,int rr){
		l=ll;
		r=rr;
	}
	bool operator<(const data &d)const{
		if(r==d.r)return l<d.l;
		return r<d.r;
	}
};

int n,w,d;
vector<data> query;



int main(void){
	scanf("%d%d%d",&n,&w,&d);
	for(int i=0;i<n;i++){
		int x,y;
		char c;
		scanf("%d%d%*c%c",&x,&y,&c);
		if(c=='N'){
			int ll=x-(d-y);
			int rr=x+(d-y);
			if(ll<0)ll+=(w+d)*2;
			query.push_back(data(ll,rr));
		}
		if(c=='E'){
			int ll=w+d-y-(w-x);
			int rr=w+d-y+(w-x);
			query.push_back(data(ll,rr));
		}
		if(c=='S'){
			int ll=w+d+(w-x)-y;
			int rr=w+d+(w-x)+y;
			query.push_back(data(ll,rr));
		}
		if(c=='W'){
			int ll=w+d+w+y-x;
			int rr=w+d+w+y+x;
			if(rr>=(w+d)*2)rr-=(w+d)*2;
			query.push_back(data(ll,rr));
		}
	}
	sort(query.begin(),query.end());
	for(int i=0;i<n;i++){
		query.push_back(query[i]);
	}
	int res=n;
	for(int i=0;i<n;i++){
		int tmp=1,last=query[i].r;
		for(int j=1;j<n;j++){
			data dd=query[i+j];
			if(dd.l<dd.r){
				if(last<dd.l || dd.r<last){
					tmp++;
					last=dd.r;
				}
			}else{
				if(last<dd.l && dd.r<last){
					tmp++;
					last=dd.r;
				}
			}
		}
		res=min(res,tmp);
		//printf("%d %d %d %d\n",i,query[i].l,query[i].r,tmp);
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 2784