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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

signed main(){
    int N;cin>>N;
    int A,B;cin>>A>>B;
    int ans=0;
    for(int i=1;i<=N;i++){
        stringstream ss;ss<<i;
        string s=ss.str();
        int sum=0;
        rep(j,s.size())sum+=s[j]-'0';
        if(A<=sum&&sum<=B)ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N,W=map(int,input().split())
v=[0]*N
w=[0]*N
for i in range(N):
  v[i],w[i]= map(int,input().split())

dp=[[0 for _ in range(W+1)]  for _ in range(N+1)]

for i in range(1,N+1): #品物番号
    for j in range(1,W+1): # ナップサック容量
        maxi=0
        if j-w[i-1]>=0:
            maxi = max(maxi, dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1])
        else:
            maxi = max(maxi, dp[i-1][j])
        dp[i][j]=maxi
    
print(dp[-1][-1])


Measured memory_bytes: 25940
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String args[]) throws IOException {
		@SuppressWarnings("resource")
		Scanner cin = new Scanner(System.in);
		ArrayList<String> inLines = new ArrayList<String>();
		for (; cin.hasNext();) {
			inLines.add(cin.nextLine());
		}
		Solver solver = new Solver();
		solver.solve(inLines);
	}
}

class Solver {

	public void solve(ArrayList<String> inLines) {
		int N = Integer.parseInt(inLines.get(0));
		int ans = N * 800 - ((N / 15) * 200);
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
	string s;
	int bk;
	cin>>s;
	bk=(s.size()-1)/2-1;
	for(int i=0;i<((s.size()-1)/2+1)/2;i++){
		if(!(s[i]==s[i+bk]&&s[i]==s[i+(s.size()+1)/2]&&s[i]==s[i+(s.size()+1)/2+bk])){
			cout<<"No"<<endl;
			return 0;
		}
		bk-=2;
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

using namespace std;

using ll = long long;
const int N = 100100;

int sz[N];
bool del[N];
ll sum[N];
ll ans[N];
vector<pair<int, int>> g[N];

ll dfs(int u, int p) {
   ll ansv = 0;
   for (auto e : g[u]) {
      if (e.first != p) {
         ansv += (ans[e.second] * sz[e.first] + dfs(e.first, u));
      }
   }
   return ansv;
}

int main() {
   ios_base::sync_with_stdio(false);
   int n;
   cin >> n;
   for (int i = 1; i < n; ++i) {
      int u, v;
      cin >> u >> v;
      g[u].emplace_back(v, i);
      g[v].emplace_back(u, i);
   }
   multiset<pair<ll, int>> ms;
   for (int i = 1; i <= n; ++i) {
      cin >> sum[i];
      ms.emplace(sum[i], i);
      sz[i] = 1;
   }
   for (int i = 1; i <= n - 2; ++i) {
      int u = (--ms.end())->second;
      ms.erase(--ms.end());
      int v, id;
      for (auto e : g[u]) {
         if (!del[e.first]) {
            tie(v, id) = e;
            break;
         }
      }
      del[u] = true;
      sz[v] += sz[u];
      ans[id] = (sum[u] - sum[v]) / (n - 2 * sz[u]);
   }
   int u = 0, v = 0;
   for (int i = 1; i <= n; ++i) {
      if (!del[i] && u) {
         v = i;
      } else if (!del[i]) {
         u = i;
      }
   }
   int id = 0;
   for (auto e : g[u]) {
      if (e.first == v) {
         id = e.second;
      }
   }
   ans[id] = (sum[u] - dfs(u, v) - dfs(v, u)) / sz[v];
   for (int i = 1; i < n; ++i) {
      cout << ans[i] << "\n";
   }
}

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

int main() {
  string s; cin >> s;
  int q; cin >> q;
  ll min = 0;
  ll max = s.length()-1;
  vector<pair<int, char> > pairs;
  for (int i = 0; i < s.length(); i++) {
    pairs.push_back(make_pair(i, s.at(i)));
  }
  int rule = 0;
  int tmp;
  int tmpint;
  char tmpchar;
  rep(i,q) {
    cin >> tmp;
    if (tmp == 1) {
      if (rule == 0) {
        rule = 1;
      } else {
        rule = 0;
      }
    } else {
      cin >> tmpint;
      cin >> tmpchar;
      if (tmpint == 1) {
        if (rule == 0) {
          pairs.push_back(make_pair(min-1, tmpchar));
          min--;
        } else {
          pairs.push_back(make_pair(max+1, tmpchar));
          max++;
        }
      } else {
        if (rule == 0) {
          pairs.push_back(make_pair(max+1, tmpchar));
          max++;
        } else {
          pairs.push_back(make_pair(min-1, tmpchar));
          min--;
        }
      }
    }
  }
  if (rule == 0) {
    sort(pairs.begin(), pairs.end());
  } else {
    sort(pairs.begin(), pairs.end(), greater<pair<int, char> >());
  }
  string ans = "";
  for (int i = 0; i < pairs.size(); i++) {
    ans += pairs[i].second;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5872
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >>s;
    int t,u;
    t=0;u=0;
    bool v;
    v=false;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A')v=true;
        if(v) {
            t++;
        }
        if(s[i]=='Z')u=t;
        
    }
    cout <<u <<endl;
    return 0;
}


Measured memory_bytes: 640
import sys

n,k = map(int,input().split())
s = input()


tmp1 = s[0]
count = 1
data = []
zeros = 0

for i in range(1,len(s)):
    tmp2 = s[i]
    if tmp1 != tmp2:
        data.append((tmp1, count))
        if tmp1 == '0':
            zeros += 1
        tmp1 = tmp2
        count = 1
    else:
        count += 1

data.append((tmp1,count))
if tmp1 == '0':
    zeros += 1

ans = 0

if k >= zeros:
    print(len(s))
    sys.exit()    

if data[0][0] == '0':
    data.insert(0, (1,0))

if data[-1][0] == '0':
    data.append((1,0))

anstmp = 0
for i in range(2*k + 1):
    anstmp += data[i][1]

ans = max(ans, anstmp)

for i in range(zeros - k):
    anstmp -= data[2*i][1]
    anstmp -= data[2*i + 1][1]
    anstmp += data[2*k + 2*i + 1][1]
    anstmp += data[2*k + 2*i + 2][1]

    ans = max(ans, anstmp)


print(ans)

Measured memory_bytes: 10364
import bisect
import sys
input = sys.stdin.readline
n, q = [ int(v) for v in input().split() ]
s = input()
ac_list = []

for i in range(n-1):
	if s[i:i+2] == "AC":
		ac_list.append(i)


for i in range(q):
	l, r = [ int(v) for v in input().split() ]
	a = (bisect.bisect_left(ac_list, l-1))
	b = (bisect.bisect_right(ac_list, r-2))
	print(b-a)

Measured memory_bytes: 6056
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        double[] probs = new double[n];
        String[] parts = scanner.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            probs[i] = Double.parseDouble(parts[i]);
        }

        // dp[i][j] represent the probability of getting j coins by tossing i coins
        double[][] dp = new double[n + 1][n + 1];
        dp[0][0] = 1; // probability of getting 0 heads when 0 coins are tossed is 1

        // 0th column represent the probability of getting 0 heads, so there is only one possibility which is getting tails.
        // the probability of getting tails in ith toss is 1 - p[i].
        // since coins are tossed one after another the probabilities will get multiplied
        for (int r = 1; r <= n; r++) {
            dp[r][0] = dp[r - 1][0] * (1 - probs[r - 1]);
        }

        // when we toss a coin, the outcome could be head or tail
        // based on the above fact, in order to fulfil our assumption of getting j heads in i tosses, there are only two possibilities.
        // 1. we get a tail, that means we must have j heads in (i - 1) toss dp[i-1][j]
        // 2. we get a head, that means we must (j - 1) heads in i - 1 tosses. dp[i - 1][j - 1]
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                dp[i][j] = (dp[i - 1][j] * (1 - probs[i - 1])) + (dp[i - 1][j - 1] * probs[i - 1]);
            }
        }

        // we must have more heads, that means we wil consider only those i values,
        double res = 0;
        for (int i = n / 2 + 1; i <= n; i++) {
            res += dp[n][i];
        }

        System.out.println(res);
    }
}


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

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

