akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    
    using namespace std;
    int const MOD=1e9+7;
    int r,c;
    bool valid(int i, int j){
      if(i<0 || i>=r || j<0 || j>=c)
        return 0;
      return 1;
    }
   int dfs(int i, int j, vector<vector<char>>&g, vector<vector<int>>&dp){
      if(!valid(i, j) || g[i][j]=='#')
        return 0;
      
      if(dp[i][j]!=-1)
        return dp[i][j];
      
      if(i==(r-1) && j==(c-1))
        return dp[i][j]=1;

      dp[i][j]=(dfs(i, j+1, g, dp)%(MOD) + dfs(i+1, j, g, dp)%(MOD))%(MOD);
      return dp[i][j];
    }
    int main(){
      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      cin>>r>>c;
      vector<vector<char>>g(r, vector<char>(c,'.'));
      vector<vector<int>>dp(r, vector<int>(c, -1));
      for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
          cin>>g[i][j];
          //cout<<g[i][j]<<" ";
        }
        //cout<<"\n";
      }
 
      dfs(0,0, g, dp);
      cout<<dp[0][0]<<"\n";
    }

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

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

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


int main() {
  int N;
  cin >> N;
  deque< int > A(N);
  for(int i = 0; i < N; i++) cin >> A[i];
  sort(begin(A), end(A));

  // (+----)
  auto check1 = [&]() {
    auto B(A);
    int64 ret = B.back();
    B.pop_back();
    for(int i = 0; i + 1 < N; i++) ret -= B[i];
    return ret;
  };


  // (+----) (-++++)
  auto check2 = [&]() {
    auto B(A);
    int64 ret = 0;
    ret += B.back();
    B.pop_back();
    if(B.size() <= 1) return -infll;
    ret -= B.front();
    B.pop_front();
    ret += B.back();
    B.pop_back();
    for(auto &t : B) ret += abs(t);
    return ret;
  };


  if(check1() <= check2()) {
    cout << check2() << endl;
    int64 cur1 = A.back(), cur2 = A.front();
    A.pop_front();
    A.pop_back();
    bool flag = false;
    while(A.size()) {
      int64 p = A.back();
      A.pop_back();
      if(p >= 0 || flag == false) {
        flag = true;
        cout << cur2 << " " << p << endl;
        cur2 -= p;
      } else {
        cout << cur1 << " " << p << endl;
        cur1 -= p;
      }
    }
    cout << cur1 << " " << cur2 << endl;
  } else {
    cout << check1() << endl;
    int64 cur = A.back();
    A.pop_back();
    while(A.size()) {
      int64 p = A.front();
      A.pop_front();
      cout << cur << " " << p << endl;
      cur -= p;
    }
  }
}




