akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define vvbool vector<vector<bool>>
#define INF 100000000

struct UnionFind {
    //dにリンク情報とサイズ(負の値はサイズ)を入れる
    //正の値ならば親のID,負の数ならば自分は葉であり、値は自分の属しているグループの現在のサイズになっている
    //一つの配列にリンク情報とサイズに関しての情報が入っているのが優れているところ
    vector<int> d;

    //コンストラクタ
    //int n = 0 はnの初期化をするために入れている(コンストラクタでnの値を用いるため)
    //最初はすべてのデータが根であると仮定して-1(サイズが1)が入っている
    UnionFind(int n = 0): d(n,-1) {}

    //自分がどのグループに属しているのか探すfind関数->つまりは根を探す関数
    int find(int x){
        // d[x] < 0 -> 自分の情報が負の値 -> 自分は根である -> 自分の番号を返したらいい(だって自分が根なんだもの)
        if(d[x] < 0) return x;
        // 返り値で自分の根を探す->値がマイナスになるまで探し続ける
        //{d[x] =}を足すと、自分の親も更新されるようになる->次回から深くまで潜る必要がなくなる(途中経路の葉で親のデータは保存されているため)
        return d[x] = find(d[x]);
    }
    //小さいグループを大きいグループにくっつけるunite関数
    bool unite(int x,int y){
        //x,yの根を探し、その値を代入する
        x = find(x);
        y = find(y);
        //もし両方同じ根であるならスルー
        if(x == y) return false;
        //サイズが大きい方を左に持っていきたいため(後々の計算が左に右を足す計算をするため)、もし左の方がサイズ小さいならswapする
        //->サイズは負の値で保存されているため、左のサイズが小さいと値としては左が大きくなる
        if(d[x] > d[y]) swap(x,y);
        //xのサイズにyのサイズを足す
        d[x] += d[y];
        //yの根がxに変更される
        d[y] = x;
        return true;
        //くっつけたかの判断をすると解きやすくなる問題があるため、bool値で扱っている
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
    int size(int x){
        return -d[find(x)];
    }

};

//自分の周りに何人いるかを示すdeg配列
int deg[100005];
//ブロック関係にある人についての情報を保存するto関数
vint to[1000005];

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        //それぞれの横に人がいるのでどっちも++を行う
        deg[a]++;
        deg[b]++;
        uf.unite(a,b);
    }
    rep(i,k){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    rep(i,n){
        int ans = uf.size(i) - 1 - deg[i];
        for(int u:to[i]){
            //toに入っている者同士で同じ根にあるならば--を行う
            if(uf.same(i,u)) --ans;
        }
        printf("%d%c",ans,i==n-1?'\n':' ');
    }
    return 0;
}



Measured memory_bytes: 27776
s = input()[::-1]
counts = [0] * 2019
counts[0] = 1
digit = 1
sum = 0
for c in s:
  sum = (sum + int(c) * digit) % 2019
  digit = digit * 10 % 2019
  counts[sum] += 1

result = 0
for c in counts:
  result += c * (c - 1) // 2

print(result)

Measured memory_bytes: 9380
x = int(input())
lst = []
for a in range(2):
    for b in range(2):
        for c in range(2):
            for d in range(2):
                for e in range(2):
                    for f in range(2):
                        lst.append(100*a + 101*b + 102*c + 103*d + 104*e + 105*f)
ans = 0
for n in lst[1:]:
    tmp = x % n
    if tmp in lst:
        ans = 1
        break

print(ans)

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

int main(){
    int A, b, C, D;
    cin >> A >> b >> C >> D;
    if (A<=C&&D<=b) {
        cout << D-C << endl;
        return 0;
    }
    else if (C<A && b<D) {
        cout << b-A << endl;
        return 0;
    }
    else if ((b>C && D>b)||(A<C && C<b)) {
        cout << b-C << endl;
        return 0;
    }
    else if ((A<D && C<A)||(A<D && D<b)) {
        cout << D-A << endl;
        return 0;
    }
    else if (b<=C || D<=A) cout << 0 << endl;
}


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

namespace abc131_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var l = CIn.ReadInt();

      var a = new int[n];

      var ans = 0;
      var absmin = int.MaxValue;
      
      for (var i = 0; i < n; i++)
      {
        ans += l + i;
        if (Math.Abs(absmin) > Math.Abs(l + i)) absmin = l + i;
      }

      Console.WriteLine(ans - absmin);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

Measured memory_bytes: 13396
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;
// const double PI = M_PI;

string S, T;
// vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> S >> T;
  // A.resize(N);
  // rep(i, N) { cin >> A[i]; }

  int ans = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != T[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3448
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n, m; cin >> n >> m;
  int cnts[51] = {0};
  rep(i, m) {
    int a, b; cin >> a >> b;
    cnts[a]++;
    cnts[b]++;
  }
  for (int i = 1; i <= n; i++) {
    outl(cnts[i]);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 888
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = a+b;
        int num = Integer.parseInt(c);

        int num2 = (int)Math.sqrt(num);

        if(num ==(num2*num2)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }




        
    }
}