fn main() {
    let n: usize = read();
    let s: String = read();
    let first = &s[.. n/2]; 
    let second = &s[n/2..]; 
    let ans = if first == second {"Yes"} else {"No"};
    println!("{}", ans);
}


Measured memory_bytes: 4352
patterns_dictionary = {}
patterns_dictionary[1] = 1
patterns_dictionary[2] = 1


def patterns(start_n, broken_n):
    # start;自分がいる場所，こわれていない．一つ前はこわれている
    diff = broken_n - start_n
    if diff in patterns_dictionary:
        return patterns_dictionary[diff]
    for ii in range(len(patterns_dictionary)+1, diff+1):
        patterns_dictionary[ii] = patterns_dictionary[ii-1] + patterns_dictionary[ii-2]
    ans = patterns(start_n, broken_n - 1) + patterns(start_n, broken_n - 2)
    patterns_dictionary[diff] = ans
    return ans


inp = input()
split_input = inp.split()
n = int(split_input[0])
m = int(split_input[1])
start = 0
patterns_count = 1
# broken_number = -1
for i in range(m+1):
    if i == m:
        broken = n + 1
    else:
        inp = input()
        broken = int(inp)
    if broken == start:
        # 二つ連続で通れない
        print(0)
        exit()
    # print(start, broken)
    p = patterns(start, broken)
    patterns_count = (patterns_count * p) % 1000000007
    start = broken + 1

print(patterns_count)






Measured memory_bytes: 468604
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <map>
using namespace std;

