akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <set>

using namespace std;

set<string> ans;
bool noans;

void solve(char a, string &str, int r = -1){
//	cout << "solve: " << str << " " << a << r << endl;
	if( a == 'a' ){
		ans.insert( str );
		return;
	}
	a--;
	int f = -1, count=0, countnow=0;
	for(int i=0; i<str.length(); i++){
		if( str[i] == a+1 ){
			count++;
			if( count > 1 && countnow == 0 ){
				noans = true;
				return;
			}
		}
		if( str[i] == a ){
			countnow++;
			if( (r == -1 || r > i )&& count == 0){
				if( f < 0 ){
					f = i;
				}else if( a < 'z' ){
					solve( a, str, f );
				}
				if( a < 'z' ){
				//	solve( a, tmp, f );
					string tmp = str;
					tmp[i] = a+1;
					solve( a, tmp );
				}
			}
		}
	}
	if( r<0 )
		solve( a, str, f );
}

int main(){
	string str;
	set<string>::iterator it;
	while(cin>>str, str[0] != '#'){
		ans.clear();
		noans = false;
		// ?§£???
		int count[256]={0}, flag=0;
		for(int i=0; i<str.length(); i++) count[ str[i] ]++;
		for(int a='a'; a<'z'; a++){
			if( count[a] == 0 && count[a+1] > 1 ){
				flag = 1;
				cout << 0 << endl;
				break;
			}
		}
		if( flag ) continue;
		solve( 'z'+1, str );
		// ??????
		if( noans ){
			cout << 0 << endl;
			continue;
		}
		cout << ans.size() << endl;
		if( ans.size() <= 10 ){
			for(it = ans.begin(); it != ans.end(); it++){
				cout << *it << endl;
			}
		}else{
			int count=0;
			for(it = ans.begin(); count < 5; it++, count++){
				cout << *it << endl;
			}
			for(it = ans.end(); count > 0; it--, count--){}
			for(; count < 5; it++, count++){
				cout << *it << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3136
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int ans = 0;
    char temp = '9';
    for(int i = 0; i < n; i++) {
      char c = s.charAt(i);
      if(temp != c) {
        ans++;
        temp = c;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 39704
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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; }

// ??????????????? ????°?
#define MAX_N 2000010
int heap[MAX_N], sz = 0;
void push(int x) {
	int v = sz++;
	while (v > 0) {
		int p = (v - 1) / 2;
		if (heap[p] <= x)break;
		heap[v] = heap[p];
		v = p;
	}
	heap[v] = x;
}
int pop() {
	int ret = heap[0];
	int back = heap[--sz];
	int v = 0;
	while (v * 2 + 1 < sz) {
		// l ??¨ r ??????????°???????????????¨???????????????
		int l = v * 2 + 1, r = v * 2 + 2;
		int u = (r >= sz || heap[l] < heap[r]) ? l : r;
		// ???????????¢???????????????
		if (heap[u] >= back)break;
		heap[v] = heap[u];
		v = u;
	}
	heap[v] = back;
	return ret;
}
int top() {
	return heap[0];
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	char s[10];
	while (~scanf("%s", &s)) {
		if (s[0] == 'i') {
			int a; scanf("%d", &a);
			push(-a);
		}
		else if (s[1] == 'x') {
			printf("%d\n", -pop());
		}
		else {
			break;
		}
	}
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    ll n, m;
    cin >> n >> m;
    ll ok = 0;
    ll ng = 1e14;
    while(ng - ok > 1) {
        ll mid = (ok + ng) / 2;
        ll C = m - 2 * mid;
        if(C < 0) {
            ng = mid;
            continue;
        }
        ll S = n + C / 2 - mid;
        if(S >= 0) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := newScanner()
	var n = sc.readInt()
	var x = sc.readInt()
	var t = sc.readInt()
	if n%x == 0 {
		fmt.Println(n / x * t)
	} else {
		fmt.Println((n/x + 1) * t)
	}

}

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

func abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

func reverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func reverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type scanner struct {
	bufScanner *bufio.Scanner
}

func newScanner() *scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &scanner{bufSc}
}

func (sc *scanner) readString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *scanner) readInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}

func (sc *scanner) readInt64() int64 {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.ParseInt(text, 10, 64)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1772
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func readStrings() -> [String] { readLine()!.split(separator: " ").map { String($0) } }

let (a, b) = toTuple(readStrings())
let n = floor(sqrt(Double(a + b)!))
if n == sqrt(Double(a + b)!) {
  print("Yes")
} else {
  print("No")
}

Measured memory_bytes: 13264
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define rev(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ O(logN)
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//





int main() {
    
    int H, N; cin >> H >> N;
    vector<int> a(N), b(N);
    rep(i,N) {
        cin >> a[i] >> b[i];
    }
    
    int M = 40000;
    vector<ll> dp(M);
    rep(i,M) dp[i] = INF;
    dp[0] = 0;
    for (int i = 1; i <= H+20000; ++i) {
        for (int j = 0; j < N; ++j) {
            if (0 <= i - a[j]) dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
        }
    }

    ll ans = INF;
    for (int i = H; i < M; ++i) ans = min(ans, dp[i]);

    out(ans);
    
    return 0;
}






Measured memory_bytes: 640
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<double,double>P;

signed main(){
  int n,t,nt;
  double f,nf,a,x,y,na,nx,ny;
  cin>>n;
  cin>>f>>a>>t>>x>>y;
  vector<P>v[2];
  r(i,n-1){
    cin>>nf>>na>>nt>>nx>>ny;

    if(t==nt && a!=na){
      double len = sqrt((x-nx)*(x-nx)+(y-ny)*(y-ny));
      v[t].push_back(P(-len,(nf-f)/60));
    }
    a=na;
    f=nf;
    x=nx;
    y=ny;
    t=nt;
  }

  r(i,2)sort(v[i].begin(),v[i].end());

  r(i,2){
    if((int)v[i].size()==0)cout<<"-1 -1"<<endl;
    else{
      printf("%.9f %.9f\n",-v[i][0].first,v[i][0].second);
    }
  }
}


Measured memory_bytes: 3224
#include<stdio.h>
void bubbleSort(int*,int);
int main(){
	int a,b,i,j;
	int array[100];
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&array[i]);
	}
	bubbleSort(array,a);
	return 0;
}

void bubbleSort(int* x,int y){
	int i,j,flag=1,count=0;
	while(flag){
		flag=0;
		for(i=y-1;i>=1;i--){
			if(x[i] < x[i-1]){
				j=x[i];
				x[i]=x[i-1];
				x[i-1]=j;
				flag=1;
				count++;
			}
		}
	}
	for(i=0;i<y;i++){
		if(i==y-1){
			printf("%d\n",x[i]);
		}
		else{
			printf("%d ",x[i]);
		}
	}
	printf("%d\n",count);
}


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

using namespace std;
#define N 100100
#define SIGMA 26

map<string, int> a;
vector <string> v;
string s;
int i, n, mx;
int main()
{
    int T = 1;
    //cin >> T;
    for (int tt = 0; tt < T; ++tt){
        cin >> n;
        for (i = 0; i < n; ++i){
            cin >> s;
            ++a[s];
            if (a[s] == mx){
                v.push_back (s);
            }
            else if (a[s] > mx){
                mx = a[s];
                v.clear();
                v.push_back (s);
            }
        }
        sort (v.begin(), v.end());
        for (i = 0; i < v.size(); ++i)
            cout << v[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 26736
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);

		List<Set<Integer>> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			Set<Integer> set = new HashSet<>();
			for (int j = 0; j < n; j++) {
				if (i != j) {
					set.add(j);
				}
			}
			list.add(set);
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			list.get(a).remove(b);
			list.get(b).remove(a);
		}
		br.close();

		List<Integer> g1 = new ArrayList<>();
		List<Integer> g2 = new ArrayList<>();
		int[] grp = new int[n];
		for (int i = 0; i < n; i++) {
			if (grp[i] != 0) {
				continue;
			}
			Queue<Integer> que = new ArrayDeque<>();
			que.add(i);
			grp[i] = 1;
			int cnt1 = 1;
			int cnt2 = 0;
			while (!que.isEmpty()) {
				int cur = que.poll();
				for (int next : list.get(cur)) {
					if (grp[next] == 0) {
						grp[next] = 3 - grp[cur];
						que.add(next);
						if (grp[next] == 1) {
							cnt1++;
						} else {
							cnt2++;
						}
					} else if (grp[next] == grp[cur]) {
						System.out.println(-1);
						return;
					}
				}
			}
			g1.add(cnt1);
			g2.add(cnt2);
		}

		boolean[] dp = new boolean[n + 1];
		dp[0] = true;
		for (int i = 0; i < g1.size(); i++) {
			boolean[] work = new boolean[n + 1];
			for (int j = n - 1; j >= 0; j--) {
				if (dp[j]) {
					work[j + g1.get(i)] = true;
					work[j + g2.get(i)] = true;
				}
			}
			dp = work;
		}

		int ans = Integer.MAX_VALUE;
		for (int i = 1; i <= n; i++) {
			if (dp[i]) {
				int val1 = i * (i - 1) / 2;
				int val2 = (n - i) * (n - i - 1) / 2;
				ans = Math.min(ans, val1 + val2);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 89072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
using R = double;
using P = complex<R>;
#define x real()
#define y imag()
const R eps = 1e-9,PI = acos(-1);

bool equal(R a,R b){return abs(b-a)<eps;}
bool equal0(R a){return equal(a,0.0);}

P operator*(const P& p,const R& d){
    return P(p.x*d,p.y*d);
}

istream &operator>>(istream& is,P& p){
    R a,b;
    is >> a >> b;
    p = P(a,b);
    return is;
}

ostream &operator<<(ostream& os,P& p){
    os << fixed << setprecision(10) << p.real() << " " << p.imag();
}
//内積
double dot(P a,P b) {return (conj(a)*b).real();}
//外積
double cross(P a,P b) {return (conj(a)*b).imag();}

struct L{
    P a,b;
    L(P a,P b):a(a),b(b){}
    L(R A,R B,R C){
        if(equal(A,0)) a = P(0,C/B),b = P(1,C/B);
        else if(equal(B,0)) b = P(C/A,0),b = P(C/A,1);
        else a = P(0,C/B),b = P(C/A,0);
    }
};

//pをbに射影
P projection(P p,P b) {return b*dot(p,b)/norm(b);}

//pとp1 to p2 に射影
P projection(L l,P p){
    p -= l.a; l.b -= l.a;
    P proj = projection(p,l.b);
    return l.a+proj;
}

struct S:L{
    S(P a,P b):L(a,b){}
};

//点の回転方向を判定
int ccw(P p0,P p1,P p2){
    p1 -= p0,p2 -= p0;
    if(cross(p1,p2)>eps) return 1; //"COUNTER_CLOCKWISE"
    if(cross(p1,p2)<-eps) return -1; //"CLOCKWISE"
    if(dot(p1,p2)<0) return 2; //"ONLINE_BACK"
    if(norm(p1)<norm(p2)) return -2; //"ONLINE_FRONT"
    return 0; //"ON_SEGMENT"
}

bool is_parallel(L l1,L l2){
    return equal0(cross(l1.b-l1.a,l2.b-l2.a));
}

bool is_orthogonal(L l1,L l2){
    return equal0(dot(l1.b-l1.a,l2.b-l2.a));
}

//pをlに関して対称移動
P reflection(L l,P p){
    P pj = projection(l,p);
    return 2.0*pj-p;
}

//pがl上にあるか
bool is_online(L l,P p){
    return abs(ccw(l.a,l.b,p))!=1;
}

bool is_onsegment(S s,P p){
    return ccw(s.a,s.b,p)==0;
}

//線分の交差判定
bool intersect(S s,S t){
    return ccw(s.a,s.b,t.a)*ccw(s.a,s.b,t.b)<=0 && ccw(t.a,t.b,s.a)*ccw(t.a,t.b,s.b)<=0;
}

//2直線の交点
P crosspoint(L l1,L l2){
    R a = cross(l1.b-l1.a,l2.b-l2.a);
    R b = cross(l1.b-l1.a,l1.b-l2.a);
    if(equal0(abs(a)) && equal0(abs(b))) return l2.a;
    return l2.a+(l2.b-l2.a)*b/a;
}

P crosspoint(S s1, S s2){
    return crosspoint(L(s1),L(s2));
}

R dist(P a,P b){
    return abs(a-b);
}

R dist(L l,P p){
    return abs(p-projection(l,p));
}

R dist(L l1,L l2){
    return is_parallel(l1,l2)? 0:dist(l1,l2.a);
}

R dist(S s,P p){
    P r = projection(s,p);
    if(is_onsegment(s,r)) return abs(r-p);
    return min(dist(s.a,p),dist(s.b,p));
}

R dist (S s1,S s2){
    if(intersect(s1,s2)) return 0;
    return min({dist(s1,s2.a),dist(s1,s2.b),
    dist(s2,s1.a),dist(s2,s1.b)});
}

int main(){
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        P p1,p2,p3,p4;
        cin >> p1 >> p2 >> p3 >> p4;
        R d = dist(S(p1,p2),S(p3,p4));
        cout << fixed << setprecision(10) << d << endl;
    }
}


Measured memory_bytes: 3360
#include <iostream>
#include <string.h>
using namespace std;

int s(char* n){
        int retval=0;
        int i=0;
        while(n[i]!='\0'){
            retval+=n[i]-'0';
            i++;
        }
        return retval;
}

int main(void){
        char n[100000];
        while(1) {
                cin>>n;
                if(strcmp(n,"0")==0) {
                        return 0;
                }
                cout<<s(n)<<endl;
        }
        return 0;
}



Measured memory_bytes: 3088
const fs = require("fs");
const input = fs.readFileSync("/dev/stdin", "utf8");

const [a, b, c] = input.split(" ").map((s) => parseInt(s, 10));

//const [a, b, c] = [249999999, 250000000, 999999998];
const N = 67108863;
const d = c - a - b;

const split = (v: number): [number, number] => {
  return [v % N, Math.floor(v / N)];
};
const mul = ([v1, v2]: [number, number], [u1, u2]: [number, number]) => {
  let r = [v1 * u1, v1 * u2 + v2 * u1, u2 * v2];
  r[1] += Math.floor(r[0] / N);
  r[0] = r[0] % N;

  r[2] += Math.floor(r[1] / N);
  r[1] = r[1] % N;
  return r;
};

const lhs = mul(split(a * 2), split(b * 2));
const rhs = mul(split(d), split(d));
if (d <= 0) {
  console.log("No");
} else {
  if (lhs[2] < rhs[2]) {
    console.log("Yes");
  } else if (lhs[2] > rhs[2]) {
    console.log("No");
  } else if (lhs[1] < rhs[1]) {
    console.log("Yes");
  } else if (lhs[1] > rhs[1]) {
    console.log("No");
  } else if (lhs[0] < rhs[0]) {
    console.log("Yes");
  } else {
    console.log("No");
  }
  //console.log(4 * a * b < d * d ? "Yes" : "No");
}

Measured memory_bytes: 7372
#EDPC
N,W = map(int,input().split())
WV = [list(map(int,input().split())) for i in range(N)]
dp = [[0 for i in range(W+1)] for j in range(N+1)]
for i in range(N):
    w,v = WV[i][0],WV[i][1]
    for j in range(W+1):
        if j >= w:
            dp[i+1][j] = max(dp[i][j-w]+v,dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
MAX = 0
for i in range(N+1):
    for j in range(W+1):
        MAX = max(MAX,dp[i][j])
print(MAX)

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n;
  cin >> n;
  string s, t="";
  vecll m(26, LLONG_MAX);
  forll(i, 0, n){
	cin >> s;
	vecll a(26, 0);

	forll(j, 0, s.size()){
	  a[s[j] - 'a'] += 1;
	}
	forll(j, 0, 26){
	  m[j] = min(a[j], m[j]);
	}
  }
  forll(j, 0, 26){
	if (m[j] == LLONG_MAX)
	  m[j] = 0;
	t += string(m[j], (char)('a' + j));
  }
  cout << t << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] vx = new long[n];
		long[] vy = new long[n];
		long[] vh = new long[n];
		int si = -1;
		for (int i = 0; i < n; i++) {
			vx[i] = in.nextLong();
			vy[i] = in.nextLong();
			vh[i] = in.nextLong();
			if (vh[i] > 0) {
				si = i;
			}
		}
		for (int x = 0; x <= 100; x++) {
			for (int y = 0; y <= 100; y++) {
				long h = vh[si] + Math.abs(x - vx[si]) + Math.abs(y - vy[si]);
				boolean isOk = true;
				for (int i = 0; i < n; i++) {
					if (vh[i] > 0 && h - vh[i] != Math.abs(x - vx[i]) + Math.abs(y - vy[i])) {
						isOk = false;
					}
					if (vh[i] == 0 && h > Math.abs(x - vx[i]) + Math.abs(y - vy[i])) {
						isOk = false;
					}
				}
				if (isOk) {
					System.out.println(x);
					System.out.println(y);
					System.out.println(h);
					in.close();
					return;
				}
			}
		}
	}
}

Measured memory_bytes: 22356
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, b*c, a*d, b*d}) << "\n";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
typedef long long ll;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> sw(m+1);
  for (int i = 1; i <= m; i++) {
    int x;
    cin >> x;
    while (x--) {
      int v;
      cin >> v;
      sw[i].push_back(v);
    }
  }
  // n is num of switch
  int p[m+1];
  ll ans = 0;
  for (int i = 1; i <= m; i++) cin >> p[i];
  for (int mask = 0;  mask < (1<<n); mask++) {
    vector<bool> vis(n+1);
    int k = 0;
    while ((1<<k) <= mask) {
     if ( (1<<k) & mask ){
       vis[k+1] = true;
     } 
     k++;
    }
    bool ok = true;
    for (int lamp = 1; lamp <= m; lamp++) {
      int cek = 0;
      for (auto it: sw[lamp]) {
        if (vis[it]) cek++;
      }
      if (cek%2 != p[lamp]) {
        ok = false;
        break;
      }
    }
    if (ok) ans++;
  }
  cout << ans << el;
  return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define ll long long
#define sz size()
#define all(x) x.begin(), x.end()
#define forn(x) for(int i=1;i<=x;i++) 
#define sforn(x, y) for(int i=1;i<=x;i++)for(int j=1;j<=y;j++)
#define pii pair<int, int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

/*
    LOL KEK CHEBUREK
 
    PIHALITI
 
 */
ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a%b);
}