Measured memory_bytes: 21716
#include<stdio.h>
int main(void)
{
	int a;
	while(scanf("%d",&a)!=EOF){
		a=a%39;
		if(a==0){
			printf("3C39\n");
		}
		else{
			printf("3C%02d\n",a);
		}
	}
	return 0;
}

Measured memory_bytes: 1044
import itertools
l = list(map(int, input().split()))
li = []
for i in range(l[2]):
    li += [list(map(int, input().split()))]

araw = [i for i in range(1,l[1] + 1)]
a = []
for v in itertools.combinations_with_replacement(araw, l[0]):
    a += [list(v)]

r = []
for i in a:
    r_s = 0
    for j in li:
        if  i[j[1]-1] - i[j[0]-1] == j[2]:
            r_s += j[3]
    r += [r_s]
    
print(int(max(r)))

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

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

typedef long long ll;

int main(void){
	int n, k;
	cin >> n >> k;

	vector<int> v(n);
	REP(i, n){
		cin >> v[i];
	}

	ll ans = 0;
	priority_queue<int, vector<int>, greater<int> > queue;
	for(int r = 0; r <= MIN(n, k); r++){
		for(int l = 0; r+l <= MIN(n, k); l++){
			while(!queue.empty()) queue.pop();
			ll sum = 0;
			REP(i, r){
				sum += v[i];
				queue.push(v[i]);
			}
			REP(i, l){
				sum += v[n-1-i];
				queue.push(v[n-1-i]);
			}

			for(int i = 0; i < k-r-l; i++){
				if(queue.empty()) break;
				if(queue.top() < 0){
					sum -= queue.top();
					queue.pop();
				}else{
					//cout << r << ' ' << l << ' ' << i << endl;
					break;
				}
			}

			if(sum > ans) ans = sum;
		}
	}

	cout << ans << endl;

	return 0;
}


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

map<long long, int> calc(long long x) {
	map<long long, int> ret;
	for (long long i = 2; i * i <= x; i++) {
		while (x % i == 0) {
			ret[i]++;
			x /= i;
		}
	}
	if (x > 1) ret[x]++;
	return ret;
}

int f (int x) {
	return (x * (x + 1) / 2LL);
}

int main() {
	long long n;
	cin >> n;

	int ans = 0;
	for (const auto [_, e] : calc(n)) {
		int ok = 1, ng = 50;
		while (abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;
			if (f(mid) <= e) ok = mid;
			else ng = mid;
		}
		ans += ok;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int a[n],c[n],ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        int b;
        cin>>b;
        ans+=b;
    }
    for(int i=0;i<n-1;i++){
        cin>>c[i];
    }
    for(int i=0;i<n-1;i++){
        if(a[i]+1==a[i+1]){
            ans+=c[a[i]-1];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string x, y;
int N, W;
int v[1001], w[1001];
int a[101][10001];
int main()
{
	cin >> N >> W;
	for(int i=1; i<=N; i++)
	{
		cin >> v[i] >> w[i];
	}
	for(int i=0; i<=N; i++)
	{
		a[i][0]=0;
	}
	for(int i=0; i<=W; i++)
	{
		a[0][i]=0;
	}
	for(int i=1; i<=N; i++)
	{
		for(int j=1; j<=W; j++)
		{
			if(j<w[i])
			{
				a[i][j]=a[i-1][j];
			}
			else
			{
				a[i][j]=max(a[i-1][j], a[i-1][j-w[i]]+v[i]);
			}
		}
	}
	cout << a[N][W] << endl;
	return 0;
}

Measured memory_bytes: 7060
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif


int n, a[N];
map<int,int> s[2];

struct Sum {
    void add(int id, int value)
    {
        if (a[0].second == id) {
            a[0].first = std::max(a[0].first, value);
        } else if (a[1].first < value) {
            a[1] = {value, id};
        }
        if (a[0].first < a[1].first) {
            std::swap(a[0], a[1]);
        }
    }

    int ask(int id)
    {
        if (a[0].second != id) {
            return a[0].first;
        }
        return a[1].first;
    }

    std::pair<int, int> a[2] = {{0, -1}, {0, -1}};
} f[2];

int main() {
	scanf("%d", &n);
	REP(i,1,n) ++s[i&1][rd()];
	REP(i,0,1) for (auto &t:s[i]) f[i].add(t.x,t.y);
	int ans = f[0].ask(-1)+f[1].ask(f[0].a[0].y);
	ans = max(ans, f[1].ask(-1)+f[0].ask(f[1].a[0].y));
	printf("%d\n",n-ans);
}








Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N;
	static int ans;
	static int[] rule;
	static int len;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			char[][] x = new char[5][N];
			for (int i = 0; i < 5; ++i) {
				x[i] = sc.next().toCharArray();
			}
			boolean[] exist = new boolean[N];
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < 5; ++j) {
					if (x[j][i] == 'X') exist[i] = true;
				}
			}
			int l = 0;
			int r = N - 1;
			while (!exist[l]) {
				++l;
			}
			while (!exist[r]) {
				--r;
			}
			len = r - l + 1;
			for (int i = 0; i < 5; ++i) {
				for (int j = 0; j < len; ++j) {
					x[i][j] = x[i][j + l];
				}
			}
			rule = new int[len+1];
			OUTER: for (int i = 1; i < len; ++i) {
				for (int j = 0; j < 5; ++j) {
					for (int k = i; k < len; ++k) {
						if (x[j][k] == 'X' && x[j][k - i] == 'X') {
							rule[i] = 1;
							continue OUTER;
						}
					}
				}
			}
			int[] used = new int[len * 11];
			for (int i = 0; i < len; ++i) {
				used[i] = rule[i];
			}
			ans = len * 10;
			dfs(0, 0, used);
			System.out.println(ans);
		}
	}

	static void dfs(int pos, int depth, int[] used) {
		if (depth == 9) {
			ans = Math.min(ans, pos + len);
			return;
		}
		if (pos + len + 10 - depth > ans) return; // pruning
		for (int i = 1; i <= len; ++i) {
			if (used[pos + i] > 0) continue;
			for (int j = 1; j < len; ++j) {
				used[pos + i + j] += rule[j];
			}
			dfs(pos + i, depth + 1, used);
			for (int j = 1; j < len; ++j) {
				used[pos + i + j] -= rule[j];
			}
		}
	}

}

