akhauriyash/Code-Regression huggingface dataset:
# abc175_c.py
# https://atcoder.jp/contests/abc175

global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # X = int(lines[0])
    X, K, D = list(map(int, lines[0].split()))
    # values = list(map(int, lines[0].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    # 全部プラス
    all_plus = X + D * K
    # 全部マイナス
    all_minus = X - D * K

    # 全部プラスと全部マイナスが同じ符号側だったら最小値をReturn (0を含む)
    if all_plus * all_minus >= 0:
        result = min(abs(all_plus), abs(all_minus))
        return [result]

    # D*2で除算 (X = q * (D*2) + mod)
    q, mod = divmod(X, D*2)

    # ※偶数回か奇数回で異なる

    # 偶数
    if K % 2 == 0:
        values = list()
        values.append(abs(mod - D*2))
        values.append(abs(mod))
        values.append(abs(mod + D*2))
        result = min(values)

    # 奇数
    else:
        values = list()
        values.append(abs(mod - D*3))
        values.append(abs(mod - D*1))
        values.append(abs(mod + D*1))
        values.append(abs(mod + D*3))
        result = min(values)

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['6 2 4']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['7 4 3']
        lines_export = [1]
    if pattern == 3:
        lines_input = ['10 1 2']
        lines_export = [8]
    if pattern == 4:
        lines_input = ['1000000000000000 1000000000000000 1000000000000000']
        lines_export = [1000000000000000]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9328
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	char s[31];
	scanf("%s",&s);
	s[5]=' ';
	s[13]=' ';
	printf("%s\n",s);
}

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



struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key)return u;
  if(k<u->key)return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

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 to be deleted
  Node x; // child of y
  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==NIL){
    root=x;
  }
  else if(y==y->parent->left){
    y->parent->left=x;
  }
  else{
    y->parent->right=x;
  }
  if(y!=z){
    z->key=y->key;
  }
  
}

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

void inorder(Node u){
  if(u->left!=NIL) inorder(u->left);
  printf(" %d",u->key);
  if(u->right!=NIL)  inorder(u->right);
  

}
void preorder(Node u){
printf(" %d",u->key);
if(u->left!=NIL) preorder(u->left);
if(u->right!=NIL)  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else 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] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int N;
	cin >> N;
	vector<int> A(N+1), B(N);
	for(int i = 0; i < N+1; i++) cin >> A[i];
	for(int i = 0; i < N; i++) cin >> B[i];

	ll res = 0;
	for(int i = N-1; i >= 0; i--){
		ll m= min(A[i+1], B[i]);
		res += m;
		B[i] -= m;

		m = min(A[i], B[i]);
		res += m;
		A[i] -= m;
	}

	cout << res << '\n';


	return 0;
}

Measured memory_bytes: 1024
#include <algorithm> // std::sort(begin,end)
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;