int main(){ speed;
    ll a, b;
    cin >> a >> b;
    ll d = gcd(a, b);
    ll cnt = 1;
    ll ind = 2;
    while(d > 1){
        if(d % ind == 0){
            ++cnt;
            while(d % ind == 0){
                d /= ind;
            }
        }
        ++ind;
        if(ind * ind > d) break;
    }
    if(d != 1) ++ cnt;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    static class Node{
        List<Integer> to;
        Node(){
            to = new ArrayList<Integer>();
        }
    }
    static public class IntPair{
        int x, y;
        public IntPair(int xx, int yy){
            x = xx;
            y = yy;
        }
        @Override
        public int hashCode(){
            return Long.hashCode(((long)x << 31) + y);
        }
        @Override
        public boolean equals(Object o){
            if(!(o instanceof IntPair)){
                return false;
            }
            IntPair temp = (IntPair) o;
            return x == temp.x && y == temp.y;
        }
    }
    static Node g[];
    static int ans[];
    static Map<IntPair, Integer> mp;
    public static void dfs(int s, int p, int c){
        if(p != -1){
            ans[mp.get(new IntPair(s, p))] = c;
        }
        int now = 1;
        for(Integer x : g[s].to){
            if(x == p)continue;
            if(now == c)now++;
            dfs(x, s, now++);
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        g = new Node[n];
        ans = new int[n - 1];
        mp = new HashMap<>();
        for(int i = 0; i < n; i++){
            g[i] = new Node();
        }
        for(int i = 0; i < n - 1; i++){
            Integer a = sc.nextInt() - 1;
            Integer b = sc.nextInt() - 1;
            g[a].to.add(b);
            g[b].to.add(a);
            mp.put(new IntPair(a, b), i);
            mp.put(new IntPair(b, a), i);
        }
        dfs(0, -1, 10000000);
        int mx = -1;
        for(int i : ans){
            mx = Math.max(mx, i);
        }
        System.out.println(mx);
        for(int i : ans){
            System.out.println(i);
        }
    }
}



Measured memory_bytes: 117992
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    ll n,m;
    cin >> n >> m;
    if(n*2 < m) {
        m -= n*2;
        cout << n+m/4 << endl;
    } else {
        cout << m/2 << endl;
    }
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 998244353;
const int maxn = 2e5+10;



int n, m, k;
ll dp[maxn];


ll fac[maxn], ifac[maxn], inv[maxn];

ll nck(ll n, ll k) {
    if (n<k) return 0;
    return fac[n]*ifac[k]%mod*ifac[n-k]%mod;
}

void gen_inv() {
    fac[0]=inv[0]=ifac[0]=1;
    fac[1]=inv[1]=ifac[1]=1;

    for (int i=2; i<maxn; i++) {
	fac[i]=fac[i-1]*i%mod;
	inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	ifac[i]=ifac[i-1]*inv[i]%mod;
    }

    assert(nck(4,2)==6);
}

ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    gen_inv();
    cin>>n>>m>>k;

    ll res=0;


    //iterate over same
    for (int i=0; i<=k; i++) {
	ll terms=n-1-i+1;
	ll cur=nck(n-1,n-1-i)*m%mod*pw(m-1, terms-1)%mod;
	res+=cur;
	res%=mod;
    }

    res%=mod;
    res+=mod;
    res%=mod;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 8324
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int lli;
const lli mod = 1e9 +7;

void dfs(int node, vector<int> &ord, vector<bool> &used, vector<vector<int> > &adj){
    if(used[node]) return;
    used[node] = true;
    for(int to: adj[node]){
        dfs(to, ord, used, adj);
    }
    ord.push_back(node);
}
 
vector<vector<int> > scc_decomposition(vector<vector<int> > &adj){
    int n = adj.size();
    vector<vector<int> > revadj(n);
    for(int i=0; i<n; i++){
        for(int to: adj[i]){
            revadj[to].push_back(i);
        }
    }
     
    vector<bool> used(n, false);
    vector<int> ord;
    for(int i=0; i<n; i++){
        if(used[i]) continue;
        dfs(i, ord, used, adj);
    }
    used = vector<bool>(n, false);
    vector<vector<int> > res;
    for(int i=n-1; i>=0; i--){
        if(used[ord[i]]) continue;
        res.emplace_back();
        dfs(ord[i], res.back(), used, revadj);
        sort(res.back().begin(), res.back().end());
    }
    return res;
}

lli solve(vector<vector<int> > &adj){
    int n = adj.size();
    vector<int> ord_in(n, 0);
    for(vector<int> v: adj){
        for(int i: v){
            ord_in[i]++;
        }
    }

    queue<int> wait;
    for(int i=0; i<n; i++){
        if(ord_in[i] == 0) wait.push(i);
    }
    lli ans = 1;
    vector<lli> dp(n, 1);
    while(!wait.empty()){
        int cur = wait.front();
        wait.pop();
        for(int i: adj[cur]){
            dp[i] *= dp[cur] +1;
            dp[i] %= mod;
            ord_in[i]--;
            if(ord_in[i] == 0) wait.push(i);
        }
        if(adj[cur].empty()){
            ans *= (dp[cur] +1);
            ans %= mod;
        }
    }
    return ans;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > adj(n);
    for(int i=0; i<m; i++){
        int s,d;
        cin >> s >> d;
        s--; d--;
        adj[s].push_back(d);
    }

    vector<vector<int> > scc = scc_decomposition(adj);
    vector<int> conv(n);
    for(int i=0; i<(int)scc.size(); i++){
        for(int j: scc[i]){
            conv[j] = i;
        }
    }

    {
        vector<vector<int> > newadj(scc.size());
        for(int i=0; i<n; i++){
            for(int j: adj[i]){
                if(conv[i] == conv[j]) continue;
                newadj[conv[i]].push_back(conv[j]);
            }
        }
        for(vector<int> v: newadj){
            sort(v.begin(), v.end());
            v.erase(unique(v.begin(), v.end()), v.end());
        }
        adj = newadj;
    }
    
    cout << solve(adj) << endl;
    return 0;
}



Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
 
int64_t lNum(int n){
    if(n==0){
      return 2;
    }
    else if(n==1){
      return 1;
    }
    else{
    int64_t a=2,b=1,c;
    for(int i=0;i<n-1;i++){
      c=a+b;
      a=b;
      b=c;
    }
    return b;
  }
}

int main() {
  int n;
  int64_t m;
  cin>>n;
  m=lNum(n);
  printf("%lld",m);
}

Measured memory_bytes: 3724
N = int(input())
X = list(map(int, input().split()))
X_sort = sorted(X)
m_1 = X_sort[N//2]
m_2 = X_sort[N//2-1]
for i in range(N):
    x = X[i]
    if x<= m_2:
        print(m_1)
    else:
        print(m_2)

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//main code

int main(int argc, char const* argv[])
{
	string l;
	cin >> l;
	LL ans = 0;
	VVL dp(l.size()+1, VL(2,0)); // dp[i][j] i:上からi桁目まで見たとき j:0->i桁一致, 1->L未満が確定している
	dp[0][0] = 1;
	for (int i = 1; i <= l.size(); i++) {
		// i桁目が0で，
		if (l[i-1] == '0') {
			// a+bで0にする時
			// i-1でj=0 だった個数をそのまま
			dp[i][0] += dp[i-1][0];
			// j=1も同じ
			dp[i][1] += dp[i-1][1];
			// a+bで1にする時
			// j=0はありえない
			// j=1はi-1の時の*2になる(aで1を立てる or bで1を立てる
			dp[i][1] += (dp[i-1][1]*2)%MOD;
		}
		// i桁目が1で，
		else {
			// a+bで0にする時
			// i-1でのj=0,1どちらもj=1になる
			dp[i][1] += dp[i-1][0] + dp[i-1][1];
			// a+bで1にする時
			// j=0,j=1はそれぞれi-1の時の*2になる
			dp[i][0] += (dp[i-1][0]*2)%MOD;
			dp[i][1] += (dp[i-1][1]*2)%MOD;
		}
	}
	ans = (dp[l.size()][0] + dp[l.size()][1])%MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5840
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int N, W;
	cin >> N >> W;

	vector<vector<int>> value(4);
	long w1, v1;
	cin >> w1 >> v1;
	value[0].push_back(v1);

	for (int i = 1; i < N; i++) {
		int wi, vi;
		cin >> wi >> vi;
		value[wi - w1].push_back(vi);
	}

	for (int i = 0; i < 4; i++)
		sort(begin(value[i]), end(value[i]), greater<int>());

	long ans = 0;
	for (int i = 0; i <= value[0].size(); i++) {
		for (int j = 0; j <= value[1].size(); j++) {
			for (int k = 0; k <= value[2].size(); k++) {
				for (int l = 0; l <= value[3].size(); l++) {
					long w = i * w1 + j * (w1 + 1) + k * (w1 + 2) + l * (w1 + 3);
					if (w > W) continue;

					long v = 0;
					for (int m = 0; m < i; m++) v += value[0][m];
					for (int m = 0; m < j; m++) v += value[1][m];
					for (int m = 0; m < k; m++) v += value[2][m];
					for (int m = 0; m < l; m++) v += value[3][m];
					ans = max(ans, v);
				}
			}
		}
	}

	cout << ans << endl;
	return 0;
}


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

int main() {
	int w, n;
	int a[30];
	cin >> w >> n;
	for (int i = 0;i < w;i++) {
		a[i] = i + 1;
	}
	for (int i = 0;i < n;i++) {
		int p, q;
		char s;
		cin >> p >> s >> q;
		swap(a[p - 1], a[q - 1]);
	}
	for (int i = 0;i < w;i++)cout << a[i] << endl;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	string a, b;
	cin >> a >> b;

	int az = a.size();
	int bz = b.size();
	if(az > bz){
		cout << "GREATER" << endl;
		return 0;
	}else if(az < bz){
		cout << "LESS" << endl;
		return 0;
	}else{
		rep(i, az){
			if(a[i] > b[i]){
				cout << "GREATER" << endl;
				return 0;
			}else if(a[i] < b[i]){
				cout << "LESS" << endl;
				return 0;
			}
		}
	}

	cout << "EQUAL" << endl;
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long h, w;
      scan(h, w);
      for(long i = 0; i < w+2; ++i) putchar('#');
      putchar('\n');
      for(long i = 0; i < h; ++i) {
         std::string str;
         std::cin >> str;
         printf("#%s#\n", str.c_str());
      }
      for(long i = 0; i < w+2; ++i) putchar('#');
      putchar('\n');
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

vector<ll>path[1010];


int main(){

    ll N, M;
    cin >> N >> M;
    rep(i, M){
        ll a, b;
        cin >> a >> b;
        path[a].push_back(b);
    }
    vector<ll>ans;

    rep1(i, N){
        vector<ll>flg(N + 1, INF);
        flg[i] = -1;
        queue<ll>Q;
        Q.push(i);
        ll goal = -1;
        while(!Q.empty() && goal == -1){
            ll idx = Q.front();
            Q.pop();
            rep(j, path[idx].size()){
                ll to = path[idx][j];
                if(to == i){
                    goal = idx;
                    break;
                }
                if(flg[to] != INF)continue;
                flg[to] = idx;
                Q.push(to);
            }
        }
        if(goal == -1)continue;
        vector<ll>tmp;
        for(;;){
            tmp.push_back(goal);
            if(goal == i)break;
            goal = flg[goal];
        }
        if(ans.empty() || ans.size() > tmp.size())ans = tmp;
    }

    if(ans.size()){
        cout << ans.size() << endl;
        rrep(i, ans.size())cout << ans[i] << endl;
    }
    else cout << -1 << endl;

    return 0;
}


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

int main(){
    string S,T;
    cin >> S >> T;

    int len_S = S.length();
    int len_T = T.length();

    int max = 0;

    for(int i = 0; i <= len_S - len_T; i++){
        int cnt = 0;
        for(int j = 0; j < len_T; j++){
            if(T[j] == S[i + j]){
                cnt += 1;
            }
        }
        if(cnt >= max){
            max = cnt;
        }
    }

    cout << len_T - max << endl;

    return 0;
}

Measured memory_bytes: 3628
# 2020/06/21
# AtCoder Beginner Contest 171 - D

# Input
n = int(input())
a = list(map(int,input().split()))

# al = [0] * (10 ** 2 + 1)
al = [0] * (10 ** 5 + 1)
sum = 0

# Sum and Count
for i in range(n):
    al[a[i]] = al[a[i]] + 1
    sum = sum + a[i]

# Output question
q = int(input())
chg = 0
for i in range(q):
    b, c = map(int,input().split())
    chg = -1 * b * al[b]
    chg = chg + al[b] * c
    sum = sum + chg
    print(sum)
    al[c] = al[c] + al[b]
    al[b] = 0


Measured memory_bytes: 20764
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    map<char, bool> mp;
    for (int i=0; i<n; i++) {
        mp[s[i]] = true;
    }

    bool ans = false;
    ans |= mp.size() == 4;
    ans |= mp['N'] && mp['S'] && !mp['W'] && !mp['E'];
    ans |= !mp['N'] && !mp['S'] && mp['W'] && mp['E'];
    cout << (ans? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------

int main() {

    int t1, t2, r1, r2;
    cin >> t1 >> t2 >> r1 >> r2;

    if (r1 == -1 || r2 == -1) {
        if (t1 < t2) {
            cout << "Alice" << endl;
        } else if (t1 > t2) {
            cout << "Bob" << endl;
        } else {
            cout << "Draw" << endl;
        }
        return 0;
    }

    if (r1 > r2) {
        cout << "Alice" << endl;
    } else if (r1 < r2) {
        cout << "Bob" << endl;
    } else if (r1 == r2) {
        cout << "Draw" << endl;
    } else

        return 0;
}





































Measured memory_bytes: 3120
my $s= <STDIN>;
my ($N,$K)= split(/ /,$s);
#print "N$N K$K\n";
my $mod = 10**9+7;
my $sum = 0;
for( my $i=$K;$i<=($N+1);$i++){
  my $fst = (($i-1)*($i))/2;
  my $end = ((2*($N)-($i-1))*$i)/2;
  #print "$i fst$fst end$end\n";
  $sum = $sum + ($end -$fst + 1);
  #print "i$i $sum\n";
}
$sum = $sum%$mod;

print "$sum";

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

#define int long long
#define pb push_back
#define ins insert
#define pii pair<int,int>
#define fs first
#define sc second
#define mpr make_pair
#define iter iterator
#define all(X) X.begin(),X.end()
#define sau(X) sort(all(X)),X.resize(unique(all(X))-X.begin())
#define exist(X,ele) binary_search(all(X),ele)

const int inf=5000000000000000;

bool cmp(pii p,pii q)
{
	if(p.sc!=q.sc) return p.sc<q.sc;
	return p.fs<q.fs;
}

main()
{
	ios::sync_with_stdio(false);
	
	int N; cin>>N;
	vector<pii> a;
	a.pb({-inf,-inf});
	for(int i=0,x,l;i<N;i++)
	{
		cin>>x>>l;
		a.pb({x-l,x+l});
	}
	sort(all(a),cmp); // for(auto i:a) cout<<i.fs<<" "<<i.sc<<endl; cout<<endl<<endl;
	vector<pii> dp(N+1);
	dp[0]={0,-inf};
	for(int i=1;i<=N;i++)
	{
		dp[i]=dp[i-1];
		int L=0,R=i-1,mid;
		while(R-L>=3)
		{
			mid=(L+R)/2;
			if(a[mid].sc<=a[i].fs) L=mid;
			else R=mid;
		}
		int k;
		for(k=R;k>=L;k--)
		{
			if(a[k].sc<=a[i].fs) break;
		}
		if(k>=0 && dp[k].fs+1>dp[i].fs)
		{
			dp[i]={dp[k].fs+1,a[i].sc};
		}
	}
	cout<<dp[N].fs<<endl;
	return 0;
}






















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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((a + b) > (c + d)){
        cout << "Left" << endl;
    }else if((a + b) < (c + d)){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int W,a,b;
  cin>>W>>a>>b;
  int ans=0;
  if(a+W<b)
    ans=b-a-W;
  if(b+W<a)
    ans=a-b-W;
  cout<<ans<<endl;

  
  


}
     









Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<string.h>
typedef long long int ll;
using namespace std;
int main()
{
    ll s,n,lp=1,m1,n1,n2,nl,m,i,j,k,sum;
    cin >> n >> k >> s;
    for (int i = 1; i <= k; ++i)
        {
             cout << s << ' ';
    }    if (s == 1e9) {
            for (int i = 1; i <= n - k; ++i)
        cout << 1 << ' ';
         }
          else
            {
                  for (int i = 1; i <= n - k; ++i)
                     cout << s + 1 << ' ';
          }


     return 0;
}


Measured memory_bytes: 1280
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author koneko096
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    AAC solver = new AAC();
    solver.solve(1, in, out);
    out.close();
  }

  static class AAC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      out.println(in.next().equals("ABC") ? "ARC" : "ABC");
    }

  }


  static class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

  }
}



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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;