Measured memory_bytes: 12000
def zalg(pattern, text):
  L = pattern + "$" + text
  N = len(L)
  Z = [0] * (N)
  i = 1
  j = 0
  while i < N:
    while i + j < N and L[j] == L[i + j]:
      j += 1
    Z[i] = j
    if j == 0:
      i += 1
      continue
    k = 1
    while i + k < N and k + Z[k] < j:
      Z[i + k] = Z[k]
      k += 1
    i += k
    j -= k
  return Z

N = int(input())
S = input()

ans = 0
for i in range(N):
  Z = zalg(S[i:], S)
  for j in range(1, N):
    ans = max(ans, min(Z[-j], N - i - j))

print(ans)


Measured memory_bytes: 86364
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput input)
        {
            var n = input.ReadInt;
            var k = input.ReadInt;

            WriteLine((1 + n) / 2 >= k ? "YES" : "NO");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private readonly char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n;
  cin >> n;
  set<string> st;
  string pre = "";
  bool ok = true;
  REP(i, n) {
    string s;
    cin >> s;
    int preSize = st.size();
    st.insert(s);
    int nowSize = st.size();

    if (i == 0) {
      pre = s;
      continue;
    }

    if (s[0] != pre[pre.size() - 1]) ok = false;
    pre = s;
    if (preSize == nowSize) ok = false;
  }
  print(ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
  vector<int> N(4);
  rep(i, 4){
    cin >> N.at(i);
  }
  vector<int> a = {1, 9, 7, 4};
  rep(i, 4){
    if(count(N.begin(), N.end(), a.at(i)) != 1){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

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

int main(){
    string s,t,u;
    int a,b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(u==s) a-=1;
    else b-=1;
    cout << a << ' ' << b << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    
    int ans = 0;
    rep(i,n){
        int a;
        cin >> a;
        if((i+1) % 2 == 1 && a % 2 == 1){
            ans++;
        }
    }
    
   	
  	
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3592
N, X = map(int, input().split())

def fac(n):
    if n == 0:
        return 1
    else:
        return 2 * fac(n-1) + 3

def rec(x, n, tmp):
    if n == 0:
        return tmp + 1
    m = fac(n)
    if x == 0:
        return tmp + 0
    elif x == m-1:
        return tmp + (m+1)//2
    elif x == (m-1)//2:
        return tmp + (m+3)//4
    elif 0 < x < (m-1)//2:
        return rec(x-1, n-1, tmp)
    else:
        return rec(x-(m+1)//2, n-1, tmp+(m+3)//4)

print(rec(X-1, N, 0))

Measured memory_bytes: 3064
/*

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  string s;cin>>s;
  cout<<(s[s.size()-1]!='s'?s+"s":s+"es")<<endl;
}


Measured memory_bytes: 3636
#!/usr/bin/env python3

S = input()

A = [-1] * (len(S) + 1)

if S[-1] == '>':
    A[len(S)] = 0
if S[0] == '<':
    A[0] = 0
for i in range(len(S) - 1):
    if S[i] == '>' and S[i+1] == '<':
        A[i+1] = 0

for i in range(len(S)):
    if S[i] == '<' and A[i] > A[i+1]:
        A[i+1] = A[i] + 1

for i in reversed(range(len(S))):
    if S[i] == '>' and A[i] <= A[i+1]:
        A[i] = A[i+1] + 1

ans = 0
for a in A:
    ans += a
print(ans)


Measured memory_bytes: 29164
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n, A = 1e6;
	vector<int> u(A+1);
	cin>>n;
	for(int i=0,x;i<n;++i){
		cin>>x;
		u[x]++;
	}
	
	for(int i=2;i<=A;++i){
		int s = 0 ;
		for(int j=i;j<=A;j+=i) s+=u[j];
		if(s>1){
			int g = 0;
			for(int i=1;i<=A;++i) if(u[i]) g = gcd(g,i);
			if(g==1){
				cout<<"setwise coprime"<<endl;
			}else cout<<"not coprime"<<endl;
			
			
			return 0;
		}
	}
	
	
	cout<<"pairwise coprime"<<endl;
	
	
	
	return 0;
}


Measured memory_bytes: 7096
from functools import cmp_to_key

N = int(input())
SN = []
for i in range(N):
    SN.append(input().split())
    SN[i].append(i + 1)


def cmp(a, b):
    if a[0] == b[0]:
        if int(a[1]) == int(b[1]): return 0
        return 1 if int(a[1]) <= int(b[1]) else -1
    return -1 if a[0] <= b[0] else 1

def cmpstr(a, b):
    return cmp(a, b)

sorted_SN = sorted(SN, key=cmp_to_key(cmpstr))

answer = "\n".join([str(sorted_SNi[2]) for sorted_SNi in sorted_SN])

print(answer)


Measured memory_bytes: 3572
#include <iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
#include<string.h>
using namespace std;
// log10(x)+1  number of digits 
void bubblesort(int arr[], int n);
int main()
{
	int arr[10000];
	int n,m;
	long long sumdAssignments = 0;
	cin >> n>>m;
	for (int i = 0; i < m; i++)
	{
		cin >> arr[i];
		sumdAssignments += arr[i];
	}
	if (n - sumdAssignments < 0)
	{
		cout << -1;
	}
	else
	{
		cout << n - sumdAssignments;
	}
}
void bubblesort(int arr[], int n)
{
	int i = 0, j = 0;
	for (; i < n - 1; i++)
	{
		for (; j < n - 1 - i; j++)
		{
			if (arr[j] > arr[j + 1])
			{
				swap(*&arr[j], *&arr[j + 1]);
			}
		}
	}
}

Measured memory_bytes: 3660
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
#define DD 1
#else
#define DD 0
#endif
#define Debug if(DD) printf("line %d\n",__LINE__)
#define deb(x) if(DD) cerr<<#x<<'='<<x<<endl
#define debug if(DD) printf
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void gg1(){write2(-1);exit(0);}
	void gg2(){puts("NO");exit(0);}
	
	const double eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int N=1e6+10;
	
	int a[N],mx[N];
	void main()
	{
		int n=qread();fo(i,1,n) a[i]=qread();
		fo(i,1,n)
		{
			int num=a[i];
			for(int d=2;d*d<=num;d++) if(num%d==0)
			{
				int ct=0;while(num%d==0) num/=d,ct++;
				chmax(mx[d],ct);
			}if(num>1) chmax(mx[num],1);
		}
		ll sum=1;fo(i,1,N-1) sum=sum*qpower(i,mx[i])%MOD;deb(sum);
		ll ans=0;fo(i,1,n) add(ans, sum*invm(a[i])%MOD );write(ans);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	#endif
	srand(time(0));
	mine::main();
	if(DD) cerr<<"Time: " <<1.0*clock()/CLOCKS_PER_SEC<<"s";
}

Measured memory_bytes: 4096
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    data_set;
#define rep(i,l,r)   for(int i=(l);i<(r);i++)
#define deb(x)     cout << (#x) << " = " << (x) << endl
#define here cout << " Hey!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld EPS = 1e-12;
const ld PI = 3.141592653589793116;

int32_t main()
{
	SYNC
	int n; cin >> n;
	vi v(n);
	int tot_xor = 0;
	rep(i,0,n) {
		cin >> v[i];
		tot_xor ^= v[i];
	}
	rep(i,0,n)
		cout << (v[i] ^ tot_xor) << ' ';
	return 0;
}

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

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> g[n];            // グラフ
    vector<int> ans(n, -1);      // 答え(自分自身を除くので -1 しておく)
    vector<int> idx(n);          // 各頂点が属する連結成分の index
    vector<int> sz;              // 各連結成分のサイズ
    vector<bool> seen(n, false);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        ans[a]--; ans[b]--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    // bfs で各頂点が属する連結成分の index を求める
    int cnt = 0;
    for (int s = 0; s < n; s++) if (not seen[s]) {
        idx[s] = cnt++;
        queue<int> que;
        que.emplace(s);
        while (not que.empty()) {
            int v = que.front();
            que.pop();
            if (seen[v]) continue;
            seen[v] = true;
            for (int u : g[v]) if (not seen[u]) {
                idx[u] = idx[s];
                que.emplace(u);
            }
        }
    }

    sz.resize(cnt, 0);
    for (int i : idx) sz[i]++;
    for (int i = 0; i < n; i++) ans[i] += sz[idx[i]];

    for (int i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (idx[a] == idx[b]) {
            ans[a]--;
            ans[b]--;
        }
    }

    for (int i = 0; i < n; i++) cout << ans[i] << '\n';

    return 0;
}

Measured memory_bytes: 7928
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;

typedef long long ll;
ll mod = 1000000007;
#define SIZE 1000010
ll inv[SIZE + 1];
ll kai[SIZE + 1];
ll invkai[SIZE + 1];
void invinit() {
    inv[1] = 1;
    for (ll i = 2; i <= SIZE; i++) {
        inv[i] = mod - (mod / i)*inv[mod%i] % mod;
    }
    kai[0] = invkai[0] = 1;
    for (ll i = 1; i <= SIZE; i++) {
        kai[i] = kai[i - 1] * i%mod;
        invkai[i] = invkai[i - 1] * inv[i] % mod;
    }
}

ll com(ll a, ll b) {
    if (b < 0 || a < b) return 0;
    return (invkai[b] * invkai[a - b]) % mod*kai[a] % mod;
}

ll po(ll a, ll b) {
    if (b == 0)return 1;
    ll z = po(a, b / 2);
    z = z*z%mod;
    if (b % 2 == 1) z = z*a%mod;
    return z;
}

int main() {
    invinit();
    ll x,y; cin >> x >> y;
    if ((x + y) % 3) {
        cout << 0 << "\n";
        return 0;
    }
    ll m = (2 * y - x) / 3;
    ll n = (2 * x - y) / 3;
    if (m < 0 || n < 0) {
        cout << 0 << "\n";
        return 0;
    }
    ll ans = com(m + n, n);
    cout << ans << "\n";
}

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

int main() {
    char a, b;
    cin >> a >> b;

    cout << "<>="[(a > b) + (a == b) * 2] << endl;

    return 0;
}

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

long long N, X[1009], Y[1009], H[1009];
vector<tuple<long long, long long, long long>> vec;

int main () {

    cin >> N;
    tuple<long long, long long, long long> G = make_tuple(-1, -1, -1);

    for (int i = 1; i <= N; i++) {
        cin >> X[i] >> Y[i] >> H[i];
        if (H[i] >= 1) G = make_tuple(X[i], Y[i], H[i]);
    }

    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            long long V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j);
            V = max(V, 0LL);
            bool flag = true;

            for (int k = 1; k <= N; k++) {
                long long VV = V - abs(X[k] - i) - abs(Y[k] - j);
                VV = max(VV, 0LL);
                if (H[k] != VV) {
                    flag = false;
                }
            }
            if (flag) {
                vec.push_back(make_tuple(i, j, V));
            }
        }
    }

    if (vec.size() == 1) {
        cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main (){
    int N;
    scanf("%d",&N);
    int h[N];
    for (int i = 0; i < N; i++){
        scanf("%d",&h[i]);
    }
    bool flag=1;
    h[0]--;
    for (int i = 1; i < N; i++){
        if(h[i-1] > h[i]) flag=false;
        else if(h[i-1]==h[i]) h[i]++;
        h[i]--;
    }
    if(flag) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>

int main(void)
{
  for( ; ; ){
    int h;
    int m[16][16];

    scanf("%d", &h);
    if(!h) break;

    for(int i = 0;i < h; i++)
      for(int j = 0;j < 5; j++)
        scanf("%d", m[h - i - 1] + j);

    int ans = 0;
    for( ; ; ){
      /* 水平に並んだブロックを探す */
      for(int i = 0;i < h; i++){
        int pre = m[i][0], cnt = 1;
        for(int j = 1;j < 5; j++){
          if(pre == m[i][j])
            cnt++;
          else{
            if(cnt >= 3){
              ans += pre * cnt;
              for(int k = 1;k <= cnt; k++) m[i][j - k] = 0;
            }
            pre = m[i][j]; cnt = 1;
          }
        }
        if(cnt >= 3){
          ans += pre * cnt;
          for(int k = 1;k <= cnt; k++) m[i][5 - k] = 0;
        }
      }

      /* ブロックを落とす */
      bool flag = true; // 連鎖が終わってる?
      for(int i = 1;i < h; i++){
        for(int j = 0;j < 5; j++){
          if(m[i][j] == 0 || m[i - 1][j] != 0) continue;
          int k = i - 1;
          for( ;k - 1 >= 0 && m[k - 1][j] == 0; k--) ;
          std::swap(m[k][j], m[i][j]);
          flag = false;
        }
      }

      if(flag) break;
    }
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 1028
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

const int INF = 1001001001;

int a[12][12];

int main()
{
    int n,m,x; cin >> n >> m >> x;
  	vector<int> c(n);
    rep(i,n){
      cin >> c[i];
      rep(j,m) cin >> a[i][j];
    }
  	int ans = INF;
	rep(s,1<<n){ // 2^n-1回ループ
      int cost = 0;
      vector<int> d(m);
      rep(i, n){
        if(s>>i&1){  // i回右シフトしたときの１の位が１（i番目を買う）
          cost += c[i];
          rep(j,m) d[j] += a[i][j];
        }
      }
      bool ok = true;
      rep(j,m) if(d[j] < x) ok = false;
      if(ok) ans = min(ans,cost);
    }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
      
  return 0;
}

/*
g++ c.cpp
./a.out

oj d https://atcoder.jp/contests/abc167/tasks/abc167_c
oj t
*/


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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll n, m;
  cin >> n >> m;
  if (n == 1) {
    cout << m << '\n';
    return 0;
  }

  ll ans = 0;
  for (ll i = 1; i * i <= m; ++i) {
    if (m % i != 0) {
      continue;
    }

    if (m / i >= n && ans < i) {
      ans = i;
    }

    int j = m / i;
    if (m / j >= n && ans < j) {
      ans = j;
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define FOR(i, a, n, step) for (int (i) = (a); (i) < (int)(n); (i) += (step))
#define ROF(i, a, n, step) for (int (i) = (a); (i) >= (int)(n); (i) -= (step))
#define FOREACH(it, v) for (auto (it) : (v))

using namespace std;

typedef unsigned long long ull;
typedef long long ll ;
typedef long double ld;
typedef pair <int, int> pii;

template <class T>
const bool is_impar(const T &x) {return (bool) (x & 1);}

ll k;
string s;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s >> k;
    int poz = 0;
    while (poz < sz(s) && s[poz] == '1')
        poz++;
    if (poz == sz(s))
        return !(cout << 1);
    if (poz + 1 > k)
        return !(cout << 1);
    return !(cout << s[poz]);

}


Measured memory_bytes: 256
n=gets.to_i
s=gets.chars
count = 0
sum = 0
n.times do |i|
  j = i+1
  k = i+2
  while k<n
    count += 1 if [s[i],s[j],s[k]].uniq.size == 3
    j+=1
    k+=2
  end
end
puts s.count("R") * s.count("G") * s.count("B") - count

Measured memory_bytes: 15184
n=int(input())
d=list(map(int,input().split()))

mod=998244353
from collections import Counter
c=Counter(d)
if not(d[0]==0 and sorted(d)[1]!=0):
  print(0)
  exit()
d.sort()
ans=1
for i in range(1,d[-1]+1):
  if c[i]==0:
    ans*=0
  else:
    ans*=c[i-1]**c[i]
  ans%=mod
print(ans)


Measured memory_bytes: 19808
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

def get_prime(n, count = {p: 0 for p in primes}):
    for p in primes:
        cp = n
        while cp != 0 and cp % p == 0:
            count[p] += 1
            cp = cp // p
    return count

cnt = {p: 0 for p in primes}
for i in range(1, int(input())+1):
    get_prime(i, cnt)

res = 0
for p1 in primes:
    if cnt[p1] >= 4:
        for p2 in primes:
            if cnt[p2] >= 4 and p1 > p2:
                for p3 in primes:
                    if cnt[p3] >= 2 and p3 != p1 and p3 != p2:
                        res += 1

for p1 in primes:
    if cnt[p1] >= 14:
        for p2 in primes:
            if cnt[p2] >= 4 and p1 != p2:
                res += 1

for p1 in primes:
    if cnt[p1] >= 24:
        for p2 in primes:
            if cnt[p2] >= 2 and p1 != p2:
                res += 1

for p1 in primes:
    if cnt[p1] >= 74:
        res += 1

print(res)


Measured memory_bytes: 3064
N = int(input())
H = [int(i) for i in input().split()]

dp = [0]*N
dp[1] = abs(H[0] - H[1])
for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
print(dp[-1])

Measured memory_bytes: 13928
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int b[100],m,n,x,y,z;
  int sm;
  vector<pair<int,pair<int,int> > > a;
  while(cin>>n>>m&&n+m){
    a.clear();
    for(i=0;i<m;i++){
      cin>>x>>y>>z;
      a.push_back(make_pair(z,make_pair(x,y)));
    }
    sort(a.begin(),a.end());
    memset(b,-1,sizeof(b));
    sm=0;
    for(i=0;i<m;i++){
      z=a[i].first;
      x=a[i].second.first;
      y=a[i].second.second;
      if(0){
      }else if(b[x]==-1&&b[y]==-1){
	b[x]=b[y]=i;
	sm+=z;
      }else if(b[x]==-1||b[y]==-1){
	b[x]=b[y]=max(b[x],b[y]);
	sm+=z;
      }else if(b[x]!=b[y]){
	for(j=0;j<n;j++){
	  if(j!=y&&b[j]==b[y])
	    b[j]=b[x];
	}
	b[y]=b[x];
	sm+=z;
      }
    }
    cout<<sm<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
// Last Change: 09/10/2019 12:48:01.
// 変化するのは両端のみであることに注目
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  ll cnt = 0;
  for (size_t i = 0; i < S.size() - 1; ++i) {
    if (S[i] == S[i + 1]) {
      ++cnt;
    }
  }

  ll ans = min(2 * K + cnt, N - 1);
  cout << ans << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std ; 
typedef long long ll;
#define forn(i,e) for(ll i=0; i<e; i++)
#define endl "\n"
#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PB push_back 
#define MP make_pair
#define F first
#define S second
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}


int main()
{


zoom;
    
ll n ; cin >> n ; 
ll a[n] ,b[n]  ; 
forn(i,n)
{
    cin >> a[i] ; 
}
forn(i,n)
{
    cin >> b[i] ; 
}

ll pa[n+1] ; 
ll pb[n+1] ;

pa[0] = 0 ; 
pb[0] = 0 ;
forn(i,n)
{
    pa[i+1] = pa[i] + a[i] ; 
    pb[i+1] = pb[i] + b[i] ; 

}
ll maks = 0 ; 
for(ll i = 1 ; i <= n ; i++)
{
     
    maks = max(maks , pb[n] - pb[i-1] + pa[i]) ; 
    //cout << pb[n] - pb[i-1] + pa[i] << endl ;
}

cout << maks ; 




}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()

#define MAX_N 100
#define MAX_M 100

int
main(int argc, char** argv)
{
	int a[MAX_N][MAX_M];
	int b[MAX_M];
	int c;
	int n, m;
	int i, j;

	scanf("%d %d\n", &n, &m);
	for (i = 0; i < n; ++i)
	{
		for (j = 0; j < m; ++j)
			scanf("%d", &a[i][j]);
	}

	for (i = 0; i < m; ++i)
		scanf("%d", &b[i]);

	for (i = 0; i < n; ++i)
	{
		c = 0;
		for (j = 0; j < m; ++j)
			c += a[i][j] * b[j];

		printf("%d\n", c);
	}

	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
string s;
int numd,numpd;
int main(){
	cin>>s;
	if(s[0]=='?') s[0]='D';
	for(int i=1;i<s.size();i++){
		if(s[i]=='?'){
			s[i]='D';
		}
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3764
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  int n,i;
  char buf[50],*token;
  int result = 0;
  scanf("%d",&n);
  int v[n],c[n];
  for(i=0;i<n;++i){
    scanf("%d",&v[i]);
  }
  for(i=0;i<n;++i){
    scanf("%d",&c[i]);
  }
  for(i=0;i<n;++i){
    if(c[i] < v[i] ){
      result += v[i] - c[i];
    }
  }
  /*
  for(i=0;i<n;++i){
    printf("%d ",v[i]);
  }
  printf("\n");
  for(i=0;i<n;++i){
    printf("%d ",c[i]);
  }
  printf("\n");*/
  printf("%d\n",result);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x,y,a,b,c;
  cin >> x >> y >> a >> b >>c;
  vector<ll> p(a),q(b),r(c);
  rep(i,a) cin >> p[i];
  rep(i,b) cin >> q[i];
  rep(i,c) cin >> r[i];

  sort(p.rbegin(),p.rend());
  sort(q.rbegin(),q.rend());
  sort(r.rbegin(),r.rend());

  vector<ll> can;
  rep(i,x) can.pb(p[i]);
  rep(i,y) can.pb(q[i]);
  rep(i,c) can.pb(r[i]);
  sort(can.rbegin(),can.rend());

  ll ans =0;
  rep(i,x+y) ans += can[i];
  cout << ans << endl;
    
  return 0;
    

}


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

//int gcd(int a, int b){
//	return b==0 ? a : gcd(b, a%b);
//}

int32_t main(void){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n, k;
	cin>>n>>k;
	int *h = new int[n];
	int *ans = new int[n];
	rep(i, 0, n)
	{
		cin>>h[i];
		ans[i] = INT_MAX;
	}
	ans[0] = 0;
	ans[1] = abs(h[1]-h[0]);
	int start;
	rep(i, 2, n)
	{
		if(i-k < 0) start = 0;
		else start = i-k;
		rep(j, start, i)
		{
			ans[i] = min(abs(h[i]-h[j])+ans[j], ans[i]);
		}
	}
	cout<<ans[n-1];
	delete [] h;
	delete [] ans;
}

Measured memory_bytes: 1792
"""
~~ Author : Bhaskar
~~ Dated : 31~05~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 10**18
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")

def solve():
    n = int(sys.stdin.readline())
    a = list(map(int,sys.stdin.readline().split()))
    ans =  1
    flag = False
    for i in a:
        ans *= i
        # print(ans)
        if ans > mod:
            flag = True
            break
    if 0 in a:
        print(0)
    else:
        if not flag:
            print(ans)
        else:
            print(-1)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 82580
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    string prev = string(1, S[0]);
    string buf = "";
    int cnt = 1;
    rep(i,1,S.size()){
        buf += S[i];
        //cout << i << "," << prev << "," << buf << endl;
        if(prev == buf){
            continue;
        }
        prev = buf;
        buf = "";
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] wjy) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] graph = new int[n][n];
		for (int i=0;i<n;i++) {
			int u = sc.nextInt();
			int k =sc.nextInt();
			for (int j=0;j<k;j++) {
				graph[u-1][sc.nextInt()-1]=1;
			}
		}
		sc.close();
		for (int i=0;i<n;i++) {
			for (int j=0;j<n-1;j++) {
				System.out.print(graph[i][j]+" ");
			}
			System.out.print(graph[i][n-1]);
			System.out.println();
		}
	}
}


Measured memory_bytes: 32072
#include <stdio.h>
#include <string.h>
#define MAX 20001

typedef struct dx{
  int id;
  int s;
}dx;

void push1(int S[],int x,int *t){
  S[*t]=x;
  (*t)++;
}

void push2(dx S[],int id,int s,int *t){
  S[*t].id=id;
  S[*t].s=s;
  (*t)++;
}

int pop(int S[],int *t){
  (*t)--;
  return S[*t];
}

void Union(dx S[],int *t){
  int i;
  for(i=(*t)-1;i>0;i--){
    if(S[i].id < S[i-1].id){
      (*t)--;
      S[i-1].id=S[i].id;
      S[i-1].s+=S[i].s;
    }
  }
}

int main(){
  int i,j,id,stack1[MAX],top1=0,top2=0,sum=0;
  char str[MAX];
  dx stack2[MAX];

  scanf("%s",str);
  for(i=0;i<strlen(str);i++){

    switch(str[i]){
    case '\\':push1(stack1,i,&top1);
      break;
    case '/' :if(top1==0)break;
      id=pop(stack1,&top1);
      sum+=(i-id);
      push2(stack2,id,i-id,&top2);
      Union(stack2,&top2);
      break;
    }

  }
  printf("%d\n",sum);
  if(top2 == 0)printf("%d\n",top2);
  else {
    printf("%d ",top2);
    for(i=0;i<top2-1;i++)printf("%d ",stack2[i].s);
    printf("%d\n",stack2[top2-1].s);
  }
  return 0;
}



Measured memory_bytes: 2108
my $s = <STDIN>;
chomp $s;
my ($A,$B,$N) = split(/ /,$s);

my $max =0;
if(($B-1)>$N ){
    my $i = $N;
    my $cal = int(($A*$i)/$B)- $A*int($i/$B);
    print "$cal";exit;
}
for(my $i=$B-1;$i<=$B;$i=$i+$B){
   my $cal = int(($A*$i)/$B)- $A*int($i/$B);
   if($cal >$max){
     $max = $cal;
   }
}

print "$max";

Measured memory_bytes: 4784
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		for(;;)
		{
			int N = sc.nextInt(), P = sc.nextInt();
			if (N==0 && P==0) break;
			
			int[] s = new int[N];
			for (int n = 0; ; n = (n + 1) % N)
			{
				if (P != 0)
				{
					P--;
					s[n]++;
					if (P == 0)
					{
						boolean win = true;
						for (int i = 0; i < N; i++)
						{
							if (i != n && s[i] != 0)
							{
								win = false;
								break;
							}
						}
						if (win)
						{
							System.out.println(n);
							break;
						}
					}
				}
				else
				{
					P = s[n];
					s[n] = 0;
				}
			}
		}
	}
}

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

#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 sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;
const double PI = acos(-1.0);

double DEG_to_RAD(double d) { return d * PI / 180.0; }

char X,Y;

int main(){
  //  freopen("test.txt","r",stdin);
    cin >> X >> Y;
    if ( X > Y) {
        cout << '>' << endl;
    }
    if ( X == Y) {
        cout << '=' << endl;
    }
    if ( X < Y ) {
        cout << '<' << endl;
    }
}


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

int main()
{
  int n,m;
  cin >> n >> m;
  vector<vector<int> > A(n,vector<int>(m,0));
  vector<int> b(m,0);
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      cin >> A[i][j];
    }
  }
  for(int i=0; i<m; i++) cin >> b[i];
  for(int i=0; i<n; i++){
    int sum = 0;
    for(int j=0; j<m; j++){
      sum += A[i][j] * b[j];
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main(){
    
    int i, j, N, flag_r, flag_w, count;
    cin >> N;
    flag_r = 0;
    flag_w = 0;
    count = 0;
    
    int L[N];

    string S;
    cin >> S;
    
    for (i = 0; i < N; i++){
        if (S.at(i) == 'R'){
            L[i] = 1;
            flag_r = 1;
            
        } else {
            L[i] = 0;
            flag_w = 1;
        }
    }
        
    if (flag_r == 0 || flag_w == 0){
        cout << "0" << "\n";
        return 0;
    }
    
    i = 0;
    j = N - 1;
    
    while(1){
        
        while(L[i] == 1){
            i++;
        }

        while(L[j] == 0){
            j--;
        }
        
        if (i > j) break;
        
        L[i] = 1;
        L[j] = 0;
        count++;
    }
    
    cout << count << "\n";

    return 0;
}



Measured memory_bytes: 4480