int main(int argc, char const *argv[]) {
  int n, m, k, s;
  cin >> n >> m;
  vector<pair<int, vector<int>>> denkyu(m);

  for (int i = 0; i < m; i++) {

    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> s;
      denkyu[i].second.push_back(s-1);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> denkyu[i].first;
  }
  /*
  cerr<< "n:"  << n << endl;
  cerr<< "m:"  << m << endl;
  */
  int ret = 0, tmp;
  bool ok, tmp_ok;

  for (int i = 0; i < (1 << n); i++) {
    ok = true;
   /* cerr << "hello:"; 
    for (int jk = 0; jk < n; jk++) {
      cerr << ((i & (1 << jk)) ? "1" : "0");
    }
    cerr << endl;
    */
   
    for (int j = 0; j < m; j++) {
      tmp = 0;
      for (int s : denkyu[j].second) {
        if (i & (1 << s)) {
          tmp++;
         // cerr<< "tmp incr" << endl;
        }
      }
      tmp_ok = ((tmp % 2) == denkyu[j].first);
      //cerr << "tmp" << tmp << "\tp" << denkyu[j].first << endl;
     // cerr << j << (tmp_ok ? "ok" : "ng") << endl;
      ok &= tmp_ok;
    }
    if (ok) {
      ret++;
      //cerr << "increment" << endl;
    }
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

func printIntArray(values []int) {
	arraySize := len(values)
	strValues := make([]string, arraySize)
	for i, elm := range values {
		strValues[i] = strconv.Itoa(elm)
	}

	fmt.Printf("%v\n", strings.Join(strValues, " "))
}

func selectionSort(values []int) int {
	count := 0
	for i := 0; i < len(values); i++ {
		minj := i
		for j := i; j < len(values); j++ {
			if values[j] < values[minj] {
				minj = j
			}
		}

		if i != minj {
			tmp := values[i]
			values[i] = values[minj]
			values[minj] = tmp
			count++
		}
	}
	return count
}

func main() {
	var arraySize int
	fmt.Scan(&arraySize)
	// fmt.Println("arraySize", arraySize)

	values := make([]int, arraySize)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < arraySize; i++ {
		sc.Scan()
		s := sc.Text()
		// fmt.Println("scan", s)
		values[i], _ = strconv.Atoi(s)
	}

	count := selectionSort(values)
	printIntArray(values)
	fmt.Printf("%d\n", count)

}



Measured memory_bytes: 1208
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int a[100005];
int main(){
	std::ios::sync_with_stdio(false);
	int n,k,i,ans=0;
	cin>>n>>k;
	rep(i,n){
		cin>>a[i];
	}
	i=0;
	ans=0;
	while(1){
		if(i>=n-1){
			cout<<ans<<endl;
			return 0;
		}
		//cout<<ans<<endl;
		i+=k;
		i--;
		ans++;
	}
} 	
	

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<list>
#include<string>
#define ll long long 
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
#define E exp(1)
#define mod 1e9+7
int main()
{
	int n;
	cin>>n;
	char a[10004];
	cin>>a;
	int len=strlen(a);
	for(int i=0;i<len;i++)
	{
		a[i]=(a[i]-'A'+n)%26+'A';
	}
	cout<<a;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int H,W;
	int i,j;
	while(scanf("%d %d",&H,&W),H||W){
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				printf("#");
			}
			printf("\n");
		}
		puts("");
	}
return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  //input
int n,k,i;cin>>n;vchar s(n);for(i=0;i<n;i++){cin>>s[i];}
  cin>>k;vint a(n,0);
  

  //caricurate
for(i=0;i<n;i++){if(s[i] ==s[k-1]){a[i]=1;}}
for(i=0;i<n;i++){if(a[i]){cout<<s[k-1];}else{cout<<"*";}}

  //output
cout<<endl;

}

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

const int len = 1000;
int n, w;
pair < int, int > f[len];

map < long long, long long > dp;

int main(){
    cin >> n >> w;
    for(int i = 0;i < n;i++)
        cin >> f[i].first >> f[i].second;
    dp[0] = 0;
    for(int i = 0;i < n;i++){
        for(auto j = dp.rbegin();j != dp.rend();j++){
            if(dp.count(f[i].first + j->first) == 0 && f[i].first + j->first <= w){
                dp[f[i].first + j->first] = j->second + f[i].second;
            }else
            if(dp.count(f[i].first + j->first) != 0 && f[i].first + j->first <= w){
                dp[f[i].first + j->first] = max(dp[f[i].first + j->first], j->second + f[i].second);
            }
        }
    }
    long long res = 0;
    for(auto i = dp.begin();i != dp.end();i++){
        res = max(res, i->second);
    }
    cout << res;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pl;
typedef vector<pl> vpl;
const int MN = 100100;
ll w[MN][2];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	ll n;
	cin >> n;
	vpl ord;
	for(int i=0;i<n;i++) {
		for(int j=0;j<2;j++) {
			cin >> w[i][j];
			ord.push_back({w[i][j],i});
		}
	}
	sort(ord.begin(),ord.end());
	ll su[2] = {0,0};
	for(int i=0;i<n;i++) {
		for(int j=0;j<2;j++) {
			su[j] += w[i][j];
		}
	}
	ll res = min(su[0],su[1]);
	ll miv = ord[n-1].first;
	bool wow = false;
	for(int i=0;i<n;i++) {
		ll wa = min(w[i][0],w[i][1]);
		ll wb = max(w[i][0],w[i][1]);
		if(wb <= ord[n-1].first && wa <= ord[n-2].first) {
			wow = true;break;
		}
	}
	ll saw = 0;
	for(int i=0;i<n;i++) {
		saw += ord[i].first;
	}
	if(wow) {
		res = min(res,saw);
	} else {
		for(int i=0;i<n;i++) {
			int id = n-1;
			for(;id>=0 && ord[id].second == i;id--) {
			}
			ll ma = max(w[i][0],w[i][1]);
			res = min(res,saw+ma-ord[id].first);
		}
	}
	cout << res << '\n';
}


