akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <limits>
#include <map>

using namespace std;

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> vec(n);
    for(int & e : vec){
        cin >> e;
    }
    int min=vec[0];
    for(int i = 0; i<n;i++){
        if(vec[i] <= min) {ans+=1;}
        if(vec[i] < min) min=vec[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10**9)

N, M = map(int, input().split())
edges = [list(map(int, input().split())) for i in range(M)]

#隣接リストで管理
adj = [[] for j in range(N)]
for edge in edges:
    x, y = edge
    adj[x-1].append(y)
    adj[y-1].append(x)

color = [0] * N

#二部グラフ判定
def dfs(node, c):
    color[node-1] = c
    for i in adj[node-1]:
        if c == color[i-1]:
            return False
        if color[i-1] == 0 and not dfs(i, -c):
            return False
    return True

if dfs(1, 1):
    black = color.count(1)
    white = N - black
    print(black * white - M)
else:
    print(N * (N-1) // 2 - M)

Measured memory_bytes: 47372
from sys import stdin, stdout
rock = 0
scissor = 1
paper = 2

def win(i, j):
    if j == 'r' and i == paper:
        return True
    if j == 's' and i == rock:
        return True
    if j == 'p' and i == scissor:
        return True
    return False

N, K = map(int, stdin.readline().split())
prize = list(map(int, stdin.readline().split())) # rock, scissors, paper

T = stdin.readline()
length = len(T)
dp = [[0 for _ in range(3)] for _ in range(length)]

ans = 0
for i in range(K):
    for j in range(i, length, K):
        for k in range(3):
            if j >= K:
                dp[j][k] = max(dp[j-K][(k+1)%3], dp[j-K][(k+2)%3])
            if win(k, T[j]):
                dp[j][k] = dp[j][k] + prize[k]
        if j+K >= length:
            ans = ans + max(dp[j][0], dp[j][1], dp[j][2])

print(ans)

Measured memory_bytes: 18076
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni() - 1
    i = 1
    v = 26
    while n - v >= 0:
        n -= v
        i += 1
        v *= 26
    s = ''
    for _ in range(i):
        v //= 26
        s += chr(97 + n // v)
        n %= v
    print(s)
    return

solve()


Measured memory_bytes: 9196
#include <iostream>

using namespace std;

int main(){
  char op[2] = {'-', '+'};
  int a, b, c, d;
 
  cin >> a;

  d = a % 10; a /= 10;
  c = a % 10; a /= 10;
  b = a % 10; a /= 10;

  int sum = 0;
  for(int i = 0; i < 8; i++){
    int e1, e2, e3;
    int buf = i;
    e3 = buf%2; buf/=2;
    e2 = buf%2; buf/=2;
    e1 = buf;
    sum = a + (2*e1-1)*b + (2*e2-1)*c + (2*e3-1)*d;
    if(sum == 7){
      cout << a << op[e1] << b << op[e2] << c << op[e3] << d << "=7" << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
from functools import lru_cache
import sys

sys.setrecursionlimit(10 ** 8)

H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
# 効率順にソート
# 効率が同じなら、小規模な魔法を優先
AB.sort(key=lambda ab: (ab[1] / ab[0], ab[0]))


@lru_cache(maxsize=None)
def dp(h):
    if h <= 0:
        return 0
    else:
        best = float("inf")
        for a, b in AB:
            val = b + dp(h - a)
            if val < best:
                best = val
            else:
                # 更新されなかった場合は、以降の魔法で更新されることはない
                break
        return best


print(dp(H))


Measured memory_bytes: 30180
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	long long x=0,t=1;
	string a[100010];
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sort(a[i].begin(),a[i].end());
	}
	sort(a+1,a+n+1);
	for(long i=2;i<=n+1;i++){
		if(i!=n+1){
			if(a[i]==a[i-1]){
			t++;
			} 
			else{
				x+=t*(t-1)/2;
				t=1;
			}
		}
		else{
			x+=t*(t-1)/2;
		}
	}
	cout<<x<<endl;
	return 0;
}

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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

typedef long long ll;

using namespace std;

int main ()
{
   ll N,M,res;

  cin >> N >> M;

  if (N >= M/2)
    res = M/2;
  else
    res = N + (M-N*2)/4;

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>

int main() {
    int x = 700;

    char S[4];
    scanf("%s", S);

    for (int i = 0; i < 3; i++) {
        if (S[i] == 'o') {
            x += 100;
        }
    }

    printf("%d\n", x);
    return 0;
} 

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (N, K) = listOfInt()
    var ans = 0
    while (N > 0) {
        ans += 1
        N /= K
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)


Measured memory_bytes: 37868
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
#define LINF 1e18+10  
using ll = long long; 

using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
using Ps=pair<int,string>;

using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}

//const ll mod=998244353;
const ll mod=1e9+7;
const ll MAX=300000;

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


int main(){
    int n,k;
    cin>>n>>k;
    vi a(n);
    rep(i,n)cin>>a[i];
    rep(i,n-k){
        if(a[i]<a[k+i])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 4044
class BinaryTree
	class Node
		attr_accessor :parent, :left, :right, :depth, :height

	end

	def initialize
		@nodes = []
	end

	def add(id, left, right)
		@nodes[id] ||= Node.new
		@nodes[id].left  = left
		@nodes[id].right = right

		if left != -1
			@nodes[left] ||= Node.new
			@nodes[left].parent = id
		end

		if right != -1
			@nodes[right] ||= Node.new
			@nodes[right].parent = id
		end
		self
	end

	def description(id)
		node = @nodes[id]
		desc  = "node #{id}: "
		desc += "parent = #{node.parent ? node.parent : -1}, "
		desc += "sibling = #{sibling(id)}, "
		desc += "degree = #{degree(id)}, "
		desc += "depth = #{depth(id)}, "
		desc += "height = #{height(id)}, "
		desc += "#{type(id)}"
	end

	private
	def sibling(id)
		return -1 unless @nodes[id].parent
		parent = @nodes[@nodes[id].parent]
		return parent.left if parent.left && parent.left != id
		return parent.right if parent.right && parent.right != id
		-1
	end

	def degree(id)
		node = @nodes[id]

		degree = 0
		degree += 1 if exist?(node.left)
		degree += 1 if exist?(node.right)

		degree
	end

	def depth(id)
		node = @nodes[id]

		return node.depth if node.depth
		return 0 unless node.parent

		node.depth = depth(node.parent) + 1
	end

	def height(id)
		node = @nodes[id]

		return node.height if node.height
		return 0 if !exist?(node.left) && !exist?(node.right)

		lheight = height(node.left)
		rheight = height(node.right)
		node.height = (lheight >= rheight ? lheight : rheight) + 1
	end

	def type(id)
		node = @nodes[id]
		return "root" unless node.parent
		return "internal node" if exist?(node.left) || exist?(node.right)
		"leaf"
	end

	def exist?(id)
		id && id != -1
	end

end

tree = BinaryTree.new
n = STDIN.gets.to_i
n.times do
	id, left, right = STDIN.gets.split[0..2].map(&:to_i)
	tree.add(id, left, right)
end

n.times { |i| puts tree.description(i) }

Measured memory_bytes: 6124
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

struct MyStruct {
	int num, honsu;
};

bool comp(const MyStruct& s, const MyStruct& t) {
	if (s.honsu != t.honsu)
		return s.honsu < t.honsu; // 昇順
	return s.num > t.num;
}



int main() {
	int n;
	string s;
	cin >> s;
	n = s.size();

	int zero = 0, one = 0;

	REP(i, n) {
		if (s[i] == '0') {
			zero++;
		}
		else {
			one++;
		}
	}

	ANS(min(zero, one)*2);


	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int num[5000];
int  serch(int line,int now,int maxe)
{
    if(maxe==now)return line;
    return max(line,serch(line+num[now],now+1,maxe));
}
int main()
{
    int n;
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>num[i];
        int ans=num[0];
        for(int i=0;i<n;i++)ans=max(serch(num[i],i+1,n),ans);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1216
while True:
    a = input()
    b = a.split()
    m = int(b[0])
    f = int(b[1])
    if m == 0 and f == 0 :
        break
    else:
        list1 = []
        num = 0
        for i in range(m):
            x=(int(i)+1)
            sum2=f-x
            list1.append(int(i)+1)
            for k in range(x,(m+1)):
                y = k
                z = f-x-y
                if z in list1 and z != x and z !=y and x != y:
                    num += 1
    print(num)


Measured memory_bytes: 5596
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x, 0, sizeof(x))
#define MINF(x) memset(x, 0x3f, sizeof(x))
#define MMINUS(a) memset(a, 0xff, sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1.0 / INF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

using namespace std;

//===================================== template =========================================================

int main() {
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    vector<int> x(N); REP(i, N) cin >> x[i];

    vector<int> neg, pos; 
    REP(i, N) 
        if (x[i] < 0) neg.push_back(x[i]); 
        else pos.push_back(x[i]);

    reverse(ALL(neg));
    
    int res = INF;
    FOR(i, 0, K) {
        if (i > neg.size() || K-i > pos.size()) continue;

        if (i == 0) chmin(res, pos[K-1]);
        else if (i == K) chmin(res, -neg[K-1]);
        else {
            int n = neg[i - 1]; int p = pos[K - i - 1];
            chmin(res, 2 * min(-n, p) + max(-n, p));
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 1404
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>

using namespace std;

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

int D;
int x;
int y;

//i 個マークしたときの点数
int dp[23];
vector<pair<int,int> > vec;

int main() {
    cin>>D;
    cin>>x;
    rep(i,x) {
        string a;
        int p;
        cin>>a>>p;
        if(a=="D") vec.push_back(make_pair(p,0));
    }

    cin>>y;
    rep(i,y) {
        string a;
        int p;
        cin>>a>>p;
        if(a=="DD") vec.push_back(make_pair(p,1));
    }

    rep(i,vec.size()) {
        for(int j=D-1;j>=0;j--) {
            if(vec[i].second) {
                dp[j+2] = max(dp[j+2],dp[j] + vec[i].first);
            }
            else {
                dp[j+1] = max(dp[j+1],dp[j] + vec[i].first);
            }

        }
    }
    int ans=0;
    ans=*max_element(dp,dp+D+1);
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 1220
k,n = list(map(int,input().split()))
arr = list(map(int,input().split()))
x = []
val = arr[-1] - arr[0]
if val<= k/2:
	x.append(val)
else:
	x.append(k-val)
for i in range(1,n):
	val = arr[i] - arr[i-1]
	if val <= (k/2):
		x.append(val)
	else:
		x.append(k-val)
print(k-max(x))



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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

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

const long double PI  =3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code
int main()
{
	int n;
	cin>>n;
	vector<int> a, b;
	rep(i, 0, n)
	{
		int x;
		cin>>x;
		a.pb(x);
	}
	rep(i, 0, n)
	{
		int x;
		cin>>x;
		b.pb(x);
	}
	ll ans = 0;
	rep(i, 0, 29)
	{
		int t = (1 << i);
		int t2 = t*2;
		int t4 = t2*2;
		int t3 = t*3;
		int cnt = 0;
		vector<int> at(n), bt(n);
		rep(j, 0, n)
		{
			at[j] = a[j] % t2;
			bt[j] = b[j] % t2;
		}
		sort(bt.begin(), bt.end());
		rep(j, 0, n)
		{
			int aa = at[j];
			int tt = t - aa;
			int tt2 = t2 - aa;
			int tt3 = t3 - aa;
			int tt4 = t4 - aa;
			auto itr = lower_bound(bt.begin(), bt.end(), tt);
			auto ritr = lower_bound(bt.begin(), bt.end(), tt2);
			cnt += (ritr - itr);
			itr = lower_bound(bt.begin(), bt.end(), tt3);
			ritr = lower_bound(bt.begin(), bt.end(), tt4);
			cnt += (ritr - itr);
		}
		//cout<<cnt<<endl;
		if((cnt &1) == 1) ans += (1 << i);
	}
	cout<<ans<<endl;
}


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

#define NIL NULL

struct node{

  struct node *right;

  struct node *left;

  struct node *parent;

  int key;

};

typedef struct node * Node; 
 
Node root;

void insert(int);

void inorder(Node );

void preorder(Node );

Node treeSearch(Node , int);

Node treeMinimum(Node );

Node treeMaximum(Node );

Node treeSuccessor(Node );

void treeDelete(Node );


int main(){

  int n, i, x;

  char com[20];

  Node t;

  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){

    scanf("%s", com);

    if (com[0] == 'i'){
      
      scanf("%d", &x);
      
      insert(x);

    } 
    else if (com[0] == 'p'){
      
      inorder(root);

      printf("\n");

      preorder(root);

      printf("\n");

    }

    else if(com[0] == 'f'){
      scanf("%d", &x);

       t = treeSearch(root, x);

      if ( t != NIL ) 
	printf("yes\n");

      else 
	printf("no\n");
    } 

    else if(com[0] == 'd'){

      scanf("%d", &x);

      treeDelete(treeSearch(root, x));

    }

  }
 
  return 0;
}


 
void insert(int k){

  Node y = NIL;

  Node x = root;

  Node z;
 
  z = malloc(sizeof(struct node));

  z->key = k;

  z->left = NIL;

  z->right = NIL;
 
  while(x != NIL){

    y = x;

    if((z->key) < (x->key))
      x = x->left;
    else 
      x = x->right;
  }

  z->parent = y;
 
  if(y == NIL)
    root = z;

  else if((z->key) < (y->key)) 
    y->left = z;
  else 
    y->right = z;
 
}

void inorder(Node u){

  if (u == NIL)
    return;
 
  inorder(u->left);

  printf(" %d", u->key);

  inorder(u->right);
 
}

void preorder(Node u){

  if (u == NIL)
    return;
 
 printf(" %d",u->key);

 preorder(u->left);

 preorder(u->right);
 
}
 
Node treeSearch(Node u, int k){
  
  Node x;

  x = u;
 
  while(x != NIL && k != (x->key)){

    if(k < (x->key))
      x = (x->left);

    else 
      x = (x->right);
  
  }
 
  return x;
 
}
 
Node treeMinimum(Node x){

  Node y;

  y = x;

  while((y->left) != NIL){
 
    y = (y->left);
 
  }

  return y;
 
}
 
Node treeMaximum(Node x){

 Node y;
  
 y = x;

 while((y->left) != NIL){
   
   y = (y->right);

 }
 
 return y;
 
}
 
Node treeSuccessor(Node x){
 
  Node y;
 
  if((x->right) != NIL)
    return treeMinimum(x->right);
 
  y = (x->parent);

  while(y != NIL && x == (y->right)){
   
    x = y;

    y = (y->parent);

  }

  return y;
 
}
 
void treeDelete(Node z){

  Node y;
  Node x;
 
  if((z->left) == NIL || (z->right) == NIL)
    y = z;
  else 
    y = treeSuccessor(z);
 
  if((y->left) != NIL)
    x = (y->left);
  else 
    x = (y->right);
 
  if(x != NIL)
    (x->parent) = (y->parent);

  if((y->parent) == root)
    root = x;

  else if(y == (y->parent->left))
    (y->parent->left) = x;

  else 
    (y->parent->right) = x;
 
  if(y != z) 
    (z->key) = (y->key);

  free(y);
}

Measured memory_bytes: 19364
def Score(m,f,r):
    if m == -1:
        m = 0
        return "F"
    if f == -1:
        f = 0
        return "F"
    if  (m + f ) >=80:
        return "A"
    elif (m + f ) < 80 and (m + f ) >= 65:
        return "B"
    elif (m + f ) < 65 and (m + f ) >= 50:
        return "C"
    elif (m + f ) < 50 and (m + f ) >= 30:
        if r >= 50:
            return "C"
        return "D"
    elif (m + f) < 30:
        return "F"

while True:
    m, f, r = list(map(int, input().split()))
    if m == -1 and f == -1 and r == -1:
        break
    print(Score(m,f,r))


Measured memory_bytes: 5600
#include<cstdio>
int n,t,x,y;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d%d%d",&t,&x,&y);
        if(x+y>t)
        {
            printf("No\n");
            return 0;
        }
        if(!((x+y)&1)&&t&1)
        {
            printf("No\n");
            return 0;
        }
        if((x+y)&1&&!(t&1))
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}

Measured memory_bytes: 128
main :: IO ()
main = do
  (a:b:_) <- map read . words <$> getLine
  print $ solve' a b

solve a b = snd $ head $ dropWhile (\(x,y) -> b > x) [(n*a-n+1, n) | n <- [1..]]

solve' a b = ceiling ((b - 1) / (a - 1))


Measured memory_bytes: 508
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=998244353;
inline int Pow(int x,int y){int z=1;x%=MOD;while(y){if(y&1){z=(1ll*z*x)%MOD;}x=(1ll*x*x)%MOD;y>>=1;}return z;}
int main(void)
{
  int A,B,C,D,ans=0,sum,dp[3000]={0};
  if(!scanf("%d %d %d %d",&A,&B,&C,&D))return 0;
  if(A==C){return printf("%d\n",Pow(A,D-B)),0;}
  else if(B==D){return printf("%d\n",Pow(B,C-A)),0;}
  dp[A-1]=1;
  rep(i,D-B)
  {
    sum=0;
    rep(j,C)
    {
      sum=(1ll*sum*(B+i)%MOD+dp[j])%MOD;
      dp[j]=(1ll*j*dp[j]+sum)%MOD;
    }
  }
  rep(i,C){ans=(ans+1ll*dp[C-i-1]*Pow(D,i))%MOD;}
  return printf("%d\n",ans),0;
}

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

long long b[2020];
long long a[2020];
int main()
{
    long long n, x;
    scanf("%lld%lld", &n, &x);
    for(long long i = 0; i < n; ++i)
    {
        scanf("%lld", &a[i]);
        b[i] = a[i];
    }
    long long ans = -1;
    for(long long k = 0; k < n; ++k)
    {
        long long t = k * x;
        for(long long j = 0; j < n; ++j)
            b[j] = min(b[j], a[(j - k + n) % n]);
        for(long long j = 0; j < n; ++j)
            t += b[j];
        if(ans == -1)
            ans = t;
        else
            ans = min(ans, t);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
def compare_image(A, B, N, M):
    for i in range(N):
        for j in range(N):
            # 範囲内なら
            if (i+M <= N) and (j+M <= N):
                b_flag = True

                for k in range(M):
                    str_a = A[i+k][j:j+M]
                    str_b = B[k]
                    if str_a != str_b:
                        b_flag = False

                if b_flag:
                    return True

    return False


N, M = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]

if compare_image(A, B, N, M):
    string = "Yes"
else:
    string = "No"

print(string)


Measured memory_bytes: 3064
N,K=map(int,input().split())

s=[]
for _ in range(K):
    d=int(input())
    l = list(map(int,input().split()))
    s.extend(l)


a=[]
for i in range(1,N+1):
    if i in s:
        pass
    else:
        a.append(i)

print(len(a))

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

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

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main(void){
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  REP(i, 1e+05){
    c -= b;
    a -= d;
    if (c <= 0){
      cout << "Yes" << endl;
      break;
    }
    else if (a <= 0){
      cout << "No" << endl;
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        int length = input.length();
        char[] S = new char[length];
        for (int i = 0; i < length; i++) {
            S[i] = input.charAt(i);
        }

        int ans = 0;
        for (int i = 1; i < length; i++) {
            if(S[i-1] == S[i]) {
                ans++;
                if (S[i] == '0') {
                    S[i] = '1';
                }
                else {
                    S[i] = '0';
                }
            }
        }

        System.out.println(ans);
    }
}


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

int main(void){
    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;
    for(int i=0; i<N; i++){
        cout << S[i] << T[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define FORCLS(i,a,b) for(int i = (a); i <= (b); i++)
#define REPCLS(i,n) FORCLS(i,1,n)

#define NMAX 1003

using Int = long;

Int v[NMAX];
Int pCnt[NMAX];

Int n;
void solve() {
    cin >> n;
    REPCLS(i, n){
        v[i] = i;
    }
    FORCLS(i, 2, n){
        if(v[i] == 1) continue;
        Int p = v[i];
        FORCLS(j, i, n){
            while(v[j] % p == 0){
                v[j] /= p;
                pCnt[p]++;
            }
        }
    }
    Int factCnt = 1;
    FORCLS(i, 1, n){
        if(pCnt[i] == 0) continue;
        factCnt = (factCnt * (pCnt[i] + 1)) % (1000000007);
    }
    cout << factCnt << endl;
}

#ifdef DEBUG
#define MAIN hoge
#else
#define MAIN main
#endif

int MAIN() {
    solve();
    
    return 0;
}


Measured memory_bytes: 256
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

bingo = []
for i in range(3):
    x = a[i]
    for j in range(3):
        bingo.append(x[j])

for i in b:
    for j in range(0,9):
        if i == bingo[j]:
            bingo[j] = 0

if bingo[0]==0 and bingo[1]==0 and bingo[2]==0:
    print("Yes")
elif bingo[3]==0 and bingo[4]==0 and bingo[5]==0:
    print("Yes")
elif bingo[6]==0 and bingo[7]==0 and bingo[8]==0:
    print("Yes")
elif bingo[0]==0 and bingo[3]==0 and bingo[6]==0:
    print("Yes")
elif bingo[1]==0 and bingo[4]==0 and bingo[7]==0:
    print("Yes")
elif bingo[2]==0 and bingo[5]==0 and bingo[8]==0:
    print("Yes")
elif bingo[0]==0 and bingo[4]==0 and bingo[8]==0:
    print("Yes")
elif bingo[2]==0 and bingo[4]==0 and bingo[6]==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9320
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker,"/stack:200000000")
#include <bits/stdc++.h>
using namespace std;

#define PI 2*acos(0.0)
#define print(x) return cout<<x<<endl,0
#define watch(x) cerr<<#x<<"-> "<<x<<endl
#define CLEAR(x,val) memset(x,val,sizeof(x))
// #define int long long

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

const int INF = 1000000000;
const int MOD = 1000000007; //998244353

int n,m,k;
int u,d,l,r;
int res[305][305];
char grid[305][305];

void solve(int i, int j)
{
	u = 0;
	d = m-1;

	for(int x = j+1; x < m; x++)
		if(grid[i][x]=='#' || res[i][x]!=-1){
			d = x-1;
			break;
		}

	for(int x = j-1; x >= 0; x--)
		if(grid[i][x]=='#' || res[i][x]!=-1){
			u = x+1;
			break;
		}
}

bool ok(int p)
{
	for(int x = u; x <= d; x++)
		if(grid[p][x] == '#' || res[p][x] != -1)
			return false;
	return true;	
}

signed main()
{	
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	cin.tie(0), cout.tie(0);
	ios::sync_with_stdio(0);
	cin >> n;
	cin >> m;
	cin >> k;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> grid[i][j],res[i][j] = -1;

	int cur = 0;

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
		{
			if(grid[i][j] == '#'){
				solve(i,j);

				l = i;
				r = i;

				for(int x = i+1; x < n && ok(x); x++)
					r = x;
				for(int x = i-1; x >=0 && ok(x); x--)
					l = x;

				// cout<<"done"<<endl;

				// watch(l);
				// watch(r);
				// watch(u);
				// watch(d);
				// watch(i);
				// watch(j);
				

				for(int x = l; x <= r; x++)
					for(int y = u; y <= d; y++)
						if(res[x][y] == -1)
						{
							res[x][y] = cur;
						}

				++cur;
			}
		}	

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			cout<<res[i][j]+1<<" ";
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main(){

    char b;
    cin >> b;

    if(b == 'A') cout << 'T' << endl;
    if(b == 'C') cout << 'G' << endl;
    if(b == 'G') cout << 'C' << endl;
    if(b == 'T') cout << 'A' << endl;

}

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

int main()
{
    int sum ,a,b,x,counter=0;
    scanf("%d%d",&a,&b);
    if(b==1){
        printf("%d",counter);
        return 0;

    }
counter++;
sum=a;
   while(sum<b){
    sum+=a-1;
    counter ++;
   }
   printf("%d",counter);
}


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

int main(void)
{
	string S;

	cin >> S;

	int num = atoi(S.c_str());

	int A = num / 100;
	int B = num % 100;

	bool month_flag_A = false, month_flag_B = false;
	if (A >= 1 && A <= 12) {
		month_flag_A = true;
	}
	if (B >= 1 && B <= 12) {
		month_flag_B = true;
	}

	if (month_flag_A) {
		if (month_flag_B) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else {
		if (month_flag_B) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N; cin >> N;
  ll A[N]; rep(i,N) cin >> A[i];
  ll now = A[0], result = 0;
  repr(i,1,N) {
    if (A[i]<now) result += now - A[i];
    else now = A[i];
  }
  cout << result << endl;
  return 0;
}

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;


int main() {

	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) {
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;



}

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

M = 61
D1 = [0] * M

for a in A:
    k = 0
    while a > 0:
        if a & 1:
            D1[k] += 1
        a >>= 1
        k += 1

MOD = 10 ** 9 + 7
ans = 0
for k in range(M):
    d = D1[k]
    ans += d * (N - d) * pow(2, k, MOD)
    ans %= MOD

print(ans)


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    constexpr unsigned long MOD = 1000000007;
    unordered_map<unsigned long, unsigned long> fc;
    for(auto& i : A){
        cin >> i;
        auto k = i;
        for(unsigned long j{2}; j * j <= k; ++j)if(k % j == 0){
            unsigned long c{j};
            while((k /= j) % j == 0)c *= j;
            fc[j] = max(fc[j], c);
        }
        if(k != 1)fc[k] = max(fc[k], k);
    }
    const auto& modpow = [](unsigned long a, unsigned long n, unsigned long r = 1) -> unsigned long {
        while(n){
            if(n & 1)(r *= a) %= MOD;
            (a *= a) %= MOD;
            n >>= 1;
        }
        return r;
    };
    unsigned long s{1};
    for(const auto& i : fc)(s *= i.second) %= MOD;
    unsigned long ans{0};
    for(const auto& i : A)ans += modpow(i, MOD - 2, s);
    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 768
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 500000
#define MAXM 2000000
#define INF 0x3f3f3f3f
struct Edge{
	int nxt,u,v,cap;
}edge[MAXM+5];
int ecnt=-1,cur[MAXN+5],head[MAXN+5];
void Addedge(int u,int v,int cap,int rcap){
	edge[++ecnt]=(Edge){head[u],u,v,cap},head[u]=ecnt;
	edge[++ecnt]=(Edge){head[v],v,u,rcap},head[v]=ecnt;
	return ;
}
int N,S,T;
int dep[MAXN+5];
bool BFS(){
	queue<int> Q;
	memset(dep,0x3f,sizeof(dep));
	dep[S]=0,Q.push(S);
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		for(int i=head[u];~i;i=edge[i].nxt){
			int v=edge[i].v,cap=edge[i].cap;
			if(dep[v]==INF&&cap)
				dep[v]=dep[u]+1,Q.push(v);
		}
	}
	return dep[T]<INF;
}
int DFS(int u,int aug){
	if(u==T) return aug;
	int flow=0,f;
	for(int &i=cur[u];~i;i=edge[i].nxt){
		int v=edge[i].v,cap=edge[i].cap;
		if(dep[v]==dep[u]+1&&cap&&(f=DFS(v,min(cap,aug)))){
			aug-=f,flow+=f;
			edge[i].cap-=f,edge[i^1].cap+=f;
			if(!aug) break;
		}
	}
	return flow;
}
int Dinic(){
	int Max_Flow=0;
	while(BFS()) 
		memcpy(cur,head,sizeof(head)),Max_Flow+=DFS(S,INF);
	return Max_Flow;
}
bool vis[MAXN+5];
int a[MAXN+5],b[MAXN+5];
int main(){
	memset(head,-1,sizeof(head));
	int n=read(),ncnt=2*n;
	for(int i=1;i<=n;i++)
		a[i]=read()+1,vis[i]=0;
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			int u=i,x=++ncnt;
			do{
				vis[u]=1,Addedge(x,u,INF,INF),u=a[u];
			}while(u!=i);
		}
	for(int i=1;i<=n;i++)
		b[i]=read()+1,vis[i]=0;
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			int u=i,x=++ncnt;
			do{
				vis[u]=1,Addedge(x,u+n,INF,INF),u=b[u];
			}while(u!=i);
		}
	
	S=0,T=ncnt+1,N=ncnt+2;
	for(int i=1;i<=n;i++){
		if(a[i]==i&&b[i]==i)
			Addedge(S,i,1,0),Addedge(i,T,1,0);//a=1,c=1
		else if(a[i]==b[i]&&a[i]!=i)
			Addedge(i,i+n,1,1);//e=1,f=1
		else if(a[i]!=i&&b[i]==i)
			Addedge(i,T,1,0);
		else if(a[i]==i&&b[i]!=i)
			Addedge(S,i+n,1,0);
		else if(a[i]!=b[i]&&a[i]!=i&&b[i]!=i)
			Addedge(i,i+n,1,0);
	}
	printf("%d\n",n-Dinic());
    return 0;
}


Measured memory_bytes: 25344
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        X, Y = map(lambda i: int(i), line.rstrip("\n").split(" "))
        counter = 0
        value = X
        while value <= Y:
            counter += 1
            value *= 2
        print counter

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2568
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 5121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	printf("%d\n",(a-1)/2);

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e5+10;
char s[maxn];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>s;
	int n=strlen(s);
	int flag=0;
	for(int i=0;i<n-1;i++){
		if(s[i]=='A'&&s[i+1]=='B') flag=1;
		if(s[i]=='B'&&s[i+1]=='A') flag=1;
	}
	if(flag) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define qwq (cerr<<"qwq"<<endl)
#define orz(x) (cerr<<#x": "<<x<<endl)
#define orzarr(a,n) {cerr<<#a": "; repeat(__,0,n)cerr<<(a)[__]<<" "; cerr<<endl;}
#define orzeach(a) {cerr<<#a": "; for(auto __:a)cerr<<__<<" "; cerr<<endl;}
#define fi first
#define se second
typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;}
typedef double lf; typedef long double llf; const lf err=1e-11; const lf pi=acos(-1); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;}
typedef pair<int,int> pii; template<typename A,typename B> ostream &operator<<(ostream &o,const pair<A,B> &x){return o<<'('<<x.fi<<','<<x.se<<')';}
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=1000010;
const int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
//#define int ll
string s;
#define P 2
int T,n,m,i,f[P],r[P];
int C(int n,int m){return n<m?0:f[n]*r[n-m]%P*r[m]%P;}
int rec[N];
int lucas(int n,int m){
	if(n<m)return 0;
	if(!m||n==m)return 1;
	return C(n&1,m&1)^lucas(n>>1,m>>1);
}
int Lucas(int n,int m){
	return (n&m)==m;
}
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	mst(rec,-1);
	for(r[0]=r[1]=f[0]=f[1]=1,i=2;i<P;i++){
		f[i]=f[i-1]*i%P,r[i]=-r[P%i]*(P/i)%P;
		while(r[i]<0)r[i]+=P;
	}
	for(i=2;i<P;i++)r[i]=r[i]*r[i-1]%P;
	int n,sum=0,sum2=0;
	cin>>n;
	cin>>s;
	repeat(i,0,n)s[i]--;
	repeat(i,0,n)sum^=(s[i]=='1')*(Lucas(n-1,i));
	if(sum)cout<<1<<endl,exit(0);
	int f=1;
	repeat(i,0,n)f=f && (s[i]!='1');
	if(!f)cout<<0<<endl,exit(0);
	repeat(i,0,n)sum2^=(s[i]=='2')*(Lucas(n-1,i));
	cout<<sum2*2<<endl;
	return 0;
}

Measured memory_bytes: 5788
#include <stdio.h>
int main()
{
    int num[2];
    scanf("%d %d %d",&num[0],&num[1],&num[2]);
    int i=0,j,tmp;

while(i!=2){
        for(j=0;j<2;j++){
            if(num[j]>num[j+1]){
                tmp = num[j+1];
                num[j+1] = num[j];
                num[j] = tmp;
            }
    }
    i++;
}

    i = num[2]*10 + num[1] + num[0];
    printf("%d",i);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/300 < b.F.F/300)
		return 1;
	if(a.F.F/300 > b.F.F/300)
		return 0;
	if(a.F.S < b.F.S)
		return 1;
	if(a.F.S > b.F.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (1e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 2*550;
const int SQRT = BUCK+9;

ll a[N], c[N], suma[N], sumc[N];
pli b[N];

void solve()
{
	int n, i, m, k;
	ll ans = 0;
	cin >> n >> m;
	fo(i,1,n+1)
		cin >> a[i];
	fo(i,1,m+1)
		cin >> b[i].S >> b[i].F;
	sort(a+1,a+n+1);
	sort(b+1,b+m+1,greater < pll > ());
	k = 0;
	fo(i,1,m+1)
		while(k < n && b[i].S > 0)
		{
			c[++k] = b[i].F;
			b[i].S--;
		}
	fo(i,1,n+1)
		suma[i] = suma[i-1] + a[i];
	fo(i,1,k+1)
		sumc[i] = sumc[i-1] + c[i];
	ans = suma[n];
	fo(i,1,k+1)
		ans = max(ans, suma[n] + sumc[i] - suma[i]);
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 4992
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int N, M, C;
    cin >> N >> M >>C;
    int B[M];
    int A[N][M];

    for(int i = 0; i < M; i++) 
        cin >> B[i];

    for(int i = 0; i < N; i++) 
        for(int j = 0; j < M; j++) 
            cin >> A[i][j];

    int val = 0;
    int res = 0;
    for(int i = 0; i < N; i++) 
    {
        for(int j = 0; j < M; j++) 
        {
            val += A[i][j] * B[j] ;
        }
        if(val + C > 0)
        {
            res++;
        } 

        val = 0;        
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
def isPrime(p):
    
    if p == 1:
        return False
        
    res = True
    for i in range(2, int(p**0.5) + 1):
        if p % i == 0:
            res = False
            break
    
    return res


N = int(input())
count = 0

for _ in range(N):
    p = int(input())
    
    if isPrime(p):
        count += 1

print(count)


Measured memory_bytes: 5712
// Problem : A - Multiplication 1
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

int main()
{
    io;
    ll a,b;
    cin>>a>>b;
    cout<<a*b;
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0)); 
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

pii g[90001];
int d[90001];

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    int H,W,D,Q;
    cin >> H >> W >> D;
    rep(i,H) rep(j,W){
        int n;
        cin >> n;
        g[n] = pii(i, j);
    }

    REP(i, D+1, H*W+1) d[i] = d[i-D] + abs(g[i].fi - g[i-D].fi) + abs(g[i].se - g[i-D].se);
    cin >> Q;
    rep(i,Q){
        int l, r;
        cin >> l >> r;
        cout << d[r] - d[l] << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define ld long double
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x, y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x, y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
using namespace std;

ll mode=pow(10,9)+7;
bool cmp(pair<ll,ll> x, pair<ll, ll> y){
	return x.S<y.S;
}


int main(){ 
    
    #ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
	#endif
	
	ios::sync_with_stdio(0);
    cin.tie(0);
	
	
	ll n;
	cin>>n;
	if (n%2==0){
		n=n/2;
		cout<<n-1<<endl;
	}
	else{
		n=n/2;
		cout<<n<<endl;
	}
	
	
 	return 0;
}

Measured memory_bytes: 256