int main() {

	int n;
	cin >> n;
	bool y=false;
	rep(i, 9) {
		if (n % (i + 1)==0&& n / (i + 1) <= 9)y = true;
	}
	if (y)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

Int n;
Int cnt;

void rec(string s, string t, Int depth, Int change) {
    //cout << depth << " " << s << endl;
    if (change >= cnt) return;
    if (depth == n) {
        cnt = min(cnt, change);
        return;
    }
    if (s[depth] == t[depth]) {
        rec(s, t, depth + 1, change);
    }
    Int a = s[depth] - '0';
    Int b = t[depth] - '0';
    Int add = (b - a + 10) % 10;
    vector<string> p;
    for (Int i = depth; i < n; i++) {
        s[i] = '0' + ((s[i] - '0' + add) % 10);
        p.push_back(s);
        //rec(s, t, depth + 1, change + 1);
    }
    for (Int i = (Int)p.size() - 1; i >= 0; i--) {
        rec(p[i], t, depth + 1, change + 1);
    }
}

int main() {
    vector<Int> res;
    while (cin >> n and n) {
        string s, t;
        cin >> s >> t;
        cnt = inf;
        rec(s, t, 0, 0);
        res.push_back(cnt);
    }
    for (Int i = 0; i < (Int)res.size(); i++) {
        dump(res[i]);
    }
    return 0;
}



Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

ll table[100005];

ll modpow(ll n, ll k, ll mod){
    ll rtn = 1;
    while(k > 0){
        if(k&1) rtn = rtn*n%mod;
        n = n * n % mod;
        k >>= 1;
    }
    return rtn;
}

int main(){
    int n, k;
    cin >> n >> k;
    ll dp[k+1];
    ll ans = 0;
    for(int i = k ; i >= 1 ; i--){
        ll a = modpow(k/i, n, mod); 
        for(int j = 2 ; i*j <= k ; j++){
          if(a - table[i*j]<0) a = a + mod - table[i*j];
          else a -= table[i*j];
        }
        table[i] = a;
        ans += a*i;
        ans %= mod;
    }
    cout << ans%mod << endl;
    
}

Measured memory_bytes: 4404
#include <iostream>
using namespace std;
int sumofdigits(int n)
{
	int sum = 0;
	while( n > 0 )
	{
		sum += n%10;
		n /= 10;
	}
	return sum;
}
int main()
{
	int n;
	cin >> n;
	if( n % sumofdigits(n) == 0 )
		cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3580