Measured memory_bytes: 7152
#include "bits/stdc++.h"
using namespace std;

#ifdef LOCAL
#include "debug.h"
#define input \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#else
#define debug(...) 4
#define input 4
#endif

using ll = long long;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int32_t main() {
    input;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x, k, d;
    cin >> x >> k >> d;   
    x = abs(x);
    ll moves = x / d;
    x -= min(moves, k) * d;
    k -= min(moves, k);
    if (k % 2 == 0) {
        cout << x << endl;
    } 
    else {
        cout << abs(x - d) << endl;
    } 
}



Measured memory_bytes: 3620
#include <stdio.h>

int main(void){
   
   int A,B;
   
   scanf("%d%d",&A,&B);
   
   if(B%A == 0){
      printf("%d\n",A+B);
   }
   else {
      printf("%d\n",B-A);
   }
 
   return 0;
   
}



Measured memory_bytes: 128
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var n int
var s string
var r, g, b int

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	s = nextStr()

	for i := 0; i < n; i++ {
		switch string(s[i]) {
		case "R":
			r++
		case "B":
			b++
		case "G":
			g++
		}
	}
	ans := r * g * b
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			//j-i!=k-jの反例を除きたい
			k := j*2 - i
			//色が被る条件は、ansの初期値を定義した時点で除かれているのでスキップ
			if k >= n || s[i] == s[j] || s[k] == s[i] || s[k] == s[j] {
				continue
			}

			//j-i!=k-jの反例を除く
			ans--
		}
	}

	fmt.Println(ans)
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	cout<<C<<" "<<A<<" "<<B<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 300005
#define INF 20000000000000000LL
#define alpha 26

char s[maxn] ;

i64 dp[maxn][3] , dis[maxn] ;

int main()
{
    int n ;

    scanf("%s",s) ;

    n = strlen(s) ;
    for(int i=n ; i>=1 ; i--) s[i] = s[i-1] ;

    dis[0] = 1 ;

    for(int i=1 ; i<=n ; i++)
    {
        for(int j=0 ; j<3 ; j++) dp[i][j] = dp[i-1][j] ;
        dis[i] = dis[i-1] ;

        if( s[i]=='A' ) dp[i][0] += dis[i-1] ;
        if( s[i]=='B' ) dp[i][1] += dp[i-1][0] ;
        if( s[i]=='C' ) dp[i][2] += dp[i-1][1] ;

        if( s[i]=='?' )
        {
            dp[i][0] = ( 3*dp[i-1][0] + dis[i-1] ) ;
            dp[i][1] = ( 3*dp[i-1][1] + dp[i-1][0] ) ;
            dp[i][2] = ( 3*dp[i-1][2] + dp[i-1][1] ) ;
            dis[i] = (dis[i-1]*3LL)%mod ;
        }
        for(int j=0 ; j<3 ; j++) dp[i][j] %= mod ;

 //       printf("%lld %lld %lld\n",dp[i][0] , dp[i][1] , dp[i][2]) ;
    }

    printf("%lld\n",dp[n][2]) ;

    return 0 ;
}