Measured memory_bytes: 2488
#include <iostream>
#include <queue>

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

    std::priority_queue<int> queue;

    for (int i = 0; i < n; i++) {
        int temp;
        std::cin >> temp;
        queue.push(temp);
    }

    for (int i = 0; i < m; i++) {
        int temp = queue.top() / 2;
        queue.pop();
        queue.push(temp);
    }

    long long ans = 0;
    while (queue.size()) {
        ans += queue.top();
        queue.pop();
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 892
n,m,x=map(int,input().split())
c=[]
a=[]
for i in range(n):
  l=list(map(int,input().split()))
  c.append(l[0])
  a.append(l[1:])

min_cost=float('inf')
for i in range(2**n):
  flag=True
  cost_total=0
  a_total=[0]*m
  for j in range(n):
    if (i>>j)&1:
      cost_total+=c[j]
      for k in range(m):
        a_total[k]+=a[j][k]
  for s in range(m):
    if a_total[s]<x:flag=False
  if flag:
    min_cost=min(min_cost,cost_total)
  
if min_cost==float('inf'):
  print(-1)
else:
  print(min_cost)

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

int main() {
  int n, ct=0;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(i%2==0&&a[i]%2==1)ct++;
  }
  cout << ct;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll a,b,c;
  cin >> a >> b >> c;
  if(a%2==0||b%2==0||c%2==0) {
    cout << 0 << endl;
  }
  else {
    cout << min({a*b,b*c,c*a}) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<set<int>> G1(N), G2(N);
	for (int i = 0; i < N-1+M; ++ i) {
		int u, v;
		cin >> u >> v;
		-- u; -- v;
		G1[u].insert(v);
		G2[v].insert(u);
	}
	vector<int> r(N, -1);
	queue<int> q;
	for (int i = 0; i < N; ++ i) {
		if (G2[i].size() == 0) {
			r[i] = 0;
			for (auto x : G1[i]) {
				G2[x].erase(i);
				if (G2[x].empty()) {
					r[x] = i+1;
					q.push(x);
				}
			}
			break;
		}
	}
	while (!q.empty()) {
		int i = q.front(); q.pop();
		for (auto x : G1[i]) {
			G2[x].erase(i);
			if (G2[x].empty()) {
				r[x] = i+1;
				q.push(x);
			}
		}
	}
	for (auto x : r) cout << x << endl;
}


Measured memory_bytes: 20352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int INF=0x3f3f3f3f;
int n,a[1001],f[1001],g[1001][5001],head[1001],now[5001],tot=0;
struct data {
	int next,num;
}edge[2001];
void add(int u,int v) {
	edge[++tot].next=head[u];
	edge[tot].num=v;
	head[u]=tot;
}
void dfs(int x) {
	memset(g[x],0x3f,sizeof(g[x]));
	g[x][0]=0;
	for (int i=head[x];i!=-1;i=edge[i].next) {
		int kx=edge[i].num;
		dfs(kx);
		memset(now,0x3f,sizeof(now));
		for (int j=a[kx];j<=a[x];j++) now[j]=min(now[j],g[x][j-a[kx]]+f[kx]);
		for (int j=f[kx];j<=a[x];j++) now[j]=min(now[j],g[x][j-f[kx]]+a[kx]);
		for (int j=0;j<=a[x];j++) g[x][j]=now[j];
	}
	f[x]=INF;
	for (int i=0;i<=a[x];i++) f[x]=min(f[x],g[x][i]);
}
int main() {
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for (int i=2;i<=n;i++) {
		int fat;
		scanf("%d",&fat);
		add(fat,i);
	}
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	dfs(1);
	if (f[1]==INF) printf("IMPOSSIBLE\n");
		else printf("POSSIBLE\n");
	return 0;
}

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

int main(){
    int M, N;cin>>M>>N;
    vector<int> vecX(M+1);
    vector<int> vecY(N+1);
    cin>>vecX[0]>>vecY[0];
    for (int i = 0; i < M; i++) {
     cin >> vecX.at(i+1);
    }
    for (int i = 0; i < N; i++) {
     cin >> vecY.at(i+1);
    }
    sort(vecX.begin(), vecX.end());
    sort(vecY.begin(), vecY.end());
    if(vecX.at(M) < vecY.at(0)){
      cout<<"No War"<<endl;
    }else{
      cout<<"War"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

//#include<boost/circular_buffer.hpp>
using namespace std;

//cout << fixed << setprecision(10);
typedef long long ll;
#define PI 3.141592653589793
#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}
	long long int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

long long int lcm(long long int a, long long int b) {
	long long int L;
	L = a / gcd(a, b);
	L *= b;
	return L;
}

vector<long long  int> Prime;
void Eratosthenes(long long int n) {
	vector<bool> is_prime(n, true);
	is_prime.at(0) = false;
	is_prime.at(1) = false;
	for (long long int i = 2; i * i <= n; i++) {
		if (is_prime.at(i)) {
			for (int j = i * i; j < n; j += i) {
				is_prime.at(j) = false;
			}
		}
	}
	for (int i = 2; i < n; i++) {
		if (is_prime.at(i))
			Prime.emplace_back(i);
	}
}

/*
map<int, int> prime;
void Prime_number(long long int n) {
	for (int i = 2; i <= n; i++) {
		int count = 0;
		while (n % i == 0) {
			count++;
			n /= i;
		}
		if (count != 0) {
			prime.insert(make_pair(i, count));
		}
	}
}
*/
//std::cout.fill('0');

int keta(long long int N) {
	int k = 0;
	while (N > 0) {
		N /= 10;
		k++;
	}
	return k;
}

int Combination(int n, int m) {
	long long int s = 1, t = 1;
	int tmp = n;
	while (n - m != tmp) {
		s *= tmp;
		tmp--;
	}
	tmp = m;
	while (tmp != 1) {
		t *= tmp;
		tmp--;
	}
	return s / t;
}

int main() {
	int n, m, ac = 0, wa = 0;
	cin >> n >> m;
	vector<int> p(m);
	vector<string> s(m);

	for (int i = 0; i < m; i++) {
		cin >> p.at(i) >> s.at(i);
	}
	vector<int> cnt(n,0);
	vector<bool> flag(n,false);
	for (int i = 0; i < m; i++) {
		if (s.at(i) == "AC")
			flag.at(p.at(i)-1) = true;
		else if(!flag.at(p.at(i)-1))
			cnt.at(p.at(i)-1) += 1;
	}
	for (int i = 0; i < n; i++ ) {
		if (flag.at(i)) {
			ac++;
			wa += cnt.at(i);
		}
	}
	cout << ac << ' ' << wa << endl;
}


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

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

    cin >> A >> B >> C;
    if (A > B)
    {
        if (C < A && C > B)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    else
    {
        if (C > A && C < B)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int x[110],y[110];
signed main(){
	int n,ans=0;
	cin>>n;
	f(i,n){
		cin>>x[i+1];
		x[i+1]+=x[i];
	}
	f(i,n){
		cin>>y[i+1];
		y[i+1]+=y[i];
	}
	f(i,n){
		ans=max(ans,x[i+1]+y[n]-y[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    import math
    n, k = map(int,input().split())
    kakuritsu = 0
    for i in range(1, n+1):
        kaisuu = math.ceil(math.log2(k/i))
        if i > k:
            kakuritsu += 1/n
        else:
            kakuritsu += (1/n) * ((1/2) ** kaisuu)
    print(kakuritsu)



if __name__ == "__main__":
    main()

Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
map<string,int> mp,mp1;
int main() {
	int n, m;
	string s;
	cin >> n;
	while(n--) {
		cin >> s;
		mp[s]++;
	}
	cin >> m;
	while(m--) {
		cin >> s;
		mp1[s]++;
	}
	int MAX = 0;
	map<string,int>::iterator it = mp.begin();
	for(; it != mp.end(); it++) {
		MAX = max(MAX,(*it).second-mp1[(*it).first]);
	}
	cout << MAX << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=5002;
int n,A,B,a[N];
long long f[N],tot;
int main()
{
//	freopen("D.in","r",stdin);
//	freopen("D.out","w",stdout);
	scanf("%d%d%d",&n,&A,&B);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	a[n+1]=n+1,n++;
	memset(f,63,sizeof(f));
	f[0]=0;
	for(int i=1;i<=n;i++)
	{
		tot=0;
		for(int j=i-1;~j;j--)
		{
			if (a[j]<a[i]) f[i]=min(f[i],f[j]+tot),tot+=B;
			else tot+=A;
		}
		//cout<<i<<' '<<f[i]<<endl;
	}
	printf("%lld",f[n]);
	return 0;
}


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

s = sum(a)

for i in range(n):
    if a[i] < b[i]:
        a[i+1] = max(0, a[i+1] - (b[i] - a[i]))
        a[i] = 0
    else:
        a[i] -= b[i]


print(s-sum(a))

Measured memory_bytes: 97716
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//usage
//input! {
//  h: i32;
//  v: [i32; n]
//  x: [[i32; n]; m]
//  f: chars <- Vec<char>
//}

fn main() {
    input!(
        mut h: i64
    );
    let mut ans: i64 = 0;
    let mut c: i64 = 1;
    while h > 0 {
        h /= 2;
        ans += c;
        c *= 2;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main(){
	int coin = 0;
	int happy = 0;
	int res = 0;
	cin>>coin;
	//checking the validity of a given number of coins
	happy += coin/500;
	res += happy*1000;
	coin = coin-happy*500;
	res += 5*(coin/5);
	cout<<res;
	
	return 0;
	}


Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    lint a, b, x;
    cin >> a >> b >> x;
    if(a == 0){
        cout << b / x + 1 << endl;
    }else{
        a--;
        cout << b/x - a/x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
ans =
  case n
  when 1..9
    n
  when 10..99
    9
  when 100..999
    9 + (n - 99)
  when 1000..9999
    9 + 900
  when 10000..99999
    9 + 900 + (n - 9999)
  when 100000
    9 + 900 + 90000
  end

puts ans


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

using namespace std;

#define pb push_back
#define mp make_pair
#define NL endl
#define pi 2.0*acos(0.0)
#define INTM 1e18
#define mod 1e9+7
#define FOR(i,j,n)    for(ull i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    fastIO;
    ll a,b;
    cin>>a>>b;
    if(a%b == 0) cout<<a/b<<endl;
    else cout<<(a/b)+1<<endl;
}


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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

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

// order statistics tree
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> indexed_set;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()


const int N = 11;
int n, m;
vector<int> bulb[N];
int p[N];
bool on[N];
int ans;
void bt(int i){
  if(i > n){
    // got a possible combination of switches

    // count number of switches on for each bulb
    // if one bulb is off then end the loop
    bool all_on = true;
    rep(j, 0, m){
      int s_on = 0;
      trav(s, bulb[j]){
        if(on[s]) s_on++;
      }
      if((s_on % 2) != p[j]){
        all_on = false;
        break;
      }
    }

    ans += all_on ? 1 : 0;
  } else {
    on[i] = true;
    bt(i+1);
    on[i] = false;
    bt(i+1);
  }
}

int main() {
  cin.tie(0); cin.exceptions(cin.failbit);
  scanf("%d%d", &n, &m);
  rep(i, 0, m){
    int n_switches;
    scanf("%d", &n_switches);
    rep(j, 0, n_switches){
      int sw;
      scanf("%d", &sw);
      bulb[i].PB(sw);
    }
  }

  rep(i, 0, m) scanf("%d", p+i);

  bt(1);
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#! /usr/bin/python3

# ABC119 A
import sys

def debug(fmt, *args):
    print(fmt, *args, file=sys.stderr)

def main():
    pass

if __name__ == "__main__":
    N = input()
    if N <= "2019/04/30":
        print("Heisei")
    else:
        print("TBD")
    #N = [int(x) for x in input().split()]
    #A = [tuple(int(x) for x in input().split()) for _ in N]
    #main()


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

using namespace std;


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

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

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

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
template< typename T >
using UnWeightedGraph = vector< vector< T > >;
template< typename T >
using Matrix = UnWeightedGraph< T >;


struct UnionFind
{
  vector< int > data;

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

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

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

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

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

int main()
{
  int V, E;
  cin >> V >> E;
  Edges< int > g;
  for(int i = 0; i < E; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    g.emplace_back(x, y, z);
  }
  cout << kruskal(g, V) << endl;
}


Measured memory_bytes: 4536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll a,b;
	cin>>a>>b;
	auto solve=[&](ll x){
		ll ret;
		ll sum=x+1;
		if(sum%4==0) ret=0ll;
		else if(sum%4==1) ret=x;
		else if(sum%4==2) ret=1ll;
		else if(sum%4==3) ret=1ll^x;
		return ret;
	};
	if(a) cout<<((solve(b))^(solve(a-1)))<<endl;
	else cout<<solve(b)<<endl;
}

Measured memory_bytes: 256
/*input
4 2
2 3
3 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	int cnt[10]={0};
	REP(i,6){
		int tmp;
		cin>>tmp;
		cnt[tmp]++;
	}
	REP(i,5) if(cnt[i]>=3){
		cout<<"NO\n";
		return 0;
	}
	cout<<"YES\n";
	return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define inf 1000000000000000000
#define N 1000000007
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

//try thinking from a different angle after spending some time
//edge cases when n=1,m=1.wrong variable in loop.if<->while;merge resize;LLONG_MAX
signed main()
{
	speed
	//global var
	int n,x;cin>>x>>n;
	map<int,bool> mp;
	for (int i = 0; i < n; ++i)
	{
		int tmp;
		cin>>tmp;mp[tmp]=1;
	}
	int ans=-1;
	for(int i=-1;i<=101;++i){
		if(!mp[i] and abs(i-x)<abs(ans-x)){
			ans=i;
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(void){
  int N;
  scanf("%d",&N);
  int A[2][N];
  for(int i=0;i<2;i++){
    for(int j=0;j<N;j++){
      scanf("%d",&A[i][j]);
    }
  }
  int max=0;

  for(int i=0;i<N;i++){
    int x=0;
    for(int j=0;j<=i;j++){
      x+=A[0][j];
    }
    for(int j=i;j<N;j++){
      x+=A[1][j];
    }
    if(x>max){
      max=x;
    }
  }
  printf("%d",max);
  return 0;
}



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

int main(){
	int a[200],b[200],sum[200],dight[200],line;
	for(int num=0;num<200;num++){
	dight[num]=0;a[num]=0;b[num]=0;
	}
	int fl=0;
	for(int num=0;num<200;num++){
	 // cout << "numA and numB"<< endl;
	 fl=0;
	 if(cin!=NULL){
	 cin >> a[num];
	 cin >> b[num];
	 }
	 else {
	 line=num-1;
	 break;
	 }
	 sum[num]=a[num]+b[num];
	 for(;fl!=1;){
	 if(sum[num]>=1){
	 sum[num]=sum[num]/10;
	 dight[num]++;
	 }
	 else fl=1;
    }
    }
    for(int num=0;num<line;num++){
    cout << dight[num]<< endl;
    }
  return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

const int INF=1e9;
const ll INFF=1e17;
const double EPS=1e-9;
const ll MOD=1e9+7;
const int MAXN=2e5+10;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,a[MAXN],pre[MAXN],suff[MAXN],ans=INFF;
	cin >> n;
	REP(i,n)cin >> a[i];
	pre[0]=a[0];FOR(i,1,n)pre[i]=pre[i-1]+a[i];
	suff[n-1]=a[n-1];for(int i=n-2;i>=0;i--)suff[i]=suff[i+1]+a[i];
	REP(i,n-1)ans=min(ans,abs(pre[i]-suff[i+1]));
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  constexpr int inf = 1e9;
  VV<> dp(n + 1, V<>(3, -inf));
  dp[n][1] = dp[n][2] = 0;
  for (int i = n - 1; i >= 0; --i) {
    for (int x = 1; x <= 2; ++x) for (int y = 1; y <= 2; ++y) {
      if (i + x > n or s.substr(i, x) == s.substr(i + x, y)) continue;
      dp[i][x] = max(dp[i][x], 1 + dp[i + x][y]);
    }
  }
  cout << max(dp[0][1], dp[0][2]) << '\n';
}

Measured memory_bytes: 11412
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    string S;
    cin >> S;
    ll ans = 0;
    char before = ' ';
    REP(i, S.size()) {
        if (before == S[i] || (i == S.size() - 2 && S[i] == S[i + 1])) {
            ans++;
            i++;
            before = ' ';
        } else {
            ans++;
            before = S[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

    int maxNum = 1;
    for (int i = 0; i < M; i++) maxNum <<= 1;
    maxNum--;
    
    if (K == 0)
    {
        for (int i = 0; i <= maxNum; i++)
            printf("%d %d ", i, i);
        printf("\n");
        return 0;
    }
    else if (M == 1 or K > maxNum)
    {
        cout << -1 << endl;
        return 0;
    }

    // cout << "notK " << notK << endl;
    for (int i = 0; i <= maxNum; i++)
    {
        if (i == K)
            continue;
        else
            printf("%d ", i);
    }
    printf("%d ", K);
    for (int i = maxNum; i >= 0; i--)
    {
        if (i == K)
            continue;
        else
            printf("%d ", i);
    }
    printf("%d \n", K);
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  int inf=1000000000000007;
  int n;cin>>n;
  vector<int> a(n+1,0);
  rep1(i,n)cin>>a[i];
  vector<int> sum(n+1,0);
  rep1(i,n)sum[i]=sum[i-1]+a[i];
  int res=0;
  sort(sum.begin(),sum.end());
  int before=1;
  int cnt=0;
  sum.push_back(inf);
  rep(i,n+2){
    if(sum[i]==before){
      cnt++;
    }
    else{
      before=sum[i];
      res+=cnt*(cnt-1)/2;
      cnt=1;
    }
  }
  cout<<res<<endl;
  rep(i,n+1){
    //cout<<a[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 5632
# in:   n t     20 195000
# out:  x y z   10000 5000 1000

n, t = gets.split
n = n.to_i
t = t.to_i

x = y = z = 0
t_temp = -1

(n+1).times do |i|
  (n+1-i).times do |j|
    k = n - i - j
    t_temp = t
    t_temp -= 10000 * i
    t_temp -= 5000 * j
    t_temp -= 1000 * k
    if t_temp == 0
      x = i
      y = j
      z = k
      break
    end
  end
  break if t_temp == 0
end

if t_temp != 0
  x = y = z = -1
end
puts "#{x} #{y} #{z}"


Measured memory_bytes: 14356
#include <algorithm>
#include <cstdio>
#include <set>
#include <vector>

using namespace std;

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

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

int K[30000];

int func(int n, int m)
{
    rep(i, n){
        scanf("%d", &K[i]);
        K[i] %= m;
    }
    
    int ans = 0;
    int offset = 0;
    set<int> S;
    
    rep(i, n){
        S.insert((m - offset) % m);
        offset = (offset + K[i]) % m;
        
        auto itr = S.lower_bound(m - offset);
        if(itr == S.begin()) itr = S.end();
        itr = --itr;
        ans = max(ans, (*itr + offset) % m);
    }
    
    return ans;
}
    
int main()
{
    int n, m;
    while(scanf("%d%d", &n, &m), n){
        printf("%d\n", func(n, m));
    }
}

Measured memory_bytes: 2308
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int a, b, c;
int main() {
    cin >> a >> b >> c;
    vector<int> vec={a, b, c};
    sort(vec.begin(), vec.end());
    cout << 10*vec[2] + vec[0] + vec[1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll m,n;
    cin>>n>>m;
    ll a[n+1][m+1],b[m+1],i,j,k,sum[n+1];
    for(i=1; i<=n; i++)
    {
      for(j=1; j<=m; j++)
      {
          cin>>a[i][j];
      }
    }
    for(i=1; i<=m; i++)
    {
        cin>>b[i];
    }
    for(i=1; i<=n; i++)
    {
        sum[i]=0;
    }
    for(i=1; i<=n; i++)
    {
        for(k=1; k<=m; k++)
        {
            sum[i]+=a[i][k]*b[k];
        }
    }
    for(i=1; i<=n; i++)
    {
        cout<<sum[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 3136
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main()
{
  char ch;
  cin >> ch;
  if(ch >= 'A' && ch <= 'Z')
    	cout << "A\n";
  else
    	cout << "a\n";
  return 0;
}

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

public class Main {
	
	public static int dfs(final int n, int deep, int[] array, int[] ans){
		//System.out.println(n + " " + deep + " " + Arrays.toString(array) + " " + Arrays.toString(ans));
		
		if(n == deep){
			return 0;
		}else if(array[deep] == ans[deep]){
			return dfs(n, deep + 1, array, ans);
		}else {
			final int diff = ans[deep] - array[deep];
			int ret = Integer.MAX_VALUE;
			
			for(int k = deep + 1; k <= n; k++){
				for(int i = deep; i < k; i++){
					array[i] = (10 + array[i] + diff) % 10;
				}
			
				ret = Math.min(ret, dfs(n, deep + 1, array, ans));
			
				for(int i = deep; i < k; i++){
					array[i] = (10 + array[i] - diff) % 10;
				}
			}
			
			return ret + 1;
		}
		
		
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int[] array = new int[10];
		int[] ans   = new int[10];
		
		while (true) {
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			char[] input1 = sc.next().toCharArray();
			for(int i = 0; i < n; i++){
				array[i] = input1[i] - '0';
			}
			
			char[] input2 = sc.next().toCharArray();
			for(int i = 0; i < n; i++){
				ans[i] = input2[i] - '0';
			}
			
			System.out.println(dfs(n, 0, array, ans));
			
		}

	}

}

Measured memory_bytes: 21596
#include<stdio.h>

#define MAX 10000
#define NIL -1

typedef struct node{
  int parent;
  int left;
  int right;
}Node;

Node array[MAX];

int num,dataD[MAX],dataH[MAX];
void Depth(int,int);
int Height(int);
int sibling(int);
void print(int);

int main(void){
  int v;
  int l;
  int r;
  int root = 0;
  int i;

  scanf("%d",&num);

  for(i = 0;i < num;i++){
    array[i].parent = NIL;
  }
    for(i = 0;i < num;i++){
      scanf("%d %d %d",&v,&l,&r);
      array[v].left = l;
      array[v].right = r;
      if(l != NIL){
        array[l].parent = v;
      }
      if(r != NIL){
        array[r].parent = v;
      }
    }
    for(i = 0;i < num;i++){
      if(array[i].parent == NIL){
        root = i;
      }
    }
      Depth(root,0);
      Height(root);
      for(i = 0;i < num;i++){
        print(i);
      }
      return 0;
}

void Depth(int u,int d){
  if(u == NIL){
    return;
  }
  dataD[u] = d;
  Depth(array[u].left,d + 1);
  Depth(array[u].right,d + 1);
}

int Height(int u){
  int h1 = 0;
  int h2 = 0;

  if(array[u].left != NIL){
    h1 = Height(array[u].left) + 1;
  }
  if(array[u].right != NIL){
    h2 = Height(array[u].right) + 1;
  }
  return dataH[u] = (h1 > h2 ? h1 : h2);
}

int sibling(int u){
  if(array[u].parent == NIL){
    return NIL;
  }
  if(array[array[u].parent].left != u && array[array[u].parent].left != NIL){
    return array[array[u].parent].left;
  }
  if(array[array[u].parent].right != u && array[array[u].parent].right != NIL){
    return array[array[u].parent].right;
  }
  return NIL;
}

void print(int u){
  int deg;

  printf("node %d: parent = %d, sibling = %d, ",u,array[u].parent,sibling(u));

  if(array[u].left != NIL){
    deg++;
  }
  if(array[u].right != NIL){
    deg++;
  }

  printf("degree = %d, depth = %d, height = %d, ",deg,dataD[u],dataH[u]);

  if(array[u].parent == NIL){
    printf("root\n");
  }
  else if(array[u].left == NIL && array[u].right == NIL){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}



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

using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;

ll dp[100][3][3];

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      dp[0][i][j] = !((i == j) ^ (s[0] == t[0]));
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (!((j == k) ^ (s[i] == t[i]))) {
          for (int jj = 0; jj < 3; jj++) {
            for (int kk = 0; kk < 3; kk++) {
              if (!((j == jj) ^ (s[i] == s[i - 1])) && !((k == kk) ^ (t[i] == t[i - 1])))  {
                dp[i][j][k] = (dp[i][j][k] + dp[i - 1][jj][kk]) % mod;
              }
            }
          }
        }
        //        cout << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      ans = (ans + dp[n - 1][i][j]) % mod;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

K = int(input())
cnt = 0
now = 0
if K%2==0:
    print(-1)
    exit()
s = set([0])
for _ in range(10**6+5):
    now += pow(10, cnt, K)*7
    now %= K
    if now==0:
        print(cnt+1)
        break
    s.add(now)
    cnt += 1
else:
    print(-1)

Measured memory_bytes: 156992
#include<stdio.h>
#include<string.h>
 int n,m,i,j;
char s[1000][9],x[9];
 int main(){ 
   scanf("%d",&n);
    while(n!=0){
        for(i=0;i<n*2;i++){
scanf("%s",s[i]);
}
        //printf("\nAKB%d\n",n); 
       scanf("%d",&m);   
     for(i=0;i<m;i++){  
          scanf("%s",x);     
       for(j=0;j<=n;j++){       
         if(x[0]==s[j*2][0]){    
                //strcpy(x,s[i]);   
                 x[0]=s[j*2+1][0];  
                  break;   
             }    
        }         
   printf("%c",x[0]);  
      }       
 printf("\n");  
      scanf("%d",&n);
    }    
     return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

int main(){
    ll N, M; cin >> N >> M;
    if (N % 2){
        rep(i, M){
            pt(i + 1, N - (i + 1));
        }
    }else{
        ll Mm = min((N / 2) / 2, M);

        rep(i, Mm){
            pt(i + 1, N - i);
        }
        rep(i, M - Mm){
            pt(Mm + i + 1, N - Mm - i - 1);
        }
    }

}

Measured memory_bytes: 3636
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = list(input())

    ans_dict = {"r":0, "s":0, "p":0}
    ix_list = [i for i in range(K)]

    for i in range(N):
        if i < K:
            ans_dict[T[i]] += 1
            #print(T[i])
        else:
            if T[i] == T[i-K]:
                T[i] = "t"
            else:
                ans_dict[T[i]] += 1
                #print(T[i])
    ans = (ans_dict["r"]*P) + (ans_dict["s"]*R) + (ans_dict["p"]*S)
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 7336
// Tue Jun 30 14:06:52 IST 2020  
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)        for(ii = (int)a ; ii < (int)b  ; ii++ )
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long    
#define MOD                998244353 
#define pb                 push_back
#define f1                 first 
#define s1                 second    
#define all(x)             (x).begin(),(x).end() 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
#define tough_nut          numeric_limits<int64>::min()

const double pi = 3.141592653589793238;
using namespace  std ;       
using namespace __gnu_pbds;
 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 3e5+7; 
const int INF = INT_MAX;
struct comp{
    bool operator()(const pair<int,int> A,const pair<int,int>& B)const{
        if(A.first == B.first)
            return A.second < B.second ;
        return A.first > B.first;
    } 
};    
int tests(){
    int n,m,k;
    int mask1,mask2;
    cin >> n >> m >> k;
    int ans = 0;
    int i,j;
    vector <vector <char>> a(n,vector <char> (m));
    forn(i,0,n)
        forn(j,0,m)
            cin >> a[i][j];
    forn(mask1,0,(1<<n)){ 
        forn(mask2,0,(1<<m)){
            
            vector <vector <char>> grid(a);
            forn(i,0,n)
                if(mask1&(1<<i))
                    grid[i][0] = '|';

            forn(j,0,m)
                if(mask2&(1<<j))
                    grid[0][j] = '|';
            forn(i,0,n)
                forn(j,1,m)
                    if(mask1&(1<<i))
                        grid[i][j] = grid[i][j-1];


            forn(j,0,m)
                forn(i,1,n)
                    if(mask2&(1<<j))
                        grid[i][j] = grid[i-1][j];
            int c = 0;
            forn(i,0,n)
                forn(j,0,m)
                    c += grid[i][j] == '#';
            ans += c == k;
        }
    }
    cout << ans << '\n';

    return 0;
}
int32_t main(){
    I__O ;     
    int cases = 1 ;  
    // cin >> cases ;  
    while(cases--) 
        tests(); 
     
    return 0 ; 
}

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

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

    int N;
    int a[100010];
    int b[100010];
    cin >> N;
    rep(i, N) cin >> a[i] >> b[i];
    int64_t plus = 0;
    rep(i, N) {
        int k = N - i - 1;
        plus += (b[k] - (a[k] + plus) % b[k]) % b[k];
    }
    
    cout << plus << endl;
    
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 999999999

    /*Solve*/
int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    if(a>b)swap(a,b);
    if(b>c)swap(b,c);
    if(a>c)swap(a,c);
    ll s=a*b;
    ll ans;
    if(c%2==1){ans=s;}else ans=0;
    cout << ans ;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            string s = Console.ReadLine();
            bool judge = false;
            if (s[0] == s[1] && s[1] == s[2]) judge = true;
            if (s[1] == s[2] && s[2] == s[3]) judge = true;
            Console.WriteLine(judge ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11092
K,N=list(map(int,input().split()))
A=list(map(int,input().split()))

A.append(K+A[0])

ans=0
maxdist=0
for i,a in enumerate(A):
    if i == len(A)-1:
        break
    dist = A[i+1]-a   
    ans += dist
    maxdist=max(maxdist,dist)
print(ans-maxdist)

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

vector<int> cut(vector<int> crd,int p,int c){
  vector<int> ret = crd;
  for(int i=0;i<c;++i) ret[i] = crd[i+p];
  for(int i=0;i<p;++i) ret[c+i] = crd[i];
  return ret;
}

int main(){
  int n,k;
  while(cin>>n>>k,n||k){
    vector<int> crd;
    for(int i=n;i>=1;--i) crd.push_back(i);
    while(k--){
      int p,c;
      cin >> p >> c;--p;
      crd = cut(crd,p,c);
    }
    cout << crd[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
def li():
    return list(map(int, input().split()))


def mi():
    return map(int, input().split())


def ii():
    return int(input())


S = input()
ACGT = ["A", "C", "G", "T"]

length = 0
max_length = 0

for i in range(len(S)):
    if S[i] in ACGT:
        for j in range(i, len(S)):
            if S[j] in ACGT:
                length += 1
            else:
                max_length = max(max_length, length)
                length = 0
                break
        max_length = max(max_length, length)
        length = 0

print(max_length)


Measured memory_bytes: 3064
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

H,W = inpl()
MAP = [inpl() for i in range(H)]

flag = False #コインを持っているか
ans = []
for y in range(H):
	if y%2 == 0:
		for x in range(W):
			if flag:
				ans.append([by,bx,y,x])
			if MAP[y][x]%2 == 1:
				flag = not flag
			bx,by = x,y
	else:
		for x in reversed(range(W)):
			if flag:
				ans.append([by,bx,y,x])
			if MAP[y][x]%2 == 1:
				flag = not flag
			bx,by = x,y

print(len(ans))
for a,zu,nya,n in ans:
	print(a+1,zu+1,nya+1,n+1)


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX_U 102
#define MAX_S 102
#define MAX_C 10002
#define MAX_T 102
#define MAX_N 102
#define MAX_D 102

using namespace std;

int pre1[MAX_U][MAX_S],pre2[MAX_C],S,T,U,N,O,D,e[MAX_T],c[MAX_T],h[MAX_N],a[MAX_N],dp[MAX_D][MAX_S];

int main(){
  rep(i,MAX_U)rep(j,MAX_S)pre1[i][j] = -IINF;
  rep(i,MAX_D)rep(j,MAX_S)dp[i][j] = -IINF;
  rep(i,MAX_C)pre2[i] = -IINF;

  cin >> S >> T >> U >> N >> O >> D;
  pre1[0][0] = pre2[0] = dp[0][S] = 0;
  rep(i,T)cin >> e[i] >> c[i];
  rep(i,N)cin >> h[i] >> a[i];

  rep(i,T)for(int j=U-1;j>=0;j--)rep(k,S+1)if(pre1[j][k] != -IINF){
      if( k + e[i] > S ) continue;
      pre1[j+1][k+e[i]] = max(pre1[j+1][k+e[i]],pre1[j][k]+c[i]);
    }

  rep(i,N)rep(j,MAX_C)if(pre2[j]!=-IINF){
    if( j + a[i] >= MAX_C ) continue;
    pre2[j+a[i]] = max(pre2[j+a[i]],pre2[j]+h[i]);
  }
  REP(i,1,MAX_C)pre2[i] = max(pre2[i],pre2[i-1]);

  rep(i,D){
    rep(j,S+1){
      rep(k,j+1){
	if(dp[i][j]==-IINF)continue;
	if(pre1[U][k]==-IINF)continue;
	if(pre2[pre1[U][k]] == -IINF) continue;
	int new_j = min( j + O - k , S );
	dp[i+1][new_j] = max(dp[i+1][new_j],dp[i][j]+pre2[pre1[U][k]]);
      }      
    }
  }

  int answer = -1;
  rep(i,MAX_S)answer = max(dp[D][i],answer);
  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 1284
from sys import exit

n, m = map(int, input().split())
s = input()[::-1]

res = []
pos = 0
while True:
    if pos + m >= n:
        res.append(n - pos)
        break

    step = m
    while s[pos + step] == '1':
        step -= 1
        if step == 0:
            print(-1)
            exit()
    
    pos += step
    res.append(step)
    
print(*res[::-1])

Measured memory_bytes: 84376