int main(){
  unsigned long long N;
  vector<unsigned long long> trans(5);
  unsigned long long time = 0;
  int min_i = 0;


  cin >> N;
  for(int i = 0;i < 5;i++){
    cin >> trans[i];
  }

  sort(trans.begin(),trans.end());

  if(N % trans[0] == 0){
    time = N / trans[0] + 4;
  }else{
    time = (N / trans[0] + 1) + 4;
  }
  cout << time << endl;
}


Measured memory_bytes: 256
def solve():
    n, m = map(int, input().split())
    a = [[] for _ in range(1 << 3)]
    ans = - 10 ** 14
    for _ in range(n):
        s = list(map(int, input().split()))
        for i in range(1 << 3):
            tmp = 0
            for j in range(3):
                if i >> j & 1:
                    tmp += s[j]
                else:
                    tmp -= s[j]
            a[i].append(tmp)
    for x in range(1 << 3):
        res = sorted(a[x], reverse=True)
        ans = max(ans, sum(res[:m]))
    print(ans)


solve()



Measured memory_bytes: 9472
#include <stdio.h>

int main()
{
    int n,d,x,res=0;
    scanf("%d", &n);
    scanf("%d %d", &d,&x);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    for(int i=1;i<=d;i++){
        for(int j=0;j<n;j++){
            if(((i-1)%a[j])==0){
                res++;
            }
        }
    }
    printf("%d\n", res+x);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int r=0, b=0;
    for(int i=0; i<n; i++){
        if(s[i]=='R') r++;
        else b++;
    }
    if(r>b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<cmath>
#include<map>
#include<vector>
#include<unordered_map>
#include<queue>
#include<cstring>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;  
const int N=1e5+10;
const int M=N*2;
const int INF=0x3f3f3f3f;
long long mypow(int x)
{
    long long res=1;
    for(int i=1;i<=x;i++)
        res*=2;
    return res;
}
int gcd(int a,int b)
{
    return b?a:gcd(b,a%b);
}
void solve()
{

    string s;
    cin>>s;
    if(s=="ABC")
        cout<<"ARC";
    else
        cout<<"ABC";
}
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    solve();
    getchar();
    getchar();
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>

using namespace std;

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

    int k, sum, a, b, c;
    bool flag = false;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= N - i; j++)
        {
            k = N - i - j;
            sum = 1000 * i + 5000 * j + 10000 * k;
            if(Y == sum){
                a = k; b = j; c = i;
                flag = true;
                break;
            }
        }
        if(flag) break;
    }

    if(flag){
        cout << a << " " << b << " " << c << endl;
    }
    else{
        cout << -1 << " " << -1 << " " << -1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin() z, (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  if (n % 2 == 1)
    cout << n / 2 + 1 << endl;
  else
    cout << n / 2 << endl;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if (a <= 5){
        cout << 0 << endl;
    }
    else if (a <= 12){
        cout << b / 2 << endl;
    }
    else{
        cout << b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def fact(n): #素因数分解
  f = []
  cnt = 0
  r = int(n**0.5)
  for i in range(2, r +2):
    while n % i == 0:
      cnt += 1
      n = n // i
    if cnt !=0:
      f.append([i,cnt])
      cnt = 0
  if i == 1:
    f.append([n,1])
  return f

n, p = map(int, input().split())
nn = fact(p)
aa = []

if n != 1:
  ans = 1
  for i in range(len(nn)):
    if nn[i][1] >= n:
      
      aa.append(nn[i][0]**(nn[i][1] // n))
  
  for i in range(len(aa)):
    ans *= aa[i]
else:
  ans = p

print(ans)

Measured memory_bytes: 9388
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	string s;
	cin >> s;
	int n=s.size();
	if(s[0]!='A'){
		cout << "WA" << endl;
		return 0;
	} else {
		int cnt=0;
		int x;
		if(s[1]=='C' || s[n-1]=='C'){
			cout << "WA" << endl;
			return 0;
		}		
		for(int i=1; i<n; i++){
			if(s[i]=='C'){
				cnt++;
			}
		}
		if(cnt!=1){
			cout << "WA" << endl;
			return 0;
		} else {
			for(int i=1; i<n; i++){
				bool flag=false;
				for(int j=0; j<26; j++){
					char t='a'+j;
					if(s[i]==t || s[i]=='C'){
						flag=true;
					}
				}
				if(!flag){
					cout << "WA" << endl;
					return 0;
				}
			}
		}
	}
	cout << "AC" << endl;
	
	return 0;
}

Measured memory_bytes: 256
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define NCK_MAX 510000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int move_x[] = {1,0,-1,0}, move_y[]={0,1,0,-1};

int main(int argc, char const *argv[]) {
  int h,w;
  std::cin >> h >> w;
  std::string s[h];
  int ans = 0;
  REP(i,h) std::cin >> s[i];
  REP(sx,h) REP(sy,w) {
    vector<vector<int>> d(h, vector<int>(w, INF));
    if (s[sx][sy] == '#') continue;
    d[sx][sy] = 0;
    queue<P> que;
    que.push(P(sx,sy));
    auto update = [&](int i, int j, int x){
      if (d[i][j] != INF || s[i][j] == '#') return;
      d[i][j] = x;
      que.push(P(i,j));
    };
    while (que.size()!=0) {
      int now_x = que.front().F,now_y=que.front().S;
      que.pop();
      // std::cout << "here" << '\n';
      REP(idx,4) {
        int dx=move_x[idx],dy=move_y[idx];
        int new_x=now_x+dx,new_y=now_y+dy;
        if (new_x < 0 || new_x >=h || new_y < 0 || new_y >= w) continue;
        update(new_x,new_y,d[now_x][now_y]+1);
      }
    }
    REP(idx_x,h) REP(idx_y,w) {
      if (ans < d[idx_x][idx_y] && d[idx_x][idx_y] !=INF) ans = d[idx_x][idx_y];
    }
  }
  std::cout << ans << '\n';

  return 0;
}


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

int main(){
    char a[15],b[15],c[15];
    scanf("%s %s %s",a,b,c);
    int lena = strlen(a);
    int lenb = strlen(b);
    if(a[lena-1]==b[0] && b[lenb-1] == c[0]) printf("YES");
    else printf("NO");
    return 0;
}


Measured memory_bytes: 128
/*Shivam Bhalla */
	  /* f2016941@pilani.bits-pilani.ac.in */



	  #include <iostream>
	  #include <cstdio>
	  #include <cstring>
	  #include <cstdlib>
	  #include <cctype>
	  #include <algorithm>
	  #include <map>
	  #include <vector>
	  #include <list>
	  #include <set>
	  #include <queue>
	  #include <deque>
	  #include <stack>
	  #include <iostream>
	  #include <string>
		#include <string.h>
	  #include <cmath>
	  #include <cassert>
	  #include <bits/stdc++.h>
	  #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
	  using namespace std;
	  long long maxv = 1e9;

int main(){
	long long A,B;
	cin>>A>>B;
	long long total=A+B;
	if(total%2==0)
		cout<<total/2;
	else
		cout<<"IMPOSSIBLE";
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int n, d, x; cin >> n >> d >> x;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    int ans = x;
    rep(i, n) {
        ans += (d - 1 + a[i]) / a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    int sum1 = a + b;
    int sum2 = b + c;
    int sum3 = c + a;
    int m = min(sum1, sum2);
    m = min(m, sum3);
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>

int main() {
    int a, b,c;

    scanf("%d%d", &a, &b);
    c = a + b;

    if (c % 3 == 0) {
        printf("Possible");
    } else if (a % 3 == 0) {
        printf("Possible");
    } else if (b % 3 == 0) {
        printf("Possible");
    } else  {
        printf("Impossible");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

class state{
public:
  char t;
  int w,l,id;
  bool operator<(const state & a)const {
    if (w != a.w)return w > a.w;
    if ( l != a.l)return l <a.l;
    return id < a.id;
  }
};

main(){
  int n;
  while(cin>>n && n){
    state data[n];    
    rep(i,n){
      cin>>data[i].t;
      data[i].id=i;
      data[i].w=0;
      data[i].l=0;
      rep(j,n-1){
	int tmp;cin>>tmp;
	if (  tmp == 0)data[i].w++;
	else if ( tmp == 1)data[i].l++;
      }
    }
    sort(data,data+n);
    rep(i,n)cout << data[i].t << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	double r, g;

	std::cin >> r >> g;

	std::cout << 2 * g - r << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
	ll sum=0;
	int i,a;
	cin>>a;
	for(i=1;i<=a;i++)
	{
		if(i%3!=0&&i%5!=0)sum+=i;
	}
	cout<<sum<<endl;
	return 0;
 } 

Measured memory_bytes: 3636
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

k,n,*a = [int(i) for i in read().split()]

d = max(j-i for i,j in zip(a,a[1:]))
d = max(d,k-a[-1]+a[0])

print(k-d)





Measured memory_bytes: 25124
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
int main()
{
  int t,n;
  cin>>n;
  int arr[10001]={0};
  reps(i,1,101) reps(j,1,101) reps(k,1,101){
      int x=i*i+j*j+k*k+i*j+i*k+j*k;
      if(x<10001) arr[x]++;
  }
  reps(i,1,n+1)
    cout<<arr[i]<<"\n";
  return 0;
}


Measured memory_bytes: 3632
from collections import Counter
N=int(input())
ll=[input() for i in range(N)]
ll=Counter(ll)
ll=ll.most_common()
ll=sorted(ll,key=lambda x:(x[1]),reverse=True)
ans=[l for l in ll if l[1]==ll[0][1] ]
ans=sorted(ans,key=lambda x:(x[0]),reverse=False)
for i in ans:
    print(i[0])


Measured memory_bytes: 43468
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] a){

		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

		String tmpString = null;
		int dataset = 0;

		try {
			if(null != (tmpString = bf.readLine())){
				dataset = Integer.parseInt(tmpString);
			}

			for(int i = 0; i < dataset; i++){
				if(null != (tmpString = bf.readLine())){
					double[] numbers = convert(tmpString);
					double distance = Math.sqrt(Math.pow(numbers[0] - numbers[3], 2) + Math.pow(numbers[1] - numbers[4], 2));
					if(numbers[2] + numbers[5] < distance){
						System.out.println("0");
					} else if(distance + numbers[2] < numbers[5]){
						System.out.println("-2");
					} else if(distance + numbers[5] < numbers[2]){
						System.out.println("2");
					} else {
						System.out.println("1");
					}
				}
			}
		} catch (IOException e) {
		}
	}


	private static double[] convert(String strings){
		String[] tmp = strings.split(" ");
		int count = tmp.length;
		double[] retval = new double[count];
		for(int i = 0; i < count; i++){
			retval[i] = Double.parseDouble(tmp[i]);
		}
		return retval;
	}
}

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

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

const int MAX = 1e2 + 5;
int times[MAX];

char other(char c) {
	return c == 'A' ? 'B' : 'A';
}

int main() {
	ios_base::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;
	deque<char> s;
	fori(i, 0, n) {
		char c;
		cin >> c;
		s.push_back(c);
	}

	int parity = 0;
	fori(i, 0, min(k, 2 * n)) {
		char f = s.front();
		if((f == 'A' && parity == 0) || (f == 'B' && parity == 1)) {
			*s.begin() = (f == 'A') ? 'B' : 'A';
		}
		else {
			s.pop_front();
			parity ^= 1;
			s.push_back(parity ? 'B' : 'A');
		}
	}

	for(auto &each : s) {
		each = parity ? other(each) : each;
	}

	if(k > 2 * n && ((k - 2 * n) & 1)) {
		if(s.front() == 'A') {
			*s.begin() = 'B';
		}
		else {
			s.pop_front();
			for(auto &each : s) {
				each = other(each);
			}
			s.push_back('A');
		}
	}

	for(auto &each : s) {
		cout << each;
	}
	cout << '\n';

	return 0;
}




Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {
	static FastReader in = new FastReader();

	public static void main(String[] args) {
		solve();
	}

	static void solve() {
		int n = in.nextInt();
		long[] a = new long[n];
		for(int i = 0; i < n; i++)
			a[i] = in.nextLong();
		
		long sum = 0;
		for(int i = 1; i < n; i++)
		{
			if(a[i] >= a[i - 1]) continue;
			else
			{
				sum += a[i - 1] - a[i];
				a[i] = a[i - 1];
			}
		}
		System.out.println(sum);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readarr(int abc) {
			int[] a = new int[abc];
			for (int i = 0; i < abc; i++)
				a[i] = nextInt();
			return a;
		}
	}
}





Measured memory_bytes: 55772
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>
using namespace std;
int counts[10][10];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i <= N; i++){
    string tmp = to_string(i);
    if(tmp[tmp.size() - 1] == '0'){
      continue;
    } else {
      counts[tmp[0] - '0'][tmp[tmp.size() - 1] -  '0'] ++;
    }
  }

  long long ans = 0;
  for(int i = 1; i < 10; i++){
    for(int j = 1; j < 10; j++){
      ans += counts[i][j] * counts[j][i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

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

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

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

const int mod = 1000000007;

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

  string s;
  cin >> s;

  long acnt = 0;
  long bcnt = 0;
  long ccnt = 0;

  rep(i, s.length()) {
    if(s[i] == 'a') {
      acnt++;
    } else if(s[i] == 'b'){
      bcnt++;
    } else {
      ccnt++;
    }
  }

  int mx = -INF;
  int mn = INF;
  mx = max(max(acnt, bcnt), ccnt);
  mn = min(min(acnt, bcnt), ccnt);

  cout << ((mx-mn>1)?"NO":"YES") << endl; 
}


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

int main()
{
	int n;
	char N[100001];
	int count = 1;
	cin >> n;

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

	for (int i = 0; i < n; i++)
	{
		if (i == n - 1)break;
		if (N[i] != N[i + 1])count++;
	}

	cout << count << endl;

	return 0;

}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(input.readLine());
        int b = Integer.parseInt(input.readLine());
        int c = Integer.parseInt(input.readLine());
        int target = Integer.parseInt(input.readLine());
        int count = 0;
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= b; j++) {
                for (int k = 0; k <= c; k++) {
                    if ((i * 500)+(j * 100) + (k * 50) == target)
                        count++;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21204
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(void) {
    int n,k;
    scanf("%d", &n); scanf("%d", &k);
    vector< vector<int> > graph;
    vector< vector<int> > incident;
    graph.resize(n);
    incident.resize(n);
    vector< int > edges_a(n-1), edges_b(n-1);
    
    for (int i = 0; i<n; i++) {
        graph[i].resize(n);
        for (int j=0; j<n; j++) {
            graph[i][j] = 0;
        }
    }

    for (int i =0; i < n-1; i++) {
        int x,y;
        scanf("%d %d", &x, &y);
        graph[x-1][y-1] = 1; graph[y-1][x-1] = 1;
        edges_a[i] = x-1; edges_b[i] = y-1;
        incident[x-1].push_back(y-1);
        incident[y-1].push_back(x-1);
    }

    //答えを探すDFS
    int root, node, num_delete_nodes;
    int ans= n+10;
    vector<int> distance(n,n+10);
    vector<int> visited(n,0);
    queue<int> dfs;
    int num_it;
    if(k%2 == 0) {
        num_it = n;
    } else {
        num_it = n-1;
    }

    for (int i=0; i<num_it; i++) {
        // 初期化　始まり
        num_delete_nodes = 0;
        for (int j=0; j<n; j++) {
            visited[j] = 0;
            distance[j] = n+10;
        }

        if (k%2 == 0) {
            visited[i] = 1;
            dfs.push(i);
            distance[i] = 0;
        } else {
            visited[edges_a[i]] = 1;
            dfs.push(edges_a[i]);
            distance[edges_a[i]] = 0;
            visited[edges_b[i]] = 1;
            dfs.push(edges_b[i]);
            distance[edges_b[i]] = 0;
        }
        // 初期化終わり

        // BFS main loop
        while(!dfs.empty()) {
            node = dfs.front();
            dfs.pop();
            for (int j=0; j<incident[node].size(); j++) {
                if(visited[incident[node][j]] == 0) {
                    visited[incident[node][j]] = 1;
                    dfs.push(incident[node][j]);
                    distance[incident[node][j]] = distance[node]+1;
                }
            }
        }

        //printf("nodes to delete are:");
        for (int j=0; j<n; j++) {
            if (distance[j] > (k/2) ) {
                num_delete_nodes++;
        //        printf("(%d : %d), ", j, distance[j]);
            }
        }
        //printf("distance: %d\n",num_delete_nodes);
        if (ans >= num_delete_nodes) {
            ans = num_delete_nodes;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 16128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

pair<ll, ll> L[222222];
pair<ll, ll> R[222222];

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

	vector<ll> A(N);
	vector<ll> As(N);

	REP(i, N) {
		cin >> A[i];
		As[i] = A[i];
	}

	REP(i, N - 1) As[i + 1] += As[i];

	/*REP(i, N) cout << As[i] << ' ';
	cout << endl;*/

	ll l, r;
	ll nowsum;

	l = 0;
	nowsum = A[0];
	for(r = 1; r < N; r++) {
		while(l < r - 1 && abs(2*nowsum - As[r]) > abs(2*(nowsum+A[l+1]) - As[r])) {
			l++;
			nowsum += A[l];
		}
		L[r] = MP(nowsum, As[r] - nowsum);
		//cout << l << ' ' << r << ' ' << L[r].FI << ' ' << L[r].SE << endl;
	}

	r = N - 1;
	nowsum = A[N - 1];
	for(l = N - 2; l > 0; l--) {
		while(l + 1 < r && abs(2*nowsum - (As[N-1]-As[l-1])) > abs(2*(nowsum+A[r-1]) - (As[N-1] - As[l-1]))) {
			r--;
			nowsum += A[r];
		}
		R[l] = MP(nowsum, (As[N-1]-As[l-1]) - nowsum);
		//cout << l << ' ' << r << ' ' << R[l].FI << ' ' << R[l].SE << endl;
	}

	ll ans = LLINF;
	for(int i = 1; i < N - 2; i++) {
		ll ma = max({L[i].FI, L[i].SE, R[i + 1].FI, R[i + 1].SE});
		ll mi = min({L[i].FI, L[i].SE, R[i + 1].FI, R[i + 1].SE});
		ans = min(ans, ma - mi);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9984
import math

n = int(input())

root=int(math.sqrt(n))
count=0
for i in range(1,n):
    for j in range(i,math.ceil((n/i))):
        if i*j<n:
            count+=1

count*=2
if root==math.ceil(math.sqrt(n)):
    root-=1
print(count-root)

Measured memory_bytes: 67864
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int inf = 0x3f3f3f3f;
int mp[30][30];
char str[20][122];
int dp[1<<15][15];
int st[122];
int getval(char *a,char *b)
{
    int la,lb,len;
    la = strlen(a),lb = strlen(b);

    for (int i = 0;i < la;i++)
        if (memcmp( &a[i],b,lb ) == 0) return 0;

    for (len = min(la,lb);len > 0;len--)
    {
        int i,j;
        for (i = la - len,j = 0;j < len;i++,j++)
            if (a[i] != b[j]) break;
        if (j == len) break;
    }
    return lb-len;
}

//int getval(int x,int y ){
//    int l1 = strlen(str[x]);
//    int l2 = strlen(str[y]);
//    if(l1 > l2)
//        for(int i = 0; i < l1; i++){
//            if(i + l2 > l1) break;
//            int h  = 0;
//            for(int j = 0; j < l2; j++){
//                if(str[x][i+j] == str[y][j]){
//                     h++;
//                }
//            }
//            if(h == l2) return 0;
//        }
//    int l = min(l1,l2),id = 0;
//    for(int i = l; i >= 1; i--){
//        bool flag = true;
//        for(int j = 0; j < i; j++){
//            if(str[x][l1 - (i - j)] == str[y][j] ) continue;
//            else {flag = false;break;}
//        }
//        if(flag) {id = i;break;}
//    }
//    //cout<<id<<endl;
//    return l2 - id;
//}
int main(){
    int N;
    while(cin>>N && N){
        memset(st,0,sizeof(st));
        for(int i  = 0; i < N; i++){
            scanf("%s",str[i]);
            st[i] = 1<<i;
        }
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                int t = getval(str[i],str[j]);
                if(t == 0) {
                    st[i] |= 1<<j;
                    mp[i][j] = 0;
                }
                else mp[i][j] = t;
               // cout<<i<<" "<<j<<" "<<mp[i][j]<<endl;
            }


        }
         memset(dp,-1,sizeof(dp));
         for (int i = 0;i < N;i++)
            dp[st[i]][i] = strlen(str[i]);

        for (int s = 0;s < (1<<N);s++)
            for (int i = 0;i < N;i++) if (dp[s][i] != -1)
            {
                for (int j = 0;j < N;j++) if (  !(s&1<<j)  )
                {
                    int tmp = s|st[j];//s|1<<j;
                    if (dp[tmp][j] == -1) dp[tmp][j] = dp[s][i]+mp[i][j];
                    else dp[tmp][j] = min(dp[tmp][j],dp[s][i]+mp[i][j]);
                }
            }

//        memset(dp,0x3f,sizeof(dp));
//        for(int i = 0; i < N; i++){
//                //cout<<s[i]<<endl;
//                dp[1<<i][i] = strlen(str[i]);
//        }
//
//        for(int i = 0; i < 1 << N; i++)
//            for(int j = 0; j < N; j++){
//                if(dp[i][j] == inf) continue;
//               // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
//                for(int k = 0; k < N; k++) if(!(i & 1 << k))
//                    dp[i|s[k]][k] = min(dp[i|s[k]][k],dp[i][j] + mp[j][k]);
//            }
        int ans = inf;
        for(int i = 0; i < N; i++)if(dp[(1<<N)-1][i]!=-1)
            ans = min(dp[(1<<N)-1][i],ans);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3128
n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int, input().split())))
length = 0
for i in range(n):
    for j in range(i + 1, n):
        length += ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2) ** 0.5
print(length / n * 2)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n, ans;
int c(int x, int y) {
    int base = y;
    int cnt = 0;
    while (base * y <= x) {
        base *= y;
    }
    while (x) {
        cnt += x / base;
        x %= base;
        base /= y;
    }
    return cnt;
}

int main() {
    cin >> n;
    ans = n;
    for (int i = 0; i * 9 <= n; ++i) {
        int j = (n - i * 9) / 6;
        int r = n - i * 9 - j * 6;
        int a = c(i, 9);
        int b = c(j, 6);
        ans = min(ans, r + a + b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
n = int(input())
mod = 10**9+7

prime = {}
for i in range(2, n+1):
    for j in range(2, int(i**0.5)+1):
        if i%j != 0:
            continue

        prime.setdefault(j, 1)

        while i%j == 0:
            i //= j
            prime[j] += 1

    if i != 1:
        if i not in prime:
            prime.setdefault(i, 1)
        else:
            prime[i] += 1

ans = 1
for k, v in prime.items():
    ans *= (v+1)%mod
print(ans%mod)


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


int main() {
	
	int N;
	string s;
	cin >> N >> s;
	vector<int> num(N,0);
	
	for(int i=1; i<N; i++){
		if(s.at(i)=='E') num.at(0)++;
	}
	for(int i=1; i<N; i++){
		num.at(i) += num.at(i-1);
		if(s.at(i-1)=='W') num.at(i)++;
		if(s.at(i)=='E') num.at(i)--;
	}
	
	sort(num.begin(), num.end());
	cout << num.front() << endl;
	
	
	return 0;
}

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

using namespace std;

#define inf (ll)1e15
#define ll long long
#define all(x) x.begin(), x.end()
#define x first
#define y second

int main(){

    cin.tie(0);
    cin.sync_with_stdio(0);

    #ifdef Cyborg101
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif


    int n;
    cin >> n;

    int a[3][n];
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < n; ++j){
            cin >> a[i][j];
        }
        sort(a[i], a[i] + n);
    }

    ll acc[3][n];
    memset(acc, 0, sizeof acc);
    iota(acc[0], acc[0] + n, 1);

    for(int i = 1; i < 3; ++i){
        for(int j = 0; j < n; ++j){
            int ub = upper_bound(a[i - 1], a[i - 1] + n, a[i][j] - 1) - a[i - 1];
            if(ub == 0)
                continue;
            acc[i][j] = acc[i - 1][ub - 1] + (j ? acc[i][j - 1] : 0);
        }
    }

    cout << acc[2][n - 1] << endl;

    return 0;
}

Measured memory_bytes: 3840
from itertools import product
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for bits in product(range(2), repeat=n):
    match = 0 # How many matches with the condition p?
    for num, tmp in enumerate(ks):
        k = tmp[0]
        switch = tmp[1:]
        total = sum(map(lambda x: bits[x-1], switch))
        if total % 2 == p[num]:
            match += 1
    if match == len(p):
        ans += 1
    match = 0

print(ans)


Measured memory_bytes: 43868
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

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

constexpr int evx[4] = { 1, 0, -1, 0 };
constexpr int evy[4] = { 0, 1, 0, -1 };

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;


int main()
{
    ios::sync_with_stdio(false);
    int n, l;
    vector<string> s;
    cin >> n >> l;
    REP(i, n)
    {
        string tmp;
        cin >> tmp;
        s.push_back(move(tmp));
    }
    sort(s.begin(), s.end());
    REP(i, n)
    {
        cout << s[i];
    }
    cout << '\n';
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>

typedef long long ll;

using namespace std;

int main() {
    int a, ans = 0;
	cin >> a;

	vector<int> data(a);

	for (int i = 0; i < a; i++) {
		cin >> data[i];
	}

	for (int i = 0; i < a-1; i++) {
		for (int j = i+1; j < a; j++) {
			if ((data[i] == 0) || (data[j] == 0)) {
				continue;
			}

			ans += data[i] * data[j];
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

struct node {
  int key;
  node *prev, *next;
};

node *head, head_s, *tail, tail_s;

void insert(int x) {
  node *next = head->next;
  node *nd = new node;
  nd->key = x;
  nd->next = next;
  nd->prev = head;

  next->prev = nd;
  head->next = nd;
}

void del_node(node *nd) {
  if (nd == head || nd == tail) return;
  node *next = nd->next;
  node *prev = nd->prev;
  prev->next = next;
  next->prev = prev;
  delete nd;
}

void del(int x) {
  for (node *nd = head->next; nd != tail; nd = nd->next) {
    if (nd->key == x) {
      del_node(nd);
      return;
    }
  }
}

void del_first() { del_node(head->next); }
void del_last() { del_node(tail->prev); }

void init_root() {
  head = &head_s;
  tail = &tail_s;
  head->next = tail;
  head->prev = head;
  tail->next = tail;
  tail->prev = head;
}

int main(int argc, char **argv)
{
  init_root();
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char buf[32];
    int x;
    scanf("%s", buf);
    string cmd(buf);
    if (cmd == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if (cmd == "delete") {
      scanf("%d", &x);
      del(x);
    } else if (cmd == "deleteFirst") {
      del_first();
    } else if (cmd == "deleteLast") {
      del_last();
    }
  }

  const char *sp = "";
  for (auto nd = head->next; nd != tail; nd = nd->next) {
    printf("%s%d", sp, nd->key);
    sp = " ";
  }
  putchar('\n');

  return 0;
}

Measured memory_bytes: 34544
#include<bits/stdc++.h>
#define DIST(x1,x2, y1, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
#define CLR(a) a.clear()
#define VCLR(a, n) for(int i=0; i<=n+3; i++) a[i].clear()
#define SIZE(a) a.size()
#define ERASE(a, b) memset(a, b, sizeof a)
#define PB(a, b) a.push_back(b)
#define PB2(a,i,b) a[i].push_back(b)
#define LL long long
#define DBG cout<<"I Am Here"<<endl
#define DBGA(a) cout<<a<<endl
#define DBGI(b,a) cout<<b<<' '<<a<<endl
#define DBGL(i,s,e,b) or(int i=s; i<=e; i++) cout<<b<<endl
#define INF 1e9
#define INV 1e-6
#define sll(a) scanf("%I64d", &a)
#define pll(a) printf("%I64d\n", a)
#define si(a) scanf("%d", &a)
#define pii pair<int,int>
#define MAX 600005
#define CASE(i) printf("Case %d: ", i);
#define PI acos(-1)
#define piis pair<int, string>
#define fast1 ios_base::sync_with_stdio(false);
#define fast2 cin.tie(0)

using namespace std;

int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    int five = 0, seven = 0;
    if(a==5) five++; if(a==7) seven++;
    if(b==5) five++; if(b==7) seven++;
    if(c==5) five++; if(c==7) seven++;
    if(five==2 && seven==1)
        printf("YES");
    else
        printf("NO");
}


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

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

  if(A < C && C < B || A > C && C > B) cout << "Yes" << endl;
  else cout << "No" << endl;
}



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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;

	cout << (N + 1) / 2 << endl;

	return 0;
}

Measured memory_bytes: 256