Measured memory_bytes: 5248
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
    // Your code here!
    int li[26]={};
    string str;
    
    while(cin>>str){
        for(int i=0; i<str.size(); i++){
            if('a'<=str[i] && str[i]<='z'){
                li[str[i]-'a']+=1;
            }
            else if('A'<=str[i] && str[i]<='Z'){
                li[str[i]-'A']+=1;
            }
        }
    }
    
    for(int i=0; i<26; i++){
        printf("%c : %d\n", i+'a', li[i]);
    }
        
}



Measured memory_bytes: 3248
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll M=1000010;

int main() {
	ll a, b, ans=0;

	cin >> a >> b;

	ans = a*b;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    vector<ll> sum(n+1,0);
    rep(i,n) sum[i+1] = sum[i] + v[i];
    ll ans = INF;
    rep(i,n){
        ans = min(ans, abs((sum[n]-sum[i]) - sum[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()
if A > B:
    if B == 1:
        print("Bob")
    else:
        print("Alice")
elif A == B:
    print("Draw")
else:
    if A == 1:
        print("Alice")
    else:
        print("Bob")

Measured memory_bytes: 9984
#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>;

const int INF = 1001001001;
int dist[100005][3];

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
  }
  int sv, tv;
  cin >> sv >> tv;
  --sv; --tv;
  rep(i, n)rep(j, 3) dist[i][j] = INF;
  queue<P> q;
  q.push(P(sv, 0));
  dist[sv][0] = 0;
  while (!q.empty()){
    int v = q.front().first;
    int l = q.front().second;
    q.pop();
    for (int u: to[v]){
      int nl = (l+1) % 3;
      if (dist[u][nl] != INF) continue;
      dist[u][nl] = dist[v][l] + 1;
      q.push(P(u, nl));
    }
  }
  int ans = dist[tv][0];
  if (ans == INF) ans = -1;
  else ans /= 3;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9808
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(ll i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
//const ll MOD = 1000000007ll;
const ll MOD = 998244353ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう

int main(){
    int n;
    std::cin >> n;
    VEC(ll,a,n);
    std::vector<ll> sa(n+1);
    rep(i,n){
        sa[i+1]=sa[i]+a[i];
    }
    ll r=0,l=0;
    ll dum=0;
    ll ans=0;
    while(l<n){
        if(r==n){
            ans+=r-l;
            l++;
        }
        else if((dum+a[r])==(dum^a[r])){
            dum+=a[r];
           // std::cout << dum << std::endl;
            r++;
        }
        else{
            ans+=r-l;
            l++;
            dum=sa[r]-sa[l];
          //  std::cout << dum << std::endl;
        }
    }
    
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ff first
#define ss second
#define sfi(a) scanf("%d",&a)
#define sfi2(a,b) scanf("%d %d",&a,&b)
#define sfi3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfll(a) scanf("%lld",&a)
#define all(a) a.begin(),a.end()
#define keepu(a) a.erase(unique(all(a)),a.end())
#define inf 1e7
#define m_p make_pair
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define mem(x,val) memset(x,val,sizeof(x))
#define read freopen("output.txt","r",stdin)
#define write freopen("input.txt","w",stdout)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define sqr(x) ((x)*(x))

typedef long long ll;
const ll mod = 1e9+7;
const int sz = 500;

bool cmp(pair<int,string> a,pair<int,string> b){
    return a.ff>b.ff;
}

int main(){

    int n;
    cin >> n;

    map<string,int> mp;

    for(int i=0;i<n;i++){
        string str;
        cin >> str;
        mp[str]++;
    }

    int mx = -1;

    for(auto x:mp) mx = max(mx,x.ss);

    for(auto x:mp) {
        if(x.ss == mx) cout << x.ff << endl;
    }

    return 0;
}


Measured memory_bytes: 27264
#AtCorder用　自動木取得コード

#１行目がノードの数、２行目以降が２つの数字でノードを繋ぐ辺を表すとき、使える

#変数
#node_n :ノードの数
#edge   :エッジを、入力の順番でリストとして提供
#【注意】ノードクラスのリストは関数で取り出さないと、連動して変わってしまう


#関数
#・getroot()で根を取り出す
#・getleaf()で葉を取り出す
#・childに子のノードクラスのリストが格納
#・parentに親のノードクラスが格納

import sys
sys.setrecursionlimit(1000000)



#ノードクラス
class Node():
    def __init__(self):
        self.name=-1
        self.parent=-1
        self.child=[]
        self.color=0
        
        
        
        
    #ノードに対する子供の数を取得
    def childnum(self):
        return len(self.child)

    

#木クラス
class Tree():
    
    
    #作成した瞬間、入力の数だけノードを作る。
    def __init__(self):
        self.tree=[]
        self.edge=[]
        self.node_n=int(input())
        for i in range(self.node_n):
            a=Node()
            a.name=i
            self.tree.append(a)
        for i in range(self.node_n-1):
            edge=[int(j) for j in input().split()]
            self.edge.append(edge)
            self.tree[edge[0]-1].child.append(self.tree[edge[1]-1])
            self.tree[edge[1]-1].parent=self.tree[edge[0]-1]
       
     
    #根ノードを取得
    def getroot(self):
        return self.tree[0]
    
    #葉ノードのリストを取得
    def getleaf(self):
        leaf=[]
        for i in self.tree:
            if i.child==[]:
                leaf.append(i)
        return leaf
    
    
    #全ノードリストを取得
    def gettree(self):
        return self.tree[:]

    
    
    
    
    
tree=Tree()

ans=0
node=tree.getroot()


def dps(Node):
    global ans
    colorlist=[]
    p_col=Node.color
    childnum=Node.childnum()
    for i in range(childnum+1):
        colorlist.append(i+1)
    if p_col in colorlist:
        colorlist.remove(p_col)
    else:
        colorlist.pop()
    
    if colorlist!=[]:
        maxcol=colorlist[-1]
        if maxcol>=ans:
            ans=maxcol
        children=Node.child
        for i in range(childnum):
            children[i].color=colorlist[i]
        for child in children:
            dps(child)
    

dps(node)

print(ans)

tre=tree.gettree()
edge=tree.edge
n=tree.node_n

for i in edge:
    print(tre[i[1]-1].color)


Measured memory_bytes: 95308
# -*- coding: utf-8 -*-
import numpy as np

a, b, c, d = map(int, input().split())
i = 0

while a > 0 and c > 0:
    if i % 2 == 1:
        a -= d
    else:
        c -= b
    i += 1

if a > 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 27120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n, t; cin >> n >> t;
    VI a(n), b(n);
    FOR(i, 0, n)cin >> a[i] >> b[i];

    auto dp = vec<int>(n + 1, t, 2);
    FOR(i, 0, n)FOR(j, 0, t)FOR(k, 0, 2) {
        chmax(dp[i + 1][j][k], dp[i][j][k]);
        if (j + a[i] < t)
            chmax(dp[i + 1][j + a[i]][k], dp[i][j][k] + b[i]);
        if (k == 0)
            chmax(dp[i + 1][j][1], dp[i][j][0] + b[i]);
    }
    print(max(dp[n][t - 1][0], dp[n][t - 1][1]));

    return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    vector<int> white(n + 1), black(n + 1);
    reps(i, n){
        white[i] = white[i - 1] + (s[i - 1] == '.');
        black[i] = black[i - 1] + (s[i - 1] == '#');
    }

    int ans = min(black[n], white[n]);
    rep(i, n + 1){
        ans = min(ans, black[i] + white[n] - white[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2196
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a

    if a > b:
        return gcd(b, a % b)
    else:
        return gcd(a, b % a)


def gcd_multi(nums):
    if len(nums) == 0:
        return 0
    if len(nums) == 1:
        return nums[0]

    ret = gcd(nums.pop(), nums.pop())
    while len(nums) > 0:
        ret = gcd(ret, nums.pop())
    return ret


def solve(inputs):
    [N, M] = string_to_int(inputs[0])
    targets = string_to_int(inputs[1])

    if N >= M:
        return 0

    targets.sort()
    diffs = []
    for i in range(0, len(targets)-1):
        diffs.append((i, targets[i+1] - targets[i]))
    diffs.sort(key=lambda x: x[1])

    # separate groups
    separaters = []
    for _ in range(0, N-1):
        separaters.append(diffs.pop()[0])
    separaters.sort()

    groups = []
    prev_sep = -1
    for i, s in enumerate(separaters):
        groups.append(targets[prev_sep+1:s+1])
        prev_sep = s
    groups.append(targets[prev_sep+1:])

    counts = 0
    for g in groups:
        counts += g[-1] - g[0]

    return counts


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


Measured memory_bytes: 21816
A, B = list(map(int, input().split()))

def judge(x):
  L = [0] * 5
  for i in range(5):
    L[i] = x % 10
    x //= 10
  if L[0] == L[4] and L[1] == L[3]:
    return 1
  else:
    return 0

ans = 0
for i in range(A, B + 1):
  ans += judge(i)

print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
int B = sc.nextInt(); 
int p = A+B;
int q = A-B;
int r = A*B;
int max = p;
if(max<q){
max = q;
}
if(max<r){
max = r;
}
System.out.println(max);
}
}


Measured memory_bytes: 21844
// Problem : D - Sum of Divisors
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 10000005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub uppper_bound
using namespace std;
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int arr[maxn];
void solve()
{
	int n;
	cin >> n;
	rep(i,0,n+1)
	arr[i]=i;
	rep(i,2,n+1)
	{
		if(arr[i] == i)
		for(int j=i;j*i<=n;j++)
		if(arr[j*i] == j*i)
		arr[j*i] = i;
	}
	int sol=1;
	rep(i,2,n+1)
	{
		int ans = 1;
		int cnt=0,curr=-1;
		int j = i;
		while(j > 1)
		{
			if(curr==-1)
				cnt++,curr=arr[j];
			else if(curr == arr[j])
				cnt++;
			else{
				ans*=(cnt+1);
				curr =arr[j];
				cnt=1;
			}
			j /= arr[j];
		}
		ans *=(cnt+1);
		sol  += (i*ans);
	}
	cout << sol;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


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


void solve(long long N, std::string S){
    vector<int> w(N+1);
    vector<int> b(N+1);
    w[0] = 0;
    b[0] = 0;
    for(long long i = 0; i < N; i++)
    {
        if (S[i]=='.') {
            w[i+1] = w[i]+1;
            b[i+1] = b[i];
        }
        else
        {
            w[i+1] = w[i];
            b[i+1] = b[i]+1;
        }
    }
    long long cnt = w[N];
    long long temp;
    for(long long i = 0; i < N+1; i++)
    {
        temp = b[i] + (w[N] - w[i]);
        if (temp < cnt) {
            cnt = temp;
        }
        
    }
    
    std::cout << cnt << endl;
    return;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


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

class Edge {
    public:
        int source, target, cost;
        Edge() {}
        Edge(int s = 0, int t = 0, int c = 0) : source(s), target(t), cost(c) {}
        bool operator < (const Edge &e) const { return cost < e.cost; }
};

class DisjointSet {
    public:
        DisjointSet() {}
        DisjointSet(int size) {
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i != size; ++i) makeSet(i);
        }

        void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x, int y) {
            return findSet(x) == findSet(y);
        }

        int findSet(int x) {
            if (x != p[x]) {
                p[x] = findSet(p[x]);
            }
            return p[x];
        }

        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }

        void link(int x, int y) {
            if (rank[x] > rank[y]) {
                p[y] = x;
            } else {
                p[x] = y;
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }
    private:
        vector<int> rank, p;
};

int kruskal(int n, vector<Edge> edges)
{
    int totalcost = 0;
    sort(edges.begin(), edges.end());
    DisjointSet dset = DisjointSet(n);
    for (int i = 0; i != edges.size(); ++i)
    {
        Edge e = edges[i];
        if ( !dset.same(e.source, e.target) )
        {
            totalcost += e.cost;
            dset.unite(e.source, e.target);
        }
    }
    return totalcost;
}

int main()
{
    int n, m, s, t, c;
    cin >> n >> m;
    vector<Edge> edges;
    for (int i = 0; i != m; ++i)
    {
        cin >> s >> t >> c;
        edges.push_back(Edge(s, t, c));
    }
    cout << kruskal(n, edges) << endl;
    return 0;
}


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

int main(){
	string s;
	cin >> s;
	int n = 0;
	if(s[0] == '1') n++;
	if(s[1] == '1') n++;
	if(s[2] == '1') n++;
	
	cout << n << endl;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

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

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;
int a[220000];

void no() {
	cout << -1 << "\n";
	exit(0);
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	ll ans = 0;
	if (a[0] != 0)
		no();
	for (int i = 1; i < n; ++i) {
		if (a[i] > a[i - 1] + 1)
			no();
		if (a[i] == a[i - 1] + 1)
			++ans;
		else {
			ans += a[i];
		}
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 1024
#include <cstdio>
using namespace std;
int N, M, k[11], s[11][11], p[11], ans;
int main() {
  scanf("%d %d", &N, &M);
  for(int i = 1; i <= M; ++i) {
    scanf("%d", &k[i]);
    for(int j = 1; j <= k[i]; ++j) scanf("%d", &s[i][j]);
  }
  for(int i = 1; i <= M; ++i) scanf("%d", &p[i]);

  for(int i = 0; i < (1<<N); ++i) {
    bool ok = true;
    for(int j = 1; j <= M; ++j) {
      int cnt = 0;
      for(int m = 1; m <= k[j]; ++m){
        if(i & (1<<(s[j][m]-1))) ++cnt;
      }
      ok &= (cnt%2 == p[j]);
    }
    if(ok) ++ans;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 128
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())

    if K == 0:
        ans = N * N
    else:
        ans = 0
        for b in range(K + 1, N + 1):
            ans += N // b * (b - K) + max(N % b - K + 1, 0)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    scan.close();

    String Nstr = String.valueOf(N);

    if(Nstr.charAt(0)-'0' == 7 || Nstr.charAt(1)-'0' == 7 || Nstr.charAt(2)-'0' == 7) {
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 27084
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

struct like2017 {
    lli i, j;
    lli cnt = 0;
    vector<lli> vec;

    like2017(lli n) {
        rep(i, 0, n + 1) {
            if (i % 2 == 0) {
                vec.push_back(0);
            }
            else {
                vec.push_back(1);
            }
        }
    }

    void check(lli n) {
        vec[1] = 0;
        vec[2] = 1;
        rep(i, 1, 100001) {
            if (vec[i] >= 1) {
                for(j = 2; j <= 100000 / i; j++) {
                    vec[i * j] = 0;
                }
                if (vec[(i + 1) / 2] >= 1) {
                    vec[i] = 2;
                }
            }
        }
        rep(i, 1, 100001) {
            if (vec[i] == 2) {
                cnt++;
            }
            vec[i] = cnt;
        }
    }

    lli search(lli a, lli b) {
        lli c = vec[b] - vec[a - 1];
        return c;
    }

    void print() {
        rep(i, 1, 100001) {
            if (vec[i] != vec[i - 1]) {
                cout << i << "は、" << vec[i] << "個目の2017に似てる数" << endl;
            }
        }
    }

};

int main() {
    lli q, l, r;
    vector<lli> ans;
    lli i, j, k;
    cin >> q;
    like2017 num(100000);
    num.check(1);
    rep(i, 0, q) {
        cin >> l >> r;
        ans.push_back(num.search(l, r));
    }
    //    num.print();
    rep(i, 0, q) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 2548
#include <iostream>

using namespace std;

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

    int ans = 1;
    for ( int i=0; i<N; i++ ) {
        if ( ans < K )
            ans *= 2;
        else
            ans += K;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int INF = 1e9+10;
 
 
int a[310][310];
int b[310], f[310];
 
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; ++i) {
		for (int j=1; j<=m; ++j) {
			scanf("%d", &a[i][j]);
		}
	}
 
	memset(f, 0, sizeof f);
	int ans = INF;
	for (int ii=m; ii>=1; --ii) {
		memset(b, 0, sizeof b);
		for (int i=1; i<=n; ++i) {
			for (int j=1; j<=m; ++j) {
				if (f[a[i][j]]) continue;
				b[a[i][j]] ++;
				break;
			}
		}
 
		int tmp = 0;
		int tmpi = 0;
		for (int i=1; i<=m; ++i) {
			if (tmp < b[i]) {
				tmpi = i;
				tmp = b[i];
			}
		}
 
		f[tmpi] = 1;
		ans = min(ans, tmp);
	}
 
	printf("%d\n", ans);
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var n float64
	fmt.Scan(&n)
	carrieableNums := ScanNums(5)
	sort.Ints(carrieableNums)
	minCarriableNum := carrieableNums[0]
	if float64(minCarriableNum) >= n {
		fmt.Println(5)
	} else {
		fmt.Println(int(math.Ceil(n / float64(minCarriableNum))) + 4)
	}
}


func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


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

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<String> set = new HashSet<>();
        for (int i = 0 ; i < n ; i++) {
            set.add(sc.next());
        }
        System.out.println(set.size());

    }

}

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

using namespace std;

bool jelProst(int n)
{
    for(int q=2; q*q<=n; q++)
    {
        if(n%q==0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    int x;
    cin>>x;
    for(int i=x; ; i++)
    {
        if(jelProst(i))
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

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

#define SZ(x) ((int)x.size())

const int N = (int)1e5+5;
const int base = (int)1e9+7;
int n;
ll A, B, a[N];
int tree1[N*4], tree2[N*4];
bool mark1[N*4], mark2[N*4];
vector<int> save1, save2;

void update(int tree[], vector<int> &save, bool mark[], int k, int l, int r, int p, int val) {
	if (l > r || l > p || r < p) return;
	if (l == r && r == p) {
		if (val && !mark[k]) mark[k] = true, save.push_back(k);
		tree[k] = val;
		return;
	}
	int mid = (l + r) >> 1;
	update(tree, save, mark, k << 1, l, mid, p, val);
	update(tree, save, mark, k << 1 | 1, mid + 1, r, p, val);
	tree[k] = (tree[k << 1] + tree[k << 1 | 1]) % base;
	if (tree[k] && !mark[k]) mark[k] = true, save.push_back(k);
}

int query(int tree[], int k, int l, int r, int p) {
	if (l > r || l > p) return 0;
	if (r <= p) return tree[k];
	int mid = (l + r) >> 1;
	return (query(tree, k << 1, l, mid, p) + query(tree, k << 1 | 1, mid + 1, r, p)) % base;
}

void clean(int tree[], vector<int> &save, bool mark[]) {
	while (SZ(save)) {
		tree[save.back()] = mark[save.back()] = 0;
		save.pop_back();
	}
}

int main() {
	scanf("%d%lld%lld", &n, &A, &B);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i + 1]);
	a[1] = a[2] - max(A, B), ++n;
	update(tree1, save1, mark1, 1, 1, n, 1, 1);
	update(tree2, save2, mark2, 1, 1, n, 1, 1);
	for (int i = 2; i < n; ++i) {
		int pos = upper_bound(a + 1, a + i, a[i + 1] - B) - a - 1;
		int val1 = query(tree1, 1, 1, n, pos);
		pos = upper_bound(a + 1, a + i, a[i + 1] - A) - a - 1;
		int val2 = query(tree2, 1, 1, n, pos);
		if (a[i + 1] - a[i] < A) clean(tree1, save1, mark1);
		if (a[i + 1] - a[i] < B) clean(tree2, save2, mark2);
		update(tree2, save2, mark2, 1, 1, n, i, val1);
		update(tree1, save1, mark1, 1, 1, n, i, val2);
	}
	int res = (query(tree1, 1, 1, n, n - 1) + query(tree2, 1, 1, n, n - 1)) % base;
	printf("%d", res);
	return 0;
}

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

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

    ll n, k, s;
    cin >> n >> k >> s;
    if (s == 1000000000LL) {
        rep(i, 0, k) cout << s << ' ';
        rep(i, k, n) cout << 1 << ' ';
    } else {
        rep(i, 0, k) cout << s << ' ';
        rep(i, k, n) cout << s + 1 << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1280